THREE.JS / FOUNDATIONS 206

One mesh. Many bodies.

This route follows the official Rapier instancing example and makes its hidden contract inspectable: one InstancedMesh owns many transforms while Rapier addresses the corresponding rigid bodies by index.

Initializing Preparing renderer

Preparing shared instance buffers and indexed Rapier bodies...

physics
-
instances
-
bodies
-
selected
-
velocity
-
impulses
-
renderer
-
fps
-
Indexed body controlsbox #1

Select an instance to inspect its indexed body, matrix position, and velocity.

Instanced physics contractofficial API boundary
new THREE.InstancedMesh(..., count)allocate one shared draw
mesh.setMatrixAt(index, matrix)seed each local transform
mesh.instanceMatrix.needsUpdatepublish changed transforms
physics.addScene(scene)register indexed body arrays
physics.setMeshPosition(mesh, p, i)move body i
physics.setMeshVelocity(mesh, v, i)set body i velocity
physics.applyImpulse(mesh, j, i)kick body i
mesh.computeBoundingSphere()refresh moved-instance bounds

RapierPhysics stores a body and collider array under each instanced mesh's physics data. The wrapper steps those bodies and writes their transforms back into the shared instanceMatrix every frame.

Selected instancelive
group-
index-
position-
body state-

Rapier is loading. The selected instance will expose the indexed rigid body once the addon has initialized.

Based on the official Rapier instancing example, InstancedMesh docs, and RapierPhysics docs. The lab uses 128 instances instead of the official example's 800 so every indexed operation stays readable during study.

THREE.JS FOUNDATIONS LAB