|
@@ -42,7 +42,7 @@ module spine {
|
|
|
this.duration = duration;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
if (skeleton == null) throw new Error("skeleton cannot be null.");
|
|
|
|
|
|
if (loop && this.duration != 0) {
|
|
@@ -52,20 +52,7 @@ module spine {
|
|
|
|
|
|
let timelines = this.timelines;
|
|
|
for (let i = 0, n = timelines.length; i < n; i++)
|
|
|
- timelines[i].apply(skeleton, lastTime, time, events, 1);
|
|
|
- }
|
|
|
-
|
|
|
- mix (skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number) {
|
|
|
- if (skeleton == null) throw new Error("skeleton cannot be null.");
|
|
|
-
|
|
|
- if (loop && this.duration != 0) {
|
|
|
- time %= this.duration;
|
|
|
- if (lastTime > 0) lastTime %= this.duration;
|
|
|
- }
|
|
|
-
|
|
|
- let timelines = this.timelines;
|
|
|
- for (let i = 0, n = timelines.length; i < n; i++)
|
|
|
- timelines[i].apply(skeleton, lastTime, time, events, alpha);
|
|
|
+ timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut);
|
|
|
}
|
|
|
|
|
|
static binarySearch (values: ArrayLike<number>, target: number, step: number = 1) {
|
|
@@ -91,7 +78,16 @@ module spine {
|
|
|
}
|
|
|
|
|
|
export interface Timeline {
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number): void;
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
|
|
|
+ getPropertyId (): number;
|
|
|
+ }
|
|
|
+
|
|
|
+ export enum TimelineType {
|
|
|
+ rotate, translate, scale, shear,
|
|
|
+ attachment, color, deform,
|
|
|
+ event, drawOrder,
|
|
|
+ ikConstraint, transformConstraint,
|
|
|
+ pathConstraintPosition, pathConstraintSpacing, pathConstraintMix
|
|
|
}
|
|
|
|
|
|
export abstract class CurveTimeline implements Timeline {
|
|
@@ -100,6 +96,8 @@ module spine {
|
|
|
|
|
|
private curves: ArrayLike<number>; // type, x, y, ...
|
|
|
|
|
|
+ abstract getPropertyId(): number;
|
|
|
+
|
|
|
constructor (frameCount: number) {
|
|
|
if (frameCount <= 0) throw new Error("frameCount must be > 0: " + frameCount);
|
|
|
this.curves = Utils.newFloatArray((frameCount - 1) * CurveTimeline.BEZIER_SIZE);
|
|
@@ -179,7 +177,7 @@ module spine {
|
|
|
return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
|
|
|
}
|
|
|
|
|
|
- abstract apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number): void;
|
|
|
+ abstract apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
|
|
|
}
|
|
|
|
|
|
export class RotateTimeline extends CurveTimeline {
|
|
@@ -195,6 +193,10 @@ module spine {
|
|
|
this.frames = Utils.newFloatArray(frameCount << 1);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.rotate << 24) + this.boneIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/** Sets the time and angle of the specified keyframe. */
|
|
|
setFrame (frameIndex: number, time: number, degrees: number) {
|
|
|
frameIndex <<= 1;
|
|
@@ -202,19 +204,20 @@ module spine {
|
|
|
this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let bone = skeleton.bones[this.boneIndex];
|
|
|
|
|
|
if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
- let amount = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
|
|
|
- while (amount > 180)
|
|
|
- amount -= 360;
|
|
|
- while (amount < -180)
|
|
|
- amount += 360;
|
|
|
- bone.rotation += amount * alpha;
|
|
|
+ if (setupPose)
|
|
|
+ bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
|
|
|
+ else {
|
|
|
+ let r = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
|
|
|
+ r -= (16384 - Math.floor(16384.499999999996 - r / 360)) * 360; // Wrap within -180 and 180.
|
|
|
+ bone.rotation += r * alpha;
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -225,17 +228,17 @@ module spine {
|
|
|
let percent = this.getCurvePercent((frame >> 1) - 1,
|
|
|
1 - (time - frameTime) / (frames[frame + RotateTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- let amount = frames[frame + RotateTimeline.ROTATION] - prevRotation;
|
|
|
- while (amount > 180)
|
|
|
- amount -= 360;
|
|
|
- while (amount < -180)
|
|
|
- amount += 360;
|
|
|
- amount = bone.data.rotation + (prevRotation + amount * percent) - bone.rotation;
|
|
|
- while (amount > 180)
|
|
|
- amount -= 360;
|
|
|
- while (amount < -180)
|
|
|
- amount += 360;
|
|
|
- bone.rotation += amount * alpha;
|
|
|
+ let r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
|
|
|
+ r -= (16384 - Math.floor(16384.499999999996 - r / 360)) * 360;
|
|
|
+ r = prevRotation + r * percent;
|
|
|
+ if (setupPose) {
|
|
|
+ r -= (16384 - Math.floor(16384.499999999996 - r / 360)) * 360;
|
|
|
+ bone.rotation = bone.data.rotation + r * alpha;
|
|
|
+ } else {
|
|
|
+ r = bone.data.rotation + r - bone.rotation;
|
|
|
+ r -= (16384 - Math.floor(16384.499999999996 - r / 360)) * 360;
|
|
|
+ bone.rotation += r * alpha;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -252,6 +255,10 @@ module spine {
|
|
|
this.frames = Utils.newFloatArray(frameCount * TranslateTimeline.ENTRIES);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.translate << 24) + this.boneIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/** Sets the time and value of the specified keyframe. */
|
|
|
setFrame (frameIndex: number, time: number, x: number, y: number) {
|
|
|
frameIndex *= TranslateTimeline.ENTRIES;
|
|
@@ -260,28 +267,35 @@ module spine {
|
|
|
this.frames[frameIndex + TranslateTimeline.Y] = y;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let bone = skeleton.bones[this.boneIndex];
|
|
|
|
|
|
+ let x = 0, y = 0;
|
|
|
if (time >= frames[frames.length - TranslateTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
- bone.x += (bone.data.x + frames[frames.length + TranslateTimeline.PREV_X] - bone.x) * alpha;
|
|
|
- bone.y += (bone.data.y + frames[frames.length + TranslateTimeline.PREV_Y] - bone.y) * alpha;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Interpolate between the previous frame and the current frame.
|
|
|
- let frame = Animation.binarySearch(frames, time, TranslateTimeline.ENTRIES);
|
|
|
- let prevX = frames[frame + TranslateTimeline.PREV_X];
|
|
|
- let prevY = frames[frame + TranslateTimeline.PREV_Y];
|
|
|
- let frameTime = frames[frame];
|
|
|
- let percent = this.getCurvePercent(frame / TranslateTimeline.ENTRIES - 1,
|
|
|
- 1 - (time - frameTime) / (frames[frame + TranslateTimeline.PREV_TIME] - frameTime));
|
|
|
+ x = frames[frames.length + TranslateTimeline.PREV_X];
|
|
|
+ y = frames[frames.length + TranslateTimeline.PREV_Y];
|
|
|
+ } else {
|
|
|
+ // Interpolate between the previous frame and the current frame.
|
|
|
+ let frame = Animation.binarySearch(frames, time, TranslateTimeline.ENTRIES);
|
|
|
+ x = frames[frame + TranslateTimeline.PREV_X];
|
|
|
+ y = frames[frame + TranslateTimeline.PREV_Y];
|
|
|
+ let frameTime = frames[frame];
|
|
|
+ let percent = this.getCurvePercent(frame / TranslateTimeline.ENTRIES - 1,
|
|
|
+ 1 - (time - frameTime) / (frames[frame + TranslateTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- bone.x += (bone.data.x + prevX + (frames[frame + TranslateTimeline.X] - prevX) * percent - bone.x) * alpha;
|
|
|
- bone.y += (bone.data.y + prevY + (frames[frame + TranslateTimeline.Y] - prevY) * percent - bone.y) * alpha;
|
|
|
+ x += (frames[frame + TranslateTimeline.X] - x) * percent;
|
|
|
+ y += (frames[frame + TranslateTimeline.Y] - y) * percent;
|
|
|
+ }
|
|
|
+ if (setupPose) {
|
|
|
+ bone.x = bone.data.x + x * alpha;
|
|
|
+ bone.y = bone.data.y + y * alpha;
|
|
|
+ } else {
|
|
|
+ bone.x += (bone.data.x + x - bone.x) * alpha;
|
|
|
+ bone.y += (bone.data.y + y - bone.y) * alpha;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -290,27 +304,54 @@ module spine {
|
|
|
super(frameCount);
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number) {
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.scale << 24) + this.boneIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let bone = skeleton.bones[this.boneIndex];
|
|
|
+ let x = 0, y = 0;
|
|
|
if (time >= frames[frames.length - ScaleTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
- bone.scaleX += (bone.data.scaleX * frames[frames.length + ScaleTimeline.PREV_X] - bone.scaleX) * alpha;
|
|
|
- bone.scaleY += (bone.data.scaleY * frames[frames.length + ScaleTimeline.PREV_Y] - bone.scaleY) * alpha;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Interpolate between the previous frame and the current frame.
|
|
|
- let frame = Animation.binarySearch(frames, time, ScaleTimeline.ENTRIES);
|
|
|
- let prevX = frames[frame + ScaleTimeline.PREV_X];
|
|
|
- let prevY = frames[frame + ScaleTimeline.PREV_Y];
|
|
|
- let frameTime = frames[frame];
|
|
|
- let percent = this.getCurvePercent(frame / ScaleTimeline.ENTRIES - 1,
|
|
|
- 1 - (time - frameTime) / (frames[frame + ScaleTimeline.PREV_TIME] - frameTime));
|
|
|
+ x = frames[frames.length + ScaleTimeline.PREV_X] * bone.data.scaleX;
|
|
|
+ y = frames[frames.length + ScaleTimeline.PREV_Y] * bone.data.scaleY;
|
|
|
+ } else {
|
|
|
+ // Interpolate between the previous frame and the current frame.
|
|
|
+ let frame = Animation.binarySearch(frames, time, ScaleTimeline.ENTRIES);
|
|
|
+ x = frames[frame + ScaleTimeline.PREV_X];
|
|
|
+ y = frames[frame + ScaleTimeline.PREV_Y];
|
|
|
+ let frameTime = frames[frame];
|
|
|
+ let percent = this.getCurvePercent(frame / ScaleTimeline.ENTRIES - 1,
|
|
|
+ 1 - (time - frameTime) / (frames[frame + ScaleTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- bone.scaleX += (bone.data.scaleX * (prevX + (frames[frame + ScaleTimeline.X] - prevX) * percent) - bone.scaleX) * alpha;
|
|
|
- bone.scaleY += (bone.data.scaleY * (prevY + (frames[frame + ScaleTimeline.Y] - prevY) * percent) - bone.scaleY) * alpha;
|
|
|
+ x = (x + (frames[frame + ScaleTimeline.X] - x) * percent) * bone.data.scaleX;
|
|
|
+ y = (y + (frames[frame + ScaleTimeline.Y] - y) * percent) * bone.data.scaleY;
|
|
|
+ }
|
|
|
+ if (alpha == 1) {
|
|
|
+ bone.scaleX = x;
|
|
|
+ bone.scaleY = y;
|
|
|
+ } else {
|
|
|
+ let bx = 0, by = 0;
|
|
|
+ if (setupPose) {
|
|
|
+ bx = bone.data.scaleX;
|
|
|
+ by = bone.data.scaleY;
|
|
|
+ } else {
|
|
|
+ bx = bone.scaleX;
|
|
|
+ by = bone.scaleY;
|
|
|
+ }
|
|
|
+ // Mixing out uses sign of setup or current pose, else use sign of key.
|
|
|
+ if (mixingOut) {
|
|
|
+ x = Math.abs(x) * MathUtils.signum(bx);
|
|
|
+ y = Math.abs(y) * MathUtils.signum(by);
|
|
|
+ } else {
|
|
|
+ bx = Math.abs(bx) * MathUtils.signum(x);
|
|
|
+ by = Math.abs(by) * MathUtils.signum(y);
|
|
|
+ }
|
|
|
+ bone.scaleX = bx + (x - bx) * alpha;
|
|
|
+ bone.scaleY = by + (y - by) * alpha;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -319,27 +360,39 @@ module spine {
|
|
|
super(frameCount);
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number) {
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.shear << 24) + this.boneIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let bone = skeleton.bones[this.boneIndex];
|
|
|
- if (time >= frames[frames.length - ShearTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
- bone.shearX += (bone.data.shearX + frames[frames.length + ShearTimeline.PREV_X] - bone.shearX) * alpha;
|
|
|
- bone.shearY += (bone.data.shearY + frames[frames.length + ShearTimeline.PREV_Y] - bone.shearY) * alpha;
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- // Interpolate between the previous frame and the current frame.
|
|
|
- let frame = Animation.binarySearch(frames, time, ShearTimeline.ENTRIES);
|
|
|
- let prevX = frames[frame + ShearTimeline.PREV_X];
|
|
|
- let prevY = frames[frame + ShearTimeline.PREV_Y];
|
|
|
- let frameTime = frames[frame];
|
|
|
- let percent = this.getCurvePercent(frame / ShearTimeline.ENTRIES - 1,
|
|
|
- 1 - (time - frameTime) / (frames[frame + ShearTimeline.PREV_TIME] - frameTime));
|
|
|
+ let x = 0, y = 0;
|
|
|
+ if (time >= frames[frames.length - ShearTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
+ x = frames[frames.length + ShearTimeline.PREV_X];
|
|
|
+ y = frames[frames.length + ShearTimeline.PREV_Y];
|
|
|
+ } else {
|
|
|
+ // Interpolate between the previous frame and the current frame.
|
|
|
+ let frame = Animation.binarySearch(frames, time, ShearTimeline.ENTRIES);
|
|
|
+ x = frames[frame + ShearTimeline.PREV_X];
|
|
|
+ y = frames[frame + ShearTimeline.PREV_Y];
|
|
|
+ let frameTime = frames[frame];
|
|
|
+ let percent = this.getCurvePercent(frame / ShearTimeline.ENTRIES - 1,
|
|
|
+ 1 - (time - frameTime) / (frames[frame + ShearTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- bone.shearX += (bone.data.shearX + (prevX + (frames[frame + ShearTimeline.X] - prevX) * percent) - bone.shearX) * alpha;
|
|
|
- bone.shearY += (bone.data.shearY + (prevY + (frames[frame + ShearTimeline.Y] - prevY) * percent) - bone.shearY) * alpha;
|
|
|
+ x = x + (frames[frame + ShearTimeline.X] - x) * percent;
|
|
|
+ y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
|
|
|
+ }
|
|
|
+ if (setupPose) {
|
|
|
+ bone.shearX = bone.data.shearX + x * alpha;
|
|
|
+ bone.shearY = bone.data.shearY + y * alpha;
|
|
|
+ } else {
|
|
|
+ bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
|
|
|
+ bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -356,6 +409,10 @@ module spine {
|
|
|
this.frames = Utils.newFloatArray(frameCount * ColorTimeline.ENTRIES);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.color << 24) + this.slotIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/** Sets the time and value of the specified keyframe. */
|
|
|
setFrame (frameIndex: number, time: number, r: number, g: number, b: number, a: number) {
|
|
|
frameIndex *= ColorTimeline.ENTRIES;
|
|
@@ -366,7 +423,7 @@ module spine {
|
|
|
this.frames[frameIndex + ColorTimeline.A] = a;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
@@ -393,11 +450,14 @@ module spine {
|
|
|
b += (frames[frame + ColorTimeline.B] - b) * percent;
|
|
|
a += (frames[frame + ColorTimeline.A] - a) * percent;
|
|
|
}
|
|
|
- let color: Color = skeleton.slots[this.slotIndex].color;
|
|
|
- if (alpha < 1)
|
|
|
+ let slot = skeleton.slots[this.slotIndex];
|
|
|
+ if (alpha == 1)
|
|
|
+ slot.color.set(r, g, b, a);
|
|
|
+ else {
|
|
|
+ let color = slot.color;
|
|
|
+ if (setupPose) color.setFromColor(slot.data.color);
|
|
|
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
|
|
|
- else
|
|
|
- color.set(r, g, b, a);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -411,6 +471,10 @@ module spine {
|
|
|
this.attachmentNames = new Array<string>(frameCount);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.attachment << 24) + this.slotIndex;
|
|
|
+ }
|
|
|
+
|
|
|
getFrameCount () {
|
|
|
return this.frames.length;
|
|
|
}
|
|
@@ -421,7 +485,14 @@ module spine {
|
|
|
this.attachmentNames[frameIndex] = attachmentName;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
+ if (mixingOut && setupPose) {
|
|
|
+ let slot = skeleton.slots[this.slotIndex];
|
|
|
+ let attachmentName = slot.data.attachmentName;
|
|
|
+ slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
@@ -446,6 +517,10 @@ module spine {
|
|
|
this.events = new Array<Event>(frameCount);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return TimelineType.event << 24;
|
|
|
+ }
|
|
|
+
|
|
|
getFrameCount () {
|
|
|
return this.frames.length;
|
|
|
}
|
|
@@ -457,13 +532,13 @@ module spine {
|
|
|
}
|
|
|
|
|
|
/** Fires events for frames > lastTime and <= time. */
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
if (firedEvents == null) return;
|
|
|
let frames = this.frames;
|
|
|
let frameCount = this.frames.length;
|
|
|
|
|
|
if (lastTime > time) { // Fire events after last time for looped animations.
|
|
|
- this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha);
|
|
|
+ this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut);
|
|
|
lastTime = -1;
|
|
|
} else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame.
|
|
|
return;
|
|
@@ -494,6 +569,10 @@ module spine {
|
|
|
this.drawOrders = new Array<Array<number>>(frameCount);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return TimelineType.drawOrder << 24;
|
|
|
+ }
|
|
|
+
|
|
|
getFrameCount () {
|
|
|
return this.frames.length;
|
|
|
}
|
|
@@ -505,7 +584,12 @@ module spine {
|
|
|
this.drawOrders[frameIndex] = drawOrder;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
+ if (mixingOut && setupPose) {
|
|
|
+ Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
@@ -528,10 +612,10 @@ module spine {
|
|
|
}
|
|
|
|
|
|
export class DeformTimeline extends CurveTimeline {
|
|
|
- frames: ArrayLike<number>; // time, ...
|
|
|
- frameVertices: Array<ArrayLike<number>>;
|
|
|
slotIndex: number;
|
|
|
attachment: VertexAttachment;
|
|
|
+ frames: ArrayLike<number>; // time, ...
|
|
|
+ frameVertices: Array<ArrayLike<number>>;
|
|
|
|
|
|
constructor (frameCount: number) {
|
|
|
super(frameCount);
|
|
@@ -539,13 +623,17 @@ module spine {
|
|
|
this.frameVertices = new Array<ArrayLike<number>>(frameCount);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.deform << 24) + this.slotIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/** Sets the time of the specified keyframe. */
|
|
|
setFrame (frameIndex: number, time: number, vertices: ArrayLike<number>) {
|
|
|
this.frames[frameIndex] = time;
|
|
|
this.frameVertices[frameIndex] = vertices;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let slot: Slot = skeleton.slots[this.slotIndex];
|
|
|
let slotAttachment: Attachment = slot.getAttachment();
|
|
|
if (!(slotAttachment instanceof VertexAttachment) || !(<VertexAttachment>slotAttachment).applyDeform(this.attachment)) return;
|
|
@@ -562,11 +650,26 @@ module spine {
|
|
|
|
|
|
if (time >= frames[frames.length - 1]) { // Time is after last frame.
|
|
|
let lastVertices = frameVertices[frames.length - 1];
|
|
|
- if (alpha < 1) {
|
|
|
+ if (alpha == 1) {
|
|
|
+ Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
|
|
|
+ } else if (setupPose) {
|
|
|
+ let vertexAttachment = slotAttachment as VertexAttachment;
|
|
|
+ if (vertexAttachment.bones == null) {
|
|
|
+ // Unweighted vertex positions, with alpha.
|
|
|
+ let setupVertices = vertexAttachment.vertices;
|
|
|
+ for (let i = 0; i < vertexCount; i++) {
|
|
|
+ let setup = setupVertices[i];
|
|
|
+ vertices[i] = setup + (lastVertices[i] - setup) * alpha;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // Weighted deform offsets, with alpha.
|
|
|
+ for (let i = 0; i < vertexCount; i++)
|
|
|
+ vertices[i] = lastVertices[i] * alpha;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
for (let i = 0; i < vertexCount; i++)
|
|
|
vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
|
|
|
- } else
|
|
|
- Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -577,15 +680,32 @@ module spine {
|
|
|
let frameTime = frames[frame];
|
|
|
let percent = this.getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
|
|
|
|
|
|
- if (alpha < 1) {
|
|
|
+ if (alpha == 1) {
|
|
|
for (let i = 0; i < vertexCount; i++) {
|
|
|
let prev = prevVertices[i];
|
|
|
- vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
|
|
|
+ vertices[i] = prev + (nextVertices[i] - prev) * percent;
|
|
|
+ }
|
|
|
+ } else if (setupPose) {
|
|
|
+ let vertexAttachment = slotAttachment as VertexAttachment;
|
|
|
+ if (vertexAttachment.bones == null) {
|
|
|
+ // Unweighted vertex positions, with alpha.
|
|
|
+ let setupVertices = vertexAttachment.vertices;
|
|
|
+ for (let i = 0; i < vertexCount; i++) {
|
|
|
+ let prev = prevVertices[i], setup = setupVertices[i];
|
|
|
+ vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // Weighted deform offsets, with alpha.
|
|
|
+ for (let i = 0; i < vertexCount; i++) {
|
|
|
+ let prev = prevVertices[i];
|
|
|
+ vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
+ // Vertex positions or deform offsets, with alpha.
|
|
|
for (let i = 0; i < vertexCount; i++) {
|
|
|
let prev = prevVertices[i];
|
|
|
- vertices[i] = prev + (nextVertices[i] - prev) * percent;
|
|
|
+ vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -604,6 +724,10 @@ module spine {
|
|
|
this.frames = Utils.newFloatArray(frameCount * IkConstraintTimeline.ENTRIES);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.ikConstraint << 24) + this.ikConstraintIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/** Sets the time, mix and bend direction of the specified keyframe. */
|
|
|
setFrame (frameIndex: number, time: number, mix: number, bendDirection: number) {
|
|
|
frameIndex *= IkConstraintTimeline.ENTRIES;
|
|
@@ -612,15 +736,21 @@ module spine {
|
|
|
this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let constraint: IkConstraint = skeleton.ikConstraints[this.ikConstraintIndex];
|
|
|
|
|
|
if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
- constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
|
|
|
- constraint.bendDirection = Math.floor(frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]);
|
|
|
+ if (setupPose) {
|
|
|
+ constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
|
|
|
+ constraint.bendDirection = mixingOut ? constraint.data.bendDirection
|
|
|
+ : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
|
|
|
+ } else {
|
|
|
+ constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
|
|
|
+ if (!mixingOut) constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -631,8 +761,13 @@ module spine {
|
|
|
let percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1,
|
|
|
1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
|
|
|
- constraint.bendDirection = Math.floor(frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION]);
|
|
|
+ if (setupPose) {
|
|
|
+ constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha;
|
|
|
+ constraint.bendDirection = mixingOut ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
|
|
|
+ } else {
|
|
|
+ constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
|
|
|
+ if (!mixingOut) constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -649,6 +784,10 @@ module spine {
|
|
|
this.frames = Utils.newFloatArray(frameCount * TransformConstraintTimeline.ENTRIES);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.transformConstraint << 24) + this.transformConstraintIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/** Sets the time and mixes of the specified keyframe. */
|
|
|
setFrame (frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number) {
|
|
|
frameIndex *= TransformConstraintTimeline.ENTRIES;
|
|
@@ -659,36 +798,47 @@ module spine {
|
|
|
this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let constraint: TransformConstraint = skeleton.transformConstraints[this.transformConstraintIndex];
|
|
|
|
|
|
+ let rotate = 0, translate = 0, scale = 0, shear = 0;
|
|
|
if (time >= frames[frames.length - TransformConstraintTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
let i = frames.length;
|
|
|
- constraint.rotateMix += (frames[i + TransformConstraintTimeline.PREV_ROTATE] - constraint.rotateMix) * alpha;
|
|
|
- constraint.translateMix += (frames[i + TransformConstraintTimeline.PREV_TRANSLATE] - constraint.translateMix) * alpha;
|
|
|
- constraint.scaleMix += (frames[i + TransformConstraintTimeline.PREV_SCALE] - constraint.scaleMix) * alpha;
|
|
|
- constraint.shearMix += (frames[i + TransformConstraintTimeline.PREV_SHEAR] - constraint.shearMix) * alpha;
|
|
|
- return;
|
|
|
- }
|
|
|
+ rotate = frames[i + TransformConstraintTimeline.PREV_ROTATE];
|
|
|
+ translate = frames[i + TransformConstraintTimeline.PREV_TRANSLATE];
|
|
|
+ scale = frames[i + TransformConstraintTimeline.PREV_SCALE];
|
|
|
+ shear = frames[i + TransformConstraintTimeline.PREV_SHEAR];
|
|
|
+ } else {
|
|
|
+ // Interpolate between the previous frame and the current frame.
|
|
|
+ let frame = Animation.binarySearch(frames, time, TransformConstraintTimeline.ENTRIES);
|
|
|
+ rotate = frames[frame + TransformConstraintTimeline.PREV_ROTATE];
|
|
|
+ translate = frames[frame + TransformConstraintTimeline.PREV_TRANSLATE];
|
|
|
+ scale = frames[frame + TransformConstraintTimeline.PREV_SCALE];
|
|
|
+ shear = frames[frame + TransformConstraintTimeline.PREV_SHEAR];
|
|
|
+ let frameTime = frames[frame];
|
|
|
+ let percent = this.getCurvePercent(frame / TransformConstraintTimeline.ENTRIES - 1,
|
|
|
+ 1 - (time - frameTime) / (frames[frame + TransformConstraintTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- // Interpolate between the previous frame and the current frame.
|
|
|
- let frame = Animation.binarySearch(frames, time, TransformConstraintTimeline.ENTRIES);
|
|
|
- let frameTime = frames[frame];
|
|
|
- let percent = this.getCurvePercent(frame / TransformConstraintTimeline.ENTRIES - 1,
|
|
|
- 1 - (time - frameTime) / (frames[frame + TransformConstraintTimeline.PREV_TIME] - frameTime));
|
|
|
-
|
|
|
- let rotate = frames[frame + TransformConstraintTimeline.PREV_ROTATE];
|
|
|
- let translate = frames[frame + TransformConstraintTimeline.PREV_TRANSLATE];
|
|
|
- let scale = frames[frame + TransformConstraintTimeline.PREV_SCALE];
|
|
|
- let shear = frames[frame + TransformConstraintTimeline.PREV_SHEAR];
|
|
|
- constraint.rotateMix += (rotate + (frames[frame + TransformConstraintTimeline.ROTATE] - rotate) * percent - constraint.rotateMix) * alpha;
|
|
|
- constraint.translateMix += (translate + (frames[frame + TransformConstraintTimeline.TRANSLATE] - translate) * percent - constraint.translateMix)
|
|
|
- * alpha;
|
|
|
- constraint.scaleMix += (scale + (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent - constraint.scaleMix) * alpha;
|
|
|
- constraint.shearMix += (shear + (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent - constraint.shearMix) * alpha;
|
|
|
+ rotate += (frames[frame + TransformConstraintTimeline.ROTATE] - rotate) * percent;
|
|
|
+ translate += (frames[frame + TransformConstraintTimeline.TRANSLATE] - translate) * percent;
|
|
|
+ scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
|
|
|
+ shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
|
|
|
+ }
|
|
|
+ if (setupPose) {
|
|
|
+ let data = constraint.data;
|
|
|
+ constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
|
|
|
+ constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
|
|
|
+ constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
|
|
|
+ constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
|
|
|
+ } else {
|
|
|
+ constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
|
|
|
+ constraint.translateMix += (translate - constraint.translateMix) * alpha;
|
|
|
+ constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
|
|
|
+ constraint.shearMix += (shear - constraint.shearMix) * alpha;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -706,6 +856,10 @@ module spine {
|
|
|
this.frames = Utils.newFloatArray(frameCount * PathConstraintPositionTimeline.ENTRIES);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.pathConstraintPosition << 24) + this.pathConstraintIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/** Sets the time and value of the specified keyframe. */
|
|
|
setFrame (frameIndex: number, time: number, value: number) {
|
|
|
frameIndex *= PathConstraintPositionTimeline.ENTRIES;
|
|
@@ -713,26 +867,29 @@ module spine {
|
|
|
this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex];
|
|
|
|
|
|
- if (time >= frames[frames.length - PathConstraintPositionTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
- let i = frames.length;
|
|
|
- constraint.position += (frames[i + PathConstraintPositionTimeline.PREV_VALUE] - constraint.position) * alpha;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Interpolate between the previous frame and the current frame.
|
|
|
- let frame = Animation.binarySearch(frames, time, PathConstraintPositionTimeline.ENTRIES);
|
|
|
- let position = frames[frame + PathConstraintPositionTimeline.PREV_VALUE];
|
|
|
- let frameTime = frames[frame];
|
|
|
- let percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1,
|
|
|
- 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
|
|
|
+ let position = 0;
|
|
|
+ if (time >= frames[frames.length - PathConstraintPositionTimeline.ENTRIES]) // Time is after last frame.
|
|
|
+ position = frames[frames.length + PathConstraintPositionTimeline.PREV_VALUE];
|
|
|
+ else {
|
|
|
+ // Interpolate between the previous frame and the current frame.
|
|
|
+ let frame = Animation.binarySearch(frames, time, PathConstraintPositionTimeline.ENTRIES);
|
|
|
+ position = frames[frame + PathConstraintPositionTimeline.PREV_VALUE];
|
|
|
+ let frameTime = frames[frame];
|
|
|
+ let percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1,
|
|
|
+ 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- constraint.position += (position + (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent - constraint.position) * alpha;
|
|
|
+ position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
|
|
|
+ }
|
|
|
+ if (setupPose)
|
|
|
+ constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
|
|
|
+ else
|
|
|
+ constraint.position += (position - constraint.position) * alpha;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -741,26 +898,34 @@ module spine {
|
|
|
super(frameCount);
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number) {
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex];
|
|
|
|
|
|
- if (time >= frames[frames.length - PathConstraintSpacingTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
- let i = frames.length;
|
|
|
- constraint.spacing += (frames[i + PathConstraintSpacingTimeline.PREV_VALUE] - constraint.spacing) * alpha;
|
|
|
- return;
|
|
|
- }
|
|
|
+ let spacing = 0;
|
|
|
+ if (time >= frames[frames.length - PathConstraintSpacingTimeline.ENTRIES]) // Time is after last frame.
|
|
|
+ spacing = frames[frames.length + PathConstraintSpacingTimeline.PREV_VALUE];
|
|
|
+ else {
|
|
|
+ // Interpolate between the previous frame and the current frame.
|
|
|
+ let frame = Animation.binarySearch(frames, time, PathConstraintSpacingTimeline.ENTRIES);
|
|
|
+ spacing = frames[frame + PathConstraintSpacingTimeline.PREV_VALUE];
|
|
|
+ let frameTime = frames[frame];
|
|
|
+ let percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1,
|
|
|
+ 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- // Interpolate between the previous frame and the current frame.
|
|
|
- let frame = Animation.binarySearch(frames, time, PathConstraintSpacingTimeline.ENTRIES);
|
|
|
- let spacing = frames[frame + PathConstraintSpacingTimeline.PREV_VALUE];
|
|
|
- let frameTime = frames[frame];
|
|
|
- let percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1,
|
|
|
- 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
|
|
|
+ spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
|
|
|
+ }
|
|
|
|
|
|
- constraint.spacing += (spacing + (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent - constraint.spacing) * alpha;
|
|
|
+ if (setupPose)
|
|
|
+ constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
|
|
|
+ else
|
|
|
+ constraint.spacing += (spacing - constraint.spacing) * alpha;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -778,6 +943,10 @@ module spine {
|
|
|
this.frames = Utils.newFloatArray(frameCount * PathConstraintMixTimeline.ENTRIES);
|
|
|
}
|
|
|
|
|
|
+ getPropertyId () {
|
|
|
+ return (TimelineType.pathConstraintMix << 24) + this.pathConstraintIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/** Sets the time and mixes of the specified keyframe. */
|
|
|
setFrame (frameIndex: number, time: number, rotateMix: number, translateMix: number) {
|
|
|
frameIndex *= PathConstraintMixTimeline.ENTRIES;
|
|
@@ -786,30 +955,36 @@ module spine {
|
|
|
this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
|
|
|
}
|
|
|
|
|
|
- apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number) {
|
|
|
+ apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) {
|
|
|
let frames = this.frames;
|
|
|
if (time < frames[0]) return; // Time is before first frame.
|
|
|
|
|
|
let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex];
|
|
|
|
|
|
+ let rotate = 0, translate = 0;
|
|
|
if (time >= frames[frames.length - PathConstraintMixTimeline.ENTRIES]) { // Time is after last frame.
|
|
|
- let i = frames.length;
|
|
|
- constraint.rotateMix += (frames[i + PathConstraintMixTimeline.PREV_ROTATE] - constraint.rotateMix) * alpha;
|
|
|
- constraint.translateMix += (frames[i + PathConstraintMixTimeline.PREV_TRANSLATE] - constraint.translateMix) * alpha;
|
|
|
- return;
|
|
|
- }
|
|
|
+ rotate = frames[frames.length + PathConstraintMixTimeline.PREV_ROTATE];
|
|
|
+ translate = frames[frames.length + PathConstraintMixTimeline.PREV_TRANSLATE];
|
|
|
+ } else {
|
|
|
+ // Interpolate between the previous frame and the current frame.
|
|
|
+ let frame = Animation.binarySearch(frames, time, PathConstraintMixTimeline.ENTRIES);
|
|
|
+ rotate = frames[frame + PathConstraintMixTimeline.PREV_ROTATE];
|
|
|
+ translate = frames[frame + PathConstraintMixTimeline.PREV_TRANSLATE];
|
|
|
+ let frameTime = frames[frame];
|
|
|
+ let percent = this.getCurvePercent(frame / PathConstraintMixTimeline.ENTRIES - 1,
|
|
|
+ 1 - (time - frameTime) / (frames[frame + PathConstraintMixTimeline.PREV_TIME] - frameTime));
|
|
|
|
|
|
- // Interpolate between the previous frame and the current frame.
|
|
|
- let frame = Animation.binarySearch(frames, time, PathConstraintMixTimeline.ENTRIES);
|
|
|
- let rotate = frames[frame + PathConstraintMixTimeline.PREV_ROTATE];
|
|
|
- let translate = frames[frame + PathConstraintMixTimeline.PREV_TRANSLATE];
|
|
|
- let frameTime = frames[frame];
|
|
|
- let percent = this.getCurvePercent(frame / PathConstraintMixTimeline.ENTRIES - 1,
|
|
|
- 1 - (time - frameTime) / (frames[frame + PathConstraintMixTimeline.PREV_TIME] - frameTime));
|
|
|
+ rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
|
|
|
+ translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
|
|
|
+ }
|
|
|
|
|
|
- constraint.rotateMix += (rotate + (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent - constraint.rotateMix) * alpha;
|
|
|
- constraint.translateMix += (translate + (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent - constraint.translateMix)
|
|
|
- * alpha;
|
|
|
+ if (setupPose) {
|
|
|
+ constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
|
|
|
+ constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
|
|
|
+ } else {
|
|
|
+ constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
|
|
|
+ constraint.translateMix += (translate - constraint.translateMix) * alpha;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|