@@ -44,6 +44,8 @@ public class ModelExporter : System.IDisposable
44
44
const string RegexCharStart = "[" ;
45
45
const string RegexCharEnd = "]" ;
46
46
47
+ const int UnitScaleFactor = 100 ;
48
+
47
49
/// <summary>
48
50
/// Create instance of example
49
51
/// </summary>
@@ -359,12 +361,14 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene, b
359
361
}
360
362
fbxMesh . InitControlPoints ( NumControlPoints ) ;
361
363
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.
363
367
foreach ( var controlPoint in ControlPointToIndex . Keys ) {
364
368
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
368
372
) , ControlPointToIndex [ controlPoint ] ) ;
369
373
}
370
374
} else {
@@ -376,9 +380,9 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene, b
376
380
{
377
381
// convert from left to right-handed by negating x (Unity negates x again on import)
378
382
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
382
386
) , v ) ;
383
387
}
384
388
}
@@ -455,8 +459,13 @@ protected void ExportTransform (UnityEngine.Transform unityTransform, FbxNode fb
455
459
456
460
// transfer transform data from Unity to Fbx
457
461
// 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
+ ) ;
460
469
var fbxRotate = new FbxDouble3 ( unityRotate . x , - unityRotate . y , - unityRotate . z ) ;
461
470
var fbxScale = new FbxDouble3 ( unityScale . x , unityScale . y , unityScale . z ) ;
462
471
@@ -621,9 +630,11 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
621
630
fbxSceneInfo . mComment = Comments ;
622
631
fbxScene . SetSceneInfo ( fbxSceneInfo ) ;
623
632
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
625
636
var fbxSettings = fbxScene . GetGlobalSettings ( ) ;
626
- fbxSettings . SetSystemUnit ( FbxSystemUnit . m ) ;
637
+ fbxSettings . SetSystemUnit ( FbxSystemUnit . cm ) ;
627
638
628
639
// The Unity axis system has Y up, Z forward, X to the right (left handed system with odd parity).
629
640
// The Maya axis system has Y up, Z forward, X to the left (right handed system with odd parity).
0 commit comments