A collection of active model animations. Access this using
ModelExperimental#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.
-
Default Value:
new Event()
Example:
model.activeAnimations.animationAdded.addEventListener(function(model, animation) {
console.log('Animation added: ' + animation.name);
});
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.
-
Default Value:
new Event()
Example:
model.activeAnimations.animationRemoved.addEventListener(function(model, animation) {
console.log('Animation removed: ' + animation.name);
});
The number of animations in the collection.
readonly model : ModelExperimental
The model that owns this animation collection.
Methods
Creates and adds an animation with the specified initial properties to the collection.
This raises the ModelExperimentalAnimationCollection#animationAdded
event so, for example, a UI can stay in sync.
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Object with the following properties:
|
Returns:
The animation that was added to the collection.
Throws:
-
DeveloperError : Animations are not loaded. Wait for the
ModelExperimental#readyPromise
to resolve. -
DeveloperError : options.name must be a valid animation name.
-
DeveloperError : options.index must be a valid animation index.
-
DeveloperError : Either options.name or options.index must be defined.
-
DeveloperError : options.multiplier must be greater than zero.
Examples:
// Example 1. Add an animation by name
model.activeAnimations.add({
name : 'animation name'
});
// Example 2. Add an animation by index
model.activeAnimations.add({
index : 0
});
// Example 3. Add an animation and provide all properties and events
const startTime = Cesium.JulianDate.now();
const animation = model.activeAnimations.add({
name : 'another animation name',
startTime : startTime,
delay : 0.0, // Play at startTime (default)
stopTime : Cesium.JulianDate.addSeconds(startTime, 4.0, new Cesium.JulianDate()),
removeOnStop : false, // Do not remove when animation stops (default)
multiplier : 2.0, // Play at double speed
reverse : true, // Play in reverse
loop : Cesium.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(options) → Array.<ModelExperimentalAnimation>
Creates and adds animations with the specified initial properties to the collection
for all animations in the model.
This raises the ModelExperimentalAnimationCollection#animationAdded
event for each model so, for example, a UI can stay in sync.
Name | Type | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
optional
Object with the following properties:
|
Returns:
An array of
ModelExperimentalAnimation
objects, one for each animation added to the collection. If there are no glTF animations, the array is empty.
Throws:
-
DeveloperError : Animations are not loaded. Wait for the
ModelExperimental#readyPromise
to resolve. -
DeveloperError : options.multiplier must be greater than zero.
Example:
model.activeAnimations.addAll({
multiplier : 0.5, // Play at half-speed
loop : Cesium.ModelAnimationLoop.REPEAT // Loop the animations
});
Determines whether this collection contains a given animation.
Name | Type | Description |
---|---|---|
runtimeAnimation |
ModelExperimentalAnimation | The runtime animation to check for. |
Returns:
true
if this collection contains the animation, false
otherwise.
get(index) → ModelExperimentalAnimation
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.
Name | Type | Description |
---|---|---|
index |
Number | The zero-based index of the animation. |
Returns:
The runtime animation at the specified index.
Example:
// Output the names of all the animations in the collection.
const animations = model.activeAnimations;
const length = animations.length;
for (let i = 0; i < length; ++i) {
console.log(animations.get(i).name);
}
Removes an animation from the collection.
This raises the ModelExperimentalAnimationCollection#animationRemoved
event so, for example, a UI can stay in sync.
An animation can also be implicitly removed from the collection by setting ModelExperimentalAnimationCollection#removeOnStop
to
true
. The ModelExperimentalAnimationCollection#animationRemoved
event is still fired when the animation is removed.
Name | Type | Description |
---|---|---|
runtimeAnimation |
ModelExperimentalAnimation | The runtime animation to remove. |
Returns:
true
if the animation was removed; false
if the animation was not found in the collection.
Example:
const a = model.activeAnimations.add({
name : 'animation name'
});
model.activeAnimations.remove(a); // Returns true
Removes all animations from the collection.
This raises the ModelExperimentalAnimationCollection#animationRemoved
event for each
animation so, for example, a UI can stay in sync.