|
@@ -78,6 +78,73 @@ namespace Spine {
|
|
|
clippingPolygon.Clear();
|
|
|
}
|
|
|
|
|
|
+ public void ClipTriangles (float[] vertices, int verticesLength, int[] triangles, int trianglesLength) {
|
|
|
+ ExposedList<float> clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
|
|
|
+ ExposedList<int> clippedTriangles = this.clippedTriangles;
|
|
|
+ ExposedList<float>[] polygons = clippingPolygons.Items;
|
|
|
+ int polygonsCount = clippingPolygons.Count;
|
|
|
+
|
|
|
+ int index = 0;
|
|
|
+ clippedVertices.Clear();
|
|
|
+ clippedTriangles.Clear();
|
|
|
+ //outer:
|
|
|
+ for (int i = 0; i < trianglesLength; i += 3) {
|
|
|
+ int vertexOffset = triangles[i] << 1;
|
|
|
+ float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
|
|
|
+
|
|
|
+ vertexOffset = triangles[i + 1] << 1;
|
|
|
+ float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
|
|
|
+
|
|
|
+ vertexOffset = triangles[i + 2] << 1;
|
|
|
+ float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
|
|
|
+
|
|
|
+ for (int p = 0; p < polygonsCount; p++) {
|
|
|
+ int s = clippedVertices.Count;
|
|
|
+ if (Clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
|
|
|
+ int clipOutputLength = clipOutput.Count;
|
|
|
+ if (clipOutputLength == 0) continue;
|
|
|
+
|
|
|
+ int clipOutputCount = clipOutputLength >> 1;
|
|
|
+ float[] clipOutputItems = clipOutput.Items;
|
|
|
+ float[] clippedVerticesItems = clippedVertices.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;
|
|
|
+ s += 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ s = clippedTriangles.Count;
|
|
|
+ int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3 * (clipOutputCount - 2)).Items;
|
|
|
+ clipOutputCount--;
|
|
|
+ for (int ii = 1; ii < clipOutputCount; ii++) {
|
|
|
+ clippedTrianglesItems[s] = index;
|
|
|
+ clippedTrianglesItems[s + 1] = index + ii;
|
|
|
+ clippedTrianglesItems[s + 2] = index + ii + 1;
|
|
|
+ s += 3;
|
|
|
+ }
|
|
|
+ index += clipOutputCount + 1;
|
|
|
+ } else {
|
|
|
+ float[] clippedVerticesItems = clippedVertices.Resize(s + 3 * 2).Items;
|
|
|
+ clippedVerticesItems[s] = x1;
|
|
|
+ clippedVerticesItems[s + 1] = y1;
|
|
|
+ clippedVerticesItems[s + 2] = x2;
|
|
|
+ clippedVerticesItems[s + 3] = y2;
|
|
|
+ clippedVerticesItems[s + 4] = x3;
|
|
|
+ clippedVerticesItems[s + 5] = y3;
|
|
|
+
|
|
|
+ s = clippedTriangles.Count;
|
|
|
+ int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3).Items;
|
|
|
+ clippedTrianglesItems[s] = index;
|
|
|
+ clippedTrianglesItems[s + 1] = index + 1;
|
|
|
+ clippedTrianglesItems[s + 2] = index + 2;
|
|
|
+ index += 3;
|
|
|
+ break; //continue outer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void ClipTriangles (float[] vertices, int verticesLength, int[] triangles, int trianglesLength, float[] uvs) {
|
|
|
ExposedList<float> clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
|
|
|
ExposedList<int> clippedTriangles = this.clippedTriangles;
|
|
@@ -164,11 +231,10 @@ namespace Spine {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- /** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping
|
|
|
- * area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list. */
|
|
|
+ ///<summary>Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping
|
|
|
+ /// area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list.</summary>
|
|
|
internal bool Clip (float x1, float y1, float x2, float y2, float x3, float y3, ExposedList<float> clippingArea, ExposedList<float> output) {
|
|
|
ExposedList<float> originalOutput = output;
|
|
|
bool clipped = false;
|