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

Manim v0.17.03相机聚焦动画报错:'Camera'无'frame'属性

问题解决:Manim v0.17.03中相机操作报错AttributeError

错误原因

Manim v0.17.x版本对相机API做了调整,Camera类不再包含frame属性,旧版本中通过camera.frame实现的相机动画逻辑需要改用新的API。

修正后的代码

场景类代码

class CameraFocusing(Scene):
    def construct(self):
        s = Square(color=YELLOW).move_to(np.array([-4,0,0]))
        c = Circle().move_to(np.array([4,0,0]))
        self.add(s,c)
        self.wait(3)
        
        # 瞬间将相机聚焦到正方形中心
        self.camera.frame_center = s.get_center()
        self.wait(3)
        
        # 动画将相机移动到圆形中心(替代原frame.animate.shift逻辑)
        self.play(self.camera.animate.set_frame_center(c.get_center()), run_time=2)
        self.wait(2)

主配置代码(去除重复配置项)

if __name__ == "__main__":
    config.pixel_height = 720
    config.pixel_width = 1280
    config.frame_height = 7.0
    config.frame_width = 7.0
    config.frame_center = [-4, 0, 0]
    config.background_color = BLACK
    config.save_as_gif = True
    config.quality = "medium"
    config.media_height = 7.0
    config.media_width = 7.0

    scene = CameraFocusing()
    scene.render()

额外说明

  • 如果需要实现自定义偏移的相机动画,也可以直接对frame_center做属性动画,比如:
    # 动画将相机向右偏移8个单位
    self.play(self.camera.animate.frame_center.shift(8 * RIGHT), run_time=2)
    
  • Manim v0.17+中,相机的核心控制属性包括frame_center(位置)、frame_height(视野高度)、frame_width(视野宽度),直接操作这些属性或通过animate修饰即可实现相机的静态调整与动画效果。

内容的提问来源于stack exchange,提问作者Mukul Sharma

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 18:46:16