Repository navigation
Conversation
This was referenced Nov 23, 2026
| # A fan of triangles from the first corner (the polygon is convex). | ||
| triangles = np.array([[0, i, i + 1] for i in range(1, count - 1)]) | ||
| super().__init__(points=corners_array, triangles=triangles, **kwargs) | ||
| self.faces = np.arange(count)[None, :] |
Member
Author
There was a problem hiding this comment.
False positive: faces is a versioned field (a data descriptor defined on MeshMobject), and this line assigns the instance's value through it, after MeshMobject.__init__ set the empty default. A polygon face has one face, its corners in order.
behackl
force-pushed
the
refactor/meshes
branch
from
November 23, 2026 21:06
b3f5ff4 to
3b7bf9e
Compare
The Cairo renderer raised CapabilityError for MeshMobject and ParametricSurface. It now draws a mesh as one filled polygon per face: the faces become path snapshots sorted far to near, and under a ThreeDCamera they are sorted with the other 3D paths of the scene. - Faces: MeshMobject.faces holds the polygons a mesh is made of (quads for ParametricSurface, in order around each); empty means its triangles. Each face is colored by its corners' mean color or by the texture at its middle (renderer/_mesh.py, shared with OpenGL). - Lighting: each face is lit at its middle by renderer/_lighting.shade, the function the OpenGL mesh shader computes per pixel, with the camera's light and eye (Camera._light, _eye, _view_rotation); not lit under a flat camera or when fixed in frame. - Outlines: stroke colour and width for the faces (new fields, none by default). Without them, opaque faces get a one-pixel outline in their own colour, which closes the seams where antialiased edges of neighbouring faces meet. - Keys: a face node's key is (mesh key, face index), or None if the mesh has none, so the path cache never reuses a face across a change of the mesh, its material included. The mesh drawing tests run on both renderers now (translucency stays an OpenGL test: Cairo shows the back faces of translucent meshes), and Cairo's faces are compared with the lighting function. Interpolating between meshes with the same outline colours and width keeps their versions (equal widths are not mixed: that can round them).
A mesh with outlines (stroke_width > 0) is drawn by the OpenGL renderer with a vertex per corner of each face, so that its fragment shader can outline the faces: at the distance from the face's sides (quad or barycentric coordinates per corner), as wide as a stroke on the Cairo renderer, half inside each face; so the outlines take part in the depth test and are lit with the face. Meshes without outlines keep shared vertices and smooth lighting. The faces come from renderer/_mesh.py, as on Cairo; the OpenGL package does not import the Cairo package. A test checks that outlines land on the same pixels as Cairo's strokes.
Surface was a VGroup of one VMobject per face, drawn as thousands of paths; ParametricSurface a mesh. Surface is now a ParametricSurface with its former API: faces in a checkerboard (checkerboard_colors, set_fill_by_checkerboard), outlined (stroke_color, stroke_width), and set_fill_by_value colouring each face, and its outline, by the value halfway around it, with pivots as before. Sphere, Dot3D, Torus, Cone, Cylinder, Line3D, Arrow3D and plot_surface build on it unchanged; on OpenGL they are meshes with a depth test now. should_make_jagged, surface_piece_config and pre_function_handle_to_anchor_scale_factor go; color is the fill colour, as for other mobjects. Surfaces are lit by their material, Pbr() by default, as meshes are: under a ThreeDCamera, faces turned away from its light are darker than the old shade_in_3d shading made them, and surfaces have highlights. With a checkerboard (or after set_fill_by_value), every face has its own corners and is lit flat; without, neighbouring faces share corners and the surface is lit smoothly. The end caps of Cylinder and the base of Cone are discs of the same kind (ParametricSurface), with the surface's colour and material, so they are lit as the side is; they were Circle paths with the old 3D shading. So that existing code keeps working with meshes in groups: - Meshes may be submobjects of VMobjects and VGroups (the Dot3D vertices of polyhedra are in a Graph): Mobject._vmobject_like, true for VMobjects and MeshMobjects. VMobject methods that walk the family skip what only paths have (anchor modes, handles), and bounds use the points of meshes. - MeshMobject has the styling methods groups call: set_fill, set_stroke (outline colours: one or one per face), set_style, fill_color/fill_opacity/stroke_color/stroke_opacity, and no-op set_sheen and color_using_background_image. Surface.set_color colours the outlines too, as for the faces before. set_color, set_fill, set_opacity, fade, set_stroke and set_style reach submobjects unless family=False, so a Cone's base, a Cylinder's caps and an Arrow3D's parts take the solid's colour. ThreeDCamera sorts a whole mesh (on OpenGL; Cairo sorts its faces) by its middle among the 3D paths, so the end caps of a Cylinder show. ConvexHull3D took its faces, and their corners, from sets of points whose iteration order depended on the hash seed, which made its test flaky; they are sorted now, with corners in order around the outward normal. Control data regenerated deliberately (Cairo), the look approved before: threed (Sphere, Dot3D, Cone, Cylinder, Line3D, Arrow3D, Torus, SurfaceColorscale, Y_Direction), coordinate_system (plot_surface, plot_surface_colorscale), and the polyhedra (their vertices are Dot3D spheres, now lit). The upgrading guide has a section on surfaces.
The faces of Cube, Prism and the polyhedra were Square and Polygon paths
shaded with shade_in_3d, the old 3D shading of vector mobjects. They are
now PolygonFace meshes (a flat polygon as a MeshMobject, its corners in
order around it), lit by a material like surfaces: Pbr() by default;
Cube(material=...) and faces_config={"material": ...} set another.
- Cube and Prism stay VGroups of six faces; Polyhedron keeps its faces
in a VGroup and moves their corners with the graph's vertices.
- faces_config takes the styling arguments of the Polygon faces
(fill_color, fill_opacity, stroke_color, stroke_width, stroke_opacity,
color); polyhedron faces keep their outline, 4 wide in the face's
colour, as the edges of the solid. shade_in_3d has no effect.
The faces are lit flat, and darker where they turn away from the light,
on both renderers; translucent solids show their back faces as before.
Control data regenerated deliberately (Cairo): threed Cube, CameraMove
and AmbientCameraMove. The polyhedra tests run in a Scene without a
light and keep their pixels.
The upgrading guide has a section on the faces of solids.
VMobject.get_points_defining_boundary built a Python list of every anchor row of the family and converted it back to an array, and get_critical_point then reduced it once per dimension. Both are now array operations with the same results (and the same order of anchors). get_critical_point keeps the per-dimension path for subclasses that override get_extremum_along_dim. Every positioning method goes through these (next_to, arrange, get_center, ...), as does the depth sorting of 3D faces and the axis shading of ThreeDAxes, which asks for edge centers of whole axes in every frame.
_groups updated each group's pixel box with numpy calls for every path that joined it, which cost more than the comparisons themselves.
Review of #5173, for the commits of this branch: the faces of a mesh take its RNode.placement (they had z_index and the two fixed-placement fields), and renderer/cairo/mesh_faces.py, a renderer internal, becomes _mesh_faces.py.
behackl
force-pushed
the
refactor/meshes
branch
from
November 24, 2026 23:18
3b7bf9e to
f1399f4
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #5174.
Overview
Surfacewas aVGroupwith oneVMobjectper face, so a sphere was hundreds of paths that the renderer sorted and shaded one by one. It is now aParametricSurfacemesh (from #5174).Sphere,Dot3D,Torus,Cone,Cylinder,Line3D,Arrow3Dandplot_surfacebuild on it as before. The faces ofCube,Prismand the polyhedra become meshes too.The Cairo renderer learns to draw meshes: one polygon per face, sorted far to near and lit per face. OpenGL draws them with a depth test and per-pixel lighting.
Breaking changes
surface[i], iterating over its faces andlist_of_facesare gone. Colour faces withset_fill_by_checkerboard,set_fill_by_valueorset_vertex_colors.Surfaceloses the argumentsshould_make_jagged,surface_piece_configandpre_function_handle_to_anchor_scale_factor.Cube,Prismand polyhedra arePolygonFacemeshes.cube[i]andpolyhedron.faces[i]still work, as doset_fill,set_stroke,set_colorandset_opacity. Path methods such asget_verticesorpoint_from_proportionare gone; a face's corners are itspoints.Cylinderand the base ofConeare disc meshes (they wereCirclepaths).ValueErrorthat says so.Visible changes
ThreeDCamera: faces turned away from the light are darker than before, and surfaces have highlights.material=Unlit()shows the plain colours.Createshows a face of a solid at once instead of drawing its outline.Control data is regenerated for 19 Cairo tests of 3D primitives, surface plots and polyhedra.
New
MeshMobjecthas the styling methods groups call (set_fill,set_stroke,set_style, ...) and face outlines (stroke_color,stroke_width), so meshes can sit in aVGroup.PolygonFace;Cube(material=...)andfaces_config={"material": ...}.Docs
For reviewers
6 commits. The last two speed up bounding boxes, which every positioning method and the depth sort use. Also fixes a flaky
ConvexHull3Dtest (face order depended on the hash seed).