@relu-interactives/spatial-ecs 0.2.12 → 0.2.14
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/dist/{System-CHCucemW.d.cts → System-BeuJ1xt5.d.cts} +291 -2
- package/dist/{System-CHCucemW.d.ts → System-BeuJ1xt5.d.ts} +291 -2
- package/dist/{Video-B9ZKmBIT.d.ts → Video-Cym2C52L.d.ts} +2 -241
- package/dist/{Video-ACTSfWjH.d.cts → Video-D4B-z74P.d.cts} +2 -241
- package/dist/{chunk-PH43YHUT.js → chunk-27RBPOVO.js} +3 -3
- package/dist/{chunk-PH43YHUT.js.map → chunk-27RBPOVO.js.map} +1 -1
- package/dist/{chunk-ZCEMOTH4.js → chunk-7QBONTBW.js} +4 -4
- package/dist/{chunk-ZCEMOTH4.js.map → chunk-7QBONTBW.js.map} +1 -1
- package/dist/{chunk-XPCVEXMY.js → chunk-FTIQQK62.js} +2 -2
- package/dist/chunk-FTIQQK62.js.map +1 -0
- package/dist/{chunk-ON4E5E5O.js → chunk-KDZ6VBRO.js} +4 -4
- package/dist/{chunk-ON4E5E5O.js.map → chunk-KDZ6VBRO.js.map} +1 -1
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +1 -1
- package/dist/docs/api/Behaviour/classes/Behaviour.md +29 -29
- package/dist/docs/api/Component/classes/Component.md +1 -1
- package/dist/docs/api/components/classes/AnimationComponent.md +26 -26
- package/dist/docs/api/components/classes/AudioComponent.md +19 -19
- package/dist/docs/api/components/classes/CameraComponent.md +14 -14
- package/dist/docs/api/components/classes/EntityType.md +3 -3
- package/dist/docs/api/components/classes/Environment.md +7 -3
- package/dist/docs/api/components/classes/ImageComponent.md +7 -7
- package/dist/docs/api/components/classes/ImageTarget.md +7 -7
- package/dist/docs/api/components/classes/ImageTargetAnchor.md +4 -4
- package/dist/docs/api/components/classes/InstanceSlotComponent.md +4 -4
- package/dist/docs/api/components/classes/InstancedMeshComponent.md +10 -10
- package/dist/docs/api/components/classes/LightComponent.md +6 -6
- package/dist/docs/api/components/classes/MaterialComponent.md +11 -11
- package/dist/docs/api/components/classes/MeshComponent.md +3 -3
- package/dist/docs/api/components/classes/MeshGeometryComponent.md +9 -9
- package/dist/docs/api/components/classes/ModelComponent.md +4 -4
- package/dist/docs/api/components/classes/Name.md +3 -3
- package/dist/docs/api/components/classes/Object3DRef.md +4 -4
- package/dist/docs/api/components/classes/ParentId.md +3 -3
- package/dist/docs/api/components/classes/PhysicsComponent.md +6 -6
- package/dist/docs/api/components/classes/Postprocessing.md +7 -3
- package/dist/docs/api/components/classes/ScriptComponent.md +5 -5
- package/dist/docs/api/components/classes/Selectable.md +3 -3
- package/dist/docs/api/components/classes/SelectionTransformState.md +5 -5
- package/dist/docs/api/components/classes/SpriteComponent.md +7 -7
- package/dist/docs/api/components/classes/TransformComponent.md +12 -12
- package/dist/docs/api/components/classes/VideoComponent.md +28 -28
- package/dist/docs/api/components/functions/normalizePhysicsState.md +1 -1
- package/dist/docs/api/components/index.md +1 -1
- package/dist/docs/api/components/type-aliases/AnimationComponentOptions.md +9 -9
- package/dist/docs/api/components/type-aliases/CameraComponentOptions.md +13 -13
- package/dist/docs/api/components/type-aliases/CameraProjection.md +1 -1
- package/dist/docs/api/components/type-aliases/CameraRuntimeType.md +1 -1
- package/dist/docs/api/components/type-aliases/ColliderShape.md +1 -1
- package/dist/docs/api/components/type-aliases/ColliderState.md +20 -20
- package/dist/docs/api/components/type-aliases/CubeMeshParameters.md +4 -4
- package/dist/docs/api/components/type-aliases/EditableMeshObjectKind.md +1 -1
- package/dist/docs/api/components/type-aliases/EnvironmentFogState.md +8 -8
- package/dist/docs/api/components/type-aliases/EnvironmentFogType.md +1 -1
- package/dist/docs/api/components/type-aliases/EnvironmentGradientEffect.md +1 -1
- package/dist/docs/api/components/type-aliases/EnvironmentSkyboxState.md +7 -7
- package/dist/docs/api/components/type-aliases/EnvironmentSkyboxType.md +1 -1
- package/dist/docs/api/components/type-aliases/EnvironmentState.md +5 -5
- package/dist/docs/api/components/type-aliases/ImageTargetAnchorOptions.md +3 -3
- package/dist/docs/api/components/type-aliases/ImageTargetReference.md +7 -7
- package/dist/docs/api/components/type-aliases/InstanceTransform.md +13 -13
- package/dist/docs/api/components/type-aliases/InstancedMeshKind.md +1 -1
- package/dist/docs/api/components/type-aliases/LightValueState.md +11 -11
- package/dist/docs/api/components/type-aliases/MaterialTypeValue.md +1 -1
- package/dist/docs/api/components/type-aliases/MaterialValueState.md +28 -28
- package/dist/docs/api/components/type-aliases/MeshGeometryParameters.md +1 -1
- package/dist/docs/api/components/type-aliases/MeshGeometryParametersByKind.md +7 -7
- package/dist/docs/api/components/type-aliases/PhysicsState.md +3 -3
- package/dist/docs/api/components/type-aliases/PlaneMeshParameters.md +3 -3
- package/dist/docs/api/components/type-aliases/PostprocessingState.md +62 -62
- package/dist/docs/api/components/type-aliases/RadiusHeightMeshParameters.md +3 -3
- package/dist/docs/api/components/type-aliases/RadiusMeshParameters.md +2 -2
- package/dist/docs/api/components/type-aliases/RigidbodyState.md +17 -17
- package/dist/docs/api/components/type-aliases/RigidbodyType.md +1 -1
- package/dist/docs/api/components/type-aliases/ScriptEntry.md +9 -9
- package/dist/docs/api/components/type-aliases/TextureFilteringValue.md +1 -1
- package/dist/docs/api/components/type-aliases/TransformData.md +4 -4
- package/dist/docs/api/components/type-aliases/TransformModeValue.md +1 -1
- package/dist/docs/api/components/type-aliases/TransformSpaceValue.md +1 -1
- package/dist/docs/api/components/type-aliases/Vec3.md +4 -4
- package/dist/docs/api/components/variables/DEFAULT_COLLIDER_STATE.md +1 -1
- package/dist/docs/api/components/variables/DEFAULT_ENVIRONMENT_STATE.md +1 -1
- package/dist/docs/api/components/variables/DEFAULT_INSTANCED_MESH_PARAMETERS.md +1 -1
- package/dist/docs/api/components/variables/DEFAULT_INSTANCE_TRANSFORM.md +1 -1
- package/dist/docs/api/components/variables/DEFAULT_MESH_GEOMETRY_PARAMETERS.md +1 -1
- package/dist/docs/api/components/variables/DEFAULT_PHYSICS_STATE.md +1 -1
- package/dist/docs/api/components/variables/DEFAULT_POSTPROCESSING_STATE.md +1 -1
- package/dist/docs/api/components/variables/DEFAULT_RIGIDBODY_STATE.md +1 -1
- package/dist/docs/api/index/classes/AnimationStateMachine.md +16 -16
- package/dist/docs/api/index/classes/AnimationStateManager.md +13 -13
- package/dist/docs/api/index/classes/AnimationSystem.md +3 -3
- package/dist/docs/api/index/classes/AudioSystem.md +4 -4
- package/dist/docs/api/index/classes/CameraSyncSystem.md +2 -2
- package/dist/docs/api/index/classes/EnvironmentSyncSystem.md +4 -4
- package/dist/docs/api/index/classes/InputSystem.md +33 -33
- package/dist/docs/api/index/classes/InstancedMeshSystem.md +2 -2
- package/dist/docs/api/index/classes/LightSyncSystem.md +2 -2
- package/dist/docs/api/index/classes/MaterialSyncSystem.md +3 -3
- package/dist/docs/api/index/classes/MeshGeometrySystem.md +2 -2
- package/dist/docs/api/index/classes/ObjectManagementSystem.md +14 -14
- package/dist/docs/api/index/classes/ObjectVisibilitySystem.md +2 -2
- package/dist/docs/api/index/classes/PhysicsSyncSystem.md +4 -4
- package/dist/docs/api/index/classes/PostprocessingSyncSystem.md +4 -4
- package/dist/docs/api/index/classes/RenderSystem.md +3 -3
- package/dist/docs/api/index/classes/ScriptBehaviourSystem.md +4 -4
- package/dist/docs/api/index/classes/TransformSyncSystem.md +2 -2
- package/dist/docs/api/index/classes/VideoSystem.md +4 -4
- package/dist/docs/api/index/classes/World.md +186 -82
- package/dist/docs/api/index/functions/createAnimationComponent.md +1 -1
- package/dist/docs/api/index/functions/createAudioComponent.md +1 -1
- package/dist/docs/api/index/functions/createCameraComponent.md +1 -1
- package/dist/docs/api/index/functions/createEntityTypeComponent.md +1 -1
- package/dist/docs/api/index/functions/createEnvironmentComponent.md +1 -1
- package/dist/docs/api/index/functions/createImageComponent.md +1 -1
- package/dist/docs/api/index/functions/createImageTargetAnchorComponent.md +1 -1
- package/dist/docs/api/index/functions/createImageTargetComponent.md +1 -1
- package/dist/docs/api/index/functions/createInstanceSlotComponent.md +1 -1
- package/dist/docs/api/index/functions/createInstancedMeshComponent.md +1 -1
- package/dist/docs/api/index/functions/createLightComponent.md +1 -1
- package/dist/docs/api/index/functions/createMaterialComponent.md +1 -1
- package/dist/docs/api/index/functions/createMeshComponent.md +1 -1
- package/dist/docs/api/index/functions/createMeshGeometryComponent.md +1 -1
- package/dist/docs/api/index/functions/createModelComponent.md +1 -1
- package/dist/docs/api/index/functions/createNameComponent.md +1 -1
- package/dist/docs/api/index/functions/createObject3DRefComponent.md +1 -1
- package/dist/docs/api/index/functions/createParentIdComponent.md +1 -1
- package/dist/docs/api/index/functions/createPhysicsComponent.md +1 -1
- package/dist/docs/api/index/functions/createPostprocessingComponent.md +1 -1
- package/dist/docs/api/index/functions/createScriptComponent.md +1 -1
- package/dist/docs/api/index/functions/createSelectableComponent.md +1 -1
- package/dist/docs/api/index/functions/createSelectionTransformStateComponent.md +1 -1
- package/dist/docs/api/index/functions/createSpriteComponent.md +1 -1
- package/dist/docs/api/index/functions/createTransformComponent.md +1 -1
- package/dist/docs/api/index/functions/createVideoComponent.md +1 -1
- package/dist/docs/api/index/functions/hydrateWorldFromSnapshot.md +1 -1
- package/dist/docs/api/index/functions/hydrateWorldFromSnapshotDetailed.md +1 -1
- package/dist/docs/api/index/functions/registerDefaultComponentFactories.md +1 -1
- package/dist/docs/api/index/functions/registerDefaultFactories.md +1 -1
- package/dist/docs/api/index/interfaces/EcsSystem.md +3 -3
- package/dist/docs/api/index/interfaces/StateMachine.md +13 -13
- package/dist/docs/api/index/type-aliases/AnimationStateCallbacks.md +4 -4
- package/dist/docs/api/index/type-aliases/ComponentFactory.md +1 -1
- package/dist/docs/api/index/type-aliases/EcsComponentFactoryKind.md +1 -1
- package/dist/docs/api/index/type-aliases/EcsWorldComponentSnapshot.md +3 -3
- package/dist/docs/api/index/type-aliases/EcsWorldStateSnapshotLike.md +4 -4
- package/dist/docs/api/index/type-aliases/HydrateWorldFromSnapshotResult.md +3 -3
- package/dist/docs/api/index/type-aliases/KeyboardKey.md +1 -1
- package/dist/docs/api/index/type-aliases/MouseButton.md +1 -1
- package/dist/docs/api/index/type-aliases/SelectionContext.md +4 -4
- package/dist/docs/api/index/variables/HYDRATABLE_ENTITY_KINDS.md +1 -1
- package/dist/docs/api/index/variables/KeyboardKeys.md +89 -89
- package/dist/docs/api/types/type-aliases/AssetInput.md +3 -3
- package/dist/docs/api/types/type-aliases/CheckboxInput.md +12 -2
- package/dist/docs/api/types/type-aliases/ColorInput.md +1 -1
- package/dist/docs/api/types/type-aliases/ComponentInput.md +4 -4
- package/dist/docs/api/types/type-aliases/ComponentKind.md +1 -1
- package/dist/docs/api/types/type-aliases/DropdownInput.md +3 -3
- package/dist/docs/api/types/type-aliases/DropdownOption.md +3 -3
- package/dist/docs/api/types/type-aliases/EcsEntityEditorKind.md +1 -1
- package/dist/docs/api/types/type-aliases/EcsEntityKind.md +1 -1
- package/dist/docs/api/types/type-aliases/EntityId.md +1 -1
- package/dist/docs/api/types/type-aliases/EntityInput.md +3 -3
- package/dist/docs/api/types/type-aliases/FloatInput.md +1 -1
- package/dist/docs/api/types/type-aliases/IntersectionResult.md +3 -3
- package/dist/docs/api/types/type-aliases/ParentLookup.md +3 -3
- package/dist/docs/api/types/type-aliases/SelectionListener.md +1 -1
- package/dist/docs/api/types/type-aliases/SliderInput.md +5 -5
- package/dist/docs/api/types/type-aliases/TextInput.md +1 -1
- package/dist/docs/api/types/type-aliases/ToggleInput.md +1 -1
- package/dist/docs/api/types/type-aliases/Vec3.md +1 -1
- package/dist/docs/api/types/type-aliases/Vector2Input.md +3 -3
- package/dist/docs/api/types/type-aliases/Vector3Input.md +4 -4
- package/dist/docs/api/types/type-aliases/WorldEntityView.md +1 -1
- package/dist/docs/guide/accessing-components.md +135 -1
- package/dist/docs/guide/authoring-a-behaviour.md +1 -1
- package/dist/docs/guide/behaviour-data-binding/asset-input.md +54 -0
- package/dist/docs/guide/behaviour-data-binding/checkbox-input.md +38 -0
- package/dist/docs/guide/behaviour-data-binding/color-input.md +38 -0
- package/dist/docs/guide/behaviour-data-binding/component-input.md +79 -0
- package/dist/docs/guide/behaviour-data-binding/dropdown-input.md +53 -0
- package/dist/docs/guide/behaviour-data-binding/entity-input.md +100 -0
- package/dist/docs/guide/behaviour-data-binding/float-input.md +35 -0
- package/dist/docs/guide/behaviour-data-binding/index.md +158 -0
- package/dist/docs/guide/behaviour-data-binding/slider-input.md +37 -0
- package/dist/docs/guide/behaviour-data-binding/text-input.md +35 -0
- package/dist/docs/guide/behaviour-data-binding/toggle-input.md +36 -0
- package/dist/docs/guide/behaviour-data-binding/vector2-input.md +36 -0
- package/dist/docs/guide/behaviour-data-binding/vector3-input.md +41 -0
- package/dist/docs/guide/components/parent-id.md +25 -0
- package/dist/docs/guide/runtime-entity-management.md +302 -0
- package/dist/docs/guide/scene/environment.md +5 -6
- package/dist/docs/guide/scene/index.md +5 -10
- package/dist/docs/guide/scene/postprocessing.md +5 -6
- package/dist/docs/guide/systems/object-management-system.md +61 -0
- package/dist/docs/guide/world-api.md +37 -1
- package/dist/factories/index.cjs.map +1 -1
- package/dist/factories/index.d.cts +2 -2
- package/dist/factories/index.d.ts +2 -2
- package/dist/factories/index.js +3 -3
- package/dist/{index-B5JcGMJ5.d.ts → index-BfoOC2CG.d.cts} +2 -2
- package/dist/{index-kx5O2mVU.d.cts → index-BoJ3_6a3.d.ts} +2 -2
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +73 -8
- package/dist/index.js.map +1 -1
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.d.cts +2 -2
- package/dist/systems/index.d.ts +2 -2
- package/dist/systems/index.js +3 -3
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/worldSnapshotUtils.d.cts +1 -1
- package/dist/worldSnapshotUtils.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-XPCVEXMY.js.map +0 -1
- package/dist/docs/guide/inspector-data-binding.md +0 -367
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
# Inspector Data Binding
|
|
2
|
-
|
|
3
|
-
The `ScriptComponent.data` field is the bridge between the editor inspector and your `Behaviour` subclass. Anything you place on `data` is:
|
|
4
|
-
|
|
5
|
-
1. Saved with the project.
|
|
6
|
-
2. Rendered as a live inspector control in the editor.
|
|
7
|
-
3. Available at runtime as `this.data` inside the script.
|
|
8
|
-
|
|
9
|
-
The **type annotation** on each field tells the editor which control to render. Import the input types from `@relu-interactives/spatial-ecs` and use them as `as` casts on the initial values in your data object.
|
|
10
|
-
|
|
11
|
-
## Input types reference
|
|
12
|
-
|
|
13
|
-
| Type | Import | Inspector control | Runtime value |
|
|
14
|
-
| --- | --- | --- | --- |
|
|
15
|
-
| `FloatInput` | ✓ | Number input | `number` |
|
|
16
|
-
| `TextInput` | ✓ | Text input | `string` |
|
|
17
|
-
| `ColorInput` | ✓ | Color picker | `string` (hex, e.g. `"#ff0000"`) |
|
|
18
|
-
| `Vector2Input` | ✓ | XY number pair | `{ x: number; y: number }` |
|
|
19
|
-
| `Vector3Input` | ✓ | XYZ number triple | `{ x: number; y: number; z: number }` |
|
|
20
|
-
| `SliderInput` | ✓ | Range slider | `{ min, max, step, value }` (read `field.value` at runtime) |
|
|
21
|
-
| `DropdownInput` | ✓ | Select dropdown | `{ options: DropdownOption[]; value: string }` (read `field.value`) |
|
|
22
|
-
| `CheckboxInput` | ✓ | Checkbox | `boolean` |
|
|
23
|
-
| `ToggleInput` | ✓ | Toggle switch | `boolean` |
|
|
24
|
-
| `AssetInput` | ✓ | Asset file picker | `{ path: string; type: string }` — read `field.path`; `.value` is always `null` |
|
|
25
|
-
| `EntityInput` | ✓ | Entity picker | `{ type: "entity"; value: WorldEntityView \| null }` — read `field.value` |
|
|
26
|
-
| `ComponentInput` | ✓ | Entity + component picker | `{ type: "component"; componentKind?: ComponentKind; value: Component \| null }` — read `field.value` |
|
|
27
|
-
|
|
28
|
-
## Declaring inspector fields
|
|
29
|
-
|
|
30
|
-
Import the input types you need alongside `Behaviour`, then declare them directly on the `data` class property using `as` casts:
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
import {
|
|
34
|
-
Behaviour,
|
|
35
|
-
type FloatInput,
|
|
36
|
-
type TextInput,
|
|
37
|
-
type ColorInput,
|
|
38
|
-
type Vector2Input,
|
|
39
|
-
type Vector3Input,
|
|
40
|
-
type SliderInput,
|
|
41
|
-
type DropdownInput,
|
|
42
|
-
type CheckboxInput,
|
|
43
|
-
type ToggleInput,
|
|
44
|
-
type AssetInput,
|
|
45
|
-
type EntityInput,
|
|
46
|
-
type ComponentInput,
|
|
47
|
-
} from "@relu-interactives/spatial-ecs";
|
|
48
|
-
|
|
49
|
-
export default class Demo extends Behaviour {
|
|
50
|
-
data = {
|
|
51
|
-
speed: 1 as FloatInput,
|
|
52
|
-
label: "Hello" as TextInput,
|
|
53
|
-
tint: "#ffffff" as ColorInput,
|
|
54
|
-
offset: { x: 0, y: 0 } as Vector2Input,
|
|
55
|
-
origin: { x: 0, y: 0, z: 0 } as Vector3Input,
|
|
56
|
-
range: { min: 0, max: 10, step: 0.1, value: 5 } as SliderInput,
|
|
57
|
-
axis: {
|
|
58
|
-
value: "y",
|
|
59
|
-
options: [
|
|
60
|
-
{ label: "X", value: "x" },
|
|
61
|
-
{ label: "Y", value: "y" },
|
|
62
|
-
{ label: "Z", value: "z" },
|
|
63
|
-
],
|
|
64
|
-
} as DropdownInput,
|
|
65
|
-
active: true as ToggleInput,
|
|
66
|
-
visible: true as CheckboxInput,
|
|
67
|
-
texture: { path: "", type: "texture" } as AssetInput,
|
|
68
|
-
target: { type: "entity", value: null } as EntityInput,
|
|
69
|
-
camera: { type: "component", componentKind: "Camera", value: null } as ComponentInput,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Reading values at runtime
|
|
75
|
-
|
|
76
|
-
Most types map directly to their underlying primitive. The exceptions are `SliderInput`, `DropdownInput`, `AssetInput`, `EntityInput`, and `ComponentInput`, which are objects — read the nested value:
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
export default class Demo extends Behaviour {
|
|
80
|
-
data = {
|
|
81
|
-
speed: 1 as FloatInput,
|
|
82
|
-
active: true as ToggleInput,
|
|
83
|
-
range: { min: 0, max: 1, step: 0.1, value: 0.8 } as SliderInput,
|
|
84
|
-
axis: { value: "y", options: [{ label: "X", value: "x" }, { label: "Y", value: "y" }, { label: "Z", value: "z" }] } as DropdownInput,
|
|
85
|
-
texture: { path: "", type: "texture" } as AssetInput,
|
|
86
|
-
target: { type: "entity", value: null } as EntityInput,
|
|
87
|
-
camera: { type: "component", componentKind: "Camera", value: null } as ComponentInput,
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
onUpdate() {
|
|
91
|
-
// FloatInput / TextInput / ColorInput / CheckboxInput / ToggleInput
|
|
92
|
-
// → use directly
|
|
93
|
-
this.transform.rotation.y += this.data.speed * this.deltaTime;
|
|
94
|
-
const isOn = this.data.active;
|
|
95
|
-
|
|
96
|
-
// SliderInput → read .value
|
|
97
|
-
const volume = this.data.range.value;
|
|
98
|
-
|
|
99
|
-
// DropdownInput → read .value
|
|
100
|
-
const axis = this.data.axis.value as "x" | "y" | "z";
|
|
101
|
-
this.transform.rotation[axis] += this.data.speed * this.deltaTime;
|
|
102
|
-
|
|
103
|
-
// AssetInput → read .path (see AssetInput section below)
|
|
104
|
-
const src = this.data.texture.path;
|
|
105
|
-
|
|
106
|
-
// EntityInput → cast to WorldEntityView | null
|
|
107
|
-
const entity = this.data.target.value as WorldEntityView | null;
|
|
108
|
-
|
|
109
|
-
// ComponentInput → cast to the concrete component type
|
|
110
|
-
const cam = this.data.camera.value as CameraComponent | null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## EntityInput — picking and using scene entities
|
|
116
|
-
|
|
117
|
-
`EntityInput` lets the editor user pick any entity from the scene. Declare it with `{ type: "entity", value: null }` as the default (no entity selected).
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
import {
|
|
121
|
-
Behaviour,
|
|
122
|
-
type EntityInput,
|
|
123
|
-
} from "@relu-interactives/spatial-ecs";
|
|
124
|
-
|
|
125
|
-
export default class Follower extends Behaviour {
|
|
126
|
-
data = {
|
|
127
|
-
target: { type: "entity", value: null } as EntityInput,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
At runtime, `this.data.target.value` is resolved to a **`WorldEntityView`** — not a raw ID. You can import and use this type directly:
|
|
133
|
-
|
|
134
|
-
```ts
|
|
135
|
-
import { type WorldEntityView } from "@relu-interactives/spatial-ecs";
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
`WorldEntityView` has the following shape:
|
|
139
|
-
|
|
140
|
-
```ts
|
|
141
|
-
type WorldEntityView = {
|
|
142
|
-
name: string; // entity name from the NameComponent
|
|
143
|
-
entityId: number; // runtime entity ID
|
|
144
|
-
type: string; // entity type ("mesh", "camera", "light", …)
|
|
145
|
-
object: THREE.Object3D | null; // live three.js scene object
|
|
146
|
-
components: Component[]; // all components attached to this entity
|
|
147
|
-
};
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### Reading entity data
|
|
151
|
-
|
|
152
|
-
```ts
|
|
153
|
-
onUpdate() {
|
|
154
|
-
const target = this.data.target.value as WorldEntityView | null;
|
|
155
|
-
if (!target) return; // no entity assigned in the inspector
|
|
156
|
-
|
|
157
|
-
// Name and ID
|
|
158
|
-
console.log(target.name); // e.g. "Camera"
|
|
159
|
-
console.log(target.entityId); // runtime numeric ID
|
|
160
|
-
|
|
161
|
-
// Access the three.js object directly
|
|
162
|
-
const obj = target.object;
|
|
163
|
-
if (obj) {
|
|
164
|
-
console.log(obj.position); // THREE.Vector3
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### Moving another entity from a script
|
|
170
|
-
|
|
171
|
-
Use `getEntity()` on `WorldEntityView` to get the entity's transform and mutate it:
|
|
172
|
-
|
|
173
|
-
```ts
|
|
174
|
-
import {
|
|
175
|
-
Behaviour,
|
|
176
|
-
TransformComponent,
|
|
177
|
-
type EntityInput,
|
|
178
|
-
type WorldEntityView,
|
|
179
|
-
} from "@relu-interactives/spatial-ecs";
|
|
180
|
-
|
|
181
|
-
export default class Mover extends Behaviour {
|
|
182
|
-
data = {
|
|
183
|
-
target: { type: "entity", value: null } as EntityInput,
|
|
184
|
-
speed: 5 as FloatInput,
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
onUpdate() {
|
|
188
|
-
const target = this.data.target.value as WorldEntityView | null;
|
|
189
|
-
if (!target) return;
|
|
190
|
-
|
|
191
|
-
// Find the TransformComponent on the picked entity
|
|
192
|
-
const transform = target.components.find(
|
|
193
|
-
(c) => c instanceof TransformComponent,
|
|
194
|
-
) as TransformComponent | undefined;
|
|
195
|
-
|
|
196
|
-
if (transform) {
|
|
197
|
-
transform.position.x += this.data.speed * this.deltaTime;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
> [!TIP]
|
|
204
|
-
> Always guard with `if (!target) return;` — the field is `null` until the user picks an entity in the inspector, and may be `null` in new scenes.
|
|
205
|
-
|
|
206
|
-
## ComponentInput — picking and using a specific component
|
|
207
|
-
|
|
208
|
-
`ComponentInput` lets the user pick an entity **and** a specific component kind from that entity. Use this when you want to read or drive a particular component (e.g. a `CameraComponent`, `AudioComponent`, or `AnimationComponent`).
|
|
209
|
-
|
|
210
|
-
```ts
|
|
211
|
-
import {
|
|
212
|
-
Behaviour,
|
|
213
|
-
type ComponentInput,
|
|
214
|
-
} from "@relu-interactives/spatial-ecs";
|
|
215
|
-
|
|
216
|
-
export default class CameraController extends Behaviour {
|
|
217
|
-
data = {
|
|
218
|
-
cam: { type: "component", componentKind: "CameraComponent", value: null } as ComponentInput,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
At runtime, `this.data.cam.value` is resolved to the **live component instance** — the actual class instance that the ECS manages each frame.
|
|
224
|
-
|
|
225
|
-
### Reading component properties
|
|
226
|
-
|
|
227
|
-
```ts
|
|
228
|
-
import {
|
|
229
|
-
Behaviour,
|
|
230
|
-
CameraComponent,
|
|
231
|
-
type ComponentInput,
|
|
232
|
-
} from "@relu-interactives/spatial-ecs";
|
|
233
|
-
|
|
234
|
-
export default class FovAnimator extends Behaviour {
|
|
235
|
-
data = {
|
|
236
|
-
camera: { type: "component", componentKind: "CameraComponent", value: null } as ComponentInput,
|
|
237
|
-
targetFov: 90 as FloatInput,
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
onUpdate() {
|
|
241
|
-
const cam = this.data.camera.value as CameraComponent | null;
|
|
242
|
-
if (!cam) return; // no component assigned
|
|
243
|
-
|
|
244
|
-
// Read a property
|
|
245
|
-
console.log(cam.fov); // current field of view in degrees
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
### Changing component properties
|
|
251
|
-
|
|
252
|
-
Mutate the instance directly — the system that owns the component will pick up the change next frame:
|
|
253
|
-
|
|
254
|
-
```ts
|
|
255
|
-
import {
|
|
256
|
-
Behaviour,
|
|
257
|
-
CameraComponent,
|
|
258
|
-
type ComponentInput,
|
|
259
|
-
type FloatInput,
|
|
260
|
-
} from "@relu-interactives/spatial-ecs";
|
|
261
|
-
|
|
262
|
-
export default class FovAnimator extends Behaviour {
|
|
263
|
-
data = {
|
|
264
|
-
camera: { type: "component", componentKind: "CameraComponent", value: null } as ComponentInput,
|
|
265
|
-
targetFov: 90 as FloatInput,
|
|
266
|
-
speed: 30 as FloatInput,
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
onUpdate() {
|
|
270
|
-
const cam = this.data.camera.value as CameraComponent | null;
|
|
271
|
-
if (!cam) return;
|
|
272
|
-
|
|
273
|
-
// Lerp the field of view toward targetFov
|
|
274
|
-
cam.fov += (this.data.targetFov - cam.fov) * this.data.speed * this.deltaTime;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
> [!TIP]
|
|
280
|
-
> Cast the resolved value to the concrete component type (e.g. `as CameraComponent | null`) to get full TypeScript autocompletion on its properties. Always guard the null case — the field is `null` until the user picks both an entity and a component in the inspector.
|
|
281
|
-
|
|
282
|
-
## AssetInput — referencing project assets
|
|
283
|
-
|
|
284
|
-
`AssetInput` exposes a file picker in the inspector. The user selects a file from the project's `assets/` folder. The field stores the relative path to that file.
|
|
285
|
-
|
|
286
|
-
```ts
|
|
287
|
-
import {
|
|
288
|
-
Behaviour,
|
|
289
|
-
type AssetInput,
|
|
290
|
-
} from "@relu-interactives/spatial-ecs";
|
|
291
|
-
|
|
292
|
-
export default class AudioPlayer extends Behaviour {
|
|
293
|
-
data = {
|
|
294
|
-
clip: { path: "", type: "audio" } as AssetInput,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
At runtime, **`this.data.clip.value` is always `null`** — `AssetInput` does not resolve to a loaded asset object. Use `this.data.clip.path` to get the relative file path, then load the asset yourself if needed:
|
|
300
|
-
|
|
301
|
-
```ts
|
|
302
|
-
onUpdate() {
|
|
303
|
-
const path = this.data.clip.path;
|
|
304
|
-
if (!path) return;
|
|
305
|
-
|
|
306
|
-
// path is the relative asset path, e.g. "./assets/sounds/click.mp3"
|
|
307
|
-
console.log(path);
|
|
308
|
-
}
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
The `type` field on the default value (`"audio"`, `"texture"`, `"model"`, etc.) is used by the editor to filter the file picker to relevant asset types.
|
|
312
|
-
|
|
313
|
-
## Practical example — spinner with inspector controls
|
|
314
|
-
|
|
315
|
-
```ts
|
|
316
|
-
import {
|
|
317
|
-
Behaviour,
|
|
318
|
-
type FloatInput,
|
|
319
|
-
type ColorInput,
|
|
320
|
-
type DropdownInput,
|
|
321
|
-
type ToggleInput,
|
|
322
|
-
} from "@relu-interactives/spatial-ecs";
|
|
323
|
-
|
|
324
|
-
export default class Spinner extends Behaviour {
|
|
325
|
-
data = {
|
|
326
|
-
speed: 1 as FloatInput,
|
|
327
|
-
color: "#00aaff" as ColorInput,
|
|
328
|
-
enabled: true as ToggleInput,
|
|
329
|
-
axis: {
|
|
330
|
-
value: "y",
|
|
331
|
-
options: [
|
|
332
|
-
{ label: "X", value: "x" },
|
|
333
|
-
{ label: "Y", value: "y" },
|
|
334
|
-
{ label: "Z", value: "z" },
|
|
335
|
-
],
|
|
336
|
-
} as DropdownInput,
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
onUpdate() {
|
|
340
|
-
if (!this.data.enabled) return;
|
|
341
|
-
const axis = this.data.axis.value as "x" | "y" | "z";
|
|
342
|
-
this.transform.rotation[axis] += this.data.speed * this.deltaTime;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
## Defaulting fields
|
|
348
|
-
|
|
349
|
-
Defaults are set inline on the `data` property. When a saved project reloads, saved values take precedence — the inline defaults only apply when a field has never been saved. This means:
|
|
350
|
-
|
|
351
|
-
- Adding a new field with an inline default is safe — existing saves will pick it up on next load.
|
|
352
|
-
- The inspector always has a valid initial value when the script is first attached.
|
|
353
|
-
- For `SliderInput` and `DropdownInput`, the full object (including `options`) must be present in the inline default — the editor reads `options` to build the control.
|
|
354
|
-
|
|
355
|
-
## Persistence
|
|
356
|
-
|
|
357
|
-
`ScriptComponent.data` is serialized and saved with the project. On reload, your `data` payload is restored verbatim. If you rename or restructure a field, migrate it inside `init()`:
|
|
358
|
-
|
|
359
|
-
```ts
|
|
360
|
-
init() {
|
|
361
|
-
// migrate renamed field
|
|
362
|
-
if ((this.data as any).oldSpeed !== undefined) {
|
|
363
|
-
this.data.speed = (this.data as any).oldSpeed;
|
|
364
|
-
delete (this.data as any).oldSpeed;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
```
|