Skip to content

Commit 335663d

Browse files
inwoodsvkovec
authored andcommitted
include camera node w/ export of animation clip bound to camera
1 parent 2340d60 commit 335663d

File tree

2 files changed

+79
-33
lines changed

2 files changed

+79
-33
lines changed

Packages/com.unity.formats.fbx/Editor/Scripts/ExportModelEditorWindow.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ protected bool IsInSameHierarchy(Transform t1, Transform t2){
188188
return (IsAncestor (t1, t2) || IsAncestor (t2, t1));
189189
}
190190

191+
protected virtual GameObject GetGameObject()
192+
{
193+
return ModelExporter.GetGameObject ( ToExport [0] );
194+
}
191195

192196
protected bool TransferAnimationSourceIsValid(Transform newValue){
193197
if (!newValue) {
@@ -199,7 +203,7 @@ protected bool TransferAnimationSourceIsValid(Transform newValue){
199203
return false;
200204
}
201205

202-
var selectedGO = ModelExporter.GetGameObject(ToExport[0]);
206+
var selectedGO = GetGameObject();
203207

204208
// source must be ancestor to dest
205209
if (TransferAnimationDest && !IsAncestor(newValue, TransferAnimationDest)) {
@@ -224,7 +228,7 @@ protected bool TransferAnimationDestIsValid(Transform newValue){
224228
return false;
225229
}
226230

227-
var selectedGO = ModelExporter.GetGameObject(ToExport[0]);
231+
var selectedGO = GetGameObject();
228232

229233
// source must be ancestor to dest
230234
if (TransferAnimationSource && !IsAncestor(TransferAnimationSource, newValue)) {
@@ -399,6 +403,14 @@ protected override bool DisableNameSelection {
399403
return false;
400404
}
401405
}
406+
407+
protected override GameObject GetGameObject()
408+
{
409+
return (IsTimelineAnim)
410+
? ModelExporter.AnimationOnlyExportData.GetGameObjectAndAnimationClip(ToExport [0]).Key
411+
: ModelExporter.GetGameObject ( ToExport [0] );
412+
}
413+
402414
protected override bool DisableTransferAnim {
403415
get {
404416
// don't transfer animation if we are exporting more than one hierarchy, the timeline clips from
@@ -448,7 +460,7 @@ protected override ExportOptionsSettingsSerializeBase SettingsObject
448460

449461
private ExportSettings.Include m_previousInclude = ExportSettings.Include.ModelAndAnim;
450462

451-
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", bool isTimelineAnim = false, bool isPlayableDirector = false)
463+
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", bool isTimelineAnim = false)
452464
{
453465
ExportModelEditorWindow window = CreateWindow<ExportModelEditorWindow> ();
454466
window.IsTimelineAnim = isTimelineAnim;
@@ -464,20 +476,20 @@ public static void Init (IEnumerable<UnityEngine.Object> toExport, string filena
464476

465477
protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
466478
ToExport = toExport.ToArray ();
479+
if (ToExport.Length==0) return 0;
467480

468481
TransferAnimationSource = null;
469482
TransferAnimationDest = null;
470483

471484
// if only one object selected, set transfer source/dest to this object
472-
if (ToExport.Length == 1 || (IsTimelineAnim && ToExport.Length > 0)) {
473-
var go = ModelExporter.GetGameObject (ToExport [0]);
474-
if (go) {
475-
TransferAnimationSource = go.transform;
476-
TransferAnimationDest = go.transform;
477-
}
485+
GameObject go = GetGameObject();
486+
487+
if (go) {
488+
TransferAnimationSource = go.transform;
489+
TransferAnimationDest = go.transform;
478490
}
479491

480-
return ToExport.Length;
492+
return 1;
481493
}
482494

483495
/// <summary>

Packages/com.unity.formats.fbx/Editor/Scripts/FbxExporter.cs

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,16 @@ internal static EditorTools.ExportSettings ExportSettings {
199199
get { return EditorTools.ExportSettings.instance; }
200200
}
201201

202+
internal static EditorTools.IExportOptions DefaultOptions {
203+
get { return new ExportModelSettingsSerialize(); }
204+
}
205+
202206
private EditorTools.IExportOptions m_exportOptions;
203207
private EditorTools.IExportOptions ExportOptions {
204208
get {
205209
if (m_exportOptions == null) {
206210
// get default settings;
207-
m_exportOptions = new ExportModelSettingsSerialize();
211+
m_exportOptions = DefaultOptions;
208212
}
209213
return m_exportOptions;
210214
}
@@ -2618,11 +2622,31 @@ public AnimationOnlyExportData(
26182622
this.defaultClip = null;
26192623
}
26202624

2621-
public void ComputeObjectsInAnimationClips(
2625+
/// <summary>
2626+
/// collect all objects dependencies for animation clips.
2627+
/// </summary>
2628+
public void CollectDependencies(
26222629
AnimationClip[] animClips,
2623-
GameObject animationRootObject,
2624-
bool exportSkinnedMeshAnim = true
2630+
GameObject rootObject,
2631+
IExportOptions exportOptions
26252632
){
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+
}
26262650
// NOTE: the object (animationRootObject) containing the animation is not necessarily animated
26272651
// when driven by an animator or animation component.
26282652

@@ -2632,10 +2656,10 @@ public void ComputeObjectsInAnimationClips(
26322656
continue;
26332657
}
26342658

2635-
this.animationClips.Add (animClip, animationRootObject);
2659+
this.animationClips.Add (animClip, rootObject);
26362660

26372661
foreach (EditorCurveBinding uniCurveBinding in AnimationUtility.GetCurveBindings (animClip)) {
2638-
Object uniObj = AnimationUtility.GetAnimatedObject (animationRootObject, uniCurveBinding);
2662+
Object uniObj = AnimationUtility.GetAnimatedObject (rootObject, uniCurveBinding);
26392663
if (!uniObj) {
26402664
continue;
26412665
}
@@ -2645,7 +2669,7 @@ public void ComputeObjectsInAnimationClips(
26452669
continue;
26462670
}
26472671

2648-
if (!exportSkinnedMeshAnim && unityGo.GetComponent<SkinnedMeshRenderer>()) {
2672+
if (!exportOptions.AnimateSkinnedMesh && unityGo.GetComponent<SkinnedMeshRenderer>()) {
26492673
continue;
26502674
}
26512675

@@ -3064,11 +3088,13 @@ internal int GetAnimOnlyHierarchyCount(Dictionary<GameObject, IExportData> hiera
30643088

30653089
internal static Dictionary<GameObject, IExportData> GetExportData(Object[] objects, IExportOptions exportOptions = null)
30663090
{
3067-
ExportSettings.Include includeOptions = (exportOptions!=null) ? exportOptions.ModelAnimIncludeOption : ExportSettings.Include.ModelAndAnim;
3091+
if (exportOptions==null)
3092+
exportOptions = DefaultOptions;
3093+
Debug.Assert(exportOptions!=null);
30683094

30693095
Dictionary<GameObject, IExportData> exportData = new Dictionary<GameObject, IExportData>();
30703096

3071-
if (includeOptions == ExportSettings.Include.Anim)
3097+
if (exportOptions.ModelAnimIncludeOption == ExportSettings.Include.Anim)
30723098
{
30733099
foreach (var obj in objects)
30743100
{
@@ -3092,7 +3118,9 @@ internal static Dictionary<GameObject, IExportData> GetExportData(Object[] objec
30923118

30933119
public static IExportData GetExportData(GameObject rootObject, AnimationClip animationClip, IExportOptions exportOptions = null)
30943120
{
3095-
bool includeAnimatedSkinnedMeshes = (exportOptions!=null) ? exportOptions.AnimateSkinnedMesh : true;
3121+
if (exportOptions==null)
3122+
exportOptions = DefaultOptions;
3123+
Debug.Assert(exportOptions!=null);
30963124

30973125
// get animation clips for root object from animation track
30983126
List<AnimationClip> clips = new List<AnimationClip>(){animationClip};
@@ -3102,15 +3130,17 @@ public static IExportData GetExportData(GameObject rootObject, AnimationClip ani
31023130
var exportComponent = new Dictionary<GameObject, System.Type>();
31033131

31043132
var exportData = new AnimationOnlyExportData(animationClips, goToExport, exportComponent);
3105-
exportData.ComputeObjectsInAnimationClips(clips.ToArray(), rootObject, includeAnimatedSkinnedMeshes);
3133+
exportData.CollectDependencies(clips.ToArray(), rootObject, exportOptions);
31063134

31073135
return exportData;
31083136
}
31093137

3110-
internal static IExportData GetExportData(GameObject rootObject, AnimationTrack animationTrack, IExportOptions exportOptions)
3138+
internal static IExportData GetExportData(GameObject rootObject, AnimationTrack animationTrack, IExportOptions exportOptions = null)
31113139
{
3112-
bool includeAnimatedSkinnedMeshes = (exportOptions!=null) ? exportOptions.AnimateSkinnedMesh : true;
3113-
3140+
if (exportOptions==null)
3141+
exportOptions = DefaultOptions;
3142+
Debug.Assert(exportOptions!=null);
3143+
31143144
// get animation clips for root object from animation track
31153145
List<AnimationClip> clips = new List<AnimationClip>();
31163146

@@ -3124,14 +3154,16 @@ internal static IExportData GetExportData(GameObject rootObject, AnimationTrack
31243154
var exportComponent = new Dictionary<GameObject, System.Type>();
31253155

31263156
var exportData = new AnimationOnlyExportData(animationClips, goToExport, exportComponent);
3127-
exportData.ComputeObjectsInAnimationClips(clips.ToArray(), rootObject, includeAnimatedSkinnedMeshes);
3157+
exportData.CollectDependencies(clips.ToArray(), rootObject, exportOptions);
31283158

31293159
return exportData;
31303160
}
31313161

3132-
protected static IExportData GetExportData(GameObject go, IExportOptions exportOptions)
3162+
protected static IExportData GetExportData(GameObject go, IExportOptions exportOptions = null)
31333163
{
3134-
bool includeAnimatedSkinnedMeshes = (exportOptions!=null) ? exportOptions.AnimateSkinnedMesh : true;
3164+
if (exportOptions==null)
3165+
exportOptions = DefaultOptions;
3166+
Debug.Assert(exportOptions!=null);
31353167

31363168
// gather all animation clips
31373169
var legacyAnim = go.GetComponentsInChildren<Animation>();
@@ -3156,7 +3188,7 @@ protected static IExportData GetExportData(GameObject go, IExportOptions exportO
31563188
}
31573189

31583190
var animClips = AnimationUtility.GetAnimationClips(anim.gameObject);
3159-
exportData.ComputeObjectsInAnimationClips(animClips, anim.gameObject, includeAnimatedSkinnedMeshes);
3191+
exportData.CollectDependencies(animClips, anim.gameObject, exportOptions);
31603192
}
31613193

31623194
int depthFromRootAnimator = int.MaxValue;
@@ -3175,7 +3207,7 @@ protected static IExportData GetExportData(GameObject go, IExportOptions exportO
31753207
var controller = anim.runtimeAnimatorController;
31763208
if (controller)
31773209
{
3178-
exportData.ComputeObjectsInAnimationClips(controller.animationClips, anim.gameObject, includeAnimatedSkinnedMeshes);
3210+
exportData.CollectDependencies(controller.animationClips, anim.gameObject, exportOptions);
31793211
}
31803212
}
31813213

@@ -3509,14 +3541,16 @@ internal int ExportAll (
35093541
FbxNode fbxRootNode = fbxScene.GetRootNode ();
35103542
// stores how many objects we have exported, -1 if export was cancelled
35113543
int exportProgress = 0;
3512-
var revisedExportSet = RemoveRedundantObjects(unityExportSet);
3544+
IEnumerable<GameObject> revisedExportSet = null;
35133545

35143546
int count = 0;
35153547
if(animOnly){
35163548
count = GetAnimOnlyHierarchyCount(exportData);
3549+
revisedExportSet = from entry in exportData select entry.Key;
35173550
} else {
3518-
count = GetHierarchyCount (revisedExportSet);
3519-
3551+
var revisedGOSet = RemoveRedundantObjects(unityExportSet);
3552+
count = GetHierarchyCount (revisedGOSet);
3553+
revisedExportSet = revisedGOSet;
35203554
}
35213555

35223556
if(count <= 0){
@@ -3530,7 +3564,7 @@ internal int ExportAll (
35303564
switch(ExportOptions.ObjectPosition){
35313565
case ExportSettings.ObjectPosition.LocalCentered:
35323566
// one object to export -> move to (0,0,0)
3533-
if(revisedExportSet.Count == 1){
3567+
if(count == 1){
35343568
var tempList = new List<GameObject>(revisedExportSet);
35353569
center = tempList[0].transform.position;
35363570
break;

0 commit comments

Comments
 (0)