Skip to content

Commit 989cfa8

Browse files
committed
connect model/anim include option to implementation
- replace animation enum with bool
1 parent 45f1a01 commit 989cfa8

File tree

6 files changed

+64
-115
lines changed

6 files changed

+64
-115
lines changed

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ConvertToPrefabEditorWindow : ExportOptionsEditorWindow
2121
public static void Init (IEnumerable<GameObject> toConvert)
2222
{
2323
ConvertToPrefabEditorWindow window = CreateWindow<ConvertToPrefabEditorWindow> ();
24-
window.InitializeWindow (filename: "", singleHierarchyExport: true, exportType: ModelExporter.AnimationExportType.all);
24+
window.InitializeWindow (filename: "", singleHierarchyExport: true, isTimelineAnim: false);
2525
window.SetGameObjectsToConvert (toConvert);
2626
window.Show ();
2727
}

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class ExportOptionsEditorWindow : EditorWindow
2626
protected virtual GUIContent WindowTitle { get { return new GUIContent (DefaultWindowTitle); } }
2727

2828
protected string m_exportFileName = "";
29-
protected ModelExporter.AnimationExportType m_animExportType = ModelExporter.AnimationExportType.all;
29+
protected bool m_isTimelineAnim = false;
3030
protected bool m_singleHierarchyExport = true;
3131

3232
protected UnityEditor.Editor m_innerEditor;
@@ -62,10 +62,10 @@ protected static T CreateWindow<T>() where T : EditorWindow {
6262
return (T)EditorWindow.GetWindow <T>(DefaultWindowTitle, focus:true);
6363
}
6464

