Browse Source

[csharp] Separated triangulation and convex decomposition

badlogic 8 years ago
parent
commit
c542fb3d91

+ 1 - 1
examples/export/runtimes.sh

@@ -235,7 +235,7 @@ cp -f ../spineboy/export/spineboy.png ../../spine-ts/widget/example/assets/
 echo "spine-xna"
 rm -f ../../spine-xna/example/data/*
 cp -f ../coin/export/coin.json ../../spine-xna/example/data/
-cp -f ../coin/export/coin.json ../../spine-xna/example/data/
+cp -f ../coin/export/coin.skel ../../spine-xna/example/data/
 cp -f ../coin/export/coin.atlas ../../spine-xna/example/data/
 cp -f ../coin/export/coin.png ../../spine-xna/example/data/
 

+ 1 - 1
spine-csharp/spine-csharp.csproj

@@ -71,7 +71,7 @@
     <Compile Include="src\BlendMode.cs" />
     <Compile Include="src\Bone.cs" />
     <Compile Include="src\BoneData.cs" />
-    <Compile Include="src\ConvexDecomposer.cs" />
+    <Compile Include="src\Triangulator.cs" />
     <Compile Include="src\Event.cs" />
     <Compile Include="src\EventData.cs" />
     <Compile Include="src\ExposedList.cs" />

+ 5 - 4
spine-csharp/src/SkeletonClipping.cs

@@ -32,7 +32,7 @@ using System;
 
 namespace Spine {
 	public class SkeletonClipping {
-		private readonly ConvexDecomposer decomposer = new ConvexDecomposer();
+		private readonly Triangulator triangulator = new Triangulator();
 		private readonly ExposedList<float> clippingPolygon = new ExposedList<float>();
 		private readonly ExposedList<float> clipOutput = new ExposedList<float>(128);
 		private readonly ExposedList<float> clippedVertices = new ExposedList<float>(128);
@@ -47,20 +47,21 @@ namespace Spine {
 		public ExposedList<int> ClippedTriangles { get { return clippedTriangles; } }
 		public ExposedList<float> ClippedUVs { get { return clippedUVs; } }
 
-		public void ClipStart(Slot slot, ClippingAttachment clip) {
-			if (clipAttachment != null) return;
+		public int ClipStart(Slot slot, ClippingAttachment clip) {
+			if (clipAttachment != null) return 0;
 			clipAttachment = clip;
 
 			int n = clip.worldVerticesLength;
 			float[] vertices = clippingPolygon.Resize(n).Items;
 			clip.ComputeWorldVertices(slot, 0, n, vertices, 0, 2);
 			MakeClockwise(clippingPolygon);
-			clippingPolygons = decomposer.Decompose(clippingPolygon);
+			clippingPolygons = triangulator.Decompose(clippingPolygon, triangulator.Triangulate(clippingPolygon));
 			foreach (var polygon in clippingPolygons) {
 				MakeClockwise(polygon);
 				polygon.Add(polygon.Items[0]);
 				polygon.Add(polygon.Items[1]);
 			}
+			return clippingPolygons.Count;
 		}
 
 		public void ClipEnd(Slot slot) {

+ 9 - 4
spine-csharp/src/ConvexDecomposer.cs → spine-csharp/src/Triangulator.cs

@@ -31,7 +31,7 @@
 using System;
 
 namespace Spine {
-	internal class ConvexDecomposer {
+	internal class Triangulator {
 		private readonly ExposedList<ExposedList<float>> convexPolygons = new ExposedList<ExposedList<float>>();
 		private readonly ExposedList<ExposedList<int>> convexPolygonsIndices = new ExposedList<ExposedList<int>>();
 
@@ -42,9 +42,9 @@ namespace Spine {
 		private readonly Pool<ExposedList<float>> polygonPool = new Pool<ExposedList<float>>();
 		private readonly Pool<ExposedList<int>> polygonIndicesPool = new Pool<ExposedList<int>>();
 
-		public ExposedList<ExposedList<float>> Decompose(ExposedList<float> input) {
-			var vertices = input.Items;
-			int vertexCount = input.Count >> 1;
+		public ExposedList<int> Triangulate(ExposedList<float> verticesArray) {
+			var vertices = verticesArray.Items;
+			int vertexCount = verticesArray.Count >> 1;
 
 			var indicesArray = this.indicesArray;
 			indicesArray.Clear();
@@ -117,6 +117,11 @@ namespace Spine {
 				triangles.Add(indices[1]);
 			}
 
+			return triangles;
+		}
+
+		public ExposedList<ExposedList<float>> Decompose(ExposedList<float> verticesArray, ExposedList<int> triangles) {
+			var vertices = verticesArray.Items;
 			var convexPolygons = this.convexPolygons;
 			for (int i = 0, n = convexPolygons.Count; i < n; i++) {
 				polygonPool.Free(convexPolygons.Items[i]);

+ 4 - 4
spine-monogame/example/ExampleGame.cs

@@ -72,8 +72,8 @@ namespace Spine {
 			// String name = "spineboy";
 			// String name = "goblins-mesh";
 			// String name = "raptor";
-			String name = "tank";
-			// String name = "star";
+			// String name = "tank";
+			String name = "coin";
 			bool binaryData = true;
 
 			Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
@@ -119,8 +119,8 @@ namespace Spine {
 				state.SetAnimation(0, "walk", true);
 				state.AddAnimation(1, "gungrab", false, 2);
 			}
-			else if (name == "star") {
-				// no animation in star
+			else if (name == "coin") {
+				state.SetAnimation(0, "rotate", true);
 			}
 			else if (name == "tank") {
 				state.SetAnimation(0, "drive", true);