Issue with extrusion/ribbon closePath UV mapping

,

I’m struggling to create a closed path extrusion that is both seamless and has nice UV coordinates.

In the example below I have an extrusion with a circle path and sine wave shape. When I leave a gap in the circle and use closePath = true (on the left) the normals/shading are great, but the UV mapping is messed up as the gap faces are filled with UVs 0.0 - 1.0 rather than a proportion of the entire path. When I instead set closePath = false (on the right) and manually copy the first path point to the last in order to close the gap, then the UV mapping is as expected, but due to the wave shape I can’t achieve a seamless connection.

I’m unsure if this is expected behaviour for extrusions, but the way UV mapping is handled in the first case (closePath = true), doesn’t seem right to me.

I can see the bug in the Babylon.js code where the last v coord is correct, but there’s no v of 1 added when the path is closed, so the last segment’s v interpolates from ~0.9 to 0 instead of ~0.9 to 1.

I think this is a bug, but I’ll have to cc @Evgeni_Popov or @sebavan to verify and fix if needed since I don’t have a good handle on the UV code, yet.

1 Like

There’s a bug in the order closePath and closeShape are passed to extrude shape internally. This PR will fix it:

However, I’m not sure this will fix your problem. You may have to pass your own uvs coordinates through the uvs option parameter.

2 Likes

Thanks @Evgeni_Popov. I had noticed that shape and path were mapped incorrectly between extrusion and ribbon, however I think this is a separate issue to the UV problem, and extrusion front or back UVs can only be passed into extrusion if it’s double sided.

Looking at the extrusion and ribbon code I think @docEdub was on the right track. The issue is with the underlying ribbon, in that UVs are calculated before the path is closed.

Yes, the problem is that you would have to create new vertices to close the path, and calculate the correct normals / uvs for these additional vertices. I’m giving it a try.

I updated my PR, hoping the fix is ok…

3 Likes

Thanks so much for the fix @Evgeni_Popov. I’ve tested it locally and it seems to do the trick!

Here’s the example with fix applied:

1 Like