@relu-interactives/spatial-ecs 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -0
- package/dist/System-rXAmagXA.d.cts +659 -0
- package/dist/System-rXAmagXA.d.ts +659 -0
- package/dist/Video-CDemv74U.d.cts +1261 -0
- package/dist/Video-ChKV1UI7.d.ts +1261 -0
- package/dist/assets/draco/draco_decoder.js +34 -0
- package/dist/assets/draco/draco_decoder.wasm +0 -0
- package/dist/assets/draco/draco_wasm_wrapper.js +117 -0
- package/dist/chunk-AYEF3X2P.js +223 -0
- package/dist/chunk-AYEF3X2P.js.map +1 -0
- package/dist/chunk-MAWBTMCG.js +1722 -0
- package/dist/chunk-MAWBTMCG.js.map +1 -0
- package/dist/chunk-NFDTIYR4.js +248 -0
- package/dist/chunk-NFDTIYR4.js.map +1 -0
- package/dist/chunk-OY7ZODZP.js +16 -0
- package/dist/chunk-OY7ZODZP.js.map +1 -0
- package/dist/chunk-P2YDX5DB.js +3304 -0
- package/dist/chunk-P2YDX5DB.js.map +1 -0
- package/dist/chunk-QHILSPT4.js +3 -0
- package/dist/chunk-QHILSPT4.js.map +1 -0
- package/dist/chunk-XWIEEJ7Z.js +1315 -0
- package/dist/chunk-XWIEEJ7Z.js.map +1 -0
- package/dist/components/index.cjs +1745 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +4 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -0
- package/dist/docs/api/Behaviour/classes/Behaviour.md +554 -0
- package/dist/docs/api/Behaviour/index.md +15 -0
- package/dist/docs/api/Component/classes/Component.md +57 -0
- package/dist/docs/api/Component/index.md +15 -0
- package/dist/docs/api/components/classes/AnimationComponent.md +318 -0
- package/dist/docs/api/components/classes/AudioComponent.md +114 -0
- package/dist/docs/api/components/classes/CameraComponent.md +59 -0
- package/dist/docs/api/components/classes/EntityType.md +48 -0
- package/dist/docs/api/components/classes/Environment.md +47 -0
- package/dist/docs/api/components/classes/ImageComponent.md +57 -0
- package/dist/docs/api/components/classes/ImageTarget.md +60 -0
- package/dist/docs/api/components/classes/ImageTargetAnchor.md +48 -0
- package/dist/docs/api/components/classes/LightComponent.md +70 -0
- package/dist/docs/api/components/classes/MaterialComponent.md +181 -0
- package/dist/docs/api/components/classes/MeshComponent.md +48 -0
- package/dist/docs/api/components/classes/MeshGeometryComponent.md +64 -0
- package/dist/docs/api/components/classes/ModelComponent.md +49 -0
- package/dist/docs/api/components/classes/Name.md +46 -0
- package/dist/docs/api/components/classes/Object3DRef.md +54 -0
- package/dist/docs/api/components/classes/ParentId.md +47 -0
- package/dist/docs/api/components/classes/PhysicsComponent.md +82 -0
- package/dist/docs/api/components/classes/Postprocessing.md +49 -0
- package/dist/docs/api/components/classes/ScriptComponent.md +54 -0
- package/dist/docs/api/components/classes/Selectable.md +46 -0
- package/dist/docs/api/components/classes/SelectionTransformState.md +54 -0
- package/dist/docs/api/components/classes/SpriteComponent.md +55 -0
- package/dist/docs/api/components/classes/TransformComponent.md +197 -0
- package/dist/docs/api/components/classes/VideoComponent.md +123 -0
- package/dist/docs/api/components/functions/normalizePhysicsState.md +23 -0
- package/dist/docs/api/components/index.md +94 -0
- package/dist/docs/api/components/type-aliases/AnimationComponentOptions.md +42 -0
- package/dist/docs/api/components/type-aliases/CameraComponentOptions.md +45 -0
- package/dist/docs/api/components/type-aliases/CameraProjection.md +15 -0
- package/dist/docs/api/components/type-aliases/CameraRuntimeType.md +15 -0
- package/dist/docs/api/components/type-aliases/ColliderShape.md +15 -0
- package/dist/docs/api/components/type-aliases/ColliderState.md +62 -0
- package/dist/docs/api/components/type-aliases/CubeMeshParameters.md +27 -0
- package/dist/docs/api/components/type-aliases/EditableMeshObjectKind.md +15 -0
- package/dist/docs/api/components/type-aliases/EnvironmentFogState.md +37 -0
- package/dist/docs/api/components/type-aliases/EnvironmentFogType.md +15 -0
- package/dist/docs/api/components/type-aliases/EnvironmentGradientEffect.md +15 -0
- package/dist/docs/api/components/type-aliases/EnvironmentSkyboxState.md +34 -0
- package/dist/docs/api/components/type-aliases/EnvironmentSkyboxType.md +15 -0
- package/dist/docs/api/components/type-aliases/EnvironmentState.md +29 -0
- package/dist/docs/api/components/type-aliases/ImageTargetAnchorOptions.md +25 -0
- package/dist/docs/api/components/type-aliases/ImageTargetReference.md +33 -0
- package/dist/docs/api/components/type-aliases/LightValueState.md +41 -0
- package/dist/docs/api/components/type-aliases/MaterialTypeValue.md +15 -0
- package/dist/docs/api/components/type-aliases/MaterialValueState.md +75 -0
- package/dist/docs/api/components/type-aliases/MeshGeometryParameters.md +13 -0
- package/dist/docs/api/components/type-aliases/MeshGeometryParametersByKind.md +33 -0
- package/dist/docs/api/components/type-aliases/PhysicsState.md +25 -0
- package/dist/docs/api/components/type-aliases/PlaneMeshParameters.md +25 -0
- package/dist/docs/api/components/type-aliases/PostprocessingState.md +164 -0
- package/dist/docs/api/components/type-aliases/RadiusHeightMeshParameters.md +25 -0
- package/dist/docs/api/components/type-aliases/RadiusMeshParameters.md +23 -0
- package/dist/docs/api/components/type-aliases/RigidbodyState.md +53 -0
- package/dist/docs/api/components/type-aliases/RigidbodyType.md +19 -0
- package/dist/docs/api/components/type-aliases/ScriptEntry.md +38 -0
- package/dist/docs/api/components/type-aliases/TextureFilteringValue.md +15 -0
- package/dist/docs/api/components/type-aliases/TransformData.md +27 -0
- package/dist/docs/api/components/type-aliases/TransformModeValue.md +15 -0
- package/dist/docs/api/components/type-aliases/TransformSpaceValue.md +15 -0
- package/dist/docs/api/components/type-aliases/Vec3.md +27 -0
- package/dist/docs/api/components/variables/DEFAULT_COLLIDER_STATE.md +13 -0
- package/dist/docs/api/components/variables/DEFAULT_ENVIRONMENT_STATE.md +13 -0
- package/dist/docs/api/components/variables/DEFAULT_MESH_GEOMETRY_PARAMETERS.md +13 -0
- package/dist/docs/api/components/variables/DEFAULT_PHYSICS_STATE.md +13 -0
- package/dist/docs/api/components/variables/DEFAULT_POSTPROCESSING_STATE.md +13 -0
- package/dist/docs/api/components/variables/DEFAULT_RIGIDBODY_STATE.md +13 -0
- package/dist/docs/api/index/classes/AnimationStateMachine.md +201 -0
- package/dist/docs/api/index/classes/AnimationStateManager.md +253 -0
- package/dist/docs/api/index/classes/AnimationSystem.md +68 -0
- package/dist/docs/api/index/classes/AudioSystem.md +98 -0
- package/dist/docs/api/index/classes/CameraSyncSystem.md +49 -0
- package/dist/docs/api/index/classes/EnvironmentSyncSystem.md +75 -0
- package/dist/docs/api/index/classes/InputSystem.md +449 -0
- package/dist/docs/api/index/classes/LightSyncSystem.md +49 -0
- package/dist/docs/api/index/classes/MaterialSyncSystem.md +67 -0
- package/dist/docs/api/index/classes/MeshGeometrySystem.md +49 -0
- package/dist/docs/api/index/classes/ObjectManagementSystem.md +298 -0
- package/dist/docs/api/index/classes/ObjectVisibilitySystem.md +49 -0
- package/dist/docs/api/index/classes/PhysicsSyncSystem.md +83 -0
- package/dist/docs/api/index/classes/PostprocessingSyncSystem.md +80 -0
- package/dist/docs/api/index/classes/RenderSystem.md +64 -0
- package/dist/docs/api/index/classes/ScriptBehaviourSystem.md +83 -0
- package/dist/docs/api/index/classes/TransformSyncSystem.md +49 -0
- package/dist/docs/api/index/classes/VideoSystem.md +97 -0
- package/dist/docs/api/index/classes/World.md +1405 -0
- package/dist/docs/api/index/functions/createAnimationComponent.md +28 -0
- package/dist/docs/api/index/functions/createAudioComponent.md +32 -0
- package/dist/docs/api/index/functions/createCameraComponent.md +28 -0
- package/dist/docs/api/index/functions/createEntityTypeComponent.md +28 -0
- package/dist/docs/api/index/functions/createEnvironmentComponent.md +28 -0
- package/dist/docs/api/index/functions/createImageComponent.md +28 -0
- package/dist/docs/api/index/functions/createImageTargetAnchorComponent.md +28 -0
- package/dist/docs/api/index/functions/createImageTargetComponent.md +28 -0
- package/dist/docs/api/index/functions/createLightComponent.md +28 -0
- package/dist/docs/api/index/functions/createMaterialComponent.md +28 -0
- package/dist/docs/api/index/functions/createMeshComponent.md +28 -0
- package/dist/docs/api/index/functions/createMeshGeometryComponent.md +28 -0
- package/dist/docs/api/index/functions/createModelComponent.md +28 -0
- package/dist/docs/api/index/functions/createNameComponent.md +28 -0
- package/dist/docs/api/index/functions/createObject3DRefComponent.md +28 -0
- package/dist/docs/api/index/functions/createParentIdComponent.md +28 -0
- package/dist/docs/api/index/functions/createPhysicsComponent.md +30 -0
- package/dist/docs/api/index/functions/createPostprocessingComponent.md +28 -0
- package/dist/docs/api/index/functions/createScriptComponent.md +28 -0
- package/dist/docs/api/index/functions/createSelectableComponent.md +28 -0
- package/dist/docs/api/index/functions/createSelectionTransformStateComponent.md +28 -0
- package/dist/docs/api/index/functions/createSpriteComponent.md +28 -0
- package/dist/docs/api/index/functions/createTransformComponent.md +28 -0
- package/dist/docs/api/index/functions/createVideoComponent.md +28 -0
- package/dist/docs/api/index/functions/hydrateWorldFromSnapshot.md +28 -0
- package/dist/docs/api/index/functions/hydrateWorldFromSnapshotDetailed.md +28 -0
- package/dist/docs/api/index/functions/registerDefaultComponentFactories.md +23 -0
- package/dist/docs/api/index/functions/registerDefaultFactories.md +23 -0
- package/dist/docs/api/index/index.md +249 -0
- package/dist/docs/api/index/interfaces/EcsSystem.md +50 -0
- package/dist/docs/api/index/interfaces/StateMachine.md +26 -0
- package/dist/docs/api/index/type-aliases/AnimationStateCallbacks.md +25 -0
- package/dist/docs/api/index/type-aliases/ComponentFactory.md +25 -0
- package/dist/docs/api/index/type-aliases/EcsComponentFactoryKind.md +37 -0
- package/dist/docs/api/index/type-aliases/EcsWorldComponentSnapshot.md +26 -0
- package/dist/docs/api/index/type-aliases/EcsWorldStateSnapshotLike.md +25 -0
- package/dist/docs/api/index/type-aliases/HydrateWorldFromSnapshotResult.md +23 -0
- package/dist/docs/api/index/type-aliases/KeyboardKey.md +13 -0
- package/dist/docs/api/index/type-aliases/MouseButton.md +13 -0
- package/dist/docs/api/index/type-aliases/SelectionContext.md +31 -0
- package/dist/docs/api/index/variables/HYDRATABLE_ENTITY_KINDS.md +13 -0
- package/dist/docs/api/index/variables/KeyboardKeys.md +195 -0
- package/dist/docs/api/index.md +15 -0
- package/dist/docs/api/typedoc-sidebar.json +1 -0
- package/dist/docs/api/types/index.md +34 -0
- package/dist/docs/api/types/type-aliases/AssetInput.md +23 -0
- package/dist/docs/api/types/type-aliases/CheckboxInput.md +13 -0
- package/dist/docs/api/types/type-aliases/ColorInput.md +13 -0
- package/dist/docs/api/types/type-aliases/ComponentInput.md +52 -0
- package/dist/docs/api/types/type-aliases/ComponentKind.md +37 -0
- package/dist/docs/api/types/type-aliases/DropdownInput.md +23 -0
- package/dist/docs/api/types/type-aliases/DropdownOption.md +23 -0
- package/dist/docs/api/types/type-aliases/EcsEntityEditorKind.md +15 -0
- package/dist/docs/api/types/type-aliases/EcsEntityKind.md +35 -0
- package/dist/docs/api/types/type-aliases/EntityId.md +16 -0
- package/dist/docs/api/types/type-aliases/EntityInput.md +23 -0
- package/dist/docs/api/types/type-aliases/FloatInput.md +13 -0
- package/dist/docs/api/types/type-aliases/IntersectionResult.md +29 -0
- package/dist/docs/api/types/type-aliases/ParentLookup.md +26 -0
- package/dist/docs/api/types/type-aliases/SelectionListener.md +25 -0
- package/dist/docs/api/types/type-aliases/SliderInput.md +27 -0
- package/dist/docs/api/types/type-aliases/TextInput.md +13 -0
- package/dist/docs/api/types/type-aliases/ToggleInput.md +13 -0
- package/dist/docs/api/types/type-aliases/Vec3.md +23 -0
- package/dist/docs/api/types/type-aliases/Vector2Input.md +23 -0
- package/dist/docs/api/types/type-aliases/Vector3Input.md +25 -0
- package/dist/docs/api/types/type-aliases/WorldEntityView.md +17 -0
- package/dist/docs/guide/accessing-components.md +399 -0
- package/dist/docs/guide/authoring-a-behaviour.md +166 -0
- package/dist/docs/guide/behaviour-lifecycle.md +43 -0
- package/dist/docs/guide/component-catalog.md +59 -0
- package/dist/docs/guide/components/_sidebar.json +78 -0
- package/dist/docs/guide/components/animation.md +171 -0
- package/dist/docs/guide/components/audio.md +181 -0
- package/dist/docs/guide/components/camera.md +179 -0
- package/dist/docs/guide/components/entity-type.md +141 -0
- package/dist/docs/guide/components/image-target-anchor.md +103 -0
- package/dist/docs/guide/components/image-target.md +122 -0
- package/dist/docs/guide/components/image.md +146 -0
- package/dist/docs/guide/components/light.md +157 -0
- package/dist/docs/guide/components/material.md +161 -0
- package/dist/docs/guide/components/mesh-geometry.md +153 -0
- package/dist/docs/guide/components/mesh.md +151 -0
- package/dist/docs/guide/components/model.md +96 -0
- package/dist/docs/guide/components/name.md +121 -0
- package/dist/docs/guide/components/object3d-ref.md +115 -0
- package/dist/docs/guide/components/parent-id.md +108 -0
- package/dist/docs/guide/components/physics.md +163 -0
- package/dist/docs/guide/components/script.md +142 -0
- package/dist/docs/guide/components/sprite.md +155 -0
- package/dist/docs/guide/components/transform.md +155 -0
- package/dist/docs/guide/components/video.md +153 -0
- package/dist/docs/guide/concepts.md +34 -0
- package/dist/docs/guide/getting-started/creating-objects.md +50 -0
- package/dist/docs/guide/getting-started/editing-objects.md +62 -0
- package/dist/docs/guide/getting-started/editor/assets-browser.md +55 -0
- package/dist/docs/guide/getting-started/editor/hierarchy.md +47 -0
- package/dist/docs/guide/getting-started/editor/index.md +16 -0
- package/dist/docs/guide/getting-started/editor/inspector.md +36 -0
- package/dist/docs/guide/getting-started/editor/modules.md +35 -0
- package/dist/docs/guide/getting-started/editor/scene-inspector.md +64 -0
- package/dist/docs/guide/getting-started/editor/toolbar.md +39 -0
- package/dist/docs/guide/getting-started/editor/viewport.md +43 -0
- package/dist/docs/guide/getting-started/first-launch.md +17 -0
- package/dist/docs/guide/getting-started/index.md +37 -0
- package/dist/docs/guide/getting-started/installation.md +59 -0
- package/dist/docs/guide/getting-started/preview-and-test.md +55 -0
- package/dist/docs/guide/getting-started/project-types/3d.md +30 -0
- package/dist/docs/guide/getting-started/project-types/ar.md +6 -0
- package/dist/docs/guide/getting-started/project-types/face-tracking.md +6 -0
- package/dist/docs/guide/getting-started/project-types/image-tracking.md +42 -0
- package/dist/docs/guide/getting-started/project-types/index.md +25 -0
- package/dist/docs/guide/getting-started/project-types/vr.md +6 -0
- package/dist/docs/guide/getting-started/projects.md +53 -0
- package/dist/docs/guide/getting-started/shortcuts.md +43 -0
- package/dist/docs/guide/inspector-data-binding.md +367 -0
- package/dist/docs/guide/reading-input.md +202 -0
- package/dist/docs/guide/scene/environment.md +101 -0
- package/dist/docs/guide/scene/index.md +36 -0
- package/dist/docs/guide/scene/postprocessing.md +108 -0
- package/dist/docs/guide/spawning/ambient-light.md +28 -0
- package/dist/docs/guide/spawning/area-light.md +32 -0
- package/dist/docs/guide/spawning/audio.md +42 -0
- package/dist/docs/guide/spawning/camera.md +50 -0
- package/dist/docs/guide/spawning/capsule.md +29 -0
- package/dist/docs/guide/spawning/cube.md +31 -0
- package/dist/docs/guide/spawning/cylinder.md +29 -0
- package/dist/docs/guide/spawning/directional-light.md +32 -0
- package/dist/docs/guide/spawning/empty.md +31 -0
- package/dist/docs/guide/spawning/image-target.md +48 -0
- package/dist/docs/guide/spawning/image.md +33 -0
- package/dist/docs/guide/spawning/index.md +79 -0
- package/dist/docs/guide/spawning/model.md +31 -0
- package/dist/docs/guide/spawning/plane.md +31 -0
- package/dist/docs/guide/spawning/point-light.md +32 -0
- package/dist/docs/guide/spawning/sphere.md +29 -0
- package/dist/docs/guide/spawning/spot-light.md +32 -0
- package/dist/docs/guide/spawning/sprite.md +31 -0
- package/dist/docs/guide/spawning/video.md +53 -0
- package/dist/docs/guide/system-overview.md +73 -0
- package/dist/docs/guide/systems/_sidebar.json +66 -0
- package/dist/docs/guide/systems/animation-system.md +32 -0
- package/dist/docs/guide/systems/audio-system.md +28 -0
- package/dist/docs/guide/systems/camera-sync-system.md +31 -0
- package/dist/docs/guide/systems/environment-sync-system.md +31 -0
- package/dist/docs/guide/systems/input-system.md +217 -0
- package/dist/docs/guide/systems/light-sync-system.md +29 -0
- package/dist/docs/guide/systems/material-sync-system.md +32 -0
- package/dist/docs/guide/systems/mesh-geometry-system.md +40 -0
- package/dist/docs/guide/systems/object-management-system.md +38 -0
- package/dist/docs/guide/systems/object-visibility-system.md +26 -0
- package/dist/docs/guide/systems/physics-sync-system.md +56 -0
- package/dist/docs/guide/systems/postprocessing-sync-system.md +43 -0
- package/dist/docs/guide/systems/render-system.md +22 -0
- package/dist/docs/guide/systems/script-behaviour-system.md +59 -0
- package/dist/docs/guide/systems/transform-sync-system.md +29 -0
- package/dist/docs/guide/systems/video-system.md +30 -0
- package/dist/docs/guide/world-api.md +405 -0
- package/dist/factories/index.cjs +3077 -0
- package/dist/factories/index.cjs.map +1 -0
- package/dist/factories/index.d.cts +69 -0
- package/dist/factories/index.d.ts +69 -0
- package/dist/factories/index.js +6 -0
- package/dist/factories/index.js.map +1 -0
- package/dist/index-B4-YyUNR.d.cts +73 -0
- package/dist/index-BZUOKeTO.d.ts +73 -0
- package/dist/index.cjs +8584 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +283 -0
- package/dist/index.d.ts +283 -0
- package/dist/index.js +1729 -0
- package/dist/index.js.map +1 -0
- package/dist/systems/index.cjs +5119 -0
- package/dist/systems/index.cjs.map +1 -0
- package/dist/systems/index.d.cts +200 -0
- package/dist/systems/index.d.ts +200 -0
- package/dist/systems/index.js +6 -0
- package/dist/systems/index.js.map +1 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +3 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/worldSnapshotUtils.cjs +259 -0
- package/dist/worldSnapshotUtils.cjs.map +1 -0
- package/dist/worldSnapshotUtils.d.cts +3 -0
- package/dist/worldSnapshotUtils.d.ts +3 -0
- package/dist/worldSnapshotUtils.js +4 -0
- package/dist/worldSnapshotUtils.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# The `World`
|
|
2
|
+
|
|
3
|
+
Every `Behaviour` script has a `this.world` reference to the owning [`World`](../api/index/classes/World.md). It is the runtime gateway for finding entities, querying components, reading input, and driving the scene from your scripts.
|
|
4
|
+
|
|
5
|
+
> [!TIP]
|
|
6
|
+
> Full TypeScript signatures live in the auto-generated reference: [`World` API](../api/index/classes/World.md).
|
|
7
|
+
|
|
8
|
+
This page summarises the methods most useful from a `Behaviour` and shows how to combine them.
|
|
9
|
+
|
|
10
|
+
## Inside a Behaviour
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { Behaviour, TransformComponent } from "@relu-interactives/spatial-ecs";
|
|
14
|
+
|
|
15
|
+
export default class Spinner extends Behaviour {
|
|
16
|
+
onUpdate() {
|
|
17
|
+
// `this.world` is refreshed every frame
|
|
18
|
+
const transform = this.world.getComponent(this.entity.entityId, TransformComponent);
|
|
19
|
+
if (transform) {
|
|
20
|
+
transform.rotation.y += this.deltaTime;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Method reference
|
|
27
|
+
|
|
28
|
+
### Entity lifecycle
|
|
29
|
+
|
|
30
|
+
| Method | Purpose |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `createEntity()` | Allocate a new entity id. |
|
|
33
|
+
| `destroyEntity(entityId)` | Remove an entity and all of its components. |
|
|
34
|
+
| `hasEntity(entityId)` | `true` if the entity still exists. |
|
|
35
|
+
| `getEntities()` | Array of every active entity id. |
|
|
36
|
+
| `getEntityCount()` | Number of active entities. |
|
|
37
|
+
|
|
38
|
+
### Components
|
|
39
|
+
|
|
40
|
+
| Method | Purpose |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `addComponent(entityId, component)` | Attach a single component. |
|
|
43
|
+
| `addComponents(entityId, [components])` | Attach a batch of components. |
|
|
44
|
+
| `removeComponent(entityId, ComponentClass)` | Detach a component by class. |
|
|
45
|
+
| `getComponent(entityId, ComponentClass)` | Read a component or `null`. |
|
|
46
|
+
| `hasComponent(entityId, ComponentClass)` | `true` if the entity has the component. |
|
|
47
|
+
| `query(...ComponentClasses)` | Array of entity ids that have **all** of the given components. |
|
|
48
|
+
|
|
49
|
+
### Entity lookups
|
|
50
|
+
|
|
51
|
+
| Method | Purpose |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `getAllEntities()` | All entities as `WorldEntityView` objects (`{ entityId, name, type, object, components }`). |
|
|
54
|
+
| `getEntityById(entityId)` | One `WorldEntityView` or `null`. |
|
|
55
|
+
| `getEntityByName(name)` | First entity whose `Name` matches, or `null`. |
|
|
56
|
+
| `getEntitiesByName(name)` | All entities sharing a `Name`. |
|
|
57
|
+
| `getEntitiesByComponent(component)` | All entities that own a component of the same class. |
|
|
58
|
+
|
|
59
|
+
### Scripts
|
|
60
|
+
|
|
61
|
+
| Method | Purpose |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `getEntityScript<T>(entityId)` | The live `Behaviour` instance attached to an entity. |
|
|
64
|
+
| `getScript<T>(className)` | First behaviour instance of the given class anywhere in the world. |
|
|
65
|
+
| `getScripts<T>(className)` | All behaviour instances of the given class. |
|
|
66
|
+
|
|
67
|
+
### Input
|
|
68
|
+
|
|
69
|
+
| Method | Purpose |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `getKey(key)` | `true` while a key is held this frame. |
|
|
72
|
+
| `getKeyDown(key)` / `getKeyUp(key)` | Edge-triggered: `true` only on the frame the key transitions. |
|
|
73
|
+
| `getMouse(button)` / `getMouseDown(button)` / `getMouseUp(button)` | Mouse buttons (`'left'`, `'right'`, etc.). |
|
|
74
|
+
| `getScrollClick()` / `getScrollClickDown()` / `getScrollClickUp()` | Middle-mouse / scroll-wheel click. |
|
|
75
|
+
| `getMousePosition()` | Latest pointer position (canvas-relative). |
|
|
76
|
+
| `getMouseDelta()` / `consumeMouseDelta()` | Movement since last frame; `consume` zeroes it after read. |
|
|
77
|
+
| `getScrollDelta()` / `consumeScrollDelta()` | Wheel deltas; `consume` zeroes them. |
|
|
78
|
+
| `lockMousePointer()` / `unlockMousePointer()` / `isMousePointerLocked()` | Pointer-lock for first-person controls. |
|
|
79
|
+
|
|
80
|
+
### Scene & physics access
|
|
81
|
+
|
|
82
|
+
| Method | Purpose |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| `getScene()` | The live `THREE.Scene`. |
|
|
85
|
+
| `getCamera()` | The active rendering camera. |
|
|
86
|
+
| `getRenderer()` | The `THREE.WebGLRenderer`. |
|
|
87
|
+
| `getPhysicsWorld()` | The Rapier `World` (or `null` if physics is disabled). |
|
|
88
|
+
|
|
89
|
+
### Raycasting
|
|
90
|
+
|
|
91
|
+
| Method | Purpose |
|
|
92
|
+
| --- | --- |
|
|
93
|
+
| `raycast(origin, direction, near?, far?)` | Cast a ray through the scene; returns `IntersectionResult[]` sorted by distance. |
|
|
94
|
+
| `raycastFrom(eid, near?, far?)` | Cast a ray from an entity's world position along its forward direction; the source entity is filtered out of results. |
|
|
95
|
+
|
|
96
|
+
Both methods accept `Vec3` (`THREE.Vector3` or `{ x, y, z }`) and return `IntersectionResult[]` — each entry pairs the owning ECS `entityId` with the underlying `threeResult: THREE.Intersection` so you can read `point`, `distance`, `face`, `uv`, etc. directly from three.js.
|
|
97
|
+
|
|
98
|
+
### Systems
|
|
99
|
+
|
|
100
|
+
| Method | Purpose |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `getSystem(SystemClass)` | Resolve a registered system instance. |
|
|
103
|
+
| `hasSystem(SystemClass)` | `true` if the system is registered. |
|
|
104
|
+
|
|
105
|
+
### World lifecycle
|
|
106
|
+
|
|
107
|
+
| Method | Purpose |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `pause()` | Pause simulation. All system ticks stop — physics, animation, scripts, and rendering freeze on the last frame. |
|
|
110
|
+
| `resume()` | Resume simulation after a `pause()` call. Has no effect if the world is not paused. |
|
|
111
|
+
| `isPaused()` | Returns `true` while the world is paused. |
|
|
112
|
+
|
|
113
|
+
## Examples
|
|
114
|
+
|
|
115
|
+
### Find an entity by name and move it
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { Behaviour, TransformComponent } from "@relu-interactives/spatial-ecs";
|
|
119
|
+
|
|
120
|
+
export default class TargetMover extends Behaviour {
|
|
121
|
+
onUpdate() {
|
|
122
|
+
const target = this.world.getEntityByName("Goal");
|
|
123
|
+
if (!target) return;
|
|
124
|
+
|
|
125
|
+
const transform = this.world.getComponent(target.entityId, TransformComponent);
|
|
126
|
+
if (!transform) return;
|
|
127
|
+
|
|
128
|
+
transform.position.x += this.deltaTime * 0.5;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Iterate every entity that owns a component
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { Behaviour, LightComponent } from "@relu-interactives/spatial-ecs";
|
|
137
|
+
|
|
138
|
+
export default class FlickerAllLights extends Behaviour {
|
|
139
|
+
onUpdate() {
|
|
140
|
+
const ids = this.world.query(LightComponent);
|
|
141
|
+
for (const id of ids) {
|
|
142
|
+
const light = this.world.getComponent(id, LightComponent);
|
|
143
|
+
if (!light) continue;
|
|
144
|
+
light.values.intensity = 1 + Math.sin(performance.now() / 200) * 0.2;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Talk to another script on a different entity
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { Behaviour } from "@relu-interactives/spatial-ecs";
|
|
154
|
+
import type Health from "./Health";
|
|
155
|
+
|
|
156
|
+
export default class DamageDealer extends Behaviour {
|
|
157
|
+
fire() {
|
|
158
|
+
const target = this.world.getEntityByName("Player");
|
|
159
|
+
if (!target) return;
|
|
160
|
+
|
|
161
|
+
const health = this.world.getEntityScript<Health>(target.entityId);
|
|
162
|
+
health?.takeDamage(10);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Spawn a new entity at runtime
|
|
168
|
+
|
|
169
|
+
There are two ways to spawn entities from a script:
|
|
170
|
+
|
|
171
|
+
1. **Manually** — allocate an id, build your own `THREE.Object3D`, and attach components yourself. Use this when you need full control over the mesh/material.
|
|
172
|
+
2. **Through the `ObjectManagementSystem`** — ask the registered factory for a built-in kind (`"cube"`, `"sphere"`, `"model"`, `"pointLight"`, …) to create the entity with all of its baseline components for you. Use this when you want a primitive that behaves exactly like one created from the editor.
|
|
173
|
+
|
|
174
|
+
#### Option 1 (Manual: build the `Object3D` yourself)
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import {
|
|
178
|
+
Behaviour,
|
|
179
|
+
createEntityTypeComponent,
|
|
180
|
+
createNameComponent,
|
|
181
|
+
createObject3DRefComponent,
|
|
182
|
+
createTransformComponent,
|
|
183
|
+
} from "@relu-interactives/spatial-ecs";
|
|
184
|
+
import * as THREE from "three";
|
|
185
|
+
|
|
186
|
+
export default class Spawner extends Behaviour {
|
|
187
|
+
init() {
|
|
188
|
+
const id = this.world.createEntity();
|
|
189
|
+
const mesh = new THREE.Mesh(
|
|
190
|
+
new THREE.BoxGeometry(1, 1, 1),
|
|
191
|
+
new THREE.MeshStandardMaterial({ color: "tomato" }),
|
|
192
|
+
);
|
|
193
|
+
this.world.getScene().add(mesh);
|
|
194
|
+
|
|
195
|
+
this.world.addComponents(id, [
|
|
196
|
+
createNameComponent({ value: "RuntimeCube" }),
|
|
197
|
+
createEntityTypeComponent({ value: "cube" }),
|
|
198
|
+
createTransformComponent({ position: { x: 0, y: 1, z: 0 } }),
|
|
199
|
+
createObject3DRefComponent({ object: mesh }),
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### Option 2 (Use `ObjectManagementSystem`)
|
|
206
|
+
|
|
207
|
+
`ObjectManagementSystem` is the same system the editor uses to create objects, so the new entity comes pre-wired with the correct components for its kind.
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
import {
|
|
211
|
+
Behaviour,
|
|
212
|
+
ObjectManagementSystem,
|
|
213
|
+
} from "@relu-interactives/spatial-ecs";
|
|
214
|
+
|
|
215
|
+
export default class CubeSpawner extends Behaviour {
|
|
216
|
+
init() {
|
|
217
|
+
const objects = this.world.getSystem(ObjectManagementSystem);
|
|
218
|
+
if (!objects) return;
|
|
219
|
+
|
|
220
|
+
// Supported kinds:
|
|
221
|
+
// "cube", "sphere", "plane", "capsule", "cylinder", "empty",
|
|
222
|
+
// "model", "image", "imageTarget", "sprite", "audio", "camera", "video",
|
|
223
|
+
// "ambientLight", "directionalLight", "pointLight", "spotLight", "areaLight"
|
|
224
|
+
objects.requestCreate(
|
|
225
|
+
"cube",
|
|
226
|
+
{
|
|
227
|
+
name: "RuntimeCube",
|
|
228
|
+
transform: {
|
|
229
|
+
position: { x: 0, y: 1, z: 0 },
|
|
230
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
231
|
+
scale: { x: 1, y: 1, z: 1 },
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
(entityId) => {
|
|
235
|
+
// Optional: runs once the entity has been created.
|
|
236
|
+
console.log("spawned cube", entityId);
|
|
237
|
+
},
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
For the payload accepted by each kind (audio paths, camera projection, light colors, video chroma-key, image targets, etc.), see the [Spawning](./spawning/) reference.
|
|
244
|
+
|
|
245
|
+
### Cast a ray and read the hit entity
|
|
246
|
+
|
|
247
|
+
`world.raycast` accepts any origin/direction in world space and returns every
|
|
248
|
+
intersected mesh sorted by distance. Each hit carries the owning `entityId`
|
|
249
|
+
so you can drive game logic from the result.
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
import { Behaviour, NameComponent } from "@relu-interactives/spatial-ecs";
|
|
253
|
+
import * as THREE from "three";
|
|
254
|
+
|
|
255
|
+
export default class ClickToInspect extends Behaviour {
|
|
256
|
+
private direction = new THREE.Vector3();
|
|
257
|
+
|
|
258
|
+
onUpdate() {
|
|
259
|
+
if (!this.world.getMouseDown("left")) return;
|
|
260
|
+
|
|
261
|
+
const camera = this.world.getCamera();
|
|
262
|
+
camera.getWorldDirection(this.direction);
|
|
263
|
+
|
|
264
|
+
const hits = this.world.raycast(camera.position, this.direction);
|
|
265
|
+
const first = hits.find((hit) => hit.entityId !== null);
|
|
266
|
+
if (!first || first.entityId === null) return;
|
|
267
|
+
|
|
268
|
+
const name = this.world.getComponent(first.entityId, NameComponent);
|
|
269
|
+
console.log(
|
|
270
|
+
"clicked",
|
|
271
|
+
name?.value ?? first.entityId,
|
|
272
|
+
"@",
|
|
273
|
+
first.threeResult.distance.toFixed(2),
|
|
274
|
+
"m",
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Cast a ray from an entity's forward direction
|
|
281
|
+
|
|
282
|
+
`world.raycastFrom(eid)` uses the entity's world position and `+Z` direction.
|
|
283
|
+
The source entity is automatically excluded from the results so you don't
|
|
284
|
+
hit yourself.
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
import { Behaviour } from "@relu-interactives/spatial-ecs";
|
|
288
|
+
|
|
289
|
+
export default class LookDetector extends Behaviour {
|
|
290
|
+
onUpdate() {
|
|
291
|
+
const hits = this.world.raycastFrom(this.entityId, 0, 25);
|
|
292
|
+
const target = hits[0];
|
|
293
|
+
|
|
294
|
+
if (target && target.entityId !== null) {
|
|
295
|
+
const view = this.world.getEntityById(target.entityId);
|
|
296
|
+
console.log(
|
|
297
|
+
"looking at",
|
|
298
|
+
view?.name,
|
|
299
|
+
"@",
|
|
300
|
+
target.threeResult.distance.toFixed(2),
|
|
301
|
+
"m",
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Read keyboard and mouse input
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
import { Behaviour, TransformComponent, KeyboardKeys } from "@relu-interactives/spatial-ecs";
|
|
312
|
+
|
|
313
|
+
export default class WASDMove extends Behaviour {
|
|
314
|
+
speed = 3;
|
|
315
|
+
|
|
316
|
+
onUpdate() {
|
|
317
|
+
const transform = this.world.getComponent(this.entity.entityId, TransformComponent);
|
|
318
|
+
if (!transform) return;
|
|
319
|
+
|
|
320
|
+
const dt = this.deltaTime;
|
|
321
|
+
if (this.world.getKey(KeyboardKeys.W)) transform.position.z -= this.speed * dt;
|
|
322
|
+
if (this.world.getKey(KeyboardKeys.S)) transform.position.z += this.speed * dt;
|
|
323
|
+
if (this.world.getKey(KeyboardKeys.A)) transform.position.x -= this.speed * dt;
|
|
324
|
+
if (this.world.getKey(KeyboardKeys.D)) transform.position.x += this.speed * dt;
|
|
325
|
+
|
|
326
|
+
if (this.world.getMouseDown("left")) {
|
|
327
|
+
console.log("click at", this.world.getMousePosition());
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Pointer lock for a first-person camera
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
import { Behaviour } from "@relu-interactives/spatial-ecs";
|
|
337
|
+
|
|
338
|
+
export default class FpsLook extends Behaviour {
|
|
339
|
+
init() {
|
|
340
|
+
this.world.lockMousePointer();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
onUpdate() {
|
|
344
|
+
if (!this.world.isMousePointerLocked()) return;
|
|
345
|
+
|
|
346
|
+
const { x, y } = this.world.consumeMouseDelta();
|
|
347
|
+
this.entity.object?.rotateY(-x * 0.002);
|
|
348
|
+
this.world.getCamera().rotateX(-y * 0.002);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
dispose() {
|
|
352
|
+
this.world.unlockMousePointer();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Reach into the physics world
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
import { Behaviour, PhysicsComponent } from "@relu-interactives/spatial-ecs";
|
|
361
|
+
|
|
362
|
+
export default class Jump extends Behaviour {
|
|
363
|
+
onUpdate() {
|
|
364
|
+
if (!this.world.getKeyDown("space")) return;
|
|
365
|
+
|
|
366
|
+
const physics = this.world.getComponent(this.entity.entityId, PhysicsComponent);
|
|
367
|
+
physics?.rigidBody?.applyImpulse({ x: 0, y: 5, z: 0 }, true);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Pause and resume the world
|
|
373
|
+
|
|
374
|
+
Use `pause()` / `resume()` to freeze and unfreeze simulation. All system
|
|
375
|
+
ticks stop when paused — physics, animation, scripts, and the render pass.
|
|
376
|
+
The last rendered frame stays frozen on the canvas.
|
|
377
|
+
|
|
378
|
+
```ts
|
|
379
|
+
import { Behaviour } from "@relu-interactives/spatial-ecs";
|
|
380
|
+
|
|
381
|
+
export default class PauseOnHit extends Behaviour {
|
|
382
|
+
onUpdate() {
|
|
383
|
+
// Pause when the spacebar is pressed, resume when pressed again.
|
|
384
|
+
if (!this.world.getKeyDown("Space")) return;
|
|
385
|
+
|
|
386
|
+
if (this.world.isPaused()) {
|
|
387
|
+
this.world.resume();
|
|
388
|
+
} else {
|
|
389
|
+
this.world.pause();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
> [!TIP]
|
|
396
|
+
> `pause()` and `resume()` affect the **entire world**. If you only want to
|
|
397
|
+
> stop a subset of entities (for example, freeze enemies while a menu is open)
|
|
398
|
+
> use a flag on a custom component instead and guard your `onUpdate` logic.
|
|
399
|
+
|
|
400
|
+
## See also
|
|
401
|
+
|
|
402
|
+
- [Custom Behaviours](./authoring-a-behaviour) — `init`, `onUpdate`, `dispose`, `data`, lifecycle.
|
|
403
|
+
- [Inspector Data Binding](./inspector-data-binding) — exposing fields to the inspector through `data`.
|
|
404
|
+
- [Behaviour Lifecycle & Events](./behaviour-lifecycle) — when each hook fires.
|
|
405
|
+
- [Component Catalog](./component-catalog) — the components you'll read and mutate from scripts.
|