소스 검색

[libgdx] Handle whitespace stripping for mesh texture regions.

NathanSweet 6 년 전
부모
커밋
63238bfc69
1개의 변경된 파일24개의 추가작업 그리고 14개의 파일을 삭제
  1. 24 14
      spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/MeshAttachment.java

+ 24 - 14
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;
 		}
 	}