Mirror Engine
V5
How To
Mirror Engine Logo

Mirror Engine API


Mirror Engine API / Entity

Class: Entity

The Entity is the core primitive of a Mirror Engine game. Generally speaking an object in your game will consist of an Entity, and a set of Components which are managed by their respective ComponentSystems. One of those components maybe a ScriptComponent which allows you to write custom code to attach to your Entity.

The Entity uniquely identifies the object and also provides a transform for position and orientation which it inherits from GraphNode so can be added into the scene graph. The Component and ComponentSystem provide the logic to give an Entity a specific type of behavior. e.g. the ability to render a model or play a sound. Components are specific to an instance of an Entity and are attached (e.g. this.entity.render) ComponentSystems allow access to all Entities and Components and are attached to the AppBase.

Extends

Constructors

new Entity()

new Entity(name?: string, app?: AppBase): Entity

Create a new Entity.

Parameters

name?

string

The non-unique name of the entity, default is "Untitled".

app?

AppBase = ...

The application the entity belongs to, default is the current application.

Returns

Entity

Example

const entity = new Entity()

// Add a Component to the Entity
entity.addComponent('camera', {
  fov: 45,
  nearClip: 1,
  farClip: 10000
})

// Add the Entity into the scene graph
app.root.addChild(entity)

// Move the entity
entity.translate(10, 0, 0)

// Or translate it by setting its position directly
const p = entity.getPosition()
entity.setPosition(p.x + 10, p.y, p.z)

// Change the entity's rotation in local space
const e = entity.getLocalEulerAngles()
entity.setLocalEulerAngles(e.x, e.y + 90, e.z)

// Or use rotateLocal
entity.rotateLocal(0, 90, 0)

Overrides

GraphNode.constructor

Properties

anim

readonly anim: undefined | AnimComponent;

Gets the AnimComponent attached to this entity.


animation

readonly animation: undefined | AnimationComponent;

Gets the AnimationComponent attached to this entity.


audiolistener

readonly audiolistener: undefined | AudioListenerComponent;

Gets the AudioListenerComponent attached to this entity.


button

readonly button: undefined | ButtonComponent;

Gets the ButtonComponent attached to this entity.


camera

readonly camera: undefined | CameraComponent;

Gets the CameraComponent attached to this entity.


collision

readonly collision: undefined | CollisionComponent;

Gets the CollisionComponent attached to this entity.


controlledByUserId

controlledByUserId: undefined | string = undefined;

Description

If a user is controlling this entity, controlledByUserId will be that userId. It is ONLY set for a single entity, not its children.


element

readonly element: undefined | ElementComponent;

Gets the ElementComponent attached to this entity.


gsplat

readonly gsplat: undefined | GSplatComponent;

Gets the GSplatComponent attached to this entity.


layoutchild

readonly layoutchild: undefined | LayoutChildComponent;

Gets the LayoutChildComponent attached to this entity.


layoutgroup

readonly layoutgroup: undefined | LayoutGroupComponent;

Gets the LayoutGroupComponent attached to this entity.


light

readonly light: undefined | LightComponent;

Gets the LightComponent attached to this entity.


model

readonly model: undefined | ModelComponent;

Gets the ModelComponent attached to this entity.


name

name: string

The non-unique name of a graph node. Defaults to 'Untitled'.

Inherited from

GraphNode.name


particlesystem

readonly particlesystem: undefined | ParticleSystemComponent;

Gets the ParticleSystemComponent attached to this entity.


render

readonly render: undefined | RenderComponent;

Gets the RenderComponent attached to this entity.


rigidbody

readonly rigidbody: undefined | RigidBodyComponent;

Gets the RigidBodyComponent attached to this entity.


screen

readonly screen: undefined | ScreenComponent;

Gets the ScreenComponent attached to this entity.


script

readonly script: undefined | ScriptComponent;

Gets the ScriptComponent attached to this entity.


scrollbar

readonly scrollbar: undefined | ScrollbarComponent;

Gets the ScrollbarComponent attached to this entity.


scrollview

readonly scrollview: undefined | ScrollViewComponent;

Gets the ScrollViewComponent attached to this entity.


sound

readonly sound: undefined | SoundComponent;

