Communitygithub.com

aminghaseminia/manim-animation

使用 Manim Community 生成数学、科学和技术动画——包括方程、证明、图形、坐标系、几何、算法、数据结构以及精确的图表变换。适用于强调数学关系正确性的场景,例如教育讲解、研究或会议视觉展示,以及需要每个元素精确定位的动画推导。涵盖使用 uv 安装、场景设计、LaTeX/MathTex、相机和 3D 场景、渲染质量预设以及与其他工具的合成。

manim-animation 是什么?

该技能为 AI 智能体提供了一个全面的 Manim 社区版动画引擎使用指南。Manim 是一个 Python 动画引擎,专注于生成精确、可解释的数学、科学和技术视频。其核心优势在于能够将公式、图形和构造作为数学上定义的对象进行动画化,而非设计工具中的近似表示。技能详细介绍了基于 uv 的隔离式安装流程,以及在不同平台(Linux/macOS/Windows)上所需的依赖项。它提供了完整的渲染命令集,涵盖了从低质量快速预览到 4K 生产级输出的各种预设。在场景设计方面,该技能强调“一个场景一个概念”的原则,并提供了一系列设计规则,如限制相机移动、保持标签与对象绑定、合理使用变换和淡入淡出效果。此外,它还提供了场景组合模板、导出和交接指南(包括透明背景支持和与其他工具如 Remotion 的组合策略),以及一份常见的故障排查表。该参考资料旨在确保生成动画的过程中避免常见的数学和布局错误,并验证最终输出的正确性。该技能适用于 Claude Code、Cursor 等支持智能体工具的代码辅助环境。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/aminghaseminia/blender-animation-skill/tree/HEAD/skills/manim-animation

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Manim 动画 —— 数学与技术视频

Manim 是一个用于解释性视觉效果的 Python 动画引擎。其优势在于精确性:公式、图形或构造可以作为数学上定义的对象进行动画化,而不是设计工具中的近似值。

阅读 references/MANIM-PLAYBOOK.md 获取模式与代码。根据已安装版本验证参数:https://docs.manim.community/en/stable/

1. 何时选择 Manim

在以下情况选择 Manim:

  • 方程、符号或证明是主题。
  • 坐标系、图形、向量或几何构造必须精确。
  • 算法、数据结构或过程需要逐步的视觉解释。
  • 标签必须与数学对象对齐,而非手动放置的帧位置。
  • 风格应克制且图表化,而非电影化。

在以下情况不要选择 Manim:电影级 3D、品牌宣传片、动态图形排版或交互式交付物。这些属于 Blender、Remotion 或 Web 图形的领域。

2. 安装(隔离、可复现)

uv --version                     # 如果缺少 uv,先安装
uv init --python 3.12 manim-project
cd manim-project
uv add manim
uv run manim --version

Linux 通常需要本地库:

sudo apt update
sudo apt install build-essential python3-dev pkg-config libcairo2-dev libpango1.0-dev ffmpeg
sudo apt install texlive texlive-latex-extra texlive-fonts-recommended   # 用于 MathTex/Tex

macOS:brew install cairo pango pkg-config ffmpeg,如果使用 MathTex 还需要 TeX 发行版(如 MacTeX)。 Windows:安装 FFmpeg 和 MiKTeX/TeX Live;可能需要 Microsoft C++ Build Tools 来构建 Cairo/Pango wheel 包。

验证:

uv run manim --version
uv run python -c "import manim; print(manim.__version__)"

如果已有项目环境,请勿将 Manim 安装到系统 Python 中。在项目 README 中记录版本号。

3. 渲染命令

# 低质量预览(快速)
uv run manim -pql scenes/explain.py ExplainScene

# 中等质量
uv run manim -qm scenes/explain.py ExplainScene

# 高质量 / 生产级
uv run manim -qh scenes/explain.py ExplainScene

# 4K
uv run manim -qk scenes/explain.py ExplainScene

# 透明背景
uv run manim -qh -t scenes/explain.py ExplainScene

# 特定区间
uv run manim -qh scenes/explain.py ExplainScene -n 12,20

质量预设:-ql 480p15,-qm 720p30,-qh 1080p60,-qk 2160p60。以已安装版本为准。输出文件位于 media/videos/<文件>/<质量>/。

ffprobe -v error -show_entries stream=width,height,r_frame_rate,duration \
  -of json media/videos/explain/1080p60/ExplainScene.mp4

4. 场景设计规则

  • 每个场景一个概念。 拆分为 Scene 子类;通过拼接组合较长的视频,而非在一个巨大的场景中完成。
  • 调色板和字体只需设置一次,放在一个模块(theme.py)中并导入,而不是重复写十六进制值。
  • 限制相机移动。 Manim 的 MovingCameraScene 功能强大且容易被滥用;仅在需要揭示观看者无法直接看到的结构时才进行缩放。
  • 尊重时长。 一个 3 分钟阅读效果很好的公式推导,在 40 秒内会显得仓促。根据阅读速度计算停留时间,而非直觉。
  • 保持标签附着 在其所描述的对象上(使用 Tex + next_to),这样后续布局更改不会在静默中破坏对齐。
  • 使用 Transform/ReplacementTransform 表示含义转变,使用 FadeIn/FadeOut 表示存在性变化。变形无关的形状会混淆观众。
  • 不要独立地逐个动画化每个元素。 使用 VGroup 进行分组,并有目的地错开动画。

