@@ -82,6 +82,7 @@ public class ModelExporter : System.IDisposable
82
82
// from being passed to command, thus resulting in OnContextItem()
83
83
// being called only once regardless of what is selected.
84
84
const string MenuItemName = "GameObject/Export Model..." ;
85
+ const string ModelOnlyMenuItemName = "GameObject/Export Model Only..." ;
85
86
86
87
const string ClipMenuItemName = "GameObject/Export All Recorded Animation Clips..." ;
87
88
const string TimelineClipMenuItemName = "GameObject/Export Selected Timeline Clip..." ;
@@ -2505,7 +2506,7 @@ protected Dictionary<GameObject, AnimationOnlyExportData> GetAnimationExportData
2505
2506
/// Transform components have already been exported.
2506
2507
/// This function exports the other components and animation.
2507
2508
/// </summary>
2508
- protected bool ExportComponents ( FbxScene fbxScene )
2509
+ protected bool ExportComponents ( FbxScene fbxScene , AnimationExportType animationExportType = AnimationExportType . all )
2509
2510
{
2510
2511
var animationNodes = new HashSet < GameObject > ( ) ;
2511
2512
@@ -2544,7 +2545,7 @@ protected bool ExportComponents(FbxScene fbxScene)
2544
2545
2545
2546
// check if this object contains animation, keep track of it
2546
2547
// if it does
2547
- if ( GameObjectHasAnimation ( unityGo ) ) {
2548
+ if ( animationExportType != AnimationExportType . none && GameObjectHasAnimation ( unityGo ) ) {
2548
2549
animationNodes . Add ( unityGo ) ;
2549
2550
}
2550
2551
}
@@ -2712,8 +2713,9 @@ public enum TransformExportType { Local, Global, Reset };
2712
2713
public int ExportAll (
2713
2714
IEnumerable < UnityEngine . Object > unityExportSet ,
2714
2715
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 )
2717
2719
{
2718
2720
exportCancelled = false ;
2719
2721
@@ -2817,18 +2819,18 @@ public int ExportAll (
2817
2819
}
2818
2820
2819
2821
Vector3 center = Vector3 . zero ;
2820
- if ( exportType == TransformExportType . Global ) {
2822
+ if ( transformExportType == TransformExportType . Global ) {
2821
2823
center = ( ExportSettings . centerObjects && revisedExportSet . Count > 1 ) ? FindCenter ( revisedExportSet ) : Vector3 . zero ;
2822
2824
}
2823
2825
2824
2826
foreach ( var unityGo in revisedExportSet ) {
2825
2827
AnimationOnlyExportData data ;
2826
2828
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 ) ;
2828
2830
}
2829
2831
else {
2830
2832
exportProgress = this . ExportTransformHierarchy ( unityGo , fbxScene , fbxRootNode ,
2831
- exportProgress , count , center , exportType , lodExportType ) ;
2833
+ exportProgress , count , center , transformExportType , lodExportType ) ;
2832
2834
}
2833
2835
if ( exportCancelled || exportProgress < 0 ) {
2834
2836
Debug . LogWarning ( "Export Cancelled" ) ;
@@ -2837,7 +2839,7 @@ public int ExportAll (
2837
2839
}
2838
2840
2839
2841
if ( ! animOnly ) {
2840
- if ( ! ExportComponents ( fbxScene ) ) {
2842
+ if ( ! ExportComponents ( fbxScene , animationExportType ) ) {
2841
2843
Debug . LogWarning ( "Export Cancelled" ) ;
2842
2844
return 0 ;
2843
2845
}
@@ -3105,6 +3107,30 @@ public static bool OnValidateMenuItem ()
3105
3107
return true ;
3106
3108
}
3107
3109
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
+
3108
3134
/// <summary>
3109
3135
/// Add a menu item "Export Animation Only" to a GameObject's context menu.
3110
3136
/// </summary>
@@ -3579,7 +3605,8 @@ public enum AnimationExportType{
3579
3605
timelineAnimationClip ,
3580
3606
timelineAnimationTrack ,
3581
3607
componentAnimation ,
3582
- all
3608
+ all ,
3609
+ none
3583
3610
}
3584
3611
3585
3612
@@ -3618,7 +3645,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3618
3645
return ;
3619
3646
}
3620
3647
3621
- if ( ExportObjects ( filePath , exportType : exportType , lodExportType : ExportSettings . instance . lodExportType ) != null ) {
3648
+ if ( ExportObjects ( filePath , animationExportType : exportType , lodExportType : ExportSettings . instance . lodExportType ) != null ) {
3622
3649
// refresh the asset database so that the file appears in the
3623
3650
// asset folder view.
3624
3651
AssetDatabase . Refresh ( ) ;
@@ -3632,7 +3659,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3632
3659
public static string ExportObjects (
3633
3660
string filePath ,
3634
3661
UnityEngine . Object [ ] objects = null ,
3635
- AnimationExportType exportType = AnimationExportType . all ,
3662
+ AnimationExportType animationExportType = AnimationExportType . all ,
3636
3663
TransformExportType transformExportType = TransformExportType . Global ,
3637
3664
ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All )
3638
3665
{
@@ -3648,7 +3675,7 @@ public static string ExportObjects (
3648
3675
3649
3676
3650
3677
Dictionary < GameObject , AnimationOnlyExportData > animationExportData = null ;
3651
- switch ( exportType )
3678
+ switch ( animationExportType )
3652
3679
{
3653
3680
case AnimationExportType . timelineAnimationClip :
3654
3681
// 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 (
3675
3702
break ;
3676
3703
}
3677
3704
3678
- if ( fbxExporter . ExportAll ( objects , animationExportData , transformExportType , lodExportType ) > 0 ) {
3705
+ if ( fbxExporter . ExportAll ( objects , animationExportData , transformExportType , lodExportType , animationExportType ) > 0 ) {
3679
3706
string message = string . Format ( "Successfully exported: {0}" , filePath ) ;
3680
3707
UnityEngine . Debug . Log ( message ) ;
3681
3708
0 commit comments