I am getting the glb file of the model from readyplayerme, I simply import it into blender and export a fbx file. I use that fbx file in Mixamo to get animations. I am using React Three Fibre and I am playing the animations in useEffect, the animations are running fine but when I switch from one animation to another, it goes from animation 1 to T Pose to animation 2. The code for my use Effect is below:
useEffect(() => {
actions[context_.state_].fadeIn(0.5).play();
const index = context_.state_;
console.log("Twice");
return ()=>{
actions[index].fadeOut(1);
}
}, [animationTriggers, actions, mixer, context_.state_]);
The complete code is here
useEffect may be a bit too slow for this purpose - animations run at 60/120 fps, while useEffect depends on react state updates. There may be a noticeable milliseconds’ delay between previous useEffect disposal and new useEffect trigger.
Instead of fading the animations in and out directly in useEffect, consider placing that logic in useFrame - then just control it based on state, ex:
const [animation, setAnimation] = useState("idle");
useFrame(() => {
if (model.userData.currentAnimation === animation) {
return;
}
if (model.userData.currentAnimation) {
actions[model.userData.currentAnimation].fadeOut(1.0);
}
model.userData.currentAnimation = animation;
actions[animation].fadeIn(0.5).play();
});
I don’t think that is the case because, when instead of playing the animation, If I only fadeIn or fadeOut the animation, the character is fixed at T pose, It seems as if fadeIn and fadeOut don’t work at all
I found a problem, don’t know how to fix it. There is an animation clip Armature.quaternion that does not match with any of the bone names, how can I fix this? It is also giving this error:
THREE.PropertyBinding: Trying to update node for track: Armature.quaternion but it wasn’t found.
Maybe that is causing the issue.
For your OP problem, try to reset
the action before you fadeIn
and play
.
e.g.,
See line 117 in the above example. Delete the reset
and see that it goes back into a t-pose at the end of each action.
useEffect(() => {
actions[context_.state_].reset().fadeIn(0.5).play();
console.log(actions[context_.state_]);
const index = context_.state_;
return ()=>{
actions[context_.state_].fadeOut(0.5);
}
}, [context_.state_, actions]);
This is my code, the problem is not that It goes to T-Pose after each animation, the problem is that when I switch from one animation to another, It fadesOut of a T pose at every transition. Instead of fading out of the previous animation.