给 AI 智能体一个模型想法。引导它,让它构建出来,然后得到一个 LDraw LEGO© 模型。

构建过程结束后你会得到:

  • 它的源代码,使用LDraw 语言。
  • 不同视图:3D 查看器、3D 播放器、VR 交互(Meta Quest 3)、图像……
  • Blender 可编辑的glTF 文件,格式为.glb,元信息作为 Blender 的自定义属性。
  • 聊天记录以及智能体思考过程。
  • 以及更多…… 👌

看看这个视频:

安装

重要

工具由智能体使用,以便查找合适的零件和示例模型利用jev-rerank(我也是作者)。这是一个语义搜索工具带有重排序由TypeSafe的Jev System OneAI 模型提供支持。

  • 如果你有 TypeSafe API key(TYPESAFE_API_KEY),在 web 应用的Settings部分设置它的值。
  • 如果你没有,重排序搜索将无法工作,智能体将退而求其次使用FTS(全文搜索)策略作为后备方案,这可能会(也许)产生更差的模型。

运行ldraw-nova作为 web 应用,使用 Docker。你需要Git和Docker。

这个 web 应用将以 Docker 方式运行,而构建 Docker 镜像需要两个同级仓库:

1. 克隆两个仓库并排放置,在相同的 tag,以便它们协同工作:

git clone --branch v0.6.0 https://github.com/anteloc/ldraw-nova.git
git clone --branch v0.6.0 https://github.com/anteloc/ldraw-nova-docker.git

2. 构建Docker 镜像。首次构建需要一段时间,并需要约 5 GB 磁盘空间:

cd ldraw-nova-docker
docker compose build

3. 启动应用:

docker compose up -d

4. 打开它在你的浏览器中:

  • https://localhost:8443:Meta Quest 3 上的 VR 需要它。证书是自签名的,所以第一次接受浏览器的警告。
  • http://localhost:8765:纯 HTTP,没有证书警告。如果自签名证书造成麻烦就用它。VR 无法通过它工作。

你网络上的其他设备可以通过你电脑的 IP 访问该应用,而不是localhost,例如https://192.168.1.20:8443从 Quest 3。该应用没有登录,所以只在信任的网络上运行它。

停止它:

docker compose down

为什么要做这一切?

嗯,总结一下:我这样做是为了得到能够设计可构建的物理事物的智能体式 LLM!

找到LDraw,一种汇编语言(双关语!😜),它同时简单,底层,并且可执行以便生成 3D CAD 模型,让我有了实验的想法,同时使用ChatGPT和Claude来尝试让它们用 LDraw 编码,就像它们对其他编程语言所做的那样。

令我惊讶的是,尽管这门语言非常侧重于数学(部件旋转、定位……),而 LLM 通常不擅长这些,智能体在初步测试中却表现得相当好,后续项目也取得了不错的结果,但永远不够以认定生成的模型是正确的:

这三次尝试,以及相当多的其他实验,让我得出以下结论:

💡 结论 1:存在一条通往几何数学的最小阻力路径对智能体而言,即:

  • 给智能体提供工具来生成 LDraw 源文件,就能绕开(邪恶的!)几何数学
  • ……因为它们在生成方面表现得好得多Python 代码这些代码能产生数学
  • ……而不是自己直接产生数学!

💡 结论 2:

  • 智能体在学习时往往表现得更好当从 Python代码中学习这些代码能产生模型
  • ……而不是从模型本身学习(又是 LDraw 那邪恶的几何……)

然后,唯一剩下的事 🤔就是创建一个基于 Python 的工具,具备所需的图元、动词、构造性词汇……这样智能体就能通过示例学习并自行做类似的事情。

事实证明这真的很难做对,即使是 vibe coding 也一样……直到GPT-6 Astra和Claude Opus 5.5到来……然后用 vibe coding 把它做对了!🚀🚀🚀

工作原理

ldraw-nova为智能体提供用真实 LDraw 部件设计模型所需的工具、示例和指令。

流程如下:

  1. 智能体接收一个提示词。
  2. 阅读 instructions.md及相关文档,以了解LDraw 语言和 LEGO© 模型搭建。
  3. 规划如何构建模型:所需部件、要创建的子模型、美学……
  4. 迭代地:
    1. 从模型/子模型渲染图像
    2. 检查它们,调整定位、美学……然后回到渲染
  5. ……直到它认为模型已完成并准备好交付!

所提供的工具帮助智能体:

  • 寻找合适的部件。
  • 此外,示例模型和子模型作为起点。
  • 碰撞和间隙检测以正确放置部件。
  • 无头渲染以检查当前结果。
  • 以及更多……

智能体实际上并不是从放置部件开始的,除了诸如原型制作和通过修改已有示例模型来学习之类的情况。

它生成模型的方式更像是:

  • 收集the required information, from experimental results, docs and planning.
  • Buildsone or moreplans, that fully describe the model and submodels, including its geometry, like e.g.atlas-crane.plan.json
  • And with that plan, it creates one or moregenerator scriptslike e.g.generate.py
  • ... that when executed,produce LDraw sourcefile(s), a very specialized3D CAD language.
  • ... like e.g.atlas-crane.mpd

Tosummarize, this is like:

  • anagentcreating agenerator
  • ... that produces a3D model
  • ... in anassembly languagenamedLDraw🤯

Acompilerof sorts, so to say 🤓

flowchart TD
    agent([agent]) -- produces --> plan[plan.json]
    plan -- interpretation --> gen[generator.py]
    gen -- execution --> model[model.mpd]

Loading

Agent's informational sources

These are some of the guides and references given to the agent in order to make it a builder:

I want to… Read…
Ask an agent to generate a model Agent instructions
Improve shape, colour and detail Visual design guide
Build vehicles Vehicle workflowandexamples
Build advanced spaceships Spaceship workflowandatlas
Learn a submodel and grow an atlas Build-manual workflow
Build Technic structures Structural workflowandexamples
Build with mechanisms Mechanism workflowandbuild manuals
Find parts and reusable constructions Reference discoveryandreference atlas
Organize a large model Module workflowandCopper Lane example
Understand connections and checks Geometry,snappingandvalidation
Look up a command or file-format rule Tool referenceandLDraw rules

Development

Being this afirst release, there are quite some things that still require some work:

  • VR on Meta Quest 3:model handling hasmany issues, performance issues.
  • Adapt for low-end agents:adapt current tooling, docs and instructions in order to improve usage by low-end models like e.g. Luna, Haiku, etc.
  • Expensive generation:currently, onlyexpensive, high-end models, are currently capable of generating large-sized and correct models.
  • Improve efficiency:generative process is currently slow.
  • Add and improvemoremodel families:
    • Humans and animals: minifigs
    • Technic models: machines, engines...
    • Spaceships: generated models are not very good
  • Building models from manuals:it partially works, better if page manuals are given as images.
  • Fine-grained inspection:for inspecting submodels and their step-by-step building processes.

Contributing

COMING SOON

Acknowledgements

I'd like to thank the following:

  • LDraw 社区
  • LDView的 Travis Cobbs(@tcobbs)及贡献者。
  • LeoCAD的 Leonardo Zide(@leozide)及贡献者。
  • LDCad和 Shadow Library,Roland Melkert。
  • ldraw.rs的 Park Joon-Kyu(@segfault87)及贡献者。
  • pyldraw3的 Harold Martin(@hbmartin)及贡献者。

……并感谢所有众多其他 LDraw 创作者!

注意:在这项工作中,我使用了许多来自众多来源的 LDraw 模型、库、工具、文档……

有很多了不起的人为此慷慨贡献,甚至数十年,通过慷慨捐赠他们最出色的作品给公共领域和开源社区。

如果你认为你应被列入本节,请给我发邮件!

商标

LEGO(R)是LEGO Group的商标,该公司不赞助、授权或认可本软件。