So I’ve downloaded a mixamo character and, separately, an animation pack. I’ve set up a scene with lights, cameras, textured ground and all. I load all the animations and then, I play one of the animations. I setup an eventListener
to tell me when the animation ends (All this is working!) THEN I attempt to crossFadeTo
a random endAction.
HERE the character fades to its tpose (this is not what I want). Here is the relevant code:
loadAnimations(){
const loader = new FBXLoader();
var that = this;
for(var i=0;i<this.animationFiles.length;i++){
loader.load(that.animationFiles[i],
function(animObj){
that.animations.push(animObj.animations[0]);
},
function(){
console.log(Math.round(100*((that.animations.length+1)/that.animationFiles.length))+'% loaded');
if((that.animations.length+1)==that.animationFiles.length) {
that.finishedLoading.bind(that)
that.finishedLoading();
}
}
);
}
}
finishedLoading(a){
console.log(this.animations)
this.tpose.animations = this.animations;
this.mixer = new THREE.AnimationMixer(this.tpose);
this.action = this.mixer.clipAction(this.tpose.animations[1]);
this.action.play();
this.mixer.addEventListener('loop',this.animationEnd.bind(this));
}
animationEnd(){
console.log('animation end');
var i= Math.floor(Math.random()*this.tpose.animations.length);
console.log('playing animation#'+i);
const endAction = this.mixer.clipAction(this.tpose.animations[i]);
endAction.enabled = true;
endAction.setEffectiveTimeScale(1);
endAction.setEffectiveWeight(1);
endAction.time = 0;
endAction.weight=1;
this.action.crossFadeTo ( endAction, 1, true);
}
I got all the endAction
stuff in animationEnd()
from various examples online. In particular, I gather from this that its especially important to set the weight
to 1.