- Home /
Mesh.CombineMeshes Problem. Are there limitations?
I try th combine 15000 cube Meshes into one single Mesh.
I do it like this:
// i have a Dictionary of cubes which i reference to some information, // and contains 15000 cubes public Dictionary<string, GameObject> cubes; // i also have an Mesh created in the Start() function public Mesh mesh = new Mesh();
CombineInstance[] combineMeshes = new CombineInstance[cubes.Values.Count]; int count = 0; foreach (GameObject c in cubes.Values) { MeshFilter mF = c.GetComponent<MeshFilter>(); combineFileMeshes[count].mesh = mF.mesh; combineFileMeshes[count].transform = c.transform.localToWorldMatrix; count++; }
mesh = Mesh.CombineMeshes(combineMeshes); mesh.Optimize();
After i did this, the cubes existed, and the cubes in the mesh should look the same. But they dont. Are there limitations how many objects you can combine in a single Mesh?
It realy looks like there are limitations. I tryd to use two $$anonymous$$eshes, which both only holds 10000 cube meshes, and now i can see much more, but still not all.
Answer by jonas-echterhoff · Jul 09, 2010 at 03:44 PM
Meshes in Unity cannot have more then 65536 vertices, because indices are 16 bit numbers internally. So, given that your cubes have 8 vertices each, you cannot have more then 8192 cubes in one mesh (does not matter if it is created using Mesh.CombineMeshes or by other means).
I recently noticed I managed to create meshes in code with more than 100000 vertices each. I guess the limitation has been removed? (I'm using the latest unity 3 version btw)
I was making a mesh and I learned the limit is smaller than 8192 cubes. It is actually 2730 cubes because cubes must have 24 vertices and not 8 (source: https://answers.unity.com/questions/143109/why-does-a-primitive-cube-contain-24-verts.html) Basically, each face must have 4 unique vertices for normals for lighting. I was making a 3000+ cube mesh and was puzzled. I'm happy to contribute to the discussion for once :)