Controlling Soft Body Stiffness in Ammo.js
This article provides an overview of the key mathematical parameters and configuration settings used in ammo.js (the JavaScript port of the Bullet physics engine) to control the deformation, stiffness, and structural integrity of soft bodies. By understanding these parameters, developers can realistically simulate diverse materials ranging from highly elastic gelatin to rigid cloth.
Core Material Coefficients
In ammo.js, soft body physical properties are primarily governed by
the btSoftBody::Material structure. Three main stiffness
coefficients dictate how the simulation responds to different types of
stress:
- Linear Stiffness (
m_kLST): This parameter controls the resistance of the soft body’s structural links to stretching and compression. It operates on a scale from0.0(highly elastic, like rubber) to1.0(nearly rigid, resisting any change in length). - Angular Stiffness (
m_kAST): This coefficient governs the resistance of the body to bending forces. Adjusting this value determines how easily a soft body creases or folds. A value close to1.0maintains a flatter, more rigid surface, while a value near0.0allows for limp, cloth-like draping. - Volume Stiffness (
m_kVST): Used primarily for closed, 3D soft meshes, this parameter regulates how well the body maintains its overall volume under pressure. High volume stiffness prevents the mesh from collapsing flat when compressed.
Solver Iterations
The perceived stiffness of a soft body is heavily influenced by the
constraint solver configuration. Even with stiffness coefficients set to
1.0, a low number of solver iterations will make the body
behave like jelly due to numerical drift.
- Position Iterations (
piterations): Located in the soft body configuration (sb.get_m_cfg()), this parameter defines how many times the solver calculates position constraints per simulation step. Increasingpiterationsdrastically increases the stiffness and structural integrity of the body, preventing stretching under gravity, though at a higher CPU cost. - Velocity Iterations (
viterations): Controls the velocity constraint solver passes, helping to stabilize high-speed collisions and damp sudden motions. - Drift Iterations (
diterations): Manages the correction of numerical drift, ensuring that the soft body vertices do not permanently deform or drift away from their original relative positions over time.
Structural Link Types
The structural integrity of a soft body is also determined by how its vertices (nodes) are interconnected. When creating a soft body helper, developers can generate different types of links:
- Structural Links: Created between adjacent vertices. These form the basic wireframe of the body.
- Shear Links: Created diagonally across faces. These prevent the mesh from shearing or twisting out of shape.
- Bending Links: Generated by skipping vertices (linking node \(i\) to node \(i+2\)). These provide the structural leverage needed to resist folding and are crucial for simulating stiff sheets of plastic or metal.
Aerodynamics and Pressure Parameters
For specialized soft bodies, like balloons or sails, gas dynamics and external forces play a critical role in structural integrity:
- Pressure Coefficient (
m_kPR): Simulates internal gas pressure. When positive, it exerts an outward force on the triangles of a closed mesh, inflating the soft body and keeping it structurally rigid even under heavy external loads. - Damping Coefficient (
m_kDP): Controls the rate at which kinetic energy is dissipated. Higher damping prevents continuous oscillation (wobbling) after a soft body collides with an object, helping it quickly return to its resting state.