question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactoring Scene.mobjects

See original GitHub issue

Currently, Scene.mobjects is implemented as a list, and the Scene class does a lot of bookkeeping in order to keep it neatly organized. This is necessary because mobjects 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 to append something to it. You have to use restructure_mobjects every time you touch it. This is done so that mobjects are kept in the right order, but also to avoid duplication, deal with VGroups, etc. So, Scene.mobjects is implemented as a list but it’s never used as one. Sounds familiar? This means that Scene.mobjects should be its own class that handles all of these operations. If Scene.mobjects were a different class, then any dev working on Scene-derived classes will never have to think about whether to use append, add, or when to call restructure_mobjects.

In my mind I can think of a few things to do here:

  1. Extract all of the Scene.mobjects logic and define a new class OrderedMobjectList or something along those lines.
  2. Inside the new class, the 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.
  3. (Maybe) I’m not sure if mobjects needs to ever contain a Group or VGroup. I cannot find a reason why self.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 a Scene 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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
huguesdevimeuxcommented, Aug 27, 2020

Everything seems very good to me. Mobjects handling is very, very messy.

Does a Scene really need to keep track of which objects are grouped together?

And I don’t think so, as every time manim extract every family members to add them to scene.mobjects.

0reactions
leotrscommented, Sep 18, 2020

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”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refactor GameObjects | RiderFlow - JetBrains
RiderFlow includes the Replace Objects refactoring. Select one or more in a scene, right-click and choose Replace Objects.
Read more >
Refactoring Data stored in Unity Prefabs, Scenes and other ...
Using Unity, most of the Data will be serialized inside Prefabs, Scenes (inside MonoBehaviour serialized fields) and other Assets.
Read more >
Refactoring NetworkScenePostProcssing · Discussion #608 ...
Disable scene objects at build time. Solution: remove this features · Find SceneObjects at runtime and spawn them · Allow SceneObjects to be...
Read more >
Codea Craft 4 - do we need any objects here?
This is a refactoring. When we're done, we will have exactly the same scene and motion as before. No external behavior change.
Read more >
Refactoring From a Huge Storyboard to Multiple Smaller and ...
In short, new scenes have been added to the original storyboard and over time, ... to separate a large storyboard into smaller and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found