Skip to content

Conversation

OeGiaretta
Copy link

Overview: What does this pull request change?

Adds a new ImplicitSurface mobject for rendering 3D surfaces defined by implicit equations of the form f(x, y, z) = 0.

Motivation and Explanation: Why and how do your changes improve the library?

Currently, Manim supports explicit and parametric surfaces (Surface, ParametricSurface), but there is no direct way to visualize surfaces defined implicitly.

This PR introduces ImplicitSurface, which:

  • Evaluates a scalar function over a 3D grid defined by x_range, y_range, and z_range.
  • Uses the marching cubes algorithm (skimage.measure.marching_cubes) to extract the zero level-set as a triangular mesh.
  • Creates a VGroup of polygons that integrates seamlessly with Manim’s 3D rendering pipeline.
  • Enables users to easily render common implicit shapes such as spheres, tori, or more complex algebraic surfaces.

This directly addresses feature request #4428.

Further Information and Comments

  • This is an initial implementation. Known limitations include:
    • Performance may degrade for very high resolutions.
    • Normals for smooth shading are not yet integrated (currently uses polygons directly).
    • Users need to choose appropriate sampling ranges to capture the surface correctly.
  • Future work could include support for adaptive meshing, better handling of normals, and clipping options.

Example render of ImplicitSurface in action:

Test-Surface360-Manim-CE-v0-19-0.gif

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Generating test codes and examples to create an isosurface by simply providing f(x, y, z).
@OeGiaretta
Copy link
Author

I noticed that the tests are failing in my PR (#4429), but this is also happening in other recent PRs. It seems to be an issue with the CI environment rather than something directly related to my ImplicitSurface implementation. Could you please confirm if I should wait until the pipeline is fixed?

@chopan050
Copy link
Contributor

Hi and thanks for your contribution!

I noticed that the tests are failing in my PR (#4429), but this is also happening in other recent PRs. It seems to be an issue with the CI environment rather than something directly related to my ImplicitSurface implementation. Could you please confirm if I should wait until the pipeline is fixed?

Taking a look at the errors on the pipelines, the main issue in this case is that Manim can't find the skimage module you're using for ImplicitSurface. This is because it hasn't been marked as a dependency.

To add this dependency, run uv add scikit-image. This will modify the pyproject.toml file which contains this module's configuration. It also modifies uv.lock.

- Implemented ImplicitSurface class using Marching Cubes for isosurface
  rendering
  - Added type hints to implicit_surface.py
  - Fixed mypy typing issues in autoaliasattr_directive.py and
    file_ops.py
  - Updated conduct.md documentation
import numpy as np
from skimage import measure

from manim import *

Check notice

Code scanning / CodeQL

'import *' may pollute namespace Note

Import pollutes the enclosing namespace, as the imported module
manim
does not define '__all__'.
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