Skip to content

Commit

Permalink
[unity] Fixed SPINE_TRIANGLE_CHECK define, was broken when disabled. …
Browse files Browse the repository at this point in the history
…Fixed documentation. Closes #2632.
  • Loading branch information
HaraldCsaszar committed Sep 12, 2024
1 parent 4cadd15 commit 7a999ea
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -285,7 +286,12 @@ public static void GenerateSingleSubmeshInstruction (SkeletonRendererInstruction
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 {
Expand Down Expand Up @@ -367,7 +373,9 @@ public static void GenerateSkeletonRendererInstruction (SkeletonRendererInstruct
|| (slot.A == 0f && slot.Data != clippingEndSlot)
#endif
) {
#if SPINE_TRIANGLECHECK
workingAttachmentsItems[i] = null;
#endif
continue;
}
if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true;
Expand Down Expand Up @@ -458,7 +466,11 @@ public static void GenerateSkeletonRendererInstruction (SkeletonRendererInstruct
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;
Expand Down Expand Up @@ -526,9 +538,9 @@ public static void TryReplaceMaterials (ExposedList<SubmeshInstruction> workingS
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);
Expand Down Expand Up @@ -799,6 +811,9 @@ public void BuildMesh (SkeletonRendererInstruction instruction, bool updateTrian

// 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;
Expand Down Expand Up @@ -1113,6 +1128,7 @@ public void BuildMeshWithArrays (SkeletonRendererInstruction instruction, bool u
}
}
}
#endif // SPINE_TRIANGLECHECK
}

public void ScaleVertexData (float scale) {
Expand Down Expand Up @@ -1202,9 +1218,9 @@ void ResizeOptionalUVBuffer (ref ExposedList<Vector2> uvBuffer, int vertexCount)
}
}
}
#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;
Expand Down Expand Up @@ -1284,7 +1300,7 @@ public void FillTriangles (Mesh mesh) {
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) {
Expand Down Expand Up @@ -1332,7 +1348,7 @@ public void TrimExcess () {
if (tangents != null) Array.Resize(ref tangents, vbiLength);
}

#region TangentSolver2D
#region TangentSolver2D
// Thanks to contributions from forum user ToddRivers

/// <summary>Step 1 of solving tangents. Ensure you have buffers of the correct size.</summary>
Expand Down Expand Up @@ -1419,9 +1435,9 @@ internal static void SolveTangents2DBuffer (Vector4[] tangents, Vector2[] tempTa
tangents[i] = tangent;
}
}
#endregion
#endregion

#region AttachmentRendering
#region AttachmentRendering
static List<Vector3> AttachmentVerts = new List<Vector3>();
static List<Vector2> AttachmentUVs = new List<Vector2>();
static List<Color32> AttachmentColors32 = new List<Color32>();
Expand Down Expand Up @@ -1533,6 +1549,6 @@ public static void FillMeshLocal (Mesh mesh, MeshAttachment meshAttachment, Skel
AttachmentColors32.Clear();
AttachmentIndices.Clear();
}
#endregion
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,6 +50,11 @@ public class SkeletonRendererInstruction {
public bool hasActiveClipping;
public int rawVertexCount = -1;
public readonly ExposedList<Attachment> attachments = new ExposedList<Attachment>();
#else
/// <summary>Returns constant true to avoid BuildMeshWithArrays in renderers.</summary>
public bool hasActiveClipping { get { return true; } }
/// <summary>Returns constant vertex count for early-return if-clauses in renderers.</summary>
public int rawVertexCount { get { return 1; } }
#endif

public void Clear () {
Expand All @@ -60,9 +66,11 @@ public void Clear () {
this.submeshInstructions.Clear(false);
}

#if SPINE_TRIANGLECHECK
public void Dispose () {
attachments.Clear(true);
}
#endif

public void SetWithSubset (ExposedList<SubmeshInstruction> instructions, int startSubmesh, int endSubmesh) {
#if SPINE_TRIANGLECHECK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,6 +67,9 @@ public struct SubmeshInstruction {
public int rawVertexCount;
public int rawFirstVertexIndex;
public bool hasClipping;
#else
/// <summary>Returns constant vertex count for early-return if clauses in renderers.</summary>
public int rawVertexCount { get { return 1; } }
#endif
public bool hasPMAAdditiveSlot;

Expand Down
2 changes: 1 addition & 1 deletion spine-unity/Assets/Spine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7a999ea

Please sign in to comment.