Animation system
import { Actor, AssetLoader, BaseActor, inject } from '@hology/core/gameplay';
import * as THREE from 'three';
@Actor()
class Character extends BaseActor {
private assetLoader = inject(AssetLoader)
private mixer: THREE.AnimationMixer
async onInit(): Promise<void> {
// We load a model by name that has previously been
// imported to the project in the editor.
const model = await this.assetLoader.getModelByAssetName('character-human')
const mesh = model.scene
// Adding the model to the actor's object to be rendered.
this.object.add(mesh)
// Each object to be animated needs its own animation mixer
const mixer = new THREE.AnimationMixer(mesh)
// Find a clip from loaded animations by name
const clip = THREE.AnimationClip.findByName(model.animations, 'idle')
const action = mixer.clipAction(clip)
action.play()
this.mixer = mixer
}
onUpdate(deltaTime: number): void {
this.mixer.update(deltaTime)
}
}
export default CharacterLast updated