Home Reference Source
public class | source

Entity

Entity - actor of the scene, container for behaviour components.

Example:

const entity = new Entity();
entity.deserialize({ name: 'hey', components: { Hello: { hello: 'world' } } });
const hello = entity.getComponent('Hello');
console.log(hello.hello);

Constructor Summary

Public Constructor
public

Constructor.

Member Summary

Public Members
public get
public set
public get
public get
public set
public get
public get
public get
public get
public get

meta: *

public get
public set
public get
public get
public set
public get
public get

position: vec3

public get
public get

rotation: quat

public get

scale: vec3

public get
public set
public get

transform: mat4

public get

Method Summary

Public Methods
public

Make this entity and it's children active.

public

attachComponent(typename: string, component: Component)

Attach component to this entity.

public

Make this entity and it's children inactive.

public

deserialize(json: *)

Deserialize JSON data into this entity.

public

detachComponent(typename: string)

Detach component by it's type name.

public

Destructor (disposes internal resources).

public

Find entity by it's name or path in scene tree.

public

Get entity children at given index.

public

Find component by it's type name.

public

Get entity local Z axis radian rotation.

public

getRotationEuler(result: vec3)

Get entity local euler axis rotation in degrees.

public

Kills all entity children (calls dispose on them and removes them from entity).

public

performAction(name: string, args: *)

Perform action on entity.

public

Perform action only on components (do not pass action further to children).

public

Perform custom callback action only on entity and optionally it's children.

public

Perform custom callback action on entity components of given type and it's children.

public

reparent(entity: Entity | null, insertAt: number)

Rebind entity to different parent.

public

serialize(): *

Serialize this entity into JSON data.

public

Set entity local position.

public

Set entity local Z axis rotation.

public

Set entity local rotation from euler degrees.

public

Set entity local scale.

public

Sort children by entity childrenSorting function if set.

public

transformCoord(target: vec3, coord: vec3, entity: Entity)

Transform coordinate from this entity local space into other entity local space.

public

updateTransforms(parentTransform: mat4, forced: boolean)

Update entity ant it's children transforms.

Public Constructors

public constructor() source

Constructor.

Public Members

public get active: boolean source

public set active: boolean source

public get childrenCount: number source

public get childrenSorting: Function | null source

public set childrenSorting: Function | null source

public get componentNames: * source

public get globalPosition: vec3 source

public get indexInParent: number source

public get inverseTransform: mat4 source

public get meta: * source

public get name: string | null source

public set name: string | null source

public get owner: EntitySystem | null source

public get parent: Entity | null source

public set parent: Entity | null source

public get path: string source

public get position: vec3 source

public get root: Entity source

public get rotation: quat source

public get scale: vec3 source

public get tag: string | null source

public set tag: string | null source

public get transform: mat4 source

public get transformLocal: mat4 source

Public Methods

public activate() source

Make this entity and it's children active.

Example:

entity.activete();
entity.active === true;

public attachComponent(typename: string, component: Component) source

Attach component to this entity.

Params:

NameTypeAttributeDescription
typename string

Component type name.

component Component

Component instance.

Example:

entity.attachComponent('MyComponent', new MyComponent());
entity.attachComponent('Hello', new Hello());

public deactivate() source

Make this entity and it's children inactive.

Example:

entity.deactivete();
entity.active === false;

public deserialize(json: *) source

Deserialize JSON data into this entity.

Params:

NameTypeAttributeDescription
json *

Serialized entity JSON data.

Example:

entity.deserialize({ name: 'deserialized' });
entity.name === 'deserialized';

public detachComponent(typename: string) source

Detach component by it's type name.

Params:

NameTypeAttributeDescription
typename string

Component type name.

Example:

entity.detachComponent('Hello');

public dispose() source

Destructor (disposes internal resources).

Example:

entity.dispose();
entity = null;

public findEntity(name: string): Entity | null source

Find entity by it's name or path in scene tree.

Params:

NameTypeAttributeDescription
name string

Entity name or path.

Return:

Entity | null

Found entity instance or null if not found.

Example:

entity.findEntity('./some-child');
entity.findEntity('/root-child');
entity.findEntity('/root-child/some-child');

public getChild(index: number): Entity source

Get entity children at given index.

Params:

NameTypeAttributeDescription
index number

