Merge Mesh and select Submesh - DrawCalls

Hi,
I want to ask about Submeshes. I have used the Merge Mesh function to create a new mesh with submeshes. I was hoping I could select the submeshes via id afterwards. This actually works, but I was not aware, that the drawcall count would not decrease if subdivideWithSubMeshes is set to true. I guess I have no chance to create a merged mesh where I can select submeshes while keeping a drawcall count of 1? Materials for the submeshes are the same.

Do you know another good approach to select objects within a merged mesh?

Futhermore I did not fully understand the Parameter meshSubclass of MergeMeshes. It means I can add an additional submesh to the merged mesh? How does it differ to the array of meshes of the first parameter?

https://playground.babylonjs.com/#CURCZC#80

MergeMeshes(meshes, disposeSource: boolean, allow32BitsIndices: boolean, meshSubclass: [Mesh], subdivideWithSubMeshes: boolean, multiMultiMaterials: boolean)

This is correct. submeshes are meant to be used with multi material and then end up being used with multiple draw calls

the meshSubclass property is an option to let you provide the final mesh which will be the output of the merge. if you do not provide it the function will create a new mesh for it

Thanks a lot! This makes sense!

Do you have a recommendation for another approch on selecting parts of a mesh? In my case I want to merge buildings to one mesh to reduce draw calls. But I would still like to select individual meshes. I though submeshes are a good approach, since I know vertex start and count. This allowed me to colour the individual vertices of the merged mesh. I could build up a seperate structure that just stores the vertex start and count, but it would have been nice to just use the submeshes for it. Do you think I would need to build my own merging algorithm?

Well you can’t have 1 draw call ans submeshes. So I guess you have to choose :slight_smile:
Other idea is simply as you said to store your own vertex start and counts but this will not let you color individual submeshes

Actually it is not too complicated at the end. I created an array of my mesh objects, since they keep order in mesh merge I can actually easily store vertex start and count seperately in the mesh. Afterwards I check for faceId take the first vertex and go through my vertexStart/Count array and color only the one that contains my vertex.

https://playground.babylonjs.com/#CURCZC#83

If you have any recommendations, let me know! Otherwise use it as solution :slight_smile:

1 Like