ModelAnimationCollection

internal constructor new Cesium.ModelAnimationCollection()

通过 Model#activeAnimations 访问模型的动画。不要直接调用构造函数。
A collection of active model animations.
See:

Members

当为 true 时,即使场景时间处于暂停状态,动画仍会播放。但是, 动画是否发生取决于分配给模型动画的 animationTime 函数。 默认情况下,它基于场景时间,因此使用 默认设置的模型无论此设置如何都不会产生动画。
Default Value: false
当动画被添加到集合时触发的事件。例如, 可用于使 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 Object with the following properties:
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 到开始播放的延迟(秒)。只有当 options.loop 为 ModelAnimationLoop.NONE 时,这才会影响该动画。
stopTime JulianDate optional 停止播放该动画的场景时间。当其为 undefined 时,动画将播放其完整时长。
removeOnStop boolean false optional 当为 true 时,动画在停止播放后被移除。只有当 options.loop 为 ModelAnimationLoop.NONE 时,这才会影响该动画。
multiplier number 1.0 optional 大于 1.0 的值会相对于场景时钟速度加快动画的播放速度;小于 1.0 的值会减慢播放速度。
reverse boolean false optional 当为 true 时,动画将反向播放。
loop ModelAnimationLoop ModelAnimationLoop.NONE optional 决定动画是否循环以及循环方式。
animationTime ModelAnimation.AnimationTimeCallback 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
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}`);
});
为模型中的所有动画创建并将具有指定初始属性的动画添加到集合中。

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

Name Type Description
options object optional Object with the following properties:
Name Type Default Description
startTime JulianDate optional 开始播放这些动画的场景时间。当其为 undefined 时,动画在下一帧开始播放。
delay number 0.0 optionalstartTime 到开始播放的延迟(秒)。只有当 options.loop 为 ModelAnimationLoop.NONE 时,这才会影响该动画。
stopTime JulianDate optional 停止播放这些动画的场景时间。当其为 undefined 时,动画将播放其完整时长。
removeOnStop boolean false optional 当为 true 时,这些动画在停止播放后被移除。只有当 options.loop 为 ModelAnimationLoop.NONE 时,这才会影响该动画。
multiplier number 1.0 optional 大于 1.0 的值会相对于场景时钟速度加快这些动画的播放速度;小于 1.0 的值会减慢播放速度。
reverse boolean false optional 当为 true 时,这些动画将反向播放。
loop ModelAnimationLoop ModelAnimationLoop.NONE optional 决定这些动画是否循环以及循环方式。
animationTime ModelAnimation.AnimationTimeCallback optional 如果已定义,则计算所有动画的局部动画时间。
Returns:
一个 ModelAnimation 对象数组,集合中添加的每个动画对应一个。如果没有 glTF 动画,则数组为空。
Throws:
Example:
model.activeAnimations.addAll({
  multiplier : 0.5,                            // Play at half-speed
  loop : Cesium.ModelAnimationLoop.REPEAT      // Loop the animations
});

contains(runtimeAnimation)boolean

确定此集合是否包含给定的动画。
Name Type Description
runtimeAnimation ModelAnimation 要检查的运行时动画。
Returns:
true 如果此集合包含该动画,否则为 false
返回集合中指定索引处的动画。索引从零开始, 并随动画的添加而增加。移除一个动画会将其后面的 所有动画向左移动,从而改变它们的索引。此函数 通常用于遍历集合中的所有动画。
Name Type Description
index number 动画的从零开始的索引。
Returns:
指定索引处的运行时动画。
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

从集合中移除一个动画。

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

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

Name Type Description
runtimeAnimation ModelAnimation 要移除的运行时动画。
Returns:
true 如果动画已被移除;false 如果集合中未找到该动画。
Example:
const a = model.activeAnimations.add({
  name : 'animation name'
});
model.activeAnimations.remove(a); // Returns true
从集合中移除所有动画。

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

需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。