Access a model's animations
活跃模式动画集.
Model#activeAnimations. Do not call the constructor directly
Members
当真实时,动画即使在场景时间暂停时也会播放. 不过,
动画是否发生取决于动画 分配的时间职能
到模型的动画。 默认,这是基于场景时间,所以模型使用
默认将不会动起来,无论设置如何.
-
Default Value:
false
animationAdded : Event
当动画被添加到收藏中时,事件就开火了. 这个可以用来,用于
例如,保持用户界面同步.
-
Default Value:
new Event()
Example:
model.activeAnimations.animationAdded.addEventListener(function(model, animation) {
console.log(`Animation added: ${animation.name}`);
});
animationRemoved : Event
动画被从收藏中移除后,事件即告发. 这个可以用来,用于
例如,保持用户界面同步.
-
Default Value:
new Event()
Example:
model.activeAnimations.animationRemoved.addEventListener(function(model, animation) {
console.log(`Animation removed: ${animation.name}`);
});
收藏中的动画数量.
readonly model : Model
拥有这本动画集的模型.
Methods
add(options) → ModelAnimation
创建并添加带有指定初始属性的动画到收藏中.
这提升了 ModelAnimationCollection#animationAdded 事件,以例如UI可以保持同步.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
下列属性的对象 :
|
Returns:
收藏中加入的动画.
Throws:
-
DeveloperError : Animations are not loaded. Wait for the
Model#readyto 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>
创建并添加带有指定初始属性的动画到收藏中
用于模型中的所有动画.
This raises the ModelAnimationCollection#animationAdded event for each model so, for example, a UI can stay in sync.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
下列属性的对象 :
|
Returns:
An array of
ModelAnimation objects, one for each animation added to the collection. If there are no glTF animations, the array is empty.
Throws:
-
DeveloperError : Animations are not loaded. Wait for the
Model#readyto return true. -
DeveloperError : options.multiplier must be greater than zero.
Example:
model.activeAnimations.addAll({
multiplier : 0.5, // Play at half-speed
loop : Cesium.ModelAnimationLoop.REPEAT // Loop the animations
});
确定此收藏是否包含给定的动画 .
| Name | Type | Description |
|---|---|---|
runtimeAnimation |
ModelAnimation | 要检查的运行时间动画 . |
Returns:
如果本集包含该动画,则#NT#0 真 NT 1 ,#NT#2 假 NT 3 否则.
get(index) → ModelAnimation
在指定的索引中返回收藏中的动画。 指数为零
并随着动画的添加而增加. 删除动画后的所有动画
在左边,改变他们的指数。 此函数通常用于斜拉
收藏中的所有动画.
| 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. The ModelAnimationCollection#animationRemoved event is still fired when the animation is removed.
| Name | Type | Description |
|---|---|---|
runtimeAnimation |
ModelAnimation | 要删除的运行时间动画 . |
Returns:
如果动画被移除,则使用 NT##0 真 NT 1 ;如果在收藏中找不到动画,则使用 NT 2 假 NT 3 .
Example:
const a = model.activeAnimations.add({
name : 'animation name'
});
model.activeAnimations.remove(a); // Returns true
从收藏中删除所有动画.
This raises the ModelAnimationCollection#animationRemoved event for each
例如,动画可以保持同步.