Home

Assignment 5 — PBD Cloth

Due Thursday, 11/9 at 23:59:59. You must work individually.

Goals

In this assignment, we’re going to simulate cloth with Position Based Dynamics.

Setting up Eigen

For linear algebra, we’ll be using a C++ library called Eigen. You’ll have to install this in the same way you installed glm in lab 0. You’ll need to create a new environment variable called EIGEN3_INCLUDE_DIR that points to the Eigen directory. Once you have it installed, you may want to look at this quick tutorial.

Starting Point

Please download the assignment and go over the code.

Your main task is to complete the function Cloth::step(). The skeleton code has a lot of functionalities that deal with setting up the scene and rendering the cloth. Study the code carefully to see what is happening.

Setting up the Cloth

First, add some code into Cloth::Cloth() to set up the particles and the springs. Start with rows = cols = 2.

Time Stepper

Apply the XPBD stepping scheme:

for each particle i
   fi = mi * g - di * vi
   vi += (h / mi) * fi
   pi = xi
   xi += h * vi
end
for each constraint j between x0 and x1
   [Cj,Cj] = springConstraint(x0, x1)
   λj = -Cj / (w0 * |Cj0|^2 + w1 * |Cj1|^2 + αj/h^2)
   x0 += λj * w0 *Cj0
   x1 += λj * w1 *Cj1
end
for each particle i
   vi = (1 / h) * (xi - pi)
end

Keep in mind that some particles are marked as “fixed.” The positions and velocities of these particles should not be modified.

The spring constraint between particles \(\vec{x}_0\) and \(\vec{x}_1\) is \[ C = l - L, \] where \[ l = \| \Delta \vec{x} \|, \quad \Delta \vec{x} = \vec{x}_1 - \vec{x}_0. \] The gradients are \[ \nabla C_0 = -\frac{\Delta \vec{x}}{l}, \quad \nabla C_1 = \frac{\Delta \vec{x}}{l}. \] Note that for this constraint, \(\| \nabla C_i \| = 1\) because the norm of a unit vector is one. This means that the denominator for the calculation of \(\lambda\) can be simplified.

Sphere Collision

If you uncomment line 47 in Scene::load(...), you’ll see a collision sphere moving, but it won’t be affecting the cloth yet. We need to write some collision code first.

Implement collisions in Cloth::step(), right before the final update for the velocities. You must check all the cloth particles against all the collision spheres (which are also particles) in the scene, which in this case is just a single sphere. For each particle, if there is a collision, snap the position of the cloth particle onto the surface of the sphere.

In the image below, the smaller sphere represents a cloth particle, and the larger sphere represents the collision sphere. If collision is detected, move the particle in the direction from the center of the collision sphere to the center of the particle so that the two spheres are just touching.

Parameter Exploration

Try changing the compliance, damping, and time step parameters. Write a short paragraph in the README discussing the following:

Point breakdown

Total: 100 points

What to hand in

Failing to follow these points may decrease your “general execution” score.

If you’re using Mac/Linux, make sure that your code compiles and runs by typing:

> mkdir build
> cd build
> cmake ..
> make
> ./A5 <SHADER DIR>

If you’re using Windows, make sure your code builds using the steps described in Lab 0.


Generated on Mon Nov 27 20:12:50 CST 2023