[csharp][libgdx] Fixed indexing in RegionAttachment. [monogame][xna] Fixed SkeletonMeshRenderer clipping

This commit is contained in:
badlogic 2017-04-20 15:02:24 +02:00
parent a1889341c9
commit 0fd553e75a
4 changed files with 42 additions and 40 deletions

View File

@ -115,6 +115,15 @@ namespace Spine {
float[] uvs = this.uvs;
// UV values differ from RegionAttachment.java
if (rotate) {
uvs[URX] = u;
uvs[URY] = v2;
uvs[BRX] = u;
uvs[BRY] = v;
uvs[BLX] = u2;
uvs[BLY] = v;
uvs[ULX] = u2;
uvs[ULY] = v2;
} else {
uvs[ULX] = u;
uvs[ULY] = v2;
uvs[URX] = u;
@ -123,15 +132,6 @@ namespace Spine {
uvs[BRY] = v;
uvs[BLX] = u2;
uvs[BLY] = v2;
} else {
uvs[BLX] = u;
uvs[BLY] = v2;
uvs[ULX] = u;
uvs[ULY] = v;
uvs[URX] = u2;
uvs[URY] = v;
uvs[BRX] = u2;
uvs[BRY] = v2;
}
}
@ -147,26 +147,26 @@ namespace Spine {
float offsetX, offsetY;
// Vertex order is different from RegionAttachment.java
offsetX = vertexOffset[BLX]; // 0
offsetY = vertexOffset[BLY]; // 1
offsetX = vertexOffset[BRX]; // 0
offsetY = vertexOffset[BRY]; // 1
worldVertices[offset] = offsetX * a + offsetY * b + bwx; // bl
worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy;
offset += stride;
offsetX = vertexOffset[ULX]; // 2
offsetY = vertexOffset[ULY]; // 3
offsetX = vertexOffset[BLX]; // 2
offsetY = vertexOffset[BLY]; // 3
worldVertices[offset] = offsetX * a + offsetY * b + bwx; // ul
worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy;
offset += stride;
offsetX = vertexOffset[URX]; // 4
offsetY = vertexOffset[URY]; // 5
offsetX = vertexOffset[ULX]; // 4
offsetY = vertexOffset[ULY]; // 5
worldVertices[offset] = offsetX * a + offsetY * b + bwx; // ur
worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy;
offset += stride;
offsetX = vertexOffset[BRX]; // 6
offsetY = vertexOffset[BRY]; // 7
offsetX = vertexOffset[URX]; // 6
offsetY = vertexOffset[URY]; // 7
worldVertices[offset] = offsetX * a + offsetY * b + bwx; // br
worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy;
//offset += stride;

View File

@ -117,23 +117,23 @@ public class RegionAttachment extends Attachment {
this.region = region;
float[] uvs = this.uvs;
if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) {
uvs[4] = region.getU();
uvs[5] = region.getV2();
uvs[6] = region.getU();
uvs[7] = region.getV();
uvs[0] = region.getU2();
uvs[1] = region.getV();
uvs[2] = region.getU2();
uvs[3] = region.getV2();
uvs[URX] = region.getU();
uvs[URY] = region.getV2();
uvs[BRX] = region.getU();
uvs[BRY] = region.getV();
uvs[BLX] = region.getU2();
uvs[BLY] = region.getV();
uvs[ULX] = region.getU2();
uvs[ULY] = region.getV2();
} else {
uvs[2] = region.getU();
uvs[3] = region.getV2();
uvs[4] = region.getU();
uvs[5] = region.getV();
uvs[6] = region.getU2();
uvs[7] = region.getV();
uvs[0] = region.getU2();
uvs[1] = region.getV2();
uvs[ULX] = region.getU();
uvs[ULY] = region.getV2();
uvs[URX] = region.getU();
uvs[URY] = region.getV();
uvs[BRX] = region.getU2();
uvs[BRY] = region.getV();
uvs[BLX] = region.getU2();
uvs[BLY] = region.getV2();
}
}

View File

@ -71,13 +71,13 @@ namespace Spine {
protected override void LoadContent () {
skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
skeletonRenderer.PremultipliedAlpha = true;
skeletonRenderer.PremultipliedAlpha = false;
// String name = "spineboy";
String name = "spineboy";
// String name = "goblins-mesh";
// String name = "raptor";
// String name = "tank";
String name = "coin";
// String name = "coin";
bool binaryData = false;
Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));

View File

@ -143,8 +143,8 @@ namespace Spine {
// set blend state
BlendState blend = slot.Data.BlendMode == BlendMode.Additive ? BlendState.Additive : defaultBlendState;
if (device.BlendState != blend) {
End();
device.BlendState = blend;
//End();
//device.BlendState = blend;
}
// calculate color
@ -166,7 +166,7 @@ namespace Spine {
if (clipper.IsClipping()) {
clipper.ClipTriangles(vertices, verticesCount << 1, indices, indicesCount, uvs);
vertices = clipper.ClippedVertices.Items;
verticesCount = clipper.ClippedVertices.Count;
verticesCount = clipper.ClippedVertices.Count >> 1;
indices = clipper.ClippedTriangles.Items;
indicesCount = clipper.ClippedTriangles.Count;
uvs = clipper.ClippedUVs.Items;
@ -178,7 +178,9 @@ namespace Spine {
// submit to batch
MeshItem item = batcher.NextItem(verticesCount, indicesCount);
item.texture = texture;
item.triangles = indices;
for (int ii = 0, nn = indicesCount; ii < nn; ii++) {
item.triangles[ii] = indices[ii];
}
VertexPositionColorTexture[] itemVertices = item.vertices;
for (int ii = 0, v = 0, nn = verticesCount << 1; v < nn; ii++, v += 2) {
itemVertices[ii].Color = color;