- Home /
Why doesn't my combined mesh look how it supposed to do?
I have a script that generates all necessary quads and it works fine. The picture below shows the separate quads before combining:
After that i'm combining everything with this function:
void combineQuads()
{
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
for (int i = 0; i < meshFilters.Length; i++)
{
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
}
MeshFilter mf = (MeshFilter)this.gameObject.AddComponent(typeof(MeshFilter));
mf.mesh = new Mesh();
mf.mesh.CombineMeshes(combine);
MeshRenderer renderer = this.gameObject.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
renderer.material = material;
foreach (Transform quad in this.transform)
{
Destroy(quad.gameObject);
}
}
And then i get this:
Why does this happen? If i generate a way smaller chunk everything is working fine but the larger ones are glitching. It confuses me.
Answer by Glurth · Jul 22, 2018 at 09:51 PM
I suspect you are simply exceeding the maximum number of vertices for a mesh. https://answers.unity.com/questions/255405/vertex-limit.html
You will need to make a few meshes, rather than just one.
Right, you can try setting the index format to 32 bit on the target mesh. However i never tried something like that with Combine$$anonymous$$eshes.
Wow, didn't know about that one, thanks Bunny! Alas, there ARE platform limitations with that option.
I've been hoping to find some open-source code to take a huge procedural-mesh (or similar data struct), and break it up into multiple smaller meshes for (all-platform) use. I've yet to find something like this [I suck at searching], has anyone else?
Your answer
Follow this Question
Related Questions
Why mesh colliders doesn't work with combined meshes using Mesh.CombineMeshes? 3 Answers
Combining Objects for Performance 0 Answers
500K upper bound on total number of meshes? 0 Answers
Lightmapping Error with combined meshes 0 Answers
Is there a maximum amount of memory Unity assigns for instantiating meshes? 1 Answer