- Home /
Mesh Combine Increases Triangle Count
I've just noticed that I'm getting a significant increase in my mesh triangle count when performing a mesh combine on child objects. I'm seeing a doubling in mesh size. While the reduction in draw calls is helpful, the increased mesh triangle count is completely undoing any benefits and slowing down rendering.
Here is my code:
#pragma strict
@script RequireComponent(MeshFilter)
@script RequireComponent(MeshRenderer)
function Start () {
var meshFilters = GetComponentsInChildren.<MeshFilter>(); // Get the MeshFilter components of the children
var combine : CombineInstance[] = new CombineInstance[meshFilters.Length-1]; // Create an array to hold the meshes
var index = 0;
for (var i=0;i<meshFilters.Length;i++) { // Create a loop to iterate through the "combine" array
if (meshFilters[i].sharedMesh == null) continue;
combine[index].mesh = meshFilters[i].sharedMesh; // Assign the mesh of this child to the sharedMesh
combine[index++].transform = meshFilters[i].transform.localToWorldMatrix; // Position the mesh
Destroy(meshFilters[i].renderer); // Remove the renderer as it's no longer needed
Destroy(meshFilters[i]); // Remove the mesh filter as it's no longer needed
}
GetComponent(MeshFilter).mesh = new Mesh();
GetComponent(MeshFilter).mesh.CombineMeshes(combine); // Get the combined mesh
if(renderer)
renderer.material = renderer.sharedMaterial; // Assign the material
}
I'm hoping someone can either spot something in my code or offer other assistance. Maybe something to do with the way the fbx files are imported? I've toyed with the normals and tangents, but with no success.
Thanks!
I've struggled with this for about 8 hours or so and still don't have a clue as to why the triangle count is being doubled. $$anonymous$$aybe my search-fu isn't working so good today.
If you're reading this and have used Combine$$anonymous$$eshes/CombineInstance before, have you noticed the same?
...bit of a stab in the Dark, but it could be something to do with mesh compression, which is optimal when the FBX importer applies it in your project, but cannot me applied at run time AFAI$$anonymous$$. To test this theory it might be worth, changing the import settings for the FBX in the inspector to $$anonymous$$esh Compression: Off and Optimise $$anonymous$$esh : Unchchecked - then repeat the comparison with and without meshcombine to exa$$anonymous$$e the difference.
It's a good suggestion and thanks for the reply. Unfortunately I already have compression off and optimize mess unchecked as well.
Strangely, I didn't notice any difference on the combined mesh between the original mesh being compressed & optimized before combining vs it not being compressed & optimized before combining. I would have expected there to be a fairly significant difference between the two.
I noticed the same thing in a simple project. $$anonymous$$y best guess is that the original objects are holding onto the original meshes.
I never dug into it further to see if the triangles are actually being sent to the GPU, or just present in memory.
I'm 100% sure that the original objects are not still displaying (or even containing) the meshes as I can see the child meshes being removed once hitting the play button. As well, I've even removed all the child gameObjects manually after hitting play. There is no change in triangle count after doing that and the triangle count remains about double the original.
I'm still struggling with this and am starting to think that maybe there's nothing that can be done.
Your answer