Finding and selecting fliiped (red-colored) UVs

2,481 views
Skip to first unread message

likage

unread,
May 1, 2017, 1:46:10 PM5/1/17
to Python Programming for Autodesk Maya
Hi all, I have several models in my scene that contains flipped uvs (those colored in red when opening in UV editor) and each mesh contains a mixture of red and blue ones (blue are the correct uvs)

While I can manually select each/ all of these red colored uvs and flip them inidvually per mesh, it is a hassle as I will need to select only the red-color ones since I will need to go through each of them.

I tried to write a python script but unable to find any commands in the maya cmds documentation that will allow me to find and select these red uvs/faces.

Wondering if anyone know of any similar commands that I can use?

Andres Weber

unread,
May 1, 2017, 3:53:33 PM5/1/17
to Python Programming for Autodesk Maya
A bit of a tricky one:

Go to Layout UVs [Option box]:
1.  Toggle Shell Layout: None
2.  Toggle Rotate None
3.  Toggle Scale Mode: None
4.  Toggle on Flip reversed

Now hit Layout UVs and it should flip and reversed UVs without affecting the current UV layout except for the flipped sections.

likage

unread,
May 1, 2017, 7:00:46 PM5/1/17
to Python Programming for Autodesk Maya
Hi Andres, thanks for getting back.

The settings you have given works like a charm! Was not aware of such a setting as I only knows of selecting the faces and flipping them manually.
Though I have yet to check all the UVs in general if they are working correctly/ have changed anything in its initial setup.

I have managed to found a code from cgsociety, though it is using pymel, its execution speed seems to be wayyyy longer as compared to the solution derived by Andres as it seems to be iterating every single uv it can find... 

Even so, I am still curious if there is a pythonic way (using maya.cmds) to do it?

Michael Boon

unread,
May 1, 2017, 10:44:31 PM5/1/17
to Python Programming for Autodesk Maya
Using maya.cmds you'd probably want to execute the MEL commands that do the same actions Andres detailed. I'm not sure how to do that but if you turn on "Echo All Commands" in the Script Editor and do some digging in the MEL scripts that ship with Maya, you might be able to figure it out.

Using PyMel, or the C++ or Python API, I think you could do it faster than the script you linked by using the isRightHandedTangent function of PyMel's Mesh or the API's MFnMesh class. (You can pass UV ids to that function.) You'd still have to iterate through all UV IDs but you let Maya do the vector math for you. You would then probably select the left-handed UVs for the user to flip. Flipping them in script would be more complex because you'd have to account for cases where a UV shell folds on itself.

likage

unread,
May 2, 2017, 12:57:02 PM5/2/17
to Python Programming for Autodesk Maya
Using maya.cmds you'd probably want to execute the MEL commands that do the same actions Andres detailed. I'm not sure how to do that but if you turn on "Echo All Commands" in the Script Editor and do some digging in the MEL scripts that ship with Maya, you might be able to figure it out.

Using PyMel, or the C++ or Python API, I think you could do it faster than the script you linked by using the isRightHandedTangent function of PyMel's Mesh or the API's MFnMesh class. (You can pass UV ids to that function.) You'd still have to iterate through all UV IDs but you let Maya do the vector math for you. You would then probably select the left-handed UVs for the user to flip. Flipping them in script would be more complex because you'd have to account for cases where a UV shell folds on itself.

Hi Michael, yes I am able to use the solution given by Andres and convert them using maya.cmds.polyMultiLayoutUV.
By the way, how are you able to tell that the script I have linked is using the isRightHandedTangent function (I have hardly used PyMel, mostly I am using maya.cmds)?

I have also managed to find another script that uses both PyMel and Maya Api altogether. Tried running it (though there are some errors), I think it run similarly to the script I have linked previously but it is still slow, nowhere fast as the solution provided by Andres.

Script02 - Uses PyMel + Maya Api >

To my knowledge, I had thought that using of maya api will makes the process faster? Wondering if the cause of slowness could be due to PyMel - read that PyMel is more in ease of use over execution speed






Michael Boon

unread,
May 2, 2017, 11:45:31 PM5/2/17
to Python Programming for Autodesk Maya
The first script you linked is NOT using isRightHandedTangent. Instead it creates vectors and does a cross product in Python, which would slow it down for sure.

The second script is very involved! It uses the API for some stuff but it is also iterating through all faces by converting each of them to a string and then a PyMel object. It then creates vectors and does a cross product in Python, just like the first script, so I expect it is even slower.

If maya.cmds.polyMultiLayoutUV does what you want, I think you should stick with it. I don't think you'll find anything that can match its speed, and as a bonus, you have less code to maintain.

likage

unread,
May 5, 2017, 7:28:54 PM5/5/17
to Python Programming for Autodesk Maya
Alright, I have misunderstand. 

Yes I think I will stick to the cmds command as it is faster and easier to maintain like you have mentioned.
Appreciate for the information on the API and PyMel etc. :)

Cheers!
Reply all
Reply to author
Forward
0 new messages