Houdini Lego Bricks
This project came about because I wanted to get more familiar with some fundamental concepts in Houdini. My focus was on understanding PDG and experimenting a bit with differnt ways of organizing data within a Houdini scene / project.
To have a clear goal, I like to formulate a fictional use case, e.g. “We need a unique 3D model for every possible Lego brick size from 1 by 1 to 2 by 6 studs.”
“Every possible brick” may sound a bit daunting, but I’m only concerned with regular box shaped bricks with standard height (no tiles, narrow bricks or modified bricks) to keep things simple for this exercise.
I set up a basic scene with a geo object for the brick, a PDG network and a simple render environment that allows to create some renders of the bricks.
Let’s take a look at the entire geo network and then dive a bit deeper into the individual generation steps:
At the very top we have two null settings nodes that control all the nodes down below.
I started by measuring some real lego bricks and noting down the key measurements in the settings node. In addition to this there are two parameters (X Size and S Size) that control the size of the lego brick in stud dimentions. As you can see in the following screenshot these two variables are connected to channel properties that are linked to properties from the TOP network.
There is a scond null-node in which I calculated some of the shared properties of the brick that can be derived from the initial measurements:
From these settings, I created a grid that gives reference points for all the studs. E.g. here you can see a grid for a classic 4-by-2 brick:
Let’s start with one of the most defining characteristics for Lego bricks: The studs can be placed exactly on top of the previous grid positions. To get their iconic look just right, I needed to add the small Lego lettermark on top of the stud cylinder.
I was not super concerned with getting things real-time performant so I simply created geometry for the letters from a stenciled image I found on worldvectorlogo.com. In general I worked a lot with simple extrude and bevel operations.
These studs by themselves are not of much use. The actual brick is still missing. Luckily the box shape for the brick can be realized with a simple boolean operation. Anyone more familiar with Lego bricks wil know though that the insides of the bricks have tiny holes below the studs (probably to save some plastic). For these holes, I used boolean operations again: After all it’s just little cylinder shapes that go into a perfectly flat plane.
To make the underside of the bricks complete we of course also need the cylinders that grip between the studs of any bricks below. Depending on the brick size these will either be a single row of small cylinders that go between two studs or slighly bigger pipes that go between four studs:
The network to create these cylinders looks like this:
The final step is just merging all of these individual pieces with a merge node. I’ll spare you the screenshot.
Rendering the Bricks
To fulfill the final requirement of my self-imposed task (“generate all possible bricks”) I planned to use PDG to export all the required 3D models. While working I found that I could use the same setup to monitor my work by rendering all brick variations from above and below. That way I could observe both the studs and the pins/tubes on the underside.
You already saw the cameras I set up for this purpose above. To actually render the images, I set up a little TOP network.
First off are a bunch of wedge nodes that create work-items for all the permutations we want to render:
For each of the work-items an image is rendered with a ropmantra node and augmented with a text overlay that tells me for each image what the key input parameters were (i.e. height and width of the brick in studs).
Finally, the individual images are combined with an ImageMagick node and copied over to a backup directory:
And this is the image created from this final task:
Note that the Houdini logos in the render stem from the Houdini Apprentice version I used for this excercise. If you use a commercial Houdini license you can render images without any watermark.