Real-Time Cloth Simulation
[implementation | videos | executable demo ]
Implementation and Sample Code
Cloth Simulation
The cloth simulation algorithm I implemented is based on the paper "Advanced
Character Physics" by Thomas Jakobsen in the proceedings of the Game Developer's
Conference, San Jose, 2001. The method represents a piece of cloth as an array
of particles linked by distance constraints. The particles of the cloth are
updated in two different ways:
- Verlet Integration
This is a velocity less integration method similar to the Euler integration
method. This is used to integrate all field forces such as gravity and wind.
The advantage of this method is that, because it does not explicitly store
the velocity of each particle, it is much more stable than the Euler method
when particles are translated to satisfy constraints. This allows for more
stable resting and collision contacts in the simulation. - Iterative
Constraint Solving
After the particles are updated with the forces acting on them, the algorithm
uses Non-Linear Gause-Siedel Relaxation to satisfy the distance constraints
between the particles and ensure that particles of cloth do not penetrate
the projectiles or the floor. The relaxation method satisfies each constraint
locally, in turn, by translating the violating particles; repeating until
all of the constraints are satisfied to within some tolerance. A common optimization
is to terminate the relaxation after a set number of iterations. This results
in consistently fast simulation updates, at the price of error in the constraints
and slightly rubbery cloth.
The cloth particle system is maintained using an array of packed floats to
optimize speed and memory usage.
Source Code: SimCloth.h, SimCloth.cpp
Projectiles
The projectiles in the scene are simply spheres that can be launched at a
particular speed and direction, and then fly under the force of gravity until
they collide. Projectiles are also integrated using the Verlet integration
scheme. Iterative relaxation is used to handle collisions between spheres,
with the ground, and with cloth. In the relaxation process the cloth is allowed
to effect the spheres, enabling the spheres to display realistic response
to collision with the cloth.
Source Code: SimSphere.h, SimSphere.cpp, ProjectileLaunchParams.h
Scene Manager
For this demo I implemented a very simple scene manager, that maintains a
list of all objects in the scene for simulation and rendering, and culls those
objects that are not active. The scene manager is initialized in a main program,
which renders the objects in the scene, along with the cannon model, and
allows simple user interaction.
Source Code: SimScene.h, SimScene.cpp, main.cpp
Videos
|
Hanging Cloth with Collisions
This scene shows 2 pieces of cloth, 900 particles each, hanging in
the air. The cloth sheets react when they are impacted by projectiles
launched from the cannon. The cloth also exerts force back onto the projectiles,
causing them to lose velocity and drop to the ground.
The simulation together with rendering runs at approximately
41 frames per second.
Videos: <MPEG 2.0MB>
|
|
Pinned Cloth with Collisions and Object Support
This scene more clearly illustrates the ability of the cloth to exert forces
on objects in the scene. The cloth net, with 900 particles, reacts when impacted
by the projectiles. The cloth exerts a force back on the particles, holding
them suspended in the net.
The simulation together with rendering runs at approximately
42 frames per second.
Videos: <MPEG 4.1MB>
|
Demo
Hanging Cloth and Cannon