public static NativeArray <T> Broadcast <T>(this NativeArray <T> arr, T value) where T : struct
 {
     return(arr.Broadcast(value, 0, arr.Length));
 }
                void Run()
                {
                    _finalVerts.Init();

                    var numIndices = _smoothVerts.counts[0];
                    var maxLayer   = _smoothVerts.counts[1];

                    _materials    = new NativeArray <int>(MAX_MATERIALS_PER_SUBMESH, Allocator.Temp, NativeArrayOptions.ClearMemory);
                    _matrefcounts = new NativeArray <int>(MAX_MATERIALS_PER_SUBMESH, Allocator.Temp, NativeArrayOptions.ClearMemory);

                    var emitFlags = new NativeArray <int>(numIndices / 3, Allocator.Temp, NativeArrayOptions.ClearMemory);

                    for (int layer = 0; layer <= maxLayer; ++layer)
                    {
                        int maxLayerSubmesh = -1;
                        int numEmitted      = 0;

                        _finalVerts.BeginLayer(layer);
                        emitFlags.Broadcast(0);

                        while (numEmitted < numIndices)
                        {
                            for (int maxMats = 1; maxMats <= MAX_MATERIALS_PER_SUBMESH; ++maxMats)
                            {
                                if (numEmitted >= numIndices)
                                {
                                    break;
                                }
                                var texBlend = default(TexBlend_t);

                                int numTris    = 0;
                                int firstIndex = 0;

                                // pack submesh edges textures

                                for (int k = 0; k < numIndices; k += 3)
                                {
                                    if (emitFlags[k / 3] == 0)
                                    {
                                        int packedIndex0 = _smoothVerts.indices[k];
                                        int vertNum0     = packedIndex0 & 0x00ffffff;
                                        int vertOfs0     = packedIndex0 >> 24;
                                        int bankedIndex0 = (vertNum0 * BANK_SIZE) + vertOfs0;

                                        if (_smoothVerts.layers[bankedIndex0] == layer)
                                        {
                                            int packedIndex1 = _smoothVerts.indices[k + 1];
                                            int vertNum1     = packedIndex1 & 0x00ffffff;
                                            int packedIndex2 = _smoothVerts.indices[k + 2];
                                            int vertNum2     = packedIndex2 & 0x00ffffff;

                                            var numMats = AddVertexMaterials(layer, vertNum0, vertNum1, vertNum2);
                                            if ((numMats > 0) && (numMats <= maxMats))
                                            {
                                                if (AddSubmeshMaterials(ref texBlend, numMats, maxMats))
                                                {
                                                    if (numTris == 0)
                                                    {
                                                        firstIndex = k;
                                                    }

                                                    ++numTris;
                                                }
                                            }                                             /*else {
                                                                                           * emitFlags[k/3] = 1;
                                                                                           * numEmitted = 3;
                                                                                           * }*/
                                        }
                                        else
                                        {
                                            emitFlags[k / 3] = 1;
                                            numEmitted      += 3;
                                        }
                                    }
                                }

                                if (numTris > 0)
                                {
                                    // we've packed as many triangles as we can into a TexBlend_t
                                    // write out the packed submesh.
                                    if (maxLayerSubmesh == MAX_CHUNK_SUBMESHES)
                                    {
                                        throw new Exception("MAX_CHUNK_SUBMESHES");
                                    }

                                    ++maxLayerSubmesh;
                                    int numSubmeshVerts = 0;
                                    var curBlend        = default(TexBlend_t);

                                    for (int k = firstIndex; k < numIndices; k += 3)
                                    {
                                        if (emitFlags[k / 3] == 0)
                                        {
                                            int packedIndex0 = _smoothVerts.indices[k];
                                            int vertNum0     = packedIndex0 & 0x00ffffff;
                                            int vertOfs0     = packedIndex0 >> 24;
                                            int bankedIndex0 = (vertNum0 * BANK_SIZE) + vertOfs0;

                                            int packedIndex1 = _smoothVerts.indices[k + 1];
                                            int vertNum1     = packedIndex1 & 0x00ffffff;
                                            int vertOfs1     = packedIndex1 >> 24;
                                            int bankedIndex1 = (vertNum1 * BANK_SIZE) + vertOfs1;

                                            int packedIndex2 = _smoothVerts.indices[k + 2];
                                            int vertNum2     = packedIndex2 & 0x00ffffff;
                                            int vertOfs2     = packedIndex2 >> 24;
                                            int bankedIndex2 = (vertNum2 * BANK_SIZE) + vertOfs2;

                                            var numMats = AddVertexMaterials(layer, vertNum0, vertNum1, vertNum2);
                                            if ((numMats > 0) && (numMats <= maxMats))
                                            {
                                                if (AddSubmeshMaterials(ref curBlend, numMats, maxMats))
                                                {
                                                    Vector3 p;
                                                    Vector3 n;
                                                    Color32 c;
                                                    Vector4 blendFactor;

                                                    BlendVertex(vertNum0, vertOfs0, bankedIndex0, out p, out n, out c);
                                                    blendFactor = GetTriVertTexBlendFactor(texBlend, layer, vertNum0);
                                                    _finalVerts.EmitVert(p, n, c, blendFactor);

                                                    BlendVertex(vertNum1, vertOfs1, bankedIndex1, out p, out n, out c);
                                                    blendFactor = GetTriVertTexBlendFactor(texBlend, layer, vertNum1);
                                                    _finalVerts.EmitVert(p, n, c, blendFactor);

                                                    BlendVertex(vertNum2, vertOfs2, bankedIndex2, out p, out n, out c);
                                                    blendFactor = GetTriVertTexBlendFactor(texBlend, layer, vertNum2);
                                                    _finalVerts.EmitVert(p, n, c, blendFactor);

                                                    numSubmeshVerts += 3;

                                                    emitFlags[k / 3] = 1;
                                                    numEmitted      += 3;
                                                }
                                            }
                                        }
                                    }

                                    _finalVerts.submeshTextures[(layer * MAX_CHUNK_SUBMESHES) + maxLayerSubmesh] = texBlend;
                                    _finalVerts.submeshes[(layer * MAX_CHUNK_SUBMESHES) + maxLayerSubmesh]       = numSubmeshVerts;
                                }
                            }
                        }

                        _finalVerts.FinishLayer(maxLayerSubmesh);
                    }

                    _materials.Dispose();
                    _matrefcounts.Dispose();
                    emitFlags.Dispose();
                }