From 6cf7dcf4136e072b3512080166d3f46fb69d8b06 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Tue, 22 Apr 2014 03:11:32 +0200 Subject: [PATCH] Support for rotated atlas regions. --- .../spine/attachments/MeshAttachment.java | 14 +++++++++++--- .../spine/attachments/SkinnedMeshAttachment.java | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java index dd3dd2f51..94298d30e 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java @@ -33,6 +33,7 @@ import com.esotericsoftware.spine.Skeleton; import com.esotericsoftware.spine.Slot; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.NumberUtils; @@ -167,9 +168,16 @@ public class MeshAttachment extends Attachment { w = region.getU2() - u; h = region.getV2() - v; } - for (int i = 0, ii = 3, n = vertices.length; i < n; i += 2, ii += 5) { - worldVertices[ii] = u + uvs[i] * w; - worldVertices[ii + 1] = v + uvs[i + 1] * h; + if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) { + for (int i = 0, ii = 3, n = vertices.length; i < n; i += 2, ii += 5) { + worldVertices[ii] = u + uvs[i + 1] * w; + worldVertices[ii + 1] = v + h - uvs[i] * h; + } + } else { + for (int i = 0, ii = 3, n = vertices.length; i < n; i += 2, ii += 5) { + worldVertices[ii] = u + uvs[i] * w; + worldVertices[ii + 1] = v + uvs[i + 1] * h; + } } } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/SkinnedMeshAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/SkinnedMeshAttachment.java index b4005c74d..e31de74e8 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/SkinnedMeshAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/SkinnedMeshAttachment.java @@ -33,6 +33,7 @@ import com.esotericsoftware.spine.Skeleton; import com.esotericsoftware.spine.Slot; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.utils.FloatArray; import com.badlogic.gdx.utils.NumberUtils; @@ -203,9 +204,16 @@ public class SkinnedMeshAttachment extends Attachment { w = region.getU2() - u; h = region.getV2() - v; } - for (int i = 0, ii = 3; i < uvsLength; i += 2, ii += 5) { - worldVertices[ii] = u + uvs[i] * w; - worldVertices[ii + 1] = v + uvs[i + 1] * h; + if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) { + for (int i = 0, ii = 3; i < uvsLength; i += 2, ii += 5) { + worldVertices[ii] = u + uvs[i + 1] * w; + worldVertices[ii + 1] = v + h - uvs[i] * h; + } + } else { + for (int i = 0, ii = 3; i < uvsLength; i += 2, ii += 5) { + worldVertices[ii] = u + uvs[i] * w; + worldVertices[ii + 1] = v + uvs[i + 1] * h; + } } } }