Skip to content

Commit 0e17fc5

Browse files
committed
pass export data in a struct
1 parent b4031d9 commit 0e17fc5

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,15 +2176,29 @@ protected int ExportTransformHierarchy(
21762176
return numObjectsExported;
21772177
}
21782178

2179-
protected void ExportAnimationOnly(
2179+
public struct AnimationOnlyExportData {
2180+
public Dictionary<AnimationClip, GameObject> animationClips;
2181+
public HashSet<GameObject> goExportSet;
2182+
public Dictionary<GameObject, System.Type> exportComponent;
2183+
2184+
public AnimationOnlyExportData(
2185+
Dictionary<AnimationClip, GameObject> animClips,
2186+
HashSet<GameObject> exportSet,
2187+
Dictionary<GameObject, System.Type> exportComponent
2188+
){
2189+
this.animationClips = animClips;
2190+
this.goExportSet = exportSet;
2191+
this.exportComponent = exportComponent;
2192+
}
2193+
}
2194+
2195+
protected int ExportAnimationOnly(
21802196
GameObject unityGO,
21812197
FbxScene fbxScene,
21822198
int exportProgress,
21832199
int objectCount,
21842200
Vector3 newCenter,
2185-
Dictionary<AnimationClip, GameObject> animationClips,
2186-
HashSet<GameObject> goExportSet,
2187-
Dictionary<GameObject, System.Type> exportComponent,
2201+
AnimationOnlyExportData exportData,
21882202
TransformExportType exportType = TransformExportType.Local
21892203
){
21902204
// export any bones
@@ -2203,10 +2217,10 @@ protected void ExportAnimationOnly(
22032217
var rootBone = skinnedMesh.rootBone;
22042218

22052219
// get the bones that are also in the export set
2206-
bones.IntersectWith (goExportSet);
2220+
bones.IntersectWith (exportData.goExportSet);
22072221

22082222
// remove the exported bones from the export set
2209-
goExportSet.ExceptWith (bones);
2223+
exportData.goExportSet.ExceptWith (bones);
22102224

22112225
foreach (var bone in bones) {
22122226
FbxNode node;
@@ -2217,14 +2231,14 @@ protected void ExportAnimationOnly(
22172231
}
22182232

22192233
// export everything else
2220-
foreach (var go in goExportSet) {
2234+
foreach (var go in exportData.goExportSet) {
22212235
FbxNode node;
22222236
ExportGameObjectAndParents (
22232237
go, unityGO, fbxScene, out node, newCenter, exportType, exportProgress, objectCount
22242238
);
22252239

22262240
System.Type compType;
2227-
if (exportComponent.TryGetValue (go, out compType)) {
2241+
if (exportData.exportComponent.TryGetValue (go, out compType)) {
22282242
if (compType == typeof(Light)) {
22292243
ExportLight (go, fbxScene, node);
22302244
} else if (compType == typeof(Camera)) {
@@ -2234,9 +2248,11 @@ protected void ExportAnimationOnly(
22342248
}
22352249

22362250
// export animation
2237-
foreach (var animClip in animationClips) {
2251+
foreach (var animClip in exportData.animationClips) {
22382252
ExportAnimationClip (animClip.Key, animClip.Value, fbxScene);
22392253
}
2254+
2255+
return 0;
22402256
}
22412257

22422258
private bool ExportGameObjectAndParents(
@@ -2392,42 +2408,43 @@ private bool ExportBoneTransform(
23922408
return true;
23932409
}
23942410

2395-
protected int AnimOnlyHierarchyCount(
2411+
protected int GetAnimOnlyHierarchyCount(
23962412
HashSet<GameObject> exportSet,
2397-
out Dictionary<AnimationClip, GameObject> animationClips,
2398-
out Dictionary<GameObject, HashSet<GameObject>> mapGameObjectToExportSet,
2399-
out Dictionary<GameObject, System.Type> exportComponent
2413+
out Dictionary<GameObject, AnimationOnlyExportData> hierarchyToExportData
24002414
){
2401-
animationClips = new Dictionary<AnimationClip, GameObject> ();
2402-
mapGameObjectToExportSet = new Dictionary<GameObject, HashSet<GameObject>> ();
2403-
exportComponent = new Dictionary<GameObject, System.Type> ();
2415+
hierarchyToExportData = new Dictionary<GameObject, AnimationOnlyExportData>();
24042416

24052417
foreach (var go in exportSet) {
24062418
// gather all animation clips
24072419
var legacyAnim = go.GetComponentsInChildren<Animation>();
24082420
var genericAnim = go.GetComponentsInChildren<Animator> ();
24092421

24102422
var goToExport = new HashSet<GameObject> ();
2411-
mapGameObjectToExportSet.Add (go, goToExport);
2423+
var animationClips = new Dictionary<AnimationClip, GameObject> ();
2424+
var exportComponent = new Dictionary<GameObject, System.Type> ();
2425+
2426+
var exportData = new AnimationOnlyExportData (animationClips, goToExport, exportComponent);
2427+
2428+
hierarchyToExportData.Add (go, exportData);
24122429

24132430
foreach (var anim in legacyAnim) {
24142431
var animClips = AnimationUtility.GetAnimationClips (anim.gameObject);
2415-
GetObjectsInAnimationClips (animClips, anim.gameObject, ref animationClips, ref goToExport, ref exportComponent);
2432+
GetObjectsInAnimationClips (animClips, anim.gameObject, ref exportData);
24162433
}
24172434

24182435
foreach (var anim in genericAnim) {
24192436
// Try the animator controller (mecanim)
24202437
var controller = anim.runtimeAnimatorController;
24212438
if (controller)
24222439
{
2423-
GetObjectsInAnimationClips (controller.animationClips, anim.gameObject, ref animationClips, ref goToExport, ref exportComponent);
2440+
GetObjectsInAnimationClips (controller.animationClips, anim.gameObject, ref exportData);
24242441
}
24252442
}
24262443
}
24272444

24282445
int count = 0;
2429-
foreach (var es in mapGameObjectToExportSet.Values) {
2430-
count += es.Count;
2446+
foreach (var data in hierarchyToExportData.Values) {
2447+
count += data.goExportSet.Count;
24312448
}
24322449

24332450
return count;
@@ -2436,20 +2453,18 @@ protected int AnimOnlyHierarchyCount(
24362453
protected void GetObjectsInAnimationClips(
24372454
AnimationClip[] animClips,
24382455
GameObject animationRootObject,
2439-
ref Dictionary<AnimationClip, GameObject> clipSet,
2440-
ref HashSet<GameObject> goToExport,
2441-
ref Dictionary<GameObject, System.Type> exportComponent
2456+
ref AnimationOnlyExportData exportData
24422457
){
24432458
var cameraProps = new List<string>{"field of view"};
24442459
var lightProps = new List<string>{"m_Intensity", "m_SpotAngle", "m_Color.r", "m_Color.g", "m_Color.b"};
24452460

24462461
foreach (var animClip in animClips) {
2447-
if (clipSet.ContainsKey(animClip)) {
2462+
if (exportData.animationClips.ContainsKey(animClip)) {
24482463
// we have already exported gameobjects for this clip
24492464
continue;
24502465
}
24512466

2452-
clipSet.Add (animClip, animationRootObject);
2467+
exportData.animationClips.Add (animClip, animationRootObject);
24532468

24542469
foreach (EditorCurveBinding uniCurveBinding in AnimationUtility.GetCurveBindings (animClip)) {
24552470
Object uniObj = AnimationUtility.GetAnimatedObject (animationRootObject, uniCurveBinding);
@@ -2464,12 +2479,12 @@ protected void GetObjectsInAnimationClips(
24642479
}
24652480

24662481
if (lightProps.Contains (uniCurveBinding.propertyName)) {
2467-
exportComponent.Add (unityGo, typeof(Light));
2482+
exportData.exportComponent.Add (unityGo, typeof(Light));
24682483
} else if (cameraProps.Contains (uniCurveBinding.propertyName)) {
2469-
exportComponent.Add (unityGo, typeof(Camera));
2484+
exportData.exportComponent.Add (unityGo, typeof(Camera));
24702485
}
24712486

2472-
goToExport.Add (unityGo);
2487+
exportData.goExportSet.Add (unityGo);
24732488
}
24742489
}
24752490
}

0 commit comments

Comments
 (0)