Home Technical Talk

Maya script to automatically offset overlapped UVs by 1

polycounter lvl 12
Offline / Send Message
BARDLER polycounter lvl 12
I am curious if anybody knows of, or has, a Maya script that can automatically move all UV shells that are flipped and overlapping by 1?
Thanks!

Replies

  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    Sounds fancy,
    So if they are flipped AND overlapping? It's not always necessarily flipped UV shells that are overlapping. Wouldn't just overlapping be good enough?
  • BARDLER
    Options
    Offline / Send Message
    BARDLER polycounter lvl 12
    kodde wrote: »
    Sounds fancy,
    So if they are flipped AND overlapping? It's not always necessarily flipped UV shells that are overlapping. Wouldn't just overlapping be good enough?

    Yea thats true.
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    I had a look at the UV MEL commands and there doesn't seem to be anything to easily query for overlapping.

    I take it you'd want this for prepping for baking? Is it safe to assume that the overlapping UV part is identical to the underlying one when it comes to shape and UV-space-position?
  • BARDLER
    Options
    Offline / Send Message
    BARDLER polycounter lvl 12
    kodde wrote: »
    I had a look at the UV MEL commands and there doesn't seem to be anything to easily query for overlapping.

    I take it you'd want this for prepping for baking? Is it safe to assume that the overlapping UV part is identical to the underlying one when it comes to shape and UV-space-position?

    Yea the shells would be exactly the same, and yes it would be for setting up bakes.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    Then a simple workaround that might work is if you could check the centered pivot for each shell, and check for shell pivots that are on the same location (with a small tolerance). This would find stacked shells given that they are in fact neatly placed on top of each other.

    Then you might work on a solution to figure out if they are flipped or not. I didn't try it but I think I saw a command that you could query for this.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Might take a stab at this today. Need more Maya scripting to do as at work there's been less of that haha.

    Edit: thinking about this something that might also happen is you might move both uv shells as you would obviously be iterating over every uv shell unless you check all shells versus ones already processed. Might be able to save some processing time by doing a distance check maybe?
  • Mark Dygert
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
  • leleuxart
    Options
    Offline / Send Message
    leleuxart polycounter lvl 10
    If I am understanding you, Nightshade may be of some help. It's not automatic, but you can select the shells, hit a button, and it moves them over to the next quadrant in whatever direction you press.
  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    Here's a very basic script that should do what you want. Select the UV borders, and then run it (Also works with everything selected but will be slower). It just checks if any of the selected UV points are directly overlapping each other, nothing fancy like checking for vector intersections.
    $uvShellVerts = `ls -sl -fl`;
    for ($mapOne in $uvShellVerts)
         {
         $fc = `polyEditUV -q -u -v $mapOne`;
         for ($mapTwo in $uvShellVerts)
             {
             $sc = `polyEditUV -q -u -v $mapTwo`;
             if (($fc[0] == $sc[0]) && ($fc[1] == $sc[1]))
                 {
                 select $mapTwo;
                 polySelectBorderShell 0;
                 polyEditUV -u 1 -v 0 ;
                 select -add $mapOne;
                 polySelectBorderShell 0;
                 
                 $buff = `ls -sl -fl`;
                 $uvShellVerts = stringArrayRemove($buff, $uvShellVerts);
                 break;
                 }
             }
         }
    
    
  • artquest
    Options
    Offline / Send Message
    artquest polycounter lvl 13
    PolyHertz wrote: »
    Here's a very basic script that should do what you want. Select the UV borders, and then run it (Also works with everything selected but will be slower). It just checks if any of the selected UV points are directly overlapping each other, nothing fancy like checking for vector intersections.
    $uvShellVerts = `ls -sl -fl`;
    for ($mapOne in $uvShellVerts)
         {
         $fc = `polyEditUV -q -u -v $mapOne`;
         for ($mapTwo in $uvShellVerts)
             {
             $sc = `polyEditUV -q -u -v $mapTwo`;
             if (($fc[0] == $sc[0]) && ($fc[1] == $sc[1]))
                 {
                 select $mapTwo;
                 polySelectBorderShell 0;
                 polyEditUV -u 1 -v 0 ;
                 select -add $mapOne;
                 polySelectBorderShell 0;
                 
                 $buff = `ls -sl -fl`;
                 $uvShellVerts = stringArrayRemove($buff, $uvShellVerts);
                 break;
                 }
             }
         }
    
    

    You are awesome sir! I will be trying this out soon. :)
  • 54Strat
    Options
    Offline / Send Message
    54Strat polycounter lvl 5
    If you're just looking to identify the overlaps and manually fix them, have you tried using UV Texture Editor / Image / Shade UVs?

    It will display the winding order (the flipping) as different colours, defaults are blue = front facing, red = back facing. It will also shade them with an alpha value, default is 0.25 so any overlaps are easily identified.

    Providing the scene's not too complex, this might help.
  • artquest
    Options
    Offline / Send Message
    artquest polycounter lvl 13
    PolyHertz, I tested your script and it seems to not leave behind the final non overlapping uv shell in many cases. So for instance if I have 4 identical overlapping uv shells instead of leaving the 4th and final shell for baking in 0-1 space it moves it with the other 3 shells to "1-2" space.
  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    Oops, sorry about that. Removing values from an array like the above version was a mistake because Maya doesn't just mark them as inactive until the loop ends, it actually gets rid of them which makes the next loop jump values instead (maybe it was different in earlier versions or I got it mixed up with another language).
    Though to be honest, looking at it again I'm not sure how to fix it :( . Something like this should work, but it doesn't, no clue why. Maybe someone else can fix it:
    $usersUVSelection = `ls -sl -fl`; for ($uvPassOne in $usersUVSelection)
     {
         $uvXYone = `polyEditUV -q -u -v $uvPassOne`;
         for ($uvPassTwo in $usersUVSelection)
         {
             $uvXYtwo = `polyEditUV -q -u -v $uvPassTwo`;
             if (($uvXYone[0] == $uvXYtwo[0]) && ($uvXYone[0] == $uvXYtwo[0]) && (!($uvXYone[0] >= 1)))
             {
                 select $uvPassTwo;
                 polySelectBorderShell 0;
                 polyEditUV -u 1 -v 0; 
             }
         }
     }
    
  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    Here's a super basic bit of code that should work, however it's not entirely automatic. If you have a single component of a shell selected, it will move everything over. It shouldn't be too big of a hassle considering you should know which areas of your model are mirrored/overlapping, so just select a single face of each one and it'll do the rest.
    polySelectBorderShell 0;
    PolySelectConvert 4;
    polyEditUV -relative true -uValue -1;
    
  • ValN84
    Options
    Offline / Send Message
    ValN84 polycounter lvl 5
    kodde wrote: »
    Then you might work on a solution to figure out if they are flipped or not. I didn't try it but I think I saw a command that you could query for this.

    I've tried to find a way to tell whether the UV shell is flipped or not but couldn't find any.
    There's an error in the Maya help file for the polyEvaluate command in the mel section. It states that for the -boundingBox2d flag, the mel command will return the UV coordinates for the bounding box as 4 float values in Mel and as three pairs of floats in Python. I thought "This is IT!", I can get a "W" like in Max! Thinking that using the Python command will save the day, I tried it but unfortunately, just like the mel command, using that flag will just return the U and V coordinates, no "W" :( I cross-checked with the Python command reference and it is consistent with the real world test which means the mel command reference was wrong :((

    So, does anyone know of way to query the winding order? From there it's very easy to write a script to get all the flipped shells and offset them to one side.
  • Moosebish
    Options
    Offline / Send Message
    Moosebish polycounter lvl 12
    I use the UV Nightshade Editor script for unwrapping and packing UV's, it has revolutionized my work flow for unwrapping and editting UVs in Maya. It can do what you asked and way way more. I like it way more than I ever like max for headus.

    Here's a link:

    http://www.creativecrash.com/maya/script/nightshade-uv-editor
  • rollin
    Options
    Offline / Send Message
    rollin polycounter
    made a script like that in max to explode and also implode (reset all back to 0-1 uv range)
    it's not that difficult (you have to scan overlapping uv shells and store their overlapping count) but it saves fivebrazidillion hours when baking, changing uvs re baking, changing uvs re re baking ...

    uvexplode.gif
  • animax
    Options
    Offline / Send Message
    animax polycounter lvl 15
    Textools has shift overlap function which does the same. but in max.
  • ValN84
    Options
    Offline / Send Message
    ValN84 polycounter lvl 5
    Moosebish wrote: »
    I use the UV Nightshade Editor script for unwrapping and packing UV's, it has revolutionized my work flow for unwrapping and editting UVs in Maya. It can do what you asked and way way more. I like it way more than I ever like max for headus.

    Here's a link:

    http://www.creativecrash.com/maya/script/nightshade-uv-editor

    I couldn't find how to automatically move flipped UVs with Nightshade. Which command should I use?
  • Moosebish
    Options
    Offline / Send Message
    Moosebish polycounter lvl 12
    I couldn't find how to automatically move flipped UVs with Nightshade. Which command should I use?

    It depends on how the model is setup, but if I were working on a model that had one whole half mirrored over I'd do it like this:

    Go to orthographic front view

    Select by face

    Select the half of the mesh that is mirrored.

    Convert selection to UV's

    In the UV window, move them all over exactly 1 unit.
  • ValN84
    Options
    Offline / Send Message
    ValN84 polycounter lvl 5
    It's not about how to actually do it manually. I should have mentioned more clearly in my first comment that I'm interested on how to query this in mel :(
    It's just that with some meshes that have flipped overlapped UVs, not all flipped shells are easily selectable in the 3d view as they aren't always on the same side and even if they were, it's quite difficult to tell which side is the flipped one in the 3d view. There are cases when the UV layout contains a lot of overlapped shells and it would speed up work flow if we could easily move the flipped ones to the side to aid baking.
    Just as the OP, I'm interested how to do this in Maya. It seems that Max solutions do exist but implementing them in Maya might not be so easy as the mel or python commands don't seem to provide a way to easily query a UV shell/selection to see if it's flipped or not.
Sign In or Register to comment.