English中文

ModelAnimationCollection

internal constructor new Cesium.ModelAnimationCollection()

访问模型的动画 Access a model's animations Model#activeAnimations。不要直接调用构造函数 . Do not call the constructor directly
活动模型动画的集合。 A collection of active model animations.
另见: See:

成员 Members

如果为 true,即使场景时间暂停,动画也会播放。但是,动画是否发生将取决于分配给模型动画的animationTime 函数。默认情况下,这是基于场景时间的,因此无论此设置如何,使用默认值的模型都不会生成动画。 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
当动画添加到集合中时触发该事件。例如,这可用于保持 UI 同步。 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}`);
});
当动画从集合中删除时触发该事件。例如,这可用于保持 UI 同步。 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.
拥有此动画集合的模型。 The model that owns this animation collection.

方法 Methods

创建具有指定初始属性的动画并将其添加到集合中。 Creates and adds an animation with the specified initial properties to the collection.

这提高了 This raises the ModelAnimationCollection#animationAdded 例如,UI 可以保持同步。 event so, for example, a UI can stay in sync.

名称 Name 类型 Type 说明 Description
options object 具有以下属性的对象: Object with the following properties:
名称 Name 类型 Type 默认值 Default 说明 Description
name string 可选 optional 标识动画的 glTF 动画名称。必须定义如果 The glTF animation name that identifies the animation. Must be defined if options.index is undefined.
index number 可选 optional 标识动画的 glTF 动画索引。必须定义如果 The glTF animation index that identifies the animation. Must be defined if options.name is undefined.
startTime JulianDate 可选 optional 开始播放动画的场景时间。当这是 The scene time to start playing the animation. When this is undefined,动画从下一帧开始。 , the animation starts at the next frame.
delay number 0.0 可选 optional 延迟(以秒为单位) The delay, in seconds, from startTime 开始播放。这只会影响动画,如果 to start playing. This will only affect the animation if options.loop 是 ModelAnimationLoop.NONE。 is ModelAnimationLoop.NONE.
stopTime JulianDate 可选 optional 停止播放动画的场景时间。当这是 The scene time to stop playing the animation. When this is undefined,动画将完整播放。 , the animation is played for its full duration.
removeOnStop boolean false 可选 optional When true,动画在停止播放后被删除。这只会影响动画,如果 , the animation is removed after it stops playing. This will only affect the animation if options.loop 是 ModelAnimationLoop.NONE。 is ModelAnimationLoop.NONE.
multiplier number 1.0 可选 optional 值大于 Values greater than 1.0 提高动画相对于场景时钟速度的播放速度;值小于 increase the speed that the animation is played relative to the scene clock speed; values less than 1.0 降低速度。 decrease the speed.
reverse boolean false 可选 optional When true,动画反向播放。 , the animation is played in reverse.
loop ModelAnimationLoop ModelAnimationLoop.NONE 可选 optional 确定动画是否循环以及如何循环。 Determines if and how the animation is looped.
animationTime ModelAnimation.AnimationTimeCallback 可选 optional 如果定义,则计算该动画的本地动画时间。 If defined, computes the local animation time for this animation.
返回: Returns:
添加到集合中的动画。 The animation that was added to the collection.
抛出: Throws:
  • DeveloperError : 动画未加载。等待 : Animations are not loaded. Wait for the Model#ready 返回 true。 to return trues.
  • DeveloperError :options.name 必须是有效的动画名称。 : 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}`);
});
创建具有指定初始属性的动画并将其添加到模型中所有动画的集合中。 Creates and adds animations with the specified initial properties to the collection for all animations in the model.

这提高了 This raises the ModelAnimationCollection#animationAdded 每个模型的事件,因此,例如,UI 可以保持同步。 event for each model so, for example, a UI can stay in sync.

名称 Name 类型 Type 说明 Description
options object 可选 optional 具有以下属性的对象: Object with the following properties:
名称 Name 类型 Type 默认值 Default 说明 Description
startTime JulianDate 可选 optional 开始播放动画的场景时间。当这是 The scene time to start playing the animations. When this is undefined,动画从下一帧开始。 , the animations starts at the next frame.
delay number 0.0 可选 optional 延迟(以秒为单位) The delay, in seconds, from startTime 开始播放。这只会影响动画,如果 to start playing. This will only affect the animation if options.loop 是 ModelAnimationLoop.NONE。 is ModelAnimationLoop.NONE.
stopTime JulianDate 可选 optional 停止播放动画的场景时间。当这是 The scene time to stop playing the animations. When this is undefined,动画将在其整个持续时间内播放。 , the animations are played for its full duration.
removeOnStop boolean false 可选 optional When true,动画在停止播放后被删除。这只会影响动画,如果 , the animations are removed after they stop playing. This will only affect the animation if options.loop 是 ModelAnimationLoop.NONE。 is ModelAnimationLoop.NONE.
multiplier number 1.0 可选 optional 值大于 Values greater than 1.0 提高动画相对于场景时钟速度的播放速度;值小于 increase the speed that the animations play relative to the scene clock speed; values less than 1.0 降低速度。 decrease the speed.
reverse boolean false 可选 optional When true,动画反向播放。 , the animations are played in reverse.
loop ModelAnimationLoop ModelAnimationLoop.NONE 可选 optional 确定动画是否循环以及如何循环。 Determines if and how the animations are looped.
animationTime ModelAnimation.AnimationTimeCallback 可选 optional 如果定义,则计算所有动画的本地动画时间。 If defined, computes the local animation time for all of the animations.
返回: Returns:
一个数组 An array of ModelAnimation 对象,每个添加到集合中的动画都有一个。如果没有 glTF 动画,则数组为空。 objects, one for each animation added to the collection. If there are no glTF animations, the array is empty.
抛出: Throws:
示例: Example:
model.activeAnimations.addAll({
  multiplier : 0.5,                            // Play at half-speed
  loop : Cesium.ModelAnimationLoop.REPEAT      // Loop the animations
});

contains(runtimeAnimation)boolean

确定该集合是否包含给定的动画。 Determines whether this collection contains a given animation.
名称 Name 类型 Type 说明 Description
runtimeAnimation ModelAnimation 要检查的运行时动画。 The runtime animation to check for.
返回: Returns:
true 如果该集合包含动画, if this collection contains the animation, false otherwise.
返回集合中指定索引处的动画。索引从零开始,并随着动画的添加而增加。删除动画会将其后的所有动画向左移动,从而更改其索引。此函数通常用于迭代集合中的所有动画。 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);
}

remove(runtimeAnimation)boolean

从集合中删除动画。 Removes an animation from the collection.

这提高了 This raises the ModelAnimationCollection#animationRemoved 例如,UI 可以保持同步。 event so, for example, a UI can stay in sync.

还可以通过设置从集合中隐式删除动画 An animation can also be implicitly removed from the collection by setting ModelAnimationCollection#removeOnStop to true。的 . The ModelAnimationCollection#animationRemoved 当动画被移除时,事件仍然会被触发。 event is still fired when the animation is removed.

名称 Name 类型 Type 说明 Description
runtimeAnimation ModelAnimation 要删除的运行时动画。 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 ModelAnimationCollection#animationRemoved 每个动画的事件,因此,例如,UI 可以保持同步。 event for each animation so, for example, a UI can stay in sync.

需要帮助吗?获得答案的最快方法是从社区和团队那里获得答案 Need help? The fastest way to get answers is from the community and team on the Cesium Forum.