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.
Creating the main-thread scene while the worker loads deterministic Rapier...
- physics
- -
- bodies
- -
- snapshot
- -
- transfer
- -
- replay
- -
- step ms
- -
- messages
- -
- fps
- -
The worker is loading Rapier. Once ready, the selected index will address one worker-owned rigid body.
world.takeSnapshot()serialize inside the workerpostMessage(bytes, [buffer])transfer state to the pagesnapshot.slice().buffersend a copy back for restoreWorld.restoreSnapshot(bytes)rebuild worker-owned stateworld.timestep = 1 / 60replay fixed simulation stepsworker.terminate()close the lifecycle explicitlyThe 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.
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.