From 9f5ce06f17a31b82320feebd5f3d765eb4f65041 Mon Sep 17 00:00:00 2001 From: Luke Ingram Date: Wed, 14 Sep 2022 17:32:13 -0400 Subject: [PATCH 01/11] [sdl] Port of 899f7d7 Also, fix typo in README.md. --- spine-sdl/README.md | 2 +- spine-sdl/src/spine-sdl-cpp.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-sdl/README.md b/spine-sdl/README.md index 565a90ac5..e5ed9d110 100644 --- a/spine-sdl/README.md +++ b/spine-sdl/README.md @@ -24,7 +24,7 @@ spine-sdl supports all Spine features except premultiplied alpha, screen blend m 1. Create a new SDL project. See the [SDL documentation](https://wiki.libsdl.org/FrontPage) or have a look at the example in this repository. 2. Download the Spine Runtimes source using git (`git clone https://github.com/esotericsoftware/spine-runtimes`) or download it as a zip via the download button above. 3. If you are using C, add the sources from `spine-c/spine-c/src/spine` and `spine-sdl/src/spine-sdl-c.c` to your project, and add the folder `spine-c/spine-c/include` and `spine-sdl/src/spine-sdl-c.h` to your header search path. Note that includes are specified as `#inclue `, so the `spine` directory cannot be omitted when copying the source files. -3. If you are using C++, add the sources from `spine-cpp/spine-cpp/src/spine` and `spine-sdl/src/spine-sdl-cpp.cpp` to your project, and add the folder `spine-cpp/spine-cpp/include` and `spine-sdl/src/spine-sdl-cpp.h` to your header search path. Note that includes are specified as `#inclue `, so the `spine` directory cannot be omitted when copying the source files. +3. If you are using C++, add the sources from `spine-cpp/spine-cpp/src/spine` and `spine-sdl/src/spine-sdl-cpp.cpp` to your project, and add the folder `spine-cpp/spine-cpp/include` and `spine-sdl/src/spine-sdl-cpp.h` to your header search path. Note that includes are specified as `#include `, so the `spine` directory cannot be omitted when copying the source files. See the [Spine Runtimes documentation](http://esotericsoftware.com/spine-documentation#runtimesTitle) on how to use the APIs or check out the Spine SDL example in this repository. diff --git a/spine-sdl/src/spine-sdl-cpp.cpp b/spine-sdl/src/spine-sdl-cpp.cpp index 365abf221..353a8b3ef 100644 --- a/spine-sdl/src/spine-sdl-cpp.cpp +++ b/spine-sdl/src/spine-sdl-cpp.cpp @@ -114,8 +114,8 @@ void SkeletonDrawable::draw(SDL_Renderer *renderer) { } worldVertices.setSize(mesh->getWorldVerticesLength(), 0); - texture = (SDL_Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2); + texture = (SDL_Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); verticesCount = mesh->getWorldVerticesLength() >> 1; uvs = &mesh->getUVs(); indices = &mesh->getTriangles(); From 1ef33f1d1afd72a2f51e1c722297653f5bf63faf Mon Sep 17 00:00:00 2001 From: Luke Ingram Date: Wed, 14 Sep 2022 17:37:58 -0400 Subject: [PATCH 02/11] [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; } } From dc978ed05d13b04017c47ac7fb007c79b4149630 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 07:45:30 +0200 Subject: [PATCH 03/11] [ts] Fix port of 899f7d7 --- spine-ts/spine-canvas/src/SkeletonRenderer.ts | 5 +++- .../src/attachments/RegionAttachment.ts | 24 +++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/spine-ts/spine-canvas/src/SkeletonRenderer.ts b/spine-ts/spine-canvas/src/SkeletonRenderer.ts index 67340c5bd..4b4a7fd31 100644 --- a/spine-ts/spine-canvas/src/SkeletonRenderer.ts +++ b/spine-ts/spine-canvas/src/SkeletonRenderer.ts @@ -30,6 +30,8 @@ import { Utils, Color, Skeleton, RegionAttachment, TextureAtlasRegion, BlendMode, MeshAttachment, Slot } from "@esotericsoftware/spine-core"; import { CanvasTexture } from "./CanvasTexture"; +const worldVertices = Utils.newFloatArray(8); + export class SkeletonRenderer { static QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0]; static VERTEX_SIZE = 2 + 2 + 4; @@ -64,7 +66,8 @@ export class SkeletonRenderer { if (!bone.active) continue; let attachment = slot.getAttachment(); - if (!(attachment instanceof RegionAttachment)) continue; + if (!(attachment instanceof RegionAttachment)) continue; + attachment.computeWorldVertices(slot, worldVertices, 0, 2); let region: TextureAtlasRegion = attachment.region; let image: HTMLImageElement = (region.page.texture).getImage() as HTMLImageElement; diff --git a/spine-ts/spine-core/src/attachments/RegionAttachment.ts b/spine-ts/spine-core/src/attachments/RegionAttachment.ts index 6df55fa4b..7aafebbc5 100644 --- a/spine-ts/spine-core/src/attachments/RegionAttachment.ts +++ b/spine-ts/spine-core/src/attachments/RegionAttachment.ts @@ -93,7 +93,7 @@ export class RegionAttachment extends Attachment implements HasTextureRegion { if (region == null) { uvs[0] = 0; uvs[1] = 0; - uvs[2] = 1; + uvs[2] = 0; uvs[3] = 1; uvs[4] = 1; uvs[5] = 1; @@ -131,23 +131,23 @@ export class RegionAttachment extends Attachment implements HasTextureRegion { offset[7] = localYCos + localX2Sin; 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; } } From ba5f89f3610381a9111c74fef3481467b5c3d25c Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 07:46:33 +0200 Subject: [PATCH 04/11] [ts] Correct order of UV assignements in RegionAttachment.updateRegion() --- spine-ts/spine-core/src/attachments/RegionAttachment.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-ts/spine-core/src/attachments/RegionAttachment.ts b/spine-ts/spine-core/src/attachments/RegionAttachment.ts index 7aafebbc5..6c46306a2 100644 --- a/spine-ts/spine-core/src/attachments/RegionAttachment.ts +++ b/spine-ts/spine-core/src/attachments/RegionAttachment.ts @@ -131,14 +131,14 @@ export class RegionAttachment extends Attachment implements HasTextureRegion { offset[7] = localYCos + localX2Sin; if (region.degrees == 90) { + 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; From 975a3fa30aa9a80310fadf6bb77a0ff80fcf1303 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 07:48:58 +0200 Subject: [PATCH 05/11] [libgdx] Fix UVs for null region in RegionAttachment.updateRegion() --- .../esotericsoftware/spine/attachments/RegionAttachment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java index 5b439df7d..2ea4d4a90 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java @@ -84,7 +84,7 @@ public class RegionAttachment extends Attachment implements HasTextureRegion { if (region == null) { uvs[BLX] = 0; uvs[BLY] = 0; - uvs[ULX] = 1; + uvs[ULX] = 0; uvs[ULY] = 1; uvs[URX] = 1; uvs[URY] = 1; From 531e256d6dca0603d9d7140839c5b07f6fa958a8 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 07:58:12 +0200 Subject: [PATCH 06/11] [c][cpp][sfml] Fixes #2154 --- spine-c/spine-c/src/spine/AnimationState.c | 3 +- spine-c/spine-c/src/spine/RegionAttachment.c | 49 +++++++++++++------ spine-c/spine-c/src/spine/Skeleton.c | 2 - .../spine-cpp/src/spine/RegionAttachment.cpp | 12 +++++ spine-sfml/c/src/spine/spine-sfml.cpp | 2 +- spine-sfml/cpp/src/spine/spine-sfml.cpp | 8 +-- 6 files changed, 50 insertions(+), 26 deletions(-) diff --git a/spine-c/spine-c/src/spine/AnimationState.c b/spine-c/spine-c/src/spine/AnimationState.c index e6ede4220..72381620a 100644 --- a/spine-c/spine-c/src/spine/AnimationState.c +++ b/spine-c/spine-c/src/spine/AnimationState.c @@ -595,7 +595,8 @@ _spAnimationState_setAttachment(spAnimationState *self, spSkeleton *skeleton, sp /* @param target After the first and before the last entry. */ static int binarySearch1(float *values, int valuesLength, float target) { - for (int i = 1; i < valuesLength; i++) { + int i; + for (i = 1; i < valuesLength; i++) { if (values[i] > target) return (int) (i - 1); } return (int) valuesLength - 1; diff --git a/spine-c/spine-c/src/spine/RegionAttachment.c b/spine-c/spine-c/src/spine/RegionAttachment.c index f888d6100..14a2224f4 100644 --- a/spine-c/spine-c/src/spine/RegionAttachment.c +++ b/spine-c/spine-c/src/spine/RegionAttachment.c @@ -79,22 +79,39 @@ spRegionAttachment *spRegionAttachment_create(const char *name) { } void spRegionAttachment_updateRegion(spRegionAttachment *self) { - float regionScaleX = self->width / self->region->originalWidth * self->scaleX; - float regionScaleY = self->height / self->region->originalHeight * self->scaleY; - float localX = -self->width / 2 * self->scaleX + self->region->offsetX * regionScaleX; - float localY = -self->height / 2 * self->scaleY + self->region->offsetY * regionScaleY; - float localX2 = localX + self->region->width * regionScaleX; - float localY2 = localY + self->region->height * regionScaleY; - float radians = self->rotation * DEG_RAD; - float cosine = COS(radians), sine = SIN(radians); - float localXCos = localX * cosine + self->x; - float localXSin = localX * sine; - float localYCos = localY * cosine + self->y; - float localYSin = localY * sine; - float localX2Cos = localX2 * cosine + self->x; - float localX2Sin = localX2 * sine; - float localY2Cos = localY2 * cosine + self->y; - float localY2Sin = localY2 * sine; + float regionScaleX, regionScaleY, localX, localY, localX2, localY2; + float radians, cosine, sine; + float localXCos, localXSin, localYCos, localYSin, localX2Cos, localX2Sin, localY2Cos, localY2Sin; + + if (self->region == NULL) { + self->uvs[0] = 0; + self->uvs[1] = 0; + self->uvs[2] = 1; + self->uvs[3] = 1; + self->uvs[4] = 1; + self->uvs[5] = 0; + self->uvs[6] = 0; + self->uvs[7] = 0; + return; + } + + regionScaleX = self->width / self->region->originalWidth * self->scaleX; + regionScaleY = self->height / self->region->originalHeight * self->scaleY; + localX = -self->width / 2 * self->scaleX + self->region->offsetX * regionScaleX; + localY = -self->height / 2 * self->scaleY + self->region->offsetY * regionScaleY; + localX2 = localX + self->region->width * regionScaleX; + localY2 = localY + self->region->height * regionScaleY; + radians = self->rotation * DEG_RAD; + cosine = COS(radians), sine = SIN(radians); + localXCos = localX * cosine + self->x; + localXSin = localX * sine; + localYCos = localY * cosine + self->y; + localYSin = localY * sine; + localX2Cos = localX2 * cosine + self->x; + localX2Sin = localX2 * sine; + localY2Cos = localY2 * cosine + self->y; + localY2Sin = localY2 * sine; + self->offset[BLX] = localXCos - localYSin; self->offset[BLY] = localYCos + localXSin; self->offset[ULX] = localXCos - localY2Sin; diff --git a/spine-c/spine-c/src/spine/Skeleton.c b/spine-c/spine-c/src/spine/Skeleton.c index 953f36e86..a637ba6f8 100644 --- a/spine-c/spine-c/src/spine/Skeleton.c +++ b/spine-c/spine-c/src/spine/Skeleton.c @@ -437,7 +437,6 @@ void spSkeleton_updateWorldTransformWith(const spSkeleton *self, const spBone *p /* Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection. */ int i; float rotationY, la, lb, lc, ld; - _spUpdate *updateCache; _spSkeleton *internal = SUB_CAST(_spSkeleton, self); spBone *rootBone = self->root; float pa = parent->a, pb = parent->b, pc = parent->c, pd = parent->d; @@ -455,7 +454,6 @@ void spSkeleton_updateWorldTransformWith(const spSkeleton *self, const spBone *p CONST_CAST(float, rootBone->d) = (pc * lb + pd * ld) * self->scaleY; /* Update everything except root bone. */ - updateCache = internal->updateCache; for (i = 0; i < internal->updateCacheCount; ++i) { _spUpdate *update = internal->updateCache + i; switch (update->type) { diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index 14ea9746a..5b4d14e1a 100644 --- a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp @@ -68,6 +68,18 @@ RegionAttachment::~RegionAttachment() { } void RegionAttachment::updateRegion() { + if (_region == NULL) { + _uvs[BLX] = 0; + _uvs[BLY] = 0; + _uvs[ULX] = 0; + _uvs[ULY] = 1; + _uvs[URX] = 1; + _uvs[URY] = 1; + _uvs[BRX] = 1; + _uvs[BRY] = 0; + return; + } + float regionScaleX = _width / _region->originalWidth * _scaleX; float regionScaleY = _height / _region->originalHeight * _scaleY; float localX = -_width / 2 * _scaleX + _region->offsetX * regionScaleX; diff --git a/spine-sfml/c/src/spine/spine-sfml.cpp b/spine-sfml/c/src/spine/spine-sfml.cpp index 71615b672..372cf5080 100644 --- a/spine-sfml/c/src/spine/spine-sfml.cpp +++ b/spine-sfml/c/src/spine/spine-sfml.cpp @@ -211,12 +211,12 @@ namespace spine { } if (mesh->super.worldVerticesLength > SPINE_MESH_VERTEX_COUNT_MAX) continue; - texture = (Texture *) ((spAtlasRegion *) mesh->rendererObject)->page->rendererObject; spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2); verticesCount = mesh->super.worldVerticesLength >> 1; uvs = mesh->uvs; indices = mesh->triangles; indicesCount = mesh->trianglesCount; + texture = (Texture *) ((spAtlasRegion *) mesh->rendererObject)->page->rendererObject; } else if (attachment->type == SP_ATTACHMENT_CLIPPING) { spClippingAttachment *clip = (spClippingAttachment *) slot->attachment; diff --git a/spine-sfml/cpp/src/spine/spine-sfml.cpp b/spine-sfml/cpp/src/spine/spine-sfml.cpp index 98962be00..a10ab7fee 100644 --- a/spine-sfml/cpp/src/spine/spine-sfml.cpp +++ b/spine-sfml/cpp/src/spine/spine-sfml.cpp @@ -103,7 +103,6 @@ namespace spine { } Vector *vertices = &worldVertices; - int verticesCount = 0; Vector *uvs = NULL; Vector *indices = NULL; int indicesCount = 0; @@ -121,7 +120,6 @@ namespace spine { worldVertices.setSize(8, 0); regionAttachment->computeWorldVertices(slot, worldVertices, 0, 2); - verticesCount = 4; uvs = ®ionAttachment->getUVs(); indices = &quadIndices; indicesCount = 6; @@ -138,12 +136,11 @@ namespace spine { } worldVertices.setSize(mesh->getWorldVerticesLength(), 0); - texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); - mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2); - verticesCount = mesh->getWorldVerticesLength() >> 1; + mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2); uvs = &mesh->getUVs(); indices = &mesh->getTriangles(); indicesCount = mesh->getTriangles().size(); + texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); } else if (attachment->getRTTI().isExactly(ClippingAttachment::rtti)) { ClippingAttachment *clip = (ClippingAttachment *) slot.getAttachment(); @@ -216,7 +213,6 @@ namespace spine { if (clipper.isClipping()) { clipper.clipTriangles(worldVertices, *indices, *uvs, 2); vertices = &clipper.getClippedVertices(); - verticesCount = clipper.getClippedVertices().size() >> 1; uvs = &clipper.getClippedUVs(); indices = &clipper.getClippedTriangles(); indicesCount = clipper.getClippedTriangles().size(); From 98980e02d3f7bc14ea03e63b3e05fed98a172df2 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 08:03:25 +0200 Subject: [PATCH 07/11] [csharp] Fix port of 2154 --- spine-csharp/src/Attachments/RegionAttachment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-csharp/src/Attachments/RegionAttachment.cs b/spine-csharp/src/Attachments/RegionAttachment.cs index 0e7197ea7..1e1ec929e 100644 --- a/spine-csharp/src/Attachments/RegionAttachment.cs +++ b/spine-csharp/src/Attachments/RegionAttachment.cs @@ -97,7 +97,7 @@ namespace Spine { if (region == null) { uvs[BLX] = 0; uvs[BLY] = 0; - uvs[ULX] = 1; + uvs[ULX] = 0; uvs[ULY] = 1; uvs[URX] = 1; uvs[URY] = 1; From 34534d0e90b900d0ee479a0cff14bf73695b9943 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 08:09:48 +0200 Subject: [PATCH 08/11] [godot] Call computeWorldVertices before fetching region. See #2154 --- spine-godot/spine_godot/SpineSprite.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp index 9eb9ceb7c..ed1ebba72 100644 --- a/spine-godot/spine_godot/SpineSprite.cpp +++ b/spine-godot/spine_godot/SpineSprite.cpp @@ -552,10 +552,10 @@ void SpineSprite::update_meshes(Ref skeleton_ref) { if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) { auto *region = (spine::RegionAttachment *) attachment; - renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region->getRendererObject())->page->getRendererObject(); vertices->setSize(8, 0); region->computeWorldVertices(*slot, *vertices, 0); + renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region->getRendererObject())->page->getRendererObject(); uvs = ®ion->getUVs(); indices = &quad_indices; @@ -566,10 +566,10 @@ void SpineSprite::update_meshes(Ref skeleton_ref) { tint.a *= attachment_color.a; } else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) { auto *mesh = (spine::MeshAttachment *) attachment; - renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); vertices->setSize(mesh->getWorldVerticesLength(), 0); mesh->computeWorldVertices(*slot, *vertices); + renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); uvs = &mesh->getUVs(); indices = &mesh->getTriangles(); From d890eed2dcb230cceb547ac76d1b672554d301d1 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 08:32:44 +0200 Subject: [PATCH 09/11] [cocos2dx] Update README.md for M1. --- spine-cocos2dx/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spine-cocos2dx/README.md b/spine-cocos2dx/README.md index 7c3a0b643..a025533b8 100644 --- a/spine-cocos2dx/README.md +++ b/spine-cocos2dx/README.md @@ -68,12 +68,14 @@ Execute the following on the command line: ``` cd spine-runtimes/spine-cocos2dx/example -mkdir build-macos && cmake . -GXcode -Bbuild-macos +mkdir build-macos && cmake . -GXcode -Bbuild-macos -DCMAKE_OSX_ARCHITECTURES=x86_64 open build-macos/spine-cocos2dx-example.xcodeproj ``` This will generate an Xcode project in `build-macos/spine-cocos2dx-example.xcodeproj` and open it in Xcode. To build and run the example, select the `spine-cocos2dx-example` scheme and press `CMD + R`. +> **NOTE:** Passing `-DCMAKE_OSX_ARCHITECTURES=x86_64` to CMake is currently required, as Cocos2d-X only provides prebuilt x86_64 binaries for its external dependencies. + ### iOS Execute the following on the command line: From 25719370c7cf6741b21515676e20fee5a9989636 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 08:36:00 +0200 Subject: [PATCH 10/11] [ue4] Call computeWorldVertices before fetching renderer object. See #2154. --- .../Source/SpinePlugin/Private/SSpineWidget.cpp | 8 ++++---- .../Private/SpineSkeletonRendererComponent.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp index 4a845f1f1..2b0fb3381 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp @@ -273,18 +273,18 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList &OutDrawEle if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { RegionAttachment *regionAttachment = (RegionAttachment *) attachment; - attachmentColor.set(regionAttachment->getColor()); - attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); + attachmentColor.set(regionAttachment->getColor()); regionAttachment->computeWorldVertices(*slot, *attachmentVertices, 0, 2); + attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); attachmentIndices = quadIndices; attachmentUvs = regionAttachment->getUVs().buffer(); numVertices = 4; numIndices = 6; } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { MeshAttachment *mesh = (MeshAttachment *) attachment; - attachmentColor.set(mesh->getColor()); - attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject(); + attachmentColor.set(mesh->getColor()); mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), attachmentVertices->buffer(), 0, 2); + attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject(); attachmentIndices = mesh->getTriangles().buffer(); attachmentUvs = mesh->getUVs().buffer(); numVertices = mesh->getWorldVerticesLength() >> 1; diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp index 7b9eeedba..fbf2ad5cc 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp @@ -235,9 +235,9 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) { continue; } - attachmentColor.set(regionAttachment->getColor()); - attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); + attachmentColor.set(regionAttachment->getColor()); regionAttachment->computeWorldVertices(*slot, *attachmentVertices, 0, 2); + attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); attachmentIndices = quadIndices; attachmentUvs = regionAttachment->getUVs().buffer(); numVertices = 4; @@ -251,9 +251,9 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) { continue; } - attachmentColor.set(mesh->getColor()); - attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject(); + attachmentColor.set(mesh->getColor()); mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), attachmentVertices->buffer(), 0, 2); + attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject(); attachmentIndices = mesh->getTriangles().buffer(); attachmentUvs = mesh->getUVs().buffer(); numVertices = mesh->getWorldVerticesLength() >> 1; From 669af9f6bbaac8409250441a297f5e7786d22ab6 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 15 Sep 2022 08:37:55 +0200 Subject: [PATCH 11/11] Formatting. --- spine-c/spine-c/src/spine/AnimationState.c | 2 +- spine-c/spine-c/src/spine/RegionAttachment.c | 28 +++++++++---------- .../spine-cpp/src/spine/RegionAttachment.cpp | 22 +++++++-------- spine-godot/spine_godot/SpineSprite.cpp | 4 +-- spine-sfml/c/src/spine/spine-sfml.cpp | 2 +- spine-sfml/cpp/src/spine/spine-sfml.cpp | 4 +-- spine-ts/spine-canvas/src/SkeletonRenderer.ts | 2 +- .../SpinePlugin/Private/SSpineWidget.cpp | 4 +-- .../SpineSkeletonRendererComponent.cpp | 4 +-- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/spine-c/spine-c/src/spine/AnimationState.c b/spine-c/spine-c/src/spine/AnimationState.c index 72381620a..2ff7f484c 100644 --- a/spine-c/spine-c/src/spine/AnimationState.c +++ b/spine-c/spine-c/src/spine/AnimationState.c @@ -595,7 +595,7 @@ _spAnimationState_setAttachment(spAnimationState *self, spSkeleton *skeleton, sp /* @param target After the first and before the last entry. */ static int binarySearch1(float *values, int valuesLength, float target) { - int i; + int i; for (i = 1; i < valuesLength; i++) { if (values[i] > target) return (int) (i - 1); } diff --git a/spine-c/spine-c/src/spine/RegionAttachment.c b/spine-c/spine-c/src/spine/RegionAttachment.c index 14a2224f4..b91ce5bef 100644 --- a/spine-c/spine-c/src/spine/RegionAttachment.c +++ b/spine-c/spine-c/src/spine/RegionAttachment.c @@ -79,21 +79,21 @@ spRegionAttachment *spRegionAttachment_create(const char *name) { } void spRegionAttachment_updateRegion(spRegionAttachment *self) { - float regionScaleX, regionScaleY, localX, localY, localX2, localY2; - float radians, cosine, sine; - float localXCos, localXSin, localYCos, localYSin, localX2Cos, localX2Sin, localY2Cos, localY2Sin; + float regionScaleX, regionScaleY, localX, localY, localX2, localY2; + float radians, cosine, sine; + float localXCos, localXSin, localYCos, localYSin, localX2Cos, localX2Sin, localY2Cos, localY2Sin; - if (self->region == NULL) { - self->uvs[0] = 0; - self->uvs[1] = 0; - self->uvs[2] = 1; - self->uvs[3] = 1; - self->uvs[4] = 1; - self->uvs[5] = 0; - self->uvs[6] = 0; - self->uvs[7] = 0; - return; - } + if (self->region == NULL) { + self->uvs[0] = 0; + self->uvs[1] = 0; + self->uvs[2] = 1; + self->uvs[3] = 1; + self->uvs[4] = 1; + self->uvs[5] = 0; + self->uvs[6] = 0; + self->uvs[7] = 0; + return; + } regionScaleX = self->width / self->region->originalWidth * self->scaleX; regionScaleY = self->height / self->region->originalHeight * self->scaleY; diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index 5b4d14e1a..2a9ba7377 100644 --- a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp @@ -68,17 +68,17 @@ RegionAttachment::~RegionAttachment() { } void RegionAttachment::updateRegion() { - if (_region == NULL) { - _uvs[BLX] = 0; - _uvs[BLY] = 0; - _uvs[ULX] = 0; - _uvs[ULY] = 1; - _uvs[URX] = 1; - _uvs[URY] = 1; - _uvs[BRX] = 1; - _uvs[BRY] = 0; - return; - } + if (_region == NULL) { + _uvs[BLX] = 0; + _uvs[BLY] = 0; + _uvs[ULX] = 0; + _uvs[ULY] = 1; + _uvs[URX] = 1; + _uvs[URY] = 1; + _uvs[BRX] = 1; + _uvs[BRY] = 0; + return; + } float regionScaleX = _width / _region->originalWidth * _scaleX; float regionScaleY = _height / _region->originalHeight * _scaleY; diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp index ed1ebba72..9cbc69923 100644 --- a/spine-godot/spine_godot/SpineSprite.cpp +++ b/spine-godot/spine_godot/SpineSprite.cpp @@ -555,7 +555,7 @@ void SpineSprite::update_meshes(Ref skeleton_ref) { vertices->setSize(8, 0); region->computeWorldVertices(*slot, *vertices, 0); - renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region->getRendererObject())->page->getRendererObject(); + renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region->getRendererObject())->page->getRendererObject(); uvs = ®ion->getUVs(); indices = &quad_indices; @@ -569,7 +569,7 @@ void SpineSprite::update_meshes(Ref skeleton_ref) { vertices->setSize(mesh->getWorldVerticesLength(), 0); mesh->computeWorldVertices(*slot, *vertices); - renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); + renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); uvs = &mesh->getUVs(); indices = &mesh->getTriangles(); diff --git a/spine-sfml/c/src/spine/spine-sfml.cpp b/spine-sfml/c/src/spine/spine-sfml.cpp index 372cf5080..56d79fe14 100644 --- a/spine-sfml/c/src/spine/spine-sfml.cpp +++ b/spine-sfml/c/src/spine/spine-sfml.cpp @@ -216,7 +216,7 @@ namespace spine { uvs = mesh->uvs; indices = mesh->triangles; indicesCount = mesh->trianglesCount; - texture = (Texture *) ((spAtlasRegion *) mesh->rendererObject)->page->rendererObject; + texture = (Texture *) ((spAtlasRegion *) mesh->rendererObject)->page->rendererObject; } else if (attachment->type == SP_ATTACHMENT_CLIPPING) { spClippingAttachment *clip = (spClippingAttachment *) slot->attachment; diff --git a/spine-sfml/cpp/src/spine/spine-sfml.cpp b/spine-sfml/cpp/src/spine/spine-sfml.cpp index a10ab7fee..c5c1c3fd1 100644 --- a/spine-sfml/cpp/src/spine/spine-sfml.cpp +++ b/spine-sfml/cpp/src/spine/spine-sfml.cpp @@ -136,11 +136,11 @@ namespace spine { } worldVertices.setSize(mesh->getWorldVerticesLength(), 0); - mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2); + mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2); uvs = &mesh->getUVs(); indices = &mesh->getTriangles(); indicesCount = mesh->getTriangles().size(); - texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); + texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); } else if (attachment->getRTTI().isExactly(ClippingAttachment::rtti)) { ClippingAttachment *clip = (ClippingAttachment *) slot.getAttachment(); diff --git a/spine-ts/spine-canvas/src/SkeletonRenderer.ts b/spine-ts/spine-canvas/src/SkeletonRenderer.ts index 4b4a7fd31..55b73bbbd 100644 --- a/spine-ts/spine-canvas/src/SkeletonRenderer.ts +++ b/spine-ts/spine-canvas/src/SkeletonRenderer.ts @@ -66,7 +66,7 @@ export class SkeletonRenderer { if (!bone.active) continue; let attachment = slot.getAttachment(); - if (!(attachment instanceof RegionAttachment)) continue; + if (!(attachment instanceof RegionAttachment)) continue; attachment.computeWorldVertices(slot, worldVertices, 0, 2); let region: TextureAtlasRegion = attachment.region; let image: HTMLImageElement = (region.page.texture).getImage() as HTMLImageElement; diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp index 2b0fb3381..90b9d29e2 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp @@ -273,7 +273,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList &OutDrawEle if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { RegionAttachment *regionAttachment = (RegionAttachment *) attachment; - attachmentColor.set(regionAttachment->getColor()); + attachmentColor.set(regionAttachment->getColor()); regionAttachment->computeWorldVertices(*slot, *attachmentVertices, 0, 2); attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); attachmentIndices = quadIndices; @@ -282,7 +282,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList &OutDrawEle numIndices = 6; } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { MeshAttachment *mesh = (MeshAttachment *) attachment; - attachmentColor.set(mesh->getColor()); + attachmentColor.set(mesh->getColor()); mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), attachmentVertices->buffer(), 0, 2); attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject(); attachmentIndices = mesh->getTriangles().buffer(); diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp index fbf2ad5cc..022079d14 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp @@ -235,7 +235,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) { continue; } - attachmentColor.set(regionAttachment->getColor()); + attachmentColor.set(regionAttachment->getColor()); regionAttachment->computeWorldVertices(*slot, *attachmentVertices, 0, 2); attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); attachmentIndices = quadIndices; @@ -251,7 +251,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) { continue; } - attachmentColor.set(mesh->getColor()); + attachmentColor.set(mesh->getColor()); mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), attachmentVertices->buffer(), 0, 2); attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject(); attachmentIndices = mesh->getTriangles().buffer();