Skip to content

Commit 5d270d4

Browse files
authored
Merge pull request #332 from Unity-Technologies/Uni-37352-ExportModelOnly
Uni 37352 export model only
2 parents 168eb78 + 1ab29c5 commit 5d270d4

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 40 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 Only...";
8586

8687
const string ClipMenuItemName = "GameObject/Export All Recorded Animation 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 (animationExportType != AnimationExportType.none && GameObjectHasAnimation (unityGo) ) {
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
}
@@ -3105,6 +3107,30 @@ public static bool OnValidateMenuItem ()
31053107
return true;
31063108
}
31073109

3110+
/// <summary>
3111+
/// Add a menu item "Export Model Only..." to a GameObject's context menu.
3112+
/// </summary>
3113+
/// <param name="command">Command.</param>
3114+
[MenuItem (ModelOnlyMenuItemName, false, 30)]
3115+
static void ModelOnlyOnContextItem (MenuCommand command)
3116+
{
3117+
if (Selection.objects.Length <= 0) {
3118+
DisplayNoSelectionDialog ();
3119+
return;
3120+
}
3121+
OnExport (AnimationExportType.none);
3122+
}
3123+
3124+
/// <summary>
3125+
/// Validate the menu item defined by the function above.
3126+
/// </summary>
3127+
[MenuItem (ModelOnlyMenuItemName, true, 30)]
3128+
public static bool ModelOnlyOnValidateMenuItem ()
3129+
{
3130+
return true;
3131+
}
3132+
3133+
31083134
/// <summary>
31093135
/// Add a menu item "Export Animation Only" to a GameObject's context menu.
31103136
/// </summary>
@@ -3579,7 +3605,8 @@ public enum AnimationExportType{
35793605
timelineAnimationClip,
35803606
timelineAnimationTrack,
35813607
componentAnimation,
3582-
all
3608+
all,
3609+
none
35833610
}
35843611

35853612

@@ -3618,7 +3645,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
36183645
return;
36193646
}
36203647

3621-
if (ExportObjects (filePath, exportType: exportType, lodExportType: ExportSettings.instance.lodExportType) != null) {
3648+
if (ExportObjects (filePath, animationExportType: exportType, lodExportType: ExportSettings.instance.lodExportType) != null) {
36223649
// refresh the asset database so that the file appears in the
36233650
// asset folder view.
36243651
AssetDatabase.Refresh ();
@@ -3632,7 +3659,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
36323659
public static string ExportObjects (
36333660
string filePath,
36343661
UnityEngine.Object[] objects = null,
3635-
AnimationExportType exportType = AnimationExportType.all,
3662+
AnimationExportType animationExportType = AnimationExportType.all,
36363663
TransformExportType transformExportType = TransformExportType.Global,
36373664
ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All)
36383665
{
@@ -3648,7 +3675,7 @@ public static string ExportObjects (
36483675

36493676

36503677
Dictionary<GameObject, AnimationOnlyExportData> animationExportData = null;
3651-
switch (exportType)
3678+
switch (animationExportType)
36523679
{
36533680
case AnimationExportType.timelineAnimationClip:
36543681
// 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
@@ -3675,7 +3702,7 @@ public static string ExportObjects (
36753702
break;
36763703
}
36773704

3678-
if (fbxExporter.ExportAll (objects, animationExportData, transformExportType, lodExportType) > 0) {
3705+
if (fbxExporter.ExportAll (objects, animationExportData, transformExportType, lodExportType, animationExportType) > 0) {
36793706
string message = string.Format ("Successfully exported: {0}", filePath);
36803707
UnityEngine.Debug.Log (message);
36813708

0 commit comments

Comments
 (0)