Tuesday 16 May 2017

Sam's Rigid Bodies notes

Backup of Sam's Rigid Bodies notes

Rigid Bodies

General


When creating a rigid body object the main ingredients to create anything dynamic is to have the following nodes: RBDpackedobject, rigidbody solver (not rbd solver), gravity, groundplane, merge (to merge groundplane and gravity), output.

When Houdini computes rigid bodies for collisions, it converts them to convex hulls. Convex hulls is like creating a sphere around your geometry and shrink wrapping it around your geometry. The geometry won’t be perfect but it will try to be as close to your original geo as possible. You can change the method of the geometry representation in the rbdpackedobject DOP. This can be changed to things like sphere or boxes depending on your desired simulation look.

When working with packed geometry all points are 4x4 transformation matrixs. It looks something like:

[X] * [ 0.0 0.0 0.0 0.0 ]
[Y] * [ 0.0 0.0 0.0 0.0 ]
[Z] * [ 0.0 0.0 0.0 0.0 ]
[1] * [ 0 0 0 1    ]

Green means rotation and red means translation. The X Y Z 1 represents each point. The bottom numbers aren't anything you need to worry about.

Voronoi Fracturing Geometry

Random Fracturing - Iso offset

When fragmenting your geometry, place an isooffset and then a scatter. This will place points inside the geometry instead of on the surface. These points you create will kind of be the center of the vorononi pieces.


When scattering you can turn on relax iterations, this will recompute the point placements when changing the amount of points on the geometry. You can add a noise deformer under the isooffset SOP to break up the scatter placement of the points.

Plug in a turbulent noise and clamp it between 0, 1 or max it with a constant. You can also plug a ramp parameter after the max DOP to push the low and high values, just like a remap in maya.

If you want to break up certain areas on top of the original voronoi fracture, you can create a foreach loop.

Inside the foreach loop, place a null, scatter and a voronoi fracture. Plug foreach_begin into the null > scatter > voronoi fracture 2nd input. Plug the foreach_begin into the first input of the voronoi fracture. On the for each begin, click create meta import node.

On the scatter node, scatter the points by density instead of force total count.

Create a switch node and plug in the foreach_begin and voronoi fracture and type the following into the select input:
rand(+3008+detail("../foreach_begin1_metadata1/", "iteration", 0)) < 0.4 && npoints("../scatter4/") > 1.

You can change some of the values to get the desired look you want.

On the foreach_end change the attribute to name.

NOTE: It’s a good idea to push more scatter points across the area of impact.

Precise Fracturing Points - Painting


If you want to create an even more precise voronoi you can paint where you would like more fracturing to happen.

To do this make sure your geometry has enough detail as you will be painting directly onto the points., if it is quite a low detail you can place a divide and turn off convex polygons and turn on bricker polygons.

Once you are happy with the detail of the mesh, place a paint node down. Paint on the mesh with a white brush where you want more detailed fractures to happen.

Then place a point wrangle and type the following:
@Cd = lerp(@Cd.x,1,ch("blend"));

This will blend the white and black parts of the mesh so there is a gradient of points/fracturing. You can then place two blast nodes down and separate the white and black into two separate branches. Use @Cd.x>0.5 & @Cd.x<0.5 to do this. Make sure to change the blast to points.

Place a scatter after each of these and then type in the desired amount of points you’d like to scatter in the more condensed (white) areas and the less condensed (black) areas. Once you're happy with the amount of points merge these two back together.

Then place an attribute randomise down with the attribute name “rep”, change the max value to something like 10.

Place another attribute randomise and give it the name “pscale”, increasing the min value.

You can also place a point replicate to replicate points around the points you have created. If you do this, you can change the method to a shape instead of quantity.

After this place your voronoi fracture. You can change the look of the fracture by going back to the paint SOP and painting certain areas differently, or you could change the scatter amount on the less dense areas for example.

Precise Fracturing Points - Procedural


If you want to create an even more precise voronoi you can paint where you would like more fracturing to happen.

To do this, place an add node or curve. For the point method, add your point and turn it on. Use a transform node to where you’d like the more precise fracture to happen. For the curve, draw your nurbs curve to whatever shape you want and resample the curve.

From the geometry, place a polygon to VDB on a separate branch. Lower the value of the VDB to get a higher resolution VDB. Also change the the VDB to fog.

Then place down a volume VOP and plug the VDB into the first input and point or curve into the second input.

Inside the volume VOP place a pcopen VOP and plug in P and second opinput, promote the radius and maxpoints. Double click on the promoted radius so the parameter node appears.

Then place a pcfilter after the pcopen and a pcnumfound which will also go after the pcfilter in a separate branch. Add a compare after the pcnumfound and change the test to greater than.

