SolveTangents2DTriangles() public static method

Step 2 of solving tangents. Fills (part of) a temporary tangent-solution buffer based on the vertices and uvs defined by a submesh's triangle buffer. Only needs to be called once for single-submesh meshes.
public static SolveTangents2DTriangles ( Vector2 tempTanBuffer, int triangles, int triangleCount, Vector3 vertices, Vector2 uvs, int vertexCount ) : void
tempTanBuffer UnityEngine.Vector2 A temporary Vector3[] for calculating tangents.
triangles int The mesh's current triangles buffer.
triangleCount int The number of triangle indexes in the triangle array to be used.
vertices UnityEngine.Vector3 The mesh's current vertex position buffer.
uvs UnityEngine.Vector2 The mesh's current uvs buffer.
vertexCount int Number of vertices that require tangents (or the size of the vertex array)
return void
        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));
        }
        public MeshAndMaterials GenerateMesh(ExposedList <SubmeshInstruction> instructions, int startSubmesh, int endSubmesh)
        {
            SubmeshInstruction[] items = instructions.Items;
            this.currentInstructions.Clear(false);
            for (int i = startSubmesh; i < endSubmesh; i++)
            {
                this.currentInstructions.Add(items[i]);
            }
            SmartMesh next  = this.doubleBufferedSmartMesh.GetNext();
            Mesh      mesh  = next.mesh;
            int       count = this.currentInstructions.Count;

            SubmeshInstruction[] items2 = this.currentInstructions.Items;
            int num = 0;

            for (int j = 0; j < count; j++)
            {
                items2[j].firstVertexIndex = num;
                num += items2[j].vertexCount;
            }
            bool    flag     = ArraysMeshGenerator.EnsureSize(num, ref this.meshVertices, ref this.meshUVs, ref this.meshColors32);
            bool    flag2    = ArraysMeshGenerator.EnsureTriangleBuffersSize(this.submeshBuffers, count, items2);
            float   zspacing = this.ZSpacing;
            Vector3 boundsMin;
            Vector3 boundsMax;

            if (num <= 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;
                int endSlot = items2[count - 1].endSlot;
                if (zspacing > 0f)
                {
                    boundsMin.z = 0f;
                    boundsMax.z = zspacing * (float)endSlot;
                }
                else
                {
                    boundsMin.z = zspacing * (float)endSlot;
                    boundsMax.z = 0f;
                }
            }
            ExposedList <Attachment> exposedList = this.attachmentBuffer;

            exposedList.Clear(false);
            int num2 = 0;

            for (int k = 0; k < count; k++)
            {
                SubmeshInstruction submeshInstruction = items2[k];
                int      startSlot = submeshInstruction.startSlot;
                int      endSlot2  = submeshInstruction.endSlot;
                Skeleton skeleton  = submeshInstruction.skeleton;
                Slot[]   items3    = skeleton.DrawOrder.Items;
                for (int l = startSlot; l < endSlot2; l++)
                {
                    Attachment attachment = items3[l].attachment;
                    if (attachment != null)
                    {
                        exposedList.Add(attachment);
                    }
                }
                ArraysMeshGenerator.FillVerts(skeleton, startSlot, endSlot2, zspacing, base.PremultiplyVertexColors, this.meshVertices, this.meshUVs, this.meshColors32, ref num2, ref this.attachmentVertexBuffer, ref boundsMin, ref boundsMax, true);
            }
            bool flag3 = flag || flag2 || next.StructureDoesntMatch(exposedList, this.currentInstructions);

            for (int m = 0; m < count; m++)
            {
                SubmeshInstruction submeshInstruction2 = items2[m];
                if (flag3)
                {
                    SubmeshTriangleBuffer submeshTriangleBuffer = this.submeshBuffers.Items[m];
                    bool isLastSubmesh = m == count - 1;
                    ArraysMeshGenerator.FillTriangles(ref submeshTriangleBuffer.triangles, submeshInstruction2.skeleton, submeshInstruction2.triangleCount, submeshInstruction2.firstVertexIndex, submeshInstruction2.startSlot, submeshInstruction2.endSlot, isLastSubmesh);
                    submeshTriangleBuffer.triangleCount = submeshInstruction2.triangleCount;
                    submeshTriangleBuffer.firstVertex   = submeshInstruction2.firstVertexIndex;
                }
            }
            if (flag3)
            {
                mesh.Clear();
                this.sharedMaterials = this.currentInstructions.GetUpdatedMaterialArray(this.sharedMaterials);
            }
            next.Set(this.meshVertices, this.meshUVs, this.meshColors32, exposedList, this.currentInstructions);
            mesh.bounds = ArraysMeshGenerator.ToBounds(boundsMin, boundsMax);
            if (flag3)
            {
                mesh.subMeshCount = count;
                for (int n = 0; n < count; n++)
                {
                    mesh.SetTriangles(this.submeshBuffers.Items[n].triangles, n);
                }
                base.TryAddNormalsTo(mesh, num);
            }
            if (this.addTangents)
            {
                ArraysMeshGenerator.SolveTangents2DEnsureSize(ref this.meshTangents, ref this.tempTanBuffer, num);
                int num3 = 0;
                int num4 = count;
                while (num3 < num4)
                {
                    SubmeshTriangleBuffer submeshTriangleBuffer2 = this.submeshBuffers.Items[num3];
                    ArraysMeshGenerator.SolveTangents2DTriangles(this.tempTanBuffer, submeshTriangleBuffer2.triangles, submeshTriangleBuffer2.triangleCount, this.meshVertices, this.meshUVs, num);
                    num3++;
                }
                ArraysMeshGenerator.SolveTangents2DBuffer(this.meshTangents, this.tempTanBuffer, num);
            }
            return(new MeshAndMaterials(next.mesh, this.sharedMaterials));
        }
        public Mesh GenerateMesh(Skeleton skeleton)
        {
            int num  = 0;
            int num2 = 0;

            Slot[] items = skeleton.drawOrder.Items;
            int    count = skeleton.drawOrder.Count;
            int    i     = 0;

            while (i < count)
            {
                Slot             slot             = items[i];
                Attachment       attachment       = slot.attachment;
                RegionAttachment regionAttachment = attachment as RegionAttachment;
                int num3;
                int num4;
                if (regionAttachment != null)
                {
                    num3 = 4;
                    num4 = 6;
                    goto IL_7E;
                }
                MeshAttachment meshAttachment = attachment as MeshAttachment;
                if (meshAttachment != null)
                {
                    num3 = meshAttachment.worldVerticesLength >> 1;
                    num4 = meshAttachment.triangles.Length;
                    goto IL_7E;
                }
IL_88:
                i++;
                continue;
IL_7E:
                num2 += num4;
                num  += num3;
                goto IL_88;
            }
            ArraysMeshGenerator.EnsureSize(num, ref this.meshVertices, ref this.meshUVs, ref this.meshColors32);
            this.triangles = (this.triangles ?? new int[num2]);
            Vector3 boundsMin;
            Vector3 boundsMax;

            if (num == 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;
                boundsMin.z = -0.01f * this.scale;
                boundsMax.z = 0.01f * this.scale;
                int num5 = 0;
                ArraysMeshGenerator.FillVerts(skeleton, 0, count, this.ZSpacing, base.PremultiplyVertexColors, this.meshVertices, this.meshUVs, this.meshColors32, ref num5, ref this.attachmentVertexBuffer, ref boundsMin, ref boundsMax, true);
                boundsMax.x *= this.scale;
                boundsMax.y *= this.scale;
                boundsMin.x *= this.scale;
                boundsMax.y *= this.scale;
                Vector3[] meshVertices = this.meshVertices;
                for (int j = 0; j < num; j++)
                {
                    Vector3 vector = meshVertices[j];
                    vector.x       *= this.scale;
                    vector.y       *= this.scale;
                    meshVertices[j] = vector;
                }
            }
            ArraysMeshGenerator.FillTriangles(ref this.triangles, skeleton, num2, 0, 0, count, true);
            Mesh nextMesh = this.doubleBufferedMesh.GetNextMesh();

            nextMesh.vertices  = this.meshVertices;
            nextMesh.colors32  = this.meshColors32;
            nextMesh.uv        = this.meshUVs;
            nextMesh.bounds    = ArraysMeshGenerator.ToBounds(boundsMin, boundsMax);
            nextMesh.triangles = this.triangles;
            base.TryAddNormalsTo(nextMesh, num);
            if (this.addTangents)
            {
                ArraysMeshGenerator.SolveTangents2DEnsureSize(ref this.meshTangents, ref this.tempTanBuffer, num);
                ArraysMeshGenerator.SolveTangents2DTriangles(this.tempTanBuffer, this.triangles, num2, this.meshVertices, this.meshUVs, num);
                ArraysMeshGenerator.SolveTangents2DBuffer(this.meshTangents, this.tempTanBuffer, num);
            }
            this.lastGeneratedMesh = nextMesh;
            return(nextMesh);
        }