API Reference

Class List

pc.GraphNode

Extends: pc.EventHandler

A hierarchical scene node.

Summary

Properties

children

A read-only property to get the children of this graph node.[read only]

enabled

Enable or disable a GraphNode.

forward

The normalized local space negative Z-axis vector of the graph node in world space.[read only]

graphDepth

A read-only property to get the depth of this child within the graph.[read only]

name

The non-unique name of a graph node.

parent

A read-only property to get a parent graph node.[read only]

path

A read-only property to get the path of the graph node relative to the root of the hierarchy.[read only]

right

The normalized local space X-axis vector of the graph node in world space.[read only]

root

A read-only property to get highest graph node from current node.[read only]

tags

Interface for tagging graph nodes.

up

The normalized local space Y-axis vector of the graph node in world space.[read only]

Methods

addChild

Add a new child to the child list and update the parent value of the child node.

find

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

findByName

Get the first node found in the graph with the name.

findByPath

Get the first node found in the graph by its full path in the graph.

findByTag

Return all graph nodes that satisfy the search query.

findOne

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

forEach

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

getEulerAngles

Get the world space rotation for the specified GraphNode in Euler angle form.

getLocalEulerAngles

Get the rotation in local space for the specified GraphNode.

getLocalPosition

Get the position in local space for the specified GraphNode.

getLocalRotation

Get the rotation in local space for the specified GraphNode.

getLocalScale

Get the scale in local space for the specified GraphNode.

getLocalTransform

Get the local transform matrix for this graph node.

getPosition

Get the world space position for the specified GraphNode.

getRotation

Get the world space rotation for the specified GraphNode in quaternion form.

getWorldTransform

Get the world transformation matrix for this graph node.

insertChild

Insert a new child to the child list at the specified index and update the parent value of the child node.

isAncestorOf

Check if node is ancestor for another node.

isDescendantOf

Check if node is descendant of another node.

lookAt

Reorients the graph node so that the negative z-axis points towards the target.

removeChild

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

reparent

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

rotate

Rotates the graph node in world-space by the specified Euler angles.

rotateLocal

Rotates the graph node in local-space by the specified Euler angles.

setEulerAngles

Sets the world-space rotation of the specified graph node using euler angles.

setLocalEulerAngles

Sets the local-space rotation of the specified graph node using euler angles.

setLocalPosition

Sets the local-space position of the specified graph node.

setLocalRotation

Sets the local-space rotation of the specified graph node.

setLocalScale

Sets the local-space scale factor of the specified graph node.

setPosition

Sets the world-space position of the specified graph node.

setRotation

Sets the world-space rotation of the specified graph node.

translate

Translates the graph node in world-space by the specified translation vector.

translateLocal

Translates the graph node in local-space by the specified translation vector.

Inherited

Methods

fire

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

hasEvent

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

off

Detach an event handler from an event.

on

Attach an event handler to an event.

once

Attach an event handler to an event.

Details

Constructor

GraphNode([name])

Parameters

namestring

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

Properties

pc.GraphNode[]children

A read-only property to get the children of this graph node.

[read only]

booleanenabled

Enable or disable a 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 / deactivate all the enabled children of the GraphNode.

pc.Vec3forward

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

[read only]

numbergraphDepth

A read-only property to get 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, i.e. It is not recalculated when a node is simply removed from the graph.

[read only]

stringname

The non-unique name of a graph node.

pc.GraphNodeparent

A read-only property to get a parent graph node.

[read only]

stringpath

A read-only property to get the path of the graph node relative to the root of the hierarchy.

[read only]

pc.GraphNoderoot

A read-only property to get highest graph node from current node.

[read only]

pc.Tagstags

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

pc.Vec3up

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

[read only]

Methods

addChild(node)

Add a new child to the child list and update the parent value of the child node.

var e = new pc.Entity(app);
this.entity.addChild(e);

Parameters

nodepc.GraphNode

The new child to add.

find(attr, [value])

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

// Finds all nodes that have a model component and have `door` in their lower-cased name
var 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'
var entities = parent.find('name', 'Test');

