Bullet Physics Tutorial

JoeMamma2000JoeMamma2000 Posts: 2,615
edited June 2013 in Carrara Discussion

I took some time to write down some basic steps and points to consider when using the Bullet Physics feature of the newest Carrara.

I apologize if it's not real flashy with a lot of pictures and stuff, but I didn't want to spend the time figuring out how and where to host a big writeup.

So, for those interested in making realistic simulations using Carrara’s Bullet physics simulator, here is a tutorial which includes building and simulating a chain swinging under realistic forces, using the Bullet Rigid Body simulator.

Here’s an example of a successful simulation on two chain objects under some fairly drastic motion:
http://www.youtube.com/watch?v=Mw9kk2pbtpA

And here’s an animation with the two chain objects integrated with a character:

http://youtu.be/ruM_nIaO0Ks

First, some basic points you need to keep in mind regarding physics simulators in CG apps like Carrara:

1. MOTION: The most difficult challenge for physics simulators is during the time when objects collide. If two colliding objects are going so fast that their surfaces pass inside each other between frames of the animation, the simulator may have a very difficult challenge to realize that, and reposition the objects so that doesn’t happen. Determining whether some polygons have moved “inside” some other polygons can be a huge challenge for a software algorithm. Therefore, physics simulations are more likely to fail when the motion, or the change in the motion, of the participating objects is high. So you want to avoid those situations when (and if) possible.

2. MESH DESIGN: Physics simulators generally tend to solve better when the objects involved in the sim are made of a clean, uniform, and dense mesh. This is very important. In fact the mesh design might mean the difference between a successful and a failed simulation. And a well-designed mesh might be the only way to achieve a successful solution under the most challenging motion conditions. This means you should be very careful before considering using objects that were not necessarily designed for use with a physics simulator. Those objects might contain non-planar polygons, n-gons, 2 point polys, co-planars, duplicates, or any other types of mesh that simulators might have difficulty with. On the other hand, the objects might work fine. However, you should decide whether it’s worth the effort to verify their suitability rather than just making your own.

3. SIMPLIFICATIONS: Since scientifically accurate simulation of physics motions would take far too long to calculate, CG simulators use various simplification methods to speed up the solution, while still giving a visually accurate result. And they usually allow users to select how much simplification the simulation will use. Depending upon the simulation, sometimes you can take full advantage of some of these simplifications, and sometimes you can’t. If you suspect your animation with have a lot of motion, it might be best to initially disable those simplifications in order to get a successful simulation.

4. SETTINGS: Make sure all associated physics simulation settings have been identified and are correct or reasonable before you attempt a simulation. This includes not only the global settings (under the Scene/Physics tab), but also the Effects parameters for each object participating in the sim.

5. COLLISION SPACING: Make sure all physics objects are initially spaced further apart than the set collision distance. This is very important, otherwise the simulation might fail. Also, too small a collision distance setting might cause simulation failure.

Now that we have some basic points to consider, let’s build our chain. I’ll do this in Hex since I find it far easier.

1. In Hex, go to Lines, then Circle from Center, and draw out a circular line. Then under Surface Modelling, select Thickness, and apply a thickness. This will give you a solid ring of 160 polygons. Of course at this point you’d also set up your shading domains and UV mapping, but that’s outside the scope of this tutorial.

2. Export the ring in Carrara format, then import into Carrara.

3. Select the ring, then under Motion tab select “Still” from the dropdown menu. This will make the ring fixed in space during the simulation, and you won’t be able to keyframe it. However, it will also allow you to later switch between physics motion and still motion without generating unnecessary keyframes, which can take a long time.

4. With the ring still selected, select Edit/Duplicate to make another identical ring. Note that when you use the Duplicate function, future changes to all the duplicated ring(s) will ripple thru all the other duplicates, making global changes/updates to all links in the chain automatic and instantaneous. This might come in handy later if you want to subdivide the mesh of all rings in the chain, for example.

5. Now that you have a second ring, change its motion to Physics instead of Still. To do this, under the Motion tab select Physics from the dropdown menu. Then move it down so it’s so it’s still linked with the top ring, and approximately in the middle of the upper ring. Then rotate 90 degrees.

6. Hit the Simulate Physics button in the upper left corner of your screen. You’ll probably see the lower ring bounce crazily inside the upper ring, and depending upon how you placed the lower ring, maybe even fall thru and off into space. Not good.

