Ammo.js Node-to-Node vs Face-to-Face Collisions
This article explains the differences between node-to-node and face-to-face soft body collision detection in the ammo.js physics engine. You will learn how both methods function under the hood, their impact on performance and simulation accuracy, and how to choose the right approach for your 3D web applications.
Soft Body Structure in Ammo.js
To understand how these collision types differ, it is important to understand how soft bodies are constructed in ammo.js (which is a JavaScript port of the Bullet Physics engine). A soft body mesh is composed of:
- Nodes (Vertices): The individual points in space that contain mass and positional data.
- Links (Edges): The structural connections between nodes that act like springs.
- Faces (Triangles): The three-sided polygons formed by connecting three nodes, defining the visible surface of the soft body.
Collision detection determines how these elements interact when they come into contact with other physics bodies.
Node-to-Node Collisions
Node-to-node collision detection (often grouped with node-to-rigid body collisions) calculates physical contact exclusively at the vertex level.
When a collision query is run, the engine only checks if the individual nodes of the soft body have penetrated another collision shape.
Pros of Node-to-Node:
- High Performance: It is computationally inexpensive because the engine only needs to calculate mathematical intersections for a finite set of points (vertices) rather than continuous surfaces.
- Simplicity: Highly effective for simple, high-density structures or rope-like objects (which are essentially a chain of nodes and links).
Cons of Node-to-Node:
- The “Tunneling” Effect: Because collision is only checked at the vertex points, thin rigid bodies (like a needle, a sword, or thin poles) can pass directly through the empty space between the nodes of a soft body without triggering a collision.
Face-to-Face Collisions
Face-to-face collision detection (often utilized alongside face-to-rigid body collisions) operates at the polygon surface level.
Instead of checking only the vertices, the engine calculates collisions across the entire triangular surface area defined by the soft body’s faces.
Pros of Face-to-Face:
- Superior Accuracy: It prevents other objects from passing through the gaps between vertices, providing highly realistic cloth and soft body deformations.
- Realistic Interactions: Essential for complex simulations like sails catching wind, flags wrapping around poles, or heavy objects landing on a stretched canvas.
Cons of Face-to-Face:
- High CPU Overhead: Calculating intersections across entire surface planes is mathematically complex. Using this mode on high-polygon meshes can severely drop the frame rate in browser-based environments.
Summary of Key Differences
| Feature | Node-to-Node Collisions | Face-to-Face Collisions |
|---|---|---|
| Collision Area | Only at the vertices (nodes) | Across the entire polygon surface (faces) |
| Performance Impact | Low CPU usage, highly optimized | High CPU usage, potential for lag |
| Accuracy | Lower; prone to clipping/tunneling | Higher; prevents clipping through surfaces |
| Best Use Cases | Ropes, simple soft blobs, high-performance mobile WebGL | Detailed cloth simulations, flags, sails, interactive curtains |