mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.75k stars 35.38k forks source link

Wrong animation duration/offsets with FBXLoader #20256

Open FlorentMasson opened 4 years ago

FlorentMasson commented 4 years ago
Description of the problem

I have a FBX file with multiple animations created with Maya. The animations are created on a single timeline and exorted with the Game Exporter - that's the only way I found to pack multiple animations in a single file. image

The animations are messed up with three .js and the duration is wrong. They work great with Windows 3D Viewer. The reason is when loading, times do not necessarily begin at zero.

At this debug point : https://github.com/mrdoob/three.js/blob/ff48de58e216bc72abb4085a080c5acb66f2f584/examples/jsm/loaders/FBXLoader.js#L2685 Here is the track content : image

And the AnimationClip duration is always calculated from offset 0 https://github.com/mrdoob/three.js/blob/cd41804aa436bb2cfd79797c04985f75c4c63e63/src/animation/AnimationClip.js#L403

In relation to https://github.com/mrdoob/three.js/issues/14894 but to me this is not a feature suggestion, it's a bug with the loader. I'm not sure what the exact clean solution should be.

Three.js version
Browser
OS
Hardware Requirements (graphics card, VR Device, ...)
FlorentMasson commented 4 years ago

Adding this

            var minTime = Number.MAX_VALUE;
            tracks.forEach(function (track) {
                minTime = Math.min(track.times[0]);
            });
            tracks.forEach(function (track) {
                for (var i = 0; i < track.times.length; i++) {
                    track.times[i] -= minTime;
                }
            });

before https://github.com/mrdoob/three.js/blob/ff48de58e216bc72abb4085a080c5acb66f2f584/examples/jsm/loaders/FBXLoader.js#L2685 fixes it for me

looeee commented 4 years ago

If I recall the issue was that doing this breaks other files. If you want to create a pull request with your fix I'll double check that and share any models with problems.