Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/faq/opengl.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Render with `--renderer=opengl`; add `-l` (or `--live-preview`) for an
interactive preview window. Both renderers draw the same mobjects, so the rest of
the documentation applies to both. Smooth, lit surfaces
({class}`.ParametricSurface`, {class}`.MeshMobject`) are currently drawn by the
OpenGL renderer only.
the documentation applies to both. Surfaces ({class}`.Surface`,
{class}`.ParametricSurface`, {class}`.MeshMobject`) are drawn by both; the OpenGL
renderer lights them per pixel and hides what is behind them with a depth test.

Earlier versions had separate OpenGL mobject classes (`OpenGLMobject`,
`OpenGLVMobject`, `OpenGLSurface`, ...); see
Expand Down
57 changes: 55 additions & 2 deletions docs/source/guides/upgrading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Removed classes
* - ``OpenGLImageMobject``
- :class:`.ImageMobject`
* - ``OpenGLSurface``
- :class:`.ParametricSurface`, a smooth lit surface (OpenGL only for now),
or :class:`.Surface`, a group of polygon faces drawn by both renderers
- :class:`.ParametricSurface`, a smooth lit surface, or :class:`.Surface`,
its checkerboard-coloured version
* - ``OpenGLTexturedSurface``
- :class:`.ParametricSurface` with ``texture=``. One texture: the separate
night-side texture is gone.
Expand Down Expand Up @@ -152,3 +152,56 @@ Things that look different
- Under :class:`.ThreeDScene`, lines and other paths are drawn in the order they
are added, as with Cairo; only :class:`.MeshMobject` takes part in the depth
test.

Surfaces are meshes
-------------------

:class:`.Surface` and the mobjects built on it (:class:`.Sphere`, :class:`.Dot3D`,
:class:`.Torus`, :class:`.Cone`, :class:`.Cylinder`, :class:`.Line3D`,
:class:`.Arrow3D`, :meth:`.ThreeDAxes.plot_surface`) used to be a :class:`.VGroup` of
one :class:`.VMobject` per face. They are now :class:`.ParametricSurface` meshes,
drawn as meshes on OpenGL and as sorted faces on Cairo:

- The faces are not submobjects anymore: ``surface[i]``, iterating over a surface
and ``list_of_faces`` are gone. Colour faces with
:meth:`~.Surface.set_fill_by_checkerboard`, :meth:`~.Surface.set_fill_by_value`
or :meth:`.MeshMobject.set_vertex_colors`.
- ``set_fill``, ``set_stroke``, ``set_style``, ``set_color`` and ``set_opacity`` set
the colours of the faces and of their outlines; meshes can still be put into a
:class:`.VGroup`.
- The arguments ``should_make_jagged``, ``surface_piece_config`` and
``pre_function_handle_to_anchor_scale_factor`` are gone.
- They are lit by their ``material`` (:class:`.Pbr` by default) under a
:class:`.ThreeDCamera`'s light: faces turned away from the light are darker than
before, and the surface has highlights. ``material=Unlit()`` shows its colors as
they are. Under other cameras, surfaces are not lit.
- A surface without ``checkerboard_colors`` is lit smoothly; with them, each face
is lit flat.
- The end caps of :class:`.Cylinder` (``base_top``, ``base_bottom``) and the base of
:class:`.Cone` (``base_circle``) are discs of the same kind, lit as the side is,
not :class:`.Circle` paths.
- The sides of the faces are straight lines between the sampled points (they were
slightly curved).
- A surface can only be transformed into a mesh with the same triangles: a surface
of the same resolution and the same kind (smooth, or with a checkerboard). A
surface and a path cannot be transformed into each other.

The faces of solids are meshes
------------------------------

The faces of :class:`.Cube`, :class:`.Prism` and the polyhedra
(:class:`.Polyhedron` and its subclasses, :class:`.ConvexHull3D`) used to be
:class:`.Square` and :class:`.Polygon` paths shaded with ``shade_in_3d``. They are
now :class:`.PolygonFace` meshes, lit by a ``material`` (:class:`.Pbr` by default;
``Cube(material=...)`` and ``faces_config={"material": ...}`` set another):

- ``cube[i]`` and ``polyhedron.faces[i]`` are still the faces, in a
:class:`.VGroup`, and ``set_fill``, ``set_stroke``, ``set_color`` and
``set_opacity`` work on them as before. Methods of paths
(``get_vertices``, ``point_from_proportion``, ...) do not; a face's corners are
its ``points``.
- ``faces_config`` takes the styling arguments it took
(``fill_color``, ``fill_opacity``, ``stroke_color``, ``stroke_width``,
``stroke_opacity``); ``shade_in_3d`` has no effect.
- A face is transformed only into a face with as many corners; ``Create`` shows a
face at once instead of drawing its outline.
2 changes: 1 addition & 1 deletion manim/animation/transform_matching_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_shape_map(self, mobject: Mobject) -> dict:
key = self.get_mobject_key(sm)
if key not in shape_map:
shape_map[key] = VGroup()
shape_map[key].add(sm) # type: ignore[arg-type]
shape_map[key].add(sm)
return shape_map

def clean_up_from_scene(self, scene: Scene) -> None:
Expand Down
18 changes: 17 additions & 1 deletion manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class Mobject:
"""

points: ArrayField[Point3D_Array] = ArrayField(np.float64)
#: Whether the mobject may be a submobject of a VMobject (see
#: ``vectorized_mobject._is_vmobject_like``).
_vmobject_like: ClassVar[bool] = False
z_index: Field[float] = Field()
fixed_in_frame: Field[bool] = Field()
#: ``None``, or the function giving the point the mobject keeps facing the camera
Expand Down Expand Up @@ -223,11 +226,18 @@ def _assert_valid_submobjects(self, submobjects: Iterable[Mobject]) -> Self:
"""
return self._assert_valid_submobjects_internal(submobjects, Mobject)

@classmethod
def _accepts_submobject(cls, submobject: object) -> bool:
"""Whether ``submobject`` may be a submobject of a mobject that holds only
mobjects of this class.
"""
return isinstance(submobject, cls)

def _assert_valid_submobjects_internal(
self, submobjects: Iterable[Mobject], mob_class: type[Mobject]
) -> Self:
for i, submob in enumerate(submobjects):
if not isinstance(submob, mob_class):
if not mob_class._accepts_submobject(submob):
error_message = (
f"Only values of type {mob_class.__name__} can be added "
f"as submobjects of {type(self).__name__}, but the value "
Expand Down Expand Up @@ -2494,6 +2504,12 @@ def get_critical_point(self, direction: Vector3DLike) -> Point3D:
all_points = self.get_points_defining_boundary()
if len(all_points) == 0:
return result
if type(self).get_extremum_along_dim is Mobject.get_extremum_along_dim:
# All dimensions at once; the same values as the loop below.
points = np.asarray(all_points)[:, : self.dim]
low, high = points.min(axis=0), points.max(axis=0)
key = np.asarray(direction, dtype=float)[: self.dim]
return np.where(key < 0, low, np.where(key > 0, high, (low + high) / 2))
for dim in range(self.dim):
result[dim] = self.get_extremum_along_dim(
all_points,
Expand Down
Loading
Loading