Skip to content

KBE3D / KBCore / Cesium / ModelAnimationCollection

类: ModelAnimationCollection

<div class="notice"> Access a model's animations Model#activeAnimations. Do not call the constructor directly </div>

A collection of active model animations.

属性

animationAdded

animationAdded: Event

The event fired when an animation is added to the collection. This can be used, for example, to keep a UI in sync.

示例

ts
model.activeAnimations.animationAdded.addEventListener(function(model, animation) {
  console.log(`Animation added: ${animation.name}`);
});

animationRemoved

animationRemoved: Event

The event fired when an animation is removed from the collection. This can be used, for example, to keep a UI in sync.

示例

ts
model.activeAnimations.animationRemoved.addEventListener(function(model, animation) {
  console.log(`Animation removed: ${animation.name}`);
});

animateWhilePaused

animateWhilePaused: boolean

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.


length

readonly length: number

The number of animations in the collection.


model

readonly model: Model

The model that owns this animation collection.

方法

add()

add(options: { name?: string; index?: number; startTime?: JulianDate; delay?: number; stopTime?: JulianDate; removeOnStop?: boolean; multiplier?: number; reverse?: boolean; loop?: ModelAnimationLoop; animationTime?: AnimationTimeCallback; }): ModelAnimation

Creates and adds an animation with the specified initial properties to the collection. <p> This raises the ModelAnimationCollection#animationAdded event so, for example, a UI can stay in sync. </p>

参数

options

Object with the following properties:

name?

string

The glTF animation name that identifies the animation. Must be defined if <code>options.index</code> is <code>undefined</code>.

index?

number

The glTF animation index that identifies the animation. Must be defined if <code>options.name</code> is <code>undefined</code>.

startTime?

JulianDate

The scene time to start playing the animation. When this is <code>undefined</code>, the animation starts at the next frame.

delay?

number

The delay, in seconds, from <code>startTime</code> to start playing. This will only affect the animation if <code>options.loop</code> is ModelAnimationLoop.NONE.

stopTime?

JulianDate

The scene time to stop playing the animation. When this is <code>undefined</code>, the animation is played for its full duration.

removeOnStop?

boolean

When <code>true</code>, the animation is removed after it stops playing. This will only affect the animation if <code>options.loop</code> is ModelAnimationLoop.NONE.

multiplier?

number

Values greater than <code>1.0</code> increase the speed that the animation is played relative to the scene clock speed; values less than <code>1.0</code> decrease the speed.

reverse?

boolean

When <code>true</code>, the animation is played in reverse.

loop?

ModelAnimationLoop

Determines if and how the animation is looped.

animationTime?

AnimationTimeCallback

If defined, computes the local animation time for this animation.

返回

ModelAnimation

The animation that was added to the collection.

Examples

ts
// Example 1. Add an animation by name
model.activeAnimations.add({
  name : 'animation name'
});
ts
// Example 2. Add an animation by index
model.activeAnimations.add({
  index : 0
});
ts
// 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()

addAll(options?: { startTime?: JulianDate; delay?: number; stopTime?: JulianDate; removeOnStop?: boolean; multiplier?: number; reverse?: boolean; loop?: ModelAnimationLoop; animationTime?: AnimationTimeCallback; }): ModelAnimation[]

Creates and adds animations with the specified initial properties to the collection for all animations in the model. <p> This raises the ModelAnimationCollection#animationAdded event for each model so, for example, a UI can stay in sync. </p>

参数

options?

Object with the following properties:

startTime?

JulianDate

The scene time to start playing the animations. When this is <code>undefined</code>, the animations starts at the next frame.

delay?

number

The delay, in seconds, from <code>startTime</code> to start playing. This will only affect the animation if <code>options.loop</code> is ModelAnimationLoop.NONE.

stopTime?

JulianDate

The scene time to stop playing the animations. When this is <code>undefined</code>, the animations are played for its full duration.

removeOnStop?

boolean

When <code>true</code>, the animations are removed after they stop playing. This will only affect the animation if <code>options.loop</code> is ModelAnimationLoop.NONE.

multiplier?

number

Values greater than <code>1.0</code> increase the speed that the animations play relative to the scene clock speed; values less than <code>1.0</code> decrease the speed.

reverse?

boolean

When <code>true</code>, the animations are played in reverse.

loop?

ModelAnimationLoop

Determines if and how the animations are looped.

animationTime?

AnimationTimeCallback

If defined, computes the local animation time for all of the animations.

返回

ModelAnimation[]

An array of ModelAnimation objects, one for each animation added to the collection. If there are no glTF animations, the array is empty.

示例

ts
model.activeAnimations.addAll({
  multiplier : 0.5,                            // Play at half-speed
  loop : Cesium.ModelAnimationLoop.REPEAT      // Loop the animations
});

remove()

remove(runtimeAnimation: ModelAnimation): boolean

Removes an animation from the collection. <p> This raises the ModelAnimationCollection#animationRemoved event so, for example, a UI can stay in sync. </p> <p> An animation can also be implicitly removed from the collection by setting ModelAnimationCollection#removeOnStop to <code>true</code>. The ModelAnimationCollection#animationRemoved event is still fired when the animation is removed. </p>

参数

runtimeAnimation

ModelAnimation

The runtime animation to remove.

返回

boolean

true if the animation was removed; false if the animation was not found in the collection.

示例

ts
const a = model.activeAnimations.add({
  name : 'animation name'
});
model.activeAnimations.remove(a); // Returns true

removeAll()

removeAll(): void

Removes all animations from the collection. <p> This raises the ModelAnimationCollection#animationRemoved event for each animation so, for example, a UI can stay in sync. </p>

返回

void


contains()

contains(runtimeAnimation: ModelAnimation): boolean

Determines whether this collection contains a given animation.

参数

runtimeAnimation

ModelAnimation

The runtime animation to check for.

返回

boolean

true if this collection contains the animation, false otherwise.


get()

get(index: number): ModelAnimation

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.

参数

index

number

The zero-based index of the animation.

返回

ModelAnimation

The runtime animation at the specified index.

示例

ts
// 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);
}

构造函数

构造函数

new ModelAnimationCollection(): ModelAnimationCollection

返回

ModelAnimationCollection

KBE3D @3.0.0 Copyright © 2024-present KBE3D