Procedural Lego bricks with Houdini

September 9, 2020 -

Creating lego brick version out of any geometry procedurally

The goal is to output any geometry as if it were made out of Lego bricks procedurally.
In this example, the tool processed a photogrammetry scan of a statue of Neptune, at the Louvre Museum, but you can use any geometry as input.

I got inspiration from one of the talks of Robert Magee and decided to create my own version, including the option of procedurally adapting the brick size, methods for coloring them and driving the way they appear in scene.

Procedural lego bricks - HDA technical Breakdown

The core component of the tool is creating an evenly-spaced point cloud.


I start with some basic cleanup, which includes proper scaling and alingment. Whenever importing any asset, I prefer checking some basics, like small angle deviations from XYZ axis, crazy scales and random orientation. I usually stick orienting to +Z and unifiying size to 1meter to have dimensions “under control”. 

Many actions and node sliders are sensitive to sizes, so having unified sizes avoids plugin a resample node to a 100km long curve and have your scene frozen accidentally.

Then I addressed the special issues from photogrammetry assets: closing holes and removing floating chunks of geo, among others.

Whenever creating a tool for production, I usually design interface first, to stablish its behaviour and controls. It doesn´t matter that these parameters do nothing at this point.
I found this approach useful even for personal and fun projects, otherwise I easily deviate from the initial goal of the tool. It is like defining a road map first, which helps me keeping focused on the target.

Some basic cleanup includes deleting small parts and closing holes.
Using the “delete_small_parts” node set to “Extract largest piece” gets rid of small chips (I usually clip the bottom as well).

 

With “polyfill” node I close the gaps. 

By default, I set it to “Single polygon”, other options take more times to compute and are not always needed.

 

The core component of the tool is creating an evenly-spaced point cloud.
There are a few ways to do it. For time´s sake, I chose the “pointsfromvolume” node which includes a lot of options. But, you can achieve same result if placing an isoffset + scatter nodes.
The distance between points in three axis (x,y,z) must be uniform, so creating a brick with a cube-shaped body, simplifies the system a lot. Then its about linking this size to the point separation value

As an aside, I found other useful methods of creating grids.

With a few lines of scripting you can get the same result, but choosing this option means you are in VEX-world, which allows more advanced and tailored possibilities.

 

Alternatively, you can use the fuse node as a snapping-to-grid tool. Set to grid and then choosing the treshold of your choice.

 

 

I decided to do the rendering using Mantra, Houdini´s native renderer engine, so I could easily benefit from coloring points and then transfering this value to the shader.
There must be a zillion ways of coloring points, but I aimed for quick results, so nothing fancy here:

Color by ramp:
I added an attribute per point, sorted them along Y axis and finally, a color node, set to “Ramp from attribute”. Useful for….who knows, maybe creating a flag-like lego sculpture.

Color by cluster:
Randomly delete some points based on treshold, color them, finally transfer this color to the original points. Clusters can be created in a ton of different ways and it is possible to achieve more organic looks authoring them a bit.

Color by texture:
This is easier to approach through VOPS (which basically is visual programming running VEX under the hood).
The trick here is just to grab a texture, assign its color value to the vertices anf then promote the color attribute to points (so that renderer can “see” this color value.

 

Color random
Just a random color value per point. Same as first option, including a unique attribute per point plus color node set to random from attribute does the trick.

I tried three different complex approaches before this one: I realized that animating the selection of a “Group_range” node grouped points the way I wanted, providing a nice visual result.

I discovered to be a goof practice to stop myself from time to time and ask:
“Am I overcomplicating things?” 

If I feel like I am falling in some kind of rabbit hole, spending a lot of effort and complex calculations, chances are I already chose a wrong approach and there is an easier method out there.

Just needed to bind the amount of points with my available frame range.

Finally, blast the points that do not belong to the group makes them “appear”.

Disclaimer: This content is product of my personal work, free to use in personal, educational and commercial projects. If you find this content useful, support me by crediting www.reveron3d.com , this is not mandatory, though.

Follow on Twitter:
@reveronadolfo

I try to highlight challenges so don´t take these series as step by step tutorials, they were created for supporting movie makers, game developers and the Houdini community in my spare time. It is product of my own expertise so it might contain mistakes. Browse www.sidefx.com for official reference.

Leave a Reply

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


Play Cover Track Title
Track Authors