Overview
TheAnimationManager class handles all animations for 3D objects in Threebox, including:
- Built-in animations from 3D model files (GLTF/GLB, FBX)
- Custom path-following animations
- Transformation animations (position, rotation, scale)
- Animation queuing and playback control
Constructor
Mapbox GL JS map instance
Core Methods
enroll
Enrolls an object for animation management and extends it with animation capabilities.The 3D object to enroll for animation. The object will be extended with:
clock: THREE.Clock instancehasDefaultAnimation: Boolean indicating if model has built-in animationsmixer: THREE.AnimationMixer instance (if animations present)actions: Array of THREE.AnimationAction instancesanimationQueue: Array for queued animations- Animation control methods (see Object Animation Methods below)
unenroll
Removes an object from animation management.The 3D object to remove from animation tracking
update
Updates all enrolled objects’ animations. Called automatically by Threebox on each frame.Current timestamp in milliseconds (typically from
Date.now() or requestAnimationFrame)Object Animation Methods
When an object is enrolled, it receives the following animation methods:set
Animates object to a new state over a specified duration.Animation duration in milliseconds. If 0, changes apply immediately without animation
Target coordinates to animate to
Target rotation in degrees. Can be a single number or per-axis object
Target scale factor. Can be uniform number or per-axis object
followPath
Animates object along a path defined by coordinates.Array of coordinates defining the path
Animation duration in milliseconds
Whether to automatically rotate object to face direction of travel
Function to execute when animation completes
playDefault
Plays the default animation from the 3D model file.How long to play the animation in milliseconds
Playback speed multiplier (e.g., 2 for double speed, 0.5 for half speed)
playAnimation
Plays a specific animation by index from the 3D model.Index of animation to play. If omitted, plays default animation
How long to play the animation in milliseconds
Playback speed multiplier
stop
Stops all animations and clears the animation queue.Animation Control Methods
Fine-grained control over animation actions:Properties
isPlaying
Read-only boolean indicating if object is currently playing an animation.IsPlayingChanged event when state changes.
Events
Animated objects dispatch the following events:IsPlayingChanged
Fired when animation playback state changes.The animated object
ObjectChanged
Fired when object position, rotation, or scale changes during animation.The object that changed
Object containing
position, rotation, and scale valuesUsage Example
Notes
- Animations are queued and executed in order
- Setting
duration: 0inset()applies changes immediately without animation - Built-in model animations require the 3D model to contain animation tracks
- The
trackHeadingoption infollowPathuses quaternion rotation for smooth orientation - Animation mixer updates are tied to the object’s internal clock for accurate timing