Esempio n. 1
0
    void UpdateCubeMeshes()
    {
        int numParticles      = MPAPI.mpGetNumParticles();
        int numActiveChildren = numParticles / 2700 + (numParticles % 2700 == 0 ? 0 : 1);

        while (children.Count < numActiveChildren)
        {
            GameObject child    = CreateChildMesh();
            Vector3[]  vertices = new Vector3[64800];
            Vector3[]  normals  = new Vector3[64800];
            Vector2[]  uv       = new Vector2[64800];
            int[]      indices  = new int[97200];
            fixed(Vector3 *v = vertices)
            {
                fixed(Vector3 *n = normals)
                {
                    fixed(Vector2 *t = uv)
                    {
                        fixed(int *idx = indices)
                        {
                            meshData.vertices = v;
                            meshData.normals  = n;
                            meshData.uv       = t;
                            meshData.indices  = idx;
                            MPAPI.mpGenerateCubeMesh(children.Count, ref meshData);
                        }
                    }
                }
            }

            Mesh mesh = child.GetComponent <MeshFilter>().mesh;
            mesh.vertices = vertices;
            mesh.normals  = normals;
            mesh.uv       = uv;
            mesh.SetIndices(indices, MeshTopology.Triangles, 0);
            children.Add(child);
        }
        UpdateChildMeshes(numActiveChildren);
    }