Skip to content

Commit ce517d4

Browse files
authored
Merge pull request #2 from Unity-Technologies/UNI-20449-fix-inverted-triangles
UNI-20449 fix so triangles are not inverted when exported
2 parents 0a50003 + a40aab3 commit ce517d4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Assets/Editor/FbxExporter.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,26 @@ 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-
fbxMesh.SetControlPointAt(new FbxVector4 (meshInfo.Vertices [v].x, meshInfo.Vertices [v].y, meshInfo.Vertices [v].z), v);
207+
// convert from left to right-handed by negating x (Unity negates x again on import)
208+
fbxMesh.SetControlPointAt(new FbxVector4 (-meshInfo.Vertices [v].x, meshInfo.Vertices [v].y, meshInfo.Vertices [v].z), v);
208209
}
209210

210211
ExportUVs (meshInfo, fbxMesh);
211212

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]);
219-
fbxMesh.AddPolygon (meshInfo.Triangles [3 * f + 1]);
220224
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,8 +241,10 @@ protected void ExportTransform (UnityEngine.Transform unityTransform, FbxNode fb
235241
UnityEngine.Vector3 unityScale = unityTransform.localScale;
236242

237243
// transfer transform data from Unity to Fbx
238-
var fbxTranslate = new FbxDouble3 (unityTranslate.x, unityTranslate.y, unityTranslate.z);
239-
var fbxRotate = new FbxDouble3 (unityRotate.x, unityRotate.y, unityRotate.z);
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)
246+
var fbxTranslate = new FbxDouble3 (-unityTranslate.x, unityTranslate.y, unityTranslate.z);
247+
var fbxRotate = new FbxDouble3 (unityRotate.x, -unityRotate.y, -unityRotate.z);
240248
var fbxScale = new FbxDouble3 (unityScale.x, unityScale.y, unityScale.z);
241249

242250
// set the local position of fbxNode

0 commit comments

Comments
 (0)