@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
|
@@ -12,15 +12,14 @@ It is a **singleton** there is exactly one `Environment` entity per scene, owned
|
|
|
12
12
|
|
|
13
13
|
## Get the component from the world
|
|
14
14
|
|
|
15
|
+
Use `world.getEnvironmentComponent()` — a convenience method that handles the entity lookup for you:
|
|
16
|
+
|
|
15
17
|
```ts
|
|
16
|
-
import { Behaviour
|
|
18
|
+
import { Behaviour } from "@relu-interactives/spatial-ecs";
|
|
17
19
|
|
|
18
20
|
export default class ReadEnvironment extends Behaviour {
|
|
19
21
|
init() {
|
|
20
|
-
const
|
|
21
|
-
if (entityId === undefined) return;
|
|
22
|
-
|
|
23
|
-
const env = this.world.getComponent(entityId, Environment);
|
|
22
|
+
const env = this.world.getEnvironmentComponent();
|
|
24
23
|
if (!env) return;
|
|
25
24
|
|
|
26
25
|
console.log("skybox type", env.values.skybox.type);
|
|
@@ -29,7 +28,7 @@ export default class ReadEnvironment extends Behaviour {
|
|
|
29
28
|
}
|
|
30
29
|
```
|
|
31
30
|
|
|
32
|
-
`env.values` is the live state object. Mutating fields on it is enough
|
|
31
|
+
`env.values` is the live state object. Mutating fields on it is enough — `EnvironmentSyncSystem` reads it every frame and pushes changes into the three.js scene.
|
|
33
32
|
|
|
34
33
|
## Change values at runtime
|
|
35
34
|
|
|
@@ -9,22 +9,17 @@ Some settings live on the **scene** rather than on a single object the skybox, f
|
|
|
9
9
|
|
|
10
10
|
## Pattern
|
|
11
11
|
|
|
12
|
-
Both components
|
|
12
|
+
Both components expose a convenience method on `world` — no manual entity lookup needed:
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
|
-
import { Behaviour
|
|
15
|
+
import { Behaviour } from "@relu-interactives/spatial-ecs";
|
|
16
16
|
|
|
17
17
|
export default class TweakScene extends Behaviour {
|
|
18
18
|
init() {
|
|
19
|
-
|
|
20
|
-
const [entityId] = this.world.query(Environment);
|
|
21
|
-
if (entityId === undefined) return;
|
|
22
|
-
|
|
23
|
-
// 2. Read the component instance.
|
|
24
|
-
const env = this.world.getComponent(entityId, Environment);
|
|
19
|
+
const env = this.world.getEnvironmentComponent();
|
|
25
20
|
if (!env) return;
|
|
26
21
|
|
|
27
|
-
//
|
|
22
|
+
// Mutate `env.values` — sync systems pick the change up next frame.
|
|
28
23
|
env.values.fog.type = "linear";
|
|
29
24
|
env.values.fog.color = "#88aaff";
|
|
30
25
|
env.values.fog.linear.near = 5;
|
|
@@ -33,4 +28,4 @@ export default class TweakScene extends Behaviour {
|
|
|
33
28
|
}
|
|
34
29
|
```
|
|
35
30
|
|
|
36
|
-
The same
|
|
31
|
+
The same pattern works for `Postprocessing` via `this.world.getPostprocessingComponent()` — see each page for the full set of authorable values.
|
|
@@ -11,15 +11,14 @@ It is a **singleton** there is exactly one `Postprocessing` entity per scene, ow
|
|
|
11
11
|
|
|
12
12
|
## Get the component from the world
|
|
13
13
|
|
|
14
|
+
Use `world.getPostprocessingComponent()` — a convenience method that handles the entity lookup for you:
|
|
15
|
+
|
|
14
16
|
```ts
|
|
15
|
-
import { Behaviour
|
|
17
|
+
import { Behaviour } from "@relu-interactives/spatial-ecs";
|
|
16
18
|
|
|
17
19
|
export default class ReadPostprocessing extends Behaviour {
|
|
18
20
|
init() {
|
|
19
|
-
const
|
|
20
|
-
if (entityId === undefined) return;
|
|
21
|
-
|
|
22
|
-
const post = this.world.getComponent(entityId, Postprocessing);
|
|
21
|
+
const post = this.world.getPostprocessingComponent();
|
|
23
22
|
if (!post) return;
|
|
24
23
|
|
|
25
24
|
console.log("post enabled?", post.values.postEnabled);
|
|
@@ -27,7 +26,7 @@ export default class ReadPostprocessing extends Behaviour {
|
|
|
27
26
|
}
|
|
28
27
|
```
|
|
29
28
|
|
|
30
|
-
`post.values` is the live state object mutate fields on it directly. The `PostprocessingSyncSystem` reads it every frame and rebuilds the composer pipeline as effects are toggled.
|
|
29
|
+
`post.values` is the live state object — mutate fields on it directly. The `PostprocessingSyncSystem` reads it every frame and rebuilds the composer pipeline as effects are toggled.
|
|
31
30
|
|
|
32
31
|
## Change values at runtime
|
|
33
32
|
|
|
@@ -44,4 +44,65 @@ Component kinds (e.g. `"animation"`, `"physics"`) are registered with `registerC
|
|
|
44
44
|
|
|
45
45
|
## API reference
|
|
46
46
|
|
|
47
|
+
### `requestCreate(kind, payload?, onCreated?)`
|
|
48
|
+
|
|
49
|
+
Queue a new entity creation request. The factory for the given `kind` runs on the next frame; the optional `onCreated` callback fires with the new `entityId`:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
const oms = this.world.getObjectManagementSystem();
|
|
53
|
+
|
|
54
|
+
oms?.requestCreate("cube", {
|
|
55
|
+
name: "DynamicCube",
|
|
56
|
+
transform: { position: { x: 0, y: 2, z: 0 } },
|
|
57
|
+
}, (entityId) => {
|
|
58
|
+
// entityId is ready — add more components here
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### `createComponentNow(kind, world, entityId, ...args)`
|
|
63
|
+
|
|
64
|
+
Synchronously call the registered component factory for `kind` on an existing entity. Use this instead of `world.addComponent` when the component needs runtime setup (Rapier bodies, Web Audio nodes, Three.js material instances):
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
// Add physics with full Rapier body + collider setup
|
|
68
|
+
oms.createComponentNow("physics", world, entityId, {
|
|
69
|
+
rigidbody: { type: "dynamic", mass: 1, gravityScale: 1 },
|
|
70
|
+
collider: { shape: "box" },
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Add a material with a Three.js material instance
|
|
74
|
+
oms.createComponentNow("material", world, entityId, { color: "#ff0000" });
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Registered factory kinds: `"animation"`, `"audio"`, `"camera"`, `"physics"`, `"environment"`, `"entityType"`, `"image"`, `"imageTarget"`, `"imageTargetAnchor"`, `"light"`, `"material"`, `"mesh"`, `"meshGeometry"`, `"model"`, `"name"`, `"object3DRef"`, `"parentId"`, `"postprocessing"`, `"script"`, `"sprite"`, `"transform"`, `"video"`, `"instancedMesh"`.
|
|
78
|
+
|
|
79
|
+
### `deleteEntity(world, entityId, dispose?)`
|
|
80
|
+
|
|
81
|
+
Remove an entity from the ECS world and its `Object3D` from the Three.js scene graph. Pass `dispose = true` to also free GPU memory by calling `.dispose()` on all `BufferGeometry` and `Material` instances in the subtree:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// Remove from scene, keep GPU resources (safe if geometry is shared)
|
|
85
|
+
oms.deleteEntity(world, entityId);
|
|
86
|
+
|
|
87
|
+
// Remove from scene and free GPU memory (use for dynamically spawned objects)
|
|
88
|
+
oms.deleteEntity(world, entityId, true);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### `setParent(world, entityId, parentId, options?)`
|
|
92
|
+
|
|
93
|
+
Re-parent an entity at runtime. Updates the `ParentId` component and reconciles the Three.js scene graph on the same frame. By default (`preserveWorldTransform: true`), world-space position and rotation are preserved by adjusting the local transform:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
// Attach child to a parent entity (preserves world position)
|
|
97
|
+
oms.setParent(world, childEntityId, parentEntityId);
|
|
98
|
+
|
|
99
|
+
// Detach from parent — make direct child of scene root
|
|
100
|
+
oms.setParent(world, childEntityId, null);
|
|
101
|
+
|
|
102
|
+
// Reparent without preserving world position (local transform reset)
|
|
103
|
+
oms.setParent(world, childEntityId, parentEntityId, { preserveWorldTransform: false });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`setParent` guards against cycles and returns `false` if the operation would create a loop or if either entity does not exist.
|
|
107
|
+
|
|
47
108
|
- Source: [`core/systems/ObjectManagementSystem.ts`](https://github.com/Relu-Interactives/relu-spatial-ecs-engine/blob/main/core/systems/ObjectManagementSystem.ts)
|
|
@@ -55,6 +55,8 @@ export default class Spinner extends Behaviour {
|
|
|
55
55
|
| `getEntityByName(name)` | First entity whose `Name` matches, or `null`. |
|
|
56
56
|
| `getEntitiesByName(name)` | All entities sharing a `Name`. |
|
|
57
57
|
| `getEntitiesByComponent(component)` | All entities that own a component of the same class. |
|
|
58
|
+
| `getEntitiesChildren(entityId)` | All child entities of the given entity (entities whose `ParentId` component points to this entity). |
|
|
59
|
+
| `getEntitiesParent(entityId)` | The parent entity of the given entity, or `null` if the entity has no parent or is at the world root. |
|
|
58
60
|
|
|
59
61
|
### Scripts
|
|
60
62
|
|
|
@@ -102,6 +104,8 @@ Both methods accept `Vec3` (`THREE.Vector3` or `{ x, y, z }`) and return `Inters
|
|
|
102
104
|
| `getSystem(SystemClass)` | Resolve a registered system instance. |
|
|
103
105
|
| `hasSystem(SystemClass)` | `true` if the system is registered. |
|
|
104
106
|
| `getObjectManagementSystem()` | Shorthand for the built-in `ObjectManagementSystem`. Use this to spawn or destroy entities at runtime (`requestCreate`, `createNow`, `deleteEntity`). |
|
|
107
|
+
| `getEnvironmentComponent()` | Returns the singleton [`Environment`](./scene/environment) component, or `undefined` if not yet initialized. Mutate `values` to change skybox, fog, or gravity at runtime. |
|
|
108
|
+
| `getPostprocessingComponent()` | Returns the singleton [`Postprocessing`](./scene/postprocessing) component, or `undefined` if not yet initialized. Mutate `values` to toggle effects or adjust parameters at runtime. |
|
|
105
109
|
|
|
106
110
|
### World lifecycle
|
|
107
111
|
|
|
@@ -148,6 +152,38 @@ export default class FlickerAllLights extends Behaviour {
|
|
|
148
152
|
}
|
|
149
153
|
```
|
|
150
154
|
|
|
155
|
+
### Navigate the entity hierarchy
|
|
156
|
+
|
|
157
|
+
Use `getEntitiesParent` and `getEntitiesChildren` to traverse parent-child relationships in the scene graph. This is useful for group operations, finding related entities, or building custom hierarchy traversal logic.
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { Behaviour } from "@relu-interactives/spatial-ecs";
|
|
161
|
+
|
|
162
|
+
export default class HierarchyWalker extends Behaviour {
|
|
163
|
+
init() {
|
|
164
|
+
// Get the parent of this entity
|
|
165
|
+
const parent = this.world.getEntitiesParent(this.entityId);
|
|
166
|
+
if (parent) {
|
|
167
|
+
console.log(`Parent: ${parent.name} (ID: ${parent.entityId})`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Get all children of this entity
|
|
171
|
+
const children = this.world.getEntitiesChildren(this.entityId);
|
|
172
|
+
console.log(`Children count: ${children.length}`);
|
|
173
|
+
for (const child of children) {
|
|
174
|
+
console.log(` - ${child.name} (ID: ${child.entityId})`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Recursively walk up to the root
|
|
178
|
+
let current = this.world.getEntityById(this.entityId);
|
|
179
|
+
while (current) {
|
|
180
|
+
console.log(`Ancestor: ${current.name}`);
|
|
181
|
+
current = this.world.getEntitiesParent(current.entityId);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
151
187
|
### Talk to another script on a different entity
|
|
152
188
|
|
|
153
189
|
```ts
|
|
@@ -398,6 +434,6 @@ export default class PauseOnHit extends Behaviour {
|
|
|
398
434
|
## See also
|
|
399
435
|
|
|
400
436
|
- [Custom Behaviours](./authoring-a-behaviour) — `init`, `onUpdate`, `dispose`, `data`, lifecycle.
|
|
401
|
-
- [
|
|
437
|
+
- [Behaviour Data Binding](./behaviour-data-binding/) — exposing fields to the inspector through `data`.
|
|
402
438
|
- [Behaviour Lifecycle & Events](./behaviour-lifecycle) — when each hook fires.
|
|
403
439
|
- [Component Catalog](./component-catalog) — the components you'll read and mutate from scripts.
|