BRICKPACK

I released the code for BRICKPACK on Github with a Python and JS/WebGL+WebGPU implementations.

Around September, I got fairly obsessed with Lego assemblies and how to make the best looking models with as few parts as possible. I first did BRICKATOR 3000, a real-time Client-Side LEGO parts detector that lets you make a census of the LEGO parts present in a picture. Then of course, I wanted to build new models from the parts at hand.

There exist a couple of models to do that:

So there was no way to go from a 3D model and obtain a LEGO build from parts and that’s what I was after. So I tried many approaches from brute force to Markov chains, Wave Function Collapse and learnt assemblies swaps but none of these gave good results. You can check the BRICKAGEN version. It’s pretty fast and globally fits the target model yet it lacks finesse.

The problem is that these techniques often took the easy route ; more or less discretizing / voxelizing the input model and using square bricks, disregarding the most expressive assembly tricks, notably ignoring slopes and columns. This was frustrating and at some point, I had the weird – and somewhat desperate – idea of using a Signed Distance Function to represent the target model and use a set of SDF encoded LEGO parts to recreate the target model.

initial SDF parts catalog

Given a discrete reference unit (the 1*1*1 brick size) I could subdivide the target SDF and scale my parts’ set accordingly, and it worked!
BRICKPACK produced more expressive & more faithful models using many less parts (~30% of brickagen!). And the previous algo could still be used to “clean up” stacks of tiny parts (see bottom left image).

BRICKPACK at work with various resolutions.

A big limitation is that BRICKPACK doesn’t use axles, wheels, hinges or ball connectors, and no “Studs Not On Top” assemblies (or SNOT, parts growing perpendicular to other) .

The BRICKPACK app is available online, the models “should” be buildable and it can be exported under various formats (LDR, GLB, PLY), it lets you order the parts for a specific model from the LEGO shop, it can also produce an instructions booklet.

it also lets you export a valid shader to use in shadertoy!


again, the code is on Github with a Python and JS/WebGL+WebGPU implementations.
I left the research I did and a list of relevant papers, in case you’re interested or want to iterate using an agent (or your brain).

here are some beauty shots

early result
and my failed BrickGPT attempt :)

Leave a Reply

Your email address will not be published. Required fields are marked *