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,43 @@ 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
+ }
1987
+ }
1988
+
1989
+ // if at least one renderer for this LOD was exported, then we succeeded
1990
+ // so stop exporting.
1991
+ if ( exportedRenderer ) {
1992
+ return numObjectsExported ;
1993
+ }
1994
+ }
1995
+ }
1996
+
1960
1997
// now unityGo through our children and recurse
1961
1998
foreach ( Transform childT in unityGo . transform ) {
1962
- numObjectsExported = ExportTransformHierarchy ( childT . gameObject , fbxScene , fbxNode , numObjectsExported , objectCount , newCenter ) ;
1999
+ numObjectsExported = ExportTransformHierarchy ( childT . gameObject , fbxScene , fbxNode , numObjectsExported , objectCount , newCenter , lodExportType : lodExportType ) ;
1963
2000
}
1964
2001
1965
2002
return numObjectsExported ;
@@ -2665,7 +2702,10 @@ public enum TransformExportType { Local, Global, Reset };
2665
2702
///
2666
2703
/// This refreshes the asset database.
2667
2704
/// </summary>
2668
- public int ExportAll ( IEnumerable < UnityEngine . Object > unityExportSet , Dictionary < GameObject , AnimationOnlyExportData > animationExportData )
2705
+ public int ExportAll (
2706
+ IEnumerable < UnityEngine . Object > unityExportSet ,
2707
+ Dictionary < GameObject , AnimationOnlyExportData > animationExportData ,
2708
+ ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All )
2669
2709
{
2670
2710
exportCancelled = false ;
2671
2711
@@ -2782,7 +2822,7 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet, Dictionary
2782
2822
}
2783
2823
else {
2784
2824
exportProgress = this . ExportTransformHierarchy ( unityGo , fbxScene , fbxRootNode ,
2785
- exportProgress , count , center , exportType ) ;
2825
+ exportProgress , count , center , exportType , lodExportType ) ;
2786
2826
}
2787
2827
if ( exportCancelled || exportProgress < 0 ) {
2788
2828
Debug . LogWarning ( "Export Cancelled" ) ;
@@ -3547,7 +3587,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3547
3587
return ;
3548
3588
}
3549
3589
3550
- if ( ExportObjects ( filePath , exportType : exportType ) != null ) {
3590
+ if ( ExportObjects ( filePath , exportType : exportType , lodExportType : ExportSettings . instance . lodExportType ) != null ) {
3551
3591
// refresh the asset database so that the file appears in the
3552
3592
// asset folder view.
3553
3593
AssetDatabase . Refresh ( ) ;
@@ -3558,7 +3598,11 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3558
3598
/// Export a list of (Game) objects to FBX file.
3559
3599
/// Use the SaveFile panel to allow user to enter a file name.
3560
3600
/// <summary>
3561
- public static string ExportObjects ( string filePath , UnityEngine . Object [ ] objects = null , AnimationExportType exportType = AnimationExportType . all )
3601
+ public static string ExportObjects (
3602
+ string filePath ,
3603
+ UnityEngine . Object [ ] objects = null ,
3604
+ AnimationExportType exportType = AnimationExportType . all ,
3605
+ ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All )
3562
3606
{
3563
3607
LastFilePath = filePath ;
3564
3608
@@ -3599,7 +3643,7 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
3599
3643
break ;
3600
3644
}
3601
3645
3602
- if ( fbxExporter . ExportAll ( objects , animationExportData ) > 0 ) {
3646
+ if ( fbxExporter . ExportAll ( objects , animationExportData , lodExportType ) > 0 ) {
3603
3647
string message = string . Format ( "Successfully exported: {0}" , filePath ) ;
3604
3648
UnityEngine . Debug . Log ( message ) ;
3605
3649
@@ -3609,9 +3653,12 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
3609
3653
return null ;
3610
3654
}
3611
3655
3612
- public static string ExportObject ( string filePath , UnityEngine . Object root , AnimationExportType exportType = AnimationExportType . all )
3656
+ public static string ExportObject (
3657
+ string filePath , UnityEngine . Object root ,
3658
+ AnimationExportType exportType = AnimationExportType . all ,
3659
+ ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All )
3613
3660
{
3614
- return ExportObjects ( filePath , new Object [ ] { root } , exportType ) ;
3661
+ return ExportObjects ( filePath , new Object [ ] { root } , exportType , lodExportType ) ;
3615
3662
}
3616
3663
3617
3664
private static void EnsureDirectory ( string path )
0 commit comments