Part II
Physics and Simulations
- Chapter 5: Getting Flexible with Soft Bodies and Cloth
- Chapter 6: Working with Particles
- Chapter 7: Volumetric Fluid, Smoke, and Fire
- Chapter 8: Bullet Physics and the Blender Game Engine
Chapter 5
Getting Flexible with Soft Bodies and Cloth
In nature, materials exhibit different properties of rigidity and structural responsiveness to the forces on them. Many materials are flexible and deform when acted upon by forces such as gravity and friction. Blender’s soft body simulation enables you to easily represent the behavior of a wide variety of flexible materials. Depending on the parameter settings you use, you can use soft body simulations to animate materials as varied as gelatin, sheet metal, and cloth.
In this chapter, you will learn to
- Control the behavior of soft body objects
- Work with force fields, collision objects, and modifiers
- Work with cloth and clothing
The Hard Facts on Soft Bodies
One of the basic aspects of animating with meshes is mesh deformation. In Blender, there are many ways to deform a mesh. You can use shape keys, hooks, and modifiers such as armatures, lattices, curves, displacement, waves, and others. Each of these methods enables different kinds of deformations, and the combination of them yields a considerable amount of control for animators. Nevertheless, some kinds of deformations are still difficult or impossible to achieve convincingly without a dedicated simulation. Soft body physics is a good example of this kind of deformation.
Soft body dynamics refers to the way that flexible materials deform in response to the forces on them. In real life, many things we deal with all the time exhibit soft body behavior: cloth, rubber, paper—even metal, when under the right kinds of stress. These objects bounce, crumple, and jiggle in ways that would often not be practical to animate by hand. By setting up a soft body simulator, you can get Blender to do the work for you.
Soft body simulation is one of Blender’s physics simulation functions, which are found in the Physics properties area shown in , when an appropriate object is selected in the 3D viewport.
Understanding Soft Body Basics
Soft body dynamics works by treating a mesh as a network of springs. In the default case, the edges of the mesh are given springlike behavior, as visualized in .
When a soft body simulation has been created on an object, you can set parameters to determine how these “springs” react to forces and how the soft body simulation itself interacts with the mesh. These parameters can be set in the Soft Body tab in the Physics properties area shown in , after you have activated soft bodies for an object by clicking Soft Body. The parameters to determine forces are as follows:
Friction Friction determines the degree to which the soft body simulation is affected by external forces.
Mass Mass determines how much force is necessary to deform the soft body. Higher mass values lead to slower movement, less responsiveness to impacts, and greater momentum after the mesh is in motion.
Speed Speed determines how quickly the simulation moves. Unlike Mass, however, Speed does not affect how much force is needed to deform the object.
The Soft Body Goal and Soft Body Edges check box options restrict the freedom of the soft body simulation’s movement.
Soft Body Goal Soft Body Goal restricts the simulation according to the weight values of a specific vertex group. Vertices with a value of 1 for the goal weight are not treated as soft bodies at all, and vertices with a value of 0 are deformed completely by the soft body simulation. Vertices with a 0 goal value are not influenced by ordinary mesh deformers such as armatures. The degree to which vertices are held to their original position is determined by the parameter values in this section, as you’ll see.
Soft Body Edges The Soft Body Edges option restricts the deformation of the soft body by affecting the spring properties of the edges. The stiffness of the edges is controlled by Pull, which affects how far the springs can extend, and Push, which affects how far the springs can compress. Damp affects the force necessary to compress or extend the springs. You can visualize damping as being similar to the effect of hydraulic shock absorbers, as shown in .
The Bending value controls the degree to which vertices allow edges to move freely in relation to each other. When the Stiff Quads option is selected, the diagonals across each quad face are also treated as springs, as shown in . In this case, the Shear value controls how strong the diagonal strings are. The Aerodynamics value adds an effect that is similar to friction but results in a more-localized fluttering of the edges.
Baking
Soft body simulations can be baked to a cache for quicker access in subsequent plays of the animation. Baking for soft bodies and cloth is done on the Soft Body Cache tab, shown in . Simply enter the values of the start and end frames for the time period you want to bake, and click the Bake button. You can also manage multiple caches on this tab, so that multiple simulations will not be overwritten.
Animating a Spring with Soft Bodies
Because springlike behavior is so central to the way soft bodies work, this section demonstrates the simplest possible soft body setup, just a single edge, by using it to drive the motion of a posable spring. You can find the file bouncing_spring.blend on the website for this book. To create a Soft Body object that will control the movement of the spring, follow these steps:
1. The Soft Body object you’ll be using will be composed simply of two vertices and an edge. I’ve created this by adding a plane (see ) and deleting two of the vertices (see ). Any simple Mesh object will do for this.
2. Select the armature and enter Pose mode. Select the lower control bone, as shown in , and snap the cursor to that bone, using Shift+S to access the Snap menu and choosing Cursor To Selected. Return to Object mode, and select the Mesh object; enter Edit mode, and select one vertex.
3. Snap the vertex to the cursor with Shift+S and then choose Selection To Cursor, as shown in .
4. Return again to Object mode, and add an empty to the same point, as shown in . Because there is already an empty in the scene (the one controlling the Array modifier), this new empty will be automatically named Empty.001.
5. Go back into Pose mode and select the topmost armature bone. Then return to Object mode, select the two-vertex Mesh object, Shift-select the armature, and bone-parent the Mesh object to the bone by pressing Ctrl+P and choosing Bone, as shown in .
6. Select the empty, and then Shift-select the Mesh object. Tab into Edit mode and select the lower vertex; then press Ctrl+P to vertex-parent the empty to that vertex, as shown in .
7. To make the empty’s movement control the armature, set up a Copy Location constraint for the bottommost bone. To do this, select the armature and enter Pose mode. Select the bottommost control bone and add a Copy Location constraint targeted to the empty, as shown in .
Now it’s time to set up the Soft Body object. A common way to control soft bodies is by use of a vertex group and a goal. When this option is used, vertices that have a high weight for the group are fixed in place to the mesh’s ordinary shape (including any non-soft-body deformations) and are not influenced by the soft body simulation. Vertices with a low goal weight are freer to move around in accordance with the soft body simulation. The Mesh object in this example has only two vertices. You will use a goal vertex group to nail the top vertex in place, while allowing the bottom vertex to exhibit soft body behavior:
1. Select the Mesh object and enter Edit mode.
2. In the Vertex Groups panel of the Mesh properties window, click the plus symbol icon. Type SoftGoal in the Name field of the new vertex group. Now select the top vertex of the mesh, as shown in , and click Assign. The default weight assignment value is 1, so this will assign a 1 value to this vertex.
Finally, activate the soft body simulation. Return to Object mode, and with the Mesh object still selected, click the Soft Body button on the Soft Body tab in the Physics buttons area.
1. To start, set the values as shown in .
2. Run the simulation by pressing Alt+A, and watch the spring deform as shown in .
The point of these three tutorials was to set up the simplest and most explicit possible example of what soft bodies actually do. You should experiment with this spring to find out how the different soft body parameters affect its behavior. Try changing the mass, stiffness, and speed values and see what happens. Try animating the location and rotation of the soft body mesh (remember, the armature is constrained to follow the empties, and the empties are vertex-parented to the mesh). If you bake the soft body and then animate the object, what happens? (Hint: To do this right, you’ll need to free the bake by clicking Free Bake in Bake Settings.)
Force Fields and Collision
Soft bodies can interact with other objects and forces in much the same way that particle systems can, as described in Chapter 6, “Working with Particles.” Forces behave essentially the same for both particles and soft bodies. Soft body collision is slightly different from collision for particles. There is no permeability parameter, but there are two parameters, Inner and Outer, that create the effect of a thickening of the internal or external surface of the Collision object. The optimal settings for these values vary depending on the situation, but a general rule is that increasing the value of one of these parameters should help diminish penetration from that side of the mesh. As you’ll see, there are other ways to minimize penetration, if these parameters don’t do the trick. The Damping value here has essentially the same function as the Damping value for particles collision: It reduces the amount of kinetic energy in the deflected object when it collides, resulting in a less-bouncy collision.
Collision detection between Soft Body objects and Collision objects is good but not perfect. Even with Inner and Outer thickness parameters set to their optimal values, penetration can occur.
Soft Body objects also can be Deflector objects and interact with other Soft Body objects, as in the case of the balls in the file bouncy_balls.blend, shown in .
The balls are initially set up as shown in , with the plane beneath them set as a Deflector object.
The balls’ own Soft Body settings are shown in . Note especially the Bending value. This refers to the amount of resistance there is to bending at the vertices. The default is 0. To make the balls maintain their shape, Bending must be set to a higher value. A value of 1 will give the balls about the hardness of a well-inflated soccer ball. I’ve set the value to 0.8, which as you can see results in much softer-seeming balls.
When you activate Collision in the Physics buttons area, a Collision modifier appears in the modifier stack that will interact with other modifiers. As in all cases when modifiers are used, it is important to be aware of the ordering of the modifiers in the modifier stack. Modifiers are evaluated from the top of the stack down. This means, for example, if the Collision modifier is positioned above the Subsurf modifier, collision will be calculated based on the un-subsurfed mesh, and if it is positioned above the Armature modifier, the collision will be calculated from the undeformed mesh shape. As you can imagine, this can result in wildly incorrect collision patterns, and it is an easy thing to overlook, because modifiers can be added in virtually any order. As a general rule of thumb, any time you are getting unexpected results from modifiers, take a close look at the ordering of the modifier stack.
Simulating Cloth and Clothing
Soft body simulations can provide a stretchy, flexible surface effect similar to cloth. In fact, in the past the best way to simulate cloth in Blender was to use soft body effects. However, Blender now features a dedicated cloth solver, which is a great improvement. Real cloth bunches together and influences its own motion by colliding with itself. The cloth simulator is more accurate and stable for these uses than soft bodies. shows the cloth simulator in action.
Hanging the Drapes
shows a still from an animation of drapes that uses both force fields and Collision objects. You’ll find a similar but somewhat simpler scene among the downloadable files for this book.
The file drapes.blend features the scene shown in .
You can see the cloth settings for this setup in . It is important to activate Self Collision for cloth in order to avoid the object penetrating itself. The drapes themselves are simply subdivided planes.
A goal vertex group is used to fix the drapes in place, and you can see the values of the vertices shown in Weight Paint mode in .
Wind is produced by the Force Field object shown in . The settings for the force field are shown in .
The Collision object is a simple cylinder. The Collision settings for that object are shown in .
Clothing for Animation
Creating clothing for animated characters is a very important and often poorly understood use of the cloth solver. It’s important to understand how to get the most of it.
Obviously, not every article of clothing that is made out of cloth in real life should be represented with a cloth simulator in CG. Some clothing articles are best modeled and rigged in the traditional way, without simulation. Clothing that is stiff or tight fitting generally doesn’t require simulation and won’t be well mimicked in this way. Articles of clothing that billow or bunch up are appropriate for cloth simulation. There are often cases where part of an article of clothing should be simulated and other parts, such as the bodice portion of a dress, should not be simulated. This can be accomplished by using vertex groups and weight painting to pin portions of the clothing that are not subject to the simulation.
When animating cloth simulation there are several issues to be aware of. You need to ensure that any potential areas of penetration are avoided or concealed. You need to make sure that the movement of the cloth is doing what you want it to and avoid wrong behaviors such as the cloth squirming when it should be resting motionlessly. Finally, you need to be prepared to bake full-quality simulations for every animated sequence involving the cloth if necessary, which can be resource intensive. But in many cases it’s not necessary.
Another question is whether to use the soft body simulator as is to provide the animation of the cloth itself or to use it as a modeling aid. In the case of a billowing, flowing dress, you would probably use the animation data directly from the soft body simulation, subject to force fields. This can be difficult to work with because the animation cannot really be controlled directly. In other cases, such as stiff boots or tight, form-fitting clothing, any kind of cloth simulation is probably inappropriate.
The most common kind of clothing resides somewhere between these two extremes. Most clothing is made of cloth, after all, and has characteristic wrinkles and perturbations whenever it is worn. However, the perturbations in ordinary-to-tight-fitting clothing do not change drastically in response to a character’s movement. The wrinkles behind the knee in a pair of jeans, for example, do not substantially change their arrangement when a person’s knee bends. You can take advantage of this by using Blender’s cloth simulation functionality not as an animation tool but as a modeling tool. Using cloth simulation you can create a static mesh that can be rigged in the ordinary way, resulting in highly realistic clothing without the extra challenges of animated cloth simulation.
The following tutorial will show you how to use cloth simulation along with an armature-rigged base body mesh (in this case just an arm) to create a sleeve. You can extrapolate what you learn here to create the rest of a shirt or any other piece of clothing.
In order to follow the steps you’ll need to prepare a bit. If you don’t want to model and rig the base mesh and armature yourself, you can append the group Arm_Rig from the file arm_sleeve.blend found on the website that accompanies this book. If you are comfortable with basic mesh modeling and rigging and would prefer to model and rig the starting point yourself, refer to for the topology used.
Your model doesn’t need to be identical, but it should be a nicely modeled arm that will deform well. Note that the polygons are fairly uniform in their size and proportions. The armature used is shown in .
Parent the mesh to the armature and select Create From Bone Heat, as shown in . The arm should deform nicely, as shown in .
To minimize clutter, put the armature in Stick view mode by selecting Stick from the Display options on the Armature buttons panel, shown in .
Once you’ve either appended the group or modeled and rigged an arm of your own, follow these steps to create the shirt sleeve:
1. The sleeve will begin its life as a lowly cylinder. Add a cylinder to the scene by pressing Shift+A and choosing Mesh > Cylinder from the Add menu, as shown in .
Make it eight vertices around by setting the Vertices field to 8 and ensure that Cap Ends is not selected in the dialog, as shown in . Then click OK.
The cylinder should appear something along the lines of .
2. If you placed it somewhere other than at the center of the Armature object, press Alt+G and Alt+R to clear any translation and rotation. In this particular example, it doesn’t matter much whether all the objects have their centers at the same place, but it’s a good habit to get into. There’s no reason why these objects should have their centers scattered around.
3. Tab into Edit mode. Select all the vertices of the mesh by pressing the A key; then rotate the cylinder by pressing the R key followed by the Z key and entering 90. Press the G key and move the cylinder so that it begins at the shoulder, as shown in . Scale as necessary by pressing the S key.
4. Select the rightmost loop of the cylinder and translate, rotate, and scale it to where the wrist is, as shown in .
5. Press Ctrl+R to activate the Loop Cut tool. Use your mouse wheel to increase the number of cuts, as shown in . This example uses eight cuts, but the important thing is to try to keep the polygons close to evenly sized squares.
When you finalize the loop cut, the mesh will look something like .
6. Turn on Proportional Editing by selecting it the 3D viewport header menu, as shown in .
7. Select some loops in the middle of the sleeve and translate them, as shown in .
8. Adjust the influence range of the Proportionate Editing tool (displayed as a circle) using the mouse wheel. The goal here is to ensure that the sleeve covers the arm without penetration. Move the loops as necessary to get the results shown in .
9. Expand the Add Modifier menu on the Modifiers tab and select Shrinkwrap, as shown in . The Shrinkwrap modifier panel will appear, as shown in .
10. In the Target field, enter the name of the Arm object, in this case Arm. Increase the value of Offset. This value determines the distance from the surface of the target mesh (the arm itself) to the shrink-wrapped mesh (the sleeve). This will directly impact how tightly or loosely the sleeve fits. The resulting modified mesh should look something like . Apply the modifier by clicking the Apply button on the Modifier panel.
11. Model the shoulder seam and the cuff of the sleeve by hand. Use the E key to extrude and the S, G, and R keys to scale, translate, and rotate as appropriate. The shoulder seam should look similar to . The cuff should look like .
12. The shoulder seam and the cuff area cling to the body and should be completely static. Neither area should be affected by the cloth simulation. To ensure this, you’ll use a vertex group to pin the cloth when the time comes. Now, you need to create the vertex group. On the Mesh properties area, click the + icon to the right of the list area in the Vertex Groups panel, as shown in .
13. Name the new vertex group Cloth. Select the second loop from the shoulder seam; then enter a value of 0.50 in the Weight field and click Assign, as shown in . Then select the topmost loop of the sleeve (the seam loop itself) and the entire cuff and assign them a weight of 1.0, as shown in .
14. To check your weights, enter Weight Paint mode from the menu on the 3D viewport header. You should see the mesh displayed, as shown in . Most of the mesh is blue, but the cuff and the shoulder seam are red. The loop nearest the shoulder seam is green.
15. Enter Object mode and rig the sleeve. Select the sleeve and the armature (in that order), press Ctrl+P to create the parent relationship, select Armature, and choose With Automatic Weights, as shown in , just as you did previously with the arm itself (if you rigged your own). You can see the effect of the skinning by viewing the mesh in Weight Paint mode, as shown in . The sleeve can now be posed with the armature.
A good way to get interesting-looking cloth wrinkles is to run the cloth simulation over a posed model set up as an obstacle to the cloth. The cloth effects can be even more dynamic and convincing if, rather than using a statically posed model, you animate the model into the pose and let the cloth simulation play out over the animated mesh.
1. To do this in this example, animate the arms from the rest pose, as shown in , to a raised, bent-arm pose like the one shown in , and then back down to the rest pose. You’ll want to have an Action Editor open to see the locations of your keyframes. Pose the bones in frame 1 and press the I key to keyframe location and rotation; then pose the bones again in about frame 70. This will ensure that the motion is slow enough not to cause any unnecessary problems with cloth penetration, even at low-cloth-quality settings.
2. Add a Subsurf modifier and set the View and Render subdivision levels value to 2 and 3, respectively, as shown in . Click Smooth Shading on the 3D viewport Tool Shelf to give it a smooth surface. The Subsurf modifier is important. The cloth simulation will work on the subsurfed mesh vertices, giving it much more detail than you would get with an un-subsurfed mesh. If you want even more detail in your cloth simulation, you can set the subdivision levels even higher, but this will slow down the cloth simulation.
3. Set the arm object to be a Collision object in the Physics buttons area, as shown in . You can leave the default values in the Collision panel as they are. This will ensure that the arm behaves as an obstacle for the cloth, so that the cloth will conform to the shape of the arm. Without this setting, the sleeve would fall right through the arm.
4. Select the sleeve and activate cloth simulation by clicking the Cloth button in the Physics buttons area, as shown in . You can leave the defaults for the parameter values in the Cloth panel.
5. Activate Pinning and select the Cloth vertex group. This will ensure that only the portions of the mesh that were blue in the previous Weight Paint view are enabled as cloth simulations. Baking for 250 frames is a waste of time here, so set an End value that’s just a second or so past the end of the arm animation, at around frame 80. When you have the settings as you want them, click Bake to bake the cloth simulation. This will take some time, so be patient.
Collision Course
For this specific example, you probably won’t need to activate Self Collision at the bottom of this panel. However, if you have a looser sleeve than the one in the example, or if you are working at a higher subsurf level, it’s possible that the cloth could collide with itself. If this happens and Self Collision is not activated, the cloth will pass right through itself. Don’t activate Self Collision unless you need it, but if you get self-penetration problems with the cloth, then activate it.
Once the cloth simulation is baked, you should be able to move back and forth along the timeline at normal speed and see the mesh at the corresponding state in the cloth simulation. The simulation frames have all been saved, so they can be quickly accessed without further computation. This simulation, however, is only appropriate for this specific animated shot. If you want to use the simulation to create a new static mesh model, follow the next steps:
1. Apply each modifier on the mesh from top to bottom by clicking the Apply button first on the Armature modifier, then the Subsurf modifier, and then the Cloth modifier, as shown in . Do the same thing for the Arm object.
2. In Object mode, copy the armature and place the copy on a separate layer so that you can work with it and the new meshes without dealing with the old armature and meshes. The copied armature will have the same action associated with it as the original armature.
3. Without changing frames, enter Pose mode and choose Apply Pose As Restpose from the Pose menu in the 3D viewport header, as shown in . This does what you expect from the name. The current bent-arm pose will become the rest pose to which the armature returns when all the transformations on it are canceled. Since you applied the deformation to the arm and sleeve meshes, the new rest pose should fit them perfectly.
4. Rig the sleeve to the armature by parenting it as shown in and choosing Armature Deform With Automatic Weights, just as you’ve done with other meshes before. Do the same thing to the arm mesh.
5. In a final rigged mesh for animation with no active simulations, there is no reason to have multiple layers of mesh. On the contrary, having mesh clothes over a mesh body will likely result in penetration where the inner mesh pops through the surface of the outer mesh. Since the sleeve now has the arm shape modeled into it, there’s no need for the actual arm model to extend through the sleeve. Delete the vertices of the arm that will not be seen so that you have an Arm object like the one shown in .
You’re basically finished now. Test your mesh by creating a simple action with a range of positions roughly representative of what your character will be doing so that you get a sense of how the sleeve will look when bent and extended in different ways. shows renders of the same process but with the Subsurf level set at 3 and with Self Collision activated on the cloth simulation. If your resources allow, try running a simulation with these settings as well.
The Bottom Line
Control the behavior of soft body objects. Soft body meshes suffer from a disadvantage in that they lack internal structure. Although bending parameters can counter this somewhat, there are some cases in which the fully 3D structure of a matrix can come in handy for giving a soft-body simulation more of a sense of volume.
Master It Try to construct a cube of gelatin from a mesh cube by using a soft-body-modified lattice for the deformation. Figure out how best to weight-paint the cube so that the lattice deformation is convincing.
Work with force fields, collision objects, and modifiers. You can obtain realistic cloth movement effects by combining rigging, pinning, and hook modifiers with the free movement of the cloth simulation.
Master It Using a cloth setup similar to the curtains shown in this chapter, create a curtain that can be animated to open in a realistic way, as though it were hung with hooks on a curtain rod.
Work with cloth and clothing. There are a variety of approaches to take with creating clothing, ranging from modeling the cloth forms directly, to using the cloth simulator as a median step in modeling, to animating with the cloth simulation directly. All of these approaches have their appropriate uses.
Master It Try to create different articles of clothing for your characters. Experiment with boots, scarves, trousers, shirts, and dresses. Which approaches do you think work best for which types of clothing? What do you think the best way to animate a long, stiff jacket might be?