[libgdx] Handle whitespace stripping for mesh texture regions.

This commit is contained in:
NathanSweet 2018-12-19 14:39:46 +01:00
parent 9d77b4bf12
commit 63238bfc69

View File

@ -33,6 +33,7 @@ package com.esotericsoftware.spine.attachments;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.esotericsoftware.spine.Animation.DeformTimeline; 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 /** 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 /** Calculates {@link #uvs} using {@link #regionUVs} and the {@link #region}. Must be called after changing the region UVs or
* region. */ * region. */
public void updateUVs () { 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; 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; u = v = 0;
width = height = 1; width = height = 1;
} else { } else {
@ -80,19 +100,9 @@ public class MeshAttachment extends VertexAttachment {
width = region.getU2() - u; width = region.getU2() - u;
height = region.getV2() - v; height = region.getV2() - v;
} }
float[] regionUVs = this.regionUVs; for (int i = 0, n = uvs.length; i < n; i += 2) {
if (this.uvs == null || this.uvs.length != regionUVs.length) this.uvs = new float[regionUVs.length]; uvs[i] = u + regionUVs[i] * width;
float[] uvs = this.uvs; uvs[i + 1] = v + regionUVs[i + 1] * height;
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;
}
} }
} }