Hi.
I’m working on an animation import tool for our artist so he can create a native Unity animation out of set of xml files and a spritesheet that his animation software exports.
I’ve got a strange errors though, that are caused by this line of code AnimationUtility.SetEditorCurve(animationClip, rotationW, curveW);
1st error:
QuaternionToEuler: Input quaternion was not normalized
UnityEditor.AnimationUtility:SetEditorCurve(AnimationClip, EditorCurveBinding, AnimationCurve)
2nd error:
Assertion failed on expression: 'IsFinite(rot)'
UnityEditor.AnimationUtility:SetEditorCurve(AnimationClip, EditorCurveBinding, AnimationCurve)
They happen when I try to set the rotation via AnimationCurve. They are caused by setting the curve for a .w value of a quaternion.
This is my code:
var rotationX = GetBinding("rotation.anglex", path);
var rotationY = GetBinding("rotation.angley", path);
var rotationZ = GetBinding("rotation.anglez", path);
var rotationW = GetBinding("rotation.anglew", path);
var pts = timedValues[attrlink.Timedvalue];
List<Keyframe> keyframesX = new List<Keyframe>();
List<Keyframe> keyframesY = new List<Keyframe>();
List<Keyframe> keyframesZ = new List<Keyframe>();
List<Keyframe> keyframesW = new List<Keyframe>();
for (int i = 0; i < pts.Count; i++)
{
var time = i / animationClip.frameRate;
var keyframeX = new Keyframe();
var keyframeY = new Keyframe();
var keyframeZ = new Keyframe();
var keyframeW = new Keyframe();
keyframeX.time = time;
keyframeY.time = time;
keyframeZ.time = time;
keyframeW.time = time;
//The xml stored values are in radians.
var degree = float.Parse(pts[i].Y) * Mathf.Rad2Deg;
var euler = new Vector3(0, 0, degree);
var quaternion = Quaternion.Euler(euler);
keyframeX.value = quaternion.x;
keyframeY.value = quaternion.y;
keyframeZ.value = quaternion.z;
keyframeW.value = quaternion.w;
keyframesX.Add(keyframeX);
keyframesY.Add(keyframeY);
keyframesZ.Add(keyframeZ);
keyframesW.Add(keyframeW);
}
var curveX = new AnimationCurve(keyframesX.ToArray());
var curveY = new AnimationCurve(keyframesY.ToArray());
var curveZ = new AnimationCurve(keyframesZ.ToArray());
var curveW = new AnimationCurve(keyframesW.ToArray());
for (var i = 0; i < curveX.keys.Length; i++)
{
AnimationUtility.SetKeyLeftTangentMode(curveX, i, AnimationUtility.TangentMode.Constant);
AnimationUtility.SetKeyRightTangentMode(curveX, i, AnimationUtility.TangentMode.Constant);
}
for (var i = 0; i < curveY.keys.Length; i++)
{
AnimationUtility.SetKeyLeftTangentMode(curveY, i, AnimationUtility.TangentMode.Constant);
AnimationUtility.SetKeyRightTangentMode(curveY, i, AnimationUtility.TangentMode.Constant);
}
for (var i = 0; i < curveZ.keys.Length; i++)
{
AnimationUtility.SetKeyLeftTangentMode(curveZ, i, AnimationUtility.TangentMode.Constant);
AnimationUtility.SetKeyRightTangentMode(curveZ, i, AnimationUtility.TangentMode.Constant);
}
for (var i = 0; i < curveW.keys.Length; i++)
{
AnimationUtility.SetKeyLeftTangentMode(curveW, i, AnimationUtility.TangentMode.Constant);
AnimationUtility.SetKeyRightTangentMode(curveW, i, AnimationUtility.TangentMode.Constant);
}
AnimationUtility.SetEditorCurve(animationClip, rotationX, curveX);
AnimationUtility.SetEditorCurve(animationClip, rotationY, curveY);
AnimationUtility.SetEditorCurve(animationClip, rotationZ, curveZ);
AnimationUtility.SetEditorCurve(animationClip, rotationW, curveW);
I also did some debugs for the final curve and it looks like all the values are set correctly.
Setting Rotation Curve for following clip: Idle_Top
Rotation X:
Path: Idle1_Up_UP_Body-P/Idle1_Up_head PropertyName: m_LocalRotation.x Type: UnityEngine.Transform IsDiscrete False IsPPtr False
Curve X Length: 10
Curve X KeyFrame[0] Time: 0 Value: 0
Curve X KeyFrame[1] Time: 0.125 Value: 0
Curve X KeyFrame[2] Time: 0.25 Value: 0
Curve X KeyFrame[3] Time: 0.375 Value: 0
Curve X KeyFrame[4] Time: 0.5 Value: 0
Curve X KeyFrame[5] Time: 0.625 Value: 0
Curve X KeyFrame[6] Time: 0.75 Value: 0
Curve X KeyFrame[7] Time: 0.875 Value: 0
Curve X KeyFrame[8] Time: 1 Value: 0
Curve X KeyFrame[9] Time: 1.125 Value: 0
Rotation Y:
Path: Idle1_Up_UP_Body-P/Idle1_Up_head PropertyName: m_LocalRotation.y Type: UnityEngine.Transform IsDiscrete False IsPPtr False
Curve Y Length: 10
Curve Y KeyFrame[0] Time: 0 Value: 0
Curve Y KeyFrame[1] Time: 0.125 Value: 0
Curve Y KeyFrame[2] Time: 0.25 Value: 0
Curve Y KeyFrame[3] Time: 0.375 Value: 0
Curve Y KeyFrame[4] Time: 0.5 Value: 0
Curve Y KeyFrame[5] Time: 0.625 Value: 0
Curve Y KeyFrame[6] Time: 0.75 Value: 0
Curve Y KeyFrame[7] Time: 0.875 Value: 0
Curve Y KeyFrame[8] Time: 1 Value: 0
Curve Y KeyFrame[9] Time: 1.125 Value: 0
Rotation Z:
Path: Idle1_Up_UP_Body-P/Idle1_Up_head PropertyName: m_LocalRotation.z Type: UnityEngine.Transform IsDiscrete False IsPPtr False
Curve Z Length: 10
Curve Z KeyFrame[0] Time: 0 Value: 0
Curve Z KeyFrame[1] Time: 0.125 Value: 0.01776127
Curve Z KeyFrame[2] Time: 0.25 Value: 0.0355178
Curve Z KeyFrame[3] Time: 0.375 Value: 0.0355178
Curve Z KeyFrame[4] Time: 0.5 Value: 0.0355178
Curve Z KeyFrame[5] Time: 0.625 Value: 0.0355178
Curve Z KeyFrame[6] Time: 0.75 Value: 0.0355178
Curve Z KeyFrame[7] Time: 0.875 Value: 0.0355178
Curve Z KeyFrame[8] Time: 1 Value: 0.01776127
Curve Z KeyFrame[9] Time: 1.125 Value: 0
Rotation W:
Path: Idle1_Up_UP_Body-P/Idle1_Up_head PropertyName: m_LocalRotation.w Type: UnityEngine.Transform IsDiscrete False IsPPtr False
Curve W Length: 10
Curve W KeyFrame[0] Time: 0 Value: 1
Curve W KeyFrame[1] Time: 0.125 Value: 0.9998422
Curve W KeyFrame[2] Time: 0.25 Value: 0.999369
Curve W KeyFrame[3] Time: 0.375 Value: 0.999369
Curve W KeyFrame[4] Time: 0.5 Value: 0.999369
Curve W KeyFrame[5] Time: 0.625 Value: 0.999369
Curve W KeyFrame[6] Time: 0.75 Value: 0.999369
Curve W KeyFrame[7] Time: 0.875 Value: 0.999369
Curve W KeyFrame[8] Time: 1 Value: 0.9998422
Curve W KeyFrame[9] Time: 1.125 Value: 1
I get double the amount of keyframes of these both errors for each Curve W i’m trying to set. These errors happen if I use the AnimationUtitlity.SetEditorCurve or animationClip.SetCurve methods. Whats strange is, that despite these errors, the animationClip seems to be working correctly, setting the rotation for each frame as it should be. But still, I’d like to get rid of these errors anyway.