new ModelAnimationCollection()
Model#activeAnimations. Do not call the constructor directly
A collection of active model animations.
Members
-
animateWhilePausedboolean
-
When true, the animation will play even when the scene time is paused. However, whether animation takes place will depend on the animationTime functions assigned to the model's animations. By default, this is based on scene time, so models using the default will not animate regardless of this setting.
- Default Value: false
animationAddedEvent
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}`);
});
animationRemovedEvent
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}`);
});
readonly lengthnumber
The number of animations in the collection.
readonly modelModel
The model that owns this animation collection.
Methods
-
add(options){ModelAnimation}
-
Creates and adds an animation with the specified initial properties to the collection.
This raises the
ModelAnimationCollection#animationAddedevent so, for example, a UI can stay in sync.Name Type Description optionsobject Object with the following properties:
Name Type Default Description namestring 可选 The glTF animation name that identifies the animation. Must be defined if
options.indexisundefined.indexnumber 可选 The glTF animation index that identifies the animation. Must be defined if
options.nameisundefined.startTimeJulianDate 可选 The scene time to start playing the animation. When this is
undefined, the animation starts at the next frame.delaynumber 0.0 可选 The delay, in seconds, from
startTimeto start playing. This will only affect the animation ifoptions.loopis ModelAnimationLoop.NONE.stopTimeJulianDate 可选 The scene time to stop playing the animation. When this is
undefined, the animation is played for its full duration.removeOnStopboolean false 可选 When
true, the animation is removed after it stops playing. This will only affect the animation ifoptions.loopis ModelAnimationLoop.NONE.multipliernumber 1.0 可选 Values greater than
1.0increase the speed that the animation is played relative to the scene clock speed; values less than1.0decrease the speed.reverseboolean false 可选 When
true, the animation is played in reverse.loopModelAnimationLoop ModelAnimationLoop.NONE 可选 Determines if and how the animation is looped.
animationTimeModelAnimation.AnimationTimeCallback 可选 If defined, computes the local animation time for this animation.
Throws:
-
-
Animations are not loaded. Wait for the
Model#readyto return trues. - Type
- DeveloperError
-
-
-
options.name must be a valid animation name.
- Type
- DeveloperError
-
-
-
options.index must be a valid animation index.
- Type
- DeveloperError
-
-
-
Either options.name or options.index must be defined.
- Type
- DeveloperError
-
-
-
options.multiplier must be greater than zero.
- Type
- DeveloperError
-
Returns:
Type Description ModelAnimation The animation that was added to the collection. 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 = SuperMap3D.JulianDate.now(); const animation = model.activeAnimations.add({ name : 'another animation name', startTime : startTime, delay : 0.0, // Play at startTime (default) stopTime : SuperMap3D.JulianDate.addSeconds(startTime, 4.0, new SuperMap3D.JulianDate()), removeOnStop : false, // Do not remove when animation stops (default) multiplier : 2.0, // Play at double speed reverse : true, // Play in reverse loop : SuperMap3D.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.<ModelAnimation>}
-
Creates and adds animations with the specified initial properties to the collection for all animations in the model.
This raises the
ModelAnimationCollection#animationAddedevent for each model so, for example, a UI can stay in sync.Name Type Description optionsobject 可选 Object with the following properties:
Name Type Default Description startTimeJulianDate 可选 The scene time to start playing the animations. When this is
undefined, the animations starts at the next frame.delaynumber 0.0 可选 The delay, in seconds, from
startTimeto start playing. This will only affect the animation ifoptions.loopis ModelAnimationLoop.NONE.stopTimeJulianDate 可选 The scene time to stop playing the animations. When this is
undefined, the animations are played for its full duration.removeOnStopboolean false 可选 When
true, the animations are removed after they stop playing. This will only affect the animation ifoptions.loopis ModelAnimationLoop.NONE.multipliernumber 1.0 可选 Values greater than
1.0increase the speed that the animations play relative to the scene clock speed; values less than1.0decrease the speed.reverseboolean false 可选 When
true, the animations are played in reverse.loopModelAnimationLoop ModelAnimationLoop.NONE 可选 Determines if and how the animations are looped.
animationTimeModelAnimation.AnimationTimeCallback 可选 If defined, computes the local animation time for all of the animations.
Throws:
-
-
Animations are not loaded. Wait for the
Model#readyto return true. - Type
- DeveloperError
-
-
-
options.multiplier must be greater than zero.
- Type
- DeveloperError
-
Returns:
Type Description Array.<ModelAnimation> An array of ModelAnimationobjects, one for each animation added to the collection. If there are no glTF animations, the array is empty.Example
model.activeAnimations.addAll({ multiplier : 0.5, // Play at half-speed loop : SuperMap3D.ModelAnimationLoop.REPEAT // Loop the animations }); -
-
contains(runtimeAnimation){boolean}
-
Determines whether this collection contains a given animation.
Name Type Description runtimeAnimationModelAnimation The runtime animation to check for.
Returns:
Type Description boolean trueif this collection contains the animation,falseotherwise. -
get(index){ModelAnimation}
-
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 indexnumber The zero-based index of the animation.
Returns:
Type Description ModelAnimation 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); } -
remove(runtimeAnimation){boolean}
-
Removes an animation from the collection.
This raises the
ModelAnimationCollection#animationRemovedevent so, for example, a UI can stay in sync.An animation can also be implicitly removed from the collection by setting
ModelAnimationCollection#removeOnStoptotrue. TheModelAnimationCollection#animationRemovedevent is still fired when the animation is removed.Name Type Description runtimeAnimationModelAnimation The runtime animation to remove.
Returns:
Type Description boolean trueif the animation was removed;falseif the animation was not found in the collection.Example
const a = model.activeAnimations.add({ name : 'animation name' }); model.activeAnimations.remove(a); // Returns true -
removeAll()
-
Removes all animations from the collection.
This raises the
ModelAnimationCollection#animationRemovedevent for each animation so, for example, a UI can stay in sync.