@@ -306,6 +306,16 @@ public FbxSurfaceMaterial ExportMaterial (Material unityMaterial, FbxScene fbxSc
306
306
return fbxMaterial ;
307
307
}
308
308
309
+ /// <summary>
310
+ /// Sets up the material to polygon mapping for fbxMesh.
311
+ /// To determine which part of the mesh uses which material, look at the submeshes
312
+ /// and which polygons they represent.
313
+ /// Assuming equal number of materials as submeshes, and that they are in the same order.
314
+ /// (i.e. submesh 1 uses material 1)
315
+ /// </summary>
316
+ /// <param name="fbxMesh">Fbx mesh.</param>
317
+ /// <param name="mesh">Mesh.</param>
318
+ /// <param name="materials">Materials.</param>
309
319
private void AssignLayerElementMaterial ( FbxMesh fbxMesh , Mesh mesh , Material [ ] materials )
310
320
{
311
321
// Add FbxLayerElementMaterial to layer 0 of the node
@@ -316,14 +326,15 @@ private void AssignLayerElementMaterial(FbxMesh fbxMesh, Mesh mesh, Material[] m
316
326
}
317
327
318
328
using ( var fbxLayerElement = FbxLayerElementMaterial . Create ( fbxMesh , "Material" ) ) {
319
- // Using all same means that the entire mesh uses the same material
320
329
fbxLayerElement . SetMappingMode ( FbxLayerElement . EMappingMode . eByPolygon ) ;
321
330
fbxLayerElement . SetReferenceMode ( FbxLayerElement . EReferenceMode . eIndexToDirect ) ;
322
331
323
332
FbxLayerElementArray fbxElementArray = fbxLayerElement . GetIndexArray ( ) ;
333
+
334
+ // assuming that each polygon is a triangle
335
+ // TODO: Add support for other mesh topologies (e.g. quads)
324
336
fbxElementArray . SetCount ( mesh . triangles . Length / 3 ) ;
325
337
326
- // Map the entire geometry to the FbxNode material at index 0
327
338
for ( int i = 0 ; i < mesh . subMeshCount ; i ++ ) {
328
339
int start = ( ( int ) mesh . GetIndexStart ( i ) ) / 3 ;
329
340
int count = ( ( int ) mesh . GetIndexCount ( i ) ) / 3 ;
0 commit comments