From the pcfilter add a distance into the second input, “P” from the global input goes into the first input. From the distance, add a fit range and plug it into the first input. The second input will be radius parameter that was promoted earlier.

Finally, multiply the fit range against the compare VOP and plug the multiply into the global output.

To break up the edges of where the smaller fractures will be, you can add a turbulent noise and add it to the multiply that you have created.

On the SOP level you can change the search radius so the search area is larger or smaller, depending on your desired look.

Place a scatter node after the volume VOP. From your VDB from polygons, place another scatter node down on a separate branch. Change the force total count on both these scatter nodes and merge them together. Remember to turn off relax iterations.

On the second branch you can place an attribute randomise down with the attribute name “rep”, change the max value to something like 10. Change the dimensions to 1 as it is a float.

Place another attribute randomise and give it the name “pscale”, increasing the min value. Change the dimensions on this 1 also as this is a float.

You can also place a point replicate to replicate points around the points you have created. Turn on generate from attribute and type rep. Then you can increase/decrease the points per point.

Finally, voronoi fracture the scattered points.

Creating the name attribute


If you are going to fracture some of the pieces that you have already fractured like the random fracturing method above, you won’t be able to rely on the name attribute. To get around this, place a connectivity SOP and change its method to primitives. Then a point wrangle and type the following:

s@name = sprintf("piece%d", @class);

If you are assembling the geometry and have copied your geometry to make a building lets say. You will need to rename your geometry as you will have multiple geo with the same name attribute name.

To do this place a point wrangle and type the following:

s@name_orig = s@name;
s@name = sprintf("inst%d", @ptnum);

The first line is saving the original name given in the first primitive wrangle. The second line is renaming all of the pieces with their own unique name attribute.


Assemble - Geo ready for Simulation


When working with rigid bodies, it's best to pack your geometry. You can do this by using the “pack SOP”. The pack SOP packs all the points, vertices etc into 1 points. It is like instancing in maya. When you pack the geometry, Houdini creates something called intrinsics. This is all the information of the geometry packed away in attributes. The reason you pack all your geometry is because Houdini can compute the simulation a lot faster. You can have tens of thousands of pieces of geometry packed into single points and you can will still be able to simulate a lot faster than if you tried to compute each piece of geometry that had 2000 points.

NOTE: When the point is created it is created as a centroid. This centroid stores attributes like velocity (V), angular velocity (W).

Instead of using the pack SOP, use the assemble SOP. This is the same as the pack SOP except it comes with some extra attributes like “name” or “class”. The assemble node is handy when wanting to fracture geometry. The assemble node can give the voronoi an attribute called “name” or “piece”. This will give each piece created from the the voronoi and Id number.

Working with Constraints

Constraints - Noise (More control)


If you are fracturing the geometry and want to constrain certain pieces together, It’s best to use 2 assemble nodes.

The first assemble SOP will give each piece of geometry a name attribute. To do this turn on “create name attribute” and “connect inside pieces”. The output prefix should be called “piece” you can add a prefix to this if you are using multiple assembles on different pieces of geometry. Place a null down after this and called it “name”, you will need this later.

The second assemble comes after the name null created before, on this one turn off create name attribute and turn on create packed geometry and connect inside pieces. Delete the output prefix name.

To create your constraints, you want to do this on the unpacked geometry. So you will need to do it on a separate branch from the second assemble which packs the geometry ready for simulation.

So, in a separate branch create a connectadjacentpieces SOP. Change the connection type to “adjacent pieces from surface points”. Play around with the search radius and max search radius to get the desired amount of points each piece will look for to connect too. Change the max connections to something like 1 or 2.

Once happy with that, you could place a primitive VOP and create a turbulent noise that is connected into a fit range, lowering the source max so the lines created from the connect adjacent pieces don't have a gradient from black to white. You will be able to visualise this if you plug the fit range into the Cd of the output. Finally plug your fit range into a bind export and name it “strength”.

Facet your primitive VOP and then place an attribute wrangle and type the following:

s@constraint_type = "all";
s@constraint_name = "pin";

Finally, place a primitive SOP down and turn on “do transformations” and change the scale to 0.

NOTE: Strength is a recognised attribute inside the DOP network.

NOTE: If you are using the 2 assemble node method, make sure you change the connection type on the connectadjacentpieces node to “adjacent pieces from surface points”.

If you have colliding static geometry, it’s best to pack this geometry too. This is so you can bring it in as a rbd packed object inside the DOP network.

Constraints - Expression (Random)


Another method instead of using a primitive VOP to create your strength is too place a primitive wrangle and type to following:

s@constraint_name = "glue";
f@strength = 1.0;