Gets the SoundComponent attached to this entity.


sprite

readonly sprite: undefined | SpriteComponent;

Gets the SpriteComponent attached to this entity.


tags

tags: Tags

Interface for tagging graph nodes. Tag based searches can be performed using the GraphNode#findByTag function.

Inherited from

GraphNode.tags

children

Get Signature

get children(): GraphNode[]

Gets the children of this graph node.

Returns

GraphNode[]

Inherited from

GraphNode.children


enabled

Get Signature

get enabled(): boolean

Gets the enabled state of the GraphNode.

Returns

boolean

Set Signature

set enabled(enabled: boolean): void

Sets the enabled state of the GraphNode. If one of the GraphNode's parents is disabled there will be no other side effects. If all the parents are enabled then the new value will activate or deactivate all the enabled children of the GraphNode.

Parameters
enabled

boolean

Returns

void

Inherited from

GraphNode.enabled


forward

Get Signature

get forward(): Vec3

Gets the normalized local space negative Z-axis vector of the graph node in world space.

Returns

Vec3

Inherited from

GraphNode.forward


graphDepth

Get Signature

get graphDepth(): number

Gets the depth of this child within the graph. Note that for performance reasons this is only recalculated when a node is added to a new parent. In other words, it is not recalculated when a node is simply removed from the graph.

Returns

number

Inherited from

GraphNode.graphDepth


parent

Get Signature

get parent(): null | GraphNode

Gets the parent of this graph node.

Returns

null | GraphNode

Inherited from

GraphNode.parent


path

Get Signature

get path(): string

Gets the path of this graph node relative to the root of the hierarchy.

Returns

string

Inherited from

GraphNode.path


Get Signature

get right(): Vec3

Gets the normalized local space X-axis vector of the graph node in world space.

Returns

Vec3

Inherited from

GraphNode.right


root

Get Signature

get root(): GraphNode

Gets the oldest ancestor graph node from this graph node.

Returns

GraphNode

Inherited from

GraphNode.root


up

Get Signature

get up(): Vec3

Gets the normalized local space Y-axis vector of the graph node in world space.

Returns

Vec3

Inherited from

GraphNode.up

Methods

addChild()

addChild(node: GraphNode): void

Add a new child to the child list and update the parent value of the child node. If the node already had a parent, it is removed from its child list.

Parameters

node

GraphNode

The new child to add.

Returns

void

Example

const e = new Entity(app)
this.entity.addChild(e)

Inherited from

GraphNode.addChild


addComponent()

addComponent(type: string, data?: any): null | Component

Create a new component and add it to the entity. Use this to add functionality to the entity like rendering a model, playing sounds and so on.

Parameters

type

string

The name of the component to add. Valid strings are:

data?

any

The initialization data for the specific component type. Refer to each specific component's API reference page for details on valid values for this parameter.

Returns

null | Component

The new Component that was attached to the entity or null if there was an error.

Example

const entity = new Entity()

// Add a light component with default properties
entity.addComponent('light')

// Add a camera component with some specified properties
entity.addComponent('camera', {
  fov: 45,
  clearColor: Color(1, 0, 0)
})

clone()

clone(): Entity

Create a deep copy of the Entity. Duplicate the full Entity hierarchy, with all Components and all descendants. Note, this Entity is not in the hierarchy and must be added manually.

Returns

Entity

A new Entity which is a deep copy of the original.

Example

const e = this.entity.clone()

// Add clone as a sibling to the original
this.entity.parent.addChild(e)

Overrides

GraphNode.clone


destroy()

destroy(): void

Destroy the entity and all of its descendants. First, all of the entity's components are disabled and then removed. Then, the entity is removed from the hierarchy. This is then repeated recursively for all descendants of the entity.

The last thing the entity does is fire the destroy event.

Returns

void

Example

const firstChild = this.entity.children[0]
firstChild.destroy() // destroy child and all of its descendants

Overrides

GraphNode.destroy


find()

find(attr: string | FindNodeCallback, value?: any): GraphNode[]

Search the graph node and all of its descendants for the nodes that satisfy some search criteria.

Parameters

attr

