PhysicsProvider
PhysicsProvider is an internal system that conditionally wraps scene content in Rapier physics. It consists of two components:
PhysicsGate — wraps World children in Rapier's
<Physics>when aphysicsconfig is provided.PhysicsBodyWrapper — wraps an Actor in Rapier's
<RigidBody>when the Actor has aphysicsprop.
You do not need to use these directly — they are used internally by World and Actor.
How It Works #
PhysicsGate (used by World) #
When a
Worldhas aphysicsprop,PhysicsGatelazy-loads@react-three/rapiervia dynamicimport().If the import succeeds, children are wrapped in
<Physics>with the configured gravity, timestep, interpolation, and debug settings.If
@react-three/rapieris not installed, a console warning is logged and children render without physics.
PhysicsBodyWrapper (used by Actor) #
When an
Actorhas aphysicsprop and aPhysicsContextis available, the Actor's group is wrapped in<RigidBody>.In 2D mode, Z translation and X/Y rotation are auto-locked.
Collision callbacks (
onCollisionEnter,onCollisionExit) are mapped to Rapier's event system.A
RigidBodyRefContextis provided sousePhysicscan access the body.
Lazy Loading #
Rapier is loaded dynamically at runtime:
Not installed — warning logged, children render normally.
Loading — children render without physics until the module resolves.
Loaded —
<Physics>and<RigidBody>wrappers activate.
This means @react-three/rapier is a true optional dependency — your bundle doesn't include it unless you install and use it.
Install #
pnpm add @react-three/rapierContext API #
Two internal contexts are exposed for advanced use:
usePhysicsContext() #
Returns PhysicsContextValue | null. Contains:
| Field | Type | Description |
|---|---|---|
available | boolean | Whether Rapier is loaded and active |
is2D | boolean | Whether the World is in 2D mode |
config | WorldPhysicsConfig | The physics config from the World |
modules | RapierModules | References to Physics and RigidBody components |
useRigidBodyRef() #
Returns RefObject<RapierRigidBody> | null. Used internally by usePhysics to access the rigid body instance.
Type Definitions #
See Types for WorldPhysicsConfig, ActorPhysicsProps, RigidBodyType, and PhysicsColliderType.