Skip to content

Commit 2ffef6e

Browse files
committed
export default clip first
- default clip is the default clip of the top most animator in the hierarchy
1 parent 3d277bf commit 2ffef6e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,14 @@ protected int ExportAnimationOnly(
22132213
}
22142214

22152215
// export animation
2216+
2217+
// export default clip first
2218+
if (exportData.defaultClip != null) {
2219+
var defaultClip = exportData.defaultClip;
2220+
ExportAnimationClip (defaultClip, exportData.animationClips[defaultClip], fbxScene);
2221+
exportData.animationClips.Remove (defaultClip);
2222+
}
2223+
22162224
foreach (var animClip in exportData.animationClips) {
22172225
ExportAnimationClip (animClip.Key, animClip.Value, fbxScene);
22182226
}
@@ -2402,19 +2410,68 @@ out Dictionary<GameObject, AnimationOnlyExportData> hierarchyToExportData
24022410

24032411
hierarchyToExportData.Add (go, exportData);
24042412

2413+
int fromRoot = int.MaxValue;
2414+
Animation rootAnimation = null;
24052415
foreach (var anim in legacyAnim) {
2416+
int count = 0;
2417+
var parent = anim.transform.parent;
2418+
while (parent != null && parent != go.transform) {
2419+
count++;
2420+
parent = parent.parent;
2421+
}
2422+
2423+
if (count < fromRoot) {
2424+
fromRoot = count;
2425+
rootAnimation = anim;
2426+
}
2427+
24062428
var animClips = AnimationUtility.GetAnimationClips (anim.gameObject);
24072429
GetObjectsInAnimationClips (animClips, anim.gameObject, ref exportData);
24082430
}
24092431

2432+
int aFromRoot = int.MaxValue;
2433+
Animator rootAnimator = null;
24102434
foreach (var anim in genericAnim) {
2435+
int count = 0;
2436+
var parent = anim.transform.parent;
2437+
while (parent != null && parent != go.transform) {
2438+
count++;
2439+
parent = parent.parent;
2440+
}
2441+
2442+
if (count < aFromRoot) {
2443+
aFromRoot = count;
2444+
rootAnimator = anim;
2445+
}
2446+
24112447
// Try the animator controller (mecanim)
24122448
var controller = anim.runtimeAnimatorController;
24132449
if (controller)
24142450
{
24152451
GetObjectsInAnimationClips (controller.animationClips, anim.gameObject, ref exportData);
24162452
}
24172453
}
2454+
2455+
// set the first clip to export
2456+
if (fromRoot < aFromRoot) {
2457+
exportData.defaultClip = rootAnimation.clip;
2458+
} else {
2459+
// Try the animator controller (mecanim)
2460+
var controller = rootAnimator.runtimeAnimatorController;
2461+
if (controller) {
2462+
var dController = controller as UnityEditor.Animations.AnimatorController;
2463+
if (dController && dController.layers.Count () > 0) {
2464+
var motion = dController.layers [0].stateMachine.defaultState.motion;
2465+
var defaultClip = motion as AnimationClip;
2466+
if (defaultClip) {
2467+
Debug.LogWarning ("default clip: " + defaultClip.name);
2468+
exportData.defaultClip = defaultClip;
2469+
} else {
2470+
Debug.LogWarningFormat ("Couldn't export motion {0}", motion.name);
2471+
}
2472+
}
2473+
}
2474+
}
24182475
}
24192476

24202477
// including any parents of animated objects that are exported

0 commit comments

Comments
 (0)