@@ -737,5 +737,98 @@ public void TestBlendShapeExport(string fbxPath)
737
737
}
738
738
}
739
739
}
740
+
741
+ [ Test ]
742
+ public void LODExportTest ( ) {
743
+ // Create the following test hierarchy:
744
+ // LODGroup
745
+ // -- Sphere_LOD0
746
+ // -- Capsule_LOD0
747
+ // -- Cube_LOD2
748
+ // Cylinder_LOD1
749
+ //
750
+ // where sphere + capsule renderers are both in LOD0, and cylinder is in LOD1
751
+ // but not parented under the LOD group
752
+
753
+ var lodGroup = new GameObject ( "LODGroup" ) ;
754
+ var sphereLOD0 = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
755
+ sphereLOD0 . name = "Sphere_LOD0" ;
756
+ var capsuleLOD0 = GameObject . CreatePrimitive ( PrimitiveType . Capsule ) ;
757
+ capsuleLOD0 . name = "Capsule_LOD0" ;
758
+ var cubeLOD2 = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
759
+ cubeLOD2 . name = "Cube_LOD2" ;
760
+ var cylinderLOD1 = GameObject . CreatePrimitive ( PrimitiveType . Cylinder ) ;
761
+ cylinderLOD1 . name = "Cylinder_LOD1" ;
762
+
763
+ sphereLOD0 . transform . SetParent ( lodGroup . transform ) ;
764
+ capsuleLOD0 . transform . SetParent ( lodGroup . transform ) ;
765
+ cubeLOD2 . transform . SetParent ( lodGroup . transform ) ;
766
+ cylinderLOD1 . transform . SetParent ( null ) ;
767
+
768
+ // add LOD group
769
+ var lodGroupComp = lodGroup . AddComponent < LODGroup > ( ) ;
770
+ Assert . That ( lodGroupComp , Is . Not . Null ) ;
771
+
772
+ LOD [ ] lods = new LOD [ 3 ] ;
773
+ lods [ 0 ] = new LOD ( 1 , new Renderer [ ] { sphereLOD0 . GetComponent < Renderer > ( ) , capsuleLOD0 . GetComponent < Renderer > ( ) } ) ;
774
+ lods [ 1 ] = new LOD ( 0.75f , new Renderer [ ] { cylinderLOD1 . GetComponent < Renderer > ( ) } ) ;
775
+ lods [ 2 ] = new LOD ( 0.5f , new Renderer [ ] { cubeLOD2 . GetComponent < Renderer > ( ) } ) ;
776
+ lodGroupComp . SetLODs ( lods ) ;
777
+ lodGroupComp . RecalculateBounds ( ) ;
778
+
779
+ // test export all
780
+ // expected LODs exported: Sphere_LOD0, Capsule_LOD0, Cube_LOD2
781
+ string filename = ExportToFbx ( lodGroup , lodExportType : EditorTools . ExportSettings . LODExportType . All ) ;
782
+ GameObject fbxObj = AssetDatabase . LoadMainAssetAtPath ( filename ) as GameObject ;
783
+ Assert . IsTrue ( fbxObj ) ;
784
+
785
+ HashSet < string > expectedChildren = new HashSet < string > ( ) { sphereLOD0 . name , capsuleLOD0 . name , cubeLOD2 . name } ;
786
+ CompareGameObjectChildren ( fbxObj , expectedChildren ) ;
787
+
788
+ // test export highest
789
+ // expected LODs exported: Sphere_LOD0, Capsule_LOD0
790
+ filename = ExportToFbx ( lodGroup , lodExportType : EditorTools . ExportSettings . LODExportType . Highest ) ;
791
+ fbxObj = AssetDatabase . LoadMainAssetAtPath ( filename ) as GameObject ;
792
+ Assert . IsTrue ( fbxObj ) ;
793
+
794
+ expectedChildren = new HashSet < string > ( ) { sphereLOD0 . name , capsuleLOD0 . name } ;
795
+ CompareGameObjectChildren ( fbxObj , expectedChildren ) ;
796
+
797
+ // test export lowest
798
+ // expected LODs exported: Cube_LOD2
799
+ filename = ExportToFbx ( lodGroup , lodExportType : EditorTools . ExportSettings . LODExportType . Lowest ) ;
800
+ fbxObj = AssetDatabase . LoadMainAssetAtPath ( filename ) as GameObject ;
801
+ Assert . IsTrue ( fbxObj ) ;
802
+
803
+ expectedChildren = new HashSet < string > ( ) { cubeLOD2 . name } ;
804
+ CompareGameObjectChildren ( fbxObj , expectedChildren ) ;
805
+
806
+ // test convert to prefab
807
+ // this should have the same result as "export all"
808
+ // expected LODs exported: Sphere_LOD0, Capsule_LOD0, Cube_LOD2
809
+ // NOTE: Cylinder_LOD1 is not exported as it is not under the LODGroup hierarchy being exported
810
+ filename = GetRandomFbxFilePath ( ) ;
811
+ var convertedHierarchy = ConvertToModel . Convert ( lodGroup , fbxFullPath : filename ) ;
812
+ Assert . That ( convertedHierarchy , Is . Not . Null ) ;
813
+
814
+ // check both converted hierarchy and fbx
815
+ expectedChildren = new HashSet < string > ( ) { sphereLOD0 . name , capsuleLOD0 . name , cubeLOD2 . name } ;
816
+ CompareGameObjectChildren ( convertedHierarchy , expectedChildren ) ;
817
+
818
+ fbxObj = AssetDatabase . LoadMainAssetAtPath ( filename ) as GameObject ;
819
+ Assert . IsTrue ( fbxObj ) ;
820
+
821
+ expectedChildren = new HashSet < string > ( ) { sphereLOD0 . name , capsuleLOD0 . name , cubeLOD2 . name } ;
822
+ CompareGameObjectChildren ( fbxObj , expectedChildren ) ;
823
+ }
824
+
825
+ private void CompareGameObjectChildren ( GameObject obj , HashSet < string > expectedChildren ) {
826
+ Assert . That ( obj . transform . childCount , Is . EqualTo ( expectedChildren . Count ) ) ;
827
+
828
+ foreach ( Transform child in obj . transform ) {
829
+ Assert . That ( expectedChildren . Contains ( child . name ) ) ;
830
+ expectedChildren . Remove ( child . name ) ;
831
+ }
832
+ }
740
833
}
741
834
}
0 commit comments