Skip to content

useVRMAnimationManager

A state-machine wrapper for VRM animations. Manages idle loops, crossfading, and automatic return-to-idle when an action finishes.

import { useVRMModel } from 'three-vrm-utils/use-vrm-model'
import { useVRMAnimations } from 'three-vrm-utils/use-vrm-animations'
import { useVRMAnimationManager } from 'three-vrm-utils/use-vrm-animation-manager'
import { useFrame } from '@react-three/fiber'
const motions = {
idle: '/assets/idle.vrma',
wave: '/assets/wave.vrma',
}
function ManagedVRM({ url }: { url: string }) {
const [, vrm] = useVRMModel(url)
const { actions, mixer } = useVRMAnimations(vrm, motions)
const { send } = useVRMAnimationManager(mixer, actions, {
idle: 'idle',
fadeTime: 0.3,
})
useFrame((_, delta) => {
vrm.update(delta)
})
return <primitive object={vrm.scene} onClick={() => send('wave')} />
}
ParameterTypeDescription
mixerAnimationMixer | nullThe mixer from useVRMAnimations
actionsRecord<T, AnimationAction> | nullThe actions from useVRMAnimations
optionsobjectConfiguration options
OptionTypeDefaultDescription
idleT | T[]'idle'Idle animation(s). A single name loops forever; an array plays each once and randomly picks the next
initialTFirst idleState to enter on mount
fadeTimenumber0.3Crossfade duration in seconds
PropertyTypeDescription
send(name: T) => numberTrigger an animation. Returns the clip duration
getState() => T | nullGet the current animation state