API Reference

Class List

AnimComponent

Extends: Component

The Anim Component allows an Entity to playback animations on models and entity properties.

Summary

Properties

activate

If true the first animation will begin playing when the scene is loaded.

baseLayer

Returns the base layer of the state graph.

layers

Returns the animation layers available in this anim component.

normalizeWeights

If true the animation component will normalize the weights of its layers by their sum total.

playable

Returns whether all component layers are currently playable.

playing

Plays or pauses all animations in the component.

rootBone

The entity that this anim component should use as the root of the animation hierarchy.

speed

Speed multiplier for animation play back speed.

Methods

addLayer

Adds a new anim component layer to the anim component.

assignAnimation

Associates an animation with a state or blend tree node in the loaded state graph.

findAnimationLayer

Finds a AnimComponentLayer in this component.

getBoolean

Returns a boolean parameter value by name.

getFloat

Returns a float parameter value by name.

getInteger

Returns an integer parameter value by name.

getTrigger

Returns a trigger parameter value by name.

loadStateGraph

Initializes component animation controllers using the provided state graph.

rebind

Rebind all of the components layers.

removeNodeAnimations

Removes animations from a node in the loaded state graph.

removeStateGraph

Removes all layers from the anim component.

reset

Reset all of the components layers and parameters to their initial states.

resetTrigger

Resets the value of a trigger parameter that was defined in the animation components state graph to false.

setBoolean

Sets the value of a boolean parameter that was defined in the animation components state graph.

setFloat

Sets the value of a float parameter that was defined in the animation components state graph.

setInteger

Sets the value of an integer parameter that was defined in the animation components state graph.

setTrigger

Sets the value of a trigger parameter that was defined in the animation components state graph to true.

Inherited

Properties

enabled

Enables or disables the component.

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

AnimComponent(system, entity)

Create a new AnimComponent instance.

Parameters

systemAnimComponentSystem

The ComponentSystem that created this Component.

entityEntity

The Entity that this Component is attached to.

Properties

booleanactivate

If true the first animation will begin playing when the scene is loaded.

AnimComponentLayer, nullbaseLayer

Returns the base layer of the state graph.

AnimComponentLayer[]layers

Returns the animation layers available in this anim component.

booleannormalizeWeights

If true the animation component will normalize the weights of its layers by their sum total.

booleanplayable

Returns whether all component layers are currently playable.

booleanplaying

Plays or pauses all animations in the component.

EntityrootBone

The entity that this anim component should use as the root of the animation hierarchy.

numberspeed

Speed multiplier for animation play back speed. 1.0 is playback at normal speed, 0.0 pauses the animation.

Methods

addLayer(name, [weight], [mask], [blendType])

Adds a new anim component layer to the anim component.

Parameters

namestring

The name of the layer to create.

weightnumber

The blending weight of the layer. Defaults to 1.

maskobject[]

A list of paths to bones in the model which should be animated in this layer. If omitted the full model is used. Defaults to null.

blendTypestring

Defines how properties animated by this layer blend with animations of those properties in previous layers. Defaults to pc.ANIM_LAYER_OVERWRITE.

Returns

AnimComponentLayer

The created anim component layer.

assignAnimation(nodePath, animTrack, [layerName], [speed], [loop])

Associates an animation with a state or blend tree node in the loaded state graph. If all states are linked and the AnimComponent#activate value was set to true then the component will begin playing. If no state graph is loaded, a default state graph will be created with a single state based on the provided nodePath parameter.

Parameters

nodePathstring

Either the state name or the path to a blend tree node that this animation should be associated with. Each section of a blend tree path is split using a period (.) therefore state names should not include this character (e.g "MyStateName" or "MyStateName.BlendTreeNode").

animTrackobject

The animation track that will be assigned to this state and played whenever this state is active.

layerNamestring

The name of the anim component layer to update. If omitted the default layer is used. If no state graph has been previously loaded this parameter is ignored.

speednumber

Update the speed of the state you are assigning an animation to. Defaults to 1.

loopboolean

Update the loop property of the state you are assigning an animation to. Defaults to true.

findAnimationLayer(name)

Finds a AnimComponentLayer in this component.

Parameters

namestring

The name of the anim component layer to find.

Returns

AnimComponentLayer

Layer.

getBoolean(name)

Returns a boolean parameter value by name.

Parameters

namestring

The name of the boolean to return the value of.

Returns

boolean

A boolean.

getFloat(name)

Returns a float parameter value by name.

Parameters

namestring

The name of the float to return the value of.

Returns

number

A float.

getInteger(name)

Returns an integer parameter value by name.

Parameters

namestring

The name of the integer to return the value of.

Returns

number

An integer.

getTrigger(name)

Returns a trigger parameter value by name.

Parameters

namestring

The name of the trigger to return the value of.

Returns

boolean

A boolean.

loadStateGraph(stateGraph)

Initializes component animation controllers using the provided state graph.

entity.anim.loadStateGraph({
    "layers": [
        {
            "name": layerName,
            "states": [
                {
                    "name": "START",
                    "speed": 1
                },
                {
                    "name": "Initial State",
                    "speed": speed,
                    "loop": loop,
                    "defaultState": true
                }
            ],
            "transitions": [
                {
                    "from": "START",
                    "to": "Initial State"
                }
            ]
        }
    ],
    "parameters": {}
});

Parameters

stateGraphobject

The state graph asset to load into the component. Contains the states, transitions and parameters used to define a complete animation controller.

rebind()

Rebind all of the components layers.

removeNodeAnimations(nodeName, [layerName])

Removes animations from a node in the loaded state graph.

Parameters

nodeNamestring

The name of the node that should have its animation tracks removed.

layerNamestring

The name of the anim component layer to update. If omitted the default layer is used.

removeStateGraph()

Removes all layers from the anim component.

reset()

Reset all of the components layers and parameters to their initial states. If a layer was playing before it will continue playing.

resetTrigger(name)

Resets the value of a trigger parameter that was defined in the animation components state graph to false.

Parameters

namestring

The name of the parameter to set.

setBoolean(name, value)

Sets the value of a boolean parameter that was defined in the animation components state graph.

Parameters

namestring

The name of the parameter to set.

valueboolean

The new boolean value to set this parameter to.

setFloat(name, value)

Sets the value of a float parameter that was defined in the animation components state graph.

Parameters

namestring

The name of the parameter to set.

valuenumber

The new float value to set this parameter to.

setInteger(name, value)

Sets the value of an integer parameter that was defined in the animation components state graph.

Parameters

namestring

The name of the parameter to set.

valuenumber

The new integer value to set this parameter to.

setTrigger(name, [singleFrame])

Sets the value of a trigger parameter that was defined in the animation components state graph to true.

Parameters

namestring

The name of the parameter to set.

singleFrameboolean

If true, this trigger will be set back to false at the end of the animation update. Defaults to false.

Inherited

Properties

booleanenabled

Enables or disables the component.

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

namestring

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

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 handler functions, called 'test' with scope this

Parameters

namestring

Name of the event to unbind.

callbackHandleEventCallback

Function to be unbound.

scopeobject

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

Returns

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.

callbackHandleEventCallback

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

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.

callbackHandleEventCallback

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

EventHandler

Self for chaining.