Selaa lähdekoodia

[libgdx] Fixed SkeletonClipping, ensure input clipping area is clockwise

badlogic 8 vuotta sitten
vanhempi
commit
18f0e6fe7f

+ 18 - 17
spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/ConvexDecomposerTest.java

@@ -190,23 +190,23 @@ public class ConvexDecomposerTest extends ApplicationAdapter {
 		}
 
 		// polygon while drawing
-		switch (polygon.size) {
-		case 0:
-			break;
-		case 2:
-			shapes.end();
-			shapes.begin(ShapeType.Point);
-			GL11.glPointSize(4);
-			shapes.point(polygon.get(0), polygon.get(1), 0);
-			shapes.end();
-			shapes.begin(ShapeType.Line);
-			break;
-		case 4:
-			shapes.line(polygon.get(0), polygon.get(1), polygon.get(2), polygon.get(3));
-			break;
-		default:
-			shapes.polygon(polygon.items, 0, polygon.size);
-		}
+//		switch (polygon.size) {
+//		case 0:
+//			break;
+//		case 2:
+//			shapes.end();
+//			shapes.begin(ShapeType.Point);
+//			GL11.glPointSize(4);
+//			shapes.point(polygon.get(0), polygon.get(1), 0);
+//			shapes.end();
+//			shapes.begin(ShapeType.Line);
+//			break;
+//		case 4:
+//			shapes.line(polygon.get(0), polygon.get(1), polygon.get(2), polygon.get(3));
+//			break;
+//		default:
+//			shapes.polygon(polygon.items, 0, polygon.size);
+//		}
 
 		// edge normals
 // shapes.setColor(Color.YELLOW);
@@ -242,6 +242,7 @@ public class ConvexDecomposerTest extends ApplicationAdapter {
 				}
 				shapes.setColor(colors.get(i));
 				shapes.polygon(convexPolygons.get(i).items, 0, convexPolygons.get(i).size);
+				if (i == 29) break;
 			}
 		}
 

+ 16 - 0
spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SoftwareClippingTest.java

@@ -52,6 +52,21 @@ public class SoftwareClippingTest extends ApplicationAdapter {
 		clipper = new Clipper();
 		decomposer = new ConvexDecomposer();
 		image = new Texture("skin/skin.png");
+		
+		float[] v = new float[] {430.90802f, 278.212f, 72.164f, 361.816f, 31.143997f, 128.804f, 191.896f, 61.0f, 291.312f,
+			175.73201f, 143.956f, 207.408f, 161.4f, 145.628f, 227.456f, 160.61601f, 224.392f, 126.535995f, 188.264f, 113.144f,
+			147.13199f, 108.87601f, 77.035995f, 158.212f, 86.15199f, 220.676f, 102.77199f, 240.716f, 174.74399f, 243.20801f,
+			250.572f, 216.74802f, 324.772f, 200.33202f, 309.388f, 124.968f, 258.168f, 60.503998f, 199.696f, 42.872f, 116.951996f,
+			6.7400017f, 11.332001f, 72.48f, -6.708008f, 143.136f, 1.0679932f, 239.92801f, 26.5f, 355.6f, -47.380005f, 377.52798f,
+			-40.608f, 303.1f, -53.584015f, 77.316f, 5.4600067f, 8.728001f, 113.343994f, -56.04f, 192.42801f, -45.112f, 274.564f,
+			-38.784f, 322.592f, -10.604f, 371.98f, 21.920002f, 405.16f, 60.896004f, 428.68f, 104.852005f, 406.996f, 188.976f,
+			364.58398f, 220.14401f, 309.3f, 238.788f, 263.232f, 244.75201f, 219.468f, 271.58002f, 210.824f, 294.176f, 250.664f,
+			295.2f, 295.972f, 276.02f, 357.46f, 269.172f, 420.008f, 242.37201f, 466.63602f, 207.648f, 437.516f, -10.579998f,
+			378.05603f, -64.624f, 465.24f, -104.992f, 554.11206f, 95.43199f, 514.89197f, 259.02f};
+		for (int i = 0, n = v.length; i < n; i++)
+			v[i] = v[i] * 0.5f + 70;
+		clippingPolygon.addAll(v);
+		clip();
 	}
 
 	@Override
@@ -189,6 +204,7 @@ public class SoftwareClippingTest extends ApplicationAdapter {
 		float x3 = triangle[10];
 		float y3 = triangle[11];
 
+		Clipper.makeClockwise(clippingPolygon);
 		Array<FloatArray> clippingPolygons = decomposer.decompose(clippingPolygon);
 		clippedPolygonVertices.clear();
 		clippedPolygonIndices.clear();

+ 1 - 0
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SkeletonClipping.java

@@ -54,6 +54,7 @@ public class SkeletonClipping {
 		int n = clip.getWorldVerticesLength();
 		float[] vertices = clippingPolygon.setSize(n);
 		clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
+		Clipper.makeClockwise(clippingPolygon);
 		convexClippingPolygons = decomposer.decompose(clippingPolygon);
 		for (FloatArray polygon : convexClippingPolygons) {
 			Clipper.makeClockwise(polygon);