You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Manim制作的3Blue1Brown风格数学视频中添加并动画CharCreature?

在Manim中添加3Blue1Brown风格的CharCreature及自定义角色

一、添加现有CharCreature(以Omega Creature为例)

Manim内置了OmegaCreature这类现成的CharCreature,直接导入使用即可:

1. 导入依赖模块

from manim import *
from manim.mobject.characters import OmegaCreature

2. 在场景中创建并添加角色

class OmegaDemo(Scene):
    def construct(self):
        # 创建Omega角色实例
        omega = OmegaCreature()
        # 调整角色位置(可选)
        omega.move_to(RIGHT * 2)
        # 添加到场景
        self.add(omega)
        self.wait()

二、为CharCreature添加动画

CharCreature自带专属动画方法,也可结合Manim标准动画实现丰富效果:

1. 角色视线跟随

让角色看向指定对象或坐标:

class CreatureLookAt(Scene):
    def construct(self):
        omega = OmegaCreature().move_to(RIGHT * 2)
        circle = Circle(color=RED).move_to(LEFT * 2)
        self.add(omega, circle)
        
        # 动画:Omega看向圆形
        self.play(omega.animate.look_at(circle), run_time=0.5)
        self.wait()

2. 眨眼动画

调用内置的blink()方法实现自然眨眼:

class CreatureBlink(Scene):
    def construct(self):
        omega = OmegaCreature()
        self.add(omega)
        
        # 单次眨眼
        self.play(omega.blink(), run_time=0.3)
        self.wait()
        
        # 连续眨眼
        for _ in range(3):
            self.play(omega.blink(), run_time=0.2)
            self.wait(0.5)

3. 对话气泡配合

结合SpeechBubble实现角色说话效果:

class CreatureSpeak(Scene):
    def construct(self):
        omega = OmegaCreature().move_to(LEFT * 1.5)
        self.add(omega)
        
        # 创建对话气泡,关联Omega角色
        bubble = SpeechBubble(omega, text="这是一个数学科普视频!")
        # 动画显示气泡
        self.play(Create(bubble))
        self.wait(2)
        # 隐藏气泡
        self.play(FadeOut(bubble))

4. 标准动画组合

使用Manim通用动画(移动、缩放、旋转等)自定义角色动作:

class CreatureBasicAnim(Scene):
    def construct(self):
        omega = OmegaCreature()
        self.add(omega)
        
        # 缩放+移动组合动画
        self.play(omega.animate.scale(1.5).move_to(RIGHT * 3), run_time=1)
        # 旋转动画
        self.play(omega.animate.rotate(PI/4), run_time=0.5)
        self.wait()

三、自定义CharCreature角色

通过继承CharCreature基类,重写init_body方法来创建专属角色:

示例:自定义方块角色

from manim import *
from manim.mobject.characters import CharCreature

class SquareCreature(CharCreature):
    def init_body(self):
        # 构建角色身体部件
        body = Square(color=GREEN, fill_opacity=1, side_length=1.5)
        # 眼睛
        left_eye = Circle(radius=0.15, color=WHITE, fill_opacity=1).move_to(body.get_left() + UP * 0.3)
        right_eye = left_eye.copy().move_to(body.get_right() + UP * 0.3)
        # 瞳孔
        left_pupil = Circle(radius=0.08, color=BLACK, fill_opacity=1).move_to(left_eye.get_center())
        right_pupil = left_pupil.copy().move_to(right_eye.get_center())
        # 嘴巴
        mouth = Arc(radius=0.3, start_angle=PI, angle=-PI, color=BLACK).move_to(body.get_bottom() + UP * 0.2)
        
        # 组合所有部件为角色身体
        self.body = VGroup(body, left_eye, right_eye, left_pupil, right_pupil, mouth)
        self.add(self.body)

# 使用自定义角色
class CustomCreatureDemo(Scene):
    def construct(self):
        square_creature = SquareCreature()
        self.add(square_creature)
        
        # 为自定义角色添加动画
        self.play(square_creature.animate.look_at(UP), run_time=0.5)
        self.play(square_creature.blink(), run_time=0.3)
        self.wait()

自定义要点

  • 所有角色部件需组合到self.body中,确保CharCreature的内置动画方法(如look_at、blink)能正常工作
  • 可根据需求添加更多细节(比如手臂、表情变化),只需在init_body中扩展VGroup的内容
  • 若需要自定义眼睛动画逻辑,可重写look_at或blink方法

内容的提问来源于stack exchange,提问作者sigma L K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 19:42:44