@relu-interactives/spatial-ecs
@relu-interactives/spatial-ecs / index / ObjectManagementSystem
Class: ObjectManagementSystem ​
Defined in: systems/ObjectManagementSystem.ts:163
Implements ​
Constructors ​
Constructor ​
new ObjectManagementSystem(
scene,
camera,
isEditor?): ObjectManagementSystem;Defined in: systems/ObjectManagementSystem.ts:181
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
scene | Scene | undefined |
camera | PerspectiveCamera | undefined |
isEditor | boolean | false |
Returns ​
ObjectManagementSystem
Properties ​
| Property | Modifier | Type | Default value | Description | Defined in |
|---|---|---|---|---|---|
runsWhilePaused | readonly | true | true | Keep ticking while the world is paused. Leave it unset for anything that moves the game on: such a system stops at world.pause() and picks up where it was at world.resume(). | systems/ObjectManagementSystem.ts:164 |
Methods ​
register() ​
register(kind, factory): void;Defined in: systems/ObjectManagementSystem.ts:191
Parameters ​
| Parameter | Type |
|---|---|
kind | EcsEntityKind |
factory | EntityFactory |
Returns ​
void
registerComponentFactory() ​
registerComponentFactory(kind, factory): void;Defined in: systems/ObjectManagementSystem.ts:195
Parameters ​
| Parameter | Type |
|---|---|
kind | EcsComponentFactoryKind |
factory | ComponentFactory |
Returns ​
void
getOrCreateAudioListener() ​
getOrCreateAudioListener(): AudioListener;Defined in: systems/ObjectManagementSystem.ts:202
Returns ​
AudioListener
isEditorMode() ​
isEditorMode(): boolean;Defined in: systems/ObjectManagementSystem.ts:214
Returns ​
boolean
getComponentFactory() ​
getComponentFactory(kind): ComponentFactory | null;Defined in: systems/ObjectManagementSystem.ts:218
Parameters ​
| Parameter | Type |
|---|---|
kind | EcsComponentFactoryKind |
Returns ​
ComponentFactory | null
createComponentNow() ​
createComponentNow(
kind,
world,
entityId, ...
args): unknown;Defined in: systems/ObjectManagementSystem.ts:222
Parameters ​
| Parameter | Type |
|---|---|
kind | EcsComponentFactoryKind |
world | World |
entityId | number |
...args | any[] |
Returns ​
unknown
requestCreate() ​
requestCreate(
kind,
payload?,
onCreated?): void;Defined in: systems/ObjectManagementSystem.ts:236
Parameters ​
| Parameter | Type |
|---|---|
kind | EcsEntityKind |
payload | CreatePayload |
onCreated? | (entityId) => void |
Returns ​
void
createNow() ​
createNow(
kind,
world,
payload?): number;Defined in: systems/ObjectManagementSystem.ts:244
Parameters ​
| Parameter | Type |
|---|---|
kind | EcsEntityKind |
world | World |
payload | CreatePayload |
Returns ​
number
deleteEntity() ​
deleteEntity(
world,
entityId,
dispose?): boolean;Defined in: systems/ObjectManagementSystem.ts:298
Removes an entity from the ECS world and its associated Object3D from the THREE.js scene graph.
Parameters ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
world | World | undefined | The world the entity belongs to. |
entityId | number | undefined | The entity to remove. |
dispose | boolean | false | When true, traverses the entity's Object3D subtree and calls .dispose() on every BufferGeometry and Material found. Pass true when the entity will not be reused and you want to free GPU memory immediately (e.g. dynamically spawned objects). Shared model resources are skipped, and an editor placement's hold on its shared model is given back. Defaults to false. |
Returns ​
boolean
true if the entity existed and was removed; false if the entity was not found.
Example ​
// Remove from scene, keep GPU resources (safe if geometry is shared)
objects.deleteEntity(world, entityId);
// Remove from scene and free GPU memory (use for one-off spawned objects)
objects.deleteEntity(world, entityId, true);setParent() ​
setParent(
world,
entityId,
parentId,
options?): boolean;Defined in: systems/ObjectManagementSystem.ts:333
Parameters ​
| Parameter | Type | Description |
|---|---|---|
world | World | - |
entityId | number | - |
parentId | number | null | - |
options? | { preserveWorldTransform?: boolean; keepAttachments?: boolean; } | - |
options.preserveWorldTransform? | boolean | - |
options.keepAttachments? | boolean | Keep a bone or face attachment. Moving an entity normally ends one, since the bone or the head belonged to the old parent. Loading a scene isn't a move: the parent link is restored after the attachment and is the very parent the attachment was made on. |
Returns ​
boolean
reconcileSceneFromWorld() ​
reconcileSceneFromWorld(world): void;Defined in: systems/ObjectManagementSystem.ts:439
Parameters ​
| Parameter | Type |
|---|---|
world | World |
Returns ​
void
attachToFace() ​
attachToFace(
world,
entityId,
headEntityId,
point,
options?): boolean;Defined in: systems/ObjectManagementSystem.ts:550
Fixes an entity to a place on a head, parenting it to that head. Its Transform becomes its offset from the place, so by default it lands on the place; keepOffset leaves the Transform as it is.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
headEntityId | number |
point | FaceAttachPointId |
options? | { followExpression?: boolean | null; } |
options.followExpression? | boolean | null |
Returns ​
boolean
detachFromFace() ​
detachFromFace(world, entityId): void;Defined in: systems/ObjectManagementSystem.ts:576
Ends a face attachment. The entity stays a child of the head.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
Returns ​
void
hasBoneHold() ​
hasBoneHold(entityId): boolean;Defined in: systems/ObjectManagementSystem.ts:673
Whether applyBoneHold is managing this attachment.
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
boolean
applyBoneHold() ​
applyBoneHold(
world,
entityId,
hold,
hidden): void;Defined in: systems/ObjectManagementSystem.ts:682
Put an attachment in a hold for the clip now playing (hold null: the attachment's own bone and Transform), moving it to the hold's bone if that changed. Called each frame, since a socket can be rebuilt under it.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
hold | BoneHold | null |
hidden | boolean |
Returns ​
void
releaseBoneHold() ​
releaseBoneHold(world, entityId): void;Defined in: systems/ObjectManagementSystem.ts:719
Stop managing an attachment that no longer has holds, and put it back.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
Returns ​
void
reloadModel() ​
reloadModel(world, entityId): boolean;Defined in: systems/ObjectManagementSystem.ts:728
Load a model entity's file again and swap it in (the file was rewritten); the entity, its components and children stay, attachments re-home.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
Returns ​
boolean
reloadModelsAt() ​
reloadModelsAt(world, matches): number;Defined in: systems/ObjectManagementSystem.ts:733
Reload every model entity whose path matches (returns how many).
Parameters ​
| Parameter | Type |
|---|---|
world | World |
matches | (path) => boolean |
Returns ​
number
listModelBones() ​
listModelBones(world, entityId): ModelBoneInfo[];Defined in: systems/ObjectManagementSystem.ts:743
The bones of an entity's loaded model (empty until it loads, or for a model without a skeleton).
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
Returns ​
getBoneSocket() ​
getBoneSocket(entityId): Object3D<Object3DEventMap> | null;Defined in: systems/ObjectManagementSystem.ts:749
The socket object an attached entity currently hangs under, if resolved.
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
Object3D<Object3DEventMap> | null
attachToBone() ​
attachToBone(
world,
entityId,
parentEntityId,
ref,
options?): {
ok: boolean;
resolved: boolean;
bone: string | null;
};Defined in: systems/ObjectManagementSystem.ts:761
Fix entityId to a bone of parentEntityId's model (making it the parent if it isn't). With preserveWorldTransform (default) it stays where it is and its Transform becomes the offset from the bone; without, it snaps onto the bone (zero offset). Returns whether the bone was found (when the model is still loading, the attachment is stored and resolves once it loads, without preserving the pose).
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
parentEntityId | number |
ref | { bone?: string; humanoid?: string | null; } |
ref.bone? | string |
ref.humanoid? | string | null |
options? | { preserveWorldTransform?: boolean; compensateScale?: boolean; } |
options.preserveWorldTransform? | boolean |
options.compensateScale? | boolean |
Returns ​
{
ok: boolean;
resolved: boolean;
bone: string | null;
}| Name | Type | Defined in |
|---|---|---|
ok | boolean | systems/ObjectManagementSystem.ts:767 |
resolved | boolean | systems/ObjectManagementSystem.ts:767 |
bone | string | null | systems/ObjectManagementSystem.ts:767 |
detachFromBone() ​
detachFromBone(
world,
entityId,
options?): boolean;Defined in: systems/ObjectManagementSystem.ts:825
Release a bone attachment. The entity stays a child of the character (or moves to the root with toRoot), and by default keeps its place in the world.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
options? | { preserveWorldTransform?: boolean; toRoot?: boolean; } |
options.preserveWorldTransform? | boolean |
options.toRoot? | boolean |
Returns ​
boolean
update() ​
update(world): void;Defined in: systems/ObjectManagementSystem.ts:856
Parameters ​
| Parameter | Type |
|---|---|
world | World |
Returns ​
void

