Skip to content

Commit 0b26590

Browse files
committed
show local pivot for single hierarchy, local centered for multi
- if single hierarchy and local pivot selected, move translation to 0,0,0 - if multi hierarchy and local centered selected, move bounding box center to world center
1 parent 687e120 commit 0b26590

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public class ExportModelEditorWindow : EditorWindow
1919
private const float FieldOffset = 18;
2020
private string m_exportFileName = "";
2121
private ModelExporter.AnimationExportType m_animExportType = ModelExporter.AnimationExportType.all;
22+
private bool m_singleHierarchyExport = true;
2223

23-
private UnityEditor.Editor innerEditor;
24+
private ExportModelSettingsEditor innerEditor;
2425
private static FbxExportPresetSelectorReceiver receiver;
2526

2627
private static GUIContent presetIcon { get { return EditorGUIUtility.IconContent ("Preset.Context"); }}
@@ -39,15 +40,17 @@ void OnEnable(){
3940
ExportSettings.LoadSettings ();
4041
ms = ExportSettings.instance.exportModelSettings;
4142
}
42-
innerEditor = UnityEditor.Editor.CreateEditor (ms, editorType: typeof(ExportModelSettingsEditor));
43+
innerEditor = UnityEditor.Editor.CreateEditor (ms) as ExportModelSettingsEditor;
44+
innerEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
4345
}
4446
}
4547

46-
public static void Init (string filename = "", ModelExporter.AnimationExportType exportType = ModelExporter.AnimationExportType.all)
48+
public static void Init (string filename = "", bool singleHierarchyExport = true, ModelExporter.AnimationExportType exportType = ModelExporter.AnimationExportType.all)
4749
{
4850
ExportModelEditorWindow window = (ExportModelEditorWindow)EditorWindow.GetWindow <ExportModelEditorWindow>(WindowTitle, focus:true);
4951
window.SetFilename (filename);
5052
window.SetAnimationExportType (exportType);
53+
window.SetSingleHierarchyExport (singleHierarchyExport);
5154
window.Show ();
5255
}
5356

@@ -69,6 +72,14 @@ public void SetAnimationExportType(ModelExporter.AnimationExportType exportType)
6972
m_animExportType = exportType;
7073
}
7174

