THREE.JS / FOUNDATIONS 212

Keep a little history.

Rollback needs more than one saved state. This worker maintains a bounded snapshot ring, accepts a deliberately late input, rewinds to the nearest checkpoint, and verifies the correction is reproducible.

Initializing Preparing worker

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

physics
-
bodies
-
ring
-
checkpoint
-
late tick
-
reconcile
-
events
-
step ms
-
fps
-
Snapshot-ring controlsbox #1

The worker is loading deterministic Rapier. Once ready, the selected index will address one fixed-tick body command.

Bounded rollback contracthistory with a hard limit
ring.push({ tick, bytes })retain recent world states
ring.shift()evict the oldest checkpoint
lateEvent.tick < currentTickaccept a past input
World.restoreSnapshot(bytes)rewind to the nearest state
replay(events, from, to)rebuild the corrected branch
postMessage(bytes, [buffer])publish checkpoint history

A late input invalidates later checkpoints. The worker evicts stale future entries, restores the nearest valid ring slot, replays the input log, then runs the corrected branch twice to verify identical serialized bytes.

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

The worker is loading deterministic Rapier. Restored body order will remain mapped 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 networking or rollback claim.

THREE.JS FOUNDATIONS LAB