Three.js Shape Inflation & Normal Offset

Inflate flat shapes into balloons in Three.js by solving a pressure equation on a Delaunay mesh, and compare normal-offset growth and shrinkage of meshes with split vs averaged normals.

Key topics: three.js inflate, balloon mesh, normal offset, laplacian, mesh deformation, teddy inflation

What this code does

- Shape Meshing: the outline plus jittered interior points are triangulated with Delaunay, dropping triangles outside the shape.
- Pressure Membrane: heights solve Δh = −p with h = 0 on the rim, using Jacobi iterations you can watch converge.
- Balloon Profile: a square-root mapping rounds the rim like a sewn pillow, with mirrored front and back layers.
- Deflate: negative pressure pulls the membrane inward into a dish.
- Normal Offset: p' = p + n·d grows or shrinks a mesh; split normals tear open at hard edges, while averaged normals stay closed but round off.
- Controls: mode, shape, pressure, rim roundness, mesh spacing, re-inflate, offset mesh, normal type, offset and breathing.

Continue Learning

JavaScript Implementation

ES6+
// Inflate a flat triangulated shape: solve Δh = −pressure with h = 0 on the outline
// `neighbors[i]` lists the vertices connected to vertex i; boundary vertices come first

function relax (h, neighbors, boundaryCount, pressure, iterations) {
  const next = new Float32Array(h.length)
  for (let k = 0; k < iterations; k++) {
    for (let i = boundaryCount; i < h.length; i++) {
      let sum = 0
      for (const j of neighbors[i]) sum += h[j]
      next[i] = sum / neighbors[i].length + pressure // average of neighbours + push
    }
    h.set(next)
    h.fill(0, 0, boundaryCount)
  }
}
// front vertex z = +sqrt(h), back vertex z = −sqrt(h) → a pillow / balloon