@@ -371,6 +371,12 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
371371 var mappingChannels = unskinnedMesh . ActiveMapChannelNum ;
372372 bool hasUV = false ;
373373 bool hasUV2 = false ;
374+ bool hasUV3 = false ;
375+ bool hasUV4 = false ;
376+ bool hasUV5 = false ;
377+ bool hasUV6 = false ;
378+ bool hasUV7 = false ;
379+ bool hasUV8 = false ;
374380 for ( int i = 0 ; i < mappingChannels . Count ; ++ i )
375381 {
376382#if MAX2017 || MAX2018 || MAX2019 || MAX2020 || MAX2021 || MAX2022 || MAX2023 || MAX2024 || MAX2025 || MAX2026
@@ -386,7 +392,33 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
386392 {
387393 hasUV2 = true ;
388394 }
395+ else if ( channelNum == 3 )
396+ {
397+ hasUV3 = true ;
398+ }
399+ else if ( channelNum == 4 )
400+ {
401+ hasUV4 = true ;
402+ }
403+ else if ( channelNum == 5 )
404+ {
405+ hasUV5 = true ;
406+ }
407+ else if ( channelNum == 6 )
408+ {
409+ hasUV6 = true ;
410+ }
411+ else if ( channelNum == 7 )
412+ {
413+ hasUV7 = true ;
414+ }
415+ else if ( channelNum == 8 )
416+ {
417+ hasUV8 = true ;
418+ }
389419 }
420+
421+
390422 var hasColor = unskinnedMesh . NumberOfColorVerts > 0 ;
391423 var hasAlpha = unskinnedMesh . GetNumberOfMapVerts ( - 2 ) > 0 ;
392424
@@ -399,7 +431,7 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
399431 // Compute normals
400432 var subMeshes = new List < BabylonSubMesh > ( ) ;
401433 List < int > faceIndexes = null ;
402- ExtractGeometry ( babylonMesh , vertices , indices , subMeshes , boneIds , skin , unskinnedMesh , invertedWorldMatrix , offsetTM , hasUV , hasUV2 , hasColor , hasAlpha , optimizeVertices , multiMatsCount , meshNode , ref faceIndexes ) ;
434+ ExtractGeometry ( babylonMesh , vertices , indices , subMeshes , boneIds , skin , unskinnedMesh , invertedWorldMatrix , offsetTM , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , optimizeVertices , multiMatsCount , meshNode , ref faceIndexes ) ;
403435
404436 if ( vertices . Count >= 65536 )
405437 {
@@ -434,8 +466,32 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
434466 {
435467 babylonMesh . uvs2 = vertices . SelectMany ( v => new [ ] { v . UV2 . X , 1 - v . UV2 . Y } ) . ToArray ( ) ;
436468 }
469+ if ( hasUV3 )
470+ {
471+ babylonMesh . uvs3 = vertices . SelectMany ( v => new [ ] { v . UV3 . X , 1 - v . UV3 . Y } ) . ToArray ( ) ;
472+ }
473+ if ( hasUV4 )
474+ {
475+ babylonMesh . uvs4 = vertices . SelectMany ( v => new [ ] { v . UV4 . X , 1 - v . UV4 . Y } ) . ToArray ( ) ;
476+ }
477+ if ( hasUV5 )
478+ {
479+ babylonMesh . uvs5 = vertices . SelectMany ( v => new [ ] { v . UV5 . X , 1 - v . UV5 . Y } ) . ToArray ( ) ;
480+ }
481+ if ( hasUV6 )
482+ {
483+ babylonMesh . uvs6 = vertices . SelectMany ( v => new [ ] { v . UV6 . X , 1 - v . UV6 . Y } ) . ToArray ( ) ;
484+ }
485+ if ( hasUV7 )
486+ {
487+ babylonMesh . uvs7 = vertices . SelectMany ( v => new [ ] { v . UV7 . X , 1 - v . UV7 . Y } ) . ToArray ( ) ;
488+ }
489+ if ( hasUV8 )
490+ {
491+ babylonMesh . uvs8 = vertices . SelectMany ( v => new [ ] { v . UV8 . X , 1 - v . UV8 . Y } ) . ToArray ( ) ;
492+ }
437493
438- if ( skin != null )
494+ if ( skin != null )
439495 {
440496 babylonMesh . matricesWeights = vertices . SelectMany ( v => v . Weights . ToArray ( ) ) . ToArray ( ) ;
441497 babylonMesh . matricesIndices = vertices . Select ( v => v . BonesIndices ) . ToArray ( ) ;
@@ -888,11 +944,11 @@ private List<GlobalVertex> ExtractVertices(BabylonAbstractMesh babylonAbstractMe
888944 var offsetTM = GetOffsetTM ( maxMorphTarget , 0 ) ;
889945
890946 var vertices = new List < GlobalVertex > ( ) ;
891- ExtractGeometry ( babylonAbstractMesh , vertices , new List < int > ( ) , new List < BabylonSubMesh > ( ) , null , null , gameMesh , invertedWorldMatrix , offsetTM , false , false , false , false , optimizeVertices , multiMatsCount , maxMorphTarget , ref faceIndexes ) ;
947+ ExtractGeometry ( babylonAbstractMesh , vertices , new List < int > ( ) , new List < BabylonSubMesh > ( ) , null , null , gameMesh , invertedWorldMatrix , offsetTM , false , false , false , false , false , false , false , false , false , false , optimizeVertices , multiMatsCount , maxMorphTarget , ref faceIndexes ) ;
892948 return vertices ;
893949 }
894950
895- private void ExtractGeometry ( BabylonAbstractMesh babylonAbstractMesh , List < GlobalVertex > vertices , List < int > indices , List < BabylonSubMesh > subMeshes , List < int > boneIds , IIGameSkin skin , IIGameMesh unskinnedMesh , IMatrix3 invertedWorldMatrix , IMatrix3 offsetTM , bool hasUV , bool hasUV2 , bool hasColor , bool hasAlpha , bool optimizeVertices , int multiMatsCount , IIGameNode meshNode , ref List < int > faceIndexes )
951+ private void ExtractGeometry ( BabylonAbstractMesh babylonAbstractMesh , List < GlobalVertex > vertices , List < int > indices , List < BabylonSubMesh > subMeshes , List < int > boneIds , IIGameSkin skin , IIGameMesh unskinnedMesh , IMatrix3 invertedWorldMatrix , IMatrix3 offsetTM , bool hasUV , bool hasUV2 , bool hasUV3 , bool hasUV4 , bool hasUV5 , bool hasUV6 , bool hasUV7 , bool hasUV8 , bool hasColor , bool hasAlpha , bool optimizeVertices , int multiMatsCount , IIGameNode meshNode , ref List < int > faceIndexes )
896952 {
897953 Dictionary < GlobalVertex , List < GlobalVertex > > verticesAlreadyExported = null ;
898954
@@ -937,7 +993,7 @@ private void ExtractGeometry(BabylonAbstractMesh babylonAbstractMesh, List<Globa
937993 {
938994 face = unskinnedMesh . GetFace ( faceIndexes [ indexInFaceIndexesArray ++ ] ) ;
939995 }
940- ExtractFace ( skin , unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , vertices , indices , hasUV , hasUV2 , hasColor , hasAlpha , verticesAlreadyExported , ref indexCount , ref minVertexIndex , ref maxVertexIndex , face , boneIds ) ;
996+ ExtractFace ( skin , unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , vertices , indices , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , verticesAlreadyExported , ref indexCount , ref minVertexIndex , ref maxVertexIndex , face , boneIds ) ;
941997 }
942998 }
943999 else
@@ -964,7 +1020,7 @@ private void ExtractGeometry(BabylonAbstractMesh babylonAbstractMesh, List<Globa
9641020 {
9651021 face = unskinnedMesh . GetFace ( faceIndexes [ indexInFaceIndexesArray ++ ] ) ;
9661022 }
967- ExtractFace ( skin , unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , vertices , indices , hasUV , hasUV2 , hasColor , hasAlpha , verticesAlreadyExported , ref indexCount , ref minVertexIndex , ref maxVertexIndex , face , boneIds ) ;
1023+ ExtractFace ( skin , unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , vertices , indices , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , verticesAlreadyExported , ref indexCount , ref minVertexIndex , ref maxVertexIndex , face , boneIds ) ;
9681024 }
9691025 }
9701026 else
@@ -1018,24 +1074,23 @@ private void ExtractGeometry(BabylonAbstractMesh babylonAbstractMesh, List<Globa
10181074 }
10191075 }
10201076 }
1021-
1022- private void ExtractFace ( IIGameSkin skin , IIGameMesh unskinnedMesh , BabylonAbstractMesh babylonAbstractMesh , IMatrix3 invertedWorldMatrix , IMatrix3 offsetTM , List < GlobalVertex > vertices , List < int > indices , bool hasUV , bool hasUV2 , bool hasColor , bool hasAlpha , Dictionary < GlobalVertex , List < GlobalVertex > > verticesAlreadyExported , ref int indexCount , ref int minVertexIndex , ref int maxVertexIndex , IFaceEx face , List < int > boneIds )
1077+ private void ExtractFace ( IIGameSkin skin , IIGameMesh unskinnedMesh , BabylonAbstractMesh babylonAbstractMesh , IMatrix3 invertedWorldMatrix , IMatrix3 offsetTM , List < GlobalVertex > vertices , List < int > indices , bool hasUV , bool hasUV2 , bool hasUV3 , bool hasUV4 , bool hasUV5 , bool hasUV6 , bool hasUV7 , bool hasUV8 , bool hasColor , bool hasAlpha , Dictionary < GlobalVertex , List < GlobalVertex > > verticesAlreadyExported , ref int indexCount , ref int minVertexIndex , ref int maxVertexIndex , IFaceEx face , List < int > boneIds )
10231078 {
10241079 int a , b , c ;
10251080 // parity is TRUE, if determinant negative ( counter-intuitive convention of 3ds max, see docs... :/ )
10261081 if ( invertedWorldMatrix . Parity )
10271082 {
1028- // flipped case: reverse winding order
1029- a = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 0 , vertices , hasUV , hasUV2 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1030- b = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 1 , vertices , hasUV , hasUV2 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1031- c = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 2 , vertices , hasUV , hasUV2 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1083+ // flipped case: reverse winding order
1084+ a = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 0 , vertices , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1085+ b = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 1 , vertices , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1086+ c = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 2 , vertices , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
10321087 }
10331088 else
10341089 {
1035- // normal case
1036- a = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 0 , vertices , hasUV , hasUV2 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1037- b = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 2 , vertices , hasUV , hasUV2 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1038- c = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 1 , vertices , hasUV , hasUV2 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1090+ // normal case
1091+ a = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 0 , vertices , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1092+ b = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 2 , vertices , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
1093+ c = CreateGlobalVertex ( unskinnedMesh , babylonAbstractMesh , invertedWorldMatrix , offsetTM , face , 1 , vertices , hasUV , hasUV2 , hasUV3 , hasUV4 , hasUV5 , hasUV6 , hasUV7 , hasUV8 , hasColor , hasAlpha , verticesAlreadyExported , skin , boneIds ) ;
10391094 }
10401095
10411096 indices . Add ( a ) ;
@@ -1077,7 +1132,7 @@ private void ExtractFace(IIGameSkin skin, IIGameMesh unskinnedMesh, BabylonAbstr
10771132 CheckCancelled ( ) ;
10781133 }
10791134
1080- int CreateGlobalVertex ( IIGameMesh mesh , BabylonAbstractMesh babylonAbstractMesh , IMatrix3 invertedWorldMatrix , IMatrix3 offsetTM , IFaceEx face , int facePart , List < GlobalVertex > vertices , bool hasUV , bool hasUV2 , bool hasColor , bool hasAlpha , Dictionary < GlobalVertex , List < GlobalVertex > > verticesAlreadyExported , IIGameSkin skin , List < int > boneIds )
1135+ int CreateGlobalVertex ( IIGameMesh mesh , BabylonAbstractMesh babylonAbstractMesh , IMatrix3 invertedWorldMatrix , IMatrix3 offsetTM , IFaceEx face , int facePart , List < GlobalVertex > vertices , bool hasUV , bool hasUV2 , bool hasUV3 , bool hasUV4 , bool hasUV5 , bool hasUV6 , bool hasUV7 , bool hasUV8 , bool hasColor , bool hasAlpha , Dictionary < GlobalVertex , List < GlobalVertex > > verticesAlreadyExported , IIGameSkin skin , List < int > boneIds )
10811136 {
10821137 var vertexIndex = ( int ) face . Vert [ facePart ] ;
10831138
@@ -1152,6 +1207,90 @@ int CreateGlobalVertex(IIGameMesh mesh, BabylonAbstractMesh babylonAbstractMesh,
11521207 vertex . UV2 = Loader . Global . Point2 . Create ( texCoord . X , 1 - texCoord . Y ) ;
11531208 }
11541209
1210+ if ( hasUV3 )
1211+ {
1212+ var indices = new int [ 3 ] ;
1213+ unsafe
1214+ {
1215+ fixed ( int * indicesPtr = indices )
1216+ {
1217+ mesh . GetMapFaceIndex ( 3 , face . MeshFaceIndex , new IntPtr ( indicesPtr ) ) ;
1218+ }
1219+ }
1220+ var texCoord = mesh . GetMapVertex ( 3 , indices [ facePart ] ) ;
1221+ vertex . UV3 = Loader . Global . Point2 . Create ( texCoord . X , 1 - texCoord . Y ) ;
1222+ }
1223+
1224+ if ( hasUV4 )
1225+ {
1226+ var indices = new int [ 3 ] ;
1227+ unsafe
1228+ {
1229+ fixed ( int * indicesPtr = indices )
1230+ {
1231+ mesh . GetMapFaceIndex ( 4 , face . MeshFaceIndex , new IntPtr ( indicesPtr ) ) ;
1232+ }
1233+ }
1234+ var texCoord = mesh . GetMapVertex ( 4 , indices [ facePart ] ) ;
1235+ vertex . UV4 = Loader . Global . Point2 . Create ( texCoord . X , 1 - texCoord . Y ) ;
1236+ }
1237+
1238+ if ( hasUV5 )
1239+ {
1240+ var indices = new int [ 3 ] ;
1241+ unsafe
1242+ {
1243+ fixed ( int * indicesPtr = indices )
1244+ {
1245+ mesh . GetMapFaceIndex ( 5 , face . MeshFaceIndex , new IntPtr ( indicesPtr ) ) ;
1246+ }
1247+ }
1248+ var texCoord = mesh . GetMapVertex ( 5 , indices [ facePart ] ) ;
1249+ vertex . UV5 = Loader . Global . Point2 . Create ( texCoord . X , 1 - texCoord . Y ) ;
1250+ }
1251+
1252+ if ( hasUV6 )
1253+ {
1254+ var indices = new int [ 3 ] ;
1255+ unsafe
1256+ {
1257+ fixed ( int * indicesPtr = indices )
1258+ {
1259+ mesh . GetMapFaceIndex ( 6 , face . MeshFaceIndex , new IntPtr ( indicesPtr ) ) ;
1260+ }
1261+ }
1262+ var texCoord = mesh . GetMapVertex ( 6 , indices [ facePart ] ) ;
1263+ vertex . UV6 = Loader . Global . Point2 . Create ( texCoord . X , 1 - texCoord . Y ) ;
1264+ }
1265+
1266+ if ( hasUV7 )
1267+ {
1268+ var indices = new int [ 3 ] ;
1269+ unsafe
1270+ {
1271+ fixed ( int * indicesPtr = indices )
1272+ {
1273+ mesh . GetMapFaceIndex ( 7 , face . MeshFaceIndex , new IntPtr ( indicesPtr ) ) ;
1274+ }
1275+ }
1276+ var texCoord = mesh . GetMapVertex ( 7 , indices [ facePart ] ) ;
1277+ vertex . UV7 = Loader . Global . Point2 . Create ( texCoord . X , 1 - texCoord . Y ) ;
1278+ }
1279+
1280+ if ( hasUV8 )
1281+ {
1282+ var indices = new int [ 3 ] ;
1283+ unsafe
1284+ {
1285+ fixed ( int * indicesPtr = indices )
1286+ {
1287+ mesh . GetMapFaceIndex ( 8 , face . MeshFaceIndex , new IntPtr ( indicesPtr ) ) ;
1288+ }
1289+ }
1290+ var texCoord = mesh . GetMapVertex ( 8 , indices [ facePart ] ) ;
1291+ vertex . UV8 = Loader . Global . Point2 . Create ( texCoord . X , 1 - texCoord . Y ) ;
1292+ }
1293+
11551294 if ( hasColor )
11561295 {
11571296 var vertexColorIndex = ( int ) face . Color [ facePart ] ;
0 commit comments