From 7f5e7c3bfc570e2e7a7c41643b05a908fe52b46d Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 17 Sep 2021 20:38:55 +0200 Subject: [PATCH] [unity] Prepared MeshGenerator class for creating subclasses. --- .../Mesh Generation/MeshGenerator.cs | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) 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 8e08a108a..5348e311d 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 @@ -98,10 +98,10 @@ namespace Spine.Unity { const float BoundsMinDefault = float.PositiveInfinity; const float BoundsMaxDefault = float.NegativeInfinity; - [NonSerialized] readonly ExposedList vertexBuffer = new ExposedList(4); - [NonSerialized] readonly ExposedList uvBuffer = new ExposedList(4); - [NonSerialized] readonly ExposedList colorBuffer = new ExposedList(4); - [NonSerialized] readonly ExposedList> submeshes = new ExposedList> { new ExposedList(6) }; // start with 1 submesh. + [NonSerialized] protected readonly ExposedList vertexBuffer = new ExposedList(4); + [NonSerialized] protected readonly ExposedList uvBuffer = new ExposedList(4); + [NonSerialized] protected readonly ExposedList colorBuffer = new ExposedList(4); + [NonSerialized] protected readonly ExposedList> submeshes = new ExposedList> { new ExposedList(6) }; // start with 1 submesh. [NonSerialized] Vector2 meshBoundsMin, meshBoundsMax; [NonSerialized] float meshBoundsThickness; @@ -121,6 +121,7 @@ namespace Spine.Unity { #endregion public int VertexCount { get { return vertexBuffer.Count; } } + public int SubmeshIndexCount (int submeshIndex) { return submeshes.Items[submeshIndex].Count; } /// A set of mesh arrays whose values are modifiable by the user. Modify these values before they are passed to the UnityEngine mesh object in order to see the effect. public MeshGeneratorBuffers Buffers { @@ -1007,6 +1008,20 @@ namespace Spine.Unity { meshBoundsThickness *= scale; } + public Bounds GetMeshBounds () { + if (float.IsInfinity(meshBoundsMin.x)) { // meshBoundsMin.x == BoundsMinDefault // == doesn't work on float Infinity constants. + return new Bounds(); + } else { + //mesh.bounds = ArraysMeshGenerator.ToBounds(meshBoundsMin, meshBoundsMax); + float halfWidth = (meshBoundsMax.x - meshBoundsMin.x) * 0.5f; + float halfHeight = (meshBoundsMax.y - meshBoundsMin.y) * 0.5f; + return new Bounds { + center = new Vector3(meshBoundsMin.x + halfWidth, meshBoundsMin.y + halfHeight), + extents = new Vector3(halfWidth, halfHeight, meshBoundsThickness * 0.5f) + }; + } + } + void AddAttachmentTintBlack (float r2, float g2, float b2, float a, int vertexCount) { var rg = new Vector2(r2, g2); var bo = new Vector2(b2, a); @@ -1054,18 +1069,7 @@ namespace Spine.Unity { mesh.vertices = vbi; mesh.uv = ubi; mesh.colors32 = cbi; - - if (float.IsInfinity(meshBoundsMin.x)) { // meshBoundsMin.x == BoundsMinDefault // == doesn't work on float Infinity constants. - mesh.bounds = new Bounds(); - } else { - //mesh.bounds = ArraysMeshGenerator.ToBounds(meshBoundsMin, meshBoundsMax); - float halfWidth = (meshBoundsMax.x - meshBoundsMin.x) * 0.5f; - float halfHeight = (meshBoundsMax.y - meshBoundsMin.y) * 0.5f; - mesh.bounds = new Bounds { - center = new Vector3(meshBoundsMin.x + halfWidth, meshBoundsMin.y + halfHeight), - extents = new Vector3(halfWidth, halfHeight, meshBoundsThickness * 0.5f) - }; - } + mesh.bounds = GetMeshBounds(); } {