I’m writing a workflow script for Maya that attempts to convert a triangulated mesh into quads based on how the mesh UVs are laid out. I’m looking for feedback about 1) why the script is running so slow and 2) how to get the UV shell border as a selection of UVs through a python command.
The script assumes that the user is working with a specific kind of mesh, ie. strokes exported from the VR app Gravity Sketch.
On the mesh UVs, the central portion of the mesh is laid out in a grid-like fashion, as seen in the image below.
My thinking was that since the triangles can already be easily identified visually at a glance on the UVs, the conversion to quads shouldn’t be too difficult. I tried doing ‘Mesh > Quadrangulate’ on a variety of meshes, but I found that this command was not reliable in all cases. My guess is that ‘Mesh > Quadrangulate’ interprets the mesh in world space (not UV space, as I am trying to do).
My script goes like this: Iterate through each UV on the model. Check its neighbouring UVs as to whether they are lined up or not in UV space. If they are not lined up, consider the edge between as an edge causing triangulation, then delete the edge.
After running the script on the UV selection shown above, the edges causing triangles are deleted.
The problem is that the script runs super slowly. I’m not sure what’s going on here or if there is a way to speed this up.
I am also having a hard time getting the UV shell border through a command (or series of commands). I am wondering whether ‘Select > Convert Selection > To UV Shell Border’ exists as a command? I have not been able to find it.
Here is my script and a demo fbx file for testing. Thanks!
# the user selects a set of uvs and runs the script # the script deletes the edges causing triangles import maya.cmds as cmds import math # defines a value to not delete an edge based on whether the u or v values of two uvs in question are within this threshold keepTol = 0.0001 # user selects a set of uvs uvSelection = cmds.ls( selection=True, flatten=True ) # for all uvs in the selection for uv in uvSelection : # set the first uv uv1 = uv # get the uv value uv1Val = cmds.polyEditUV( uv1, query=True ) # get the adjacent edges adjEdges = cmds.polyListComponentConversion( uv1, toEdge=True ) # get the adjacent uvs adjUvs = cmds.polyListComponentConversion( adjEdges, toUV=True ) # select the uvs cmds.select( adjUvs ) # remove the first uv from the selection cmds.select( uv1, deselect=True ) # set the adjacent uvs adjUvs = cmds.ls( selection=True, flatten=True ) # for the adjacent uvs for xy in adjUvs : # set the second uv uv2 = xy # get the uv values uv2Val = cmds.polyEditUV( uv2, query=True ) # if the first and second uvs don't match within a given tolerance if abs( uv1Val - uv2Val ) > keepTol and abs( uv1Val - uv2Val ) > keepTol : # proceed to delete the edge between # get the vertices verts = cmds.polyListComponentConversion( uv1, uv2, toVertex=True ) # get the edge edge = cmds.polyListComponentConversion( verts, verts, toEdge=True, internal=True ) # delete the edge cmds.polyDelEdge( edge, cv=False ) # exit the loop break