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. |
entity | The Entity that this Component is attached to. |
system | The ComponentSystem used to create this 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
system | AnimComponentSystem | The ComponentSystem that created this Component. |
entity | Entity | The Entity that this Component is attached to. |
Properties
If true the animation component will normalize the weights of its layers by their sum total.
The entity that this anim component should use as the root of the animation hierarchy.
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
name | string | The name of the layer to create. |
weight | number | The blending weight of the layer. Defaults to 1. |
mask | object[] | 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. |
blendType | string | Defines how properties animated by this layer blend with animations of those properties in previous layers. Defaults to pc.ANIM_LAYER_OVERWRITE. |
Returns
AnimComponentLayerThe 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
nodePath | string | 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 ( |
animTrack | object | The animation track that will be assigned to this state and played whenever this state is active. |
layerName | string | 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. |
speed | number | Update the speed of the state you are assigning an animation to. Defaults to 1. |
loop | boolean | 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
name | string | The name of the anim component layer to find. |
Returns
AnimComponentLayerLayer.
getBoolean(name)
Returns a boolean parameter value by name.
Parameters
name | string | The name of the boolean to return the value of. |
Returns
booleanA boolean.
getFloat(name)
Returns a float parameter value by name.
Parameters
name | string | The name of the float to return the value of. |
Returns
numberA float.
getInteger(name)
Returns an integer parameter value by name.
Parameters
name | string | The name of the integer to return the value of. |
Returns
numberAn integer.
getTrigger(name)
Returns a trigger parameter value by name.
Parameters
name | string | The name of the trigger to return the value of. |
Returns
booleanA 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
stateGraph | object | 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
nodeName | string | The name of the node that should have its animation tracks removed. |
layerName | string | 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
name | string | 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
name | string | The name of the parameter to set. |
value | boolean | 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
name | string | The name of the parameter to set. |
value | number | 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
name | string | The name of the parameter to set. |
value | number | 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
name | string | The name of the parameter to set. |
singleFrame | boolean | If true, this trigger will be set back to false at the end of the animation update. Defaults to false. |
Inherited
Properties
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
name | string | 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
EventHandlerSelf 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
name | string | The name of the event to test. |
Returns
booleanTrue 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.
const 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
name | string | Name of the event to unbind. |
callback | HandleEventCallback | Function to be unbound. |
scope | object | Scope that was used as the this when the event is fired. |
Returns
EventHandlerSelf 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
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 | object | Object to use as 'this' when the event is fired, defaults to current this. |
Returns
EventHandlerSelf 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
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 | object | Object to use as 'this' when the event is fired, defaults to current this. |
Returns
EventHandlerSelf for chaining.