This can either be a function or a string. If it's a function, it is executed for each descendant node to test if node satisfies the search logic. Returning true from the function will include the node into the results. If it's a string then it represents the name of a field or a method of the node. If this is the name of a field then the value passed as the second argument will be checked for equality. If this is the name of a function then the return value of the function will be checked for equality against the valued passed as the second argument to this function.

string | FindNodeCallback

value?

any

If the first argument (attr) is a property name then this value will be checked against the value of the property.

Returns

GraphNode[]

The array of graph nodes that match the search criteria.

Examples

// Finds all nodes that have a model component and have 'door' in their lower-cased name
const doors = house.find(function (node) {
  return node.model && node.name.toLowerCase().indexOf('door') !== -1
})
// Finds all nodes that have the name property set to 'Test'
const entities = parent.find('name', 'Test')

Inherited from

GraphNode.find


findByGuid()

findByGuid(guid: string): null | Entity

Find a descendant of this entity with the GUID.

Parameters

guid

string

The GUID to search for.

Returns

null | Entity

The entity with the matching GUID or null if no entity is found.


findByName()

findByName(name: string): null | GraphNode

Get the first node found in the graph with the name. The search is depth first.

Parameters

name

string

The name of the graph.

Returns

null | GraphNode

The first node to be found matching the supplied name. Returns null if no node is found.

Inherited from

GraphNode.findByName


findByPath()

findByPath(path: string | string[]): null | GraphNode

Get the first node found in the graph by its full path in the graph. The full path has this form 'parent/child/sub-child'. The search is depth first.

Parameters

path

The full path of the GraphNode as either a string or array of GraphNode names.

string | string[]

Returns

null | GraphNode

The first node to be found matching the supplied path. Returns null if no node is found.

Examples

// String form
const grandchild = this.entity.findByPath('child/grandchild')
// Array form
const grandchild = this.entity.findByPath([
  'child',
  'grandchild'
])

Inherited from

GraphNode.findByPath


findByTag()

findByTag(...args: any): GraphNode[]

Return all graph nodes that satisfy the search query. Query can be simply a string, or comma separated strings, to have inclusive results of assets that match at least one query. A query that consists of an array of tags can be used to match graph nodes that have each tag of array.

Parameters

args

...any

Returns

GraphNode[]

A list of all graph nodes that match the query.

Examples

// Return all graph nodes that tagged by `animal`
const animals = node.findByTag('animal')
// Return all graph nodes that tagged by `bird` OR `mammal`
const birdsAndMammals = node.findByTag('bird', 'mammal')
// Return all assets that tagged by `carnivore` AND `mammal`
const meatEatingMammals = node.findByTag([
  'carnivore',
  'mammal'
])
// Return all assets that tagged by (`carnivore` AND `mammal`) OR (`carnivore` AND `reptile`)
const meatEatingMammalsAndReptiles = node.findByTag(
  [
    'carnivore',
    'mammal'
  ],
  [
    'carnivore',
    'reptile'
  ]
)

Inherited from

GraphNode.findByTag


findComponent()

findComponent(type: string): Component

Search the entity and all of its descendants for the first component of specified type.

Parameters

type

string

The name of the component type to retrieve.

Returns

Component

A component of specified type, if the entity or any of its descendants has one. Returns undefined otherwise.

Example

// Get the first found light component in the hierarchy tree that starts with this entity
const light = entity.findComponent('light')

findComponents()

findComponents(type: string): Component[]

Search the entity and all of its descendants for all components of specified type.

Parameters

type

string

The name of the component type to retrieve.

Returns

Component[]

All components of specified type in the entity or any of its descendants. Returns empty array if none found.

Example

// Get all light components in the hierarchy tree that starts with this entity
const lights = entity.findComponents('light')

findOne()

findOne(attr: string | FindNodeCallback, value?: any): null | GraphNode

Search the graph node and all of its descendants for the first node that satisfies some search criteria.

Parameters

attr

This can either be a function or a string. If it's a function, it is executed for each descendant node to test if node satisfies the search logic. Returning true from the function will result in that node being returned from findOne. If it's a string then it represents the name of a field or a method of the node. If this is the name of a field then the value passed as the second argument will be checked for equality. If this is the name of a function then the return value of the function will be checked for equality against the valued passed as the second argument to this function.

string | FindNodeCallback

value?

any

If the first argument (attr) is a property name then this value will be checked against the value of the property.

Returns

null | GraphNode

A graph node that match the search criteria. Returns null if no node is found.

Examples

// Find the first node that is called 'head' and has a model component
const head = player.findOne(function (node) {
  return node.model && node.name === 'head'
})
// Finds the first node that has the name property set to 'Test'
const node = parent.findOne('name', 'Test')

Inherited from

GraphNode.findOne


findScript()

findScript(nameOrType: string | typeof ScriptType): undefined | ScriptType

Search the entity and all of its descendants for the first script instance of specified type.

Parameters

nameOrType

The name or type of ScriptType.

string | typeof ScriptType

Returns

undefined | ScriptType

A script instance of specified type, if the entity or any of its descendants has one. Returns undefined otherwise.

Example

// Get the first found "playerController" instance in the hierarchy tree that starts with this entity
const controller = entity.findScript('playerController')

findScripts()

findScripts(nameOrType: string | typeof ScriptType): ScriptType[]

Search the entity and all of its descendants for all script instances of specified type.

Parameters

nameOrType

The name or type of ScriptType.

string | typeof ScriptType

Returns

ScriptType[]

All script instances of specified type in the entity or any of its descendants. Returns empty array if none found.

Example

// Get all "playerController" instances in the hierarchy tree that starts with this entity
const controllers = entity.findScripts('playerController')

fire()

fire(
   name: string,
   arg1?: any,
   arg2?: any,
   arg3?: any,
   arg4?: any,
   arg5?: any,
   arg6?: any,
   arg7?: any,
   arg8?: any): EventHandler

Fire an event, all additional arguments are passed on to the event listener.

Parameters

name

string

Name of event to fire.

arg1?

any

First argument that is passed to the event handler.

arg2?

any

Second argument that is passed to the event handler.

arg3?

any

Third argument that is passed to the event handler.

arg4?

any

Fourth argument that is passed to the event handler.

arg5?

any

Fifth argument that is passed to the event handler.

arg6?

any

Sixth argument that is passed to the event handler.

arg7?

any

Seventh argument that is passed to the event handler.

arg8?

any

Eighth argument that is passed to the event handler.

Returns

EventHandler

Self for chaining.

Example

obj.fire('test', 'This is the message')

Inherited from

GraphNode.fire


forEach()

forEach(callback: ForEachNodeCallback, thisArg?: any): void

Executes a provided function once on this graph node and all of its descendants.

Parameters

callback

ForEachNodeCallback

The function to execute on the graph node and each descendant.

thisArg?

any

Optional value to use as this when executing callback function.

Returns

void

Example

// Log the path and name of each node in descendant tree starting with "parent"
parent.forEach(function (node) {
  console.log(node.path + '/' + node.name)
})

Inherited from

GraphNode.forEach


getEulerAngles()

getEulerAngles(): Vec3

Get the world space rotation for the specified GraphNode in Euler angle form. The rotation is returned as euler angles in a Vec3. The value returned by this function should be considered read-only. In order to set the world space rotation of the graph node, use GraphNode#setEulerAngles.

Returns

Vec3

The world space rotation of the graph node in Euler angle form.

Example

const angles = this.entity.getEulerAngles()
angles.y = 180 // rotate the entity around Y by 180 degrees
this.entity.setEulerAngles(angles)

Inherited from

GraphNode.getEulerAngles


getLocalEulerAngles()

getLocalEulerAngles(): Vec3

Get the rotation in local space for the specified GraphNode. The rotation is returned as euler angles in a Vec3. The returned vector should be considered read-only. To update the local rotation, use GraphNode#setLocalEulerAngles.

Returns

Vec3

The local space rotation of the graph node as euler angles in XYZ order.

Example

const angles = this.entity.getLocalEulerAngles()
angles.y = 180
this.entity.setLocalEulerAngles(angles)

Inherited from

GraphNode.getLocalEulerAngles


getLocalPosition()

getLocalPosition(): Vec3

Get the position in local space for the specified GraphNode. The position is returned as a Vec3. The returned vector should be considered read-only. To update the local position, use GraphNode#setLocalPosition.

Returns

Vec3

The local space position of the graph node.

Example

