Merging meshes - Unexpected results

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

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

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

Thanks in advance.

Hi SC! Sorry for the slow replies.

You ask difficult questions, my friend. :slight_smile:

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. :slight_smile: But, maybe others will comment soon. Stay tuned. Teach us things you learn.

1 Like

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.

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

1 Like

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

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)