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.
Preparing shared instance buffers and indexed Rapier bodies...
- physics
- -
- instances
- -
- bodies
- -
- selected
- -
- velocity
- -
- impulses
- -
- renderer
- -
- fps
- -
Select an instance to inspect its indexed body, matrix position, and velocity.
new THREE.InstancedMesh(..., count)allocate one shared drawmesh.setMatrixAt(index, matrix)seed each local transformmesh.instanceMatrix.needsUpdatepublish changed transformsphysics.addScene(scene)register indexed body arraysphysics.setMeshPosition(mesh, p, i)move body iphysics.setMeshVelocity(mesh, v, i)set body i velocityphysics.applyImpulse(mesh, j, i)kick body imesh.computeBoundingSphere()refresh moved-instance boundsRapierPhysics 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.
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.