Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

fix(scene): preserve z-index ordering in animation groups (#4918)

Benjamin Hacklacd1e231ba79
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
index 81dc7ee64..f86419e81 100644
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -923,12 +923,13 @@ class Scene:
) -> list[Mobject | OpenGLMobject]:
animation_mobjects: list[Mobject | OpenGLMobject] = []
for anim in nested_animations:
+ # Keep composition wrappers as conservative boundaries for the
+ # static frame cache, in addition to their nested animations.
+ animation_mobjects.extend(anim.mobject.get_family())
if isinstance(anim, AnimationGroup):
animation_mobjects.extend(
_collect_animation_mobjects(anim.animations),
)
- else:
- animation_mobjects.extend(anim.mobject.get_family())
return animation_mobjects
animation_mobjects = _collect_animation_mobjects(animations)
diff --git a/tests/module/scene/test_scene.py b/tests/module/scene/test_scene.py
index c64fbd46a..51db5a953 100644
--- a/tests/module/scene/test_scene.py
+++ b/tests/module/scene/test_scene.py
@@ -4,7 +4,18 @@ import datetime
import pytest
-from manim import Circle, Dot, FadeIn, Group, Mobject, Scene, Square
+from manim import (
+ Circle,
+ Dot,
+ FadeIn,
+ Group,
+ Line,
+ Mobject,
+ Scene,
+ ShowPassingFlash,
+ Square,
+ Succession,
+)
from manim.animation.animation import Wait
@@ -51,6 +62,24 @@ def test_scene_time(dry_run):
assert pytest.approx(scene.time) == 7.5
+def test_animation_group_moving_mobjects_preserve_z_index_order(dry_run):
+ scene = Scene()
+ left_circle = Circle().set_z_index(1)
+ right_circle = Circle().set_z_index(1)
+ line = Line().set_z_index(-1)
+ scene.add(left_circle, right_circle)
+
+ succession = Succession(
+ right_circle.animate.set_fill(opacity=1),
+ ShowPassingFlash(line),
+ )
+ scene.compile_animation_data(succession)
+ scene.begin_animations()
+
+ assert left_circle in scene.moving_mobjects
+ assert left_circle not in scene.static_mobjects
+
+
def test_subcaption(dry_run):
scene = Scene()
scene.add_subcaption("Testing add_subcaption", duration=1, offset=0)