ModelAnimationCollection

new Cesium.ModelAnimationCollection()

活动模型动画的集合。使用Model#activeAnimations访问。
See:

Members

将动画添加到集合时激发的事件。这可以用来 例如,保持UI同步。
Default Value: new Event()
Example:
model.activeAnimations.animationAdded.addEventListener(function(model, animation) {
  console.log('Animation added: ' + animation.name);
});
从集合中移除动画时激发的事件。这可以用来 例如,保持UI同步。
Default Value: new Event()
Example:
model.activeAnimations.animationRemoved.addEventListener(function(model, animation) {
  console.log('Animation removed: ' + animation.name);
});

readonly length : Number

集合中的动画数。

Methods

创建具有指定初始属性的动画并将其添加到集合中。

This raises the ModelAnimationCollection#animationAdded event so, for example, a UI can stay in sync.

Name Type Description
options Object 具有以下属性的对象:
Name Type Default Description
name String optional 标识动画的glTF动画名称。如果options.indexundefined,则必须定义。
index Number optional 标识动画的glTF动画索引。如果options.nameundefined,则必须定义。
startTime JulianDate optional 开始播放动画的场景时间。当这是undefined时,动画从下一帧开始。
delay Number 0.0 optionalstartTime到开始播放的延迟,以秒为单位。
stopTime JulianDate optional 停止播放动画的场景时间。当此值为undefined时,将播放动画的整个持续时间。
removeOnStop Boolean false optionaltrue时,动画在停止播放后被移除。
multiplier Number 1.0 optional 大于1.0的值会增加动画播放速度(相对于场景时钟速度);小于1.0的值会降低速度。
reverse Boolean false optionaltrue时,动画反向播放。
loop ModelAnimationLoop ModelAnimationLoop.NONE optional 确定是否以及如何循环动画。
Returns:
添加到集合中的动画。
Throws:
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
var startTime = Cesium.JulianDate.now();

var 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);
});
创建具有指定初始属性的动画并将其添加到集合中 对于模型中的每个动画。

This raises the ModelAnimationCollection#animationAdded event for each model so, for example, a UI can stay in sync.

Name Type Description
options Object optional 具有以下属性的对象:
Name Type Default Description
startTime JulianDate optional 开始播放动画的场景时间。当这是undefined时,动画从下一帧开始。
delay Number 0.0 optionalstartTime到开始播放的延迟,以秒为单位。
stopTime JulianDate optional 停止播放动画的场景时间。当此值为undefined时,动画将在整个持续时间内播放。
removeOnStop Boolean false optionaltrue时,动画在停止播放后被移除。
multiplier Number 1.0 optional 大于1.0的值将提高动画相对于场景时钟速度的播放速度;小于1.0的值会降低速度。
reverse Boolean false optionaltrue时,动画反向播放。
loop ModelAnimationLoop ModelAnimationLoop.NONE optional 确定是否以及如何循环动画。
Returns:
ModelAnimation个对象的数组,每个添加到集合中的动画对应一个对象。如果没有glTF动画,则数组为空。
Throws:
Example:
model.activeAnimations.addAll({
  multiplier : 0.5,                        // Play at half-speed
  loop : Cesium.ModelAnimationLoop.REPEAT      // Loop the animations
});

contains(animation)Boolean

确定此集合是否包含给定动画。
Name Type Description
animation ModelAnimation 要检查的动画。
Returns:
如果此集合包含动画,则为true,否则为false
返回集合中指定索引处的动画。指数以零为基础 随着动画的增加而增加。移除动画会在之后移动所有动画 它在左边,改变他们的指数。此函数通常用于迭代 集合中的所有动画。
Name Type Description
index Number 从零开始的动画索引。
Returns:
指定索引处的动画。
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(animation)Boolean

从集合中移除动画。

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.

Name Type Description
animation ModelAnimation 要移除的动画。
Returns:
如果动画已移除,则为true;如果在集合中未找到动画,则为false
Example:
var a = model.activeAnimations.add({
  name : 'animation name'
});
model.activeAnimations.remove(a); // Returns true
从集合中移除所有动画。

This raises the ModelAnimationCollection#animationRemoved event for each animation so, for example, a UI can stay in sync.