[csharp] Fixed AnimationState not respecting MixBlend.first for rotate timelines. See #1274.

This commit is contained in:
Harald Csaszar 2019-02-11 20:39:37 +01:00
parent c7d71a8eb1
commit 04e2dd835d

View File

@ -307,24 +307,33 @@ namespace Spine {
return mix; return mix;
} }
static private void ApplyRotateTimeline (RotateTimeline rotateTimeline, Skeleton skeleton, float time, float alpha, MixBlend pose, static private void ApplyRotateTimeline (RotateTimeline rotateTimeline, Skeleton skeleton, float time, float alpha, MixBlend blend,
float[] timelinesRotation, int i, bool firstFrame) { float[] timelinesRotation, int i, bool firstFrame) {
if (firstFrame) timelinesRotation[i] = 0; if (firstFrame) timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
rotateTimeline.Apply(skeleton, 0, time, null, 1, pose, MixDirection.In); rotateTimeline.Apply(skeleton, 0, time, null, 1, blend, MixDirection.In);
return; return;
} }
Bone bone = skeleton.bones.Items[rotateTimeline.boneIndex]; Bone bone = skeleton.bones.Items[rotateTimeline.boneIndex];
float[] frames = rotateTimeline.frames; float[] frames = rotateTimeline.frames;
if (time < frames[0]) { float r1, r2;
if (pose == MixBlend.Setup) bone.rotation = bone.data.rotation; if (time < frames[0]) { // Time is before first frame.
switch (blend) {
case MixBlend.Setup:
bone.rotation = bone.data.rotation;
return; return;
default:
return;
case MixBlend.First:
r1 = bone.rotation;
r2 = bone.data.rotation;
break;
} }
} else {
float r2; r1 = blend == MixBlend.Setup ? bone.data.rotation : bone.rotation;
if (time >= frames[frames.Length - RotateTimeline.ENTRIES]) // Time is after last frame. if (time >= frames[frames.Length - RotateTimeline.ENTRIES]) // Time is after last frame.
r2 = bone.data.rotation + frames[frames.Length + RotateTimeline.PREV_ROTATION]; r2 = bone.data.rotation + frames[frames.Length + RotateTimeline.PREV_ROTATION];
else { else {
@ -340,9 +349,9 @@ namespace Spine {
r2 = prevRotation + r2 * percent + bone.data.rotation; r2 = prevRotation + r2 * percent + bone.data.rotation;
r2 -= (16384 - (int)(16384.499999999996 - r2 / 360)) * 360; r2 -= (16384 - (int)(16384.499999999996 - r2 / 360)) * 360;
} }
}
// Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.
float r1 = pose == MixBlend.Setup ? bone.data.rotation : bone.rotation;
float total, diff = r2 - r1; float total, diff = r2 - r1;
diff -= (16384 - (int)(16384.499999999996 - diff / 360)) * 360; diff -= (16384 - (int)(16384.499999999996 - diff / 360)) * 360;
if (diff == 0) { if (diff == 0) {