Skip to content

The animation engine for agents: blazingly fast math and 3D videos with Manim's Python API, on a Rust GPU core.

Python

Add remove_fixed_in_frame_mobjects, the undo of add_fixed_in_frame_mobjects

japbcoelhobcbd992c9ca0
diff --git a/docs/content/changelog.md b/docs/content/changelog.md
index b864def3..3c3b09b8 100644
--- a/docs/content/changelog.md
+++ b/docs/content/changelog.md
@@ -23,6 +23,7 @@ The notable changes to ManimGX, release by release. The format follows
- Add a preview image and social metadata when sharing website and documentation links.
- Credit Academa and the creators in the README.
- Add Manim CE's `partial_bezier_points`, `subdivide_bezier`, `bezier_remap`, `integer_interpolate`, `is_closed` and `get_smooth_cubic_bezier_handle_points` to the package.
+- Add `remove_fixed_in_frame_mobjects` to `ThreeDScene` and `Camera`, Manim CE's undo of `add_fixed_in_frame_mobjects`: the camera moves the mobjects again.
### Changed
diff --git a/docs/content/reference/camera-and-3d/camera.md b/docs/content/reference/camera-and-3d/camera.md
index 2a5fe7a4..9f5d1f9c 100644
--- a/docs/content/reference/camera-and-3d/camera.md
+++ b/docs/content/reference/camera-and-3d/camera.md
@@ -98,6 +98,10 @@ tone mapping, its bloom and its shadows.
options:
heading_level: 3
+::: manimgx.Camera.remove_fixed_in_frame_mobjects
+ options:
+ heading_level: 3
+
## Its angles, in 3D
::: manimgx.Camera.three_d
diff --git a/docs/content/user-guide/camera-and-3d.md b/docs/content/user-guide/camera-and-3d.md
index 823ab7f6..d4f90976 100644
--- a/docs/content/user-guide/camera-and-3d.md
+++ b/docs/content/user-guide/camera-and-3d.md
@@ -68,7 +68,8 @@ class Hill(m.ThreeDScene):
- `self.begin_ambient_camera_rotation(rate=0.3)` turns the camera around the scene, until
`self.stop_ambient_camera_rotation()`.
- `self.add_fixed_in_frame_mobjects(title)` keeps a mobject still on the screen while the
- camera moves: here, the title stays in its corner.
+ camera moves: here, the title stays in its corner. `self.remove_fixed_in_frame_mobjects(title)`
+ lets the camera move it again.
Every mobject has three coordinates, so flat mobjects work in 3D too. The
[reference][manimgx.mobjects.three_d] shows the mobjects made for 3D, such as
diff --git a/src/manimgx/scene.py b/src/manimgx/scene.py
index 7cd4598b..e222c367 100644
--- a/src/manimgx/scene.py
+++ b/src/manimgx/scene.py
@@ -466,6 +466,20 @@ class Camera:
"""
self._fixed_in_frame.update(dict.fromkeys(mobjects))
+ def remove_fixed_in_frame_mobjects(self, *mobjects: Mobject) -> None:
+ """Unpin mobjects from the screen: undo
+ [`add_fixed_in_frame_mobjects`][manimgx.Camera.add_fixed_in_frame_mobjects], so
+ the camera's angles, zoom and center move them again, among the scene's depths.
+
+ A mobject that was not pinned is passed over. One that is a member of a pinned
+ mobject stays pinned with it: unpin that mobject instead.
+
+ Args:
+ *mobjects: The mobjects to unpin, as they were pinned.
+ """
+ for mob in mobjects:
+ self._fixed_in_frame.pop(mob, None)
+
type Act = Callable[[Fraction, "Route | None"], Callable[[], None] | None]
"""A play's step at an instant: it brings what runs there (of the parts given, if any), and
@@ -2176,6 +2190,14 @@ class ThreeDScene(Scene):
self.add(*mobjects)
self.camera.add_fixed_in_frame_mobjects(*mobjects)
+ def remove_fixed_in_frame_mobjects(self, *mobjects: Mobject) -> None:
+ """Unpin mobjects from the screen, undoing
+ [`add_fixed_in_frame_mobjects`][manimgx.ThreeDScene.add_fixed_in_frame_mobjects]:
+ they stay in the scene, and the camera moves them again. A member of a pinned
+ mobject stays pinned with it.
+ """
+ self.camera.remove_fixed_in_frame_mobjects(*mobjects)
+
def _tracks(
anim: Animation,
diff --git a/tests/integration/test_compositing.py b/tests/integration/test_compositing.py
index 7f2a87e9..9124e64f 100644
--- a/tests/integration/test_compositing.py
+++ b/tests/integration/test_compositing.py
@@ -170,6 +170,30 @@ def test_a_title_fixed_in_the_frame_changes_no_pixel_but_its_own() -> None:
assert np.array_equal(picture(scene(True))[bottom], picture(scene(False))[bottom])
+def test_a_mobject_unpinned_from_the_frame_is_drawn_as_one_never_pinned() -> None:
+ # a square and a title, pinned and then unpinned from a turned camera's frame: the square
+ # is drawn where the camera puts it, as if it had never been pinned; the title stays pinned
+ def scene(pin: bool) -> m.Scene:
+ def construct(s: m.ThreeDScene) -> None:
+ s.set_camera_orientation(phi=60 * m.DEGREES, theta=-30 * m.DEGREES)
+ square = m.Square(side_length=2.0, fill_opacity=1.0).shift(m.RIGHT)
+ title = m.Text("A title").to_corner(m.UL)
+ if pin:
+ s.add_fixed_in_frame_mobjects(square, title)
+ s.remove_fixed_in_frame_mobjects(square)
+ assert square in s.mobjects
+ assert square not in s.camera.fixed_in_frame_mobjects
+ assert title in s.camera.fixed_in_frame_mobjects
+ else:
+ s.add(square)
+ s.add_fixed_in_frame_mobjects(title)
+ s.wait(0.1)
+
+ return scenes.scene_3d(construct)
+
+ assert np.array_equal(picture(scene(True)), picture(scene(False)))
+
+
def test_points_show_where_an_earlier_frame_had_see_through_surfaces() -> None:
# a see-through surface over the whole view, then over its top only: the points below it
# show in the last frame as if it had always been at the top