mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
Fixed bounds when there are no attachments to render.
This commit is contained in:
parent
2d70e2b05b
commit
9478db3d2d
@ -320,151 +320,122 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
float a = skeleton.a * 255, r = skeleton.r, g = skeleton.g, b = skeleton.b;
|
||||
|
||||
Vector3 meshBoundsMin;
|
||||
meshBoundsMin.x = int.MaxValue;
|
||||
meshBoundsMin.y = int.MaxValue;
|
||||
Vector3 meshBoundsMax;
|
||||
meshBoundsMax.x = int.MinValue;
|
||||
meshBoundsMax.y = int.MinValue;
|
||||
if (zSpacing > 0f) {
|
||||
meshBoundsMin.z = 0f;
|
||||
meshBoundsMax.z = zSpacing * (drawOrderCount - 1);
|
||||
if (vertexCount == 0) {
|
||||
meshBoundsMin = new Vector3(0, 0, 0);
|
||||
meshBoundsMax = new Vector3(0, 0, 0);
|
||||
} else {
|
||||
meshBoundsMin.z = zSpacing * (drawOrderCount - 1);
|
||||
meshBoundsMax.z = 0f;
|
||||
}
|
||||
for (int i = 0; i < drawOrderCount; i++) {
|
||||
Slot slot = drawOrder.Items[i];
|
||||
Attachment attachment = slot.attachment;
|
||||
RegionAttachment regionAttachment = attachment as RegionAttachment;
|
||||
if (regionAttachment != null) {
|
||||
regionAttachment.ComputeWorldVertices(slot.bone, tempVertices);
|
||||
|
||||
float z = i * zSpacing;
|
||||
float x1 = tempVertices[RegionAttachment.X1], y1 = tempVertices[RegionAttachment.Y1];
|
||||
float x2 = tempVertices[RegionAttachment.X2], y2 = tempVertices[RegionAttachment.Y2];
|
||||
float x3 = tempVertices[RegionAttachment.X3], y3 = tempVertices[RegionAttachment.Y3];
|
||||
float x4 = tempVertices[RegionAttachment.X4], y4 = tempVertices[RegionAttachment.Y4];
|
||||
vertices[vertexIndex].x = x1;
|
||||
vertices[vertexIndex].y = y1;
|
||||
vertices[vertexIndex].z = z;
|
||||
vertices[vertexIndex + 1].x = x4;
|
||||
vertices[vertexIndex + 1].y = y4;
|
||||
vertices[vertexIndex + 1].z = z;
|
||||
vertices[vertexIndex + 2].x = x2;
|
||||
vertices[vertexIndex + 2].y = y2;
|
||||
vertices[vertexIndex + 2].z = z;
|
||||
vertices[vertexIndex + 3].x = x3;
|
||||
vertices[vertexIndex + 3].y = y3;
|
||||
vertices[vertexIndex + 3].z = z;
|
||||
|
||||
color.a = (byte)(a * slot.a * regionAttachment.a);
|
||||
color.r = (byte)(r * slot.r * regionAttachment.r * color.a);
|
||||
color.g = (byte)(g * slot.g * regionAttachment.g * color.a);
|
||||
color.b = (byte)(b * slot.b * regionAttachment.b * color.a);
|
||||
if (slot.data.blendMode == BlendMode.additive) color.a = 0;
|
||||
colors[vertexIndex] = color;
|
||||
colors[vertexIndex + 1] = color;
|
||||
colors[vertexIndex + 2] = color;
|
||||
colors[vertexIndex + 3] = color;
|
||||
|
||||
float[] regionUVs = regionAttachment.uvs;
|
||||
uvs[vertexIndex].x = regionUVs[RegionAttachment.X1];
|
||||
uvs[vertexIndex].y = regionUVs[RegionAttachment.Y1];
|
||||
uvs[vertexIndex + 1].x = regionUVs[RegionAttachment.X4];
|
||||
uvs[vertexIndex + 1].y = regionUVs[RegionAttachment.Y4];
|
||||
uvs[vertexIndex + 2].x = regionUVs[RegionAttachment.X2];
|
||||
uvs[vertexIndex + 2].y = regionUVs[RegionAttachment.Y2];
|
||||
uvs[vertexIndex + 3].x = regionUVs[RegionAttachment.X3];
|
||||
uvs[vertexIndex + 3].y = regionUVs[RegionAttachment.Y3];
|
||||
|
||||
// Calculate min/max X
|
||||
if (x1 < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x1;
|
||||
else if (x1 > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x1;
|
||||
if (x2 < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x2;
|
||||
else if (x2 > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x2;
|
||||
if (x3 < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x3;
|
||||
else if (x3 > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x3;
|
||||
if (x4 < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x4;
|
||||
else if (x4 > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x4;
|
||||
|
||||
// Calculate min/max Y
|
||||
if (y1 < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y1;
|
||||
else if (y1 > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y1;
|
||||
if (y2 < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y2;
|
||||
else if (y2 > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y2;
|
||||
if (y3 < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y3;
|
||||
else if (y3 > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y3;
|
||||
if (y4 < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y4;
|
||||
else if (y4 > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y4;
|
||||
|
||||
vertexIndex += 4;
|
||||
meshBoundsMin.x = int.MaxValue;
|
||||
meshBoundsMin.y = int.MaxValue;
|
||||
meshBoundsMax.x = int.MinValue;
|
||||
meshBoundsMax.y = int.MinValue;
|
||||
if (zSpacing > 0f) {
|
||||
meshBoundsMin.z = 0f;
|
||||
meshBoundsMax.z = zSpacing * (drawOrderCount - 1);
|
||||
} else {
|
||||
if (!renderMeshes)
|
||||
continue;
|
||||
MeshAttachment meshAttachment = attachment as MeshAttachment;
|
||||
if (meshAttachment != null) {
|
||||
int meshVertexCount = meshAttachment.vertices.Length;
|
||||
if (tempVertices.Length < meshVertexCount)
|
||||
this.tempVertices = tempVertices = new float[meshVertexCount];
|
||||
meshAttachment.ComputeWorldVertices(slot, tempVertices);
|
||||
meshBoundsMin.z = zSpacing * (drawOrderCount - 1);
|
||||
meshBoundsMax.z = 0f;
|
||||
}
|
||||
int i = 0;
|
||||
do {
|
||||
Slot slot = drawOrder.Items[i];
|
||||
Attachment attachment = slot.attachment;
|
||||
RegionAttachment regionAttachment = attachment as RegionAttachment;
|
||||
if (regionAttachment != null) {
|
||||
regionAttachment.ComputeWorldVertices(slot.bone, tempVertices);
|
||||
|
||||
color.a = (byte)(a * slot.a * meshAttachment.a);
|
||||
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
||||
color.g = (byte)(g * slot.g * meshAttachment.g * color.a);
|
||||
color.b = (byte)(b * slot.b * meshAttachment.b * color.a);
|
||||
if (slot.data.blendMode == BlendMode.additive) color.a = 0;
|
||||
|
||||
float[] meshUVs = meshAttachment.uvs;
|
||||
float z = i * zSpacing;
|
||||
for (int ii = 0; ii < meshVertexCount; ii += 2, vertexIndex++) {
|
||||
float x = tempVertices[ii], y = tempVertices[ii + 1];
|
||||
vertices[vertexIndex].x = x;
|
||||
vertices[vertexIndex].y = y;
|
||||
vertices[vertexIndex].z = z;
|
||||
colors[vertexIndex] = color;
|
||||
uvs[vertexIndex].x = meshUVs[ii];
|
||||
uvs[vertexIndex].y = meshUVs[ii + 1];
|
||||
float x1 = tempVertices[RegionAttachment.X1], y1 = tempVertices[RegionAttachment.Y1];
|
||||
float x2 = tempVertices[RegionAttachment.X2], y2 = tempVertices[RegionAttachment.Y2];
|
||||
float x3 = tempVertices[RegionAttachment.X3], y3 = tempVertices[RegionAttachment.Y3];
|
||||
float x4 = tempVertices[RegionAttachment.X4], y4 = tempVertices[RegionAttachment.Y4];
|
||||
vertices[vertexIndex].x = x1;
|
||||
vertices[vertexIndex].y = y1;
|
||||
vertices[vertexIndex].z = z;
|
||||
vertices[vertexIndex + 1].x = x4;
|
||||
vertices[vertexIndex + 1].y = y4;
|
||||
vertices[vertexIndex + 1].z = z;
|
||||
vertices[vertexIndex + 2].x = x2;
|
||||
vertices[vertexIndex + 2].y = y2;
|
||||
vertices[vertexIndex + 2].z = z;
|
||||
vertices[vertexIndex + 3].x = x3;
|
||||
vertices[vertexIndex + 3].y = y3;
|
||||
vertices[vertexIndex + 3].z = z;
|
||||
|
||||
if (x < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x;
|
||||
else if (x > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x;
|
||||
if (y < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y;
|
||||
else if (y > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y;
|
||||
}
|
||||
color.a = (byte)(a * slot.a * regionAttachment.a);
|
||||
color.r = (byte)(r * slot.r * regionAttachment.r * color.a);
|
||||
color.g = (byte)(g * slot.g * regionAttachment.g * color.a);
|
||||
color.b = (byte)(b * slot.b * regionAttachment.b * color.a);
|
||||
if (slot.data.blendMode == BlendMode.additive) color.a = 0;
|
||||
colors[vertexIndex] = color;
|
||||
colors[vertexIndex + 1] = color;
|
||||
colors[vertexIndex + 2] = color;
|
||||
colors[vertexIndex + 3] = color;
|
||||
|
||||
float[] regionUVs = regionAttachment.uvs;
|
||||
uvs[vertexIndex].x = regionUVs[RegionAttachment.X1];
|
||||
uvs[vertexIndex].y = regionUVs[RegionAttachment.Y1];
|
||||
uvs[vertexIndex + 1].x = regionUVs[RegionAttachment.X4];
|
||||
uvs[vertexIndex + 1].y = regionUVs[RegionAttachment.Y4];
|
||||
uvs[vertexIndex + 2].x = regionUVs[RegionAttachment.X2];
|
||||
uvs[vertexIndex + 2].y = regionUVs[RegionAttachment.Y2];
|
||||
uvs[vertexIndex + 3].x = regionUVs[RegionAttachment.X3];
|
||||
uvs[vertexIndex + 3].y = regionUVs[RegionAttachment.Y3];
|
||||
|
||||
// Calculate min/max X
|
||||
if (x1 < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x1;
|
||||
else if (x1 > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x1;
|
||||
if (x2 < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x2;
|
||||
else if (x2 > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x2;
|
||||
if (x3 < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x3;
|
||||
else if (x3 > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x3;
|
||||
if (x4 < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x4;
|
||||
else if (x4 > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x4;
|
||||
|
||||
// Calculate min/max Y
|
||||
if (y1 < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y1;
|
||||
else if (y1 > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y1;
|
||||
if (y2 < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y2;
|
||||
else if (y2 > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y2;
|
||||
if (y3 < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y3;
|
||||
else if (y3 > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y3;
|
||||
if (y4 < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y4;
|
||||
else if (y4 > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y4;
|
||||
|
||||
vertexIndex += 4;
|
||||
} else {
|
||||
SkinnedMeshAttachment skinnedMeshAttachment = attachment as SkinnedMeshAttachment;
|
||||
if (skinnedMeshAttachment != null) {
|
||||
int meshVertexCount = skinnedMeshAttachment.uvs.Length;
|
||||
if (!renderMeshes)
|
||||
continue;
|
||||
MeshAttachment meshAttachment = attachment as MeshAttachment;
|
||||
if (meshAttachment != null) {
|
||||
int meshVertexCount = meshAttachment.vertices.Length;
|
||||
if (tempVertices.Length < meshVertexCount)
|
||||
this.tempVertices = tempVertices = new float[meshVertexCount];
|
||||
skinnedMeshAttachment.ComputeWorldVertices(slot, tempVertices);
|
||||
meshAttachment.ComputeWorldVertices(slot, tempVertices);
|
||||
|
||||
color.a = (byte)(a * slot.a * skinnedMeshAttachment.a);
|
||||
color.r = (byte)(r * slot.r * skinnedMeshAttachment.r * color.a);
|
||||
color.g = (byte)(g * slot.g * skinnedMeshAttachment.g * color.a);
|
||||
color.b = (byte)(b * slot.b * skinnedMeshAttachment.b * color.a);
|
||||
color.a = (byte)(a * slot.a * meshAttachment.a);
|
||||
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
||||
color.g = (byte)(g * slot.g * meshAttachment.g * color.a);
|
||||
color.b = (byte)(b * slot.b * meshAttachment.b * color.a);
|
||||
if (slot.data.blendMode == BlendMode.additive) color.a = 0;
|
||||
|
||||
float[] meshUVs = skinnedMeshAttachment.uvs;
|
||||
float[] meshUVs = meshAttachment.uvs;
|
||||
float z = i * zSpacing;
|
||||
for (int ii = 0; ii < meshVertexCount; ii += 2, vertexIndex++) {
|
||||
float x = tempVertices[ii], y = tempVertices[ii + 1];
|
||||
@ -484,9 +455,44 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
else if (y > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y;
|
||||
}
|
||||
} else {
|
||||
SkinnedMeshAttachment skinnedMeshAttachment = attachment as SkinnedMeshAttachment;
|
||||
if (skinnedMeshAttachment != null) {
|
||||
int meshVertexCount = skinnedMeshAttachment.uvs.Length;
|
||||
if (tempVertices.Length < meshVertexCount)
|
||||
this.tempVertices = tempVertices = new float[meshVertexCount];
|
||||
skinnedMeshAttachment.ComputeWorldVertices(slot, tempVertices);
|
||||
|
||||
color.a = (byte)(a * slot.a * skinnedMeshAttachment.a);
|
||||
color.r = (byte)(r * slot.r * skinnedMeshAttachment.r * color.a);
|
||||
color.g = (byte)(g * slot.g * skinnedMeshAttachment.g * color.a);
|
||||
color.b = (byte)(b * slot.b * skinnedMeshAttachment.b * color.a);
|
||||
if (slot.data.blendMode == BlendMode.additive) color.a = 0;
|
||||
|
||||
float[] meshUVs = skinnedMeshAttachment.uvs;
|
||||
float z = i * zSpacing;
|
||||
for (int ii = 0; ii < meshVertexCount; ii += 2, vertexIndex++) {
|
||||
float x = tempVertices[ii], y = tempVertices[ii + 1];
|
||||
vertices[vertexIndex].x = x;
|
||||
vertices[vertexIndex].y = y;
|
||||
vertices[vertexIndex].z = z;
|
||||
colors[vertexIndex] = color;
|
||||
uvs[vertexIndex].x = meshUVs[ii];
|
||||
uvs[vertexIndex].y = meshUVs[ii + 1];
|
||||
|
||||
if (x < meshBoundsMin.x)
|
||||
meshBoundsMin.x = x;
|
||||
else if (x > meshBoundsMax.x)
|
||||
meshBoundsMax.x = x;
|
||||
if (y < meshBoundsMin.y)
|
||||
meshBoundsMin.y = y;
|
||||
else if (y > meshBoundsMax.y)
|
||||
meshBoundsMax.y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (++i < drawOrderCount);
|
||||
}
|
||||
|
||||
// Double buffer mesh.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user