Skip to content

Commit ae61baa

Browse files
committed
set file units to cm
scale vertices and translation
1 parent 329cfd3 commit ae61baa

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,14 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene, b
351351
}
352352
fbxMesh.InitControlPoints (NumControlPoints);
353353

354-
// copy control point data from Unity to FBX
354+
// Copy control point data from Unity to FBX.
355+
// As we do so, scale the points by 100 to convert
356+
// from m to cm.
355357
foreach (var controlPoint in ControlPointToIndex.Keys) {
356358
fbxMesh.SetControlPointAt (new FbxVector4 (
357-
-controlPoint.x,
358-
controlPoint.y,
359-
controlPoint.z
359+
-controlPoint.x*100,
360+
controlPoint.y*100,
361+
controlPoint.z*100
360362
), ControlPointToIndex [controlPoint]);
361363
}
362364
} else {
@@ -368,9 +370,9 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene, b
368370
{
369371
// convert from left to right-handed by negating x (Unity negates x again on import)
370372
fbxMesh.SetControlPointAt(new FbxVector4 (
371-
-meshInfo.Vertices [v].x,
372-
meshInfo.Vertices [v].y,
373-
meshInfo.Vertices [v].z
373+
-meshInfo.Vertices [v].x*100,
374+
meshInfo.Vertices [v].y*100,
375+
meshInfo.Vertices [v].z*100
374376
), v);
375377
}
376378
}
@@ -447,8 +449,9 @@ protected void ExportTransform (UnityEngine.Transform unityTransform, FbxNode fb
447449

448450
// transfer transform data from Unity to Fbx
449451
// Negating the x value of the translation, and the y and z values of the rotation
450-
// to convert from Unity to Maya coordinates (left to righthanded)
451-
var fbxTranslate = new FbxDouble3 (-unityTranslate.x, unityTranslate.y, unityTranslate.z);
452+
// to convert from Unity to Maya coordinates (left to righthanded).
453+
// Scaling the translation by 100 to convert from m to cm.
454+
var fbxTranslate = new FbxDouble3 (-unityTranslate.x*100, unityTranslate.y*100, unityTranslate.z*100);
452455
var fbxRotate = new FbxDouble3 (unityRotate.x, -unityRotate.y, -unityRotate.z);
453456
var fbxScale = new FbxDouble3 (unityScale.x, unityScale.y, unityScale.z);
454457

@@ -609,9 +612,11 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
609612
fbxSceneInfo.mComment = Comments;
610613
fbxScene.SetSceneInfo (fbxSceneInfo);
611614

612-
// Set up the axes (Y up, Z forward, X to the right) and units (meters)
615+
// Set up the axes (Y up, Z forward, X to the right) and units (centimeters)
616+
// Exporting in centimeters as this is the default unit for FBX files, and easiest
617+
// to work with when importing into Maya or Max
613618
var fbxSettings = fbxScene.GetGlobalSettings ();
614-
fbxSettings.SetSystemUnit (FbxSystemUnit.m);
619+
fbxSettings.SetSystemUnit (FbxSystemUnit.cm);
615620

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

0 commit comments

Comments
 (0)