diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs index 8d01c43dc..0f79e91d3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs @@ -37,8 +37,9 @@ #define MANUALLY_INLINE_VECTOR_OPERATORS #endif -// Not for optimization. Do not disable. -#define SPINE_TRIANGLECHECK // Avoid calling SetTriangles at the cost of checking for mesh differences (vertex counts, memberwise attachment list compare) every frame. +// Optimization option: Allows faster BuildMeshWithArrays call and avoids calling SetTriangles at the cost of +// checking for mesh differences (vertex counts, member-wise attachment list compare) every frame. +#define SPINE_TRIANGLECHECK //#define SPINE_DEBUG // New optimization option to avoid rendering fully transparent attachments at slot alpha 0. @@ -285,7 +286,12 @@ namespace Spine.Unity { instructionOutput.rawVertexCount = totalRawVertexCount; #endif - if (totalRawVertexCount > 0) { +#if SPINE_TRIANGLECHECK + bool hasAnyVertices = totalRawVertexCount > 0; +#else + bool hasAnyVertices = true; +#endif + if (hasAnyVertices) { workingSubmeshInstructions.Resize(1); workingSubmeshInstructions.Items[0] = current; } else { @@ -367,7 +373,9 @@ namespace Spine.Unity { || (slot.A == 0f && slot.Data != clippingEndSlot) #endif ) { +#if SPINE_TRIANGLECHECK workingAttachmentsItems[i] = null; +#endif continue; } if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true; @@ -458,7 +466,11 @@ namespace Spine.Unity { Material material = (region is Material) ? (Material)region : (Material)((AtlasRegion)region).page.rendererObject; #endif +#if !SPINE_TRIANGLECHECK + if (current.forceSeparate || !System.Object.ReferenceEquals(current.material, material)) { // Material changed. Add the previous submesh. +#else if (current.forceSeparate || (current.rawVertexCount > 0 && !System.Object.ReferenceEquals(current.material, material))) { // Material changed. Add the previous submesh. +#endif { // Add current.endSlot = i; current.preActiveClippingSlotSource = lastPreActiveClipping; @@ -526,9 +538,9 @@ namespace Spine.Unity { wsii[i].material = overrideMaterial; } } - #endregion +#endregion - #region Step 2 : Populate vertex data and triangle index buffers. +#region Step 2 : Populate vertex data and triangle index buffers. public void Begin () { vertexBuffer.Clear(false); colorBuffer.Clear(false); @@ -799,6 +811,9 @@ namespace Spine.Unity { // Use this faster method when no clipping is involved. public void BuildMeshWithArrays (SkeletonRendererInstruction instruction, bool updateTriangles) { +#if !SPINE_TRIANGLECHECK + return; +#else Settings settings = this.settings; bool canvasGroupTintBlack = settings.tintBlack && settings.canvasGroupCompatible; int totalVertexCount = instruction.rawVertexCount; @@ -1113,6 +1128,7 @@ namespace Spine.Unity { } } } +#endif // SPINE_TRIANGLECHECK } public void ScaleVertexData (float scale) { @@ -1202,9 +1218,9 @@ namespace Spine.Unity { } } } - #endregion +#endregion - #region Step 3 : Transfer vertex and triangle data to UnityEngine.Mesh +#region Step 3 : Transfer vertex and triangle data to UnityEngine.Mesh public void FillVertexData (Mesh mesh) { Vector3[] vbi = vertexBuffer.Items; Vector2[] ubi = uvBuffer.Items; @@ -1284,7 +1300,7 @@ namespace Spine.Unity { mesh.SetTriangles(submeshesItems[i].Items, i, false); #endif } - #endregion +#endregion public void EnsureVertexCapacity (int minimumVertexCount, bool inlcudeTintBlack = false, bool includeTangents = false, bool includeNormals = false) { if (minimumVertexCount > vertexBuffer.Items.Length) { @@ -1332,7 +1348,7 @@ namespace Spine.Unity { if (tangents != null) Array.Resize(ref tangents, vbiLength); } - #region TangentSolver2D +#region TangentSolver2D // Thanks to contributions from forum user ToddRivers /// Step 1 of solving tangents. Ensure you have buffers of the correct size. @@ -1419,9 +1435,9 @@ namespace Spine.Unity { tangents[i] = tangent; } } - #endregion +#endregion - #region AttachmentRendering +#region AttachmentRendering static List AttachmentVerts = new List(); static List AttachmentUVs = new List(); static List AttachmentColors32 = new List(); @@ -1533,6 +1549,6 @@ namespace Spine.Unity { AttachmentColors32.Clear(); AttachmentIndices.Clear(); } - #endregion +#endregion } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshRendererBuffers.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshRendererBuffers.cs index 2b037a7c1..22b749065 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshRendererBuffers.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshRendererBuffers.cs @@ -27,8 +27,9 @@ * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -// Not for optimization. Do not disable. -#define SPINE_TRIANGLECHECK // Avoid calling SetTriangles at the cost of checking for mesh differences (vertex counts, memberwise attachment list compare) every frame. +// Optimization option: Allows faster BuildMeshWithArrays call and avoids calling SetTriangles at the cost of +// checking for mesh differences (vertex counts, member-wise attachment list compare) every frame. +#define SPINE_TRIANGLECHECK //#define SPINE_DEBUG using System; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/SkeletonRendererInstruction.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/SkeletonRendererInstruction.cs index 4b1c192d0..4a564bd05 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/SkeletonRendererInstruction.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/SkeletonRendererInstruction.cs @@ -27,8 +27,9 @@ * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -// Not for optimization. Do not disable. -#define SPINE_TRIANGLECHECK // Avoid calling SetTriangles at the cost of checking for mesh differences (vertex counts, memberwise attachment list compare) every frame. +// Optimization option: Allows faster BuildMeshWithArrays call and avoids calling SetTriangles at the cost of +// checking for mesh differences (vertex counts, member-wise attachment list compare) every frame. +#define SPINE_TRIANGLECHECK //#define SPINE_DEBUG // Important Note: When disabling this define, also disable the one in MeshGenerator.cs @@ -49,6 +50,11 @@ namespace Spine.Unity { public bool hasActiveClipping; public int rawVertexCount = -1; public readonly ExposedList attachments = new ExposedList(); +#else + /// Returns constant true to avoid BuildMeshWithArrays in renderers. + public bool hasActiveClipping { get { return true; } } + /// Returns constant vertex count for early-return if-clauses in renderers. + public int rawVertexCount { get { return 1; } } #endif public void Clear () { @@ -60,9 +66,11 @@ namespace Spine.Unity { this.submeshInstructions.Clear(false); } +#if SPINE_TRIANGLECHECK public void Dispose () { attachments.Clear(true); } +#endif public void SetWithSubset (ExposedList instructions, int startSubmesh, int endSubmesh) { #if SPINE_TRIANGLECHECK diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/SpineMesh.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/SpineMesh.cs index 0b36a289f..e15e457d6 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/SpineMesh.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/SpineMesh.cs @@ -27,8 +27,9 @@ * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -// Not for optimization. Do not disable. -#define SPINE_TRIANGLECHECK // Avoid calling SetTriangles at the cost of checking for mesh differences (vertex counts, memberwise attachment list compare) every frame. +// Optimization option: Allows faster BuildMeshWithArrays call and avoids calling SetTriangles at the cost of +// checking for mesh differences (vertex counts, member-wise attachment list compare) every frame. +#define SPINE_TRIANGLECHECK //#define SPINE_DEBUG using System; @@ -66,6 +67,9 @@ namespace Spine.Unity { public int rawVertexCount; public int rawFirstVertexIndex; public bool hasClipping; +#else + /// Returns constant vertex count for early-return if clauses in renderers. + public int rawVertexCount { get { return 1; } } #endif public bool hasPMAAdditiveSlot; diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index 97a3bff82..2ed19ad02 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/spine-unity/Assets/Spine/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-unity", "displayName": "spine-unity Runtime", "description": "This plugin provides the spine-unity runtime core.", - "version": "4.2.84", + "version": "4.2.85", "unity": "2018.3", "author": { "name": "Esoteric Software",