5. 场景组合模板

from manim import *

class ExplainScene(Scene):
    def construct(self):
        title = Text("为什么导数是极限", font="Inter").scale(0.7)
        self.play(Write(title), run_time=1.2)
        self.wait(0.6)
        self.play(title.animate.to_edge(UP).scale(0.8), run_time=0.9)

        formula = MathTex(r"f'(x) = \lim_{h \to 0} \frac{f(x+h)-f(x)}{h}")
        formula.scale(1.2)
        self.play(Write(formula), run_time=1.6)
        self.wait(1.2)

        self.play(formula.animate.set_color_by_tex(r"h \to 0", YELLOW), run_time=0.8)
        self.wait(1.5)

6. 导出与交接

  • -qh 以高码率生成 1080p60 视频;建议为交付内容重新编码,而不是直接提供中间文件。
  • 透明背景:-t 会生成带 alpha 通道的 .mov 文件(或配合 --format=png 生成 PNG 序列)。在合成前,通过棋盘格背景验证 alpha 通道。
  • 要将 Manim 与 Remotion/Blender 结合:匹配帧率和分辨率,然后在 FFmpeg 或 Remotion 中进行组装。Manim 在 -qh 下默认为 60 FPS;可以更改 config.frame_rate 或有目的地进行转换。
  • 对于品牌化的片头/片尾和字幕,建议将 Manim 场景渲染干净后在 Remotion 中合成——不要强行使用 Manim 的排版系统进行品牌布局。

7. 验证

  • 在渲染高质量版本之前,先观看低质量渲染版本;数学错误在 480p 下也能被发现。
  • 检查没有公式被画面边缘裁剪,没有标签重叠。
  • 验证 LaTeX 已编译成功,没有静默回退(注意控制台中的红色文本警告)。
  • 使用 ffprobe 确认最终时长和帧率。
  • 逐字朗读每个符号并对照预期的数学表达式;符号翻转是正确性问题,而非风格选择。

8. 常见故障

症状原因修复方法
latex: command not found没有 TeX 发行版安装 TeX Live/MiKTeX,或使用 Text 替代 MathTex
Cairo/Pango 构建错误缺少本地库安装上述列出的开发包
公式渲染为红色错误文本LaTeX 语法错误或缺少包检查控制台;向 TexTemplate 添加包
所有内容看起来模糊使用了低质量预设为最终版本使用 -qh/-qk 渲染
希腊文/阿拉伯文显示异常字体缺少字形或排版支持使用支持排版的字体,测试静态帧,或将文本栅格化
渲染非常慢60 FPS + 4K + 复杂路径在 -ql 下预览,简化路径,拆分场景
透明度丢失格式错误使用 -t 并选择支持 alpha 的容器格式;仔细验证

9. 官方参考资料

Individual skills in this repo

This repo contains 5 individual skills — each has its own dedicated page.

aminghaseminia/blender-animation

Build 3D animations in Blender headlessly with Python (bpy) — scene setup, materials, lighting, camera rigs, keyframe and procedural animation, Geometry Nodes, particles and simulations, EEVEE/Cycles rendering, and MP4/PNG-sequence output. Triggers include "animate in Blender", "blender python", "bpy script", "3D logo animation", "cinematic render", "particle animation", "product turntable", "render an .blend", "blender headless", or any 3D scene, camera move, or motion graphics job that needs real geometry, light, and depth.

aminghaseminia/motion-design

Art direction and motion-design craft for animation projects — creative briefs, storyboards, style frames, colour and type systems, composition, timing and easing, transition vocabulary, sound direction, accessibility, and right-to-left (Persian/Arabic) typography. Use before building scenes, when a video looks amateur or generic, when choosing palette and fonts, when a request says "make it feel premium/cinematic/modern", or when text, rhythm, or hierarchy is not landing. Tool-agnostic; pairs with blender-animation, remotion-motion-graphics, and manim-animation.

aminghaseminia/motion-studio

End-to-end animation and motion-graphics production from a natural-language brief. Routes work to Blender (3D), Remotion (2D/typography/data), Manim (math/science), motion-design craft, and FFmpeg (encode/composite/validate), then builds, previews, inspects, revises, and delivers an editable project plus final MP4. Use for any request to "make an animation", "create a video", "animate this logo", "render a motion graphic", "vibe-code an animation", or produce a promo, explainer, title sequence, or social clip.

aminghaseminia/remotion-motion-graphics

Create 2D motion graphics as code with Remotion and React — kinetic typography, logo reveals, explainers, animated charts, UI demos, social clips, subtitles, and data-driven or batch-rendered video. Use when the deliverable is primarily layout, text, and 2D graphics rather than real 3D; when a video must be generated from data or a template; or when a Blender 3D pass needs titles, captions, and transitions composited on top. Covers project setup, deterministic frame-based animation, easing, typography, audio, rendering, and licensing.

aminghaseminia/video-composition

Assemble, mix, normalize, and validate finished video from Blender, Remotion, Manim, screen capture, and audio sources using FFmpeg and FFprobe — concatenation, overlays, alpha compositing, subtitle burn-in, loudness, fades, speed ramps, GIF/thumbnail export, and platform-specific encodes. Use when combining scenes, fixing mismatched resolutions or frame rates, adding music/voice-over, burning captions, converting formats, or verifying that a rendered file is actually correct.

相关技能