Few weeks ago I made a simple LEGO tool in Houdini. I decided to do a little breakdown about it.
The very core of this tool is only 4 nodes. Pretty simple right?
The first node creates a VDB volume from your input mesh. Next, we convert the 3D grid of the voxels into geometry. When we have the geometry we can extract the centre point of each little cube out of it. So now we have 3D point cloud. The last step is to literally put any kind of mesh you want and use the copy to points SOP.
If we leave it like that the object can only be build with 1 type of Lego brick. That's why I decided to push it a little bit further (Since the first step was so difficult).
This was the part i had the most trouble with. I wanted it to support any kind of the basic Lego bricks, so doing calculations by hand seemed not like the correct approach. The solution I came up with allows for any kind of convex shape on the X, Z axis. Which is pretty good I think.
We start with slicing up our point cloud for every row of points.
Then we go in to a nested for each loop. One will loop over the different rows and one will iterate over every point in said row.
What I do in the second loop is moving a template shape around and see where it matches the points. The matched areas get marked and will be merged together into one point. So in the example below I'm basically looking for an area within the point cloud were a 2x4 brick would fit in.
The downside is that for every shape we want to look for we have to loop through the points. Granted only the first time will be the most intensive loop. In my examples I searched for 2 shapes. The 4x2 and the 2x2 Lego brick. The remaining points in the end got the 1x1 brick.
I get that this might come across as a rather brute forced solution, if anyone has a better approach please let me know!
I also made a basic brick tool that would let me generate some of the basic shaped bricks. This tool allows for 1x1, 2x3, 2x4 and 2x2 bricks. It could easily be expanded to support other types but it wasn't really the focus of my experiment here. Albeit, it was still fun to make.
After all that is finished we can achieve the following result!
Btw, to get the colours you can use the SOP Attribute From Map.
Then the only thing left to do is...
(I'd love to render out a video where I trash the cathedral Lego model, but it takes ages!)