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 |
globalPosition: vec3 |
|
public get |
|
|
public get |
inverseTransform: mat4 |
|
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 |
transformLocal: mat4 |
Method Summary
Public Methods | ||
public |
activate() 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 |
dispose() Destructor (disposes internal resources). |
|
public |
findEntity(name: string): Entity | null Find entity by it's name or path in scene tree. |
|
public |
Get entity children at given index. |
|
public |
getComponent(typename: string | Function): Component | null 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 |
performActionOnComponents(name: string, args: *) Perform action only on components (do not pass action further to children). |
|
public |
performOnChildren(action: Function, deep: boolean) Perform custom callback action only on entity and optionally it's children. |
|
public |
performOnComponents(id: string | null, action: Function) Perform custom callback action on entity components of given type and it's children. |
|
public |
Rebind entity to different parent. |
|
public |
serialize(): * Serialize this entity into JSON data. |
|
public |
setPosition(x: number, y: number, z: number) Set entity local position. |
|
public |
setRotation(rad: number) Set entity local Z axis rotation. |
|
public |
setRotationEuler(x: number, y: number, z: number) 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 Members
public get componentNames: * source
public get globalPosition: vec3 source
public get inverseTransform: mat4 source
public get meta: * source
public get owner: EntitySystem | null source
public get position: vec3 source
public get rotation: quat source
public get scale: vec3 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.
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
name | string | Entity name or path. |
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:
Name | Type | Attribute | Description |
index | number | Child index. |
public getComponent(typename: string | Function): Component | null source
Find component by it's type name.
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.
Example:
console.log(entity.getRotation());
public getRotationEuler(result: vec3) source
Get entity local euler axis rotation in degrees.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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.
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.
Example:
entity.performOnComponents('Hello', component => console.log(component.hello));
public reparent(entity: Entity | null, insertAt: number) source
Rebind entity to different 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.
Example:
entity.setPosition(40, 2);
public setRotation(rad: number) source
Set entity local Z axis rotation.
Params:
Name | Type | Attribute | Description |
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.
Example:
entity.setRotationEuler(15, 30, 45);
public setScale(x: number, y: number, z: number) source
Set entity local scale.
Example:
entity.setScale(2, 3);