Fixed bug in SkeletonJson, used = instead of == in condition. Fixed vertex component order for mesh attachment. Fixed SkeletonRenderer.

This commit is contained in:
badlogic 2017-01-26 14:52:04 +01:00
parent fcade28c7a
commit be1a2e3cbb
10 changed files with 9806 additions and 9466 deletions

View File

@ -115,6 +115,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 +187,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 +445,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 +458,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 +468,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 +478,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 +492,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 +501,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 +515,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 +580,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 +633,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 +838,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 +930,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 +948,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 +996,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 +1019,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);
} }
} }
@ -1472,11 +1517,15 @@ 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;
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

@ -499,13 +499,19 @@ var spine;
g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent; g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent;
b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent; b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent;
} }
if (alpha == 1) if (alpha == 1) {
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
slot.darkColor.set(r2, g2, b2, 1);
}
else { else {
var color = slot.color; var light = slot.color;
if (setupPose) var dark = slot.darkColor;
color.setFromColor(slot.data.color); if (setupPose) {
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); 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.ENTRIES = 8;
@ -1991,7 +1997,7 @@ var spine;
else { else {
for (var i = 0, n = uvs.length; i < n; i += 2) { for (var i = 0, n = uvs.length; i < n; i += 2) {
uvs[i] = u + regionUVs[i] * width; uvs[i] = u + regionUVs[i] * width;
uvs[i] = v + regionUVs[i + 1] * height; uvs[i + 1] = v + regionUVs[i + 1] * height;
} }
} }
}; };
@ -4321,7 +4327,7 @@ 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 = "attachment") { if (timelineName == "attachment") {
var timeline = new spine.AttachmentTimeline(timelineMap.length); var timeline = new spine.AttachmentTimeline(timelineMap.length);
timeline.slotIndex = slotIndex; timeline.slotIndex = slotIndex;
var frameIndex = 0; var frameIndex = 0;
@ -7545,30 +7551,30 @@ var spine;
var vertices = spine.Utils.newFloatArray(4 * SkeletonRenderer.VERTEX_SIZE); var vertices = spine.Utils.newFloatArray(4 * SkeletonRenderer.VERTEX_SIZE);
region.computeWorldVertices(slot.bone, vertices, 0, SkeletonRenderer.VERTEX_SIZE); region.computeWorldVertices(slot.bone, vertices, 0, SkeletonRenderer.VERTEX_SIZE);
var uvs = region.uvs; var uvs = region.uvs;
vertices[spine.RegionAttachment.U1] = uvs[0];
vertices[spine.RegionAttachment.V1] = uvs[1];
vertices[spine.RegionAttachment.C1R] = color.r; vertices[spine.RegionAttachment.C1R] = color.r;
vertices[spine.RegionAttachment.C1G] = color.g; vertices[spine.RegionAttachment.C1G] = color.g;
vertices[spine.RegionAttachment.C1B] = color.b; vertices[spine.RegionAttachment.C1B] = color.b;
vertices[spine.RegionAttachment.C1A] = color.a; vertices[spine.RegionAttachment.C1A] = color.a;
vertices[spine.RegionAttachment.U2] = uvs[2]; vertices[spine.RegionAttachment.U1] = uvs[0];
vertices[spine.RegionAttachment.V2] = uvs[3]; vertices[spine.RegionAttachment.V1] = uvs[1];
vertices[spine.RegionAttachment.C2R] = color.r; vertices[spine.RegionAttachment.C2R] = color.r;
vertices[spine.RegionAttachment.C2G] = color.g; vertices[spine.RegionAttachment.C2G] = color.g;
vertices[spine.RegionAttachment.C2B] = color.b; vertices[spine.RegionAttachment.C2B] = color.b;
vertices[spine.RegionAttachment.C2A] = color.a; vertices[spine.RegionAttachment.C2A] = color.a;
vertices[spine.RegionAttachment.U3] = uvs[4]; vertices[spine.RegionAttachment.U2] = uvs[2];
vertices[spine.RegionAttachment.V3] = uvs[5]; vertices[spine.RegionAttachment.V2] = uvs[3];
vertices[spine.RegionAttachment.C3R] = color.r; vertices[spine.RegionAttachment.C3R] = color.r;
vertices[spine.RegionAttachment.C3G] = color.g; vertices[spine.RegionAttachment.C3G] = color.g;
vertices[spine.RegionAttachment.C3B] = color.b; vertices[spine.RegionAttachment.C3B] = color.b;
vertices[spine.RegionAttachment.C3A] = color.a; vertices[spine.RegionAttachment.C3A] = color.a;
vertices[spine.RegionAttachment.U4] = uvs[6]; vertices[spine.RegionAttachment.U3] = uvs[4];
vertices[spine.RegionAttachment.V4] = uvs[7]; vertices[spine.RegionAttachment.V3] = uvs[5];
vertices[spine.RegionAttachment.C4R] = color.r; vertices[spine.RegionAttachment.C4R] = color.r;
vertices[spine.RegionAttachment.C4G] = color.g; vertices[spine.RegionAttachment.C4G] = color.g;
vertices[spine.RegionAttachment.C4B] = color.b; vertices[spine.RegionAttachment.C4B] = color.b;
vertices[spine.RegionAttachment.C4A] = color.a; vertices[spine.RegionAttachment.C4A] = color.a;
vertices[spine.RegionAttachment.U4] = uvs[6];
vertices[spine.RegionAttachment.V4] = uvs[7];
return vertices; return vertices;
}; };
SkeletonRenderer.prototype.computeMeshVertices = function (slot, mesh, pma) { SkeletonRenderer.prototype.computeMeshVertices = function (slot, mesh, pma) {
@ -7585,12 +7591,12 @@ var spine;
mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, SkeletonRenderer.VERTEX_SIZE); mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, SkeletonRenderer.VERTEX_SIZE);
var uvs = mesh.uvs; var uvs = mesh.uvs;
for (var i = 0, n = numVertices, u = 0, v = 2; i < n; i++) { for (var i = 0, n = numVertices, u = 0, v = 2; i < n; i++) {
vertices[v++] = uvs[u++];
vertices[v++] = uvs[u++];
vertices[v++] = color.r; vertices[v++] = color.r;
vertices[v++] = color.g; vertices[v++] = color.g;
vertices[v++] = color.b; vertices[v++] = color.b;
vertices[v++] = color.a; vertices[v++] = color.a;
vertices[v++] = uvs[u++];
vertices[v++] = uvs[u++];
v += 2; v += 2;
} }
return vertices; return vertices;

