Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FBXLoader: Fix incorrect joint orientation for animated FBX models exported from Maya #29307

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions examples/jsm/loaders/FBXLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
Quaternion,
QuaternionKeyframeTrack,
RepeatWrapping,
SRGBColorSpace,
ShapeUtils,
Skeleton,
SkinnedMesh,
SpotLight,
Expand All @@ -39,10 +41,9 @@ import {
Vector2,
Vector3,
Vector4,
VectorKeyframeTrack,
SRGBColorSpace,
ShapeUtils
VectorKeyframeTrack
} from 'three';

import * as fflate from '../libs/fflate.module.js';
import { NURBSCurve } from '../curves/NURBSCurve.js';

Expand Down Expand Up @@ -1329,7 +1330,7 @@ class FBXTreeParser {
if ( 'InheritType' in modelNode ) transformData.inheritType = parseInt( modelNode.InheritType.value );

if ( 'RotationOrder' in modelNode ) transformData.eulerOrder = getEulerOrder( modelNode.RotationOrder.value );
else transformData.eulerOrder = 'ZYX';
else transformData.eulerOrder = getEulerOrder(0);

if ( 'Lcl_Translation' in modelNode ) transformData.translation = modelNode.Lcl_Translation.value;

Expand Down Expand Up @@ -2809,10 +2810,13 @@ class AnimationParser {

}

// For Maya models using "Joint Orient", Euler order only applies to rotation, not pre/post-rotations
const defaultEulerOrder = getEulerOrder(0);

if ( preRotation !== undefined ) {

preRotation = preRotation.map( MathUtils.degToRad );
preRotation.push( eulerOrder );
preRotation.push( defaultEulerOrder );

preRotation = new Euler().fromArray( preRotation );
preRotation = new Quaternion().setFromEuler( preRotation );
Expand All @@ -2822,7 +2826,7 @@ class AnimationParser {
if ( postRotation !== undefined ) {

postRotation = postRotation.map( MathUtils.degToRad );
postRotation.push( eulerOrder );
postRotation.push( defaultEulerOrder );

postRotation = new Euler().fromArray( postRotation );
postRotation = new Quaternion().setFromEuler( postRotation ).invert();
Expand Down Expand Up @@ -4134,26 +4138,29 @@ function generateTransform( transformData ) {

if ( transformData.translation ) lTranslationM.setPosition( tempVec.fromArray( transformData.translation ) );

// For Maya models using "Joint Orient", Euler order only applies to rotation, not pre/post-rotations
const defaultEulerOrder = getEulerOrder(0);

if ( transformData.preRotation ) {

const array = transformData.preRotation.map( MathUtils.degToRad );
array.push( transformData.eulerOrder || Euler.DEFAULT_ORDER );
array.push( defaultEulerOrder );
lPreRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );

}

if ( transformData.rotation ) {

const array = transformData.rotation.map( MathUtils.degToRad );
array.push( transformData.eulerOrder || Euler.DEFAULT_ORDER );
array.push( transformData.eulerOrder || defaultEulerOrder );
lRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );

}

if ( transformData.postRotation ) {

const array = transformData.postRotation.map( MathUtils.degToRad );
array.push( transformData.eulerOrder || Euler.DEFAULT_ORDER );
array.push( defaultEulerOrder );
lPostRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );
lPostRotationM.invert();

Expand Down