From 1ef33f1d1afd72a2f51e1c722297653f5bf63faf Mon Sep 17 00:00:00 2001 From: Luke Ingram Date: Wed, 14 Sep 2022 17:37:58 -0400 Subject: [PATCH] [ts] Port of d6adbe9. See https://github.com/EsotericSoftware/spine-runtimes/commit/d6adbe96d8af8ad19aaf9203434fb0e78d35e88a --- .../src/attachments/RegionAttachment.ts | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/spine-ts/spine-core/src/attachments/RegionAttachment.ts b/spine-ts/spine-core/src/attachments/RegionAttachment.ts index 598bcfda9..6df55fa4b 100644 --- a/spine-ts/spine-core/src/attachments/RegionAttachment.ts +++ b/spine-ts/spine-core/src/attachments/RegionAttachment.ts @@ -88,6 +88,20 @@ export class RegionAttachment extends Attachment implements HasTextureRegion { updateRegion (): void { if (!this.region) throw new Error("Region not set."); let region = this.region; + let uvs = this.uvs; + + if (region == null) { + uvs[0] = 0; + uvs[1] = 0; + uvs[2] = 1; + uvs[3] = 1; + uvs[4] = 1; + uvs[5] = 1; + uvs[6] = 1; + uvs[7] = 0; + return; + } + 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; @@ -116,25 +130,24 @@ export class RegionAttachment extends Attachment implements HasTextureRegion { offset[6] = localX2Cos - localYSin; offset[7] = localYCos + localX2Sin; - let uvs = this.uvs; if (region.degrees == 90) { + uvs[0] = region.u2; + uvs[1] = region.v; + uvs[2] = region.u2; + uvs[3] = region.v2; + uvs[4] = region.u; + uvs[5] = region.v2; + uvs[6] = region.u; + uvs[7] = region.v; + } else { + uvs[0] = region.u2; + uvs[1] = region.v2; 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; } }