@@ -800,12 +800,7 @@ private bool ExportSkeleton (SkinnedMeshRenderer skinnedMesh, FbxScene fbxScene)
800
800
// its corresponding parent, or to the scene if there is none.
801
801
FbxNode fbxBoneNode ;
802
802
if ( ! MapUnityObjectToFbxNode . TryGetValue ( t . gameObject , out fbxBoneNode ) ) {
803
- if ( ExportSettings . mayaCompatibleNames ) {
804
- t . name = ConvertToMayaCompatibleName ( t . name ) ;
805
- }
806
- fbxBoneNode = FbxNode . Create ( fbxScene , t . name ) ;
807
- fbxBoneNode . SetTransformationInheritType ( FbxTransform . EInheritType . eInheritRSrs ) ;
808
- MapUnityObjectToFbxNode . Add ( t . gameObject , fbxBoneNode ) ;
803
+ Debug . LogError ( "node should already be created" ) ;
809
804
}
810
805
811
806
// Set it up as a skeleton node if we haven't already.
@@ -828,18 +823,11 @@ private bool ExportSkeleton (SkinnedMeshRenderer skinnedMesh, FbxScene fbxScene)
828
823
}
829
824
}
830
825
831
- // Step 2: connect up the hierarchy.
832
826
var boneList = boneSet . ToArray ( ) ;
833
- foreach ( var unityBone in boneList ) {
834
- if ( unityBone . parent != null && MapUnityObjectToFbxNode . ContainsKey ( unityBone . parent . gameObject ) ) {
835
- var fbxBone = MapUnityObjectToFbxNode [ unityBone . gameObject ] ;
836
- var fbxParent = MapUnityObjectToFbxNode [ unityBone . parent . gameObject ] ;
837
- fbxParent . AddChild ( fbxBone ) ;
838
- }
839
- }
840
827
841
- // Get bindposes
842
828
SkinnedMeshToBonesMap . Add ( skinnedMesh , boneList ) ;
829
+
830
+ // Step 2: Get bindposes
843
831
var boneToBindPose = new Dictionary < Transform , Matrix4x4 > ( ) ;
844
832
for ( int boneIndex = 0 , n = boneList . Length ; boneIndex < n ; boneIndex ++ ) {
845
833
var unityBone = boneList [ boneIndex ] ;
@@ -1206,9 +1194,17 @@ private string GetUniqueName(string name)
1206
1194
}
1207
1195
1208
1196
/// <summary>
1209
- /// Unconditionally export components on this game object
1197
+ /// Creates an FbxNode for each GameObject.
1210
1198
/// </summary>
1211
- protected int ExportComponents (
1199
+ /// <returns>The nodes.</returns>
1200
+ /// <param name="unityGo">Unity go.</param>
1201
+ /// <param name="fbxScene">Fbx scene.</param>
1202
+ /// <param name="fbxNodeParent">Fbx node parent.</param>
1203
+ /// <param name="exportProgress">Export progress.</param>
1204
+ /// <param name="objectCount">Object count.</param>
1205
+ /// <param name="newCenter">New center.</param>
1206
+ /// <param name="exportType">Export type.</param>
1207
+ protected int ExportNodes (
1212
1208
GameObject unityGo , FbxScene fbxScene , FbxNode fbxNodeParent ,
1213
1209
int exportProgress , int objectCount , Vector3 newCenter ,
1214
1210
TransformExportType exportType = TransformExportType . Local )
@@ -1220,18 +1216,14 @@ protected int ExportComponents (
1220
1216
}
1221
1217
1222
1218
// create an FbxNode and add it as a child of parent
1223
- FbxNode fbxNode ;
1224
- bool alreadyExported = MapUnityObjectToFbxNode . TryGetValue ( unityGo , out fbxNode ) ;
1225
- if ( ! alreadyExported ) {
1226
- fbxNode = FbxNode . Create ( fbxScene , GetUniqueName ( unityGo . name ) ) ;
1227
- }
1219
+ FbxNode fbxNode = FbxNode . Create ( fbxScene , GetUniqueName ( unityGo . name ) ) ;
1228
1220
NumNodes ++ ;
1229
1221
1230
1222
numObjectsExported ++ ;
1231
1223
if ( EditorUtility . DisplayCancelableProgressBar (
1232
- ProgressBarTitle ,
1233
- string . Format ( "Creating FbxNode {0}/{1}" , numObjectsExported , objectCount ) ,
1234
- ( numObjectsExported / ( float ) objectCount ) * 0.5f ) ) {
1224
+ ProgressBarTitle ,
1225
+ string . Format ( "Creating FbxNode {0}/{1}" , numObjectsExported , objectCount ) ,
1226
+ ( numObjectsExported / ( float ) objectCount ) * 0.25f ) ) {
1235
1227
// cancel silently
1236
1228
return - 1 ;
1237
1229
}
@@ -1243,8 +1235,41 @@ protected int ExportComponents (
1243
1235
// Use RSrs as the scaling inhertiance instead.
1244
1236
fbxNode . SetTransformationInheritType ( FbxTransform . EInheritType . eInheritRSrs ) ;
1245
1237
1246
- if ( ! alreadyExported ) {
1247
- ExportTransform ( unityGo . transform , fbxNode , newCenter , exportType ) ;
1238
+ ExportTransform ( unityGo . transform , fbxNode , newCenter , exportType ) ;
1239
+
1240
+ MapUnityObjectToFbxNode . Add ( unityGo , fbxNode ) ;
1241
+
1242
+ if ( Verbose )
1243
+ Debug . Log ( string . Format ( "exporting {0}" , fbxNode . GetName ( ) ) ) ;
1244
+
1245
+ fbxNodeParent . AddChild ( fbxNode ) ;
1246
+
1247
+ // now unityGo through our children and recurse
1248
+ foreach ( Transform childT in unityGo . transform ) {
1249
+ numObjectsExported = ExportNodes ( childT . gameObject , fbxScene , fbxNode , numObjectsExported , objectCount , newCenter ) ;
1250
+ }
1251
+ return numObjectsExported ;
1252
+ }
1253
+
1254
+ /// <summary>
1255
+ /// Unconditionally export components on this game object
1256
+ /// </summary>
1257
+ protected bool ExportComponents ( FbxScene fbxScene )
1258
+ {
1259
+ int numObjectsExported = 0 ;
1260
+ int objectCount = MapUnityObjectToFbxNode . Count ;
1261
+ foreach ( KeyValuePair < GameObject , FbxNode > entry in MapUnityObjectToFbxNode ) {
1262
+ numObjectsExported ++ ;
1263
+ if ( EditorUtility . DisplayCancelableProgressBar (
1264
+ ProgressBarTitle ,
1265
+ string . Format ( "Exporting Components for GameObject {0}/{1}" , numObjectsExported , objectCount ) ,
1266
+ ( ( numObjectsExported / ( float ) objectCount ) * 0.25f ) + 0.25f ) ) {
1267
+ // cancel silently
1268
+ return false ;
1269
+ }
1270
+
1271
+ var unityGo = entry . Key ;
1272
+ var fbxNode = entry . Value ;
1248
1273
1249
1274
// try export mesh
1250
1275
bool exportedMesh = ExportInstance ( unityGo , fbxNode , fbxScene ) ;
@@ -1257,20 +1282,8 @@ protected int ExportComponents (
1257
1282
if ( ! exportedMesh ) {
1258
1283
ExportCamera ( unityGo , fbxScene , fbxNode ) ;
1259
1284
}
1260
-
1261
- MapUnityObjectToFbxNode . Add ( unityGo , fbxNode ) ;
1262
1285
}
1263
-
1264
- if ( Verbose )
1265
- Debug . Log ( string . Format ( "exporting {0}" , fbxNode . GetName ( ) ) ) ;
1266
-
1267
- fbxNodeParent . AddChild ( fbxNode ) ;
1268
-
1269
- // now unityGo through our children and recurse
1270
- foreach ( Transform childT in unityGo . transform ) {
1271
- numObjectsExported = ExportComponents ( childT . gameObject , fbxScene , fbxNode , numObjectsExported , objectCount , newCenter ) ;
1272
- }
1273
- return numObjectsExported ;
1286
+ return true ;
1274
1287
}
1275
1288
1276
1289
/// <summary>
@@ -1502,7 +1515,7 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
1502
1515
1503
1516
if ( revisedExportSet . Count == 1 ) {
1504
1517
foreach ( var unityGo in revisedExportSet ) {
1505
- exportProgress = this . ExportComponents (
1518
+ exportProgress = this . ExportNodes (
1506
1519
unityGo , fbxScene , fbxRootNode , exportProgress ,
1507
1520
count , Vector3 . zero , TransformExportType . Reset ) ;
1508
1521
if ( exportCancelled || exportProgress < 0 ) {
@@ -1516,7 +1529,7 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
1516
1529
Vector3 center = ExportSettings . centerObjects ? FindCenter ( revisedExportSet ) : Vector3 . zero ;
1517
1530
1518
1531
foreach ( var unityGo in revisedExportSet ) {
1519
- exportProgress = this . ExportComponents ( unityGo , fbxScene , fbxRootNode ,
1532
+ exportProgress = this . ExportNodes ( unityGo , fbxScene , fbxRootNode ,
1520
1533
exportProgress , count , center , TransformExportType . Global ) ;
1521
1534
if ( exportCancelled || exportProgress < 0 ) {
1522
1535
Debug . LogWarning ( "Export Cancelled" ) ;
@@ -1525,6 +1538,11 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
1525
1538
}
1526
1539
}
1527
1540
1541
+ if ( ! ExportComponents ( fbxScene ) ) {
1542
+ Debug . LogWarning ( "Export Cancelled" ) ;
1543
+ return 0 ;
1544
+ }
1545
+
1528
1546
// Set the scene's default camera.
1529
1547
SetDefaultCamera ( fbxScene ) ;
1530
1548
0 commit comments