Hello,
I am trying to make a sort of animation controller where I can register and call transitions but am running into an issue with the state switching. When I want to change the animation, I want to wait for the end of the current loop (I will expand this later to also be able to blend immediately) but am unable to figure out why the character is freezeframing in t-pose every so often (when one of the animation clips is loaded after finishing another animation)
Full context of the code:
Component: portfolio-project/three-js-interactive.component.ts at 3b3cefd6214b666b98d2b04780c1d4e309357374 · torbenvanassche/portfolio-project · GitHub
AnimationController: portfolio-project/animation-controller.ts at master · torbenvanassche/portfolio-project · GitHub
playClip = (id: string, once: boolean = false) => {
const activeClip = this.clips.get(id);
if (activeClip !== undefined) {
var lastAction = this.activeAction;
lastAction?.fadeOut(0.01);
this.activeAction = this.mixer.clipAction(activeClip).reset().fadeIn(0.01).play();
if (once) {
this.activeAction.loop = THREE.LoopOnce;
}
}
return this.clipEnded;
}
transition(id: string, playOnce: boolean) {
if(playOnce) {
this.activeAction?.setLoop(THREE.LoopOnce, 1);
}
this.clipEnded?.subscribe(x => {
this.playClip(id);
})
return this.clipEnded;
}
constructor(gltf: GLTF) {
this.mixer.addEventListener('finished', () => {
if (this.activeAction) {
this.clipEnded?.next(this.activeAction);
}
})
this.dog.playClip('sit_idle', false);
window.addEventListener('click', () => {
this.dog.transition('sit_bark', true)?.subscribe(x => {
this.dog.transition('sit_idle', true);
})
})
}
Any feedback/info is appreciated!