feat: use custom player module
This commit is contained in:
159
apps/module/spine-ts/core/src/attachments/Attachment.ts
Executable file
159
apps/module/spine-ts/core/src/attachments/Attachment.ts
Executable file
@@ -0,0 +1,159 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
/** The base class for all attachments. */
|
||||
export abstract class Attachment {
|
||||
name: string;
|
||||
|
||||
constructor (name: string) {
|
||||
if (name == null) throw new Error("name cannot be null.");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
abstract copy (): Attachment;
|
||||
}
|
||||
|
||||
/** Base class for an attachment with vertices that are transformed by one or more bones and can be deformed by a slot's
|
||||
* {@link Slot#deform}. */
|
||||
export abstract class VertexAttachment extends Attachment {
|
||||
private static nextID = 0;
|
||||
|
||||
/** The unique ID for this attachment. */
|
||||
id = (VertexAttachment.nextID++ & 65535) << 11;
|
||||
|
||||
/** The bones which affect the {@link #getVertices()}. The array entries are, for each vertex, the number of bones affecting
|
||||
* the vertex followed by that many bone indices, which is the index of the bone in {@link Skeleton#bones}. Will be null
|
||||
* if this attachment has no weights. */
|
||||
bones: Array<number>;
|
||||
|
||||
/** The vertex positions in the bone's coordinate system. For a non-weighted attachment, the values are `x,y`
|
||||
* entries for each vertex. For a weighted attachment, the values are `x,y,weight` entries for each bone affecting
|
||||
* each vertex. */
|
||||
vertices: ArrayLike<number>;
|
||||
|
||||
/** The maximum number of world vertex values that can be output by
|
||||
* {@link #computeWorldVertices()} using the `count` parameter. */
|
||||
worldVerticesLength = 0;
|
||||
|
||||
/** Deform keys for the deform attachment are also applied to this attachment. May be null if no deform keys should be applied. */
|
||||
deformAttachment: VertexAttachment = this;
|
||||
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/** Transforms the attachment's local {@link vertices} to world coordinates. If the slot's {@link Slot#deform} is
|
||||
* not empty, it is used to deform the vertices.
|
||||
*
|
||||
* See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
|
||||
* Runtimes Guide.
|
||||
* @param start The index of the first {@link #vertices} value to transform. Each vertex has 2 values, x and y.
|
||||
* @param count The number of world vertex values to output. Must be <= {@link #worldVerticesLength} - `start`.
|
||||
* @param worldVertices The output world vertices. Must have a length >= `offset` + `count` *
|
||||
* `stride` / 2.
|
||||
* @param offset The `worldVertices` index to begin writing values.
|
||||
* @param stride The number of `worldVertices` entries between the value pairs written. */
|
||||
computeWorldVertices (slot: Slot, start: number, count: number, worldVertices: ArrayLike<number>, offset: number, stride: number) {
|
||||
count = offset + (count >> 1) * stride;
|
||||
let skeleton = slot.bone.skeleton;
|
||||
let deformArray = slot.deform;
|
||||
let vertices = this.vertices;
|
||||
let bones = this.bones;
|
||||
if (bones == null) {
|
||||
if (deformArray.length > 0) vertices = deformArray;
|
||||
let bone = slot.bone;
|
||||
let x = bone.worldX;
|
||||
let y = bone.worldY;
|
||||
let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
||||
for (let v = start, w = offset; w < count; v += 2, w += stride) {
|
||||
let vx = vertices[v], vy = vertices[v + 1];
|
||||
worldVertices[w] = vx * a + vy * b + x;
|
||||
worldVertices[w + 1] = vx * c + vy * d + y;
|
||||
}
|
||||
return;
|
||||
}
|
||||
let v = 0, skip = 0;
|
||||
for (let i = 0; i < start; i += 2) {
|
||||
let n = bones[v];
|
||||
v += n + 1;
|
||||
skip += n;
|
||||
}
|
||||
let skeletonBones = skeleton.bones;
|
||||
if (deformArray.length == 0) {
|
||||
for (let w = offset, b = skip * 3; w < count; w += stride) {
|
||||
let wx = 0, wy = 0;
|
||||
let n = bones[v++];
|
||||
n += v;
|
||||
for (; v < n; v++, b += 3) {
|
||||
let bone = skeletonBones[bones[v]];
|
||||
let 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;
|
||||
}
|
||||
} else {
|
||||
let deform = deformArray;
|
||||
for (let w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
|
||||
let wx = 0, wy = 0;
|
||||
let n = bones[v++];
|
||||
n += v;
|
||||
for (; v < n; v++, b += 3, f += 2) {
|
||||
let bone = skeletonBones[bones[v]];
|
||||
let 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Does not copy id (generated) or name (set on construction). **/
|
||||
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;
|
||||
attachment.deformAttachment = this.deformAttachment;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
apps/module/spine-ts/core/src/attachments/AttachmentLoader.ts
Executable file
55
apps/module/spine-ts/core/src/attachments/AttachmentLoader.ts
Executable file
@@ -0,0 +1,55 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
|
||||
/** The interface which can be implemented to customize creating and populating attachments.
|
||||
*
|
||||
* See [Loading skeleton data](http://esotericsoftware.com/spine-loading-skeleton-data#AttachmentLoader) in the Spine
|
||||
* Runtimes Guide. */
|
||||
export interface AttachmentLoader {
|
||||
/** @return May be null to not load an attachment. */
|
||||
newRegionAttachment (skin: Skin, name: string, path: string): RegionAttachment;
|
||||
|
||||
/** @return May be null to not load an attachment. */
|
||||
newMeshAttachment (skin: Skin, name: string, path: string) : MeshAttachment;
|
||||
|
||||
/** @return May be null to not load an attachment. */
|
||||
newBoundingBoxAttachment (skin: Skin, name: string) : BoundingBoxAttachment;
|
||||
|
||||
/** @return May be null to not load an attachment */
|
||||
newPathAttachment(skin: Skin, name: string): PathAttachment;
|
||||
|
||||
/** @return May be null to not load an attachment */
|
||||
newPointAttachment(skin: Skin, name: string): PointAttachment;
|
||||
|
||||
/** @return May be null to not load an attachment */
|
||||
newClippingAttachment(skin: Skin, name: string): ClippingAttachment;
|
||||
}
|
||||
}
|
||||
34
apps/module/spine-ts/core/src/attachments/AttachmentType.ts
Executable file
34
apps/module/spine-ts/core/src/attachments/AttachmentType.ts
Executable file
@@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
export enum AttachmentType {
|
||||
Region, BoundingBox, Mesh, LinkedMesh, Path, Point, Clipping
|
||||
}
|
||||
}
|
||||
51
apps/module/spine-ts/core/src/attachments/BoundingBoxAttachment.ts
Executable file
51
apps/module/spine-ts/core/src/attachments/BoundingBoxAttachment.ts
Executable file
@@ -0,0 +1,51 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
|
||||
/** An attachment with vertices that make up a polygon. Can be used for hit detection, creating physics bodies, spawning particle
|
||||
* effects, and more.
|
||||
*
|
||||
* See {@link SkeletonBounds} and [Bounding Boxes](http://esotericsoftware.com/spine-bounding-boxes) in the Spine User
|
||||
* Guide. */
|
||||
export class BoundingBoxAttachment extends VertexAttachment {
|
||||
color = new Color(1, 1, 1, 1);
|
||||
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new BoundingBoxAttachment(this.name);
|
||||
this.copyTo(copy);
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
apps/module/spine-ts/core/src/attachments/ClippingAttachment.ts
Executable file
54
apps/module/spine-ts/core/src/attachments/ClippingAttachment.ts
Executable file
@@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
/** An attachment with vertices that make up a polygon used for clipping the rendering of other attachments. */
|
||||
export class ClippingAttachment extends VertexAttachment {
|
||||
/** Clipping is performed between the clipping polygon's slot and the end slot. Returns null if clipping is done until the end of
|
||||
* the skeleton's rendering. */
|
||||
endSlot: SlotData;
|
||||
|
||||
// Nonessential.
|
||||
/** The color of the clipping polygon as it was in Spine. Available only when nonessential data was exported. Clipping polygons
|
||||
* are not usually rendered at runtime. */
|
||||
color = new Color(0.2275, 0.2275, 0.8078, 1); // ce3a3aff
|
||||
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new ClippingAttachment(this.name);
|
||||
this.copyTo(copy);
|
||||
copy.endSlot = this.endSlot;
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
198
apps/module/spine-ts/core/src/attachments/MeshAttachment.ts
Executable file
198
apps/module/spine-ts/core/src/attachments/MeshAttachment.ts
Executable file
@@ -0,0 +1,198 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
/** An attachment that displays a textured mesh. A mesh has hull vertices and internal vertices within the hull. Holes are not
|
||||
* supported. Each vertex has UVs (texture coordinates) and triangles are used to map an image on to the mesh.
|
||||
*
|
||||
* See [Mesh attachments](http://esotericsoftware.com/spine-meshes) in the Spine User Guide. */
|
||||
export class MeshAttachment extends VertexAttachment {
|
||||
region: TextureRegion;
|
||||
|
||||
/** The name of the texture region for this attachment. */
|
||||
path: string;
|
||||
|
||||
/** The UV pair for each vertex, normalized within the texture region. */
|
||||
regionUVs: ArrayLike<number>;
|
||||
|
||||
/** The UV pair for each vertex, normalized within the entire texture.
|
||||
*
|
||||
* See {@link #updateUVs}. */
|
||||
uvs: ArrayLike<number>;
|
||||
|
||||
/** Triplets of vertex indices which describe the mesh's triangulation. */
|
||||
triangles: Array<number>;
|
||||
|
||||
/** The color to tint the mesh. */
|
||||
color = new Color(1, 1, 1, 1);
|
||||
|
||||
/** The width of the mesh's image. Available only when nonessential data was exported. */
|
||||
width: number;
|
||||
|
||||
/** The height of the mesh's image. Available only when nonessential data was exported. */
|
||||
height: number;
|
||||
|
||||
/** The number of entries at the beginning of {@link #vertices} that make up the mesh hull. */
|
||||
hullLength: number;
|
||||
|
||||
/** Vertex index pairs describing edges for controling triangulation. Mesh triangles will never cross edges. Only available if
|
||||
* nonessential data was exported. Triangulation is not performed at runtime. */
|
||||
edges: Array<number>;
|
||||
|
||||
private parentMesh: MeshAttachment;
|
||||
tempColor = new Color(0, 0, 0, 0);
|
||||
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/** Calculates {@link #uvs} using {@link #regionUVs} and the {@link #region}. Must be called after changing the region UVs or
|
||||
* region. */
|
||||
updateUVs () {
|
||||
let regionUVs = this.regionUVs;
|
||||
if (this.uvs == null || this.uvs.length != regionUVs.length) this.uvs = Utils.newFloatArray(regionUVs.length);
|
||||
let uvs = this.uvs;
|
||||
let n = this.uvs.length;
|
||||
let u = this.region.u, v = this.region.v, width = 0, height = 0;
|
||||
if (this.region instanceof TextureAtlasRegion) {
|
||||
let region = this.region;
|
||||
let textureWidth = region.texture.getImage().width, textureHeight = region.texture.getImage().height;
|
||||
switch(region.degrees) {
|
||||
case 90:
|
||||
u -= (region.originalHeight - region.offsetY - region.height) / textureWidth;
|
||||
v -= (region.originalWidth - region.offsetX - region.width) / textureHeight;
|
||||
width = region.originalHeight / textureWidth;
|
||||
height = region.originalWidth / textureHeight;
|
||||
for (let i = 0; i < n; i += 2) {
|
||||
uvs[i] = u + regionUVs[i + 1] * width;
|
||||
uvs[i + 1] = v + (1 - regionUVs[i]) * height;
|
||||
}
|
||||
return;
|
||||
case 180:
|
||||
u -= (region.originalWidth - region.offsetX - region.width) / textureWidth;
|
||||
v -= region.offsetY / textureHeight;
|
||||
width = region.originalWidth / textureWidth;
|
||||
height = region.originalHeight / textureHeight;
|
||||
for (let i = 0; i < n; i += 2) {
|
||||
uvs[i] = u + (1 - regionUVs[i]) * width;
|
||||
uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height;
|
||||
}
|
||||
return;
|
||||
case 270:
|
||||
u -= region.offsetY / textureWidth;
|
||||
v -= region.offsetX / textureHeight;
|
||||
width = region.originalHeight / textureWidth;
|
||||
height = region.originalWidth / textureHeight;
|
||||
for (let i = 0; i < n; i += 2) {
|
||||
uvs[i] = u + (1 - regionUVs[i + 1]) * width;
|
||||
uvs[i + 1] = v + regionUVs[i] * height;
|
||||
}
|
||||
return;
|
||||
}
|
||||
u -= region.offsetX / textureWidth;
|
||||
v -= (region.originalHeight - region.offsetY - region.height) / textureHeight;
|
||||
width = region.originalWidth / textureWidth;
|
||||
height = region.originalHeight / textureHeight;
|
||||
} else if (this.region == null) {
|
||||
u = v = 0;
|
||||
width = height = 1;
|
||||
} else {
|
||||
width = this.region.u2 - u;
|
||||
height = this.region.v2 - v;
|
||||
}
|
||||
|
||||
for (let i = 0; i < n; i += 2) {
|
||||
uvs[i] = u + regionUVs[i] * width;
|
||||
uvs[i + 1] = v + regionUVs[i + 1] * height;
|
||||
}
|
||||
}
|
||||
|
||||
/** The parent mesh if this is a linked mesh, else null. A linked mesh shares the {@link #bones}, {@link #vertices},
|
||||
* {@link #regionUVs}, {@link #triangles}, {@link #hullLength}, {@link #edges}, {@link #width}, and {@link #height} with the
|
||||
* parent mesh, but may have a different {@link #name} or {@link #path} (and therefore a different texture). */
|
||||
getParentMesh () {
|
||||
return this.parentMesh;
|
||||
}
|
||||
|
||||
/** @param parentMesh May be null. */
|
||||
setParentMesh (parentMesh: MeshAttachment) {
|
||||
this.parentMesh = parentMesh;
|
||||
if (parentMesh != null) {
|
||||
this.bones = parentMesh.bones;
|
||||
this.vertices = parentMesh.vertices;
|
||||
this.worldVerticesLength = parentMesh.worldVerticesLength;
|
||||
this.regionUVs = parentMesh.regionUVs;
|
||||
this.triangles = parentMesh.triangles;
|
||||
this.hullLength = parentMesh.hullLength;
|
||||
this.worldVerticesLength = parentMesh.worldVerticesLength
|
||||
}
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
if (this.parentMesh != null) return this.newLinkedMesh();
|
||||
|
||||
let copy = new MeshAttachment(this.name);
|
||||
copy.region = this.region;
|
||||
copy.path = this.path;
|
||||
copy.color.setFromColor(this.color);
|
||||
|
||||
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.hullLength = this.hullLength;
|
||||
|
||||
// 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;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/** Returns a new mesh with the {@link #parentMesh} set to this mesh's parent mesh, if any, else to this mesh. **/
|
||||
newLinkedMesh (): MeshAttachment {
|
||||
let copy = new MeshAttachment(this.name);
|
||||
copy.region = this.region;
|
||||
copy.path = this.path;
|
||||
copy.color.setFromColor(this.color);
|
||||
copy.deformAttachment = this.deformAttachment;
|
||||
copy.setParentMesh(this.parentMesh != null ? this.parentMesh : this);
|
||||
copy.updateUVs();
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
66
apps/module/spine-ts/core/src/attachments/PathAttachment.ts
Executable file
66
apps/module/spine-ts/core/src/attachments/PathAttachment.ts
Executable file
@@ -0,0 +1,66 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
|
||||
/** An attachment whose vertices make up a composite Bezier curve.
|
||||
*
|
||||
* See {@link PathConstraint} and [Paths](http://esotericsoftware.com/spine-paths) in the Spine User Guide. */
|
||||
export class PathAttachment extends VertexAttachment {
|
||||
|
||||
/** The lengths along the path in the setup pose from the start of the path to the end of each Bezier curve. */
|
||||
lengths: Array<number>;
|
||||
|
||||
/** If true, the start and end knots are connected. */
|
||||
closed = false;
|
||||
|
||||
/** If true, additional calculations are performed to make calculating positions along the path more accurate. If false, fewer
|
||||
* calculations are performed but calculating positions along the path is less accurate. */
|
||||
constantSpeed = false;
|
||||
|
||||
/** The color of the path as it was in Spine. Available only when nonessential data was exported. Paths are not usually
|
||||
* rendered at runtime. */
|
||||
color = new Color(1, 1, 1, 1);
|
||||
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new PathAttachment(this.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
69
apps/module/spine-ts/core/src/attachments/PointAttachment.ts
Executable file
69
apps/module/spine-ts/core/src/attachments/PointAttachment.ts
Executable file
@@ -0,0 +1,69 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
/** An attachment which is a single point and a rotation. This can be used to spawn projectiles, particles, etc. A bone can be
|
||||
* used in similar ways, but a PointAttachment is slightly less expensive to compute and can be hidden, shown, and placed in a
|
||||
* skin.
|
||||
*
|
||||
* See [Point Attachments](http://esotericsoftware.com/spine-point-attachments) in the Spine User Guide. */
|
||||
export class PointAttachment extends VertexAttachment {
|
||||
x: number; y: number; rotation: number;
|
||||
|
||||
/** The color of the point attachment as it was in Spine. Available only when nonessential data was exported. Point attachments
|
||||
* are not usually rendered at runtime. */
|
||||
color = new Color(0.38, 0.94, 0, 1);
|
||||
|
||||
constructor (name: string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
computeWorldPosition (bone: Bone, point: Vector2) {
|
||||
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;
|
||||
}
|
||||
|
||||
computeWorldRotation (bone: Bone) {
|
||||
let cos = MathUtils.cosDeg(this.rotation), sin = MathUtils.sinDeg(this.rotation);
|
||||
let x = cos * bone.a + sin * bone.b;
|
||||
let y = cos * bone.c + sin * bone.d;
|
||||
return Math.atan2(y, x) * MathUtils.radDeg;
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new PointAttachment(this.name);
|
||||
copy.x = this.x;
|
||||
copy.y = this.y;
|
||||
copy.rotation = this.rotation;
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
234
apps/module/spine-ts/core/src/attachments/RegionAttachment.ts
Executable file
234
apps/module/spine-ts/core/src/attachments/RegionAttachment.ts
Executable file
@@ -0,0 +1,234 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2020, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
|
||||
/** An attachment that displays a textured quadrilateral.
|
||||
*
|
||||
* See [Region attachments](http://esotericsoftware.com/spine-regions) in the Spine User Guide. */
|
||||
export class RegionAttachment extends Attachment {
|
||||
static OX1 = 0;
|
||||
static OY1 = 1;
|
||||
static OX2 = 2;
|
||||
static OY2 = 3;
|
||||
static OX3 = 4;
|
||||
static OY3 = 5;
|
||||
static OX4 = 6;
|
||||
static OY4 = 7;
|
||||
|
||||
static X1 = 0;
|
||||
static Y1 = 1;
|
||||
static C1R = 2;
|
||||
static C1G = 3;
|
||||
static C1B = 4;
|
||||
static C1A = 5;
|
||||
static U1 = 6;
|
||||
static V1 = 7;
|
||||
|
||||
static X2 = 8;
|
||||
static Y2 = 9;
|
||||
static C2R = 10;
|
||||
static C2G = 11;
|
||||
static C2B = 12;
|
||||
static C2A = 13;
|
||||
static U2 = 14;
|
||||
static V2 = 15;
|
||||
|
||||
static X3 = 16;
|
||||
static Y3 = 17;
|
||||
static C3R = 18;
|
||||
static C3G = 19;
|
||||
static C3B = 20;
|
||||
static C3A = 21;
|
||||
static U3 = 22;
|
||||
static V3 = 23;
|
||||
|
||||
static X4 = 24;
|
||||
static Y4 = 25;
|
||||
static C4R = 26;
|
||||
static C4G = 27;
|
||||
static C4B = 28;
|
||||
static C4A = 29;
|
||||
static U4 = 30;
|
||||
static V4 = 31;
|
||||
|
||||
/** The local x translation. */
|
||||
x = 0;
|
||||
|
||||
/** The local y translation. */
|
||||
y = 0;
|
||||
|
||||
/** The local scaleX. */
|
||||
scaleX = 1;
|
||||
|
||||
/** The local scaleY. */
|
||||
scaleY = 1;
|
||||
|
||||
/** The local rotation. */
|
||||
rotation = 0;
|
||||
|
||||
/** The width of the region attachment in Spine. */
|
||||
width = 0;
|
||||
|
||||
/** The height of the region attachment in Spine. */
|
||||
height = 0;
|
||||
|
||||
/** The color to tint the region attachment. */
|
||||
color = new Color(1, 1, 1, 1);
|
||||
|
||||
/** The name of the texture region for this attachment. */
|
||||
path: string;
|
||||
|
||||
rendererObject: any;
|
||||
region: TextureRegion;
|
||||
|
||||
/** For each of the 4 vertices, a pair of <code>x,y</code> values that is the local position of the vertex.
|
||||
*
|
||||
* See {@link #updateOffset()}. */
|
||||
offset = Utils.newFloatArray(8);
|
||||
|
||||
|
||||
uvs = Utils.newFloatArray(8);
|
||||
|
||||
tempColor = new Color(1, 1, 1, 1);
|
||||
|
||||
constructor (name:string) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/** Calculates the {@link #offset} using the region settings. Must be called after changing region settings. */
|
||||
updateOffset () : void {
|
||||
let regionScaleX = this.width / this.region.originalWidth * this.scaleX;
|
||||
let regionScaleY = this.height / this.region.originalHeight * this.scaleY;
|
||||
let localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
|
||||
let localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
|
||||
let localX2 = localX + this.region.width * regionScaleX;
|
||||
let localY2 = localY + this.region.height * regionScaleY;
|
||||
let radians = this.rotation * Math.PI / 180;
|
||||
let cos = Math.cos(radians);
|
||||
let sin = Math.sin(radians);
|
||||
let localXCos = localX * cos + this.x;
|
||||
let localXSin = localX * sin;
|
||||
let localYCos = localY * cos + this.y;
|
||||
let localYSin = localY * sin;
|
||||
let localX2Cos = localX2 * cos + this.x;
|
||||
let localX2Sin = localX2 * sin;
|
||||
let localY2Cos = localY2 * cos + this.y;
|
||||
let localY2Sin = localY2 * sin;
|
||||
let offset = this.offset;
|
||||
offset[RegionAttachment.OX1] = localXCos - localYSin;
|
||||
offset[RegionAttachment.OY1] = localYCos + localXSin;
|
||||
offset[RegionAttachment.OX2] = localXCos - localY2Sin;
|
||||
offset[RegionAttachment.OY2] = localY2Cos + localXSin;
|
||||
offset[RegionAttachment.OX3] = localX2Cos - localY2Sin;
|
||||
offset[RegionAttachment.OY3] = localY2Cos + localX2Sin;
|
||||
offset[RegionAttachment.OX4] = localX2Cos - localYSin;
|
||||
offset[RegionAttachment.OY4] = localYCos + localX2Sin;
|
||||
}
|
||||
|
||||
setRegion (region: TextureRegion) : void {
|
||||
this.region = region;
|
||||
let uvs = this.uvs;
|
||||
if (region.rotate) {
|
||||
uvs[2] = region.u;
|
||||
uvs[3] = region.v2;
|
||||
uvs[4] = region.u;
|
||||
uvs[5] = region.v;
|
||||
uvs[6] = region.u2;
|
||||
uvs[7] = region.v;
|
||||
uvs[0] = region.u2;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/** Transforms the attachment's four vertices to world coordinates.
|
||||
*
|
||||
* See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
|
||||
* Runtimes Guide.
|
||||
* @param worldVertices The output world vertices. Must have a length >= `offset` + 8.
|
||||
* @param offset The `worldVertices` index to begin writing values.
|
||||
* @param stride The number of `worldVertices` entries between the value pairs written. */
|
||||
computeWorldVertices (bone: Bone, worldVertices: ArrayLike<number>, offset: number, stride: number) {
|
||||
let vertexOffset = this.offset;
|
||||
let x = bone.worldX, y = bone.worldY;
|
||||
let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
||||
let offsetX = 0, offsetY = 0;
|
||||
|
||||
offsetX = vertexOffset[RegionAttachment.OX1];
|
||||
offsetY = vertexOffset[RegionAttachment.OY1];
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // br
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
offset += stride;
|
||||
|
||||
offsetX = vertexOffset[RegionAttachment.OX2];
|
||||
offsetY = vertexOffset[RegionAttachment.OY2];
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // bl
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
offset += stride;
|
||||
|
||||
offsetX = vertexOffset[RegionAttachment.OX3];
|
||||
offsetY = vertexOffset[RegionAttachment.OY3];
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // ul
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
offset += stride;
|
||||
|
||||
offsetX = vertexOffset[RegionAttachment.OX4];
|
||||
offsetY = vertexOffset[RegionAttachment.OY4];
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new RegionAttachment(this.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user