作者将 AI 助手嵌入 Blender 侧栏,把当前对象、材质和修改器等场景快照注入上下文。插件在主线程运行模型生成的 Python,并将输出与异常回传;文中以两个 JSON 文件应对线程通信限制。
过去几个月,我一直在开发一个本地多 Agent CLI 代码生成器:planner → coder → tester → executor → reviewer,通过 Ollama 运行开放模型。它形成了完整闭环:编写代码、运行代码、测试代码,再修复代码。
它确实能用。而这恰恰就是问题所在:它解决的并不是我自己的需求。为磁盘上的文件编写代码,已经是一个有成熟解决方案的细分领域。我是在和其他所有代码生成工具竞争,而目标用户手里早就有了同类工具。
我真正每天都在做的事情是 3D。于是,这个项目转向了另一个方向:让 AI 助手住进 Blender,真正掌握处理模型的工具,而不只是一个输出代码的文本框。
这个 add-on 叫 Game Asset Assistant,面向 Blender 4.2+,以规范的扩展 zip 包形式分发。
每次请求都会携带一份精简的场景快照,注入 system prompt:
Blender 4.2.0 场景:Scene | fps=24 | units=METRIC | render=CYCLES 对象数:12
Cube [MESH] loc=(0.00, 0.00, 0.00) rot_deg=(0.0, 0.0, 0.0) scale=(1.00, 1.00, 1.00) verts=8 edges=12 faces=6 | uv=UVMap | materials=Steel | modifiers=SUBSURF 已选中:Cube 活动对象:Cube | mode=OBJECT
所以,当你问“活动对象有多少个多边形?”时,模型回答的是你场景中的那个对象,而且会直接说出它的名字。
当回复中包含一个
python block, it appears in a box with two buttons:
Run code - executes it in the current scene on the main thread, captures print() output and tracebacks, and pushes both back into the chat. That closes the loop: the model writes, Blender executes, the model sees the error and fixes it.
To Text Editor - saves it as a text datablock for manual review.
Backends
Local (Ollama, e.g. qwen2.5-coder:7b) or any OpenAI-compatible API - switchable in preferences, no code changes.
The part that broke my brain: Blender forbids threads
Here's the non-obvious bit worth the whole post.
Blender's API docs say it plainly: Python threads that outlive the script cause hard-to-diagnose crashes in Blender's own drawing code. So the obvious approach - "spawn a thread, call the LLM API, update the UI when it returns" - is off the table.
The add-on therefore never blocks and never spawns a thread. Instead:
Blender (main thread) worker process network
┌────────────────────────┐ ┌──────────────┐
│ operator appends a │commands │ │
│ JSON line ─────────────┼────────→│ worker.py │──HTTP──→ Ollama / API
│ │ │ │
│ bpy.app.timers, │events │ │
│ every 0.1s, reads new │←────────┤ │
│ lines ─────────────────┤ └──────────────┘
└────────────────────────┘
Commands are just JSON objects appended to commands.jsonl.
Events (chunk, done, error) are appended to events.jsonl.
A bpy.app.timers callback pumps events every 0.1 s - and a timer is not a thread, it's a callback Blender invokes on the main thread between frames. That's the only legal way to do background work.
Side effect: the whole add-on ships without any third-party dependency, and the protocol already has room for tool-call requests in a later phase.
What's not there yet
Being honest about the gaps:
No structured tool-calling - the model emits a code block and we exec() it
No confirmation for destructive operations (the prompt asks the model to warn; that's a request, not a guarantee)
No undo grouping - one Ctrl+Z won't roll back a whole script
UV, rigging and texturing exist only as chat advice, not as one-click tools
Scene snapshot is blind to UV islands, texel density, weights and armature pose
Roadmap
Phase What Why first
0 Richer snapshot, undo-push, destructive-op confirmation Cheap, unlocks everything after
1 Tool-calling over the JSONL channel, executed on the main thread with a registry + JSON schemas The reliability jump: from "80 lines of text that may fail" to named calls
2 Texturing: PBR material presets, texture assignment, packing, bake helpers Stable API, high daily value
3 UV: quick unwrap/pack/texel-density, seam-by-angle, and a UV diagnostics report (overlaps, density) Most repetitive work; the report lets the model read the result and propose fixes
4 Auto-rig: metarig → Rigify, auto-weights, weight validation, export checks Hardest - errors are silent, so diagnostics matter more than generation
5 One-click pipelines: GBC Prep, Char Prep, PBR Bake, Game Export Combines 2–4 into buttons
6 Teach the model: tool catalog in the prompt, domain recipes, few-shot examples Ongoing, parallel
Integration with other Blender add-ons (delegating to UV packers, for example) is on the list - but the final roadmap is still open. I'd rather ship phases 0–3 and let real usage decide what phase 4 looks like.
The plan from here
Post progress as it lands. If you're working on AI × 3D pipelines, or you've wrapped a DCC tool for an LLM - I'd love to compare notes.
Repo link in the comments.
#blender #ai #python #gamedev #3d #showdev
如果还想采取进一步措施,可以考虑屏蔽此人和/或举报滥用行为。