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:
- Stiffness — Spring force coefficient
- Damping — Velocity damping factor
- Gravity — Per-cloth gravity override
- Wind — Directional force with turbulence noise
- Pin constraints — Fixed vertices (corners, edges, arbitrary)
- Collision — Sphere and plane collision response
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
- PBD constraints — Distance constraints with configurable compliance
- Material properties — Stiffness, damping, mass per unit length (
RopeMaterial.js) - Particle interaction — Ropes interact with the particle system (
RopeParticleInteraction.js) - GPU rendering — Smooth tube rendering with normals and lighting (
RopeGPURenderer.js)
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:
- Body types — Dynamic, kinematic, static
- Collider shapes — Sphere, box, capsule, mesh (via
Collidercomponent) - Forces — Gravity, impulses, torques
- Constraints — Distance, hinge, ball-socket
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:
- ECS physics system tick (rigid bodies, colliders)
- Cloth solver step (GPU compute)
- Rope constraint solving (PBD iterations)
- Particle simulation (main compute + advanced subsystems)
- 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.
Key Files
| File | Purpose |
|---|---|
sim/SimulationUpdate.js | Master simulation orchestrator (30K) |
sim/cloth/ | Mass-spring cloth solver |
sim/fluids/ | Eulerian fluid volumes |
sim/physics/ | Rigid body physics system |
sim/particles/RopePhysics.js | PBD rope solver |
sim/particles/RopeMaterial.js | Rope material properties |
sim/particles/ParticleSPH.js | SPH fluid solver |
sim/particles/ParticleEulerianFluid.js | Grid-based fluid |
sim/particles/ParticleConstraints.js | Distance/position constraints (59K) |