@@ -395,11 +395,14 @@ private void AssignLayerElementMaterial(FbxMesh fbxMesh, Mesh mesh, int material
395
395
396
396
FbxLayerElementArray fbxElementArray = fbxLayerElement . GetIndexArray ( ) ;
397
397
398
- for ( int i = 0 ; i < mesh . subMeshCount ; i ++ ) {
399
- var topology = mesh . GetTopology ( i ) ;
398
+ for ( int subMeshIndex = 0 ; subMeshIndex < mesh . subMeshCount ; subMeshIndex ++ ) {
399
+ var topology = mesh . GetTopology ( subMeshIndex ) ;
400
400
int polySize ;
401
401
402
402
switch ( topology ) {
403
+ case MeshTopology . Triangles :
404
+ polySize = 3 ;
405
+ break ;
403
406
case MeshTopology . Quads :
404
407
polySize = 4 ;
405
408
break ;
@@ -412,14 +415,16 @@ private void AssignLayerElementMaterial(FbxMesh fbxMesh, Mesh mesh, int material
412
415
case MeshTopology . LineStrip :
413
416
throw new System . NotImplementedException ( ) ;
414
417
break ;
415
- default : /* MeshTopology.Triangles */
416
- polySize = 3 ;
418
+ default :
419
+ throw new System . NotImplementedException ( ) ;
417
420
break ;
418
421
}
419
422
420
- var indices = mesh . GetIndices ( i ) ;
421
- for ( int j = 0 ; j < indices . Length / polySize ; j ++ ) {
422
- fbxElementArray . Add ( i ) ;
423
+ // Specify the material index for each polygon.
424
+ // Material index should match subMeshIndex.
425
+ var indices = mesh . GetIndices ( subMeshIndex ) ;
426
+ for ( int j = 0 , n = indices . Length / polySize ; j < n ; j ++ ) {
427
+ fbxElementArray . Add ( subMeshIndex ) ;
423
428
}
424
429
}
425
430
}
@@ -500,9 +505,14 @@ meshInfo.Vertices [v].z*UnitScaleFactor
500
505
int [ ] vertOrder ;
501
506
502
507
switch ( topology ) {
508
+ case MeshTopology . Triangles :
509
+ polySize = 3 ;
510
+ // flip winding order so that Maya and Unity import it properly
511
+ vertOrder = new int [ ] { 0 , 2 , 1 } ;
512
+ break ;
503
513
case MeshTopology . Quads :
504
514
polySize = 4 ;
505
- // vertices have to be reordered as this gets flipped back during import
515
+ // flip winding order so that Maya and Unity import it properly
506
516
vertOrder = new int [ ] { 0 , 3 , 2 , 1 } ;
507
517
break ;
508
518
case MeshTopology . Lines :
@@ -514,11 +524,8 @@ meshInfo.Vertices [v].z*UnitScaleFactor
514
524
case MeshTopology . LineStrip :
515
525
throw new System . NotImplementedException ( ) ;
516
526
break ;
517
- default : /* MeshTopology.Triangles */
518
- polySize = 3 ;
519
- // triangle vertices have to be reordered to be 0,2,1 instead
520
- // of 0,1,2, as this gets flipped back during import
521
- vertOrder = new int [ ] { 0 , 2 , 1 } ;
527
+ default :
528
+ throw new System . NotImplementedException ( ) ;
522
529
break ;
523
530
}
524
531
0 commit comments