Browse Source

[unity] Fixed SPINE_TRIANGLE_CHECK define, was broken when disabled. Fixed documentation. Closes #2632.

Harald Csaszar 1 year ago
parent
commit
7a999ea934

+ 28 - 12
spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs

@@ -37,8 +37,9 @@
 #define MANUALLY_INLINE_VECTOR_OPERATORS
 #define MANUALLY_INLINE_VECTOR_OPERATORS
 #endif
 #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
 //#define SPINE_DEBUG
 
 
 // New optimization option to avoid rendering fully transparent attachments at slot alpha 0.
 // New optimization option to avoid rendering fully transparent attachments at slot alpha 0.
@@ -285,7 +286,12 @@ namespace Spine.Unity {
 			instructionOutput.rawVertexCount = totalRawVertexCount;
 			instructionOutput.rawVertexCount = totalRawVertexCount;
 #endif
 #endif
 
 
-			if (totalRawVertexCount > 0) {
+#if SPINE_TRIANGLECHECK
+			bool hasAnyVertices = totalRawVertexCount > 0;
+#else
+			bool hasAnyVertices = true;
+#endif
+			if (hasAnyVertices) {
 				workingSubmeshInstructions.Resize(1);
 				workingSubmeshInstructions.Resize(1);
 				workingSubmeshInstructions.Items[0] = current;
 				workingSubmeshInstructions.Items[0] = current;
 			} else {
 			} else {
@@ -367,7 +373,9 @@ namespace Spine.Unity {
 					|| (slot.A == 0f && slot.Data != clippingEndSlot)
 					|| (slot.A == 0f && slot.Data != clippingEndSlot)
 #endif
 #endif
 					) {
 					) {
+#if SPINE_TRIANGLECHECK
 					workingAttachmentsItems[i] = null;
 					workingAttachmentsItems[i] = null;
+#endif
 					continue;
 					continue;
 				}
 				}
 				if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true;
 				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;
 					Material material = (region is Material) ? (Material)region : (Material)((AtlasRegion)region).page.rendererObject;
 #endif
 #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.
 					if (current.forceSeparate || (current.rawVertexCount > 0 && !System.Object.ReferenceEquals(current.material, material))) { // Material changed. Add the previous submesh.
+#endif
 						{ // Add
 						{ // Add
 							current.endSlot = i;
 							current.endSlot = i;
 							current.preActiveClippingSlotSource = lastPreActiveClipping;
 							current.preActiveClippingSlotSource = lastPreActiveClipping;
@@ -526,9 +538,9 @@ namespace Spine.Unity {
 					wsii[i].material = overrideMaterial;
 					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 () {
 		public void Begin () {
 			vertexBuffer.Clear(false);
 			vertexBuffer.Clear(false);
 			colorBuffer.Clear(false);
 			colorBuffer.Clear(false);
@@ -799,6 +811,9 @@ namespace Spine.Unity {
 
 
 		// Use this faster method when no clipping is involved.
 		// Use this faster method when no clipping is involved.
 		public void BuildMeshWithArrays (SkeletonRendererInstruction instruction, bool updateTriangles) {
 		public void BuildMeshWithArrays (SkeletonRendererInstruction instruction, bool updateTriangles) {
+#if !SPINE_TRIANGLECHECK
+			return;
+#else
 			Settings settings = this.settings;
 			Settings settings = this.settings;
 			bool canvasGroupTintBlack = settings.tintBlack && settings.canvasGroupCompatible;
 			bool canvasGroupTintBlack = settings.tintBlack && settings.canvasGroupCompatible;
 			int totalVertexCount = instruction.rawVertexCount;
 			int totalVertexCount = instruction.rawVertexCount;
@@ -1113,6 +1128,7 @@ namespace Spine.Unity {
 					}
 					}
 				}
 				}
 			}
 			}
+#endif // SPINE_TRIANGLECHECK
 		}
 		}
 
 
 		public void ScaleVertexData (float scale) {
 		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) {
 		public void FillVertexData (Mesh mesh) {
 			Vector3[] vbi = vertexBuffer.Items;
 			Vector3[] vbi = vertexBuffer.Items;
 			Vector2[] ubi = uvBuffer.Items;
 			Vector2[] ubi = uvBuffer.Items;
@@ -1284,7 +1300,7 @@ namespace Spine.Unity {
 				mesh.SetTriangles(submeshesItems[i].Items, i, false);
 				mesh.SetTriangles(submeshesItems[i].Items, i, false);
 #endif
 #endif
 		}
 		}
-		#endregion
+#endregion
 
 
 		public void EnsureVertexCapacity (int minimumVertexCount, bool inlcudeTintBlack = false, bool includeTangents = false, bool includeNormals = false) {
 		public void EnsureVertexCapacity (int minimumVertexCount, bool inlcudeTintBlack = false, bool includeTangents = false, bool includeNormals = false) {
 			if (minimumVertexCount > vertexBuffer.Items.Length) {
 			if (minimumVertexCount > vertexBuffer.Items.Length) {
@@ -1332,7 +1348,7 @@ namespace Spine.Unity {
 			if (tangents != null) Array.Resize(ref tangents, vbiLength);
 			if (tangents != null) Array.Resize(ref tangents, vbiLength);
 		}
 		}
 
 
-		#region TangentSolver2D
+#region TangentSolver2D
 		// Thanks to contributions from forum user ToddRivers
 		// Thanks to contributions from forum user ToddRivers
 
 
 		/// <summary>Step 1 of solving tangents. Ensure you have buffers of the correct size.</summary>
 		/// <summary>Step 1 of solving tangents. Ensure you have buffers of the correct size.</summary>
@@ -1419,9 +1435,9 @@ namespace Spine.Unity {
 				tangents[i] = tangent;
 				tangents[i] = tangent;
 			}
 			}
 		}
 		}
-		#endregion
+#endregion
 
 
-		#region AttachmentRendering
+#region AttachmentRendering
 		static List<Vector3> AttachmentVerts = new List<Vector3>();
 		static List<Vector3> AttachmentVerts = new List<Vector3>();
 		static List<Vector2> AttachmentUVs = new List<Vector2>();
 		static List<Vector2> AttachmentUVs = new List<Vector2>();
 		static List<Color32> AttachmentColors32 = new List<Color32>();
 		static List<Color32> AttachmentColors32 = new List<Color32>();
@@ -1533,6 +1549,6 @@ namespace Spine.Unity {
 			AttachmentColors32.Clear();
 			AttachmentColors32.Clear();
 			AttachmentIndices.Clear();
 			AttachmentIndices.Clear();
 		}
 		}
-		#endregion
+#endregion
 	}
 	}
 }
 }

