@relu-interactives/spatial-ecs
v0.5.3
Published
Reusable ECS core engine for Relu Spatial editor and runtime experiences.
Readme
@relu-interactives/spatial-ecs
Shared ECS (Entity-Component-System) engine powering the Relu Spatial editor and preview runtimes.
What it is
@relu-interactives/spatial-ecs is the source of truth for entity/component/system behavior used across Relu Spatial experiences. It provides a deterministic, serializable scene graph that can be saved, hydrated, and executed identically in both the editor authoring environment and deployed AR/VR previews.
What it contains
| Area | Path | Description |
|---|---|---|
| Components | core/components/** | Runtime state containers (Transform, Model, Animation, Physics, Light, …) |
| Component factories | core/factories/components/** | APIs for creating and updating component instances |
| Object factories | core/factories/objects/** | Entity assembly — wires baseline components onto scene objects |
| Systems | core/systems/** | Frame-by-frame runtime behavior and scene synchronization |
| World | core/World.ts | ECS storage, lifecycle, system scheduling, snapshot and history management |
| Hydration | core/hydration/** | World reconstruction from saved snapshot data |
| Snapshot utils | core/worldSnapshotUtils.ts | Snapshot normalization, cloning, and debug helpers |
| Scripting | core/Behaviour.ts, core/ScriptTemplate.ts | Base classes for user-authored ECS scripts |
Installation
npm install @relu-interactives/spatial-ecs
# or
pnpm add @relu-interactives/spatial-ecsthree is a peer dependency and must be installed separately:
npm install threeLocal Development
pnpm install
pnpm run build
pnpm run typecheckKey Concepts
Entities and Components
Entities are integer IDs. Components are plain data containers attached to entities and stored in the World. Systems query for entities that have specific component combinations and apply runtime behavior each frame.
Snapshot and Hydration
The world can be serialized to a plain JSON snapshot and fully reconstructed via hydrateWorldFromSnapshotDetailed. Snapshots are designed to be forward-compatible — hydration is tolerant of missing or legacy fields.
Editor / Preview Parity
The same component contracts, factory logic, and hydration path are used by both the editor and the preview runtime. Changes to any of these must preserve behavior across both consumers.
