ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
21.85k stars 1.59k forks source link

ReplacementTransform and z_index issue #3110

Open tl-jasonwu opened 1 year ago

tl-jasonwu commented 1 year ago

Description of bug / unexpected behavior

When I use the ReplacementTransform(source_mobject, target_mobject) function to transform a mobject, I find that target_mobject.z_index is unchanged, but the target_mobject will show as that target_mobject.z_index is changed to source_mobject.z_index.

Please see the code and gif below, I expect that the blue circle is above the red circle because the z_index of the blue circle is greater, but the result show that the blue circle is below the red circle.

Expected behavior

The blue circle is above the red circle.

How to reproduce the issue

Code for reproducing the problem ```py from manim import * class zIndexBug(Scene): def construct(self): circle = Circle(color=RED, fill_opacity=1).move_to(UP*0.5) circle.set_z_index(3) circle2 = Circle(color=BLUE, fill_opacity=1) circle2.set_z_index(6) circle3 = Circle(color=GREEN, fill_opacity=1).move_to(LEFT*3) circle3.set_z_index(1) self.play(FadeIn(circle3), FadeIn(circle)) self.play(ReplacementTransform(circle3, circle2)) ```

Additional media files

Images/GIFs ![](https://i.imgur.com/VB0KCrP.gif)

Logs

Terminal output ``` PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR ```

System specifications

System Details - OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): - RAM: - Python version (`python/py/python3 --version`): - Installed modules (provide output from `pip list`): ``` PASTE HERE ```
LaTeX details + LaTeX distribution (e.g. TeX Live 2020): + Installed LaTeX packages:
FFMPEG Output of `ffmpeg -version`: ``` PASTE HERE ```

Additional comments

linuxr commented 1 year ago

I have found that add self.wait() after self.play(ReplacementTransform(circle3, circle2)), the blue circle will be in front of the red one at last.

tl-jasonwu commented 1 year ago

@linuxr thanks for your help. Although the reason for this bug is still unknown, you saved my day. Now I can use this workaround to make my animation.