Breakdown 2 of 4
Procedural LEGO parts
I used a PDG network to batch generate parts and their stud positions with a raycast algorithm.
Overview
Houdini handles two jobs in the pipeline: building a mesh for every part in the part list, and finding each part’s stud and anti-stud positions so parts can connect. Stefan Müller’s LDraw2Houdini (Müller, 2023) was used to build the meshes, and I wrote the stud detection. I left the studs until last, as they weren’t immediately necessary because most parts follow the grid. I started with a loop system and then refactored to a Procedural Dependency Graph (PDG) network, which suits working through a large set of parts.
Generating the meshes
LDraw2Houdini is a Houdini Digital Asset (HDA) that parses LDraw .dat files and builds the part
geometry, so I didn’t need to write my own parser. I use it mostly as it comes, adding
scaling, a grid-aligned origin and UVs.

The PDG network makes one work item per entry in the part list, then splits in two: the right branch runs LDraw2Houdini’s full mesh asset through an HDA Processor and writes each part out as an FBX, and the left branch generates the stud positions.

Three unit systems
LDraw, Houdini and Unreal each measure parts differently, so the studs only line up once all three agree on size. LEGO’s grid isn’t uniform either: a 1 x 1 brick is taller than it is wide, and a plate is 1/3 of a brick’s height (Shenoy, 2022).

LDraw models parts in LDraw units (LDU), where one LDU is 0.4mm. In Houdini the part is at real size in millimetres, so a plate is 3.2 units tall. Unreal works in centimetres, a factor of 10, and then scaling by 1.25 makes the bricks fit nicely into Unreal’s grid system, 12.5 overall. The snapping grid in Unreal is 10 x 10 x 4.
| LDraw (LDU) | Houdini (mm) | Unreal (cm) | |
|---|---|---|---|
| 1 x 1 brick width | 20 | 8 | 10 |
| 1 x 1 brick height | 24 | 9.6 | 12 |
| Plate height | 8 | 3.2 | 4 |
Finding the studs
Every part needs two sets of points: top studs, where other parts snap on, and anti-studs underneath, where other parts’ studs fit in. The stud branch splits the part into pieces and merges the final stud positions together.

Top studs
LDraw builds parts from a library of primitives, so every top stud references the same stud primitive. LDraw2Houdini keeps those positions in its cached version of a part before it adds the stud geometry, so I read the stud positions from that cache. The stud branch keeps the points marked as studs and averages each cluster into one point per stud. Every stud on a part sits on the grid, so moving the first top stud to the origin guarantees the whole part is aligned, and it sets the offset for the anti-stud grid.

Anti-studs
Anti-studs, being a negative space, do not have a primitive to identify, so they have to be found from the shape of the part, using the grid the top studs set up. The search runs in four steps:
- Aligned grid - A grid of points is aligned to the known top studs.
- Bounding box - Any point outside the part’s bounding box is culled.
- Raycast up - Any point whose ray up misses the part is deleted.
- Climb in plates - From the bottom of the part, each point steps up one plate height at a time and fires 8 rays outward. If 6 of the 8 hit, a stud could sit there, so the point is a valid anti-stud. A point that reaches the top without passing is deleted.



