通过
A collection of active model animations.
Model#activeAnimations 访问模型的动画。不要直接调用构造函数。
Members
当为 true 时,即使场景时间处于暂停状态,动画仍会播放。但是,
动画是否发生取决于分配给模型动画的 animationTime 函数。
默认情况下,它基于场景时间,因此使用
默认设置的模型无论此设置如何都不会产生动画。
-
Default Value:
false
animationAdded : Event
当动画被添加到集合时触发的事件。例如,
可用于使 UI 保持同步。
-
Default Value:
new Event()
Example:
model.activeAnimations.animationAdded.addEventListener(function(model, animation) {
console.log(`Animation added: ${animation.name}`);
});
animationRemoved : Event
当动画从集合中移除时触发的事件。例如,
可用于使 UI 保持同步。
-
Default Value:
new Event()
Example:
model.activeAnimations.animationRemoved.addEventListener(function(model, animation) {
console.log(`Animation removed: ${animation.name}`);
});
集合中的动画数量。
readonly model : Model
拥有此动画集合的模型。
Methods
创建并将具有指定初始属性的动画添加到集合中。
这会触发 ModelAnimationCollection#animationAdded 事件,例如可使 UI 保持同步。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Object with the following properties:
|
Returns:
被添加到集合中的动画。
Throws:
-
DeveloperError : 动画尚未加载。请等待
Model#ready返回 true。 -
DeveloperError : options.name 必须是有效的动画名称。
-
DeveloperError : options.index 必须是有效的动画索引。
-
DeveloperError : 必须定义 options.name 或 options.index 其中之一。
-
DeveloperError : options.multiplier 必须大于零。
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}`);
});
addAll(options) → Array.<ModelAnimation>
为模型中的所有动画创建并将具有指定初始属性的动画添加到集合中。
这会为每个模型触发 ModelAnimationCollection#animationAdded 事件,例如可使 UI 保持同步。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
Object with the following properties:
|
Returns:
一个
ModelAnimation 对象数组,集合中添加的每个动画对应一个。如果没有 glTF 动画,则数组为空。
Throws:
-
DeveloperError : 动画尚未加载。请等待
Model#ready返回 true。 -
DeveloperError : options.multiplier 必须大于零。
Example:
model.activeAnimations.addAll({
multiplier : 0.5, // Play at half-speed
loop : Cesium.ModelAnimationLoop.REPEAT // Loop the animations
});
确定此集合是否包含给定的动画。
| 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);
}
从集合中移除一个动画。
这会触发 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 保持同步。
