@@ -60,7 +60,7 @@ protected static Material[] ImportMTLFile(string mtlFilePath) {
6060 currentMaterial . name = data ;
6161 } else if ( lineComponents [ 0 ] == "Kd" ) {
6262 currentMaterial . SetColor ( "_Color" , ParseColor ( lineComponents ) ) ;
63- } else if ( lineComponents [ 0 ] == "map_Kd" ) {
63+ } else if ( lineComponents [ 0 ] == "map_Kd" && lineComponents . Length > 1 ) {
6464 string texturePath = Path . Combine ( workingDirectory , lineComponents [ 1 ] ) ;
6565 string textureType = Path . GetExtension ( texturePath ) ;
6666 if ( textureType == ".png" || textureType == ".jpg" ) {
@@ -240,14 +240,9 @@ public static GameObject Import(StreamReader streamReader, string meshName, stri
240240 if ( objectNames . Count == 0 )
241241 objectNames . Add ( "default" ) ;
242242
243- //build objects
244- GameObject parentObject = new GameObject ( meshName ) ;
245-
246-
243+ GameObject meshGameObject = new GameObject ( meshName ) ;
247244 foreach ( string obj in objectNames ) {
248- GameObject subObject = new GameObject ( obj ) ;
249- subObject . transform . parent = parentObject . transform ;
250- subObject . transform . localScale = new Vector3 ( - 1 , 1 , 1 ) ;
245+ meshGameObject . transform . localScale = new Vector3 ( - 1 , 1 , 1 ) ;
251246 Mesh m = new Mesh ( ) ;
252247 m . name = obj ;
253248 List < Vector3 > processedVertices = new List < Vector3 > ( ) ;
@@ -273,9 +268,7 @@ public static GameObject Import(StreamReader streamReader, string meshName, stri
273268
274269 for ( int i = 0 ; i < indexes . Length ; i ++ ) {
275270 int idx = indexes [ i ] ;
276- //build remap table
277271 if ( remapTable . ContainsKey ( idx ) ) {
278- //ezpz
279272 indexes [ i ] = remapTable [ idx ] ;
280273 } else {
281274 processedVertices . Add ( uvertices [ idx ] ) ;
@@ -306,8 +299,8 @@ public static GameObject Import(StreamReader streamReader, string meshName, stri
306299 m . RecalculateBounds ( ) ;
307300 ;
308301
309- MeshFilter mf = subObject . AddComponent < MeshFilter > ( ) ;
310- MeshRenderer mr = subObject . AddComponent < MeshRenderer > ( ) ;
302+ MeshFilter mf = meshGameObject . AddComponent < MeshFilter > ( ) ;
303+ MeshRenderer mr = meshGameObject . AddComponent < MeshRenderer > ( ) ;
311304
312305 Material [ ] processedMaterials = new Material [ meshMaterialNames . Count ] ;
313306 for ( int i = 0 ; i < meshMaterialNames . Count ; i ++ ) {
@@ -331,7 +324,7 @@ public static GameObject Import(StreamReader streamReader, string meshName, stri
331324
332325 }
333326
334- return parentObject ;
327+ return meshGameObject ;
335328 }
336329
337330 }
0 commit comments