const position = this.entity.getLocalPosition()
position.x += 1 // move the entity 1 unit along x.
this.entity.setLocalPosition(position)

Inherited from

GraphNode.getLocalPosition


getLocalRotation()

getLocalRotation(): Quat

Get the rotation in local space for the specified GraphNode. The rotation is returned as a Quat. The returned quaternion should be considered read-only. To update the local rotation, use GraphNode#setLocalRotation.

Returns

Quat

The local space rotation of the graph node as a quaternion.

Example

const rotation = this.entity.getLocalRotation()

Inherited from

GraphNode.getLocalRotation


getLocalScale()

getLocalScale(): Vec3

Get the scale in local space for the specified GraphNode. The scale is returned as a Vec3. The returned vector should be considered read-only. To update the local scale, use GraphNode#setLocalScale.

Returns

Vec3

The local space scale of the graph node.

Example

const scale = this.entity.getLocalScale()
scale.x = 100
this.entity.setLocalScale(scale)

Inherited from

GraphNode.getLocalScale


getLocalTransform()

getLocalTransform(): Mat4

Get the local transform matrix for this graph node. This matrix is the transform relative to the node's parent's world transformation matrix.

Returns

Mat4

The node's local transformation matrix.

Example

const transform = this.entity.getLocalTransform()

Inherited from

GraphNode.getLocalTransform


getPosition()

getPosition(): Vec3

Get the world space position for the specified GraphNode. The position is returned as a Vec3. The value returned by this function should be considered read-only. In order to set the world space position of the graph node, use GraphNode#setPosition.

Returns

Vec3

The world space position of the graph node.

Example

const position = this.entity.getPosition()
position.x = 10
this.entity.setPosition(position)

Inherited from

GraphNode.getPosition


getRotation()

getRotation(): Quat

Get the world space rotation for the specified GraphNode. The rotation is returned as a Quat. The value returned by this function should be considered read-only. In order to set the world space rotation of the graph node, use GraphNode#setRotation.

Returns

Quat

The world space rotation of the graph node as a quaternion.

Example

const rotation = this.entity.getRotation()

Inherited from

GraphNode.getRotation


getWorldTransform()

getWorldTransform(): Mat4

Get the world transformation matrix for this graph node.

Returns

Mat4

The node's world transformation matrix.

Example

const transform = this.entity.getWorldTransform()

Inherited from

GraphNode.getWorldTransform


hasEvent()

hasEvent(name: string): boolean

Test if there are any handlers bound to an event name.

Parameters

name

string

The name of the event to test.

Returns

boolean

True if the object has handlers bound to the specified event name.

Example

obj.on('test', () => {}) // bind an event to 'test'
obj.hasEvent('test') // returns true
obj.hasEvent('hello') // returns false

Inherited from

GraphNode.hasEvent


insertChild()

insertChild(node: GraphNode, index: number): void

Insert a new child to the child list at the specified index and update the parent value of the child node. If the node already had a parent, it is removed from its child list.

Parameters

node

GraphNode

The new child to insert.

index

number

The index in the child list of the parent where the new node will be inserted.

Returns

void

Example

const e = new Entity(app)
this.entity.insertChild(e, 1)

Inherited from

GraphNode.insertChild


isAncestorOf()

isAncestorOf(node: GraphNode): boolean

Check if node is ancestor for another node.

Parameters

node

GraphNode

Potential descendant of node.

Returns

boolean

If node is ancestor for another node.

Example

if (body.isAncestorOf(foot)) {
  // foot is within body's hierarchy
}

Inherited from

GraphNode.isAncestorOf


isDescendantOf()

isDescendantOf(node: GraphNode): boolean

Check if node is descendant of another node.

Parameters

node

GraphNode

Potential ancestor of node.

Returns

boolean

If node is descendant of another node.

Example

if (roof.isDescendantOf(house)) {
  // roof is descendant of house entity
}

Inherited from

GraphNode.isDescendantOf


lookAt()

lookAt(
   x: number | Vec3,
   y?: number | Vec3,
   z?: number,
   ux?: number,
   uy?: number,
   uz?: number): void

Reorients the graph node so that the negative z-axis points towards the target. This function has two valid signatures. Either pass 3D vectors for the look at coordinate and up vector, or pass numbers to represent the vectors.