65-
protected virtual void InitializeWindow(string filename = "", bool singleHierarchyExport = true, ModelExporter.AnimationExportType exportType = ModelExporter.AnimationExportType.all){
65+
protected virtual void InitializeWindow(string filename = "", bool singleHierarchyExport = true, bool isTimelineAnim = false){
6666
this.SetTitle ();
6767
this.SetFilename (filename);
68-
this.SetAnimationExportType (exportType);
68+
this.SetAnimationExportType (isTimelineAnim);
6969
this.SetSingleHierarchyExport (singleHierarchyExport);
7070
}
7171

@@ -93,8 +93,8 @@ public void SetFilename(string filename){
9393
m_exportFileName = filename.Remove(extIndex);
9494
}
9595

96-
public void SetAnimationExportType(ModelExporter.AnimationExportType exportType){
97-
m_animExportType = exportType;
96+
public void SetAnimationExportType(bool isTimelineAnim){
97+
m_isTimelineAnim = isTimelineAnim;
9898
}
9999

100100
public void SetSingleHierarchyExport(bool singleHierarchy){
@@ -275,14 +275,14 @@ public class ExportModelEditorWindow : ExportOptionsEditorWindow
275275
protected override float MinWindowHeight { get { return 260; } }
276276
private UnityEngine.Object[] m_toExport;
277277

278-
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", ModelExporter.AnimationExportType exportType = ModelExporter.AnimationExportType.all)
278+
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", bool isTimelineAnim = false)
279279
{
280280
ExportModelEditorWindow window = CreateWindow<ExportModelEditorWindow> ();
281281
int numObjects = window.SetGameObjectsToExport (toExport);
282282
if (string.IsNullOrEmpty (filename)) {
283283
filename = window.GetFilenameFromObjects ();
284284
}
285-
window.InitializeWindow (filename, singleHierarchyExport: numObjects == 1, exportType: exportType);
285+
window.InitializeWindow (filename, singleHierarchyExport: numObjects == 1, isTimelineAnim: isTimelineAnim);
286286
window.Show ();
287287
}
288288

@@ -318,7 +318,7 @@ protected override void Export(){
318318
return;
319319
}
320320

321-
if (ModelExporter.ExportObjects (filePath, m_toExport, ExportSettings.instance.exportModelSettings, animExportType: m_animExportType) != null) {
321+
if (ModelExporter.ExportObjects (filePath, m_toExport, ExportSettings.instance.exportModelSettings, timelineAnim: m_isTimelineAnim) != null) {
322322
// refresh the asset database so that the file appears in the
323323
// asset folder view.
324324
AssetDatabase.Refresh ();

Assets/FbxExporters/Editor/ExportModelSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public ExportModelSettingsSerialize.ExportFormat GetExportFormat(){
114114
public ExportModelSettingsSerialize.Include GetModelAnimIncludeOption(){
115115
return info.include;
116116
}
117+
public void SetModelAnimIncludeOption(ExportModelSettingsSerialize.Include include){
118+
info.include = include;
119+
}
117120
public ExportModelSettingsSerialize.LODExportType GetLODExportType(){
118121
return info.lodLevel;
119122
}

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 45 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,7 @@ protected Dictionary<GameObject, AnimationOnlyExportData> GetAnimationExportData
25132513
/// Transform components have already been exported.
25142514
/// This function exports the other components and animation.
25152515
/// </summary>
2516-
protected bool ExportComponents(FbxScene fbxScene, AnimationExportType animationExportType = AnimationExportType.all)
2516+
protected bool ExportComponents(FbxScene fbxScene, bool exportAnim = true)
25172517
{
25182518
var animationNodes = new HashSet<GameObject> ();
25192519

@@ -2552,7 +2552,7 @@ protected bool ExportComponents(FbxScene fbxScene, AnimationExportType animation
25522552

25532553
// check if this object contains animation, keep track of it
25542554
// if it does
2555-
if (animationExportType != AnimationExportType.none && GameObjectHasAnimation (unityGo) ) {
2555+
if (exportAnim && GameObjectHasAnimation (unityGo) ) {
25562556
animationNodes.Add (unityGo);
25572557
}
25582558
}
@@ -2719,8 +2719,7 @@ public enum TransformExportType { Local, Global, Reset };
27192719
/// </summary>
27202720
public int ExportAll (
27212721
IEnumerable<UnityEngine.Object> unityExportSet,
2722-
Dictionary<GameObject, AnimationOnlyExportData> animationExportData,
2723-
AnimationExportType animationExportType = AnimationExportType.all)
2722+
Dictionary<GameObject, AnimationOnlyExportData> animationExportData)
27242723
{
27252724
exportCancelled = false;
27262725

@@ -2861,7 +2860,7 @@ public int ExportAll (
28612860
}
28622861

28632862
if(!animOnly){
2864-
if(!ExportComponents(fbxScene,animationExportType)){
2863+
if(!ExportComponents(fbxScene, ExportOptions.GetModelAnimIncludeOption() != ExportModelSettingsSerialize.Include.Model)){
28652864
Debug.LogWarning ("Export Cancelled");
28662865
return 0;
28672866
}
@@ -3012,11 +3011,11 @@ public static void ExportSingleTimelineClip(TimelineClip timelineClipSelected, G
30123011
};
30133012

30143013
if (!string.IsNullOrEmpty (filePath)) {
3015-
ExportObjects (filePath, myArray, animExportType: AnimationExportType.timelineAnimationClip);
3014+
ExportObjects (filePath, myArray, timelineAnim: true);
30163015
return;
30173016
}
30183017

3019-
ExportModelEditorWindow.Init (myArray, string.Format ("{0}@{1}", animationTrackGObject.name, timelineClipSelected.displayName), AnimationExportType.timelineAnimationClip);
3018+
ExportModelEditorWindow.Init (myArray, string.Format ("{0}@{1}", animationTrackGObject.name, timelineClipSelected.displayName), isTimelineAnim: true);
30203019
}
30213020

30223021
/// <summary>
@@ -3025,19 +3024,6 @@ public static void ExportSingleTimelineClip(TimelineClip timelineClipSelected, G
30253024
[MenuItem(ClipMenuItemName, false, 31)]
30263025
public static void OnPlayableDirectorGameObjectContextClick(MenuCommand command)
30273026
{
3028-
// Now that we know we have stuff to export, get the user-desired path.
3029-
string directory = string.IsNullOrEmpty(LastFilePath)
3030-
? Application.dataPath
3031-
: System.IO.Path.GetDirectoryName(LastFilePath);
3032-
3033-
string title = "Select the folder in which the animation files from the timeline will be exported";
3034-
string folderPath = EditorUtility.SaveFolderPanel(title, directory, "");
3035-
3036-
if (string.IsNullOrEmpty(folderPath))
3037-
{
3038-
return;
3039-
}
3040-
30413027
Object[] selection = null;
30423028

30433029
if (command == null || command.context == null)
@@ -3057,28 +3043,32 @@ public static void OnPlayableDirectorGameObjectContextClick(MenuCommand command)
30573043

30583044
foreach (GameObject objectWithPlayableDirector in selection)
30593045
{
3060-
ExportAllTimelineClips(objectWithPlayableDirector,folderPath);
3046+
if (ExportAllTimelineClips (objectWithPlayableDirector)) {
3047+
return;
3048+
}
30613049
}
30623050
}
30633051

3064-
public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector, string folderPath)
3052+
public static bool ExportAllTimelineClips(GameObject objectWithPlayableDirector, string folderPath = null)
30653053
{
30663054
PlayableDirector pd = objectWithPlayableDirector.GetComponent<PlayableDirector>();
3067-
if (pd != null)
3055+
if (pd == null)
30683056
{
3069-
foreach (PlayableBinding output in pd.playableAsset.outputs)
3070-
{
3071-
AnimationTrack at = output.sourceObject as AnimationTrack;
3072-
3073-
GameObject atObject = pd.GetGenericBinding(output.sourceObject) as GameObject;
3074-
// One file by animation clip
3075-
foreach (TimelineClip timeLineClip in at.GetClips()) {
3076-
string filePath = string.Format(AnimFbxFileFormat, folderPath, atObject.name, timeLineClip.displayName);
3077-
UnityEngine.Object[] myArray = new UnityEngine.Object[] { atObject, timeLineClip.animationClip };
3078-
//ExportObjects (filePath, myArray, AnimationExportType.timelineAnimationClip);
3079-
}
3057+
return false;
3058+
}
3059+
foreach (PlayableBinding output in pd.playableAsset.outputs)
3060+
{
3061+
AnimationTrack at = output.sourceObject as AnimationTrack;
3062+
3063+
GameObject atObject = pd.GetGenericBinding(output.sourceObject) as GameObject;
3064+
// One file by animation clip
3065+
foreach (TimelineClip timeLineClip in at.GetClips()) {
3066+
string filePath = string.Format(AnimFbxFileFormat, folderPath, atObject.name, timeLineClip.displayName);
3067+
UnityEngine.Object[] myArray = new UnityEngine.Object[] { atObject, timeLineClip.animationClip };
3068+
ExportObjects (filePath, myArray, timelineAnim: true);
30803069
}
30813070
}
3071+
return true;
30823072
}
30833073

30843074
/// <summary>
@@ -3128,21 +3118,7 @@ public static bool OnValidateMenuItem ()
31283118
{
31293119
return true;
31303120
}
3131-
3132-
/// <summary>
3133-
/// Add a menu item "Export Model Only..." to a GameObject's context menu.
3134-
/// </summary>
3135-
/// <param name="command">Command.</param>
3136-
[MenuItem (ModelOnlyMenuItemName, false, 30)]
3137-
static void ModelOnlyOnContextItem (MenuCommand command)
3138-
{
3139-
if (Selection.objects.Length <= 0) {
3140-
DisplayNoSelectionDialog ();
3141-
return;
3142-
}
3143-
OnExport (AnimationExportType.none);
3144-
}
3145-
3121+
31463122
/// <summary>
31473123
/// Validate the menu item defined by the function above.
31483124
/// </summary>
@@ -3152,22 +3128,6 @@ public static bool ModelOnlyOnValidateMenuItem ()
31523128
return true;
31533129
}
31543130

3155-
3156-
/// <summary>
3157-
/// Add a menu item "Export Animation Only" to a GameObject's context menu.
3158-
/// </summary>
3159-
/// <param name="command">Command.</param>
3160-
[MenuItem (AnimOnlyMenuItemName, false, 30)]
3161-
static void OnAnimOnlyContextItem (MenuCommand command)
3162-
{
3163-
if (Selection.objects.Length <= 0) {
3164-
DisplayNoSelectionDialog ();
3165-
return;
3166-
}
3167-
3168-
OnExport (AnimationExportType.componentAnimation);
3169-
}
3170-
31713131
/// <summary>
31723132
// Validate the menu item defined by the function above.
31733133
/// </summary>
@@ -3623,15 +3583,6 @@ public void Dispose ()
36233583

36243584
const string kFBXFileExtension = "fbx";
36253585

3626-
public enum AnimationExportType{
3627-
timelineAnimationClip,
3628-
timelineAnimationTrack,
3629-
componentAnimation,
3630-
all,
3631-
none
3632-
}
3633-
3634-
36353586
private static string MakeFileName (string basename = "test", string extension = kFBXFileExtension)
36363587
{
36373588
return basename + "." + extension;
@@ -3648,12 +3599,12 @@ private static string GetExportFilePath(string filenameSuggestion = ""){
36483599
return EditorUtility.SaveFilePanel (title, directory, filenameSuggestion, kFBXFileExtension);
36493600
}
36503601

3651-
private static void OnExport (AnimationExportType exportType = AnimationExportType.all)
3602+
private static void OnExport ()
36523603
{
36533604
GameObject [] selectedGOs = Selection.GetFiltered<GameObject> (SelectionMode.TopLevel);
36543605

36553606
var toExport = ModelExporter.RemoveRedundantObjects(selectedGOs);
3656-
ExportModelEditorWindow.Init (System.Linq.Enumerable.Cast<UnityEngine.Object> (toExport), exportType: exportType);
3607+
ExportModelEditorWindow.Init (System.Linq.Enumerable.Cast<UnityEngine.Object> (toExport), isTimelineAnim: false);
36573608
}
36583609

36593610
/// <summary>
@@ -3664,7 +3615,7 @@ public static string ExportObjects (
36643615
string filePath,
36653616
UnityEngine.Object[] objects = null,
36663617
IExportOptions exportOptions = null,
3667-
AnimationExportType animExportType = AnimationExportType.all)
3618+
bool timelineAnim = false)
36683619
{
36693620
LastFilePath = filePath;
36703621

@@ -3678,34 +3629,25 @@ public static string ExportObjects (
36783629
}
36793630

36803631
Dictionary<GameObject, AnimationOnlyExportData> animationExportData = null;
3681-
switch (animExportType)
3682-
{
3683-
case AnimationExportType.timelineAnimationClip:
3632+
if (exportOptions.GetModelAnimIncludeOption () == ExportModelSettingsSerialize.Include.Anim) {
3633+
if (timelineAnim) {
36843634
// We expect the first argument in the list to be the GameObject, the second one is the Animation Clip/Track we are exporting from the timeline
3685-
GameObject rootObject = ModelExporter.GetGameObject(objects[0]);
3686-
AnimationClip timelineClip = objects[1] as AnimationClip;
3687-
List<AnimationClip> clipList = new List<AnimationClip>();
3688-
clipList.Add(timelineClip);
3689-
animationExportData = fbxExporter.GetTimelineAnimationExportData(rootObject, clipList);
3690-
break;
3691-
case AnimationExportType.timelineAnimationTrack:
3692-
GameObject rootObject2 = ModelExporter.GetGameObject(objects[0]);
3693-
AnimationTrack timelineTrack = objects[1] as AnimationTrack;
3694-
animationExportData = fbxExporter.GetAnimationExportDataFromAnimationTrack(rootObject2, timelineTrack);
3695-
break;
3696-
case AnimationExportType.componentAnimation:
3697-
HashSet<GameObject> gos = new HashSet<GameObject>();
3698-
foreach(var obj in objects)
3699-
{
3700-
gos.Add(ModelExporter.GetGameObject(obj));
3635+
GameObject rootObject = ModelExporter.GetGameObject (objects [0]);
3636+
AnimationClip timelineClip = objects [1] as AnimationClip;
3637+
List<AnimationClip> clipList = new List<AnimationClip> ();
3638+
clipList.Add (timelineClip);
3639+
animationExportData = fbxExporter.GetTimelineAnimationExportData (rootObject, clipList);
3640+
}
3641+
else{
3642+
HashSet<GameObject> gos = new HashSet<GameObject> ();
3643+
foreach (var obj in objects) {
3644+
gos.Add (ModelExporter.GetGameObject (obj));
37013645
}
3702-
animationExportData = fbxExporter.GetAnimationExportData(gos);
3703-
break;
3704-
default:
3705-
break;
3646+
animationExportData = fbxExporter.GetAnimationExportData (gos);
3647+
}
37063648
}
37073649

3708-
if (fbxExporter.ExportAll (objects, animationExportData, animExportType) > 0) {
3650+
if (fbxExporter.ExportAll (objects, animationExportData) > 0) {
37093651
string message = string.Format ("Successfully exported: {0}", filePath);
37103652
UnityEngine.Debug.Log (message);
37113653

@@ -3718,9 +3660,9 @@ public static string ExportObjects (
37183660
public static string ExportObject (
37193661
string filePath, UnityEngine.Object root,
37203662
IExportOptions exportOptions = null,
3721-
AnimationExportType exportType = AnimationExportType.all)
3663+
bool isTimelineAnim = false)
37223664
{
3723-
return ExportObjects(filePath, new Object[] { root }, exportOptions, animExportType: exportType);
3665+
return ExportObjects(filePath, new Object[] { root }, exportOptions, isTimelineAnim);
37243666
}
37253667

37263668
private static void EnsureDirectory (string path)

Assets/FbxExporters/Editor/UnitTests/ExporterTestBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ protected string ExportToFbx (
270270
string filename = GetRandomFbxFilePath ();
271271
var exportOptions = ScriptableObject.CreateInstance <EditorTools.ExportModelSettings> () as EditorTools.ExportModelSettings;
272272
exportOptions.SetLODExportType (lodExportType);
273+
if (animOnly) {
274+
exportOptions.SetModelAnimIncludeOption (FbxExporters.EditorTools.ExportModelSettingsSerialize.Include.Anim);
275+
}
273276
var exportedFilePath = FbxExporters.Editor.ModelExporter.ExportObject (
274-
filename, hierarchy, exportOptions,
275-
animOnly? FbxExporters.Editor.ModelExporter.AnimationExportType.componentAnimation : FbxExporters.Editor.ModelExporter.AnimationExportType.all
277+
filename, hierarchy, exportOptions
276278
);
277279
Assert.That (exportedFilePath, Is.EqualTo (filename));
278280
return filename;

0 commit comments

Comments
 (0)