mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 02:06:03 +08:00
[csharp][unity] Port of commit 68d262b5: Improved rendering performance when an attachment is fully inside a clipping attachment.
Reuse the original vertices rather than clipping's triangle soup.
This commit is contained in:
parent
a46174b88b
commit
f8332b7773
@ -736,8 +736,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vertices != null) {
|
if (vertices != null) {
|
||||||
if (clipper != null && clipper.IsClipping) {
|
if (clipper != null && clipper.IsClipping && clipper.ClipTriangles(vertices, triangles, triangles.Length)) {
|
||||||
clipper.ClipTriangles(vertices, triangles, triangles.Length);
|
|
||||||
vertices = clipper.ClippedVertices.Items;
|
vertices = clipper.ClippedVertices.Items;
|
||||||
verticesLength = clipper.ClippedVertices.Count;
|
verticesLength = clipper.ClippedVertices.Count;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,7 @@ namespace Spine {
|
|||||||
clippingPolygon.Clear();
|
clippingPolygon.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClipTriangles (float[] vertices, int[] triangles, int trianglesLength) {
|
public bool ClipTriangles (float[] vertices, int[] triangles, int trianglesLength) {
|
||||||
ExposedList<float> clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
|
ExposedList<float> clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
|
||||||
ExposedList<int> clippedTriangles = this.clippedTriangles;
|
ExposedList<int> clippedTriangles = this.clippedTriangles;
|
||||||
ExposedList<float>[] polygons = clippingPolygons.Items;
|
ExposedList<float>[] polygons = clippingPolygons.Items;
|
||||||
@ -87,24 +87,25 @@ namespace Spine {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
clippedVertices.Clear();
|
clippedVertices.Clear();
|
||||||
clippedTriangles.Clear();
|
clippedTriangles.Clear();
|
||||||
|
float[] clipOutputItems = null;
|
||||||
for (int i = 0; i < trianglesLength; i += 3) {
|
for (int i = 0; i < trianglesLength; i += 3) {
|
||||||
int vertexOffset = triangles[i] << 1;
|
int v = triangles[i] << 1;
|
||||||
float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
|
float x1 = vertices[v], y1 = vertices[v + 1];
|
||||||
|
|
||||||
vertexOffset = triangles[i + 1] << 1;
|
v = triangles[i + 1] << 1;
|
||||||
float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
|
float x2 = vertices[v], y2 = vertices[v + 1];
|
||||||
|
|
||||||
vertexOffset = triangles[i + 2] << 1;
|
v = triangles[i + 2] << 1;
|
||||||
float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
|
float x3 = vertices[v], y3 = vertices[v + 1];
|
||||||
|
|
||||||
for (int p = 0; p < polygonsCount; p++) {
|
for (int p = 0; p < polygonsCount; p++) {
|
||||||
int s = clippedVertices.Count;
|
int s = clippedVertices.Count;
|
||||||
if (Clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
|
if (Clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
|
||||||
|
clipOutputItems = clipOutput.Items;
|
||||||
int clipOutputLength = clipOutput.Count;
|
int clipOutputLength = clipOutput.Count;
|
||||||
if (clipOutputLength == 0) continue;
|
if (clipOutputLength == 0) continue;
|
||||||
|
|
||||||
int clipOutputCount = clipOutputLength >> 1;
|
int clipOutputCount = clipOutputLength >> 1;
|
||||||
float[] clipOutputItems = clipOutput.Items;
|
|
||||||
float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items;
|
float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items;
|
||||||
for (int ii = 0; ii < clipOutputLength; ii += 2, s += 2) {
|
for (int ii = 0; ii < clipOutputLength; ii += 2, s += 2) {
|
||||||
float x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
|
float x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
|
||||||
@ -140,9 +141,10 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return clipOutputItems != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClipTriangles (float[] vertices, int[] triangles, int trianglesLength, float[] uvs) {
|
public bool ClipTriangles (float[] vertices, int[] triangles, int trianglesLength, float[] uvs) {
|
||||||
ExposedList<float> clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
|
ExposedList<float> clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
|
||||||
ExposedList<int> clippedTriangles = this.clippedTriangles;
|
ExposedList<int> clippedTriangles = this.clippedTriangles;
|
||||||
ExposedList<float>[] polygons = clippingPolygons.Items;
|
ExposedList<float>[] polygons = clippingPolygons.Items;
|
||||||
@ -152,30 +154,30 @@ namespace Spine {
|
|||||||
clippedVertices.Clear();
|
clippedVertices.Clear();
|
||||||
clippedUVs.Clear();
|
clippedUVs.Clear();
|
||||||
clippedTriangles.Clear();
|
clippedTriangles.Clear();
|
||||||
|
float[] clipOutputItems = null;
|
||||||
for (int i = 0; i < trianglesLength; i += 3) {
|
for (int i = 0; i < trianglesLength; i += 3) {
|
||||||
int vertexOffset = triangles[i] << 1;
|
int v = triangles[i] << 1;
|
||||||
float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
|
float x1 = vertices[v], y1 = vertices[v + 1];
|
||||||
float u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
|
float u1 = uvs[v], v1 = uvs[v + 1];
|
||||||
|
|
||||||
vertexOffset = triangles[i + 1] << 1;
|
v = triangles[i + 1] << 1;
|
||||||
float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
|
float x2 = vertices[v], y2 = vertices[v + 1];
|
||||||
float u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1];
|
float u2 = uvs[v], v2 = uvs[v + 1];
|
||||||
|
|
||||||
vertexOffset = triangles[i + 2] << 1;
|
v = triangles[i + 2] << 1;
|
||||||
float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
|
float x3 = vertices[v], y3 = vertices[v + 1];
|
||||||
float u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1];
|
float u3 = uvs[v], v3 = uvs[v + 1];
|
||||||
|
|
||||||
for (int p = 0; p < polygonsCount; p++) {
|
for (int p = 0; p < polygonsCount; p++) {
|
||||||
int s = clippedVertices.Count;
|
int s = clippedVertices.Count;
|
||||||
if (Clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
|
if (Clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
|
||||||
|
clipOutputItems = clipOutput.Items;
|
||||||
int clipOutputLength = clipOutput.Count;
|
int clipOutputLength = clipOutput.Count;
|
||||||
if (clipOutputLength == 0) continue;
|
if (clipOutputLength == 0) continue;
|
||||||
float d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1;
|
float d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1;
|
||||||
float d = 1 / (d0 * d2 + d1 * (y1 - y3));
|
float d = 1 / (d0 * d2 + d1 * (y1 - y3));
|
||||||
|
|
||||||
int clipOutputCount = clipOutputLength >> 1;
|
int clipOutputCount = clipOutputLength >> 1;
|
||||||
float[] clipOutputItems = clipOutput.Items;
|
|
||||||
float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items;
|
float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items;
|
||||||
float[] clippedUVsItems = clippedUVs.Resize(s + clipOutputCount * 2).Items;
|
float[] clippedUVsItems = clippedUVs.Resize(s + clipOutputCount * 2).Items;
|
||||||
for (int ii = 0; ii < clipOutputLength; ii += 2, s += 2) {
|
for (int ii = 0; ii < clipOutputLength; ii += 2, s += 2) {
|
||||||
@ -226,6 +228,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return clipOutputItems != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping
|
///<summary>Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "com.esotericsoftware.spine.spine-csharp",
|
"name": "com.esotericsoftware.spine.spine-csharp",
|
||||||
"displayName": "spine-csharp Runtime",
|
"displayName": "spine-csharp Runtime",
|
||||||
"description": "This plugin provides the spine-csharp core runtime.",
|
"description": "This plugin provides the spine-csharp core runtime.",
|
||||||
"version": "4.2.36",
|
"version": "4.3.0",
|
||||||
"unity": "2018.3",
|
"unity": "2018.3",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Esoteric Software",
|
"name": "Esoteric Software",
|
||||||
|
|||||||
@ -682,8 +682,8 @@ namespace Spine.Unity {
|
|||||||
color.b = (byte)(skeletonB * slot.B * c.b * 255);
|
color.b = (byte)(skeletonB * slot.B * c.b * 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useClipping && clipper.IsClipping) {
|
if (useClipping && clipper.IsClipping
|
||||||
clipper.ClipTriangles(workingVerts, attachmentTriangleIndices, attachmentIndexCount, uvs);
|
&& clipper.ClipTriangles(workingVerts, attachmentTriangleIndices, attachmentIndexCount, uvs)) {
|
||||||
workingVerts = clipper.ClippedVertices.Items;
|
workingVerts = clipper.ClippedVertices.Items;
|
||||||
attachmentVertexCount = clipper.ClippedVertices.Count >> 1;
|
attachmentVertexCount = clipper.ClippedVertices.Count >> 1;
|
||||||
attachmentTriangleIndices = clipper.ClippedTriangles.Items;
|
attachmentTriangleIndices = clipper.ClippedTriangles.Items;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "com.esotericsoftware.spine.spine-unity",
|
"name": "com.esotericsoftware.spine.spine-unity",
|
||||||
"displayName": "spine-unity Runtime",
|
"displayName": "spine-unity Runtime",
|
||||||
"description": "This plugin provides the spine-unity runtime core.",
|
"description": "This plugin provides the spine-unity runtime core.",
|
||||||
"version": "4.2.99",
|
"version": "4.3.0",
|
||||||
"unity": "2018.3",
|
"unity": "2018.3",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Esoteric Software",
|
"name": "Esoteric Software",
|
||||||
@ -14,7 +14,7 @@
|
|||||||
"com.unity.modules.animation" : "1.0.0",
|
"com.unity.modules.animation" : "1.0.0",
|
||||||
"com.unity.modules.physics" : "1.0.0",
|
"com.unity.modules.physics" : "1.0.0",
|
||||||
"com.unity.modules.physics2d" : "1.0.0",
|
"com.unity.modules.physics2d" : "1.0.0",
|
||||||
"com.esotericsoftware.spine.spine-csharp": "4.2.0"
|
"com.esotericsoftware.spine.spine-csharp": "4.3.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user