Simulation - Mass-springs Cloth
Path of the code: [03_cloth]
- A cloth surface is modeled as a mesh where vertices are initially placed on a regular grid.
- So far, only the weight (and a drag/friction force) is applied on the particles.
-
Two vertices are constrained to remain fixed (see the variable
constraintinsrc/scene.hpp: the functionsconstraint.add_fixed_position(ku,kv,cloth)/remove_fixed_positionadd/remove new positional constraints, seescene_structure::initialize_clothinsrc/scene.cpp).
- The GUI provides
-
-
- Sliders on the time step \(h\) ("Time step"), the stiffness ("Stiffness"), the damping ("Damping"), the mass ("Mass"), and the wind ("Wind magnitude"). These parameters are available inside the code in the variable
parameters(structuresimulation_parametersinsrc/simulation/simulation.hpp). The stiffness and the wind are not used in the initial code. - - The possibility to deactivate the cloth texture ("Texture Cloth") and display the wireframe ("Wireframe"), which may be helpful for debugging.
-
- Sliders on the time step \(h\) ("Time step"), the stiffness ("Stiffness"), the damping ("Damping"), the mass ("Mass"), and the wind ("Wind magnitude"). These parameters are available inside the code in the variable
-
An automatic check is performed after each numerical integration to detect a possible divergence of the system (function
simulation_detect_divergence). In such case, the simulation is stopped (with an error message on the command line).
Adding spring forces
The objective is to implement the network of springs able to model the behavior of a cloth.-
> Add the forces related to springs in the function simulation_compute_force (file
src/simulation/simulation.cpp). -
- - 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.
- - Then add forces modeled by shearing and bending springs.
- Consider a spring of stiffness \(K\) and rest length \(L_0\) attached between a point \(p_i\) and \(p_j\). The force exerted by the spring on the point \(p_i\) is
-
- \({\bf F}= - K (\|p_i-p_j\|-L_0) \frac{p_i-p_j}{\|p_i-p_j\|} \)
- 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 simulation_apply_constraints (file
src/simulation/simulation.cpp). Note that the radius and position of the sphere as well as the height of the ground are available in the variable constraint (constraint.sphere.center,constraint.sphere.radius,constraint.ground_z).
- > Implement the action of the wind. How do you model such force ?