[ts] Fixed all backends. Need to implement TwoColorBatcher for WebGL backend

This commit is contained in:
badlogic 2017-01-26 16:35:21 +01:00
parent 7b463b1336
commit 808aea73c6
21 changed files with 21248 additions and 19756 deletions

View File

@ -76,14 +76,19 @@ declare module spine.canvas {
declare module spine.canvas { declare module spine.canvas {
class SkeletonRenderer { class SkeletonRenderer {
static QUAD_TRIANGLES: number[]; static QUAD_TRIANGLES: number[];
static VERTEX_SIZE: number;
private ctx; private ctx;
triangleRendering: boolean; triangleRendering: boolean;
debugRendering: boolean; debugRendering: boolean;
private vertices;
private tempColor;
constructor(context: CanvasRenderingContext2D); constructor(context: CanvasRenderingContext2D);
draw(skeleton: Skeleton): void; draw(skeleton: Skeleton): void;
private drawImages(skeleton); private drawImages(skeleton);
private drawTriangles(skeleton); private drawTriangles(skeleton);
private drawTriangle(img, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2); private drawTriangle(img, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);
private computeRegionVertices(slot, region, pma);
private computeMeshVertices(slot, mesh, pma);
} }
} }
declare module spine { declare module spine {
@ -1145,10 +1150,14 @@ declare module spine.threejs {
zOffset: number; zOffset: number;
private batcher; private batcher;
static QUAD_TRIANGLES: number[]; static QUAD_TRIANGLES: number[];
static VERTEX_SIZE: number;
private vertices;
private tempColor;
constructor(skeletonData: SkeletonData); constructor(skeletonData: SkeletonData);
update(deltaTime: number): void; update(deltaTime: number): void;
private updateGeometry(); private updateGeometry();
static createMesh(map: THREE.Texture): THREE.Mesh; private computeRegionVertices(slot, region, pma);
private computeMeshVertices(slot, mesh, pma);
} }
} }
declare module spine.threejs { declare module spine.threejs {

View File

@ -213,6 +213,8 @@ var spine;
function SkeletonRenderer(context) { function SkeletonRenderer(context) {
this.triangleRendering = false; this.triangleRendering = false;
this.debugRendering = false; this.debugRendering = false;
this.vertices = spine.Utils.newFloatArray(8 * 1024);
this.tempColor = new spine.Color();
this.ctx = context; this.ctx = context;
} }
SkeletonRenderer.prototype.draw = function (skeleton) { SkeletonRenderer.prototype.draw = function (skeleton) {
@ -231,10 +233,10 @@ var spine;
var attachment = slot.getAttachment(); var attachment = slot.getAttachment();
var region = null; var region = null;
var image = null; var image = null;
var vertices = null; var vertices = this.vertices;
if (attachment instanceof spine.RegionAttachment) { if (attachment instanceof spine.RegionAttachment) {
var regionAttachment = attachment; var regionAttachment = attachment;
vertices = regionAttachment.updateWorldVertices(slot, false); vertices = this.computeRegionVertices(slot, regionAttachment, false);
region = regionAttachment.region; region = regionAttachment.region;
image = (region).texture.getImage(); image = (region).texture.getImage();
} }
@ -268,7 +270,7 @@ var spine;
}; };
SkeletonRenderer.prototype.drawTriangles = function (skeleton) { SkeletonRenderer.prototype.drawTriangles = function (skeleton) {
var blendMode = null; var blendMode = null;
var vertices = null; var vertices = this.vertices;
var triangles = null; var triangles = null;
var drawOrder = skeleton.drawOrder; var drawOrder = skeleton.drawOrder;
for (var i = 0, n = drawOrder.length; i < n; i++) { for (var i = 0, n = drawOrder.length; i < n; i++) {
@ -278,14 +280,14 @@ var spine;
var region = null; var region = null;
if (attachment instanceof spine.RegionAttachment) { if (attachment instanceof spine.RegionAttachment) {
var regionAttachment = attachment; var regionAttachment = attachment;
vertices = regionAttachment.updateWorldVertices(slot, false); vertices = this.computeRegionVertices(slot, regionAttachment, false);
triangles = SkeletonRenderer.QUAD_TRIANGLES; triangles = SkeletonRenderer.QUAD_TRIANGLES;
region = regionAttachment.region; region = regionAttachment.region;
texture = region.texture.getImage(); texture = region.texture.getImage();
} }
else if (attachment instanceof spine.MeshAttachment) { else if (attachment instanceof spine.MeshAttachment) {
var mesh = attachment; var mesh = attachment;
vertices = mesh.updateWorldVertices(slot, false); vertices = this.computeMeshVertices(slot, mesh, false);
triangles = mesh.triangles; triangles = mesh.triangles;
texture = mesh.region.renderObject.texture.getImage(); texture = mesh.region.renderObject.texture.getImage();
} }
@ -344,7 +346,73 @@ var spine;
ctx.drawImage(img, 0, 0); ctx.drawImage(img, 0, 0);
ctx.restore(); ctx.restore();
}; };
SkeletonRenderer.prototype.computeRegionVertices = function (slot, region, pma) {
var skeleton = slot.bone.skeleton;
var skeletonColor = skeleton.color;
var slotColor = slot.color;
var regionColor = region.color;
var alpha = skeletonColor.a * slotColor.a * regionColor.a;
var multiplier = pma ? alpha : 1;
var color = this.tempColor;
color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, skeletonColor.g * slotColor.g * regionColor.g * multiplier, skeletonColor.b * slotColor.b * regionColor.b * multiplier, alpha);
region.computeWorldVertices(slot.bone, this.vertices, 0, SkeletonRenderer.VERTEX_SIZE);
var vertices = this.vertices;
var uvs = region.uvs;
vertices[spine.RegionAttachment.C1R] = color.r;
vertices[spine.RegionAttachment.C1G] = color.g;
vertices[spine.RegionAttachment.C1B] = color.b;
vertices[spine.RegionAttachment.C1A] = color.a;
vertices[spine.RegionAttachment.U1] = uvs[0];
vertices[spine.RegionAttachment.V1] = uvs[1];
vertices[spine.RegionAttachment.C2R] = color.r;
vertices[spine.RegionAttachment.C2G] = color.g;
vertices[spine.RegionAttachment.C2B] = color.b;
vertices[spine.RegionAttachment.C2A] = color.a;
vertices[spine.RegionAttachment.U2] = uvs[2];
vertices[spine.RegionAttachment.V2] = uvs[3];
vertices[spine.RegionAttachment.C3R] = color.r;
vertices[spine.RegionAttachment.C3G] = color.g;
vertices[spine.RegionAttachment.C3B] = color.b;
vertices[spine.RegionAttachment.C3A] = color.a;
vertices[spine.RegionAttachment.U3] = uvs[4];
vertices[spine.RegionAttachment.V3] = uvs[5];
vertices[spine.RegionAttachment.C4R] = color.r;
vertices[spine.RegionAttachment.C4G] = color.g;
vertices[spine.RegionAttachment.C4B] = color.b;
vertices[spine.RegionAttachment.C4A] = color.a;
vertices[spine.RegionAttachment.U4] = uvs[6];
vertices[spine.RegionAttachment.V4] = uvs[7];
return vertices;
};
SkeletonRenderer.prototype.computeMeshVertices = function (slot, mesh, pma) {
var skeleton = slot.bone.skeleton;
var skeletonColor = skeleton.color;
var slotColor = slot.color;
var regionColor = mesh.color;
var alpha = skeletonColor.a * slotColor.a * regionColor.a;
var multiplier = pma ? alpha : 1;
var color = this.tempColor;
color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, skeletonColor.g * slotColor.g * regionColor.g * multiplier, skeletonColor.b * slotColor.b * regionColor.b * multiplier, alpha);
var numVertices = mesh.worldVerticesLength / 2;
if (this.vertices.length < mesh.worldVerticesLength) {
this.vertices = spine.Utils.newFloatArray(mesh.worldVerticesLength);
}
var vertices = this.vertices;
mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, SkeletonRenderer.VERTEX_SIZE);
var uvs = mesh.uvs;
for (var i = 0, n = numVertices, u = 0, v = 2; i < n; i++) {
vertices[v++] = color.r;
vertices[v++] = color.g;
vertices[v++] = color.b;
vertices[v++] = color.a;
vertices[v++] = uvs[u++];
vertices[v++] = uvs[u++];
v += 2;
}
return vertices;
};
SkeletonRenderer.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0]; SkeletonRenderer.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
SkeletonRenderer.VERTEX_SIZE = 2 + 2 + 4;
return SkeletonRenderer; return SkeletonRenderer;
}()); }());
canvas.SkeletonRenderer = SkeletonRenderer; canvas.SkeletonRenderer = SkeletonRenderer;
@ -5839,6 +5907,8 @@ var spine;
function SkeletonMesh(skeletonData) { function SkeletonMesh(skeletonData) {
_super.call(this); _super.call(this);
this.zOffset = 0.1; this.zOffset = 0.1;
this.vertices = spine.Utils.newFloatArray(1024);
this.tempColor = new spine.Color();
this.skeleton = new spine.Skeleton(skeletonData); this.skeleton = new spine.Skeleton(skeletonData);
var animData = new spine.AnimationStateData(skeletonData); var animData = new spine.AnimationStateData(skeletonData);
this.state = new spine.AnimationState(animData); this.state = new spine.AnimationState(animData);
@ -5875,13 +5945,13 @@ var spine;
var texture = null; var texture = null;
if (attachment instanceof spine.RegionAttachment) { if (attachment instanceof spine.RegionAttachment) {
var region = attachment; var region = attachment;
vertices = region.updateWorldVertices(slot, false); vertices = this.computeRegionVertices(slot, region, false);
triangles = SkeletonMesh.QUAD_TRIANGLES; triangles = SkeletonMesh.QUAD_TRIANGLES;
texture = region.region.renderObject.texture; texture = region.region.renderObject.texture;
} }
else if (attachment instanceof spine.MeshAttachment) { else if (attachment instanceof spine.MeshAttachment) {
var mesh = attachment; var mesh = attachment;
vertices = mesh.updateWorldVertices(slot, false); vertices = this.computeMeshVertices(slot, mesh, false);
triangles = mesh.triangles; triangles = mesh.triangles;
texture = mesh.region.renderObject.texture; texture = mesh.region.renderObject.texture;
} }
@ -5899,35 +5969,73 @@ var spine;
} }
batcher.end(); batcher.end();
}; };
SkeletonMesh.createMesh = function (map) { SkeletonMesh.prototype.computeRegionVertices = function (slot, region, pma) {
var geo = new THREE.BufferGeometry(); var skeleton = slot.bone.skeleton;
var vertices = new Float32Array(1024); var skeletonColor = skeleton.color;
vertices.set([ var slotColor = slot.color;
-200, -200, 1, 0, 0, 1, 0, 0, var regionColor = region.color;
200, -200, 0, 1, 0, 1, 1, 0, var alpha = skeletonColor.a * slotColor.a * regionColor.a;
200, 200, 0, 0, 1, 1, 1, 1, var multiplier = pma ? alpha : 1;
-200, 200, 1, 1, 0, 0.1, 0, 1 var color = this.tempColor;
], 0); color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, skeletonColor.g * slotColor.g * regionColor.g * multiplier, skeletonColor.b * slotColor.b * regionColor.b * multiplier, alpha);
var vb = new THREE.InterleavedBuffer(vertices, 8); region.computeWorldVertices(slot.bone, this.vertices, 0, SkeletonMesh.VERTEX_SIZE);
var positions = new THREE.InterleavedBufferAttribute(vb, 2, 0, false); var vertices = this.vertices;
geo.addAttribute("position", positions); var uvs = region.uvs;
var colors = new THREE.InterleavedBufferAttribute(vb, 4, 2, false); vertices[spine.RegionAttachment.C1R] = color.r;
geo.addAttribute("color", colors); vertices[spine.RegionAttachment.C1G] = color.g;
var uvs = new THREE.InterleavedBufferAttribute(vb, 2, 6, false); vertices[spine.RegionAttachment.C1B] = color.b;
geo.addAttribute("uv", colors); vertices[spine.RegionAttachment.C1A] = color.a;
var indices = new Uint16Array(1024); vertices[spine.RegionAttachment.U1] = uvs[0];
indices.set([0, 1, 2, 2, 3, 0], 0); vertices[spine.RegionAttachment.V1] = uvs[1];
geo.setIndex(new THREE.BufferAttribute(indices, 1)); vertices[spine.RegionAttachment.C2R] = color.r;
geo.drawRange.start = 0; vertices[spine.RegionAttachment.C2G] = color.g;
geo.drawRange.count = 6; vertices[spine.RegionAttachment.C2B] = color.b;
var mat = new THREE.MeshBasicMaterial(); vertices[spine.RegionAttachment.C2A] = color.a;
mat.vertexColors = THREE.VertexColors; vertices[spine.RegionAttachment.U2] = uvs[2];
mat.transparent = true; vertices[spine.RegionAttachment.V2] = uvs[3];
mat.map = map; vertices[spine.RegionAttachment.C3R] = color.r;
var mesh = new THREE.Mesh(geo, mat); vertices[spine.RegionAttachment.C3G] = color.g;
return mesh; vertices[spine.RegionAttachment.C3B] = color.b;
vertices[spine.RegionAttachment.C3A] = color.a;
vertices[spine.RegionAttachment.U3] = uvs[4];
vertices[spine.RegionAttachment.V3] = uvs[5];
vertices[spine.RegionAttachment.C4R] = color.r;
vertices[spine.RegionAttachment.C4G] = color.g;
vertices[spine.RegionAttachment.C4B] = color.b;
vertices[spine.RegionAttachment.C4A] = color.a;
vertices[spine.RegionAttachment.U4] = uvs[6];
vertices[spine.RegionAttachment.V4] = uvs[7];
return vertices;
};
SkeletonMesh.prototype.computeMeshVertices = function (slot, mesh, pma) {
var skeleton = slot.bone.skeleton;
var skeletonColor = skeleton.color;
var slotColor = slot.color;
var regionColor = mesh.color;
var alpha = skeletonColor.a * slotColor.a * regionColor.a;
var multiplier = pma ? alpha : 1;
var color = this.tempColor;
color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, skeletonColor.g * slotColor.g * regionColor.g * multiplier, skeletonColor.b * slotColor.b * regionColor.b * multiplier, alpha);
var numVertices = mesh.worldVerticesLength / 2;
if (this.vertices.length < mesh.worldVerticesLength) {
this.vertices = spine.Utils.newFloatArray(mesh.worldVerticesLength);
}
var vertices = this.vertices;
mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, SkeletonMesh.VERTEX_SIZE);
var uvs = mesh.uvs;
for (var i = 0, n = numVertices, u = 0, v = 2; i < n; i++) {
vertices[v++] = color.r;
vertices[v++] = color.g;
vertices[v++] = color.b;
vertices[v++] = color.a;
vertices[v++] = uvs[u++];
vertices[v++] = uvs[u++];
v += 2;
}
return vertices;
}; };
SkeletonMesh.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0]; SkeletonMesh.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
SkeletonMesh.VERTEX_SIZE = 2 + 2 + 4;
return SkeletonMesh; return SkeletonMesh;
}(THREE.Mesh)); }(THREE.Mesh));
threejs.SkeletonMesh = SkeletonMesh; threejs.SkeletonMesh = SkeletonMesh;
@ -8260,7 +8368,7 @@ var spine;
skeleton.setSkinByName(config.skin); skeleton.setSkinByName(config.skin);
skeleton.setToSetupPose(); skeleton.setToSetupPose();
skeleton.updateWorldTransform(); skeleton.updateWorldTransform();
skeleton.getBounds(bounds.offset, bounds.size); skeleton.getBounds(bounds.offset, bounds.size, []);
if (!config.fitToCanvas) { if (!config.fitToCanvas) {
skeleton.x = config.x; skeleton.x = config.x;
skeleton.y = config.y; skeleton.y = config.y;

File diff suppressed because one or more lines are too long

View File

@ -76,14 +76,19 @@ declare module spine.canvas {
declare module spine.canvas { declare module spine.canvas {
class SkeletonRenderer { class SkeletonRenderer {
static QUAD_TRIANGLES: number[]; static QUAD_TRIANGLES: number[];
static VERTEX_SIZE: number;
private ctx; private ctx;
triangleRendering: boolean; triangleRendering: boolean;
debugRendering: boolean; debugRendering: boolean;
private vertices;
private tempColor;
constructor(context: CanvasRenderingContext2D); constructor(context: CanvasRenderingContext2D);
draw(skeleton: Skeleton): void; draw(skeleton: Skeleton): void;
private drawImages(skeleton); private drawImages(skeleton);
private drawTriangles(skeleton); private drawTriangles(skeleton);
private drawTriangle(img, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2); private drawTriangle(img, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);
private computeRegionVertices(slot, region, pma);
private computeMeshVertices(slot, mesh, pma);
} }
} }
declare module spine { declare module spine {
@ -115,6 +120,7 @@ declare module spine {
pathConstraintPosition = 11, pathConstraintPosition = 11,
pathConstraintSpacing = 12, pathConstraintSpacing = 12,
pathConstraintMix = 13, pathConstraintMix = 13,
twoColor = 14,
} }
abstract class CurveTimeline implements Timeline { abstract class CurveTimeline implements Timeline {
static LINEAR: number; static LINEAR: number;
@ -186,6 +192,30 @@ declare module spine {
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
} }
class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number;
static PREV_TIME: number;
static PREV_R: number;
static PREV_G: number;
static PREV_B: number;
static PREV_A: number;
static PREV_R2: number;
static PREV_G2: number;
static PREV_B2: number;
static R: number;
static G: number;
static B: number;
static A: number;
static R2: number;
static G2: number;
static B2: number;
slotIndex: number;
frames: ArrayLike<number>;
constructor(frameCount: number);
getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
}
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -420,6 +450,7 @@ declare module spine {
newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment; newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment;
newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment; newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment;
newPathAttachment(skin: Skin, name: string): PathAttachment; newPathAttachment(skin: Skin, name: string): PathAttachment;
newPointAttachment(skin: Skin, name: string): PointAttachment;
} }
} }
declare module spine { declare module spine {
@ -432,8 +463,7 @@ declare module spine {
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;
constructor(name: string); constructor(name: string);
computeWorldVertices(slot: Slot, worldVertices: ArrayLike<number>): void; computeWorldVertices(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
computeWorldVerticesWith(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number): void;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
} }
} }
@ -443,6 +473,7 @@ declare module spine {
newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment; newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment;
newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment; newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment;
newPathAttachment(skin: Skin, name: string): PathAttachment; newPathAttachment(skin: Skin, name: string): PathAttachment;
newPointAttachment(skin: Skin, name: string): PointAttachment;
} }
} }
declare module spine { declare module spine {
@ -452,6 +483,7 @@ declare module spine {
Mesh = 2, Mesh = 2,
LinkedMesh = 3, LinkedMesh = 3,
Path = 4, Path = 4,
Point = 5,
} }
} }
declare module spine { declare module spine {
@ -465,7 +497,7 @@ declare module spine {
region: TextureRegion; region: TextureRegion;
path: string; path: string;
regionUVs: ArrayLike<number>; regionUVs: ArrayLike<number>;
worldVertices: ArrayLike<number>; uvs: ArrayLike<number>;
triangles: Array<number>; triangles: Array<number>;
color: Color; color: Color;
hullLength: number; hullLength: number;
@ -474,7 +506,6 @@ declare module spine {
tempColor: Color; tempColor: Color;
constructor(name: string); constructor(name: string);
updateUVs(): void; updateUVs(): void;
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
getParentMesh(): MeshAttachment; getParentMesh(): MeshAttachment;
setParentMesh(parentMesh: MeshAttachment): void; setParentMesh(parentMesh: MeshAttachment): void;
@ -489,6 +520,17 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
} }
declare module spine {
class PointAttachment extends VertexAttachment {
x: number;
y: number;
rotation: number;
color: Color;
constructor(name: string);
computeWorldPosition(bone: Bone, point: Vector2): Vector2;
computeWorldRotation(bone: Bone): number;
}
}
declare module spine { declare module spine {
class RegionAttachment extends Attachment { class RegionAttachment extends Attachment {
static OX1: number; static OX1: number;
@ -543,12 +585,12 @@ declare module spine {
rendererObject: any; rendererObject: any;
region: TextureRegion; region: TextureRegion;
offset: ArrayLike<number>; offset: ArrayLike<number>;
vertices: ArrayLike<number>; uvs: ArrayLike<number>;
tempColor: Color; tempColor: Color;
constructor(name: string); constructor(name: string);
setRegion(region: TextureRegion): void;
updateOffset(): void; updateOffset(): void;
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>; setRegion(region: TextureRegion): void;
computeWorldVertices(bone: Bone, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
} }
} }
declare module spine { declare module spine {
@ -596,12 +638,12 @@ declare module spine {
getWorldRotationY(): number; getWorldRotationY(): number;
getWorldScaleX(): number; getWorldScaleX(): number;
getWorldScaleY(): number; getWorldScaleY(): number;
worldToLocalRotationX(): number;
worldToLocalRotationY(): number;
rotateWorld(degrees: number): void;
updateAppliedTransform(): void; updateAppliedTransform(): void;
worldToLocal(world: Vector2): Vector2; worldToLocal(world: Vector2): Vector2;
localToWorld(local: Vector2): Vector2; localToWorld(local: Vector2): Vector2;
worldToLocalRotation(worldRotation: number): number;
localToWorldRotation(localRotation: number): number;
rotateWorld(degrees: number): void;
} }
} }
declare module spine { declare module spine {
@ -801,7 +843,7 @@ declare module spine {
findIkConstraint(constraintName: string): IkConstraint; findIkConstraint(constraintName: string): IkConstraint;
findTransformConstraint(constraintName: string): TransformConstraint; findTransformConstraint(constraintName: string): TransformConstraint;
findPathConstraint(constraintName: string): PathConstraint; findPathConstraint(constraintName: string): PathConstraint;
getBounds(offset: Vector2, size: Vector2): void; getBounds(offset: Vector2, size: Vector2, temp: Array<number>): void;
update(delta: number): void; update(delta: number): void;
} }
} }
@ -893,6 +935,7 @@ declare module spine {
data: SlotData; data: SlotData;
bone: Bone; bone: Bone;
color: Color; color: Color;
darkColor: Color;
private attachment; private attachment;
private attachmentTime; private attachmentTime;
attachmentVertices: number[]; attachmentVertices: number[];
@ -910,6 +953,7 @@ declare module spine {
name: string; name: string;
boneData: BoneData; boneData: BoneData;
color: Color; color: Color;
darkColor: Color;
attachmentName: string; attachmentName: string;
blendMode: BlendMode; blendMode: BlendMode;
constructor(index: number, name: string, boneData: BoneData); constructor(index: number, name: string, boneData: BoneData);
@ -957,6 +1001,10 @@ declare module spine {
constructor(data: TransformConstraintData, skeleton: Skeleton); constructor(data: TransformConstraintData, skeleton: Skeleton);
apply(): void; apply(): void;
update(): void; update(): void;
applyAbsoluteWorld(): void;
applyRelativeWorld(): void;
applyAbsoluteLocal(): void;
applyRelativeLocal(): void;
getOrder(): number; getOrder(): number;
} }
} }
@ -976,6 +1024,8 @@ declare module spine {
offsetScaleX: number; offsetScaleX: number;
offsetScaleY: number; offsetScaleY: number;
offsetShearY: number; offsetShearY: number;
relative: boolean;
local: boolean;
constructor(name: string); constructor(name: string);
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -27,6 +27,7 @@ declare module spine {
pathConstraintPosition = 11, pathConstraintPosition = 11,
pathConstraintSpacing = 12, pathConstraintSpacing = 12,
pathConstraintMix = 13, pathConstraintMix = 13,
twoColor = 14,
} }
abstract class CurveTimeline implements Timeline { abstract class CurveTimeline implements Timeline {
static LINEAR: number; static LINEAR: number;
@ -98,6 +99,30 @@ declare module spine {
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
} }
class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number;
static PREV_TIME: number;
static PREV_R: number;
static PREV_G: number;
static PREV_B: number;
static PREV_A: number;
static PREV_R2: number;
static PREV_G2: number;
static PREV_B2: number;
static R: number;
static G: number;
static B: number;
static A: number;
static R2: number;
static G2: number;
static B2: number;
slotIndex: number;
frames: ArrayLike<number>;
constructor(frameCount: number);
getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
}
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -354,6 +379,7 @@ declare module spine {
newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment; newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment;
newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment; newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment;
newPathAttachment(skin: Skin, name: string): PathAttachment; newPathAttachment(skin: Skin, name: string): PathAttachment;
newPointAttachment(skin: Skin, name: string): PointAttachment;
} }
} }
declare module spine { declare module spine {
@ -366,8 +392,7 @@ declare module spine {
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;
constructor(name: string); constructor(name: string);
computeWorldVertices(slot: Slot, worldVertices: ArrayLike<number>): void; computeWorldVertices(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
computeWorldVerticesWith(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number): void;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
} }
} }
@ -377,6 +402,7 @@ declare module spine {
newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment; newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment;
newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment; newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment;
newPathAttachment(skin: Skin, name: string): PathAttachment; newPathAttachment(skin: Skin, name: string): PathAttachment;
newPointAttachment(skin: Skin, name: string): PointAttachment;
} }
} }
declare module spine { declare module spine {
@ -386,6 +412,7 @@ declare module spine {
Mesh = 2, Mesh = 2,
LinkedMesh = 3, LinkedMesh = 3,
Path = 4, Path = 4,
Point = 5,
} }
} }
declare module spine { declare module spine {
@ -399,7 +426,7 @@ declare module spine {
region: TextureRegion; region: TextureRegion;
path: string; path: string;
regionUVs: ArrayLike<number>; regionUVs: ArrayLike<number>;
worldVertices: ArrayLike<number>; uvs: ArrayLike<number>;
triangles: Array<number>; triangles: Array<number>;
color: Color; color: Color;
hullLength: number; hullLength: number;
@ -408,7 +435,6 @@ declare module spine {
tempColor: Color; tempColor: Color;
constructor(name: string); constructor(name: string);
updateUVs(): void; updateUVs(): void;
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
getParentMesh(): MeshAttachment; getParentMesh(): MeshAttachment;
setParentMesh(parentMesh: MeshAttachment): void; setParentMesh(parentMesh: MeshAttachment): void;
@ -423,6 +449,17 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
} }
declare module spine {
class PointAttachment extends VertexAttachment {
x: number;
y: number;
rotation: number;
color: Color;
constructor(name: string);
computeWorldPosition(bone: Bone, point: Vector2): Vector2;
computeWorldRotation(bone: Bone): number;
}
}
declare module spine { declare module spine {
class RegionAttachment extends Attachment { class RegionAttachment extends Attachment {
static OX1: number; static OX1: number;
@ -477,12 +514,12 @@ declare module spine {
rendererObject: any; rendererObject: any;
region: TextureRegion; region: TextureRegion;
offset: ArrayLike<number>; offset: ArrayLike<number>;
vertices: ArrayLike<number>; uvs: ArrayLike<number>;
tempColor: Color; tempColor: Color;
constructor(name: string); constructor(name: string);
setRegion(region: TextureRegion): void;
updateOffset(): void; updateOffset(): void;
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>; setRegion(region: TextureRegion): void;
computeWorldVertices(bone: Bone, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
} }
} }
declare module spine { declare module spine {
@ -530,12 +567,12 @@ declare module spine {
getWorldRotationY(): number; getWorldRotationY(): number;
getWorldScaleX(): number; getWorldScaleX(): number;
getWorldScaleY(): number; getWorldScaleY(): number;
worldToLocalRotationX(): number;
worldToLocalRotationY(): number;
rotateWorld(degrees: number): void;
updateAppliedTransform(): void; updateAppliedTransform(): void;
worldToLocal(world: Vector2): Vector2; worldToLocal(world: Vector2): Vector2;
localToWorld(local: Vector2): Vector2; localToWorld(local: Vector2): Vector2;
worldToLocalRotation(worldRotation: number): number;
localToWorldRotation(localRotation: number): number;
rotateWorld(degrees: number): void;
} }
} }
declare module spine { declare module spine {
@ -735,7 +772,7 @@ declare module spine {
findIkConstraint(constraintName: string): IkConstraint; findIkConstraint(constraintName: string): IkConstraint;
findTransformConstraint(constraintName: string): TransformConstraint; findTransformConstraint(constraintName: string): TransformConstraint;
findPathConstraint(constraintName: string): PathConstraint; findPathConstraint(constraintName: string): PathConstraint;
getBounds(offset: Vector2, size: Vector2): void; getBounds(offset: Vector2, size: Vector2, temp: Array<number>): void;
update(delta: number): void; update(delta: number): void;
} }
} }
@ -827,6 +864,7 @@ declare module spine {
data: SlotData; data: SlotData;
bone: Bone; bone: Bone;
color: Color; color: Color;
darkColor: Color;
private attachment; private attachment;
private attachmentTime; private attachmentTime;
attachmentVertices: number[]; attachmentVertices: number[];
@ -844,6 +882,7 @@ declare module spine {
name: string; name: string;
boneData: BoneData; boneData: BoneData;
color: Color; color: Color;
darkColor: Color;
attachmentName: string; attachmentName: string;
blendMode: BlendMode; blendMode: BlendMode;
constructor(index: number, name: string, boneData: BoneData); constructor(index: number, name: string, boneData: BoneData);
@ -931,6 +970,10 @@ declare module spine {
constructor(data: TransformConstraintData, skeleton: Skeleton); constructor(data: TransformConstraintData, skeleton: Skeleton);
apply(): void; apply(): void;
update(): void; update(): void;
applyAbsoluteWorld(): void;
applyRelativeWorld(): void;
applyAbsoluteLocal(): void;
applyRelativeLocal(): void;
getOrder(): number; getOrder(): number;
} }
} }
@ -950,6 +993,8 @@ declare module spine {
offsetScaleX: number; offsetScaleX: number;
offsetScaleY: number; offsetScaleY: number;
offsetShearY: number; offsetShearY: number;
relative: boolean;
local: boolean;
constructor(name: string); constructor(name: string);
} }
} }

