[ts] Ported VertexAttachment id and Timeline/Animation#apply changes

This commit is contained in:
badlogic 2017-06-12 17:00:10 +02:00
parent ef6f181267
commit f158e9e996
22 changed files with 1512 additions and 879 deletions

View File

@ -178,6 +178,8 @@
* Added `ClippingAttachment`, additional method `newClippingAttachment` in `AttachmentLoader` interface. * Added `ClippingAttachment`, additional method `newClippingAttachment` in `AttachmentLoader` interface.
* Added `SkeletonClipper` and `Triangulator`, used to implement software clipping of attachments. * Added `SkeletonClipper` and `Triangulator`, used to implement software clipping of attachments.
* `AnimationState#apply` returns boolean indicating if any timeline was applied or not. * `AnimationState#apply` returns boolean indicating if any timeline was applied or not.
* `Animation#apply` and `Timeline#apply`` now take enums `MixPose` and `MixDirection` instead of booleans
### WebGL backend ### WebGL backend
* Fixed WebGL context loss * Fixed WebGL context loss

View File

@ -98,14 +98,23 @@ declare module spine {
timelines: Array<Timeline>; timelines: Array<Timeline>;
duration: number; duration: number;
constructor(name: string, timelines: Array<Timeline>, duration: number); constructor(name: string, timelines: Array<Timeline>, duration: number);
apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
static binarySearch(values: ArrayLike<number>, target: number, step?: number): number; static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
static linearSearch(values: ArrayLike<number>, target: number, step: number): number; static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
} }
interface Timeline { interface Timeline {
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
getPropertyId(): number; getPropertyId(): number;
} }
enum MixPose {
setup = 0,
current = 1,
currentLayered = 2,
}
enum MixDirection {
in = 0,
out = 1,
}
enum TimelineType { enum TimelineType {
rotate = 0, rotate = 0,
translate = 1, translate = 1,
@ -137,7 +146,7 @@ declare module spine {
getCurveType(frameIndex: number): number; getCurveType(frameIndex: number): number;
setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void; setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void;
getCurvePercent(frameIndex: number, percent: number): number; getCurvePercent(frameIndex: number, percent: number): number;
abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class RotateTimeline extends CurveTimeline { class RotateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -149,7 +158,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, degrees: number): void; setFrame(frameIndex: number, time: number, degrees: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TranslateTimeline extends CurveTimeline { class TranslateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -163,17 +172,17 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, x: number, y: number): void; setFrame(frameIndex: number, time: number, x: number, y: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ScaleTimeline extends TranslateTimeline { class ScaleTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ShearTimeline extends TranslateTimeline { class ShearTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ColorTimeline extends CurveTimeline { class ColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -191,7 +200,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TwoColorTimeline extends CurveTimeline { class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -215,7 +224,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
@ -225,7 +234,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, attachmentName: string): void; setFrame(frameIndex: number, time: number, attachmentName: string): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DeformTimeline extends CurveTimeline { class DeformTimeline extends CurveTimeline {
slotIndex: number; slotIndex: number;
@ -235,7 +244,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void; setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class EventTimeline implements Timeline { class EventTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -244,7 +253,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, event: Event): void; setFrame(frameIndex: number, event: Event): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DrawOrderTimeline implements Timeline { class DrawOrderTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -253,7 +262,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void; setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class IkConstraintTimeline extends CurveTimeline { class IkConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -267,7 +276,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void; setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TransformConstraintTimeline extends CurveTimeline { class TransformConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -285,7 +294,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintPositionTimeline extends CurveTimeline { class PathConstraintPositionTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -297,12 +306,12 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, value: number): void; setFrame(frameIndex: number, time: number, value: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline { class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintMixTimeline extends CurveTimeline { class PathConstraintMixTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -316,7 +325,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
} }
declare module spine { declare module spine {
@ -340,8 +349,8 @@ declare module spine {
update(delta: number): void; update(delta: number): void;
updateMixingFrom(to: TrackEntry, delta: number): boolean; updateMixingFrom(to: TrackEntry, delta: number): boolean;
apply(skeleton: Skeleton): boolean; apply(skeleton: Skeleton): boolean;
applyMixingFrom(to: TrackEntry, skeleton: Skeleton): number; applyMixingFrom(to: TrackEntry, skeleton: Skeleton, currentPose: MixPose): number;
applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, setupPose: boolean, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void; applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, pose: MixPose, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void;
queueEvents(entry: TrackEntry, animationTime: number): void; queueEvents(entry: TrackEntry, animationTime: number): void;
clearTracks(): void; clearTracks(): void;
clearTrack(trackIndex: number): void; clearTrack(trackIndex: number): void;
@ -467,6 +476,8 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
abstract class VertexAttachment extends Attachment { abstract class VertexAttachment extends Attachment {
private static nextID;
id: number;
bones: Array<number>; bones: Array<number>;
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;

View File

@ -463,7 +463,7 @@ var spine;
this.timelines = timelines; this.timelines = timelines;
this.duration = duration; this.duration = duration;
} }
Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, setupPose, mixingOut) { Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
if (skeleton == null) if (skeleton == null)
throw new Error("skeleton cannot be null."); throw new Error("skeleton cannot be null.");
if (loop && this.duration != 0) { if (loop && this.duration != 0) {
@ -473,7 +473,7 @@ var spine;
} }
var timelines = this.timelines; var timelines = this.timelines;
for (var i = 0, n = timelines.length; i < n; i++) for (var i = 0, n = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut); timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
}; };
Animation.binarySearch = function (values, target, step) { Animation.binarySearch = function (values, target, step) {
if (step === void 0) { step = 1; } if (step === void 0) { step = 1; }
@ -501,6 +501,17 @@ var spine;
return Animation; return Animation;
}()); }());
spine.Animation = Animation; spine.Animation = Animation;
(function (MixPose) {
MixPose[MixPose["setup"] = 0] = "setup";
MixPose[MixPose["current"] = 1] = "current";
MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
})(spine.MixPose || (spine.MixPose = {}));
var MixPose = spine.MixPose;
(function (MixDirection) {
MixDirection[MixDirection["in"] = 0] = "in";
MixDirection[MixDirection["out"] = 1] = "out";
})(spine.MixDirection || (spine.MixDirection = {}));
var MixDirection = spine.MixDirection;
(function (TimelineType) { (function (TimelineType) {
TimelineType[TimelineType["rotate"] = 0] = "rotate"; TimelineType[TimelineType["rotate"] = 0] = "rotate";
TimelineType[TimelineType["translate"] = 1] = "translate"; TimelineType[TimelineType["translate"] = 1] = "translate";
@ -615,21 +626,28 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + RotateTimeline.ROTATION] = degrees; this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
}; };
RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
bone.rotation = bone.data.rotation; case MixPose.setup:
bone.rotation = bone.data.rotation;
return;
case MixPose.current:
var r_1 = bone.data.rotation - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha;
}
return; return;
} }
if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
if (setupPose) if (pose == MixPose.setup)
bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha; bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
else { else {
var r_1 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation; var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360; r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha; bone.rotation += r_2 * alpha;
} }
return; return;
} }
@ -640,7 +658,7 @@ var spine;
var r = frames[frame + RotateTimeline.ROTATION] - prevRotation; var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
r = prevRotation + r * percent; r = prevRotation + r * percent;
if (setupPose) { if (pose == MixPose.setup) {
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.rotation = bone.data.rotation + r * alpha; bone.rotation = bone.data.rotation + r * alpha;
} }
@ -672,13 +690,18 @@ var spine;
this.frames[frameIndex + TranslateTimeline.X] = x; this.frames[frameIndex + TranslateTimeline.X] = x;
this.frames[frameIndex + TranslateTimeline.Y] = y; this.frames[frameIndex + TranslateTimeline.Y] = y;
}; };
TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.x = bone.data.x; case MixPose.setup:
bone.y = bone.data.y; bone.x = bone.data.x;
bone.y = bone.data.y;
return;
case MixPose.current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
} }
return; return;
} }
@ -696,7 +719,7 @@ var spine;
x += (frames[frame + TranslateTimeline.X] - x) * percent; x += (frames[frame + TranslateTimeline.X] - x) * percent;
y += (frames[frame + TranslateTimeline.Y] - y) * percent; y += (frames[frame + TranslateTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.x = bone.data.x + x * alpha; bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; bone.y = bone.data.y + y * alpha;
} }
@ -722,13 +745,18 @@ var spine;
ScaleTimeline.prototype.getPropertyId = function () { ScaleTimeline.prototype.getPropertyId = function () {
return (TimelineType.scale << 24) + this.boneIndex; return (TimelineType.scale << 24) + this.boneIndex;
}; };
ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.scaleX = bone.data.scaleX; case MixPose.setup:
bone.scaleY = bone.data.scaleY; bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY;
return;
case MixPose.current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
} }
return; return;
} }
@ -752,7 +780,7 @@ var spine;
} }
else { else {
var bx = 0, by = 0; var bx = 0, by = 0;
if (setupPose) { if (pose == MixPose.setup) {
bx = bone.data.scaleX; bx = bone.data.scaleX;
by = bone.data.scaleY; by = bone.data.scaleY;
} }
@ -760,7 +788,7 @@ var spine;
bx = bone.scaleX; bx = bone.scaleX;
by = bone.scaleY; by = bone.scaleY;
} }
if (mixingOut) { if (direction == MixDirection.out) {
x = Math.abs(x) * spine.MathUtils.signum(bx); x = Math.abs(x) * spine.MathUtils.signum(bx);
y = Math.abs(y) * spine.MathUtils.signum(by); y = Math.abs(y) * spine.MathUtils.signum(by);
} }
@ -783,13 +811,18 @@ var spine;
ShearTimeline.prototype.getPropertyId = function () { ShearTimeline.prototype.getPropertyId = function () {
return (TimelineType.shear << 24) + this.boneIndex; return (TimelineType.shear << 24) + this.boneIndex;
}; };
ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.shearX = bone.data.shearX; case MixPose.setup:
bone.shearY = bone.data.shearY; bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY;
return;
case MixPose.current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
} }
return; return;
} }
@ -807,7 +840,7 @@ var spine;
x = x + (frames[frame + ShearTimeline.X] - x) * percent; x = x + (frames[frame + ShearTimeline.X] - x) * percent;
y = y + (frames[frame + ShearTimeline.Y] - y) * percent; y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.shearX = bone.data.shearX + x * alpha; bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; bone.shearY = bone.data.shearY + y * alpha;
} }
@ -836,12 +869,18 @@ var spine;
this.frames[frameIndex + ColorTimeline.B] = b; this.frames[frameIndex + ColorTimeline.B] = b;
this.frames[frameIndex + ColorTimeline.A] = a; this.frames[frameIndex + ColorTimeline.A] = a;
}; };
ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.color.setFromColor(slot.data.color);
return;
case MixPose.current:
var color = slot.color, setup = slot.data.color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
}
return; return;
} }
var r = 0, g = 0, b = 0, a = 0; var r = 0, g = 0, b = 0, a = 0;
@ -869,7 +908,7 @@ var spine;
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
else { else {
var color = slot.color; var color = slot.color;
if (setupPose) if (pose == MixPose.setup)
color.setFromColor(slot.data.color); color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
} }
@ -907,13 +946,19 @@ var spine;
this.frames[frameIndex + TwoColorTimeline.G2] = g2; this.frames[frameIndex + TwoColorTimeline.G2] = g2;
this.frames[frameIndex + TwoColorTimeline.B2] = b2; this.frames[frameIndex + TwoColorTimeline.B2] = b2;
}; };
TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.darkColor.setFromColor(slot.data.darkColor); slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor);
return;
case MixPose.current:
var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
} }
return; return;
} }
@ -952,9 +997,8 @@ var spine;
slot.darkColor.set(r2, g2, b2, 1); slot.darkColor.set(r2, g2, b2, 1);
} }
else { else {
var light = slot.color; var light = slot.color, dark = slot.darkColor;
var dark = slot.darkColor; if (pose == MixPose.setup) {
if (setupPose) {
light.setFromColor(slot.data.color); light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor); dark.setFromColor(slot.data.darkColor);
} }
@ -996,16 +1040,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.attachmentNames[frameIndex] = attachmentName; this.attachmentNames[frameIndex] = attachmentName;
}; };
AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
var attachmentName_1 = slot.data.attachmentName; var attachmentName_1 = slot.data.attachmentName;
slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1)); slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
var attachmentName_2 = slot.data.attachmentName; var attachmentName_2 = slot.data.attachmentName;
slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2)); slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
} }
@ -1031,35 +1075,42 @@ var spine;
this.frameVertices = new Array(frameCount); this.frameVertices = new Array(frameCount);
} }
DeformTimeline.prototype.getPropertyId = function () { DeformTimeline.prototype.getPropertyId = function () {
return (TimelineType.deform << 24) + this.slotIndex; return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
}; };
DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) { DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frameVertices[frameIndex] = vertices; this.frameVertices[frameIndex] = vertices;
}; };
DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var slotAttachment = slot.getAttachment(); var slotAttachment = slot.getAttachment();
if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment)) if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
return; return;
var frames = this.frames;
var verticesArray = slot.attachmentVertices; var verticesArray = slot.attachmentVertices;
if (time < frames[0]) {
if (setupPose)
spine.Utils.setArraySize(verticesArray, 0);
return;
}
var frameVertices = this.frameVertices; var frameVertices = this.frameVertices;
var vertexCount = frameVertices[0].length; var vertexCount = frameVertices[0].length;
if (verticesArray.length != vertexCount && !setupPose) if (verticesArray.length != vertexCount && pose != MixPose.setup)
alpha = 1; alpha = 1;
var vertices = spine.Utils.setArraySize(verticesArray, vertexCount); var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
var frames = this.frames;
if (time < frames[0]) {
switch (pose) {
case MixPose.setup:
verticesArray.length = 0;
return;
case MixPose.current:
alpha = 1 - alpha;
for (var i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
}
return;
}
if (time >= frames[frames.length - 1]) { if (time >= frames[frames.length - 1]) {
var lastVertices = frameVertices[frames.length - 1]; var lastVertices = frameVertices[frames.length - 1];
if (alpha == 1) { if (alpha == 1) {
spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount); spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -1090,7 +1141,7 @@ var spine;
vertices[i] = prev + (nextVertices[i] - prev) * percent; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -1131,13 +1182,13 @@ var spine;
this.frames[frameIndex] = event.time; this.frames[frameIndex] = event.time;
this.events[frameIndex] = event; this.events[frameIndex] = event;
}; };
EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
if (firedEvents == null) if (firedEvents == null)
return; return;
var frames = this.frames; var frames = this.frames;
var frameCount = this.frames.length; var frameCount = this.frames.length;
if (lastTime > time) { if (lastTime > time) {
this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut); this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
lastTime = -1; lastTime = -1;
} }
else if (lastTime >= frames[frameCount - 1]) else if (lastTime >= frames[frameCount - 1])
@ -1177,16 +1228,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.drawOrders[frameIndex] = drawOrder; this.drawOrders[frameIndex] = drawOrder;
}; };
DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var drawOrder = skeleton.drawOrder; var drawOrder = skeleton.drawOrder;
var slots = skeleton.slots; var slots = skeleton.slots;
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == MixPose.setup)
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
@ -1221,25 +1272,30 @@ var spine;
this.frames[frameIndex + IkConstraintTimeline.MIX] = mix; this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection; this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
}; };
IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.ikConstraints[this.ikConstraintIndex]; var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.mix = constraint.data.mix; case MixPose.setup:
constraint.bendDirection = constraint.data.bendDirection; constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose.current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
} }
return; return;
} }
if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha; constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
return; return;
@ -1248,13 +1304,13 @@ var spine;
var mix = frames[frame + IkConstraintTimeline.PREV_MIX]; var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
var frameTime = frames[frame]; var frameTime = frames[frame];
var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha; 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]; constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha; constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
}; };
@ -1284,16 +1340,23 @@ var spine;
this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix; this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix; this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
}; };
TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.transformConstraints[this.transformConstraintIndex]; var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { var data = constraint.data;
var data = constraint.data; switch (pose) {
constraint.rotateMix = data.rotateMix; case MixPose.setup:
constraint.translateMix = data.rotateMix; constraint.rotateMix = data.rotateMix;
constraint.scaleMix = data.scaleMix; constraint.translateMix = data.translateMix;
constraint.shearMix = data.shearMix; constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix;
return;
case MixPose.current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
} }
return; return;
} }
@ -1318,7 +1381,7 @@ var spine;
scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent; scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent; shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
var data = constraint.data; var data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
@ -1359,12 +1422,17 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value; this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
}; };
PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.position = constraint.data.position; case MixPose.setup:
constraint.position = constraint.data.position;
return;
case MixPose.current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
}
return; return;
} }
var position = 0; var position = 0;
@ -1377,7 +1445,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent; position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else else
constraint.position += (position - constraint.position) * alpha; constraint.position += (position - constraint.position) * alpha;
@ -1397,12 +1465,17 @@ var spine;
PathConstraintSpacingTimeline.prototype.getPropertyId = function () { PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex; return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
}; };
PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.spacing = constraint.data.spacing; case MixPose.setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose.current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
}
return; return;
} }
var spacing = 0; var spacing = 0;
@ -1415,7 +1488,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent; spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else else
constraint.spacing += (spacing - constraint.spacing) * alpha; constraint.spacing += (spacing - constraint.spacing) * alpha;
@ -1438,13 +1511,18 @@ var spine;
this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix; this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix; this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
}; };
PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.rotateMix = constraint.data.rotateMix; case MixPose.setup:
constraint.translateMix = constraint.data.translateMix; constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix;
return;
case MixPose.current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
} }
return; return;
} }
@ -1462,7 +1540,7 @@ var spine;
rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent; rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent; translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} }
@ -1578,9 +1656,10 @@ var spine;
if (current == null || current.delay > 0) if (current == null || current.delay > 0)
continue; continue;
applied = true; applied = true;
var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
var mix = current.alpha; var mix = current.alpha;
if (current.mixingFrom != null) if (current.mixingFrom != null)
mix *= this.applyMixingFrom(current, skeleton); mix *= this.applyMixingFrom(current, skeleton, currentPose);
else if (current.trackTime >= current.trackEnd && current.next == null) else if (current.trackTime >= current.trackEnd && current.next == null)
mix = 0; mix = 0;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
@ -1588,7 +1667,7 @@ var spine;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1) { if (mix == 1) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, true, false); timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection.in);
} }
else { else {
var timelineData = current.timelineData; var timelineData = current.timelineData;
@ -1598,11 +1677,12 @@ var spine;
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineData[ii] >= AnimationState.FIRST, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
} }
else else
timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= AnimationState.FIRST, false); timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection.in);
} }
} }
this.queueEvents(current, animationTime); this.queueEvents(current, animationTime);
@ -1613,10 +1693,10 @@ var spine;
this.queue.drain(); this.queue.drain();
return applied; return applied;
}; };
AnimationState.prototype.applyMixingFrom = function (to, skeleton) { AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
var from = to.mixingFrom; var from = to.mixingFrom;
if (from.mixingFrom != null) if (from.mixingFrom != null)
this.applyMixingFrom(from, skeleton); this.applyMixingFrom(from, skeleton, currentPose);
var mix = 0; var mix = 0;
if (to.mixDuration == 0) if (to.mixDuration == 0)
mix = 1; mix = 1;
@ -1636,26 +1716,30 @@ var spine;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = from.timelinesRotation; var timelinesRotation = from.timelinesRotation;
var first = false; var pose;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0; var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
from.totalAlpha = 0; from.totalAlpha = 0;
for (var i = 0; i < timelineCount; i++) { for (var i = 0; i < timelineCount; i++) {
var timeline = timelines[i]; var timeline = timelines[i];
switch (timelineData[i]) { switch (timelineData[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
first = false; if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
pose = currentPose;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.FIRST: case AnimationState.FIRST:
first = true; pose = spine.MixPose.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.DIP:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
break; break;
default: default:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
var dipMix = timelineDipMix[i]; var dipMix = timelineDipMix[i];
alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
@ -1663,15 +1747,9 @@ var spine;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
if (timeline instanceof spine.RotateTimeline) if (timeline instanceof spine.RotateTimeline)
this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
else { else {
if (!first) { timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
}
timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true);
} }
} }
if (to.mixDuration > 0) if (to.mixDuration > 0)
@ -1681,18 +1759,18 @@ var spine;
from.nextTrackLast = from.trackTime; from.nextTrackLast = from.trackTime;
return mix; return mix;
}; };
AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, setupPose, timelinesRotation, i, firstFrame) { AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
if (firstFrame) if (firstFrame)
timelinesRotation[i] = 0; timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection.in);
return; return;
} }
var rotateTimeline = timeline; var rotateTimeline = timeline;
var frames = rotateTimeline.frames; var frames = rotateTimeline.frames;
var bone = skeleton.bones[rotateTimeline.boneIndex]; var bone = skeleton.bones[rotateTimeline.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == spine.MixPose.setup)
bone.rotation = bone.data.rotation; bone.rotation = bone.data.rotation;
return; return;
} }
@ -1709,7 +1787,7 @@ var spine;
r2 = prevRotation + r2 * percent + bone.data.rotation; r2 = prevRotation + r2 * percent + bone.data.rotation;
r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360; r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
} }
var r1 = setupPose ? bone.data.rotation : bone.rotation; var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
var total = 0, diff = r2 - r1; var total = 0, diff = r2 - r1;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];
@ -2270,6 +2348,7 @@ var spine;
__extends(VertexAttachment, _super); __extends(VertexAttachment, _super);
function VertexAttachment(name) { function VertexAttachment(name) {
_super.call(this, name); _super.call(this, name);
this.id = (VertexAttachment.nextID++ & 65535) << 11;
this.worldVerticesLength = 0; this.worldVerticesLength = 0;
} }
VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) { VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
@ -2334,6 +2413,7 @@ var spine;
VertexAttachment.prototype.applyDeform = function (sourceAttachment) { VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
}; };
VertexAttachment.nextID = 0;
return VertexAttachment; return VertexAttachment;
}(Attachment)); }(Attachment));
spine.VertexAttachment = VertexAttachment; spine.VertexAttachment = VertexAttachment;

File diff suppressed because one or more lines are too long

View File

@ -98,14 +98,23 @@ declare module spine {
timelines: Array<Timeline>; timelines: Array<Timeline>;
duration: number; duration: number;
constructor(name: string, timelines: Array<Timeline>, duration: number); constructor(name: string, timelines: Array<Timeline>, duration: number);
apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
static binarySearch(values: ArrayLike<number>, target: number, step?: number): number; static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
static linearSearch(values: ArrayLike<number>, target: number, step: number): number; static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
} }
interface Timeline { interface Timeline {
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
getPropertyId(): number; getPropertyId(): number;
} }
enum MixPose {
setup = 0,
current = 1,
currentLayered = 2,
}
enum MixDirection {
in = 0,
out = 1,
}
enum TimelineType { enum TimelineType {
rotate = 0, rotate = 0,
translate = 1, translate = 1,
@ -137,7 +146,7 @@ declare module spine {
getCurveType(frameIndex: number): number; getCurveType(frameIndex: number): number;
setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void; setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void;
getCurvePercent(frameIndex: number, percent: number): number; getCurvePercent(frameIndex: number, percent: number): number;
abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class RotateTimeline extends CurveTimeline { class RotateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -149,7 +158,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, degrees: number): void; setFrame(frameIndex: number, time: number, degrees: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TranslateTimeline extends CurveTimeline { class TranslateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -163,17 +172,17 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, x: number, y: number): void; setFrame(frameIndex: number, time: number, x: number, y: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ScaleTimeline extends TranslateTimeline { class ScaleTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ShearTimeline extends TranslateTimeline { class ShearTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ColorTimeline extends CurveTimeline { class ColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -191,7 +200,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TwoColorTimeline extends CurveTimeline { class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -215,7 +224,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
@ -225,7 +234,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, attachmentName: string): void; setFrame(frameIndex: number, time: number, attachmentName: string): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DeformTimeline extends CurveTimeline { class DeformTimeline extends CurveTimeline {
slotIndex: number; slotIndex: number;
@ -235,7 +244,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void; setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class EventTimeline implements Timeline { class EventTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -244,7 +253,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, event: Event): void; setFrame(frameIndex: number, event: Event): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DrawOrderTimeline implements Timeline { class DrawOrderTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -253,7 +262,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void; setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class IkConstraintTimeline extends CurveTimeline { class IkConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -267,7 +276,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void; setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TransformConstraintTimeline extends CurveTimeline { class TransformConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -285,7 +294,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintPositionTimeline extends CurveTimeline { class PathConstraintPositionTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -297,12 +306,12 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, value: number): void; setFrame(frameIndex: number, time: number, value: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline { class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintMixTimeline extends CurveTimeline { class PathConstraintMixTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -316,7 +325,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
} }
declare module spine { declare module spine {
@ -340,8 +349,8 @@ declare module spine {
update(delta: number): void; update(delta: number): void;
updateMixingFrom(to: TrackEntry, delta: number): boolean; updateMixingFrom(to: TrackEntry, delta: number): boolean;
apply(skeleton: Skeleton): boolean; apply(skeleton: Skeleton): boolean;
applyMixingFrom(to: TrackEntry, skeleton: Skeleton): number; applyMixingFrom(to: TrackEntry, skeleton: Skeleton, currentPose: MixPose): number;
applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, setupPose: boolean, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void; applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, pose: MixPose, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void;
queueEvents(entry: TrackEntry, animationTime: number): void; queueEvents(entry: TrackEntry, animationTime: number): void;
clearTracks(): void; clearTracks(): void;
clearTrack(trackIndex: number): void; clearTrack(trackIndex: number): void;
@ -467,6 +476,8 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
abstract class VertexAttachment extends Attachment { abstract class VertexAttachment extends Attachment {
private static nextID;
id: number;
bones: Array<number>; bones: Array<number>;
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;

View File

@ -463,7 +463,7 @@ var spine;
this.timelines = timelines; this.timelines = timelines;
this.duration = duration; this.duration = duration;
} }
Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, setupPose, mixingOut) { Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
if (skeleton == null) if (skeleton == null)
throw new Error("skeleton cannot be null."); throw new Error("skeleton cannot be null.");
if (loop && this.duration != 0) { if (loop && this.duration != 0) {
@ -473,7 +473,7 @@ var spine;
} }
var timelines = this.timelines; var timelines = this.timelines;
for (var i = 0, n = timelines.length; i < n; i++) for (var i = 0, n = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut); timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
}; };
Animation.binarySearch = function (values, target, step) { Animation.binarySearch = function (values, target, step) {
if (step === void 0) { step = 1; } if (step === void 0) { step = 1; }
@ -501,6 +501,17 @@ var spine;
return Animation; return Animation;
}()); }());
spine.Animation = Animation; spine.Animation = Animation;
(function (MixPose) {
MixPose[MixPose["setup"] = 0] = "setup";
MixPose[MixPose["current"] = 1] = "current";
MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
})(spine.MixPose || (spine.MixPose = {}));
var MixPose = spine.MixPose;
(function (MixDirection) {
MixDirection[MixDirection["in"] = 0] = "in";
MixDirection[MixDirection["out"] = 1] = "out";
})(spine.MixDirection || (spine.MixDirection = {}));
var MixDirection = spine.MixDirection;
(function (TimelineType) { (function (TimelineType) {
TimelineType[TimelineType["rotate"] = 0] = "rotate"; TimelineType[TimelineType["rotate"] = 0] = "rotate";
TimelineType[TimelineType["translate"] = 1] = "translate"; TimelineType[TimelineType["translate"] = 1] = "translate";
@ -615,21 +626,28 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + RotateTimeline.ROTATION] = degrees; this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
}; };
RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
bone.rotation = bone.data.rotation; case MixPose.setup:
bone.rotation = bone.data.rotation;
return;
case MixPose.current:
var r_1 = bone.data.rotation - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha;
}
return; return;
} }
if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
if (setupPose) if (pose == MixPose.setup)
bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha; bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
else { else {
var r_1 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation; var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360; r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha; bone.rotation += r_2 * alpha;
} }
return; return;
} }
@ -640,7 +658,7 @@ var spine;
var r = frames[frame + RotateTimeline.ROTATION] - prevRotation; var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
r = prevRotation + r * percent; r = prevRotation + r * percent;
if (setupPose) { if (pose == MixPose.setup) {
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.rotation = bone.data.rotation + r * alpha; bone.rotation = bone.data.rotation + r * alpha;
} }
@ -672,13 +690,18 @@ var spine;
this.frames[frameIndex + TranslateTimeline.X] = x; this.frames[frameIndex + TranslateTimeline.X] = x;
this.frames[frameIndex + TranslateTimeline.Y] = y; this.frames[frameIndex + TranslateTimeline.Y] = y;
}; };
TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.x = bone.data.x; case MixPose.setup:
bone.y = bone.data.y; bone.x = bone.data.x;
bone.y = bone.data.y;
return;
case MixPose.current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
} }
return; return;
} }
@ -696,7 +719,7 @@ var spine;
x += (frames[frame + TranslateTimeline.X] - x) * percent; x += (frames[frame + TranslateTimeline.X] - x) * percent;
y += (frames[frame + TranslateTimeline.Y] - y) * percent; y += (frames[frame + TranslateTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.x = bone.data.x + x * alpha; bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; bone.y = bone.data.y + y * alpha;
} }
@ -722,13 +745,18 @@ var spine;
ScaleTimeline.prototype.getPropertyId = function () { ScaleTimeline.prototype.getPropertyId = function () {
return (TimelineType.scale << 24) + this.boneIndex; return (TimelineType.scale << 24) + this.boneIndex;
}; };
ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.scaleX = bone.data.scaleX; case MixPose.setup:
bone.scaleY = bone.data.scaleY; bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY;
return;
case MixPose.current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
} }
return; return;
} }
@ -752,7 +780,7 @@ var spine;
} }
else { else {
var bx = 0, by = 0; var bx = 0, by = 0;
if (setupPose) { if (pose == MixPose.setup) {
bx = bone.data.scaleX; bx = bone.data.scaleX;
by = bone.data.scaleY; by = bone.data.scaleY;
} }
@ -760,7 +788,7 @@ var spine;
bx = bone.scaleX; bx = bone.scaleX;
by = bone.scaleY; by = bone.scaleY;
} }
if (mixingOut) { if (direction == MixDirection.out) {
x = Math.abs(x) * spine.MathUtils.signum(bx); x = Math.abs(x) * spine.MathUtils.signum(bx);
y = Math.abs(y) * spine.MathUtils.signum(by); y = Math.abs(y) * spine.MathUtils.signum(by);
} }
@ -783,13 +811,18 @@ var spine;
ShearTimeline.prototype.getPropertyId = function () { ShearTimeline.prototype.getPropertyId = function () {
return (TimelineType.shear << 24) + this.boneIndex; return (TimelineType.shear << 24) + this.boneIndex;
}; };
ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.shearX = bone.data.shearX; case MixPose.setup:
bone.shearY = bone.data.shearY; bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY;
return;
case MixPose.current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
} }
return; return;
} }
@ -807,7 +840,7 @@ var spine;
x = x + (frames[frame + ShearTimeline.X] - x) * percent; x = x + (frames[frame + ShearTimeline.X] - x) * percent;
y = y + (frames[frame + ShearTimeline.Y] - y) * percent; y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.shearX = bone.data.shearX + x * alpha; bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; bone.shearY = bone.data.shearY + y * alpha;
} }
@ -836,12 +869,18 @@ var spine;
this.frames[frameIndex + ColorTimeline.B] = b; this.frames[frameIndex + ColorTimeline.B] = b;
this.frames[frameIndex + ColorTimeline.A] = a; this.frames[frameIndex + ColorTimeline.A] = a;
}; };
ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.color.setFromColor(slot.data.color);
return;
case MixPose.current:
var color = slot.color, setup = slot.data.color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
}
return; return;
} }
var r = 0, g = 0, b = 0, a = 0; var r = 0, g = 0, b = 0, a = 0;
@ -869,7 +908,7 @@ var spine;
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
else { else {
var color = slot.color; var color = slot.color;
if (setupPose) if (pose == MixPose.setup)
color.setFromColor(slot.data.color); color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
} }
@ -907,13 +946,19 @@ var spine;
this.frames[frameIndex + TwoColorTimeline.G2] = g2; this.frames[frameIndex + TwoColorTimeline.G2] = g2;
this.frames[frameIndex + TwoColorTimeline.B2] = b2; this.frames[frameIndex + TwoColorTimeline.B2] = b2;
}; };
TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.darkColor.setFromColor(slot.data.darkColor); slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor);
return;
case MixPose.current:
var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
} }
return; return;
} }
@ -952,9 +997,8 @@ var spine;
slot.darkColor.set(r2, g2, b2, 1); slot.darkColor.set(r2, g2, b2, 1);
} }
else { else {
var light = slot.color; var light = slot.color, dark = slot.darkColor;
var dark = slot.darkColor; if (pose == MixPose.setup) {
if (setupPose) {
light.setFromColor(slot.data.color); light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor); dark.setFromColor(slot.data.darkColor);
} }
@ -996,16 +1040,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.attachmentNames[frameIndex] = attachmentName; this.attachmentNames[frameIndex] = attachmentName;
}; };
AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
var attachmentName_1 = slot.data.attachmentName; var attachmentName_1 = slot.data.attachmentName;
slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1)); slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
var attachmentName_2 = slot.data.attachmentName; var attachmentName_2 = slot.data.attachmentName;
slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2)); slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
} }
@ -1031,35 +1075,42 @@ var spine;
this.frameVertices = new Array(frameCount); this.frameVertices = new Array(frameCount);
} }
DeformTimeline.prototype.getPropertyId = function () { DeformTimeline.prototype.getPropertyId = function () {
return (TimelineType.deform << 24) + this.slotIndex; return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
}; };
DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) { DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frameVertices[frameIndex] = vertices; this.frameVertices[frameIndex] = vertices;
}; };
DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var slotAttachment = slot.getAttachment(); var slotAttachment = slot.getAttachment();
if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment)) if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
return; return;
var frames = this.frames;
var verticesArray = slot.attachmentVertices; var verticesArray = slot.attachmentVertices;
if (time < frames[0]) {
if (setupPose)
spine.Utils.setArraySize(verticesArray, 0);
return;
}
var frameVertices = this.frameVertices; var frameVertices = this.frameVertices;
var vertexCount = frameVertices[0].length; var vertexCount = frameVertices[0].length;
if (verticesArray.length != vertexCount && !setupPose) if (verticesArray.length != vertexCount && pose != MixPose.setup)
alpha = 1; alpha = 1;
var vertices = spine.Utils.setArraySize(verticesArray, vertexCount); var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
var frames = this.frames;
if (time < frames[0]) {
switch (pose) {
case MixPose.setup:
verticesArray.length = 0;
return;
case MixPose.current:
alpha = 1 - alpha;
for (var i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
}
return;
}
if (time >= frames[frames.length - 1]) { if (time >= frames[frames.length - 1]) {
var lastVertices = frameVertices[frames.length - 1]; var lastVertices = frameVertices[frames.length - 1];
if (alpha == 1) { if (alpha == 1) {
spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount); spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -1090,7 +1141,7 @@ var spine;
vertices[i] = prev + (nextVertices[i] - prev) * percent; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -1131,13 +1182,13 @@ var spine;
this.frames[frameIndex] = event.time; this.frames[frameIndex] = event.time;
this.events[frameIndex] = event; this.events[frameIndex] = event;
}; };
EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
if (firedEvents == null) if (firedEvents == null)
return; return;
var frames = this.frames; var frames = this.frames;
var frameCount = this.frames.length; var frameCount = this.frames.length;
if (lastTime > time) { if (lastTime > time) {
this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut); this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
lastTime = -1; lastTime = -1;
} }
else if (lastTime >= frames[frameCount - 1]) else if (lastTime >= frames[frameCount - 1])
@ -1177,16 +1228,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.drawOrders[frameIndex] = drawOrder; this.drawOrders[frameIndex] = drawOrder;
}; };
DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var drawOrder = skeleton.drawOrder; var drawOrder = skeleton.drawOrder;
var slots = skeleton.slots; var slots = skeleton.slots;
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == MixPose.setup)
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
@ -1221,25 +1272,30 @@ var spine;
this.frames[frameIndex + IkConstraintTimeline.MIX] = mix; this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection; this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
}; };
IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.ikConstraints[this.ikConstraintIndex]; var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.mix = constraint.data.mix; case MixPose.setup:
constraint.bendDirection = constraint.data.bendDirection; constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose.current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
} }
return; return;
} }
if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha; constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
return; return;
@ -1248,13 +1304,13 @@ var spine;
var mix = frames[frame + IkConstraintTimeline.PREV_MIX]; var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
var frameTime = frames[frame]; var frameTime = frames[frame];
var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha; 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]; constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha; constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
}; };
@ -1284,16 +1340,23 @@ var spine;
this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix; this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix; this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
}; };
TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.transformConstraints[this.transformConstraintIndex]; var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { var data = constraint.data;
var data = constraint.data; switch (pose) {
constraint.rotateMix = data.rotateMix; case MixPose.setup:
constraint.translateMix = data.rotateMix; constraint.rotateMix = data.rotateMix;
constraint.scaleMix = data.scaleMix; constraint.translateMix = data.translateMix;
constraint.shearMix = data.shearMix; constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix;
return;
case MixPose.current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
} }
return; return;
} }
@ -1318,7 +1381,7 @@ var spine;
scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent; scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent; shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
var data = constraint.data; var data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
@ -1359,12 +1422,17 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value; this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
}; };
PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.position = constraint.data.position; case MixPose.setup:
constraint.position = constraint.data.position;
return;
case MixPose.current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
}
return; return;
} }
var position = 0; var position = 0;
@ -1377,7 +1445,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent; position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else else
constraint.position += (position - constraint.position) * alpha; constraint.position += (position - constraint.position) * alpha;
@ -1397,12 +1465,17 @@ var spine;
PathConstraintSpacingTimeline.prototype.getPropertyId = function () { PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex; return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
}; };
PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.spacing = constraint.data.spacing; case MixPose.setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose.current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
}
return; return;
} }
var spacing = 0; var spacing = 0;
@ -1415,7 +1488,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent; spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else else
constraint.spacing += (spacing - constraint.spacing) * alpha; constraint.spacing += (spacing - constraint.spacing) * alpha;
@ -1438,13 +1511,18 @@ var spine;
this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix; this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix; this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
}; };
PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.rotateMix = constraint.data.rotateMix; case MixPose.setup:
constraint.translateMix = constraint.data.translateMix; constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix;
return;
case MixPose.current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
} }
return; return;
} }
@ -1462,7 +1540,7 @@ var spine;
rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent; rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent; translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} }
@ -1578,9 +1656,10 @@ var spine;
if (current == null || current.delay > 0) if (current == null || current.delay > 0)
continue; continue;
applied = true; applied = true;
var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
var mix = current.alpha; var mix = current.alpha;
if (current.mixingFrom != null) if (current.mixingFrom != null)
mix *= this.applyMixingFrom(current, skeleton); mix *= this.applyMixingFrom(current, skeleton, currentPose);
else if (current.trackTime >= current.trackEnd && current.next == null) else if (current.trackTime >= current.trackEnd && current.next == null)
mix = 0; mix = 0;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
@ -1588,7 +1667,7 @@ var spine;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1) { if (mix == 1) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, true, false); timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection.in);
} }
else { else {
var timelineData = current.timelineData; var timelineData = current.timelineData;
@ -1598,11 +1677,12 @@ var spine;
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineData[ii] >= AnimationState.FIRST, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
} }
else else
timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= AnimationState.FIRST, false); timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection.in);
} }
} }
this.queueEvents(current, animationTime); this.queueEvents(current, animationTime);
@ -1613,10 +1693,10 @@ var spine;
this.queue.drain(); this.queue.drain();
return applied; return applied;
}; };
AnimationState.prototype.applyMixingFrom = function (to, skeleton) { AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
var from = to.mixingFrom; var from = to.mixingFrom;
if (from.mixingFrom != null) if (from.mixingFrom != null)
this.applyMixingFrom(from, skeleton); this.applyMixingFrom(from, skeleton, currentPose);
var mix = 0; var mix = 0;
if (to.mixDuration == 0) if (to.mixDuration == 0)
mix = 1; mix = 1;
@ -1636,26 +1716,30 @@ var spine;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = from.timelinesRotation; var timelinesRotation = from.timelinesRotation;
var first = false; var pose;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0; var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
from.totalAlpha = 0; from.totalAlpha = 0;
for (var i = 0; i < timelineCount; i++) { for (var i = 0; i < timelineCount; i++) {
var timeline = timelines[i]; var timeline = timelines[i];
switch (timelineData[i]) { switch (timelineData[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
first = false; if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
pose = currentPose;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.FIRST: case AnimationState.FIRST:
first = true; pose = spine.MixPose.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.DIP:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
break; break;
default: default:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
var dipMix = timelineDipMix[i]; var dipMix = timelineDipMix[i];
alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
@ -1663,15 +1747,9 @@ var spine;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
if (timeline instanceof spine.RotateTimeline) if (timeline instanceof spine.RotateTimeline)
this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
else { else {
if (!first) { timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
}
timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true);
} }
} }
if (to.mixDuration > 0) if (to.mixDuration > 0)
@ -1681,18 +1759,18 @@ var spine;
from.nextTrackLast = from.trackTime; from.nextTrackLast = from.trackTime;
return mix; return mix;
}; };
AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, setupPose, timelinesRotation, i, firstFrame) { AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
if (firstFrame) if (firstFrame)
timelinesRotation[i] = 0; timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection.in);
return; return;
} }
var rotateTimeline = timeline; var rotateTimeline = timeline;
var frames = rotateTimeline.frames; var frames = rotateTimeline.frames;
var bone = skeleton.bones[rotateTimeline.boneIndex]; var bone = skeleton.bones[rotateTimeline.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == spine.MixPose.setup)
bone.rotation = bone.data.rotation; bone.rotation = bone.data.rotation;
return; return;
} }
@ -1709,7 +1787,7 @@ var spine;
r2 = prevRotation + r2 * percent + bone.data.rotation; r2 = prevRotation + r2 * percent + bone.data.rotation;
r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360; r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
} }
var r1 = setupPose ? bone.data.rotation : bone.rotation; var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
var total = 0, diff = r2 - r1; var total = 0, diff = r2 - r1;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];
@ -2270,6 +2348,7 @@ var spine;
__extends(VertexAttachment, _super); __extends(VertexAttachment, _super);
function VertexAttachment(name) { function VertexAttachment(name) {
_super.call(this, name); _super.call(this, name);
this.id = (VertexAttachment.nextID++ & 65535) << 11;
this.worldVerticesLength = 0; this.worldVerticesLength = 0;
} }
VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) { VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
@ -2334,6 +2413,7 @@ var spine;
VertexAttachment.prototype.applyDeform = function (sourceAttachment) { VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
}; };
VertexAttachment.nextID = 0;
return VertexAttachment; return VertexAttachment;
}(Attachment)); }(Attachment));
spine.VertexAttachment = VertexAttachment; spine.VertexAttachment = VertexAttachment;

File diff suppressed because one or more lines are too long

View File

@ -4,14 +4,23 @@ declare module spine {
timelines: Array<Timeline>; timelines: Array<Timeline>;
duration: number; duration: number;
constructor(name: string, timelines: Array<Timeline>, duration: number); constructor(name: string, timelines: Array<Timeline>, duration: number);
apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
static binarySearch(values: ArrayLike<number>, target: number, step?: number): number; static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
static linearSearch(values: ArrayLike<number>, target: number, step: number): number; static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
} }
interface Timeline { interface Timeline {
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
getPropertyId(): number; getPropertyId(): number;
} }
enum MixPose {
setup = 0,
current = 1,
currentLayered = 2,
}
enum MixDirection {
in = 0,
out = 1,
}
enum TimelineType { enum TimelineType {
rotate = 0, rotate = 0,
translate = 1, translate = 1,
@ -43,7 +52,7 @@ declare module spine {
getCurveType(frameIndex: number): number; getCurveType(frameIndex: number): number;
setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void; setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void;
getCurvePercent(frameIndex: number, percent: number): number; getCurvePercent(frameIndex: number, percent: number): number;
abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class RotateTimeline extends CurveTimeline { class RotateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -55,7 +64,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, degrees: number): void; setFrame(frameIndex: number, time: number, degrees: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TranslateTimeline extends CurveTimeline { class TranslateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -69,17 +78,17 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, x: number, y: number): void; setFrame(frameIndex: number, time: number, x: number, y: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ScaleTimeline extends TranslateTimeline { class ScaleTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ShearTimeline extends TranslateTimeline { class ShearTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ColorTimeline extends CurveTimeline { class ColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -97,7 +106,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TwoColorTimeline extends CurveTimeline { class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -121,7 +130,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
@ -131,7 +140,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, attachmentName: string): void; setFrame(frameIndex: number, time: number, attachmentName: string): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DeformTimeline extends CurveTimeline { class DeformTimeline extends CurveTimeline {
slotIndex: number; slotIndex: number;
@ -141,7 +150,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void; setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class EventTimeline implements Timeline { class EventTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -150,7 +159,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, event: Event): void; setFrame(frameIndex: number, event: Event): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DrawOrderTimeline implements Timeline { class DrawOrderTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -159,7 +168,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void; setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class IkConstraintTimeline extends CurveTimeline { class IkConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -173,7 +182,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void; setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TransformConstraintTimeline extends CurveTimeline { class TransformConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -191,7 +200,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintPositionTimeline extends CurveTimeline { class PathConstraintPositionTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -203,12 +212,12 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, value: number): void; setFrame(frameIndex: number, time: number, value: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline { class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintMixTimeline extends CurveTimeline { class PathConstraintMixTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -222,7 +231,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
} }
declare module spine { declare module spine {
@ -246,8 +255,8 @@ declare module spine {
update(delta: number): void; update(delta: number): void;
updateMixingFrom(to: TrackEntry, delta: number): boolean; updateMixingFrom(to: TrackEntry, delta: number): boolean;
apply(skeleton: Skeleton): boolean; apply(skeleton: Skeleton): boolean;
applyMixingFrom(to: TrackEntry, skeleton: Skeleton): number; applyMixingFrom(to: TrackEntry, skeleton: Skeleton, currentPose: MixPose): number;
applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, setupPose: boolean, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void; applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, pose: MixPose, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void;
queueEvents(entry: TrackEntry, animationTime: number): void; queueEvents(entry: TrackEntry, animationTime: number): void;
clearTracks(): void; clearTracks(): void;
clearTrack(trackIndex: number): void; clearTrack(trackIndex: number): void;
@ -396,6 +405,8 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
abstract class VertexAttachment extends Attachment { abstract class VertexAttachment extends Attachment {
private static nextID;
id: number;
bones: Array<number>; bones: Array<number>;
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;

View File

@ -15,7 +15,7 @@ var spine;
this.timelines = timelines; this.timelines = timelines;
this.duration = duration; this.duration = duration;
} }
Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, setupPose, mixingOut) { Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
if (skeleton == null) if (skeleton == null)
throw new Error("skeleton cannot be null."); throw new Error("skeleton cannot be null.");
if (loop && this.duration != 0) { if (loop && this.duration != 0) {
@ -25,7 +25,7 @@ var spine;
} }
var timelines = this.timelines; var timelines = this.timelines;
for (var i = 0, n = timelines.length; i < n; i++) for (var i = 0, n = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut); timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
}; };
Animation.binarySearch = function (values, target, step) { Animation.binarySearch = function (values, target, step) {
if (step === void 0) { step = 1; } if (step === void 0) { step = 1; }
@ -53,6 +53,17 @@ var spine;
return Animation; return Animation;
}()); }());
spine.Animation = Animation; spine.Animation = Animation;
(function (MixPose) {
MixPose[MixPose["setup"] = 0] = "setup";
MixPose[MixPose["current"] = 1] = "current";
MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
})(spine.MixPose || (spine.MixPose = {}));
var MixPose = spine.MixPose;
(function (MixDirection) {
MixDirection[MixDirection["in"] = 0] = "in";
MixDirection[MixDirection["out"] = 1] = "out";
})(spine.MixDirection || (spine.MixDirection = {}));
var MixDirection = spine.MixDirection;
(function (TimelineType) { (function (TimelineType) {
TimelineType[TimelineType["rotate"] = 0] = "rotate"; TimelineType[TimelineType["rotate"] = 0] = "rotate";
TimelineType[TimelineType["translate"] = 1] = "translate"; TimelineType[TimelineType["translate"] = 1] = "translate";
@ -167,21 +178,28 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + RotateTimeline.ROTATION] = degrees; this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
}; };
RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
bone.rotation = bone.data.rotation; case MixPose.setup:
bone.rotation = bone.data.rotation;
return;
case MixPose.current:
var r_1 = bone.data.rotation - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha;
}
return; return;
} }
if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
if (setupPose) if (pose == MixPose.setup)
bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha; bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
else { else {
var r_1 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation; var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360; r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha; bone.rotation += r_2 * alpha;
} }
return; return;
} }
@ -192,7 +210,7 @@ var spine;
var r = frames[frame + RotateTimeline.ROTATION] - prevRotation; var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
r = prevRotation + r * percent; r = prevRotation + r * percent;
if (setupPose) { if (pose == MixPose.setup) {
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.rotation = bone.data.rotation + r * alpha; bone.rotation = bone.data.rotation + r * alpha;
} }
@ -224,13 +242,18 @@ var spine;
this.frames[frameIndex + TranslateTimeline.X] = x; this.frames[frameIndex + TranslateTimeline.X] = x;
this.frames[frameIndex + TranslateTimeline.Y] = y; this.frames[frameIndex + TranslateTimeline.Y] = y;
}; };
TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.x = bone.data.x; case MixPose.setup:
bone.y = bone.data.y; bone.x = bone.data.x;
bone.y = bone.data.y;
return;
case MixPose.current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
} }
return; return;
} }
@ -248,7 +271,7 @@ var spine;
x += (frames[frame + TranslateTimeline.X] - x) * percent; x += (frames[frame + TranslateTimeline.X] - x) * percent;
y += (frames[frame + TranslateTimeline.Y] - y) * percent; y += (frames[frame + TranslateTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.x = bone.data.x + x * alpha; bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; bone.y = bone.data.y + y * alpha;
} }
@ -274,13 +297,18 @@ var spine;
ScaleTimeline.prototype.getPropertyId = function () { ScaleTimeline.prototype.getPropertyId = function () {
return (TimelineType.scale << 24) + this.boneIndex; return (TimelineType.scale << 24) + this.boneIndex;
}; };
ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.scaleX = bone.data.scaleX; case MixPose.setup:
bone.scaleY = bone.data.scaleY; bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY;
return;
case MixPose.current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
} }
return; return;
} }
@ -304,7 +332,7 @@ var spine;
} }
else { else {
var bx = 0, by = 0; var bx = 0, by = 0;
if (setupPose) { if (pose == MixPose.setup) {
bx = bone.data.scaleX; bx = bone.data.scaleX;
by = bone.data.scaleY; by = bone.data.scaleY;
} }
@ -312,7 +340,7 @@ var spine;
bx = bone.scaleX; bx = bone.scaleX;
by = bone.scaleY; by = bone.scaleY;
} }
if (mixingOut) { if (direction == MixDirection.out) {
x = Math.abs(x) * spine.MathUtils.signum(bx); x = Math.abs(x) * spine.MathUtils.signum(bx);
y = Math.abs(y) * spine.MathUtils.signum(by); y = Math.abs(y) * spine.MathUtils.signum(by);
} }
@ -335,13 +363,18 @@ var spine;
ShearTimeline.prototype.getPropertyId = function () { ShearTimeline.prototype.getPropertyId = function () {
return (TimelineType.shear << 24) + this.boneIndex; return (TimelineType.shear << 24) + this.boneIndex;
}; };
ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.shearX = bone.data.shearX; case MixPose.setup:
bone.shearY = bone.data.shearY; bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY;
return;
case MixPose.current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
} }
return; return;
} }
@ -359,7 +392,7 @@ var spine;
x = x + (frames[frame + ShearTimeline.X] - x) * percent; x = x + (frames[frame + ShearTimeline.X] - x) * percent;
y = y + (frames[frame + ShearTimeline.Y] - y) * percent; y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.shearX = bone.data.shearX + x * alpha; bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; bone.shearY = bone.data.shearY + y * alpha;
} }
@ -388,12 +421,18 @@ var spine;
this.frames[frameIndex + ColorTimeline.B] = b; this.frames[frameIndex + ColorTimeline.B] = b;
this.frames[frameIndex + ColorTimeline.A] = a; this.frames[frameIndex + ColorTimeline.A] = a;
}; };
ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.color.setFromColor(slot.data.color);
return;
case MixPose.current:
var color = slot.color, setup = slot.data.color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
}
return; return;
} }
var r = 0, g = 0, b = 0, a = 0; var r = 0, g = 0, b = 0, a = 0;
@ -421,7 +460,7 @@ var spine;
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
else { else {
var color = slot.color; var color = slot.color;
if (setupPose) if (pose == MixPose.setup)
color.setFromColor(slot.data.color); color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
} }
@ -459,13 +498,19 @@ var spine;
this.frames[frameIndex + TwoColorTimeline.G2] = g2; this.frames[frameIndex + TwoColorTimeline.G2] = g2;
this.frames[frameIndex + TwoColorTimeline.B2] = b2; this.frames[frameIndex + TwoColorTimeline.B2] = b2;
}; };
TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.darkColor.setFromColor(slot.data.darkColor); slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor);
return;
case MixPose.current:
var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
} }
return; return;
} }
@ -504,9 +549,8 @@ var spine;
slot.darkColor.set(r2, g2, b2, 1); slot.darkColor.set(r2, g2, b2, 1);
} }
else { else {
var light = slot.color; var light = slot.color, dark = slot.darkColor;
var dark = slot.darkColor; if (pose == MixPose.setup) {
if (setupPose) {
light.setFromColor(slot.data.color); light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor); dark.setFromColor(slot.data.darkColor);
} }
@ -548,16 +592,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.attachmentNames[frameIndex] = attachmentName; this.attachmentNames[frameIndex] = attachmentName;
}; };
AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
var attachmentName_1 = slot.data.attachmentName; var attachmentName_1 = slot.data.attachmentName;
slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1)); slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
var attachmentName_2 = slot.data.attachmentName; var attachmentName_2 = slot.data.attachmentName;
slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2)); slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
} }
@ -583,35 +627,42 @@ var spine;
this.frameVertices = new Array(frameCount); this.frameVertices = new Array(frameCount);
} }
DeformTimeline.prototype.getPropertyId = function () { DeformTimeline.prototype.getPropertyId = function () {
return (TimelineType.deform << 24) + this.slotIndex; return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
}; };
DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) { DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frameVertices[frameIndex] = vertices; this.frameVertices[frameIndex] = vertices;
}; };
DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var slotAttachment = slot.getAttachment(); var slotAttachment = slot.getAttachment();
if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment)) if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
return; return;
var frames = this.frames;
var verticesArray = slot.attachmentVertices; var verticesArray = slot.attachmentVertices;
if (time < frames[0]) {
if (setupPose)
spine.Utils.setArraySize(verticesArray, 0);
return;
}
var frameVertices = this.frameVertices; var frameVertices = this.frameVertices;
var vertexCount = frameVertices[0].length; var vertexCount = frameVertices[0].length;
if (verticesArray.length != vertexCount && !setupPose) if (verticesArray.length != vertexCount && pose != MixPose.setup)
alpha = 1; alpha = 1;
var vertices = spine.Utils.setArraySize(verticesArray, vertexCount); var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
var frames = this.frames;
if (time < frames[0]) {
switch (pose) {
case MixPose.setup:
verticesArray.length = 0;
return;
case MixPose.current:
alpha = 1 - alpha;
for (var i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
}
return;
}
if (time >= frames[frames.length - 1]) { if (time >= frames[frames.length - 1]) {
var lastVertices = frameVertices[frames.length - 1]; var lastVertices = frameVertices[frames.length - 1];
if (alpha == 1) { if (alpha == 1) {
spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount); spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -642,7 +693,7 @@ var spine;
vertices[i] = prev + (nextVertices[i] - prev) * percent; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -683,13 +734,13 @@ var spine;
this.frames[frameIndex] = event.time; this.frames[frameIndex] = event.time;
this.events[frameIndex] = event; this.events[frameIndex] = event;
}; };
EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
if (firedEvents == null) if (firedEvents == null)
return; return;
var frames = this.frames; var frames = this.frames;
var frameCount = this.frames.length; var frameCount = this.frames.length;
if (lastTime > time) { if (lastTime > time) {
this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut); this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
lastTime = -1; lastTime = -1;
} }
else if (lastTime >= frames[frameCount - 1]) else if (lastTime >= frames[frameCount - 1])
@ -729,16 +780,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.drawOrders[frameIndex] = drawOrder; this.drawOrders[frameIndex] = drawOrder;
}; };
DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var drawOrder = skeleton.drawOrder; var drawOrder = skeleton.drawOrder;
var slots = skeleton.slots; var slots = skeleton.slots;
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == MixPose.setup)
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
@ -773,25 +824,30 @@ var spine;
this.frames[frameIndex + IkConstraintTimeline.MIX] = mix; this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection; this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
}; };
IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.ikConstraints[this.ikConstraintIndex]; var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.mix = constraint.data.mix; case MixPose.setup:
constraint.bendDirection = constraint.data.bendDirection; constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose.current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
} }
return; return;
} }
if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha; constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
return; return;
@ -800,13 +856,13 @@ var spine;
var mix = frames[frame + IkConstraintTimeline.PREV_MIX]; var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
var frameTime = frames[frame]; var frameTime = frames[frame];
var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha; 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]; constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha; constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
}; };
@ -836,16 +892,23 @@ var spine;
this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix; this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix; this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
}; };
TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.transformConstraints[this.transformConstraintIndex]; var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { var data = constraint.data;
var data = constraint.data; switch (pose) {
constraint.rotateMix = data.rotateMix; case MixPose.setup:
constraint.translateMix = data.rotateMix; constraint.rotateMix = data.rotateMix;
constraint.scaleMix = data.scaleMix; constraint.translateMix = data.translateMix;
constraint.shearMix = data.shearMix; constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix;
return;
case MixPose.current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
} }
return; return;
} }
@ -870,7 +933,7 @@ var spine;
scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent; scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent; shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
var data = constraint.data; var data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
@ -911,12 +974,17 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value; this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
}; };
PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.position = constraint.data.position; case MixPose.setup:
constraint.position = constraint.data.position;
return;
case MixPose.current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
}
return; return;
} }
var position = 0; var position = 0;
@ -929,7 +997,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent; position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else else
constraint.position += (position - constraint.position) * alpha; constraint.position += (position - constraint.position) * alpha;
@ -949,12 +1017,17 @@ var spine;
PathConstraintSpacingTimeline.prototype.getPropertyId = function () { PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex; return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
}; };
PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.spacing = constraint.data.spacing; case MixPose.setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose.current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
}
return; return;
} }
var spacing = 0; var spacing = 0;
@ -967,7 +1040,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent; spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else else
constraint.spacing += (spacing - constraint.spacing) * alpha; constraint.spacing += (spacing - constraint.spacing) * alpha;
@ -990,13 +1063,18 @@ var spine;
this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix; this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix; this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
}; };
PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.rotateMix = constraint.data.rotateMix; case MixPose.setup:
constraint.translateMix = constraint.data.translateMix; constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix;
return;
case MixPose.current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
} }
return; return;
} }
@ -1014,7 +1092,7 @@ var spine;
rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent; rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent; translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} }
@ -1130,9 +1208,10 @@ var spine;
if (current == null || current.delay > 0) if (current == null || current.delay > 0)
continue; continue;
applied = true; applied = true;
var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
var mix = current.alpha; var mix = current.alpha;
if (current.mixingFrom != null) if (current.mixingFrom != null)
mix *= this.applyMixingFrom(current, skeleton); mix *= this.applyMixingFrom(current, skeleton, currentPose);
else if (current.trackTime >= current.trackEnd && current.next == null) else if (current.trackTime >= current.trackEnd && current.next == null)
mix = 0; mix = 0;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
@ -1140,7 +1219,7 @@ var spine;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1) { if (mix == 1) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, true, false); timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection.in);
} }
else { else {
var timelineData = current.timelineData; var timelineData = current.timelineData;
@ -1150,11 +1229,12 @@ var spine;
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineData[ii] >= AnimationState.FIRST, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
} }
else else
timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= AnimationState.FIRST, false); timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection.in);
} }
} }
this.queueEvents(current, animationTime); this.queueEvents(current, animationTime);
@ -1165,10 +1245,10 @@ var spine;
this.queue.drain(); this.queue.drain();
return applied; return applied;
}; };
AnimationState.prototype.applyMixingFrom = function (to, skeleton) { AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
var from = to.mixingFrom; var from = to.mixingFrom;
if (from.mixingFrom != null) if (from.mixingFrom != null)
this.applyMixingFrom(from, skeleton); this.applyMixingFrom(from, skeleton, currentPose);
var mix = 0; var mix = 0;
if (to.mixDuration == 0) if (to.mixDuration == 0)
mix = 1; mix = 1;
@ -1188,26 +1268,30 @@ var spine;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = from.timelinesRotation; var timelinesRotation = from.timelinesRotation;
var first = false; var pose;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0; var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
from.totalAlpha = 0; from.totalAlpha = 0;
for (var i = 0; i < timelineCount; i++) { for (var i = 0; i < timelineCount; i++) {
var timeline = timelines[i]; var timeline = timelines[i];
switch (timelineData[i]) { switch (timelineData[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
first = false; if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
pose = currentPose;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.FIRST: case AnimationState.FIRST:
first = true; pose = spine.MixPose.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.DIP:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
break; break;
default: default:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
var dipMix = timelineDipMix[i]; var dipMix = timelineDipMix[i];
alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
@ -1215,15 +1299,9 @@ var spine;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
if (timeline instanceof spine.RotateTimeline) if (timeline instanceof spine.RotateTimeline)
this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
else { else {
if (!first) { timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
}
timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true);
} }
} }
if (to.mixDuration > 0) if (to.mixDuration > 0)
@ -1233,18 +1311,18 @@ var spine;
from.nextTrackLast = from.trackTime; from.nextTrackLast = from.trackTime;
return mix; return mix;
}; };
AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, setupPose, timelinesRotation, i, firstFrame) { AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
if (firstFrame) if (firstFrame)
timelinesRotation[i] = 0; timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection.in);
return; return;
} }
var rotateTimeline = timeline; var rotateTimeline = timeline;
var frames = rotateTimeline.frames; var frames = rotateTimeline.frames;
var bone = skeleton.bones[rotateTimeline.boneIndex]; var bone = skeleton.bones[rotateTimeline.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == spine.MixPose.setup)
bone.rotation = bone.data.rotation; bone.rotation = bone.data.rotation;
return; return;
} }
@ -1261,7 +1339,7 @@ var spine;
r2 = prevRotation + r2 * percent + bone.data.rotation; r2 = prevRotation + r2 * percent + bone.data.rotation;
r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360; r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
} }
var r1 = setupPose ? bone.data.rotation : bone.rotation; var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
var total = 0, diff = r2 - r1; var total = 0, diff = r2 - r1;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];
@ -1950,6 +2028,7 @@ var spine;
__extends(VertexAttachment, _super); __extends(VertexAttachment, _super);
function VertexAttachment(name) { function VertexAttachment(name) {
_super.call(this, name); _super.call(this, name);
this.id = (VertexAttachment.nextID++ & 65535) << 11;
this.worldVerticesLength = 0; this.worldVerticesLength = 0;
} }
VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) { VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
@ -2014,6 +2093,7 @@ var spine;
VertexAttachment.prototype.applyDeform = function (sourceAttachment) { VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
}; };
VertexAttachment.nextID = 0;
return VertexAttachment; return VertexAttachment;
}(Attachment)); }(Attachment));
spine.VertexAttachment = VertexAttachment; spine.VertexAttachment = VertexAttachment;

File diff suppressed because one or more lines are too long

View File

@ -4,14 +4,23 @@ declare module spine {
timelines: Array<Timeline>; timelines: Array<Timeline>;
duration: number; duration: number;
constructor(name: string, timelines: Array<Timeline>, duration: number); constructor(name: string, timelines: Array<Timeline>, duration: number);
apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
static binarySearch(values: ArrayLike<number>, target: number, step?: number): number; static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
static linearSearch(values: ArrayLike<number>, target: number, step: number): number; static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
} }
interface Timeline { interface Timeline {
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
getPropertyId(): number; getPropertyId(): number;
} }
enum MixPose {
setup = 0,
current = 1,
currentLayered = 2,
}
enum MixDirection {
in = 0,
out = 1,
}
enum TimelineType { enum TimelineType {
rotate = 0, rotate = 0,
translate = 1, translate = 1,
@ -43,7 +52,7 @@ declare module spine {
getCurveType(frameIndex: number): number; getCurveType(frameIndex: number): number;
setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void; setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void;
getCurvePercent(frameIndex: number, percent: number): number; getCurvePercent(frameIndex: number, percent: number): number;
abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class RotateTimeline extends CurveTimeline { class RotateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -55,7 +64,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, degrees: number): void; setFrame(frameIndex: number, time: number, degrees: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TranslateTimeline extends CurveTimeline { class TranslateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -69,17 +78,17 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, x: number, y: number): void; setFrame(frameIndex: number, time: number, x: number, y: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ScaleTimeline extends TranslateTimeline { class ScaleTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ShearTimeline extends TranslateTimeline { class ShearTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ColorTimeline extends CurveTimeline { class ColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -97,7 +106,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TwoColorTimeline extends CurveTimeline { class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -121,7 +130,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
@ -131,7 +140,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, attachmentName: string): void; setFrame(frameIndex: number, time: number, attachmentName: string): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DeformTimeline extends CurveTimeline { class DeformTimeline extends CurveTimeline {
slotIndex: number; slotIndex: number;
@ -141,7 +150,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void; setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class EventTimeline implements Timeline { class EventTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -150,7 +159,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, event: Event): void; setFrame(frameIndex: number, event: Event): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DrawOrderTimeline implements Timeline { class DrawOrderTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -159,7 +168,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void; setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class IkConstraintTimeline extends CurveTimeline { class IkConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -173,7 +182,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void; setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TransformConstraintTimeline extends CurveTimeline { class TransformConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -191,7 +200,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintPositionTimeline extends CurveTimeline { class PathConstraintPositionTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -203,12 +212,12 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, value: number): void; setFrame(frameIndex: number, time: number, value: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline { class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintMixTimeline extends CurveTimeline { class PathConstraintMixTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -222,7 +231,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
} }
declare module spine { declare module spine {
@ -246,8 +255,8 @@ declare module spine {
update(delta: number): void; update(delta: number): void;
updateMixingFrom(to: TrackEntry, delta: number): boolean; updateMixingFrom(to: TrackEntry, delta: number): boolean;
apply(skeleton: Skeleton): boolean; apply(skeleton: Skeleton): boolean;
applyMixingFrom(to: TrackEntry, skeleton: Skeleton): number; applyMixingFrom(to: TrackEntry, skeleton: Skeleton, currentPose: MixPose): number;
applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, setupPose: boolean, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void; applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, pose: MixPose, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void;
queueEvents(entry: TrackEntry, animationTime: number): void; queueEvents(entry: TrackEntry, animationTime: number): void;
clearTracks(): void; clearTracks(): void;
clearTrack(trackIndex: number): void; clearTrack(trackIndex: number): void;
@ -396,6 +405,8 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
abstract class VertexAttachment extends Attachment { abstract class VertexAttachment extends Attachment {
private static nextID;
id: number;
bones: Array<number>; bones: Array<number>;
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;

View File

@ -15,7 +15,7 @@ var spine;
this.timelines = timelines; this.timelines = timelines;
this.duration = duration; this.duration = duration;
} }
Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, setupPose, mixingOut) { Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
if (skeleton == null) if (skeleton == null)
throw new Error("skeleton cannot be null."); throw new Error("skeleton cannot be null.");
if (loop && this.duration != 0) { if (loop && this.duration != 0) {
@ -25,7 +25,7 @@ var spine;
} }
var timelines = this.timelines; var timelines = this.timelines;
for (var i = 0, n = timelines.length; i < n; i++) for (var i = 0, n = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut); timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
}; };
Animation.binarySearch = function (values, target, step) { Animation.binarySearch = function (values, target, step) {
if (step === void 0) { step = 1; } if (step === void 0) { step = 1; }
@ -53,6 +53,17 @@ var spine;
return Animation; return Animation;
}()); }());
spine.Animation = Animation; spine.Animation = Animation;
(function (MixPose) {
MixPose[MixPose["setup"] = 0] = "setup";
MixPose[MixPose["current"] = 1] = "current";
MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
})(spine.MixPose || (spine.MixPose = {}));
var MixPose = spine.MixPose;
(function (MixDirection) {
MixDirection[MixDirection["in"] = 0] = "in";
MixDirection[MixDirection["out"] = 1] = "out";
})(spine.MixDirection || (spine.MixDirection = {}));
var MixDirection = spine.MixDirection;
(function (TimelineType) { (function (TimelineType) {
TimelineType[TimelineType["rotate"] = 0] = "rotate"; TimelineType[TimelineType["rotate"] = 0] = "rotate";
TimelineType[TimelineType["translate"] = 1] = "translate"; TimelineType[TimelineType["translate"] = 1] = "translate";
@ -167,21 +178,28 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + RotateTimeline.ROTATION] = degrees; this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
}; };
RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
bone.rotation = bone.data.rotation; case MixPose.setup:
bone.rotation = bone.data.rotation;
return;
case MixPose.current:
var r_1 = bone.data.rotation - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha;
}
return; return;
} }
if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
if (setupPose) if (pose == MixPose.setup)
bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha; bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
else { else {
var r_1 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation; var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360; r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha; bone.rotation += r_2 * alpha;
} }
return; return;
} }
@ -192,7 +210,7 @@ var spine;
var r = frames[frame + RotateTimeline.ROTATION] - prevRotation; var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
r = prevRotation + r * percent; r = prevRotation + r * percent;
if (setupPose) { if (pose == MixPose.setup) {
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.rotation = bone.data.rotation + r * alpha; bone.rotation = bone.data.rotation + r * alpha;
} }
@ -224,13 +242,18 @@ var spine;
this.frames[frameIndex + TranslateTimeline.X] = x; this.frames[frameIndex + TranslateTimeline.X] = x;
this.frames[frameIndex + TranslateTimeline.Y] = y; this.frames[frameIndex + TranslateTimeline.Y] = y;
}; };
TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.x = bone.data.x; case MixPose.setup:
bone.y = bone.data.y; bone.x = bone.data.x;
bone.y = bone.data.y;
return;
case MixPose.current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
} }
return; return;
} }
@ -248,7 +271,7 @@ var spine;
x += (frames[frame + TranslateTimeline.X] - x) * percent; x += (frames[frame + TranslateTimeline.X] - x) * percent;
y += (frames[frame + TranslateTimeline.Y] - y) * percent; y += (frames[frame + TranslateTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.x = bone.data.x + x * alpha; bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; bone.y = bone.data.y + y * alpha;
} }
@ -274,13 +297,18 @@ var spine;
ScaleTimeline.prototype.getPropertyId = function () { ScaleTimeline.prototype.getPropertyId = function () {
return (TimelineType.scale << 24) + this.boneIndex; return (TimelineType.scale << 24) + this.boneIndex;
}; };
ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.scaleX = bone.data.scaleX; case MixPose.setup:
bone.scaleY = bone.data.scaleY; bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY;
return;
case MixPose.current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
} }
return; return;
} }
@ -304,7 +332,7 @@ var spine;
} }
else { else {
var bx = 0, by = 0; var bx = 0, by = 0;
if (setupPose) { if (pose == MixPose.setup) {
bx = bone.data.scaleX; bx = bone.data.scaleX;
by = bone.data.scaleY; by = bone.data.scaleY;
} }
@ -312,7 +340,7 @@ var spine;
bx = bone.scaleX; bx = bone.scaleX;
by = bone.scaleY; by = bone.scaleY;
} }
if (mixingOut) { if (direction == MixDirection.out) {
x = Math.abs(x) * spine.MathUtils.signum(bx); x = Math.abs(x) * spine.MathUtils.signum(bx);
y = Math.abs(y) * spine.MathUtils.signum(by); y = Math.abs(y) * spine.MathUtils.signum(by);
} }
@ -335,13 +363,18 @@ var spine;
ShearTimeline.prototype.getPropertyId = function () { ShearTimeline.prototype.getPropertyId = function () {
return (TimelineType.shear << 24) + this.boneIndex; return (TimelineType.shear << 24) + this.boneIndex;
}; };
ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.shearX = bone.data.shearX; case MixPose.setup:
bone.shearY = bone.data.shearY; bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY;
return;
case MixPose.current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
} }
return; return;
} }
@ -359,7 +392,7 @@ var spine;
x = x + (frames[frame + ShearTimeline.X] - x) * percent; x = x + (frames[frame + ShearTimeline.X] - x) * percent;
y = y + (frames[frame + ShearTimeline.Y] - y) * percent; y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.shearX = bone.data.shearX + x * alpha; bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; bone.shearY = bone.data.shearY + y * alpha;
} }
@ -388,12 +421,18 @@ var spine;
this.frames[frameIndex + ColorTimeline.B] = b; this.frames[frameIndex + ColorTimeline.B] = b;
this.frames[frameIndex + ColorTimeline.A] = a; this.frames[frameIndex + ColorTimeline.A] = a;
}; };
ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.color.setFromColor(slot.data.color);
return;
case MixPose.current:
var color = slot.color, setup = slot.data.color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
}
return; return;
} }
var r = 0, g = 0, b = 0, a = 0; var r = 0, g = 0, b = 0, a = 0;
@ -421,7 +460,7 @@ var spine;
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
else { else {
var color = slot.color; var color = slot.color;
if (setupPose) if (pose == MixPose.setup)
color.setFromColor(slot.data.color); color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
} }
@ -459,13 +498,19 @@ var spine;
this.frames[frameIndex + TwoColorTimeline.G2] = g2; this.frames[frameIndex + TwoColorTimeline.G2] = g2;
this.frames[frameIndex + TwoColorTimeline.B2] = b2; this.frames[frameIndex + TwoColorTimeline.B2] = b2;
}; };
TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.darkColor.setFromColor(slot.data.darkColor); slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor);
return;
case MixPose.current:
var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
} }
return; return;
} }
@ -504,9 +549,8 @@ var spine;
slot.darkColor.set(r2, g2, b2, 1); slot.darkColor.set(r2, g2, b2, 1);
} }
else { else {
var light = slot.color; var light = slot.color, dark = slot.darkColor;
var dark = slot.darkColor; if (pose == MixPose.setup) {
if (setupPose) {
light.setFromColor(slot.data.color); light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor); dark.setFromColor(slot.data.darkColor);
} }
@ -548,16 +592,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.attachmentNames[frameIndex] = attachmentName; this.attachmentNames[frameIndex] = attachmentName;
}; };
AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
var attachmentName_1 = slot.data.attachmentName; var attachmentName_1 = slot.data.attachmentName;
slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1)); slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
var attachmentName_2 = slot.data.attachmentName; var attachmentName_2 = slot.data.attachmentName;
slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2)); slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
} }
@ -583,35 +627,42 @@ var spine;
this.frameVertices = new Array(frameCount); this.frameVertices = new Array(frameCount);
} }
DeformTimeline.prototype.getPropertyId = function () { DeformTimeline.prototype.getPropertyId = function () {
return (TimelineType.deform << 24) + this.slotIndex; return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
}; };
DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) { DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frameVertices[frameIndex] = vertices; this.frameVertices[frameIndex] = vertices;
}; };
DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var slotAttachment = slot.getAttachment(); var slotAttachment = slot.getAttachment();
if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment)) if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
return; return;
var frames = this.frames;
var verticesArray = slot.attachmentVertices; var verticesArray = slot.attachmentVertices;
if (time < frames[0]) {
if (setupPose)
spine.Utils.setArraySize(verticesArray, 0);
return;
}
var frameVertices = this.frameVertices; var frameVertices = this.frameVertices;
var vertexCount = frameVertices[0].length; var vertexCount = frameVertices[0].length;
if (verticesArray.length != vertexCount && !setupPose) if (verticesArray.length != vertexCount && pose != MixPose.setup)
alpha = 1; alpha = 1;
var vertices = spine.Utils.setArraySize(verticesArray, vertexCount); var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
var frames = this.frames;
if (time < frames[0]) {
switch (pose) {
case MixPose.setup:
verticesArray.length = 0;
return;
case MixPose.current:
alpha = 1 - alpha;
for (var i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
}
return;
}
if (time >= frames[frames.length - 1]) { if (time >= frames[frames.length - 1]) {
var lastVertices = frameVertices[frames.length - 1]; var lastVertices = frameVertices[frames.length - 1];
if (alpha == 1) { if (alpha == 1) {
spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount); spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -642,7 +693,7 @@ var spine;
vertices[i] = prev + (nextVertices[i] - prev) * percent; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -683,13 +734,13 @@ var spine;
this.frames[frameIndex] = event.time; this.frames[frameIndex] = event.time;
this.events[frameIndex] = event; this.events[frameIndex] = event;
}; };
EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
if (firedEvents == null) if (firedEvents == null)
return; return;
var frames = this.frames; var frames = this.frames;
var frameCount = this.frames.length; var frameCount = this.frames.length;
if (lastTime > time) { if (lastTime > time) {
this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut); this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
lastTime = -1; lastTime = -1;
} }
else if (lastTime >= frames[frameCount - 1]) else if (lastTime >= frames[frameCount - 1])
@ -729,16 +780,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.drawOrders[frameIndex] = drawOrder; this.drawOrders[frameIndex] = drawOrder;
}; };
DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var drawOrder = skeleton.drawOrder; var drawOrder = skeleton.drawOrder;
var slots = skeleton.slots; var slots = skeleton.slots;
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == MixPose.setup)
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
@ -773,25 +824,30 @@ var spine;
this.frames[frameIndex + IkConstraintTimeline.MIX] = mix; this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection; this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
}; };
IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.ikConstraints[this.ikConstraintIndex]; var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.mix = constraint.data.mix; case MixPose.setup:
constraint.bendDirection = constraint.data.bendDirection; constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose.current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
} }
return; return;
} }
if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha; constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
return; return;
@ -800,13 +856,13 @@ var spine;
var mix = frames[frame + IkConstraintTimeline.PREV_MIX]; var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
var frameTime = frames[frame]; var frameTime = frames[frame];
var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha; 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]; constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha; constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
}; };
@ -836,16 +892,23 @@ var spine;
this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix; this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix; this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
}; };
TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.transformConstraints[this.transformConstraintIndex]; var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { var data = constraint.data;
var data = constraint.data; switch (pose) {
constraint.rotateMix = data.rotateMix; case MixPose.setup:
constraint.translateMix = data.rotateMix; constraint.rotateMix = data.rotateMix;
constraint.scaleMix = data.scaleMix; constraint.translateMix = data.translateMix;
constraint.shearMix = data.shearMix; constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix;
return;
case MixPose.current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
} }
return; return;
} }
@ -870,7 +933,7 @@ var spine;
scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent; scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent; shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
var data = constraint.data; var data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
@ -911,12 +974,17 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value; this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
}; };
PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.position = constraint.data.position; case MixPose.setup:
constraint.position = constraint.data.position;
return;
case MixPose.current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
}
return; return;
} }
var position = 0; var position = 0;
@ -929,7 +997,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent; position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else else
constraint.position += (position - constraint.position) * alpha; constraint.position += (position - constraint.position) * alpha;
@ -949,12 +1017,17 @@ var spine;
PathConstraintSpacingTimeline.prototype.getPropertyId = function () { PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex; return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
}; };
PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.spacing = constraint.data.spacing; case MixPose.setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose.current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
}
return; return;
} }
var spacing = 0; var spacing = 0;
@ -967,7 +1040,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent; spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else else
constraint.spacing += (spacing - constraint.spacing) * alpha; constraint.spacing += (spacing - constraint.spacing) * alpha;
@ -990,13 +1063,18 @@ var spine;
this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix; this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix; this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
}; };
PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.rotateMix = constraint.data.rotateMix; case MixPose.setup:
constraint.translateMix = constraint.data.translateMix; constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix;
return;
case MixPose.current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
} }
return; return;
} }
@ -1014,7 +1092,7 @@ var spine;
rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent; rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent; translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} }
@ -1130,9 +1208,10 @@ var spine;
if (current == null || current.delay > 0) if (current == null || current.delay > 0)
continue; continue;
applied = true; applied = true;
var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
var mix = current.alpha; var mix = current.alpha;
if (current.mixingFrom != null) if (current.mixingFrom != null)
mix *= this.applyMixingFrom(current, skeleton); mix *= this.applyMixingFrom(current, skeleton, currentPose);
else if (current.trackTime >= current.trackEnd && current.next == null) else if (current.trackTime >= current.trackEnd && current.next == null)
mix = 0; mix = 0;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
@ -1140,7 +1219,7 @@ var spine;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1) { if (mix == 1) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, true, false); timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection.in);
} }
else { else {
var timelineData = current.timelineData; var timelineData = current.timelineData;
@ -1150,11 +1229,12 @@ var spine;
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineData[ii] >= AnimationState.FIRST, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
} }
else else
timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= AnimationState.FIRST, false); timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection.in);
} }
} }
this.queueEvents(current, animationTime); this.queueEvents(current, animationTime);
@ -1165,10 +1245,10 @@ var spine;
this.queue.drain(); this.queue.drain();
return applied; return applied;
}; };
AnimationState.prototype.applyMixingFrom = function (to, skeleton) { AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
var from = to.mixingFrom; var from = to.mixingFrom;
if (from.mixingFrom != null) if (from.mixingFrom != null)
this.applyMixingFrom(from, skeleton); this.applyMixingFrom(from, skeleton, currentPose);
var mix = 0; var mix = 0;
if (to.mixDuration == 0) if (to.mixDuration == 0)
mix = 1; mix = 1;
@ -1188,26 +1268,30 @@ var spine;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = from.timelinesRotation; var timelinesRotation = from.timelinesRotation;
var first = false; var pose;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0; var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
from.totalAlpha = 0; from.totalAlpha = 0;
for (var i = 0; i < timelineCount; i++) { for (var i = 0; i < timelineCount; i++) {
var timeline = timelines[i]; var timeline = timelines[i];
switch (timelineData[i]) { switch (timelineData[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
first = false; if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
pose = currentPose;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.FIRST: case AnimationState.FIRST:
first = true; pose = spine.MixPose.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.DIP:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
break; break;
default: default:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
var dipMix = timelineDipMix[i]; var dipMix = timelineDipMix[i];
alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
@ -1215,15 +1299,9 @@ var spine;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
if (timeline instanceof spine.RotateTimeline) if (timeline instanceof spine.RotateTimeline)
this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
else { else {
if (!first) { timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
}
timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true);
} }
} }
if (to.mixDuration > 0) if (to.mixDuration > 0)
@ -1233,18 +1311,18 @@ var spine;
from.nextTrackLast = from.trackTime; from.nextTrackLast = from.trackTime;
return mix; return mix;
}; };
AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, setupPose, timelinesRotation, i, firstFrame) { AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
if (firstFrame) if (firstFrame)
timelinesRotation[i] = 0; timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection.in);
return; return;
} }
var rotateTimeline = timeline; var rotateTimeline = timeline;
var frames = rotateTimeline.frames; var frames = rotateTimeline.frames;
var bone = skeleton.bones[rotateTimeline.boneIndex]; var bone = skeleton.bones[rotateTimeline.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == spine.MixPose.setup)
bone.rotation = bone.data.rotation; bone.rotation = bone.data.rotation;
return; return;
} }
@ -1261,7 +1339,7 @@ var spine;
r2 = prevRotation + r2 * percent + bone.data.rotation; r2 = prevRotation + r2 * percent + bone.data.rotation;
r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360; r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
} }
var r1 = setupPose ? bone.data.rotation : bone.rotation; var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
var total = 0, diff = r2 - r1; var total = 0, diff = r2 - r1;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];
@ -1950,6 +2028,7 @@ var spine;
__extends(VertexAttachment, _super); __extends(VertexAttachment, _super);
function VertexAttachment(name) { function VertexAttachment(name) {
_super.call(this, name); _super.call(this, name);
this.id = (VertexAttachment.nextID++ & 65535) << 11;
this.worldVerticesLength = 0; this.worldVerticesLength = 0;
} }
VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) { VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
@ -2014,6 +2093,7 @@ var spine;
VertexAttachment.prototype.applyDeform = function (sourceAttachment) { VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
}; };
VertexAttachment.nextID = 0;
return VertexAttachment; return VertexAttachment;
}(Attachment)); }(Attachment));
spine.VertexAttachment = VertexAttachment; spine.VertexAttachment = VertexAttachment;

File diff suppressed because one or more lines are too long

View File

@ -4,14 +4,23 @@ declare module spine {
timelines: Array<Timeline>; timelines: Array<Timeline>;
duration: number; duration: number;
constructor(name: string, timelines: Array<Timeline>, duration: number); constructor(name: string, timelines: Array<Timeline>, duration: number);
apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
static binarySearch(values: ArrayLike<number>, target: number, step?: number): number; static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
static linearSearch(values: ArrayLike<number>, target: number, step: number): number; static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
} }
interface Timeline { interface Timeline {
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
getPropertyId(): number; getPropertyId(): number;
} }
enum MixPose {
setup = 0,
current = 1,
currentLayered = 2,
}
enum MixDirection {
in = 0,
out = 1,
}
enum TimelineType { enum TimelineType {
rotate = 0, rotate = 0,
translate = 1, translate = 1,
@ -43,7 +52,7 @@ declare module spine {
getCurveType(frameIndex: number): number; getCurveType(frameIndex: number): number;
setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void; setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void;
getCurvePercent(frameIndex: number, percent: number): number; getCurvePercent(frameIndex: number, percent: number): number;
abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class RotateTimeline extends CurveTimeline { class RotateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -55,7 +64,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, degrees: number): void; setFrame(frameIndex: number, time: number, degrees: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TranslateTimeline extends CurveTimeline { class TranslateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -69,17 +78,17 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, x: number, y: number): void; setFrame(frameIndex: number, time: number, x: number, y: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ScaleTimeline extends TranslateTimeline { class ScaleTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ShearTimeline extends TranslateTimeline { class ShearTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ColorTimeline extends CurveTimeline { class ColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -97,7 +106,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TwoColorTimeline extends CurveTimeline { class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -121,7 +130,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
@ -131,7 +140,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, attachmentName: string): void; setFrame(frameIndex: number, time: number, attachmentName: string): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DeformTimeline extends CurveTimeline { class DeformTimeline extends CurveTimeline {
slotIndex: number; slotIndex: number;
@ -141,7 +150,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void; setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class EventTimeline implements Timeline { class EventTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -150,7 +159,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, event: Event): void; setFrame(frameIndex: number, event: Event): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DrawOrderTimeline implements Timeline { class DrawOrderTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -159,7 +168,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void; setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class IkConstraintTimeline extends CurveTimeline { class IkConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -173,7 +182,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void; setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TransformConstraintTimeline extends CurveTimeline { class TransformConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -191,7 +200,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintPositionTimeline extends CurveTimeline { class PathConstraintPositionTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -203,12 +212,12 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, value: number): void; setFrame(frameIndex: number, time: number, value: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline { class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintMixTimeline extends CurveTimeline { class PathConstraintMixTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -222,7 +231,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
} }
declare module spine { declare module spine {
@ -246,8 +255,8 @@ declare module spine {
update(delta: number): void; update(delta: number): void;
updateMixingFrom(to: TrackEntry, delta: number): boolean; updateMixingFrom(to: TrackEntry, delta: number): boolean;
apply(skeleton: Skeleton): boolean; apply(skeleton: Skeleton): boolean;
applyMixingFrom(to: TrackEntry, skeleton: Skeleton): number; applyMixingFrom(to: TrackEntry, skeleton: Skeleton, currentPose: MixPose): number;
applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, setupPose: boolean, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void; applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, pose: MixPose, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void;
queueEvents(entry: TrackEntry, animationTime: number): void; queueEvents(entry: TrackEntry, animationTime: number): void;
clearTracks(): void; clearTracks(): void;
clearTrack(trackIndex: number): void; clearTrack(trackIndex: number): void;
@ -396,6 +405,8 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
abstract class VertexAttachment extends Attachment { abstract class VertexAttachment extends Attachment {
private static nextID;
id: number;
bones: Array<number>; bones: Array<number>;
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;

View File

@ -15,7 +15,7 @@ var spine;
this.timelines = timelines; this.timelines = timelines;
this.duration = duration; this.duration = duration;
} }
Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, setupPose, mixingOut) { Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
if (skeleton == null) if (skeleton == null)
throw new Error("skeleton cannot be null."); throw new Error("skeleton cannot be null.");
if (loop && this.duration != 0) { if (loop && this.duration != 0) {
@ -25,7 +25,7 @@ var spine;
} }
var timelines = this.timelines; var timelines = this.timelines;
for (var i = 0, n = timelines.length; i < n; i++) for (var i = 0, n = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut); timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
}; };
Animation.binarySearch = function (values, target, step) { Animation.binarySearch = function (values, target, step) {
if (step === void 0) { step = 1; } if (step === void 0) { step = 1; }
@ -53,6 +53,17 @@ var spine;
return Animation; return Animation;
}()); }());
spine.Animation = Animation; spine.Animation = Animation;
(function (MixPose) {
MixPose[MixPose["setup"] = 0] = "setup";
MixPose[MixPose["current"] = 1] = "current";
MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
})(spine.MixPose || (spine.MixPose = {}));
var MixPose = spine.MixPose;
(function (MixDirection) {
MixDirection[MixDirection["in"] = 0] = "in";
MixDirection[MixDirection["out"] = 1] = "out";
})(spine.MixDirection || (spine.MixDirection = {}));
var MixDirection = spine.MixDirection;
(function (TimelineType) { (function (TimelineType) {
TimelineType[TimelineType["rotate"] = 0] = "rotate"; TimelineType[TimelineType["rotate"] = 0] = "rotate";
TimelineType[TimelineType["translate"] = 1] = "translate"; TimelineType[TimelineType["translate"] = 1] = "translate";
@ -167,21 +178,28 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + RotateTimeline.ROTATION] = degrees; this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
}; };
RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
bone.rotation = bone.data.rotation; case MixPose.setup:
bone.rotation = bone.data.rotation;
return;
case MixPose.current:
var r_1 = bone.data.rotation - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha;
}
return; return;
} }
if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
if (setupPose) if (pose == MixPose.setup)
bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha; bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
else { else {
var r_1 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation; var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360; r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha; bone.rotation += r_2 * alpha;
} }
return; return;
} }
@ -192,7 +210,7 @@ var spine;
var r = frames[frame + RotateTimeline.ROTATION] - prevRotation; var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
r = prevRotation + r * percent; r = prevRotation + r * percent;
if (setupPose) { if (pose == MixPose.setup) {
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.rotation = bone.data.rotation + r * alpha; bone.rotation = bone.data.rotation + r * alpha;
} }
@ -224,13 +242,18 @@ var spine;
this.frames[frameIndex + TranslateTimeline.X] = x; this.frames[frameIndex + TranslateTimeline.X] = x;
this.frames[frameIndex + TranslateTimeline.Y] = y; this.frames[frameIndex + TranslateTimeline.Y] = y;
}; };
TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.x = bone.data.x; case MixPose.setup:
bone.y = bone.data.y; bone.x = bone.data.x;
bone.y = bone.data.y;
return;
case MixPose.current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
} }
return; return;
} }
@ -248,7 +271,7 @@ var spine;
x += (frames[frame + TranslateTimeline.X] - x) * percent; x += (frames[frame + TranslateTimeline.X] - x) * percent;
y += (frames[frame + TranslateTimeline.Y] - y) * percent; y += (frames[frame + TranslateTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.x = bone.data.x + x * alpha; bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; bone.y = bone.data.y + y * alpha;
} }
@ -274,13 +297,18 @@ var spine;
ScaleTimeline.prototype.getPropertyId = function () { ScaleTimeline.prototype.getPropertyId = function () {
return (TimelineType.scale << 24) + this.boneIndex; return (TimelineType.scale << 24) + this.boneIndex;
}; };
ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.scaleX = bone.data.scaleX; case MixPose.setup:
bone.scaleY = bone.data.scaleY; bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY;
return;
case MixPose.current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
} }
return; return;
} }
@ -304,7 +332,7 @@ var spine;
} }
else { else {
var bx = 0, by = 0; var bx = 0, by = 0;
if (setupPose) { if (pose == MixPose.setup) {
bx = bone.data.scaleX; bx = bone.data.scaleX;
by = bone.data.scaleY; by = bone.data.scaleY;
} }
@ -312,7 +340,7 @@ var spine;
bx = bone.scaleX; bx = bone.scaleX;
by = bone.scaleY; by = bone.scaleY;
} }
if (mixingOut) { if (direction == MixDirection.out) {
x = Math.abs(x) * spine.MathUtils.signum(bx); x = Math.abs(x) * spine.MathUtils.signum(bx);
y = Math.abs(y) * spine.MathUtils.signum(by); y = Math.abs(y) * spine.MathUtils.signum(by);
} }
@ -335,13 +363,18 @@ var spine;
ShearTimeline.prototype.getPropertyId = function () { ShearTimeline.prototype.getPropertyId = function () {
return (TimelineType.shear << 24) + this.boneIndex; return (TimelineType.shear << 24) + this.boneIndex;
}; };
ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.shearX = bone.data.shearX; case MixPose.setup:
bone.shearY = bone.data.shearY; bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY;
return;
case MixPose.current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
} }
return; return;
} }
@ -359,7 +392,7 @@ var spine;
x = x + (frames[frame + ShearTimeline.X] - x) * percent; x = x + (frames[frame + ShearTimeline.X] - x) * percent;
y = y + (frames[frame + ShearTimeline.Y] - y) * percent; y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.shearX = bone.data.shearX + x * alpha; bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; bone.shearY = bone.data.shearY + y * alpha;
} }
@ -388,12 +421,18 @@ var spine;
this.frames[frameIndex + ColorTimeline.B] = b; this.frames[frameIndex + ColorTimeline.B] = b;
this.frames[frameIndex + ColorTimeline.A] = a; this.frames[frameIndex + ColorTimeline.A] = a;
}; };
ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.color.setFromColor(slot.data.color);
return;
case MixPose.current:
var color = slot.color, setup = slot.data.color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
}
return; return;
} }
var r = 0, g = 0, b = 0, a = 0; var r = 0, g = 0, b = 0, a = 0;
@ -421,7 +460,7 @@ var spine;
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
else { else {
var color = slot.color; var color = slot.color;
if (setupPose) if (pose == MixPose.setup)
color.setFromColor(slot.data.color); color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
} }
@ -459,13 +498,19 @@ var spine;
this.frames[frameIndex + TwoColorTimeline.G2] = g2; this.frames[frameIndex + TwoColorTimeline.G2] = g2;
this.frames[frameIndex + TwoColorTimeline.B2] = b2; this.frames[frameIndex + TwoColorTimeline.B2] = b2;
}; };
TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.darkColor.setFromColor(slot.data.darkColor); slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor);
return;
case MixPose.current:
var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
} }
return; return;
} }
@ -504,9 +549,8 @@ var spine;
slot.darkColor.set(r2, g2, b2, 1); slot.darkColor.set(r2, g2, b2, 1);
} }
else { else {
var light = slot.color; var light = slot.color, dark = slot.darkColor;
var dark = slot.darkColor; if (pose == MixPose.setup) {
if (setupPose) {
light.setFromColor(slot.data.color); light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor); dark.setFromColor(slot.data.darkColor);
} }
@ -548,16 +592,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.attachmentNames[frameIndex] = attachmentName; this.attachmentNames[frameIndex] = attachmentName;
}; };
AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
var attachmentName_1 = slot.data.attachmentName; var attachmentName_1 = slot.data.attachmentName;
slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1)); slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
var attachmentName_2 = slot.data.attachmentName; var attachmentName_2 = slot.data.attachmentName;
slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2)); slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
} }
@ -583,35 +627,42 @@ var spine;
this.frameVertices = new Array(frameCount); this.frameVertices = new Array(frameCount);
} }
DeformTimeline.prototype.getPropertyId = function () { DeformTimeline.prototype.getPropertyId = function () {
return (TimelineType.deform << 24) + this.slotIndex; return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
}; };
DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) { DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frameVertices[frameIndex] = vertices; this.frameVertices[frameIndex] = vertices;
}; };
DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var slotAttachment = slot.getAttachment(); var slotAttachment = slot.getAttachment();
if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment)) if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
return; return;
var frames = this.frames;
var verticesArray = slot.attachmentVertices; var verticesArray = slot.attachmentVertices;
if (time < frames[0]) {
if (setupPose)
spine.Utils.setArraySize(verticesArray, 0);
return;
}
var frameVertices = this.frameVertices; var frameVertices = this.frameVertices;
var vertexCount = frameVertices[0].length; var vertexCount = frameVertices[0].length;
if (verticesArray.length != vertexCount && !setupPose) if (verticesArray.length != vertexCount && pose != MixPose.setup)
alpha = 1; alpha = 1;
var vertices = spine.Utils.setArraySize(verticesArray, vertexCount); var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
var frames = this.frames;
if (time < frames[0]) {
switch (pose) {
case MixPose.setup:
verticesArray.length = 0;
return;
case MixPose.current:
alpha = 1 - alpha;
for (var i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
}
return;
}
if (time >= frames[frames.length - 1]) { if (time >= frames[frames.length - 1]) {
var lastVertices = frameVertices[frames.length - 1]; var lastVertices = frameVertices[frames.length - 1];
if (alpha == 1) { if (alpha == 1) {
spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount); spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -642,7 +693,7 @@ var spine;
vertices[i] = prev + (nextVertices[i] - prev) * percent; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -683,13 +734,13 @@ var spine;
this.frames[frameIndex] = event.time; this.frames[frameIndex] = event.time;
this.events[frameIndex] = event; this.events[frameIndex] = event;
}; };
EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
if (firedEvents == null) if (firedEvents == null)
return; return;
var frames = this.frames; var frames = this.frames;
var frameCount = this.frames.length; var frameCount = this.frames.length;
if (lastTime > time) { if (lastTime > time) {
this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut); this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
lastTime = -1; lastTime = -1;
} }
else if (lastTime >= frames[frameCount - 1]) else if (lastTime >= frames[frameCount - 1])
@ -729,16 +780,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.drawOrders[frameIndex] = drawOrder; this.drawOrders[frameIndex] = drawOrder;
}; };
DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var drawOrder = skeleton.drawOrder; var drawOrder = skeleton.drawOrder;
var slots = skeleton.slots; var slots = skeleton.slots;
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == MixPose.setup)
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
@ -773,25 +824,30 @@ var spine;
this.frames[frameIndex + IkConstraintTimeline.MIX] = mix; this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection; this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
}; };
IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.ikConstraints[this.ikConstraintIndex]; var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.mix = constraint.data.mix; case MixPose.setup:
constraint.bendDirection = constraint.data.bendDirection; constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose.current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
} }
return; return;
} }
if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha; constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
return; return;
@ -800,13 +856,13 @@ var spine;
var mix = frames[frame + IkConstraintTimeline.PREV_MIX]; var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
var frameTime = frames[frame]; var frameTime = frames[frame];
var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha; 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]; constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha; constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
}; };
@ -836,16 +892,23 @@ var spine;
this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix; this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix; this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
}; };
TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.transformConstraints[this.transformConstraintIndex]; var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { var data = constraint.data;
var data = constraint.data; switch (pose) {
constraint.rotateMix = data.rotateMix; case MixPose.setup:
constraint.translateMix = data.rotateMix; constraint.rotateMix = data.rotateMix;
constraint.scaleMix = data.scaleMix; constraint.translateMix = data.translateMix;
constraint.shearMix = data.shearMix; constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix;
return;
case MixPose.current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
} }
return; return;
} }
@ -870,7 +933,7 @@ var spine;
scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent; scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent; shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
var data = constraint.data; var data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
@ -911,12 +974,17 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value; this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
}; };
PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.position = constraint.data.position; case MixPose.setup:
constraint.position = constraint.data.position;
return;
case MixPose.current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
}
return; return;
} }
var position = 0; var position = 0;
@ -929,7 +997,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent; position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else else
constraint.position += (position - constraint.position) * alpha; constraint.position += (position - constraint.position) * alpha;
@ -949,12 +1017,17 @@ var spine;
PathConstraintSpacingTimeline.prototype.getPropertyId = function () { PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex; return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
}; };
PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.spacing = constraint.data.spacing; case MixPose.setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose.current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
}
return; return;
} }
var spacing = 0; var spacing = 0;
@ -967,7 +1040,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent; spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else else
constraint.spacing += (spacing - constraint.spacing) * alpha; constraint.spacing += (spacing - constraint.spacing) * alpha;
@ -990,13 +1063,18 @@ var spine;
this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix; this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix; this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
}; };
PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.rotateMix = constraint.data.rotateMix; case MixPose.setup:
constraint.translateMix = constraint.data.translateMix; constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix;
return;
case MixPose.current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
} }
return; return;
} }
@ -1014,7 +1092,7 @@ var spine;
rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent; rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent; translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} }
@ -1130,9 +1208,10 @@ var spine;
if (current == null || current.delay > 0) if (current == null || current.delay > 0)
continue; continue;
applied = true; applied = true;
var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
var mix = current.alpha; var mix = current.alpha;
if (current.mixingFrom != null) if (current.mixingFrom != null)
mix *= this.applyMixingFrom(current, skeleton); mix *= this.applyMixingFrom(current, skeleton, currentPose);
else if (current.trackTime >= current.trackEnd && current.next == null) else if (current.trackTime >= current.trackEnd && current.next == null)
mix = 0; mix = 0;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
@ -1140,7 +1219,7 @@ var spine;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1) { if (mix == 1) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, true, false); timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection.in);
} }
else { else {
var timelineData = current.timelineData; var timelineData = current.timelineData;
@ -1150,11 +1229,12 @@ var spine;
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineData[ii] >= AnimationState.FIRST, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
} }
else else
timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= AnimationState.FIRST, false); timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection.in);
} }
} }
this.queueEvents(current, animationTime); this.queueEvents(current, animationTime);
@ -1165,10 +1245,10 @@ var spine;
this.queue.drain(); this.queue.drain();
return applied; return applied;
}; };
AnimationState.prototype.applyMixingFrom = function (to, skeleton) { AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
var from = to.mixingFrom; var from = to.mixingFrom;
if (from.mixingFrom != null) if (from.mixingFrom != null)
this.applyMixingFrom(from, skeleton); this.applyMixingFrom(from, skeleton, currentPose);
var mix = 0; var mix = 0;
if (to.mixDuration == 0) if (to.mixDuration == 0)
mix = 1; mix = 1;
@ -1188,26 +1268,30 @@ var spine;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = from.timelinesRotation; var timelinesRotation = from.timelinesRotation;
var first = false; var pose;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0; var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
from.totalAlpha = 0; from.totalAlpha = 0;
for (var i = 0; i < timelineCount; i++) { for (var i = 0; i < timelineCount; i++) {
var timeline = timelines[i]; var timeline = timelines[i];
switch (timelineData[i]) { switch (timelineData[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
first = false; if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
pose = currentPose;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.FIRST: case AnimationState.FIRST:
first = true; pose = spine.MixPose.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.DIP:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
break; break;
default: default:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
var dipMix = timelineDipMix[i]; var dipMix = timelineDipMix[i];
alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
@ -1215,15 +1299,9 @@ var spine;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
if (timeline instanceof spine.RotateTimeline) if (timeline instanceof spine.RotateTimeline)
this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
else { else {
if (!first) { timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
}
timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true);
} }
} }
if (to.mixDuration > 0) if (to.mixDuration > 0)
@ -1233,18 +1311,18 @@ var spine;
from.nextTrackLast = from.trackTime; from.nextTrackLast = from.trackTime;
return mix; return mix;
}; };
AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, setupPose, timelinesRotation, i, firstFrame) { AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
if (firstFrame) if (firstFrame)
timelinesRotation[i] = 0; timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection.in);
return; return;
} }
var rotateTimeline = timeline; var rotateTimeline = timeline;
var frames = rotateTimeline.frames; var frames = rotateTimeline.frames;
var bone = skeleton.bones[rotateTimeline.boneIndex]; var bone = skeleton.bones[rotateTimeline.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == spine.MixPose.setup)
bone.rotation = bone.data.rotation; bone.rotation = bone.data.rotation;
return; return;
} }
@ -1261,7 +1339,7 @@ var spine;
r2 = prevRotation + r2 * percent + bone.data.rotation; r2 = prevRotation + r2 * percent + bone.data.rotation;
r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360; r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
} }
var r1 = setupPose ? bone.data.rotation : bone.rotation; var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
var total = 0, diff = r2 - r1; var total = 0, diff = r2 - r1;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];
@ -1950,6 +2028,7 @@ var spine;
__extends(VertexAttachment, _super); __extends(VertexAttachment, _super);
function VertexAttachment(name) { function VertexAttachment(name) {
_super.call(this, name); _super.call(this, name);
this.id = (VertexAttachment.nextID++ & 65535) << 11;
this.worldVerticesLength = 0; this.worldVerticesLength = 0;
} }
VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) { VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
@ -2014,6 +2093,7 @@ var spine;
VertexAttachment.prototype.applyDeform = function (sourceAttachment) { VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
}; };
VertexAttachment.nextID = 0;
return VertexAttachment; return VertexAttachment;
}(Attachment)); }(Attachment));
spine.VertexAttachment = VertexAttachment; spine.VertexAttachment = VertexAttachment;

File diff suppressed because one or more lines are too long

View File

@ -4,14 +4,23 @@ declare module spine {
timelines: Array<Timeline>; timelines: Array<Timeline>;
duration: number; duration: number;
constructor(name: string, timelines: Array<Timeline>, duration: number); constructor(name: string, timelines: Array<Timeline>, duration: number);
apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
static binarySearch(values: ArrayLike<number>, target: number, step?: number): number; static binarySearch(values: ArrayLike<number>, target: number, step?: number): number;
static linearSearch(values: ArrayLike<number>, target: number, step: number): number; static linearSearch(values: ArrayLike<number>, target: number, step: number): number;
} }
interface Timeline { interface Timeline {
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
getPropertyId(): number; getPropertyId(): number;
} }
enum MixPose {
setup = 0,
current = 1,
currentLayered = 2,
}
enum MixDirection {
in = 0,
out = 1,
}
enum TimelineType { enum TimelineType {
rotate = 0, rotate = 0,
translate = 1, translate = 1,
@ -43,7 +52,7 @@ declare module spine {
getCurveType(frameIndex: number): number; getCurveType(frameIndex: number): number;
setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void; setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void;
getCurvePercent(frameIndex: number, percent: number): number; getCurvePercent(frameIndex: number, percent: number): number;
abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class RotateTimeline extends CurveTimeline { class RotateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -55,7 +64,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, degrees: number): void; setFrame(frameIndex: number, time: number, degrees: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TranslateTimeline extends CurveTimeline { class TranslateTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -69,17 +78,17 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, x: number, y: number): void; setFrame(frameIndex: number, time: number, x: number, y: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ScaleTimeline extends TranslateTimeline { class ScaleTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ShearTimeline extends TranslateTimeline { class ShearTimeline extends TranslateTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class ColorTimeline extends CurveTimeline { class ColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -97,7 +106,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TwoColorTimeline extends CurveTimeline { class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -121,7 +130,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
@ -131,7 +140,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, attachmentName: string): void; setFrame(frameIndex: number, time: number, attachmentName: string): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DeformTimeline extends CurveTimeline { class DeformTimeline extends CurveTimeline {
slotIndex: number; slotIndex: number;
@ -141,7 +150,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void; setFrame(frameIndex: number, time: number, vertices: ArrayLike<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class EventTimeline implements Timeline { class EventTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -150,7 +159,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, event: Event): void; setFrame(frameIndex: number, event: Event): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class DrawOrderTimeline implements Timeline { class DrawOrderTimeline implements Timeline {
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -159,7 +168,7 @@ declare module spine {
getPropertyId(): number; getPropertyId(): number;
getFrameCount(): number; getFrameCount(): number;
setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void; setFrame(frameIndex: number, time: number, drawOrder: Array<number>): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class IkConstraintTimeline extends CurveTimeline { class IkConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -173,7 +182,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void; setFrame(frameIndex: number, time: number, mix: number, bendDirection: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class TransformConstraintTimeline extends CurveTimeline { class TransformConstraintTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -191,7 +200,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number, scaleMix: number, shearMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintPositionTimeline extends CurveTimeline { class PathConstraintPositionTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -203,12 +212,12 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, value: number): void; setFrame(frameIndex: number, time: number, value: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline { class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
class PathConstraintMixTimeline extends CurveTimeline { class PathConstraintMixTimeline extends CurveTimeline {
static ENTRIES: number; static ENTRIES: number;
@ -222,7 +231,7 @@ declare module spine {
constructor(frameCount: number); constructor(frameCount: number);
getPropertyId(): number; getPropertyId(): number;
setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void; setFrame(frameIndex: number, time: number, rotateMix: number, translateMix: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
} }
declare module spine { declare module spine {
@ -246,8 +255,8 @@ declare module spine {
update(delta: number): void; update(delta: number): void;
updateMixingFrom(to: TrackEntry, delta: number): boolean; updateMixingFrom(to: TrackEntry, delta: number): boolean;
apply(skeleton: Skeleton): boolean; apply(skeleton: Skeleton): boolean;
applyMixingFrom(to: TrackEntry, skeleton: Skeleton): number; applyMixingFrom(to: TrackEntry, skeleton: Skeleton, currentPose: MixPose): number;
applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, setupPose: boolean, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void; applyRotateTimeline(timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, pose: MixPose, timelinesRotation: Array<number>, i: number, firstFrame: boolean): void;
queueEvents(entry: TrackEntry, animationTime: number): void; queueEvents(entry: TrackEntry, animationTime: number): void;
clearTracks(): void; clearTracks(): void;
clearTrack(trackIndex: number): void; clearTrack(trackIndex: number): void;
@ -396,6 +405,8 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
abstract class VertexAttachment extends Attachment { abstract class VertexAttachment extends Attachment {
private static nextID;
id: number;
bones: Array<number>; bones: Array<number>;
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;

View File

@ -15,7 +15,7 @@ var spine;
this.timelines = timelines; this.timelines = timelines;
this.duration = duration; this.duration = duration;
} }
Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, setupPose, mixingOut) { Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
if (skeleton == null) if (skeleton == null)
throw new Error("skeleton cannot be null."); throw new Error("skeleton cannot be null.");
if (loop && this.duration != 0) { if (loop && this.duration != 0) {
@ -25,7 +25,7 @@ var spine;
} }
var timelines = this.timelines; var timelines = this.timelines;
for (var i = 0, n = timelines.length; i < n; i++) for (var i = 0, n = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut); timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
}; };
Animation.binarySearch = function (values, target, step) { Animation.binarySearch = function (values, target, step) {
if (step === void 0) { step = 1; } if (step === void 0) { step = 1; }
@ -53,6 +53,17 @@ var spine;
return Animation; return Animation;
}()); }());
spine.Animation = Animation; spine.Animation = Animation;
(function (MixPose) {
MixPose[MixPose["setup"] = 0] = "setup";
MixPose[MixPose["current"] = 1] = "current";
MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
})(spine.MixPose || (spine.MixPose = {}));
var MixPose = spine.MixPose;
(function (MixDirection) {
MixDirection[MixDirection["in"] = 0] = "in";
MixDirection[MixDirection["out"] = 1] = "out";
})(spine.MixDirection || (spine.MixDirection = {}));
var MixDirection = spine.MixDirection;
(function (TimelineType) { (function (TimelineType) {
TimelineType[TimelineType["rotate"] = 0] = "rotate"; TimelineType[TimelineType["rotate"] = 0] = "rotate";
TimelineType[TimelineType["translate"] = 1] = "translate"; TimelineType[TimelineType["translate"] = 1] = "translate";
@ -167,21 +178,28 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + RotateTimeline.ROTATION] = degrees; this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
}; };
RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
bone.rotation = bone.data.rotation; case MixPose.setup:
bone.rotation = bone.data.rotation;
return;
case MixPose.current:
var r_1 = bone.data.rotation - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha;
}
return; return;
} }
if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
if (setupPose) if (pose == MixPose.setup)
bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha; bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
else { else {
var r_1 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation; var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360; r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
bone.rotation += r_1 * alpha; bone.rotation += r_2 * alpha;
} }
return; return;
} }
@ -192,7 +210,7 @@ var spine;
var r = frames[frame + RotateTimeline.ROTATION] - prevRotation; var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
r = prevRotation + r * percent; r = prevRotation + r * percent;
if (setupPose) { if (pose == MixPose.setup) {
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.rotation = bone.data.rotation + r * alpha; bone.rotation = bone.data.rotation + r * alpha;
} }
@ -224,13 +242,18 @@ var spine;
this.frames[frameIndex + TranslateTimeline.X] = x; this.frames[frameIndex + TranslateTimeline.X] = x;
this.frames[frameIndex + TranslateTimeline.Y] = y; this.frames[frameIndex + TranslateTimeline.Y] = y;
}; };
TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.x = bone.data.x; case MixPose.setup:
bone.y = bone.data.y; bone.x = bone.data.x;
bone.y = bone.data.y;
return;
case MixPose.current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
} }
return; return;
} }
@ -248,7 +271,7 @@ var spine;
x += (frames[frame + TranslateTimeline.X] - x) * percent; x += (frames[frame + TranslateTimeline.X] - x) * percent;
y += (frames[frame + TranslateTimeline.Y] - y) * percent; y += (frames[frame + TranslateTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.x = bone.data.x + x * alpha; bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; bone.y = bone.data.y + y * alpha;
} }
@ -274,13 +297,18 @@ var spine;
ScaleTimeline.prototype.getPropertyId = function () { ScaleTimeline.prototype.getPropertyId = function () {
return (TimelineType.scale << 24) + this.boneIndex; return (TimelineType.scale << 24) + this.boneIndex;
}; };
ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.scaleX = bone.data.scaleX; case MixPose.setup:
bone.scaleY = bone.data.scaleY; bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY;
return;
case MixPose.current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
} }
return; return;
} }
@ -304,7 +332,7 @@ var spine;
} }
else { else {
var bx = 0, by = 0; var bx = 0, by = 0;
if (setupPose) { if (pose == MixPose.setup) {
bx = bone.data.scaleX; bx = bone.data.scaleX;
by = bone.data.scaleY; by = bone.data.scaleY;
} }
@ -312,7 +340,7 @@ var spine;
bx = bone.scaleX; bx = bone.scaleX;
by = bone.scaleY; by = bone.scaleY;
} }
if (mixingOut) { if (direction == MixDirection.out) {
x = Math.abs(x) * spine.MathUtils.signum(bx); x = Math.abs(x) * spine.MathUtils.signum(bx);
y = Math.abs(y) * spine.MathUtils.signum(by); y = Math.abs(y) * spine.MathUtils.signum(by);
} }
@ -335,13 +363,18 @@ var spine;
ShearTimeline.prototype.getPropertyId = function () { ShearTimeline.prototype.getPropertyId = function () {
return (TimelineType.shear << 24) + this.boneIndex; return (TimelineType.shear << 24) + this.boneIndex;
}; };
ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var bone = skeleton.bones[this.boneIndex]; var bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
bone.shearX = bone.data.shearX; case MixPose.setup:
bone.shearY = bone.data.shearY; bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY;
return;
case MixPose.current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
} }
return; return;
} }
@ -359,7 +392,7 @@ var spine;
x = x + (frames[frame + ShearTimeline.X] - x) * percent; x = x + (frames[frame + ShearTimeline.X] - x) * percent;
y = y + (frames[frame + ShearTimeline.Y] - y) * percent; y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.shearX = bone.data.shearX + x * alpha; bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; bone.shearY = bone.data.shearY + y * alpha;
} }
@ -388,12 +421,18 @@ var spine;
this.frames[frameIndex + ColorTimeline.B] = b; this.frames[frameIndex + ColorTimeline.B] = b;
this.frames[frameIndex + ColorTimeline.A] = a; this.frames[frameIndex + ColorTimeline.A] = a;
}; };
ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.color.setFromColor(slot.data.color);
return;
case MixPose.current:
var color = slot.color, setup = slot.data.color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
}
return; return;
} }
var r = 0, g = 0, b = 0, a = 0; var r = 0, g = 0, b = 0, a = 0;
@ -421,7 +460,7 @@ var spine;
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
else { else {
var color = slot.color; var color = slot.color;
if (setupPose) if (pose == MixPose.setup)
color.setFromColor(slot.data.color); color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
} }
@ -459,13 +498,19 @@ var spine;
this.frames[frameIndex + TwoColorTimeline.G2] = g2; this.frames[frameIndex + TwoColorTimeline.G2] = g2;
this.frames[frameIndex + TwoColorTimeline.B2] = b2; this.frames[frameIndex + TwoColorTimeline.B2] = b2;
}; };
TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
slot.color.setFromColor(slot.data.color); case MixPose.setup:
slot.darkColor.setFromColor(slot.data.darkColor); slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor);
return;
case MixPose.current:
var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
} }
return; return;
} }
@ -504,9 +549,8 @@ var spine;
slot.darkColor.set(r2, g2, b2, 1); slot.darkColor.set(r2, g2, b2, 1);
} }
else { else {
var light = slot.color; var light = slot.color, dark = slot.darkColor;
var dark = slot.darkColor; if (pose == MixPose.setup) {
if (setupPose) {
light.setFromColor(slot.data.color); light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor); dark.setFromColor(slot.data.darkColor);
} }
@ -548,16 +592,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.attachmentNames[frameIndex] = attachmentName; this.attachmentNames[frameIndex] = attachmentName;
}; };
AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) { AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
var attachmentName_1 = slot.data.attachmentName; var attachmentName_1 = slot.data.attachmentName;
slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1)); slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
var attachmentName_2 = slot.data.attachmentName; var attachmentName_2 = slot.data.attachmentName;
slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2)); slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
} }
@ -583,35 +627,42 @@ var spine;
this.frameVertices = new Array(frameCount); this.frameVertices = new Array(frameCount);
} }
DeformTimeline.prototype.getPropertyId = function () { DeformTimeline.prototype.getPropertyId = function () {
return (TimelineType.deform << 24) + this.slotIndex; return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
}; };
DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) { DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frameVertices[frameIndex] = vertices; this.frameVertices[frameIndex] = vertices;
}; };
DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var slot = skeleton.slots[this.slotIndex]; var slot = skeleton.slots[this.slotIndex];
var slotAttachment = slot.getAttachment(); var slotAttachment = slot.getAttachment();
if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment)) if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
return; return;
var frames = this.frames;
var verticesArray = slot.attachmentVertices; var verticesArray = slot.attachmentVertices;
if (time < frames[0]) {
if (setupPose)
spine.Utils.setArraySize(verticesArray, 0);
return;
}
var frameVertices = this.frameVertices; var frameVertices = this.frameVertices;
var vertexCount = frameVertices[0].length; var vertexCount = frameVertices[0].length;
if (verticesArray.length != vertexCount && !setupPose) if (verticesArray.length != vertexCount && pose != MixPose.setup)
alpha = 1; alpha = 1;
var vertices = spine.Utils.setArraySize(verticesArray, vertexCount); var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
var frames = this.frames;
if (time < frames[0]) {
switch (pose) {
case MixPose.setup:
verticesArray.length = 0;
return;
case MixPose.current:
alpha = 1 - alpha;
for (var i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
}
return;
}
if (time >= frames[frames.length - 1]) { if (time >= frames[frames.length - 1]) {
var lastVertices = frameVertices[frames.length - 1]; var lastVertices = frameVertices[frames.length - 1];
if (alpha == 1) { if (alpha == 1) {
spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount); spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -642,7 +693,7 @@ var spine;
vertices[i] = prev + (nextVertices[i] - prev) * percent; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} }
else if (setupPose) { else if (pose == MixPose.setup) {
var vertexAttachment = slotAttachment; var vertexAttachment = slotAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
var setupVertices = vertexAttachment.vertices; var setupVertices = vertexAttachment.vertices;
@ -683,13 +734,13 @@ var spine;
this.frames[frameIndex] = event.time; this.frames[frameIndex] = event.time;
this.events[frameIndex] = event; this.events[frameIndex] = event;
}; };
EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
if (firedEvents == null) if (firedEvents == null)
return; return;
var frames = this.frames; var frames = this.frames;
var frameCount = this.frames.length; var frameCount = this.frames.length;
if (lastTime > time) { if (lastTime > time) {
this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut); this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
lastTime = -1; lastTime = -1;
} }
else if (lastTime >= frames[frameCount - 1]) else if (lastTime >= frames[frameCount - 1])
@ -729,16 +780,16 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.drawOrders[frameIndex] = drawOrder; this.drawOrders[frameIndex] = drawOrder;
}; };
DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var drawOrder = skeleton.drawOrder; var drawOrder = skeleton.drawOrder;
var slots = skeleton.slots; var slots = skeleton.slots;
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
var frames = this.frames; var frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == MixPose.setup)
spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
@ -773,25 +824,30 @@ var spine;
this.frames[frameIndex + IkConstraintTimeline.MIX] = mix; this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection; this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
}; };
IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.ikConstraints[this.ikConstraintIndex]; var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.mix = constraint.data.mix; case MixPose.setup:
constraint.bendDirection = constraint.data.bendDirection; constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose.current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
} }
return; return;
} }
if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha; constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
return; return;
@ -800,13 +856,13 @@ var spine;
var mix = frames[frame + IkConstraintTimeline.PREV_MIX]; var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
var frameTime = frames[frame]; var frameTime = frames[frame];
var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha; 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]; constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
else { else {
constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha; constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
if (!mixingOut) if (direction == MixDirection.in)
constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION]; constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
}; };
@ -836,16 +892,23 @@ var spine;
this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix; this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix; this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
}; };
TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.transformConstraints[this.transformConstraintIndex]; var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { var data = constraint.data;
var data = constraint.data; switch (pose) {
constraint.rotateMix = data.rotateMix; case MixPose.setup:
constraint.translateMix = data.rotateMix; constraint.rotateMix = data.rotateMix;
constraint.scaleMix = data.scaleMix; constraint.translateMix = data.translateMix;
constraint.shearMix = data.shearMix; constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix;
return;
case MixPose.current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
} }
return; return;
} }
@ -870,7 +933,7 @@ var spine;
scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent; scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent; shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
var data = constraint.data; var data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
@ -911,12 +974,17 @@ var spine;
this.frames[frameIndex] = time; this.frames[frameIndex] = time;
this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value; this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
}; };
PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.position = constraint.data.position; case MixPose.setup:
constraint.position = constraint.data.position;
return;
case MixPose.current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
}
return; return;
} }
var position = 0; var position = 0;
@ -929,7 +997,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent; position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else else
constraint.position += (position - constraint.position) * alpha; constraint.position += (position - constraint.position) * alpha;
@ -949,12 +1017,17 @@ var spine;
PathConstraintSpacingTimeline.prototype.getPropertyId = function () { PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex; return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
}; };
PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) switch (pose) {
constraint.spacing = constraint.data.spacing; case MixPose.setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose.current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
}
return; return;
} }
var spacing = 0; var spacing = 0;
@ -967,7 +1040,7 @@ var spine;
var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime)); var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent; spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else else
constraint.spacing += (spacing - constraint.spacing) * alpha; constraint.spacing += (spacing - constraint.spacing) * alpha;
@ -990,13 +1063,18 @@ var spine;
this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix; this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix; this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
}; };
PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, setupPose, mixingOut) { PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
var frames = this.frames; var frames = this.frames;
var constraint = skeleton.pathConstraints[this.pathConstraintIndex]; var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
constraint.rotateMix = constraint.data.rotateMix; case MixPose.setup:
constraint.translateMix = constraint.data.translateMix; constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix;
return;
case MixPose.current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
} }
return; return;
} }
@ -1014,7 +1092,7 @@ var spine;
rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent; rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent; translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} }
@ -1130,9 +1208,10 @@ var spine;
if (current == null || current.delay > 0) if (current == null || current.delay > 0)
continue; continue;
applied = true; applied = true;
var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
var mix = current.alpha; var mix = current.alpha;
if (current.mixingFrom != null) if (current.mixingFrom != null)
mix *= this.applyMixingFrom(current, skeleton); mix *= this.applyMixingFrom(current, skeleton, currentPose);
else if (current.trackTime >= current.trackEnd && current.next == null) else if (current.trackTime >= current.trackEnd && current.next == null)
mix = 0; mix = 0;
var animationLast = current.animationLast, animationTime = current.getAnimationTime(); var animationLast = current.animationLast, animationTime = current.getAnimationTime();
@ -1140,7 +1219,7 @@ var spine;
var timelines = current.animation.timelines; var timelines = current.animation.timelines;
if (mix == 1) { if (mix == 1) {
for (var ii = 0; ii < timelineCount; ii++) for (var ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, true, false); timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection.in);
} }
else { else {
var timelineData = current.timelineData; var timelineData = current.timelineData;
@ -1150,11 +1229,12 @@ var spine;
var timelinesRotation = current.timelinesRotation; var timelinesRotation = current.timelinesRotation;
for (var ii = 0; ii < timelineCount; ii++) { for (var ii = 0; ii < timelineCount; ii++) {
var timeline = timelines[ii]; var timeline = timelines[ii];
var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
if (timeline instanceof spine.RotateTimeline) { if (timeline instanceof spine.RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineData[ii] >= AnimationState.FIRST, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
} }
else else
timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= AnimationState.FIRST, false); timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection.in);
} }
} }
this.queueEvents(current, animationTime); this.queueEvents(current, animationTime);
@ -1165,10 +1245,10 @@ var spine;
this.queue.drain(); this.queue.drain();
return applied; return applied;
}; };
AnimationState.prototype.applyMixingFrom = function (to, skeleton) { AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
var from = to.mixingFrom; var from = to.mixingFrom;
if (from.mixingFrom != null) if (from.mixingFrom != null)
this.applyMixingFrom(from, skeleton); this.applyMixingFrom(from, skeleton, currentPose);
var mix = 0; var mix = 0;
if (to.mixDuration == 0) if (to.mixDuration == 0)
mix = 1; mix = 1;
@ -1188,26 +1268,30 @@ var spine;
if (firstFrame) if (firstFrame)
spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
var timelinesRotation = from.timelinesRotation; var timelinesRotation = from.timelinesRotation;
var first = false; var pose;
var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0; var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
from.totalAlpha = 0; from.totalAlpha = 0;
for (var i = 0; i < timelineCount; i++) { for (var i = 0; i < timelineCount; i++) {
var timeline = timelines[i]; var timeline = timelines[i];
switch (timelineData[i]) { switch (timelineData[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
first = false; if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
pose = currentPose;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.FIRST: case AnimationState.FIRST:
first = true; pose = spine.MixPose.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.DIP:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
break; break;
default: default:
first = true; pose = spine.MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
var dipMix = timelineDipMix[i]; var dipMix = timelineDipMix[i];
alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
@ -1215,15 +1299,9 @@ var spine;
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
if (timeline instanceof spine.RotateTimeline) if (timeline instanceof spine.RotateTimeline)
this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
else { else {
if (!first) { timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
if (!attachments && timeline instanceof spine.AttachmentTimeline)
continue;
if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
continue;
}
timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true);
} }
} }
if (to.mixDuration > 0) if (to.mixDuration > 0)
@ -1233,18 +1311,18 @@ var spine;
from.nextTrackLast = from.trackTime; from.nextTrackLast = from.trackTime;
return mix; return mix;
}; };
AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, setupPose, timelinesRotation, i, firstFrame) { AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
if (firstFrame) if (firstFrame)
timelinesRotation[i] = 0; timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection.in);
return; return;
} }
var rotateTimeline = timeline; var rotateTimeline = timeline;
var frames = rotateTimeline.frames; var frames = rotateTimeline.frames;
var bone = skeleton.bones[rotateTimeline.boneIndex]; var bone = skeleton.bones[rotateTimeline.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) if (pose == spine.MixPose.setup)
bone.rotation = bone.data.rotation; bone.rotation = bone.data.rotation;
return; return;
} }
@ -1261,7 +1339,7 @@ var spine;
r2 = prevRotation + r2 * percent + bone.data.rotation; r2 = prevRotation + r2 * percent + bone.data.rotation;
r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360; r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
} }
var r1 = setupPose ? bone.data.rotation : bone.rotation; var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
var total = 0, diff = r2 - r1; var total = 0, diff = r2 - r1;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];
@ -1950,6 +2028,7 @@ var spine;
__extends(VertexAttachment, _super); __extends(VertexAttachment, _super);
function VertexAttachment(name) { function VertexAttachment(name) {
_super.call(this, name); _super.call(this, name);
this.id = (VertexAttachment.nextID++ & 65535) << 11;
this.worldVerticesLength = 0; this.worldVerticesLength = 0;
} }
VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) { VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
@ -2014,6 +2093,7 @@ var spine;
VertexAttachment.prototype.applyDeform = function (sourceAttachment) { VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
return this == sourceAttachment; return this == sourceAttachment;
}; };
VertexAttachment.nextID = 0;
return VertexAttachment; return VertexAttachment;
}(Attachment)); }(Attachment));
spine.VertexAttachment = VertexAttachment; spine.VertexAttachment = VertexAttachment;

File diff suppressed because one or more lines are too long

View File

@ -42,7 +42,7 @@ module spine {
this.duration = duration; this.duration = duration;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
if (skeleton == null) throw new Error("skeleton cannot be null."); if (skeleton == null) throw new Error("skeleton cannot be null.");
if (loop && this.duration != 0) { if (loop && this.duration != 0) {
@ -52,7 +52,7 @@ module spine {
let timelines = this.timelines; let timelines = this.timelines;
for (let i = 0, n = timelines.length; i < n; i++) for (let i = 0, n = timelines.length; i < n; i++)
timelines[i].apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut); timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
} }
static binarySearch (values: ArrayLike<number>, target: number, step: number = 1) { static binarySearch (values: ArrayLike<number>, target: number, step: number = 1) {
@ -78,10 +78,20 @@ module spine {
} }
export interface Timeline { export interface Timeline {
apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
getPropertyId (): number; getPropertyId (): number;
} }
export enum MixPose {
setup,
current,
currentLayered
}
export enum MixDirection {
in, out
}
export enum TimelineType { export enum TimelineType {
rotate, translate, scale, shear, rotate, translate, scale, shear,
attachment, color, deform, attachment, color, deform,
@ -178,7 +188,7 @@ module spine {
return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1. 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, setupPose: boolean, mixingOut: boolean): void; abstract apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection): void;
} }
export class RotateTimeline extends CurveTimeline { export class RotateTimeline extends CurveTimeline {
@ -205,17 +215,25 @@ module spine {
this.frames[frameIndex + RotateTimeline.ROTATION] = degrees; this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let bone = skeleton.bones[this.boneIndex]; let bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) bone.rotation = bone.data.rotation; switch (pose) {
case MixPose.setup:
bone.rotation = bone.data.rotation;
return;
case MixPose.current:
let r = bone.data.rotation - bone.rotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.rotation += r * alpha;
}
return; return;
} }
if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { // Time is after last frame. if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { // Time is after last frame.
if (setupPose) if (pose == MixPose.setup)
bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha; bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
else { else {
let r = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation; let r = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
@ -235,7 +253,7 @@ module spine {
let r = frames[frame + RotateTimeline.ROTATION] - prevRotation; let r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
r = prevRotation + r * percent; r = prevRotation + r * percent;
if (setupPose) { if (pose == MixPose.setup) {
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.rotation = bone.data.rotation + r * alpha; bone.rotation = bone.data.rotation + r * alpha;
} else { } else {
@ -271,14 +289,19 @@ module spine {
this.frames[frameIndex + TranslateTimeline.Y] = y; this.frames[frameIndex + TranslateTimeline.Y] = y;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let bone = skeleton.bones[this.boneIndex]; let bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
bone.x = bone.data.x; bone.x = bone.data.x;
bone.y = bone.data.y; bone.y = bone.data.y;
return;
case MixPose.current:
bone.x += (bone.data.x - bone.x) * alpha;
bone.y += (bone.data.y - bone.y) * alpha;
} }
return; return;
} }
@ -299,7 +322,7 @@ module spine {
x += (frames[frame + TranslateTimeline.X] - x) * percent; x += (frames[frame + TranslateTimeline.X] - x) * percent;
y += (frames[frame + TranslateTimeline.Y] - y) * percent; y += (frames[frame + TranslateTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.x = bone.data.x + x * alpha; bone.x = bone.data.x + x * alpha;
bone.y = bone.data.y + y * alpha; bone.y = bone.data.y + y * alpha;
} else { } else {
@ -318,14 +341,19 @@ module spine {
return (TimelineType.scale << 24) + this.boneIndex; return (TimelineType.scale << 24) + this.boneIndex;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let bone = skeleton.bones[this.boneIndex]; let bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
bone.scaleX = bone.data.scaleX; bone.scaleX = bone.data.scaleX;
bone.scaleY = bone.data.scaleY; bone.scaleY = bone.data.scaleY;
return;
case MixPose.current:
bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
} }
return; return;
} }
@ -351,7 +379,7 @@ module spine {
bone.scaleY = y; bone.scaleY = y;
} else { } else {
let bx = 0, by = 0; let bx = 0, by = 0;
if (setupPose) { if (pose == MixPose.setup) {
bx = bone.data.scaleX; bx = bone.data.scaleX;
by = bone.data.scaleY; by = bone.data.scaleY;
} else { } else {
@ -359,7 +387,7 @@ module spine {
by = bone.scaleY; by = bone.scaleY;
} }
// Mixing out uses sign of setup or current pose, else use sign of key. // Mixing out uses sign of setup or current pose, else use sign of key.
if (mixingOut) { if (direction == MixDirection.out) {
x = Math.abs(x) * MathUtils.signum(bx); x = Math.abs(x) * MathUtils.signum(bx);
y = Math.abs(y) * MathUtils.signum(by); y = Math.abs(y) * MathUtils.signum(by);
} else { } else {
@ -381,14 +409,19 @@ module spine {
return (TimelineType.shear << 24) + this.boneIndex; return (TimelineType.shear << 24) + this.boneIndex;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let bone = skeleton.bones[this.boneIndex]; let bone = skeleton.bones[this.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
bone.shearX = bone.data.shearX; bone.shearX = bone.data.shearX;
bone.shearY = bone.data.shearY; bone.shearY = bone.data.shearY;
return;
case MixPose.current:
bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
} }
return; return;
} }
@ -409,7 +442,7 @@ module spine {
x = x + (frames[frame + ShearTimeline.X] - x) * percent; x = x + (frames[frame + ShearTimeline.X] - x) * percent;
y = y + (frames[frame + ShearTimeline.Y] - y) * percent; y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
bone.shearX = bone.data.shearX + x * alpha; bone.shearX = bone.data.shearX + x * alpha;
bone.shearY = bone.data.shearY + y * alpha; bone.shearY = bone.data.shearY + y * alpha;
} else { } else {
@ -446,11 +479,19 @@ module spine {
this.frames[frameIndex + ColorTimeline.A] = a; this.frames[frameIndex + ColorTimeline.A] = a;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let slot = skeleton.slots[this.slotIndex]; let slot = skeleton.slots[this.slotIndex];
let frames = this.frames; let frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) slot.color.setFromColor(slot.data.color); switch (pose) {
case MixPose.setup:
slot.color.setFromColor(slot.data.color);
return;
case MixPose.current:
let color = slot.color, setup = slot.data.color;
color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha,
(setup.a - color.a) * alpha);
}
return; return;
} }
@ -481,7 +522,7 @@ module spine {
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
else { else {
let color = slot.color; let color = slot.color;
if (setupPose) color.setFromColor(slot.data.color); if (pose == MixPose.setup) color.setFromColor(slot.data.color);
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
} }
} }
@ -518,13 +559,20 @@ module spine {
this.frames[frameIndex + TwoColorTimeline.B2] = b2; this.frames[frameIndex + TwoColorTimeline.B2] = b2;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let slot = skeleton.slots[this.slotIndex]; let slot = skeleton.slots[this.slotIndex];
let frames = this.frames; let frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
slot.color.setFromColor(slot.data.color); slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor); slot.darkColor.setFromColor(slot.data.darkColor);
return;
case MixPose.current:
let light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha,
(setupLight.a - light.a) * alpha);
dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
} }
return; return;
} }
@ -565,9 +613,8 @@ module spine {
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
slot.darkColor.set(r2, g2, b2, 1); slot.darkColor.set(r2, g2, b2, 1);
} else { } else {
let light = slot.color; let light = slot.color, dark = slot.darkColor;
let dark = slot.darkColor; if (pose == MixPose.setup) {
if (setupPose) {
light.setFromColor(slot.data.color); light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor); dark.setFromColor(slot.data.darkColor);
} }
@ -601,9 +648,9 @@ module spine {
this.attachmentNames[frameIndex] = attachmentName; this.attachmentNames[frameIndex] = attachmentName;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let slot = skeleton.slots[this.slotIndex]; let slot = skeleton.slots[this.slotIndex];
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
let attachmentName = slot.data.attachmentName; let attachmentName = slot.data.attachmentName;
slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName)); slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
return; return;
@ -611,7 +658,7 @@ module spine {
let frames = this.frames; let frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { if (pose == MixPose.setup) {
let attachmentName = slot.data.attachmentName; let attachmentName = slot.data.attachmentName;
slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName)); slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
} }
@ -643,7 +690,7 @@ module spine {
} }
getPropertyId () { getPropertyId () {
return (TimelineType.deform << 24) + this.slotIndex; return (TimelineType.deform << 27) + + this.attachment.id + this.slotIndex;
} }
/** Sets the time of the specified keyframe. */ /** Sets the time of the specified keyframe. */
@ -652,29 +699,36 @@ module spine {
this.frameVertices[frameIndex] = vertices; this.frameVertices[frameIndex] = vertices;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let slot: Slot = skeleton.slots[this.slotIndex]; let slot: Slot = skeleton.slots[this.slotIndex];
let slotAttachment: Attachment = slot.getAttachment(); let slotAttachment: Attachment = slot.getAttachment();
if (!(slotAttachment instanceof VertexAttachment) || !(<VertexAttachment>slotAttachment).applyDeform(this.attachment)) return; if (!(slotAttachment instanceof VertexAttachment) || !(<VertexAttachment>slotAttachment).applyDeform(this.attachment)) return;
let verticesArray: Array<number> = slot.attachmentVertices;
let frameVertices = this.frameVertices;
let vertexCount = frameVertices[0].length;
if (verticesArray.length != vertexCount && pose != MixPose.setup) alpha = 1; // Don't mix from uninitialized slot vertices.
let vertices: Array<number> = Utils.setArraySize(verticesArray, vertexCount);
let frames = this.frames; let frames = this.frames;
let verticesArray: Array<number> = slot.attachmentVertices;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) Utils.setArraySize(verticesArray, 0); switch (pose) {
case MixPose.setup:
verticesArray.length = 0;
return;
case MixPose.current:
alpha = 1 - alpha;
for (let i = 0; i < vertexCount; i++)
vertices[i] *= alpha;
}
return; return;
} }
let frameVertices = this.frameVertices;
let vertexCount = frameVertices[0].length;
if (verticesArray.length != vertexCount && !setupPose) alpha = 1; // Don't mix from uninitialized slot vertices.
let vertices: Array<number> = Utils.setArraySize(verticesArray, vertexCount);
if (time >= frames[frames.length - 1]) { // Time is after last frame. if (time >= frames[frames.length - 1]) { // Time is after last frame.
let lastVertices = frameVertices[frames.length - 1]; let lastVertices = frameVertices[frames.length - 1];
if (alpha == 1) { if (alpha == 1) {
Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount); Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
} else if (setupPose) { } else if (pose == MixPose.setup) {
let vertexAttachment = slotAttachment as VertexAttachment; let vertexAttachment = slotAttachment as VertexAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
// Unweighted vertex positions, with alpha. // Unweighted vertex positions, with alpha.
@ -707,7 +761,7 @@ module spine {
let prev = prevVertices[i]; let prev = prevVertices[i];
vertices[i] = prev + (nextVertices[i] - prev) * percent; vertices[i] = prev + (nextVertices[i] - prev) * percent;
} }
} else if (setupPose) { } else if (pose == MixPose.setup) {
let vertexAttachment = slotAttachment as VertexAttachment; let vertexAttachment = slotAttachment as VertexAttachment;
if (vertexAttachment.bones == null) { if (vertexAttachment.bones == null) {
// Unweighted vertex positions, with alpha. // Unweighted vertex positions, with alpha.
@ -757,13 +811,13 @@ module spine {
} }
/** Fires events for frames > lastTime and <= time. */ /** Fires events for frames > lastTime and <= time. */
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
if (firedEvents == null) return; if (firedEvents == null) return;
let frames = this.frames; let frames = this.frames;
let frameCount = this.frames.length; let frameCount = this.frames.length;
if (lastTime > time) { // Fire events after last time for looped animations. if (lastTime > time) { // Fire events after last time for looped animations.
this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, setupPose, mixingOut); this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
lastTime = -1; lastTime = -1;
} else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame. } else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame.
return; return;
@ -809,17 +863,17 @@ module spine {
this.drawOrders[frameIndex] = drawOrder; this.drawOrders[frameIndex] = drawOrder;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let drawOrder: Array<Slot> = skeleton.drawOrder; let drawOrder: Array<Slot> = skeleton.drawOrder;
let slots: Array<Slot> = skeleton.slots; let slots: Array<Slot> = skeleton.slots;
if (mixingOut && setupPose) { if (direction == MixDirection.out && pose == MixPose.setup) {
Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
let frames = this.frames; let frames = this.frames;
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); if (pose == MixPose.setup) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
@ -864,25 +918,30 @@ module spine {
this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection; this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let constraint: IkConstraint = skeleton.ikConstraints[this.ikConstraintIndex]; let constraint: IkConstraint = skeleton.ikConstraints[this.ikConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
constraint.mix = constraint.data.mix; constraint.mix = constraint.data.mix;
constraint.bendDirection = constraint.data.bendDirection; constraint.bendDirection = constraint.data.bendDirection;
return;
case MixPose.current:
constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
constraint.bendDirection = constraint.data.bendDirection;
} }
return; return;
} }
if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { // Time is after last frame. if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { // Time is after last frame.
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha; constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
constraint.bendDirection = mixingOut ? constraint.data.bendDirection constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} else { } else {
constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha; constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
if (!mixingOut) constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION]; if (direction == MixDirection.in) constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
return; return;
} }
@ -894,12 +953,12 @@ module spine {
let percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, let percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1,
1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime)); 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
if (setupPose) { if (pose == MixPose.setup) {
constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha; 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]; constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} else { } else {
constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha; constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
if (!mixingOut) constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION]; if (direction == MixDirection.in) constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
} }
} }
} }
@ -931,17 +990,24 @@ module spine {
this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix; this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let constraint: TransformConstraint = skeleton.transformConstraints[this.transformConstraintIndex]; let constraint: TransformConstraint = skeleton.transformConstraints[this.transformConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { let data = constraint.data;
let data = constraint.data; switch (pose) {
case MixPose.setup:
constraint.rotateMix = data.rotateMix; constraint.rotateMix = data.rotateMix;
constraint.translateMix = data.rotateMix; constraint.translateMix = data.translateMix;
constraint.scaleMix = data.scaleMix; constraint.scaleMix = data.scaleMix;
constraint.shearMix = data.shearMix; constraint.shearMix = data.shearMix;
return;
case MixPose.current:
constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
} }
return; return;
} }
@ -969,7 +1035,7 @@ module spine {
scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent; scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent; shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
let data = constraint.data; let data = constraint.data;
constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha; constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha; constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
@ -1009,11 +1075,17 @@ module spine {
this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value; this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex]; let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) constraint.position = constraint.data.position; switch (pose) {
case MixPose.setup:
constraint.position = constraint.data.position;
return;
case MixPose.current:
constraint.position += (constraint.data.position - constraint.position) * alpha;
}
return; return;
} }
@ -1030,7 +1102,7 @@ module spine {
position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent; position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.position = constraint.data.position + (position - constraint.data.position) * alpha; constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
else else
constraint.position += (position - constraint.position) * alpha; constraint.position += (position - constraint.position) * alpha;
@ -1046,11 +1118,17 @@ module spine {
return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex; return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex]; let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) constraint.spacing = constraint.data.spacing; switch (pose) {
case MixPose.setup:
constraint.spacing = constraint.data.spacing;
return;
case MixPose.current:
constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
}
return; return;
} }
@ -1068,7 +1146,7 @@ module spine {
spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent; spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
} }
if (setupPose) if (pose == MixPose.setup)
constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha; constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else else
constraint.spacing += (spacing - constraint.spacing) * alpha; constraint.spacing += (spacing - constraint.spacing) * alpha;
@ -1101,14 +1179,19 @@ module spine {
this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix; this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
} }
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, pose: MixPose, direction: MixDirection) {
let frames = this.frames; let frames = this.frames;
let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex]; let constraint: PathConstraint = skeleton.pathConstraints[this.pathConstraintIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) { switch (pose) {
case MixPose.setup:
constraint.rotateMix = constraint.data.rotateMix; constraint.rotateMix = constraint.data.rotateMix;
constraint.translateMix = constraint.data.translateMix; constraint.translateMix = constraint.data.translateMix;
return;
case MixPose.current:
constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
} }
return; return;
} }
@ -1130,7 +1213,7 @@ module spine {
translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent; translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
} }
if (setupPose) { if (pose == MixPose.setup) {
constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha; constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha; constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
} else { } else {

View File

@ -143,11 +143,12 @@ module spine {
let current = tracks[i]; let current = tracks[i];
if (current == null || current.delay > 0) continue; if (current == null || current.delay > 0) continue;
applied = true; applied = true;
let currentPose = i == 0 ? MixPose.current : MixPose.currentLayered;
// Apply mixing from entries first. // Apply mixing from entries first.
let mix = current.alpha; let mix = current.alpha;
if (current.mixingFrom != null) if (current.mixingFrom != null)
mix *= this.applyMixingFrom(current, skeleton); mix *= this.applyMixingFrom(current, skeleton, currentPose);
else if (current.trackTime >= current.trackEnd && current.next == null) else if (current.trackTime >= current.trackEnd && current.next == null)
mix = 0; mix = 0;
@ -157,7 +158,7 @@ module spine {
let timelines = current.animation.timelines; let timelines = current.animation.timelines;
if (mix == 1) { if (mix == 1) {
for (let ii = 0; ii < timelineCount; ii++) for (let ii = 0; ii < timelineCount; ii++)
timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, true, false); timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, MixPose.setup, MixDirection.in);
} else { } else {
let timelineData = current.timelineData; let timelineData = current.timelineData;
@ -167,11 +168,11 @@ module spine {
for (let ii = 0; ii < timelineCount; ii++) { for (let ii = 0; ii < timelineCount; ii++) {
let timeline = timelines[ii]; let timeline = timelines[ii];
let pose = timelineData[ii] >= AnimationState.FIRST ? MixPose.setup : currentPose;
if (timeline instanceof RotateTimeline) { if (timeline instanceof RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineData[ii] >= AnimationState.FIRST, timelinesRotation, ii << 1, this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
firstFrame);
} else } else
timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineData[ii] >= AnimationState.FIRST, false); timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, MixDirection.in);
} }
} }
this.queueEvents(current, animationTime); this.queueEvents(current, animationTime);
@ -184,9 +185,9 @@ module spine {
return applied; return applied;
} }
applyMixingFrom (to: TrackEntry, skeleton: Skeleton) { applyMixingFrom (to: TrackEntry, skeleton: Skeleton, currentPose: MixPose) {
let from = to.mixingFrom; let from = to.mixingFrom;
if (from.mixingFrom != null) this.applyMixingFrom(from, skeleton); if (from.mixingFrom != null) this.applyMixingFrom(from, skeleton, currentPose);
let mix = 0; let mix = 0;
if (to.mixDuration == 0) // Single frame mix to undo mixingFrom changes. if (to.mixDuration == 0) // Single frame mix to undo mixingFrom changes.
@ -207,27 +208,29 @@ module spine {
let firstFrame = from.timelinesRotation.length == 0; let firstFrame = from.timelinesRotation.length == 0;
if (firstFrame) Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null); if (firstFrame) Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
let timelinesRotation = from.timelinesRotation; let timelinesRotation = from.timelinesRotation;
let first = false; let pose: MixPose;
let alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0; let alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
from.totalAlpha = 0; from.totalAlpha = 0;
for (var i = 0; i < timelineCount; i++) { for (var i = 0; i < timelineCount; i++) {
let timeline = timelines[i]; let timeline = timelines[i];
switch (timelineData[i]) { switch (timelineData[i]) {
case AnimationState.SUBSEQUENT: case AnimationState.SUBSEQUENT:
first = false; if (!attachments && timeline instanceof AttachmentTimeline) continue;
if (!drawOrder && timeline instanceof DrawOrderTimeline) continue;
pose = currentPose;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.FIRST: case AnimationState.FIRST:
first = true; pose = MixPose.setup
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.DIP: case AnimationState.DIP:
first = true; pose = MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
break; break;
default: default:
first = true; pose = MixPose.setup;
alpha = alphaDip; alpha = alphaDip;
let dipMix = timelineDipMix[i]; let dipMix = timelineDipMix[i];
alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration); alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
@ -235,13 +238,9 @@ module spine {
} }
from.totalAlpha += alpha; from.totalAlpha += alpha;
if (timeline instanceof RotateTimeline) if (timeline instanceof RotateTimeline)
this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, first, timelinesRotation, i << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
else { else {
if (!first) { timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, MixDirection.out);
if (!attachments && timeline instanceof AttachmentTimeline) continue;
if (!drawOrder && timeline instanceof DrawOrderTimeline) continue;
}
timeline.apply(skeleton, animationLast, animationTime, events, alpha, first, true);
} }
} }
@ -253,13 +252,13 @@ module spine {
return mix; return mix;
} }
applyRotateTimeline (timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, setupPose: boolean, applyRotateTimeline (timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, pose: MixPose,
timelinesRotation: Array<number>, i: number, firstFrame: boolean) { timelinesRotation: Array<number>, i: number, firstFrame: boolean) {
if (firstFrame) timelinesRotation[i] = 0; if (firstFrame) timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, pose, MixDirection.in);
return; return;
} }
@ -267,7 +266,7 @@ module spine {
let frames = rotateTimeline.frames; let frames = rotateTimeline.frames;
let bone = skeleton.bones[rotateTimeline.boneIndex]; let bone = skeleton.bones[rotateTimeline.boneIndex];
if (time < frames[0]) { if (time < frames[0]) {
if (setupPose) bone.rotation = bone.data.rotation; if (pose == MixPose.setup) bone.rotation = bone.data.rotation;
return; return;
} }
@ -289,7 +288,7 @@ module spine {
} }
// 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.
let r1 = setupPose ? bone.data.rotation : bone.rotation; let r1 = pose == MixPose.setup ? bone.data.rotation : bone.rotation;
let total = 0, diff = r2 - r1; let total = 0, diff = r2 - r1;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];

View File

@ -39,6 +39,9 @@ module spine {
} }
export abstract class VertexAttachment extends Attachment { export abstract class VertexAttachment extends Attachment {
private static nextID = 0;
id = (VertexAttachment.nextID++ & 65535) << 11;
bones: Array<number>; bones: Array<number>;
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength = 0; worldVerticesLength = 0;