Parameters

attrpc.callbacks.FindNode, string

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.

valueobject

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

Returns

pc.GraphNode[]

The array of graph nodes that match the search criteria.

findByName(name)

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

Parameters

namestring

The name of the graph.

Returns

pc.GraphNode

The first node to be found matching the supplied name.

findByPath(path)

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.

var path = this.entity.findByPath('child/another_child');

Parameters

pathstring

The full path of the pc.GraphNode.

Returns

pc.GraphNode

The first node to be found matching the supplied path.

findByTag(query)

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.

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

Parameters

querystring

Name of a tag or array of tags.

Returns

pc.GraphNode[]

A list of all graph nodes that match the query.

findOne(attr, [value])

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

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

Parameters

attrpc.callbacks.FindNode, string

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.

valueobject

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

Returns

pc.GraphNode

A graph node that match the search criteria.

forEach(callback, [thisArg])

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

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

Parameters

callbackpc.callbacks.ForEach

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

thisArgobject

Optional value to use as this when executing callback function.

getEulerAngles()

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

var angles = this.entity.getEulerAngles(); // [0,0,0]
angles[1] = 180; // rotate the entity around Y by 180 degrees
this.entity.setEulerAngles(angles);

Returns

pc.Vec3

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

getLocalEulerAngles()

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

var angles = this.entity.getLocalEulerAngles();
angles[1] = 180;
this.entity.setLocalEulerAngles(angles);

Returns

pc.Vec3

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

getLocalPosition()

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

var position = this.entity.getLocalPosition();
position[0] += 1; // move the entity 1 unit along x.
this.entity.setLocalPosition(position);

Returns

pc.Vec3

The local space position of the graph node.

getLocalRotation()

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

var rotation = this.entity.getLocalRotation();

Returns

pc.Quat

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

getLocalScale()

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

var scale = this.entity.getLocalScale();
scale.x = 100;
this.entity.setLocalScale(scale);

Returns

pc.Vec3

The local space scale of the graph node.

getLocalTransform()

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

var transform = this.entity.getLocalTransform();

Returns

pc.Mat4

The node's local transformation matrix.

getPosition()

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

var position = this.entity.getPosition();
position.x = 10;
this.entity.setPosition(position);

Returns

pc.Vec3

The world space position of the graph node.

getRotation()

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

var rotation = this.entity.getRotation();

Returns

pc.Quat

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

getWorldTransform()

Get the world transformation matrix for this graph node.

var transform = this.entity.getWorldTransform();

Returns

pc.Mat4

The node's world transformation matrix.

insertChild(node, index)

Insert a new child to the child list at the specified index and update the parent value of the child node.

var e = new pc.Entity(app);
this.entity.insertChild(e, 1);

Parameters

nodepc.GraphNode

The new child to insert.

indexnumber

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

isAncestorOf(node)

Check if node is ancestor for another node.

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

Parameters

nodepc.GraphNode

Potential descendant of node.

Returns

boolean

If node is ancestor for another node.

isDescendantOf(node)

Check if node is descendant of another node.

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

Parameters

nodepc.GraphNode

Potential ancestor of node.

Returns

boolean

If node is descendant of another node.

lookAt(x, y, z, [ux], [uy], [uz])

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.

// Look at another entity, using the (default) positive y-axis for up
var position = otherEntity.getPosition();
this.entity.lookAt(position);
// Look at another entity, using the negative world y-axis for up
var position = otherEntity.getPosition();
this.entity.lookAt(position, pc.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);

Parameters

xpc.Vec3, number

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.

ypc.Vec3, number

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.

znumber

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

uxnumber

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

uynumber

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

uznumber

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

removeChild(child)

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

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

Parameters

childpc.GraphNode

The node to remove.

reparent(parent, [index])

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

Parameters

parentpc.GraphNode

New parent to attach graph node to.

indexnumber

The child index where the child node should be placed.

rotate(x, [y], [z])

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.

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

Parameters

xpc.Vec3, number

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

ynumber

