@@ -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 ) ;
0 commit comments