From c542fb3d91f3521dd04390d4875d4732d974b37d Mon Sep 17 00:00:00 2001 From: badlogic Date: Fri, 21 Apr 2017 10:46:02 +0200 Subject: [PATCH] [csharp] Separated triangulation and convex decomposition --- examples/export/runtimes.sh | 2 +- spine-csharp/spine-csharp.csproj | 2 +- spine-csharp/src/SkeletonClipping.cs | 9 +++++---- .../src/{ConvexDecomposer.cs => Triangulator.cs} | 13 +++++++++---- spine-monogame/example/ExampleGame.cs | 8 ++++---- 5 files changed, 20 insertions(+), 14 deletions(-) rename spine-csharp/src/{ConvexDecomposer.cs => Triangulator.cs} (97%) diff --git a/examples/export/runtimes.sh b/examples/export/runtimes.sh index 7289e62e2..4ef745f00 100755 --- a/examples/export/runtimes.sh +++ b/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/ diff --git a/spine-csharp/spine-csharp.csproj b/spine-csharp/spine-csharp.csproj index 1767eb8cc..50792c8fa 100644 --- a/spine-csharp/spine-csharp.csproj +++ b/spine-csharp/spine-csharp.csproj @@ -71,7 +71,7 @@ - + diff --git a/spine-csharp/src/SkeletonClipping.cs b/spine-csharp/src/SkeletonClipping.cs index 3b1a4a9e9..c5dfb3865 100644 --- a/spine-csharp/src/SkeletonClipping.cs +++ b/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 clippingPolygon = new ExposedList(); private readonly ExposedList clipOutput = new ExposedList(128); private readonly ExposedList clippedVertices = new ExposedList(128); @@ -47,20 +47,21 @@ namespace Spine { public ExposedList ClippedTriangles { get { return clippedTriangles; } } public ExposedList 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) { diff --git a/spine-csharp/src/ConvexDecomposer.cs b/spine-csharp/src/Triangulator.cs similarity index 97% rename from spine-csharp/src/ConvexDecomposer.cs rename to spine-csharp/src/Triangulator.cs index 250d2b26e..99b58e9cc 100644 --- a/spine-csharp/src/ConvexDecomposer.cs +++ b/spine-csharp/src/Triangulator.cs @@ -31,7 +31,7 @@ using System; namespace Spine { - internal class ConvexDecomposer { + internal class Triangulator { private readonly ExposedList> convexPolygons = new ExposedList>(); private readonly ExposedList> convexPolygonsIndices = new ExposedList>(); @@ -42,9 +42,9 @@ namespace Spine { private readonly Pool> polygonPool = new Pool>(); private readonly Pool> polygonIndicesPool = new Pool>(); - public ExposedList> Decompose(ExposedList input) { - var vertices = input.Items; - int vertexCount = input.Count >> 1; + public ExposedList Triangulate(ExposedList 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> Decompose(ExposedList verticesArray, ExposedList triangles) { + var vertices = verticesArray.Items; var convexPolygons = this.convexPolygons; for (int i = 0, n = convexPolygons.Count; i < n; i++) { polygonPool.Free(convexPolygons.Items[i]); diff --git a/spine-monogame/example/ExampleGame.cs b/spine-monogame/example/ExampleGame.cs index a20817cfb..4773279bd 100644 --- a/spine-monogame/example/ExampleGame.cs +++ b/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);