So, I’ve run into a very large wall at the intersection of Maxscript and UVs.
Big picture, I’m working on a UV strip mapper. Users select faces, all those faces get scaled relative to each other, with nice, squared-off edges.
I’m going about that by breaking out each face, flattening it, and rectifying it with TexTools. The wall I’ve run into is in sewing all those faces back together. I’ve tried a few different methods of exclusion/inclusion to try and make sure I’m only stitching edges that are contained by the selected faces, but everything has come up short. In the UV Editor Window Maxscript knows which edges pair with which edges, but I can’t seem to find a maxscript method for accessing that information as a way to check whether or not an edge is valid to stitch.
Anyone have any ideas/leads? Is there something else I could be doing at a higher level to sidestep this problem altogether?
Don’t know a thing about maxscript (or any of the max apis honestly), but could you create a list of connected faces before you break them apart, and then use that to put them back together?
So, given a selection of broken-off faces, this script adds one face to the selection on each iteration and stitches them together, which works. It’s a bit kludgy, and it definitely doesn’t work in all cases, but it’s close.
uv = $.modifiers[1]
faces = uv.getselectedfaces()
subobjectlevel = 3
selFaces = #{}
print faces
for i in faces do
(
selFaces[i] = true
if(selFaces.numberSet > 1) then
(
print selFaces
uv.selectFaces selFaces
uv.stitchVertsNoParams()
)
)
Ignore that last guy, he has no clue what he’s talking about. His method was error prone, because it’d end up stitching to faces outside the selection.
Pseudo-code for the new process:
-- 1) Break off all the faces in the selection
-- 2) Flatten those faces, with "Normalize Clusters" set to false
-- 3) For each face, align the verts of each edge (this requires a bit of assumption on the part of the script about the vertical/horizontal orientation of an edge)
-- 4) Determine all the interior UV edges of the face selection by:
---- Get all Geo edges on the outside of the face selection (should appear only once if looping over all faces)
---- Get all Geo edges on the inside of the face selection (should appear twice if looping over faces)
---- Get all UV edges corresponding to the interior geo edges by getting the UV verts corresponding to those edges
-- 5) Until there are no unshared UV edges, do 4, select the first UV edge in the list, and "stitch selected"
-- 6) Realign all the edge loops in the face selection
Right now this process is kinda slow (about 7 seconds for a reasonable number of faces) because I’m looping over faces and edges and verts a fair bit, and most of this only works with the UV Editor window open. If anyone has any suggestions on speeding that up, I’d be very appreciative