CSG behaves different between bjs meshes and gltf meshes

Hello guys,

I noticed that csg leads to different results if you cut a bjs mesh like meshBuilder.CreateBox and if you cut an imported gltf mesh.

You can see this here: https://playground.babylonjs.com/#C4B8QB#49

It seems to have something to do with rightHandedSystem. Turning it off changes the behavior but there is still a difference between both boxes.

Any idea how to solve this? The imported mesh should behave the same way like the bjs one.

Best

This must be a right-handed system issue, as you have already noticed. CSG is using the vertex data, which is unmodified by the parent root node transformation. Probably should be taken into account :slight_smile:

To avoid this issue, you can bake the current transformation to the root node of the glTF loaded - Babylon.js Playground (babylonjs.com) (notice line 21). That’s for left handed systems.
I have to admit I am not sure what happened with the right handed system, but I can only assume it has something to do with the way CSG is reading the vertex data. We can investigate that, you can submit a github issue if you wish. Please link this topic (and the playground) in the github issue

1 Like

Thanks, @RaananW.

I will create a GitHub issue!

1 Like

I saw that @Deltakosh added this issue to 5.0.0 milestone. Unfortunately I have to solve this problem earlier. Since I always use right handed system and my project is set up for this I can’t switch to left handed system for this. Is there any workaround or fix that I can use to make csg work as expected? Do you have an idea, @Evgeni_Popov? I noticed you were assigned to this case.

https://playground.babylonjs.com/#C4B8QB#51

Best

I will have a look as soon as possible.

In the meantime, a workaround is to use union instead of subtract:

https://playground.babylonjs.com/#C4B8QB#52

2 Likes

The workaround works pretty good. Thank you!