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

View File

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

View File

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

View File

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