Esempio n. 1
0
    public static Mesh Combine(MeshCombineUtility.MeshInstance[] combines, bool generateStrips)
    {
        int num    = 0;
        int length = 0;
        int num1   = 0;

        MeshCombineUtility.MeshInstance[] meshInstanceArray = combines;
        for (int i = 0; i < (int)meshInstanceArray.Length; i++)
        {
            MeshCombineUtility.MeshInstance meshInstance = meshInstanceArray[i];
            if (meshInstance.mesh)
            {
                num = num + meshInstance.mesh.vertexCount;
                if (generateStrips)
                {
                    int length1 = (int)meshInstance.mesh.GetTriangleStrip(meshInstance.subMeshIndex).Length;
                    if (length1 == 0)
                    {
                        generateStrips = false;
                    }
                    else
                    {
                        if (num1 != 0)
                        {
                            num1 = ((num1 & 1) != 1 ? num1 + 2 : num1 + 3);
                        }
                        num1 = num1 + length1;
                    }
                }
            }
        }
        if (!generateStrips)
        {
            MeshCombineUtility.MeshInstance[] meshInstanceArray1 = combines;
            for (int j = 0; j < (int)meshInstanceArray1.Length; j++)
            {
                MeshCombineUtility.MeshInstance meshInstance1 = meshInstanceArray1[j];
                if (meshInstance1.mesh)
                {
                    length = length + (int)meshInstance1.mesh.GetTriangles(meshInstance1.subMeshIndex).Length;
                }
            }
        }
        Vector3[] vector3Array  = new Vector3[num];
        Vector3[] vector3Array1 = new Vector3[num];
        Vector4[] vector4Array  = new Vector4[num];
        Vector2[] vector2Array  = new Vector2[num];
        Vector2[] vector2Array1 = new Vector2[num];
        Color[]   colorArray    = new Color[num];
        int[]     numArray      = new int[length];
        int[]     numArray1     = new int[num1];
        int       num2          = 0;

        MeshCombineUtility.MeshInstance[] meshInstanceArray2 = combines;
        for (int k = 0; k < (int)meshInstanceArray2.Length; k++)
        {
            MeshCombineUtility.MeshInstance meshInstance2 = meshInstanceArray2[k];
            if (meshInstance2.mesh)
            {
                MeshCombineUtility.Copy(meshInstance2.mesh.vertexCount, meshInstance2.mesh.vertices, vector3Array, ref num2, meshInstance2.transform);
            }
        }
        num2 = 0;
        MeshCombineUtility.MeshInstance[] meshInstanceArray3 = combines;
        for (int l = 0; l < (int)meshInstanceArray3.Length; l++)
        {
            MeshCombineUtility.MeshInstance meshInstance3 = meshInstanceArray3[l];
            if (meshInstance3.mesh)
            {
                Matrix4x4 matrix4x4 = meshInstance3.transform.inverse.transpose;
                MeshCombineUtility.CopyNormal(meshInstance3.mesh.vertexCount, meshInstance3.mesh.normals, vector3Array1, ref num2, matrix4x4);
            }
        }
        num2 = 0;
        MeshCombineUtility.MeshInstance[] meshInstanceArray4 = combines;
        for (int m = 0; m < (int)meshInstanceArray4.Length; m++)
        {
            MeshCombineUtility.MeshInstance meshInstance4 = meshInstanceArray4[m];
            if (meshInstance4.mesh)
            {
                Matrix4x4 matrix4x41 = meshInstance4.transform.inverse.transpose;
                MeshCombineUtility.CopyTangents(meshInstance4.mesh.vertexCount, meshInstance4.mesh.tangents, vector4Array, ref num2, matrix4x41);
            }
        }
        num2 = 0;
        MeshCombineUtility.MeshInstance[] meshInstanceArray5 = combines;
        for (int n = 0; n < (int)meshInstanceArray5.Length; n++)
        {
            MeshCombineUtility.MeshInstance meshInstance5 = meshInstanceArray5[n];
            if (meshInstance5.mesh)
            {
                MeshCombineUtility.Copy(meshInstance5.mesh.vertexCount, meshInstance5.mesh.uv, vector2Array, ref num2);
            }
        }
        num2 = 0;
        MeshCombineUtility.MeshInstance[] meshInstanceArray6 = combines;
        for (int o = 0; o < (int)meshInstanceArray6.Length; o++)
        {
            MeshCombineUtility.MeshInstance meshInstance6 = meshInstanceArray6[o];
            if (meshInstance6.mesh)
            {
                MeshCombineUtility.Copy(meshInstance6.mesh.vertexCount, meshInstance6.mesh.uv1, vector2Array1, ref num2);
            }
        }
        num2 = 0;
        MeshCombineUtility.MeshInstance[] meshInstanceArray7 = combines;
        for (int p = 0; p < (int)meshInstanceArray7.Length; p++)
        {
            MeshCombineUtility.MeshInstance meshInstance7 = meshInstanceArray7[p];
            if (meshInstance7.mesh)
            {
                MeshCombineUtility.CopyColors(meshInstance7.mesh.vertexCount, meshInstance7.mesh.colors, colorArray, ref num2);
            }
        }
        int length2 = 0;
        int length3 = 0;
        int num3    = 0;

        MeshCombineUtility.MeshInstance[] meshInstanceArray8 = combines;
        for (int q = 0; q < (int)meshInstanceArray8.Length; q++)
        {
            MeshCombineUtility.MeshInstance meshInstance8 = meshInstanceArray8[q];
            if (meshInstance8.mesh)
            {
                if (!generateStrips)
                {
                    int[] triangles = meshInstance8.mesh.GetTriangles(meshInstance8.subMeshIndex);
                    for (int r = 0; r < (int)triangles.Length; r++)
                    {
                        numArray[r + length2] = triangles[r] + num3;
                    }
                    length2 = length2 + (int)triangles.Length;
                }
                else
                {
                    int[] triangleStrip = meshInstance8.mesh.GetTriangleStrip(meshInstance8.subMeshIndex);
                    if (length3 != 0)
                    {
                        if ((length3 & 1) != 1)
                        {
                            numArray1[length3]     = numArray1[length3 - 1];
                            numArray1[length3 + 1] = triangleStrip[0] + num3;
                            length3 = length3 + 2;
                        }
                        else
                        {
                            numArray1[length3]     = numArray1[length3 - 1];
                            numArray1[length3 + 1] = triangleStrip[0] + num3;
                            numArray1[length3 + 2] = triangleStrip[0] + num3;
                            length3 = length3 + 3;
                        }
                    }
                    for (int s = 0; s < (int)triangleStrip.Length; s++)
                    {
                        numArray1[s + length3] = triangleStrip[s] + num3;
                    }
                    length3 = length3 + (int)triangleStrip.Length;
                }
                num3 = num3 + meshInstance8.mesh.vertexCount;
            }
        }
        Mesh mesh = new Mesh()
        {
            name     = "Combined Mesh",
            vertices = vector3Array,
            normals  = vector3Array1,
            colors   = colorArray,
            uv       = vector2Array,
            uv1      = vector2Array1,
            tangents = vector4Array
        };

        if (!generateStrips)
        {
            mesh.triangles = numArray;
        }
        else
        {
            mesh.SetTriangleStrip(numArray1, 0);
        }
        return(mesh);
    }
