Axis-aligning a uv island along it's longest conjoined edge

   2010   2   2
User Avatar
Member
12 posts
Joined: Jan. 2020
Offline
I'm trying to lay out primitives for trim uvs using the UvFlatten on individual islands to get the initial uv. Unfortunately it tends to put things at wonky angles (see pic!). Ideally i'd find the longest edge and have that run along the bottom of the uv space.

The ‘axis-aligned vertex groups’ seems to be the way to fix this, as long as I can pass in which is the longest edge(s) as an align group. How can I calculate this group? I found the Measure node, but I don't just want the longest single edge, because a grid might have a chain of edges that are individual short but form the longest edge (see other pic!).

I have managed to extract the outer edges (via Group + unshared edges) so I can ignore interiour edges at least (although polys with holes end up with the hole edges included as well - for now I'm kinda ignoring that).

Any pointers appreciated, thanks!

Attachments:
JauntyAngle.PNG (47.6 KB)
EdgeChain.PNG (31.2 KB)

User Avatar
Member
12 posts
Joined: Jan. 2020
Offline
So I kinda got this working so I thought I'd update this.

My current solution is:
1. Attrib promote the uvs from vertices->points
2. Convert the mesh into uv space by swapping the point's positions and uvs. That means I can use standard nodes to manipulate uv data.
3. Find the outer edges via a Group with unshared edges
4. A big chunk of python code to find runs of connected edges that are within a tolerance angle of each other.
5. A smaller chunk of python code to calculate the world-space length and uv-space length of the longest run, and it's angle in uv space, and set those as detail attribs
6. Attrib transfer the detail attribs to the original model (before the position-uv swap)
7. UvTransform and rotate by the angle to align the longest space with the u axis.

Annoyingly I had to drop to python rather than vex because I needed an array of structs which contain arrays, which apparently VEX doesn't support. The python code is quite inefficient and slow, but I'm mostly dealing with islands of <200 edges so it's working fast enough.

There's probably a more node-based solution possible - I couldn't figure out how to merge adjacent edges if lower than a certain angle difference (eg. the second image would become just a quad with 4 points). If I could do that then a Measure node would probably do a lot of the rest.
User Avatar
Member
3 posts
Joined: Dec. 2017
Offline
Just bumping this thread as I am actually trying to do the same thing and can't really get my head around how to approach that. Any help would be welcome, thank you!
  • Quick Links