-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Refactoring Scene.mobjects #358
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
Comments
Everything seems very good to me. Mobjects handling is very, very messy.
And I don't think so, as every time manim extract every family members to add them to |
Tagging the devs as this is a major project that requires consensus from the community @ManimCommunity/core |
But how do you know which mobject is in front of the other if z_index are the same ? |
The point is that If you then manually change the z_index of a mobject that happens to clash with that of another one, then they can each be rendered in an arbitrary order OR the tie can be broken by the time of addition (the oldest added mobject gets rendered first). |
And if, in the future, you want to put a method to put an object between two other. Would you have to use floating point zindex ? More commonly, if you want to put a .moveBehind() method, how would you do that ? I think that a dedicated data structure (maybe a tree) would allow to move objects to the front or to the back easily. Of course, it would be compatible with z-index methods. |
Yeah I think there's no problem in using floating point indices. As long as there is a unique way of sorting the mobjects, you should be able to implement "move behind" and "move to the back". |
Currently,
Scene.mobjects
is implemented as a list, and theScene
class does a lot of bookkeeping in order to keep it neatly organized. This is necessary becausemobjects
must be kept in the order that mobjects are going to be rendered on screen.Or at least that was the case, until z-index was implemented #117. It is not without bugs (#327) but I think that keeping the z-order of each mobject is far better than trying to keep the list organized.
The truth is that
Scene.mobjects
should never have been a list. There main reason is that you cannot just choose toappend
something to it. You have to userestructure_mobjects
every time you touch it. This is done so that mobjects are kept in the right order, but also to avoid duplication, deal withVGroup
s, etc. So,Scene.mobjects
is implemented as a list but it's never used as one. Sounds familiar? This means thatScene.mobjects
should be its own class that handles all of these operations. IfScene.mobjects
were a different class, then any dev working onScene
-derived classes will never have to think about whether to useappend
,add
, or when to callrestructure_mobjects
.In my mind I can think of a few things to do here:
Scene.mobjects
logic and define a new classOrderedMobjectList
or something along those lines.mobjects
collection need not be a list. I think it should be a priority queue instead, where the priority values are the z-order of each mobject.mobjects
needs to ever contain aGroup
orVGroup
. I cannot find a reason whyself.add(some_group)
could't just add each element in the group to the scene, instead of adding the group itself to the scene. Does aScene
really need to keep track of which objects are grouped together? If the only reason to do this is to keep track of rendering order, we already have z-index for that!Please share your thoughts.
The text was updated successfully, but these errors were encountered: