From BlenderWiki

Jump to: navigation, search

Cloth Simulation

Cloth example.
Cloth on carved wooden men (made by motorsep).
Cloth example.

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.

Description

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).


Workflow

A general process for working with cloth is to:

  1. Model the cloth object as a general starting shape.
  2. Designate the object as a “cloth” in the Physics sub-context of the Object context (F7).
  3. 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.
  4. Light the cloth and assign materials and textures, UV-unwrapping if desired.
  5. If desired, give the object particles, such as steam coming off the surface.
  6. Run the simulation and adjust Options to obtain satisfactory results. The timeline window’s VCR controls are great for this step.
  7. Optionally age the the mesh to some point in the simulation to obtain a new default starting shape.
  8. Make minor edits to the mesh on a frame-by-frame basis to correct minor tears.


Cloth Panel Options

Cloth panel.
Cloth Collisions panel.
Cloth Advanced functions panel.

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.

Cloth Definition

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.

Collisions

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:

  1. The Cloth object must be told to participate in Collisions.
  2. Optionally (but recommended) tell the cloth to collide with itself.
  3. Other objects must be visible to the Cloth object via shared layers.
  4. The other objects must be mesh objects.
  5. The other objects may move or be themselves deformed by other objects (like an armature or shape key).
  6. The other mesh objects must be told to deflect the cloth object.
  7. The blend file must be saved in a directory so that simulation results can be saved.
  8. You then Bake the simulation. The simulator computes the shape of the cloth for a frame range.
  9. You can then edit the simulation results, or make adjustments to the cloth mesh, at specific frames.
  10. You can make adjustments to the environment or deforming objects, and then re-run the cloth simulation from the current frame forward.


Cloth Collision

Cloth Collisions panel.

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:

Enable Collisions
LMB Template-LMB.png click this to tell the cloth object that it needs to move out of the way.
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.
Friction
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.


Self-collisions

Real cloth cannot permeate itself, so you normally want the cloth to self-collide.

Enable Selfcollisions
LMB Template-LMB.png 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.

Shared Layers

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 Template-RMB.png 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 Template-LMB.png click the layer button. To put the object on multiple layers, ⇧ ShiftLMB Template-LMB.png the layer buttons. To remove an object from a selected layer, simply ⇧ ShiftLMB Template-LMB.png 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

Collision settings.

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).

Beware
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

Collision 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).

Bake Collision

After Baking.

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.

Start
The starting frame of the animation when you want the cloth to start responding.
End
The end frame of the simulation. The cloth will remain “frozen” after End.
Bake
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.
Standard settings cloth collide with sphere.

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 Template-LMB.png 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.

Troubleshooting

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.
Subsurf modifier
A bake/cache is done for every subsurf level so please use one equal subsurf level for render and preview.


Examples

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

Cloth in action.

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

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

Flag with wind applied.

Regression blend file for Cloth with wind and selfcollisions (also the blend for the image above): Cloth flag with wind and selfcollisions.



