Skip to content

@relu-interactives/spatial-ecs


@relu-interactives/spatial-ecs / index / ObjectManagementSystem

Class: ObjectManagementSystem ​

Defined in: systems/ObjectManagementSystem.ts:163

Implements ​

Constructors ​

Constructor ​

ts
new ObjectManagementSystem(
   scene, 
   camera, 
   isEditor?): ObjectManagementSystem;

Defined in: systems/ObjectManagementSystem.ts:181

Parameters ​

ParameterTypeDefault value
sceneSceneundefined
cameraPerspectiveCameraundefined
isEditorbooleanfalse

Returns ​

ObjectManagementSystem

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
runsWhilePausedreadonlytruetrueKeep 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() ​

ts
register(kind, factory): void;

Defined in: systems/ObjectManagementSystem.ts:191

Parameters ​

ParameterType
kindEcsEntityKind
factoryEntityFactory

Returns ​

void


registerComponentFactory() ​

ts
registerComponentFactory(kind, factory): void;

Defined in: systems/ObjectManagementSystem.ts:195

Parameters ​

ParameterType
kindEcsComponentFactoryKind
factoryComponentFactory

Returns ​

void


getOrCreateAudioListener() ​

ts
getOrCreateAudioListener(): AudioListener;

Defined in: systems/ObjectManagementSystem.ts:202

Returns ​

AudioListener


isEditorMode() ​

ts
isEditorMode(): boolean;

Defined in: systems/ObjectManagementSystem.ts:214

Returns ​

boolean


getComponentFactory() ​

ts
getComponentFactory(kind): ComponentFactory | null;

Defined in: systems/ObjectManagementSystem.ts:218

Parameters ​

ParameterType
kindEcsComponentFactoryKind

Returns ​

ComponentFactory | null


createComponentNow() ​

ts
createComponentNow(
   kind, 
   world, 
   entityId, ...
   args): unknown;

Defined in: systems/ObjectManagementSystem.ts:222

Parameters ​

ParameterType
kindEcsComponentFactoryKind
worldWorld
entityIdnumber
...argsany[]

Returns ​

unknown


requestCreate() ​

ts
requestCreate(
   kind, 
   payload?, 
   onCreated?): void;

Defined in: systems/ObjectManagementSystem.ts:236

Parameters ​

ParameterType
kindEcsEntityKind
payloadCreatePayload
onCreated?(entityId) => void

Returns ​

void


createNow() ​

ts
createNow(
   kind, 
   world, 
   payload?): number;

Defined in: systems/ObjectManagementSystem.ts:244

Parameters ​

ParameterType
kindEcsEntityKind
worldWorld
payloadCreatePayload

Returns ​

number


deleteEntity() ​

ts
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 ​

ParameterTypeDefault valueDescription
worldWorldundefinedThe world the entity belongs to.
entityIdnumberundefinedThe entity to remove.
disposebooleanfalseWhen 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 ​

ts
// 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() ​

ts
setParent(
   world, 
   entityId, 
   parentId, 
   options?): boolean;

Defined in: systems/ObjectManagementSystem.ts:333

Parameters ​

ParameterTypeDescription
worldWorld-
entityIdnumber-
parentIdnumber | null-
options?{ preserveWorldTransform?: boolean; keepAttachments?: boolean; }-
options.preserveWorldTransform?boolean-
options.keepAttachments?booleanKeep 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() ​

ts
reconcileSceneFromWorld(world): void;

Defined in: systems/ObjectManagementSystem.ts:439

Parameters ​

ParameterType
worldWorld

Returns ​

void


attachToFace() ​

ts
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 ​

ParameterType
worldWorld
entityIdnumber
headEntityIdnumber
pointFaceAttachPointId
options?{ followExpression?: boolean | null; }
options.followExpression?boolean | null

Returns ​

boolean


detachFromFace() ​

ts
detachFromFace(world, entityId): void;

Defined in: systems/ObjectManagementSystem.ts:576

Ends a face attachment. The entity stays a child of the head.

Parameters ​

ParameterType
worldWorld
entityIdnumber

Returns ​

void


hasBoneHold() ​

ts
hasBoneHold(entityId): boolean;

Defined in: systems/ObjectManagementSystem.ts:673

Whether applyBoneHold is managing this attachment.

Parameters ​

ParameterType
entityIdnumber

Returns ​

boolean


applyBoneHold() ​

ts
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 ​

ParameterType
worldWorld
entityIdnumber
holdBoneHold | null
hiddenboolean

Returns ​

void


releaseBoneHold() ​

ts
releaseBoneHold(world, entityId): void;

Defined in: systems/ObjectManagementSystem.ts:719

Stop managing an attachment that no longer has holds, and put it back.

Parameters ​

ParameterType
worldWorld
entityIdnumber

Returns ​

void


reloadModel() ​

ts
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 ​

ParameterType
worldWorld
entityIdnumber

Returns ​

boolean


reloadModelsAt() ​

ts
reloadModelsAt(world, matches): number;

Defined in: systems/ObjectManagementSystem.ts:733

Reload every model entity whose path matches (returns how many).

Parameters ​

ParameterType
worldWorld
matches(path) => boolean

Returns ​

number


listModelBones() ​

ts
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 ​

ParameterType
worldWorld
entityIdnumber

Returns ​

ModelBoneInfo[]


getBoneSocket() ​

ts
getBoneSocket(entityId): Object3D<Object3DEventMap> | null;

Defined in: systems/ObjectManagementSystem.ts:749

The socket object an attached entity currently hangs under, if resolved.

Parameters ​

ParameterType
entityIdnumber

Returns ​

Object3D<Object3DEventMap> | null


attachToBone() ​

ts
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 ​

ParameterType
worldWorld
entityIdnumber
parentEntityIdnumber
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 ​

ts
{
  ok: boolean;
  resolved: boolean;
  bone: string | null;
}
NameTypeDefined in
okbooleansystems/ObjectManagementSystem.ts:767
resolvedbooleansystems/ObjectManagementSystem.ts:767
bonestring | nullsystems/ObjectManagementSystem.ts:767

detachFromBone() ​

ts
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 ​

ParameterType
worldWorld
entityIdnumber
options?{ preserveWorldTransform?: boolean; toRoot?: boolean; }
options.preserveWorldTransform?boolean
options.toRoot?boolean

Returns ​

boolean


update() ​

ts
update(world): void;

Defined in: systems/ObjectManagementSystem.ts:856

Parameters ​

ParameterType
worldWorld

Returns ​

void

Implementation of ​

EcsSystem.update