From 63238bfc69d449bffa6518f2c357a8204ba90bff Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Wed, 19 Dec 2018 14:39:46 +0100 Subject: [PATCH] [libgdx] Handle whitespace stripping for mesh texture regions. --- .../spine/attachments/MeshAttachment.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java index a1cba92db..a4d87994f 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java @@ -33,6 +33,7 @@ package com.esotericsoftware.spine.attachments; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion; + import com.esotericsoftware.spine.Animation.DeformTimeline; /** An attachment that displays a textured mesh. A mesh has hull vertices and internal vertices within the hull. Holes are not @@ -70,8 +71,27 @@ public class MeshAttachment extends VertexAttachment { /** Calculates {@link #uvs} using {@link #regionUVs} and the {@link #region}. Must be called after changing the region UVs or * region. */ public void updateUVs () { + float[] regionUVs = this.regionUVs; + if (this.uvs == null || this.uvs.length != regionUVs.length) this.uvs = new float[regionUVs.length]; + float[] uvs = this.uvs; float u, v, width, height; - if (region == null) { + if (region instanceof AtlasRegion) { + AtlasRegion region = (AtlasRegion)this.region; + float textureWidth = region.getTexture().getWidth(), textureHeight = region.getTexture().getHeight(); + width = region.originalWidth / textureWidth; + height = region.originalHeight / textureHeight; + if (region.rotate) { + u = region.getU() - (region.originalHeight - region.offsetY - region.packedWidth) / textureWidth; + v = region.getV() - (region.originalWidth - region.offsetX - region.packedHeight) / textureHeight; + for (int i = 0, n = uvs.length; i < n; i += 2) { + uvs[i] = u + regionUVs[i + 1] * height; + uvs[i + 1] = v + width - regionUVs[i] * width; + } + return; + } + u = region.getU() - region.offsetX / textureWidth; + v = region.getV() - (region.originalHeight - region.offsetY - region.packedHeight) / textureHeight; + } else if (region == null) { u = v = 0; width = height = 1; } else { @@ -80,19 +100,9 @@ public class MeshAttachment extends VertexAttachment { width = region.getU2() - u; height = region.getV2() - v; } - float[] regionUVs = this.regionUVs; - if (this.uvs == null || this.uvs.length != regionUVs.length) this.uvs = new float[regionUVs.length]; - float[] uvs = this.uvs; - if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) { - for (int i = 0, n = uvs.length; i < n; i += 2) { - uvs[i] = u + regionUVs[i + 1] * width; - uvs[i + 1] = v + height - regionUVs[i] * height; - } - } else { - for (int i = 0, n = uvs.length; i < n; i += 2) { - uvs[i] = u + regionUVs[i] * width; - uvs[i + 1] = v + regionUVs[i + 1] * height; - } + for (int i = 0, n = uvs.length; i < n; i += 2) { + uvs[i] = u + regionUVs[i] * width; + uvs[i + 1] = v + regionUVs[i + 1] * height; } }