Skip to content

Commit 87cd635

Browse files
Merzlikin-Matveypre-commit-ci[bot]behackl
authored
Add support for negative z-index in AnimationGroup (#4389)
* Add support for negative z-index in AnimationGroup * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor animation unpacking logic for clarity * Fix unpacking logic to handle Mobject instances correctly * Fix mypy check * Fix tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: simplify AnimationGroup unpacking for moving mobjects --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>
1 parent cd37061 commit 87cd635

5 files changed

Lines changed: 39 additions & 1 deletion

File tree

manim/scene/scene.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,24 @@ def get_moving_mobjects(self, *animations: Animation) -> list[Mobject]:
903903
# as soon as there's one that needs updating of
904904
# some kind per frame, return the list from that
905905
# point forward.
906-
animation_mobjects = [anim.mobject for anim in animations]
906+
# Imported inside the method to avoid cyclic import.
907+
from ..animation.composition import AnimationGroup
908+
909+
def _collect_animation_mobjects(
910+
nested_animations: Iterable[Animation],
911+
) -> list[Mobject | OpenGLMobject]:
912+
animation_mobjects: list[Mobject | OpenGLMobject] = []
913+
for anim in nested_animations:
914+
if isinstance(anim, AnimationGroup):
915+
animation_mobjects.extend(
916+
_collect_animation_mobjects(anim.animations),
917+
)
918+
else:
919+
animation_mobjects.extend(anim.mobject.get_family())
920+
return animation_mobjects
921+
922+
animation_mobjects = _collect_animation_mobjects(animations)
923+
907924
mobjects = self.get_mobject_family_members()
908925
for i, mob in enumerate(mobjects):
909926
update_possibilities = [
Binary file not shown.
Binary file not shown.

tests/test_graphical_units/test_geometry.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ def test_ZIndex(scene):
174174
scene.play(ApplyMethod(triangle.shift, 2 * UP))
175175

176176

177+
@frames_comparison(last_frame=False)
178+
def test_negative_z_index_AnimationGroup(scene):
179+
# https://github.com/ManimCommunity/manim/issues/3334
180+
s = Square().set_z_index(-1)
181+
scene.play(AnimationGroup(GrowFromCenter(s)))
182+
183+
184+
@frames_comparison(last_frame=False)
185+
def test_negative_z_index_LaggedStart(scene):
186+
# https://github.com/ManimCommunity/manim/issues/3914
187+
line_1 = Line(LEFT, RIGHT, color=BLUE)
188+
line_2 = Line(UP + LEFT, UP + RIGHT, color=RED).set_z_index(-1)
189+
scene.play(LaggedStart(FadeIn(line_1), FadeIn(line_2), lag_ratio=0.5))
190+
191+
192+
@frames_comparison(last_frame=False)
193+
def test_nested_animation_groups_with_negative_z_index(scene):
194+
line = Line(LEFT, RIGHT, color=BLUE).set_z_index(-1)
195+
scene.play(AnimationGroup(AnimationGroup(AnimationGroup(FadeIn(line)))))
196+
197+
177198
@frames_comparison
178199
def test_Angle(scene):
179200
l1 = Line(ORIGIN, RIGHT)

0 commit comments

Comments
 (0)