@@ -1889,8 +1889,8 @@ protected void ExportAnimationClip (AnimationClip uniAnimClip, GameObject uniRoo
1889
1889
/// Transfers transform animation from source to dest. Replaces dest's Unity Animation Curves with updated animations.
1890
1890
/// NOTE: Source must be the parent of dest.
1891
1891
/// </summary>
1892
- /// <param name="source">Source.</param>
1893
- /// <param name="dest">Destination.</param>
1892
+ /// <param name="source">Source animated object .</param>
1893
+ /// <param name="dest">Destination, child of the source .</param>
1894
1894
/// <param name="sampleRate">Sample rate.</param>
1895
1895
/// <param name="unityCurves">Unity curves.</param>
1896
1896
private void TransferMotion ( Transform source , Transform dest , float sampleRate , ref Dictionary < GameObject , List < UnityCurve > > unityCurves ) {
@@ -1933,14 +1933,23 @@ private void TransferMotion(Transform source, Transform dest, float sampleRate,
1933
1933
scaleKeyFrames [ k ] = new Keyframe [ sampleTimes . Count ] ;
1934
1934
}
1935
1935
1936
+ // If we have a point in local coords represented as a column-vector x, the equation of x in coordinates relative to source's parent is:
1937
+ // x_grandparent = source * dest * x
1938
+ // Now we're going to change dest to dest' which has the animation from source. And we're going to change
1939
+ // source to source' which has no animation. The equation of x will become:
1940
+ // x_grandparent = source' * dest' * x
1941
+ // We're not changing x_grandparent and x, so we need that:
1942
+ // source * dest = source' * dest'
1943
+ // We know dest and source (both animated) and source' (static). Solve for dest':
1944
+ // dest' = (source')^-1 * source * dest
1936
1945
int keyIndex = 0 ;
1946
+ var sourceStaticMatrixInverse = Matrix4x4 . TRS ( source . localPosition , source . localRotation , source . localScale ) . inverse ;
1937
1947
foreach ( var currSampleTime in sampleTimes )
1938
1948
{
1939
1949
var sourceLocalMatrix = GetTransformMatrix ( currSampleTime , source , sourceUnityCurves ) ;
1940
1950
var destLocalMatrix = GetTransformMatrix ( currSampleTime , dest , destUnityCurves ) ;
1941
1951
1942
- // child * parent
1943
- var newLocalMatrix = sourceLocalMatrix * destLocalMatrix ;
1952
+ var newLocalMatrix = sourceStaticMatrixInverse * sourceLocalMatrix * destLocalMatrix ;
1944
1953
1945
1954
FbxVector4 translation , rotation , scale ;
1946
1955
GetTRSFromMatrix ( newLocalMatrix , out translation , out rotation , out scale ) ;
@@ -2227,9 +2236,6 @@ protected int ExportTransformHierarchy(
2227
2236
// Use RSrs as the scaling inheritance instead.
2228
2237
fbxNode . SetTransformationInheritType ( FbxTransform . EInheritType . eInheritRSrs ) ;
2229
2238
2230
- if ( TransformShouldBeReset ( unityGo . transform ) ) {
2231
- exportType = TransformExportType . Reset ;
2232
- }
2233
2239
ExportTransform ( unityGo . transform , fbxNode , newCenter , exportType ) ;
2234
2240
2235
2241
fbxNodeParent . AddChild ( fbxNode ) ;
@@ -2278,35 +2284,6 @@ protected int ExportTransformHierarchy(
2278
2284
return numObjectsExported ;
2279
2285
}
2280
2286
2281
- /// <summary>
2282
- /// Checks if the transform should be reset.
2283
- /// Transform should be reset if animation is being transferred, and this transform
2284
- /// is either the animation source, destination, or between these nodes.
2285
- /// </summary>
2286
- /// <returns><c>true</c>, if transform should be reset, <c>false</c> otherwise.</returns>
2287
- /// <param name="t">Transform.</param>
2288
- private bool TransformShouldBeReset ( Transform t ) {
2289
- var source = ExportOptions . AnimationSource ;
2290
- var dest = ExportOptions . AnimationDest ;
2291
-
2292
- if ( ! source || ! dest || source == dest ) {
2293
- return false ;
2294
- }
2295
-
2296
- // don't want to reset destination, if it's a bone this could cause issues with the skinning
2297
- var curr = dest . parent ;
2298
- while ( curr != source && curr != null ) {
2299
- if ( t == curr ) {
2300
- return true ;
2301
- }
2302
- curr = curr . parent ;
2303
- }
2304
- if ( t == source ) {
2305
- return true ;
2306
- }
2307
- return false ;
2308
- }
2309
-
2310
2287
/// <summary>
2311
2288
/// Export data containing what to export when
2312
2289
/// exporting animation only.
@@ -2534,9 +2511,6 @@ private bool ExportGameObjectAndParents(
2534
2511
2535
2512
// export regular transform if we are not a bone or failed to export as a bone
2536
2513
if ( ! exportedBoneTransform ) {
2537
- if ( TransformShouldBeReset ( unityGo . transform ) ) {
2538
- exportType = TransformExportType . Reset ;
2539
- }
2540
2514
ExportTransform ( unityGo . transform , fbxNode , newCenter , exportType ) ;
2541
2515
}
2542
2516
0 commit comments