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
| Param | Type | Description |
|---|---|---|
app | ThreeUseApp | Application instance (used to register render callback) |
root | Object3D | Animation root object |
clips | AnimationClip[] | Array of animation clips |
Return Value
| Property | Type | Description |
|---|---|---|
play | (name) => void | Play the specified animation |
stop | (name?) => void | Stop all or a specific animation |
crossFadeTo | (name, duration?) => void | Cross-fade to target animation |
currentClip | Ref<string> | Currently playing animation name |
isPlaying | ComputedRef<boolean> | Whether animation is playing |