Introduction
What is Blender?
Introduction
Blender’s History
License
Blender’s Community
About this Manual
What's changed with Blender 2.4
Installing Blender
Introduction
Python
Installing on Windows
Installing on GNU/Linux
Installing on Mac
Installing on other Operating Systems
Configuring Blender
Directory Layout
Starting
The Interface
Introduction
Keyboard and Mouse
Window System
Arranging frames
Headers
Console window
Window Types
Screens (Workspace Layouts)
Scenes
Configuration
Modes
Contexts
Menus
Panels
Buttons and Controls
Internationalization
Your First Animation
1/2: A static Gingerbread Man
2/2: Animating the Gingerbread Man
The Vital Functions
Quick render
Undo and Redo
Default scene
Screenshots
Help!
Setting Preferences
Configuring Preferences
Interface
Editing
Themes
File
System
Interaction in 3D
Introduction
Introduction
Navigation
Introduction
3D View
3D View Options
3D View Usage
Camera View
Layers
Local or Global View
Sketch in 3D Space
Introduction to Grease Pencil
Drawing sketches
Layers and Animation
Converting sketches to geometry
Transformations
Introduction
Basics
- Grab/Move
- Rotate
- Scale
- Gestures
Advanced
- Mirror
- To Sphere
- Shear
- Warp
- Push/Pull
Transform Control
Introduction
Precision of Transformations
Numeric Transformations
Transform Properties
Reset Object Transforms
Manipulators
Transform Orientations
Axis Locking
Pivot Point
- Active object
- Individual Centers
- 3D Cursor
- Median Point
- Bounding Box Center
Snapping
Snap to Mesh
Proportional Edit
Data System and Files
Blender's Data System
Blender's Library and Data System
Blender's Datablocks
Scenes
Working with Scenes
The Outliner Window
Appending and Linking
File operations
Introduction
Opening blender files
Saving blender files
Modeling
Introduction
Introduction
Objects
Objects
Selecting Objects
Editing Objects
Groups and Parenting
Tracking
Duplication
- DupliVerts
- DupliFaces
- DupliGroup
- DupliFrames
Mesh Objects
Meshes
- Mesh Structures
- Mesh Primitives
Selecting
- Selectable Elements
- Selection Basics
- Advanced Selecting
- Selecting Edges
- Selecting Faces
Editing
Basic Editing
- Translation, Rotation, Scale
- Adding Elements
- Deleting Elements
- Creating Faces and Edges
- Mirror editing
Vertex Editing
Edge Editing
Face Editing
Deforming Tools
- Mirror
- Shrink/Fatten Along Normals
- Smooth
- Noise
Duplicating Tools
- Duplicate
- Extrude
- Extrude Dup
- Spin
- Spin Dup
- Screw
Subdividing Tools
- Subdivide
- Subdivide fractal
- Subdivide smooth
- Loop Subdivide
- Knife Subdivide
- Bevel
Miscellaneous Tools
Retopo Tool
Sculpt Mode
Multi Resolution Mesh
Vertex Groups
Weight Paint
Mesh Smoothing
Curve Objects
Curves
Selecting
Editing
Advanced Editing
Surface Objects
Surfaces
Selecting
Editing
Text Objects
Texts
Editing
Meta Objects
Metas
Editing
Empty Objects
Empties
Group Objects
Groups
Scripts
Modeling Scripts
Modifiers and Deformation
Introduction
Introduction
Modifiers Stack
Modify
UVProject
Generate
Array
Bevel
Booleans
Build
Decimate
EdgeSplit
Mask
Mirror
Subsurf
Deform
Armature
Cast
Curve
Displace
Hooks
Lattice
MeshDeform
Shrinkwrap
SimpleDeform
Smooth
Wave
Simulate
Cloth
Collision
Explode
Fluid
Particle Instance
Particle System
Soft Body
Lighting
Introduction
Introduction
Lights
Introduction
Light Properties
Light Attenuation
Light Textures
What Light Affects
Lights In Other Contexts
Shadows
Introduction
Shadow Properties
Raytraced Shadow Properties
Volumetric Lights
Introduction
Lamps
Introduction
Lamp Light
- Raytraced Shadows
Spot Light
- Raytraced Shadows
- Buffered Shadows
- Halos
Area Light
- Raytraced Shadows
Hemi Light
Sun Light
- Raytraced Shadows
- Sky & Atmosphere
Lighting Rigs
Radiosity
Introduction
Rendering
Baking
Scene Light
Ambient Light
Ambient Occlusion
Exposure
Exposure
Materials
Introduction
Introduction to Shading
Materials Introduction
Usage
Assigning a material
Material Preview
Material Options
Multiple Materials
Properties
Diffuse Shaders
Specular Shaders
Ambient Light Effect
Color Ramps
Raytraced Reflections
Raytraced Transparency
Subsurface Scattering (SSS)
Strands
Node Materials
Material Nodes
Nodes Editor
Node Controls
Nodes usage
Nodes Groups
Material Node Types
- Input Nodes
- Output
- Color
- Vector
- Convertor
- Dynamic
Vertex Paint
Using Vertex Paint
Halos
Halos
Textures
Introduction
Introduction
UV/Image Editor
Common Options
Texture Stack
Texture Types
Texture Types
Procedural Textures
Image Textures
Video Textures
Texture Nodes
- Nodes Editor
- Node Controls
- Nodes usage
- Nodes Groups
-- Textures Input Nodes
-- Textures Output Nodes
-- Textures Color Nodes
-- Textures Patterns Nodes
-- Textures Textures Nodes
-- Textures Convertor Nodes
-- Textures Distort Nodes
Texture Plugins
Texture Painting
Painting the Texture
- Projection Paint
Mapping
Mapping
Environment Maps
UV Unwrapping Explained
- Unwrapping a Mesh
- Managing the UV Layout
- Editing the UV Layout
- Applying an Image
Influence
Influence
- Material
-- Bump and Normal
-- Displacement
- Particles
- World
World and Ambient Effects
World
Introduction
World Background
Ambient Effects
Mist
Stars
Rigging
Introduction
Introduction to Rigging
Armatures
Armature Objects
Panels overview
Bones
Visualization
Structure
Selecting
Editing
- Bones
- Properties
- Sketching
- Templating
Skinning
Introduction
Linking Objects to Bones
Skinning to Objects’ Shapes
Retargeting
Posing
Introduction
Visualization
Editing Poses
Pose Library
Using Constraints
Inverse Kinematics
Constraints
Introduction
Introduction
Constraints Common Interface
Constraints’ Stack
Transform Constraints
Copy Location
Copy Rotation
Copy Scale
Limit Distance
Limit Location
Limit Rotation
Limit Scale
Transformation
Tracking Constraints
Clamp To
IK Solver
Locked Track
Stretch To
Track To
Relationship Constraints
Action
Child Of
Floor
Follow Path
Null
Rigid Body Joint
Script
Shrinkwrap
Animation
Introduction
Introduction
The Timeline
Markers
3D Views
Animation Editors
Animation Editors
Ipo Editor
Ipo Curves and Keyframes
Ipo Datablocks
Ipo Types
Ipo Editor Interface
Editing
- Ipo Curves
- Keyframes
Ipo Drivers
Action Editor
Editing Action Channels
NLA Editor
Editing NLA Strips
Strip Modifiers
Animation Techniques
Introduction
Animating Objects
- Using Constraints
- Moving Objects on a Path
Animating Shapes
- Shape Keys
- Editing Shape Keys
- Animating Shape Keys
- Shape Keys Examples
Indirect Shape Animation
Animating Armatures
- Stride
Animating Lamps
Animating Cameras
Animating Materials
Animating Textures
Animating World
Physical Simulation
Introduction
Introduction
Dynamics
Force Fields
Collisions
Particles
Particles
Types
Physics
- Newtonian
- Keyed
- Boids
Visualization
Controlling Emission, Interaction and Time
Cache & Bake
Hair
Children
Vertex Groups
Particle Mode
Soft Body
Introduction
Exterior Forces
Interior Forces
Collisions
Simple Examples
Combination with Armatures
Combination with Hair Particles
Reference
Cloth
Introduction
Fluids
Fluid
Using the Game Engine
Using the Game Engine
Rendering
Introduction
Introduction
Camera
The Camera
Perspective (Vanishing points)
Depth Of Field
Render
Displaying Renders
Basic Options
Antialiasing (Oversampling)
Rendering Animations
Panoramic
Render Baking
Using the Command Line
Output
Output
Video Output
Effects and Post Processing
Introduction
Render Layers
Render Passes
Edges & Toon
Stamp
Color Management & Exposure
Depth Of Field
Motion Blur
Render Performance
Rendering Performance
Distributed Rendering
External Render Engines
Introduction
YafRay
Compositing with nodes
Composite Nodes
Introduction
Nodes Editor
Node Controls
Nodes usage
Nodes Groups
Composite Node types
Composite Node types
Input Nodes
Output Nodes
Color Nodes
Vector Nodes
Filter Nodes
Convertor Nodes
Matte Nodes
Distortion Nodes
Editing Sequences
Introduction
Introduction
The sequencer
Usage
Sequencer Modes
Sequence Screen Layout
Effects
Built-in Effects
Plugin Effects
Audio
Audio Sequences
Extending Blender
Introduction
Introduction
Python Scripting
Python Scripting in Blender
Setting up Python
The Text Editor
A working example
References
Python Scripts
Script Catalog
Bundled Scripts
Plugins
Blender's Plugins System
Texture plugins specifications
Sequence plugins specifications
Game Engine
Introduction
Introduction
The Logic Editor
Usage
Game Properties
Sensors
Introduction
Sensor Types
Controllers
Introduction
Expressions
Actuators
Introduction
Action
Camera
CD
Constraint
Edit Object
Ipo
2D Filters
Game
Message
Motion
Parent
Property
Random
Scene
Shape Action
Sound
State
Visibility
Cameras
Cameras
Dome Camera
Physics
Physics Engine
Material Physics
Object Types
- Static
- No Collision
- Dynamic
- Rigid Body
- Soft Body
- Occluder
- Sensor
Python API
Bullet physics
VideoTexture
Various resources
List of Features
External resources
Game Engine Basics (BSoD Tutorial)
FAQ