School project

XPBD: Cloth and Soft-Body Simulation

Implementing an XPBD constraint solver in C++ to explore ropes, cloth, self-collision, and tetrahedral soft bodies through an interactive OpenGL viewer.

  • Simulation
  • Physics
  • C++
  • XPBD
  • OpenGL
Watch demo View source Read report (PDF)

Overview

For my final-year Advanced 3D Computer Graphics project at Télécom Paris, I explored Extended Position-Based Dynamics (XPBD) by implementing a C++ constraint-based simulation application. The same CPU solver is used to experiment with a hanging rope, cloth, and deformable solids, while OpenGL displays the results and an ImGui interface exposes the simulation parameters.

The project follows the ideas in XPBD: Position-Based Simulation of Compliant Constrained Dynamics and Small Steps in Physics Simulation. I was particularly interested in how the formulation of constraints and the choice of integration method affect the resulting motion.

Cloth simulation from the XPBD project
Cloth simulation from the XPBD project

A shared XPBD solver

In a position-based solver, particles first move under external forces, then constraints correct their predicted positions. Rather than deriving a separate force law for every material, each constraint evaluates an error and its gradients with respect to the particles it affects.

XPBD extends this approach with compliance and accumulated Lagrange multipliers. In my implementation, each correction depends on the constraint error, particle inverse masses, and a compliance term scaled by the squared time step. This makes it possible to represent constraints that are not perfectly rigid, while using the same solver code for different kinds of geometry.

I implemented two update modes to compare the integration strategies:

  • Iterations: predict a full time step, then repeatedly solve the constraints before updating particle velocities.
  • Substeps: divide the frame interval into smaller steps, solving the constraints once per substep and reconstructing velocities along the way. This path also uses damping.

The three-particle rope is a useful test case because differences in its motion are easier to inspect than in a large cloth mesh. My project report includes trajectory comparisons between the approaches. The substep mode is not simply a faster version of the iterative solver: its damping and update sequence also influence the behavior.

Cloth constraints and self-collision

The cloth is a grid of particles connected by distance constraints along its edges and diagonals. I also added longer-range distance constraints to resist bending. I chose this simpler approximation instead of angle-based bending constraints because it is easier and less expensive to evaluate, although it does not prevent triangles from flipping.

Several scenes reuse these constraints: a hanging sheet, cloth falling over a sphere, and a cloth loop interacting with two cylinders. They use the same underlying particle solver, with different initial geometry and obstacle constraints.

Self-collision required another layer of logic. Following ideas from Ten Minute Physics, the implementation groups particles into a spatial hash grid, queries nearby cells, and creates temporary minimum-distance constraints for candidate particle pairs. This self-collision path is applied in substep mode. It is an approximation based on particle separation, not continuous collision detection for the cloth triangles, so some intersections can remain.

Deformable solids with tetrahedral constraints

I extended the same framework to a soft-body scene using a tetrahedral bunny. Each edge has a distance constraint, while each tetrahedron has a volume constraint based on the signed volume relative to its rest configuration. Together, these constraints let the solid deform while resisting changes to its internal shape and volume.

The supplied bunny contains 333 particles and 1,351 tetrahedra. The geometry and tetrahedralization come from the Ten Minute Physics soft-body example; my work here was to integrate that data with the XPBD constraints and simulation. Changing the distance and volume compliance values provides a way to explore different deformation responses, without claiming calibrated physical material properties.

Visualization and interaction

To inspect the simulations, I built an OpenGL viewer with scene selection, solver settings, camera controls, and mouse-driven particle dragging. Deformed particle positions are transferred to the display meshes, whose geometry and normals are updated for rendering. Selected scenes also use a directional shadow map and a checkerboard floor to make shape and contact easier to read.

The application can export PNG frame sequences for video assembly. Besides the working rope, cloth and tetrahedral examples, I experimented with rigid-body and fluid constraints, but those paths were not completed; they are not part of the demonstrated results here.

Demo and report

The project report contains additional implementation details and comparisons of solver strategies, bending constraints, self-collision, and soft-body deformation.