Monday 16 April 2018

scaling UV code, around the centre of selection instead of 0,0

Original code stolen from
http://polycount.com/discussion/172364/maya-mel-scale-uv-shells-locally-script-for-anyone-that-wants-it


//store uvs into array
float $uvvalues[] =`polyEditUV -q`;
int $selSize = `size ($uvvalues)`;

//split array into U and V
float $Uarray[];
float $Varray[];

//copy U and V arrays with values
for($u = 0; $u < $selSize; $u++) {
          $Uarray[size($Uarray)] = $uvvalues[$u]; 
          $u=$u+1;
}

for($v = 1; $v < $selSize; $v++) {
          $Varray[size($Varray)] = $uvvalues[$v]; 
          $v=$v+1;
}

//sort arrays by coords and get size of array
$Uarray = `sort $Uarray`;
$Varray = `sort $Varray`;
int $UarraySize = `size ($Uarray)`;

//get max values
float $maxNuU = $Uarray[$UarraySize-1];
float $maxNuV = $Varray[$UarraySize-1];

//get min values
float $minNuU = $Uarray[0];
float $minNuV = $Varray[0];

//calculate centre values
float $middleU = ($maxNuU + $minNuU)/2;
float $middleV = ($maxNuV + $minNuV)/2;

polyEditUV -pu $middleU -pv $middleV -su .2 -sv .2;