跳到主要内容

动画

类型

默认用法

import { Scene, GLTFLoader, Animation } from 'react-three-lite'

function App() {
const handleCreated = async (scene, { camera }) => {
scene.position.set(0, -0.5, 0)
camera.position.set(0, 1.5, 3)

const model = await GLTFLoader('/models/perseverance-draco.glb', true)
scene.add(model)

const animation = new Animation(model)
animation.playAll()
}

return (
<Scene
style={{ marginTop: '10px', width: '100%', height: '300px' }}
bgColor="#FAEBD7"
onCreated={handleCreated}
/>
)
}

方法

名称参数描述
constructor(obj: THREE.Mesh | THREE.Group | THREE.Object3D, animations?: THREE.AnimationClip[]) => voidobj 传 THREE.Mesh、THREE.Group 或 THREE.Object3D 对象;animations 可选的动画片段数组。
set(index: number) => thisindex 当前播放的动画索引。
setByName(name: string) => thisname 当前动画的名称。
setLoop(loop: typeof THREE.LoopOnce | typeof THREE.LoopRepeat | typeof THREE.LoopPingPong) => thisloop 当前动画播放循环方式。
setTimeScale(timeScale: number) => thistimeScale 当前动画播放速度。
setClampWhenFinished(clampWhenFinished: boolean) => thisclampWhenFinished 当前动画是否在播放完成时停止。
play() => void播放动画。默认播放 mesh 中第一个动画。如果要播放特定的动画,需要先调用 setsetByName 方法。
playAll() => void播放模型中的所有动画。
stop() => void停止动画,只能停止使用 play 方法播放的动画。
stopAll() => void停止所有动画。只能停止使用 playAll 方法播放的动画。
pause() => void暂停动画,只能暂停使用 play 方法播放的动画。
pauseAll() => void暂停所有动画。只能暂停使用 playAll 方法播放的动画。