Six out of eight matches how many sides a real stud needs to sit in an anti-stud. Climbing one plate at a time keeps the number of checks to a minimum without ever stepping past a possible anti-stud. The climb is a single point wrangle:
The anti-stud point wrangle (VEX, 53 lines)
// 8 directions: 4 cardinal + 4 diagonals
vector dirs[] = {
{ 1, 0, 0}, // +X
{-1, 0, 0}, // -X
{ 0, 0, 1}, // +Z
{ 0, 0, -1}, // -Z
{ 1, 0, 1}, // +X+Z
{ 1, 0, -1}, // +X-Z
{-1, 0, -1}, // -X-Z
{-1, 0, 1} // -X+Z
};
float plate = 3.2; // Snap to plate heights
// Start and stop positions for iteration snapped
float minY = floor(@P.y / plate) * plate; ;
float maxY = floor(detail(0, "hit_y", 0) / plate) * plate;
float testY = minY; // Iteration height
float foundY = -1e9; // If valid set to height
// Ray cast config
int required = 6; // x/8 amount of rays hit to count as valid space
float dist = 100.0; // Max check distance in directions
// Loop upwards in plate increments until we reach the hit height
for (; testY <= maxY + 1e-4; testY += plate) {
int hitCount = 0;
// Cast 8 dir check - ray is slight higher to stop grazing angle
foreach (vector D; dirs) {
vector origin = set(@P.x, testY + 0.1, @P.z);
vector hitP;
float u, v;
int prim = intersect(1, origin, D * dist, hitP, u, v);
// Hit mesh
if (prim >= 0)
hitCount++;}
// If reaches theshold for valid snap, store the height
if (hitCount >= required) {
foundY = ceil(testY / plate) * plate; // Snap down
break;}
}
// If it wasnt valid at any iteration, remove
if (foundY < -1e8){
removepoint(0, @ptnum);
return;}
// Set to anti stud height
@P.y = foundY;
s@type = "AntiStud";Part 58846, a large quarter round brick with a cutout underneath, was my test case for the outward rays. Its real anti-studs would be able to fit on the edge of the curve despite technically sitting within the part.

The climb also works when anti-studs sit at different heights. On this curved part each anti-stud is found at its own step, shown again on the right without the part.

Writing it out for Unreal
Once both sets of points are merged, a Python Script TOP writes a JSON file per part with each stud’s type and its offset from the origin, swapping Y and Z on the way because Houdini is Y-up and Unreal is Z-up. Those files are merged back into the main part list, which the tool reads to spawn its snap handles.
The 2 x 4 brick’s entry in the released list, cut down to one top stud and one anti-stud, has top studs 10 apart and anti-studs 12 below them, one stud and one brick height in Unreal units:
Part 3001 in the part list (JSON, 19 lines)
{
"PartID": "3001",
"Name": "Brick 2 x 4",
"Keywords": "brick;2;x;4",
"Studs": [
{
"ID": 1,
"Type": "SolidTopStud",
"PosOffset": { "X": -10, "Y": 0, "Z": 0 },
"RotOffset": { "Pitch": 0, "Yaw": 0, "Roll": 0 }
},
{
"ID": 8,
"Type": "AntiStud",
"PosOffset": { "X": -30, "Y": 0, "Z": -12 },
"RotOffset": { "Pitch": 0, "Yaw": 0, "Roll": 0 }
}
]
}

Reflections
- Parts without top studs - Everything hangs off the first top stud, so a part without one (tiles, and a lot of curved and decorative pieces) has no origin on the grid, and the rays often miss its anti-studs too. That’s roughly 1/3 of the library. Those parts sit off the grid, and moving them around means turning grid snapping off.
- No side studs - The saved transform has a rotation, so side studs are supported in theory, but nothing finds them yet because they weren’t a priority in the timeframe. I’d like to add them, along with the more unusual stud formats.
- Baking the whole library up front - Adding one more part means cooking the whole lot again. With Houdini Engine inside the editor, an artist could request a part and have it generated without leaving Unreal.
Sources
Müller, S. (2023). ldraw2houdini: Import LDraw Files Directly into Houdini. [online] GitHub. Available at: https://github.com/stefanmuller/ldraw2houdini [Accessed 23 Nov. 2025].
The Houdini tool to generate the parts from LDraw .dat files.
Shenoy, D. (2022). Isn't That Stud Supposed to Be on Top? No, It's SNOT - Building Sideways Using LEGO. [online] Brick Builder's Handbook. Available at: https://brickbuildershandbook.com/2022/01/20/ [Accessed 23 Nov. 2025].
The brick and plate dimensions.