[ts] Clean up, build fixes.

This commit is contained in:
Nathan Sweet 2021-05-30 20:17:54 -04:00
parent 9e00e5c701
commit 551f33b2d1
33 changed files with 75895 additions and 77496 deletions

View File

@ -81,10 +81,10 @@ package spine.examples {
skeleton.state.apply(skeleton.skeleton); skeleton.state.apply(skeleton.skeleton);
skeleton.skeleton.updateWorldTransform(); skeleton.skeleton.updateWorldTransform();
this.setRequiresRedraw(); this.setRequiresRedraw();
// skeleton.vertexEffect = new JitterEffect(10, 10); // skeleton.vertexEffect = new JitterEffect(10, 10);
swirl = new SwirlEffect(400); swirl = new SwirlEffect(400);
swirl.centerY = -200; swirl.centerY = -200;
skeleton.vertexEffect = swirl; skeleton.vertexEffect = swirl;
addChild(skeleton); addChild(skeleton);

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -111,13 +111,31 @@ module spine {
mixIn, mixOut mixIn, mixOut
} }
export enum Property { const Property = {
rotate, x, y, scaleX, scaleY, shearX, shearY, // rotate: 0,
rgb, alpha, rgb2, // x: 1,
attachment, deform, // y: 2,
event, drawOrder, // scaleX: 3,
ikConstraint, transformConstraint, // scaleY: 4,
pathConstraintPosition, pathConstraintSpacing, pathConstraintMix shearX: 5,
shearY: 6,
rgb: 7,
alpha: 8,
rgb2: 9,
attachment: 10,
deform: 11,
event: 12,
drawOrder: 13,
ikConstraint: 14,
transformConstraint: 15,
pathConstraintPosition: 16,
pathConstraintSpacing: 17,
pathConstraintMix: 18
} }
/** The interface for all timelines. */ /** The interface for all timelines. */
@ -173,33 +191,33 @@ module spine {
slotIndex: number; slotIndex: number;
} }
const LINEAR = 0; const STEPPED = 1; const BEZIER = 2;
const BEZIER_SIZE = 18;
/** The base class for timelines that use interpolation between key frame values. */ /** The base class for timelines that use interpolation between key frame values. */
export abstract class CurveTimeline extends Timeline { export abstract class CurveTimeline extends Timeline {
static LINEAR = 0; static STEPPED = 1; static BEZIER = 2;
static BEZIER_SIZE = 18;
protected curves: ArrayLike<number>; // type, x, y, ... protected curves: ArrayLike<number>; // type, x, y, ...
constructor (frameCount: number, bezierCount: number, propertyIds: string[]) { constructor (frameCount: number, bezierCount: number, propertyIds: string[]) {
super(frameCount, propertyIds); super(frameCount, propertyIds);
this.curves = Utils.newFloatArray(frameCount + bezierCount * CurveTimeline.BEZIER_SIZE); this.curves = Utils.newFloatArray(frameCount + bezierCount * BEZIER_SIZE);
this.curves[frameCount - 1] = CurveTimeline.STEPPED; this.curves[frameCount - 1] = STEPPED;
} }
/** Sets the specified key frame to linear interpolation. */ /** Sets the specified key frame to linear interpolation. */
setLinear (frame: number) { setLinear (frame: number) {
this.curves[frame] = CurveTimeline.LINEAR; this.curves[frame] = LINEAR;
} }
/** Sets the specified key frame to stepped interpolation. */ /** Sets the specified key frame to stepped interpolation. */
setStepped (frame: number) { setStepped (frame: number) {
this.curves[frame] = CurveTimeline.STEPPED; this.curves[frame] = STEPPED;
} }
/** Shrinks the storage for Bezier curves, for use when <code>bezierCount</code> (specified in the constructor) was larger /** Shrinks the storage for Bezier curves, for use when <code>bezierCount</code> (specified in the constructor) was larger
* than the actual number of Bezier curves. */ * than the actual number of Bezier curves. */
shrink (bezierCount: number) { shrink (bezierCount: number) {
let size = this.getFrameCount() + bezierCount * CurveTimeline.BEZIER_SIZE; let size = this.getFrameCount() + bezierCount * BEZIER_SIZE;
if (this.curves.length > size) { if (this.curves.length > size) {
let newCurves = Utils.newFloatArray(size); let newCurves = Utils.newFloatArray(size);
Utils.arrayCopy(this.curves, 0, newCurves, 0, size); Utils.arrayCopy(this.curves, 0, newCurves, 0, size);
@ -224,14 +242,14 @@ module spine {
setBezier (bezier: number, frame: number, value: number, time1: number, value1: number, cx1: number, cy1: number, cx2: number, setBezier (bezier: number, frame: number, value: number, time1: number, value1: number, cx1: number, cy1: number, cx2: number,
cy2: number, time2: number, value2: number) { cy2: number, time2: number, value2: number) {
let curves = this.curves; let curves = this.curves;
let i = this.getFrameCount() + bezier * CurveTimeline.BEZIER_SIZE; let i = this.getFrameCount() + bezier * BEZIER_SIZE;
if (value == 0) curves[frame] = CurveTimeline.BEZIER + i; if (value == 0) curves[frame] = BEZIER + i;
let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = (value1 - cy1 * 2 + cy2) * 0.03; let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = (value1 - cy1 * 2 + cy2) * 0.03;
let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = ((cy1 - cy2) * 3 - value1 + value2) * 0.006; let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = ((cy1 - cy2) * 3 - value1 + value2) * 0.006;
let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy; let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = (cy1 - value1) * 0.3 + tmpy + dddy * 0.16666667; let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = (cy1 - value1) * 0.3 + tmpy + dddy * 0.16666667;
let x = time1 + dx, y = value1 + dy; let x = time1 + dx, y = value1 + dy;
for (let n = i + CurveTimeline.BEZIER_SIZE; i < n; i += 2) { for (let n = i + BEZIER_SIZE; i < n; i += 2) {
curves[i] = x; curves[i] = x;
curves[i + 1] = y; curves[i + 1] = y;
dx += ddx; dx += ddx;
@ -250,10 +268,10 @@ module spine {
getBezierValue (time: number, frameIndex: number, valueOffset: number, i: number) { getBezierValue (time: number, frameIndex: number, valueOffset: number, i: number) {
let curves = this.curves; let curves = this.curves;
if (curves[i] > time) { if (curves[i] > time) {
let x = frames[frameIndex], y = frames[frameIndex + valueOffset]; let x = this.frames[frameIndex], y = this.frames[frameIndex + valueOffset];
return y + (time - x) / (curves[i] - x) * (curves[i + 1] - y); return y + (time - x) / (curves[i] - x) * (curves[i + 1] - y);
} }
let n = i + CurveTimeline.BEZIER_SIZE; let n = i + BEZIER_SIZE;
for (i += 2; i < n; i += 2) { for (i += 2; i < n; i += 2) {
if (curves[i] >= time) { if (curves[i] >= time) {
let x = curves[i - 2], y = curves[i - 1]; let x = curves[i - 2], y = curves[i - 1];
@ -262,7 +280,7 @@ module spine {
} }
frameIndex += this.getFrameEntries(); frameIndex += this.getFrameEntries();
let x = curves[n - 2], y = curves[n - 1]; let x = curves[n - 2], y = curves[n - 1];
return y + (time - x) / (frames[frameIndex] - x) * (frames[frameIndex + valueOffset] - y); return y + (time - x) / (this.frames[frameIndex] - x) * (this.frames[frameIndex + valueOffset] - y);
} }
} }
@ -300,21 +318,20 @@ module spine {
let curveType = this.curves[i >> 1]; let curveType = this.curves[i >> 1];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i], value = frames[i + CurveTimeline1.VALUE]; let before = frames[i], value = frames[i + CurveTimeline1.VALUE];
return value + (time - before) / (frames[i + CurveTimeline1.ENTRIES] - before) * (frames[i + CurveTimeline1.ENTRIES + CurveTimeline1.VALUE] - value); return value + (time - before) / (frames[i + CurveTimeline1.ENTRIES] - before) * (frames[i + CurveTimeline1.ENTRIES + CurveTimeline1.VALUE] - value);
case CurveTimeline.STEPPED: case STEPPED:
return frames[i + CurveTimeline1.VALUE]; return frames[i + CurveTimeline1.VALUE];
} }
return this.getBezierValue(time, i, CurveTimeline1.VALUE, curveType - CurveTimeline.BEZIER); return this.getBezierValue(time, i, CurveTimeline1.VALUE, curveType - BEZIER);
} }
} }
/** The base class for a {@link CurveTimeline} which sets two properties. */ /** The base class for a {@link CurveTimeline} which sets two properties. */
export abstract class CurveTimeline2 extends CurveTimeline { export abstract class CurveTimeline2 extends CurveTimeline {
static ENTRIES = 3; static ENTRIES = 3;
static VALUE1 = 1; static VALUE1 = 1; static VALUE2 = 2;
static VALUE2 = 2;
/** @param bezierCount The maximum number of Bezier curves. See {@link #shrink(int)}. /** @param bezierCount The maximum number of Bezier curves. See {@link #shrink(int)}.
* @param propertyIds Unique identifiers for the properties the timeline modifies. */ * @param propertyIds Unique identifiers for the properties the timeline modifies. */
@ -412,7 +429,7 @@ module spine {
let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES); let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES);
let curveType = this.curves[i / CurveTimeline2.ENTRIES]; let curveType = this.curves[i / CurveTimeline2.ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
x = frames[i + CurveTimeline2.VALUE1]; x = frames[i + CurveTimeline2.VALUE1];
y = frames[i + CurveTimeline2.VALUE2]; y = frames[i + CurveTimeline2.VALUE2];
@ -420,13 +437,13 @@ module spine {
x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t; x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t;
y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t; y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
x = frames[i + CurveTimeline2.VALUE1]; x = frames[i + CurveTimeline2.VALUE1];
y = frames[i + CurveTimeline2.VALUE2]; y = frames[i + CurveTimeline2.VALUE2];
break; break;
default: default:
x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline.BEZIER); x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - BEZIER);
y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + BEZIER_SIZE - BEZIER);
} }
switch (blend) { switch (blend) {
@ -564,7 +581,7 @@ module spine {
let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES); let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES);
let curveType = this.curves[i / CurveTimeline2.ENTRIES]; let curveType = this.curves[i / CurveTimeline2.ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
x = frames[i + CurveTimeline2.VALUE1]; x = frames[i + CurveTimeline2.VALUE1];
y = frames[i + CurveTimeline2.VALUE2]; y = frames[i + CurveTimeline2.VALUE2];
@ -572,13 +589,13 @@ module spine {
x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t; x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t;
y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t; y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
x = frames[i + CurveTimeline2.VALUE1]; x = frames[i + CurveTimeline2.VALUE1];
y = frames[i + CurveTimeline2.VALUE2]; y = frames[i + CurveTimeline2.VALUE2];
break; break;
default: default:
x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline.BEZIER); x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - BEZIER);
y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + BEZIER_SIZE - BEZIER);
} }
x *= bone.data.scaleX; x *= bone.data.scaleX;
y *= bone.data.scaleY; y *= bone.data.scaleY;
@ -816,7 +833,7 @@ module spine {
let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES); let i = Timeline.search2(frames, time, CurveTimeline2.ENTRIES);
let curveType = this.curves[i / CurveTimeline2.ENTRIES]; let curveType = this.curves[i / CurveTimeline2.ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
x = frames[i + CurveTimeline2.VALUE1]; x = frames[i + CurveTimeline2.VALUE1];
y = frames[i + CurveTimeline2.VALUE2]; y = frames[i + CurveTimeline2.VALUE2];
@ -824,13 +841,13 @@ module spine {
x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t; x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t;
y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t; y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
x = frames[i + CurveTimeline2.VALUE1]; x = frames[i + CurveTimeline2.VALUE1];
y = frames[i + CurveTimeline2.VALUE2]; y = frames[i + CurveTimeline2.VALUE2];
break; break;
default: default:
x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline.BEZIER); x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - BEZIER);
y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + BEZIER_SIZE - BEZIER);
} }
switch (blend) { switch (blend) {
@ -937,7 +954,6 @@ module spine {
/** Changes a slot's {@link Slot#color}. */ /** Changes a slot's {@link Slot#color}. */
export class RGBATimeline extends CurveTimeline implements SlotTimeline { export class RGBATimeline extends CurveTimeline implements SlotTimeline {
static ENTRIES = 5; static ENTRIES = 5;
static R = 1; static G = 2; static B = 3; static A = 4; static R = 1; static G = 2; static B = 3; static A = 4;
slotIndex = 0; slotIndex = 0;
@ -987,7 +1003,7 @@ module spine {
let i = Timeline.search2(frames, time, RGBATimeline.ENTRIES); let i = Timeline.search2(frames, time, RGBATimeline.ENTRIES);
let curveType = this.curves[i / RGBATimeline.ENTRIES]; let curveType = this.curves[i / RGBATimeline.ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
r = frames[i + RGBATimeline.R]; r = frames[i + RGBATimeline.R];
g = frames[i + RGBATimeline.G]; g = frames[i + RGBATimeline.G];
@ -999,17 +1015,17 @@ module spine {
b += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.B] - b) * t; b += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.B] - b) * t;
a += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.A] - a) * t; a += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.A] - a) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
r = frames[i + RGBATimeline.R]; r = frames[i + RGBATimeline.R];
g = frames[i + RGBATimeline.G]; g = frames[i + RGBATimeline.G];
b = frames[i + RGBATimeline.B]; b = frames[i + RGBATimeline.B];
a = frames[i + RGBATimeline.A]; a = frames[i + RGBATimeline.A];
break; break;
default: default:
r = this.getBezierValue(time, i, RGBATimeline.R, curveType - CurveTimeline.BEZIER); r = this.getBezierValue(time, i, RGBATimeline.R, curveType - BEZIER);
g = this.getBezierValue(time, i, RGBATimeline.G, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); g = this.getBezierValue(time, i, RGBATimeline.G, curveType + BEZIER_SIZE - BEZIER);
b = this.getBezierValue(time, i, RGBATimeline.B, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); b = this.getBezierValue(time, i, RGBATimeline.B, curveType + BEZIER_SIZE * 2 - BEZIER);
a = this.getBezierValue(time, i, RGBATimeline.A, curveType + CurveTimeline.BEZIER_SIZE * 3 - CurveTimeline.BEZIER); a = this.getBezierValue(time, i, RGBATimeline.A, curveType + BEZIER_SIZE * 3 - BEZIER);
} }
if (alpha == 1) if (alpha == 1)
color.set(r, g, b, a); color.set(r, g, b, a);
@ -1023,7 +1039,6 @@ module spine {
/** Changes a slot's {@link Slot#color}. */ /** Changes a slot's {@link Slot#color}. */
export class RGBTimeline extends CurveTimeline implements SlotTimeline { export class RGBTimeline extends CurveTimeline implements SlotTimeline {
static ENTRIES = 4; static ENTRIES = 4;
static R = 1; static G = 2; static B = 3; static R = 1; static G = 2; static B = 3;
slotIndex = 0; slotIndex = 0;
@ -1074,7 +1089,7 @@ module spine {
let i = Timeline.search2(frames, time, RGBTimeline.ENTRIES); let i = Timeline.search2(frames, time, RGBTimeline.ENTRIES);
let curveType = this.curves[i >> 2]; let curveType = this.curves[i >> 2];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
r = frames[i + RGBTimeline.R]; r = frames[i + RGBTimeline.R];
g = frames[i + RGBTimeline.G]; g = frames[i + RGBTimeline.G];
@ -1084,15 +1099,15 @@ module spine {
g += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.G] - g) * t; g += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.G] - g) * t;
b += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.B] - b) * t; b += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.B] - b) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
r = frames[i + RGBTimeline.R]; r = frames[i + RGBTimeline.R];
g = frames[i + RGBTimeline.G]; g = frames[i + RGBTimeline.G];
b = frames[i + RGBTimeline.B]; b = frames[i + RGBTimeline.B];
break; break;
default: default:
r = this.getBezierValue(time, i, RGBTimeline.R, curveType - CurveTimeline.BEZIER); r = this.getBezierValue(time, i, RGBTimeline.R, curveType - BEZIER);
g = this.getBezierValue(time, i, RGBTimeline.G, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); g = this.getBezierValue(time, i, RGBTimeline.G, curveType + BEZIER_SIZE - BEZIER);
b = this.getBezierValue(time, i, RGBTimeline.B, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); b = this.getBezierValue(time, i, RGBTimeline.B, curveType + BEZIER_SIZE * 2 - BEZIER);
} }
if (alpha == 1) { if (alpha == 1) {
color.r = r; color.r = r;
@ -1153,7 +1168,6 @@ module spine {
/** Changes a slot's {@link Slot#color} and {@link Slot#darkColor} for two color tinting. */ /** Changes a slot's {@link Slot#color} and {@link Slot#darkColor} for two color tinting. */
export class RGBA2Timeline extends CurveTimeline implements SlotTimeline{ export class RGBA2Timeline extends CurveTimeline implements SlotTimeline{
static ENTRIES = 8; static ENTRIES = 8;
static R = 1; static G = 2; static B = 3; static A = 4; static R2 = 5; static G2 = 6; static B2 = 7; static R = 1; static G = 2; static B = 3; static A = 4; static R2 = 5; static G2 = 6; static B2 = 7;
slotIndex = 0; slotIndex = 0;
@ -1213,7 +1227,7 @@ module spine {
let i = Timeline.search2(frames, time, RGBA2Timeline.ENTRIES); let i = Timeline.search2(frames, time, RGBA2Timeline.ENTRIES);
let curveType = this.curves[i >> 3]; let curveType = this.curves[i >> 3];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
r = frames[i + RGBA2Timeline.R]; r = frames[i + RGBA2Timeline.R];
g = frames[i + RGBA2Timeline.G]; g = frames[i + RGBA2Timeline.G];
@ -1231,7 +1245,7 @@ module spine {
g2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.G2] - g2) * t; g2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.G2] - g2) * t;
b2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.B2] - b2) * t; b2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.B2] - b2) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
r = frames[i + RGBA2Timeline.R]; r = frames[i + RGBA2Timeline.R];
g = frames[i + RGBA2Timeline.G]; g = frames[i + RGBA2Timeline.G];
b = frames[i + RGBA2Timeline.B]; b = frames[i + RGBA2Timeline.B];
@ -1241,13 +1255,13 @@ module spine {
b2 = frames[i + RGBA2Timeline.B2]; b2 = frames[i + RGBA2Timeline.B2];
break; break;
default: default:
r = this.getBezierValue(time, i, RGBA2Timeline.R, curveType - CurveTimeline.BEZIER); r = this.getBezierValue(time, i, RGBA2Timeline.R, curveType - BEZIER);
g = this.getBezierValue(time, i, RGBA2Timeline.G, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); g = this.getBezierValue(time, i, RGBA2Timeline.G, curveType + BEZIER_SIZE - BEZIER);
b = this.getBezierValue(time, i, RGBA2Timeline.B, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); b = this.getBezierValue(time, i, RGBA2Timeline.B, curveType + BEZIER_SIZE * 2 - BEZIER);
a = this.getBezierValue(time, i, RGBA2Timeline.A, curveType + CurveTimeline.BEZIER_SIZE * 3 - CurveTimeline.BEZIER); a = this.getBezierValue(time, i, RGBA2Timeline.A, curveType + BEZIER_SIZE * 3 - BEZIER);
r2 = this.getBezierValue(time, i, RGBA2Timeline.R2, curveType + CurveTimeline.BEZIER_SIZE * 4 - CurveTimeline.BEZIER); r2 = this.getBezierValue(time, i, RGBA2Timeline.R2, curveType + BEZIER_SIZE * 4 - BEZIER);
g2 = this.getBezierValue(time, i, RGBA2Timeline.G2, curveType + CurveTimeline.BEZIER_SIZE * 5 - CurveTimeline.BEZIER); g2 = this.getBezierValue(time, i, RGBA2Timeline.G2, curveType + BEZIER_SIZE * 5 - BEZIER);
b2 = this.getBezierValue(time, i, RGBA2Timeline.B2, curveType + CurveTimeline.BEZIER_SIZE * 6 - CurveTimeline.BEZIER); b2 = this.getBezierValue(time, i, RGBA2Timeline.B2, curveType + BEZIER_SIZE * 6 - BEZIER);
} }
if (alpha == 1) { if (alpha == 1) {
@ -1271,7 +1285,6 @@ module spine {
/** Changes a slot's {@link Slot#color} and {@link Slot#darkColor} for two color tinting. */ /** Changes a slot's {@link Slot#color} and {@link Slot#darkColor} for two color tinting. */
export class RGB2Timeline extends CurveTimeline implements SlotTimeline{ export class RGB2Timeline extends CurveTimeline implements SlotTimeline{
static ENTRIES = 7; static ENTRIES = 7;
static R = 1; static G = 2; static B = 3; static R2 = 4; static G2 = 5; static B2 = 6; static R = 1; static G = 2; static B = 3; static R2 = 4; static G2 = 5; static B2 = 6;
slotIndex = 0; slotIndex = 0;
@ -1332,7 +1345,7 @@ module spine {
let i = Timeline.search2(frames, time, RGB2Timeline.ENTRIES); let i = Timeline.search2(frames, time, RGB2Timeline.ENTRIES);
let curveType = this.curves[i / RGB2Timeline.ENTRIES]; let curveType = this.curves[i / RGB2Timeline.ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
r = frames[i + RGB2Timeline.R]; r = frames[i + RGB2Timeline.R];
g = frames[i + RGB2Timeline.G]; g = frames[i + RGB2Timeline.G];
@ -1348,7 +1361,7 @@ module spine {
g2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.G2] - g2) * t; g2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.G2] - g2) * t;
b2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.B2] - b2) * t; b2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.B2] - b2) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
r = frames[i + RGB2Timeline.R]; r = frames[i + RGB2Timeline.R];
g = frames[i + RGB2Timeline.G]; g = frames[i + RGB2Timeline.G];
b = frames[i + RGB2Timeline.B]; b = frames[i + RGB2Timeline.B];
@ -1357,12 +1370,12 @@ module spine {
b2 = frames[i + RGB2Timeline.B2]; b2 = frames[i + RGB2Timeline.B2];
break; break;
default: default:
r = this.getBezierValue(time, i, RGB2Timeline.R, curveType - CurveTimeline.BEZIER); r = this.getBezierValue(time, i, RGB2Timeline.R, curveType - BEZIER);
g = this.getBezierValue(time, i, RGB2Timeline.G, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); g = this.getBezierValue(time, i, RGB2Timeline.G, curveType + BEZIER_SIZE - BEZIER);
b = this.getBezierValue(time, i, RGB2Timeline.B, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); b = this.getBezierValue(time, i, RGB2Timeline.B, curveType + BEZIER_SIZE * 2 - BEZIER);
r2 = this.getBezierValue(time, i, RGB2Timeline.R2, curveType + CurveTimeline.BEZIER_SIZE * 3 - CurveTimeline.BEZIER); r2 = this.getBezierValue(time, i, RGB2Timeline.R2, curveType + BEZIER_SIZE * 3 - BEZIER);
g2 = this.getBezierValue(time, i, RGB2Timeline.G2, curveType + CurveTimeline.BEZIER_SIZE * 4 - CurveTimeline.BEZIER); g2 = this.getBezierValue(time, i, RGB2Timeline.G2, curveType + BEZIER_SIZE * 4 - BEZIER);
b2 = this.getBezierValue(time, i, RGB2Timeline.B2, curveType + CurveTimeline.BEZIER_SIZE * 5 - CurveTimeline.BEZIER); b2 = this.getBezierValue(time, i, RGB2Timeline.B2, curveType + BEZIER_SIZE * 5 - BEZIER);
} }
if (alpha == 1) { if (alpha == 1) {
@ -1474,14 +1487,14 @@ module spine {
setBezier (bezier: number, frame: number, value: number, time1: number, value1: number, cx1: number, cy1: number, cx2: number, setBezier (bezier: number, frame: number, value: number, time1: number, value1: number, cx1: number, cy1: number, cx2: number,
cy2: number, time2: number, value2: number) { cy2: number, time2: number, value2: number) {
let curves = this.curves; let curves = this.curves;
let i = this.getFrameCount() + bezier * CurveTimeline.BEZIER_SIZE; let i = this.getFrameCount() + bezier * BEZIER_SIZE;
if (value == 0) curves[frame] = CurveTimeline.BEZIER + i; if (value == 0) curves[frame] = BEZIER + i;
let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = cy2 * 0.03 - cy1 * 0.06; let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = cy2 * 0.03 - cy1 * 0.06;
let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = (cy1 - cy2 + 0.33333333) * 0.018; let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = (cy1 - cy2 + 0.33333333) * 0.018;
let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy; let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = cy1 * 0.3 + tmpy + dddy * 0.16666667; let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = cy1 * 0.3 + tmpy + dddy * 0.16666667;
let x = time1 + dx, y = dy; let x = time1 + dx, y = dy;
for (let n = i + CurveTimeline.BEZIER_SIZE; i < n; i += 2) { for (let n = i + BEZIER_SIZE; i < n; i += 2) {
curves[i] = x; curves[i] = x;
curves[i + 1] = y; curves[i + 1] = y;
dx += ddx; dx += ddx;
@ -1497,18 +1510,18 @@ module spine {
let curves = this.curves; let curves = this.curves;
let i = curves[frame]; let i = curves[frame];
switch (i) { switch (i) {
case CurveTimeline.LINEAR: case LINEAR:
let x = frames[frame]; let x = this.frames[frame];
return (time - x) / (frames[frame + this.getFrameEntries()] - x); return (time - x) / (this.frames[frame + this.getFrameEntries()] - x);
case CurveTimeline.STEPPED: case STEPPED:
return 0; return 0;
} }
i -= CurveTimeline.BEZIER; i -= BEZIER;
if (curves[i] > time) { if (curves[i] > time) {
let x = frames[frame]; let x = this.frames[frame];
return curves[i + 1] * (time - x) / (curves[i] - x); return curves[i + 1] * (time - x) / (curves[i] - x);
} }
let n = i + CurveTimeline.BEZIER_SIZE; let n = i + BEZIER_SIZE;
for (i += 2; i < n; i += 2) { for (i += 2; i < n; i += 2) {
if (curves[i] >= time) { if (curves[i] >= time) {
let x = curves[i - 2], y = curves[i - 1]; let x = curves[i - 2], y = curves[i - 1];
@ -1516,7 +1529,7 @@ module spine {
} }
} }
let x = curves[n - 2], y = curves[n - 1]; let x = curves[n - 2], y = curves[n - 1];
return y + (1 - y) * (time - x) / (frames[frame + this.getFrameEntries()] - x); return y + (1 - y) * (time - x) / (this.frames[frame + this.getFrameEntries()] - x);
} }
apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection) { apply (skeleton: Skeleton, lastTime: number, time: number, firedEvents: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection) {
@ -1777,12 +1790,12 @@ module spine {
return; return;
} }
if (time < frames[0]) { if (time < this.frames[0]) {
if (blend == MixBlend.setup || blend == MixBlend.first) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); if (blend == MixBlend.setup || blend == MixBlend.first) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
return; return;
} }
let drawOrderToSetupIndex = this.drawOrders[Timeline.search(frames, time)]; let drawOrderToSetupIndex = this.drawOrders[Timeline.search(this.frames, time)];
if (drawOrderToSetupIndex == null) if (drawOrderToSetupIndex == null)
Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
else { else {
@ -1798,7 +1811,6 @@ module spine {
* {@link IkConstraint#bendDirection}, {@link IkConstraint#stretch}, and {@link IkConstraint#compress}. */ * {@link IkConstraint#bendDirection}, {@link IkConstraint#stretch}, and {@link IkConstraint#compress}. */
export class IkConstraintTimeline extends CurveTimeline { export class IkConstraintTimeline extends CurveTimeline {
static ENTRIES = 6; static ENTRIES = 6;
static MIX = 1; static SOFTNESS = 2; static BEND_DIRECTION = 3; static COMPRESS = 4; static STRETCH = 5; static MIX = 1; static SOFTNESS = 2; static BEND_DIRECTION = 3; static COMPRESS = 4; static STRETCH = 5;
/** The index of the IK constraint slot in {@link Skeleton#ikConstraints} that will be changed. */ /** The index of the IK constraint slot in {@link Skeleton#ikConstraints} that will be changed. */
@ -1854,7 +1866,7 @@ module spine {
let i = Timeline.search2(frames, time, IkConstraintTimeline.ENTRIES) let i = Timeline.search2(frames, time, IkConstraintTimeline.ENTRIES)
let curveType = this.curves[i / IkConstraintTimeline.ENTRIES]; let curveType = this.curves[i / IkConstraintTimeline.ENTRIES];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
mix = frames[i + IkConstraintTimeline.MIX]; mix = frames[i + IkConstraintTimeline.MIX];
softness = frames[i + IkConstraintTimeline.SOFTNESS]; softness = frames[i + IkConstraintTimeline.SOFTNESS];
@ -1862,13 +1874,13 @@ module spine {
mix += (frames[i + IkConstraintTimeline.ENTRIES + IkConstraintTimeline.MIX] - mix) * t; mix += (frames[i + IkConstraintTimeline.ENTRIES + IkConstraintTimeline.MIX] - mix) * t;
softness += (frames[i + IkConstraintTimeline.ENTRIES + IkConstraintTimeline.SOFTNESS] - softness) * t; softness += (frames[i + IkConstraintTimeline.ENTRIES + IkConstraintTimeline.SOFTNESS] - softness) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
mix = frames[i + IkConstraintTimeline.MIX]; mix = frames[i + IkConstraintTimeline.MIX];
softness = frames[i + IkConstraintTimeline.SOFTNESS]; softness = frames[i + IkConstraintTimeline.SOFTNESS];
break; break;
default: default:
mix = this.getBezierValue(time, i, IkConstraintTimeline.MIX, curveType - CurveTimeline.BEZIER); mix = this.getBezierValue(time, i, IkConstraintTimeline.MIX, curveType - BEZIER);
softness = this.getBezierValue(time, i, IkConstraintTimeline.SOFTNESS, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); softness = this.getBezierValue(time, i, IkConstraintTimeline.SOFTNESS, curveType + BEZIER_SIZE - BEZIER);
} }
if (blend == MixBlend.setup) { if (blend == MixBlend.setup) {
@ -1900,7 +1912,6 @@ module spine {
* {@link TransformConstraint#scaleMix}, and {@link TransformConstraint#shearMix}. */ * {@link TransformConstraint#scaleMix}, and {@link TransformConstraint#shearMix}. */
export class TransformConstraintTimeline extends CurveTimeline { export class TransformConstraintTimeline extends CurveTimeline {
static ENTRIES = 7; static ENTRIES = 7;
static ROTATE = 1; static X = 2; static Y = 3; static SCALEX = 4; static SCALEY = 5; static SHEARY = 6; static ROTATE = 1; static X = 2; static Y = 3; static SCALEX = 4; static SCALEY = 5; static SHEARY = 6;
/** The index of the transform constraint slot in {@link Skeleton#transformConstraints} that will be changed. */ /** The index of the transform constraint slot in {@link Skeleton#transformConstraints} that will be changed. */
@ -1958,18 +1969,17 @@ module spine {
return; return;
} }
let rotate, x, y, scaleX, scaleY, shearY; let X = TransformConstraintTimeline.X, Y = TransformConstraintTimeline.Y;
let i = Timeline.search2(frames, time, TransformConstraintTimeline.ENTRIES); let SCALEX = TransformConstraintTimeline.SCALEX, SCALEY = TransformConstraintTimeline.SCALEY;
let curveType = this.curves[i / TransformConstraintTimeline.ENTRIES];
let ROTATE = TransformConstraintTimeline.ROTATE;
let X = TransformConstraintTimeline.X;
let Y = TransformConstraintTimeline.Y;
let SCALEX = TransformConstraintTimeline.SCALEX;
let SCALEY = TransformConstraintTimeline.SCALEY;
let SHEARY = TransformConstraintTimeline.SHEARY; let SHEARY = TransformConstraintTimeline.SHEARY;
let ENTRIES = TransformConstraintTimeline.ENTRIES; let ENTRIES = TransformConstraintTimeline.ENTRIES;
let rotate, x, y, scaleX, scaleY, shearY;
let i = Timeline.search2(frames, time, ENTRIES);
let curveType = this.curves[i / ENTRIES];
let ROTATE = TransformConstraintTimeline.ROTATE;
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
rotate = frames[i + ROTATE]; rotate = frames[i + ROTATE];
x = frames[i + X]; x = frames[i + X];
@ -1985,7 +1995,7 @@ module spine {
scaleY += (frames[i + ENTRIES + SCALEY] - scaleY) * t; scaleY += (frames[i + ENTRIES + SCALEY] - scaleY) * t;
shearY += (frames[i + ENTRIES + SHEARY] - shearY) * t; shearY += (frames[i + ENTRIES + SHEARY] - shearY) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
rotate = frames[i + ROTATE]; rotate = frames[i + ROTATE];
x = frames[i + X]; x = frames[i + X];
y = frames[i + Y]; y = frames[i + Y];
@ -1994,12 +2004,12 @@ module spine {
shearY = frames[i + SHEARY]; shearY = frames[i + SHEARY];
break; break;
default: default:
rotate = this.getBezierValue(time, i, ROTATE, curveType - CurveTimeline.BEZIER); rotate = this.getBezierValue(time, i, ROTATE, curveType - BEZIER);
x = this.getBezierValue(time, i, X, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); x = this.getBezierValue(time, i, X, curveType + BEZIER_SIZE - BEZIER);
y = this.getBezierValue(time, i, Y, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); y = this.getBezierValue(time, i, Y, curveType + BEZIER_SIZE * 2 - BEZIER);
scaleX = this.getBezierValue(time, i, SCALEX, curveType + CurveTimeline.BEZIER_SIZE * 3 - CurveTimeline.BEZIER); scaleX = this.getBezierValue(time, i, SCALEX, curveType + BEZIER_SIZE * 3 - BEZIER);
scaleY = this.getBezierValue(time, i, SCALEY, curveType + CurveTimeline.BEZIER_SIZE * 4 - CurveTimeline.BEZIER); scaleY = this.getBezierValue(time, i, SCALEY, curveType + BEZIER_SIZE * 4 - BEZIER);
shearY = this.getBezierValue(time, i, SHEARY, curveType + CurveTimeline.BEZIER_SIZE * 5 - CurveTimeline.BEZIER); shearY = this.getBezierValue(time, i, SHEARY, curveType + BEZIER_SIZE * 5 - BEZIER);
} }
if (blend == MixBlend.setup) { if (blend == MixBlend.setup) {
@ -2148,7 +2158,7 @@ module spine {
let i = Timeline.search2(frames, time, PathConstraintMixTimeline.ENTRIES); let i = Timeline.search2(frames, time, PathConstraintMixTimeline.ENTRIES);
let curveType = this.curves[i >> 2]; let curveType = this.curves[i >> 2];
switch (curveType) { switch (curveType) {
case CurveTimeline.LINEAR: case LINEAR:
let before = frames[i]; let before = frames[i];
rotate = frames[i + PathConstraintMixTimeline.ROTATE]; rotate = frames[i + PathConstraintMixTimeline.ROTATE];
x = frames[i + PathConstraintMixTimeline.X]; x = frames[i + PathConstraintMixTimeline.X];
@ -2158,15 +2168,15 @@ module spine {
x += (frames[i + PathConstraintMixTimeline.ENTRIES + PathConstraintMixTimeline.X] - x) * t; x += (frames[i + PathConstraintMixTimeline.ENTRIES + PathConstraintMixTimeline.X] - x) * t;
y += (frames[i + PathConstraintMixTimeline.ENTRIES + PathConstraintMixTimeline.Y] - y) * t; y += (frames[i + PathConstraintMixTimeline.ENTRIES + PathConstraintMixTimeline.Y] - y) * t;
break; break;
case CurveTimeline.STEPPED: case STEPPED:
rotate = frames[i + PathConstraintMixTimeline.ROTATE]; rotate = frames[i + PathConstraintMixTimeline.ROTATE];
x = frames[i + PathConstraintMixTimeline.X]; x = frames[i + PathConstraintMixTimeline.X];
y = frames[i + PathConstraintMixTimeline.Y]; y = frames[i + PathConstraintMixTimeline.Y];
break; break;
default: default:
rotate = this.getBezierValue(time, i, PathConstraintMixTimeline.ROTATE, curveType - CurveTimeline.BEZIER); rotate = this.getBezierValue(time, i, PathConstraintMixTimeline.ROTATE, curveType - BEZIER);
x = this.getBezierValue(time, i, PathConstraintMixTimeline.X, curveType + CurveTimeline.BEZIER_SIZE - CurveTimeline.BEZIER); x = this.getBezierValue(time, i, PathConstraintMixTimeline.X, curveType + BEZIER_SIZE - BEZIER);
y = this.getBezierValue(time, i, PathConstraintMixTimeline.Y, curveType + CurveTimeline.BEZIER_SIZE * 2 - CurveTimeline.BEZIER); y = this.getBezierValue(time, i, PathConstraintMixTimeline.Y, curveType + BEZIER_SIZE * 2 - BEZIER);
} }
if (blend == MixBlend.setup) { if (blend == MixBlend.setup) {

View File

@ -34,51 +34,11 @@ module spine {
* *
* See [Applying Animations](http://esotericsoftware.com/spine-applying-animations/) in the Spine Runtimes Guide. */ * See [Applying Animations](http://esotericsoftware.com/spine-applying-animations/) in the Spine Runtimes Guide. */
export class AnimationState { export class AnimationState {
private static _emptyAnimation: Animation = null;
private static emptyAnimation(): Animation { private static emptyAnimation(): Animation {
if (AnimationState._emptyAnimation == null) AnimationState._emptyAnimation = new Animation("<empty>", [], 0); if (_emptyAnimation == null) _emptyAnimation = new Animation("<empty>", [], 0);
return AnimationState._emptyAnimation; return _emptyAnimation;
} }
/** 1. A previously applied timeline has set this property.
*
* Result: Mix from the current pose to the timeline pose. */
static SUBSEQUENT = 0;
/** 1. This is the first timeline to set this property.
* 2. The next track entry applied after this one does not have a timeline to set this property.
*
* Result: Mix from the setup pose to the timeline pose. */
static FIRST = 1;
/** 1) A previously applied timeline has set this property.<br>
* 2) The next track entry to be applied does have a timeline to set this property.<br>
* 3) The next track entry after that one does not have a timeline to set this property.<br>
* Result: Mix from the current pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading
* animations that key the same property. A subsequent timeline will set this property using a mix. */
static HOLD_SUBSEQUENT = 2;
/** 1) This is the first timeline to set this property.<br>
* 2) The next track entry to be applied does have a timeline to set this property.<br>
* 3) The next track entry after that one does not have a timeline to set this property.<br>
* Result: Mix from the setup pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading animations
* that key the same property. A subsequent timeline will set this property using a mix. */
static HOLD_FIRST = 3;
/** 1. This is the first timeline to set this property.
* 2. The next track entry to be applied does have a timeline to set this property.
* 3. The next track entry after that one does have a timeline to set this property.
* 4. timelineHoldMix stores the first subsequent track entry that does not have a timeline to set this property.
*
* Result: The same as HOLD except the mix percentage from the timelineHoldMix track entry is used. This handles when more than
* 2 track entries in a row have a timeline that sets the same property.
*
* Eg, A -> B -> C -> D where A, B, and C have a timeline setting same property, but D does not. When A is applied, to avoid
* "dipping" A is not mixed out, however D (the first entry that doesn't set the property) mixing in is used to mix out A
* (which affects B and C). Without using D to mix out, A would be applied fully until mixing completes, then snap into
* place. */
static HOLD_MIX = 4;
static SETUP = 1;
static CURRENT = 2;
/** The AnimationStateData to look up mix durations. */ /** The AnimationStateData to look up mix durations. */
data: AnimationStateData; data: AnimationStateData;
@ -243,7 +203,7 @@ 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 timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : MixBlend.setup; let timelineBlend = timelineMode[ii] == SUBSEQUENT ? blend : MixBlend.setup;
if (timeline instanceof RotateTimeline) { if (timeline instanceof RotateTimeline) {
this.applyRotateTimeline(timeline, skeleton, applyTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); this.applyRotateTimeline(timeline, skeleton, applyTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
} else if (timeline instanceof AttachmentTimeline) { } else if (timeline instanceof AttachmentTimeline) {
@ -264,7 +224,7 @@ module spine {
// Set slots attachments to the setup pose, if needed. This occurs if an animation that is mixing out sets attachments so // Set slots attachments to the setup pose, if needed. This occurs if an animation that is mixing out sets attachments so
// subsequent timelines see any deform, but the subsequent timelines don't set an attachment (eg they are also mixing out or // subsequent timelines see any deform, but the subsequent timelines don't set an attachment (eg they are also mixing out or
// the time is before the first key). // the time is before the first key).
var setupState = this.unkeyedState + AnimationState.SETUP; var setupState = this.unkeyedState + SETUP;
var slots = skeleton.slots; var slots = skeleton.slots;
for (var i = 0, n = skeleton.slots.length; i < n; i++) { for (var i = 0, n = skeleton.slots.length; i < n; i++) {
var slot = slots[i]; var slot = slots[i];
@ -322,20 +282,20 @@ module spine {
let timelineBlend: MixBlend; let timelineBlend: MixBlend;
let alpha = 0; let alpha = 0;
switch (timelineMode[i]) { switch (timelineMode[i]) {
case AnimationState.SUBSEQUENT: case SUBSEQUENT:
if (!drawOrder && timeline instanceof DrawOrderTimeline) continue; if (!drawOrder && timeline instanceof DrawOrderTimeline) continue;
timelineBlend = blend; timelineBlend = blend;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.FIRST: case FIRST:
timelineBlend = MixBlend.setup; timelineBlend = MixBlend.setup;
alpha = alphaMix; alpha = alphaMix;
break; break;
case AnimationState.HOLD_SUBSEQUENT: case HOLD_SUBSEQUENT:
timelineBlend = blend; timelineBlend = blend;
alpha = alphaHold; alpha = alphaHold;
break; break;
case AnimationState.HOLD_FIRST: case HOLD_FIRST:
timelineBlend = MixBlend.setup; timelineBlend = MixBlend.setup;
alpha = alphaHold; alpha = alphaHold;
break; break;
@ -381,12 +341,12 @@ module spine {
this.setAttachment(skeleton, slot, timeline.attachmentNames[Timeline.search(frames, time)], attachments); this.setAttachment(skeleton, slot, timeline.attachmentNames[Timeline.search(frames, time)], attachments);
// If an attachment wasn't set (ie before the first frame or attachments is false), set the setup attachment later. // If an attachment wasn't set (ie before the first frame or attachments is false), set the setup attachment later.
if (slot.attachmentState <= this.unkeyedState) slot.attachmentState = this.unkeyedState + AnimationState.SETUP; if (slot.attachmentState <= this.unkeyedState) slot.attachmentState = this.unkeyedState + SETUP;
} }
setAttachment (skeleton: Skeleton, slot: Slot, attachmentName: string, attachments: boolean) { setAttachment (skeleton: Skeleton, slot: Slot, attachmentName: string, attachments: boolean) {
slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(slot.data.index, attachmentName)); slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(slot.data.index, attachmentName));
if (attachments) slot.attachmentState = this.unkeyedState + AnimationState.CURRENT; if (attachments) slot.attachmentState = this.unkeyedState + CURRENT;
} }
applyRotateTimeline (timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, blend: MixBlend, applyRotateTimeline (timeline: Timeline, skeleton: Skeleton, time: number, alpha: number, blend: MixBlend,
@ -755,7 +715,7 @@ module spine {
if (to != null && to.holdPrevious) { if (to != null && to.holdPrevious) {
for (let i = 0; i < timelinesCount; i++) for (let i = 0; i < timelinesCount; i++)
timelineMode[i] = propertyIDs.addAll(timelines[i].getPropertyIds()) ? AnimationState.HOLD_FIRST : AnimationState.HOLD_SUBSEQUENT; timelineMode[i] = propertyIDs.addAll(timelines[i].getPropertyIds()) ? HOLD_FIRST : HOLD_SUBSEQUENT;
return; return;
} }
@ -764,21 +724,21 @@ module spine {
let timeline = timelines[i]; let timeline = timelines[i];
let ids = timeline.getPropertyIds(); let ids = timeline.getPropertyIds();
if (!propertyIDs.addAll(ids)) if (!propertyIDs.addAll(ids))
timelineMode[i] = AnimationState.SUBSEQUENT; timelineMode[i] = SUBSEQUENT;
else if (to == null || timeline instanceof AttachmentTimeline || timeline instanceof DrawOrderTimeline else if (to == null || timeline instanceof AttachmentTimeline || timeline instanceof DrawOrderTimeline
|| timeline instanceof EventTimeline || !to.animation.hasTimeline(ids)) { || timeline instanceof EventTimeline || !to.animation.hasTimeline(ids)) {
timelineMode[i] = AnimationState.FIRST; timelineMode[i] = FIRST;
} else { } else {
for (let next = to.mixingTo; next != null; next = next.mixingTo) { for (let next = to.mixingTo; next != null; next = next.mixingTo) {
if (next.animation.hasTimeline(ids)) continue; if (next.animation.hasTimeline(ids)) continue;
if (entry.mixDuration > 0) { if (entry.mixDuration > 0) {
timelineMode[i] = AnimationState.HOLD_MIX; timelineMode[i] = HOLD_MIX;
timelineHoldMix[i] = next; timelineHoldMix[i] = next;
continue outer; continue outer;
} }
break; break;
} }
timelineMode[i] = AnimationState.HOLD_FIRST; timelineMode[i] = HOLD_FIRST;
} }
} }
} }
@ -1176,4 +1136,44 @@ module spine {
event (entry: TrackEntry, event: Event) { event (entry: TrackEntry, event: Event) {
} }
} }
/** 1. A previously applied timeline has set this property.
*
* Result: Mix from the current pose to the timeline pose. */
const SUBSEQUENT = 0;
/** 1. This is the first timeline to set this property.
* 2. The next track entry applied after this one does not have a timeline to set this property.
*
* Result: Mix from the setup pose to the timeline pose. */
const FIRST = 1;
/** 1) A previously applied timeline has set this property.<br>
* 2) The next track entry to be applied does have a timeline to set this property.<br>
* 3) The next track entry after that one does not have a timeline to set this property.<br>
* Result: Mix from the current pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading
* animations that key the same property. A subsequent timeline will set this property using a mix. */
const HOLD_SUBSEQUENT = 2;
/** 1) This is the first timeline to set this property.<br>
* 2) The next track entry to be applied does have a timeline to set this property.<br>
* 3) The next track entry after that one does not have a timeline to set this property.<br>
* Result: Mix from the setup pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading animations
* that key the same property. A subsequent timeline will set this property using a mix. */
const HOLD_FIRST = 3;
/** 1. This is the first timeline to set this property.
* 2. The next track entry to be applied does have a timeline to set this property.
* 3. The next track entry after that one does have a timeline to set this property.
* 4. timelineHoldMix stores the first subsequent track entry that does not have a timeline to set this property.
*
* Result: The same as HOLD except the mix percentage from the timelineHoldMix track entry is used. This handles when more than
* 2 track entries in a row have a timeline that sets the same property.
*
* Eg, A -> B -> C -> D where A, B, and C have a timeline setting same property, but D does not. When A is applied, to avoid
* "dipping" A is not mixed out, however D (the first entry that doesn't set the property) mixing in is used to mix out A
* (which affects B and C). Without using D to mix out, A would be applied fully until mixing completes, then snap into
* place. */
const HOLD_MIX = 4;
const SETUP = 1;
const CURRENT = 2;
let _emptyAnimation: Animation = null;
} }

View File

@ -1,39 +0,0 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
module spine {
/** Determines how images are blended with existing pixels when drawn. */
export enum BlendMode {
Normal,
Additive,
Multiply,
Screen
}
}

View File

@ -86,7 +86,5 @@ module spine {
} }
/** Determines how a bone inherits world transforms from parent bones. */ /** Determines how a bone inherits world transforms from parent bones. */
export enum TransformMode { export enum TransformMode { Normal, OnlyTranslation, NoRotationOrReflection, NoScale, NoScaleOrReflection }
Normal, OnlyTranslation, NoRotationOrReflection, NoScale, NoScaleOrReflection
}
} }

View File

@ -70,21 +70,15 @@ module spine {
/** Controls how the first bone is positioned along the path. /** Controls how the first bone is positioned along the path.
* *
* See [position](http://esotericsoftware.com/spine-path-constraints#Position) in the Spine User Guide. */ * See [position](http://esotericsoftware.com/spine-path-constraints#Position) in the Spine User Guide. */
export enum PositionMode { export enum PositionMode { Fixed, Percent }
Fixed, Percent
}
/** Controls how bones after the first bone are positioned along the path. /** Controls how bones after the first bone are positioned along the path.
* *
* See [spacing](http://esotericsoftware.com/spine-path-constraints#Spacing) in the Spine User Guide. */ * See [spacing](http://esotericsoftware.com/spine-path-constraints#Spacing) in the Spine User Guide. */
export enum SpacingMode { export enum SpacingMode { Length, Fixed, Percent, Proportional }
Length, Fixed, Percent, Proportional
}
/** Controls how bones are rotated, translated, and scaled to match the path. /** Controls how bones are rotated, translated, and scaled to match the path.
* *
* See [rotate mix](http://esotericsoftware.com/spine-path-constraints#Rotate-mix) in the Spine User Guide. */ * See [rotate mix](http://esotericsoftware.com/spine-path-constraints#Rotate-mix) in the Spine User Guide. */
export enum RotateMode { export enum RotateMode { Tangent, Chain, ChainScale }
Tangent, Chain, ChainScale
}
} }

View File

@ -34,39 +34,6 @@ module spine {
* [JSON and binary data](http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data) in the Spine * [JSON and binary data](http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data) in the Spine
* Runtimes Guide. */ * Runtimes Guide. */
export class SkeletonBinary { export class SkeletonBinary {
static AttachmentTypeValues = [ 0 /*AttachmentType.Region*/, 1/*AttachmentType.BoundingBox*/, 2/*AttachmentType.Mesh*/, 3/*AttachmentType.LinkedMesh*/, 4/*AttachmentType.Path*/, 5/*AttachmentType.Point*/, 6/*AttachmentType.Clipping*/ ];
static TransformModeValues = [TransformMode.Normal, TransformMode.OnlyTranslation, TransformMode.NoRotationOrReflection, TransformMode.NoScale, TransformMode.NoScaleOrReflection];
static PositionModeValues = [ PositionMode.Fixed, PositionMode.Percent ];
static SpacingModeValues = [ SpacingMode.Length, SpacingMode.Fixed, SpacingMode.Percent];
static RotateModeValues = [ RotateMode.Tangent, RotateMode.Chain, RotateMode.ChainScale ];
static BlendModeValues = [ BlendMode.Normal, BlendMode.Additive, BlendMode.Multiply, BlendMode.Screen];
static BONE_ROTATE = 0;
static BONE_TRANSLATE = 1;
static BONE_TRANSLATEX = 2;
static BONE_TRANSLATEY = 3;
static BONE_SCALE = 4;
static BONE_SCALEX = 5;
static BONE_SCALEY = 6;
static BONE_SHEAR = 7;
static BONE_SHEARX = 8;
static BONE_SHEARY = 9;
static SLOT_ATTACHMENT = 0;
static SLOT_RGBA = 1;
static SLOT_RGB = 2;
static SLOT_RGBA2 = 3;
static SLOT_RGB2 = 4;
static SLOT_ALPHA = 5;
static PATH_POSITION = 0;
static PATH_SPACING = 1;
static PATH_MIX = 2;
static CURVE_LINEAR = 0;
static CURVE_STEPPED = 1;
static CURVE_BEZIER = 2;
/** Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at /** Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at
* runtime than were used in Spine. * runtime than were used in Spine.
* *
@ -125,7 +92,7 @@ module spine {
data.shearX = input.readFloat(); data.shearX = input.readFloat();
data.shearY = input.readFloat(); data.shearY = input.readFloat();
data.length = input.readFloat() * scale; data.length = input.readFloat() * scale;
data.transformMode = SkeletonBinary.TransformModeValues[input.readInt(true)]; data.transformMode = input.readInt(true);
data.skinRequired = input.readBoolean(); data.skinRequired = input.readBoolean();
if (nonessential) Color.rgba8888ToColor(data.color, input.readInt32()); if (nonessential) Color.rgba8888ToColor(data.color, input.readInt32());
skeletonData.bones.push(data); skeletonData.bones.push(data);
@ -143,7 +110,7 @@ module spine {
if (darkColor != -1) Color.rgb888ToColor(data.darkColor = new Color(), darkColor); if (darkColor != -1) Color.rgb888ToColor(data.darkColor = new Color(), darkColor);
data.attachmentName = input.readStringRef(); data.attachmentName = input.readStringRef();
data.blendMode = SkeletonBinary.BlendModeValues[input.readInt(true)]; data.blendMode = input.readInt(true);
skeletonData.slots.push(data); skeletonData.slots.push(data);
} }
@ -203,9 +170,9 @@ module spine {
for (let ii = 0; ii < nn; ii++) for (let ii = 0; ii < nn; ii++)
data.bones.push(skeletonData.bones[input.readInt(true)]); data.bones.push(skeletonData.bones[input.readInt(true)]);
data.target = skeletonData.slots[input.readInt(true)]; data.target = skeletonData.slots[input.readInt(true)];
data.positionMode = SkeletonBinary.PositionModeValues[input.readInt(true)]; data.positionMode = input.readInt(true);
data.spacingMode = SkeletonBinary.SpacingModeValues[input.readInt(true)]; data.spacingMode = input.readInt(true);
data.rotateMode = SkeletonBinary.RotateModeValues[input.readInt(true)]; data.rotateMode = input.readInt(true);
data.offsetRotation = input.readFloat(); data.offsetRotation = input.readFloat();
data.position = input.readFloat(); data.position = input.readFloat();
if (data.positionMode == PositionMode.Fixed) data.position *= scale; if (data.positionMode == PositionMode.Fixed) data.position *= scale;
@ -309,8 +276,7 @@ module spine {
let name = input.readStringRef(); let name = input.readStringRef();
if (name == null) name = attachmentName; if (name == null) name = attachmentName;
let typeIndex = input.readByte(); switch (input.readByte()) {
switch (SkeletonBinary.AttachmentTypeValues[typeIndex]) {
case AttachmentType.Region: { case AttachmentType.Region: {
let path = input.readStringRef(); let path = input.readStringRef();
let rotation = input.readFloat(); let rotation = input.readFloat();
@ -523,14 +489,14 @@ module spine {
let frameCount = input.readInt(true); let frameCount = input.readInt(true);
let frameLast = frameCount - 1; let frameLast = frameCount - 1;
switch (timelineType) { switch (timelineType) {
case SkeletonBinary.SLOT_ATTACHMENT: { case SLOT_ATTACHMENT: {
let timeline = new AttachmentTimeline(frameCount, slotIndex); let timeline = new AttachmentTimeline(frameCount, slotIndex);
for (let frame = 0; frame < frameCount; frame++) for (let frame = 0; frame < frameCount; frame++)
timeline.setFrame(frame, input.readFloat(), input.readStringRef()); timeline.setFrame(frame, input.readFloat(), input.readStringRef());
timelines.push(timeline); timelines.push(timeline);
break; break;
} }
case SkeletonBinary.SLOT_RGBA: { case SLOT_RGBA: {
let bezierCount = input.readInt(true); let bezierCount = input.readInt(true);
let timeline = new RGBATimeline(frameCount, bezierCount, slotIndex); let timeline = new RGBATimeline(frameCount, bezierCount, slotIndex);
@ -551,14 +517,14 @@ module spine {
let a2 = input.readUnsignedByte() / 255.0; let a2 = input.readUnsignedByte() / 255.0;
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1); setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1); setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 3, time, time2, a, a2, 1); setBezier(input, timeline, bezier++, frame, 3, time, time2, a, a2, 1);
} }
time = time2; time = time2;
r = r2; r = r2;
@ -569,7 +535,7 @@ module spine {
timelines.push(timeline); timelines.push(timeline);
break; break;
} }
case SkeletonBinary.SLOT_RGB: { case SLOT_RGB: {
let bezierCount = input.readInt(true); let bezierCount = input.readInt(true);
let timeline = new RGBTimeline(frameCount, bezierCount, slotIndex); let timeline = new RGBTimeline(frameCount, bezierCount, slotIndex);
@ -588,13 +554,13 @@ module spine {
let b2 = input.readUnsignedByte() / 255.0; let b2 = input.readUnsignedByte() / 255.0;
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1); setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1); setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
} }
time = time2; time = time2;
r = r2; r = r2;
@ -604,7 +570,7 @@ module spine {
timelines.push(timeline); timelines.push(timeline);
break; break;
} }
case SkeletonBinary.SLOT_RGBA2: { case SLOT_RGBA2: {
let bezierCount = input.readInt(true); let bezierCount = input.readInt(true);
let timeline = new RGBA2Timeline(frameCount, bezierCount, slotIndex); let timeline = new RGBA2Timeline(frameCount, bezierCount, slotIndex);
@ -630,17 +596,17 @@ module spine {
let nb2 = input.readUnsignedByte() / 255.0; let nb2 = input.readUnsignedByte() / 255.0;
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1); setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1); setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 3, time, time2, a, na, 1); setBezier(input, timeline, bezier++, frame, 3, time, time2, a, na, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 4, time, time2, r2, nr2, 1); setBezier(input, timeline, bezier++, frame, 4, time, time2, r2, nr2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 5, time, time2, g2, ng2, 1); setBezier(input, timeline, bezier++, frame, 5, time, time2, g2, ng2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 6, time, time2, b2, nb2, 1); setBezier(input, timeline, bezier++, frame, 6, time, time2, b2, nb2, 1);
} }
time = time2; time = time2;
r = nr; r = nr;
@ -654,7 +620,7 @@ module spine {
timelines.push(timeline); timelines.push(timeline);
break; break;
} }
case SkeletonBinary.SLOT_RGB2: { case SLOT_RGB2: {
let bezierCount = input.readInt(true); let bezierCount = input.readInt(true);
let timeline = new RGB2Timeline(frameCount, bezierCount, slotIndex); let timeline = new RGB2Timeline(frameCount, bezierCount, slotIndex);
@ -678,16 +644,16 @@ module spine {
let nb2 = input.readUnsignedByte() / 255.0; let nb2 = input.readUnsignedByte() / 255.0;
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1); setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1); setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 3, time, time2, r2, nr2, 1); setBezier(input, timeline, bezier++, frame, 3, time, time2, r2, nr2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 4, time, time2, g2, ng2, 1); setBezier(input, timeline, bezier++, frame, 4, time, time2, g2, ng2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 5, time, time2, b2, nb2, 1); setBezier(input, timeline, bezier++, frame, 5, time, time2, b2, nb2, 1);
} }
time = time2; time = time2;
r = nr; r = nr;
@ -700,7 +666,7 @@ module spine {
timelines.push(timeline); timelines.push(timeline);
break; break;
} }
case SkeletonBinary.SLOT_ALPHA: { case SLOT_ALPHA: {
let timeline = new AlphaTimeline(frameCount, input.readInt(true), slotIndex); let timeline = new AlphaTimeline(frameCount, input.readInt(true), slotIndex);
let time = input.readFloat(), a = input.readUnsignedByte() / 255; let time = input.readFloat(), a = input.readUnsignedByte() / 255;
for (let frame = 0, bezier = 0;; frame++) { for (let frame = 0, bezier = 0;; frame++) {
@ -709,11 +675,11 @@ module spine {
let time2 = input.readFloat(); let time2 = input.readFloat();
let a2 = input.readUnsignedByte() / 255; let a2 = input.readUnsignedByte() / 255;
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, a, a2, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, a, a2, 1);
} }
time = time2; time = time2;
a = a2; a = a2;
@ -731,35 +697,35 @@ module spine {
for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
let type = input.readByte(), frameCount = input.readInt(true), bezierCount = input.readInt(true); let type = input.readByte(), frameCount = input.readInt(true), bezierCount = input.readInt(true);
switch (type) { switch (type) {
case SkeletonBinary.BONE_ROTATE: case BONE_ROTATE:
timelines.push(SkeletonBinary.readTimeline(input, new RotateTimeline(frameCount, bezierCount, boneIndex), 1)); timelines.push(readTimeline1(input, new RotateTimeline(frameCount, bezierCount, boneIndex), 1));
break; break;
case SkeletonBinary.BONE_TRANSLATE: case BONE_TRANSLATE:
timelines.push(SkeletonBinary.readTimeline2(input, new TranslateTimeline(frameCount, bezierCount, boneIndex), scale)); timelines.push(readTimeline2(input, new TranslateTimeline(frameCount, bezierCount, boneIndex), scale));
break; break;
case SkeletonBinary.BONE_TRANSLATEX: case BONE_TRANSLATEX:
timelines.push(SkeletonBinary.readTimeline(input, new TranslateXTimeline(frameCount, bezierCount, boneIndex), scale)); timelines.push(readTimeline1(input, new TranslateXTimeline(frameCount, bezierCount, boneIndex), scale));
break; break;
case SkeletonBinary.BONE_TRANSLATEY: case BONE_TRANSLATEY:
timelines.push(SkeletonBinary.readTimeline(input, new TranslateYTimeline(frameCount, bezierCount, boneIndex), scale)); timelines.push(readTimeline1(input, new TranslateYTimeline(frameCount, bezierCount, boneIndex), scale));
break; break;
case SkeletonBinary.BONE_SCALE: case BONE_SCALE:
timelines.push(SkeletonBinary.readTimeline2(input, new ScaleTimeline(frameCount, bezierCount, boneIndex), 1)); timelines.push(readTimeline2(input, new ScaleTimeline(frameCount, bezierCount, boneIndex), 1));
break; break;
case SkeletonBinary.BONE_SCALEX: case BONE_SCALEX:
timelines.push(SkeletonBinary.readTimeline(input, new ScaleXTimeline(frameCount, bezierCount, boneIndex), 1)); timelines.push(readTimeline1(input, new ScaleXTimeline(frameCount, bezierCount, boneIndex), 1));
break; break;
case SkeletonBinary.BONE_SCALEY: case BONE_SCALEY:
timelines.push(SkeletonBinary.readTimeline(input, new ScaleYTimeline(frameCount, bezierCount, boneIndex), 1)); timelines.push(readTimeline1(input, new ScaleYTimeline(frameCount, bezierCount, boneIndex), 1));
break; break;
case SkeletonBinary.BONE_SHEAR: case BONE_SHEAR:
timelines.push(SkeletonBinary.readTimeline2(input, new ShearTimeline(frameCount, bezierCount, boneIndex), 1)); timelines.push(readTimeline2(input, new ShearTimeline(frameCount, bezierCount, boneIndex), 1));
break; break;
case SkeletonBinary.BONE_SHEARX: case BONE_SHEARX:
timelines.push(SkeletonBinary.readTimeline(input, new ShearXTimeline(frameCount, bezierCount, boneIndex), 1)); timelines.push(readTimeline1(input, new ShearXTimeline(frameCount, bezierCount, boneIndex), 1));
break; break;
case SkeletonBinary.BONE_SHEARY: case BONE_SHEARY:
timelines.push(SkeletonBinary.readTimeline(input, new ShearYTimeline(frameCount, bezierCount, boneIndex), 1)); timelines.push(readTimeline1(input, new ShearYTimeline(frameCount, bezierCount, boneIndex), 1));
} }
} }
} }
@ -774,12 +740,12 @@ module spine {
if (frame == frameLast) break; if (frame == frameLast) break;
let time2 = input.readFloat(), mix2 = input.readFloat(), softness2 = input.readFloat() * scale; let time2 = input.readFloat(), mix2 = input.readFloat(), softness2 = input.readFloat() * scale;
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale); setBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale);
} }
time = time2; time = time2;
mix = mix2; mix = mix2;
@ -800,16 +766,16 @@ module spine {
let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat(), let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat(),
mixScaleX2 = input.readFloat(), mixScaleY2 = input.readFloat(), mixShearY2 = input.readFloat(); mixScaleX2 = input.readFloat(), mixScaleY2 = input.readFloat(), mixShearY2 = input.readFloat();
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1); setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1); setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 3, time, time2, mixScaleX, mixScaleX2, 1); setBezier(input, timeline, bezier++, frame, 3, time, time2, mixScaleX, mixScaleX2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 4, time, time2, mixScaleY, mixScaleY2, 1); setBezier(input, timeline, bezier++, frame, 4, time, time2, mixScaleY, mixScaleY2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 5, time, time2, mixShearY, mixShearY2, 1); setBezier(input, timeline, bezier++, frame, 5, time, time2, mixShearY, mixShearY2, 1);
} }
time = time2; time = time2;
mixRotate = mixRotate2; mixRotate = mixRotate2;
@ -828,17 +794,17 @@ module spine {
let data = skeletonData.pathConstraints[index]; let data = skeletonData.pathConstraints[index];
for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.PATH_POSITION: case PATH_POSITION:
timelines timelines
.push(SkeletonBinary.readTimeline(input, new PathConstraintPositionTimeline(input.readInt(true), input.readInt(true), index), .push(readTimeline1(input, new PathConstraintPositionTimeline(input.readInt(true), input.readInt(true), index),
data.positionMode == PositionMode.Fixed ? scale : 1)); data.positionMode == PositionMode.Fixed ? scale : 1));
break; break;
case SkeletonBinary.PATH_SPACING: case PATH_SPACING:
timelines timelines
.push(SkeletonBinary.readTimeline(input, new PathConstraintSpacingTimeline(input.readInt(true), input.readInt(true), index), .push(readTimeline1(input, new PathConstraintSpacingTimeline(input.readInt(true), input.readInt(true), index),
data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed ? scale : 1)); data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed ? scale : 1));
break; break;
case SkeletonBinary.PATH_MIX: case PATH_MIX:
let timeline = new PathConstraintMixTimeline(input.readInt(true), input.readInt(true), index); let timeline = new PathConstraintMixTimeline(input.readInt(true), input.readInt(true), index);
let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat(); let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat();
for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) { for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
@ -847,13 +813,13 @@ module spine {
let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(),
mixY2 = input.readFloat(); mixY2 = input.readFloat();
switch (input.readByte()) { switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1); setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1); setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
} }
time = time2; time = time2;
mixRotate = mixRotate2; mixRotate = mixRotate2;
@ -910,11 +876,11 @@ module spine {
if (frame == frameLast) break; if (frame == frameLast) break;
let time2 = input.readFloat(); let time2 = input.readFloat();
switch(input.readByte()) { switch(input.readByte()) {
case SkeletonBinary.CURVE_STEPPED: case CURVE_STEPPED:
timeline.setStepped(frame); timeline.setStepped(frame);
break; break;
case SkeletonBinary.CURVE_BEZIER: case CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1); setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
} }
time = time2; time = time2;
} }
@ -980,56 +946,10 @@ module spine {
duration = Math.max(duration, timelines[i].getDuration()); duration = Math.max(duration, timelines[i].getDuration());
return new Animation(name, timelines, duration); return new Animation(name, timelines, duration);
} }
static readTimeline (input: BinaryInput, timeline: CurveTimeline1, scale: number): CurveTimeline1 {
let time = input.readFloat(), value = input.readFloat() * scale;
for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
timeline.setFrame(frame, time, value);
if (frame == frameLast) break;
let time2 = input.readFloat(), value2 = input.readFloat() * scale;
switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED:
timeline.setStepped(frame);
break;
case SkeletonBinary.CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, 1);
}
time = time2;
value = value2;
}
return timeline;
}
static readTimeline2 (input: BinaryInput, timeline: CurveTimeline2, scale: number): CurveTimeline2 {
let time = input.readFloat(), value1 = input.readFloat() * scale, value2 = input.readFloat() * scale;
for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
timeline.setFrame(frame, time, value1, value2);
if (frame == frameLast) break;
let time2 = input.readFloat(), nvalue1 = input.readFloat() * scale, nvalue2 = input.readFloat() * scale;
switch (input.readByte()) {
case SkeletonBinary.CURVE_STEPPED:
timeline.setStepped(frame);
break;
case SkeletonBinary.CURVE_BEZIER:
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale);
SkeletonBinary.setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale);
}
time = time2;
value1 = nvalue1;
value2 = nvalue2;
}
return timeline;
}
static setBezier (input: BinaryInput, timeline: CurveTimeline, bezier: number, frame: number, value: number,
time1: number, time2: number, value1: number, value2: number, scale: number) {
timeline.setBezier(bezier, frame, value, time1, value1, input.readFloat(), input.readFloat() * scale, input.readFloat(), input.readFloat() * scale, time2, value2);
}
} }
class BinaryInput { class BinaryInput {
constructor(data: Uint8Array, public strings = new Array<string>(), private index: number = 0, private buffer = new DataView(data.buffer)) {  constructor(data: Uint8Array, public strings = new Array<string>(), private index: number = 0, private buffer = new DataView(data.buffer)) { 
} }
readByte(): number { readByte(): number {
@ -1139,4 +1059,77 @@ module spine {
class Vertices { class Vertices {
constructor(public bones: Array<number> = null, public vertices: Array<number> | Float32Array = null) { } constructor(public bones: Array<number> = null, public vertices: Array<number> | Float32Array = null) { }
} }
enum AttachmentType { Region, BoundingBox, Mesh, LinkedMesh, Path, Point, Clipping }
function readTimeline1 (input: BinaryInput, timeline: CurveTimeline1, scale: number): CurveTimeline1 {
let time = input.readFloat(), value = input.readFloat() * scale;
for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
timeline.setFrame(frame, time, value);
if (frame == frameLast) break;
let time2 = input.readFloat(), value2 = input.readFloat() * scale;
switch (input.readByte()) {
case CURVE_STEPPED:
timeline.setStepped(frame);
break;
case CURVE_BEZIER:
setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, 1);
}
time = time2;
value = value2;
}
return timeline;
}
function readTimeline2 (input: BinaryInput, timeline: CurveTimeline2, scale: number): CurveTimeline2 {
let time = input.readFloat(), value1 = input.readFloat() * scale, value2 = input.readFloat() * scale;
for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
timeline.setFrame(frame, time, value1, value2);
if (frame == frameLast) break;
let time2 = input.readFloat(), nvalue1 = input.readFloat() * scale, nvalue2 = input.readFloat() * scale;
switch (input.readByte()) {
case CURVE_STEPPED:
timeline.setStepped(frame);
break;
case CURVE_BEZIER:
setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale);
setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale);
}
time = time2;
value1 = nvalue1;
value2 = nvalue2;
}
return timeline;
}
function setBezier (input: BinaryInput, timeline: CurveTimeline, bezier: number, frame: number, value: number,
time1: number, time2: number, value1: number, value2: number, scale: number) {
timeline.setBezier(bezier, frame, value, time1, value1, input.readFloat(), input.readFloat() * scale, input.readFloat(), input.readFloat() * scale, time2, value2);
}
const BONE_ROTATE = 0;
const BONE_TRANSLATE = 1;
const BONE_TRANSLATEX = 2;
const BONE_TRANSLATEY = 3;
const BONE_SCALE = 4;
const BONE_SCALEX = 5;
const BONE_SCALEY = 6;
const BONE_SHEAR = 7;
const BONE_SHEARX = 8;
const BONE_SHEARY = 9;
const SLOT_ATTACHMENT = 0;
const SLOT_RGBA = 1;
const SLOT_RGB = 2;
const SLOT_RGBA2 = 3;
const SLOT_RGB2 = 4;
const SLOT_ALPHA = 5;
const PATH_POSITION = 0;
const PATH_SPACING = 1;
const PATH_MIX = 2;
const CURVE_LINEAR = 0;
const CURVE_STEPPED = 1;
const CURVE_BEZIER = 2;
} }

View File

@ -86,7 +86,7 @@ module spine {
data.scaleY = getValue(boneMap, "scaleY", 1); data.scaleY = getValue(boneMap, "scaleY", 1);
data.shearX = getValue(boneMap, "shearX", 0); data.shearX = getValue(boneMap, "shearX", 0);
data.shearY = getValue(boneMap, "shearY", 0); data.shearY = getValue(boneMap, "shearY", 0);
data.transformMode = SkeletonJson.transformModeFromString(getValue(boneMap, "transform", "normal")); data.transformMode = Utils.enumValue(TransformMode, getValue(boneMap, "transform", "Normal"));
data.skinRequired = getValue(boneMap, "skin", false); data.skinRequired = getValue(boneMap, "skin", false);
let color = getValue(boneMap, "color", null); let color = getValue(boneMap, "color", null);
@ -110,13 +110,10 @@ module spine {
if (color != null) data.color.setFromString(color); if (color != null) data.color.setFromString(color);
let dark: string = getValue(slotMap, "dark", null); let dark: string = getValue(slotMap, "dark", null);
if (dark != null) { if (dark != null) data.darkColor = Color.fromString(dark);
data.darkColor = new Color(1, 1, 1, 1);
data.darkColor.setFromString(dark);
}
data.attachmentName = getValue(slotMap, "attachment", null); data.attachmentName = getValue(slotMap, "attachment", null);
data.blendMode = SkeletonJson.blendModeFromString(getValue(slotMap, "blend", "normal")); data.blendMode = Utils.enumValue(BlendMode, getValue(slotMap, "blend", "normal"));
skeletonData.slots.push(data); skeletonData.slots.push(data);
} }
} }
@ -209,9 +206,9 @@ module spine {
data.target = skeletonData.findSlot(targetName); data.target = skeletonData.findSlot(targetName);
if (data.target == null) throw new Error("Path target slot not found: " + targetName); if (data.target == null) throw new Error("Path target slot not found: " + targetName);
data.positionMode = SkeletonJson.positionModeFromString(getValue(constraintMap, "positionMode", "percent")); data.positionMode = Utils.enumValue(PositionMode, getValue(constraintMap, "positionMode", "Percent"));
data.spacingMode = SkeletonJson.spacingModeFromString(getValue(constraintMap, "spacingMode", "length")); data.spacingMode = Utils.enumValue(SpacingMode, getValue(constraintMap, "spacingMode", "Length"));
data.rotateMode = SkeletonJson.rotateModeFromString(getValue(constraintMap, "rotateMode", "tangent")); data.rotateMode = Utils.enumValue(RotateMode, getValue(constraintMap, "rotateMode", "Tangent"));
data.offsetRotation = getValue(constraintMap, "rotation", 0); data.offsetRotation = getValue(constraintMap, "rotation", 0);
data.position = getValue(constraintMap, "position", 0); data.position = getValue(constraintMap, "position", 0);
if (data.positionMode == PositionMode.Fixed) data.position *= scale; if (data.positionMode == PositionMode.Fixed) data.position *= scale;
@ -484,14 +481,14 @@ module spine {
let timeline = new RGBATimeline(timelineMap.length, timelineMap.length << 2, slotIndex); let timeline = new RGBATimeline(timelineMap.length, timelineMap.length << 2, slotIndex);
let keyMap = timelineMap[0]; let keyMap = timelineMap[0];
let time = getValue(keyMap, "time", 0); let time = getValue(keyMap, "time", 0);
let color = new Color().setFromString(keyMap.color); let color = Color.fromString(keyMap.color);
for (let frame = 0, bezier = 0;; frame++) { for (let frame = 0, bezier = 0;; frame++) {
timeline.setFrame(frame, time, color.r, color.g, color.b, color.a); timeline.setFrame(frame, time, color.r, color.g, color.b, color.a);
if (timelineMap.length == frame + 1) break; if (timelineMap.length == frame + 1) break;
let nextMap = timelineMap[frame + 1]; let nextMap = timelineMap[frame + 1];
let time2 = getValue(nextMap, "time", 0); let time2 = getValue(nextMap, "time", 0);
let newColor = new Color().setFromString(nextMap.color); let newColor = Color.fromString(nextMap.color);
let curve = keyMap.curve; let curve = keyMap.curve;
if (curve) { if (curve) {
bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
@ -510,14 +507,14 @@ module spine {
let timeline = new RGBTimeline(timelineMap.length, timelineMap.length * 3, slotIndex); let timeline = new RGBTimeline(timelineMap.length, timelineMap.length * 3, slotIndex);
let keyMap = timelineMap[0]; let keyMap = timelineMap[0];
let time = getValue(keyMap, "time", 0); let time = getValue(keyMap, "time", 0);
let color = new Color().setFromString(keyMap.color); let color = Color.fromString(keyMap.color);
for (let frame = 0, bezier = 0;; frame++) { for (let frame = 0, bezier = 0;; frame++) {
timeline.setFrame(frame, time, color.r, color.g, color.b); timeline.setFrame(frame, time, color.r, color.g, color.b);
if (timelineMap.length == frame + 1) break; if (timelineMap.length == frame + 1) break;
let nextMap = timelineMap[frame + 1]; let nextMap = timelineMap[frame + 1];
let time2 = getValue(nextMap, "time", 0); let time2 = getValue(nextMap, "time", 0);
let newColor = new Color().setFromString(nextMap.color); let newColor = Color.fromString(nextMap.color);
let curve = keyMap.curve; let curve = keyMap.curve;
if (curve) { if (curve) {
bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
@ -532,22 +529,22 @@ module spine {
timelines.push(timeline); timelines.push(timeline);
} else if (timelineName == "alpha") { } else if (timelineName == "alpha") {
timelines.push(readTimeline(timelineMap, new AlphaTimeline(timelineMap.length, timelineMap.length, slotIndex), 0, 1)); timelines.push(readTimeline1(timelineMap, new AlphaTimeline(timelineMap.length, timelineMap.length, slotIndex), 0, 1));
} else if (timelineName == "rgba2") { } else if (timelineName == "rgba2") {
let timeline = new RGBA2Timeline(timelineMap.length, timelineMap.length * 7, slotIndex); let timeline = new RGBA2Timeline(timelineMap.length, timelineMap.length * 7, slotIndex);
let keyMap = timelineMap[0]; let keyMap = timelineMap[0];
let time = getValue(keyMap, "time", 0); let time = getValue(keyMap, "time", 0);
let color = new Color().setFromString(keyMap.light); let color = Color.fromString(keyMap.light);
let color2 = new Color().setFromString(keyMap.dark); let color2 = Color.fromString(keyMap.dark);
for (let frame = 0, bezier = 0;; frame++) { for (let frame = 0, bezier = 0;; frame++) {
timeline.setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b); timeline.setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b);
if (timelineMap.length == frame + 1) break; if (timelineMap.length == frame + 1) break;
let nextMap = timelineMap[frame + 1]; let nextMap = timelineMap[frame + 1];
let time2 = getValue(nextMap, "time", 0); let time2 = getValue(nextMap, "time", 0);
let newColor = new Color().setFromString(nextMap.light); let newColor = Color.fromString(nextMap.light);
let newColor2 = new Color().setFromString(nextMap.dark); let newColor2 = Color.fromString(nextMap.dark);
let curve = keyMap.curve; let curve = keyMap.curve;
if (curve) { if (curve) {
bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
@ -571,16 +568,16 @@ module spine {
let keyMap = timelineMap[0]; let keyMap = timelineMap[0];
let time = getValue(keyMap, "time", 0); let time = getValue(keyMap, "time", 0);
let color = new Color().setFromString(keyMap.light); let color = Color.fromString(keyMap.light);
let color2 = new Color().setFromString(keyMap.dark); let color2 = Color.fromString(keyMap.dark);
for (let frame = 0, bezier = 0;; frame++) { for (let frame = 0, bezier = 0;; frame++) {
timeline.setFrame(frame, time, color.r, color.g, color.b, color2.r, color2.g, color2.b); timeline.setFrame(frame, time, color.r, color.g, color.b, color2.r, color2.g, color2.b);
if (timelineMap.length == frame + 1) break; if (timelineMap.length == frame + 1) break;
let nextMap = timelineMap[frame + 1]; let nextMap = timelineMap[frame + 1];
let time2 = getValue(nextMap, "time", 0); let time2 = getValue(nextMap, "time", 0);
let newColor = new Color().setFromString(nextMap.light); let newColor = Color.fromString(nextMap.light);
let newColor2 = new Color().setFromString(nextMap.dark); let newColor2 = Color.fromString(nextMap.dark);
let curve = keyMap.curve; let curve = keyMap.curve;
if (curve) { if (curve) {
bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
@ -615,34 +612,34 @@ module spine {
if (timelineMap.length == 0) continue; if (timelineMap.length == 0) continue;
if (timelineName === "rotate") { if (timelineName === "rotate") {
timelines.push(readTimeline(timelineMap, new RotateTimeline(timelineMap.length, timelineMap.length, boneIndex), 0, 1)); timelines.push(readTimeline1(timelineMap, new RotateTimeline(timelineMap.length, timelineMap.length, boneIndex), 0, 1));
} else if (timelineName === "translate") { } else if (timelineName === "translate") {
let timeline = new TranslateTimeline(timelineMap.length, timelineMap.length << 1, boneIndex); let timeline = new TranslateTimeline(timelineMap.length, timelineMap.length << 1, boneIndex);
timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 0, scale)); timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 0, scale));
} else if (timelineName === "translatex") { } else if (timelineName === "translatex") {
let timeline = new TranslateXTimeline(timelineMap.length, timelineMap.length, boneIndex); let timeline = new TranslateXTimeline(timelineMap.length, timelineMap.length, boneIndex);
timelines.push(readTimeline(timelineMap, timeline, 0, scale)); timelines.push(readTimeline1(timelineMap, timeline, 0, scale));
} else if (timelineName === "translatey") { } else if (timelineName === "translatey") {
let timeline = new TranslateYTimeline(timelineMap.length, timelineMap.length, boneIndex); let timeline = new TranslateYTimeline(timelineMap.length, timelineMap.length, boneIndex);
timelines.push(readTimeline(timelineMap, timeline, 0, scale)); timelines.push(readTimeline1(timelineMap, timeline, 0, scale));
} else if (timelineName === "scale") { } else if (timelineName === "scale") {
let timeline = new ScaleTimeline(timelineMap.length, timelineMap.length << 1, boneIndex); let timeline = new ScaleTimeline(timelineMap.length, timelineMap.length << 1, boneIndex);
timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 1, 1)); timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 1, 1));
} else if (timelineName === "scalex") { } else if (timelineName === "scalex") {
let timeline = new ScaleXTimeline(timelineMap.length, timelineMap.length, boneIndex); let timeline = new ScaleXTimeline(timelineMap.length, timelineMap.length, boneIndex);
timelines.push(readTimeline(timelineMap, timeline, 1, 1)); timelines.push(readTimeline1(timelineMap, timeline, 1, 1));
} else if (timelineName === "scaley") { } else if (timelineName === "scaley") {
let timeline = new ScaleYTimeline(timelineMap.length, timelineMap.length, boneIndex); let timeline = new ScaleYTimeline(timelineMap.length, timelineMap.length, boneIndex);
timelines.push(readTimeline(timelineMap, timeline, 1, 1)); timelines.push(readTimeline1(timelineMap, timeline, 1, 1));
} else if (timelineName === "shear") { } else if (timelineName === "shear") {
let timeline = new ShearTimeline(timelineMap.length, timelineMap.length << 1, boneIndex); let timeline = new ShearTimeline(timelineMap.length, timelineMap.length << 1, boneIndex);
timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 0, 1)); timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 0, 1));
} else if (timelineName === "shearx") { } else if (timelineName === "shearx") {
let timeline = new ShearXTimeline(timelineMap.length, timelineMap.length, boneIndex); let timeline = new ShearXTimeline(timelineMap.length, timelineMap.length, boneIndex);
timelines.push(readTimeline(timelineMap, timeline, 0, 1)); timelines.push(readTimeline1(timelineMap, timeline, 0, 1));
} else if (timelineName === "sheary") { } else if (timelineName === "sheary") {
let timeline = new ShearYTimeline(timelineMap.length, timelineMap.length, boneIndex); let timeline = new ShearYTimeline(timelineMap.length, timelineMap.length, boneIndex);
timelines.push(readTimeline(timelineMap, timeline, 0, 1)); timelines.push(readTimeline1(timelineMap, timeline, 0, 1));
} else } else
throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"); throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
} }
@ -755,10 +752,10 @@ module spine {
if (timelineName === "position") { if (timelineName === "position") {
let timeline = new PathConstraintPositionTimeline(timelineMap.length, timelineMap.length, index); let timeline = new PathConstraintPositionTimeline(timelineMap.length, timelineMap.length, index);
timelines.push(readTimeline(timelineMap, timeline, 0, data.positionMode == PositionMode.Fixed ? scale : 1)); timelines.push(readTimeline1(timelineMap, timeline, 0, data.positionMode == PositionMode.Fixed ? scale : 1));
} else if (timelineName === "spacing") { } else if (timelineName === "spacing") {
let timeline = new PathConstraintSpacingTimeline(timelineMap.length, timelineMap.length, index); let timeline = new PathConstraintSpacingTimeline(timelineMap.length, timelineMap.length, index);
timelines.push(readTimeline(timelineMap, timeline, 0, data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed ? scale : 1)); timelines.push(readTimeline1(timelineMap, timeline, 0, data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed ? scale : 1));
} else if (timelineName === "mix") { } else if (timelineName === "mix") {
let timeline = new PathConstraintMixTimeline(timelineMap.size, timelineMap.size * 3, index); let timeline = new PathConstraintMixTimeline(timelineMap.size, timelineMap.size * 3, index);
let time = getValue(keyMap, "time", 0); let time = getValue(keyMap, "time", 0);
@ -913,115 +910,6 @@ module spine {
skeletonData.animations.push(new Animation(name, timelines, duration)); skeletonData.animations.push(new Animation(name, timelines, duration));
} }
static private readTimeline (keys: any[], timeline: CurveTimeline1, defaultValue: number, scale: number) {
let keyMap = keys[0];
let time = getValue(keyMap, "time", 0);
let value = getValue(keyMap, "value", defaultValue) * scale;
let bezier = 0;
for (let frame = 0;; frame++) {
timeline.setFrame(frame, time, value);
let nextMap = keys[frame + 1];
if (!nextMap) break;
let time2 = getValue(nextMap, "time", 0);
let value2 = getValue(nextMap, "value", defaultValue) * scale;
let curve = keyMap.curve;
if (curve) bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value, value2, scale);
time = time2;
value = value2;
keyMap = nextMap;
}
return timeline;
}
static private readTimeline2 (keys: any[], timeline: CurveTimeline2, name1: string, name2: string, defaultValue: number, scale: number) {
let keyMap = keys[0];
let time = getValue(keyMap, "time", 0);
let value1 = getValue(keyMap, name1, defaultValue) * scale;
let value2 = getValue(keyMap, name2, defaultValue) * scale;
let bezier = 0;
for (let frame = 0;; frame++) {
timeline.setFrame(frame, time, value1, value2);
let nextMap = keys[frame + 1];
if (!nextMap) break;
let time2 = getValue(nextMap, "time", 0);
let nvalue1 = getValue(nextMap, name1, defaultValue) * scale;
let nvalue2 = getValue(nextMap, name2, defaultValue) * scale;
let curve = keyMap.curve;
if (curve != null) {
bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale);
bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale);
}
time = time2;
value1 = nvalue1;
value2 = nvalue2;
keyMap = nextMap;
}
timeline.shrink(bezier);
return timeline;
}
static private readCurve (curve: any, timeline: CurveTimeline, bezier: number, frame: number, value: number, time1: number, time2: number,
value1: number, value2: number, scale: number) {
if (curve == "stepped") {
if (value != 0) timeline.setStepped(frame);
} else {
let i = value << 2;
let cx1 = curve[i++];
let cy1 = curve[i++] * scale;
let cx2 = curve[i++];
let cy2 = curve[i++] * scale;
timeline.setBezier(bezier++, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2);
}
return bezier;
}
static private getValue (map: any, property: string, defaultValue: any) {
return map[property] !== undefined ? map[property] : defaultValue;
}
static private blendModeFromString (str: string) {
str = str.toLowerCase();
if (str == "normal") return BlendMode.Normal;
if (str == "additive") return BlendMode.Additive;
if (str == "multiply") return BlendMode.Multiply;
if (str == "screen") return BlendMode.Screen;
throw new Error(`Unknown blend mode: ${str}`);
}
static private positionModeFromString (str: string) {
str = str.toLowerCase();
if (str == "fixed") return PositionMode.Fixed;
if (str == "percent") return PositionMode.Percent;
throw new Error(`Unknown position mode: ${str}`);
}
static private spacingModeFromString (str: string) {
str = str.toLowerCase();
if (str == "length") return SpacingMode.Length;
if (str == "fixed") return SpacingMode.Fixed;
if (str == "percent") return SpacingMode.Percent;
if (str == "proportional") return SpacingMode.Proportional;
throw new Error(`Unknown spacing mode: ${str}`);
}
static private rotateModeFromString (str: string) {
str = str.toLowerCase();
if (str == "tangent") return RotateMode.Tangent;
if (str == "chain") return RotateMode.Chain;
if (str == "chainscale") return RotateMode.ChainScale;
throw new Error(`Unknown rotate mode: ${str}`);
}
static private transformModeFromString(str: string) {
str = str.toLowerCase();
if (str == "normal") return TransformMode.Normal;
if (str == "onlytranslation") return TransformMode.OnlyTranslation;
if (str == "norotationorreflection") return TransformMode.NoRotationOrReflection;
if (str == "noscale") return TransformMode.NoScale;
if (str == "noscaleorreflection") return TransformMode.NoScaleOrReflection;
throw new Error(`Unknown transform mode: ${str}`);
}
} }
class LinkedMesh { class LinkedMesh {
@ -1038,4 +926,70 @@ module spine {
this.inheritDeform = inheritDeform; this.inheritDeform = inheritDeform;
} }
} }
function readTimeline1 (keys: any[], timeline: CurveTimeline1, defaultValue: number, scale: number) {
let keyMap = keys[0];
let time = getValue(keyMap, "time", 0);
let value = getValue(keyMap, "value", defaultValue) * scale;
let bezier = 0;
for (let frame = 0;; frame++) {
timeline.setFrame(frame, time, value);
let nextMap = keys[frame + 1];
if (!nextMap) break;
let time2 = getValue(nextMap, "time", 0);
let value2 = getValue(nextMap, "value", defaultValue) * scale;
let curve = keyMap.curve;
if (curve) bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value, value2, scale);
time = time2;
value = value2;
keyMap = nextMap;
}
return timeline;
}
function readTimeline2 (keys: any[], timeline: CurveTimeline2, name1: string, name2: string, defaultValue: number, scale: number) {
let keyMap = keys[0];
let time = getValue(keyMap, "time", 0);
let value1 = getValue(keyMap, name1, defaultValue) * scale;
let value2 = getValue(keyMap, name2, defaultValue) * scale;
let bezier = 0;
for (let frame = 0;; frame++) {
timeline.setFrame(frame, time, value1, value2);
let nextMap = keys[frame + 1];
if (!nextMap) break;
let time2 = getValue(nextMap, "time", 0);
let nvalue1 = getValue(nextMap, name1, defaultValue) * scale;
let nvalue2 = getValue(nextMap, name2, defaultValue) * scale;
let curve = keyMap.curve;
if (curve != null) {
bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale);
bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale);
}
time = time2;
value1 = nvalue1;
value2 = nvalue2;
keyMap = nextMap;
}
timeline.shrink(bezier);
return timeline;
}
function readCurve (curve: any, timeline: CurveTimeline, bezier: number, frame: number, value: number, time1: number, time2: number,
value1: number, value2: number, scale: number) {
if (curve == "stepped") {
if (value != 0) timeline.setStepped(frame);
} else {
let i = value << 2;
let cx1 = curve[i++];
let cy1 = curve[i++] * scale;
let cx2 = curve[i++];
let cy2 = curve[i++] * scale;
timeline.setBezier(bezier++, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2);
}
return bezier;
}
function getValue (map: any, property: string, defaultValue: any) {
return map[property] !== undefined ? map[property] : defaultValue;
}
} }

View File

@ -31,7 +31,6 @@ module spine {
/** Stores the setup pose for a {@link Slot}. */ /** Stores the setup pose for a {@link Slot}. */
export class SlotData { export class SlotData {
/** The index of the slot in {@link Skeleton#getSlots()}. */ /** The index of the slot in {@link Skeleton#getSlots()}. */
index: number; index: number;
@ -64,4 +63,7 @@ module spine {
this.boneData = boneData; this.boneData = boneData;
} }
} }
/** Determines how images are blended with existing pixels when drawn. */
export enum BlendMode { Normal, Additive, Multiply, Screen }
} }

View File

@ -42,28 +42,6 @@ module spine {
abstract setFilters (minFilter: TextureFilter, magFilter: TextureFilter): void; abstract setFilters (minFilter: TextureFilter, magFilter: TextureFilter): void;
abstract setWraps (uWrap: TextureWrap, vWrap: TextureWrap): void; abstract setWraps (uWrap: TextureWrap, vWrap: TextureWrap): void;
abstract dispose (): void; abstract dispose (): void;
public static filterFromString (text: string): TextureFilter {
switch (text.toLowerCase()) {
case "nearest": return TextureFilter.Nearest;
case "linear": return TextureFilter.Linear;
case "mipmap": return TextureFilter.MipMap;
case "mipmapnearestnearest": return TextureFilter.MipMapNearestNearest;
case "mipmaplinearnearest": return TextureFilter.MipMapLinearNearest;
case "mipmapnearestlinear": return TextureFilter.MipMapNearestLinear;
case "mipmaplinearlinear": return TextureFilter.MipMapLinearLinear;
default: throw new Error(`Unknown texture filter ${text}`);
}
}
public static wrapFromString (text: string): TextureWrap {
switch (text.toLowerCase()) {
case "mirroredtepeat": return TextureWrap.MirroredRepeat;
case "clamptoedge": return TextureWrap.ClampToEdge;
case "repeat": return TextureWrap.Repeat;
default: throw new Error(`Unknown texture wrap ${text}`);
}
}
} }
export enum TextureFilter { export enum TextureFilter {

View File

@ -54,8 +54,8 @@ module spine {
// page.format = Format[tuple[0]]; we don't need format in WebGL // page.format = Format[tuple[0]]; we don't need format in WebGL
}; };
pageFields["filter"] = () => { pageFields["filter"] = () => {
page.minFilter = Texture.filterFromString(entry[1]); page.minFilter = Utils.enumValue(TextureFilter, entry[1]);
page.magFilter = Texture.filterFromString(entry[2]); page.magFilter = Utils.enumValue(TextureFilter, entry[2]);
}; };
pageFields["repeat"] = () => { pageFields["repeat"] = () => {
if (entry[1].indexOf('x') != -1) page.uWrap = TextureWrap.Repeat; if (entry[1].indexOf('x') != -1) page.uWrap = TextureWrap.Repeat;
@ -153,7 +153,7 @@ module spine {
else { else {
if (names == null) { if (names == null) {
names = []; names = [];
values = [] values = [];
} }
names.push(entry[0]); names.push(entry[0]);
let entryValues: number[] = []; let entryValues: number[] = [];

View File

@ -165,6 +165,10 @@ module spine {
color.g = ((value & 0x0000ff00) >>> 8) / 255; color.g = ((value & 0x0000ff00) >>> 8) / 255;
color.b = ((value & 0x000000ff)) / 255; color.b = ((value & 0x000000ff)) / 255;
} }
static fromString (hex : string) : Color {
return new Color().setFromString(hex);
}
} }
export class MathUtils { export class MathUtils {
@ -318,6 +322,10 @@ module spine {
if (array[i] == element) return true; if (array[i] == element) return true;
return false; return false;
} }
static enumValue (type: any, name: string) {
return type[name[0].toUpperCase() + name.slice(1)];
}
} }
export class DebugUtils { export class DebugUtils {

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
module spine {
export enum AttachmentType {
Region, BoundingBox, Mesh, LinkedMesh, Path, Point, Clipping
}
}

View File

@ -33,51 +33,6 @@ module spine {
* *
* See [Region attachments](http://esotericsoftware.com/spine-regions) in the Spine User Guide. */ * See [Region attachments](http://esotericsoftware.com/spine-regions) in the Spine User Guide. */
export class RegionAttachment extends Attachment { export class RegionAttachment extends Attachment {
static OX1 = 0;
static OY1 = 1;
static OX2 = 2;
static OY2 = 3;
static OX3 = 4;
static OY3 = 5;
static OX4 = 6;
static OY4 = 7;
static X1 = 0;
static Y1 = 1;
static C1R = 2;
static C1G = 3;
static C1B = 4;
static C1A = 5;
static U1 = 6;
static V1 = 7;
static X2 = 8;
static Y2 = 9;
static C2R = 10;
static C2G = 11;
static C2B = 12;
static C2A = 13;
static U2 = 14;
static V2 = 15;
static X3 = 16;
static Y3 = 17;
static C3R = 18;
static C3G = 19;
static C3B = 20;
static C3A = 21;
static U3 = 22;
static V3 = 23;
static X4 = 24;
static Y4 = 25;
static C4R = 26;
static C4G = 27;
static C4B = 28;
static C4A = 29;
static U4 = 30;
static V4 = 31;
/** The local x translation. */ /** The local x translation. */
x = 0; x = 0;
@ -142,14 +97,14 @@ module spine {
let localY2Cos = localY2 * cos + this.y; let localY2Cos = localY2 * cos + this.y;
let localY2Sin = localY2 * sin; let localY2Sin = localY2 * sin;
let offset = this.offset; let offset = this.offset;
offset[RegionAttachment.OX1] = localXCos - localYSin; offset[0] = localXCos - localYSin;
offset[RegionAttachment.OY1] = localYCos + localXSin; offset[1] = localYCos + localXSin;
offset[RegionAttachment.OX2] = localXCos - localY2Sin; offset[2] = localXCos - localY2Sin;
offset[RegionAttachment.OY2] = localY2Cos + localXSin; offset[3] = localY2Cos + localXSin;
offset[RegionAttachment.OX3] = localX2Cos - localY2Sin; offset[4] = localX2Cos - localY2Sin;
offset[RegionAttachment.OY3] = localY2Cos + localX2Sin; offset[5] = localY2Cos + localX2Sin;
offset[RegionAttachment.OX4] = localX2Cos - localYSin; offset[6] = localX2Cos - localYSin;
offset[RegionAttachment.OY4] = localYCos + localX2Sin; offset[7] = localYCos + localX2Sin;
} }
setRegion (region: TextureRegion) : void { setRegion (region: TextureRegion) : void {
@ -189,26 +144,26 @@ module spine {
let a = bone.a, b = bone.b, c = bone.c, d = bone.d; let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
let offsetX = 0, offsetY = 0; let offsetX = 0, offsetY = 0;
offsetX = vertexOffset[RegionAttachment.OX1]; offsetX = vertexOffset[0];
offsetY = vertexOffset[RegionAttachment.OY1]; offsetY = vertexOffset[1];
worldVertices[offset] = offsetX * a + offsetY * b + x; // br worldVertices[offset] = offsetX * a + offsetY * b + x; // br
worldVertices[offset + 1] = offsetX * c + offsetY * d + y; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
offset += stride; offset += stride;
offsetX = vertexOffset[RegionAttachment.OX2]; offsetX = vertexOffset[2];
offsetY = vertexOffset[RegionAttachment.OY2]; offsetY = vertexOffset[3];
worldVertices[offset] = offsetX * a + offsetY * b + x; // bl worldVertices[offset] = offsetX * a + offsetY * b + x; // bl
worldVertices[offset + 1] = offsetX * c + offsetY * d + y; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
offset += stride; offset += stride;
offsetX = vertexOffset[RegionAttachment.OX3]; offsetX = vertexOffset[4];
offsetY = vertexOffset[RegionAttachment.OY3]; offsetY = vertexOffset[5];
worldVertices[offset] = offsetX * a + offsetY * b + x; // ul worldVertices[offset] = offsetX * a + offsetY * b + x; // ul
worldVertices[offset + 1] = offsetX * c + offsetY * d + y; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
offset += stride; offset += stride;
offsetX = vertexOffset[RegionAttachment.OX4]; offsetX = vertexOffset[6];
offsetY = vertexOffset[RegionAttachment.OY4]; offsetY = vertexOffset[7];
worldVertices[offset] = offsetX * a + offsetY * b + x; // ur worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
worldVertices[offset + 1] = offsetX * c + offsetY * d + y; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
} }
@ -230,5 +185,41 @@ module spine {
copy.color.setFromColor(this.color); copy.color.setFromColor(this.color);
return copy; return copy;
} }
static X1 = 0;
static Y1 = 1;
static C1R = 2;
static C1G = 3;
static C1B = 4;
static C1A = 5;
static U1 = 6;
static V1 = 7;
static X2 = 8;
static Y2 = 9;
static C2R = 10;
static C2G = 11;
static C2B = 12;
static C2A = 13;
static U2 = 14;
static V2 = 15;
static X3 = 16;
static Y3 = 17;
static C3R = 18;
static C3G = 19;
static C3B = 20;
static C3A = 21;
static U3 = 22;
static V3 = 23;
static X4 = 24;
static Y4 = 25;
static C4R = 26;
static C4G = 27;
static C4B = 28;
static C4A = 29;
static U4 = 30;
static V4 = 31;
} }
} }

View File

@ -33,6 +33,7 @@ var shapes;
var lastFrameTime; var lastFrameTime;
var skeletons = {}; var skeletons = {};
var activeSkeleton = "spineboy"; var activeSkeleton = "spineboy";
var pow2 = new spine.Pow(2);
var swirlEffect = new spine.SwirlEffect(0); var swirlEffect = new spine.SwirlEffect(0);
var jitterEffect = new spine.JitterEffect(20, 20); var jitterEffect = new spine.JitterEffect(20, 20);
var swirlTime = 0; var swirlTime = 0;
@ -83,42 +84,46 @@ function init () {
assetManager.loadTextureAtlas("assets/stretchyman-pma.atlas"); assetManager.loadTextureAtlas("assets/stretchyman-pma.atlas");
assetManager.loadBinary("assets/coin-pro.skel"); assetManager.loadBinary("assets/coin-pro.skel");
assetManager.loadTextureAtlas("assets/coin-pma.atlas"); assetManager.loadTextureAtlas("assets/coin-pma.atlas");
assetManager.loadBinary("assets/mix-and-match-pro.skel");
assetManager.loadText("assets/mix-and-match-pro.json");
assetManager.loadTextureAtlas("assets/mix-and-match-pma.atlas");
requestAnimationFrame(load); requestAnimationFrame(load);
} }
function load () { function load () {
// Wait until the AssetManager has loaded all resources, then load the skeletons. // Wait until the AssetManager has loaded all resources, then load the skeletons.
if (assetManager.isLoadingComplete()) { if (assetManager.isLoadingComplete()) {
skeletons["raptor"] = loadSkeleton("raptor-pro", "walk", true); skeletons["coin"] = loadSkeleton("coin-pro.skel", "animation", true);
skeletons["spineboy"] = loadSkeleton("spineboy-pro", "run", true); skeletons["goblins"] = loadSkeleton("goblins-pro.skel", "walk", true, "goblin");
skeletons["tank"] = loadSkeleton("tank-pro", "drive", true); skeletons["mix-and-match-skel"] = loadSkeleton("mix-and-match-pro.skel", "dance", true, "full-skins/girl-blue-cape");
skeletons["goblins"] = loadSkeleton("goblins-pro", "walk", true, "goblin"); skeletons["mix-and-match-json"] = loadSkeleton("mix-and-match-pro.json", "dance", true, "full-skins/girl-blue-cape");
skeletons["vine"] = loadSkeleton("vine-pro", "grow", true); skeletons["raptor"] = loadSkeleton("raptor-pro.skel", "walk", true);
skeletons["stretchyman"] = loadSkeleton("stretchyman-pro", "sneak", true); skeletons["spineboy"] = loadSkeleton("spineboy-pro.skel", "run", true);
skeletons["coin"] = loadSkeleton("coin-pro", "animation", true); skeletons["stretchyman"] = loadSkeleton("stretchyman-pro.skel", "sneak", true);
skeletons["tank"] = loadSkeleton("tank-pro.skel", "drive", true);
skeletons["vine"] = loadSkeleton("vine-pro.skel", "grow", true);
setupUI(); setupUI();
lastFrameTime = Date.now() / 1000; lastFrameTime = Date.now() / 1000;
requestAnimationFrame(render); // Loading is done, call render every frame. requestAnimationFrame(render); // Loading is done, call render every frame.
} else { } else
requestAnimationFrame(load); requestAnimationFrame(load);
}
} }
function loadSkeleton (name, initialAnimation, premultipliedAlpha, skin) { function loadSkeleton (name, initialAnimation, premultipliedAlpha, skin) {
if (skin === undefined) skin = "default"; if (skin === undefined) skin = "default";
// Load the texture atlas using name.atlas from the AssetManager. // Load the texture atlas using name.atlas from the AssetManager.
var atlas = assetManager.get("assets/" + name.replace("-ess", "").replace("-pro", "") + (premultipliedAlpha ? "-pma": "") + ".atlas"); var atlas = assetManager.get("assets/" + name.replace(/(?:-ess|-pro)\.(skel|json)/, "") + (premultipliedAlpha ? "-pma": "") + ".atlas");
// Create a AtlasAttachmentLoader that resolves region, mesh, boundingbox and path attachments // Create an AtlasAttachmentLoader that resolves region, mesh, boundingbox and path attachments
var atlasLoader = new spine.AtlasAttachmentLoader(atlas); var atlasLoader = new spine.AtlasAttachmentLoader(atlas);
// Create a SkeletonBinary instance for parsing the .skel file. // Create a skeleton loader instance for parsing the skeleton data file.
var skeletonBinary = new spine.SkeletonBinary(atlasLoader); var skeletonLoader = name.endsWith(".skel") ? new spine.SkeletonBinary(atlasLoader) : new spine.SkeletonJson(atlasLoader);
// Set the scale to apply during parsing, parse the file, and create a new skeleton. // Set the scale to apply during parsing, parse the file, and create a new skeleton.
skeletonBinary.scale = 1; skeletonLoader.scale = 1;
var skeletonData = skeletonBinary.readSkeletonData(assetManager.get("assets/" + name + ".skel")); var skeletonData = skeletonLoader.readSkeletonData(assetManager.get("assets/" + name));
var skeleton = new spine.Skeleton(skeletonData); var skeleton = new spine.Skeleton(skeletonData);
skeleton.setSkinByName(skin); skeleton.setSkinByName(skin);
var bounds = calculateSetupPoseBounds(skeleton); var bounds = calculateSetupPoseBounds(skeleton);
@ -126,33 +131,43 @@ function loadSkeleton (name, initialAnimation, premultipliedAlpha, skin) {
// Create an AnimationState, and set the initial animation in looping mode. // Create an AnimationState, and set the initial animation in looping mode.
var animationStateData = new spine.AnimationStateData(skeleton.data); var animationStateData = new spine.AnimationStateData(skeleton.data);
var animationState = new spine.AnimationState(animationStateData); var animationState = new spine.AnimationState(animationStateData);
if (name == "spineboy") { if (name == "spineboy-pro.skel") {
animationStateData.setMix("walk", "jump", 0.4) animationStateData.setMix("walk", "run", 1.5)
animationStateData.setMix("run", "jump", 0.2)
animationStateData.setMix("jump", "run", 0.4); animationStateData.setMix("jump", "run", 0.4);
animationState.setAnimation(0, "walk", true); animationState.setEmptyAnimation(0, 0);
var jumpEntry = animationState.addAnimation(0, "jump", false, 3); var entry = animationState.addAnimation(0, "walk", true, 0);
entry.mixDuration = 1;
animationState.addAnimation(0, "run", true, 1.5);
animationState.addAnimation(0, "jump", false, 2);
animationState.addAnimation(0, "run", true, 0); animationState.addAnimation(0, "run", true, 0);
} else { animationState.addEmptyAnimation(0, 1, 1);
entry = animationState.addAnimation(0, "walk", true, 1.5);
entry.mixDuration = 1;
} else
animationState.setAnimation(0, initialAnimation, true); animationState.setAnimation(0, initialAnimation, true);
function log (message) {
if ($('#debug').is(':checked')) console.log(message);
} }
animationState.addListener({ animationState.addListener({
start: function(track) { start: function(track) {
console.log("Animation on track " + track.trackIndex + " started"); log("Animation on track " + track.trackIndex + " started");
}, },
interrupt: function(track) { interrupt: function(track) {
console.log("Animation on track " + track.trackIndex + " interrupted"); log("Animation on track " + track.trackIndex + " interrupted");
}, },
end: function(track) { end: function(track) {
console.log("Animation on track " + track.trackIndex + " ended"); log("Animation on track " + track.trackIndex + " ended");
}, },
disposed: function(track) { disposed: function(track) {
console.log("Animation on track " + track.trackIndex + " disposed"); log("Animation on track " + track.trackIndex + " disposed");
}, },
complete: function(track) { complete: function(track) {
console.log("Animation on track " + track.trackIndex + " completed"); log("Animation on track " + track.trackIndex + " completed");
}, },
event: function(track, event) { event: function(track, event) {
console.log("Event on track " + track.trackIndex + ": " + JSON.stringify(event)); log("Event on track " + track.trackIndex + ": " + JSON.stringify(event));
} }
}) })
@ -273,14 +288,13 @@ function render () {
swirlTime += delta; swirlTime += delta;
var percent = swirlTime % 2; var percent = swirlTime % 2;
if (percent > 1) percent = 1 - (percent -1 ); if (percent > 1) percent = 1 - (percent -1 );
swirlEffect.angle = 120 * percent - 60; swirlEffect.angle = pow2.apply(-60, 60, percent);
swirlEffect.centerX = bounds.offset.x + bounds.size.x / 2; swirlEffect.centerX = bounds.offset.x + bounds.size.x / 2;
swirlEffect.centerY = bounds.offset.y + bounds.size.y / 2; swirlEffect.centerY = bounds.offset.y + bounds.size.y / 2;
swirlEffect.radius = Math.sqrt(bounds.size.x * bounds.size.x + bounds.size.y * bounds.size.y); swirlEffect.radius = Math.sqrt(bounds.size.x * bounds.size.x + bounds.size.y * bounds.size.y) * 0.75;
skeletonRenderer.vertexEffect = swirlEffect; skeletonRenderer.vertexEffect = swirlEffect;
} else if (effect == "Jitter") { } else if (effect == "Jitter")
skeletonRenderer.vertexEffect = jitterEffect; skeletonRenderer.vertexEffect = jitterEffect;
}
skeletonRenderer.premultipliedAlpha = premultipliedAlpha; skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
skeletonRenderer.draw(batcher, skeleton); skeletonRenderer.draw(batcher, skeleton);
@ -317,7 +331,7 @@ function resize () {
var centerY = bounds.offset.y + bounds.size.y / 2; var centerY = bounds.offset.y + bounds.size.y / 2;
var scaleX = bounds.size.x / canvas.width; var scaleX = bounds.size.x / canvas.width;
var scaleY = bounds.size.y / canvas.height; var scaleY = bounds.size.y / canvas.height;
var scale = Math.max(scaleX, scaleY) * 1.2; var scale = Math.max(scaleX, scaleY) * 2;
if (scale < 1) scale = 1; if (scale < 1) scale = 1;
var width = canvas.width * scale; var width = canvas.width * scale;
var height = canvas.height * scale; var height = canvas.height * scale;