Skip to content

Commit a40aab3

Browse files
committed
added comments
1 parent 06bc7ce commit a40aab3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Assets/Editor/FbxExporter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
204204
// copy control point data from Unity to FBX
205205
for (int v = 0; v < NumControlPoints; v++)
206206
{
207+
// convert from left to right-handed by negating x (Unity negates x again on import)
207208
fbxMesh.SetControlPointAt(new FbxVector4 (-meshInfo.Vertices [v].x, meshInfo.Vertices [v].y, meshInfo.Vertices [v].z), v);
208209
}
209210

@@ -212,12 +213,17 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
212213
var fbxMaterial = ExportMaterial (meshInfo.Material, fbxScene);
213214
fbxNode.AddMaterial (fbxMaterial);
214215

216+
/*
217+
* Triangles have to be added in reverse order,
218+
* or else they will be inverted on import
219+
* (due to the conversion from left to right handed coords)
220+
*/
215221
for (int f = 0; f < meshInfo.Triangles.Length / 3; f++)
216222
{
217223
fbxMesh.BeginPolygon ();
218-
fbxMesh.AddPolygon (meshInfo.Triangles [3 * f + 2]);
219-
fbxMesh.AddPolygon (meshInfo.Triangles [3 * f + 1]);
220-
fbxMesh.AddPolygon (meshInfo.Triangles [3 * f]);
224+
fbxMesh.AddPolygon (meshInfo.Triangles [3 * f + 2]);
225+
fbxMesh.AddPolygon (meshInfo.Triangles [3 * f + 1]);
226+
fbxMesh.AddPolygon (meshInfo.Triangles [3 * f]);
221227
fbxMesh.EndPolygon ();
222228
}
223229

@@ -235,6 +241,8 @@ protected void ExportTransform (UnityEngine.Transform unityTransform, FbxNode fb
235241
UnityEngine.Vector3 unityScale = unityTransform.localScale;
236242

237243
// transfer transform data from Unity to Fbx
244+
// Negating the x value of the translation, and the y and z values of the rotation
245+
// to convert from Unity to Maya coordinates (left to righthanded)
238246
var fbxTranslate = new FbxDouble3 (-unityTranslate.x, unityTranslate.y, unityTranslate.z);
239247
var fbxRotate = new FbxDouble3 (unityRotate.x, -unityRotate.y, -unityRotate.z);
240248
var fbxScale = new FbxDouble3 (unityScale.x, unityScale.y, unityScale.z);

0 commit comments

Comments
 (0)