mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-17 20:41:38 +08:00
[libgdx] Handle whitespace stripping for mesh texture regions.
This commit is contained in:
parent
9d77b4bf12
commit
63238bfc69
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user