skip to content

How can a jelly-like soft body keep its volume and rest shape in a particle simulation, and how do volume constraints compare with shape matching?

level: middleimportance: nice to knowfreq 15%

answer

  1. a closed surface alone can collapse
  2. signed volume of a closed mesh
  3. best-fit rotation of the rest shape
  4. polar decomposition of the covariance
  5. pull each particle toward a goal

basics

~20 s

A volume constraint holds the signed volume of a closed mesh, or of each tetrahedron, at its rest value; shape matching fits the rest shape to the current particles with the best rotation and pulls each particle toward its fitted position.

solid answer

~50 s

Distance constraints on a jelly's surface alone let it fold flat, because a crushed surface can keep every edge length. A **volume constraint** adds `C = V - V0`, with `V` the signed volume of the closed surface, `(1/6) * sum of dot(cross(pa, pb), pc)` over outward-wound triangles, or one per tetrahedron. It keeps the jelly inflated but does not remember the shape: any shape with the same volume satisfies it. **Shape matching** computes the current centre of mass `c` and the rest one `c0`, builds `A = sum m * (x - c) * transpose(x0 - c0)`, takes the rotation `R` from its polar decomposition, and pulls each particle toward `g = R * (x0 - c0) + c`. It pulls back toward the rest shape even from a crushed or inverted state, but one cluster wobbles too rigidly; overlapping clusters restore local softness.

go deeper

for a junior

Recall that a soft body needs something beyond edge lengths to stay inflated: a volume constraint or shape matching.

for a middle

Explain the signed-volume constraint and the shape-matching steps: centres of mass, the matrix A, its rotation, goals, and a pull toward them.

for a senior

Choose per asset: volume for squishy bulging, shape matching for springing back from crushes, clusters for local softness, and watch for inverted tetrahedra.

for a principal

Weigh visual goals against cost and robustness when soft bodies must survive gameplay abuse, and set which technique each class of asset uses.

## Why distance constraints are not enough A soft body in a particle simulation is usually a closed surface mesh, a lattice, or a tetrahedral mesh filling the interior. Distance constraints along a closed surface's edges keep it from stretching, but they say nothing about what is inside. A jelly made only of surface edges can fold flat, buckle inwards or end inside out while every edge keeps its rest length. Two additions fix that, and they fix different things. ## Volume constraints A **volume constraint** measures enclosed volume and pushes it back to its rest value. - **Global volume of a closed surface.** With triangles wound counter-clockwise when seen from outside, and the right-handed cross product, the signed volume is `V = (1/6) * sum over triangles (a, b, c) of dot(cross(pa, pb), pc)`. The constraint is `C = V - k * V0`, where `V0` is the rest volume and `k` an optional overpressure factor that inflates the body like a balloon. - **Per-tetrahedron volume.** Each tetrahedron `(p1, p2, p3, p4)` gets `C = (1/6) * dot(cross(p2 - p1, p3 - p1), p4 - p1) - V0_tet`. This keeps volume locally, everywhere inside the body. The gradient for the global form is simple: for each triangle containing particle `a`, its contribution is `(1/6) * cross(pb, pc)` with the triangle's other two vertices in winding order, summed over those triangles. The projection then follows the usual position-based formula, weighted by inverse mass. The limits are just as clear: - volume holds, but **shape does not**: a squashed jelly bulges out somewhere else and stays that way; - a global constraint couples every particle, so a poke on one side moves the whole surface; - tetrahedral constraints need an interior mesh, and heavily crushed or inverted tetrahedra can recover into a tangled configuration rather than the rest shape. ## Shape matching, step by step **Shape matching** treats the rest shape as a template and asks where the template would sit if it were moved rigidly to fit the current particles as well as possible. With rest positions `x0_i`, current positions `x_i` and masses `m_i`: 1. Compute the current centre of mass `c = sum(m_i * x_i) / sum(m_i)` and the rest centre `c0` the same way. 2. Build `A = sum m_i * (x_i - c) * transpose(x0_i - c0)`, a 3x3 matrix relating current offsets to rest offsets. 3. Take the **rotation** `R` from the polar decomposition `A = R * S`, discarding the symmetric stretch `S`, and make sure `R` is a proper rotation, not a reflection. 4. Set each **goal** `g_i = R * (x0_i - c0) + c`. 5. Move each particle toward its goal by a stiffness fraction, `x_i = x_i + s * (g_i - x_i)`, or treat the goals as constraints in the position-based loop. Because the goals are always a rigidly placed copy of the rest shape, shape matching pulls back from any state, crushed flat or inside out. It needs no mesh connectivity at all. Its weakness is the flip side: one cluster can only express a rigid motion of the whole body, so a single cluster jiggles like a stiff rubber ball. Splitting the body into **overlapping clusters**, each matched separately, lets regions deform independently, and linear or quadratic extensions let the goal shape shear and bend within limits. ## Comparing them | | Volume constraint | Shape matching | |---|---|---| | Restores | enclosed volume | rest shape, up to rotation | | Needs | closed surface or tetrahedra | rest positions only | | From a crushed or inverted state | may stay wrong | pulls back reliably | | Local softness | per-tetrahedron form is local | only with clusters | | Typical use | inflated, squishy bodies | jelly, props that must spring back | ## Combining and tuning Real jelly usually uses both, plus surface distance constraints: - distance constraints for the skin's stretch; - a volume constraint so pokes bulge instead of collapse; - shape matching, at low stiffness or per cluster, so the jelly springs back to its rest shape.

  • Why does shape matching take the rotation from a polar decomposition instead of using the matrix A directly?
    A mixes rotation with the current stretch and shear. Using it directly would let the goal shape copy any deformation, so nothing would pull the jelly back. The rotation part is the best rigid fit of the rest shape, and checking its determinant avoids a reflection that would turn the goal inside out.
  • Why does a jelly with only a global volume constraint drift into odd shapes after being hit?
    Any shape with the right volume satisfies the constraint, so after a hit the surface keeps whatever bulge the impact left. Nothing remembers the rest shape. Adding shape matching, or per-tetrahedron constraints with distance constraints, supplies that memory.

Shape matching is like a transparent ghost of the jelly's rest shape that slides and turns to fit the blob as closely as it can, with every particle tied to its ghost twin by an elastic band. However the blob is squashed, the ghost stays a perfect copy, so the bands always pull back toward the rest shape.

  • Distance constraints on the surface edges alone will keep a closed jelly inflated.
  • A volume constraint restores the jelly's original shape after it is squashed.
  • Shape matching needs a tetrahedral mesh of the interior.
  • Shape matching can use the covariance matrix A directly as the goal rotation.
  • A single shape-matching cluster gives soft, local, jelly-like deformation.