paaracetamol / soft-body-cube

Soft body physics

Squishy cubes from scratch, built on the XPBD paper.

Thumbnail of the soft body physics video showing a deformed cube mesh

soft-body-cube / README.md

The idea Squishy cubes you can grab.

A real time soft body simulator in Python, PyOpenGL and Pygame. Deformable cube meshes, interactive mouse grabbing and a 3D camera.

Entirely based on the XPBD paper. Making the video took longer than the code, because I had to learn manim to animate the maths.

Position based dynamics Predict, then correct.

Instead of integrating forces directly, each particle’s next position is predicted and then corrected until the constraints hold. That keeps it stable even with large time steps.

Constraints

Distance
Every pair of connected particles keeps its rest length, like an elastic link.
Volume
Each cube is split into tetrahedra and each one keeps its rest volume, so the cube squashes instead of collapsing or inflating.

Screenshots. Straight from the repo.

A soft cube mesh deforming
A soft cube mesh deforming
Thumbnail of Making soft body physics from scratch

Watch the devlog. 1,121 views.

Making soft body physics from scratch

Watch on YouTube