Cloth simulation has been an important topic in computer graphics since the 1980's. In this assignment, you will implement a particle system and use this system to simulate cloth based on the mass-spring model. You will also explore Maya's ncloth, a more complicated cloth system.
If you are using our starter code, a particle class and a generalized force structure is already in place. You must implement two subclass forces: GravityForce and SpringForce.
Arrange your particles properly and connect them to form a piece of cloth by adding: strench spring and damping forces, shear spring and damping forces, bend spring and damping forces.
Your handin directory is at /afs/cs.cmu.edu/academic/class/15464-s13-users/andrewid if you are in 15-464 or /afs/cs.cmu.edu/academic/class/15664-s13-users/andrewid if you are in 15-664. Please submit the following:
In addition, please submit your code, brief documentation on how to run it, and a list of features you chose to implement. Your code should be able to run on the Gates cluster machines.
Also note that if you have not presented yet in the semester, you will be presenting your work in class this time.
There is starter code built on the basic viewer from the previous assignments, located at http://www.cs.cmu.edu/~15464-s13/assignments/assignment3/AMCViewer-Project3.zip. The files we added to the basic viewer are located in the \Character" directory.
This code also contains an updated BrowserMode.hpp and BrowserMode.cpp, which loads the particles and springs into the viewer.
Simulating cloth has two steps: 1. Compute forces and acceleration for each particle 2. Integrate the acceleration to get the new cloth position.
We will use the mass-spring model to model forces, and Forward Euler's Method to integrate the motion.
Mass-Spring Model
The Mass-Spring Model is a very basic method to simulate cloth. It is relatively easy to implement, and with some care can produce good results, so it is a good exercise before exploring more advanced methods.
In the Mass-Spring Model, cloth is simulated as a grid of particles, which are connected to each other by spring-dampers. Each spring-damper connects two particles and generates a force based on the particles' positions and velocities. We will use three types of spring dampers: stretch springs, shear springs, and bend springs. In addition to these spring forces, each particle is also influenced by gravity. The layout of this model is illustrated in the figure below:
Computing Forces:
Gravity: gravity is simply a force porportional to the mass of the particle. We can use the equation: $$ f_g = mg $$ Spring-Dampers: A spring-damper is dened by three constants: its spring constant $K_s$, a damping factor $K_d$, and its rest length $l_0$. We can compute the force using the equation: $$ f_1 = -\left[ k_s(|p_1-p_2|-l_0)+k_d \left( \frac{(v_1-v_2)\cdot(p_1-p_2)}{|p_1-p_2|}\right)\right] \cdot \frac{(p_1-p_2)}{|p_1-p_2|} \\ f_2 = -f_1 $$
Euler Integration:
Once we've computed the all the forces in the system, we can compute the acceleration of each particle. Using Newton's Second Law: $$ a_n = \frac{1}{m_n}f_n $$ Where $a_n$ is the acceleration of particle $n$, $f_n$ is the net force acting on particle $n$, and $m_n$ is the mass of particle $n$. After we compute the acceleration, we can use it to advance the simulation by a small time-step, $\Delta t$: $$ v_{n+1} = v_n+a_n \cdot \Delta t \\ p_{n+1} = p_n + v_n \cdot \Delta t $$ Note: Euler Integration is not stable, and may lead to erratic behavior if you use too large a time step. You may want to consider implementing a different method of integration.
Extra Credit: