Skip to content

Commit f812b0b

Browse files
authored
Merge pull request #28 from Unity-Technologies/UNI-20151-reliable-system-units
UNI-20151 set file units to cm
2 parents dc16093 + 60e874b commit f812b0b

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class ModelExporter : System.IDisposable
4444
const string RegexCharStart = "[";
4545
const string RegexCharEnd = "]";
4646

47+
const int UnitScaleFactor = 100;
48+
4749
/// <summary>
4850
/// Create instance of example
4951
/// </summary>
@@ -359,12 +361,14 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene, b
359361
}
360362
fbxMesh.InitControlPoints (NumControlPoints);
361363

362-
// copy control point data from Unity to FBX
364+
// Copy control point data from Unity to FBX.
365+
// As we do so, scale the points by 100 to convert
366+
// from m to cm.
363367
foreach (var controlPoint in ControlPointToIndex.Keys) {
364368
fbxMesh.SetControlPointAt (new FbxVector4 (
365-
-controlPoint.x,
366-
controlPoint.y,
367-
controlPoint.z
369+
-controlPoint.x*UnitScaleFactor,
370+
controlPoint.y*UnitScaleFactor,
371+
controlPoint.z*UnitScaleFactor
368372
), ControlPointToIndex [controlPoint]);
369373
}
370374
} else {
@@ -376,9 +380,9 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene, b
376380
{
377381
// convert from left to right-handed by negating x (Unity negates x again on import)
378382
fbxMesh.SetControlPointAt(new FbxVector4 (
379-
-meshInfo.Vertices [v].x,
380-
meshInfo.Vertices [v].y,
381-
meshInfo.Vertices [v].z
383+
-meshInfo.Vertices [v].x*UnitScaleFactor,
384+
meshInfo.Vertices [v].y*UnitScaleFactor,
385+
meshInfo.Vertices [v].z*UnitScaleFactor
382386
), v);
383387
}
384388
}
@@ -455,8 +459,13 @@ protected void ExportTransform (UnityEngine.Transform unityTransform, FbxNode fb
455459

456460
// transfer transform data from Unity to Fbx
457461
// Negating the x value of the translation, and the y and z values of the rotation
458-
// to convert from Unity to Maya coordinates (left to righthanded)
459-
var fbxTranslate = new FbxDouble3 (-unityTranslate.x, unityTranslate.y, unityTranslate.z);
462+
// to convert from Unity to Maya coordinates (left to righthanded).
463+
// Scaling the translation by 100 to convert from m to cm.
464+
var fbxTranslate = new FbxDouble3 (
465+
-unityTranslate.x*UnitScaleFactor,
466+
unityTranslate.y*UnitScaleFactor,
467+
unityTranslate.z*UnitScaleFactor
468+
);
460469
var fbxRotate = new FbxDouble3 (unityRotate.x, -unityRotate.y, -unityRotate.z);
461470
var fbxScale = new FbxDouble3 (unityScale.x, unityScale.y, unityScale.z);
462471

@@ -621,9 +630,11 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
621630
fbxSceneInfo.mComment = Comments;
622631
fbxScene.SetSceneInfo (fbxSceneInfo);
623632

624-
// Set up the axes (Y up, Z forward, X to the right) and units (meters)
633+
// Set up the axes (Y up, Z forward, X to the right) and units (centimeters)
634+
// Exporting in centimeters as this is the default unit for FBX files, and easiest
635+
// to work with when importing into Maya or Max
625636
var fbxSettings = fbxScene.GetGlobalSettings ();
626-
fbxSettings.SetSystemUnit (FbxSystemUnit.m);
637+
fbxSettings.SetSystemUnit (FbxSystemUnit.cm);
627638

628639
// The Unity axis system has Y up, Z forward, X to the right (left handed system with odd parity).
629640
// The Maya axis system has Y up, Z forward, X to the left (right handed system with odd parity).

0 commit comments

Comments
 (0)