7
7
using System . Linq ;
8
8
using UnityEngine . Playables ;
9
9
using UnityEngine . Timeline ;
10
+ using FbxExporters . EditorTools ;
10
11
11
12
namespace FbxExporters
12
13
{
@@ -1922,7 +1923,9 @@ private string GetUniqueName(string name)
1922
1923
protected int ExportTransformHierarchy (
1923
1924
GameObject unityGo , FbxScene fbxScene , FbxNode fbxNodeParent ,
1924
1925
int exportProgress , int objectCount , Vector3 newCenter ,
1925
- TransformExportType exportType = TransformExportType . Local )
1926
+ TransformExportType exportType = TransformExportType . Local ,
1927
+ ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All
1928
+ )
1926
1929
{
1927
1930
int numObjectsExported = exportProgress ;
1928
1931
@@ -1957,9 +1960,45 @@ protected int ExportTransformHierarchy(
1957
1960
1958
1961
fbxNodeParent . AddChild ( fbxNode ) ;
1959
1962
1963
+ // if this object has an LOD group, then export according to the LOD preference setting
1964
+ var lodGroup = unityGo . GetComponent < LODGroup > ( ) ;
1965
+ if ( lodGroup && lodExportType != ExportSettings . LODExportType . All ) {
1966
+ LOD [ ] lods = lodGroup . GetLODs ( ) ;
1967
+
1968
+ // LODs are ordered from highest to lowest.
1969
+ // If exporting lowest LOD, reverse the array
1970
+ if ( lodExportType == ExportSettings . LODExportType . Lowest ) {
1971
+ // reverse the array
1972
+ LOD [ ] tempLods = new LOD [ lods . Length ] ;
1973
+ System . Array . Copy ( lods , tempLods , lods . Length ) ;
1974
+ System . Array . Reverse ( tempLods ) ;
1975
+ lods = tempLods ;
1976
+ }
1977
+
1978
+ for ( int i = 0 ; i < lods . Length ; i ++ ) {
1979
+ var lod = lods [ i ] ;
1980
+ bool exportedRenderer = false ;
1981
+ foreach ( var renderer in lod . renderers ) {
1982
+ // only export if parented under LOD group
1983
+ if ( renderer . transform . parent == unityGo . transform ) {
1984
+ numObjectsExported = ExportTransformHierarchy ( renderer . gameObject , fbxScene , fbxNode , numObjectsExported , objectCount , newCenter , lodExportType : lodExportType ) ;
1985
+ exportedRenderer = true ;
1986
+ } else if ( Verbose ) {
1987
+ Debug . LogFormat ( "FbxExporter: Not exporting LOD {0}: {1}" , i , renderer . name ) ;
1988
+ }
1989
+ }
1990
+
1991
+ // if at least one renderer for this LOD was exported, then we succeeded
1992
+ // so stop exporting.
1993
+ if ( exportedRenderer ) {
1994
+ return numObjectsExported ;
1995
+ }
1996
+ }
1997
+ }
1998
+
1960
1999
// now unityGo through our children and recurse
1961
2000
foreach ( Transform childT in unityGo . transform ) {
1962
- numObjectsExported = ExportTransformHierarchy ( childT . gameObject , fbxScene , fbxNode , numObjectsExported , objectCount , newCenter ) ;
2001
+ numObjectsExported = ExportTransformHierarchy ( childT . gameObject , fbxScene , fbxNode , numObjectsExported , objectCount , newCenter , lodExportType : lodExportType ) ;
1963
2002
}
1964
2003
1965
2004
return numObjectsExported ;
@@ -2665,7 +2704,11 @@ public enum TransformExportType { Local, Global, Reset };
2665
2704
///
2666
2705
/// This refreshes the asset database.
2667
2706
/// </summary>
2668
- public int ExportAll ( IEnumerable < UnityEngine . Object > unityExportSet , Dictionary < GameObject , AnimationOnlyExportData > animationExportData , TransformExportType exportType = TransformExportType . Global )
2707
+ public int ExportAll (
2708
+ IEnumerable < UnityEngine . Object > unityExportSet ,
2709
+ Dictionary < GameObject , AnimationOnlyExportData > animationExportData ,
2710
+ TransformExportType exportType = TransformExportType . Global ,
2711
+ ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All )
2669
2712
{
2670
2713
exportCancelled = false ;
2671
2714
@@ -2780,7 +2823,7 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet, Dictionary
2780
2823
}
2781
2824
else {
2782
2825
exportProgress = this . ExportTransformHierarchy ( unityGo , fbxScene , fbxRootNode ,
2783
- exportProgress , count , center , exportType ) ;
2826
+ exportProgress , count , center , exportType , lodExportType ) ;
2784
2827
}
2785
2828
if ( exportCancelled || exportProgress < 0 ) {
2786
2829
Debug . LogWarning ( "Export Cancelled" ) ;
@@ -3545,7 +3588,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3545
3588
return ;
3546
3589
}
3547
3590
3548
- if ( ExportObjects ( filePath , exportType : exportType ) != null ) {
3591
+ if ( ExportObjects ( filePath , exportType : exportType , lodExportType : ExportSettings . instance . lodExportType ) != null ) {
3549
3592
// refresh the asset database so that the file appears in the
3550
3593
// asset folder view.
3551
3594
AssetDatabase . Refresh ( ) ;
@@ -3556,7 +3599,12 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3556
3599
/// Export a list of (Game) objects to FBX file.
3557
3600
/// Use the SaveFile panel to allow user to enter a file name.
3558
3601
/// <summary>
3559
- public static string ExportObjects ( string filePath , UnityEngine . Object [ ] objects = null , AnimationExportType exportType = AnimationExportType . all , TransformExportType transformExportType = TransformExportType . Global )
3602
+ public static string ExportObjects (
3603
+ string filePath ,
3604
+ UnityEngine . Object [ ] objects = null ,
3605
+ AnimationExportType exportType = AnimationExportType . all ,
3606
+ TransformExportType transformExportType = TransformExportType . Global ,
3607
+ ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All )
3560
3608
{
3561
3609
LastFilePath = filePath ;
3562
3610
@@ -3597,7 +3645,7 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
3597
3645
break ;
3598
3646
}
3599
3647
3600
- if ( fbxExporter . ExportAll ( objects , animationExportData , transformExportType ) > 0 ) {
3648
+ if ( fbxExporter . ExportAll ( objects , animationExportData , transformExportType , lodExportType ) > 0 ) {
3601
3649
string message = string . Format ( "Successfully exported: {0}" , filePath ) ;
3602
3650
UnityEngine . Debug . Log ( message ) ;
3603
3651
@@ -3607,9 +3655,13 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
3607
3655
return null ;
3608
3656
}
3609
3657
3610
- public static string ExportObject ( string filePath , UnityEngine . Object root , AnimationExportType exportType = AnimationExportType . all , TransformExportType transformExportType = TransformExportType . Reset )
3658
+ public static string ExportObject (
3659
+ string filePath , UnityEngine . Object root ,
3660
+ AnimationExportType exportType = AnimationExportType . all ,
3661
+ TransformExportType transformExportType = TransformExportType . Reset ,
3662
+ ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All )
3611
3663
{
3612
- return ExportObjects ( filePath , new Object [ ] { root } , exportType , transformExportType ) ;
3664
+ return ExportObjects ( filePath , new Object [ ] { root } , exportType , transformExportType , lodExportType ) ;
3613
3665
}
3614
3666
3615
3667
private static void EnsureDirectory ( string path )
0 commit comments