@@ -199,12 +199,16 @@ internal static EditorTools.ExportSettings ExportSettings {
199
199
get { return EditorTools . ExportSettings . instance ; }
200
200
}
201
201
202
+ internal static EditorTools . IExportOptions DefaultOptions {
203
+ get { return new ExportModelSettingsSerialize ( ) ; }
204
+ }
205
+
202
206
private EditorTools . IExportOptions m_exportOptions ;
203
207
private EditorTools . IExportOptions ExportOptions {
204
208
get {
205
209
if ( m_exportOptions == null ) {
206
210
// get default settings;
207
- m_exportOptions = new ExportModelSettingsSerialize ( ) ;
211
+ m_exportOptions = DefaultOptions ;
208
212
}
209
213
return m_exportOptions ;
210
214
}
@@ -2618,11 +2622,31 @@ public AnimationOnlyExportData(
2618
2622
this . defaultClip = null ;
2619
2623
}
2620
2624
2621
- public void ComputeObjectsInAnimationClips (
2625
+ /// <summary>
2626
+ /// collect all objects dependencies for animation clips.
2627
+ /// </summary>
2628
+ public void CollectDependencies (
2622
2629
AnimationClip [ ] animClips ,
2623
- GameObject animationRootObject ,
2624
- bool exportSkinnedMeshAnim = true
2630
+ GameObject rootObject ,
2631
+ IExportOptions exportOptions
2625
2632
) {
2633
+ Debug . Assert ( rootObject != null ) ;
2634
+ Debug . Assert ( exportOptions != null ) ;
2635
+
2636
+ // if we're exporting animation-only and the root is a Camera or Light then we also
2637
+ // to export the static values so that these are pointing the right way
2638
+ if ( exportOptions . ModelAnimIncludeOption == ExportSettings . Include . Anim )
2639
+ {
2640
+ if ( rootObject . GetComponent < Light > ( ) )
2641
+ {
2642
+ this . exportComponent . Add ( rootObject , typeof ( Light ) ) ;
2643
+ }
2644
+ else if ( rootObject . GetComponent < Camera > ( ) )
2645
+ {
2646
+ this . exportComponent . Add ( rootObject , typeof ( Camera ) ) ;
2647
+ }
2648
+ this . goExportSet . Add ( rootObject ) ;
2649
+ }
2626
2650
// NOTE: the object (animationRootObject) containing the animation is not necessarily animated
2627
2651
// when driven by an animator or animation component.
2628
2652
@@ -2632,10 +2656,10 @@ public void ComputeObjectsInAnimationClips(
2632
2656
continue ;
2633
2657
}
2634
2658
2635
- this . animationClips . Add ( animClip , animationRootObject ) ;
2659
+ this . animationClips . Add ( animClip , rootObject ) ;
2636
2660
2637
2661
foreach ( EditorCurveBinding uniCurveBinding in AnimationUtility . GetCurveBindings ( animClip ) ) {
2638
- Object uniObj = AnimationUtility . GetAnimatedObject ( animationRootObject , uniCurveBinding ) ;
2662
+ Object uniObj = AnimationUtility . GetAnimatedObject ( rootObject , uniCurveBinding ) ;
2639
2663
if ( ! uniObj ) {
2640
2664
continue ;
2641
2665
}
@@ -2645,7 +2669,7 @@ public void ComputeObjectsInAnimationClips(
2645
2669
continue ;
2646
2670
}
2647
2671
2648
- if ( ! exportSkinnedMeshAnim && unityGo . GetComponent < SkinnedMeshRenderer > ( ) ) {
2672
+ if ( ! exportOptions . AnimateSkinnedMesh && unityGo . GetComponent < SkinnedMeshRenderer > ( ) ) {
2649
2673
continue ;
2650
2674
}
2651
2675
@@ -3064,11 +3088,13 @@ internal int GetAnimOnlyHierarchyCount(Dictionary<GameObject, IExportData> hiera
3064
3088
3065
3089
internal static Dictionary < GameObject , IExportData > GetExportData ( Object [ ] objects , IExportOptions exportOptions = null )
3066
3090
{
3067
- ExportSettings . Include includeOptions = ( exportOptions != null ) ? exportOptions . ModelAnimIncludeOption : ExportSettings . Include . ModelAndAnim ;
3091
+ if ( exportOptions == null )
3092
+ exportOptions = DefaultOptions ;
3093
+ Debug . Assert ( exportOptions != null ) ;
3068
3094
3069
3095
Dictionary < GameObject , IExportData > exportData = new Dictionary < GameObject , IExportData > ( ) ;
3070
3096
3071
- if ( includeOptions == ExportSettings . Include . Anim )
3097
+ if ( exportOptions . ModelAnimIncludeOption == ExportSettings . Include . Anim )
3072
3098
{
3073
3099
foreach ( var obj in objects )
3074
3100
{
@@ -3092,7 +3118,9 @@ internal static Dictionary<GameObject, IExportData> GetExportData(Object[] objec
3092
3118
3093
3119
public static IExportData GetExportData ( GameObject rootObject , AnimationClip animationClip , IExportOptions exportOptions = null )
3094
3120
{
3095
- bool includeAnimatedSkinnedMeshes = ( exportOptions != null ) ? exportOptions . AnimateSkinnedMesh : true ;
3121
+ if ( exportOptions == null )
3122
+ exportOptions = DefaultOptions ;
3123
+ Debug . Assert ( exportOptions != null ) ;
3096
3124
3097
3125
// get animation clips for root object from animation track
3098
3126
List < AnimationClip > clips = new List < AnimationClip > ( ) { animationClip } ;
@@ -3102,15 +3130,17 @@ public static IExportData GetExportData(GameObject rootObject, AnimationClip ani
3102
3130
var exportComponent = new Dictionary < GameObject , System . Type > ( ) ;
3103
3131
3104
3132
var exportData = new AnimationOnlyExportData ( animationClips , goToExport , exportComponent ) ;
3105
- exportData . ComputeObjectsInAnimationClips ( clips . ToArray ( ) , rootObject , includeAnimatedSkinnedMeshes ) ;
3133
+ exportData . CollectDependencies ( clips . ToArray ( ) , rootObject , exportOptions ) ;
3106
3134
3107
3135
return exportData ;
3108
3136
}
3109
3137
3110
- internal static IExportData GetExportData ( GameObject rootObject , AnimationTrack animationTrack , IExportOptions exportOptions )
3138
+ internal static IExportData GetExportData ( GameObject rootObject , AnimationTrack animationTrack , IExportOptions exportOptions = null )
3111
3139
{
3112
- bool includeAnimatedSkinnedMeshes = ( exportOptions != null ) ? exportOptions . AnimateSkinnedMesh : true ;
3113
-
3140
+ if ( exportOptions == null )
3141
+ exportOptions = DefaultOptions ;
3142
+ Debug . Assert ( exportOptions != null ) ;
3143
+
3114
3144
// get animation clips for root object from animation track
3115
3145
List < AnimationClip > clips = new List < AnimationClip > ( ) ;
3116
3146
@@ -3124,14 +3154,16 @@ internal static IExportData GetExportData(GameObject rootObject, AnimationTrack
3124
3154
var exportComponent = new Dictionary < GameObject , System . Type > ( ) ;
3125
3155
3126
3156
var exportData = new AnimationOnlyExportData ( animationClips , goToExport , exportComponent ) ;
3127
- exportData . ComputeObjectsInAnimationClips ( clips . ToArray ( ) , rootObject , includeAnimatedSkinnedMeshes ) ;
3157
+ exportData . CollectDependencies ( clips . ToArray ( ) , rootObject , exportOptions ) ;
3128
3158
3129
3159
return exportData ;
3130
3160
}
3131
3161
3132
- protected static IExportData GetExportData ( GameObject go , IExportOptions exportOptions )
3162
+ protected static IExportData GetExportData ( GameObject go , IExportOptions exportOptions = null )
3133
3163
{
3134
- bool includeAnimatedSkinnedMeshes = ( exportOptions != null ) ? exportOptions . AnimateSkinnedMesh : true ;
3164
+ if ( exportOptions == null )
3165
+ exportOptions = DefaultOptions ;
3166
+ Debug . Assert ( exportOptions != null ) ;
3135
3167
3136
3168
// gather all animation clips
3137
3169
var legacyAnim = go . GetComponentsInChildren < Animation > ( ) ;
@@ -3156,7 +3188,7 @@ protected static IExportData GetExportData(GameObject go, IExportOptions exportO
3156
3188
}
3157
3189
3158
3190
var animClips = AnimationUtility . GetAnimationClips ( anim . gameObject ) ;
3159
- exportData . ComputeObjectsInAnimationClips ( animClips , anim . gameObject , includeAnimatedSkinnedMeshes ) ;
3191
+ exportData . CollectDependencies ( animClips , anim . gameObject , exportOptions ) ;
3160
3192
}
3161
3193
3162
3194
int depthFromRootAnimator = int . MaxValue ;
@@ -3175,7 +3207,7 @@ protected static IExportData GetExportData(GameObject go, IExportOptions exportO
3175
3207
var controller = anim . runtimeAnimatorController ;
3176
3208
if ( controller )
3177
3209
{
3178
- exportData . ComputeObjectsInAnimationClips ( controller . animationClips , anim . gameObject , includeAnimatedSkinnedMeshes ) ;
3210
+ exportData . CollectDependencies ( controller . animationClips , anim . gameObject , exportOptions ) ;
3179
3211
}
3180
3212
}
3181
3213
@@ -3509,14 +3541,16 @@ internal int ExportAll (
3509
3541
FbxNode fbxRootNode = fbxScene . GetRootNode ( ) ;
3510
3542
// stores how many objects we have exported, -1 if export was cancelled
3511
3543
int exportProgress = 0 ;
3512
- var revisedExportSet = RemoveRedundantObjects ( unityExportSet ) ;
3544
+ IEnumerable < GameObject > revisedExportSet = null ;
3513
3545
3514
3546
int count = 0 ;
3515
3547
if ( animOnly ) {
3516
3548
count = GetAnimOnlyHierarchyCount ( exportData ) ;
3549
+ revisedExportSet = from entry in exportData select entry . Key ;
3517
3550
} else {
3518
- count = GetHierarchyCount ( revisedExportSet ) ;
3519
-
3551
+ var revisedGOSet = RemoveRedundantObjects ( unityExportSet ) ;
3552
+ count = GetHierarchyCount ( revisedGOSet ) ;
3553
+ revisedExportSet = revisedGOSet ;
3520
3554
}
3521
3555
3522
3556
if ( count <= 0 ) {
@@ -3530,7 +3564,7 @@ internal int ExportAll (
3530
3564
switch ( ExportOptions . ObjectPosition ) {
3531
3565
case ExportSettings . ObjectPosition . LocalCentered :
3532
3566
// one object to export -> move to (0,0,0)
3533
- if ( revisedExportSet . Count == 1 ) {
3567
+ if ( count == 1 ) {
3534
3568
var tempList = new List < GameObject > ( revisedExportSet ) ;
3535
3569
center = tempList [ 0 ] . transform . position ;
3536
3570
break ;
0 commit comments