THREE.JS / FOUNDATIONS 209

Save the state.

A physics scene is more useful when it can be captured, restored, and replayed. This route keeps Rapier's serialized world beside the Three.js instance buffers, then checks whether identical inputs and fixed steps produce identical snapshot bytes.

Initializing Loading Rapier

Preparing a directly owned Rapier world and shared instance buffers...

physics
-
bodies
-
snapshot
-
checksum
-
step ms
-
replay
-
selected
-
fps
-
State controlsbox #1

The selected body is addressed by its creation-order slot and mirrored into one Three.js instance matrix.

Serialization contractofficial Rapier API
world.takeSnapshot()serialize the whole world
World.restoreSnapshot(bytes)create an identical world
Uint8Arraysave or transfer the state payload
world.profilerEnabled = trueenable internal step timings
world.timingStep()read the last physics step cost
instanceMatrix.needsUpdatepublish restored transforms to WebGL

The replay check compares serialized bytes after the same deterministic impulse and 60 fixed steps. The displayed checksum is a local FNV-1a diagnostic; it is not the MD5 procedure described in Rapier's documentation.

Selected bodypending
group-
index-
body slot-
position-
velocity-

Rapier is loading. Once ready, the selected body can be inspected before and after capture/restore.

Based on the official Rapier serialization guide, determinism guide, Rapier package guidance, World API, and InstancedMesh docs. Measurements are local browser evidence, not a universal determinism or performance claim.

THREE.JS FOUNDATIONS LAB