CS 294 Project 3"Stable and Responsive Cloth"
Steve Martin
For this project, I chose the option to build a semi-complex particle system. I chose to do this because I am interested in particle simulation in general, and also because I read several papers on cloth modeling when considering a final project, and I wanted a crack at it! The goal of this project is to simulate the animation of a piece of cloth using a physically based model. The model consists of series of masses and springs. The constants of these springs can then be manipulated to present different types of cloth behavior. In addition, other aspects of the cloth such as its size, the mass of a particle in the cloth, and the density of particles per square meter are available for tweaking to allow different simulation effects. This page presents the results of my work. I built a fairly robust cloth simulation in Win32 using OpenGL. The program is highly configurable and can handle cloth with a large number of particles. The model uses the Runge-Kutta explicit integration scheme with a small amount of damping so that extremely stiff cloth is possible. In addition, the cloth can interact with objects in the environment.
The Cloth Model Cloth StructureBy itself, my cloth object consists of a series of masses and springs. Each mass is represented by a particle, and linked to its neighbors by a series of springs. In my model, there are three different types of springs:
Figures 1 through 5 show the spring connection model used in this simulation.
Although there are other methods of hooking up springs for cloth simulation, this technique, which I read about in work by Chahal [1], worked well. Once the springs have been connected, the cloth animation is created through integrating Newton's second law of motion. To do this, we need sum up the forces on each particle, both from global sources such as wind and gravity as well as from the springs connected to it. From these forces, we solve for velocity, and from velocity we get the new position of each particle. In other words, given the i, j-th mass in an lattice of mn masses, we compute the following.
From equations 1 through 3, we can see that:
The last equation is also known as Newton's motion equation. Before we can solve for the acceleration, etc, we need to find the total force Fi,j(t) on the i,j-th mass, which we determine from the model.
Forces There are both internal and external forces acting on my model. Internal forces are the forces exerted by the cloth springs on each node. This force can be calculated using the following equation:
Looking at equation 4, we see that
The cumulative force vector is
calculated by summing the force for each type of of spring connecting the
point. Note that points on the outer edges have less springs attached
to them.
In equation 5, we see that:
Wind is also very straightforward. Wind is a case of vicious fluid resistance, and can be treated as such in our model. The equation for wind or air resistance is:
In equation 6,
Finally, I added a damping force, which provides a loss of mechanical energy of the cloth. The equation for damping is:
Where:
Adding these forces with the sum of the internal forces imparted by the springs gives a net force for the node. From here, we can solve for the accelleration and then perform numerical integration to get the velocity and positions of the particles.
Numerical Integration Method For this project I initially started out with Euler numerical integration and lots of damping. However, as I started working on collisions and various stiff spring values, it became more and more clear that the Euler method just wasn't good enough. So, with some help from a good explanation by Hugh Jack [2], I implemented 4th order Runge-Kutta integration. The following equations describe this method. Assume that x(t) is a function that represents the state of mass i, j at time t. Equations 1-3 show how to do calculate position, velocity, and acceleration at a given time. From this, we now calculate:
Where:
Using this method, I was able to vastly decrease the amount of damping in my simulation, making some of the cloth types motioned in the next section possible. Although it is slower, larger time steps are possible with this integration method.
Results of Physical Cloth Simulation Using the model described in the previous section, I built a program that can animate a piece of cloth in various interesting ways. The first result I present is just simple cloth consisting of more than 20,000 particles with equal spring constants and medium damping swinging from a pin. Gravity is set at 9.8 m/s2 throughout all of the following movies. All of these examples were recorded in real time, and are compressed using the DivX 5 codec. Movie 1: Simple cloth hanging from nail [513 KB] Next, I started tweaking the various spring constants to simulate different types of cloth. I found that certain ratios of stiffness between the structural, shear, and flex springs gave drastically different results. Table 1 gives the relationship between cloth types and spring constants.
The following movie demonstrates the cloth types listed in table 1. In the movie, the upper left cloth is canvas, the upper right piece is silk, the lower left piece is knit or fleece, and the lower right piece is of rubber. Movie 2: Demonstration of cloth type simulation [2.62 MB]
Collisions with Static Objects The next step in my simulation was to allow the cloth to collide with solid objects. To do this, I ended up using techniques developed by Fedkiw [3] and Provot [4]. Subsequently, my program can handle collisions between cloth and two types of simple objects: boxes and spheres. For both of these objects, the basic method is the same. The first step is to detect when a cloth node is inside the surface, and then get the nearest point on the surface. For both of the aforementioned object types, this is straightforward. Boxes consist of planes, so a simple set of comparisons will suffice for both collision detection and nearest point on the surface. For spheres, if the point is within a radius length of the middle it is inside the sphere, and then we solve the equation for a sphere as in ray tracing to get the point on the surface. Next, the node is projected back to the surface of the object. Assuming that the object is at rest, we can modify the penetrating cloth particle's velocity using the following equation.
Where d is the depth of the mass node inside the object, and n is the unit vector pointing towards the nearest point on the surface. This equation can also have a constant multiplied to the d/Dt term to relax the collision reaction. I found this to be useful when the object is moving. In my model, I disregard elastic energy. Another component of cloth collision is friction. In my model, I have only rudimentary friction; I did not have time to play with this aspect of collisions. However, ideally, there would be kinetic and static friction components in any collision. The following movies show the results of collision between my cloth and static objects. I chose a particularly stiff cloth in each of these movies to better show the drape of the cloth as it collides with the object. Note that cloth-on-cloth collision is not handled fully due to time constraints; this is particularly noticeable in the last clip. Movie 3: Cloth colliding with a box [734 KB] Movie 4: Cloth colliding with a sphere [1.01 MB] Movie 5: Cloth colliding with multiple objects, and then sliding off the objects. [1.64 MB]
I really enjoyed this project, despite being extremely pressed for time on final projects. I have always wanted to experiment with cloth simulation, and this was as good an excuse as one can get! There is a lot of improvement left to be done in my cloth simulation. First of all, I could optimize it heavily; it only ran quickly because I was working on a fast machine. Secondly, I do not handle cloth on cloth collisions very well. My program can detect point collisions and force those outside the cloth, but I do not detect point-in-triangle collisions, leading to some unwanted penetrations. If I had more time to spend on the program, I would work on coming up with a nice solution for this. Finally, implementing friction effects would have been a lot of fun and could vastly improve my results.
References [1] Chahal, Pardeep. Physically Based Model of Cloth Draping, 2001. http://members.shaw.ca/chahal/clothpaper.htm [2] Jack, Hugh. Runge-Kutta Integration, 2001. http://claymore.engineer.gvsu.edu/eod/refer/refer-52.html [3] R. Bridson, R. Fedkiw, and J. Anderson, Robust treatment of collisions, contact and friction for cloth animation, 2002, ACM Trans. Gr. (Proceedings of SIGGRAPH’02), vol. 21, pp. 594 – 603 [4] X. Provot, Collision and self-collision handling in cloth model dedicated to design garment, 1997, Graphics Interface, pp. 177 – 89Various OpenGL help sites Various math help sites (Wolfram, etc) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||