@@ -502,47 +502,70 @@ meshInfo.Vertices [v].z*UnitScaleFactor
502
502
return fbxMesh ;
503
503
}
504
504
505
+ /// <summary>
506
+ /// Takes a Quaternion and returns a Euler with XYZ rotation order.
507
+ /// Also converts from left (Unity) to righthanded (Maya) coordinates.
508
+ ///
509
+ /// Note: Cannot simply use the FbxQuaternion.DecomposeSphericalXYZ()
510
+ /// function as this returns the angle in spherical coordinates
511
+ /// instead of Euler angles, which Maya does not import properly.
512
+ /// </summary>
513
+ /// <returns>Euler with XYZ rotation order.</returns>
514
+ public static FbxDouble3 QuaternionToXYZEuler ( Quaternion q )
515
+ {
516
+ FbxQuaternion quat = new FbxQuaternion ( q . x , q . y , q . z , q . w ) ;
517
+ FbxAMatrix m = new FbxAMatrix ( ) ;
518
+ m . SetQ ( quat ) ;
519
+ var vector4 = m . GetR ( ) ;
520
+
521
+ // Negate the y and z values of the rotation to convert
522
+ // from Unity to Maya coordinates (left to righthanded).
523
+ var result = new FbxDouble3 ( vector4 . X , - vector4 . Y , - vector4 . Z ) ;
524
+
525
+ return result ;
526
+ }
527
+
505
528
// get a fbxNode's global default position.
506
529
protected void ExportTransform ( UnityEngine . Transform unityTransform , FbxNode fbxNode , Vector3 newCenter , TransformExportType exportType )
507
530
{
508
531
// Fbx rotation order is XYZ, but Unity rotation order is ZXY.
509
532
// This causes issues when converting euler to quaternion, causing the final
510
533
// rotation to be slighlty off.
511
- // Fixed if we set the rotation order to the Unity rotation order in the FBX .
512
- fbxNode . SetRotationOrder ( FbxNode . EPivotSet . eSourcePivot , FbxEuler . EOrder . eOrderZXY ) ;
534
+ // Fixed by exporting the rotations as eulers with XYZ rotation order.
535
+ fbxNode . SetRotationOrder ( FbxNode . EPivotSet . eSourcePivot , FbxEuler . EOrder . eOrderXYZ ) ;
513
536
514
537
UnityEngine . Vector3 unityTranslate ;
515
- UnityEngine . Vector3 unityRotate ;
538
+ FbxDouble3 unityRotate ;
516
539
UnityEngine . Vector3 unityScale ;
517
540
518
541
switch ( exportType ) {
519
542
case TransformExportType . Reset :
520
543
unityTranslate = Vector3 . zero ;
521
- unityRotate = Vector3 . zero ;
544
+ unityRotate = new FbxDouble3 ( 0 ) ;
522
545
unityScale = Vector3 . one ;
523
546
break ;
524
547
case TransformExportType . Global :
525
548
unityTranslate = GetRecenteredTranslation ( unityTransform , newCenter ) ;
526
- unityRotate = unityTransform . rotation . eulerAngles ;
549
+ unityRotate = QuaternionToXYZEuler ( unityTransform . rotation ) ;
527
550
unityScale = unityTransform . lossyScale ;
528
551
break ;
529
552
default : /*case TransformExportType.Local*/
530
553
unityTranslate = unityTransform . localPosition ;
531
- unityRotate = unityTransform . localRotation . eulerAngles ;
554
+ unityRotate = QuaternionToXYZEuler ( unityTransform . localRotation ) ;
532
555
unityScale = unityTransform . localScale ;
533
556
break ;
534
557
}
535
558
536
559
// transfer transform data from Unity to Fbx
537
- // Negating the x value of the translation, and the y and z values of the rotation
538
- // to convert from Unity to Maya coordinates (left to righthanded).
560
+ // Negating the x value of the translation to convert from Unity
561
+ // to Maya coordinates (left to righthanded).
539
562
// Scaling the translation by 100 to convert from m to cm.
540
563
var fbxTranslate = new FbxDouble3 (
541
564
- unityTranslate . x * UnitScaleFactor ,
542
565
unityTranslate . y * UnitScaleFactor ,
543
566
unityTranslate . z * UnitScaleFactor
544
567
) ;
545
- var fbxRotate = new FbxDouble3 ( unityRotate . x , - unityRotate . y , - unityRotate . z ) ;
568
+ var fbxRotate = unityRotate ;
546
569
var fbxScale = new FbxDouble3 ( unityScale . x , unityScale . y , unityScale . z ) ;
547
570
548
571
// set the local position of fbxNode
@@ -772,6 +795,7 @@ public enum TransformExportType { Local, Global, Reset };
772
795
/// </summary>
773
796
public int ExportAll ( IEnumerable < UnityEngine . Object > unityExportSet )
774
797
{
798
+ exportCancelled = false ;
775
799
Verbose = true ;
776
800
try {
777
801
// Create the FBX manager
0 commit comments