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);
});
集合中的动画数量。

Methods

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

这会引发 ModelAnimationCollection#animationAdded 事件,例如,UI可以保持同步。

Name Type Description
options Object 具有以下属性的对象:
名称 类型 默认 说明
名称 字符串 可选 标识动画的glTF动画名称。如果 options.index 是 undefined 。必须定义。
index 数字 可选 标识动画的glTF动画索引。如果 options.name 是 undefined 。必须定义。
startTime JulianDate 可选 开始播放动画的场景时间。如果是 undefined ,则动画将从下一帧开始。
延迟 数字 0.0 可选 从 startTime 开始播放的延迟(以秒为单位)。
stopTime JulianDate 可选 场景时间停止播放动画。 undefined (未定义)时,动画将完整播放。
removeOnStop 布尔值 错误 可选 如果为 true ,则动画将在停止播放后被删除。
乘数 数字 1.0 可选 大于 1.0 的值相对于场景时钟速度提高了动画播放的速度;小于 1.0 的值会降低速度。
reverse 布尔值 错误 可选 当 true 时,动画将反向播放。
loop ModelAnimationLoop ModelAnimationLoop.NONE 可选 确定是否以及如何循环播放动画。
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);
});
创建具有指定初始属性的动画并将其添加到集合中模型中的每个动画。

这会为每个模型引发 ModelAnimationCollection#animationAdded 事件,例如,UI可以保持同步。

Name Type Description
options Object 可选 具有以下属性的对象:
名称 类型 默认 说明
startTime JulianDate 可选 开始播放动画的场景时间。如果是 undefined ,则动画将从下一帧开始。
延迟 数字 0.0 可选 从 startTime 开始播放的延迟(以秒为单位)。
stopTime JulianDate 可选 场景时间停止播放动画。 undefined (未定义)时,动画将完整播放。
removeOnStop 布尔值 错误 可选 如果为 true ,则动画在停止播放后将被删除。
乘数 数字 1.0 可选 大于 1.0 的值可提高动画相对于场景时钟速度的播放速度。小于 1.0 的值会降低速度。
reverse 布尔值 错误 可选 当 true 时,动画将反向播放。
loop ModelAnimationLoop ModelAnimationLoop.NONE 可选 确定是否以及如何循环播放动画。
Returns:
一组 模型动画 对象,每个动画添加到集合中。如果没有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:
真正 如果此集合包含动画, 假 除此以外。
返回指定索引处集合中的动画。指标从零开始并随着动画的添加而增加。删除动画会在之后移动所有动画它在左侧,更改了索引。此函数通常用于迭代集合中的所有动画。
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

从集合中删除动画。

这会引发 ModelAnimationCollection#animationRemoved 事件,例如,UI可以保持同步。

通过将 ModelAnimation#removeOnStop 设置为,也可以从集合中隐式删除动画。 true 。删除动画时,仍会触发 ModelAnimationCollection#animationRemoved 事件。

Name Type Description
animation ModelAnimation 要删除的动画。
Returns:
真正 如果动画被删除; 假 如果在集合中找不到动画。
Example:
var a = model.activeAnimations.add({
  name : 'animation name'
});
model.activeAnimations.remove(a); // Returns true
从集合中删除所有动画。

这会为每个事件引发 ModelAnimationCollection#animationRemoved 事件动画,例如,UI可以保持同步。