facebookresearch/ai4animationpy
GitHub: facebookresearch/ai4animationpy
将原本依赖 Unity 的 AI 角色动画框架完整迁移到 Python,在统一的 PyTorch/NumPy 环境中实现从动捕数据处理、神经网络训练到实时渲染的全流程。
Stars: 1561 | Forks: 189
# AI4AnimationPy
**一个使用神经网络进行 AI 驱动角色动画的 Python 框架。**
由 [Paul Starke](https://github.com/paulstarke) 和 [Sebastian Starke](https://github.com/sebastianstarke) 开发
[](LICENSE)
[](https://www.python.org/downloads/release/python-3120/)
[](https://facebookresearch.github.io/ai4animationpy/)
AI4AnimationPy 实现了通过神经网络进行角色动画,并为动作捕捉处理、训练与推理以及动画工程提供了有用的工具。该框架将 [AI4Animation](https://github.com/sebastianstarke/AI4Animation) 引入 Python —— 移除了数据处理、特征提取、推理和后处理对 Unity 的依赖,同时保留了类似游戏引擎风格的架构(ECS、更新循环、渲染管线)。所有功能均在 **NumPy** 或 **PyTorch** 上运行,因此训练、推理和可视化可以在一个统一的环境中进行。
## 入门指南
请查阅完整文档以获取安装说明以及使用 AI4AnimationPy 的其他实用技巧:
[**完整文档**](https://facebookresearch.github.io/ai4animationpy/)
- [安装说明](https://facebookresearch.github.io/ai4animationpy/getting-started/installation/)
- [快速入门指南](https://facebookresearch.github.io/ai4animationpy/getting-started/quickstart/)
- [架构概览](https://facebookresearch.github.io/ai4animationpy/architecture/overview/)
- [演示程序](https://facebookresearch.github.io/ai4animationpy/tutorials/demos/)
- [API 参考](https://facebookresearch.github.io/ai4animationpy/api/actor/)
## 架构
该框架可以通过以下三种方式执行:1) 使用内置渲染管线(“Standalone”),2) 无头模式(“Headless”),或 3) 手动执行(“Manual”),后者允许在本地或服务器端远程运行代码。
Standalone 和 Headless 模式都会自动调用更新回调,而 Manual 模式允许手动控制调用更新循环的频率和时间间隔。
## 交互式演示
| | |
|---|---|
|  |  |
| 在 style100 上训练的 **Stylized Biped Locomotion Controller** | **Quadruped Locomotion Controller** —— 带有步态转换和动作姿势的交互式狗运动 |
|  |  |
| 具有交互式模型训练可视化的 **Future Motion Anticipation** | **ECS** —— 实体层次结构与组件系统 |
|  |  |
| **Inverse Kinematics** —— 实时 IK 求解 | **Motion Capture Import** —— GLB/FBX/BVH/NPZ 加载 |
|  | |
| **Motion Editor** —— 动画浏览和特征可视化| |
## 为什么选择 AI4AnimationPy?
AI 驱动的角色动画研究过去常常需要兼顾多个互不关联的工具 —— 模型研究在 Python 中进行,而可视化则需要专门的软件,连接两者涉及自定义的通信管道。这增加了摩擦,减慢了迭代速度,并使得即时验证结果变得困难。
[AI4Animation](https://github.com/sebastianstarke/AI4Animation) 中的训练管道严重依赖于 Unity。虽然这有利于可视化和运行时推理,但与 PyTorch 的通信必须通过 ONNX 或数据流进行,导致整个工作流脱节。AI4AnimationPy 通过将所有功能融合到一个仅运行在 NumPy/PyTorch 上的统一框架中解决了这一问题:
- 在动作捕捉数据上**训练神经网络**
- **即时可视化**,无需切换工具 —— 训练、推理和渲染共享同一后端
- **无头运行**,用于服务器端训练,并支持可选的独立模式
- 通过模块化的 ECS 设计**轻松扩展**新功能,如几何、音频、视觉或物理
| | AI4AnimationPy | AI4Animation (Unity) |
|---|---|---|
| **训练数据生成** (20h 动作捕捉) | < 5 分钟 | > 4 小时 |
| 新实验的**设置时间** | ~10 分钟 | > 4 小时 |
| 训练期间**可视化**输入/输出 | 内置 | 需要流式传输 |
| 推理过程中的**反向传播** | ✅ 支持 | ❌ 不可能 |
| **量化** | 完整的 PyTorch 支持 | 仅限于 ONNX |
| **可视化** | 可选的内置渲染器 | 内置 |
## 功能特性
| | 特性 | 状态 |
|---|---------|:------:|
| 🧩 | **Entity-Component-System** —— 带有生命周期管理的模块化架构 | ✅ |
| 🔄 | **Update Loop** —— 游戏引擎风格的回调 (Update / Draw / GUI) | ✅ |
| 📐 | **Math Library** —— 矢量化 FK、四元数、轴角、矩阵、镜像 | ✅ |
| 🧠 | **Neural Networks** —— MLP、Autoencoder、Codebook Matching 及训练实用工具 | ✅ |
| 🖥️ | **Real-time Renderer** —— 延迟着色、阴影贴图、SSAO、泛光、FXAA | ✅ |
| 💀 | **Skinned Mesh Rendering** —— GPU 加速的骨骼网格渲染 | ✅ |
| 🦴 | **Inverse Kinematics** —— 用于实时 IK 的 FABRIK 求解器 | ✅ |
| 🎬 | **Animation Modules** —— 关节接触、根节点与关节轨迹 | ✅ |
| 🎥 | **Camera System** —— 自由、固定、第三人称、轨道模式及平滑混合 | ✅ |
| 📦 | **Motion Import** —— GLB、FBX、BVH | ✅ |
| ⚡ | **Execution Modes** —— Standalone、Headless、Manual | ✅ |
| 🏗️ | 物理模拟 (刚体 / 碰撞) | 🔜 |
| 🛤️ | 路径规划和样条工具 | 🔜 |
| 🔊 | 音频支持 | 🔜 |
## Motion Capture 导入
该框架支持从 **GLB**、**FBX** 和 **BVH** 文件导入网格、蒙皮和动画数据。内部运动格式为 `.npz`,存储每帧每个骨骼关节的 3D 位置和 4D 四元数。
```
from ai4animation import Motion
motion = Motion.LoadFromGLB("character.glb")
motion = Motion.LoadFromFBX("character.fbx")
motion = Motion.LoadFromBVH("character.bvh", scale=0.01)
motion.SaveToNPZ("character")
```
使用内置的 CLI 批量转换整个目录:
```
convert --input_dir path/to/motions --output_dir path/to/output
```
有关设置的详细信息,请参阅[加载运动数据](https://facebookresearch.github.io/ai4animationpy/getting-started/quickstart/#importing-motion-data)指南。
| 数据集 | 角色 | 下载 | |---------|-----------|----------| | [Cranberry](https://github.com/sebastianstarke/AI4Animation) | Cranberry | [FBX & GLB](https://starke-consult.de/AI4Animation/SIGGRAPH_2024/Cranberry_Dataset.zip) | | [100Style retargeted](https://github.com/orangeduck/100style-retarget) | Geno | [BVH](https://theorangeduck.com/media/uploads/Geno/100style-retarget/bvh.zip) / [FBX](https://theorangeduck.com/media/uploads/Geno/100style-retarget/fbx.zip) | | [LaFan](https://github.com/ubisoft/ubisoft-laforge-animation-dataset) | Ubisoft LaFan | [BVH](https://github.com/ubisoft/ubisoft-laforge-animation-dataset/blob/master/lafan1/lafan1.zip) | | [LaFan resolved](https://github.com/orangeduck/lafan1-resolved) | Geno | [BVH](https://theorangeduck.com/media/uploads/Geno/lafan1-resolved/bvh.zip) / [FBX](https://theorangeduck.com/media/uploads/Geno/lafan1-resolved/fbx.zip) | | [ZeroEggs retargeted](https://github.com/orangeduck/zeroeggs-retarget) | Geno | [BVH](https://theorangeduck.com/media/uploads/Geno/zeroeggs-retarget/bvh.zip) / [FBX](https://theorangeduck.com/media/uploads/Geno/zeroeggs-retarget/fbx.zip) | | [Motorica retargeted](https://github.com/orangeduck/motorica-retarget) | Geno | [BVH](https://theorangeduck.com/media/uploads/Geno/motorica-retarget/bvh.zip) / [FBX](https://theorangeduck.com/media/uploads/Geno/motorica-retarget/fbx.zip) | | [NSM](https://github.com/sebastianstarke/AI4Animation/tree/master/AI4Animation/SIGGRAPH_Asia_2019) | Anubis | [BVH](https://starke-consult.de/AI4Animation/SIGGRAPH_Asia_2019/MotionCapture.zip) | | [MANN](https://github.com/sebastianstarke/AI4Animation/tree/master/AI4Animation/SIGGRAPH_2018) | Dog | [BVH](https://starke-consult.de/AI4Animation/SIGGRAPH_2018/MotionCapture.zip) | ## 许可证 AI4AnimationPy 采用 [CC BY-NC 4.0 许可证](LICENSE) 授权。
标签:3D动画, AI, Apex, ECS, Mutation, NumPy, Python, PyTorch, Terraform, 人工智能, 凭据扫描, 动作捕捉, 动画生成, 可视化, 开源框架, 持续集成, 推理, 数字人, 无后门, 机器学习, 模型训练, 深度学习, 游戏引擎, 用户模式Hook绕过, 神经网络, 自动化代码审查, 虚拟角色, 角色动画, 计算机图形学, 计算机视觉, 逆向工具, 骨骼动画