Skip to content

Commit 1f10a22

Browse files
committed
clean up implementation + still sample eulers with prerotation
1 parent dfaad3b commit 1f10a22

File tree

3 files changed

+12
-82
lines changed

3 files changed

+12
-82
lines changed

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

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,23 +1745,9 @@ internal static HashSet<float> GetKeyTimes(AnimationCurve[] animCurves)
17451745
/// NOTE : This is a work in progress (WIP). We only export the key time and value on
17461746
/// a Cubic curve using the default tangents.
17471747
/// </summary>
1748-
internal void ExportAnimationKeys (AnimationCurve uniAnimCurve, FbxAnimCurve fbxAnimCurve,
1748+
internal static void ExportAnimationKeys (AnimationCurve uniAnimCurve, FbxAnimCurve fbxAnimCurve,
17491749
UnityToMayaConvertSceneHelper convertSceneHelper, string uniPropertyName)
17501750
{
1751-
// TODO: complete the mapping between key tangents modes Unity and FBX
1752-
Dictionary<AnimationUtility.TangentMode, List<FbxAnimCurveDef.ETangentMode>> MapUnityKeyTangentModeToFBX =
1753-
new Dictionary<AnimationUtility.TangentMode, List<FbxAnimCurveDef.ETangentMode>>
1754-
{
1755-
//TangeantAuto|GenericTimeIndependent|GenericClampProgressive
1756-
{AnimationUtility.TangentMode.Free, new List<FbxAnimCurveDef.ETangentMode>{FbxAnimCurveDef.ETangentMode.eTangentAuto,FbxAnimCurveDef.ETangentMode.eTangentGenericClampProgressive}},
1757-
1758-
//TangeantAuto|GenericTimeIndependent
1759-
{AnimationUtility.TangentMode.Auto, new List<FbxAnimCurveDef.ETangentMode>{FbxAnimCurveDef.ETangentMode.eTangentAuto,FbxAnimCurveDef.ETangentMode.eTangentGenericTimeIndependent}},
1760-
1761-
//TangeantAuto|GenericTimeIndependent|GenericClampProgressive
1762-
{AnimationUtility.TangentMode.ClampedAuto, new List<FbxAnimCurveDef.ETangentMode>{FbxAnimCurveDef.ETangentMode.eTangentAuto,FbxAnimCurveDef.ETangentMode.eTangentGenericClampProgressive}},
1763-
};
1764-
17651751
// Copy Unity AnimCurve to FBX AnimCurve.
17661752
// NOTE: only cubic keys are supported by the FbxImporter
17671753
using (new FbxAnimCurveModifyHelper(new List<FbxAnimCurve>{fbxAnimCurve}))
@@ -1781,13 +1767,6 @@ internal void ExportAnimationKeys (AnimationCurve uniAnimCurve, FbxAnimCurve fbx
17811767
FbxAnimCurveDef.EInterpolationType interpMode = FbxAnimCurveDef.EInterpolationType.eInterpolationCubic;
17821768
switch (rTangent)
17831769
{
1784-
/*case AnimationUtility.TangentMode.Auto:
1785-
case AnimationUtility.TangentMode.ClampedAuto:
1786-
tanMode = FbxAnimCurveDef.ETangentMode.eTangentAuto;
1787-
break;
1788-
case AnimationUtility.TangentMode.Free:
1789-
tanMode = FbxAnimCurveDef.ETangentMode.eTangentUser;
1790-
break;*/
17911770
case AnimationUtility.TangentMode.Linear:
17921771
interpMode = FbxAnimCurveDef.EInterpolationType.eInterpolationLinear;
17931772
break;
@@ -1799,21 +1778,17 @@ internal void ExportAnimationKeys (AnimationCurve uniAnimCurve, FbxAnimCurve fbx
17991778
break;
18001779
}
18011780

1802-
float tangentMultiplier = 100;
1781+
float tangentMultiplier = UnitScaleFactor;
18031782
if(uniPropertyName.StartsWith("localEulerAnglesRaw"))
18041783
{
18051784
tangentMultiplier = 1;
18061785
}
1807-
if(uniPropertyName == "m_LocalPosition.x" || uniPropertyName == "localEulerAnglesRaw.y" || uniPropertyName == "localEulerAnglesRaw.z")
1808-
{
1809-
tangentMultiplier *= -1; // have to negate x when switching between Unity->Maya axes
1810-
}
18111786

18121787
fbxAnimCurve.KeySet (fbxKeyIndex,
18131788
fbxTime,
18141789
convertSceneHelper.Convert(uniKeyFrame.value),
1815-
interpMode,//FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
1816-
tanMode,//FbxAnimCurveDef.ETangentMode.eTangentBreak,
1790+
interpMode,
1791+
tanMode,
18171792
tangentMultiplier*uniKeyFrame.outTangent,
18181793
keyIndex < uniAnimCurve.length -1 ? tangentMultiplier*uniAnimCurve[keyIndex+1].inTangent : 0,
18191794
FbxAnimCurveDef.EWeightedMode.eWeightedAll,
@@ -1822,16 +1797,6 @@ internal void ExportAnimationKeys (AnimationCurve uniAnimCurve, FbxAnimCurve fbx
18221797
);
18231798

18241799
Debug.LogWarning(uniPropertyName + ": tangents: " + uniKeyFrame.inTangent + ", " + uniKeyFrame.outTangent + ", weights: " + uniKeyFrame.inWeight + ", " + uniKeyFrame.outWeight);
1825-
1826-
if (!(MapUnityKeyTangentModeToFBX.ContainsKey(lTangent) && MapUnityKeyTangentModeToFBX.ContainsKey(rTangent)))
1827-
{
1828-
Debug.LogWarning(string.Format("key[{0}] missing tangent mapping ({1},{2})", keyIndex, lTangent.ToString(), rTangent.ToString()));
1829-
continue;
1830-
}
1831-
1832-
// TODO : handle broken tangents
1833-
1834-
// TODO : set key tangents
18351800
}
18361801
}
18371802
}
@@ -1975,13 +1940,11 @@ private void ExportAnimationCurve (FbxNode fbxNode,
19751940
// AxisSystem (LeftHanded to RightHanded) and FBX's default units
19761941
// (Meters to Centimetres)
19771942
var convertSceneHelper = new UnityToMayaConvertSceneHelper (uniPropertyName);
1978-
1979-
// TODO: we'll resample the curve so we don't have to
1980-
// configure tangents
1943+
19811944
/*if (ModelExporter.ExportSettings.BakeAnimationProperty) {
19821945
ExportAnimationSamples (uniAnimCurve, fbxAnimCurve, frameRate, convertSceneHelper);
19831946
} else {*/
1984-
ExportAnimationKeys (uniAnimCurve, fbxAnimCurve, convertSceneHelper, uniPropertyName);
1947+
ExportAnimationKeys (uniAnimCurve, fbxAnimCurve, convertSceneHelper, uniPropertyName);
19851948
// }
19861949
}
19871950
}
@@ -2158,12 +2121,14 @@ private void ExportAnimationClip (AnimationClip uniAnimClip, GameObject uniRoot,
21582121
continue;
21592122
}
21602123

2161-
/*index = EulerCurve.GetEulerIndex (propertyName);
2162-
if (index >= 0) {
2124+
// If this is an euler curve with a prerotation, then need to sample animations to remove the prerotation.
2125+
// Otherwise can export normally with tangents.
2126+
index = EulerCurve.GetEulerIndex (propertyName);
2127+
if (index >= 0 && fbxNode.GetPreRotation(FbxNode.EPivotSet.eSourcePivot).Distance(new FbxVector4()) > 0) {
21632128
RotationCurve rotCurve = GetRotationCurve<EulerCurve> (uniGO, uniAnimClip.frameRate, ref rotations);
21642129
rotCurve.SetCurve (index, uniAnimCurve);
21652130
continue;
2166-
}*/
2131+
}
21672132

21682133
// simple property (e.g. intensity), export right away
21692134
ExportAnimationCurve (fbxNode, uniAnimCurve, uniAnimClip.frameRate,

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
5858
fbxPreRotationInverse.Inverse();
5959

6060
// Find when we have keys set.
61-
var keyTimes =
62-
(UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportSettings.BakeAnimationProperty)
63-
? ModelExporter.GetSampleTimes(GetCurves(), SampleRate)
64-
: ModelExporter.GetKeyTimes(GetCurves());
61+
var keyTimes = ModelExporter.GetSampleTimes(GetCurves(), SampleRate);
6562

6663
// Convert to the Key type.
6764
var keys = new Key[keyTimes.Count];
@@ -120,9 +117,6 @@ public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxA
120117
}
121118
}
122119

123-
// Uni-35616 unroll curves to preserve continuous rotations
124-
var fbxCurveNode = fbxNode.LclRotation.GetCurveNode(fbxAnimLayer, false /*should already exist*/);
125-
126120
if (Verbose) {
127121
Debug.Log("Exported rotation animation for " + fbxNode.GetName());
128122
}

com.unity.formats.fbx/Tests/Models/Player/Player.controller

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,6 @@ AnimatorController:
2222
m_IKPass: 0
2323
m_SyncedLayerAffectsTiming: 0
2424
m_Controller: {fileID: 9100000}
25-
--- !u!1102 &380199431843810593
26-
AnimatorState:
27-
serializedVersion: 5
28-
m_ObjectHideFlags: 1
29-
m_CorrespondingSourceObject: {fileID: 0}
30-
m_PrefabInstance: {fileID: 0}
31-
m_PrefabAsset: {fileID: 0}
32-
m_Name: EulerAnimation 0
33-
m_Speed: 1
34-
m_CycleOffset: 0
35-
m_Transitions: []
36-
m_StateMachineBehaviours: []
37-
m_Position: {x: 50, y: 50, z: 0}
38-
m_IKOnFeet: 0
39-
m_WriteDefaultValues: 1
40-
m_Mirror: 0
41-
m_SpeedParameterActive: 0
42-
m_MirrorParameterActive: 0
43-
m_CycleOffsetParameterActive: 0
44-
m_TimeParameterActive: 0
45-
m_Motion: {fileID: 7400000, guid: dfbbf56ceff8a4b31b6f69b12073eefc, type: 2}
46-
m_Tag:
47-
m_SpeedParameter:
48-
m_MirrorParameter:
49-
m_CycleOffsetParameter:
50-
m_TimeParameter:
5125
--- !u!1102 &1102573189940394992
5226
AnimatorState:
5327
serializedVersion: 5
@@ -86,9 +60,6 @@ AnimatorStateMachine:
8660
- serializedVersion: 1
8761
m_State: {fileID: 1102573189940394992}
8862
m_Position: {x: 250, y: 170, z: 0}
89-
- serializedVersion: 1
90-
m_State: {fileID: 380199431843810593}
91-
m_Position: {x: 285, y: 235, z: 0}
9263
m_ChildStateMachines: []
9364
m_AnyStateTransitions: []
9465
m_EntryTransitions: []

0 commit comments

Comments
 (0)