Parameters

x

If passing a 3D vector, this is the world space coordinate to look at. Otherwise, it is the x-component of the world space coordinate to look at.

number | Vec3

y?

If passing a 3D vector, this is the world space up vector for look at transform. Otherwise, it is the y-component of the world space coordinate to look at.

number | Vec3

z?

number

Z-component of the world space coordinate to look at.

ux?

number = 0

X-component of the up vector for the look at transform. Defaults to 0.

uy?

number = 1

Y-component of the up vector for the look at transform. Defaults to 1.

uz?

number = 0

Z-component of the up vector for the look at transform. Defaults to 0.

Returns

void

Examples

// Look at another entity, using the (default) positive y-axis for up
const position = otherEntity.getPosition()
this.entity.lookAt(position)
// Look at another entity, using the negative world y-axis for up
const position = otherEntity.getPosition()
this.entity.lookAt(position, Vec3.DOWN)
// Look at the world space origin, using the (default) positive y-axis for up
this.entity.lookAt(0, 0, 0)
// Look at world space coordinate [10, 10, 10], using the negative world y-axis for up
this.entity.lookAt(10, 10, 10, 0, -1, 0)

Inherited from

GraphNode.lookAt


off()

off(
   name?: string,
   callback?: HandleEventCallback,
   scope?: any): EventHandler

Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

Parameters

name?

string

Name of the event to unbind.

callback?

HandleEventCallback

Function to be unbound.

scope?

any

Scope that was used as the this when the event is fired.

Returns

EventHandler

Self for chaining.

Example

const handler = () => {}
obj.on('test', handler)

obj.off() // Removes all events
obj.off('test') // Removes all events called 'test'
obj.off('test', handler) // Removes all handler functions, called 'test'
obj.off('test', handler, this) // Removes all handler functions, called 'test' with scope this

Inherited from

GraphNode.off


on()

on(
   name: string,
   callback: HandleEventCallback,
   scope?: any): EventHandle

Attach an event handler to an event.

Parameters

name

string

Name of the event to bind the callback to.

callback

HandleEventCallback

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scope?

any = ...

Object to use as 'this' when the event is fired, defaults to current this.

Returns

EventHandle

Can be used for removing event in the future.

Examples

obj.on('test', (a, b) => {
  console.log(a + b)
})
obj.fire('test', 1, 2) // prints 3 to the console
const evt = obj.on('test', (a, b) => {
  console.log(a + b)
})
// some time later
evt.off()

Inherited from

GraphNode.on


once()

once(
   name: string,
   callback: HandleEventCallback,
   scope?: any): EventHandle

Attach an event handler to an event. This handler will be removed after being fired once.

Parameters

name

string

Name of the event to bind the callback to.

callback

HandleEventCallback

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scope?

any = ...

Object to use as 'this' when the event is fired, defaults to current this.

Returns

EventHandle

  • can be used for removing event in the future.

Example

obj.once('test', (a, b) => {
  console.log(a + b)
})
obj.fire('test', 1, 2) // prints 3 to the console
obj.fire('test', 1, 2) // not going to get handled

Inherited from

GraphNode.once


remove()

remove(): void

Remove graph node from current parent.

Returns

void

Inherited from

GraphNode.remove


removeChild()

removeChild(child: GraphNode): void

Remove the node from the child list and update the parent value of the child.

Parameters

child

GraphNode

The node to remove.

Returns

void

Example

const child = this.entity.children[0]
this.entity.removeChild(child)

Inherited from

GraphNode.removeChild


removeComponent()

removeComponent(type: string): void

Remove a component from the Entity.

Parameters

type

string

The name of the Component type.

Returns

void

Example

const entity = new Entity()
entity.addComponent('light') // add new light component

entity.removeComponent('light') // remove light component

reparent()

reparent(parent: GraphNode, index?: number): void

Remove graph node from current parent and add as child to new parent.

Parameters

parent

GraphNode

New parent to attach graph node to.

index?

number

The child index where the child node should be placed.

Returns

void

Inherited from

GraphNode.reparent


rotate()

rotate(
   x: number | Vec3,
   y?: number,
   z?: number): void

