[SOLVED] Csg.js port broken with latest release - v1.40.0

I’ve been using this port of csg.js for boolean operations in my project. It was working for about a few weeks after commenting a line out in the port but with the release of v1.40.0, the mesh appears to not be rendering properly.

With v1.40.0

There should be a perfect circle cut in the wall in this screenshot here. It looks perfect in v1.39.4.

The csg port hasn’t been updated in 3 years, though I did have to do some debugging it to get to work with v.1.39.4. I did notice the createMesh function was updated in the latest release. Could anyone provide me more info or where to start?

Or if there’s a different way I can approach doing mesh boolean operations, that would be great as well. :slight_smile:

https://playcanvas.com/project/768492/overview/2d-demo

Hi @Kano_Ngo and welcome,

There was something regarding 2d in the latest release. Maybe this has to do something about your problem? Other then that im no expert on boolean.

Yes, you are right. Something has broken this in 1.40.0. Here’s 1.40.0:

https://launch.playcanvas.com/1098585

And here’s 1.39.4:

https://launch.playcanvas.com/1098585?use_local_engine=https://code.playcanvas.com/playcanvas-1.39.4.js

We’ll look into it.

My guess is that it might have something to do with this PR:

It seems I’m a good guesser. This is the scene for the commit directly before that PR:

It’s broken after.

OK @Kano_Ngo, I have found the problem. It’s line 354 in playcanvas.csg.js which pokes into private structures in the vertex iterator:

        var numVertices = iterator.element[attributeMap.position].array.length /  format.size*4;

Change it to:

        var numVertices = mesh.vertexBuffer.numVertices;

The code above is ‘legal’ and public API.

4 Likes

Wow, thank you, Will! It’s working now. :slight_smile:

2 Likes