View Full Version : Copying values to uvs.

06 June 2012, 02:59 PM

I am trying to write a small script to copy vertex colors to UVs. The problem I am having is I want to efficiently copy the vertex value to the uv position. I can do something like this but its slow becuase it has to go through each vert individually and perform the operations, so for 100k+ verts it takes forever.

PolySelectConvert 3;
string $vertices[]=`ls -sl -fl`;
for ($vert in $vertices)
select $vert;
float $red[] = `polyColorPerVertex -q -r`;
PolySelectConvert 4;
polyEditUV -r 0 -u $red[0] ;

I want to do something where I copy and paste the whole array into the UVs. I think the code below is on the right track but I have a syntax error becuase it wants the array $red to be $red[0]. I dont want to copy just the first value of the array but the whole array to I guess an array of UVs. Is this possible?

PolySelectConvert 3;
float $red[] = `polyColorPerVertex -q -r`;
PolySelectConvert 4;
polyEditUV -r 0 -u $red;

06 June 2012, 03:07 AM
Hi fghajhe,

Maybe you can try the polyCopyUV command instead.

06 June 2012, 04:29 AM
Thanks for the reply.

The polyCopyUV command only seems to work in copying one uv set to another.

06 June 2012, 09:17 AM
you are currently doing twice-or more the amount of work in your script as it is. DO NOT change selection in your scripts (especially in a loop) if you want to maintain any kind of efficiency. The following is dumb, inefficient code:
select $something;
performCommand -flags;and this is how to do it properly:
performCommand -flags $something;Additionally, any MEL "command" that starts with a CAPITAL letter (i.e. PolySelectConvert) is not actually a command, but a RunTimeCommand (or script) and is likely to also be very ineffcient (as they are designed purely for convenience, not efficiency)

Finally, polyColorPerVertex returns 3 (or 4) floats but polyEditUV only takes 2, so you are still going to have to pass in a partial array, which means the most likely solution would be to construct a command string and then eval() it.
However, polyEditUV will not allow you to set different values on different UVs in a single execution, so you may need to set the uvs via setAttr (a lot of data on a mesh is ultimately just attributes that can be get and set, so you can do a setAttr to set an array of UVs)

First I'd just try removing all the PolySelectConvert and select commands from your script to see if that helps (it may not btw), then turn off undo before you start (and then back on again using undoInfo command). If neither of these help then you may have to try constructing a command string and using setAttr, but can be quite messy, and not guarenteed to give you a massive increase either. You may have to go into the API for performance increases on 100K+ vert meshes.

06 June 2012, 12:52 PM
thanks for your repsonse and great info! I will look into it and see what happens.

CGTalk Moderation
06 June 2012, 12:52 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.