Retrieved article excerpt
Open article · Retrieved 2026-11-06T20:21:48.453363+00:00
# ldraw-mecha
**Give an [LDraw](https://www.ldraw.org/) LEGO© model to an AI agent, get back a Blender-animated version of it.**
The **agent** will:
- **Reverse-engineer** (infer) the **LDraw model's mechanics** from its **.mpd source code file** 🤓
- **Study** the **discovered** mechanisms.
- **Plan** the **interactions** between their different mechanical components.
- And finally, turn those **plans** into **python code for Blender**, that will:
- **Create** the required **rigs** for controlling the different mechanisms.
- **Animate** them according to **plan**! 🤯
## Installation
Note
The installation process will **install** every required tool and dependency **locally** on this project repo, in order to **avoid polluting the host OS**.
However, there is a requirement of setting several **env vars** on rc files, like e.g. `.bashrc` or `.zshrc`
The installed dependencies, like e.g. Blender, are **git-ignored** by default.
You'll need **Python 3.12+** installed.
| System | Requirements |
| --- | --- |
| **macOS** | git-lfs (`brew install git-lfs`) |
| **Linux, x86\_64** (WIP, untested) | git-lfs, Blender and LeoCAD required graphics libs |
| **Windows** (WIP, untested) | Run inside WSL2 (Ubuntu) |
Start by **cloning** the repo and **running the setup script**, pick the right one for your OS:
```
git clone https://github.com/anteloc/ldraw-mecha.git
cd ldraw-mecha
./setup-macos.sh # or ./setup-linux.sh, ./setup-win-wsl.sh
```
### Installed during setup
| Item | Version |
| --- | --- |
| uv | 0.9.3 |
| bun | 1.4.4 |
| [ldraw-annotator](https://github.com/anteloc/ldraw-annotator-nova) | 0.5.0 |
| [ldraw-xray](https://github.com/anteloc/ldraw-xray) | 0.5.0 |
| [jev-rerank](https://github.com/anteloc/jev-rerank) | 0.5.0 |
| [mpd2glb](https://github.com/anteloc/mpd2glb) | 0.9.1 |
| Blender | 5.2.3 |
| LeoCAD | 26.09 |
| LDraw parts library | latest |
At the end of the setup process, you'll get a snippet with the env vars to be **added to your shell profile** (`.bashrc`, `.zshrc`, etc.), something like e.g.:
```
# >>> ldraw-mecha (from setup-macos.sh) >>>
export LDRAW_DIR="/Users/me/ldraw-mecha/data/ldraw"
export LDRAWDIR="$LDRAW_DIR"
export BLENDER_BIN="/Users/me/ldraw-mecha/bin/Blender.app/Contents/MacOS/Blender"
export LEOCAD="/Users/me/ldraw-mecha/bin/LeoCAD.app/Contents/MacOS/LeoCAD"
export LDRAW_XRAY_CACHE="/Users/me/ldraw-mecha/.cache/ldraw-xray"
export LDRAW_ANNOTATOR_DB="/Users/me/ldraw-mecha/data/ldraw-info.db"
# export TYPESAFE_API_KEY=... # optional: Jev semantic search (jev-rerank)
# other env vars...
# <<< ldraw-mecha <<<
```
If you're on **VS Code** or a **terminal**, **restart it** in order to get an **updated env** with the newly added env vars.
## Usage
For **inspecting** and **selecting** one pre-annotated model to animate, open the **annotated models selector** by running:
```
python3 model-selector/serve.py
```
Then, take a look at the [Process](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/PROCESS.md) guide for a **step-by-step usage example**.
## Samples
Note
More samples available at: [Gallery](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/GALLERY.md)
Animations have been generated from **original models**, not from ai-generated ones.
These are **some samples** of animations by different agents, take a look at their **Summaries** for more details.
## 42043 Mercedes-Benz Arocs flatbed truck: the pneumatic crane on its own
- **Agent: Claude Sonnet 5.5**
- **Original model:** [42043-1\_Flatbed-Trailer.mpd](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/data/models-annotated/42043-1_Flatbed-Trailer.mpd)
- **Context:** The model was too large and complex for fully animating it, finally I accepted Sonnet's suggestion about animating the crane alone.
[42043 Mercedes-Benz Arocs flatbed truck](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/samples/42043-crane.png)
[▶ Video](https://anteloc.github.io/ldraw-mecha/samples/42043-crane.mp4) · [Summary](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/samples/42043-crane.md)
**Original**
[42043 Mercedes-Benz Arocs flatbed truck](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/img/42043-1_Flatbed-Trailer.png)
## 3625 Fabuland plane: take-off, flight and landing
- **Agent: Claude Sonnet 5.5**
- **Original model:** [3625-1.mpd](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/data/models-annotated/3625-1.mpd)
- **Context:** Asked for an in-place animation, to avoid the plane moving around.
[3625 Fabuland plane](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/samples/3625.png)
[▶ Video](https://anteloc.github.io/ldraw-mecha/samples/3625.mp4) · [Summary](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/samples/3625.md)
## Minifig movement catalog: ten minifigs, three moves each
- **Agent: Claude Opus 5.5**
- **Original model:** None
- **Context:** This one is actually a **generated composition**, from several **different minifigs**, to be used as a **"howto reference"** for other agents also animating minifigs.
[Minifig movement catalog](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/samples/minifigs.png)
[▶ Video](https://anteloc.github.io/ldraw-mecha/samples/minifigs.mp4) · [Summary](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/samples/minifigs.md)
## Agent's informational sources
| Need | Read |
| --- | --- |
| The whole process, step by step, on one example | [Process](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/PROCESS.md) |
| Everyday commands and recovery | [Workflow](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/workflow.md) |
| Joint types, equations, frames and fields | [Motion plan](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/motion-plan.md) |
| Source discovery and live Blender tools | [API guide](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/discovery-and-blender.md) |
| Look boards for candidates and authored joints | [Visual inspection with ldraw-xray](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/xray.md) |
| Missed contacts, rounded transforms, coverage | [Discovery quality](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/discovery-quality.md) |
| Part families, descriptions and dimensions | [Part information](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/part-information.md) |
| Testing, clearance and evidence limits | [Validation](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/validation.md) |
| Code boundaries | [Architecture](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/architecture.md) |
| Publishing a selected working example | [Curation](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/reference/curation.md) and [asset archive](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/examples/README.md) |
## Why and How?
After publishing [LDraw Nova](https://github.com/anteloc/ldraw-nova), a sibling project for **agentic generation of LDraw models**, several people reached out to me asking about if models could be **animated** somehow.
During the development of Nova, I noticed that **adding** some **special annotations** to `.mpd` **original** model **source files**, and then giving those to **agents**, would:
- **Help** agents in **understanding how to build** other different models.
- But also, in **understanding how a model was built**.
Which gave me the idea that, maybe, an agent would **also understand how a model would work.**
### Reverse-engineering mechanisms from their sources
As a first step to it, I gave **annotated models** to different agents, and prompted them to **infer (reverse-engineer)** their **constituent submodels** (see **Haiku 5.5. experiment** below).
Results from **inference experiments** were both pretty **good** and **consistent** across different agents, and I also noticed the following: **many of the submodels inferred were actually mechanisms.**
After questioning several agents about those inferred mechanisms, regarding how would they **actually work**, I also got consistent results: agents would **describe behaviours** based on the **descriptions for the parts** on a **mechanism!** 🤯
At this point, I had the following:
- Agents would **split and refine** models into submodels and mechanisms.
- Agents would **understand** each mechanism in **isolation**.
- Agents would **understand** how **individual** mechanisms **worked**.
The **result** of an actual **divide-and-conquer process**, right? 🤓
Which would make **handling individual mechanisms** manageable. 🤩
### Correlating LDraw source code to a 3D model
Now, there was the matter of giving agents the **means to actually animate** mechanisms they already knew how they worked.
I was playing with **Blender MCP** at the time, and Blender looked promising as a tool that would provide agents a way to **manipulate LDraw models in 3D**, imported into Blender as **glTF (.glb) files.**
But there was still an **open issue:**
***How to map from a refined model source code an agent would understand, to its equivalent 3D model in glTF format an agent could manipulate?***
And the **solution** I found was:
***Annotate the 3D glTF model's nodes with the same annotations as the source code, so the agent would:***
- **Outside Blender: plan on submodels** 🤔 and parts as **source code.**
- **Inside Blender: execute on matching nodes** ✨ on the **3D glTF model.**
### Putting the pieces together 😉
Now, I had a **draft** for a **process**, but **no tools for the agent** to use and carry it forward.
Given that the process would require a **high amount of complex geometric and spatial calculations**, I asked the agent to **derive a new python toolset** from the one created for [ldraw-nova](https://github.com/anteloc/ldraw-nova)
The new [**python toolset**](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/docs/architecture.md) I refined **iteratively**, by giving the agent **simple models** at the beginning, and **increasingly complex ones** each time.
And to test it, I gave an agent **instructions** to:
- **first, plan** from an annotated and refined `.mpd` model
- then, **generate a glTF 3D version of it, with matching annotations**
- then, **upload it to Blender**
- and then, **produce the Blender python scripts** that would **animate the model as planned.**
**And it finally [worked](https://github.com/anteloc/ldraw-mecha/blob/v0.5.0/GALLERY.md)!** 🚀🚀🚀
(but not perfectly) 😜
## Experiment - Claude Haiku 5.5 reverse-engineering session
**Prompt:**
*This is a fragment, a submodel, from an LDraw .mpd file model.*
*This is not an executable code fragment, but more like a 3D CAD model fragment written in LDraw language.*
***Infer what this submodel is, and also split it into submodels** (starting with: 0 FILE):*
- *always with relevant, semantical meaning,*
- *the first 0-line following every 0 FILE line is the "description line" for the submodel, according to the LDaw standard*
- *add the description for every submodel there, a one-liner, as a person would describe it while looking at it*
- *at the answer, first place the parent model, then the child one(s) and then the grandchildren, and then descendants... etc.: go from containers or parents to containees or children, children of children. etc.*
---
Expand code...
```
0 FILE file-01
0 file-01
0 Name: file-01.ldr
0 Author: Unknown
0 !LDRAW_ORG Model
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
0 // Plate 2 x 12 (dark_bluish_grey)
1 72 0 0 0 1 0 0 0 1 0 0 0 1 2445.dat
0 // Tile 1 x 2 Grille with Groove (metallic_silver)
1 80 -110 -8 0 0 0 1 0 1 0 -1 0 0 2412b.dat
0 STEP
0 // Slope Brick Curved 2 x 2 x 0.667 (metallic_silver)
1 80 -80 8 20 -1 0 0 0 1 0 0 0 -1 15068.dat
0 // Slope Brick Curved 2 x 2 x 0.667 (metallic_silver)
1 80 -40 8 20 -1 0 0 0 1 0 0 0 -1 15068.dat
0 // Slope Brick Curved 2 x 2 x 0.667 (metallic_silver)
1 80 0 8 20 -1 0 0 0 1 0 0 0 -1 15068.dat
0 // Slope Brick Curved 2 x 2 x 0.667 (metallic_silver)