# Merging meshes - Unexpected results

**URL:** <https://forum.babylonjs.com/t/merging-meshes-unexpected-results/823>\
**Category:** Questions\
**Created:** [January 18, 2019, 11:10am UTC](https://forum.babylonjs.com/t/merging-meshes-unexpected-results/823 "2019-01-18T11:10:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Subrahmanya\_Chakrava](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/subrahmanya_chakrava/32/3313_2.png) [@Subrahmanya\_Chakrava](https://forum.babylonjs.com/u/Subrahmanya_Chakrava)\
**Post date:** [January 18, 2019, 11:10am UTC](https://forum.babylonjs.com/t/merging-meshes-unexpected-results/823/1 "2019-01-18T11:10:21Z")

</div>

Hi Saviours,

To merge meshes, i could think of two approaches.

function mergeAndGetCSG1 (meshes, scene) {  
var wholeCSG = null;  
for (var i = 0; i \< meshes.length; i++) {  
var mesh = meshes[i];  
var csg = BABYLON.CSG.FromMesh(mesh);  
if (wholeCSG === null) {  
wholeCSG = csg;  
} else {  
wholeCSG.unionInPlace(csg);  
}  
}  
return wholeCSG;  
}

function mergeAndGetCSG2 (meshes, scene) {  
var wholeCSG = null;  
var mergedMesh = BABYLON.Mesh.MergeMeshes(meshes, false);  
var csg = BABYLON.CSG.FromMesh(mergedMesh);  
scene.removeMesh(mergedMesh);  
return csg;  
}

In the below PG, I am getting the same result with both of these approaches.  
[https://playground.babylonjs.com/#INZ0Z0#36](https://playground.babylonjs.com/#INZ0Z0#36)

But, in this PG, I am getting different results with each approach.  
[https://playground.babylonjs.com/#INZ0Z0#37](https://playground.babylonjs.com/#INZ0Z0#37)

What is the wrong that I am doing? Can you please help me?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [January 20, 2019, 8:17am UTC](https://forum.babylonjs.com/t/merging-meshes-unexpected-results/823/2 "2019-01-20T08:17:10Z")

</div>

Hi SC! Sorry for the slow replies.

You ask difficult questions, my friend. 🙂

[https://playground.babylonjs.com/#INZ0Z0#41](https://playground.babylonjs.com/#INZ0Z0#41)

Nothing learned, so far. I am not yet sure WHY your _mergeAndGetCSG1()_ and _mergeAndGetCSG2()_ are getting different results… when used on flat2009 floors. hmm.

Anyway, maybe this playground makes work easier, or makes issue easier to understand.

I am no expert in merging or CSG… not even a little bit. 🙂 But, maybe others will comment soon. Stay tuned. Teach us things you learn.

---

<div class="post-metadata">

**Author:** ![Subrahmanya\_Chakrava](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/subrahmanya_chakrava/32/3313_2.png) [@Subrahmanya\_Chakrava](https://forum.babylonjs.com/u/Subrahmanya_Chakrava)\
**Post date:** [January 28, 2019, 5:26pm UTC](https://forum.babylonjs.com/t/merging-meshes-unexpected-results/823/3 "2019-01-28T17:26:56Z")

</div>

Hi,

I have been seeking help on this for more than 10 days. Every minute I am checking for a response to this post but surprisingly no light has been thrown.

Hi @sebavan, @Deltakosh, @trevordev,

Sorry for tagging you. Can you please help me on this?

Thanks in advance.

---

<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:** [January 28, 2019, 5:43pm UTC](https://forum.babylonjs.com/t/merging-meshes-unexpected-results/823/4 "2019-01-28T17:43:18Z")

</div>

My recommendation would be to stick with MergeMeshes as CSG can be quite expensive

---

<div class="post-metadata">

**Author:** ![Subrahmanya\_Chakrava](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/subrahmanya_chakrava/32/3313_2.png) [@Subrahmanya\_Chakrava](https://forum.babylonjs.com/u/Subrahmanya_Chakrava)\
**Post date:** [January 28, 2019, 5:52pm UTC](https://forum.babylonjs.com/t/merging-meshes-unexpected-results/823/5 "2019-01-28T17:52:33Z")

</div>

Thank you. But my question is, why the output is not same?

---

<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:** [January 28, 2019, 5:55pm UTC](https://forum.babylonjs.com/t/merging-meshes-unexpected-results/823/6 "2019-01-28T17:55:15Z")

</div>

Because CSG is considreing your faces differently. (They may be not perfectly coplanar or there is something else in the geometry that does not fit well)
