Bug when cutting GLTF object with CSG2

Hi everybody,

I tried to use the new CSG class to replace all my CSG work but I have an issue when cutting a GLTF profile.

I’ve made a PG here : https://playground.babylonjs.com/#M829XG#17

You can change the CSG version (1 or 2) in the line number 227. My purpose is to cut a GLTF profile with a box on the left side and on the right side if I give an angle.

With versionCSG = 1 → all is well, that was my previous code

With versionCSG = 2 → there is an error in the console in the line46 and I really don’t understand why.

Maybe I’ve made a mistake but it does not work like it should be.

There are three JS classes that are not useful for your understanding : tools, BandeauPergola and Profil_GLTF.

Thanks in advance,

Boris

Hey this error means that your 2 meshes do not have the same number of attributes:

The Bandeau has positions + normals but the Box has also UVs so to fix it you need to remove the UVs from the Box:

slicer.removeVerticesData(BABYLON.VertexBuffer.UVKind);

Then the call to toMesh has changed for CSG2 (the scene is now the 2nd parameter and we have options after):

var newMesh2 = subCSG.toMesh(name, scene, {materialToUse : mat0});

Fix:
Bug CSG2 | Babylon.js Playground

3 Likes

Thanks very much for your answer… It is not as simple as i thought.

There are no more errors but the profile is not cut on the two sides with CSG2.

The final mesh has to be like that (cut with CSG class)

The problem comes from the source mesh in this case:
You can call csg2.printDebug() and this is what we get:


We have a negative genus and a volume === 0 so the CSG cannot find a way to get a manifold out of it.

You have to make sure your mesh is convex and that all the faces are correctly oriented

Ok I understand but the CSG was previously working. I do not know the new CSG2 class and what to do to correct that. Here’s the gltf object if you can help me.

Cheneau Pergola PS double.zip (48.7 KB)

Let me investigate :slight_smile:

1 Like

When investigating a little bit more, I see that is the volume of the slicer cube that is equal to 0. The debug of the source mesh after the first cut is

image

And after the second cut it is

image

What i can do to help you to understand :slightly_smiling_face:

I have a gltf profile (zip file). I give it a length to “extrude it” and then I cut it on the left side and on the right side.

The slicer are cubes and can be displayed in the line number 248 (fifth parameter = true) to obtain something like that and check if the cut is correct.

I first cut on the left side, it creates a new mesh and i cut this new mesh on the right side.

If you need some more explanation, i will give it to you, unfortunately, that is only what i can do to help.

it is all clear but the main issue I have is that gltf are right handed and we transform them to lef handed. Can you get the same mesh as a .babylon file?

lol I think I found it
Stay tuned!

Here’s an new PG where the gltf file is replaced by a babylon file (line number 224). I loaded the file in the sandbox and then exported it to a .babylon

I had to place again the slicers to have a cut even if it is not the right angle, only to see if it cuts or not.

If it can help…

HERE WE ARE LOL!

Bug CSG2 | Babylon.js Playground

I was literally writing a bug report for Manifold:

And while writing I realized that the boxes genus was negative!!

This is because you used a double side box so the volume was literally 0 :slight_smile:

I will add a warning on CSG2 when detecting negative genus!

A better version by the way with no intermediate mesh:
Bug CSG2 | Babylon.js Playground

2 Likes

Once again you’re my hero !!! :heart_eyes:

By the way, I have some other CSG functions that will be deprecated soon. May be when you have time, it will be great to publish some advices. For instance, I had no idea I could not cut with a double sided box if I could before with the previous CSG class.

But I also know that it is only the first day with the new CSG2 class so it will take a little bit time to fix all the bad uses that were made with the first CSG class.

Can you tell me when you will delete the previous CSG class to only use the second one ?

And thanks very much again…

You have time. It is deprecated for 8.0 and will be removed for 9:) so more than a year

But CSG2 is league away above CSG

1 Like

Sorry but I have to reopen the post.

If I choose some other profiles, sometimes it works and sometimes it does not.

Here’s a PG : https://playground.babylonjs.com/#M829XG#32

when choosing the profile in line number 218, it perfectly works with CSG and does not with CSG2.

But the glb profile in line number 217 works.

This error means that there is no volume. To build a manifold you have to provide enough thickness.

Edit: Well no this is not the cause…let me check what are the differences with the working one

Ok I don’t know lol
Specific mesh not being a manifold · elalish/manifold · Discussion #1011

Ok, wait and see and thanks again for your help…

1 Like

They answered and unfortunately you have to update the mesh :frowning: