mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-01 13:19:08 +08:00
[libgdx] Rotated mesh region UV loading.
This commit is contained in:
parent
175bb90523
commit
d2c006dfd9
@ -74,35 +74,55 @@ public class MeshAttachment extends VertexAttachment {
|
|||||||
float[] regionUVs = this.regionUVs;
|
float[] regionUVs = this.regionUVs;
|
||||||
if (this.uvs == null || this.uvs.length != regionUVs.length) this.uvs = new float[regionUVs.length];
|
if (this.uvs == null || this.uvs.length != regionUVs.length) this.uvs = new float[regionUVs.length];
|
||||||
float[] uvs = this.uvs;
|
float[] uvs = this.uvs;
|
||||||
float u, v, width, height;
|
int n = uvs.length;
|
||||||
|
float u = region.getU(), v = region.getV(), width, height;
|
||||||
if (region instanceof AtlasRegion) {
|
if (region instanceof AtlasRegion) {
|
||||||
AtlasRegion region = (AtlasRegion)this.region;
|
AtlasRegion region = (AtlasRegion)this.region;
|
||||||
float textureWidth = region.getTexture().getWidth(), textureHeight = region.getTexture().getHeight();
|
float textureWidth = region.getTexture().getWidth(), textureHeight = region.getTexture().getHeight();
|
||||||
if (region.rotate) {
|
switch (region.degrees) {
|
||||||
u = region.getU() - (region.originalHeight - region.offsetY - region.packedWidth) / textureWidth;
|
case 90:
|
||||||
v = region.getV() - (region.originalWidth - region.offsetX - region.packedHeight) / textureHeight;
|
u -= (region.originalHeight - region.offsetY - region.packedWidth) / textureWidth;
|
||||||
|
v -= (region.originalWidth - region.offsetX - region.packedHeight) / textureHeight;
|
||||||
width = region.originalHeight / textureWidth;
|
width = region.originalHeight / textureWidth;
|
||||||
height = region.originalWidth / textureHeight;
|
height = region.originalWidth / textureHeight;
|
||||||
for (int i = 0, n = uvs.length; i < n; i += 2) {
|
for (int i = 0; i < n; i += 2) {
|
||||||
uvs[i] = u + regionUVs[i + 1] * width;
|
uvs[i] = u + regionUVs[i + 1] * width;
|
||||||
uvs[i + 1] = v + height - regionUVs[i] * height;
|
uvs[i + 1] = v + (1 - regionUVs[i]) * height;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case 180:
|
||||||
|
u -= (region.originalWidth - region.offsetX - region.packedWidth) / textureWidth;
|
||||||
|
v -= region.offsetY / textureHeight;
|
||||||
|
width = region.originalWidth / textureWidth;
|
||||||
|
height = region.originalHeight / textureHeight;
|
||||||
|
for (int i = 0; i < n; i += 2) {
|
||||||
|
uvs[i] = u + (1 - regionUVs[i]) * width;
|
||||||
|
uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case 270:
|
||||||
|
u -= region.offsetY / textureWidth;
|
||||||
|
v -= region.offsetX / textureHeight;
|
||||||
|
width = region.originalHeight / textureWidth;
|
||||||
|
height = region.originalWidth / textureHeight;
|
||||||
|
for (int i = 0; i < n; i += 2) {
|
||||||
|
uvs[i] = u + (1 - regionUVs[i + 1]) * width;
|
||||||
|
uvs[i + 1] = v + regionUVs[i] * height;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
u = region.getU() - region.offsetX / textureWidth;
|
u -= region.offsetX / textureWidth;
|
||||||
v = region.getV() - (region.originalHeight - region.offsetY - region.packedHeight) / textureHeight;
|
v -= (region.originalHeight - region.offsetY - region.packedHeight) / textureHeight;
|
||||||
width = region.originalWidth / textureWidth;
|
width = region.originalWidth / textureWidth;
|
||||||
height = region.originalHeight / textureHeight;
|
height = region.originalHeight / textureHeight;
|
||||||
} else if (region == null) {
|
} else if (region == null) {
|
||||||
u = v = 0;
|
u = v = 0;
|
||||||
width = height = 1;
|
width = height = 1;
|
||||||
} else {
|
} else {
|
||||||
u = region.getU();
|
|
||||||
v = region.getV();
|
|
||||||
width = region.getU2() - u;
|
width = region.getU2() - u;
|
||||||
height = region.getV2() - v;
|
height = region.getV2() - v;
|
||||||
}
|
}
|
||||||
for (int i = 0, n = uvs.length; i < n; i += 2) {
|
for (int i = 0; i < n; i += 2) {
|
||||||
uvs[i] = u + regionUVs[i] * width;
|
uvs[i] = u + regionUVs[i] * width;
|
||||||
uvs[i + 1] = v + regionUVs[i + 1] * height;
|
uvs[i + 1] = v + regionUVs[i + 1] * height;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user