Calculate correctly custom UVs for the "last" polygons in a mesh

Hello, imagine you have a mesh without pre-calculated UVs and you need to apply them on load. The mesh is rounded from the top perspective.
You can find my approach to calculate UVs on this playground:
Here I use a standard sphere, but reapply the UVs.

The approach works except the last polygons. Basically, because of horizontally the last U will be always 0, that means I get an entire texture flipped and drawn on the last polygons. Of course I can add yet another condition to explicitly apply U to 1 in the end, however I believe Iā€™m missing a more flexible and better approach.

Ahh, I can just find the amount of segments and just divide my step to the amount. Means no trigonometry needed at all. Will provide the result if it works.

UV unwrapping is highly complex and might require a lot of fiddling to handle all cases unfortunately.

1 Like