x


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?

more ▼

asked Jul 09 '10 at 02:03 PM

Case23 gravatar image

Case23
441 18 21 30

It realy looks like there are limitations. I tryd to use two Meshes, which both only holds 10000 cube meshes, and now i can see much more, but still not all.

Jul 09 '10 at 03:26 PM Case23
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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).

more ▼

answered Jul 09 '10 at 03:44 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

Thanks again jonas! Perfect Answer!

Jul 09 '10 at 05:28 PM Case23

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)

Jan 08 at 01:52 PM Steven 1
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1403
x32

asked: Jul 09 '10 at 02:03 PM

Seen: 1782 times

Last Updated: Jan 08 at 01:52 PM