Blender 仿真
Blender 仿真能力位于 components/blender-simulation,并且刻意独立于 SOP 转换器流水线。转换器仍然只负责写出 04-requirements.json 等 JSON 产物;只有调用方显式导入 Blender 组件时,仿真代码才会消费这些产物。
Python 引擎
需要生成 Blender 脚本或渲染视频时,先安装独立 Python 引擎:
python -m pip install -e components/blender-simulation/py-engine
然后从 TypeScript 调用组件包装器。Node.js 层只负责构造 CLI 参数、启动 Python 模块,并解析 Python stderr 中的结构化 JSON 错误:
import { runBlenderSimulation } from "./components/blender-simulation/src/index.js";
await runBlenderSimulation({
requirementsPath: "out/04-requirements.json",
scriptOut: "out/blender-simulation.py",
render: {
outputPath: "out/e2e_blender_simulation.mp4",
fps: 12,
resolution: { x: 320, y: 240 }
}
});
也可以使用组件级 CLI 包装器:
npx tsx components/blender-simulation/scripts/run-simulation.ts out/04-requirements.json --script-out out/blender-simulation.py --render-output out/e2e_blender_simulation.mp4 --fps 12 --resolution 320x240
生成的 Python 会配置 Blender 自带的视频输出,先设置 image_settings.media_type = 'VIDEO',再设置 image_settings.file_format = 'FFMPEG',随后配置 scene.render.ffmpeg 并调用 bpy.ops.render.render(animation=True)。这个路径会由 Blender 直接写出 MP4,不再依赖外部系统 ffmpeg 编码步骤。
边界
不要从 src/pipeline 导入 Blender 代码。Blender 渲染、资产布局、动画宏和原生视频输出都应保留在 components/blender-simulation/py-engine 内,原 CLI 转换器继续专注于 SOP 到结构化需求的转换。