Skip to content

Commit c6f0a18

Browse files
pandaGaumeDrigax
andauthored
Add support for MaterialId on multiMaterial (#927)
* Add support for MaterialId on multiMaterial On Multi-Material, when user set it's own id, we must access the id using Max meshNode.NodeMaterial.GetMaterialID(i) instead of assign sequential index * Update 3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs * Update 3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs Co-authored-by: Nicholas Barlow <whoisdrigax@gmail.com>
1 parent c6bda67 commit c6f0a18

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,12 +808,14 @@ private void ExtractGeometry(BabylonAbstractMesh babylonAbstractMesh, List<Globa
808808
int indexInFaceIndexesArray = 0;
809809
for (int i = 0; i < multiMatsCount; ++i)
810810
{
811-
int materialId = i;
812811
var indexCount = 0;
813812
var minVertexIndex = int.MaxValue;
814813
var maxVertexIndex = int.MinValue;
814+
// Material Id is 0 if normal material, and GetMaterialID if multi-material
815+
// default is [1,n] increment by 1 but user can decide to change the id (still an int) and set for example [4,3,9,1]
816+
// note that GetMaterialID return the user id minus 1
817+
int materialId = multiMatsCount == 1? i : meshNode.NodeMaterial.GetMaterialID(i);
815818
var subMesh = new BabylonSubMesh { indexStart = indexStart, materialIndex = i };
816-
817819
if (multiMatsCount == 1)
818820
{
819821
for (int j = 0; j < unskinnedMesh.NumberOfFaces; ++j)
@@ -898,10 +900,8 @@ private void ExtractGeometry(BabylonAbstractMesh babylonAbstractMesh, List<Globa
898900
}
899901
}
900902
}
901-
902903
if (indexCount != 0)
903904
{
904-
905905
subMesh.indexCount = indexCount;
906906
subMesh.verticesStart = minVertexIndex;
907907
subMesh.verticesCount = maxVertexIndex - minVertexIndex + 1;

0 commit comments

Comments
 (0)