I have a gltf file with various related animations. I need to play these animations sequentially on button click.
Am able to loop through the animations but the previous animation endstate is not being maintained. What am I missing?
My code so far:
loader.load( ‘xxx.gltf’, function ( gltf ) {
var animcount = gltf.animations.length;
mixer = new THREE.AnimationMixer( gltf.scene );
nextButton.onclick = function NextAnimation() {
index++;
if(index < animcount ) {
action1 = mixer.clipAction( gltf.animations[ index] );
action1.clampWhenFinished = true;
action1.timeScale = 1;
action1.reset();
action1.setLoop( THREE.LoopOnce )
action1.setDuration(action1._clip.duration)
if(prevAction)
prevAction.fadeOut(0)
action1.play();
scene.add( gltf.scene );
animate();
mixer.addEventListener('finished', () => {
prevAction = action1 // Save a reference to the previous action
})
}
}
});
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.gammaOutput = true;
const controls = new OrbitControls( camera, renderer.domElement );
document.body.appendChild(renderer.domElement);
}