diff --git a/spine-cpp/spine-cpp/include/spine/Atlas.h b/spine-cpp/spine-cpp/include/spine/Atlas.h index 6b49518c3..807b682fb 100644 --- a/spine-cpp/spine-cpp/include/spine/Atlas.h +++ b/spine-cpp/spine-cpp/include/spine/Atlas.h @@ -93,6 +93,7 @@ public: int originalWidth, originalHeight; int index; bool rotate; + int degrees; Vector splits; Vector pads; }; diff --git a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h index 8f42c5518..f44dca5fa 100644 --- a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h @@ -136,6 +136,7 @@ namespace spine { int _hullLength; bool _inheritDeform; bool _regionRotate; + int _regionDegrees; }; } diff --git a/spine-cpp/spine-cpp/src/spine/Atlas.cpp b/spine-cpp/spine-cpp/src/spine/Atlas.cpp index ea3b6f348..37e2cde73 100644 --- a/spine-cpp/spine-cpp/src/spine/Atlas.cpp +++ b/spine-cpp/spine-cpp/src/spine/Atlas.cpp @@ -176,7 +176,14 @@ void Atlas::load(const char *begin, int length, const char *dir) { region->name = String(mallocString(&str), true); readValue(&begin, end, &str); - region->rotate = equals(&str, "true") ? true : false; + if (equals(&str, "true")) { + region->degrees = 90; + } else if (equals(&str, "false")) { + region->degrees = 0; + } else { + region->degrees = toInt(&str); + } + region->rotate = region->degrees == 90; readTuple(&begin, end, tuple); region->x = toInt(tuple); diff --git a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp index ad6c3c519..f052a65cb 100644 --- a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp @@ -88,6 +88,7 @@ MeshAttachment *AtlasAttachmentLoader::newMeshAttachment(Skin &skin, const Strin attachment._regionU2 = region.u2; attachment._regionV2 = region.v2; attachment._regionRotate = region.rotate; + attachment._regionDegrees = region.degrees; attachment._regionOffsetX = region.offsetX; attachment._regionOffsetY = region.offsetY; attachment._regionWidth = (float)region.width; diff --git a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp index 905821094..cc283a822 100644 --- a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp @@ -57,7 +57,8 @@ MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), Has _color(1, 1, 1, 1), _hullLength(0), _inheritDeform(false), - _regionRotate(false) { + _regionRotate(false), + _regionDegrees(0) { } MeshAttachment::~MeshAttachment() {} @@ -67,27 +68,61 @@ void MeshAttachment::updateUVs() { _uvs.setSize(_regionUVs.size(), 0); } - if (_regionRotate) { - float textureHeight = _regionWidth / (_regionV2 - _regionV); - float textureWidth = _regionHeight / (_regionU2 - _regionU); - float u = _regionU - (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureWidth; - float v = _regionV - (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureHeight; - float width = _regionOriginalHeight / textureWidth; - float height = _regionOriginalWidth / textureHeight; - for (size_t i = 0, n = _uvs.size(); i < n; i += 2) { - _uvs[i] = u + _regionUVs[i + 1] * width; - _uvs[i + 1] = v + height - _regionUVs[i] * height; + int i = 0, n = _regionUVs.size(); + float u = _regionU, v = _regionV; + float width = 0, height = 0; + + switch (_regionDegrees) { + case 90: { + float textureWidth = _regionHeight / (_regionU2 - _regionU); + float textureHeight = _regionWidth / (_regionV2 - _regionV); + u -= (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureWidth; + v -= (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureHeight; + width = _regionOriginalHeight / textureWidth; + height = _regionOriginalWidth / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + _regionUVs[i + 1] * width; + _uvs[i + 1] = v + (1 - _regionUVs[i]) * height; + } + return; } - } else { - float textureWidth = _regionWidth / (_regionU2 - _regionU); - float textureHeight = _regionHeight / (_regionV2 - _regionV); - float u = _regionU - _regionOffsetX / textureWidth; - float v = _regionV - (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureHeight; - float width = _regionOriginalWidth / textureWidth; - float height = _regionOriginalHeight / textureHeight; - for (size_t i = 0, n = _uvs.size(); i < n; i += 2) { - _uvs[i] = u + _regionUVs[i] * width; - _uvs[i + 1] = v + _regionUVs[i + 1] * height; + case 180: { + float textureWidth = _regionWidth / (_regionU2 - _regionU); + float textureHeight = _regionHeight / (_regionV2 - _regionV); + u -= (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureWidth; + v -= _regionOffsetY / textureHeight; + width = _regionOriginalWidth / textureWidth; + height = _regionOriginalHeight / textureHeight; + for (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: { + float textureHeight = _regionHeight / (_regionV2 - _regionV); + float textureWidth = _regionWidth / (_regionU2 - _regionU); + u -= _regionOffsetY / textureWidth; + v -= _regionOffsetX / textureHeight; + width = _regionOriginalHeight / textureWidth; + height = _regionOriginalWidth / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + (1 - _regionUVs[i + 1]) * width; + _uvs[i + 1] = v + _regionUVs[i] * height; + } + return; + } + default: { + float textureWidth = _regionWidth / (_regionU2 - _regionU); + float textureHeight = _regionHeight / (_regionV2 - _regionV); + u -= _regionOffsetX / textureWidth; + v -= (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureHeight; + width = _regionOriginalWidth / textureWidth; + height = _regionOriginalHeight / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + _regionUVs[i] * width; + _uvs[i + 1] = v + _regionUVs[i + 1] * height; + } } } }