75+
public void SetSingleHierarchyExport(bool singleHierarchy){
76+
m_singleHierarchyExport = singleHierarchy;
77+
78+
if (innerEditor) {
79+
innerEditor.SetIsSingleHierarchy (m_singleHierarchyExport);
80+
}
81+
}
82+
7283
public void OnPresetDialogClosed()
7384
{
7485
// save once preset selection is finished

Assets/FbxExporters/Editor/ExportModelSettings.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ public class ExportModelSettingsEditor : UnityEditor.Editor
99
private const float LabelWidth = 175;
1010
private const float FieldOffset = 18;
1111

12+
private string[] exportFormatOptions = new string[]{ "ASCII", "Binary" };
13+
private string[] includeOptions = new string[]{"Model(s) Only", "Animation Only", "Model(s) + Animation"};
14+
private string[] lodOptions = new string[]{"All", "Highest", "Lowest"};
15+
16+
public const string singleHierarchyOption = "Local Pivot";
17+
public const string multiHerarchyOption = "Local Centered";
18+
private string hierarchyDepOption = "";
19+
private string[] objPositionOptions { get { return new string[]{hierarchyDepOption, "World Absolute"}; }}
20+
21+
public void SetIsSingleHierarchy(bool singleHierarchy){
22+
if (singleHierarchy) {
23+
hierarchyDepOption = singleHierarchyOption;
24+
return;
25+
}
26+
hierarchyDepOption = multiHerarchyOption;
27+
}
28+
1229
public override void OnInspectorGUI ()
1330
{
1431
var exportSettings = ((ExportModelSettings)target).info;
@@ -18,24 +35,24 @@ public override void OnInspectorGUI ()
1835
GUILayout.BeginHorizontal();
1936
EditorGUILayout.LabelField(new GUIContent("Export Format", "Export the FBX file in the standard binary format." +
2037
" Select ASCII to export the FBX file in ASCII format."), GUILayout.Width(LabelWidth - FieldOffset));
21-
exportSettings.exportFormat = (ExportModelSettingsSerialize.ExportFormat)EditorGUILayout.Popup((int)exportSettings.exportFormat, new string[]{ "ASCII", "Binary" });
38+
exportSettings.exportFormat = (ExportModelSettingsSerialize.ExportFormat)EditorGUILayout.Popup((int)exportSettings.exportFormat, exportFormatOptions);
2239
GUILayout.EndHorizontal();
2340

2441
GUILayout.BeginHorizontal();
2542
EditorGUILayout.LabelField(new GUIContent("Include", "Select whether to export models, animation or both."), GUILayout.Width(LabelWidth - FieldOffset));
26-
exportSettings.include = (ExportModelSettingsSerialize.Include)EditorGUILayout.Popup((int)exportSettings.include, new string[]{"Model(s) Only", "Animation Only", "Model(s) + Animation"});
43+
exportSettings.include = (ExportModelSettingsSerialize.Include)EditorGUILayout.Popup((int)exportSettings.include, includeOptions);
2744
GUILayout.EndHorizontal();
2845

2946
// greyed out if animation only
3047
EditorGUI.BeginDisabledGroup(exportSettings.include == ExportModelSettingsSerialize.Include.Anim);
3148
GUILayout.BeginHorizontal();
3249
EditorGUILayout.LabelField(new GUIContent("LOD level", "Select which LOD to export."), GUILayout.Width(LabelWidth - FieldOffset));
33-
exportSettings.lodLevel = (ExportModelSettingsSerialize.LODExportType)EditorGUILayout.Popup((int)exportSettings.lodLevel, new string[]{"All", "Highest", "Lowest"});
50+
exportSettings.lodLevel = (ExportModelSettingsSerialize.LODExportType)EditorGUILayout.Popup((int)exportSettings.lodLevel, lodOptions);
3451
GUILayout.EndHorizontal();
3552

3653
GUILayout.BeginHorizontal();
3754
EditorGUILayout.LabelField(new GUIContent("Object(s) Position", "Select an option for exporting object's transform."), GUILayout.Width(LabelWidth - FieldOffset));
38-
exportSettings.objectPosition = (ExportModelSettingsSerialize.ObjectPosition)EditorGUILayout.Popup((int)exportSettings.objectPosition, new string[]{"Local Centered", "World Absolute", "Local Pivot"});
55+
exportSettings.objectPosition = (ExportModelSettingsSerialize.ObjectPosition)EditorGUILayout.Popup((int)exportSettings.objectPosition, objPositionOptions);
3956
GUILayout.EndHorizontal();
4057
EditorGUI.EndDisabledGroup ();
4158

@@ -79,7 +96,7 @@ public enum ExportFormat { ASCII = 0, Binary = 1}
7996

8097
public enum Include { Model = 0, Anim = 1, ModelAndAnim = 2 }
8198

82-
public enum ObjectPosition { LocalCentered = 0, WorldAbsolute = 1, LocalPivot = 2 }
99+
public enum ObjectPosition { LocalCentered = 0, WorldAbsolute = 1 }
83100

84101
public enum LODExportType { All = 0, Highest = 1, Lowest = 2 }
85102

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,9 +2807,22 @@ public int ExportAll (
28072807

28082808
Vector3 center = Vector3.zero;
28092809
if(exportType == TransformExportType.Global){
2810-
center = (
2811-
ExportSettings.GetObjectPosition() == ExportModelSettingsSerialize.ObjectPosition.LocalCentered && revisedExportSet.Count > 1
2812-
)? FindCenter(revisedExportSet) : Vector3.zero;
2810+
switch(ExportSettings.GetObjectPosition()){
2811+
case ExportModelSettingsSerialize.ObjectPosition.LocalCentered:
2812+
// one object to export -> move to (0,0,0)
2813+
if(revisedExportSet.Count == 1){
2814+
var tempList = new List<GameObject>(revisedExportSet);
2815+
center = tempList[0].transform.position;
2816+
break;
2817+
}
2818+
// more than one object to export -> get bounding center
2819+
center = FindCenter(revisedExportSet);
2820+
break;
2821+
// absolute center -> don't do anything
2822+
default:
2823+
center = Vector3.zero;
2824+
break;
2825+
}
28132826
}
28142827

28152828
foreach (var unityGo in revisedExportSet) {
@@ -3570,7 +3583,9 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
35703583
: System.IO.Path.GetFileName (LastFilePath);
35713584
}
35723585

3573-
ExportModelEditorWindow.Init (filename, exportType);
3586+
var hierarchyCount = ModelExporter.RemoveRedundantObjects(selectedGOs).Count;
3587+
3588+
ExportModelEditorWindow.Init (filename, singleHierarchyExport: hierarchyCount == 1, exportType: exportType);
35743589
}
35753590

35763591
/// <summary>

0 commit comments

Comments
 (0)