Rotation around world-space y-axis in degrees.

znumber

Rotation around world-space z-axis in degrees.

rotateLocal(x, [y], [z])

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.

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

Parameters

xpc.Vec3, number

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

ynumber

Rotation around local-space y-axis in degrees.

znumber

Rotation around local-space z-axis in degrees.

setEulerAngles(x, [y], [z])

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.

// 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
var angles = new pc.Vec3(0, 90, 0);
this.entity.setEulerAngles(angles);

Parameters

xpc.Vec3, number

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

ynumber

Rotation around world-space y-axis in degrees.

znumber

Rotation around world-space z-axis in degrees.

setLocalEulerAngles(x, [y], [z])

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.

// 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
var angles = new pc.Vec3(0, 90, 0);
this.entity.setLocalEulerAngles(angles);

Parameters

xpc.Vec3, number

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

ynumber

Rotation around local-space y-axis in degrees.

znumber

Rotation around local-space z-axis in degrees.

setLocalPosition(x, [y], [z])

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.

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

Parameters

xpc.Vec3, number

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

ynumber

Y-coordinate of local-space position.

znumber

Z-coordinate of local-space position.

setLocalRotation(x, [y], [z], [w])

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.

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

Parameters

xpc.Quat, number

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

ynumber

Y-component of local-space quaternion rotation.

znumber

Z-component of local-space quaternion rotation.

wnumber

W-component of local-space quaternion rotation.

setLocalScale(x, [y], [z])

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.

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

Parameters

xpc.Vec3, number

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

ynumber

Y-coordinate of local-space scale.

znumber

Z-coordinate of local-space scale.

setPosition(x, [y], [z])

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.

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

Parameters

xpc.Vec3, number

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

ynumber

Y-coordinate of world-space position.

znumber

Z-coordinate of world-space position.

setRotation(x, [y], [z], [w])

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.

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

Parameters

xpc.Quat, number

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

ynumber

Y-component of world-space quaternion rotation.

znumber

Z-component of world-space quaternion rotation.

wnumber

W-component of world-space quaternion rotation.

translate(x, [y], [z])

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.

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

Parameters

xpc.Vec3, number

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

ynumber

Y-coordinate of world-space translation.

znumber

Z-coordinate of world-space translation.

translateLocal(x, [y], [z])

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.

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

Parameters

xpc.Vec3, number

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

ynumber

Y-coordinate of local-space translation.

znumber

Z-coordinate of local-space translation.

Inherited

Methods

fire(name, [arg1], [arg2], [arg3], [arg4], [arg5], [arg6], [arg7], [arg8])

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

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

Parameters

nameobject

Name of event to fire.

arg1*

First argument that is passed to the event handler.

arg2*

Second argument that is passed to the event handler.

arg3*

Third argument that is passed to the event handler.

arg4*

Fourth argument that is passed to the event handler.

arg5*

Fifth argument that is passed to the event handler.

arg6*

Sixth argument that is passed to the event handler.

arg7*

Seventh argument that is passed to the event handler.

arg8*

Eighth argument that is passed to the event handler.

Returns

pc.EventHandler

Self for chaining.

hasEvent(name)

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

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

Parameters

namestring

The name of the event to test.

Returns

boolean

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

off([name], [callback], [scope])

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.

var handler = function () {
};
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 hander functions, called 'test' with scope this

Parameters

namestring

Name of the event to unbind.

callbackpc.callbacks.HandleEvent

Function to be unbound.

scopeobject

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

Returns

pc.EventHandler

Self for chaining.

on(name, callback, [scope])

Attach an event handler to an event.

obj.on('test', function (a, b) {
    console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console

Parameters

namestring

Name of the event to bind the callback to.

callbackpc.callbacks.HandleEvent

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

scopeobject

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

Returns

pc.EventHandler

Self for chaining.

once(name, callback, [scope])

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

obj.once('test', function (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

Parameters

namestring

Name of the event to bind the callback to.

callbackpc.callbacks.HandleEvent

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

scopeobject

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

Returns

pc.EventHandler

Self for chaining.