So apparently we violated some or all of the basic points mentioned above.

Let’s take a step back and reconsider what we’re doing.

First, let’s make sure that the global settings for the simulation are reasonable (Point #4 above). Select Scene in the Instances tab, then under the Physics tab you’ll notice there are 4 settings: Simulation Accuracy, Geometric Fidelity, Collision Distance, and Gravity.

Simulation Accuracy is an example of Point #3 above. The Bullet simulator allows you to specify how much of a simplification is made in order to speed things up. For simple simulations, with little motion to calculate, you’ll need less accuracy. But for fast moving and difficult sims, you’ll need a lot of accuracy. So step #1 is to crank this value up to a maximum, which is 1000%. Now, run the sim once again, and what do you see? Well a little less craziness, but not much…and the ring probably still flies off into space. And you’ll also notice that the sim took a bit longer to run. But since the simulation is still not well behaved, then clearly we have some other problems.

However, leave Simulation Accuracy at maximum, because our goal here is not a fast simulation, it’s achieving a successful simulation. And it’s probably a good working practice to normally put this setting at maximum while you’re learning about how the simulators work.

Now move to Geometric Fidelity. This is another simplification, which allows you to simulate complex geometry, which would take a long time to calculate, with a much simpler geometric shape during collision detection. However, while this might gain some speed in calculating the sim, it may also result in a failed collision detection. So crank this value up to maximum (100%), and rerun the sim. Not a lot of difference, the lower ring flies off into space.

And as you did with Simulation Accuracy, leave the Geometric Fidelity at maximum. Again, probably a good general practice while you’re learning.

Now look at Collision Distance. This is pre-set at 100%, which is a distance in percent of the basic unit of distance in the scene. In a medium scene, which is 30x30x30 feet, a 100% collision distance appears to be approximately 0.13 feet (about 1.5 inches), which, FWIW, is a bit larger than the standard Carrara unit of 1 inch. You can check this by placing a sphere between the two colliding objects (with Geometric Fidelity set at 100%) and re-sizing the sphere until it fits exactly between the two objects. You’ll notice that a 100% Collision Distance setting leaves a fairly large gap between the objects, so crank that value down to around 10%. Then make sure that all of your interlocking rings are initially spaced more than 0.15 inch (10%) apart (use a sphere to check if you want…), and rerun the sim. You may notice that the sim doesn’t fail, but there’s still a lot of bouncing around.

For now we’ll leave the Gravity setting as it is.

Next we’ll look at the physics parameters for each of the physics objects.

First select the top ring since, even though it’s not a physics object, a physics object will collide with it. Then under the Effects tab you will see the other parameters which affect a simulation.

Leave the default “collide with” settings checked, as well as the default Density of 1.0. The Density is basically a measure of the object’s weight, but more specifically the density of the material the object is made of. And Density is, by definition, the weight of a given volume of material. A 1 inch cube of steel weighs more than a 1 inch cube of jello, because it has a higher density. But for purposes of this sim you can just assume it’s a measure of the object’s weight.

Now the two remaining settings are Bounce and Friction. You’ll probably find that these two parameters are surprisingly, and perhaps unexpectedly, very important in achieving a successful simulation.

Bounce, as you might guess, gives an indication of how much bounce occurs when objects collide. If you drop a golf ball on a tile floor, it will bounce more than if you drop it on a carpet. And Friction tells you how much two colliding objects slide against each other.

Now you may have noticed in the simulations that the two rings are very bouncy when they collide. And that might cause a problem with Point #1 above. The more they bounce, the more high speed collisions must be detected, and the more likely it is that one of those collisions might fail. So unless you need a lot of bounciness, let’s set the Bounce slider near 0 for BOTH rings. Then re-run the sim.
Suddenly you’ll notice the sim is very solid and well behaved, and the chain remains intact. So we’ve learned that a high Bounce setting in EITHER colliding object can cause problems. Which means we probably want to develop the habit of setting Bounce for our objects close to zero, at least while we’re learning. And fortunately, in this case, a low Bounce setting is appropriate if you’re simulating, say, a galvanized metal chain.

Now that you have some decent global settings and object parameter settings, you can start duplicating your ring to make a chain.

Select the lower ring, then Edit/Duplicate, and move that new ring down and rotate. Then select the lower two rings, and repeat. Then the lower four rings, etc. Keep repeating until you have a chain with 16 physics links and one fixed link at the top whose motion is set to Still.
Now re-run the sim, and you’ll notice you have a nice, well behaved simulation of a hanging chain.

Just for fun, let’s change all of the links to have a very low value of Friction. Select each link, and set its Friction slider around 5%, and re-run the sim. Wow, after a couple of seconds, suddenly your well behaved sim starts falling apart. By having little or no friction, you’re allowing the colliding objects to have a lot of motion between them as they collide, which is at odds with Point #2 about relative motion between colliding objects.

So now that we know that Friction is our friend, re-set all of the friction values up to high values, near the default 85%.

Now we have a fairly well behaved, although very boring sim. And so far we’ve learned the following basic guidelines:

Start out with:
1. Max settings for Simulation Accuracy and Geometric Fidelity
2. Approx. 10% Collision Distance
3. Material parameters of very low Bounce and very high Friction.

Okay, now let’s make the sim more interesting, and throw it more of a challenge…

How would a real life chain respond if you suddenly yanked it, say, 10 feet to one side and back in a couple of seconds? Well, that’s pretty drastic motion, and not something you’d normally see, right? And you’d expect the reaction of the chain to be fairly violent, right? So let’s try that as an extreme example of motion. And if we can get this to work, we’ll feel pretty confident that less violent motions would work.

So animate the top link to move 10 feet to the left at the 1 second point of the animation, then back to its starting point at 2 seconds. Don’t worry that only your top “Keyframe” link moves when you animate it, and the physics links just stay there. Once you run the simulation the physics links will follow along.

Now run the sim. You’ll probably get a failure of the chain, since we’ve given the simulator a speed overload, in direct conflict with Points #1 and #2 above. We’ve given a lot of motion between frames, and although we’ve given it high Simulation Accuracy and Geometric Fidelity to help the calcs, apparently that wasn’t enough. So let’s reach into our bag of tricks by re-reading the five points at the start of this tutorial, and see if we can find some other way to help the simulator obtain a successful simulation.

The one thing we haven’t addressed yet is Mesh Design. We’ve generated what we can assume is a clean, uniform mesh with, presumably, no nasty geometry that would choke the simulator. However, the one thing we haven’t considered is Mesh Density, one of the most important factors in achieving success under difficult conditions. So let’s improve that. We’re starting out with links that are composed of something like 160 polygons.

Select the top link, go into the Modeler Room, select the entire object, then choose Subdivision/Smooth/Level 2, then Convert. And since you used Duplicate to initially generate all of the other links, that subdivision will automatically occur in all the other links simultaneously. So instead of 17 links with only 160 polygons each, we now have 2560 polygons per link.
Now re-run the sim….

SUCCESS !!!

You’ll notice it takes a lot longer to calculate the sim, but the result is a well behaved sim that even responds well to extreme motion. And the only difference between success and failure was an increased mesh density.

So now we’ve generated a high motion physics simulation by following a few basic principles. Of course, now you can modify those settings to suit your particular needs. Some things to consider:

1. If it’s really important to you that you don’t wait a long time for the simulator to do its calculations, and/or your animated motion isn’t as drastic, you might try pulling back the max settings for Simulation Accuracy and Geometric Fidelity. But if you can wait for the simulation to do its thing, why not keep them at maximum?

2. You also might try objects with less subdivision depending upon the motion you’re applying. After a bit of experimenting, you’ll probably find that you can get a successful simulation with our link animation using a far less dense mesh.

3. Keep in mind that you don’t need to have the entire physics object with a dense mesh, only those surfaces which are colliding. So you might try tesselating/subdividing only the colliding surfaces, and leaving the rest of the object at low resolution to speed things up.

Post edited by JoeMamma2000 on

Comments

  • HeadwaxHeadwax Posts: 10,004
    edited December 1969

    Nice work again Joe, thanks for that. Very informative and kind.

    Questions: are you using 8.1 release or the beta?
    How is it working for cloth "sims" at the moment?

    thanks in advance

  • Box8068_31c338ee4bBox8068_31c338ee4b Posts: 292
    edited December 1969

    Great Info.
    Thanks for posting this!
    8068

  • evilproducerevilproducer Posts: 9,050
    edited December 1969

    Thanks for the tutorial Joe. If you ever decide to put a more detailed version together or even an example scene you wish to share, you can upload .zip files up to 5 MB in size at the CarraraCafe.com's forum.

Sign In or Register to comment.