@@ -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,24 +463,26 @@ 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 exportProgress , int objectCount , TransformExportType exportType = TransformExportType . Local )
450
469
{
451
- int i = currentIndex ;
470
+ int numObjectsExported = exportProgress ;
452
471
453
472
// create an FbxNode and add it as a child of parent
454
473
FbxNode fbxNode = FbxNode . Create ( fbxScene , unityGo . name ) ;
455
474
NumNodes ++ ;
456
475
457
- i ++ ;
476
+ numObjectsExported ++ ;
458
477
if ( EditorUtility . DisplayCancelableProgressBar (
459
478
ProgressBarTitle ,
460
- string . Format ( "Creating FbxNode {0}/{1}" , i , objectCount ) ,
461
- ( i / ( float ) objectCount ) * 0.5f ) ) {
479
+ string . Format ( "Creating FbxNode {0}/{1}" , numObjectsExported , objectCount ) ,
480
+ ( numObjectsExported / ( float ) objectCount ) * 0.5f ) ) {
462
481
// cancel silently
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 ) ;
@@ -475,9 +494,9 @@ protected int ExportComponents (GameObject unityGo, FbxScene fbxScene, FbxNode
475
494
476
495
// now unityGo through our children and recurse
477
496
foreach ( Transform childT in unityGo . transform ) {
478
- i = ExportComponents ( childT . gameObject , fbxScene , fbxNode , i , objectCount ) ;
497
+ numObjectsExported = ExportComponents ( childT . gameObject , fbxScene , fbxNode , numObjectsExported , objectCount ) ;
479
498
}
480
- return i ;
499
+ return numObjectsExported ;
481
500
}
482
501
483
502
/// <summary>
@@ -538,6 +557,8 @@ public static HashSet<GameObject> RemoveRedundantObjects(IEnumerable<UnityEngine
538
557
return toExport ;
539
558
}
540
559
560
+ public enum TransformExportType { Local , Global , Zeroed } ;
561
+
541
562
/// <summary>
542
563
/// Export all the objects in the set.
543
564
/// Return the number of objects in the set that we exported.
@@ -600,14 +621,28 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
600
621
601
622
// export set of object
602
623
FbxNode fbxRootNode = fbxScene . GetRootNode ( ) ;
603
- int i = 0 ;
624
+ // stores how many objects we have exported, -1 if export was cancelled
625
+ int exportProgress = 0 ;
604
626
var revisedExportSet = RemoveRedundantObjects ( unityExportSet ) ;
605
627
int count = GetHierarchyCount ( revisedExportSet ) ;
606
- foreach ( var unityGo in revisedExportSet ) {
607
- i = this . ExportComponents ( unityGo , fbxScene , fbxRootNode , i , count ) ;
608
- if ( i < 0 ) {
609
- Debug . LogWarning ( "Export Cancelled" ) ;
610
- return 0 ;
628
+
629
+ if ( revisedExportSet . Count == 1 ) {
630
+ foreach ( var unityGo in revisedExportSet ) {
631
+ exportProgress = this . ExportComponents ( unityGo , fbxScene , fbxRootNode , exportProgress , count , TransformExportType . Zeroed ) ;
632
+ if ( exportProgress < 0 ) {
633
+ Debug . LogWarning ( "Export Cancelled" ) ;
634
+ return 0 ;
635
+ }
636
+ }
637
+ }
638
+ else {
639
+ foreach ( var unityGo in revisedExportSet ) {
640
+ exportProgress = this . ExportComponents ( unityGo , fbxScene , fbxRootNode , exportProgress , count ,
641
+ unityGo . transform . parent == null ? TransformExportType . Local : TransformExportType . Global ) ;
642
+ if ( exportProgress < 0 ) {
643
+ Debug . LogWarning ( "Export Cancelled" ) ;
644
+ return 0 ;
645
+ }
611
646
}
612
647
}
613
648
0 commit comments