//AlignUVShells ver1.0 //made by Takahiro Nakajima //nkj@lib.net //You can use this script with your own risk. //Overview: //This aligns UV shells of selected uv vertices. //How to use: //1)Run this script to show its dialog window. //2)In UV Texture Editor, select a UV vertex on each UV shells which you want to align. //This means, if you have 3 UV shells to align, you should select 3 UV vertices. //3)Select one of radio buttons in dialog window. //4)Click "Align" button to align shells. //As a result, all UV vertices you have selected gathers with moving their UV shells. //Note: //You should not select more than 1 UV vertex per 1 UV shell. //If you do that, this script doesn't work well. //-------------------------------------------------------- //----------------------------------------------- global proc string[] returnUVoutsideVtx(string$vtxList[]) { //This returns 4 UV verteces of $vtxList. //The return values are: //address 0 is the far-left uv vertex. //address 1 is the far-right uv vertex. //address 2 is the lowest uv vertex. //address 3 is the highest uv vertex. string $result[]; float $initialValues[] = `polyEditUV -q $vtxList[0]`; float $topValues[] = { $initialValues[0], $initialValues[0], $initialValues[1], $initialValues[1] }; string $topNames[] = { $vtxList[0], $vtxList[0], $vtxList[0], $vtxList[0] }; int $size = `size $vtxList`; int $count; for($count=1;$count<$size;$count++) { float $currentValues[] = `polyEditUV -q $vtxList[$count]`; if($currentValues[0] < $topValues[0]) { $topValues[0] = $currentValues[0]; $topNames[0] = $vtxList[$count]; } else if($currentValues[0] > $topValues[1]) { $topValues[1] = $currentValues[0]; $topNames[1] = $vtxList[$count]; } if($currentValues[1] < $topValues[2]) { $topValues[2] = $currentValues[1]; $topNames[2] = $vtxList[$count]; } else if($currentValues[1] > $topValues[3]) { $topValues[3] = $currentValues[1]; $topNames[3] = $vtxList[$count]; } } return $topNames; } //------------------------------------- global proc float[] getRelativePos(string$UV1,string$UV2) { //This returns a relative position of 2 UV vertices. //The return value is as $UV1 is an original position. float $UV1Pos[] = `polyEditUV -q $UV1`; float $UV2Pos[] = `polyEditUV -q $UV2`; float $posU = $UV2Pos[0] - $UV1Pos[0]; float $posV = $UV2Pos[1] - $UV1Pos[1]; float $result[] = { $posU,$posV }; return $result; } //------------------------------------- global proc string[] toUVShell(string$UV) { //$UV is a UV vertex. //This returns a list of all UV vertices in a UV shell of $UV. string $UVList[] = {$UV}; int $size = 1; int $sizeNew = 0; while($size!=$sizeNew) { $size = `size $UVList`; string $faceList[] = `polyListComponentConversion -tf $UVList`; $UVList = `polyListComponentConversion -tuv $faceList`; $UVList = `ls -fl $UVList`; $sizeNew = `size $UVList`; } return $UVList; } //------------------------------------- global proc synchroUVshellsPos(string$ref,string$sub) { //This moves $ref's UV shell to $sub's UV shell. //Get relative position. float $reletivePos[] = `getRelativePos $ref $sub`; string $shell[] = `toUVShell $sub`; select $shell; polyEditUV -u ($reletivePos[0]*(-1)) -v ($reletivePos[1]*(-1)); } //------------------------------------- global proc synchroAllUVshellsPos(string$UVvtx[],int$switch) { //This aligns all UV shells of $UVvtx. //If $switch = 0, all shells align to far-left. //If $switch = 1, all shells align to far-right. //If $switch = 2, all shells align to the lowest. //If $switch = 3, all shells align to the highest. //Get four sides' vertices. string $sides[] = `returnUVoutsideVtx $UVvtx`; string $ref = $sides[$switch]; int $size = `size $UVvtx`; int $count; for($count=0;$count<$size;$count++) { synchroUVshellsPos $ref $UVvtx[$count]; } select -cl; } //------------------------------------- global proc synchroAllUVshellsPosExec() { int $switch; string $dir = `radioCollection -q -sl alignUVShellRadioCollection00`; if($dir == "radiobuttonLeft") { $switch = 0; } else if($dir == "radiobuttonRight") { $switch = 1; } else if($dir == "radiobuttonLower") { $switch = 2; } else if($dir == "radiobuttonUpper") { $switch = 3; } string $uvs[] = `ls -sl -fl`; synchroAllUVshellsPos $uvs $switch; } //------------------------------------- //------------------------------------- //Make a window. { string $title = "alignUVShells"; string $object = "alignUVShellsObject"; if(`window -ex $object` == 1) { deleteUI $object; } window -t $title $object; columnLayout -p $object "layout"; //----- text -l "AlignUVShells"; separator -w 90; //----- text -l ""; button -w 90 -c "synchroAllUVshellsPosExec" -l "Align"; radioCollection alignUVShellRadioCollection00; radioButton -l "Left" -sl radiobuttonLeft; radioButton -l "Right" radiobuttonRight; radioButton -l "Lower" radiobuttonLower; radioButton -l "Upper" radiobuttonUpper; window -e -w 100 -h 160 $object; showWindow $object; } //------------------------------------- //The end of the script.