Child index.

Return:

Entity

Child entity instance.

public getComponent(typename: string | Function): Component | null source

Find component by it's type name.

Params:

NameTypeAttributeDescription
typename string | Function

Component type (class or name).

Return:

Component | null

Component instance if found or null otherwise.

Example:

class Hello extends Component {}
entity.attachComponent('Hello', new Hello());
const hello1 = entity.getComponent('Hello');
const hello2 = entity.getComponent(Hello);

public getRotation(): number source

Get entity local Z axis radian rotation.

Return:

number

Z axis local radian rotation.

Example:

console.log(entity.getRotation());

public getRotationEuler(result: vec3) source

Get entity local euler axis rotation in degrees.

Params:

NameTypeAttributeDescription
result vec3

Result vec3 object.

Example:

const euler = vec3.create();
entity.getRotationEuler(euler);
console.log(euler);

public killChildren() source

Kills all entity children (calls dispose on them and removes them from entity).

Example:

entity.killChildren();

public performAction(name: string, args: *) source

Perform action on entity.

Params:

NameTypeAttributeDescription
name string

Action name.

args *

Action parameters.

Example:

class Hi extends Component { onAction(name, wat) { if (name === 'hi') console.log(wat); } }
entity.attachComponent('Hi', new Hi());
entity.performAction('hi', 'hello');

public performActionOnComponents(name: string, args: *) source

Perform action only on components (do not pass action further to children). See: performAction

Params:

NameTypeAttributeDescription
name string

Action name.

args *

Action parameters.

public performOnChildren(action: Function, deep: boolean) source

Perform custom callback action only on entity and optionally it's children.

Params:

NameTypeAttributeDescription
action Function

Custom action callback. Callback gets one argument with child instance.

deep boolean

True if should be called on it's children.

Example:

entity.performOnChildren(e => console.log(e.name));

public performOnComponents(id: string | null, action: Function) source

Perform custom callback action on entity components of given type and it's children.

Params:

NameTypeAttributeDescription
id string | null

Affected component type (can be null if want to call every component).

action Function

Custom action callback. Callback gets one argument with component instance.

Example:

entity.performOnComponents('Hello', component => console.log(component.hello));

public reparent(entity: Entity | null, insertAt: number) source

Rebind entity to different parent.

Params:

NameTypeAttributeDescription
entity Entity | null

New parent entity or null if not bound to any entity.

insertAt number

Child index at given should be placed this entity in new parent

Example:

entity.reparent(system.root);

public serialize(): * source

Serialize this entity into JSON data.

Return:

*

Serialized JSON data.

Example:

entity.name = 'serialized';
const json = entity.serialize();
json.name === 'serialized';

public setPosition(x: number, y: number, z: number) source

Set entity local position.

Params:

NameTypeAttributeDescription
x number

Local X position.

y number

Local Y position.

z number

Local Z position.

Example:

entity.setPosition(40, 2);

public setRotation(rad: number) source

Set entity local Z axis rotation.

Params:

NameTypeAttributeDescription
rad number

Z axis radian angle.

Example:

entity.setRotation(90 * Math.PI / 180);

public setRotationEuler(x: number, y: number, z: number) source

Set entity local rotation from euler degrees.

Params:

NameTypeAttributeDescription
x number

X axis degree rotation.

y number

Y axis degree rotation.

z number

Z axis degree rotation.

Example:

entity.setRotationEuler(15, 30, 45);

public setScale(x: number, y: number, z: number) source

Set entity local scale.

Params:

NameTypeAttributeDescription
x number

Local X scale.

y number

Local Y scale.

z number

Local Z scale.

Example:

entity.setScale(2, 3);

public sortChildren() source

Sort children by entity childrenSorting function if set.

public transformCoord(target: vec3, coord: vec3, entity: Entity) source

Transform coordinate from this entity local space into other entity local space.

Params:

NameTypeAttributeDescription
target vec3

Result vec3 value.

coord vec3

Input vec3 value.

entity Entity

Other entity.

public updateTransforms(parentTransform: mat4, forced: boolean) source

Update entity ant it's children transforms.

Params:

NameTypeAttributeDescription
parentTransform mat4

Parent transformation.

forced boolean

If true ignore optimizations and update anyway.

Example:

entity.updateTransforms();