@@ -415,18 +415,35 @@ meshInfo.Vertices [v].z
415
415
}
416
416
417
417
// get a fbxNode's global default position.
418
- protected void ExportTransform ( UnityEngine . Transform unityTransform , FbxNode fbxNode )
418
+ protected void ExportTransform ( UnityEngine . Transform unityTransform , FbxNode fbxNode , TransformExportType exportType )
419
419
{
420
420
// Fbx rotation order is XYZ, but Unity rotation order is ZXY.
421
421
// This causes issues when converting euler to quaternion, causing the final
422
422
// rotation to be slighlty off.
423
423
// Fixed if we set the rotation order to the Unity rotation order in the FBX.
424
424
fbxNode . SetRotationOrder ( FbxNode . EPivotSet . eSourcePivot , FbxEuler . EOrder . eOrderZXY ) ;
425
425
426
- // get local position of fbxNode (from Unity)
427
- UnityEngine . Vector3 unityTranslate = unityTransform . localPosition ;
428
- UnityEngine . Vector3 unityRotate = unityTransform . localRotation . eulerAngles ;
429
- UnityEngine . Vector3 unityScale = unityTransform . localScale ;
426
+ UnityEngine . Vector3 unityTranslate ;
427
+ UnityEngine . Vector3 unityRotate ;
428
+ UnityEngine . Vector3 unityScale ;
429
+
430
+ switch ( exportType ) {
431
+ case TransformExportType . Zeroed :
432
+ unityTranslate = Vector3 . zero ;
433
+ unityRotate = Vector3 . zero ;
434
+ unityScale = Vector3 . one ;
435
+ break ;
436
+ case TransformExportType . Global :
437
+ unityTranslate = unityTransform . position ;
438
+ unityRotate = unityTransform . rotation . eulerAngles ;
439
+ unityScale = unityTransform . lossyScale ;
440
+ break ;
441
+ default : /*case TransformExportType.Local*/
442
+ unityTranslate = unityTransform . localPosition ;
443
+ unityRotate = unityTransform . localRotation . eulerAngles ;
444
+ unityScale = unityTransform . localScale ;
445
+ break ;
446
+ }
430
447
431
448
// transfer transform data from Unity to Fbx
432
449
// Negating the x value of the translation, and the y and z values of the rotation
@@ -446,7 +463,9 @@ protected void ExportTransform (UnityEngine.Transform unityTransform, FbxNode fb
446
463
/// <summary>
447
464
/// Unconditionally export components on this game object
448
465
/// </summary>
449
- protected int ExportComponents ( GameObject unityGo , FbxScene fbxScene , FbxNode fbxNodeParent , int currentIndex , int objectCount )
466
+ protected int ExportComponents (
467
+ GameObject unityGo , FbxScene fbxScene , FbxNode fbxNodeParent ,
468
+ int currentIndex , int objectCount , TransformExportType exportType = TransformExportType . Local )
450
469
{
451
470
int i = currentIndex ;
452
471
@@ -463,7 +482,7 @@ protected int ExportComponents (GameObject unityGo, FbxScene fbxScene, FbxNode
463
482
return - 1 ;
464
483
}
465
484
466
- ExportTransform ( unityGo . transform , fbxNode ) ;
485
+ ExportTransform ( unityGo . transform , fbxNode , exportType ) ;
467
486
468
487
bool weldVertices = FbxExporters . EditorTools . ExportSettings . instance . weldVertices ;
469
488
ExportMesh ( GetMeshInfo ( unityGo ) , fbxNode , fbxScene , weldVertices ) ;
@@ -532,6 +551,8 @@ public static HashSet<GameObject> RemoveDuplicateObjects(IEnumerable<UnityEngine
532
551
return toExport ;
533
552
}
534
553
554
+ public enum TransformExportType { Local , Global , Zeroed } ;
555
+
535
556
/// <summary>
536
557
/// Export all the objects in the set.
537
558
/// Return the number of objects in the set that we exported.
@@ -597,11 +618,24 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
597
618
int i = 0 ;
598
619
var revisedExportSet = RemoveDuplicateObjects ( unityExportSet ) ;
599
620
int count = GetGameObjectCount ( revisedExportSet ) ;
600
- foreach ( var unityGo in revisedExportSet ) {
601
- i = this . ExportComponents ( unityGo , fbxScene , fbxRootNode , i , count ) ;
602
- if ( i < 0 ) {
603
- Debug . LogWarning ( "Export Cancelled" ) ;
604
- return 0 ;
621
+
622
+ if ( revisedExportSet . Count == 1 ) {
623
+ foreach ( var unityGo in revisedExportSet ) {
624
+ i = this . ExportComponents ( unityGo , fbxScene , fbxRootNode , i , count , TransformExportType . Zeroed ) ;
625
+ if ( i < 0 ) {
626
+ Debug . LogWarning ( "Export Cancelled" ) ;
627
+ return 0 ;
628
+ }
629
+ }
630
+ }
631
+ else {
632
+ foreach ( var unityGo in revisedExportSet ) {
633
+ i = this . ExportComponents ( unityGo , fbxScene , fbxRootNode , i , count ,
634
+ unityGo . transform . parent == null ? TransformExportType . Local : TransformExportType . Global ) ;
635
+ if ( i < 0 ) {
636
+ Debug . LogWarning ( "Export Cancelled" ) ;
637
+ return 0 ;
638
+ }
605
639
}
606
640
}
607
641
0 commit comments