Przeglądaj źródła

[csharp] Refactored SkeletonClipping, spits out vertices and uvs separately so it can be easily reused in XNA and Unity

badlogic 8 lat temu
rodzic
commit
cd788ebbba

+ 1 - 0
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/
 

+ 23 - 52
spine-csharp/src/SkeletonClipping.cs

@@ -37,6 +37,7 @@ namespace Spine {
 		private readonly ExposedList<float> clipOutput = new ExposedList<float>(128);
 		private readonly ExposedList<float> clippedVertices = new ExposedList<float>(128);
 		private readonly ExposedList<short> clippedTriangles = new ExposedList<short>(128);
+		private readonly ExposedList<float> clippedUVs = new ExposedList<float>(128);
 		private readonly ExposedList<float> scratch = new ExposedList<float>();
 
 		private ClippingAttachment clipAttachment;
@@ -44,6 +45,7 @@ namespace Spine {
 
 		public ExposedList<float> ClippedVertices { get { return clippedVertices; } }
 		public ExposedList<short> ClippedTriangles { get { return clippedTriangles; } }
+		public ExposedList<float> 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<float> 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 + 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;
-						}
+						clippedVerticesItems[s + 2] = x2;
+						clippedVerticesItems[s + 3] = y2;
+						clippedVerticesItems[s + 4] = x3;
+						clippedVerticesItems[s + 5] = y3;
+
+						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;

BIN
spine-xna/example/data/coin.skel


+ 46 - 7
spine-xna/example/spine-xna-example.csproj

@@ -116,13 +116,35 @@
     <Compile Include="src\ExampleProgram.cs" />
   </ItemGroup>
   <ItemGroup>
-    <Content Include="data\goblins-ffd.png" />
-    <Content Include="data\raptor.png" />
-    <Content Include="data\spineboy.png">
+    <None Include="data\coin.png">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\coin.skel">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\goblins.png">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\raptor.png">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\spineboy.png">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <Content Include="data\tank.png">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
     <Content Include="Game.ico" />
     <Content Include="GameThumbnail.png" />
+    <None Include="data\tank.atlas">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\tank.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\tank.skel">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\spine-csharp\spine-csharp.csproj">
@@ -162,10 +184,27 @@
     </BootstrapperPackage>
   </ItemGroup>
   <ItemGroup>
-    <None Include="data\goblins-ffd.atlas" />
-    <None Include="data\goblins-ffd.json" />
-    <None Include="data\raptor.atlas" />
-    <None Include="data\raptor.json" />
+    <None Include="data\coin.atlas">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\coin.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\goblins-mesh.atlas">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\goblins-mesh.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\goblins-mesh.skel">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\raptor.atlas">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="data\raptor.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
     <None Include="data\spineboy.atlas">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>

+ 6 - 5
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);