box3d-rust
A pure Rust port of Box3D, Erin Catto's 3D physics engine for games — exact behavioral match, including cross-platform deterministic math.
Demo Site
Follow the port live in your browser
The demo site mirrors the upstream samples app via WebAssembly — same light SPA shell as
our finished box2d-rust demos. Collision-layer
demos and rigid-body simulation samples (including the falling-ragdoll determinism scene) are
live in the browser.
Part of the rust-apps suite — a collection of Rust graphics and geometry libraries by Lars Brubaker.
Status: Determinism gate passed — bit-exact with the C reference
Box3D was released by Erin Catto in June 2026. The pinned reference source lives in the
box3d-cpp-reference/ submodule (v0.1.0+, 540ea38), and this port follows the same
playbook that took box2d-rust to completion:
whole modules in dependency order, each landing with its portion of the upstream C test
suite.
| Area | Ported | Tests |
|---|---|---|
| Foundation: math_functions (Vec3/Quat/Matrix3), core/constants | ✅ | ✅ (test_math.c) |
| Foundation: id, bitset, id_pool, table (container → Vec) | ✅ | ✅ (test_id/bitset/table.c) |
| Collision: aabb, distance (GJK/TOI) | ✅ | ✅ (test_collision AABB + test_distance.c) |
| Collision: hull, geometry, manifolds, mesh, height_field, compound, dynamic_tree | ✅ | ✅ (test_hull/shape/compound/height_field + authored) |
| Broad phase: proxy ops, move buffer (pair update deferred to world) | ✅ | ✅ (authored proxy tests) |
| Dynamics: body/shape lifecycle, contact lifecycle, constraint graph, solver sets | ✅ | ✅ (test_body + authored world tests) |
| Dynamics: islands — link, merge, split, sleep/wake | ✅ | ✅ (authored sleep/split tests) |
| Joints: distance, motor, parallel, prismatic, revolute, spherical, weld, wheel | ✅ | ✅ (test_joint.c) |
| Solver: serial contact solve, sub-step pipeline, sleeping, CCD/bullets, sensors, hit events | ✅ | ✅ (test_world.c) |
| Narrow phase: mesh/height-field contacts (mesh_contact.c) | ✅ | ✅ (TestMeshDrop + authored) |
| World API: queries, casts, explode, character mover | ✅ | ✅ (test_body_query.c, test_mover.c) |
| Shape/Body public API (filters, materials, geometry set, per-shape queries) | ✅ | ✅ (test_shape.c, test_body.c) |
| Determinism: bit-exact vs the C scalar build (both precision modes) | ✅ | ✅ (test_determinism.c) |
Large world mode (double-precision feature = BOX3D_DOUBLE_PRECISION) |
✅ | ✅ (test_large_world.c) |
| API completeness: introspection accessors, kinematic targets, wind | ✅ | ✅ (WorldTest/BodyTest remainders) |
| Debug draw (b3DebugDraw / b3World_Draw) | ✅ | ✅ (authored) |
| Snapshots and recording/replay | ✅ | ✅ (test_recording.c) |
Not ported (by design): the task scheduler/worker threads (the port is serial), SIMD
codepaths (the scalar BOX3D_DISABLE_SIMD path is the behavioral reference), and the C
arena/block allocators (Rust Vecs).
Quick start
[]
= "0.2"
# Optional: large-world positions (mirrors BOX3D_DOUBLE_PRECISION)
# box3d-rust = { version = "0.2", features = ["double-precision"] }
use create_body;
use Sphere;
use make_box_hull;
use ;
use ;
use World;
use ;
Porting principles
- Exact behavioral match — same algorithms, same
f32arithmetic, same edge cases as the C source. Floating-point operations are never reordered or "improved". - Determinism preserved — Box3D's hand-rolled
b3Atan2andb3ComputeCosSin(built for cross-platform determinism) are ported bit-for-bit, never replaced with std functions. - Tests ported too — every module lands together with its portion of the C test suite.
- No stubs — no
todo!(), no placeholders; modules are ported whole, in dependency order. - Large world mode — the
double-precisioncargo feature mirrorsBOX3D_DOUBLE_PRECISION.
The approach follows HOW_WE_PORTED_CLIPPER2.md and the completed box2d-rust port.
API style
The public API is a direct C-mirror (same shapes, defs, and call patterns as Box3D / box2d-rust), not a Rust-ergonomic wrapper. A thin ergonomic layer may be considered later if downstream users ask for one.
Development
# Clone with the C reference submodule
# Run tests (both precision modes)
# Full pre-commit gauntlet: file lengths, tests, fmt, clippy, build
Demo site
The demo site (demo/) runs the port in the browser via WebAssembly.
The quickest way to see it — builds the wasm and serves the demo at
http://localhost:3001, opening your browser:
run_demo.cmd # Windows (double-click or run from a terminal)
./run_demo.sh # Linux / macOS
Or drive the steps yourself:
Deployed automatically to GitHub Pages on push to main.
Acknowledgments
- Erin Catto — Box3D author
- MatterHackers — sponsoring the port
- Ported with Claude Code
