mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Remove old front-facing-triangles code.
This commit is contained in:
parent
2ad6fd1280
commit
34f8afbefc
@ -33,8 +33,6 @@
|
|||||||
#define SPINE_OPTIONAL_NORMALS
|
#define SPINE_OPTIONAL_NORMALS
|
||||||
#define SPINE_OPTIONAL_SOLVETANGENTS
|
#define SPINE_OPTIONAL_SOLVETANGENTS
|
||||||
|
|
||||||
//#define SPINE_OPTIONAL_FRONTFACING
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -73,9 +71,6 @@ namespace Spine.Unity {
|
|||||||
#if SPINE_OPTIONAL_SOLVETANGENTS
|
#if SPINE_OPTIONAL_SOLVETANGENTS
|
||||||
public bool calculateTangents;
|
public bool calculateTangents;
|
||||||
#endif
|
#endif
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
public bool frontFacing;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public bool logErrors = false;
|
public bool logErrors = false;
|
||||||
|
|
||||||
@ -257,14 +252,6 @@ namespace Spine.Unity {
|
|||||||
workingAttachments.Count = drawOrderCount;
|
workingAttachments.Count = drawOrderCount;
|
||||||
var workingAttachmentsItems = workingInstruction.attachments.Items;
|
var workingAttachmentsItems = workingInstruction.attachments.Items;
|
||||||
|
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
var workingFlips = workingInstruction.attachmentFlips;
|
|
||||||
workingFlips.Clear(false);
|
|
||||||
workingFlips.GrowIfNeeded(drawOrderCount);
|
|
||||||
workingFlips.Count = drawOrderCount;
|
|
||||||
var workingFlipsItems = workingFlips.Items;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var workingSubmeshInstructions = workingInstruction.submeshInstructions; // Items array should not be cached. There is dynamic writing to this list.
|
var workingSubmeshInstructions = workingInstruction.submeshInstructions; // Items array should not be cached. There is dynamic writing to this list.
|
||||||
workingSubmeshInstructions.Clear(false);
|
workingSubmeshInstructions.Clear(false);
|
||||||
|
|
||||||
@ -282,11 +269,6 @@ namespace Spine.Unity {
|
|||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.attachment;
|
||||||
workingAttachmentsItems[i] = attachment;
|
workingAttachmentsItems[i] = attachment;
|
||||||
|
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
bool flip = frontFacing && (slot.bone.WorldSignX != slot.bone.WorldSignY);
|
|
||||||
workingFlipsItems[i] = flip;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
object rendererObject = null; // 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;
|
bool noRender = false;
|
||||||
@ -395,9 +377,6 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
workingInstruction.vertexCount = vertexCount;
|
workingInstruction.vertexCount = vertexCount;
|
||||||
workingInstruction.immutableTriangles = this.immutableTriangles;
|
workingInstruction.immutableTriangles = this.immutableTriangles;
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
workingInstruction.frontFacing = this.frontFacing;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// STEP 1.9. Post-process workingInstructions. ============================================================
|
// STEP 1.9. Post-process workingInstructions. ============================================================
|
||||||
@ -510,7 +489,6 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
if (mutableTriangles || i >= oldSubmeshCount) {
|
if (mutableTriangles || i >= oldSubmeshCount) {
|
||||||
|
|
||||||
#if !SPINE_OPTIONAL_FRONTFACING
|
|
||||||
var currentSubmesh = submeshes.Items[i];
|
var currentSubmesh = submeshes.Items[i];
|
||||||
int instructionTriangleCount = submeshInstruction.triangleCount;
|
int instructionTriangleCount = submeshInstruction.triangleCount;
|
||||||
if (renderMeshes) {
|
if (renderMeshes) {
|
||||||
@ -519,9 +497,6 @@ namespace Spine.Unity {
|
|||||||
} else {
|
} else {
|
||||||
ArraysMeshGenerator.FillTrianglesQuads(ref currentSubmesh.triangles, ref currentSubmesh.triangleCount, ref currentSubmesh.firstVertex, submeshInstruction.firstVertexIndex, instructionTriangleCount, (i == last));
|
ArraysMeshGenerator.FillTrianglesQuads(ref currentSubmesh.triangles, ref currentSubmesh.triangleCount, ref currentSubmesh.firstVertex, submeshInstruction.firstVertexIndex, instructionTriangleCount, (i == last));
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
SetSubmesh(i, submeshInstruction, currentInstructions.attachmentFlips, i == last);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,19 +588,6 @@ namespace Spine.Unity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
if (a.frontFacing != b.frontFacing) { // if settings changed
|
|
||||||
return true;
|
|
||||||
} else if (a.frontFacing) { // if settings matched, only need to check one.
|
|
||||||
var flipsA = a.attachmentFlips.Items;
|
|
||||||
var flipsB = b.attachmentFlips.Items;
|
|
||||||
for (int i = 0; i < attachmentCountB; i++) {
|
|
||||||
if (flipsA[i] != flipsB[i])
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Submesh count changed
|
// Submesh count changed
|
||||||
int submeshCountA = a.submeshInstructions.Count;
|
int submeshCountA = a.submeshInstructions.Count;
|
||||||
int submeshCountB = b.submeshInstructions.Count;
|
int submeshCountB = b.submeshInstructions.Count;
|
||||||
@ -652,106 +614,6 @@ namespace Spine.Unity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
void SetSubmesh (int submeshIndex, Spine.Unity.MeshGeneration.SubmeshInstruction submeshInstructions, ExposedList<bool> flipStates, bool isLastSubmesh) {
|
|
||||||
var currentSubmesh = submeshes.Items[submeshIndex];
|
|
||||||
int[] triangles = currentSubmesh.triangles;
|
|
||||||
|
|
||||||
int triangleCount = submeshInstructions.triangleCount;
|
|
||||||
int firstVertex = submeshInstructions.firstVertexIndex;
|
|
||||||
|
|
||||||
int trianglesCapacity = triangles.Length;
|
|
||||||
if (isLastSubmesh && trianglesCapacity > triangleCount) {
|
|
||||||
// Last submesh may have more triangles than required, so zero triangles to the end.
|
|
||||||
for (int i = triangleCount; i < trianglesCapacity; i++)
|
|
||||||
triangles[i] = 0;
|
|
||||||
|
|
||||||
currentSubmesh.triangleCount = triangleCount;
|
|
||||||
|
|
||||||
} else if (trianglesCapacity != triangleCount) {
|
|
||||||
// Reallocate triangles when not the exact size needed.
|
|
||||||
currentSubmesh.triangles = triangles = new int[triangleCount];
|
|
||||||
currentSubmesh.triangleCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.renderMeshes && !this.frontFacing) {
|
|
||||||
// Use stored triangles if possible.
|
|
||||||
if (currentSubmesh.firstVertex != firstVertex || currentSubmesh.triangleCount < triangleCount) { //|| currentSubmesh.triangleCount == 0
|
|
||||||
currentSubmesh.triangleCount = triangleCount;
|
|
||||||
currentSubmesh.firstVertex = firstVertex;
|
|
||||||
|
|
||||||
for (int i = 0; i < triangleCount; i += 6, firstVertex += 4) {
|
|
||||||
triangles[i] = firstVertex;
|
|
||||||
triangles[i + 1] = firstVertex + 2;
|
|
||||||
triangles[i + 2] = firstVertex + 1;
|
|
||||||
triangles[i + 3] = firstVertex + 2;
|
|
||||||
triangles[i + 4] = firstVertex + 3;
|
|
||||||
triangles[i + 5] = firstVertex + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var flipStatesItems = flipStates.Items;
|
|
||||||
|
|
||||||
// Iterate through all slots and store their triangles.
|
|
||||||
var drawOrderItems = skeleton.DrawOrder.Items;
|
|
||||||
int triangleIndex = 0; // Modified by loop
|
|
||||||
for (int i = submeshInstructions.startSlot, n = submeshInstructions.endSlot; i < n; i++) {
|
|
||||||
Attachment attachment = drawOrderItems[i].attachment;
|
|
||||||
bool flip = frontFacing && flipStatesItems[i];
|
|
||||||
|
|
||||||
// Add RegionAttachment triangles
|
|
||||||
if (attachment is RegionAttachment) {
|
|
||||||
if (!flip) {
|
|
||||||
triangles[triangleIndex] = firstVertex;
|
|
||||||
triangles[triangleIndex + 1] = firstVertex + 2;
|
|
||||||
triangles[triangleIndex + 2] = firstVertex + 1;
|
|
||||||
triangles[triangleIndex + 3] = firstVertex + 2;
|
|
||||||
triangles[triangleIndex + 4] = firstVertex + 3;
|
|
||||||
triangles[triangleIndex + 5] = firstVertex + 1;
|
|
||||||
} else {
|
|
||||||
triangles[triangleIndex] = firstVertex + 1;
|
|
||||||
triangles[triangleIndex + 1] = firstVertex + 2;
|
|
||||||
triangles[triangleIndex + 2] = firstVertex;
|
|
||||||
triangles[triangleIndex + 3] = firstVertex + 1;
|
|
||||||
triangles[triangleIndex + 4] = firstVertex + 3;
|
|
||||||
triangles[triangleIndex + 5] = firstVertex + 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
triangleIndex += 6;
|
|
||||||
firstVertex += 4;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add (Weighted)MeshAttachment triangles
|
|
||||||
int[] attachmentTriangles;
|
|
||||||
int attachmentVertexCount;
|
|
||||||
var meshAttachment = attachment as MeshAttachment;
|
|
||||||
if (meshAttachment != null) {
|
|
||||||
attachmentVertexCount = meshAttachment.worldVerticesLength >> 1; // length/2
|
|
||||||
attachmentTriangles = meshAttachment.triangles;
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flip) {
|
|
||||||
for (int ii = 0, nn = attachmentTriangles.Length; ii < nn; ii += 3, triangleIndex += 3) {
|
|
||||||
triangles[triangleIndex + 2] = firstVertex + attachmentTriangles[ii];
|
|
||||||
triangles[triangleIndex + 1] = firstVertex + attachmentTriangles[ii + 1];
|
|
||||||
triangles[triangleIndex] = firstVertex + attachmentTriangles[ii + 2];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (int ii = 0, nn = attachmentTriangles.Length; ii < nn; ii++, triangleIndex++) {
|
|
||||||
triangles[triangleIndex] = firstVertex + attachmentTriangles[ii];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
firstVertex += attachmentVertexCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///<summary>This is a Mesh that also stores the instructions SkeletonRenderer generated for it.</summary>
|
///<summary>This is a Mesh that also stores the instructions SkeletonRenderer generated for it.</summary>
|
||||||
public class SmartMesh {
|
public class SmartMesh {
|
||||||
public Mesh mesh = Spine.Unity.SpineMesh.NewMesh();
|
public Mesh mesh = Spine.Unity.SpineMesh.NewMesh();
|
||||||
@ -763,18 +625,9 @@ namespace Spine.Unity {
|
|||||||
public readonly ExposedList<Attachment> attachments = new ExposedList<Attachment>();
|
public readonly ExposedList<Attachment> attachments = new ExposedList<Attachment>();
|
||||||
public readonly ExposedList<Spine.Unity.MeshGeneration.SubmeshInstruction> submeshInstructions = new ExposedList<Spine.Unity.MeshGeneration.SubmeshInstruction>();
|
public readonly ExposedList<Spine.Unity.MeshGeneration.SubmeshInstruction> submeshInstructions = new ExposedList<Spine.Unity.MeshGeneration.SubmeshInstruction>();
|
||||||
|
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
public bool frontFacing;
|
|
||||||
public readonly ExposedList<bool> attachmentFlips = new ExposedList<bool>();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public void Clear () {
|
public void Clear () {
|
||||||
this.attachments.Clear(false);
|
this.attachments.Clear(false);
|
||||||
this.submeshInstructions.Clear(false);
|
this.submeshInstructions.Clear(false);
|
||||||
|
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
this.attachmentFlips.Clear(false);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Set (Instruction other) {
|
public void Set (Instruction other) {
|
||||||
@ -786,15 +639,6 @@ namespace Spine.Unity {
|
|||||||
this.attachments.Count = other.attachments.Count;
|
this.attachments.Count = other.attachments.Count;
|
||||||
other.attachments.CopyTo(this.attachments.Items);
|
other.attachments.CopyTo(this.attachments.Items);
|
||||||
|
|
||||||
#if SPINE_OPTIONAL_FRONTFACING
|
|
||||||
this.frontFacing = other.frontFacing;
|
|
||||||
this.attachmentFlips.Clear(false);
|
|
||||||
this.attachmentFlips.GrowIfNeeded(other.attachmentFlips.Capacity);
|
|
||||||
this.attachmentFlips.Count = other.attachmentFlips.Count;
|
|
||||||
if (this.frontFacing)
|
|
||||||
other.attachmentFlips.CopyTo(this.attachmentFlips.Items);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
this.submeshInstructions.Clear(false);
|
this.submeshInstructions.Clear(false);
|
||||||
this.submeshInstructions.GrowIfNeeded(other.submeshInstructions.Capacity);
|
this.submeshInstructions.GrowIfNeeded(other.submeshInstructions.Capacity);
|
||||||
this.submeshInstructions.Count = other.submeshInstructions.Count;
|
this.submeshInstructions.Count = other.submeshInstructions.Count;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user