Skip to content

Commit b2098b5

Browse files
committed
added comments
1 parent 99f8982 commit b2098b5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ public FbxSurfaceMaterial ExportMaterial (Material unityMaterial, FbxScene fbxSc
306306
return fbxMaterial;
307307
}
308308

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>
309319
private void AssignLayerElementMaterial(FbxMesh fbxMesh, Mesh mesh, Material[] materials)
310320
{
311321
// Add FbxLayerElementMaterial to layer 0 of the node
@@ -316,14 +326,15 @@ private void AssignLayerElementMaterial(FbxMesh fbxMesh, Mesh mesh, Material[] m
316326
}
317327

318328
using (var fbxLayerElement = FbxLayerElementMaterial.Create (fbxMesh, "Material")) {
319-
// Using all same means that the entire mesh uses the same material
320329
fbxLayerElement.SetMappingMode (FbxLayerElement.EMappingMode.eByPolygon);
321330
fbxLayerElement.SetReferenceMode (FbxLayerElement.EReferenceMode.eIndexToDirect);
322331

323332
FbxLayerElementArray fbxElementArray = fbxLayerElement.GetIndexArray ();
333+
334+
// assuming that each polygon is a triangle
335+
// TODO: Add support for other mesh topologies (e.g. quads)
324336
fbxElementArray.SetCount (mesh.triangles.Length / 3);
325337

326-
// Map the entire geometry to the FbxNode material at index 0
327338
for (int i = 0; i < mesh.subMeshCount; i++) {
328339
int start = ((int)mesh.GetIndexStart (i))/3;
329340
int count = ((int)mesh.GetIndexCount (i))/3;

0 commit comments

Comments
 (0)