A community-maintained Python framework for creating mathematical animations.
add z_index
Tony031218defaf4254ae0
diff --git a/manim/camera/camera.py b/manim/camera/camera.pyindex 5a76684b9..fd4e3512e 100644--- a/manim/camera/camera.py+++ b/manim/camera/camera.py@@ -61,6 +61,7 @@ class Camera(object):# round z coordinate to nearest hundredth when comparring"z_buff_func": lambda m: np.round(m.get_center()[2], 2),"cairo_line_width_multiple": 0.01,+ "open_z_index": True,}def __init__(self, background=None, **kwargs):@@ -413,6 +414,8 @@ class Camera(object):method = Mobject.family_members_with_pointselse:method = Mobject.get_family+ if self.open_z_index:+ mobjects.sort(key=lambda m: m.z_index)return remove_list_redundancies(list(it.chain(*[method(m) for m in mobjects])))diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex 44280bba3..b3649a4ea 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -34,6 +34,7 @@ class Mobject(Container):"name": None,"dim": 3,"target": None,+ "z_index": 0,}def __init__(self, **kwargs):@@ -1119,6 +1120,19 @@ class Mobject(Container):"for a Mobject with no points"caller_name = sys._getframe(1).f_code.co_nameraise Exception(message.format(caller_name))++ # About z-index+ def set_z_index(self, z_index_value):+ self.z_index = z_index_value+ return self++ def get_z_index(self):+ return self.z_index++ def set_z_index_by_z_coordinate(self):+ z_coord = self.get_center()[-1]+ self.set_z_index(z_coord)+ return selfclass Group(Mobject):