Physics & Simulation

GPU-accelerated cloth, rope, fluid volumes, and rigid body physics. All solvers run on compute shaders via vGPU.

Cloth Simulation

Mass-spring cloth solver in engine/sim/cloth/. Each cloth is a grid of particles connected by structural, shear, and bending springs. The solver runs on GPU compute with configurable:

Rope Physics

Position-Based Dynamics (PBD) rope solver in engine/sim/particles/RopePhysics.js. Ropes are chains of particles with distance constraints solved iteratively.

Rope Features

Fluid Simulation

Two approaches to fluid simulation:

Lagrangian (SPH)

Smoothed Particle Hydrodynamics via the particle system. Each fluid particle carries density, pressure, and viscosity. The SPH solver computes inter-particle forces using a neighbor grid. See ParticleSPH.js.

Eulerian (Grid-Based)

ParticleEulerianFluid.js provides a grid-based fluid solver using the Navier-Stokes equations. Suitable for contained volumes (pools, rivers). Uses pressure projection and velocity advection on a 3D grid.

Rigid Body Physics

The ECS PhysicsBody component drives rigid body simulation:

PBD Ragdoll

Position-Based Dynamics ragdoll solver for character physics. Joint limits, bone chains, and muscle constraints. Integrates with the AGI system for learning-based locomotion.

Simulation Update

SimulationUpdate.js (30K lines) orchestrates all simulation systems per frame:

  1. ECS physics system tick (rigid bodies, colliders)
  2. Cloth solver step (GPU compute)
  3. Rope constraint solving (PBD iterations)
  4. Particle simulation (main compute + advanced subsystems)
  5. Fluid pressure solve (if active)

GPU Physics Engine

New: A full WebGPU compute-based physics engine with PhysX 5.4.1 feature parity has been built. 15 modules covering rigid bodies, broadphase, narrowphase, constraint solver, CCD, vehicles, character controllers, FEM soft bodies, triggers, scene queries, heightfield, and triangle mesh collision.

Read the full GPU Physics Engine documentation →

Key Files

FilePurpose
sim/SimulationUpdate.jsMaster simulation orchestrator (30K)
sim/cloth/Mass-spring cloth solver
sim/fluids/Eulerian fluid volumes
sim/physics/Rigid body physics system
sim/particles/RopePhysics.jsPBD rope solver
sim/particles/RopeMaterial.jsRope material properties
sim/particles/ParticleSPH.jsSPH fluid solver
sim/particles/ParticleEulerianFluid.jsGrid-based fluid
sim/particles/ParticleConstraints.jsDistance/position constraints (59K)