In the primitive wrangle created earlier, you can also add an expression to make a super strong constraint to a certain amount of points. To do this type:

if(rand(@primnum) < 0.15){
   f@strength = 10000;
}

The value after the @primnum can be changed to whatever you would like, this will control the amount of points selected. The strength value is the strength of the glue.

Constraints - Expression (Clustering)


After you have placed your connectadjacentpieces, drop a pointVOP down. Inside, create a voronoinoise and promote the frequency. Then create a bind export and give it the name “cluster”, changing it to an integer.

After this, place a primitivewrangle and type the following:

Int pt0 = vertexpoint (0, primvertex(0, @primnum, 0));
Int pt1 = vertexpoint (0, primvertex(0, @primnum, 1));

Int cluster0 = point(0, “cluster”, pt0);
Int cluster1 = point(0, “cluster”, pt1);

if(cluster0 == cluster1){
s@constraint_name = “Glue_Inside”;
} else {
s@constraint_name = “Glue_Outside”;
}

f@strength = 1;

This is essentially saying that from the connect adjacent pieces lines created earlier and the clustering VOP. If you are from the same clustering piece you are really strong. However, if you are connected to another piece from the connectadjacentpieces and not from the clustering VOP, you are not as strong.

You will be able to control the strength of inside pieces and outside pieces differently which can really help your simulation.

Constraints - Metaballs & Forces


Using this method will delete the glue from the radial force of the metaball.

NOTE: Hard constraints, like the methods above give a much more realistic look and are easier to work with.

A good way to create forces to your rigid bodies is to add a metaball force. To do this, create a metaball and add a force node, this is the same as adding a wrangle and typing in the force expression.

You can place the metaball where you would like then add it to a switch with a null attached. You can add an expression into the switch so it only applies the force occasionally. Something like “$F==1003”, this will switch to the metaball every 1003th frame.

In the DOP network, plug in a popmetaballforce into the solver and connect the SOP path. Negate the force scale because by default a metaball force implodes instead of exploding.

Sometimes you might want to visualise the constraints frame by frame, Houdini doesnt do this manually so you have to set it up yourself. To do this, place a SOP solver and plug it into the constraint network.

Inside there, place an object merge and merge in the your rbdpackedobject from the DOP level, you wont want to bring in everything, just the geometry, so your object merge should be something like: ../../rbdpackedobject1/geometry/.

Add a pointwrangle, first input is the relationship_geometry, second input is your object merge. Inside the wrangle type the following:

int pt = findattribval(1, "point", "name", @name);
@P = point(1, "P", pt);

You then want to place another object merge, this time, you want to bring in your metaball OUT null. Place a group node and plug the metaball into the secondinput and the wrangle into the first. Change the bounding type to bounding object, and call the group active.

You will need to promote the group to the primitive level using a group promote and adding the group activate. Then copy the group “activate”, to the wrangle stream, using a group copy.

Place another wrangle and apply it to the activate group and type the following:

@group_broken = 1;

Finally clean up the groups with a group delete and plug it into the OUT. You may need to lower the glue strength on the outside pieces to see some real distruction.

Activating rigid bodies manually


Sometimes you may want to control where the simulation starts or the speed everything falls, To do this you will need to create active groups.

After placing your assemble node that packs the geometry. Create a group node and name it “active”. Turn on bounding box, from here you can either animated the size and center of the bounding box or you can plug in your own shape that animates. To get better, more realistic results, plug in your own shape. Something like a sphere with a noise deformer on it. On the group node, make sure you turn the bounding type to bounding object and change the group type to points.

You can create multiple active groups so the simulation starts in multiple areas. One key thing to remember is to change the initial merge to “union with existing”. If you don't do this, you will keep overwriting each active group node.

Once you are happy with the group activation animation, place an attribute create and name it active. Make it an integer and make sure the group at the top has the active group created before. Also change the value in X to 1.

After the attribute create, put down an point wrangle and name the group “fixed”. Inside the point wrangle type the following:

i@active = 0;

This will keep all points that aren't active from the group stationary. To visualise which pieces are being activated over time you can create a blast node on a separate branch from your attribute wrangle and type the following:

@active==1

You can actively control sections of your simulation, like the height threshold, so if pieces are closer to the ground, they don't break (a bit like foundations on a building). To do this, place a point wrangle after your assemble and type the following:

if (@P.y < ch("height_threshold")){
   i@active = 0;
} else {
   i@active = 1;
}

Click the small slider on the right of the box to create a height threshold slider. On a separate branch add a delete node and type @active=0 into the group name and change it to delete non selected and change it to points. (This is more for visualising, this will not go into the simulation).

DOP network - rigid bodies


