@@ -2176,25 +2176,110 @@ protected int ExportTransformHierarchy(
2176
2176
return numObjectsExported ;
2177
2177
}
2178
2178
2179
- protected bool ExportAnimationOnly ( GameObject unityGo , FbxScene fbxScene , FbxNode fbxNodeParent ) {
2179
+ protected bool ExportAnimationOnly ( GameObject unityGo , FbxScene fbxScene ) {
2180
2180
// gather all animation clips
2181
2181
var legacyAnim = unityGo . GetComponentsInChildren < Animation > ( ) ;
2182
2182
var genericAnim = unityGo . GetComponentsInChildren < Animator > ( ) ;
2183
2183
2184
+ // from clips determine what needs to be exported
2185
+
2186
+ // export nodes and their parent hierarchies
2187
+
2188
+ // export objects as we go, create parent hierarchies after
2189
+ // store objects in a set, along with parents that need to be exported..
2190
+
2191
+ // also need to know if a gameobject is a bone and export accordingly
2192
+
2193
+ // export components
2194
+ // only light and camera components, and only if that component is animated
2195
+
2196
+ // export animation
2197
+
2198
+ var animationClips = new HashSet < AnimationClip > ( ) ;
2199
+
2184
2200
foreach ( var anim in legacyAnim ) {
2185
- var animClip = anim . clip ;
2201
+ var animClips = AnimationUtility . GetAnimationClips ( anim . gameObject ) ;
2202
+ ExportAnimatedGameObjects ( animClips , anim . gameObject , unityGo , fbxScene , ref animationClips ) ;
2203
+ }
2204
+
2205
+ foreach ( var anim in genericAnim ) {
2206
+ // Try the animator controller (mecanim)
2207
+ var controller = anim . runtimeAnimatorController ;
2208
+ if ( controller )
2209
+ {
2210
+ ExportAnimatedGameObjects ( controller . animationClips , anim . gameObject , unityGo , fbxScene , ref animationClips ) ;
2211
+ }
2212
+ }
2213
+
2214
+ return false ;
2215
+ }
2216
+
2217
+ private bool ExportAnimatedGameObjects ( AnimationClip [ ] animClips , GameObject animationRootObject , GameObject exportRoot , FbxScene fbxScene , ref HashSet < AnimationClip > clipSet ) {
2218
+ foreach ( var animClip in animClips ) {
2219
+ if ( ! clipSet . Add ( animClip ) ) {
2220
+ // we have already exported gameobjects for this clip
2221
+ continue ;
2222
+ }
2223
+
2186
2224
foreach ( EditorCurveBinding uniCurveBinding in AnimationUtility . GetCurveBindings ( animClip ) ) {
2187
- Object uniObj = AnimationUtility . GetAnimatedObject ( anim . gameObject , uniCurveBinding ) ;
2225
+ Object uniObj = AnimationUtility . GetAnimatedObject ( animationRootObject , uniCurveBinding ) ;
2188
2226
if ( ! uniObj ) {
2189
2227
continue ;
2190
2228
}
2191
- Debug . LogWarning ( uniObj . name + ": " + uniCurveBinding . propertyName ) ;
2229
+ //Debug.LogWarning (uniObj.name + ": " + uniCurveBinding.propertyName);
2230
+
2231
+ GameObject unityGo = GetGameObject ( uniObj ) ;
2232
+ if ( ! unityGo ) {
2233
+ continue ;
2234
+ }
2235
+ FbxNode fbxNode ;
2236
+ ExportGameObjectAndParents ( unityGo , exportRoot , fbxScene , out fbxNode ) ;
2192
2237
}
2193
2238
}
2194
2239
2195
2240
return false ;
2196
2241
}
2197
2242
2243
+ private bool ExportGameObjectAndParents ( GameObject unityGo , GameObject rootObject , FbxScene fbxScene , out FbxNode fbxNode ) {
2244
+ // node already exists
2245
+ if ( MapUnityObjectToFbxNode . TryGetValue ( unityGo , out fbxNode ) ) {
2246
+ return true ;
2247
+ }
2248
+
2249
+ if ( ExportSettings . mayaCompatibleNames ) {
2250
+ unityGo . name = ConvertToMayaCompatibleName ( unityGo . name ) ;
2251
+ }
2252
+
2253
+ // create an FbxNode and add it as a child of parent
2254
+ fbxNode = FbxNode . Create ( fbxScene , GetUniqueName ( unityGo . name ) ) ;
2255
+ MapUnityObjectToFbxNode [ unityGo ] = fbxNode ;
2256
+
2257
+ // Default inheritance type in FBX is RrSs, which causes scaling issues in Maya as
2258
+ // both Maya and Unity use RSrs inheritance by default.
2259
+ // Note: MotionBuilder uses RrSs inheritance by default as well, though it is possible
2260
+ // to select a different inheritance type in the UI.
2261
+ // Use RSrs as the scaling inhertiance instead.
2262
+ fbxNode . SetTransformationInheritType ( FbxTransform . EInheritType . eInheritRSrs ) ;
2263
+
2264
+ ExportTransform ( unityGo . transform , fbxNode , Vector3 . zero , TransformExportType . Local ) ; //newCenter, exportType);
2265
+
2266
+ if ( unityGo . transform . parent != null || unityGo . transform . parent != rootObject . transform . parent ) {
2267
+ FbxNode fbxNodeParent ;
2268
+ if ( ! ExportGameObjectAndParents ( unityGo . transform . parent . gameObject , rootObject , fbxScene , out fbxNodeParent ) ) {
2269
+ Debug . LogWarningFormat ( "Failed to export GameObject {0}" , unityGo . transform . parent . name ) ;
2270
+ return false ;
2271
+ }
2272
+ fbxNodeParent . AddChild ( fbxNode ) ;
2273
+ }
2274
+
2275
+ if ( unityGo == rootObject ) {
2276
+ Debug . Log ( "over here" ) ;
2277
+ fbxScene . GetRootNode ( ) . AddChild ( fbxNode ) ;
2278
+ }
2279
+
2280
+ return true ;
2281
+ }
2282
+
2198
2283
/// <summary>
2199
2284
/// Export components on this game object.
2200
2285
/// Transform components have already been exported.
0 commit comments