Houdini How-To: Randomise Geometry

Please note my blogs aren’t meant to be read in any particular order. Obviously the ones with Fundamentals in the title are aimed more at the beginner and the others will be more focussed on more complicated topics that require some knowledge beforehand. The How-To topics are of the latter type and take a single problem I’ve faced in Houdini and show my solution to them.

In this case I’m looking at how to randomise which geometry is used from a fixed set. I’ve chosen this because there is a definite difference between an older way fallen out of favour with SideFX and a newer way which is better to use. You will see the old way, the Copy Stamp, mentioned in a lot of older Houdini Tutorials – this has now been supplanted (but not replaced, SideFX don’t want to break old set-ups) by the Copy-to-Points node and the For-Each loop. This is the method I’ll be covering here.

This image has an empty alt attribute; its file name is image-1-1024x785.png
This is our goal, my graphic design skills are unsurpassed.
This image has an empty alt attribute; its file name is image-1024x664.png
The entire set-up, split into three main areas.

In the first section, coloured green above, I create three different geometries for our randomiser to select from. They are the letters A, B and C formed from a Font node and a PolyExtrude node. They are all linked into the same Switch node. In Houdini a Switch node is used to select which of n inputs (3 in our case) to use based upon a single integer that is a parameter of that Switch node. For example, if the Switch is set to 0, our setup will send out the A geometry. Why 0? Because coders start counting at zero, it’s traditional.

This image has an empty alt attribute; its file name is image-2.png
Our different geometries, these could be anything, as long as they are all plugged into a Switch node

Don’t worry for now about what to put in your Switch parameter, I’ll come to that after explaining the next section.

The CopyToPoints node takes any geometry and copies them to the location of a set of points. In addition it will take specific attributes of those points and extend them to the geometry. For example, if you set the colour (attribute Cd) of a point to red, your geometry will be rendered in red. This allows for a limited set of randomisation options, the colour, the scale, the orientation and so on. You’ll see in the yellow section of my set up that I create a Sphere, set to polygon, which creates a regular set of points at each vertex that creates the sphere.

I then create three attributes (piecenum, pscale and Cd) and randomise each within sensible ranges. By now pscale and Cd may be familiar to you. They are the universal scale and colour attributes of the particles. CopyToPoints knows all about those and will propagate them into your geometry.

This image has an empty alt attribute; its file name is image-3.png

In fact, in something of an aside, if you delete the For Each structure you have what you might think of as the standard CopyToPoints functionality.

But as you can see below, though our scale and colour is randomised the geometry is definitely not. In effect the Switch select input is set to 0 and so only the A geometry is used. CopyToPoints doesn’t know about our piecenum attribute. SideFX could add that functionality in at a later date but that would be specifically for that attribute. There’s no way the CopyToPoints node can know about every attribute you put on the points and how to alter the geometry exactly how you want.

So, we use a For Each loop around our CopyToPoints node, which will let us use a bit of Houdini trickery to put any attribute we want up the pipe to our Switch select input.

If you go back to the Switch node and look at the parameter pane, I’ve typed the following into the field:


This tells the CopyToPoints node that for each point it needs to pluck out our piecenum attribute and put that value into the Switch select input. In effect the Switch node becomes part of the For Each loop though Houdini doesn’t show it in the Node Network.

Here is a link to my .HIPNC file.

An example I put together using random geometry

Leave a Reply

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