To fracture the geometry that has been set up. Inside your DOP network place a bullet solver and plug it into a constraint network. Inside the constraint network DOP, change the “constraint network” to whatever the constraint nulls called that was created earlier.

Create a hard constraint relationship DOP and plug it into the second input of the constraint network. Change the data name to “pin”. This attribute should have been made earlier in the connect adjacent pieces branch. Change the rest length to 0 and increase the constraint force mixing.

You can also work with SOPs on a DOP level. To do this, create a sopsolver and plug it into the third input of the constraint network. You may want to do this to control the things like the break threshold of the constraints.

If you want to control the break threshold of the constraints, go inside your SOP solver create a primitive wrangle and place it under the relationship geometry SOP. Then type the following:

if (f@force > ch("breakThreshold") * f@strength) {
   //i@group_broken = 1;
   removeprim(0,@primnum,1);
}

You can click the small slider button on the primitive wrangle and promote the attribute to the DOP level. This will be easier when controlling the threshold.

Above the bullet solver you need to plug in your fractured geometry and static geometry if there is any. Place a RBD packed object and connect your fractured packed geometry into the SOP path. Make sure you tick “overwrite attribute” and rename it “active”.

If you need to plug in static colliding geometry, make sure that is packed too and create another RBD packed object. All you need to do is merge this with your fractured (moving) packed object. Make sure that the static geometry are the first inputs.

Your geometry be rolling around a bit more than it should be, this could be because the convex hulling has rounded the edges off. To help this, go to your RBDpackedobject and lower your collision padding to 0.1.

On the RBD packed objects, on the physical tab you can change the friction and bounce properties of the object. As a starting point, lower the friction and bounce.

NOTE: You can connect POPs into the DOP network when working with rigid bodies, like the drag force for example.

DOP import to SOP level


When bringing the simulation to the SOP level you may not want the ground plane or some other constraints etc. You can choose what objects you want to bring out of the DOP network by typing in the name of your object on the DOPnetwork SOP > Object Merge > Object.

Another way to do this is (which is a better way, as you can do this in different Geo Nodes) to place a DOP import SOP. Choose which DOP network you are wanting to import, type in which object you want to bring out of the DOP network into the Object mask.

When done with simulating, you can move point by point your heavy geometry to the pack geometry position. If you want to move everything you can just unpack the simulation. However, to move point by point you can place a point wrangle after a null under the DOP network and type the following:

matrix M = primintrinsic(1, "packedfulltransform", 0);
@P = @P * M;

Plug the null into the second input and the unpacked geometry into the first input. This technique is basically moving each point to the new location.

Adding a post displacement


As the voronoi fracture is a bit basic in terms of detail, you can add a post displacement. This can be done at render time but it's sometimes nice to visualise what the displacement looks like before rendering.

You may even want to do the post displacement and then a render time displacement to get extra detail. As you might be working with high resolution geometry already, you may as well add this bit of detail.

NOTE: Doing this method will make your scene a lot slower as you are subdividing the mesh quite a lot. Obviously this can be controlled to what your desired effect.

To create the displacement you will need to displace your fractured object at a rest position and transform the pieces back to the the simulated position.

Place an object merge and bring in your geometry at a rest position. Delete any colour on the object. You will want to divide your mesh using a divide SOP so you can add detail. Change the size to whatever subdivision you’d like.

Create a bound SOP and blast away the top and bottom edges of the bounding box. Place an attribute VOP. Plug the divide into the first input and the blast from the bound SOP into the second input.

Inside the attribute VOP place an xyzdist plugging “P” into “pos” and “opinput2” into “input”. Plug the xyzdist into a fit range. Sliding the source max will control part of the displacement later once the rest of the VOP is set up.

Create a trubulent noise “3D” and promote all the parameters. Plug “P” into “pos”. Also create a constant vector and change the values to 1, 0, 1.

Once you have these 4 VOPs created, place a multiply and connect the turbulent noise into the first input, the constant into the second input, and the fit range into the third input.

Then place an add VOP and plug “P” into the first input and the multiply into the second input. Finally, plug the add into the output VOP “P”.

Outside the VOP you will want to place a transform pieces, plug the displacement VOP just created into the first input and your cached simulation into the second input. Make sure you change the attribute to “name”, this should be default anyway.




2 comments:

  1. Very nice notes here. Could you please post example hip files! It's make it easier to follow a long. Thanks. This is gold.

    ReplyDelete
    Replies
    1. Sadly not, as I don't have a reliable space to host them! This blog is mostly for my own reference and is a big mix of things I pick up as I work, or find through much trawling of odForce or Matt Estella's great site. This post in particular is just a backup of a colleague's notes from a video-tut (a Stephen Knipping one I think)!

      Delete