CSG2 Same operation fails in TS but not in JS

Playground Version: 8.25.0
Browser: MS Edge

Playground JS: BoxCSG_JS | Babylon.js Playground

Playground TS: BoxCSG_TS_Broken | Babylon.js Playground

I have been trying to mess around with CSG in a project of mine and was running into a problem where the result mesh would be unaltered even when the vertex data clearly overlapped between the two meshes. To sanity check myself I tried to create a playground that mirrored the situation I had and noticed it was crashing the engine.

I then noticed all the CSG examples in the docs are in JS, not TS so I copied the exact same logic into a JS playground and it worked as intended.

Feels like a bug, but also wanted to post to make sure Im not forgetting anything critical on the TS side that would get this to work.

EDIT:
Digging into this further, the problem seems to be line 183 : csg2.ts
Babylon.js/packages/dev/core/src/Meshes/csg2.ts at master · BabylonJS/Babylon.js · GitHub

The call this._manifold.getMesh(…) is returning an object with no vertex data. Which means when trying to retrieve the vertex data in the for loop below on line 201 : csg2.ts the vertexCount variable is 0 which has no data being recorded.

Im not sure where in the process the internal manifold object in the CSG2 loses the properties, but it causes .toMesh to fail.

The returned IManifoldMesh returned when running in JS is intact with data, while in TS it is not. There must be some process when creating the _manifold object for the CSG2 object with a manifold operation (add, subtract, intersect) in TS that fails.

Having a look!

They are not the same :slight_smile:

You are using sideOrientation: BABYLON.Mesh.DOUBLESIDE on the TS version which is doubling the number of faces and positions and prevents Manifold to find well a manifold :wink:

BoxCSG_TS_Broken | Babylon.js Playground

1 Like

Wow sorry oversight on my part. Did not realize that would break manifold.

I’m adding a better error handling :slight_smile:

3 Likes