# Merge Mesh and select Submesh - DrawCalls

**URL:** <https://forum.babylonjs.com/t/merge-mesh-and-select-submesh-drawcalls/14439>\
**Category:** Questions\
**Created:** [September 25, 2020, 4:30pm UTC](https://forum.babylonjs.com/t/merge-mesh-and-select-submesh-drawcalls/14439 "2020-09-25T16:30:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dennemark](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dennemark/32/10745_2.png) [@dennemark](https://forum.babylonjs.com/u/dennemark)\
**Post date:** [September 25, 2020, 4:30pm UTC](https://forum.babylonjs.com/t/merge-mesh-and-select-submesh-drawcalls/14439/1 "2020-09-25T16:30:45Z")

</div>

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](https://playground.babylonjs.com/#CURCZC#80)

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

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 25, 2020, 4:49pm UTC](https://forum.babylonjs.com/t/merge-mesh-and-select-submesh-drawcalls/14439/2 "2020-09-25T16:49:44Z")

</div>

> [@dennemark](#):
>
> I guess I have no chance to create a merged mesh where I can select submeshes while keeping a drawcall count of 1

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

---

<div class="post-metadata">

**Author:** ![dennemark](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dennemark/32/10745_2.png) [@dennemark](https://forum.babylonjs.com/u/dennemark)\
**Post date:** [September 25, 2020, 7:12pm UTC](https://forum.babylonjs.com/t/merge-mesh-and-select-submesh-drawcalls/14439/3 "2020-09-25T19:12:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 25, 2020, 7:58pm UTC](https://forum.babylonjs.com/t/merge-mesh-and-select-submesh-drawcalls/14439/4 "2020-09-25T19:58:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dennemark](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dennemark/32/10745_2.png) [@dennemark](https://forum.babylonjs.com/u/dennemark)\
**Post date:** [September 26, 2020, 9:37am UTC](https://forum.babylonjs.com/t/merge-mesh-and-select-submesh-drawcalls/14439/5 "2020-09-26T09:37:14Z")

</div>

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](https://playground.babylonjs.com/#CURCZC#83)

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