Skip to content

anteloc/ldbuilder-ai

Repository files navigation

LDBuilder AI

An AI skill to build virtual LDraw/LEGO models

Overview

Warning

WIP: the skill is not ready yet, and the current source code doesn't fully work, but models can be generated using a bundle zip file on this repository.

The main goal for this project is: making an agentic LLM build virtual LDraw/LEGO models.

According to their own definition, LDraw is:

"..a completely unofficial, community run free CAD system which represents official parts produced by the LEGO company."

Part of this system is the LDraw language, an extremely simple programming language for building virtual models, mostly LEGOs.

This makes possible for an agentic LLM to generate LDraw source code, that's equivalent to generating a virtual model.

See the Results section below for samples of generated virtual models.

Quick Start

Warning

Not every attempt at generating a new model will be successful!

Generating models via an agentic LLM involves just a few easy steps, detailed below.

Preliminars

The following are required downloads:

Extract the parts library zip file and then configure LDView to use it.

These other downloads are optional:

As with LDView, these tools may also require configuration for using the parts library.

Model Generation

To start generating models:

  • Log in to the chat website (e.g. https://claude.ai/ or https://chatgpt.com/)
  • Add the following to the initial chat message:
    • The zip bundle you downloaded before
    • The prompt message:
      • "Follow the instructions.md in the attached bundle. Build me a ______"
  • Send the message

Create more models on the same conversation by entering more prompts like e.g.:

  • Build me a car
  • Build me a house
  • Generate a wizard
  • ...

Then, the agentic LLM will start the building process and provide an LDraw .mpd file for download when finished.

To inspect the resulting model, download the .mpd file and open it on LDView.

That's it!

How It Works

TODO

  • The LDraw language
  • Parsing the language
  • Adjusting the geometry for the LLM
  • BOMs
  • Models library creation
  • The validation-feedback process loop
  • Pending - RAG
  • Pending - Fine tuning

Results

Tip

Browse these generated models and more on a 3D or VR environment at:

https://anteloc.github.io/ldbuilder-ai-viewer.html

NOTE: VR mode requires a WebXR-compatible headset like e.g. Meta Quest

The following models have been generated using Claude.ai (Opus 4.5, Opus 4.6 and Sonnet 4.6).

It was a simple process:

  • I gave it a simple prompt, few constraints, so it would be creative
  • Then, it would start the creation process, by generating LDraw source code
  • At the end of the process, I would download the generated sources (.mpd file)
  • After that, I would open them in LDView for inspecting the generated model

The resulting models are actual editable CAD models, not only meshes. This is a model I opened in Blender:

Model A + B: 01-opus-4.5/009-speed_falcon_hybrid.mpd

hybrid-falcon-cad.png hybrid-falcon-cad-geom.png

Prompt: Create a car, you decide about its features

It has quite some defects, but symmetry is pretty good.

01-opus-4.5/001-generated_sports_car.mpd
Create a car, you decide about its features

Prompt: now, create a paladin

It took care itself of dressing the minifig accordingly.

01-opus-4.5/002-generated_paladin.mpd
now, create a paladin

Prompt: now, another paladin, but this time, a dragonslayer

Even with only one hint, "dragonslayer", it took care of even choosing a proper shield.

01-opus-4.5/003-generated_dragonslayer.mpd
now, another paladin, but this time, a dragonslayer

Prompt: now, a skyscraper, in silver and red, with big windows

This rendered image is missing several details:

01-opus-4.5/004-generated_skyscraper.mpd
now, a skyscraper, in silver and red, with big windows

A better screenshot, from LDView, proof that the requested features are present:

skyscraper-viewer.png

Prompt: build the Millenium Falcon

The result is only slightly similar to the original one, with a similar outline.

01-opus-4.5/005-generated_millennium_falcon.mpd
build the Millenium Falcon

Prompt: create a squad of 4 firemen

Two things I've noticed:

  • First, it can count ;-)
  • Second, all of the minifigs correctly hold the tools in their right hands.
01-opus-4.5/006-generated_fireman_squad.mpd
create a squad of 4 firemen

Prompt: now, a pilot sitting in a F1 car

It often happens that it gets rotations wrong, like in this case, with the pilot facing rear instead of front.

01-opus-4.5/007-generated_f1_car_with_pilot.mpd
now, a pilot sitting in a F1 car

Prompt: attached you will find a model for the Millenium Falcon.Modify it in order to create a new spaceship

I gave it this as a baseline to start working.

01-opus-4.5/008-10179_Ultimate_Collectors_Millennium_Falcon.lxf.mpd
(INPUT) attached you will find a model for the Millenium Falcon.Modify it in order to create a new spaceship

The model being too big, instead of changing its shape, it decided to make it red, and gave it the name "The Crimson Interceptor".

01-opus-4.5/008-crimson_interceptor.mpd
(RESULT) attached you will find a model for the Millenium Falcon.Modify it in order to create a new spaceship

Prompt: create a hybrid of these two attached models

Here I tried something different: gave it two models, and asked it to "merge" them.

The end result it's like it copied the engines and rear wings from A and pasted them onto B.

Model A: 01-opus-4.5/009-4882_Speed_Wings-Model_A.lxf.mpd
(INPUT 1) create a hybrid of these two attached models
Model B: 01-opus-4.5/009-4882_Speed_Wings-Model_B.lxf.mpd
(INPUT 2) create a hybrid of these two attached models
Model A + B: 01-opus-4.5/009-speed_falcon_hybrid.mpd
(RESULT) create a hybrid of these two attached models

