Skip to content

Commit 759f3ea

Browse files
committed
move GetObjectsInAnimationClips function into export data struct
1 parent 6d66c08 commit 759f3ea

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,44 @@ public AnimationOnlyExportData(
21442144
this.exportComponent = exportComponent;
21452145
this.defaultClip = null;
21462146
}
2147+
2148+
public void ComputeObjectsInAnimationClips(
2149+
AnimationClip[] animClips,
2150+
GameObject animationRootObject
2151+
){
2152+
// TODO: find a better way to keep track of which components + properties we support
2153+
var cameraProps = new List<string>{"field of view"};
2154+
var lightProps = new List<string>{"m_Intensity", "m_SpotAngle", "m_Color.r", "m_Color.g", "m_Color.b"};
2155+
2156+
foreach (var animClip in animClips) {
2157+
if (this.animationClips.ContainsKey(animClip)) {
2158+
// we have already exported gameobjects for this clip
2159+
continue;
2160+
}
2161+
2162+
this.animationClips.Add (animClip, animationRootObject);
2163+
2164+
foreach (EditorCurveBinding uniCurveBinding in AnimationUtility.GetCurveBindings (animClip)) {
2165+
Object uniObj = AnimationUtility.GetAnimatedObject (animationRootObject, uniCurveBinding);
2166+
if (!uniObj) {
2167+
continue;
2168+
}
2169+
2170+
GameObject unityGo = GetGameObject (uniObj);
2171+
if (!unityGo) {
2172+
continue;
2173+
}
2174+
2175+
if (lightProps.Contains (uniCurveBinding.propertyName)) {
2176+
this.exportComponent.Add (unityGo, typeof(Light));
2177+
} else if (cameraProps.Contains (uniCurveBinding.propertyName)) {
2178+
this.exportComponent.Add (unityGo, typeof(Camera));
2179+
}
2180+
2181+
this.goExportSet.Add (unityGo);
2182+
}
2183+
}
2184+
}
21472185
}
21482186

21492187
/// <summary>
@@ -2468,7 +2506,7 @@ out Dictionary<GameObject, AnimationOnlyExportData> hierarchyToExportData
24682506
}
24692507

24702508
var animClips = AnimationUtility.GetAnimationClips (anim.gameObject);
2471-
GetObjectsInAnimationClips (animClips, anim.gameObject, ref exportData);
2509+
exportData.ComputeObjectsInAnimationClips (animClips, anim.gameObject);
24722510
}
24732511

24742512
int aFromRoot = int.MaxValue;
@@ -2485,7 +2523,7 @@ out Dictionary<GameObject, AnimationOnlyExportData> hierarchyToExportData
24852523
var controller = anim.runtimeAnimatorController;
24862524
if (controller)
24872525
{
2488-
GetObjectsInAnimationClips (controller.animationClips, anim.gameObject, ref exportData);
2526+
exportData.ComputeObjectsInAnimationClips (controller.animationClips, anim.gameObject);
24892527
}
24902528
}
24912529

@@ -2526,45 +2564,6 @@ out Dictionary<GameObject, AnimationOnlyExportData> hierarchyToExportData
25262564
return completeExpSet.Count;
25272565
}
25282566

2529-
protected void GetObjectsInAnimationClips(
2530-
AnimationClip[] animClips,
2531-
GameObject animationRootObject,
2532-
ref AnimationOnlyExportData exportData
2533-
){
2534-
// TODO: find a better way to keep track of which components + properties we support
2535-
var cameraProps = new List<string>{"field of view"};
2536-
var lightProps = new List<string>{"m_Intensity", "m_SpotAngle", "m_Color.r", "m_Color.g", "m_Color.b"};
2537-
2538-
foreach (var animClip in animClips) {
2539-
if (exportData.animationClips.ContainsKey(animClip)) {
2540-
// we have already exported gameobjects for this clip
2541-
continue;
2542-
}
2543-
2544-
exportData.animationClips.Add (animClip, animationRootObject);
2545-
2546-
foreach (EditorCurveBinding uniCurveBinding in AnimationUtility.GetCurveBindings (animClip)) {
2547-
Object uniObj = AnimationUtility.GetAnimatedObject (animationRootObject, uniCurveBinding);
2548-
if (!uniObj) {
2549-
continue;
2550-
}
2551-
2552-
GameObject unityGo = GetGameObject (uniObj);
2553-
if (!unityGo) {
2554-
continue;
2555-
}
2556-
2557-
if (lightProps.Contains (uniCurveBinding.propertyName)) {
2558-
exportData.exportComponent.Add (unityGo, typeof(Light));
2559-
} else if (cameraProps.Contains (uniCurveBinding.propertyName)) {
2560-
exportData.exportComponent.Add (unityGo, typeof(Camera));
2561-
}
2562-
2563-
exportData.goExportSet.Add (unityGo);
2564-
}
2565-
}
2566-
}
2567-
25682567
/// <summary>
25692568
/// Export components on this game object.
25702569
/// Transform components have already been exported.

0 commit comments

Comments
 (0)