THREE.JS / FOUNDATIONS 210

Send the state back.

The worker owns Rapier, fixed-step simulation, snapshots, and replay. The page owns the renderer and instanced meshes, so rollback crosses the worker boundary as an explicit transferable payload.

Initializing Preparing worker

Creating the main-thread scene while the worker loads deterministic Rapier...

physics
-
bodies
-
snapshot
-
transfer
-
replay
-
step ms
-
messages
-
fps
-
Rollback controlsbox #1

The worker is loading Rapier. Once ready, the selected index will address one worker-owned rigid body.

Rollback contractstate crosses the worker
world.takeSnapshot()serialize inside the worker
postMessage(bytes, [buffer])transfer state to the page
snapshot.slice().buffersend a copy back for restore
World.restoreSnapshot(bytes)rebuild worker-owned state
world.timestep = 1 / 60replay fixed simulation steps
worker.terminate()close the lifecycle explicitly

The main thread never reads a Rapier body. It stores the transferred snapshot bytes, returns a copy for restore, and applies only transferable transform frames to Three.js.

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

The worker is loading deterministic Rapier. Its restored body order will be mapped back to these instance slots.

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

THREE.JS FOUNDATIONS LAB