Skip to content

Commit dc721b5

Browse files
committed
export tangents instead of baking curves
1 parent 9383351 commit dc721b5

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

com.unity.formats.fbx/Editor/FbxExporter.cs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ internal static HashSet<float> GetKeyTimes(AnimationCurve[] animCurves)
18041804
/// a Cubic curve using the default tangents.
18051805
/// </summary>
18061806
internal void ExportAnimationKeys (AnimationCurve uniAnimCurve, FbxAnimCurve fbxAnimCurve,
1807-
UnityToMayaConvertSceneHelper convertSceneHelper)
1807+
UnityToMayaConvertSceneHelper convertSceneHelper, string uniPropertyName)
18081808
{
18091809
// TODO: complete the mapping between key tangents modes Unity and FBX
18101810
Dictionary<AnimationUtility.TangentMode, List<FbxAnimCurveDef.ETangentMode>> MapUnityKeyTangentModeToFBX =
@@ -1831,14 +1831,47 @@ internal void ExportAnimationKeys (AnimationCurve uniAnimCurve, FbxAnimCurve fbx
18311831

18321832
int fbxKeyIndex = fbxAnimCurve.KeyAdd (fbxTime);
18331833

1834-
fbxAnimCurve.KeySet (fbxKeyIndex,
1835-
fbxTime,
1836-
convertSceneHelper.Convert(uniKeyFrame.value)
1837-
);
18381834

18391835
// configure tangents
18401836
var lTangent = AnimationUtility.GetKeyLeftTangentMode(uniAnimCurve, keyIndex);
18411837
var rTangent = AnimationUtility.GetKeyRightTangentMode(uniAnimCurve, keyIndex);
1838+
FbxAnimCurveDef.ETangentMode tanMode = FbxAnimCurveDef.ETangentMode.eTangentAuto;
1839+
FbxAnimCurveDef.EInterpolationType interpMode = FbxAnimCurveDef.EInterpolationType.eInterpolationCubic;
1840+
switch (rTangent)
1841+
{
1842+
case AnimationUtility.TangentMode.Auto:
1843+
case AnimationUtility.TangentMode.ClampedAuto:
1844+
break;
1845+
case AnimationUtility.TangentMode.Free:
1846+
tanMode = FbxAnimCurveDef.ETangentMode.eTangentUser;
1847+
break;
1848+
case AnimationUtility.TangentMode.Linear:
1849+
interpMode = FbxAnimCurveDef.EInterpolationType.eInterpolationLinear;
1850+
break;
1851+
case AnimationUtility.TangentMode.Constant:
1852+
interpMode = FbxAnimCurveDef.EInterpolationType.eInterpolationConstant;
1853+
break;
1854+
default:
1855+
break;
1856+
}
1857+
1858+
float tangentMultiplier = 100;
1859+
if(uniPropertyName == "m_LocalPosition.x")
1860+
{
1861+
tangentMultiplier *= -1; // have to negate x when switching between Unity->Maya axes
1862+
}
1863+
1864+
fbxAnimCurve.KeySet (fbxKeyIndex,
1865+
fbxTime,
1866+
convertSceneHelper.Convert(uniKeyFrame.value),
1867+
interpMode,//FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
1868+
tanMode,//FbxAnimCurveDef.ETangentMode.eTangentBreak,
1869+
tangentMultiplier*uniKeyFrame.outTangent,
1870+
keyIndex < uniAnimCurve.length -1 ? tangentMultiplier*uniAnimCurve[keyIndex+1].inTangent : 0,
1871+
FbxAnimCurveDef.EWeightedMode.eWeightedAll,
1872+
uniKeyFrame.outWeight,
1873+
keyIndex < uniAnimCurve.length - 1 ? uniAnimCurve[keyIndex + 1].inWeight : 0
1874+
);
18421875

18431876
if (!(MapUnityKeyTangentModeToFBX.ContainsKey(lTangent) && MapUnityKeyTangentModeToFBX.ContainsKey(rTangent)))
18441877
{
@@ -1995,11 +2028,11 @@ private void ExportAnimationCurve (FbxNode fbxNode,
19952028

19962029
// TODO: we'll resample the curve so we don't have to
19972030
// configure tangents
1998-
if (ModelExporter.ExportSettings.BakeAnimationProperty) {
2031+
/*if (ModelExporter.ExportSettings.BakeAnimationProperty) {
19992032
ExportAnimationSamples (uniAnimCurve, fbxAnimCurve, frameRate, convertSceneHelper);
2000-
} else {
2001-
ExportAnimationKeys (uniAnimCurve, fbxAnimCurve, convertSceneHelper);
2002-
}
2033+
} else {*/
2034+
ExportAnimationKeys (uniAnimCurve, fbxAnimCurve, convertSceneHelper, uniPropertyName);
2035+
// }
20032036
}
20042037
}
20052038

0 commit comments

Comments
 (0)