Skip to content

Add ImplicitSurface class for 3D implicit surface visualization#4499

Closed
jakekinchen wants to merge 9 commits intoManimCommunity:mainfrom
jakekinchen:feature/implicit-surface
Closed

Add ImplicitSurface class for 3D implicit surface visualization#4499
jakekinchen wants to merge 9 commits intoManimCommunity:mainfrom
jakekinchen:feature/implicit-surface

Conversation

@jakekinchen
Copy link
Copy Markdown
Contributor

@jakekinchen jakekinchen commented Dec 2, 2025

Summary

This PR introduces a new ImplicitSurface mobject that enables visualization of 3D surfaces defined by implicit functions f(x, y, z) = 0, analogous to how ImplicitFunction handles 2D implicit curves.

Key Features

  • Marching cubes algorithm via PyMCubes library for high-quality mesh extraction
  • Lightweight dependency: PyMCubes is only ~50-300KB (vs scikit-image's 22MB)
  • Configurable resolution parameter for mesh density control
  • High accuracy: Mean vertex error < 0.001 for unit sphere, axis intercepts at ±0.998
  • Dual renderer support: Works with both Cairo and OpenGL renderers
  • Verification method: verify_surface() for accuracy validation

New Dependency

  • pymcubes>=0.1.0 - Fast, lightweight marching cubes implementation

Example Usage

from manim import *

class ImplicitSphereExample(ThreeDScene):
    def construct(self):
        def sphere_func(x, y, z):
            return x**2 + y**2 + z**2 - 1.0

        surface = ImplicitSurface(
            sphere_func,
            x_range=(-1.3, 1.3),
            y_range=(-1.3, 1.3),
            z_range=(-1.3, 1.3),
            resolution=40,
            fill_color=BLUE,
            fill_opacity=0.8,
        )

        self.set_camera_orientation(phi=70 * DEGREES, theta=-45 * DEGREES)
        self.add(surface)

Rendered Examples

Sphere (unit sphere with 3D axes):
sphere_test0000

Torus (major radius 2, minor radius 0.5):
torus_test0000

Gyroid (minimal surface with salmon-to-pink gradient):
gyroid_test0000

manim -ql example_scenes/implicit_surface_examples.py ImplicitSphereExample
manim -ql example_scenes/implicit_surface_examples.py ImplicitGyroidExample

Files Changed

  • manim/mobject/three_d/implicit_surface.py - Main implementation
  • manim/mobject/opengl/opengl_implicit_surface.py - OpenGL renderer support
  • tests/module/mobject/test_implicit_surface.py - 10 unit tests
  • tests/test_graphical_units/test_threed.py - Graphical regression tests
  • example_scenes/implicit_surface_examples.py - 6 example scenes
  • pyproject.toml - Added pymcubes dependency

Test Plan

  • All 10 unit tests pass (pytest tests/module/mobject/test_implicit_surface.py)
  • Vertex accuracy verified (mean radius error 0.0005 for unit sphere)
  • Axis intersection points correctly positioned (±0.998 for unit sphere)
  • Linting passes (ruff check)
  • Renders correctly with Cairo renderer
  • CI tests pass
  • Documentation builds correctly

Related

  • Similar to ImplicitFunction for 2D curves
  • Complements existing Surface class for parametric surfaces

Introduces a new ImplicitSurface mobject that visualizes 3D surfaces
defined by implicit functions f(x, y, z) = 0, similar to how
ImplicitFunction handles 2D implicit curves.

Features:
- Uses PyMCubes library for marching cubes mesh extraction (~50-300KB)
- Configurable resolution parameter for mesh density control
- High vertex accuracy (mean error < 0.001 for unit sphere)
- Supports both Cairo and OpenGL renderers
- Includes verify_surface() method for accuracy validation

New dependency: pymcubes>=0.1.0

Includes unit tests, graphical tests, and example scenes demonstrating
spheres, tori, gyroids, and other implicit surfaces.
pre-commit-ci Bot and others added 8 commits December 2, 2025 18:39
The ImplicitSurface functionality is already covered by unit tests
in tests/module/mobject/test_implicit_surface.py
- Add proper type annotations to __init__ and method signatures
- Remove unused type: ignore comments
- Fix return types to match parent class signatures
@behackl
Copy link
Copy Markdown
Member

behackl commented Feb 22, 2026

Hey! Sorry for the late reply. I like the idea of this, and it obviously works very well based on the rendered examples -- but at the moment I am very hesitant to add this to the core library due to the added dependency on pymcubes, which looks a bit stale and doesn't offer wheels for newer releases of Python.

I do want to encourage you to turn this into a independently published manim plugin though!

@behackl behackl closed this Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

2 participants