Skip to content

Commit 4d4a46a

Browse files
committed
added comments + move add material before add polygon
1 parent 578d54e commit 4d4a46a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,17 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
242242

243243
// copy control point data from Unity to FBX
244244
for (int v = 0; v < meshInfo.VertexCount; v++) {
245+
// convert from left to right-handed by negating x (Unity negates x again on import)
245246
fbxMesh.SetControlPointAt (new FbxVector4 (
246247
-meshInfo.Vertices [v].x,
247248
meshInfo.Vertices [v].y,
248249
meshInfo.Vertices [v].z
249250
), v);
250251
}
251252

253+
var fbxMaterial = ExportMaterial (meshInfo.Material, fbxScene);
254+
fbxNode.AddMaterial (fbxMaterial);
255+
252256
/*
253257
* Triangles have to be added in reverse order,
254258
* or else they will be inverted on import
@@ -259,6 +263,8 @@ meshInfo.Vertices [v].z
259263
for (int f = 0; f < meshInfo.Triangles.Length / 3; f++) {
260264
fbxMesh.BeginPolygon ();
261265

266+
// triangle vertices have to be reordered to be 0,2,1 instead
267+
// of 0,1,2, as this gets flipped back during import
262268
foreach (int val in new int[]{0,2,1}) {
263269
int tri = meshInfo.Triangles [3 * f + val];
264270
fbxMesh.AddPolygon (tri);
@@ -273,9 +279,6 @@ meshInfo.Vertices [v].z
273279

274280
ExportUVsAndNormals (meshInfo, fbxMesh, fbxTriangles);
275281

276-
var fbxMaterial = ExportMaterial (meshInfo.Material, fbxScene);
277-
fbxNode.AddMaterial (fbxMaterial);
278-
279282
// set the fbxNode containing the mesh
280283
fbxNode.SetNodeAttribute (fbxMesh);
281284
fbxNode.SetShadingMode (FbxNode.EShadingMode.eWireFrame);

0 commit comments

Comments
 (0)