Skip to main content

Animation

Type

Class

Default Usage

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}
/>
)
}

Methods

NameParametersDescription
constructor(obj: THREE.Mesh | THREE.Group | THREE.Object3D, animations?: THREE.AnimationClip[]) => voidobj is the mesh or group containing the animation; animations optional animation clips array.
set(index: number) => thisindex is the index of the animation to play. The default is 0.
setByName(name: string) => thisname is the name of the animation to play.
setLoop(loop: typeof THREE.LoopOnce | typeof THREE.LoopRepeat | typeof THREE.LoopPingPong) => thisloop is the loop mode. The default is LoopRepeat.
setTimeScale(timeScale: number) => thistimeScale is the time scale of the animation.
setClampWhenFinished(clampWhenFinished: boolean) => thisclampWhenFinished is the clamp when finished of the animation.
play() => voidPlay the animation. Default is the first animation of the mesh contained. If you want to play a specific animation, you need to call set or setByName first.
playAll() => voidPlay all animations of the mesh contained.
stop() => voidStop the animation. Only stop the animation using play method played.
stopAll() => voidStop all animations using playAll method played.
pause() => voidPause the animation. Only pause the animation using play method played.
pauseAll() => voidPause all animations using playAll method played.