Julio Garcia
Julio Garcia

Reputation: 1954

FBX animations not running properly with three js

I am having an issue with animations on some fbx models. If I have, for example an animation that lasts 20 secs, the model will stay still for 19 secs and then all changes will happen within the last second or so. On other fbx models the animation runs correctly. The code that I am using to run the animation is a follows: The loader.load callback is:

var clock = new THREE.Clock();
var mixers = [];

function(object){
        object.position.set(0,0,0);
        object.mixer = new THREE.AnimationMixer(object);
        mixers.push(object.mixer);
        console.log(object);
        for (var a = 0; a < object.animations.length; a++){
            var action = object.mixer.clipAction(object.animations[a]);
            action.play();
            console.log(action);
        }



        scene.add(object);
        animate();
    }

And the animate code is:

function animate() {
    requestAnimationFrame(animate);
    for(var i = 0; i < mixers.length; i++){
        mixers[i].update(clock.getDelta());
    }
    render();
    stats.update();
}

function render() {
    if (mixer) {
        mixer.update(clock.getDelta());
    }
    renderer.render(scene, camera);
}

Any ideas? Thanks!

Upvotes: 2

Views: 1899

Answers (1)

blueFrog
blueFrog

Reputation: 59

From experience, I can tell you that the fbx ascii export process (at least for Autodesk Maya) doesn't always give either

  1. the correct start and end times set in Maya or
  2. gives a set of numbers that threejs doesn't import properly.

What you end up getting is -- as you describe -- a lot of time in the animation where nothing happens. As far as I've seen, it's usually trailing at the end, but it could certainly be at the beginning as well.

You could fix the fbx file manually, but it might be easier just add a function to set the beginning time to the time of your first frame (and if the first frame is the issue, start with the second frame).

I have the code for this somewhere, let me find it and then I'll add it to this answer.

Upvotes: 3

Related Questions