mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[csharp] Separated triangulation and convex decomposition
This commit is contained in:
parent
5b2a8cfd1e
commit
c542fb3d91
@ -235,7 +235,7 @@ cp -f ../spineboy/export/spineboy.png ../../spine-ts/widget/example/assets/
|
|||||||
echo "spine-xna"
|
echo "spine-xna"
|
||||||
rm -f ../../spine-xna/example/data/*
|
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.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.atlas ../../spine-xna/example/data/
|
||||||
cp -f ../coin/export/coin.png ../../spine-xna/example/data/
|
cp -f ../coin/export/coin.png ../../spine-xna/example/data/
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@
|
|||||||
<Compile Include="src\BlendMode.cs" />
|
<Compile Include="src\BlendMode.cs" />
|
||||||
<Compile Include="src\Bone.cs" />
|
<Compile Include="src\Bone.cs" />
|
||||||
<Compile Include="src\BoneData.cs" />
|
<Compile Include="src\BoneData.cs" />
|
||||||
<Compile Include="src\ConvexDecomposer.cs" />
|
<Compile Include="src\Triangulator.cs" />
|
||||||
<Compile Include="src\Event.cs" />
|
<Compile Include="src\Event.cs" />
|
||||||
<Compile Include="src\EventData.cs" />
|
<Compile Include="src\EventData.cs" />
|
||||||
<Compile Include="src\ExposedList.cs" />
|
<Compile Include="src\ExposedList.cs" />
|
||||||
|
|||||||
@ -32,7 +32,7 @@ using System;
|
|||||||
|
|
||||||
namespace Spine {
|
namespace Spine {
|
||||||
public class SkeletonClipping {
|
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> clippingPolygon = new ExposedList<float>();
|
||||||
private readonly ExposedList<float> clipOutput = new ExposedList<float>(128);
|
private readonly ExposedList<float> clipOutput = new ExposedList<float>(128);
|
||||||
private readonly ExposedList<float> clippedVertices = 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<int> ClippedTriangles { get { return clippedTriangles; } }
|
||||||
public ExposedList<float> ClippedUVs { get { return clippedUVs; } }
|
public ExposedList<float> ClippedUVs { get { return clippedUVs; } }
|
||||||
|
|
||||||
public void ClipStart(Slot slot, ClippingAttachment clip) {
|
public int ClipStart(Slot slot, ClippingAttachment clip) {
|
||||||
if (clipAttachment != null) return;
|
if (clipAttachment != null) return 0;
|
||||||
clipAttachment = clip;
|
clipAttachment = clip;
|
||||||
|
|
||||||
int n = clip.worldVerticesLength;
|
int n = clip.worldVerticesLength;
|
||||||
float[] vertices = clippingPolygon.Resize(n).Items;
|
float[] vertices = clippingPolygon.Resize(n).Items;
|
||||||
clip.ComputeWorldVertices(slot, 0, n, vertices, 0, 2);
|
clip.ComputeWorldVertices(slot, 0, n, vertices, 0, 2);
|
||||||
MakeClockwise(clippingPolygon);
|
MakeClockwise(clippingPolygon);
|
||||||
clippingPolygons = decomposer.Decompose(clippingPolygon);
|
clippingPolygons = triangulator.Decompose(clippingPolygon, triangulator.Triangulate(clippingPolygon));
|
||||||
foreach (var polygon in clippingPolygons) {
|
foreach (var polygon in clippingPolygons) {
|
||||||
MakeClockwise(polygon);
|
MakeClockwise(polygon);
|
||||||
polygon.Add(polygon.Items[0]);
|
polygon.Add(polygon.Items[0]);
|
||||||
polygon.Add(polygon.Items[1]);
|
polygon.Add(polygon.Items[1]);
|
||||||
}
|
}
|
||||||
|
return clippingPolygons.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClipEnd(Slot slot) {
|
public void ClipEnd(Slot slot) {
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Spine {
|
namespace Spine {
|
||||||
internal class ConvexDecomposer {
|
internal class Triangulator {
|
||||||
private readonly ExposedList<ExposedList<float>> convexPolygons = new ExposedList<ExposedList<float>>();
|
private readonly ExposedList<ExposedList<float>> convexPolygons = new ExposedList<ExposedList<float>>();
|
||||||
private readonly ExposedList<ExposedList<int>> convexPolygonsIndices = new ExposedList<ExposedList<int>>();
|
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<float>> polygonPool = new Pool<ExposedList<float>>();
|
||||||
private readonly Pool<ExposedList<int>> polygonIndicesPool = new Pool<ExposedList<int>>();
|
private readonly Pool<ExposedList<int>> polygonIndicesPool = new Pool<ExposedList<int>>();
|
||||||
|
|
||||||
public ExposedList<ExposedList<float>> Decompose(ExposedList<float> input) {
|
public ExposedList<int> Triangulate(ExposedList<float> verticesArray) {
|
||||||
var vertices = input.Items;
|
var vertices = verticesArray.Items;
|
||||||
int vertexCount = input.Count >> 1;
|
int vertexCount = verticesArray.Count >> 1;
|
||||||
|
|
||||||
var indicesArray = this.indicesArray;
|
var indicesArray = this.indicesArray;
|
||||||
indicesArray.Clear();
|
indicesArray.Clear();
|
||||||
@ -117,6 +117,11 @@ namespace Spine {
|
|||||||
triangles.Add(indices[1]);
|
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;
|
var convexPolygons = this.convexPolygons;
|
||||||
for (int i = 0, n = convexPolygons.Count; i < n; i++) {
|
for (int i = 0, n = convexPolygons.Count; i < n; i++) {
|
||||||
polygonPool.Free(convexPolygons.Items[i]);
|
polygonPool.Free(convexPolygons.Items[i]);
|
||||||
@ -72,8 +72,8 @@ namespace Spine {
|
|||||||
// String name = "spineboy";
|
// String name = "spineboy";
|
||||||
// String name = "goblins-mesh";
|
// String name = "goblins-mesh";
|
||||||
// String name = "raptor";
|
// String name = "raptor";
|
||||||
String name = "tank";
|
// String name = "tank";
|
||||||
// String name = "star";
|
String name = "coin";
|
||||||
bool binaryData = true;
|
bool binaryData = true;
|
||||||
|
|
||||||
Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
|
Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
|
||||||
@ -119,8 +119,8 @@ namespace Spine {
|
|||||||
state.SetAnimation(0, "walk", true);
|
state.SetAnimation(0, "walk", true);
|
||||||
state.AddAnimation(1, "gungrab", false, 2);
|
state.AddAnimation(1, "gungrab", false, 2);
|
||||||
}
|
}
|
||||||
else if (name == "star") {
|
else if (name == "coin") {
|
||||||
// no animation in star
|
state.SetAnimation(0, "rotate", true);
|
||||||
}
|
}
|
||||||
else if (name == "tank") {
|
else if (name == "tank") {
|
||||||
state.SetAnimation(0, "drive", true);
|
state.SetAnimation(0, "drive", true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user