Rotates the graph node in world space by the specified Euler angles. Eulers are specified in degrees in XYZ order. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the world space rotation.

Parameters

x

3-dimensional vector holding world space rotation or rotation around world space x-axis in degrees.

number | Vec3

y?

number

Rotation around world space y-axis in degrees.

z?

number

Rotation around world space z-axis in degrees.

Returns

void

Examples

// Rotate via 3 numbers
this.entity.rotate(0, 90, 0)
// Rotate via vector
const r = new Vec3(0, 90, 0)
this.entity.rotate(r)

Inherited from

GraphNode.rotate


rotateLocal()

rotateLocal(
   x: number | Vec3,
   y?: number,
   z?: number): void

Rotates the graph node in local space by the specified Euler angles. Eulers are specified in degrees in XYZ order. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space rotation.

Parameters

x

3-dimensional vector holding local space rotation or rotation around local space x-axis in degrees.

number | Vec3

y?

number

Rotation around local space y-axis in degrees.

z?

number

Rotation around local space z-axis in degrees.

Returns

void

Examples

// Rotate via 3 numbers
this.entity.rotateLocal(0, 90, 0)
// Rotate via vector
const r = new Vec3(0, 90, 0)
this.entity.rotateLocal(r)

Inherited from

GraphNode.rotateLocal


setEulerAngles()

setEulerAngles(
   x: number | Vec3,
   y?: number,
   z?: number): void

Sets the world space rotation of the specified graph node using euler angles. Eulers are interpreted in XYZ order. Eulers must be specified in degrees. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the world space euler rotation.

Parameters

x

3-dimensional vector holding eulers or rotation around world space x-axis in degrees.

number | Vec3

y?

number

Rotation around world space y-axis in degrees.

z?

number

Rotation around world space z-axis in degrees.

Returns

void

Examples

// Set rotation of 90 degrees around world space y-axis via 3 numbers
this.entity.setEulerAngles(0, 90, 0)
// Set rotation of 90 degrees around world space y-axis via a vector
const angles = new Vec3(0, 90, 0)
this.entity.setEulerAngles(angles)

Inherited from

GraphNode.setEulerAngles


setLocalEulerAngles()

setLocalEulerAngles(
   x: number | Vec3,
   y?: number,
   z?: number): void

Sets the local space rotation of the specified graph node using euler angles. Eulers are interpreted in XYZ order. Eulers must be specified in degrees. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space euler rotation.

Parameters

x

3-dimensional vector holding eulers or rotation around local space x-axis in degrees.

number | Vec3

y?

number

Rotation around local space y-axis in degrees.

z?

number

Rotation around local space z-axis in degrees.

Returns

void

Examples

// Set rotation of 90 degrees around y-axis via 3 numbers
this.entity.setLocalEulerAngles(0, 90, 0)
// Set rotation of 90 degrees around y-axis via a vector
const angles = new Vec3(0, 90, 0)
this.entity.setLocalEulerAngles(angles)

Inherited from

GraphNode.setLocalEulerAngles


setLocalPosition()

setLocalPosition(
   x: number | Vec3,
   y?: number,
   z?: number): void

Sets the local space position of the specified graph node. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space position.

Parameters

x

3-dimensional vector holding local space position or x-coordinate of local space position.

number | Vec3

y?

number

Y-coordinate of local space position.

z?

number

Z-coordinate of local space position.

Returns

void

Examples

// Set via 3 numbers
this.entity.setLocalPosition(0, 10, 0)
// Set via vector
const pos = new Vec3(0, 10, 0)
this.entity.setLocalPosition(pos)

Inherited from

GraphNode.setLocalPosition


setLocalRotation()

setLocalRotation(
   x: number | Quat,
   y?: number,
   z?: number,
   w?: number): void

Sets the local space rotation of the specified graph node. This function has two valid signatures: you can either pass a quaternion or 3 numbers to specify the local space rotation.

Parameters

x

Quaternion holding local space rotation or x-component of local space quaternion rotation.

number | Quat

y?

number

Y-component of local space quaternion rotation.

z?

number

Z-component of local space quaternion rotation.

w?

number

W-component of local space quaternion rotation.

Returns

void

Examples

