Skip to content

useAnimation

Wraps Three.js AnimationMixer to support play, stop, and cross-fade transitions.

Usage

ts
import { useAnimation } from '@threeuse/core'
// gltf is the result from GLTFLoader
const { play, crossFadeTo, currentClip } = useAnimation(app, gltf.scene, gltf.animations)

play('Walk')
setTimeout(() => crossFadeTo('Run', 0.3), 2000)

Parameters

ParamTypeDescription
appThreeUseAppApplication instance (used to register render callback)
rootObject3DAnimation root object
clipsAnimationClip[]Array of animation clips

Return Value

PropertyTypeDescription
play(name) => voidPlay the specified animation
stop(name?) => voidStop all or a specific animation
crossFadeTo(name, duration?) => voidCross-fade to target animation
currentClipRef<string>Currently playing animation name
isPlayingComputedRef<boolean>Whether animation is playing

Released under the MIT License.