Skip to content

Commit

Permalink
Fix incorrect joint orientation for FBX models exported from Maya usi…
Browse files Browse the repository at this point in the history
…ng Joint Orient (#29307)
  • Loading branch information
mwhirls authored Sep 5, 2024
1 parent b19cd6a commit e20e8ae
Showing 1 changed file with 16 additions and 9 deletions.
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

0 comments on commit e20e8ae

Please sign in to comment.