mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
add zorder to mobject
This commit is contained in:
parent
d8428585f8
commit
0b5e9d4a8b
2 changed files with 9 additions and 0 deletions
|
@ -83,6 +83,7 @@ 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,
|
||||||
|
zorder: int = 0,
|
||||||
):
|
):
|
||||||
self.color = color
|
self.color = color
|
||||||
self.opacity = opacity
|
self.opacity = opacity
|
||||||
|
@ -90,6 +91,8 @@ class Mobject(object):
|
||||||
self.texture_paths = texture_paths
|
self.texture_paths = texture_paths
|
||||||
self._is_fixed_in_frame = is_fixed_in_frame
|
self._is_fixed_in_frame = is_fixed_in_frame
|
||||||
self.depth_test = depth_test
|
self.depth_test = depth_test
|
||||||
|
self.zorder = zorder
|
||||||
|
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.zorder,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