访问模型的动画
活跃模型动画的集合。
Model#activeAnimations。请勿直接调用构造函数。
Members
如果为真,即使在场景时间暂停时,动画也会播放。但是,动画是否发生将取决于分配给模型动画的 animationTime 函数。默认情况下,这基于场景时间,因此使用默认设置的模型将不会动画化,不管这个设置如何。
-
Default Value:
false
animationAdded : Event
当动画被添加到集合时触发的事件。这可以用于,例如,保持用户界面同步。
-
Default Value:
new Event()
Example:
model.activeAnimations.animationAdded.addEventListener(function(model, animation) {
console.log(`动画添加:${animation.name}`);
});
animationRemoved : Event
当动画从集合中移除时触发的事件。这可以用于,例如,保持用户界面同步。
-
Default Value:
new Event()
Example:
model.activeAnimations.animationRemoved.addEventListener(function(model, animation) {
console.log(`动画移除:${animation.name}`);
});
集合中的动画数量。
readonly model : Model
拥有此动画集合的模型。
Methods
创建并将具有指定初始属性的动画添加到集合中。
这会触发 ModelAnimationCollection#animationAdded 事件,因此,例如,用户界面可以保持同步。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的对象:
|
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 事件,因此,例如,用户界面可以保持同步。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有以下属性的对象:
|
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 事件,因此,例如,用户界面可以保持同步。
通过将 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 事件,因此,例如,用户界面可以保持同步。
