mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 22:13:30 +08:00
Moved more of animation cleanup handling to the animations themselves
This commit is contained in:
@ -118,8 +118,11 @@ class Animation(object):
|
|||||||
def is_remover(self):
|
def is_remover(self):
|
||||||
return self.remover
|
return self.remover
|
||||||
|
|
||||||
def clean_up(self):
|
def clean_up(self, surrounding_scene = None):
|
||||||
self.update(1)
|
self.update(1)
|
||||||
|
if self.is_remover() and surrounding_scene is not None:
|
||||||
|
surrounding_scene.remove(self.mobject)
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
def sync_animation_run_times_and_rate_funcs(*animations, **kwargs):
|
def sync_animation_run_times_and_rate_funcs(*animations, **kwargs):
|
||||||
|
@ -55,6 +55,12 @@ class Transform(Animation):
|
|||||||
submob.interpolate(start, end, alpha, self.path_func)
|
submob.interpolate(start, end, alpha, self.path_func)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def clean_up(self, surrounding_scene = None):
|
||||||
|
Animation.clean_up(self, surrounding_scene)
|
||||||
|
if self.replace_mobject_with_target_in_scene and surrounding_scene is not None:
|
||||||
|
surrounding_scene.remove(self.mobject)
|
||||||
|
surrounding_scene.add(self.original_target_mobject)
|
||||||
|
|
||||||
class ReplacementTransform(Transform):
|
class ReplacementTransform(Transform):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"replace_mobject_with_target_in_scene" : True,
|
"replace_mobject_with_target_in_scene" : True,
|
||||||
@ -147,7 +153,8 @@ class FadeOut(Transform):
|
|||||||
target.set_fill(opacity = 0)
|
target.set_fill(opacity = 0)
|
||||||
Transform.__init__(self, mobject, target, **kwargs)
|
Transform.__init__(self, mobject, target, **kwargs)
|
||||||
|
|
||||||
def clean_up(self):
|
def clean_up(self, surrounding_scene = None):
|
||||||
|
Transform.clean_up(self, surrounding_scene)
|
||||||
self.update(0)
|
self.update(0)
|
||||||
|
|
||||||
class FadeIn(Transform):
|
class FadeIn(Transform):
|
||||||
|
@ -17,7 +17,7 @@ from tk_scene import TkSceneRoot
|
|||||||
from mobject import Mobject, VMobject
|
from mobject import Mobject, VMobject
|
||||||
from animation import Animation
|
from animation import Animation
|
||||||
from animation.animation import sync_animation_run_times_and_rate_funcs
|
from animation.animation import sync_animation_run_times_and_rate_funcs
|
||||||
from animation.transform import MoveToTarget, Transform
|
from animation.transform import MoveToTarget
|
||||||
|
|
||||||
class Scene(object):
|
class Scene(object):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
@ -142,6 +142,20 @@ class Scene(object):
|
|||||||
lambda m : m not in mobjects_to_remove,
|
lambda m : m not in mobjects_to_remove,
|
||||||
self.mobjects
|
self.mobjects
|
||||||
)
|
)
|
||||||
|
self.remove_mobjects_without_family_on_screen()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def remove_mobjects_without_family_on_screen(self):
|
||||||
|
def should_keep(mobject):
|
||||||
|
if mobject.get_num_points() > 0:
|
||||||
|
return True
|
||||||
|
num_family_members_among_mobjects = sum([
|
||||||
|
submob in self.mobjects
|
||||||
|
for submob in mobject.submobject_family()
|
||||||
|
])
|
||||||
|
return num_family_members_among_mobjects > 1
|
||||||
|
|
||||||
|
self.mobjects = filter(should_keep, self.mobjects)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def bring_to_front(self, *mobjects):
|
def bring_to_front(self, *mobjects):
|
||||||
@ -266,13 +280,7 @@ class Scene(object):
|
|||||||
|
|
||||||
def clean_up_animations(self, *animations):
|
def clean_up_animations(self, *animations):
|
||||||
for animation in animations:
|
for animation in animations:
|
||||||
animation.clean_up()
|
animation.clean_up(self)
|
||||||
if animation.is_remover():
|
|
||||||
self.remove(animation.mobject)
|
|
||||||
if isinstance(animation, Transform) :
|
|
||||||
if animation.replace_mobject_with_target_in_scene:
|
|
||||||
self.remove(animation.mobject)
|
|
||||||
self.add(animation.original_target_mobject)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_mobjects_from_last_animation(self):
|
def get_mobjects_from_last_animation(self):
|
||||||
|
@ -329,6 +329,7 @@ class RemovePiCreatureBubble(AnimationGroup):
|
|||||||
CONFIG = {
|
CONFIG = {
|
||||||
"target_mode" : "plain",
|
"target_mode" : "plain",
|
||||||
"look_at_arg" : None,
|
"look_at_arg" : None,
|
||||||
|
"remover" : True,
|
||||||
}
|
}
|
||||||
def __init__(self, pi_creature, **kwargs):
|
def __init__(self, pi_creature, **kwargs):
|
||||||
assert hasattr(pi_creature, "bubble")
|
assert hasattr(pi_creature, "bubble")
|
||||||
@ -346,9 +347,12 @@ class RemovePiCreatureBubble(AnimationGroup):
|
|||||||
FadeOut(pi_creature.bubble.content),
|
FadeOut(pi_creature.bubble.content),
|
||||||
)
|
)
|
||||||
|
|
||||||
def clean_up(self):
|
def clean_up(self, surrounding_scene = None):
|
||||||
AnimationGroup.clean_up(self)
|
AnimationGroup.clean_up(self, surrounding_scene)
|
||||||
self.pi_creature.bubble = None
|
self.pi_creature.bubble = None
|
||||||
|
if surrounding_scene is not None:
|
||||||
|
surrounding_scene.add(self.pi_creature)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PiCreatureScene(Scene):
|
class PiCreatureScene(Scene):
|
||||||
|
Reference in New Issue
Block a user