// Set via 4 numbers
this.entity.setLocalRotation(0, 0, 0, 1)
// Set via quaternion
const q = Quat()
this.entity.setLocalRotation(q)

Inherited from

GraphNode.setLocalRotation


setLocalScale()

setLocalScale(
   x: number | Vec3,
   y?: number,
   z?: number): void

Sets the local space scale factor of the specified graph node. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space scale.

Parameters

x

3-dimensional vector holding local space scale or x-coordinate of local space scale.

number | Vec3

y?

number

Y-coordinate of local space scale.

z?

number

Z-coordinate of local space scale.

Returns

void

Examples

// Set via 3 numbers
this.entity.setLocalScale(10, 10, 10)
// Set via vector
const scale = new Vec3(10, 10, 10)
this.entity.setLocalScale(scale)

Inherited from

GraphNode.setLocalScale


setPosition()

setPosition(
   x: number | Vec3,
   y?: number,
   z?: number): void

Sets the world space position of the specified graph node. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the world space position.

Parameters

x

3-dimensional vector holding world space position or x-coordinate of world space position.

number | Vec3

y?

number

Y-coordinate of world space position.

z?

number

Z-coordinate of world space position.

Returns

void

Examples

// Set via 3 numbers
this.entity.setPosition(0, 10, 0)
// Set via vector
const position = new Vec3(0, 10, 0)
this.entity.setPosition(position)

Inherited from

GraphNode.setPosition


setPositionAndRotation()

setPositionAndRotation(position: Vec3, rotation: Quat): void

Sets the world space position and rotation of the specified graph node. This is faster than setting the position and rotation independently.

Parameters

position

Vec3

The world space position to set.

rotation

Quat

The world space rotation to set.

Returns

void

Example

const position = new Vec3(0, 10, 0)
const rotation = new Quat().setFromEulerAngles(0, 90, 0)
this.entity.setPositionAndRotation(position, rotation)

Inherited from

GraphNode.setPositionAndRotation


setRotation()

setRotation(
   x: number | Quat,
   y?: number,
   z?: number,
   w?: number): void

Sets the world space rotation of the specified graph node. This function has two valid signatures: you can either pass a quaternion or 3 numbers to specify the world space rotation.

Parameters

x

Quaternion holding world space rotation or x-component of world space quaternion rotation.

number | Quat

y?

number

Y-component of world space quaternion rotation.

z?

number

Z-component of world space quaternion rotation.

w?

number

W-component of world space quaternion rotation.

Returns

void

Examples

// Set via 4 numbers
this.entity.setRotation(0, 0, 0, 1)
// Set via quaternion
const q = Quat()
this.entity.setRotation(q)

Inherited from

GraphNode.setRotation


translate()

translate(
   x: number | Vec3,
   y?: number,
   z?: number): void

Translates the graph node in world space by the specified translation vector. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the world space translation.

Parameters

x

3-dimensional vector holding world space translation or x-coordinate of world space translation.

number | Vec3

y?

number

Y-coordinate of world space translation.

z?

number

Z-coordinate of world space translation.

Returns

void

Examples

// Translate via 3 numbers
this.entity.translate(10, 0, 0)
// Translate via vector
const t = new Vec3(10, 0, 0)
this.entity.translate(t)

Inherited from

GraphNode.translate


translateLocal()

translateLocal(
   x: number | Vec3,
   y?: number,
   z?: number): void

Translates the graph node in local space by the specified translation vector. This function has two valid signatures: you can either pass a 3D vector or 3 numbers to specify the local space translation.

Parameters

x

3-dimensional vector holding local space translation or x-coordinate of local space translation.

number | Vec3

y?

number

Y-coordinate of local space translation.

z?

number

Z-coordinate of local space translation.

Returns

void

Examples

// Translate via 3 numbers
this.entity.translateLocal(10, 0, 0)
// Translate via vector
const t = new Vec3(10, 0, 0)
this.entity.translateLocal(t)

Inherited from

GraphNode.translateLocal

Events

EVENT_DESTROY

static EVENT_DESTROY: string = 'destroy';

Fired after the entity is destroyed.

Example

entity.on('destroy', (e) => {
  console.log(`Entity ${'${e.name}'} has been destroyed`)
})
Mirror Engine Logo