3/4

3. Cloth simulation

3D mass spring simulation

Simple spring

Consider the code in 02_cloth_simulation/mass_spring. This code models two particles pa and pb linked by a spring. Particle pa is fixed at position \((0,0,0)\), while pb is free to move. The numerical integration is performed using explicit Euler

  • Observe that the discrete solution quickly diverges when running the code.

  • Change the numerical integration to semi-implicit Euler (/verlet). You should get a permanently oscillating spring.

  • Set the time step to \(h=1.99/\sqrt{K/m}\) - is the simulation stable ?

  • Set the time step to \(h=2.0/\sqrt{K/m}\) - is the simulation stable ?

Coupled springs

  • Add a new particle pc linked by a second spring to pb and set its initial position to \(p_c(0)=(1,0,0)\)

    • Adapt the forces accordingly - check that you get a correct coupled interaction between \(p_b\) and \(p_c\).

  • Add a friction force such that the speed of particles decrease toward a static equilibrium.

Chain of springs

  • Generalize your code to model a chain of arbitrary number of mass springs (ex. modeling a deformable rope, hair, etc). Each particle is linked to its k-nearest neighbors (start with k=1, and then test with 2 and 3 to model bending constraints).

Cloth

Consider the code in 02_cloth_simulation/cloth

A cloth surface is modeled as a mesh where vertices are initially placed on a regular grid. So far, only the weight is applied on the particles, but not the forces of springs. Two vertices are constrained to remain fixed (see variable positional_constraints to remove/add new positional constraints).

The objective is to implement the network of springs able to model the behavior of a cloth. You may observe that the code already provides

  • A set of GUI-based controlers on the time scale multiplicator applied on \(h\), stiffness, damping, mass, and wind force. These parameters are available inside the code (only time scale is used in the initial code).

  • The possibility to desactivate the cloth texture and display the wireframe, which may be helpfull for debugging.

  • An automatic check is performed after each numerical integration to detect a possible divergence of the system (detect_simulation_divergence). In such case, the simulation is stopped (with an error message on the command line). You can still force to continue the simulation anyway when clicking on "Start anim". A new simulation can be started again when clicking on "Initialize Geometry".

Implementation

  • Implement friction force (parameterized by the "Damping" value) on each particle.

  • Implement the forces related to springs.

    • Add first the forces of structural springs only and make sure that you get a plausible behavior before adding more forces. Using wireframe mode with slow time step and coarse mesh (few particles) can help debugging if something is wrong.

    • Add forces modeled by shearing and bending springs.

  • Note the effect of spring stiffness and mass on the resulting simulation.

    • You may add more springs, linking for instance 2-, or 3-neighborhood, if you want to model more rigid and smooth behavior for higher resolution meshes.

  • Implement the collision detection and response with respect to the ground and the sphere in the function collision_constraints. Note that the parameters of the radius and position of the sphere as well as the height of the ground are available in the variable collision_shapes.

  • Implement the action of the wind. How do you model such force ?