clone

an endless marble-race generator in the browser; the url is the seed, so every track can be shared

main
marbles / tools / physics-spike / README.md
README.md 2.3K rendered
1# M9 physics spike — Box3D → WASM (2026-08-08)23**Verdict: Box3D confirmed as the physics-era engine.**45Box3D (Erin Catto, released 2026-06-30, MIT, C17) — the 3D successor to Box2D.6Spiked at commit `3fc20f5b453ba9e14cdf54ecafa87a2a4bcdf53c`.78## Spike setup910- `git clone --depth 1 https://github.com/erincatto/box3d && cd box3d`11- `emcmake cmake -B build-wasm -DCMAKE_BUILD_TYPE=Release -DBOX3D_SAMPLES=OFF12 -DBOX3D_UNIT_TESTS=OFF -DBOX3D_BENCHMARKS=OFF && cmake --build build-wasm`13 — builds `libbox3d.a` for wasm32 with ZERO patches.14- `emcc spike.c libbox3d.a -I include -O2 -o spike.js && node spike.js`1516`spike.c` here: a slalom-like trough (floor + walls + end caps, tilted 5°) with17a marble-sized (r=0.2) sphere rolling down 60 units, 1200 steps at 60 Hz × 418substeps.1920## Gate results2122- **Determinism**: position-trace FNV hash bit-identical, both in-process (two23 worlds) and across separate runs. Box3D advertises cross-platform24 determinism + record/replay — matches what we measured.25- **Performance**: ~228k steps/s single-worker under Node (≈3,800× realtime at26 60 Hz; the gate was ≥4×). Effectively unlimited headroom.27- **Behavior**: marble slalom maxAbsX settled at exactly the geometric28 wall-contact plane (0.75 − 0.05 wall − 0.2 radius = 0.500) — contact precision29 is excellent. Escaped-marble freefall behaves as expected (first run tumbled30 into the void forever — endless-mode-compatible).31- **API**: portable C API in the Box2D v3 style (b3DefaultWorldDef /32 b3CreateBody / b3CreateHullShape / b3CreateSphereShape / b3CreateMeshShape /33 b3World_Step / b3Body_GetPosition). Double-precision positions by default34 (b3CreateWorld = b3CreateWorldDoublePrecision) — good for the endless line's35 unbounded coordinates.36- **Size**: spike .wasm 369 KB (-O2, whole library linked).3738## M10 integration plan3940- Vendor box3d pinned at the commit above (or a submodule) + a build task41 producing `static/dist/box3d.js/.wasm`.42- Hand-written C shim exporting exactly the calls the marble needs43 (world/step/static hulls+meshes per piece proxy, one dynamic sphere,44 transforms out) — keep the JS surface tiny.45- Collision proxies per PieceDef measured from the GLBs (floor ribbon + wall46 strips as hulls; helix/curved floors as trimesh), authored in the registry47 like centerlines.