Pratyai Mazumder, Tal Rastopchin, and Konstantinos Stavratis.
An implementation of cloth simulation using projective dynamics. Written in Python. Created as the final project of the Physically-Based Simulation in Computer Graphics course at ETH Zürich the fall of 2022.
The two demo programs that we have put together are src/demos/spring_demo.py and src/demos/strain_demo.py. Each demo program reads a .obj triangle mesh and allows the user to interactively model cloth simulation. The spring_demo models the cloth with a mass-spring system and the strain_demo models the cloth as a triangle mesh with a continuous strain energy.
Your local Python environment requires the following libraries to run our demos:
From within the src directory, we run the spring_demo with the input triangle mesh data/square_100_unstructured.obj as follows:
python -m demos.spring_demo ../data/square_100_unstructured.obj
(You might need to find the Polyscope application window after the program starts.) Hovering over the controls button of the Polyscope panel on the left-hand side of the application explains view and menu navigation. All of the panels on the left-hand side of the application allow the user to change how the 3D scene looks.
The Command UI panel on the right-hand side of the screen allows the user to control the cloth simulation.
The system parameters subpanel allows the user to control the simulation's underlying system parameters.
-
The
Initialize / resetbutton both applies the specified system parameters as well as resets the simulation. This means that every time after the user changes the point mass, spring stiffness, or pinned vertices, this button must be clicked to update the system and apply the parameters. -
The
Point massfloat input field allows the user to specify the mass of each point. (This value is used as a scalar coefficient during the construction of the underlying system's lumped mass matrix.) -
The
Spring Stiffnessfloat input field allows the user to specify the spring stiffness constantkused for every spring in the system. -
The
Pin Selected Vertexbutton allows the user to click on vertices and mark them as pinned. To do this, the user must left-click on a vertex. Note: it is important that theSelectionpanel that pops up under theCommand UIpanel specifies that the selection is anodeand not anedge. After selecting a vertex, the user can then clickPin Selected Vertexand it will get added to the list of pinned vertices. The user can see the indices of the pinned vertices displayed underneath thePin Selected Vertexbutton. To the right of the button there is aClear Selectionbutton which clears the list of pinned vertices.
The simulation control subpanel allows the user to control the simulation.
-
The
Start/Stopbutton start and stop the simulation, respectively. -
The
Step sizefloat input field allows the user to specify the implicit Euler step sizeh. The default value of0.01seems to work well. -
The
Steps per frameinteger input field allows the user to specify the number of projective dynamics implicit Euler steps to take each frame. The default value of10seems to work well. (Any smaller value and the application slows down due to the overhead of copying the vertex positions from our system's representation to Polyscope's curve network representation.)
From within the src directory, we run the strain_demo with the input triangle mesh data/square_100_unstructured.obj as follows:
python -m demos.strain_demo ../data/square_100_unstructured.obj
The Command UI panel on the right-hand side of the screen allows the user to control the cloth simulation.
The system parameters subpanel allows the user to control the simulation's underlying system parameters.
-
The
Initialize / resetbutton andPoint massfloat input field are identical to that of thespring_demo. -
The
Singular values epsilonfloat input field allows the user to specify "how much triangles can stretch past the strain constraint being locally satisfied". (Behind the scenes projective dynamics uses singular value decomposition (SVD) to "project" the current configuration of a triangle onto the constraint maniold SO(3). To ensure the rotation matrix (orthonormal matrix in the SVD) is in fact orthnormal, we clip the singular values to the range [1, 1]. The epsilon value is used to clip the singular values to [1 - epsilon, 1 + epsilon], allowing isotropic strain limiting where the strain constraint now is not binary and has a controllable epsilon threshold for "how much the constraint needs to be satisfied.") -
The
Pin Selected Vertexbutton is identical to that of thespring_demo. The only difference is that when selecting a vertex, theSelectionpanel that pops up under theCommand UIpanel needs to specify that the selection is avertexand no other halfedge mesh element.
The simulation control subpanel is identical to that of the spring_demo.
- Sofien Bouaziz et al. 2014. Projective dynamics: fusing constraint projections for fast simulation. https://www.projectivedynamics.org/projectivedynamics.pdf