mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Merge pull request #2057 from germanzhu/add-zorder-mobject
add zorder to mobject
This commit is contained in:
commit
aebf2220a6
2 changed files with 9 additions and 0 deletions
|
@ -86,12 +86,15 @@ class Mobject(object):
|
||||||
# If true, the mobject will not get rotated according to camera position
|
# If true, the mobject will not get rotated according to camera position
|
||||||
is_fixed_in_frame: bool = False,
|
is_fixed_in_frame: bool = False,
|
||||||
depth_test: bool = False,
|
depth_test: bool = False,
|
||||||
|
z_index: int = 0,
|
||||||
):
|
):
|
||||||
self.color = color
|
self.color = color
|
||||||
self.opacity = opacity
|
self.opacity = opacity
|
||||||
self.shading = shading
|
self.shading = shading
|
||||||
self.texture_paths = texture_paths
|
self.texture_paths = texture_paths
|
||||||
self.depth_test = depth_test
|
self.depth_test = depth_test
|
||||||
|
self.z_index = z_index
|
||||||
|
self._scene_order = 0
|
||||||
|
|
||||||
# Internal state
|
# Internal state
|
||||||
self.submobjects: list[Mobject] = []
|
self.submobjects: list[Mobject] = []
|
||||||
|
|
|
@ -414,7 +414,13 @@ class Scene(object):
|
||||||
foreground in the order with which they are added.
|
foreground in the order with which they are added.
|
||||||
"""
|
"""
|
||||||
self.remove(*new_mobjects)
|
self.remove(*new_mobjects)
|
||||||
|
idx = 0
|
||||||
|
scene_order = len(self.mobjects)
|
||||||
|
for m in new_mobjects:
|
||||||
|
m._scene_order = scene_order+idx
|
||||||
|
idx += 1
|
||||||
self.mobjects += new_mobjects
|
self.mobjects += new_mobjects
|
||||||
|
self.mobjects = [self.mobjects[0]]+sorted(self.mobjects[1:], key=lambda m:(m.z_index, m._scene_order))
|
||||||
self.id_to_mobject_map.update({
|
self.id_to_mobject_map.update({
|
||||||
id(sm): sm
|
id(sm): sm
|
||||||
for m in new_mobjects
|
for m in new_mobjects
|
||||||
|
|
Loading…
Add table
Reference in a new issue