Lecture 12: Animation 3 (Springs) (slides)Learning ObjectivesBy the end of this lecture, you will be able to:
|
Our main goal for today is to extend our discussion about particles from last class and model systems in which the particles may be connected. This will allow us to animate cloth (see the demo at the end of the notes), which is what you'll implement in this week's lab.
For some systems, such as an elastic string or cloth, we can model particles as being connected to each other through a mini spring. For example, we might model an elastic string as a bunch of springs attached to each other (see the figure above). The external force acting on each particle (a vertex in the mesh) would then depend on the position of the neighboring springs and is described using Hooke's law. Hooke's law states that the force
where
In the case of a cloth simulation, we have a grid of particles connected by springs, i.e. a 2d mesh instead of a 1d mesh we had above. The only extra complication is that instead of only having structural springs between neighboring vertices, we also have shear and bending springs:
We also need to be careful in the way we model the forces arising from springs near the cloth boundaries. Of course, you can add external forces such as gravity, wind, etc. to your equations of motion.
There are other ways to do cloth simulations with triangle meshes (instead of a grid). Many of these techniques also make use of adaptive methods (see this article), whereby anisotropic triangles are placed in regions in which the cloth currently exhibits a lot of curvature. Adaptation has the benefit of reducing computation time since you can potentially use fewer triangles to resolve the cloth motion with the same accuracy. The difficulty arises in how to automatically determine where these triangles should be placed (and how to orient them) - this is related to my research so please feel free to ask me about it!
It can be tricky to model cloth with the methods above because there's a lot of bookkeeping needed to keep track of the forces between neighboring particles, and we need to be careful with how the equations are applied at boundaries. Also, separately updating position and velocity like we did last class can be error prone. Remember, we're not trying to model the physics perfectly, we just want something to look okay (the previous methods aren't exactly physically correct anyway). Let's continue with the spring-mass model, but this time, we'll model the springs as a bunch of constraints and also use Verlet integration to update the particle positions. Instead of updating the position and velocity by computing the right-hand-side of our system of ODEs, Verlet integration updates the positions directly using:
where
where
where
We would then immediately set
// cloth update algorithm for one time step (frame)
for numIter iterations: // numIter is usually about 1 or 2
for each particle:
particle.forceUpdate(); // compute new position using external forces and Verlet integration
for each constraint:
p = constraint.p; // first endpoint vertex (vec3)
q = constraint.q; // second endpoint vertex (vec3)
delta = (||q - p|| - L0)/||q - p||; // scalar
dx = delta * (q - p); // vec3
mt = mp * mq / (mp + mq); // mp and mq are the masses of particles p and q
constraint.p += dx * mt / mp;
constraint.q -= dx * mt / mq;
With this scheme, you can also impose certain vertices to be fixed with this weighting: just set
Here is an example of a cloth animation using the scheme described above, which you will implement in this week's lab. Try clicking one of the particles (dots) and pull it around. The animation will then re-run and it should look like a swaying cloth!
We can also model hair using the techniques we saw today in which each strand of hair is a collection of springs. Based on the type of hair, certain types of springs (structural, shear or bending) may have more of an influence on the motion of the strand. For a recent research paper about modeling tightly-coiled hair, please see this project.
© Philip Claude Caplan, 2023 (Last updated: 2023-12-07)