PDA

View Full Version : How to space columns of UVs evenly


goodvibrato
06-11-2010, 07:26 PM
I was wondering if I could get some help with a script I'm writing to sort out my UVs. First let me show you a picture of the UVs so I can explain better what I'm trying to do.
http://img38.imageshack.us/img38/1631/uvs.png (http://img38.imageshack.us/i/uvs.png/)
As you can see, the spacing between the vertical lines is different and I want them all to be the same. I had an idea to position groups of vertical UVs to the grid, but as far as I can tell I only have to choices: Move them with -r false, which will end up putting the entire group on top of each other, or move them with -r true, which works, but doesn't help me because I will just move all the lines left or right and they will look just the same.

I've also thought of moving each UV one by one by just pickwalking, but the pickwalk will go in erratic directions. For example, I'll click the UV at the top left corner, pickwalk down, but it will stop at the 3rd or 4th vertex. Sometimes it will even do the opposite of what I tell it. I'll pickwalk down and it will go up, so I'm not sure what to do. Any ideas would be appreciated. Thanks.

goodvibrato
06-11-2010, 09:45 PM
Been working on this and I've got something that works pretty well. Figured out I could just put the UV information of a group into an array and then just change every other value so that the U is modified, but not the V. Here's the code in case anyone is interested. You first go into edge mode and click any vertical edge for a starting point. Then just run the script. It will iterate 10 times to evenly space 10 lines of UVs. The problem I'm getting now is the edgeloop pickwalking is not always consistent. The code tells it to always go right, but sometimes it will go left, which messes everything up.

string $selectFirst[] = `ls -sl`;
pickWalk -d right -type edgeloop;

for ($j = 0; $j < 10; $j++)
{
pickWalk -d right -type edgeloop;
string $selectNext[] = `ls -sl`;
pickWalk -d left -type edgeloop;
ConvertSelectionToUVs;

float $moveUVs[] = `polyEditUV -q`;

// moves the next line 0.005 units to the right
for ($i = 0; $i < size($moveUVs); $i++)
{
$moveUVs[$i] = $moveUVs[$i] + 0.005;
$i++; // skips the V coordinate
}

// select UVs to move
select $selectNext;
ConvertSelectionToUVs;

for ($x = 0; $x < size($moveUVs); $x++)
{
polyEditUV -r false -u $moveUVs[$x];
$x++; // skips the V coordinate
}

$selectFirst = $selectNext;
select $selectFirst;
}

goodvibrato
06-12-2010, 03:56 AM
Ok, I've pretty much gotten this script to work. To make up for the fact that sometimes pick walking will go the opposite direction I just test the current U and the next U. If the current U is higher than the next U, then I know it went left instead of right (since I'm sorting these in the positive U direction). The only thing I don't understand now is why on the first column of vertices I have to pick walk twice instead of once. After that it accepts one pick walk command just fine. That means basically I'd need 2 versions of the script, one for starting on the very first edge, and then one for any "between" edges. Also, I think there might be a memory leak somewhere because if I do about 2-300 iterations it will start off fast, but get slower and slower until my computer crashes. Even after the script has stopped and I have closed Maya, my computer is still really slow. So, if you run it I'd recommend just keeping the iterations to 10. Here's what I've got so far:

// declare variables
string $selectFirst[];
string $selectNext[];
float $initialUVs[];
float $firstU;
float $nextUVs[];
float $nextU;
float $moveUVs[];

PickWalkRight;
$selectFirst = `ls -sl`;
ConvertSelectionToUVs;
$initialUVs = `polyEditUV -q`;
$firstU = $initialUVs[0];
select $selectFirst;

//PickWalkRight;

