Skip to content

Commit 96ff8e4

Browse files
committed
First Draft of "Exporting Model without animation"
1 parent 0186ef9 commit 96ff8e4

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class ModelExporter : System.IDisposable
8282
// from being passed to command, thus resulting in OnContextItem()
8383
// being called only once regardless of what is selected.
8484
const string MenuItemName = "GameObject/Export Model...";
85+
const string ModelOnlyMenuItemName = "GameObject/Export Model without Animation...";
8586

8687
const string ClipMenuItemName = "GameObject/Export All Timeline Clips...";
8788
const string TimelineClipMenuItemName = "GameObject/Export Selected Timeline Clip...";
@@ -2505,7 +2506,7 @@ protected Dictionary<GameObject, AnimationOnlyExportData> GetAnimationExportData
25052506
/// Transform components have already been exported.
25062507
/// This function exports the other components and animation.
25072508
/// </summary>
2508-
protected bool ExportComponents(FbxScene fbxScene)
2509+
protected bool ExportComponents(FbxScene fbxScene, AnimationExportType animationExportType = AnimationExportType.all)
25092510
{
25102511
var animationNodes = new HashSet<GameObject> ();
25112512

@@ -2544,7 +2545,7 @@ protected bool ExportComponents(FbxScene fbxScene)
25442545

25452546
// check if this object contains animation, keep track of it
25462547
// if it does
2547-
if (GameObjectHasAnimation (unityGo)) {
2548+
if (GameObjectHasAnimation (unityGo) && animationExportType != AnimationExportType.none) {
25482549
animationNodes.Add (unityGo);
25492550
}
25502551
}
@@ -2712,8 +2713,9 @@ public enum TransformExportType { Local, Global, Reset };
27122713
public int ExportAll (
27132714
IEnumerable<UnityEngine.Object> unityExportSet,
27142715
Dictionary<GameObject, AnimationOnlyExportData> animationExportData,
2715-
TransformExportType exportType = TransformExportType.Global,
2716-
ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All)
2716+
TransformExportType transformExportType = TransformExportType.Global,
2717+
ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All,
2718+
AnimationExportType animationExportType = AnimationExportType.all)
27172719
{
27182720
exportCancelled = false;
27192721

@@ -2817,18 +2819,18 @@ public int ExportAll (
28172819
}
28182820

28192821
Vector3 center = Vector3.zero;
2820-
if(exportType == TransformExportType.Global){
2822+
if(transformExportType == TransformExportType.Global){
28212823
center = (ExportSettings.centerObjects && revisedExportSet.Count > 1)? FindCenter(revisedExportSet) : Vector3.zero;
28222824
}
28232825

28242826
foreach (var unityGo in revisedExportSet) {
28252827
AnimationOnlyExportData data;
28262828
if(animOnly && animationExportData.TryGetValue(unityGo, out data)){
2827-
exportProgress = this.ExportAnimationOnly(unityGo, fbxScene, exportProgress, count, center, data, exportType);
2829+
exportProgress = this.ExportAnimationOnly(unityGo, fbxScene, exportProgress, count, center, data, transformExportType);
28282830
}
28292831
else {
28302832
exportProgress = this.ExportTransformHierarchy (unityGo, fbxScene, fbxRootNode,
2831-
exportProgress, count, center, exportType, lodExportType);
2833+
exportProgress, count, center, transformExportType, lodExportType);
28322834
}
28332835
if (exportCancelled || exportProgress < 0) {
28342836
Debug.LogWarning ("Export Cancelled");
@@ -2837,7 +2839,7 @@ public int ExportAll (
28372839
}
28382840

28392841
if(!animOnly){
2840-
if(!ExportComponents(fbxScene)){
2842+
if(!ExportComponents(fbxScene,animationExportType)){
28412843
Debug.LogWarning ("Export Cancelled");
28422844
return 0;
28432845
}
@@ -3093,6 +3095,30 @@ public static bool OnValidateMenuItem ()
30933095
return true;
30943096
}
30953097

3098+
/// <summary>
3099+
/// Add a menu item "Export Model Only..." to a GameObject's context menu.
3100+
/// </summary>
3101+
/// <param name="command">Command.</param>
3102+
[MenuItem (ModelOnlyMenuItemName, false, 30)]
3103+
static void ModelOnlyOnContextItem (MenuCommand command)
3104+
{
3105+
if (Selection.objects.Length <= 0) {
3106+
DisplayNoSelectionDialog ();
3107+
return;
3108+
}
3109+
OnExport (AnimationExportType.none);
3110+
}
3111+
3112+
/// <summary>
3113+
/// Validate the menu item defined by the function above.
3114+
/// </summary>
3115+
[MenuItem (ModelOnlyMenuItemName, true, 30)]
3116+
public static bool ModelOnlyOnValidateMenuItem ()
3117+
{
3118+
return true;
3119+
}
3120+
3121+
30963122
/// <summary>
30973123
/// Add a menu item "Export Animation Only" to a GameObject's context menu.
30983124
/// </summary>
@@ -3560,7 +3586,8 @@ public enum AnimationExportType{
35603586
timelineAnimationClip,
35613587
timelineAnimationTrack,
35623588
componentAnimation,
3563-
all
3589+
all,
3590+
none
35643591
}
35653592

35663593

@@ -3595,7 +3622,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
35953622
return;
35963623
}
35973624

3598-
if (ExportObjects (filePath, exportType: exportType, lodExportType: ExportSettings.instance.lodExportType) != null) {
3625+
if (ExportObjects (filePath, animationExportType: exportType, lodExportType: ExportSettings.instance.lodExportType) != null) {
35993626
// refresh the asset database so that the file appears in the
36003627
// asset folder view.
36013628
AssetDatabase.Refresh ();
@@ -3609,7 +3636,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
36093636
public static string ExportObjects (
36103637
string filePath,
36113638
UnityEngine.Object[] objects = null,
3612-
AnimationExportType exportType = AnimationExportType.all,
3639+
AnimationExportType animationExportType = AnimationExportType.all,
36133640
TransformExportType transformExportType = TransformExportType.Global,
36143641
ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All)
36153642
{
@@ -3625,7 +3652,7 @@ public static string ExportObjects (
36253652

36263653

36273654
Dictionary<GameObject, AnimationOnlyExportData> animationExportData = null;
3628-
switch (exportType)
3655+
switch (animationExportType)
36293656
{
36303657
case AnimationExportType.timelineAnimationClip:
36313658
// 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
@@ -3648,11 +3675,13 @@ public static string ExportObjects (
36483675
}
36493676
animationExportData = fbxExporter.GetAnimationExportData(gos);
36503677
break;
3678+
case AnimationExportType.none:
3679+
break;
36513680
default:
36523681
break;
36533682
}
36543683

3655-
if (fbxExporter.ExportAll (objects, animationExportData, transformExportType, lodExportType) > 0) {
3684+
if (fbxExporter.ExportAll (objects, animationExportData, transformExportType, lodExportType, animationExportType) > 0) {
36563685
string message = string.Format ("Successfully exported: {0}", filePath);
36573686
UnityEngine.Debug.Log (message);
36583687

0 commit comments

Comments
 (0)