new ModelAnimationCollection
A collection of active model animations. Access this using Model#activeAnimations.
Members
-
animationAdded :Event
-
The event fired when an animation is added to the collection. This can be used, for example, to keep a UI in sync.
Example
model.activeAnimations.animationAdded.addEventListener(function(model, animation) { console.log('Animation added: ' + animation.name); });
- Default Value:
- new Event()
-
animationRemoved :Event
-
The event fired when an animation is removed from the collection. This can be used, for example, to keep a UI in sync.
Example
model.activeAnimations.animationRemoved.addEventListener(function(model, animation) { console.log('Animation removed: ' + animation.name); });
- Default Value:
- new Event()
-
<static, readonly> length :Number
-
The number of animations in the collection.
-
<static> matrix :Matrix4
-
The node's 4x4 matrix transform from its local coordinates to its parent's.
For changes to take effect, this property must be assigned to; setting individual elements of the matrix will not work.
Methods
-
add
-
Creates and adds an animation with the specified initial properties to the collection.
This raises the ModelAnimationCollection#animationAdded event so, for example, a UI can stay in sync.
Parameters:
Name Type Argument Default Description options.name
String The glTF animation name that identifies the animation. options.startTime
JulianDate <optional>
undefined The scene time to start playing the animation. When this is undefined
, the animation starts at the next frame.options.startOffset
Number <optional>
0.0 The offset, in seconds, from startTime
to start playing.options.stopTime
JulianDate <optional>
undefined The scene time to stop playing the animation. When this is undefined
, the animation is played for its full duration.options.removeOnStop
Boolean <optional>
false When true
, the animation is removed after it stops playing.options.speedup
Number <optional>
1.0 Values greater than 1.0
increase the speed that the animation is played relative to the scene clock speed; values less than1.0
decrease the speed.options.reverse
Boolean <optional>
false When true
, the animation is played in reverse.options.loop
ModelAnimationLoop <optional>
ModelAnimationLoop.NONE Determines if and how the animation is looped. Throws:
-
DeveloperError : Animations are not loaded. Wait for the Model#readyToRender event.
-
DeveloperError : options.name must be a valid animation name.
-
DeveloperError : options.speedup must be greater than zero.
Returns:
ModelAnimation The animation that was added to the collection.Example
// Example 1. Add an animation model.activeAnimations.add({ name : 'animation name' }); // Example 2. Add an animation and provide all properties and events var startTime = new JulianDate(); var animation = model.activeAnimations.add({ name : 'another animation name', startTime : startTime, startOffset : 0.0, // Play at startTime (default) stopTime : startTime.addSeconds(4.0), removeOnStop : false, // Do not remove when animation stops (default) speedup : 2.0, // Play at double speed reverse : true, // Play in reverse loop : ModelAnimationLoop.REPEAT // Loop the animation }); animation.start.addEventListener(function(model, animation) { console.log('Animation started: ' + animation.name); }); animation.update.addEventListener(function(model, animation, time) { console.log('Animation updated: ' + animation.name + '. glTF animation time: ' + time); }); animation.stop.addEventListener(function(model, animation) { console.log('Animation stopped: ' + animation.name); });
-
-
addAll
-
Creates and adds an animation with the specified initial properties to the collection for each animation in the model.
This raises the ModelAnimationCollection#animationAdded event for each model so, for example, a UI can stay in sync.
Parameters:
Name Type Argument Default Description options.startTime
JulianDate <optional>
undefined The scene time to start playing the animations. When this is undefined
, the animations starts at the next frame.options.startOffset
Number <optional>
0.0 The offset, in seconds, from startTime
to start playing.options.stopTime
JulianDate <optional>
undefined The scene time to stop playing the animations. When this is undefined
, the animations are played for its full duration.options.removeOnStop
Boolean <optional>
false When true
, the animations are removed after they stop playing.options.speedup
Number <optional>
1.0 Values greater than 1.0
increase the speed that the animations play relative to the scene clock speed; values less than1.0
decrease the speed.options.reverse
Boolean <optional>
false When true
, the animations are played in reverse.options.loop
ModelAnimationLoop <optional>
ModelAnimationLoop.NONE Determines if and how the animations are looped. Throws:
-
DeveloperError : Animations are not loaded. Wait for the Model#readyToRender event.
-
DeveloperError : options.speedup must be greater than zero.
Returns:
Array An array of ModelAnimation objects, one for each animation added to the collection. If there are no glTF animations, the array is empty.Example
model.activeAnimations.addAll({ speedup : 0.5, // Play at half-speed loop : ModelAnimationLoop.REPEAT // Loop the animations });
-
-
contains
-
Determines whether this collection contains a given animation.
Parameters:
Name Type Description animation
ModelAnimation The animation to check for. Returns:
Booleantrue
if this animation contains the animation,false
otherwise. -
get
-
Returns the animation in the collection at the specified index. Indices are zero-based and increase as animations are added. Removing an animation shifts all animations after it to the left, changing their indices. This function is commonly used to iterate over all the animations in the collection.
Parameters:
Name Type Description index
Number The zero-based index of the animation. Returns:
ModelAnimation The animation at the specified index.Example
// Output the names of all the animations in the collection. var animations = model.activeAnimations; var length = animations.length; for (var i = 0; i < length; ++i) { console.log(animations.get(i).name); }
-
remove
-
Removes an animation from the collection.
This raises the ModelAnimationCollection#animationRemoved event so, for example, a UI can stay in sync.
An animation can also be implicitly removed from the collection by setting ModelAnimation#removeOnStop to
true
. The ModelAnimationCollection#animationRemoved event is still fired when the animation is removed.Parameters:
Name Type Description animation
ModelAnimation The animation to remove. Returns:
Booleantrue
if the animation was removed;false
if the animation was not found in the collection.Example
var a = model.activeAnimations.add({ name : 'animation name' }); model.activeAnimations.remove(a); // Returns true
-
removeAll
-
Removes all animations from the collection.
This raises the ModelAnimationCollection#animationRemoved event for each animation so, for example, a UI can stay in sync.