Esempio n. 2
0
    public static Mesh Combine(MeshCombineUtility.MeshInstance[] combines, bool generateStrips)
    {
        int num  = 0;
        int num2 = 0;
        int num3 = 0;

        foreach (MeshCombineUtility.MeshInstance meshInstance in combines)
        {
            if (meshInstance.mesh)
            {
                num += meshInstance.mesh.vertexCount;
                if (generateStrips)
                {
                    int num4 = meshInstance.mesh.GetTriangles(meshInstance.subMeshIndex).Length;
                    if (num4 != 0)
                    {
                        if (num3 != 0)
                        {
                            if ((num3 & 1) == 1)
                            {
                                num3 += 3;
                            }
                            else
                            {
                                num3 += 2;
                            }
                        }
                        num3 += num4;
                    }
                    else
                    {
                        generateStrips = false;
                    }
                }
            }
        }
        if (!generateStrips)
        {
            foreach (MeshCombineUtility.MeshInstance meshInstance2 in combines)
            {
                if (meshInstance2.mesh)
                {
                    num2 += meshInstance2.mesh.GetTriangles(meshInstance2.subMeshIndex).Length;
                }
            }
        }
        Vector3[] array  = new Vector3[num];
        Vector3[] array2 = new Vector3[num];
        Vector4[] array3 = new Vector4[num];
        Vector2[] array4 = new Vector2[num];
        Vector2[] array5 = new Vector2[num];
        Color[]   array6 = new Color[num];
        int[]     array7 = new int[num2];
        int[]     array8 = new int[num3];
        int       num5   = 0;

        foreach (MeshCombineUtility.MeshInstance meshInstance3 in combines)
        {
            if (meshInstance3.mesh)
            {
                MeshCombineUtility.Copy(meshInstance3.mesh.vertexCount, meshInstance3.mesh.vertices, array, ref num5, meshInstance3.transform);
            }
        }
        num5 = 0;
        foreach (MeshCombineUtility.MeshInstance meshInstance4 in combines)
        {
            if (meshInstance4.mesh)
            {
                Matrix4x4 transform = meshInstance4.transform;
                transform = transform.inverse.transpose;
                MeshCombineUtility.CopyNormal(meshInstance4.mesh.vertexCount, meshInstance4.mesh.normals, array2, ref num5, transform);
            }
        }
        num5 = 0;
        foreach (MeshCombineUtility.MeshInstance meshInstance5 in combines)
        {
            if (meshInstance5.mesh)
            {
                Matrix4x4 transform2 = meshInstance5.transform;
                transform2 = transform2.inverse.transpose;
                MeshCombineUtility.CopyTangents(meshInstance5.mesh.vertexCount, meshInstance5.mesh.tangents, array3, ref num5, transform2);
            }
        }
        num5 = 0;
        foreach (MeshCombineUtility.MeshInstance meshInstance6 in combines)
        {
            if (meshInstance6.mesh)
            {
                MeshCombineUtility.Copy(meshInstance6.mesh.vertexCount, meshInstance6.mesh.uv, array4, ref num5);
            }
        }
        num5 = 0;
        foreach (MeshCombineUtility.MeshInstance meshInstance7 in combines)
        {
            if (meshInstance7.mesh)
            {
                MeshCombineUtility.Copy(meshInstance7.mesh.vertexCount, meshInstance7.mesh.uv2, array5, ref num5);
            }
        }
        num5 = 0;
        foreach (MeshCombineUtility.MeshInstance meshInstance8 in combines)
        {
            if (meshInstance8.mesh)
            {
                MeshCombineUtility.CopyColors(meshInstance8.mesh.vertexCount, meshInstance8.mesh.colors, array6, ref num5);
            }
        }
        int num8  = 0;
        int num9  = 0;
        int num10 = 0;

        foreach (MeshCombineUtility.MeshInstance meshInstance9 in combines)
        {
            if (meshInstance9.mesh)
            {
                if (generateStrips)
                {
                    int[] triangles = meshInstance9.mesh.GetTriangles(meshInstance9.subMeshIndex);
                    if (num9 != 0)
                    {
                        if ((num9 & 1) == 1)
                        {
                            array8[num9]     = array8[num9 - 1];
                            array8[num9 + 1] = triangles[0] + num10;
                            array8[num9 + 2] = triangles[0] + num10;
                            num9            += 3;
                        }
                        else
                        {
                            array8[num9]     = array8[num9 - 1];
                            array8[num9 + 1] = triangles[0] + num10;
                            num9            += 2;
                        }
                    }
                    for (int num12 = 0; num12 < triangles.Length; num12++)
                    {
                        array8[num12 + num9] = triangles[num12] + num10;
                    }
                    num9 += triangles.Length;
                }
                else
                {
                    int[] triangles2 = meshInstance9.mesh.GetTriangles(meshInstance9.subMeshIndex);
                    for (int num13 = 0; num13 < triangles2.Length; num13++)
                    {
                        array7[num13 + num8] = triangles2[num13] + num10;
                    }
                    num8 += triangles2.Length;
                }
                num10 += meshInstance9.mesh.vertexCount;
            }
        }
        Mesh mesh = new Mesh();

        mesh.name     = "Combined Mesh";
        mesh.vertices = array;
        mesh.normals  = array2;
        mesh.colors   = array6;
        mesh.uv       = array4;
        mesh.uv2      = array5;
        mesh.tangents = array3;
        if (generateStrips)
        {
            mesh.SetTriangles(array8, 0);
        }
        else
        {
            mesh.triangles = array7;
        }
        return(mesh);
    }
