访问模型的动画
活动模型动画的集合。
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 |
对象,具有以下属性:
|
Returns:
已添加到集合中的动画。
Throws:
-
DeveloperError : Animations are not loaded. Wait for the
Model#ready
to return trues. -
DeveloperError : 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}`);
});
addAll(options) → Array.<ModelAnimation>
创建具有指定初始属性的动画并将其添加到集合中
对于模型中的所有动画。
这会为每个模型引发 ModelAnimationCollection#animationAdded
事件,因此,例如,UI 可以保持同步。
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:
如果此集合包含 animation,则为
true
,否则为false
。
返回集合中指定索引处的动画。 索引从 0 开始
并随着动画的添加而增加。 删除动画会在
它向左移动,更改其索引。 此函数通常用于迭代
集合中的所有动画。
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 可以保持同步。