Skip to content

useAnimation

封装 Three.js AnimationMixer,支持播放、停止和交叉过渡动画。

用法

ts
import { useAnimation } from '@threeuse/core'
// gltf 是 GLTFLoader 加载的结果
const { play, crossFadeTo, currentClip } = useAnimation(app, gltf.scene, gltf.animations)

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

参数

参数类型说明
appThreeUseApp应用实例(用于注册渲染回调)
rootObject3D动画根对象
clipsAnimationClip[]动画剪辑数组

返回值

属性类型说明
play(name) => void播放指定动画
stop(name?) => void停止(全部或指定动画)
crossFadeTo(name, duration?) => void交叉淡入目标动画
currentClipRef<string>当前播放的动画名
isPlayingComputedRef<boolean>是否在播放

Released under the MIT License.