diff --git a/spine-c/spine-c/src/spine/AnimationState.c b/spine-c/spine-c/src/spine/AnimationState.c index e6ede4220..2ff7f484c 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..b91ce5bef 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-cocos2dx/README.md b/spine-cocos2dx/README.md index e169faae9..a025533b8 100644 --- a/spine-cocos2dx/README.md +++ b/spine-cocos2dx/README.md @@ -68,13 +68,13 @@ 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**: cocos2d-x only ships pre-built external libraries like Bullet or FreeType for x86_64. If you build on a machine with Apple Silicon, adjust the `cmake` command above to `mkdir build-macos && cmake . -GXcode -Bbuild-macos -DCMAKE_OSX_ARCHITECTURES=x86_64`. +> **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: diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index da15c053c..a1024d193 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-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; diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp index 68d2c7b96..9cbc69923 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 *) region->getRegion()->rendererObject; 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 *) mesh->getRegion()->rendererObject; vertices->setSize(mesh->getWorldVerticesLength(), 0); mesh->computeWorldVertices(*slot, *vertices); + renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); uvs = &mesh->getUVs(); indices = &mesh->getTriangles(); 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; diff --git a/spine-sdl/README.md b/spine-sdl/README.md index cf91c35f1..f02be0700 100644 --- a/spine-sdl/README.md +++ b/spine-sdl/README.md @@ -26,7 +26,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 c7c7c90a6..9cbba5504 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 *) mesh->getRegion()->rendererObject; 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(); @@ -221,4 +221,4 @@ void SDLTextureLoader::unload(void *texture) { SpineExtension *spine::getDefaultExtension() { return new DefaultSpineExtension(); -} \ No newline at end of file +} diff --git a/spine-sfml/c/src/spine/spine-sfml.cpp b/spine-sfml/c/src/spine/spine-sfml.cpp index 71615b672..56d79fe14 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 50c08fe60..8b98c2a03 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); - texture = (Texture *) mesh->getRegion()->rendererObject; 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(); diff --git a/spine-ts/spine-canvas/src/SkeletonRenderer.ts b/spine-ts/spine-canvas/src/SkeletonRenderer.ts index 67340c5bd..55b73bbbd 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; @@ -65,6 +67,7 @@ export class SkeletonRenderer { let attachment = slot.getAttachment(); 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 598bcfda9..6c46306a2 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] = 0; + 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,16 +130,15 @@ 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.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; diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp index 4a845f1f1..90b9d29e2 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp @@ -274,8 +274,8 @@ 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(); regionAttachment->computeWorldVertices(*slot, *attachmentVertices, 0, 2); + attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); attachmentIndices = quadIndices; attachmentUvs = regionAttachment->getUVs().buffer(); numVertices = 4; @@ -283,8 +283,8 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList &OutDrawEle } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { MeshAttachment *mesh = (MeshAttachment *) attachment; attachmentColor.set(mesh->getColor()); - attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject(); 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..022079d14 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp @@ -236,8 +236,8 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) { } attachmentColor.set(regionAttachment->getColor()); - attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); regionAttachment->computeWorldVertices(*slot, *attachmentVertices, 0, 2); + attachmentAtlasRegion = (AtlasRegion *) regionAttachment->getRendererObject(); attachmentIndices = quadIndices; attachmentUvs = regionAttachment->getUVs().buffer(); numVertices = 4; @@ -252,8 +252,8 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton *Skeleton) { } attachmentColor.set(mesh->getColor()); - attachmentAtlasRegion = (AtlasRegion *) mesh->getRendererObject(); 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;