CSG2 discards uv2-uv6

Hello! While working on migrating to CSG2, I discovered that several vertex channels are lost somewhere in operation. Digging deeper, I noticed that the CSG2.FromMesh gets the vertex data with UV2Kind and sends it on to CSG2._Construct, but when the vertex data / mesh is returned from the CSG2 object the UV2Kind data is not there. This happens even when no operations are done to the CSG2.

I believe what’s happening is that the properties on the data object that’s sent to _Construct are named differently from the constants that are compared against when creating the vertex structure for the Manifold. The vertex structure creation looks for property names on an IVertexDataLike with the VertexBuffer.UVKind, and adds them to the structure if they exist. Problem is that the properties are named differently than the values of UVKind and its ilk (“uvs” instead of “uv” and so on").

Here’s a repro in the Playground

https://playground.babylonjs.com/#1GT138#1

The lower model uses a material with coordinatesIndex set to 1, and with uvs copied from the first to the second channel.

The upper model shows the expected result.

cc @Deltakosh

I’ll have a look asap!

Here we are:
Fix CSG2 losing uvs data by deltakosh · Pull Request #17805 · BabylonJS/Babylon.js

2 Likes

Thanks a lot for the amazing response time!

1 Like