Adjusting UVs for mapping a partial TubeGeometry

Hey all

I’m currently working on an experience which involves me cutting various segment rings and partial segment rings out of a tubegeometry more or less procedurally (e.g the backing curve will change).

Currently my code seems to work, I can choose the segments I want and have them align properly with an original tubegeometry.

My problem is the UVs. Ideally, I want to map my UVs to the segments I extract from the tubegeo. I originally tried scaling these by the amount of tubular segments and radial segments removed from the original, but this doesn’t work. I can’t use cylindrical UV mapping (from maath for example) because this isn’t a cylinder, and the curve will dictate how the faces show the map (e.g they aren’t all even).

The idea is to have an image map fitted across the surface of the radial segments of the selected ring, as if I was painting a poster on a curved wall.

My example is here TubeGeo Mapping - CodeSandbox. It’s R3F but I’m basically using just THREE for most of it.