From cd788ebbba38ffe562692169744e4e240d86d9db Mon Sep 17 00:00:00 2001 From: badlogic Date: Wed, 19 Apr 2017 15:38:51 +0200 Subject: [PATCH] [csharp] Refactored SkeletonClipping, spits out vertices and uvs separately so it can be easily reused in XNA and Unity --- examples/export/runtimes.sh | 1 + spine-csharp/src/SkeletonClipping.cs | 73 +++++++-------------- spine-xna/example/data/coin.skel | Bin 0 -> 5921 bytes spine-xna/example/spine-xna-example.csproj | 53 +++++++++++++-- spine-xna/example/src/ExampleGame.cs | 11 ++-- 5 files changed, 75 insertions(+), 63 deletions(-) create mode 100644 spine-xna/example/data/coin.skel diff --git a/examples/export/runtimes.sh b/examples/export/runtimes.sh index b1754d275..7289e62e2 100755 --- a/examples/export/runtimes.sh +++ b/examples/export/runtimes.sh @@ -235,6 +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.atlas ../../spine-xna/example/data/ cp -f ../coin/export/coin.png ../../spine-xna/example/data/ diff --git a/spine-csharp/src/SkeletonClipping.cs b/spine-csharp/src/SkeletonClipping.cs index 805544264..bf4ba6e8c 100644 --- a/spine-csharp/src/SkeletonClipping.cs +++ b/spine-csharp/src/SkeletonClipping.cs @@ -37,6 +37,7 @@ namespace Spine { private readonly ExposedList clipOutput = new ExposedList(128); private readonly ExposedList clippedVertices = new ExposedList(128); private readonly ExposedList clippedTriangles = new ExposedList(128); + private readonly ExposedList clippedUVs = new ExposedList(128); private readonly ExposedList scratch = new ExposedList(); private ClippingAttachment clipAttachment; @@ -44,6 +45,7 @@ namespace Spine { public ExposedList ClippedVertices { get { return clippedVertices; } } public ExposedList ClippedTriangles { get { return clippedTriangles; } } + public ExposedList ClippedUVs { get { return clippedUVs; } } public void ClipStart(Slot slot, ClippingAttachment clip) { if (clipAttachment != null) return; @@ -78,17 +80,16 @@ namespace Spine { return clipAttachment != null; } - public void ClipTriangles(float[] vertices, int verticesLength, short[] triangles, int trianglesLength, float[] uvs, - float light, float dark, bool twoColor) { + public void ClipTriangles(float[] vertices, int verticesLength, short[] triangles, int trianglesLength, float[] uvs) { ExposedList clipOutput = this.clipOutput, clippedVertices = this.clippedVertices; var clippedTriangles = this.clippedTriangles; var polygons = clippingPolygons.Items; - int polygonsCount = clippingPolygons.Count; - int vertexSize = twoColor ? 6 : 5; + int polygonsCount = clippingPolygons.Count; short index = 0; clippedVertices.Clear(); + clippedUVs.Clear(); clippedTriangles.Clear(); outer: for (int i = 0; i < trianglesLength; i += 3) { @@ -114,24 +115,18 @@ namespace Spine { int clipOutputCount = clipOutputLength >> 1; float[] clipOutputItems = clipOutput.Items; - float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * vertexSize).Items; + float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items; + float[] clippedUVsItems = clippedUVs.Resize(s + clipOutputCount * 2).Items; for (int ii = 0; ii < clipOutputLength; ii += 2) { float x = clipOutputItems[ii], y = clipOutputItems[ii + 1]; clippedVerticesItems[s] = x; - clippedVerticesItems[s + 1] = y; - clippedVerticesItems[s + 2] = light; - if (twoColor) { - clippedVerticesItems[s + 3] = dark; - s += 4; - } - else - s += 3; + clippedVerticesItems[s + 1] = y; float c0 = x - x3, c1 = y - y3; float a = (d0 * c0 + d1 * c1) * d; float b = (d4 * c0 + d2 * c1) * d; float c = 1 - a - b; - clippedVerticesItems[s] = u1 * a + u2 * b + u3 * c; - clippedVerticesItems[s + 1] = v1 * a + v2 * b + v3 * c; + clippedUVsItems[s] = u1 * a + u2 * b + u3 * c; + clippedUVsItems[s + 1] = v1 * a + v2 * b + v3 * c; s += 2; } @@ -148,45 +143,21 @@ namespace Spine { } else { - float[] clippedVerticesItems = clippedVertices.Resize(s + 3 * vertexSize).Items; + float[] clippedVerticesItems = clippedVertices.Resize(s + 3 * 2).Items; + float[] clippedUVsItems = clippedUVs.Resize(s + 3 * 2).Items; clippedVerticesItems[s] = x1; clippedVerticesItems[s + 1] = y1; - clippedVerticesItems[s + 2] = light; - if (!twoColor) { - clippedVerticesItems[s + 3] = u1; - clippedVerticesItems[s + 4] = v1; + clippedVerticesItems[s + 2] = x2; + clippedVerticesItems[s + 3] = y2; + clippedVerticesItems[s + 4] = x3; + clippedVerticesItems[s + 5] = y3; - clippedVerticesItems[s + 5] = x2; - clippedVerticesItems[s + 6] = y2; - clippedVerticesItems[s + 7] = light; - clippedVerticesItems[s + 8] = u2; - clippedVerticesItems[s + 9] = v2; - - clippedVerticesItems[s + 10] = x3; - clippedVerticesItems[s + 11] = y3; - clippedVerticesItems[s + 12] = light; - clippedVerticesItems[s + 13] = u3; - clippedVerticesItems[s + 14] = v3; - } - else { - clippedVerticesItems[s + 3] = dark; - clippedVerticesItems[s + 4] = u1; - clippedVerticesItems[s + 5] = v1; - - clippedVerticesItems[s + 6] = x2; - clippedVerticesItems[s + 7] = y2; - clippedVerticesItems[s + 8] = light; - clippedVerticesItems[s + 9] = dark; - clippedVerticesItems[s + 10] = u2; - clippedVerticesItems[s + 11] = v2; - - clippedVerticesItems[s + 12] = x3; - clippedVerticesItems[s + 13] = y3; - clippedVerticesItems[s + 14] = light; - clippedVerticesItems[s + 15] = dark; - clippedVerticesItems[s + 16] = u3; - clippedVerticesItems[s + 17] = v3; - } + clippedUVsItems[s] = u1; + clippedUVsItems[s + 1] = v1; + clippedUVsItems[s + 2] = u2; + clippedUVsItems[s + 3] = v2; + clippedUVsItems[s + 4] = u3; + clippedUVsItems[s + 5] = v3; s = clippedTriangles.Count; short[] clippedTrianglesItems = clippedTriangles.Resize(s + 3).Items; diff --git a/spine-xna/example/data/coin.skel b/spine-xna/example/data/coin.skel new file mode 100644 index 0000000000000000000000000000000000000000..c96827da43df18398b96e25a32b43325f443e892 GIT binary patch literal 5921 zcmdUzX;@T8*2k-xO%WBbMG$Fr6ctcGMMK}BFGMlH1>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?->1V$44at@+JQmd-XC#M|>N&s*`l zaI}9>iy&5^aK%m4tfVtmIJ7=WC|YZgwoHVH9;CY~=JSlwr%bwc@4g}H*vC9wUQgW_ zY(~!&Rhj5c`c*YjwU)+IB5q3Dkn~p;y_1Kfafy>?!~RbxCEdF}jHwAJtHo6K$4lVT zm{RIke5it|ZacC0$x1=F%jjQ-z4NvaUq6sb9JM``IC<1$;?!$Jf8x07$)pd?xK0f0 zokw)+yIIiK!0|B-9?Y*G_RoG-u;te>KO@_lB5cN-krdC2S89F~y4=d)JEDgz{jn_% zNH|M+WK}b9jLk^mWK#)oTDi{5aS}1M{u*)EfKJ4qFOL%KYbOdCE6#sTTr*;V%cl5>5ovZqt>{o3@5GzgQC9WxVAiZXsfml&bTP9x^U|!P0Uw%#Y zb+u-fh&3;rY&&9%up5_Tc+sK3(lymh5T-D_)fFn*`^4PTf19V!<%P@p5x4r7z3Qm* z`=o!r^)B&elQr>vemwC}z003icj@M?s&;HVYPlw+mV{BP@+>c1mI zG*gqk=pQZW#_YF9-@A#Lt0%J;kzSH^o%qx5Q;2mI_QboY6R}}e&;OvGxqNg4@y4)d zVtGBiwptuQ(^S7IrR7k!KXIq>%>A^T>WIR8p)1cD= - - - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + @@ -162,10 +184,27 @@ - - - - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/spine-xna/example/src/ExampleGame.cs b/spine-xna/example/src/ExampleGame.cs index 2b2c40e1b..28f82ea98 100644 --- a/spine-xna/example/src/ExampleGame.cs +++ b/spine-xna/example/src/ExampleGame.cs @@ -76,8 +76,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)); @@ -85,7 +85,8 @@ namespace Spine { float scale = 1; if (name == "spineboy") scale = 0.6f; if (name == "raptor") scale = 0.5f; - if (name == "tank") scale = 0.3f; + if (name == "tank") scale = 0.3f; + if (name == "coin") scale = 1; SkeletonData skeletonData; if (binaryData) { @@ -123,8 +124,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);