mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Fix ignored slot separators. Some optimizations.
This commit is contained in:
parent
acb84e44d7
commit
612ed2e3ae
@ -55,7 +55,7 @@ namespace Spine.Unity.Modules {
|
|||||||
|
|
||||||
MeshRenderer mainMeshRenderer;
|
MeshRenderer mainMeshRenderer;
|
||||||
public bool copyPropertyBlock = false;
|
public bool copyPropertyBlock = false;
|
||||||
[Tooltip("Copies MeshRenderer flags into ")]
|
[Tooltip("Copies MeshRenderer flags into each parts renderer")]
|
||||||
public bool copyMeshRendererFlags = false;
|
public bool copyMeshRendererFlags = false;
|
||||||
public List<Spine.Unity.Modules.SkeletonPartsRenderer> partsRenderers = new List<SkeletonPartsRenderer>();
|
public List<Spine.Unity.Modules.SkeletonPartsRenderer> partsRenderers = new List<SkeletonPartsRenderer>();
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ namespace Spine.Unity.Modules {
|
|||||||
int rendererCount = partsRenderers.Count;
|
int rendererCount = partsRenderers.Count;
|
||||||
if (rendererCount <= 0) return;
|
if (rendererCount <= 0) return;
|
||||||
|
|
||||||
int rendererIndex = 0;
|
|
||||||
|
|
||||||
if (copyPropertyBlock)
|
if (copyPropertyBlock)
|
||||||
mainMeshRenderer.GetPropertyBlock(copiedBlock);
|
mainMeshRenderer.GetPropertyBlock(copiedBlock);
|
||||||
@ -134,11 +134,13 @@ namespace Spine.Unity.Modules {
|
|||||||
var submeshInstructionsItems = submeshInstructions.Items;
|
var submeshInstructionsItems = submeshInstructions.Items;
|
||||||
int lastSubmeshInstruction = submeshInstructions.Count - 1;
|
int lastSubmeshInstruction = submeshInstructions.Count - 1;
|
||||||
|
|
||||||
var currentRenderer = partsRenderers[rendererIndex];
|
|
||||||
bool addNormals = skeletonRenderer.calculateNormals;
|
bool addNormals = skeletonRenderer.calculateNormals;
|
||||||
bool addTangents = skeletonRenderer.calculateTangents;
|
bool addTangents = skeletonRenderer.calculateTangents;
|
||||||
bool pmaVertexColors = skeletonRenderer.pmaVertexColors;
|
bool pmaVertexColors = skeletonRenderer.pmaVertexColors;
|
||||||
|
|
||||||
|
int rendererIndex = 0;
|
||||||
|
var currentRenderer = partsRenderers[rendererIndex];
|
||||||
for (int si = 0, start = 0; si <= lastSubmeshInstruction; si++) {
|
for (int si = 0, start = 0; si <= lastSubmeshInstruction; si++) {
|
||||||
if (submeshInstructionsItems[si].forceSeparate || si == lastSubmeshInstruction) {
|
if (submeshInstructionsItems[si].forceSeparate || si == lastSubmeshInstruction) {
|
||||||
// Apply properties
|
// Apply properties
|
||||||
|
|||||||
@ -267,6 +267,7 @@ namespace Spine.Unity {
|
|||||||
bool isCustomSlotMaterialsPopulated = customSlotMaterials.Count > 0;
|
bool isCustomSlotMaterialsPopulated = customSlotMaterials.Count > 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool hasSeparators = separatorSlots.Count > 0;
|
||||||
int vertexCount = 0;
|
int vertexCount = 0;
|
||||||
int submeshVertexCount = 0;
|
int submeshVertexCount = 0;
|
||||||
int submeshTriangleCount = 0, submeshFirstVertex = 0, submeshStartSlotIndex = 0;
|
int submeshTriangleCount = 0, submeshFirstVertex = 0, submeshStartSlotIndex = 0;
|
||||||
@ -281,8 +282,9 @@ namespace Spine.Unity {
|
|||||||
workingFlipsItems[i] = flip;
|
workingFlipsItems[i] = flip;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
object rendererObject; // An AtlasRegion in plain Spine-Unity. Spine-TK2D hooks into TK2D's system. eventual source of Material object.
|
object rendererObject = null; // An AtlasRegion in plain Spine-Unity. Spine-TK2D hooks into TK2D's system. eventual source of Material object.
|
||||||
int attachmentVertexCount, attachmentTriangleCount;
|
int attachmentVertexCount, attachmentTriangleCount;
|
||||||
|
bool noRender = false;
|
||||||
|
|
||||||
var regionAttachment = attachment as RegionAttachment;
|
var regionAttachment = attachment as RegionAttachment;
|
||||||
if (regionAttachment != null) {
|
if (regionAttachment != null) {
|
||||||
@ -290,56 +292,85 @@ namespace Spine.Unity {
|
|||||||
attachmentVertexCount = 4;
|
attachmentVertexCount = 4;
|
||||||
attachmentTriangleCount = 6;
|
attachmentTriangleCount = 6;
|
||||||
} else {
|
} else {
|
||||||
if (!renderMeshes)
|
if (!renderMeshes) {
|
||||||
continue;
|
noRender = true;
|
||||||
var meshAttachment = attachment as MeshAttachment;
|
attachmentVertexCount = 0;
|
||||||
if (meshAttachment != null) {
|
attachmentTriangleCount = 0;
|
||||||
rendererObject = meshAttachment.RendererObject;
|
//continue;
|
||||||
attachmentVertexCount = meshAttachment.worldVerticesLength >> 1;
|
|
||||||
attachmentTriangleCount = meshAttachment.triangles.Length;
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
var meshAttachment = attachment as MeshAttachment;
|
||||||
|
if (meshAttachment != null) {
|
||||||
|
rendererObject = meshAttachment.RendererObject;
|
||||||
|
attachmentVertexCount = meshAttachment.worldVerticesLength >> 1;
|
||||||
|
attachmentTriangleCount = meshAttachment.triangles.Length;
|
||||||
|
} else {
|
||||||
|
noRender = true;
|
||||||
|
attachmentVertexCount = 0;
|
||||||
|
attachmentTriangleCount = 0;
|
||||||
|
//continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !SPINE_TK2D
|
|
||||||
Material material; //= (Material)((AtlasRegion)rendererObject).page.rendererObject; // For no customSlotMaterials
|
|
||||||
if (isCustomSlotMaterialsPopulated) {
|
|
||||||
if (!customSlotMaterials.TryGetValue(slot, out material)) {
|
|
||||||
material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
Material material = (rendererObject.GetType() == typeof(Material)) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Create a new SubmeshInstruction when material changes. (or when forced to separate by a submeshSeparator)
|
// Create a new SubmeshInstruction when material changes. (or when forced to separate by a submeshSeparator)
|
||||||
bool forceSeparate = (separatorSlots.Count > 0 && separatorSlots.Contains(slot));
|
// Slot with a separator/new material will become the starting slot of the next new instruction.
|
||||||
if (vertexCount > 0 && (lastMaterial.GetInstanceID() != material.GetInstanceID() || forceSeparate)) {
|
bool forceSeparate = (hasSeparators && separatorSlots.Contains(slot));
|
||||||
workingSubmeshInstructions.Add(
|
if (noRender) {
|
||||||
new Spine.Unity.MeshGeneration.SubmeshInstruction {
|
if (forceSeparate && vertexCount > 0 && this.generateMeshOverride != null) {
|
||||||
skeleton = this.skeleton,
|
workingSubmeshInstructions.Add(
|
||||||
material = lastMaterial,
|
new Spine.Unity.MeshGeneration.SubmeshInstruction {
|
||||||
startSlot = submeshStartSlotIndex,
|
skeleton = this.skeleton,
|
||||||
endSlot = i,
|
material = lastMaterial,
|
||||||
triangleCount = submeshTriangleCount,
|
startSlot = submeshStartSlotIndex,
|
||||||
firstVertexIndex = submeshFirstVertex,
|
endSlot = i,
|
||||||
vertexCount = submeshVertexCount,
|
triangleCount = submeshTriangleCount,
|
||||||
forceSeparate = forceSeparate
|
firstVertexIndex = submeshFirstVertex,
|
||||||
}
|
vertexCount = submeshVertexCount,
|
||||||
);
|
forceSeparate = forceSeparate
|
||||||
submeshTriangleCount = 0;
|
}
|
||||||
submeshVertexCount = 0;
|
);
|
||||||
submeshFirstVertex = vertexCount;
|
submeshTriangleCount = 0;
|
||||||
submeshStartSlotIndex = i;
|
submeshVertexCount = 0;
|
||||||
|
submeshFirstVertex = vertexCount;
|
||||||
|
submeshStartSlotIndex = i;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#if !SPINE_TK2D
|
||||||
|
Material material;
|
||||||
|
if (isCustomSlotMaterialsPopulated) {
|
||||||
|
if (!customSlotMaterials.TryGetValue(slot, out material))
|
||||||
|
material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
||||||
|
} else {
|
||||||
|
material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Material material = (rendererObject.GetType() == typeof(Material)) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (vertexCount > 0 && (forceSeparate || lastMaterial.GetInstanceID() != material.GetInstanceID())) {
|
||||||
|
workingSubmeshInstructions.Add(
|
||||||
|
new Spine.Unity.MeshGeneration.SubmeshInstruction {
|
||||||
|
skeleton = this.skeleton,
|
||||||
|
material = lastMaterial,
|
||||||
|
startSlot = submeshStartSlotIndex,
|
||||||
|
endSlot = i,
|
||||||
|
triangleCount = submeshTriangleCount,
|
||||||
|
firstVertexIndex = submeshFirstVertex,
|
||||||
|
vertexCount = submeshVertexCount,
|
||||||
|
forceSeparate = forceSeparate
|
||||||
|
}
|
||||||
|
);
|
||||||
|
submeshTriangleCount = 0;
|
||||||
|
submeshVertexCount = 0;
|
||||||
|
submeshFirstVertex = vertexCount;
|
||||||
|
submeshStartSlotIndex = i;
|
||||||
|
}
|
||||||
|
// Update state for the next iteration.
|
||||||
|
lastMaterial = material;
|
||||||
|
submeshTriangleCount += attachmentTriangleCount;
|
||||||
|
vertexCount += attachmentVertexCount;
|
||||||
|
submeshVertexCount += attachmentVertexCount;
|
||||||
}
|
}
|
||||||
// Update state for the next iteration.
|
|
||||||
lastMaterial = material;
|
|
||||||
submeshTriangleCount += attachmentTriangleCount;
|
|
||||||
vertexCount += attachmentVertexCount;
|
|
||||||
submeshVertexCount += attachmentVertexCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (submeshVertexCount != 0) {
|
if (submeshVertexCount != 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user