View File

@ -68,6 +68,7 @@ var spine;
TimelineType[TimelineType["pathConstraintPosition"] = 11] = "pathConstraintPosition"; TimelineType[TimelineType["pathConstraintPosition"] = 11] = "pathConstraintPosition";
TimelineType[TimelineType["pathConstraintSpacing"] = 12] = "pathConstraintSpacing"; TimelineType[TimelineType["pathConstraintSpacing"] = 12] = "pathConstraintSpacing";
TimelineType[TimelineType["pathConstraintMix"] = 13] = "pathConstraintMix"; TimelineType[TimelineType["pathConstraintMix"] = 13] = "pathConstraintMix";
TimelineType[TimelineType["twoColor"] = 14] = "twoColor";
})(spine.TimelineType || (spine.TimelineType = {})); })(spine.TimelineType || (spine.TimelineType = {}));
var TimelineType = spine.TimelineType; var TimelineType = spine.TimelineType;
var CurveTimeline = (function () { var CurveTimeline = (function () {
@ -438,6 +439,100 @@ var spine;
return ColorTimeline; return ColorTimeline;
}(CurveTimeline)); }(CurveTimeline));
spine.ColorTimeline = ColorTimeline; spine.ColorTimeline = ColorTimeline;
var TwoColorTimeline = (function (_super) {
__extends(TwoColorTimeline, _super);
function TwoColorTimeline(frameCount) {
_super.call(this, frameCount);
this.frames = spine.Utils.newFloatArray(frameCount * TwoColorTimeline.ENTRIES);
}
TwoColorTimeline.prototype.getPropertyId = function () {
return (TimelineType.twoColor << 24) + this.slotIndex;
};
TwoColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a, r2, g2, b2) {
frameIndex *= TwoColorTimeline.ENTRIES;
this.frames[frameIndex] = time;
this.frames[frameIndex + TwoColorTimeline.R] = r;
this.frames[frameIndex + TwoColorTimeline.G] = g;
this.frames[frameIndex + TwoColorTimeline.B] = b;
this.frames[frameIndex + TwoColorTimeline.A] = a;
this.frames[frameIndex + TwoColorTimeline.R2] = r2;
this.frames[frameIndex + TwoColorTimeline.G2] = g2;
this.frames[frameIndex + TwoColorTimeline.B2] = b2;
};
TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, setupPose, mixingOut) {
var slot = skeleton.slots[this.slotIndex];
var frames = this.frames;
if (time < frames[0]) {
if (setupPose) {
slot.color.setFromColor(slot.data.color);
slot.darkColor.setFromColor(slot.data.darkColor);
}
return;
}
var r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
if (time >= frames[frames.length - TwoColorTimeline.ENTRIES]) {
var i = frames.length;
r = frames[i + TwoColorTimeline.PREV_R];
g = frames[i + TwoColorTimeline.PREV_G];
b = frames[i + TwoColorTimeline.PREV_B];
a = frames[i + TwoColorTimeline.PREV_A];
r2 = frames[i + TwoColorTimeline.PREV_R2];
g2 = frames[i + TwoColorTimeline.PREV_G2];
b2 = frames[i + TwoColorTimeline.PREV_B2];
}
else {
var frame = Animation.binarySearch(frames, time, TwoColorTimeline.ENTRIES);
r = frames[frame + TwoColorTimeline.PREV_R];
g = frames[frame + TwoColorTimeline.PREV_G];
b = frames[frame + TwoColorTimeline.PREV_B];
a = frames[frame + TwoColorTimeline.PREV_A];
r2 = frames[frame + TwoColorTimeline.PREV_R2];
g2 = frames[frame + TwoColorTimeline.PREV_G2];
b2 = frames[frame + TwoColorTimeline.PREV_B2];
var frameTime = frames[frame];
var percent = this.getCurvePercent(frame / TwoColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TwoColorTimeline.PREV_TIME] - frameTime));
r += (frames[frame + TwoColorTimeline.R] - r) * percent;
g += (frames[frame + TwoColorTimeline.G] - g) * percent;
b += (frames[frame + TwoColorTimeline.B] - b) * percent;
a += (frames[frame + TwoColorTimeline.A] - a) * percent;
r2 += (frames[frame + TwoColorTimeline.R2] - r2) * percent;
g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent;
b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent;
}
if (alpha == 1) {
slot.color.set(r, g, b, a);
slot.darkColor.set(r2, g2, b2, 1);
}
else {
var light = slot.color;
var dark = slot.darkColor;
if (setupPose) {
light.setFromColor(slot.data.color);
dark.setFromColor(slot.data.darkColor);
}
light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
dark.add((r2 - dark.r) * alpha, (g2 - dark.g) * alpha, (b2 - dark.b) * alpha, 0);
}
};
TwoColorTimeline.ENTRIES = 8;
TwoColorTimeline.PREV_TIME = -8;
TwoColorTimeline.PREV_R = -7;
TwoColorTimeline.PREV_G = -6;
TwoColorTimeline.PREV_B = -5;
TwoColorTimeline.PREV_A = -4;
TwoColorTimeline.PREV_R2 = -3;
TwoColorTimeline.PREV_G2 = -2;
TwoColorTimeline.PREV_B2 = -1;
TwoColorTimeline.R = 1;
TwoColorTimeline.G = 2;
TwoColorTimeline.B = 3;
TwoColorTimeline.A = 4;
TwoColorTimeline.R2 = 5;
TwoColorTimeline.G2 = 6;
TwoColorTimeline.B2 = 7;
return TwoColorTimeline;
}(CurveTimeline));
spine.TwoColorTimeline = TwoColorTimeline;
var AttachmentTimeline = (function () { var AttachmentTimeline = (function () {
function AttachmentTimeline(frameCount) { function AttachmentTimeline(frameCount) {
this.frames = spine.Utils.newFloatArray(frameCount); this.frames = spine.Utils.newFloatArray(frameCount);
@ -1753,6 +1848,9 @@ var spine;
AtlasAttachmentLoader.prototype.newPathAttachment = function (skin, name) { AtlasAttachmentLoader.prototype.newPathAttachment = function (skin, name) {
return new spine.PathAttachment(name); return new spine.PathAttachment(name);
}; };
AtlasAttachmentLoader.prototype.newPointAttachment = function (skin, name) {
return new spine.PointAttachment(name);
};
return AtlasAttachmentLoader; return AtlasAttachmentLoader;
}()); }());
spine.AtlasAttachmentLoader = AtlasAttachmentLoader; spine.AtlasAttachmentLoader = AtlasAttachmentLoader;
@ -1774,11 +1872,8 @@ var spine;
_super.call(this, name); _super.call(this, name);
this.worldVerticesLength = 0; this.worldVerticesLength = 0;
} }
VertexAttachment.prototype.computeWorldVertices = function (slot, worldVertices) { VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
this.computeWorldVerticesWith(slot, 0, this.worldVerticesLength, worldVertices, 0); count = offset + (count >> 1) * stride;
};
VertexAttachment.prototype.computeWorldVerticesWith = function (slot, start, count, worldVertices, offset) {
count += offset;
var skeleton = slot.bone.skeleton; var skeleton = slot.bone.skeleton;
var deformArray = slot.attachmentVertices; var deformArray = slot.attachmentVertices;
var vertices = this.vertices; var vertices = this.vertices;
@ -1790,7 +1885,7 @@ var spine;
var x = bone.worldX; var x = bone.worldX;
var y = bone.worldY; var y = bone.worldY;
var a = bone.a, b = bone.b, c = bone.c, d = bone.d; var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
for (var v_1 = start, w = offset; w < count; v_1 += 2, w += 2) { for (var v_1 = start, w = offset; w < count; v_1 += 2, w += stride) {
var vx = vertices[v_1], vy = vertices[v_1 + 1]; var vx = vertices[v_1], vy = vertices[v_1 + 1];
worldVertices[w] = vx * a + vy * b + x; worldVertices[w] = vx * a + vy * b + x;
worldVertices[w + 1] = vx * c + vy * d + y; worldVertices[w + 1] = vx * c + vy * d + y;
@ -1805,7 +1900,7 @@ var spine;
} }
var skeletonBones = skeleton.bones; var skeletonBones = skeleton.bones;
if (deformArray.length == 0) { if (deformArray.length == 0) {
for (var w = offset, b = skip * 3; w < count; w += 2) { for (var w = offset, b = skip * 3; w < count; w += stride) {
var wx = 0, wy = 0; var wx = 0, wy = 0;
var n = bones[v++]; var n = bones[v++];
n += v; n += v;
@ -1821,7 +1916,7 @@ var spine;
} }
else { else {
var deform = deformArray; var deform = deformArray;
for (var w = offset, b = skip * 3, f = skip << 1; w < count; w += 2) { for (var w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
var wx = 0, wy = 0; var wx = 0, wy = 0;
var n = bones[v++]; var n = bones[v++];
n += v; n += v;
@ -1851,6 +1946,7 @@ var spine;
AttachmentType[AttachmentType["Mesh"] = 2] = "Mesh"; AttachmentType[AttachmentType["Mesh"] = 2] = "Mesh";
AttachmentType[AttachmentType["LinkedMesh"] = 3] = "LinkedMesh"; AttachmentType[AttachmentType["LinkedMesh"] = 3] = "LinkedMesh";
AttachmentType[AttachmentType["Path"] = 4] = "Path"; AttachmentType[AttachmentType["Path"] = 4] = "Path";
AttachmentType[AttachmentType["Point"] = 5] = "Point";
})(spine.AttachmentType || (spine.AttachmentType = {})); })(spine.AttachmentType || (spine.AttachmentType = {}));
var AttachmentType = spine.AttachmentType; var AttachmentType = spine.AttachmentType;
})(spine || (spine = {})); })(spine || (spine = {}));
@ -1877,11 +1973,6 @@ var spine;
this.tempColor = new spine.Color(0, 0, 0, 0); this.tempColor = new spine.Color(0, 0, 0, 0);
} }
MeshAttachment.prototype.updateUVs = function () { MeshAttachment.prototype.updateUVs = function () {
var regionUVs = this.regionUVs;
var verticesLength = regionUVs.length;
var worldVerticesLength = (verticesLength >> 1) * 8;
if (this.worldVertices == null || this.worldVertices.length != worldVerticesLength)
this.worldVertices = spine.Utils.newFloatArray(worldVerticesLength);
var u = 0, v = 0, width = 0, height = 0; var u = 0, v = 0, width = 0, height = 0;
if (this.region == null) { if (this.region == null) {
u = v = 0; u = v = 0;
@ -1893,88 +1984,23 @@ var spine;
width = this.region.u2 - u; width = this.region.u2 - u;
height = this.region.v2 - v; height = this.region.v2 - v;
} }
var regionUVs = this.regionUVs;
if (this.uvs == null || this.uvs.length != regionUVs.length)
this.uvs = spine.Utils.newFloatArray(regionUVs.length);
var uvs = this.uvs;
if (this.region.rotate) { if (this.region.rotate) {
for (var i = 0, w = 6; i < verticesLength; i += 2, w += 8) { for (var i = 0, n = uvs.length; i < n; i += 2) {
this.worldVertices[w] = u + regionUVs[i + 1] * width; uvs[i] = u + regionUVs[i + 1] * width;
this.worldVertices[w + 1] = v + height - regionUVs[i] * height; uvs[i + 1] = v + height - regionUVs[i] * height;
} }
} }
else { else {
for (var i = 0, w = 6; i < verticesLength; i += 2, w += 8) { for (var i = 0, n = uvs.length; i < n; i += 2) {
this.worldVertices[w] = u + regionUVs[i] * width; uvs[i] = u + regionUVs[i] * width;
this.worldVertices[w + 1] = v + regionUVs[i + 1] * height; uvs[i + 1] = v + regionUVs[i + 1] * height;
} }
} }
}; };
MeshAttachment.prototype.updateWorldVertices = function (slot, premultipliedAlpha) {
var skeleton = slot.bone.skeleton;
var skeletonColor = skeleton.color, slotColor = slot.color, meshColor = this.color;
var alpha = skeletonColor.a * slotColor.a * meshColor.a;
var multiplier = premultipliedAlpha ? alpha : 1;
var color = this.tempColor;
color.set(skeletonColor.r * slotColor.r * meshColor.r * multiplier, skeletonColor.g * slotColor.g * meshColor.g * multiplier, skeletonColor.b * slotColor.b * meshColor.b * multiplier, alpha);
var deformArray = slot.attachmentVertices;
var vertices = this.vertices, worldVertices = this.worldVertices;
var bones = this.bones;
if (bones == null) {
var verticesLength = vertices.length;
if (deformArray.length > 0)
vertices = deformArray;
var bone = slot.bone;
var x = bone.worldX;
var y = bone.worldY;
var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
for (var v = 0, w = 0; v < verticesLength; v += 2, w += 8) {
var vx = vertices[v], vy = vertices[v + 1];
worldVertices[w] = vx * a + vy * b + x;
worldVertices[w + 1] = vx * c + vy * d + y;
worldVertices[w + 2] = color.r;
worldVertices[w + 3] = color.g;
worldVertices[w + 4] = color.b;
worldVertices[w + 5] = color.a;
}
return worldVertices;
}
var skeletonBones = skeleton.bones;
if (deformArray.length == 0) {
for (var w = 0, v = 0, b = 0, n = bones.length; v < n; w += 8) {
var wx = 0, wy = 0;
var nn = bones[v++] + v;
for (; v < nn; v++, b += 3) {
var bone = skeletonBones[bones[v]];
var vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
}
worldVertices[w] = wx;
worldVertices[w + 1] = wy;
worldVertices[w + 2] = color.r;
worldVertices[w + 3] = color.g;
worldVertices[w + 4] = color.b;
worldVertices[w + 5] = color.a;
}
}
else {
var deform = deformArray;
for (var w = 0, v = 0, b = 0, f = 0, n = bones.length; v < n; w += 8) {
var wx = 0, wy = 0;
var nn = bones[v++] + v;
for (; v < nn; v++, b += 3, f += 2) {
var bone = skeletonBones[bones[v]];
var vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
}
worldVertices[w] = wx;
worldVertices[w + 1] = wy;
worldVertices[w + 2] = color.r;
worldVertices[w + 3] = color.g;
worldVertices[w + 4] = color.b;
worldVertices[w + 5] = color.a;
}
}
return worldVertices;
};
MeshAttachment.prototype.applyDeform = function (sourceAttachment) { MeshAttachment.prototype.applyDeform = function (sourceAttachment) {
return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment); return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment);
}; };
@ -2010,6 +2036,29 @@ var spine;
spine.PathAttachment = PathAttachment; spine.PathAttachment = PathAttachment;
})(spine || (spine = {})); })(spine || (spine = {}));
var spine; var spine;
(function (spine) {
var PointAttachment = (function (_super) {
__extends(PointAttachment, _super);
function PointAttachment(name) {
_super.call(this, name);
this.color = new spine.Color(0.38, 0.94, 0, 1);
}
PointAttachment.prototype.computeWorldPosition = function (bone, point) {
point.x = this.x * bone.a + this.y * bone.b + bone.worldX;
point.y = this.x * bone.c + this.y * bone.d + bone.worldY;
return point;
};
PointAttachment.prototype.computeWorldRotation = function (bone) {
var cos = spine.MathUtils.cosDeg(this.rotation), sin = spine.MathUtils.sinDeg(this.rotation);
var x = cos * bone.a + sin * bone.b;
var y = cos * bone.c + sin * bone.d;
return Math.atan2(y, x) * spine.MathUtils.radDeg;
};
return PointAttachment;
}(spine.VertexAttachment));
spine.PointAttachment = PointAttachment;
})(spine || (spine = {}));
var spine;
(function (spine) { (function (spine) {
var RegionAttachment = (function (_super) { var RegionAttachment = (function (_super) {
__extends(RegionAttachment, _super); __extends(RegionAttachment, _super);
@ -2024,33 +2073,9 @@ var spine;
this.height = 0; this.height = 0;
this.color = new spine.Color(1, 1, 1, 1); this.color = new spine.Color(1, 1, 1, 1);
this.offset = spine.Utils.newFloatArray(8); this.offset = spine.Utils.newFloatArray(8);
this.vertices = spine.Utils.newFloatArray(8 * 4); this.uvs = spine.Utils.newFloatArray(8);
this.tempColor = new spine.Color(1, 1, 1, 1); this.tempColor = new spine.Color(1, 1, 1, 1);
} }
RegionAttachment.prototype.setRegion = function (region) {
var vertices = this.vertices;
if (region.rotate) {
vertices[RegionAttachment.U2] = region.u;
vertices[RegionAttachment.V2] = region.v2;
vertices[RegionAttachment.U3] = region.u;
vertices[RegionAttachment.V3] = region.v;
vertices[RegionAttachment.U4] = region.u2;
vertices[RegionAttachment.V4] = region.v;
vertices[RegionAttachment.U1] = region.u2;
vertices[RegionAttachment.V1] = region.v2;
}
else {
vertices[RegionAttachment.U1] = region.u;
vertices[RegionAttachment.V1] = region.v2;
vertices[RegionAttachment.U2] = region.u;
vertices[RegionAttachment.V2] = region.v;
vertices[RegionAttachment.U3] = region.u2;
vertices[RegionAttachment.V3] = region.v;
vertices[RegionAttachment.U4] = region.u2;
vertices[RegionAttachment.V4] = region.v2;
}
this.region = region;
};
RegionAttachment.prototype.updateOffset = function () { RegionAttachment.prototype.updateOffset = function () {
var regionScaleX = this.width / this.region.originalWidth * this.scaleX; var regionScaleX = this.width / this.region.originalWidth * this.scaleX;
var regionScaleY = this.height / this.region.originalHeight * this.scaleY; var regionScaleY = this.height / this.region.originalHeight * this.scaleY;
@ -2079,54 +2104,54 @@ var spine;
offset[RegionAttachment.OX4] = localX2Cos - localYSin; offset[RegionAttachment.OX4] = localX2Cos - localYSin;
offset[RegionAttachment.OY4] = localYCos + localX2Sin; offset[RegionAttachment.OY4] = localYCos + localX2Sin;
}; };
RegionAttachment.prototype.updateWorldVertices = function (slot, premultipliedAlpha) { RegionAttachment.prototype.setRegion = function (region) {
var skeleton = slot.bone.skeleton; this.region = region;
var skeletonColor = skeleton.color; var uvs = this.uvs;
var slotColor = slot.color; if (region.rotate) {
var regionColor = this.color; uvs[2] = region.u;
var alpha = skeletonColor.a * slotColor.a * regionColor.a; uvs[3] = region.v2;
var multiplier = premultipliedAlpha ? alpha : 1; uvs[4] = region.u;
var color = this.tempColor; uvs[5] = region.v;
color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, skeletonColor.g * slotColor.g * regionColor.g * multiplier, skeletonColor.b * slotColor.b * regionColor.b * multiplier, alpha); uvs[6] = region.u2;
var vertices = this.vertices; uvs[7] = region.v;
var offset = this.offset; uvs[0] = region.u2;
var bone = slot.bone; uvs[1] = region.v2;
}
else {
uvs[0] = region.u;
uvs[1] = region.v2;
uvs[2] = region.u;
uvs[3] = region.v;
uvs[4] = region.u2;
uvs[5] = region.v;
uvs[6] = region.u2;
uvs[7] = region.v2;
}
};
RegionAttachment.prototype.computeWorldVertices = function (bone, worldVertices, offset, stride) {
var vertexOffset = this.offset;
var x = bone.worldX, y = bone.worldY; var x = bone.worldX, y = bone.worldY;
var a = bone.a, b = bone.b, c = bone.c, d = bone.d; var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
var offsetX = 0, offsetY = 0; var offsetX = 0, offsetY = 0;
offsetX = offset[RegionAttachment.OX1]; offsetX = vertexOffset[RegionAttachment.OX1];
offsetY = offset[RegionAttachment.OY1]; offsetY = vertexOffset[RegionAttachment.OY1];
vertices[RegionAttachment.X1] = offsetX * a + offsetY * b + x; worldVertices[offset] = offsetX * a + offsetY * b + x;
vertices[RegionAttachment.Y1] = offsetX * c + offsetY * d + y; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
vertices[RegionAttachment.C1R] = color.r; offset += stride;
vertices[RegionAttachment.C1G] = color.g; offsetX = vertexOffset[RegionAttachment.OX2];
vertices[RegionAttachment.C1B] = color.b; offsetY = vertexOffset[RegionAttachment.OY2];
vertices[RegionAttachment.C1A] = color.a; worldVertices[offset] = offsetX * a + offsetY * b + x;
offsetX = offset[RegionAttachment.OX2]; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
offsetY = offset[RegionAttachment.OY2]; offset += stride;
vertices[RegionAttachment.X2] = offsetX * a + offsetY * b + x; offsetX = vertexOffset[RegionAttachment.OX3];
vertices[RegionAttachment.Y2] = offsetX * c + offsetY * d + y; offsetY = vertexOffset[RegionAttachment.OY3];
vertices[RegionAttachment.C2R] = color.r; worldVertices[offset] = offsetX * a + offsetY * b + x;
vertices[RegionAttachment.C2G] = color.g; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
vertices[RegionAttachment.C2B] = color.b; offset += stride;
vertices[RegionAttachment.C2A] = color.a; offsetX = vertexOffset[RegionAttachment.OX4];
offsetX = offset[RegionAttachment.OX3]; offsetY = vertexOffset[RegionAttachment.OY4];
offsetY = offset[RegionAttachment.OY3]; worldVertices[offset] = offsetX * a + offsetY * b + x;
vertices[RegionAttachment.X3] = offsetX * a + offsetY * b + x; worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
vertices[RegionAttachment.Y3] = offsetX * c + offsetY * d + y;
vertices[RegionAttachment.C3R] = color.r;
vertices[RegionAttachment.C3G] = color.g;
vertices[RegionAttachment.C3B] = color.b;
vertices[RegionAttachment.C3A] = color.a;
offsetX = offset[RegionAttachment.OX4];
offsetY = offset[RegionAttachment.OY4];
vertices[RegionAttachment.X4] = offsetX * a + offsetY * b + x;
vertices[RegionAttachment.Y4] = offsetX * c + offsetY * d + y;
vertices[RegionAttachment.C4R] = color.r;
vertices[RegionAttachment.C4G] = color.g;
vertices[RegionAttachment.C4B] = color.b;
vertices[RegionAttachment.C4A] = color.a;
return vertices;
}; };
RegionAttachment.OX1 = 0; RegionAttachment.OX1 = 0;
RegionAttachment.OY1 = 1; RegionAttachment.OY1 = 1;
@ -2370,29 +2395,6 @@ var spine;
Bone.prototype.getWorldScaleY = function () { Bone.prototype.getWorldScaleY = function () {
return Math.sqrt(this.b * this.b + this.d * this.d); return Math.sqrt(this.b * this.b + this.d * this.d);
}; };
Bone.prototype.worldToLocalRotationX = function () {
var parent = this.parent;
if (parent == null)
return this.arotation;
var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d, a = this.a, c = this.c;
return Math.atan2(pa * c - pc * a, pd * a - pb * c) * spine.MathUtils.radDeg;
};
Bone.prototype.worldToLocalRotationY = function () {
var parent = this.parent;
if (parent == null)
return this.arotation;
var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d, b = this.b, d = this.d;
return Math.atan2(pa * d - pc * b, pd * b - pb * d) * spine.MathUtils.radDeg;
};
Bone.prototype.rotateWorld = function (degrees) {
var a = this.a, b = this.b, c = this.c, d = this.d;
var cos = spine.MathUtils.cosDeg(degrees), sin = spine.MathUtils.sinDeg(degrees);
this.a = cos * a - sin * c;
this.b = cos * b - sin * d;
this.c = sin * a + cos * c;
this.d = sin * b + cos * d;
this.appliedValid = false;
};
Bone.prototype.updateAppliedTransform = function () { Bone.prototype.updateAppliedTransform = function () {
this.appliedValid = true; this.appliedValid = true;
var parent = this.parent; var parent = this.parent;
@ -2448,6 +2450,23 @@ var spine;
local.y = x * this.c + y * this.d + this.worldY; local.y = x * this.c + y * this.d + this.worldY;
return local; return local;
}; };
Bone.prototype.worldToLocalRotation = function (worldRotation) {
var sin = spine.MathUtils.sinDeg(worldRotation), cos = spine.MathUtils.cosDeg(worldRotation);
return Math.atan2(this.a * sin - this.c * cos, this.d * cos - this.b * sin) * spine.MathUtils.radDeg;
};
Bone.prototype.localToWorldRotation = function (localRotation) {
var sin = spine.MathUtils.sinDeg(localRotation), cos = spine.MathUtils.cosDeg(localRotation);
return Math.atan2(cos * this.c + sin * this.d, cos * this.a + sin * this.b) * spine.MathUtils.radDeg;
};
Bone.prototype.rotateWorld = function (degrees) {
var a = this.a, b = this.b, c = this.c, d = this.d;
var cos = spine.MathUtils.cosDeg(degrees), sin = spine.MathUtils.sinDeg(degrees);
this.a = cos * a - sin * c;
this.b = cos * b - sin * d;
this.c = sin * a + cos * c;
this.d = sin * b + cos * d;
this.appliedValid = false;
};
return Bone; return Bone;
}()); }());
spine.Bone = Bone; spine.Bone = Bone;
@ -2773,11 +2792,11 @@ var spine;
lengths = spine.Utils.setArraySize(this.lengths, boneCount); lengths = spine.Utils.setArraySize(this.lengths, boneCount);
for (var i = 0, n = spacesCount - 1; i < n;) { for (var i = 0, n = spacesCount - 1; i < n;) {
var bone = bones[i]; var bone = bones[i];
var length_1 = bone.data.length, x = length_1 * bone.a, y = length_1 * bone.c; var setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
length_1 = Math.sqrt(x * x + y * y); var length_1 = Math.sqrt(x * x + y * y);
if (scale) if (scale)
lengths[i] = length_1; lengths[i] = length_1;
spaces[++i] = lengthSpacing ? Math.max(0, length_1 + spacing) : spacing; spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length_1 / setupLength;
} }
} }
else { else {
@ -2873,7 +2892,7 @@ var spine;
else if (p < 0) { else if (p < 0) {
if (prevCurve != PathConstraint.BEFORE) { if (prevCurve != PathConstraint.BEFORE) {
prevCurve = PathConstraint.BEFORE; prevCurve = PathConstraint.BEFORE;
path.computeWorldVerticesWith(target, 2, 4, world, 0); path.computeWorldVertices(target, 2, 4, world, 0, 2);
} }
this.addBeforePosition(p, world, 0, out, o); this.addBeforePosition(p, world, 0, out, o);
continue; continue;
@ -2881,7 +2900,7 @@ var spine;
else if (p > pathLength_1) { else if (p > pathLength_1) {
if (prevCurve != PathConstraint.AFTER) { if (prevCurve != PathConstraint.AFTER) {
prevCurve = PathConstraint.AFTER; prevCurve = PathConstraint.AFTER;
path.computeWorldVerticesWith(target, verticesLength - 6, 4, world, 0); path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
} }
this.addAfterPosition(p - pathLength_1, world, 0, out, o); this.addAfterPosition(p - pathLength_1, world, 0, out, o);
continue; continue;
@ -2901,11 +2920,11 @@ var spine;
if (curve != prevCurve) { if (curve != prevCurve) {
prevCurve = curve; prevCurve = curve;
if (closed && curve == curveCount) { if (closed && curve == curveCount) {
path.computeWorldVerticesWith(target, verticesLength - 4, 4, world, 0); path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
path.computeWorldVerticesWith(target, 0, 4, world, 4); path.computeWorldVertices(target, 0, 4, world, 4, 2);
} }
else else
path.computeWorldVerticesWith(target, curve * 6 + 2, 8, world, 0); path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
} }
this.addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o, tangents || (i > 0 && space == 0)); this.addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o, tangents || (i > 0 && space == 0));
} }
@ -2914,8 +2933,8 @@ var spine;
if (closed) { if (closed) {
verticesLength += 2; verticesLength += 2;
world = spine.Utils.setArraySize(this.world, verticesLength); world = spine.Utils.setArraySize(this.world, verticesLength);
path.computeWorldVerticesWith(target, 2, verticesLength - 4, world, 0); path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
path.computeWorldVerticesWith(target, 0, 2, world, verticesLength - 4); path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
world[verticesLength - 2] = world[0]; world[verticesLength - 2] = world[0];
world[verticesLength - 1] = world[1]; world[verticesLength - 1] = world[1];
} }
@ -2923,7 +2942,7 @@ var spine;
curveCount--; curveCount--;
verticesLength -= 4; verticesLength -= 4;
world = spine.Utils.setArraySize(this.world, verticesLength); world = spine.Utils.setArraySize(this.world, verticesLength);
path.computeWorldVerticesWith(target, 2, verticesLength, world, 0); path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
} }
var curves = spine.Utils.setArraySize(this.curves, curveCount); var curves = spine.Utils.setArraySize(this.curves, curveCount);
var pathLength = 0; var pathLength = 0;
@ -3368,27 +3387,38 @@ var spine;
this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone); this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin) if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin)
this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone); this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
for (var ii = 0, nn = this.data.skins.length; ii < nn; ii++) for (var i = 0, n = this.data.skins.length; i < n; i++)
this.sortPathConstraintAttachment(this.data.skins[ii], slotIndex, slotBone); this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
var attachment = slot.getAttachment(); var attachment = slot.getAttachment();
if (attachment instanceof spine.PathAttachment) if (attachment instanceof spine.PathAttachment)
this.sortPathConstraintAttachmentWith(attachment, slotBone); this.sortPathConstraintAttachmentWith(attachment, slotBone);
var constrained = constraint.bones; var constrained = constraint.bones;
var boneCount = constrained.length; var boneCount = constrained.length;
for (var ii = 0; ii < boneCount; ii++) for (var i = 0; i < boneCount; i++)
this.sortBone(constrained[ii]); this.sortBone(constrained[i]);
this._updateCache.push(constraint); this._updateCache.push(constraint);
for (var ii = 0; ii < boneCount; ii++) for (var i = 0; i < boneCount; i++)
this.sortReset(constrained[ii].children); this.sortReset(constrained[i].children);
for (var ii = 0; ii < boneCount; ii++) for (var i = 0; i < boneCount; i++)
constrained[ii].sorted = true; constrained[i].sorted = true;
}; };
Skeleton.prototype.sortTransformConstraint = function (constraint) { Skeleton.prototype.sortTransformConstraint = function (constraint) {
this.sortBone(constraint.target); this.sortBone(constraint.target);
var constrained = constraint.bones; var constrained = constraint.bones;
var boneCount = constrained.length; var boneCount = constrained.length;
for (var ii = 0; ii < boneCount; ii++) if (constraint.data.local) {
this.sortBone(constrained[ii]); for (var i = 0; i < boneCount; i++) {
var child = constrained[constrained.length - 1];
this.sortBone(child.parent);
if (!(this._updateCache.indexOf(child) > -1))
this.updateCacheReset.push(child);
}
}
else {
for (var i = 0; i < boneCount; i++) {
this.sortBone(constrained[i]);
}
}
this._updateCache.push(constraint); this._updateCache.push(constraint);
for (var ii = 0; ii < boneCount; ii++) for (var ii = 0; ii < boneCount; ii++)
this.sortReset(constrained[ii].children); this.sortReset(constrained[ii].children);
@ -3631,7 +3661,7 @@ var spine;
} }
return null; return null;
}; };
Skeleton.prototype.getBounds = function (offset, size) { Skeleton.prototype.getBounds = function (offset, size, temp) {
if (offset == null) if (offset == null)
throw new Error("offset cannot be null."); throw new Error("offset cannot be null.");
if (size == null) if (size == null)
@ -3640,15 +3670,23 @@ var spine;
var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY; var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
for (var i = 0, n = drawOrder.length; i < n; i++) { for (var i = 0, n = drawOrder.length; i < n; i++) {
var slot = drawOrder[i]; var slot = drawOrder[i];
var verticesLength = 0;
var vertices = null; var vertices = null;
var attachment = slot.getAttachment(); var attachment = slot.getAttachment();
if (attachment instanceof spine.RegionAttachment) if (attachment instanceof spine.RegionAttachment) {
vertices = attachment.updateWorldVertices(slot, false); verticesLength = 8;
else if (attachment instanceof spine.MeshAttachment) vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
vertices = attachment.updateWorldVertices(slot, true); attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
}
else if (attachment instanceof spine.MeshAttachment) {
var mesh = attachment;
verticesLength = mesh.worldVerticesLength;
vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
}
if (vertices != null) { if (vertices != null) {
for (var ii = 0, nn = vertices.length; ii < nn; ii += 8) { for (var i_1 = 0, nn = vertices.length; i_1 < nn; i_1 += 8) {
var x = vertices[ii], y = vertices[ii + 1]; var x = vertices[i_1], y = vertices[i_1 + 1];
minX = Math.min(minX, x); minX = Math.min(minX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);
@ -3702,7 +3740,7 @@ var spine;
polygon = spine.Utils.newFloatArray(boundingBox.worldVerticesLength); polygon = spine.Utils.newFloatArray(boundingBox.worldVerticesLength);
} }
polygons.push(polygon); polygons.push(polygon);
boundingBox.computeWorldVertices(slot, polygon); boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
} }
} }
if (updateAabb) { if (updateAabb) {
@ -4021,6 +4059,9 @@ var spine;
var color = this.getValue(slotMap, "color", null); var color = this.getValue(slotMap, "color", null);
if (color != null) if (color != null)
data.color.setFromString(color); data.color.setFromString(color);
var dark = this.getValue(slotMap, "dark", null);
if (dark != null)
data.darkColor.setFromString(color);
data.attachmentName = this.getValue(slotMap, "attachment", null); data.attachmentName = this.getValue(slotMap, "attachment", null);
data.blendMode = SkeletonJson.blendModeFromString(this.getValue(slotMap, "blend", "normal")); data.blendMode = SkeletonJson.blendModeFromString(this.getValue(slotMap, "blend", "normal"));
skeletonData.slots.push(data); skeletonData.slots.push(data);
@ -4232,6 +4273,18 @@ var spine;
path.color.setFromString(color); path.color.setFromString(color);
return path; return path;
} }
case "point": {
var point = this.attachmentLoader.newPointAttachment(skin, name);
if (point == null)
return null;
point.x = this.getValue(map, "x", 0) * scale;
point.y = this.getValue(map, "y", 0) * scale;
point.rotation = this.getValue(map, "rotation", 0);
var color = this.getValue(map, "color", null);
if (color != null)
point.color.setFromString(color);
return point;
}
} }
return null; return null;
}; };
@ -4274,7 +4327,18 @@ var spine;
throw new Error("Slot not found: " + slotName); throw new Error("Slot not found: " + slotName);
for (var timelineName in slotMap) { for (var timelineName in slotMap) {
var timelineMap = slotMap[timelineName]; var timelineMap = slotMap[timelineName];
if (timelineName == "color") { if (timelineName == "attachment") {
var timeline = new spine.AttachmentTimeline(timelineMap.length);
timeline.slotIndex = slotIndex;
var frameIndex = 0;
for (var i = 0; i < timelineMap.length; i++) {
var valueMap = timelineMap[i];
timeline.setFrame(frameIndex++, valueMap.time, valueMap.name);
}
timelines.push(timeline);
duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
}
else if (timelineName == "color") {
var timeline = new spine.ColorTimeline(timelineMap.length); var timeline = new spine.ColorTimeline(timelineMap.length);
timeline.slotIndex = slotIndex; timeline.slotIndex = slotIndex;
var frameIndex = 0; var frameIndex = 0;
@ -4289,16 +4353,22 @@ var spine;
timelines.push(timeline); timelines.push(timeline);
duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.ColorTimeline.ENTRIES]); duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.ColorTimeline.ENTRIES]);
} }
else if (timelineName = "attachment") { else if (timelineName == "twoColor") {
var timeline = new spine.AttachmentTimeline(timelineMap.length); var timeline = new spine.TwoColorTimeline(timelineMap.length);
timeline.slotIndex = slotIndex; timeline.slotIndex = slotIndex;
var frameIndex = 0; var frameIndex = 0;
for (var i = 0; i < timelineMap.length; i++) { for (var i = 0; i < timelineMap.length; i++) {
var valueMap = timelineMap[i]; var valueMap = timelineMap[i];
timeline.setFrame(frameIndex++, valueMap.time, valueMap.name); var light = new spine.Color();
var dark = new spine.Color();
light.setFromString(valueMap.color);
dark.setFromString(valueMap.dark);
timeline.setFrame(frameIndex, valueMap.time, light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
this.readCurve(valueMap, timeline, frameIndex);
frameIndex++;
} }
timelines.push(timeline); timelines.push(timeline);
duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]); duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TwoColorTimeline.ENTRIES]);
} }
else else
throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"); throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
@ -4685,6 +4755,7 @@ var spine;
this.data = data; this.data = data;
this.bone = bone; this.bone = bone;
this.color = new spine.Color(); this.color = new spine.Color();
this.darkColor = data.darkColor == null ? null : new spine.Color();
this.setToSetupPose(); this.setToSetupPose();
} }
Slot.prototype.getAttachment = function () { Slot.prototype.getAttachment = function () {
@ -4705,6 +4776,8 @@ var spine;
}; };
Slot.prototype.setToSetupPose = function () { Slot.prototype.setToSetupPose = function () {
this.color.setFromColor(this.data.color); this.color.setFromColor(this.data.color);
if (this.darkColor != null)
this.darkColor.setFromColor(this.data.darkColor);
if (this.data.attachmentName == null) if (this.data.attachmentName == null)
this.attachment = null; this.attachment = null;
else { else {
@ -4983,6 +5056,20 @@ var spine;
this.update(); this.update();
}; };
TransformConstraint.prototype.update = function () { TransformConstraint.prototype.update = function () {
if (this.data.local) {
if (this.data.relative)
this.applyRelativeLocal();
else
this.applyAbsoluteLocal();
}
else {
if (this.data.relative)
this.applyRelativeWorld();
else
this.applyAbsoluteWorld();
}
};
TransformConstraint.prototype.applyAbsoluteWorld = function () {
var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix; var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
var target = this.target; var target = this.target;
var ta = target.a, tb = target.b, tc = target.c, td = target.d; var ta = target.a, tb = target.b, tc = target.c, td = target.d;
@ -5048,6 +5135,132 @@ var spine;
bone.appliedValid = false; bone.appliedValid = false;
} }
}; };
TransformConstraint.prototype.applyRelativeWorld = function () {
var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
var target = this.target;
var ta = target.a, tb = target.b, tc = target.c, td = target.d;
var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
var offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
var bones = this.bones;
for (var i = 0, n = bones.length; i < n; i++) {
var bone = bones[i];
var modified = false;
if (rotateMix != 0) {
var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
var r = Math.atan2(tc, ta) + offsetRotation;
if (r > spine.MathUtils.PI)
r -= spine.MathUtils.PI2;
else if (r < -spine.MathUtils.PI)
r += spine.MathUtils.PI2;
r *= rotateMix;
var cos = Math.cos(r), sin = Math.sin(r);
bone.a = cos * a - sin * c;
bone.b = cos * b - sin * d;
bone.c = sin * a + cos * c;
bone.d = sin * b + cos * d;
modified = true;
}
if (translateMix != 0) {
var temp = this.temp;
target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
bone.worldX += temp.x * translateMix;
bone.worldY += temp.y * translateMix;
modified = true;
}
if (scaleMix > 0) {
var s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * scaleMix + 1;
bone.a *= s;
bone.c *= s;
s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * scaleMix + 1;
bone.b *= s;
bone.d *= s;
modified = true;
}
if (shearMix > 0) {
var r = Math.atan2(td, tb) - Math.atan2(tc, ta);
if (r > spine.MathUtils.PI)
r -= spine.MathUtils.PI2;
else if (r < -spine.MathUtils.PI)
r += spine.MathUtils.PI2;
var b = bone.b, d = bone.d;
r = Math.atan2(d, b) + (r - spine.MathUtils.PI / 2 + offsetShearY) * shearMix;
var s = Math.sqrt(b * b + d * d);
bone.b = Math.cos(r) * s;
bone.d = Math.sin(r) * s;
modified = true;
}
if (modified)
bone.appliedValid = false;
}
};
TransformConstraint.prototype.applyAbsoluteLocal = function () {
var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
var target = this.target;
if (!target.appliedValid)
target.updateAppliedTransform();
var bones = this.bones;
for (var i = 0, n = bones.length; i < n; i++) {
var bone = bones[i];
if (!bone.appliedValid)
bone.updateAppliedTransform();
var rotation = bone.arotation;
if (rotateMix != 0) {
var r = target.arotation - rotation + this.data.offsetRotation;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
rotation += r * rotateMix;
}
var x = bone.ax, y = bone.ay;
if (translateMix != 0) {
x += (target.ax - x + this.data.offsetX) * translateMix;
y += (target.ay - y + this.data.offsetY) * translateMix;
}
var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
if (scaleMix > 0) {
if (scaleX > 0.00001)
scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * scaleMix) / scaleX;
if (scaleY > 0.00001)
scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * scaleMix) / scaleY;
}
var shearY = bone.ashearY;
if (shearMix > 0) {
var r = target.ashearY - shearY + this.data.offsetShearY;
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
bone.shearY += r * shearMix;
}
bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
}
};
TransformConstraint.prototype.applyRelativeLocal = function () {
var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
var target = this.target;
if (!target.appliedValid)
target.updateAppliedTransform();
var bones = this.bones;
for (var i = 0, n = bones.length; i < n; i++) {
var bone = bones[i];
if (!bone.appliedValid)
bone.updateAppliedTransform();
var rotation = bone.arotation;
if (rotateMix != 0)
rotation += (target.arotation + this.data.offsetRotation) * rotateMix;
var x = bone.ax, y = bone.ay;
if (translateMix != 0) {
x += (target.ax + this.data.offsetX) * translateMix;
y += (target.ay + this.data.offsetY) * translateMix;
}
var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
if (scaleMix > 0) {
if (scaleX > 0.00001)
scaleX *= ((target.ascaleX - 1 + this.data.offsetScaleX) * scaleMix) + 1;
if (scaleY > 0.00001)
scaleY *= ((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1;
}
var shearY = bone.ashearY;
if (shearMix > 0)
shearY += (target.ashearY + this.data.offsetShearY) * shearMix;
bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
}
};
TransformConstraint.prototype.getOrder = function () { TransformConstraint.prototype.getOrder = function () {
return this.data.order; return this.data.order;
}; };
@ -5071,6 +5284,8 @@ var spine;
this.offsetScaleX = 0; this.offsetScaleX = 0;
this.offsetScaleY = 0; this.offsetScaleY = 0;
this.offsetShearY = 0; this.offsetShearY = 0;
this.relative = false;
this.local = false;
if (name == null) if (name == null)
throw new Error("name cannot be null."); throw new Error("name cannot be null.");
this.name = name; this.name = name;

File diff suppressed because one or more lines are too long

View File

@ -27,6 +27,7 @@ declare module spine {
pathConstraintPosition = 11, pathConstraintPosition = 11,
pathConstraintSpacing = 12, pathConstraintSpacing = 12,
pathConstraintMix = 13, pathConstraintMix = 13,
twoColor = 14,
} }
abstract class CurveTimeline implements Timeline { abstract class CurveTimeline implements Timeline {
static LINEAR: number; static LINEAR: number;
@ -98,6 +99,30 @@ declare module spine {
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
} }
class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number;
static PREV_TIME: number;
static PREV_R: number;
static PREV_G: number;
static PREV_B: number;
static PREV_A: number;
static PREV_R2: number;
static PREV_G2: number;
static PREV_B2: number;
static R: number;
static G: number;
static B: number;
static A: number;
static R2: number;
static G2: number;
static B2: number;
slotIndex: number;
frames: ArrayLike<number>;
constructor(frameCount: number);
getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
}
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -354,6 +379,7 @@ declare module spine {
newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment; newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment;
newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment; newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment;
newPathAttachment(skin: Skin, name: string): PathAttachment; newPathAttachment(skin: Skin, name: string): PathAttachment;
newPointAttachment(skin: Skin, name: string): PointAttachment;
} }
} }
declare module spine { declare module spine {
@ -366,8 +392,7 @@ declare module spine {
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;
constructor(name: string); constructor(name: string);
computeWorldVertices(slot: Slot, worldVertices: ArrayLike<number>): void; computeWorldVertices(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
computeWorldVerticesWith(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number): void;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
} }
} }
@ -377,6 +402,7 @@ declare module spine {
newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment; newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment;
newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment; newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment;
newPathAttachment(skin: Skin, name: string): PathAttachment; newPathAttachment(skin: Skin, name: string): PathAttachment;
newPointAttachment(skin: Skin, name: string): PointAttachment;
} }
} }
declare module spine { declare module spine {
@ -386,6 +412,7 @@ declare module spine {
Mesh = 2, Mesh = 2,
LinkedMesh = 3, LinkedMesh = 3,
Path = 4, Path = 4,
Point = 5,
} }
} }
declare module spine { declare module spine {
@ -399,7 +426,7 @@ declare module spine {
region: TextureRegion; region: TextureRegion;
path: string; path: string;
regionUVs: ArrayLike<number>; regionUVs: ArrayLike<number>;
worldVertices: ArrayLike<number>; uvs: ArrayLike<number>;
triangles: Array<number>; triangles: Array<number>;
color: Color; color: Color;
hullLength: number; hullLength: number;
@ -408,7 +435,6 @@ declare module spine {
tempColor: Color; tempColor: Color;
constructor(name: string); constructor(name: string);
updateUVs(): void; updateUVs(): void;
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
getParentMesh(): MeshAttachment; getParentMesh(): MeshAttachment;
setParentMesh(parentMesh: MeshAttachment): void; setParentMesh(parentMesh: MeshAttachment): void;
@ -423,6 +449,17 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
} }
declare module spine {
class PointAttachment extends VertexAttachment {
x: number;
y: number;
rotation: number;
color: Color;
constructor(name: string);
computeWorldPosition(bone: Bone, point: Vector2): Vector2;
computeWorldRotation(bone: Bone): number;
}
}
declare module spine { declare module spine {
class RegionAttachment extends Attachment { class RegionAttachment extends Attachment {
static OX1: number; static OX1: number;
@ -477,12 +514,12 @@ declare module spine {
rendererObject: any; rendererObject: any;
region: TextureRegion; region: TextureRegion;
offset: ArrayLike<number>; offset: ArrayLike<number>;
vertices: ArrayLike<number>; uvs: ArrayLike<number>;
tempColor: Color; tempColor: Color;
constructor(name: string); constructor(name: string);
setRegion(region: TextureRegion): void;
updateOffset(): void; updateOffset(): void;
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>; setRegion(region: TextureRegion): void;
computeWorldVertices(bone: Bone, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
} }
} }
declare module spine { declare module spine {
@ -530,12 +567,12 @@ declare module spine {
getWorldRotationY(): number; getWorldRotationY(): number;
getWorldScaleX(): number; getWorldScaleX(): number;
getWorldScaleY(): number; getWorldScaleY(): number;
worldToLocalRotationX(): number;
worldToLocalRotationY(): number;
rotateWorld(degrees: number): void;
updateAppliedTransform(): void; updateAppliedTransform(): void;
worldToLocal(world: Vector2): Vector2; worldToLocal(world: Vector2): Vector2;
localToWorld(local: Vector2): Vector2; localToWorld(local: Vector2): Vector2;
worldToLocalRotation(worldRotation: number): number;
localToWorldRotation(localRotation: number): number;
rotateWorld(degrees: number): void;
} }
} }
declare module spine { declare module spine {
@ -735,7 +772,7 @@ declare module spine {
findIkConstraint(constraintName: string): IkConstraint; findIkConstraint(constraintName: string): IkConstraint;
findTransformConstraint(constraintName: string): TransformConstraint; findTransformConstraint(constraintName: string): TransformConstraint;
findPathConstraint(constraintName: string): PathConstraint; findPathConstraint(constraintName: string): PathConstraint;
getBounds(offset: Vector2, size: Vector2): void; getBounds(offset: Vector2, size: Vector2, temp: Array<number>): void;
update(delta: number): void; update(delta: number): void;
} }
} }
@ -827,6 +864,7 @@ declare module spine {
data: SlotData; data: SlotData;
bone: Bone; bone: Bone;
color: Color; color: Color;
darkColor: Color;
private attachment; private attachment;
private attachmentTime; private attachmentTime;
attachmentVertices: number[]; attachmentVertices: number[];
@ -844,6 +882,7 @@ declare module spine {
name: string; name: string;
boneData: BoneData; boneData: BoneData;
color: Color; color: Color;
darkColor: Color;
attachmentName: string; attachmentName: string;
blendMode: BlendMode; blendMode: BlendMode;
constructor(index: number, name: string, boneData: BoneData); constructor(index: number, name: string, boneData: BoneData);
@ -931,6 +970,10 @@ declare module spine {
constructor(data: TransformConstraintData, skeleton: Skeleton); constructor(data: TransformConstraintData, skeleton: Skeleton);
apply(): void; apply(): void;
update(): void; update(): void;
applyAbsoluteWorld(): void;
applyRelativeWorld(): void;
applyAbsoluteLocal(): void;
applyRelativeLocal(): void;
getOrder(): number; getOrder(): number;
} }
} }
@ -950,6 +993,8 @@ declare module spine {
offsetScaleX: number; offsetScaleX: number;
offsetScaleY: number; offsetScaleY: number;
offsetShearY: number; offsetShearY: number;
relative: boolean;
local: boolean;
constructor(name: string); constructor(name: string);
} }
} }
@ -1074,10 +1119,14 @@ declare module spine.threejs {
zOffset: number; zOffset: number;
private batcher; private batcher;
static QUAD_TRIANGLES: number[]; static QUAD_TRIANGLES: number[];
static VERTEX_SIZE: number;
private vertices;
private tempColor;
constructor(skeletonData: SkeletonData); constructor(skeletonData: SkeletonData);
update(deltaTime: number): void; update(deltaTime: number): void;
private updateGeometry(); private updateGeometry();
static createMesh(map: THREE.Texture): THREE.Mesh; private computeRegionVertices(slot, region, pma);
private computeMeshVertices(slot, mesh, pma);
} }
} }
declare module spine.threejs { declare module spine.threejs {

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -27,6 +27,7 @@ declare module spine {
pathConstraintPosition = 11, pathConstraintPosition = 11,
pathConstraintSpacing = 12, pathConstraintSpacing = 12,
pathConstraintMix = 13, pathConstraintMix = 13,
twoColor = 14,
} }
abstract class CurveTimeline implements Timeline { abstract class CurveTimeline implements Timeline {
static LINEAR: number; static LINEAR: number;
@ -98,6 +99,30 @@ declare module spine {
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void; setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void; apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
} }
class TwoColorTimeline extends CurveTimeline {
static ENTRIES: number;
static PREV_TIME: number;
static PREV_R: number;
static PREV_G: number;
static PREV_B: number;
static PREV_A: number;
static PREV_R2: number;
static PREV_G2: number;
static PREV_B2: number;
static R: number;
static G: number;
static B: number;
static A: number;
static R2: number;
static G2: number;
static B2: number;
slotIndex: number;
frames: ArrayLike<number>;
constructor(frameCount: number);
getPropertyId(): number;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, setupPose: boolean, mixingOut: boolean): void;
}
class AttachmentTimeline implements Timeline { class AttachmentTimeline implements Timeline {
slotIndex: number; slotIndex: number;
frames: ArrayLike<number>; frames: ArrayLike<number>;
@ -354,6 +379,7 @@ declare module spine {
newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment; newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment;
newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment; newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment;
newPathAttachment(skin: Skin, name: string): PathAttachment; newPathAttachment(skin: Skin, name: string): PathAttachment;
newPointAttachment(skin: Skin, name: string): PointAttachment;
} }
} }
declare module spine { declare module spine {
@ -366,8 +392,7 @@ declare module spine {
vertices: ArrayLike<number>; vertices: ArrayLike<number>;
worldVerticesLength: number; worldVerticesLength: number;
constructor(name: string); constructor(name: string);
computeWorldVertices(slot: Slot, worldVertices: ArrayLike<number>): void; computeWorldVertices(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
computeWorldVerticesWith(slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number): void;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
} }
} }
@ -377,6 +402,7 @@ declare module spine {
newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment; newMeshAttachment(skin: Skin, name: string, path: string): MeshAttachment;
newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment; newBoundingBoxAttachment(skin: Skin, name: string): BoundingBoxAttachment;
newPathAttachment(skin: Skin, name: string): PathAttachment; newPathAttachment(skin: Skin, name: string): PathAttachment;
newPointAttachment(skin: Skin, name: string): PointAttachment;
} }
} }
declare module spine { declare module spine {
@ -386,6 +412,7 @@ declare module spine {
Mesh = 2, Mesh = 2,
LinkedMesh = 3, LinkedMesh = 3,
Path = 4, Path = 4,
Point = 5,
} }
} }
declare module spine { declare module spine {
@ -399,7 +426,7 @@ declare module spine {
region: TextureRegion; region: TextureRegion;
path: string; path: string;
regionUVs: ArrayLike<number>; regionUVs: ArrayLike<number>;
worldVertices: ArrayLike<number>; uvs: ArrayLike<number>;
triangles: Array<number>; triangles: Array<number>;
color: Color; color: Color;
hullLength: number; hullLength: number;
@ -408,7 +435,6 @@ declare module spine {
tempColor: Color; tempColor: Color;
constructor(name: string); constructor(name: string);
updateUVs(): void; updateUVs(): void;
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
applyDeform(sourceAttachment: VertexAttachment): boolean; applyDeform(sourceAttachment: VertexAttachment): boolean;
getParentMesh(): MeshAttachment; getParentMesh(): MeshAttachment;
setParentMesh(parentMesh: MeshAttachment): void; setParentMesh(parentMesh: MeshAttachment): void;
@ -423,6 +449,17 @@ declare module spine {
constructor(name: string); constructor(name: string);
} }
} }
declare module spine {
class PointAttachment extends VertexAttachment {
x: number;
y: number;
rotation: number;
color: Color;
constructor(name: string);
computeWorldPosition(bone: Bone, point: Vector2): Vector2;
computeWorldRotation(bone: Bone): number;
}
}
declare module spine { declare module spine {
class RegionAttachment extends Attachment { class RegionAttachment extends Attachment {
static OX1: number; static OX1: number;
@ -477,12 +514,12 @@ declare module spine {
rendererObject: any; rendererObject: any;
region: TextureRegion; region: TextureRegion;
offset: ArrayLike<number>; offset: ArrayLike<number>;
vertices: ArrayLike<number>; uvs: ArrayLike<number>;
tempColor: Color; tempColor: Color;
constructor(name: string); constructor(name: string);
setRegion(region: TextureRegion): void;
updateOffset(): void; updateOffset(): void;
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>; setRegion(region: TextureRegion): void;
computeWorldVertices(bone: Bone, worldVertices: ArrayLike<number>, offset: number, stride: number): void;
} }
} }
declare module spine { declare module spine {
@ -530,12 +567,12 @@ declare module spine {
getWorldRotationY(): number; getWorldRotationY(): number;
getWorldScaleX(): number; getWorldScaleX(): number;
getWorldScaleY(): number; getWorldScaleY(): number;
worldToLocalRotationX(): number;
worldToLocalRotationY(): number;
rotateWorld(degrees: number): void;
updateAppliedTransform(): void; updateAppliedTransform(): void;
worldToLocal(world: Vector2): Vector2; worldToLocal(world: Vector2): Vector2;
localToWorld(local: Vector2): Vector2; localToWorld(local: Vector2): Vector2;
worldToLocalRotation(worldRotation: number): number;
localToWorldRotation(localRotation: number): number;
rotateWorld(degrees: number): void;
} }
} }
declare module spine { declare module spine {
@ -735,7 +772,7 @@ declare module spine {
findIkConstraint(constraintName: string): IkConstraint; findIkConstraint(constraintName: string): IkConstraint;
findTransformConstraint(constraintName: string): TransformConstraint; findTransformConstraint(constraintName: string): TransformConstraint;
findPathConstraint(constraintName: string): PathConstraint; findPathConstraint(constraintName: string): PathConstraint;
getBounds(offset: Vector2, size: Vector2): void; getBounds(offset: Vector2, size: Vector2, temp: Array<number>): void;
update(delta: number): void; update(delta: number): void;
} }
} }
@ -827,6 +864,7 @@ declare module spine {
data: SlotData; data: SlotData;
bone: Bone; bone: Bone;
color: Color; color: Color;
darkColor: Color;
private attachment; private attachment;
private attachmentTime; private attachmentTime;
attachmentVertices: number[]; attachmentVertices: number[];
@ -844,6 +882,7 @@ declare module spine {
name: string; name: string;
boneData: BoneData; boneData: BoneData;
color: Color; color: Color;
darkColor: Color;
attachmentName: string; attachmentName: string;
blendMode: BlendMode; blendMode: BlendMode;
constructor(index: number, name: string, boneData: BoneData); constructor(index: number, name: string, boneData: BoneData);
@ -931,6 +970,10 @@ declare module spine {
constructor(data: TransformConstraintData, skeleton: Skeleton); constructor(data: TransformConstraintData, skeleton: Skeleton);
apply(): void; apply(): void;
update(): void; update(): void;
applyAbsoluteWorld(): void;
applyRelativeWorld(): void;
applyAbsoluteLocal(): void;
applyRelativeLocal(): void;
getOrder(): number; getOrder(): number;
} }
} }
@ -950,6 +993,8 @@ declare module spine {
offsetScaleX: number; offsetScaleX: number;
offsetScaleY: number; offsetScaleY: number;
offsetShearY: number; offsetShearY: number;
relative: boolean;
local: boolean;
constructor(name: string); constructor(name: string);
} }
} }
@ -1393,6 +1438,7 @@ declare module spine.webgl {
private gl; private gl;
private bounds; private bounds;
private temp; private temp;
private vertices;
private static LIGHT_GRAY; private static LIGHT_GRAY;
private static GREEN; private static GREEN;
constructor(gl: WebGLRenderingContext); constructor(gl: WebGLRenderingContext);
@ -1402,11 +1448,16 @@ declare module spine.webgl {
} }
declare module spine.webgl { declare module spine.webgl {
class SkeletonRenderer { class SkeletonRenderer {
static VERTEX_SIZE: number;
static QUAD_TRIANGLES: number[]; static QUAD_TRIANGLES: number[];
premultipliedAlpha: boolean; premultipliedAlpha: boolean;
private gl; private gl;
private tempColor;
private vertices;
constructor(gl: WebGLRenderingContext); constructor(gl: WebGLRenderingContext);
draw(batcher: PolygonBatcher, skeleton: Skeleton): void; draw(batcher: PolygonBatcher, skeleton: Skeleton): void;
computeRegionVertices(slot: Slot, region: RegionAttachment, pma: boolean): ArrayLike<number>;
computeMeshVertices(slot: Slot, mesh: MeshAttachment, pma: boolean): ArrayLike<number>;
} }
} }
declare module spine.webgl { declare module spine.webgl {

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -100,7 +100,7 @@ function calculateBounds(skeleton) {
skeleton.updateWorldTransform(); skeleton.updateWorldTransform();
var offset = new spine.Vector2(); var offset = new spine.Vector2();
var size = new spine.Vector2(); var size = new spine.Vector2();
skeleton.getBounds(offset, size); skeleton.getBounds(offset, size, []);
return { offset: offset, size: size }; return { offset: offset, size: size };
} }

View File

@ -31,11 +31,14 @@
module spine.canvas { module spine.canvas {
export class SkeletonRenderer { export class SkeletonRenderer {
static QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0]; static QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
static VERTEX_SIZE = 2 + 2 + 4;
private ctx: CanvasRenderingContext2D; private ctx: CanvasRenderingContext2D;
public triangleRendering = false; public triangleRendering = false;
public debugRendering = false; public debugRendering = false;
private vertices = Utils.newFloatArray(8 * 1024);
private tempColor = new Color();
constructor (context: CanvasRenderingContext2D) { constructor (context: CanvasRenderingContext2D) {
this.ctx = context; this.ctx = context;
@ -57,10 +60,10 @@ module spine.canvas {
let attachment = slot.getAttachment(); let attachment = slot.getAttachment();
let region: TextureAtlasRegion = null; let region: TextureAtlasRegion = null;
let image: HTMLImageElement = null; let image: HTMLImageElement = null;
let vertices: ArrayLike<number> = null; let vertices: ArrayLike<number> = this.vertices;
if (attachment instanceof RegionAttachment) { if (attachment instanceof RegionAttachment) {
let regionAttachment = <RegionAttachment>attachment; let regionAttachment = <RegionAttachment>attachment;
vertices = regionAttachment.updateWorldVertices(slot, false); vertices = this.computeRegionVertices(slot, regionAttachment, false);
region = <TextureAtlasRegion>regionAttachment.region; region = <TextureAtlasRegion>regionAttachment.region;
image = (<CanvasTexture>(region).texture).getImage(); image = (<CanvasTexture>(region).texture).getImage();
@ -94,7 +97,7 @@ module spine.canvas {
private drawTriangles (skeleton: Skeleton) { private drawTriangles (skeleton: Skeleton) {
let blendMode: BlendMode = null; let blendMode: BlendMode = null;
let vertices: ArrayLike<number> = null; let vertices: ArrayLike<number> = this.vertices;
let triangles: Array<number> = null; let triangles: Array<number> = null;
let drawOrder = skeleton.drawOrder; let drawOrder = skeleton.drawOrder;
@ -105,14 +108,14 @@ module spine.canvas {
let region: TextureAtlasRegion = null; let region: TextureAtlasRegion = null;
if (attachment instanceof RegionAttachment) { if (attachment instanceof RegionAttachment) {
let regionAttachment = <RegionAttachment>attachment; let regionAttachment = <RegionAttachment>attachment;
vertices = regionAttachment.updateWorldVertices(slot, false); vertices = this.computeRegionVertices(slot, regionAttachment, false);
triangles = SkeletonRenderer.QUAD_TRIANGLES; triangles = SkeletonRenderer.QUAD_TRIANGLES;
region = <TextureAtlasRegion>regionAttachment.region; region = <TextureAtlasRegion>regionAttachment.region;
texture = (<CanvasTexture>region.texture).getImage(); texture = (<CanvasTexture>region.texture).getImage();
} else if (attachment instanceof MeshAttachment) { } else if (attachment instanceof MeshAttachment) {
let mesh = <MeshAttachment>attachment; let mesh = <MeshAttachment>attachment;
vertices = mesh.updateWorldVertices(slot, false); vertices = this.computeMeshVertices(slot, mesh, false);
triangles = mesh.triangles; triangles = mesh.triangles;
texture = (<TextureAtlasRegion>mesh.region.renderObject).texture.getImage(); texture = (<TextureAtlasRegion>mesh.region.renderObject).texture.getImage();
} else continue; } else continue;
@ -196,5 +199,88 @@ module spine.canvas {
ctx.drawImage(img, 0, 0); ctx.drawImage(img, 0, 0);
ctx.restore(); ctx.restore();
} }
private computeRegionVertices(slot: Slot, region: RegionAttachment, pma: boolean) {
let skeleton = slot.bone.skeleton;
let skeletonColor = skeleton.color;
let slotColor = slot.color;
let regionColor = region.color;
let alpha = skeletonColor.a * slotColor.a * regionColor.a;
let multiplier = pma ? alpha : 1;
let color = this.tempColor;
color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier,
skeletonColor.g * slotColor.g * regionColor.g * multiplier,
skeletonColor.b * slotColor.b * regionColor.b * multiplier,
alpha);
region.computeWorldVertices(slot.bone, this.vertices, 0, SkeletonRenderer.VERTEX_SIZE);
let vertices = this.vertices;
let uvs = region.uvs;
vertices[RegionAttachment.C1R] = color.r;
vertices[RegionAttachment.C1G] = color.g;
vertices[RegionAttachment.C1B] = color.b;
vertices[RegionAttachment.C1A] = color.a;
vertices[RegionAttachment.U1] = uvs[0];
vertices[RegionAttachment.V1] = uvs[1];
vertices[RegionAttachment.C2R] = color.r;
vertices[RegionAttachment.C2G] = color.g;
vertices[RegionAttachment.C2B] = color.b;
vertices[RegionAttachment.C2A] = color.a;
vertices[RegionAttachment.U2] = uvs[2];
vertices[RegionAttachment.V2] = uvs[3];
vertices[RegionAttachment.C3R] = color.r;
vertices[RegionAttachment.C3G] = color.g;
vertices[RegionAttachment.C3B] = color.b;
vertices[RegionAttachment.C3A] = color.a;
vertices[RegionAttachment.U3] = uvs[4];
vertices[RegionAttachment.V3] = uvs[5];
vertices[RegionAttachment.C4R] = color.r;
vertices[RegionAttachment.C4G] = color.g;
vertices[RegionAttachment.C4B] = color.b;
vertices[RegionAttachment.C4A] = color.a;
vertices[RegionAttachment.U4] = uvs[6];
vertices[RegionAttachment.V4] = uvs[7];
return vertices;
}
private computeMeshVertices(slot: Slot, mesh: MeshAttachment, pma: boolean) {
let skeleton = slot.bone.skeleton;
let skeletonColor = skeleton.color;
let slotColor = slot.color;
let regionColor = mesh.color;
let alpha = skeletonColor.a * slotColor.a * regionColor.a;
let multiplier = pma ? alpha : 1;
let color = this.tempColor;
color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier,
skeletonColor.g * slotColor.g * regionColor.g * multiplier,
skeletonColor.b * slotColor.b * regionColor.b * multiplier,
alpha);
let numVertices = mesh.worldVerticesLength / 2;
if (this.vertices.length < mesh.worldVerticesLength) {
this.vertices = Utils.newFloatArray(mesh.worldVerticesLength);
}
let vertices = this.vertices;
mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, SkeletonRenderer.VERTEX_SIZE);
let uvs = mesh.uvs;
for (let i = 0, n = numVertices, u = 0, v = 2; i < n; i++) {
vertices[v++] = color.r;
vertices[v++] = color.g;
vertices[v++] = color.b;
vertices[v++] = color.a;
vertices[v++] = uvs[u++];
vertices[v++] = uvs[u++];
v += 2;
}
return vertices;
}
} }
} }

View File

@ -38,6 +38,10 @@ module spine.threejs {
private batcher: MeshBatcher; private batcher: MeshBatcher;
static QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0]; static QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
static VERTEX_SIZE = 2 + 2 + 4;
private vertices = Utils.newFloatArray(1024);
private tempColor = new Color();
constructor (skeletonData: SkeletonData) { constructor (skeletonData: SkeletonData) {
super(); super();
@ -85,13 +89,13 @@ module spine.threejs {
let texture: ThreeJsTexture = null; let texture: ThreeJsTexture = null;
if (attachment instanceof RegionAttachment) { if (attachment instanceof RegionAttachment) {
let region = <RegionAttachment>attachment; let region = <RegionAttachment>attachment;
vertices = region.updateWorldVertices(slot, false); vertices = this.computeRegionVertices(slot, region, false);
triangles = SkeletonMesh.QUAD_TRIANGLES; triangles = SkeletonMesh.QUAD_TRIANGLES;
texture = <ThreeJsTexture>(<TextureAtlasRegion>region.region.renderObject).texture; texture = <ThreeJsTexture>(<TextureAtlasRegion>region.region.renderObject).texture;
} else if (attachment instanceof MeshAttachment) { } else if (attachment instanceof MeshAttachment) {
let mesh = <MeshAttachment>attachment; let mesh = <MeshAttachment>attachment;
vertices = mesh.updateWorldVertices(slot, false); vertices = this.computeMeshVertices(slot, mesh, false);
triangles = mesh.triangles; triangles = mesh.triangles;
texture = <ThreeJsTexture>(<TextureAtlasRegion>mesh.region.renderObject).texture; texture = <ThreeJsTexture>(<TextureAtlasRegion>mesh.region.renderObject).texture;
} else continue; } else continue;
@ -117,35 +121,87 @@ module spine.threejs {
batcher.end(); batcher.end();
} }
static createMesh(map: THREE.Texture) { private computeRegionVertices(slot: Slot, region: RegionAttachment, pma: boolean) {
let geo = new THREE.BufferGeometry(); let skeleton = slot.bone.skeleton;
let vertices = new Float32Array(1024); let skeletonColor = skeleton.color;
vertices.set([ let slotColor = slot.color;
-200, -200, 1, 0, 0, 1, 0, 0, let regionColor = region.color;
200, -200, 0, 1, 0, 1, 1, 0, let alpha = skeletonColor.a * slotColor.a * regionColor.a;
200, 200, 0, 0, 1, 1, 1, 1, let multiplier = pma ? alpha : 1;
-200, 200, 1, 1, 0, 0.1, 0, 1 let color = this.tempColor;
], 0); color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier,
let vb = new THREE.InterleavedBuffer(vertices, 8); skeletonColor.g * slotColor.g * regionColor.g * multiplier,
var positions = new THREE.InterleavedBufferAttribute(vb, 2, 0, false); skeletonColor.b * slotColor.b * regionColor.b * multiplier,
geo.addAttribute("position", positions); alpha);
var colors = new THREE.InterleavedBufferAttribute(vb, 4, 2, false);
geo.addAttribute("color", colors);
var uvs = new THREE.InterleavedBufferAttribute(vb, 2, 6, false);
geo.addAttribute("uv", colors);
var indices = new Uint16Array(1024); region.computeWorldVertices(slot.bone, this.vertices, 0, SkeletonMesh.VERTEX_SIZE);
indices.set([0, 1, 2, 2, 3, 0], 0);
geo.setIndex(new THREE.BufferAttribute(indices, 1));
geo.drawRange.start = 0;
geo.drawRange.count = 6;
let mat = new THREE.MeshBasicMaterial(); let vertices = this.vertices;
mat.vertexColors = THREE.VertexColors; let uvs = region.uvs;
mat.transparent = true;
mat.map = map; vertices[RegionAttachment.C1R] = color.r;
let mesh = new THREE.Mesh(geo, mat); vertices[RegionAttachment.C1G] = color.g;
return mesh; vertices[RegionAttachment.C1B] = color.b;
vertices[RegionAttachment.C1A] = color.a;
vertices[RegionAttachment.U1] = uvs[0];
vertices[RegionAttachment.V1] = uvs[1];
vertices[RegionAttachment.C2R] = color.r;
vertices[RegionAttachment.C2G] = color.g;
vertices[RegionAttachment.C2B] = color.b;
vertices[RegionAttachment.C2A] = color.a;
vertices[RegionAttachment.U2] = uvs[2];
vertices[RegionAttachment.V2] = uvs[3];
vertices[RegionAttachment.C3R] = color.r;
vertices[RegionAttachment.C3G] = color.g;
vertices[RegionAttachment.C3B] = color.b;
vertices[RegionAttachment.C3A] = color.a;
vertices[RegionAttachment.U3] = uvs[4];
vertices[RegionAttachment.V3] = uvs[5];
vertices[RegionAttachment.C4R] = color.r;
vertices[RegionAttachment.C4G] = color.g;
vertices[RegionAttachment.C4B] = color.b;
vertices[RegionAttachment.C4A] = color.a;
vertices[RegionAttachment.U4] = uvs[6];
vertices[RegionAttachment.V4] = uvs[7];
return vertices;
}
private computeMeshVertices(slot: Slot, mesh: MeshAttachment, pma: boolean) {
let skeleton = slot.bone.skeleton;
let skeletonColor = skeleton.color;
let slotColor = slot.color;
let regionColor = mesh.color;
let alpha = skeletonColor.a * slotColor.a * regionColor.a;
let multiplier = pma ? alpha : 1;
let color = this.tempColor;
color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier,
skeletonColor.g * slotColor.g * regionColor.g * multiplier,
skeletonColor.b * slotColor.b * regionColor.b * multiplier,
alpha);
let numVertices = mesh.worldVerticesLength / 2;
if (this.vertices.length < mesh.worldVerticesLength) {
this.vertices = Utils.newFloatArray(mesh.worldVerticesLength);
}
let vertices = this.vertices;
mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, SkeletonMesh.VERTEX_SIZE);
let uvs = mesh.uvs;
for (let i = 0, n = numVertices, u = 0, v = 2; i < n; i++) {
vertices[v++] = color.r;
vertices[v++] = color.g;
vertices[v++] = color.b;
vertices[v++] = color.a;
vertices[v++] = uvs[u++];
vertices[v++] = uvs[u++];
v += 2;
}
return vertices;
} }
} }
} }

View File

@ -143,7 +143,7 @@ module spine {
skeleton.setSkinByName(config.skin); skeleton.setSkinByName(config.skin);
skeleton.setToSetupPose(); skeleton.setToSetupPose();
skeleton.updateWorldTransform(); skeleton.updateWorldTransform();
skeleton.getBounds(bounds.offset, bounds.size); skeleton.getBounds(bounds.offset, bounds.size, []);
if (!config.fitToCanvas) { if (!config.fitToCanvas) {
skeleton.x = config.x; skeleton.x = config.x;
skeleton.y = config.y; skeleton.y = config.y;