Repository navigation
07 Mesh And 3D
English | 中文
The painter is a 2D pipeline that covers in submission order. For a self-intersecting surface, a rim crossing its own edge, or coplanar grid cells, sorting alone cannot decide per pixel what is in front. RTM's mesh path hands geometry to the GPU depth buffer:
mesh (depth write)
↓
painter (depth test, no write)
↓
text / images / 2D overlays
batch = MeshBatch()
batch.append(quads, colors)-
quads:(Q, 4, 3), world-space positions of the four corners; -
colors:(Q, 4, 4), per-corner RGBA.
batch = MeshBatch()
batch.append_indexed(vertices, quads, colors)-
vertices:(N, 3)unique vertices; -
quads:(Q, 4)integer indices; - shared corners are projected once, then gathered per quad.
MeshBatch.from_surface(surface) bakes an ordinary Surface into an indexed batch; MeshMobject.from_surface(...) turns the mesh into a scene mobject, so shift/rotate/scale/.animate really move it.
The current native path submits 4 vertices + 6 uint32 indices per quad:
AddMeshIndexed(vertex_count, x,y,z,rgba, index_count, indices)
The old path submitted 6 expanded vertices; indexing removes duplicates and raises the capacity to:
MAX_MESH_VERTS = 524,288- indexed path:
131,072quads - legacy six-vertex fallback:
87,381quads
MeshGroup(*batches) / win.set_mesh([a, b]) merge independent batches into the frame's single native mesh; list order is draw order. It changes ownership and ordering, not total capacity.
-
win.set_mesh(batch): an explicit frame-level mesh that does not follow scene transforms. -
MeshMobject: a scene mobject;synccollects everyMeshMobject(including nested ones) and merges them with explicit batches into the frame's single mesh. -
MeshGroup: a merge of several batches; each batch can still update its arrays independently.
Two mutually exclusive paths:
MeshMobject.from_surface(surf, shade=True)- bakes ManimCE's two-sided shading into per-corner colours;
- re-shades as geometry moves and the world light changes;
- does not depend on
win.set_mesh_light.
MeshBatch.from_surface(surf, lit=True)
# or MeshBatch(lit=True).append(quads, colors)
win.set_mesh_light(ambient=0.3, diffuse=0.8, specular=0.25, shininess=24)- vertices carry normals:
x,y,z,nx,ny,nz,r,g,b,a; - the fragment stage does Lambert + Blinn-Phong;
-
ambient=1, diffuse=0, specular=0is pixel-identical to unlit output; -
append_indexed(normals=...)accepts per-vertex smooth normals(N,3)or per-corner face normals(Q,4,3).
Text, math and images are always on top by default. To let a 3D primitive be occluded by meshes:
label.set_shade_in_3d(True)
img.set_shade_in_3d(True)Its paint unit depth maps into the mesh's [0,1] depth range and takes part in depth testing; unmarked 2D content keeps depth 0 and the overlay semantics.
With RTM_AUTO_DEPTH=1, depth_mesh.py tries to route Surface roots that are "opaque, flat-shaded, no visible stroke" into the depth channel; if any condition fails, the whole frame falls back to painter to avoid cross-object ordering mistakes.
- quads only; use a degenerate quad for triangles, or go through
from_surface. - no per-pixel transparency sorting; translucent coplanar faces still blend in submission order.
- one native mesh per frame;
appendraisesValueErrorpast capacity, and writing the public arrays directly truncates to whole quads with a singleRuntimeWarning. -
MeshGroup's per-batch ownership does not change the frame budget; the total is still capped at131,072quads. -
lit=Trueandshade=Truecannot be mixed on one mesh.
-
real_time_manim/mesh.py:MeshBatch,MeshGroup,from_surface, indexed/lit construction -
real_time_manim/mesh_mobject.py:MeshMobject, scene transforms -
real_time_manim/window/depth_mesh.py:RTM_AUTO_DEPTH -
native/vulkan_draw.c,native/platform.c:AddMesh*and the lit pipeline