+ 3 - 2
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.
  * 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
 //#define SPINE_DEBUG
 
 
 using System;
 using System;

+ 10 - 2
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.
  * 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
 //#define SPINE_DEBUG
 
 
 // Important Note: When disabling this define, also disable the one in MeshGenerator.cs
 // Important Note: When disabling this define, also disable the one in MeshGenerator.cs
@@ -49,6 +50,11 @@ namespace Spine.Unity {
 		public bool hasActiveClipping;
 		public bool hasActiveClipping;
 		public int rawVertexCount = -1;
 		public int rawVertexCount = -1;
 		public readonly ExposedList<Attachment> attachments = new ExposedList<Attachment>();
 		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
 #endif
 
 
 		public void Clear () {
 		public void Clear () {
@@ -60,9 +66,11 @@ namespace Spine.Unity {
 			this.submeshInstructions.Clear(false);
 			this.submeshInstructions.Clear(false);
 		}
 		}
 
 
+#if SPINE_TRIANGLECHECK
 		public void Dispose () {
 		public void Dispose () {
 			attachments.Clear(true);
 			attachments.Clear(true);
 		}
 		}
+#endif
 
 
 		public void SetWithSubset (ExposedList<SubmeshInstruction> instructions, int startSubmesh, int endSubmesh) {
 		public void SetWithSubset (ExposedList<SubmeshInstruction> instructions, int startSubmesh, int endSubmesh) {
 #if SPINE_TRIANGLECHECK
 #if SPINE_TRIANGLECHECK

+ 6 - 2
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.
  * 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
 //#define SPINE_DEBUG
 
 
 using System;
 using System;
@@ -66,6 +67,9 @@ namespace Spine.Unity {
 		public int rawVertexCount;
 		public int rawVertexCount;
 		public int rawFirstVertexIndex;
 		public int rawFirstVertexIndex;
 		public bool hasClipping;
 		public bool hasClipping;
+#else
+		/// <summary>Returns constant vertex count for early-return if clauses in renderers.</summary>
+		public int rawVertexCount { get { return 1; } }
 #endif
 #endif
 		public bool hasPMAAdditiveSlot;
 		public bool hasPMAAdditiveSlot;
 
 

+ 1 - 1
spine-unity/Assets/Spine/package.json

@@ -2,7 +2,7 @@
 	"name": "com.esotericsoftware.spine.spine-unity",
 	"name": "com.esotericsoftware.spine.spine-unity",
 	"displayName": "spine-unity Runtime",
 	"displayName": "spine-unity Runtime",
 	"description": "This plugin provides the spine-unity runtime core.",
 	"description": "This plugin provides the spine-unity runtime core.",
-	"version": "4.2.84",
+	"version": "4.2.85",
 	"unity": "2018.3",
 	"unity": "2018.3",
 	"author": {
 	"author": {
 		"name": "Esoteric Software",
 		"name": "Esoteric Software",