@@ -15,7 +15,7 @@ internal partial class BabylonExporter
1515 private MStringArray allMayaInfluenceNames ; // the joint names that influence the mesh (joint with 0 weight included)
1616 private MDoubleArray allMayaInfluenceWeights ; // the joint weights for the vertex (0 weight included)
1717 private Dictionary < string , int > indexByNodeName = new Dictionary < string , int > ( ) ; // contains the node (joint and parents of the current skin) fullPathName and its index
18-
18+
1919 /// <summary>
2020 ///
2121 /// </summary>
@@ -496,7 +496,7 @@ private BabylonNode ExportMesh(MDagPath mDagPath, BabylonScene babylonScene)
496496
497497 var uvSetNames = new MStringArray ( ) ;
498498 mFnMesh . getUVSetNames ( uvSetNames ) ;
499- bool [ ] isUVExportSuccess = new bool [ Math . Min ( uvSetNames . Count , 2 ) ] ;
499+ bool [ ] isUVExportSuccess = new bool [ Math . Min ( uvSetNames . Count , 8 ) ] ;
500500 for ( int indexUVSet = 0 ; indexUVSet < isUVExportSuccess . Length ; indexUVSet ++ )
501501 {
502502 isUVExportSuccess [ indexUVSet ] = true ;
@@ -584,13 +584,36 @@ private BabylonNode ExportMesh(MDagPath mDagPath, BabylonScene babylonScene)
584584 // UVs
585585 if ( uvSetNames . Count > 0 && isUVExportSuccess [ 0 ] )
586586 {
587-
588587 babylonMesh . uvs = vertices . SelectMany ( v => v . UV ) . ToArray ( ) ;
589588 }
590589 if ( uvSetNames . Count > 1 && isUVExportSuccess [ 1 ] )
591590 {
592591 babylonMesh . uvs2 = vertices . SelectMany ( v => v . UV2 ) . ToArray ( ) ;
593592 }
593+ if ( uvSetNames . Count > 2 && isUVExportSuccess [ 2 ] )
594+ {
595+ babylonMesh . uvs3 = vertices . SelectMany ( v => v . UV3 ) . ToArray ( ) ;
596+ }
597+ if ( uvSetNames . Count > 3 && isUVExportSuccess [ 3 ] )
598+ {
599+ babylonMesh . uvs4 = vertices . SelectMany ( v => v . UV4 ) . ToArray ( ) ;
600+ }
601+ if ( uvSetNames . Count > 4 && isUVExportSuccess [ 4 ] )
602+ {
603+ babylonMesh . uvs5 = vertices . SelectMany ( v => v . UV5 ) . ToArray ( ) ;
604+ }
605+ if ( uvSetNames . Count > 5 && isUVExportSuccess [ 5 ] )
606+ {
607+ babylonMesh . uvs6 = vertices . SelectMany ( v => v . UV6 ) . ToArray ( ) ;
608+ }
609+ if ( uvSetNames . Count > 6 && isUVExportSuccess [ 6 ] )
610+ {
611+ babylonMesh . uvs7 = vertices . SelectMany ( v => v . UV7 ) . ToArray ( ) ;
612+ }
613+ if ( uvSetNames . Count > 7 && isUVExportSuccess [ 7 ] )
614+ {
615+ babylonMesh . uvs8 = vertices . SelectMany ( v => v . UV8 ) . ToArray ( ) ;
616+ }
594617
595618 babylonMesh . subMeshes = subMeshes . ToArray ( ) ;
596619
@@ -824,6 +847,37 @@ private void ExtractGeometry(BabylonMesh babylonMesh, MFnMesh mFnMesh, List<Glob
824847
825848 }
826849
850+ /// <summary>
851+ /// Extract vertex UV for the given UV channel.
852+ /// </summary>
853+ /// <param name="mFnMesh"></param>
854+ /// <param name="polygonId">The polygon (face) to examine</param>
855+ /// <param name="vertexIndexLocal">The face-relative (local) vertex id to examine</param>
856+ /// <param name="indexUVSet">Index of the target UV set.</param>
857+ /// <param name="uvSetNames"></param>
858+ /// <param name="isUVExportSuccess"></param>
859+ /// <returns></returns>
860+ private float [ ] ExtractVertexUV ( MFnMesh mFnMesh , int polygonId , int vertexIndexLocal , int indexUVSet , MStringArray uvSetNames , ref bool [ ] isUVExportSuccess )
861+ {
862+ if ( uvSetNames . Count > indexUVSet && isUVExportSuccess [ indexUVSet ] )
863+ {
864+ try
865+ {
866+ float u = 0 , v = 0 ;
867+ mFnMesh . getPolygonUV ( polygonId , vertexIndexLocal , ref u , ref v , uvSetNames [ indexUVSet ] ) ;
868+ return new float [ ] { u , v } ;
869+ }
870+ catch
871+ {
872+ // An exception is raised when a vertex isn't mapped to an UV coordinate
873+ isUVExportSuccess [ indexUVSet ] = false ;
874+ return null ;
875+ }
876+ }
877+
878+ return null ;
879+ }
880+
827881 /// <summary>
828882 /// Extract geometry (position, normal, UVs...) for a specific vertex
829883 /// </summary>
@@ -907,37 +961,14 @@ private GlobalVertex ExtractVertex(MFnMesh mFnMesh, int polygonId, int vertexInd
907961 }
908962 }
909963
910- // UV
911- int indexUVSet = 0 ;
912- if ( uvSetNames . Count > indexUVSet && isUVExportSuccess [ indexUVSet ] )
913- {
914- try
915- {
916- float u = 0 , v = 0 ;
917- mFnMesh . getPolygonUV ( polygonId , vertexIndexLocal , ref u , ref v , uvSetNames [ indexUVSet ] ) ;
918- vertex . UV = new float [ ] { u , v } ;
919- }
920- catch
921- {
922- // An exception is raised when a vertex isn't mapped to an UV coordinate
923- isUVExportSuccess [ indexUVSet ] = false ;
924- }
925- }
926- indexUVSet = 1 ;
927- if ( uvSetNames . Count > indexUVSet && isUVExportSuccess [ indexUVSet ] )
928- {
929- try
930- {
931- float u = 0 , v = 0 ;
932- mFnMesh . getPolygonUV ( polygonId , vertexIndexLocal , ref u , ref v , uvSetNames [ indexUVSet ] ) ;
933- vertex . UV2 = new float [ ] { u , v } ;
934- }
935- catch
936- {
937- // An exception is raised when a vertex isn't mapped to an UV coordinate
938- isUVExportSuccess [ indexUVSet ] = false ;
939- }
940- }
964+ vertex . UV = ExtractVertexUV ( mFnMesh , polygonId , vertexIndexLocal , 0 , uvSetNames , ref isUVExportSuccess ) ; // UV
965+ vertex . UV2 = ExtractVertexUV ( mFnMesh , polygonId , vertexIndexLocal , 1 , uvSetNames , ref isUVExportSuccess ) ; // UV2
966+ vertex . UV3 = ExtractVertexUV ( mFnMesh , polygonId , vertexIndexLocal , 2 , uvSetNames , ref isUVExportSuccess ) ; // UV3
967+ vertex . UV4 = ExtractVertexUV ( mFnMesh , polygonId , vertexIndexLocal , 3 , uvSetNames , ref isUVExportSuccess ) ; // UV4
968+ vertex . UV5 = ExtractVertexUV ( mFnMesh , polygonId , vertexIndexLocal , 4 , uvSetNames , ref isUVExportSuccess ) ; // UV5
969+ vertex . UV6 = ExtractVertexUV ( mFnMesh , polygonId , vertexIndexLocal , 5 , uvSetNames , ref isUVExportSuccess ) ; // UV6
970+ vertex . UV7 = ExtractVertexUV ( mFnMesh , polygonId , vertexIndexLocal , 6 , uvSetNames , ref isUVExportSuccess ) ; // UV7
971+ vertex . UV8 = ExtractVertexUV ( mFnMesh , polygonId , vertexIndexLocal , 7 , uvSetNames , ref isUVExportSuccess ) ; // UV8
941972
942973 // skin
943974 if ( mFnSkinCluster != null )
0 commit comments