Skip to content

Commit cd25932

Browse files
committed
add progress bar + ability to cancel anim export
1 parent 0e17fc5 commit cd25932

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,7 @@ protected int ExportAnimationOnly(
22032203
){
22042204
// export any bones
22052205
var skinnedMeshRenderers = unityGO.GetComponentsInChildren<SkinnedMeshRenderer> ();
2206+
int numObjectsExported = exportProgress;
22062207

22072208
foreach (var skinnedMesh in skinnedMeshRenderers) {
22082209
var boneArray = skinnedMesh.bones;
@@ -2224,18 +2225,24 @@ protected int ExportAnimationOnly(
22242225

22252226
foreach (var bone in bones) {
22262227
FbxNode node;
2227-
ExportGameObjectAndParents (
2228-
bone.gameObject, unityGO, fbxScene, out node, newCenter, exportType, exportProgress, objectCount, skinnedMesh, boneDict, rootBone, true
2229-
);
2228+
if (!ExportGameObjectAndParents (
2229+
bone.gameObject, unityGO, fbxScene, out node, newCenter, exportType, ref numObjectsExported, objectCount, skinnedMesh, boneDict, rootBone, true
2230+
)) {
2231+
// export cancelled
2232+
return -1;
2233+
}
22302234
}
22312235
}
22322236

22332237
// export everything else
22342238
foreach (var go in exportData.goExportSet) {
22352239
FbxNode node;
2236-
ExportGameObjectAndParents (
2237-
go, unityGO, fbxScene, out node, newCenter, exportType, exportProgress, objectCount
2238-
);
2240+
if (!ExportGameObjectAndParents (
2241+
go, unityGO, fbxScene, out node, newCenter, exportType, ref numObjectsExported, objectCount
2242+
)) {
2243+
// export cancelled
2244+
return -1;
2245+
}
22392246

22402247
System.Type compType;
22412248
if (exportData.exportComponent.TryGetValue (go, out compType)) {
@@ -2252,7 +2259,7 @@ protected int ExportAnimationOnly(
22522259
ExportAnimationClip (animClip.Key, animClip.Value, fbxScene);
22532260
}
22542261

2255-
return 0;
2262+
return numObjectsExported;
22562263
}
22572264

22582265
private bool ExportGameObjectAndParents(
@@ -2262,7 +2269,7 @@ private bool ExportGameObjectAndParents(
22622269
out FbxNode fbxNode,
22632270
Vector3 newCenter,
22642271
TransformExportType exportType,
2265-
int exportProgress,
2272+
ref int exportProgress,
22662273
int objectCount,
22672274
SkinnedMeshRenderer skinnedMesh = null,
22682275
Dictionary<Transform, int> boneDict = null,
@@ -2282,6 +2289,15 @@ private bool ExportGameObjectAndParents(
22822289
fbxNode = FbxNode.Create (fbxScene, GetUniqueName (unityGo.name));
22832290
MapUnityObjectToFbxNode [unityGo] = fbxNode;
22842291

2292+
exportProgress++;
2293+
if (EditorUtility.DisplayCancelableProgressBar (
2294+
ProgressBarTitle,
2295+
string.Format ("Creating FbxNode {0}/{1}", exportProgress, objectCount),
2296+
(exportProgress / (float)objectCount) * 0.5f)) {
2297+
// cancel silently
2298+
return false;
2299+
}
2300+
22852301
// Default inheritance type in FBX is RrSs, which causes scaling issues in Maya as
22862302
// both Maya and Unity use RSrs inheritance by default.
22872303
// Note: MotionBuilder uses RrSs inheritance by default as well, though it is possible
@@ -2312,14 +2328,14 @@ private bool ExportGameObjectAndParents(
23122328
out fbxNodeParent,
23132329
newCenter,
23142330
TransformExportType.Local,
2315-
exportProgress,
2331+
ref exportProgress,
23162332
objectCount,
23172333
skinnedMesh,
23182334
boneDict,
23192335
rootBone,
23202336
parentIsBone
23212337
)) {
2322-
Debug.LogWarningFormat ("Failed to export GameObject {0}", unityGo.transform.parent.name);
2338+
// export cancelled
23232339
return false;
23242340
}
23252341
fbxNodeParent.AddChild (fbxNode);

0 commit comments

Comments
 (0)