for ($j = 0; $j < 10; $j++)
{
PickWalkRight; // move to right adjacent edgeloop
$selectNext = `ls -sl`; // store it for later
ConvertSelectionToUVs;
$nextUVs = `polyEditUV -q`; // store UV selection
$nextU = $nextUVs[0]; // store a U coordinate

print ($nextU - $firstU); // should be .005 every time

// if the above line reads -0.005 then the firstU is higher than the nextU
// which means the PickWalk went the wrong way. We make it go the right way.
if ($firstU > $nextU)
{
select $selectFirst;
PickWalkLeft; // Pick walk left instead of right this time
$selectNext = `ls -sl`; // store it for later
ConvertSelectionToUVs;
$nextUVs = `polyEditUV -q`;
$nextU = $nextUVs[0];
}

select $selectFirst; // move back to initial edgeloop
ConvertSelectionToUVs;

$moveUVs = `polyEditUV -q`; // store current UV info

// add .005 units to the U of current UV info
for ($i = 0; $i < size($moveUVs); $i++)
{
$moveUVs[$i] += 0.005;
$i++; // skips the V coordinate
}

// select UVs to move
select $selectNext;
ConvertSelectionToUVs;

// move the UVs
for ($x = 0; $x < size($moveUVs); $x++)
{
polyEditUV -r false -u $moveUVs[$x];
$x++; // skips the V coordinate
}

// progress to the right
$selectFirst = $selectNext;
$firstU = $nextU;
select $selectFirst;

print ("\n///////////////////////////////////// Iterations: " + ($j+1) + "\n");
}

goodvibrato
06-13-2010, 05:00 PM
Here is the latest version of the script. I found that if I disable undo, my computer won't slow down. I have Maya set for unlimited undo, so that's probably where the problem was. The undo lines are commented out since I have it currently set to do 5 iterations. To change the iterations just give the $iterations variable a new value.

Also, the first edge and the last edge are the only problem. The first edge is the only edge where I have to tell it to pickwalk twice. I just made it to where if you start with the first edge nothing happens. If you start with the next edge it should work just fine. As far as the last edge, in order to get even spacing you have to make sure it's the last edge the script reads. If the script tries to pickwalk from the last edge, strange things happen.

// declare variables
string $selectFirst[];
string $selectNext[];
float $initialUVs[];
float $firstU;
float $nextUVs[];
float $nextU;
float $moveUVs[];
int $iterations = 5;

// disable undo
//undoInfo -state 0;

$selectFirst = `ls -sl`; // see what is selected

// if only one edge is selected get the rest
print (size($selectFirst));
if (size($selectFirst) == 1)
{
PickWalkRight; // get the rest of the edges
$selectFirst = `ls -sl`;
ConvertSelectionToUVs;
$initialUVs = `polyEditUV -q`;
$firstU = $initialUVs[0];
select $selectFirst;
}
else
{
ConvertSelectionToUVs;
$initialUVs = `polyEditUV -q`;
$firstU = $initialUVs[0];
select $selectFirst;
}

for ($j = 0; $j < $iterations; $j++)
{
PickWalkRight; // move to right adjacent edgeloop
$selectNext = `ls -sl`; // store it for later
ConvertSelectionToUVs;
$nextUVs = `polyEditUV -q`; // store UV selection
$nextU = $nextUVs[0]; // store a U coordinate

// calculation should be positive
print ("\nDistance between Us is: " + ($nextU - $firstU) + "\n");

// if the above calculation is zero, pickwalking didn't work and the same edge
// has been selected twice. Don't do anything. Only happens on the first (left most)
// edge that I can tell.
if (($firstU - $nextU) == 0)
{
print ("\n--------- Stopped at " + ($j + 1) + " iterations --------------\n");
$j = $iterations; // end the script
}
else if ($firstU > $nextU)
{
// if the above calculation is negative then the firstU is higher than the nextU
// which means the PickWalk went the wrong way. We make it go the right way.

select $selectFirst;
PickWalkLeft; // Pick walk left instead of right this time
$selectNext = `ls -sl`; // store it for later
ConvertSelectionToUVs;
$nextUVs = `polyEditUV -q`;
$nextU = $nextUVs[0];
}

if ($j != $iterations)
{
select $selectFirst; // move back to initial edgeloop
ConvertSelectionToUVs;

$moveUVs = `polyEditUV -q`; // store current UV info

// add .005 units to the U of current UV info
for ($i = 0; $i < size($moveUVs); $i++)
{
$moveUVs[$i] += 0.005;
$i++; // skips the V coordinate
}

// select UVs to move
select $selectNext;
ConvertSelectionToUVs;

// move the UVs
for ($x = 0; $x < size($moveUVs); $x++)
{
polyEditUV -r false -u $moveUVs[$x];
$x++; // skips the V coordinate
}

// progress to the right
$selectFirst = $selectNext;
$firstU = $nextU;
select $selectFirst;

print ("\n================================= Iterations: " + ($j+1) + "\n");
}
}

// re-enable undo
//undoInfo -state 1;

CGTalk Moderation
06-13-2010, 05:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.