Skip to content

Commit 2d18ef0

Browse files
authored
Merge pull request #312 from Unity-Technologies/UNI-39347-export-model-global-transform
Uni 39347 export model global transform
2 parents 4fab4e0 + 0f80d44 commit 2d18ef0

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public static string[] DCCVendorLocations
431431

432432
// Note: default values are set in LoadDefaults().
433433
public bool mayaCompatibleNames = true;
434-
public bool centerObjects = true;
434+
public bool centerObjects = false;
435435
public bool autoUpdaterEnabled = true;
436436
public bool launchAfterInstallation = true;
437437
public bool HideSendToUnityMenu = true;

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,7 @@ public enum TransformExportType { Local, Global, Reset };
26652665
///
26662666
/// This refreshes the asset database.
26672667
/// </summary>
2668-
public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet, Dictionary<GameObject, AnimationOnlyExportData> animationExportData)
2668+
public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet, Dictionary<GameObject, AnimationOnlyExportData> animationExportData, TransformExportType exportType = TransformExportType.Global)
26692669
{
26702670
exportCancelled = false;
26712671

@@ -2769,10 +2769,8 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet, Dictionary
27692769
}
27702770

27712771
Vector3 center = Vector3.zero;
2772-
var exportType = TransformExportType.Reset;
2773-
if(revisedExportSet.Count != 1){
2772+
if(exportType == TransformExportType.Global){
27742773
center = ExportSettings.centerObjects? FindCenter(revisedExportSet) : Vector3.zero;
2775-
exportType = TransformExportType.Global;
27762774
}
27772775

27782776
foreach (var unityGo in revisedExportSet) {
@@ -3558,7 +3556,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
35583556
/// Export a list of (Game) objects to FBX file.
35593557
/// Use the SaveFile panel to allow user to enter a file name.
35603558
/// <summary>
3561-
public static string ExportObjects (string filePath, UnityEngine.Object[] objects = null, AnimationExportType exportType = AnimationExportType.all)
3559+
public static string ExportObjects (string filePath, UnityEngine.Object[] objects = null, AnimationExportType exportType = AnimationExportType.all, TransformExportType transformExportType = TransformExportType.Global)
35623560
{
35633561
LastFilePath = filePath;
35643562

@@ -3599,7 +3597,7 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
35993597
break;
36003598
}
36013599

3602-
if (fbxExporter.ExportAll (objects, animationExportData) > 0) {
3600+
if (fbxExporter.ExportAll (objects, animationExportData, transformExportType) > 0) {
36033601
string message = string.Format ("Successfully exported: {0}", filePath);
36043602
UnityEngine.Debug.Log (message);
36053603

@@ -3609,9 +3607,9 @@ public static string ExportObjects (string filePath, UnityEngine.Object[] object
36093607
return null;
36103608
}
36113609

3612-
public static string ExportObject (string filePath, UnityEngine.Object root, AnimationExportType exportType = AnimationExportType.all)
3610+
public static string ExportObject (string filePath, UnityEngine.Object root, AnimationExportType exportType = AnimationExportType.all, TransformExportType transformExportType = TransformExportType.Reset)
36133611
{
3614-
return ExportObjects(filePath, new Object[] { root }, exportType);
3612+
return ExportObjects(filePath, new Object[] { root }, exportType, transformExportType);
36153613
}
36163614

36173615
private static void EnsureDirectory (string path)

Assets/FbxExporters/Editor/UnitTests/DefaultSelectionTest.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,32 @@ public void TestDefaultSelection ()
6161
m_root = CreateHierarchy ();
6262
Assert.IsNotNull (m_root);
6363

64+
// test without centered objects
65+
FbxExporters.EditorTools.ExportSettings.instance.centerObjects = false;
66+
6467
// test Export Root
6568
// Expected result: everything gets exported
66-
// Expected transform: root is zeroed out, all other transforms unchanged
69+
// Expected transform: all transforms unchanged
6770
var exportedRoot = ExportSelection (new Object[]{ m_root });
6871
CompareHierarchies (m_root, exportedRoot, true, false);
69-
CompareGlobalTransform (exportedRoot.transform);
72+
CompareGlobalTransform (exportedRoot.transform, m_root.transform);
7073

7174
// test Export Parent1, Child1
7275
// Expected result: Parent1, Child1, Child2
73-
// Expected transform: Parent1 zeroed out, all other transforms unchanged
76+
// Expected transform: all transforms unchanged
7477
var parent1 = m_root.transform.Find ("Parent1");
7578
var child1 = parent1.Find ("Child1");
7679
exportedRoot = ExportSelection (new Object[]{ parent1.gameObject, child1.gameObject });
7780
CompareHierarchies (parent1.gameObject, exportedRoot, true, false);
78-
CompareGlobalTransform (exportedRoot.transform);
81+
CompareGlobalTransform (exportedRoot.transform, parent1);
7982

8083
// test Export Child2
8184
// Expected result: Child2
82-
// Expected transform: Child2 zeroed out
85+
// Expected transform: Child2 unchanged
8386
var child2 = parent1.Find ("Child2").gameObject;
8487
exportedRoot = ExportSelection (new Object[]{ child2 });
8588
CompareHierarchies (child2, exportedRoot, true, false);
86-
CompareGlobalTransform (exportedRoot.transform);
89+
CompareGlobalTransform (exportedRoot.transform, child2.transform);
8790

8891
// test Export Child2, Parent2
8992
// Expected result: Parent2, Child3, Child2
@@ -127,7 +130,12 @@ public void TestDefaultSelection ()
127130
{
128131
var actualMatrix = ConstructTRSMatrix (actual);
129132
var expectedMatrix = expected == null ? new FbxAMatrix () : ConstructTRSMatrix (expected, false, center);
130-
Assert.AreEqual (expectedMatrix, actualMatrix);
133+
134+
for (int i = 0; i < 4; i++) {
135+
for (int j = 0; j < 4; j++) {
136+
Assert.That (actualMatrix [i] [j], Is.EqualTo (expectedMatrix [i] [j]).Within(0.0001));
137+
}
138+
}
131139
}
132140

133141
/// <summary>

0 commit comments

Comments
 (0)