@@ -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 without Animation..." ;
85
86
86
87
const string ClipMenuItemName = "GameObject/Export All Timeline 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 ( GameObjectHasAnimation ( unityGo ) && animationExportType != AnimationExportType . none ) {
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
}
@@ -3093,6 +3095,30 @@ public static bool OnValidateMenuItem ()
3093
3095
return true ;
3094
3096
}
3095
3097
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
+
3096
3122
/// <summary>
3097
3123
/// Add a menu item "Export Animation Only" to a GameObject's context menu.
3098
3124
/// </summary>
@@ -3560,7 +3586,8 @@ public enum AnimationExportType{
3560
3586
timelineAnimationClip ,
3561
3587
timelineAnimationTrack ,
3562
3588
componentAnimation ,
3563
- all
3589
+ all ,
3590
+ none
3564
3591
}
3565
3592
3566
3593
@@ -3595,7 +3622,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3595
3622
return ;
3596
3623
}
3597
3624
3598
- if ( ExportObjects ( filePath , exportType : exportType , lodExportType : ExportSettings . instance . lodExportType ) != null ) {
3625
+ if ( ExportObjects ( filePath , animationExportType : exportType , lodExportType : ExportSettings . instance . lodExportType ) != null ) {
3599
3626
// refresh the asset database so that the file appears in the
3600
3627
// asset folder view.
3601
3628
AssetDatabase . Refresh ( ) ;
@@ -3609,7 +3636,7 @@ private static void OnExport (AnimationExportType exportType = AnimationExportTy
3609
3636
public static string ExportObjects (
3610
3637
string filePath ,
3611
3638
UnityEngine . Object [ ] objects = null ,
3612
- AnimationExportType exportType = AnimationExportType . all ,
3639
+ AnimationExportType animationExportType = AnimationExportType . all ,
3613
3640
TransformExportType transformExportType = TransformExportType . Global ,
3614
3641
ExportSettings . LODExportType lodExportType = ExportSettings . LODExportType . All )
3615
3642
{
@@ -3625,7 +3652,7 @@ public static string ExportObjects (
3625
3652
3626
3653
3627
3654
Dictionary < GameObject , AnimationOnlyExportData > animationExportData = null ;
3628
- switch ( exportType )
3655
+ switch ( animationExportType )
3629
3656
{
3630
3657
case AnimationExportType . timelineAnimationClip :
3631
3658
// 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 (
3648
3675
}
3649
3676
animationExportData = fbxExporter . GetAnimationExportData ( gos ) ;
3650
3677
break ;
3678
+ case AnimationExportType . none :
3679
+ break ;
3651
3680
default :
3652
3681
break ;
3653
3682
}
3654
3683
3655
- if ( fbxExporter . ExportAll ( objects , animationExportData , transformExportType , lodExportType ) > 0 ) {
3684
+ if ( fbxExporter . ExportAll ( objects , animationExportData , transformExportType , lodExportType , animationExportType ) > 0 ) {
3656
3685
string message = string . Format ( "Successfully exported: {0}" , filePath ) ;
3657
3686
UnityEngine . Debug . Log ( message ) ;
3658
3687
0 commit comments