Esempio n. 3
0
    public static Mesh Combine(MeshCombineUtility.MeshInstance[] combines, bool generateStrips)
    {
        int num  = 0;
        int num2 = 0;
        int num3 = 0;

        for (int i = 0; i < combines.Length; i++)
        {
            MeshCombineUtility.MeshInstance meshInstance = combines[i];
            if (meshInstance.mesh)
            {
                num += meshInstance.mesh.get_vertexCount();
                if (generateStrips)
                {
                    int num4 = meshInstance.mesh.GetTriangleStrip(meshInstance.subMeshIndex).Length;
                    if (num4 != 0)
                    {
                        if (num3 != 0)
                        {
                            if ((num3 & 1) == 1)
                            {
                                num3 += 3;
                            }
                            else
                            {
                                num3 += 2;
                            }
                        }
                        num3 += num4;
                    }
                    else
                    {
                        generateStrips = false;
                    }
                }
            }
        }
        if (!generateStrips)
        {
            for (int j = 0; j < combines.Length; j++)
            {
                MeshCombineUtility.MeshInstance meshInstance2 = combines[j];
                if (meshInstance2.mesh)
                {
                    num2 += meshInstance2.mesh.GetTriangles(meshInstance2.subMeshIndex).Length;
                }
            }
        }
        Vector3[] array  = new Vector3[num];
        Vector3[] array2 = new Vector3[num];
        Vector4[] array3 = new Vector4[num];
        Vector2[] array4 = new Vector2[num];
        Vector2[] array5 = new Vector2[num];
        Color[]   array6 = new Color[num];
        int[]     array7 = new int[num2];
        int[]     array8 = new int[num3];
        int       num5   = 0;

        for (int k = 0; k < combines.Length; k++)
        {
            MeshCombineUtility.MeshInstance meshInstance3 = combines[k];
            if (meshInstance3.mesh)
            {
                MeshCombineUtility.Copy(meshInstance3.mesh.get_vertexCount(), meshInstance3.mesh.get_vertices(), array, ref num5, meshInstance3.transform);
            }
        }
        num5 = 0;
        for (int l = 0; l < combines.Length; l++)
        {
            MeshCombineUtility.MeshInstance meshInstance4 = combines[l];
            if (meshInstance4.mesh)
            {
                Matrix4x4 transform = meshInstance4.transform;
                transform = transform.get_inverse().get_transpose();
                MeshCombineUtility.CopyNormal(meshInstance4.mesh.get_vertexCount(), meshInstance4.mesh.get_normals(), array2, ref num5, transform);
            }
        }
        num5 = 0;
        for (int m = 0; m < combines.Length; m++)
        {
            MeshCombineUtility.MeshInstance meshInstance5 = combines[m];
            if (meshInstance5.mesh)
            {
                Matrix4x4 transform2 = meshInstance5.transform;
                transform2 = transform2.get_inverse().get_transpose();
                MeshCombineUtility.CopyTangents(meshInstance5.mesh.get_vertexCount(), meshInstance5.mesh.get_tangents(), array3, ref num5, transform2);
            }
        }
        num5 = 0;
        for (int n = 0; n < combines.Length; n++)
        {
            MeshCombineUtility.MeshInstance meshInstance6 = combines[n];
            if (meshInstance6.mesh)
            {
                MeshCombineUtility.Copy(meshInstance6.mesh.get_vertexCount(), meshInstance6.mesh.get_uv(), array4, ref num5);
            }
        }
        num5 = 0;
        for (int num6 = 0; num6 < combines.Length; num6++)
        {
            MeshCombineUtility.MeshInstance meshInstance7 = combines[num6];
            if (meshInstance7.mesh)
            {
                MeshCombineUtility.Copy(meshInstance7.mesh.get_vertexCount(), meshInstance7.mesh.get_uv1(), array5, ref num5);
            }
        }
        num5 = 0;
        for (int num7 = 0; num7 < combines.Length; num7++)
        {
            MeshCombineUtility.MeshInstance meshInstance8 = combines[num7];
            if (meshInstance8.mesh)
            {
                MeshCombineUtility.CopyColors(meshInstance8.mesh.get_vertexCount(), meshInstance8.mesh.get_colors(), array6, ref num5);
            }
        }
        int num8  = 0;
        int num9  = 0;
        int num10 = 0;

        for (int num11 = 0; num11 < combines.Length; num11++)
        {
            MeshCombineUtility.MeshInstance meshInstance9 = combines[num11];
            if (meshInstance9.mesh)
            {
                if (generateStrips)
                {
                    int[] triangleStrip = meshInstance9.mesh.GetTriangleStrip(meshInstance9.subMeshIndex);
                    if (num9 != 0)
                    {
                        if ((num9 & 1) == 1)
                        {
                            array8[num9]     = array8[num9 - 1];
                            array8[num9 + 1] = triangleStrip[0] + num10;
                            array8[num9 + 2] = triangleStrip[0] + num10;
                            num9            += 3;
                        }
                        else
                        {
                            array8[num9]     = array8[num9 - 1];
                            array8[num9 + 1] = triangleStrip[0] + num10;
                            num9            += 2;
                        }
                    }
                    for (int num12 = 0; num12 < triangleStrip.Length; num12++)
                    {
                        array8[num12 + num9] = triangleStrip[num12] + num10;
                    }
                    num9 += triangleStrip.Length;
                }
                else
                {
                    int[] triangles = meshInstance9.mesh.GetTriangles(meshInstance9.subMeshIndex);
                    for (int num13 = 0; num13 < triangles.Length; num13++)
                    {
                        array7[num13 + num8] = triangles[num13] + num10;
                    }
                    num8 += triangles.Length;
                }
                num10 += meshInstance9.mesh.get_vertexCount();
            }
        }
        Mesh mesh = new Mesh();

        mesh.set_name("Combined Mesh");
        mesh.set_vertices(array);
        mesh.set_normals(array2);
        mesh.set_colors(array6);
        mesh.set_uv(array4);
        mesh.set_uv1(array5);
        mesh.set_tangents(array3);
        if (generateStrips)
        {
            mesh.SetTriangleStrip(array8, 0);
        }
        else
        {
            mesh.set_triangles(array7);
        }
        return(mesh);
    }