////////////////////////////////////////////////////////////////// // // worldSpaceUVLineUI // // UI for worldSpaceUVLine script // // written by Tylney Taylor, some time early Feb 2005 // // copyright bold vfx pty ltd. 2005-2007 // // instructions: select single line (can be continuous) that is near straight // on the character itself. Then select your options from the window // to lay out the UV's in U or V direction and execute. // // version History: // // version 2.2 - oops, forgot a separate little script to get array positions :P // // version 2.1 - now also supports uv selection (in a row) - error checking still to come // to detect multiple lines // // version 2.0 - added nominalisation and relative Scale functionality to allow // several lines to be scaled relative to each other. Further added // option to reselect the UV's at the end of the operation for easier // manipulation (Feb 14 1005) // // version 1.5 - added u and v direction functionality and edgeloop detection // // version 1.0 - simple select single edge line and perfoem script to layout // UV's in only V direction with nominalized spacing. The spacing // is the same as the relative distances the CV's havein worldspace ///////////////////////////////////////////////////////////////////////////// // // procedure: ttGetStringArrayPos(string $item, string $array[]) // // Author: Tylney Taylor, bold vfx pty ltd. // // date: 1/2/05 // // function: returns the position of the item in the array as an integer global proc int[] ttGetStringArrayPos(string $item, string $array[]) { // first argument is failure/success 0/1, then the arary position int $return[] = {0, 0}, $i = 0; string $element; for ($element in $array){ if ($item == $array[$i]) { $return[0] = 1; break; } $i++; } $return[1] = $i; return $return; } global proc worldSpaceUVLineUICommandGen() { string $alignDir; int $mode, $keepSelection; float $scale; if (`radioButtonGrp -q -select uvLayoutDirRadioButtonGrp` == 1){ $alignDir = "-u"; } else { $alignDir = "-v"; } if (`radioButtonGrp -q -select uvlayoutModeRadioButtonGrp` == 1){ $mode = "0"; $scale = `floatFieldGrp -q -value1 uvScaleFloatFieldGrp`; } else { $mode = "1"; $scale = `floatFieldGrp -q -value1 uvScaleFloatFieldGrp`; } if (`checkBoxGrp -q -value1 keepUVSelectionCheckBoxGrp` == 1){ $keepSelection = "1"; } else { $keepSelection = "0"; } string $cmd = ("worldSpaceUVLineDoIt " + $alignDir + " " + $mode + " " + $scale + " " + $keepSelection); eval $cmd; } // UI script and main entry point global proc worldSpaceUVLine() { string $window, $dir = "-u"; if (`window -q -exists wsUVwindow`) deleteUI wsUVwindow; window -title "world Space UV line - Layout 2.2" -widthHeight 300 200 wsUVwindow; columnLayout; separator -height 5 -style "none"; radioButtonGrp -label "UV layout direction:" -nrb 2 -label1 "u" -label2 "v" -ct2 "left" "left" -cl2 "left" "left" -cw2 10 10 -co2 5 5 -select 1 uvLayoutDirRadioButtonGrp; separator -width 310 -height 5; radioButtonGrp -label "UV layout method: " -nrb 2 -label1 "normalised" -label2 "scale" -ct2 "left" "left" -cl2 "left" "left" -cw2 10 10 -co2 5 5 -select 1 -onCommand1 "floatFieldGrp -edit -enable 0 uvScaleFloatFieldGrp" -onCommand2 "floatFieldGrp -edit -enable 1 uvScaleFloatFieldGrp" uvlayoutModeRadioButtonGrp; floatFieldGrp -label "scale: " -numberOfFields 1 -value1 1.0 -precision 3 -cw1 50 -enable 0 uvScaleFloatFieldGrp; separator -width 310 -height 5; checkBoxGrp -label "keep UV selection: " -ncb 1 -label1 "" -value1 1 keepUVSelectionCheckBoxGrp; button -label "align UV's on selected line" -c ("worldSpaceUVLineUICommandGen") uvLayoutGoAheadButton; setParent ..; if (( ! `objExists wsUVwindow`) || (`window -q -visible 0 wsUVwindow`)) showWindow wsUVwindow; window -edit -wh 310 135 wsUVwindow; } ////////////////////////////////////////////////////////////////// // // worldSpaceUVLineDoIt(string $alignDir) // // select single line (or continuous edges), and now also UV's including loops and // lays out the uv's in that line in -u or -v (parameters) // direction // // written by Tylney Taylor, some time early Feb 2005 // // copyright bold vfx pty ltd. global proc worldSpaceUVLineDoIt(string $alignDir, int $mode, float $scale, int $keepSelection) { // if (`objExists front1`) select -r front1; string $edges[0], $originalUVs[0]; string $selList[] = `ls -sl -fl`; // convert to edges if UV otherwise simply continue if edges are selected // if (`match "\\.map." $selList[0]` == ".map["){ //print "UV-pre-process\n"; $originalUVs = $selList; // for each UV get the connected edges by cervert to edges // test the connected UV's for each edge and select the ones that are in UV list string $uv; select -clear; for ($uv in $selList){ select -r $uv; string $edge, $edgs[0]; PolySelectConvert 2; $edgs = `ls -sl -fl`; select -clear; for ($edge in $edgs){ select -r $edge; PolySelectConvert 4; string $edgeUVs[] = `ls -sl -fl`; string $edgeUV; select -clear; for ($edgeUV in $edgeUVs) { string $each; for ($each in $selList){ if (`strcmp $edgeUV $each` == 0){ if (`strcmp $edgeUV $uv` != 0){ //print ("edgeFound: " + $edge + "\n"); $edges[`size($edges)`] = $edge; } } } } } select -clear; } //print $edges; $edges = stringArrayRemoveDuplicates($edges); } else if (`match "\\.e." $selList[0]` == ".e["){ // print "edge"; $edges = $selList; } //string $edges[] = `ls -fl -sl`; // need to have edges int $print = 0; if ($print) print $edges; select -r $edges; if (size($edges) == 0){ error "no edges selected, script only works with edges\n"; } else { string $uvs[0], $uv, $cv, $edge, $edgeVertexArray[0], $evOrigArray[0], $seqVertexArray[0], $uniqueCVs[0], $element, $endCVs[0]; int $i = 0; // start with first edge and record CV's associated with the edge // we might have to later re-order the selection into a contiuous line // as we might have $edges[0] point to an edge in the middle of the selected line // clear $edgeVertexArray; // get selected UV's of that edge, using PolySelectConvert 4 PolySelectConvert 4; string $selectedUVs[] = `ls -fl -sl -type float2`; if (size($originalUVs) > 0) $selectedUVs = $originalUVs; // reselect the edges select -r $edges; if ($print) print ("number of edges: " + `size($edges)` + "\n"); for ($edge in $edges){ // as an edge has only 2 CV's we stuff them into the $edgeVertexArray // we are parsing the list by numerical order NOT geometrical order select -r $edge; if ($print) print ($edge + " : "); PolySelectConvert 3; // convert selection to CV's $tmp = `ls -fl -sl`; // get CV's $edgeVertexArray[$i] = $tmp[0]; if ($print) print ($edgeVertexArray[$i] + " : "); $edgeVertexArray[$i+1] = $tmp[1]; if ($print) print ($edgeVertexArray[$i+1] + "\n"); $i += 2; } select -cl; if ($print) print "all selected unordered CV's:\n"; for ($i = 0; $i < size($edgeVertexArray); $i++){ if ($print) print ($i + " - " + $edgeVertexArray[$i] + "\n"); } // first lets find the CV's that are unique // for ($i = 0; $i < (`size($edgeVertexArray)`); $i++){ int $count = `stringArrayCount $edgeVertexArray[$i] $edgeVertexArray`; if ($count == 1){ $uniqueCVs[size($uniqueCVs)] = $edgeVertexArray[$i]; } } if ($print) print "start and end CV's:\n"; if ($print) print $uniqueCVs; if (size($uniqueCVs) == 2){ // Main Code here: // // make a backup of the original vertex array as we are going to edit it from now on $evOrigArray = $edgeVertexArray; // local scope variables string $eString[1] = {""}, $nextCV; int $j = 0, $t = 0, $findNext = 1; int $position[0]; int $break = 0, $partnerCVFound = 0; int $count = 0, $t = 0, $endCVfoundEarly = 0; int $tmpArrayPos[] = {1, 0}; // get starting CV $nextCV = $uniqueCVs[0]; if ($print) print ("entering while-loop with start CV " + $nextCV + "\n"); // loop though all CV's and create spacially sequentially ordered array // while ($break == 0){ if ($print) print ("beginning of outer while loop iteration " + ($j/2+1) + " $nextCV = " + $nextCV + "\n"); // search for $nextCV in $edgeVertexArray and find edgeSharing CV // ignore if the connected CV is unique (the other end CV) // NEED TO LOOP HERE! // only evaluate if the element is found $t = 0; string $otherCV; // find partner CV Loop while ($findNext == 1){ // find nextCV in edgeVertexArray if ($nextCV == $edgeVertexArray[$t]) { if ($print) print ("index $t: " + $t + " - current CV: "+ $nextCV); float $fmod = `fmod $t 2.0`; if ($print) print (" fmod $t: " + $fmod); if ($fmod){ $otherCV = $edgeVertexArray[$t-1]; // PREVIOUS CV if (($otherCV != $uniqueCVs[0]) && ($j/2 < `size($edges)`)){ if (($otherCV == $uniqueCVs[1]) && ($endCVfoundEarly == 0)){ if ($print) warning "found end CV, but continuing\n"; $findNext = 1; $endCVfoundEarly = 1; $t++; } else { $tmpArrayPos[1] = $t-1; // $tmpArrayPos[0] = 1; $t = 0; if ($print) print (" and prev edgeCV: " + $otherCV + "\n"); $findNext = 0; break; } } else { $tmpArrayPos[0] = 0; $break = 1; if ($print) warning "endCV detected in find NextCV loop\n"; $findNext = 0; break; } } else { $otherCV = $edgeVertexArray[$t+1]; // NEXT CV if (($otherCV != $uniqueCVs[0]) && ($j/2 < `size($edges)`)){ if (($otherCV == $uniqueCVs[1]) && ($endCVfoundEarly == 0)){ if ($print) warning "found end CV, but continuing\n"; $findNext = 1; $endCVfoundEarly = 1; $t++; } else { $tmpArrayPos[1] = $t+1; $tmpArrayPos[0] = 1; $t = 0; if ($print) print (" and next edgeCV: " + $otherCV + "\n"); $findNext = 0; break; } } else { $tmpArrayPos[0] = 0; $break = 1; if ($print) warning "endCV detected in find NextCV loop\n"; $findNext = 0; break; } } } else { $tmpArrayPos[0] = 0; $t++; if ($t >= `size($edgeVertexArray)`){ $findNext = 0; if ($print) warning "array overrun, exiting nextCV Loop\n"; } } } // now order the array for the found tmpArrayPos[0,1] if ($tmpArrayPos[0] == 0){ if ($endCVfoundEarly == 1) $seqVertexArray[$j] = $uniqueCVs[1]; $break = 1; if ($print) warning "endCV detected, written into array as last value, exiting breakLoop\n"; break; } else { float $fmod = `fmod $tmpArrayPos[1] 2.0`; if ($fmod) { // if the position in the array is odd, we want the previous and current position // for this edge, the //$seqVertexArray[$j] = $edgeVertexArray[$tmpArrayPos[1]-1]; //$seqVertexArray[$j+1] = $nextCV = $edgeVertexArray[$tmpArrayPos[1]]; $seqVertexArray[$j] = $nextCV; $seqVertexArray[$j+1] = $nextCV = $otherCV; // remove the points from the array to reduce searching and doubling up of searches // this is ok as we are removing two at the same time // if ($print) { print ("fmod : " + $fmod + " - removing: " + $edgeVertexArray[$tmpArrayPos[1]-1] + " and " + $edgeVertexArray[$tmpArrayPos[1]] + " from array\n"); } $edgeVertexArray[$tmpArrayPos[1]-1] = ""; $edgeVertexArray[$tmpArrayPos[1]] = ""; $edgeVertexArray = stringArrayRemove($eString, $edgeVertexArray); if ($nextCV == $uniqueCVs[1]) { $break = 1; if ($print) warning "endCV detected exiting 2nd loop\n"; break; } $findNext = 1; // reset find Loop } else { //$seqVertexArray[$j] = $edgeVertexArray[$tmpArrayPos[1]]; //$seqVertexArray[$j+1] = $nextCV = $edgeVertexArray[$tmpArrayPos[1]+1]; $seqVertexArray[$j] = $nextCV; $seqVertexArray[$j+1] = $nextCV = $otherCV; // remove the points from the array to reduce searching and doubling up of searches // if ($print) { print ("fmod : " + $fmod + " - removing: " + $edgeVertexArray[$tmpArrayPos[1]] + " and " + $edgeVertexArray[$tmpArrayPos[1]+1] + " from array\n"); } $edgeVertexArray[$tmpArrayPos[1]] = ""; $edgeVertexArray[$tmpArrayPos[1]+1] = ""; $edgeVertexArray = stringArrayRemove($eString, $edgeVertexArray); if ($nextCV == $uniqueCVs[1]) { $break = 1; if ($print) warning "endCV detected exiting 2nd loop\n"; break; } $findNext = 1; // reset find Loop } if ($break == 1) break; $j += 2; } } if ($print) print "longArray CV's:\n"; if ($print) print $seqVertexArray; // remove any duplicates in array $seqVertexArray = stringArrayRemoveDuplicates($seqVertexArray); if ($print) print "order of CV's:\n"; if ($print) print $seqVertexArray; // now that we have sorted and identified individual line/CV order // lets get the additive distances between the points (ws) and fill another array // order will be [0] -> distance between cv[0] and cv[1] ... last CV in chain has total distance of line // vector $p0, $p1; float $distance = 0; float $cvDistanceArray[0]; $startIndex = 0; $endIndex = (`size($seqVertexArray)`-1); if ($print) print ("startIndex: " + $startIndex + "\n"); if ($print) print ("endIndex: " + $endIndex + "\n"); for ($i = $startIndex; $i <= ($endIndex); $i++){ // get worldspace positions of cv's // $p0 = `xform -q -ws -t $seqVertexArray[$i]`; if ($i+1 <= $endIndex){ if (`objExists $seqVertexArray[$i+1]`) $p1 = `xform -q -ws -t $seqVertexArray[$i+1]`; $distance += `mag(abs($p1 - $p0))`; $cvDistanceArray[$i] = $distance; if ($print) print ("Index: "+ $i + " Distance between vtx " + $seqVertexArray[$i] + " - " + $seqVertexArray[$i+1]); if ($print) print (" is: " + `mag(abs($p1 - $p0))` + "\n"); if ($print) print ("$cvDistanceArray["+$i+"] has value: " + $cvDistanceArray[$i] + "\n"); } $amount = (int) ($i/$endIndex*100); } if ($print) print ("total distance for Line is: " + $distance + "\n"); if ($print) print ("so now I get onto the real work, which is actually easy compared to all the crap I had to go though until now\n\n"); //the shifting of the UV's // float $baseUV[2]; select -r $seqVertexArray[0]; PolySelectConvert 4; // change selection to UV $baseUV = `polyEditUV -q -uValue`; // get base UV value if ($print) print ("number of total UV's to move: " + `size($selectedUVs)` + "\n"); $t = 1; for ($j = $startIndex ; $j <= ($endIndex + 1); $j++){ if (`objExists $seqVertexArray[$j]`){ select -r $seqVertexArray[$j]; PolySelectConvert 4; // to UV if ($print) print ("processing ... " + $seqVertexArray[$j] + " - \n"); string $selUV[] = `ls -sl -fl -type float2`; if ($print) print $selUV; string $uv; for ($uv in $selUV){ int $validUV[2]; $validUV = ttGetStringArrayPos($uv, $selectedUVs); if ($validUV[0] == 1){ // align along U or V if (($alignDir == "-v") || ($alignDir == "")){ select -r $uv; float $vValue = 0.00; if ($j == $startIndex){ $vValue = 0.00; } else { if ($mode){ // scale the values $vValue = ($cvDistanceArray[$j-1] * $scale); } else { // normalize the values $vValue = ($cvDistanceArray[$j-1]/$distance); } } polyEditUV -relative false -uValue $baseUV[0] -vValue $vValue; if ($print) print ("changing No " + $t + " " + $uv + " UV vValue to: " + $vValue + "\n"); $t++; } else if ($alignDir == "-u"){ select -r $uv; float $uValue = 0.00; if ($j == $startIndex){ $uValue = 0.00; } else { if ($mode){ // scale the values $uValue = ($cvDistanceArray[$j-1] * $scale); } else { // normalize the values $uValue = ($cvDistanceArray[$j-1]/$distance); } } polyEditUV -relative false -uValue $uValue -vValue $baseUV[1]; if ($print) print ("changing No " + $t + " " + $uv + " UV uValue to: " + $uValue + "\n"); $t++; } } } } } if ($keepSelection) select -r $selectedUVs; if ($print) print ("finished uvLine edit - check your results\n"); } else if (size($uniqueCVs) == 0){ // Woho, we have a continuous loop here, lets disect it, // if there is a split uv along the loop, lets use that as the start/end // // make a backup of the original vertex array as we are going to edit it from now on $evOrigArray = $edgeVertexArray; // local scope variables string $eString[1] = {""}, $nextCV, $vtx, $startUVmap, $endUVmap; int $j = 0, $t = 0, $findNext = 1; int $position[0]; int $break = 0, $partnerCVFound = 0; int $count = 0, $t = 0, $endCVfoundEarly = 0; int $tmpArrayPos[] = {1, 0}; // find any cut (double )uv's per vertex and then use that one! // // eliminate duplicate cv's for now $edgeVertexArray = stringArrayRemoveDuplicates($edgeVertexArray); for ($vtx in $edgeVertexArray){ select -r $vtx; PolySelectConvert 4; // convert selection to UV string $selUV[] = `ls -sl -fl -type float2`; if (size($selUV) == 2){ $nextCV = $vtx; $uniqueCVs[0] = $uniqueCVs[1] = $nextCV; $startUVmap = $selUV[0]; $endUVmap = $selUV[1]; // assuming here bigtime that we only have 2 UVmaps, else lets hope its the right one could do more in API if ($print) print ("found double UV on start CV " + $nextCV + "\n"); if ($print) print $selUV; break; } else if ($t == (size($edgeVertexArray)-1)){ $nextCV = $vtx; $uniqueCVs[0] = $uniqueCVs[1] = $nextCV; $startUVmap = $selUV[0]; $endUVmap = $selUV[0]; if ($print) print ("decided to use last CV as start CV " + $nextCV + "\n"); if ($print) print $selUV; break; } else { $nextCV = $vtx; $t++; } } $t = 0; // restore original edgeArray $edgeVertexArray = $evOrigArray; if ($print) print ("entering while-loop with start CV " + $nextCV + "\n"); // loop though all CV's and create spacially sequentially ordered array // while ($break == 0){ if ($print) print ("beginning of outer while loop iteration " + ($j/2+1) + " $nextCV = " + $nextCV + "\n"); // search for $nextCV in $edgeVertexArray and find edgeSharing CV // ignore if the connected CV is unique (the other end CV) // NEED TO LOOP HERE! // only evaluate if the element is found $t = 0; string $otherCV; // find partner CV Loop while ($findNext == 1){ // find nextCV in edgeVertexArray if ($nextCV == $edgeVertexArray[$t]) { if ($print) print ("index $t: " + $t + " - current CV: "+ $nextCV); float $fmod = `fmod $t 2.0`; if ($print) print (" fmod $t: " + $fmod); if ($fmod){ $otherCV = $edgeVertexArray[$t-1]; // PREVIOUS CV if (($otherCV != $uniqueCVs[0]) && ($j/2 < `size($edges)`)){ if (($otherCV == $uniqueCVs[1]) && ($endCVfoundEarly == 0)){ if ($print) warning "found end CV, but continuing\n"; $tmpArrayPos[1] = $uniqueCVs[0]; $findNext = 1; $endCVfoundEarly = 1; $t++; } else { $tmpArrayPos[1] = $t-1; // $tmpArrayPos[0] = 1; $t = 0; if ($print) print (" and prev edgeCV: " + $otherCV + "\n"); $findNext = 0; break; } } else { $tmpArrayPos[0] = 0; $break = 1; if ($print) warning "endCV detected in find NextCV loop\n"; $findNext = 0; break; } } else { $otherCV = $edgeVertexArray[$t+1]; // NEXT CV if (($otherCV != $uniqueCVs[0]) && ($j/2 < `size($edges)`)){ if (($otherCV == $uniqueCVs[1]) && ($endCVfoundEarly == 0)){ if ($print) warning "found end CV, but continuing\n"; $tmpArrayPos[1] = $uniqueCVs[0]; $findNext = 1; $endCVfoundEarly = 1; $t++; } else { $tmpArrayPos[1] = $t+1; $tmpArrayPos[0] = 1; $t = 0; if ($print) print (" and next edgeCV: " + $otherCV + "\n"); $findNext = 0; break; } } else { $tmpArrayPos[0] = 0; $break = 1; if ($print) warning "endCV detected in find NextCV loop\n"; $findNext = 0; break; } } } else { $tmpArrayPos[0] = 0; $t++; if ($t >= `size($edgeVertexArray)`){ $findNext = 0; if ($print) warning "array overrun, exiting nextCV Loop\n"; } } } // now order the array for the found tmpArrayPos[0,1] // if ($tmpArrayPos[0] == 0){ // if ($endCVfoundEarly == 1) $seqVertexArray[$j] = $uniqueCVs[1]; // // $break = 1; // if ($print) warning "loopEndCV detected, written into array as last value, exiting breakLoop\n"; // break; // } else { float $fmod = `fmod $tmpArrayPos[1] 2.0`; if ($fmod) { // if the position in the array is odd, we want the previous and current position // for this edge, the //$seqVertexArray[$j] = $edgeVertexArray[$tmpArrayPos[1]-1]; //$seqVertexArray[$j+1] = $nextCV = $edgeVertexArray[$tmpArrayPos[1]]; $seqVertexArray[$j] = $nextCV; $seqVertexArray[$j+1] = $nextCV = $otherCV; // remove the points from the array to reduce searching and doubling up of searches // this is ok as we are removing two at the same time // if ($print) { print ("fmod : " + $fmod + " - removing: " + $edgeVertexArray[$tmpArrayPos[1]-1] + " and " + $edgeVertexArray[$tmpArrayPos[1]] + " from array\n"); } $edgeVertexArray[$tmpArrayPos[1]-1] = ""; $edgeVertexArray[$tmpArrayPos[1]] = ""; $edgeVertexArray = stringArrayRemove($eString, $edgeVertexArray); if (($nextCV == $uniqueCVs[1]) && ($j > 0)) { $break = 1; if ($print) warning "endCV detected exiting 2nd loop\n"; break; } $findNext = 1; // reset find Loop } else { //$seqVertexArray[$j] = $edgeVertexArray[$tmpArrayPos[1]]; //$seqVertexArray[$j+1] = $nextCV = $edgeVertexArray[$tmpArrayPos[1]+1]; $seqVertexArray[$j] = $nextCV; $seqVertexArray[$j+1] = $nextCV = $otherCV; // remove the points from the array to reduce searching and doubling up of searches // if ($print) { print ("fmod : " + $fmod + " - removing: " + $edgeVertexArray[$tmpArrayPos[1]] + " and " + $edgeVertexArray[$tmpArrayPos[1]+1] + " from array\n"); } $edgeVertexArray[$tmpArrayPos[1]] = ""; $edgeVertexArray[$tmpArrayPos[1]+1] = ""; $edgeVertexArray = stringArrayRemove($eString, $edgeVertexArray); if (($nextCV == $uniqueCVs[1]) && ($j > 0)) { $break = 1; if ($print) warning "endCV detected exiting 2nd loop\n"; break; } $findNext = 1; // reset find Loop } if ($break == 1) break; $j += 2; } } if ($print) print "longArray CV's:\n"; if ($print) print $seqVertexArray; // remove any duplicates in array but first CV to last CV position $seqVertexArray = stringArrayRemoveDuplicates($seqVertexArray); if ($startUVmap != $endUVmap) $seqVertexArray[size($seqVertexArray)] = $seqVertexArray[0]; if ($print) print "order of CV's:\n"; if ($print) print $seqVertexArray; // now that we have sorted and identified individual line/CV order // lets get the additive distances between the points (ws) and fill another array // order will be [0] -> distance between cv[0] and cv[1] ... last CV in chain has total distance of line // vector $p0, $p1; float $distance = 0; float $cvDistanceArray[0]; $startIndex = 0; $endIndex = (`size($seqVertexArray)`-1); if ($print) print ("startIndex: " + $startIndex + "\n"); if ($print) print ("endIndex: " + $endIndex + "\n"); for ($i = $startIndex; $i <= ($endIndex); $i++){ // get worldspace positions of cv's // $p0 = `xform -q -ws -t $seqVertexArray[$i]`; if ($i+1 <= $endIndex){ if (`objExists $seqVertexArray[$i+1]`) $p1 = `xform -q -ws -t $seqVertexArray[$i+1]`; $distance += `mag(abs($p1 - $p0))`; $cvDistanceArray[$i] = $distance; if ($print) print ("Index: "+ $i + " Distance between vtx " + $seqVertexArray[$i] + " - " + $seqVertexArray[$i+1]); if ($print) print (" is: " + `mag(abs($p1 - $p0))` + "\n"); if ($print) print ("$cvDistanceArray["+$i+"] has value: " + $cvDistanceArray[$i] + "\n"); } $amount = (int) ($i/$endIndex*100); } if ($print) print ("total distance for Line is: " + $distance + "\n"); if ($print) print ("so now I get onto the real work, which is actually easy compared to all the crap I had to go though until now\n\n"); //the shifting of the UV's // float $baseUV[2]; select -r $seqVertexArray[0]; PolySelectConvert 4; // change selection to UV $baseUV = `polyEditUV -q -uValue`; // get base UV value if ($print) print ("number of total UV's to move: " + `size($selectedUVs)` + "\n"); $t = 1; for ($j = $startIndex ; $j <= ($endIndex + 1); $j++){ if (`objExists $seqVertexArray[$j]`){ select -r $seqVertexArray[$j]; PolySelectConvert 4; // to UV if ($print) print ("processing ... " + $seqVertexArray[$j] + " - \n"); string $selUV[] = `ls -sl -fl -type float2`; if ($print) print $selUV; string $uv; select -clear; for ($uv in $selUV){ int $validUV[2]; $validUV = ttGetStringArrayPos($uv, $selectedUVs); //need to put in test for start/end UV here if ($validUV[0] == 1){ // align along U or V if (($alignDir == "-v") || ($alignDir == "")){ if (($j == $startIndex)){ // start UV $uv = $startUVmap; } else if (($j == ($endIndex)) && ($startUVmap != $endUVmap)){ // end UV $uv = $endUVmap; } float $vValue = 0.00; if ($j == $startIndex){ $vValue = 0.00; } else { if ($mode){ // scale the values $vValue = ($cvDistanceArray[$j-1] * $scale); } else { // normalize the values $vValue = ($cvDistanceArray[$j-1]/$distance); } } polyEditUV -relative false -uValue $baseUV[0] -vValue $vValue $uv; if ($print) print ("changing No " + $t + " " + $uv + " UV vValue to: " + $vValue + "\n"); $t++; } else if ($alignDir == "-u"){ if (($j == $startIndex)){ // start UV $uv = $startUVmap; } else if (($j == ($endIndex)) && ($startUVmap != $endUVmap)){ // end UV $uv = $endUVmap; } float $uValue = 0.00; if ($j == $startIndex){ $uValue = 0.00; } else { if ($mode){ // scale the values $uValue = ($cvDistanceArray[$j-1] * $scale); } else { // normalize the values $uValue = ($cvDistanceArray[$j-1]/$distance); } } polyEditUV -relative false -uValue $uValue -vValue $baseUV[1] $uv; if ($print) print ("changing No " + $t + " " + $uv + " UV uValue to: " + $uValue + "\n"); $t++; } } } } } if ($keepSelection) select -r $selectedUVs; if ($print) print ("finished uvLine edit - check your results\n"); } else { error ("only select one edge line, the script doesnt do more than one line yet! \n"); } // change to uv component mode changeSelectMode -component; selectType -ocm -alc false; selectType -alc false; selectType -puv true; selectType -smu true; selectType -suv true; updateObjectSelectionMasks; updateComponentSelectionMasks; } } // END