mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[ts] Ported skin API changes, see #841.
This commit is contained in:
parent
b71970afa6
commit
576c1da32f
@ -87,6 +87,7 @@ public class PathAttachment extends VertexAttachment {
|
||||
System.arraycopy(lengths, 0, copy.lengths, 0, lengths.length);
|
||||
copy.closed = closed;
|
||||
copy.constantSpeed = constantSpeed;
|
||||
copy.color.set(color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
3167
spine-ts/build/spine-webgl.d.ts
vendored
3167
spine-ts/build/spine-webgl.d.ts
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -214,7 +214,7 @@ module spine {
|
||||
let slotMap = skinMap[slotName];
|
||||
for (let entryName in slotMap) {
|
||||
let attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData);
|
||||
if (attachment != null) skin.addAttachment(slotIndex, entryName, attachment);
|
||||
if (attachment != null) skin.setAttachment(slotIndex, entryName, attachment);
|
||||
}
|
||||
}
|
||||
skeletonData.skins.push(skin);
|
||||
@ -306,6 +306,9 @@ module spine {
|
||||
let color = this.getValue(map, "color", null);
|
||||
if (color != null) mesh.color.setFromString(color);
|
||||
|
||||
mesh.width = this.getValue(map, "width", 0) * scale;
|
||||
mesh.height = this.getValue(map, "height", 0) * scale;
|
||||
|
||||
let parent: string = this.getValue(map, "parent", null);
|
||||
if (parent != null) {
|
||||
mesh.inheritDeform = this.getValue(map, "deform", true);
|
||||
@ -319,6 +322,7 @@ module spine {
|
||||
mesh.regionUVs = uvs;
|
||||
mesh.updateUVs();
|
||||
|
||||
mesh.edges = this.getValue(map, "edges", null);
|
||||
mesh.hullLength = this.getValue(map, "hull", 0) * 2;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@ -28,16 +28,22 @@
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
export class SkinEntry {
|
||||
constructor(public slotIndex: number, public name: string, public attachment: Attachment) { }
|
||||
}
|
||||
|
||||
export class Skin {
|
||||
name: string;
|
||||
attachments = new Array<Map<Attachment>>();
|
||||
bones = Array<BoneData>();
|
||||
constraints = new Array<SlotData>();
|
||||
|
||||
constructor (name: string) {
|
||||
if (name == null) throw new Error("name cannot be null.");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
addAttachment (slotIndex: number, name: string, attachment: Attachment) {
|
||||
setAttachment (slotIndex: number, name: string, attachment: Attachment) {
|
||||
if (attachment == null) throw new Error("attachment cannot be null.");
|
||||
let attachments = this.attachments;
|
||||
if (slotIndex >= attachments.length) attachments.length = slotIndex + 1;
|
||||
@ -45,12 +51,124 @@ module spine {
|
||||
attachments[slotIndex][name] = attachment;
|
||||
}
|
||||
|
||||
addSkin (skin: Skin) {
|
||||
for(let i = 0; i < skin.bones.length; i++) {
|
||||
let bone = skin.bones[i];
|
||||
let contained = false;
|
||||
for (let j = 0; j < this.bones.length; j++) {
|
||||
if (this.bones[j] == bone) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contained) this.bones.push(bone);
|
||||
}
|
||||
|
||||
for(let i = 0; i < skin.constraints.length; i++) {
|
||||
let constraint = skin.constraints[i];
|
||||
let contained = false;
|
||||
for (let j = 0; j < this.constraints.length; j++) {
|
||||
if (this.constraints[j] == constraint) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contained) this.constraints.push(constraint);
|
||||
}
|
||||
|
||||
let attachments = skin.getAttachments();
|
||||
for (let i = 0; i < attachments.length; i++) {
|
||||
var attachment = attachments[i];
|
||||
this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
|
||||
}
|
||||
}
|
||||
|
||||
copySkin (skin: Skin) {
|
||||
for(let i = 0; i < skin.bones.length; i++) {
|
||||
let bone = skin.bones[i];
|
||||
let contained = false;
|
||||
for (let j = 0; j < this.bones.length; j++) {
|
||||
if (this.bones[j] == bone) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contained) this.bones.push(bone);
|
||||
}
|
||||
|
||||
for(let i = 0; i < skin.constraints.length; i++) {
|
||||
let constraint = skin.constraints[i];
|
||||
let contained = false;
|
||||
for (let j = 0; j < this.constraints.length; j++) {
|
||||
if (this.constraints[j] == constraint) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contained) this.constraints.push(constraint);
|
||||
}
|
||||
|
||||
let attachments = skin.getAttachments();
|
||||
for (let i = 0; i < attachments.length; i++) {
|
||||
var attachment = attachments[i];
|
||||
attachment.attachment = attachment.attachment.copy();
|
||||
this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
|
||||
}
|
||||
|
||||
attachments = this.getAttachments();
|
||||
for (let i = 0; i < attachments.length; i++) {
|
||||
let attachment = attachments[i];
|
||||
if (attachment.attachment instanceof MeshAttachment) {
|
||||
let mesh = attachment.attachment as MeshAttachment;
|
||||
if (mesh.getParentMesh()) {
|
||||
mesh.setParentMesh(this.getAttachment(attachment.slotIndex, mesh.getParentMesh().name) as MeshAttachment);
|
||||
mesh.updateUVs();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @return May be null. */
|
||||
getAttachment (slotIndex: number, name: string): Attachment {
|
||||
let dictionary = this.attachments[slotIndex];
|
||||
return dictionary ? dictionary[name] : null;
|
||||
}
|
||||
|
||||
removeAttachment (slotIndex: number, name: string) {
|
||||
let dictionary = this.attachments[slotIndex];
|
||||
if (dictionary) dictionary[name] = null;
|
||||
}
|
||||
|
||||
getAttachments (): Array<SkinEntry> {
|
||||
let entries = new Array<SkinEntry>();
|
||||
for (var i = 0; i < this.attachments.length; i++) {
|
||||
let slotAttachments = this.attachments[i];
|
||||
if (slotAttachments) {
|
||||
for (let name in slotAttachments) {
|
||||
let attachment = slotAttachments[name];
|
||||
if (attachment) entries.push(new SkinEntry(i, name, attachment));
|
||||
}
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
getAttachmentsForSlot (slotIndex: number, attachments: Array<SkinEntry>) {
|
||||
let slotAttachments = this.attachments[slotIndex];
|
||||
if (slotAttachments) {
|
||||
for (let name in slotAttachments) {
|
||||
let attachment = slotAttachments[name];
|
||||
if (attachment) attachments.push(new SkinEntry(slotIndex, name, attachment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear () {
|
||||
this.attachments.length = 0;
|
||||
this.bones.length = 0;
|
||||
this.constraints.length = 0;
|
||||
}
|
||||
|
||||
/** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
|
||||
attachAll (skeleton: Skeleton, oldSkin: Skin) {
|
||||
let slotIndex = 0;
|
||||
|
||||
@ -35,6 +35,8 @@ module spine {
|
||||
if (name == null) throw new Error("name cannot be null.");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
abstract copy (): Attachment;
|
||||
}
|
||||
|
||||
export abstract class VertexAttachment extends Attachment {
|
||||
@ -116,5 +118,21 @@ module spine {
|
||||
applyDeform (sourceAttachment: VertexAttachment) {
|
||||
return this == sourceAttachment;
|
||||
}
|
||||
|
||||
copyTo (attachment: VertexAttachment) {
|
||||
if (this.bones != null) {
|
||||
attachment.bones = new Array<number>(this.bones.length);
|
||||
Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
|
||||
} else
|
||||
attachment.bones = null;
|
||||
|
||||
if (this.vertices != null) {
|
||||
attachment.vertices = Utils.newFloatArray(this.vertices.length);
|
||||
Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
|
||||
} else
|
||||
attachment.vertices = null;
|
||||
|
||||
attachment.worldVerticesLength = this.worldVerticesLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,5 +34,12 @@ module spine {
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new BoundingBoxAttachment(name);
|
||||
this.copyTo(copy);
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,5 +37,13 @@ module spine {
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new ClippingAttachment(name);
|
||||
this.copyTo(copy);
|
||||
copy.endSlot = this.endSlot;
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,10 @@ module spine {
|
||||
regionUVs: ArrayLike<number>; uvs: ArrayLike<number>;
|
||||
triangles: Array<number>;
|
||||
color = new Color(1, 1, 1, 1);
|
||||
width: number;
|
||||
height: number;
|
||||
hullLength: number;
|
||||
edges: Array<number>;
|
||||
private parentMesh: MeshAttachment;
|
||||
inheritDeform = false;
|
||||
tempColor = new Color(0, 0, 0, 0);
|
||||
@ -102,33 +105,6 @@ module spine {
|
||||
}
|
||||
}
|
||||
|
||||
/*updateUVs () {
|
||||
let u = 0, v = 0, width = 0, height = 0;
|
||||
if (this.region == null) {
|
||||
u = v = 0;
|
||||
width = height = 1;
|
||||
} else {
|
||||
u = this.region.u;
|
||||
v = this.region.v;
|
||||
width = this.region.u2 - u;
|
||||
height = this.region.v2 - v;
|
||||
}
|
||||
let regionUVs = this.regionUVs;
|
||||
if (this.uvs == null || this.uvs.length != regionUVs.length) this.uvs = Utils.newFloatArray(regionUVs.length);
|
||||
let uvs = this.uvs;
|
||||
if (this.region.rotate) {
|
||||
for (let i = 0, n = uvs.length; i < n; i += 2) {
|
||||
uvs[i] = u + regionUVs[i + 1] * width;
|
||||
uvs[i + 1] = v + height - regionUVs[i] * height;
|
||||
}
|
||||
} else {
|
||||
for (let i = 0, n = uvs.length; i < n; i += 2) {
|
||||
uvs[i] = u + regionUVs[i] * width;
|
||||
uvs[i + 1] = v + regionUVs[i + 1] * height;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
applyDeform (sourceAttachment: VertexAttachment): boolean {
|
||||
return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment);
|
||||
}
|
||||
@ -150,6 +126,39 @@ module spine {
|
||||
this.worldVerticesLength = parentMesh.worldVerticesLength
|
||||
}
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new MeshAttachment(name);
|
||||
copy.region = this.region;
|
||||
copy.path = this.path;
|
||||
|
||||
if (this.parentMesh == null) {
|
||||
this.copyTo(copy);
|
||||
copy.regionUVs = new Array<number>(this.regionUVs.length);
|
||||
Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
|
||||
copy.uvs = new Array<number>(this.uvs.length);
|
||||
Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
|
||||
copy.triangles = new Array<number>(this.triangles.length);
|
||||
Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
|
||||
copy.color.setFromColor(this.color);
|
||||
copy.hullLength = this.hullLength;
|
||||
|
||||
copy.inheritDeform = this.inheritDeform;
|
||||
|
||||
// Nonessential.
|
||||
if (this.edges != null) {
|
||||
copy.edges = new Array<number>(this.edges.length);
|
||||
Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
|
||||
}
|
||||
copy.width = this.width;
|
||||
copy.height = this.height;
|
||||
} else {
|
||||
copy.setParentMesh(this.parentMesh);
|
||||
copy.updateUVs();
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,5 +36,16 @@ module spine {
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new PathAttachment(name);
|
||||
this.copyTo(copy);
|
||||
copy.lengths = new Array<number>(this.lengths.length);
|
||||
Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
|
||||
copy.closed = closed;
|
||||
copy.constantSpeed = this.constantSpeed;
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,5 +48,14 @@ module spine {
|
||||
let y = cos * bone.c + sin * bone.d;
|
||||
return Math.atan2(y, x) * MathUtils.radDeg;
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new PointAttachment(name);
|
||||
copy.x = this.x;
|
||||
copy.y = this.y;
|
||||
copy.rotation = this.rotation;
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,5 +172,23 @@ module spine {
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new RegionAttachment(name);
|
||||
copy.region = this.region;
|
||||
copy.rendererObject = this.rendererObject;
|
||||
copy.path = this.path;
|
||||
copy.x = this.x;
|
||||
copy.y = this.y;
|
||||
copy.scaleX = this.scaleX;
|
||||
copy.scaleY = this.scaleY;
|
||||
copy.rotation = this.rotation;
|
||||
copy.width = this.width;
|
||||
copy.height = this.height;
|
||||
Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
|
||||
Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ var skinsDemo = function(canvas, bgColor) {
|
||||
var skin = skins[(Math.random() * skins.length - 1) | 0];
|
||||
var attachments = skin.attachments[slot];
|
||||
for (var attachmentName in attachments) {
|
||||
newSkin.addAttachment(slot, attachmentName, attachments[attachmentName]);
|
||||
newSkin.setAttachment(slot, attachmentName, attachments[attachmentName]);
|
||||
}
|
||||
}
|
||||
setSkin(newSkin);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user