|
The illustrations above come from a cloth simulation that I wrote, based on an article about simulating physics for video games. In order to model the movement of cloth, I divided it into small pieces, like the squares of a quilt, which are easy to simulate individually. When all the pieces are joined together, the collection behaves like fabric. The individual pieces of the cloth, the quilt squares, are relatively stiff and unbending. Most of the flexing happens at the seams, where the squares are joined together.
Every time-step, the program applies forces (such as gravity or wind) to each vertex (corner of a quilt square) of the cloth. Since these forces are a little different for each vertex, they will be moved apart from each other in various directions, like smoke particles blowing in the wind. But once this is done, the program corrects the distances between the vertices to make sure the four corners of each square stay the correct distance from each other. Distance is measured using the familiar distance formula √(x² + y² + z²).The program checks all four edges and the two diagonals of each square to make sure that they are the right distance apart. If they aren't, it either moves them closer together or farther apart to try to correct the situation. The only thing which can change without being corrected is the angle between each square and its neighbors. After everything is calculated, the program shows it all on the screen, and moves on to the next time-step.
Implicit surfaces are used to check if the fabric has landed on an object. The coordinates of each vertex of the cloth are plugged into the implicit function describing the object. For example, to see if the cloth has landed on a cylinder of radius 1 centered at the origin, we replace x and z in x² + z² - 1 with the x and z coordinates of each vertex of the cloth. If the answer comes out positve for a particular corner, the vertex is outside the cylinder. If it comes out to zero, the vertex is resting right on the surface and should stop where it is. If it comes out negative, the vertex has fallen into the interior of the cylinder, so it needs to be moved back out again.
The image above on the left shows what has been described so far (simple.exe, below). It moves like cloth, but looks unreal. In the right image, two major changes have been made. First, the flat quilt squares have been replaced with curved surfaces that pass through all of the same vertices. This gives the cloth a smooth, flexible appearance. Second, the cloth is prevented from passing through itself by a repulsive force between any two vertices of the cloth which get too close. In order for this to work well, no part of the cloth can be moving too fast, or it could pass through the cloth before the force could act on it. So there is an absolute speed limit imposed that prevents any part of the cloth moving too fast. This field requires a lot more computation than any other part of the program. With this feature added, doubling the number of squares along the length and width of the cloth would make it take 16 times as long to calculate each frame.
There are a few things that could be done to improve the program further. There is no friction between the cloth and itself or the walls and floor. Also, if the cloth is jammed hard enough against the paraboloid in the center, it can be forced to pass through itself.
If you would like to see the fabric in action, you can run this version of my cloth program by using the links below. Try pressing the following keys while the program is running:
| arrow keys | drag cloth around by one corner |
| Q | turn cloth transparency on or off |
| W | make the walls visible or invisible |
| E | show individual faces or curved NURBS surfaces |
| R | turn off self-intersection testing (bad things may happen if you try to turn it back on) |
| T | turn quilt texture off and on |
| Y | display cloth in point mode or line mode |
| U | make the paraboloid visible or invisible |
| 1 and 2 | turn diagonal shear springs off and on (turn both off for a liquid effect) |
| 3 and 4 | turn structural springs off and on |
| 5 and 6 | turn bend springs off and on (cloth can make sharper bends at seams with these off) |
cloth.zip This is the complete cloth program described on this page. Open this zipped archive and extract the contents to a folder. Then run cloth.exe. If it runs too slowly on your system, run lite.exe, a trimmed down version, instead.
simple.exe This is the same program, but with 80 squares by 80 squares instead of 45 by 45 and with the advanced features turned off. This can be run just by clicking on it.
| |