Home Technical Talk

Combining UV Texture Sets in Maya

polycounter lvl 8
Offline / Send Message
PattyWhacker polycounter lvl 8
I'm working a low resolution version of a lion warrior that I've been working on. I finished creating a UV texture map within 3D Coat, but I decided to clean up the UV set within Maya. As you can see below, I have several pieces that are similar:



With this in mind I decided to duplicate these individual pieces and move each piece to the correct location to save space on the UV map. When I combine the meshes together, I get a whole ton of separate UV maps within the model as you can see below:




In the past, I'd solve this issue by tediously copy and pasting to the first UV map and then deleting the copied UV map to avoid confusion. I'm wondering if there is an easier way to combine all UV sets together without having to deal with the horrible, tedious busy work of copying and pasting. 




Replies

  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    I could probably whip up a MEL script to knock that out but I would need to know a bit more.  Does each UV set refer to a unique mesh element?  If you were to separate all the pieces out as their own objects, would they all only have UVs under a single UV set (all UV sets but one are empty)?
  • Scruples
    Offline / Send Message
    Scruples polycounter lvl 10
    It's too late, but in the future Combine>Merge UV Sets set to "Merge By Name", will make it easier to manage them.
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 12
    I went ahead and did it anyway.  I was curious, and I've actually had this problem crop up before.

    Assuming you can Mesh > Separate (then delete history) your model to separate all the individual pieces, and also assuming that each piece only has UV information inside one of the many UV Sets, the script below will work for you.

    Basically, the script will check through each UV Set and delete any empty ones.  When it's left with map1 and whichever UV Set the UV information is in, it copies the UV info into map1, then deletes the last empty set.  It should leave all your pieces with UV info inside map1 and no empty sets.  If by chance it comes across more than one UV set with UV information in it, it'll leave it alone and kick out a warning for each object it encounters.

    You can use this with all your separated objects selected at once.

    proc dp_MergeUVSets() {<br>&nbsp;&nbsp;&nbsp; // get selection<br>&nbsp;&nbsp;&nbsp; string $sel[] = `ls -sl`;<br>&nbsp;&nbsp;&nbsp; //figure out which UV window to query for UV sets<br>&nbsp;&nbsp;&nbsp; string $texWinName[] = `getPanel -sty polyTexturePlacementPanel`;<br><br>&nbsp;&nbsp;&nbsp; for ( $obj in $sel ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select $obj;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //query all UV sets on selection<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $UVs = `polyUVSet -q -auv`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($set in $UVs) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $mapName = $set;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; polyUVSet -cuv -uvs $mapName;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int $size[] = `polyEvaluate -uvcoord`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //if there are no UVs in the current UV Set, delete it<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( $size[0] == 0 && $mapName != "map1") {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; polyUVSet -delete;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //query all UV sets on selection again (should only be two left now, map1 which can't be deleted, and whatever set contains the UVs)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $UVs = `polyUVSet -q -auv`;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($set in $UVs) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $mapName = $set;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; polyUVSet -cuv -uvs $mapName;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int $size[] = `polyEvaluate -uvcoord`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //if not on map 1 and it's got the UVs, copy them to map1 and delete this set (should result in only one UV Set, map1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($mapName != "map1" && $size[0] > 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; polyUVSet -cp -nuv "map1";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; polyUVSet -delete;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //if not on map1 and it's still somehow empty, delete it<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if ($mapName != "map1" && $size[0] == 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; polyUVSet -delete;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //final check to make sure there is only one set remaining with UVs inside it. at this point it should at least be manageable to fix manually<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select $obj;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $UVs = `polyUVSet -q -auv`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (`size $UVs` > 1) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; warning ( "Check " + $obj + "!&nbsp; Found multiple UV Sets with UV information.");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br>dp_MergeUVSets;


  • throttlekitty
    Offline / Send Message
    throttlekitty ngon master
    Thanks Bartalon! I was just sitting down to try my hand at this one and thought I'd check the thread. I also had this pop up recently but not as extreme, still tedious.
  • Rawbdiel
    Offline / Send Message
    Rawbdiel polycounter lvl 3
    Thank you so much. I had a crazy amount of UV sets. It tiled across my monitor. For me it worked great when I combined the objects I wanted to share the same UV space. I deleted history, ran your script, and deleted history again. When I first tried it I didn't delete history before running it, I waited for about 5 minutes to wait for Maya to respond before closing the program.
Sign In or Register to comment.