mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 15:24:55 +08:00
Fixed IK constraint bend direction keys.
This commit is contained in:
parent
3c7a83d95c
commit
37f332d149
@ -746,8 +746,9 @@ void spFFDTimeline_setFrame (spFFDTimeline* self, int frameIndex, float time, fl
|
||||
/**/
|
||||
|
||||
static const int IKCONSTRAINT_PREV_FRAME_TIME = -3;
|
||||
static const int IKCONSTRAINT_PREV_FRAME_MIX = -2;
|
||||
static const int IKCONSTRAINT_PREV_FRAME_BEND_DIRECTION = -1;
|
||||
static const int IKCONSTRAINT_FRAME_MIX = 1;
|
||||
static const int IKCONSTRAINT_FRAME_BEND_DIRECTION = 2;
|
||||
|
||||
void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time,
|
||||
spEvent** firedEvents, int* eventsCount, float alpha) {
|
||||
@ -768,14 +769,14 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel
|
||||
|
||||
/* Interpolate between the previous frame and the current frame. */
|
||||
frameIndex = binarySearch(self->frames, self->framesCount, time, 3);
|
||||
prevFrameMix = self->frames[frameIndex - 2];
|
||||
prevFrameMix = self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_MIX];
|
||||
frameTime = self->frames[frameIndex];
|
||||
percent = 1 - (time - frameTime) / (self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_TIME] - frameTime);
|
||||
percent = spCurveTimeline_getCurvePercent(SUPER(self), frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent));
|
||||
|
||||
mix = prevFrameMix + (self->frames[frameIndex + IKCONSTRAINT_FRAME_MIX] - prevFrameMix) * percent;
|
||||
ikConstraint->mix += (mix - ikConstraint->mix) * alpha;
|
||||
ikConstraint->bendDirection = (int)self->frames[frameIndex + IKCONSTRAINT_FRAME_BEND_DIRECTION];
|
||||
ikConstraint->bendDirection = (int)self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_BEND_DIRECTION];
|
||||
}
|
||||
|
||||
spIkConstraintTimeline* spIkConstraintTimeline_create (int framesCount) {
|
||||
|
||||
@ -622,8 +622,9 @@ namespace Spine {
|
||||
|
||||
public class IkConstraintTimeline : CurveTimeline {
|
||||
private const int PREV_FRAME_TIME = -3;
|
||||
private const int PREV_FRAME_MIX = -2;
|
||||
private const int PREV_FRAME_BEND_DIRECTION = -1;
|
||||
private const int FRAME_MIX = 1;
|
||||
private const int FRAME_BEND_DIRECTION = 2;
|
||||
|
||||
internal int ikConstraintIndex;
|
||||
internal float[] frames;
|
||||
@ -662,14 +663,14 @@ namespace Spine {
|
||||
|
||||
// Interpolate between the previous frame and the current frame.
|
||||
int frameIndex = Animation.binarySearch(frames, time, 3);
|
||||
float prevFrameMix = frames[frameIndex - 2];
|
||||
float prevFrameMix = frames[frameIndex + PREV_FRAME_MIX];
|
||||
float frameTime = frames[frameIndex];
|
||||
float percent = 1 - (time - frameTime) / (frames[frameIndex + PREV_FRAME_TIME] - frameTime);
|
||||
percent = GetCurvePercent(frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent));
|
||||
|
||||
float mix = prevFrameMix + (frames[frameIndex + FRAME_MIX] - prevFrameMix) * percent;
|
||||
ikConstraint.mix += (mix - ikConstraint.mix) * alpha;
|
||||
ikConstraint.bendDirection = (int)frames[frameIndex + FRAME_BEND_DIRECTION];
|
||||
ikConstraint.bendDirection = (int)frames[frameIndex + PREV_FRAME_BEND_DIRECTION];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,8 +373,8 @@ public class Animation {
|
||||
|
||||
Bone bone = skeleton.bones.get(boneIndex);
|
||||
if (time >= frames[frames.length - 3]) { // Time is after last frame.
|
||||
bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha;
|
||||
bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha;
|
||||
bone.scaleX += (bone.data.scaleX * frames[frames.length - 2] - bone.scaleX) * alpha;
|
||||
bone.scaleY += (bone.data.scaleY * frames[frames.length - 1] - bone.scaleY) * alpha;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -386,9 +386,9 @@ public class Animation {
|
||||
float percent = MathUtils.clamp(1 - (time - frameTime) / (frames[frameIndex + PREV_FRAME_TIME] - frameTime), 0, 1);
|
||||
percent = getCurvePercent(frameIndex / 3 - 1, percent);
|
||||
|
||||
bone.scaleX += (bone.data.scaleX - 1 + prevFrameX + (frames[frameIndex + FRAME_X] - prevFrameX) * percent - bone.scaleX)
|
||||
bone.scaleX += (bone.data.scaleX * (prevFrameX + (frames[frameIndex + FRAME_X] - prevFrameX) * percent) - bone.scaleX)
|
||||
* alpha;
|
||||
bone.scaleY += (bone.data.scaleY - 1 + prevFrameY + (frames[frameIndex + FRAME_Y] - prevFrameY) * percent - bone.scaleY)
|
||||
bone.scaleY += (bone.data.scaleY * (prevFrameY + (frames[frameIndex + FRAME_Y] - prevFrameY) * percent) - bone.scaleY)
|
||||
* alpha;
|
||||
}
|
||||
}
|
||||
@ -719,8 +719,9 @@ public class Animation {
|
||||
|
||||
static public class IkConstraintTimeline extends CurveTimeline {
|
||||
static private final int PREV_FRAME_TIME = -3;
|
||||
static private final int PREV_FRAME_MIX = -2;
|
||||
static private final int PREV_FRAME_BEND_DIRECTION = -1;
|
||||
static private final int FRAME_MIX = 1;
|
||||
static private final int FRAME_BEND_DIRECTION = 2;
|
||||
|
||||
int ikConstraintIndex;
|
||||
private final float[] frames; // time, mix, bendDirection, ...
|
||||
@ -764,14 +765,14 @@ public class Animation {
|
||||
|
||||
// Interpolate between the previous frame and the current frame.
|
||||
int frameIndex = binarySearch(frames, time, 3);
|
||||
float prevFrameMix = frames[frameIndex - 2];
|
||||
float prevFrameMix = frames[frameIndex + PREV_FRAME_MIX];
|
||||
float frameTime = frames[frameIndex];
|
||||
float percent = MathUtils.clamp(1 - (time - frameTime) / (frames[frameIndex + PREV_FRAME_TIME] - frameTime), 0, 1);
|
||||
percent = getCurvePercent(frameIndex / 3 - 1, percent);
|
||||
|
||||
float mix = prevFrameMix + (frames[frameIndex + FRAME_MIX] - prevFrameMix) * percent;
|
||||
ikConstraint.mix += (mix - ikConstraint.mix) * alpha;
|
||||
ikConstraint.bendDirection = (int)frames[frameIndex + FRAME_BEND_DIRECTION];
|
||||
ikConstraint.bendDirection = (int)frames[frameIndex + PREV_FRAME_BEND_DIRECTION];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user