0026. 3D: render-3d, physics-rapier, 3D levels and the 3D template
- Status: Accepted 2026-11-30 (Phase 5c; owner decisions 2026-11-29: a third-person collect-a-thon, block-and-model levels, deterministic Rapier, preview and AI tools only, no visual 3D editor yet)
- Date: 2026-11-29
- Phase: 5
Context
Section titled “Context”ADR 0005 (Three.js) and ADR 0006 (Rapier for rigid bodies) were confirmed at the start of Phase 5. Phase 5c adds the 3D genre. Two constraints shape it:
- 2D games must not pay for 3D: no Three.js or Rapier in their bundles.
- As elsewhere, gameplay should be data that creators, packs and the AI can write.
Decision
Section titled “Decision”-
@ludrel/render-3d. Three.js behind aRender3DBackendinterface; onlythree-backend.tsimports Three.js, and there is a stub backend for headless runs. Components:Transform3D(position, rotation in degrees, scale);Mesh(box, sphere, cylinder, ramp, capsule, plane, with a colour or texture);Model(a glTF asset, with an optional animation);Light(ambient, directional with shadows, point);Camera3D(a follow camera or a fixed one).
WebGL 2 by default; the WebGPU renderer can come later behind the same interface.
-
2D on top. 3D games keep the 2D renderer as a transparent overlay, so the HUD, menus, banners, the dialogue box and touch controls work unchanged.
-
@ludrel/physics-rapier. The deterministic Rapier build (rapier3d-deterministic-compat, WASM included, no network fetch). Components:RigidBody3D(dynamic, fixed, kinematic);Collider3D(box, sphere, capsule, cylinder, with sensors for triggers);CharacterController3D: Rapier’s kinematic character controller with slopes and steps, and jump, coyote time and buffering like the platformer’s.
Sensors emit
trigger:<event>like 2D triggers, so rules work unchanged. -
Opt-in loading.
display.mode: "3d"makesstartGameimportrender-3dandphysics-rapierdynamically, as separate chunks. 2D bundles stay as they are;pnpm sizechecks it. -
3D levels as data. A new
level3ddocument:pieces: primitive boxes, ramps, cylinders and spheres with sizes, colours, and whether they collide;objects: prefab spawns, triggers and points, as in 2D levels;- lights and sky.
A scene names it with
level3d. glTF models are assets used by prefabs and pieces. -
Editor and AI. No visual 3D editor yet: 3D games run in the sandboxed preview, and levels are edited as JSON or with new agent tools,
read_level3dandedit_level3d(add, update and remove pieces and objects). -
Template.
templates/island: an original third-person collect-a-thon. It has a small island of blocks, a runner with a follow camera, gems, moving platforms and a goal. Low-poly glTF models are generated in code. A bot collects the gems in a headless test (Rapier runs in Node).
Alternatives considered
Section titled “Alternatives considered”- One 3D canvas with HUD drawn in Three.js: the 2D UI kit would need to be rewritten.
- glTF-only levels: hard for the AI and the editor to change.
- The non-deterministic Rapier build: faster, but replays and tests could differ between machines.
Consequences
Section titled “Consequences”- 3D games load two renderers (about 150 kB more than 2D games, gzipped) plus the Rapier WASM (about 500 kB).
- The bot and headless tests drive 3D physics without rendering. Screenshots of 3D need a browser.
- 3D levels live in
game/levels3d/(game/levels/ holds 2D levels; tools and editor checks tell them apart by folder). - The play origin’s CSP allows
'wasm-unsafe-eval'(compiling WebAssembly for Rapier; JavaScript eval stays off). - Game size budgets are measured on what a 2D game loads (
scripts/check-bundles.ts, brotli, the lazythree-dchunk excluded), which also fails if 3D code reaches any other chunk.