Spatial scenes and physics
Load src/spatial-core.js before src/spatial-physics.js. Use EpsilonSpatial to author a scene and EpsilonSpatialPhysics to run a controller against its geometry. Spatial positions are scene units. X and Z form the ground plane, Y is vertical, and rotations in authored transforms are degrees.
Author a playable scene#
EpsilonSpatial.clean(raw) returns a bounded scene with mode, camera, grid, objects and two cast-plane placements. clean() returns an empty flat scene. Available modes are flat, hybrid and spatial. The gameplay controller requires spatial mode.
| Field | Meaning |
|---|---|
objects[] |
Each object needs a unique id and a kind of box, sphere, cylinder or pyramid. transform takes x/y/z, rx/ry/rz and sx/sy/sz. Color is a six-digit hex value. |
keys[] |
Time-keyed transforms use t in seconds. A scene holds up to 48 objects, each with up to 32 distinct keys. evaluate(object, t) interpolates between keys. |
gameplay.colliders[] |
Bind object IDs to solid, collectible or exit. Use exactly one exit. The compiler uses the world-axis-aligned bounds of the transformed primitives. Collider meshes must be static. |
spawn and half |
Three-component vectors inside gameplay. Spawn is the player center and half gives the half-extents of its collision box. The player must fit inside X/Z from −12 to 12 and Y from 0 to 12, clear of solids. |
speed, gravity, jump, cameraMode |
Movement speed (0.5–24), downward acceleration (1–50) and jump speed (1–20). Camera mode can be fixed or follow. |
Here the player collects a beacon and reaches an exit by holding Right. Both events come from the simulation, independent of the renderer.
import './src/spatial-core.js';
import './src/spatial-physics.js';
const S = globalThis.EpsilonSpatial;
const P = globalThis.EpsilonSpatialPhysics;
const space = S.clean({
mode: 'spatial',
objects: [
{ id: 'beacon', kind: 'sphere', transform: { x: 1, y: 0.5 } },
{ id: 'dock', kind: 'box', transform: { x: 3, y: 0.5 } }
],
gameplay: {
colliders: [{ id: 'beacon', role: 'collectible' }, { id: 'dock', role: 'exit' }],
spawn: { x: 0, y: 0.5, z: 0 }, half: { x: 0.25, y: 0.5, z: 0.25 },
speed: 4, gravity: 18, jump: 7
}
});
const world = P.create(space, space.gameplay);
const events = [];
for (let frame = 0; frame < 60; frame++) {
events.push(...P.advance(world, 1 / 60, { right: true }));
}
console.log(events.map(e => e.type + '/' + e.id).join(' '), P.snapshot(world).won);
collect/beacon win/dock true
Runtime and rendering calls#
| Call | Result or effect |
|---|---|
S.object(raw), S.transform(raw), S.camera(raw) |
Normalize one mesh, transform or camera. S.starter(mode) supplies an authored sample stage. |
P.meshBounds(object), P.compile(space, config) |
Return bounds or the validated controller level with solids, triggers, spawn, half-extents and movement constants. A duplicate binding, keyed collider or blocked spawn throws. |
P.create(space, config), P.advance(world, dt, input?) |
Create a fresh run, then mutate it in fixed 1/120 s ticks. Use left/right/up/down/jump. Up moves toward negative Z. The elapsed-time cap is 0.25 s per call. |
P.snapshot(world) |
Returns a detached report with position, vy, grounded, ticks, sorted collected IDs and won. The live world maintains its accumulator and locomotion state. |
| Events | {type: "jump", tick}, {type: "collect", id, tick} and {type: "win", id, tick}. Collectibles trigger once. The exit succeeds after all collectibles are secured. |
P.cameraTarget(space, snapshot), P.playerPose(world, reduced?), P.playerMeshes(world, reduced?) |
Follow-camera target or null, controller-derived pose, and renderable primitive avatar parts. Locomotion tracks actual collision-resolved displacement. |
S.makeRenderer(canvas) |
Returns {surface, backend, render}. Call render(space, t, palette, actors?, follow?) on a fixed-size 2D canvas, up to 1280 × 720 pixels in area. The software renderer depth-tests triangles and composites cast planes. |
S.view(camera, aspect, orthographic?, follow?), S.project(point, view) |
Build camera axes and project a three-element point to normalized {x, y, depth}. A point outside the near/far range returns null. |
S.geometry(kind), S.transformed(mesh, transform), S.billboard(view, placement, aspect?) |
Produce triangle vertex streams for primitive geometry, a transformed mesh or a camera-facing plane. |
The original spatial game exporter embeds the primitive runtime in a standalone HTML player. Frontier Dispatch supplies its own model renderer and uses this same physics API. Exports · Architecture.