Houdini Tip of the Day - Emit RBD Objects

It's been a while since the last time I posted anything but I thought this time I'd show how to emit RBD objects. A particularly useful setup that I've used numerous times to simulate rocks piling up.

In a nutshell all we are going to be doing is taking a piece of geometry that we want to use as out emitter geo, copy stamping random geo to each of it's points, transferring Velocity from a particle network, then converting the geo to RBD's that will fall and collide with whatever we have set up.

When I was originally learning this I was worried it was going to be complicated but I was relieved when I saw how simple the node graph was.

Lets dive in!

To start off, you will need some geometry that you want to emit from.
I've chosen to go with a box and then I animated a "Mountain" SOP to make all the points on the box move around in a crazy manner so when the objects get emitted from this object they will appear somewhat random.

After the Mountain SOP I added a "Point" SOP with "Add Normal" chosen under the "Standard" tab. I didn't end up using the normals in the end but it's always nice to have just in case. 

Now we need to generate some particles that we will use to copy some geometry onto. To do that, drop down a "Pop Network - Old" SOP and dive inside. 

In order be able to birth particles onto our emitter geo we need to use the "Source" POP. Set it to "Points(random)" and for Geometry Source choose "First Context Geometry". This will take whatever we have plugged into the first input of our particle network, just as Second, Third, and Fourth Context Geometry will respectively represent the other inputs on the particle network.
Change the "Const. Birth Rate" parameter to increase how many particles will be born. You don't have to worry about the "Life Expectancy" parameter just yet because we will be adding a "Kill" POP at the end to essentially make the Life Expectancy 0.

If you play the scene now, all you would see is a bunch of particles being generated on your emitter geo. Right now they aren't going anywhere though. Let's change that. Drop down a "Force" POP and change the Y Force to -9.8 (gravity). Now for this setup we might not even need the "Force" POP because we are going to be letting the gravity in DOP's affect how our objects fall, but I still like to put the "Force" POP in there just in case there comes a situation where I might need to emit particles for some amount of time before having DOP's take over.

The particles are now falling because of the "Force" POP

The last thing we want to do in our particle network is set the Life Expectancy to 0. We want the particles to emit, then die because as soon as they are emitted our DOP network will take over. Normally, you would just set the "Life Expectancy" parameter to 0 on the "Source" POP but you can also throw down a "Kill" POP and set the "Rule" to "@LIFE==0". This changes the LIFE attribute to 0.

Now lets jump back up to object level and start copying geo onto our particles.
For this example, I chose to keep it simple and just use three objects: a sphere, a box, and a tube.
Then I threw down a "Switch" node that we will use later to, well, switch randomly between our objects.

Okay now for the meat and potatoes of this setup. After the Switch node, drop down a "Copy" SOP and connect the Switch to the first input and the Particle Network to the second input. Then add a "Null" node at the end just to finish it off. (We'll be referencing back to this Null node when we go into DOP's)

Let's take a look at this Copy node.
For starters, on the "Copy" tab I checked on "Create Output Groups". We need this to be on for our setup in DOP's to see our objects. You can leave the "Copy Groups" parameter to it's default if you want but I changed mine to "piece_`$CY`_`$PT`". Essentially it's just there to add a different name to each piece when we bring it into DOP's so even "piece_`$PT`" will do just fine.

On the "Stamp" tab is really where everything is taking place.
We need to enable "Stamp Inputs". For the most part, the only things we want to randomize are the object, the object size, and the object's rotation. Here's how I've got my copy node setup:

If you know your basic fit01 expression then most of this is pretty self explanatory, but the expression I have for the "objSwitch" is a little different:

int(round(fit01(rand(@ptnum + $FF * 1000), 0, 3)))

All this expression is doing is taking a random number between 0 and 3 (3 being the number of different objects I have), then rounding it to the nearest whole number.
The only other thing left to do is transfer over any Velocity from our Particle Network. Again, we won't have any in this case becuase we are killing the particles as soon as they are born but if you have a different setup and need to transfer the Velocity you can actually do it inside the Copy SOP on the "Attribute" tab. All you need to do is type in "v":

Now that we have our Copy node up and working, we need to actually apply this to our scene because currently it's not doing anything.
In order to make use of the variables we made in the Copy SOP we need to apply them to our objects using the "stamp" expression:

stamp("../copy1", "objSwitch", 0)

So in this case we would use this expression on our Switch node because we know that the "objSwitch" variable that we made on our Copy node will return a random value between 0 and 3 (because we have 3 objects).

This will now randomly switch between each object we have

Now we need to take care of the "objSize" and "objRotate" variables.
Well, because we want the "objSize" variable to control the overall size of our objects, we can add a Transform SOP between the Switch node and the Copy node and then add the "stamp" expression to the Scale parameter on the Transform SOP:

And finally, to add random rotation to each object I decided to add a Transform node under each object and then apply the "stamp" expression to each Transform node:

Now let's emit some Rigid Bodies!!

To make the DOP network setup easier, I just clicked on the Ground Plane shelf tool to get things going.

To bring in our emitted geometry into DOP's drop down a "RBD Fractured Object" DOP and link the "SOP Path" to the Null node we made earlier. The key to getting this to work is to also change the "Group Mask" to "piece_*". This will go and look for the output group names that we made on the Copy SOP. Connect this node up to a Rigid Body Solver and your done!

Now when you play the simulation back you should see all your objects appear each frame and they should fall down and interact with whatever else is in your scene.

Pretty simple stuff but extremely useful when you want to pile up a bunch of objects.

Until next time, happy sims!