Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active February 18, 2026 14:38
Show Gist options
  • Select an option

  • Save uwezi/cd2b553e0fe9396cf273173a2d212854 to your computer and use it in GitHub Desktop.

Select an option

Save uwezi/cd2b553e0fe9396cf273173a2d212854 to your computer and use it in GitHub Desktop.
[Manifold3D and Manim] Using the manifold3D library within Manim. #manim #3D #manifold3D #csg
from manim import *
import manifold3d as mf3
class spherical(ThreeDScene):
def construct(self):
self.set_camera_orientation(phi=70 * DEGREES, theta=-70 * DEGREES)
sp = mf3.Manifold.sphere(radius =2, circular_segments=24)
verts = sp.to_mesh().vert_properties
manimsphere = VGroup(
Polygon(
*[verts[k],verts[l],verts[m]],
joint_type = LineJointType.ROUND,
fill_opacity=0.5,
stroke_width=1,
stroke_color=ORANGE,
)
for (k,l,m) in sp.to_mesh().tri_verts
)
self.add(manimsphere)
class intersection(ThreeDScene):
def construct(self):
self.set_camera_orientation(phi=70 * DEGREES, theta=-70 * DEGREES)
sp = mf3.Manifold.sphere(radius =2, circular_segments=24)
box = mf3.Manifold.cube(size=[3,3,3], center=True)
obj = box ^ sp
verts = obj.to_mesh().vert_properties
manimobj = VGroup(
Polygon(
*[verts[k],verts[l],verts[m]],
joint_type = LineJointType.ROUND,
fill_opacity=1,
stroke_width=1,
stroke_color=ORANGE,
)
for (k,l,m) in obj.to_mesh().tri_verts
)
self.add(manimobj)
self.begin_ambient_camera_rotation(0.5)
self.wait(5)

How to use the mesh functions from the Python library Manifold3D in Manim.

This code is for the Cairo renderer - some changes will probably be necessary for the opengl renderer, however since the opengl-renderer natively works with triangular meshes, it should be quite feasible.

Two examples: a simple sphere and the intersection between a sphere and a cube

image

intersection_ManimCE_v0 19 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment