Soft body & fluid simulation based on Position Based Dynamics (PBD).
- Position Based Dynamics (PBD) and Position Based Fluids (PBF) is used for simulating soft bodies and fluid.
- For two-way coupling of soft body and fluid simulation, a method described in Unified Particle Physics for Real-Time Applications is used.
- Buoyancy is naturally simulated thanks to this paper.
- The simulation is accelerated with multithreading using wasm-bindgen-rayon.
npm install
npm run build
npm run dev
If you have trouble running the repo, feel free to open an issue.
Soft bodies are simulated using distance constraint and area constraint.
Distance constraints limit adjacent particles of each soft body from moving too far apart or too close together. And area constraints limit the movement of particles so that soft bodies do not collapse.
For more detail, reading section 3.3 (Constraint Projection) and 4.4 (Cloth Balloons) in the original PBD paper would help.
The simulation of fluid is based on Position Based Fluids. That is,
My initial implementation is based on the one by Matthias Müller.
To simulate surface tension, cohesion and curvature term is used, which is described in Versatile Surface Tension and Adhesion for SPH Fluids by Akinci et al.
Following the framework described in Unified Particle Physics for Real-Time Applications, two-way coupling of fluid and soft bodies can be naturally simulated.
In PBF calculations, fluid particles and soft body particles are treated in almost the same way. Buoyancy is automatically achieved using the mass weighted version of PBD (Eq. (4) and (5) in the paper).
The softbodies can easily get entangled when they collide. To prevent this problem, repulsive forces are applied between overlapping soft bodies. They still sometimes get entangled even with this trick, but it's less frequent than it would be without it.
In addition, soft body particles within other soft bodies do not interact with those soft bodies. This also prevents soft bodies from becoming entangled with each other.
To prevent fluid particles from remaining inside soft bodies, fluid particles inside soft bodies do not interact with soft body particles. Fluid particles naturally go out of the soft bodies thanks to this trick.
- Position Based Dynamics by Müller et al.
- Position Based Fluids by Macklin et al.
- Unified Particle Physics for Real-Time Applications by Macklin et al.
- Small Steps in Physics Simulation by Macklin et al.