File: RapierPhysics.md | Updated: 11/15/2025
Can be used to include Rapier as a Physics engine into three.js apps. The API can be initialized via:
The component automatically imports Rapier from a CDN so make sure to use the component with an active Internet connection.
const physics = await RapierPhysics();
RapierPhysics is an addon, and must be imported explicitly, see Installation#Addons.
import { RapierPhysics } from 'three/addons/physics/RapierPhysics.js';
Adds a heightfield terrain to the physics simulation.
mesh | The Three.js mesh representing the terrain.
---|---
width | The number of vertices along the width (x-axis) of the heightfield.
depth | The number of vertices along the depth (z-axis) of the heightfield.
heights | Array of height values for each vertex in the heightfield.
scale | Scale factors for the heightfield dimensions. | x | Scale factor for width.
---|---
y | Scale factor for height.
z | Scale factor for depth.
Returns: The created Rapier rigid body for the heightfield.
Adds the given mesh to this physics simulation.
mesh | The mesh to add.
---|---
mass | The mass in kg of the mesh. Default is 0.
restitution | The restitution/friction of the mesh. Default is 0.
Adds the given scene to this physics simulation. Only meshes with a physics object in their Object3D#userData field will be honored. The object can be used to store the mass and restitution of the mesh. E.g.:
box.userData.physics = { mass: 1, restitution: 0 };
scene | The scene or any type of 3D object to add.
---|---
Removes the given mesh from this physics simulation.
mesh | The mesh to remove.
---|---
Set the position of the given mesh which is part of the physics simulation. Calling this method will reset the current simulated velocity of the mesh.
mesh | The mesh to update the position for.
---|---
position | The new position.
index | If the mesh is instanced, the index represents the instanced ID. Default is 0.
Set the velocity of the given mesh which is part of the physics simulation.
mesh | The mesh to update the velocity for.
---|---
velocity | The new velocity.
index | If the mesh is instanced, the index represents the instanced ID. Default is 0.