Prompt: from the attached model, create a new one that contains only the plane

Now, I tested extracting a submodel from a model: get me the plane alone!

01-opus-4.5/010-4209_Ffire_Plane.lxf.mpd
(INPUT) from the attached model, create a new one that contains only the plane

It failed the first attempt, and extracted the car and wagon, instead of the plane.

01-opus-4.5/010-A-fire_plane_only.mpd
(RESULT 1) from the attached model, create a new one that contains only the plane

Prompt: actually, this is not the plane, but the car and its wagon. try again.

Second attempt at extracting the plane, this came out better than before. The plane is missing several parts, but the ones present seem to be correct.

01-opus-4.5/010-B-fire_plane_only.mpd
(RESULT 1 - FIX) actually, this is not the plane, but the car and its wagon. try again.

Prompt: remove the people from the attached model

This was an actual surprise, I gave it the following model:

01-opus-4.5/011-2150_Ttrain_Station.ldr
(INPUT) remove the people from the attached model

... and it "removed" the people there, but left most of their clothes, hair, etc. intact (!)

01-opus-4.5/011-train_station_no_people.ldr
(RESULT) remove the people from the attached model

Prompt: ok, now: add some people to the model, dressed accordingly

It added several minifigs, in winter garments, but their hats were oddly attached.

01-opus-4.5/012-10267-1.mpd
(INPUT) ok, now: add some people to the model, dressed accordingly
01-opus-4.5/012-generated_10267_with_people.mpd
(RESULT) ok, now: add some people to the model, dressed accordingly

Prompt: Create a car, you decide about its features

Same prompt I used before with Claude Opus 4.5, now with Sonnet 4.6 is way better!

02-sonnet-4.6/001-generated_sports_car.mpd
Create a car, you decide about its features

Prompt: now, a cat

Just took a ready-made minifig and placed it on a base.

02-sonnet-4.6/002-generated_cat.mpd
now, a cat

Prompt: now, a plane, a fast one!

Not a good result, simmetry was clearly wrong.

02-sonnet-4.6/003-generated_fighter_jet.mpd
now, a plane, a fast one!

Prompt: it has some structural defects, symmetry errors... fix them.

Besides this prompt, I also attached a screenshot from top perspective for the previous defective model. It analyzed the image, correctly detected several symmetry errors, and partially fixed them.

Before:

02-sonnet-4.6/003-generated_fighter_jet.mpd (top)
now, a plane, a fast one!

After:

02-sonnet-4.6/003-generated_fighter_jet_v2.mpd (top)
it has some structural defects, symmetry errors... fix them.

End result (partially fixed):

02-sonnet-4.6/003-generated_fighter_jet_v2.mpd (isometric)
it has some structural defects, symmetry errors... fix them.

Prompt: now, a skyscraper, 25 floors, in silver and red, with big windows

This really amazed me, even though the resulting model has structural defects.

It got it right by creating a small python script that would create all the floors by repeating the same one... 25 times!

skyscraper_25_prompt.png

02-sonnet-4.6/004-generated_25_floors_skyscraper.mpd
now, a skyscraper, 25 floors, in silver and red, with big windows

Prompt: build a stadium

This one took 743 parts (pieces) across 9 sub-models, according to itself (Sonnet 4.6. ) The supports under the base plate don't make much sense, but for the rest, structurally speaking, it seems pretty good.

This is the script it created and run itself for generating the stadium.

02-sonnet-4.6/005-generated_stadium.mpd
build a stadium

Prompt: build me the attached building

I gave it this photo from an iconic building, the Bradbury, just to test how accurate it is when copying something real.

building-small.jpg

Because of being a famous building, it had extra information, took that into account, and this is the end result:

04-opus-4.6/001-generated_bradbury_building.mpd
build me the attached building

Prompt: now, build me this other attached building

I gave it a drawing of a regular building, so it wouldn't have any extra information besides what it could infer from the picture.

building-drawing.jpeg

The floors on the lower levels of the model have four windows per side, instead of the three in the picture. However, windows in the picture are of different sizes, but in the model they are the same size.

04-opus-4.6/002-generated_tiered_building.mpd
now, build me this other attached building

Prompt: now, replicate the attached picture on a mosaic, using blocks

The picture I gave it was:

The resulting model, oddly, was upside-down:

04-opus-4.6/003-generated_mosaic.mpd
Girl with a Pearl Earring by Johannes Vermeer

After opening the model in LDView and rotating it, I got this:

Prompt: attached you will find the image of a transparent vase.

Here I asked for it to create a python script that would generate the LDraw source code to build the attached image.

Full prompt was:

now, the following task will be different. attached you will find the image of a transparent vase. I want you to create a big vase, but because I want a huge number of pieces, we will do the following:

  • instead of directly building the vase, create a python script that generates the required ldraw instructions to create it
  • instead of using custom pieces, use 1-stud pieces as if they were voxels

The attached vase image:

It successfully created the requested python script to generate the vase, 5,074 pieces in size.

04-opus-4.6/004-generated_vase.mpd
attached you will find the image of a transparent vase.

Acknowledgements

I'd like to thank the following:

... and thanks to all of the many other LDraw creators!

About

WIP - An AI skill that builds LDraw/LEGO models

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors