Skip to content

Commit

Permalink
fixed for one step rotation animation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicloay committed Oct 27, 2014
1 parent da3a3f3 commit 4141e56
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ public static void addBoneAnimationToClip(AnimationClip clip, Dictionary<string,
AnimationCurve localRotationW = new AnimationCurve();

JsonData[] curveData = new JsonData[boneAnimation.rotate.Count];
Quaternion baseRotation = Quaternion.identity;
for (int i = 0; i < boneAnimation.rotate.Count; i++) {
float origAngle = (float)boneAnimation.rotate[i].angle;
if (origAngle > 0)
Expand All @@ -989,17 +990,10 @@ public static void addBoneAnimationToClip(AnimationClip clip, Dictionary<string,

}

fixAngles (localRotationX , curveData);
setTangents(localRotationX , curveData);

fixAngles (localRotationY , curveData);
setTangents(localRotationY , curveData);

fixAngles (localRotationZ , curveData);
setTangents(localRotationZ , curveData);

fixAngles (localRotationW , curveData);
setTangents(localRotationW , curveData);
fixAngleCurve (localRotationX , curveData, baseRotation.x);
fixAngleCurve (localRotationY , curveData, baseRotation.y);
fixAngleCurve (localRotationZ , curveData, baseRotation.z);
fixAngleCurve (localRotationW , curveData, baseRotation.w);

AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"m_LocalRotation.x"), localRotationX);
AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"m_LocalRotation.y"), localRotationY);
Expand Down Expand Up @@ -1035,6 +1029,23 @@ public static void addBoneAnimationToClip(AnimationClip clip, Dictionary<string,
}



static void fixAngleCurve(AnimationCurve animationCurve, JsonData[] curveData, float defSingleStepValue){
fixSingleStep(animationCurve, defSingleStepValue);
fixAngles (animationCurve, curveData);
setTangents (animationCurve, curveData);
}

static void fixSingleStep (AnimationCurve animationCurve, float defSingleStepValue)
{
if (animationCurve.keys.Length == 1 && animationCurve.keys[0].time != 0.0f){
Keyframe key = animationCurve.keys[0];
key.time = 0.0f;
key.value = defSingleStepValue;
animationCurve.AddKey(key);
}
}

static void fixAngles(AnimationCurve curve, JsonData[] curveData){
if (curve.keys.Length <3)
return;
Expand Down

0 comments on commit 4141e56

Please sign in to comment.