mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Have animation group collect parts as a VGroup if it can
This commit is contained in:
parent
e9333a908c
commit
bf2a609246
2 changed files with 14 additions and 10 deletions
|
@ -6,6 +6,8 @@ from manimlib.animation.animation import Animation
|
|||
from manimlib.animation.animation import prepare_animation
|
||||
from manimlib.mobject.mobject import _AnimationBuilder
|
||||
from manimlib.mobject.mobject import Group
|
||||
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||
from manimlib.utils.bezier import integer_interpolate
|
||||
from manimlib.utils.bezier import interpolate
|
||||
from manimlib.utils.iterables import remove_list_redundancies
|
||||
|
@ -14,7 +16,7 @@ from manimlib.utils.simple_functions import clip
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Callable
|
||||
from typing import Callable, Optional
|
||||
|
||||
from manimlib.mobject.mobject import Mobject
|
||||
from manimlib.scene.scene import Scene
|
||||
|
@ -28,8 +30,8 @@ class AnimationGroup(Animation):
|
|||
*animations: Animation | _AnimationBuilder,
|
||||
run_time: float = -1, # If negative, default to sum of inputed animation runtimes
|
||||
lag_ratio: float = 0.0,
|
||||
group: Mobject | None = None,
|
||||
group_type: type = Group,
|
||||
group: Optional[Mobject] = None,
|
||||
group_type: Optional[type] = None,
|
||||
**kwargs
|
||||
):
|
||||
self.animations = [prepare_animation(anim) for anim in animations]
|
||||
|
@ -37,11 +39,15 @@ class AnimationGroup(Animation):
|
|||
self.max_end_time = max((awt[2] for awt in self.anims_with_timings), default=0)
|
||||
self.run_time = self.max_end_time if run_time < 0 else run_time
|
||||
self.lag_ratio = lag_ratio
|
||||
mobs = remove_list_redundancies([a.mobject for a in self.animations])
|
||||
if group is not None:
|
||||
self.group = group
|
||||
if self.group is None:
|
||||
self.group = group_type(*remove_list_redundancies(
|
||||
[anim.mobject for anim in self.animations]
|
||||
))
|
||||
if group_type is not None:
|
||||
self.group = group_type(*mobs)
|
||||
elif all(isinstance(anim.mobject, VMobject) for anim in animations):
|
||||
self.group = VGroup(*mobs)
|
||||
else:
|
||||
self.group = Group(*mobs)
|
||||
|
||||
super().__init__(
|
||||
self.group,
|
||||
|
|
|
@ -32,7 +32,6 @@ class TransformMatchingParts(AnimationGroup):
|
|||
mismatch_animation: type = Transform,
|
||||
run_time: float = 2,
|
||||
lag_ratio: float = 0,
|
||||
group_type: type = Group,
|
||||
**kwargs,
|
||||
):
|
||||
self.source = source
|
||||
|
@ -76,7 +75,6 @@ class TransformMatchingParts(AnimationGroup):
|
|||
*self.anims,
|
||||
run_time=run_time,
|
||||
lag_ratio=lag_ratio,
|
||||
group_type=group_type,
|
||||
)
|
||||
|
||||
def add_transform(
|
||||
|
|
Loading…
Add table
Reference in a new issue