-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Properly respect submobjects when sorting by z_index #872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM.
Quick q : I saw that this is not recursive. Is it fine?
extracted_mobjects = remove_list_redundancies( | ||
list(it.chain(*[method(m) for m in mobjects])) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment At some point all the iterable handling in manim sutff should definitely be changed, as this is .. hmm .. not pretty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, we should refactor this. Stuff concerning families is really weird.
Cool!
And of course, there is the z variable, which is not related to the screen order right now. |
I just tested this feature with this below script, and I think that MathTex has a problem with z_index right now: from manim import *
config.background_color = WHITE
class MovingCameraOnGraph( Scene):
def construct(self):
logo_green = "#87c2a5"
logo_blue = "#525893"
logo_red = "#e07a5f"
ds_m = MathTex(r"\mathbb{M}", z_index=12).scale(7) # <- Problem!
ds_m.shift(2.25*LEFT + 1.5*UP)
circle = Circle(color=logo_green,
fill_opacity=1,
z_index=7)
square = Square(color=logo_blue,
fill_opacity=1,
z_index=5)
triangle = Triangle(color=logo_red,
fill_opacity=1,
z_index=3)
circle.shift(LEFT)
square.shift(UP)
triangle.shift(RIGHT)
vgroup = VGroup(triangle, square, circle, ds_m).move_to(ORIGIN).scale(0.2)
self.add(vgroup)
m5 = Square(fill_opacity=1, fill_color=BLACK).set_z_index(0)
self.add(m5)
self.wait() MovingCameraOnGraph.mp4When I change MathTex to Tex, the error is still there, however when I change MathTex to Dot with z_index 12, I get this as expected: |
I think so: the |
While this might seem like a lot of options, 2, 3, and 4 all simply modify |
Excellent catch! |
Exactly, I just think we should mention this somewhere in the docs.
And a very quick fix ;) |
Motivation
The only option to reorder Mobjects in a Scene from foreground to background, apart from adding them in the desired order in the list of (sub)mobjects currently is
z_index
-- and it is not working particularly well, see #327.Overview / Explanation for Changes
This PR changes the sorting of mobjects w.r.t. their
z_index
. Currently, only mobjects inScene.mobjects
and/orScene.foreground_mobjects
are sorted, and not all the submobjects contained in these families.In terms of the example provided in #327 this means that while both
circle
andsquare
have az_index
set, only thez_index
of theVGroup
containing both (which is added to the scene via theFadeIn
animation) is considered when sorting. With this PR, thez_index
of the objects themselves is considered.As an example, a simple scene which first sets the
z_index
of a square, a triangle and a circle to 0, 1, and 2, respectively, renders asZIndexTest.mp4
with this change, and as
ZIndexTest.mp4
on current master.
Note: This change should rather be seen as a quick bugfix; we should still revisit the entire idea of
z_index
(and, e.g., replace it by sorting by the z coordinate or so).Oneline Summary of Changes
Testing Status
See rendered example above, I've also added it as a graphical unit test (because the current, wrong, behavior can be observed from the final frame.)
Acknowledgements
Reviewer Checklist