public void Set(Vector3[] verts, Vector2[] uvs, Color32[] colors, SubmeshedMeshInstruction instruction)
 {
     this.mesh.vertices = verts;
     this.mesh.uv       = uvs;
     this.mesh.colors32 = colors;
     this.attachmentsUsed.Clear(false);
     this.attachmentsUsed.GrowIfNeeded(instruction.attachmentList.Capacity);
     this.attachmentsUsed.Count = instruction.attachmentList.Count;
     instruction.attachmentList.CopyTo(this.attachmentsUsed.Items);
     this.instructionsUsed.Clear(false);
     this.instructionsUsed.GrowIfNeeded(instruction.submeshInstructions.Capacity);
     this.instructionsUsed.Count = instruction.submeshInstructions.Count;
     instruction.submeshInstructions.CopyTo(this.instructionsUsed.Items);
 }
            public bool StructureDoesntMatch(SubmeshedMeshInstruction instructions)
            {
                // Check count inequality.
                if (instructions.attachmentList.Count != this.attachmentsUsed.Count)
                {
                    return(true);
                }
                if (instructions.submeshInstructions.Count != this.instructionsUsed.Count)
                {
                    return(true);
                }

                // Check each attachment.
                var attachmentsPassed = instructions.attachmentList.Items;
                var myAttachments     = this.attachmentsUsed.Items;

                for (int i = 0, n = attachmentsUsed.Count; i < n; i++)
                {
                    if (attachmentsPassed[i] != myAttachments[i])
                    {
                        return(true);
                    }
                }

                // Check each submesh for equal arrangement.
                var instructionListItems = instructions.submeshInstructions.Items;
                var myInstructions       = this.instructionsUsed.Items;

                for (int i = 0, n = this.instructionsUsed.Count; i < n; i++)
                {
                    var lhs = instructionListItems[i];
                    var rhs = myInstructions[i];
                    if (
                        lhs.material.GetInstanceID() != rhs.material.GetInstanceID() ||
                        lhs.startSlot != rhs.startSlot ||
                        lhs.endSlot != rhs.endSlot ||
                        lhs.triangleCount != rhs.triangleCount ||
                        lhs.vertexCount != rhs.vertexCount ||
                        lhs.firstVertexIndex != rhs.firstVertexIndex
                        )
                    {
                        return(true);
                    }
                }

                //Debug.Log("structure matched");
                return(false);
            }
            public bool StructureDoesntMatch(SubmeshedMeshInstruction instructions)
            {
                if (instructions.attachmentList.Count != this.attachmentsUsed.Count)
                {
                    return(true);
                }
                if (instructions.submeshInstructions.Count != this.instructionsUsed.Count)
                {
                    return(true);
                }
                Attachment[] items  = instructions.attachmentList.Items;
                Attachment[] items2 = this.attachmentsUsed.Items;
                int          i      = 0;
                int          count  = this.attachmentsUsed.Count;

                while (i < count)
                {
                    if (items[i] != items2[i])
                    {
                        return(true);
                    }
                    i++;
                }
                SubmeshInstruction[] items3 = instructions.submeshInstructions.Items;
                SubmeshInstruction[] items4 = this.instructionsUsed.Items;
                int j      = 0;
                int count2 = this.instructionsUsed.Count;

                while (j < count2)
                {
                    SubmeshInstruction submeshInstruction  = items3[j];
                    SubmeshInstruction submeshInstruction2 = items4[j];
                    if (submeshInstruction.material.GetInstanceID() != submeshInstruction2.material.GetInstanceID() || submeshInstruction.startSlot != submeshInstruction2.startSlot || submeshInstruction.endSlot != submeshInstruction2.endSlot || submeshInstruction.triangleCount != submeshInstruction2.triangleCount || submeshInstruction.vertexCount != submeshInstruction2.vertexCount || submeshInstruction.firstVertexIndex != submeshInstruction2.firstVertexIndex)
                    {
                        return(true);
                    }
                    j++;
                }
                return(false);
            }
        // ISubmeshedMeshGenerator.GenerateMesh
        /// <summary>Generates a mesh based on SubmeshedMeshInstructions</summary>
        public MeshAndMaterials GenerateMesh(SubmeshedMeshInstruction meshInstructions)
        {
            var smartMesh       = doubleBufferedSmartMesh.GetNext();
            var mesh            = smartMesh.mesh;
            int submeshCount    = meshInstructions.submeshInstructions.Count;
            var instructionList = meshInstructions.submeshInstructions;

            // STEP 1: Ensure correct buffer sizes.
            int  vertexCount           = meshInstructions.vertexCount;
            bool submeshBuffersResized = ArraysMeshGenerator.EnsureTriangleBuffersSize(submeshBuffers, submeshCount, instructionList.Items);
            bool vertBufferResized     = ArraysMeshGenerator.EnsureSize(vertexCount, ref this.meshVertices, ref this.meshUVs, ref this.meshColors32);

            Vector3[] vertices = this.meshVertices;

            // STEP 2: Update buffers based on Skeleton.
            float   zSpacing = this.ZSpacing;
            Vector3 meshBoundsMin;
            Vector3 meshBoundsMax;
            int     attachmentCount = meshInstructions.attachmentList.Count;

            if (attachmentCount <= 0)
            {
                meshBoundsMin = new Vector3(0, 0, 0);
                meshBoundsMax = new Vector3(0, 0, 0);
            }
            else
            {
                meshBoundsMin.x = int.MaxValue;
                meshBoundsMin.y = int.MaxValue;
                meshBoundsMax.x = int.MinValue;
                meshBoundsMax.y = int.MinValue;

                if (zSpacing > 0f)
                {
                    meshBoundsMin.z = 0f;
                    meshBoundsMax.z = zSpacing * (attachmentCount - 1);
                }
                else
                {
                    meshBoundsMin.z = zSpacing * (attachmentCount - 1);
                    meshBoundsMax.z = 0f;
                }
            }
            bool structureDoesntMatch = vertBufferResized || submeshBuffersResized || smartMesh.StructureDoesntMatch(meshInstructions);
            // For each submesh, add vertex data From attachments. Also triangles, but only if needed.
            int vertexIndex = 0;             // modified by FillVerts

            for (int submeshIndex = 0; submeshIndex < submeshCount; submeshIndex++)
            {
                var submeshInstruction = instructionList.Items[submeshIndex];
                int start    = submeshInstruction.startSlot;
                int end      = submeshInstruction.endSlot;
                var skeleton = submeshInstruction.skeleton;
                ArraysMeshGenerator.FillVerts(skeleton, start, end, zSpacing, this.PremultiplyVertexColors, vertices, this.meshUVs, this.meshColors32, ref vertexIndex, ref this.attachmentVertexBuffer, ref meshBoundsMin, ref meshBoundsMax);
                if (structureDoesntMatch)
                {
                    var  currentBuffer = submeshBuffers.Items[submeshIndex];
                    bool isLastSubmesh = (submeshIndex == submeshCount - 1);
                    ArraysMeshGenerator.FillTriangles(ref currentBuffer.triangles, skeleton, submeshInstruction.triangleCount, submeshInstruction.firstVertexIndex, start, end, isLastSubmesh);
                    currentBuffer.triangleCount = submeshInstruction.triangleCount;
                    currentBuffer.firstVertex   = submeshInstruction.firstVertexIndex;
                }
            }

            if (structureDoesntMatch)
            {
                mesh.Clear();
                this.sharedMaterials = meshInstructions.GetUpdatedMaterialArray(this.sharedMaterials);
            }

            // STEP 3: Assign the buffers into the Mesh.
            smartMesh.Set(this.meshVertices, this.meshUVs, this.meshColors32, meshInstructions);
            mesh.bounds = ArraysMeshGenerator.ToBounds(meshBoundsMin, meshBoundsMax);

            if (structureDoesntMatch)
            {
                // Push new triangles if doesn't match.
                mesh.subMeshCount = submeshCount;
                for (int i = 0; i < submeshCount; i++)
                {
                    mesh.SetTriangles(submeshBuffers.Items[i].triangles, i);
                }

                TryAddNormalsTo(mesh, vertexCount);
            }

            if (addTangents)
            {
                SolveTangents2DEnsureSize(ref this.meshTangents, ref this.tempTanBuffer, vertexCount);
                for (int i = 0, n = submeshCount; i < n; i++)
                {
                    var submesh = submeshBuffers.Items[i];
                    SolveTangents2DTriangles(this.tempTanBuffer, submesh.triangles, submesh.triangleCount, meshVertices, meshUVs, vertexCount);
                }
                SolveTangents2DBuffer(this.meshTangents, this.tempTanBuffer, vertexCount);
            }

            return(new MeshAndMaterials(smartMesh.mesh, sharedMaterials));
        }
            public bool StructureDoesntMatch(SubmeshedMeshInstruction instructions)
            {
                // Check count inequality.
                if (instructions.attachmentList.Count != this.attachmentsUsed.Count) return true;
                if (instructions.submeshInstructions.Count != this.instructionsUsed.Count) return true;

                // Check each attachment.
                var attachmentsPassed = instructions.attachmentList.Items;
                var myAttachments = this.attachmentsUsed.Items;
                for (int i = 0, n = attachmentsUsed.Count; i < n; i++)
                    if (attachmentsPassed[i] != myAttachments[i]) return true;

                // Check each submesh for equal arrangement.
                var instructionListItems = instructions.submeshInstructions.Items;
                var myInstructions = this.instructionsUsed.Items;
                for (int i = 0, n = this.instructionsUsed.Count; i < n; i++) {
                    var lhs = instructionListItems[i];
                    var rhs = myInstructions[i];
                    if (
                        lhs.material.GetInstanceID() != rhs.material.GetInstanceID() ||
                        lhs.startSlot != rhs.startSlot ||
                        lhs.endSlot != rhs.endSlot ||
                        lhs.triangleCount != rhs.triangleCount ||
                        lhs.vertexCount != rhs.vertexCount ||
                        lhs.firstVertexIndex != rhs.firstVertexIndex
                    ) return true;
                }

                //Debug.Log("structure matched");
                return false;
            }
            public void Set(Vector3[] verts, Vector2[] uvs, Color32[] colors, SubmeshedMeshInstruction instruction)
            {
                mesh.vertices = verts;
                mesh.uv = uvs;
                mesh.colors32 = colors;

                attachmentsUsed.Clear(false);
                attachmentsUsed.GrowIfNeeded(instruction.attachmentList.Capacity);
                attachmentsUsed.Count = instruction.attachmentList.Count;
                instruction.attachmentList.CopyTo(attachmentsUsed.Items);

                instructionsUsed.Clear(false);
                instructionsUsed.GrowIfNeeded(instruction.submeshInstructions.Capacity);
                instructionsUsed.Count = instruction.submeshInstructions.Count;
                instruction.submeshInstructions.CopyTo(instructionsUsed.Items);
            }
        // ISubmeshedMeshGenerator.GenerateMesh
        /// <summary>Generates a mesh based on SubmeshedMeshInstructions</summary>
        public MeshAndMaterials GenerateMesh(SubmeshedMeshInstruction meshInstructions)
        {
            var smartMesh = doubleBufferedSmartMesh.GetNext();
            var mesh = smartMesh.mesh;
            int submeshCount = meshInstructions.submeshInstructions.Count;
            var instructionList = meshInstructions.submeshInstructions;

            // STEP 1: Ensure correct buffer sizes.
            bool submeshBuffersResized = ArraysMeshGenerator.EnsureTriangleBuffersSize(submeshBuffers, submeshCount, instructionList.Items);
            bool vertBufferResized = ArraysMeshGenerator.EnsureSize(meshInstructions.vertexCount, ref this.meshVertices, ref this.meshUVs, ref this.meshColors32);
            Vector3[] vertices = this.meshVertices;

            // STEP 2: Update buffers based on Skeleton.
            float zSpacing = this.zSpacing;
            Vector3 meshBoundsMin;
            Vector3 meshBoundsMax;
            int attachmentCount = meshInstructions.attachmentList.Count;
            if (attachmentCount <= 0) {
                meshBoundsMin = new Vector3(0, 0, 0);
                meshBoundsMax = new Vector3(0, 0, 0);
            } else {
                meshBoundsMin.x = int.MaxValue;
                meshBoundsMin.y = int.MaxValue;
                meshBoundsMax.x = int.MinValue;
                meshBoundsMax.y = int.MinValue;

                if (zSpacing > 0f) {
                    meshBoundsMin.z = 0f;
                    meshBoundsMax.z = zSpacing * (attachmentCount - 1);
                } else {
                    meshBoundsMin.z = zSpacing * (attachmentCount - 1);
                    meshBoundsMax.z = 0f;
                }
            }
            bool structureDoesntMatch = vertBufferResized || submeshBuffersResized || smartMesh.StructureDoesntMatch(meshInstructions);
            // For each submesh, add vertex data from attachments. Also triangles, but only if needed.
            int vertexIndex = 0; // modified by FillVerts
            for (int submeshIndex = 0; submeshIndex < submeshCount; submeshIndex++) {
                var submeshInstruction = instructionList.Items[submeshIndex];
                int start = submeshInstruction.startSlot;
                int end = submeshInstruction.endSlot;
                var skeleton = submeshInstruction.skeleton;
                ArraysMeshGenerator.FillVerts(skeleton, start, end, zSpacing, this.premultiplyVertexColors, vertices, this.meshUVs, this.meshColors32, ref vertexIndex, ref this.attachmentVertexBuffer, ref meshBoundsMin, ref meshBoundsMax);
                if (structureDoesntMatch) {
                    var currentBuffer = submeshBuffers.Items[submeshIndex];
                    bool isLastSubmesh = (submeshIndex == submeshCount - 1);
                    ArraysMeshGenerator.FillTriangles(skeleton, submeshInstruction.triangleCount, submeshInstruction.firstVertexIndex, start, end, ref currentBuffer.triangles, isLastSubmesh);
                }
            }

            if (structureDoesntMatch) {
                mesh.Clear();
                this.sharedMaterials = meshInstructions.GetUpdatedMaterialArray(this.sharedMaterials);
            }

            // STEP 3: Assign the buffers into the Mesh.
            smartMesh.Set(this.meshVertices, this.meshUVs, this.meshColors32, meshInstructions);
            mesh.bounds = ArraysMeshGenerator.ToBounds(meshBoundsMin, meshBoundsMax);

            if (structureDoesntMatch) {
                // Push new triangles if doesn't match.
                mesh.subMeshCount = submeshCount;
                for (int i = 0; i < submeshCount; i++)
                    mesh.SetTriangles(submeshBuffers.Items[i].triangles, i);

                #if SPINE_OPTIONAL_NORMALS
                if (generateNormals) {
                    int vertexCount = meshInstructions.vertexCount;
                    Vector3[] normals = new Vector3[vertexCount];
                    Vector3 normal = new Vector3(0, 0, -1);
                    for (int i = 0; i < vertexCount; i++)
                        normals[i] = normal;
                    mesh.normals = normals;

                    if (generateTangents) {
                        Vector4[] tangents = new Vector4[vertexCount];
                        Vector4 tangent = new Vector4(1, 0, 0, -1);
                        for (int i = 0; i < vertexCount; i++)
                            tangents[i] = tangent;
                        mesh.tangents = tangents;
                    }
                }
                #endif
            }

            return new MeshAndMaterials(smartMesh.mesh, sharedMaterials);
        }
        public MeshAndMaterials GenerateMesh(SubmeshedMeshInstruction meshInstructions)
        {
            SmartMesh next  = this.doubleBufferedSmartMesh.GetNext();
            Mesh      mesh  = next.mesh;
            int       count = meshInstructions.submeshInstructions.Count;
            ExposedList <SubmeshInstruction> submeshInstructions = meshInstructions.submeshInstructions;
            int  vertexCount = meshInstructions.vertexCount;
            bool flag        = ArraysMeshGenerator.EnsureTriangleBuffersSize(this.submeshBuffers, count, submeshInstructions.Items);
            bool flag2       = ArraysMeshGenerator.EnsureSize(vertexCount, ref this.meshVertices, ref this.meshUVs, ref this.meshColors32);

            Vector3[] meshVertices = this.meshVertices;
            float     zspacing     = this.ZSpacing;
            int       count2       = meshInstructions.attachmentList.Count;
            Vector3   boundsMin;
            Vector3   boundsMax;

            if (count2 <= 0)
            {
                boundsMin = new Vector3(0f, 0f, 0f);
                boundsMax = new Vector3(0f, 0f, 0f);
            }
            else
            {
                boundsMin.x = 2.14748365E+09f;
                boundsMin.y = 2.14748365E+09f;
                boundsMax.x = -2.14748365E+09f;
                boundsMax.y = -2.14748365E+09f;
                if (zspacing > 0f)
                {
                    boundsMin.z = 0f;
                    boundsMax.z = zspacing * (float)(count2 - 1);
                }
                else
                {
                    boundsMin.z = zspacing * (float)(count2 - 1);
                    boundsMax.z = 0f;
                }
            }
            bool flag3 = flag2 || flag || next.StructureDoesntMatch(meshInstructions);
            int  num   = 0;

            for (int i = 0; i < count; i++)
            {
                SubmeshInstruction submeshInstruction = submeshInstructions.Items[i];
                int      startSlot = submeshInstruction.startSlot;
                int      endSlot   = submeshInstruction.endSlot;
                Skeleton skeleton  = submeshInstruction.skeleton;
                ArraysMeshGenerator.FillVerts(skeleton, startSlot, endSlot, zspacing, base.PremultiplyVertexColors, meshVertices, this.meshUVs, this.meshColors32, ref num, ref this.attachmentVertexBuffer, ref boundsMin, ref boundsMax, true);
                if (flag3)
                {
                    SubmeshTriangleBuffer submeshTriangleBuffer = this.submeshBuffers.Items[i];
                    bool isLastSubmesh = i == count - 1;
                    ArraysMeshGenerator.FillTriangles(ref submeshTriangleBuffer.triangles, skeleton, submeshInstruction.triangleCount, submeshInstruction.firstVertexIndex, startSlot, endSlot, isLastSubmesh);
                    submeshTriangleBuffer.triangleCount = submeshInstruction.triangleCount;
                    submeshTriangleBuffer.firstVertex   = submeshInstruction.firstVertexIndex;
                }
            }
            if (flag3)
            {
                mesh.Clear();
                this.sharedMaterials = meshInstructions.GetUpdatedMaterialArray(this.sharedMaterials);
            }
            next.Set(this.meshVertices, this.meshUVs, this.meshColors32, meshInstructions);
            mesh.bounds = ArraysMeshGenerator.ToBounds(boundsMin, boundsMax);
            if (flag3)
            {
                mesh.subMeshCount = count;
                for (int j = 0; j < count; j++)
                {
                    mesh.SetTriangles(this.submeshBuffers.Items[j].triangles, j);
                }
                base.TryAddNormalsTo(mesh, vertexCount);
            }
            if (this.addTangents)
            {
                ArraysMeshGenerator.SolveTangents2DEnsureSize(ref this.meshTangents, ref this.tempTanBuffer, vertexCount);
                int k    = 0;
                int num2 = count;
                while (k < num2)
                {
                    SubmeshTriangleBuffer submeshTriangleBuffer2 = this.submeshBuffers.Items[k];
                    ArraysMeshGenerator.SolveTangents2DTriangles(this.tempTanBuffer, submeshTriangleBuffer2.triangles, submeshTriangleBuffer2.triangleCount, this.meshVertices, this.meshUVs, vertexCount);
                    k++;
                }
                ArraysMeshGenerator.SolveTangents2DBuffer(this.meshTangents, this.tempTanBuffer, vertexCount);
            }
            return(new MeshAndMaterials(next.mesh, this.sharedMaterials));
        }