Cloth simulation is one of the hardest aspects of CG, because it is a deceptively simple real-world item that is taken for granted, yet actually has very complex internal and environmental interactions. After years of development, Blender has a very robust cloth simulator that is used to make clothing, flags, banners, and so on. Cloth interacts with and is affected by other moving objects, the wind and other forces, as well as a general aerodynamic model, all of which is under your control.
Mode: Object Mode
Panel: Editing context → Modifiers panel
Hotkey: F7 to get to Object context; repeat to change sub-context.
A piece of cloth is any mesh, open or enclosed, that has been designated as cloth. The Cloth panels are located in the Physics sub-context and consist of three panels of options. Cloth is either an open or closed mesh and is mass-less, in that all cloth is assumed to have the same density, or mass per square unit.
Cloth is commonly modeled as a mesh grid primitive, or a cube, but can also be, for example, a teddy bear. However, Blender’s Softbody system provides better simulation of closed meshes; Cloth is a specialized simulation of fabrics.
Once the object is designated as Cloth, a Cloth modifier will be added to the object’s modifier stack automatically. As a modifier then, it can interact with other modifiers, such as Armature and Smooth. In these cases, the ultimate shape of the mesh is computed in accordance with the order of the modifier stack. For example, you should smooth the cloth after the modifier computes the shape of the cloth.
So you edit the Cloth in two places. In the F7 Physics buttons to edit the properties of the cloth and in the Modifier stack where you edit the Modifier properties related to display and interaction with other modifiers.
You can Apply the cloth modifier to freeze, or lock in, the shape of the mesh at that frame, which removes the modifier. For example, you can drape a flat cloth over a table, let the simulation run, and then apply the modifier. In this sense, you are using the simulator to save yourself a lot of modeling time.
Results of the simulation are saved in a cache, so that the shape of the mesh, once calculated for a frame in an animation, does not have to be recomputed again. If changes to the simulation are made, the user has full control over clearing the cache and re-running the simulation. Running the simulation for the first time is fully automatic and no baking or separate step interrupts the workflow.
Computation of the shape of the cloth at every frame is automatic and done in the background; thus you can continue working while the simulation is computed. However it is CPU-intensive and depending on the power of your PC and the complexity of the simulation, the amount of CPU needed to compute the mesh varies as does the lag you might notice.
Don’t jump ahead
If you set up a cloth simulation but Blender has not computed the shapes for the duration of the simulation, and if you jump ahead a lot of frames forward in your animation, the cloth simulator may not be able to compute or show you an accurate mesh shape for that frame, if it has not previously computed the shape for the previous frame(s).
A general process for working with cloth is to:
- Model the cloth object as a general starting shape.
- Designate the object as a “cloth” in the Physics sub-context of the Object context (F7).
- Model other deflection objects that will interact with the cloth. Ensure the Deflection modifier is last on the modifier stack, after any other mesh deforming modifiers.
- Light the cloth and assign materials and textures, UV-unwrapping if desired.
- If desired, give the object particles, such as steam coming off the surface.
- Run the simulation and adjust Options to obtain satisfactory results. The timeline window’s VCR controls are great for this step.
- Optionally age the the mesh to some point in the simulation to obtain a new default starting shape.
- Make minor edits to the mesh on a frame-by-frame basis to correct minor tears.
Cloth Panel Options
Cloth is controlled by the three panels shown above. Each of the options (buttons and controls) on those three panels is fully documented in the Reference manual. This section discusses how to use those options to get the effect you want.
First, enable Cloth. Set up for the kind of cloth you are simulating. You can choose one of the presets to have a starting point.
As you can see, the heavier the fabric, the more stiff it is and the less it stretches and is affected by the air.
Next, position and pin the cloth in the desired position. Pinning is described below. Note that if you move the cloth object after you have already run some simulations, you must unprotect and clear the cache; otherwise, Blender will use the position of the current/cached mesh’s vertices when trying to represent where they are. Editing the shape of the mesh, after simulation, is also discussed below. You may disable the cloth and edit the mesh as a normal mesh editing process.
Finally, use the Timeline window Play button, or press AltA in the 3D View to run the simulation. Your cloth will fall and interact with Deflection objects as it would in the real world.
Using Simulation to Shape/Sculpt a Mesh
You can Apply the Cloth modifier at any point to freeze the mesh in position at that frame. You can then re-enable cloth, setting the start and end frames from which to run the simulation forward.
Another example of aging is a flag. Define the flag as a simple grid shape and pin the edge against the flagpole. Simulate for 50 frames or so, and the flag will drop to its “rest” position. Apply the Cloth modifier. If you want the flag to flap or otherwise move in the scene, re-enable it for the frame range when it is in camera view.
In most cases, a piece of cloth does not just hang there in 3D space, it collides with other objects in the environment. To ensure proper simulation,there are several items that have to be set up and working together:
- The Cloth object must be told to participate in Collisions.
- Optionally (but recommended) tell the cloth to collide with itself.
- Other objects must be visible to the Cloth object via shared layers.
- The other objects must be mesh objects.
- The other objects may move or be themselves deformed by other objects (like an armature or shape key).
- The other mesh objects must be told to deflect the cloth object.
- The blend file must be saved in a directory so that simulation results can be saved.
- You then Bake the simulation. The simulator computes the shape of the cloth for a frame range.
- You can then edit the simulation results, or make adjustments to the cloth mesh, at specific frames.
- You can make adjustments to the environment or deforming objects, and then re-run the cloth simulation from the current frame forward.
Now you must tell the Cloth object that you want it to participate in collisions. For the cloth object, locate the Cloth Collision panel, shown to the right:
- Min Distance
- As another object gets this close to it (in Blender Units), the simulation will start to push the cloth out of the way.
- Collision Quality
- A general setting for how fine and good a simulation you wish. Higher numbers take more time but ensure less tears and penetrations through the cloth.
- A coefficient for how slippery the cloth is when it collides with the mesh object. For example, silk has a lower coefficient of friction than cotton.
Real cloth cannot permeate itself, so you normally want the cloth to self-collide.
- Enable Selfcollisions
- LMB click this to tell the cloth object that it should not penetrate itself. This adds to simulation compute time, but provides more realistic results. A flag, viewed from a distance does not need this enabled, but a close-up of a cape or blouse on a character should have this enabled.
- Min Distance
- If you encounter problems, you could also change the Min Distance value for the self-collisions. The best value is 0.75, for fast things you better take 1.0. The value 0.5 is quite risky (most likely many penetrations) but also gives some speedup.
- Selfcoll Quality
- For higher self-collision quality just increase the Selfcoll Quality and more selfcollision layers can be solved. Just keep in mind that you need to have at least the same Collision Quality value as the Selfcoll Quality value.
Regression blend file: Cloth selfcollisions.
For example, suppose you have two objects: a pair of Pants on layers 2 and 3, and your Character mesh on layers 1 and 2. You have enabled the Pants as cloth as described above. You must now make the Character “visible” to the Cloth object, so that as your character bends its leg, it will push the cloth. This principle is the same for all simulations; simulations only interact with objects on a shared layer. In this example, both objects share layer 2.
To view/change an object’s layers, RMB click to select the object in Object mode in the 3D view. M to bring up the “Move Layers” popup, which shows you all the layers that the object is on. To put the object on a single layer, LMB click the layer button. To put the object on multiple layers, ⇧ ShiftLMB the layer buttons. To remove an object from a selected layer, simply ⇧ ShiftLMB the layer button again to toggle it.
Mesh Objects Collide
If your colliding object is not a mesh object, such as a NURBS surface, or text object, you must convert it to a mesh object. To do so, select the object in object mode, and in the 3D View header, select Object → Convert Object Type (AltC), and select Mesh from the popup menu.
Cloth - Object collisions
The cloth object needs to be deflected by some other object. To deflect a cloth, the object must be enabled as an object that collides with the cloth object. To enable Cloth - Object collisions, you have to enable deflections on the collision object (not on the cloth object).
In the Buttons window, Object context, Physics sub-context, locate the Collision panel shown to the right. It is also important to note that this collision panel is used to tell all simulations that this object is to participate in colliding/deflecting other objects on a shared layer (particles, soft bodies, and cloth).
There are three different Collision panels, all found in the Physics sub-context. The first (by default), a tab beside the Fields panel, is the one needed here. The second panel, a tab in the Soft Body group, concern softbodies (and so has nothing to see with clothes). And we have already seen the last one, by default a tab beside the Cloth panel.
Mesh Object Modifier Stack
The object’s shape deforms the cloth, so the cloth simulation must know the “true” shape of that mesh object at that frame. This true shape is the basis shape as modified by shape keys or armatures. Therefore, the Collision modifier must be after any of those. The image to the right shows the Modifiers panel for the Character mesh object (not the cloth object).
After you have set up the deflection mesh for the frame range you intend to run the simulation (including animating that mesh via armatures), you can now tell the cloth simulation to compute (and avoid) collisions. Select the cloth object and in the Object context, Physics sub-context, set the Start and End settings for the simulation frames you wish to compute, and click the Bake button.
- The starting frame of the animation when you want the cloth to start responding.
- The end frame of the simulation. The cloth will remain “frozen” after End.
- Starts the simulation process.
You cannot change Start or End without clearing the bake simulation. When the simulation has finished, you will notice you have the option to free the bake, edit the bake and re-bake:
- Free Bake
- Deletes the simulation, enabling you to make changes and then start over.
- Bake Editing
- Enables you to protect the cache and prevent the simulation from recomputing the mesh shape. You can then edit the mesh shape manually.
- Rebake From Current Frame
- Enables you to re-compute the cloth simulation from the current frame to End.
There’s a few things you’ll probably notice right away. First, it will bake significantly slower than before, and it will probably clip through the box pretty bad as in the picture on the right.
Editing the cached simulation
The cache contains the shape of the mesh at each frame. You can edit the cached simulation, when you baked the simulation and pressed the Bake Editing button. Just go to the frame you want to fix and ⇆ Tab into Edit mode. There you can move your vertices using all of Blender’s mesh shaping tools. When you exit, the shape of the mesh will be recorded for that frame of the animation. If you want Blender to resume the simulation using the new shape forward, LMB click ’Rebake from next Frame and play the animation. Blender will then pick up with that shape and resume the simulation.
Edit the mesh to correct minor tears and places where the colliding object has punctured the cloth.
If you add, delete, extrude, or remove the vertices in the mesh, Blender will take the new mesh as the starting shape of the mesh back to the first frame of the animation, replacing the original shape you started with, up to the frame you were on when you edited the mesh. Therefore, if you change the content of a mesh, when you ⇆ Tab out of Edit mode, you should unprotect and clear the cache so that Blender will make a consistent simulation.
If you encounter some problems with collision detection there are two ways to fix them:
- The fastest solution would be to put up the Min Distance setting under the Cloth Collision panel. This will be the fastest way to fix the clipping, however, it will be less accurate and won’t look as good. Using this method tends to make it look like the cloth is resting on air, and gives it a very rounded look.
- A second method is to increase the Quality (in the first Cloth panel). This results in smaller steps for the simulator and therefore to a higher probability that fast moving collisions get catch. You can also increase the Collision Quality to perform more iterations to get collisions solved.
- If none of the methods help, you can easily edit the cached/baked result in Edit mode afterwards.
- My Cloth is torn by the deforming mesh - he “Hulks Out”: Increase its structural stiffness (StructStiff setting, Cloth panel) very high, like 1000.
A bake/cache is done for every subsurf level so please use one equal subsurf level for render and preview.
To start with cloth, the first thing you need, of course, is some fabric. So, lets delete the default cube and add a plane. I scaled mine up along the Y axis, but you don’t have to do this. In order to get some good floppy and flexible fabric, you’ll need to subdivide it several times. I did it 8 times for this example. So ⇆ Tab into Edit mode, and press W → Subdivide multi, and set it to 8.
Now, we’ll make this cloth by going to the Object context (F7) → Physics sub-context. Scroll down until you see the Cloth panel, and press the Cloth button. Now, a lot of settings will appear, most of which we’ll ignore now.
That’s all you need to do to set your cloth up for animating, but if you hit AltA, your lovely fabric will just drop very un-spectacularly. That’s what we’ll cover in the next two sections about pinning and colliding.
Pinning of cloth
The first thing you need when pinning cloth are Vertex Groups. There are several ways of doing this including using the Weight Paint tool to paint the areas you want to pin (see the Weight paint section of the manual).
Once you have a vertex group set, things are pretty straightforward, all you have to do is press the Pinning of cloth button in the Cloth panel and select which vertex group you want to use, and the stiffness you want it at. You can leave the stiffness as it is, default value is fine.
Smoothing of Cloth
Now, if you followed this from the previous section, your cloth is probably looking a little blocky. In order to make it look nice and smooth like the picture you need to apply a Smooth and/or Subsurf modifier in the Modifiers panel under the Editing context (F9). Then, in the same context, find the Links and Materials panel (the same one you used for vertex groups) and press Set Smooth.
Now, if you hit AltA, things are starting to look pretty nice, don’t you think?
Cloth on armature
Cloth deformed by armature and also respecting an additional collision object: Regression blend file.
Using Cloth for Softbodies
Cloth can also be used to simulate softbodies. It’s for sure not it’s main purpose but it works nonetheless. The example image uses standard Rubber material, no fancy settings, just AltA.
Blend file for the example image: Using Cloth for softbodies.
Cloth with Wind
Regression blend file for Cloth with wind and selfcollisions (also the blend for the image above): Cloth flag with wind and selfcollisions.