add

Creates and adds an animation with the specified initial properties to the collection.

This raises the ModelAnimationCollection.animationAdded event so, for example, a UI can stay in sync.

// 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 = JulianDate.now();

const animation = model.activeAnimations.add({
  name : 'another animation name',
  startTime : startTime,
  delay : 0.0,                                 // Play at startTime (default)
  stopTime : JulianDate.addSeconds(startTime, 4.0, new JulianDate()),
  removeOnStop : false,                        // Do not remove when animation stops (default)
  multiplier : 2.0,                            // Play at double speed
  reverse : true,                              // Play in reverse
  loop : 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}`);
});

Return

The animation that was added to the collection.

See also