Skip to main content

Class: InstancedEntity<TData, TVariant>

An entity drawn as one slot of a SkinnedInstancePool. It holds the slot for its lifetime, follows the server's position and facing with damping, writes its instance matrix and voxel light, and calls animate each frame for the family's bone pose.

A family subclasses it and implements animate, posing bones with setBone (each matrix rotates the bone's boxes about their pivot).

Example

class Walker extends InstancedEntity {
protected animate(time: number) {
const swing = Math.sin(time * 6) * 0.5 * this.movement;
this.setBone(BONE.LEG_L, this.boneMatrix.makeRotationX(swing));
this.setBone(BONE.LEG_R, this.boneMatrix.makeRotationX(-swing));
}
}
entities.setClass("walker", (id) => new Walker(id, walkerPool, { world }));

Type parameters​

NameType
TDataextends InstancedEntityData = InstancedEntityData
TVariantextends string = string

Hierarchy​

  • Entity<TData>

    ↳ InstancedEntity

Constructors​

constructor​

• new InstancedEntity<TData, TVariant>(id, pool, options?): InstancedEntity<TData, TVariant>

Type parameters​

NameType
TDataextends InstancedEntityData = InstancedEntityData
TVariantextends string = string

Parameters​

NameType
idstring
poolSkinnedInstancePool<TVariant, SkinnedRigInfo>
optionsInstancedEntityOptions

Returns​

InstancedEntity<TData, TVariant>

Overrides​

Entity.constructor

Properties​

entId​

• entId: string

Inherited from​

Entity.entId


entType​

• entType: string = ""

Inherited from​

Entity.entType


metadata​

• metadata: TData = null

Inherited from​

Entity.metadata


offscreenRadius​

• Optional offscreenRadius: number

Blocks around the entity that bound what it draws, for the off-screen test: around its group's position, or around the position the server last gave it when its class leaves the group at the origin and poses a child in world space. Unset, OFFSCREEN_DEFAULT_RADIUS.

Inherited from​

Entity.offscreenRadius


offscreenUpdateInterval​

• Optional offscreenUpdateInterval: number

This entity's own EntitiesOptions.offscreenUpdateInterval (1: every frame, wherever it is). Unset, it takes the option.

Inherited from​

Entity.offscreenUpdateInterval


targetPosition​

• Readonly targetPosition: Vector3

Where the server last put the entity; position damps toward it.

Methods​

markHit​

▸ markHit(): void

Flashes the instance red, fading over a third of a second.

Returns​

void


onCreate​

▸ onCreate(data): void

Parameters​

NameType
dataTData

Returns​

void

Overrides​

Entity.onCreate


onDelete​

▸ onDelete(): void

Returns​

void

Overrides​

Entity.onDelete


onUpdate​

▸ onUpdate(data): void

Parameters​

NameType
dataTData

Returns​

void

Overrides​

Entity.onUpdate


setHidden​

▸ setHidden(hidden): void

Parameters​

NameType
hiddenboolean

Returns​

void

Overrides​

Entity.setHidden


snapToTarget​

▸ snapToTarget(): void

Returns​

void

Overrides​

Entity.snapToTarget


update​

▸ update(): void

Returns​

void

Overrides​

Entity.update


updateFrozen​

▸ updateFrozen(): void

Returns​

void

Overrides​

Entity.updateFrozen


updateMatrixWorld​

▸ updateMatrixWorld(force?): void

The scene walk's matrix update, skipped while nothing under the entity draws: an instanced creature draws from its pool, and its group holds only a hidden nametag. Hundreds of them were half the walk's objects, rebuilt every frame for nothing. A child shown again is placed on the next walk; getWorldPosition and updateWorldMatrix compute as ever.

Parameters​

NameType
force?boolean

Returns​

void

Inherited from​

Entity.updateMatrixWorld