File diff suppressed because one or more lines are too long

View File

@ -561,12 +561,18 @@ module spine {
g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent; g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent;
b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent; b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent;
} }
if (alpha == 1) if (alpha == 1) {
slot.color.set(r, g, b, a); slot.color.set(r, g, b, a);
else { slot.darkColor.set(r2, g2, b2, 1);
let color = slot.color; } else {
if (setupPose) color.setFromColor(slot.data.color); let light = slot.color;
color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); let 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);
} }
} }
} }

View File

@ -382,7 +382,7 @@ module spine {
if (slotIndex == -1) throw new Error("Slot not found: " + slotName); if (slotIndex == -1) throw new Error("Slot not found: " + slotName);
for (let timelineName in slotMap) { for (let timelineName in slotMap) {
let timelineMap = slotMap[timelineName]; let timelineMap = slotMap[timelineName];
if (timelineName = "attachment") { if (timelineName == "attachment") {
let timeline = new AttachmentTimeline(timelineMap.length); let timeline = new AttachmentTimeline(timelineMap.length);
timeline.slotIndex = slotIndex; timeline.slotIndex = slotIndex;

View File

@ -66,7 +66,7 @@ module spine {
} else { } else {
for (let i = 0, n = uvs.length; i < n; i += 2) { for (let i = 0, n = uvs.length; i < n; i += 2) {
uvs[i] = u + regionUVs[i] * width; uvs[i] = u + regionUVs[i] * width;
uvs[i] = v + regionUVs[i + 1] * height; uvs[i + 1] = v + regionUVs[i + 1] * height;
} }
} }
} }

View File

@ -29,7 +29,7 @@ var skeletonRenderer;
var debugRenderer; var debugRenderer;
var shapes; var shapes;
var skeletons = {}; var skeletons = {};
var activeSkeleton = "raptor"; var activeSkeleton = "vine";
function init () { function init () {
// Setup canvas and WebGL context. We pass alpha: false to canvas.getContext() so we don't use premultiplied alpha when // Setup canvas and WebGL context. We pass alpha: false to canvas.getContext() so we don't use premultiplied alpha when

View File

@ -94,33 +94,33 @@ module spine.webgl {
let uvs = region.uvs; let uvs = region.uvs;
vertices[RegionAttachment.U1] = uvs[0];
vertices[RegionAttachment.V1] = uvs[1];
vertices[RegionAttachment.C1R] = color.r; vertices[RegionAttachment.C1R] = color.r;
vertices[RegionAttachment.C1G] = color.g; vertices[RegionAttachment.C1G] = color.g;
vertices[RegionAttachment.C1B] = color.b; vertices[RegionAttachment.C1B] = color.b;
vertices[RegionAttachment.C1A] = color.a; vertices[RegionAttachment.C1A] = color.a;
vertices[RegionAttachment.U1] = uvs[0];
vertices[RegionAttachment.V1] = uvs[1];
vertices[RegionAttachment.U2] = uvs[2];
vertices[RegionAttachment.V2] = uvs[3];
vertices[RegionAttachment.C2R] = color.r; vertices[RegionAttachment.C2R] = color.r;
vertices[RegionAttachment.C2G] = color.g; vertices[RegionAttachment.C2G] = color.g;
vertices[RegionAttachment.C2B] = color.b; vertices[RegionAttachment.C2B] = color.b;
vertices[RegionAttachment.C2A] = color.a; vertices[RegionAttachment.C2A] = color.a;
vertices[RegionAttachment.U2] = uvs[2];
vertices[RegionAttachment.V2] = uvs[3];
vertices[RegionAttachment.U3] = uvs[4];
vertices[RegionAttachment.V3] = uvs[5];
vertices[RegionAttachment.C3R] = color.r; vertices[RegionAttachment.C3R] = color.r;
vertices[RegionAttachment.C3G] = color.g; vertices[RegionAttachment.C3G] = color.g;
vertices[RegionAttachment.C3B] = color.b; vertices[RegionAttachment.C3B] = color.b;
vertices[RegionAttachment.C3A] = color.a; vertices[RegionAttachment.C3A] = color.a;
vertices[RegionAttachment.U3] = uvs[4];
vertices[RegionAttachment.V3] = uvs[5];
vertices[RegionAttachment.U4] = uvs[6];
vertices[RegionAttachment.V4] = uvs[7];
vertices[RegionAttachment.C4R] = color.r; vertices[RegionAttachment.C4R] = color.r;
vertices[RegionAttachment.C4G] = color.g; vertices[RegionAttachment.C4G] = color.g;
vertices[RegionAttachment.C4B] = color.b; vertices[RegionAttachment.C4B] = color.b;
vertices[RegionAttachment.C4A] = color.a; vertices[RegionAttachment.C4A] = color.a;
vertices[RegionAttachment.U4] = uvs[6];
vertices[RegionAttachment.V4] = uvs[7];
return vertices; return vertices;
} }
@ -144,12 +144,12 @@ module spine.webgl {
let uvs = mesh.uvs; let uvs = mesh.uvs;
for (let i = 0, n = numVertices, u = 0, v = 2; i < n; i++) { for (let i = 0, n = numVertices, u = 0, v = 2; i < n; i++) {
vertices[v++] = uvs[u++];
vertices[v++] = uvs[u++];
vertices[v++] = color.r; vertices[v++] = color.r;
vertices[v++] = color.g; vertices[v++] = color.g;
vertices[v++] = color.b; vertices[v++] = color.b;
vertices[v++] = color.a; vertices[v++] = color.a;
vertices[v++] = uvs[u++];
vertices[v++] = uvs[u++];
v += 2; v += 2;
} }