PDA

View Full Version : Getting the values of the U and V cordinates of a UV point?


H3ro
02-15-2006, 09:15 PM
Is it possible to get the values of the U and V cordinates of a UV point using a mel comand?

Like you can do to get the XYZ cordinates of a PolyCube
xform -query -worldSpace -translation pCube1


The final goal will be to create a expresion like
polyCube1.vertex1_position = << UVpoint1.U, UVpoint1.V ,0 >>;
polyCube1.vertex2_position = << UVpoint2.U, UVpoint2.V ,0 >>;

(Yes i know that scrip is mostly one big error, but I hope you people will see what I tend to do)

el diablo
02-16-2006, 05:19 AM
polyEditUV

H3ro
02-16-2006, 10:39 AM
this is what i have so far:

//selection
select -r pCube1.vtx[2];

//determin the Map
$uvMap = `polyListComponentConversion -fv -tuv`;
print $uvMap;


// Query the UV for this mapping.
polyEditUV -q $uvMap;


How can I store the value gained from the last line? So I can use it later. Eg something like :
"vector $uvCord = polyEditUV -q $uvMap;" (again i know this is completly wrong, but it is just to illustrate what i try to do)
then I could do $uvCord.U and $uvCord.V

Clanker
02-16-2006, 11:12 AM
A vector is an array of three values.

Simply use an array.

float $uv[2]=`polyEditUV -q $uvMap`;
print $uv[0];
print $uv[1];


But depending of your uv's unfold, more than one uv could be affected to one vertex, so you'll have more than 2 values in $uvmap.

H3ro
02-16-2006, 11:38 AM
Thanke you a lot :)

Here is the update:

//Selection
select -r pCube1.vtx[2];

//Determin the Map
$uvMap = `polyListComponentConversion -fv -tuv`;
print $uvMap;


// Query the UV for this mapping
float $uv[2]=`polyEditUV -q $uvMap`;
print $uv[0];
print $uv[1];

//using the UV position for the position of the vertex
setAttr "pCubeShape1.pnts[2].pntx" $uv[0];
setAttr "pCubeShape1.pnts[2].pnty" $uv[1];
setAttr "pCubeShape1.pnts[2].pntz" 0;


I have some more questions:
1. How to if $uvMap is more then one, then stop the script and return a error
2. How to make it work for any vertex selected, not just vertex 2?

Im still learning MEL, so im super thankful for the help.

A_New_Hope
02-16-2006, 12:36 PM
1. How to if $uvMap is more then one, then stop the script and return a error

check the size of the $uvMap array

if ( size( $uvMap ) != 1 )
{
error "more then one";
}


2. How to make it work for any vertex selected, not just vertex 2?

just skip the "select -r pCube1.vtx[2];" line, then it work on any vertex that is selected
but then you must select vertex by hand and you dont wont that do you?

Clanker
02-16-2006, 12:50 PM
I'm still learning too ;)

1 :

if (size($uvMap)>1) //return the size of the string array $uvmap
{
error "More than one UV on selected vertex";
}

2 :

If you select more than one vertex :

string $sel_vertices[] = `ls -sl`; //list selected components
for ($vertex in $sel_vertices)
{
print ($vertex + "\n");
//instructions
}

If you select just one vertex :

string $sel_vertice[] = `ls -sl`;
print $sel_vertice[0];

Ooops sorry...The same answer :)

H3ro
02-16-2006, 03:56 PM
Wow, I realy have to thank you guys for great help so far. Your my heros :D

but, as always, there is more :P

This time I writen the question in the expression, so it will be easyer to see where and what I need the changes to be made

------------------------------

//Selection
string $sel_vertices[] = `ls -sl`;


//list selected components
float $ShowSelected = 0;

if ($ShowSelected ==1)
for ($vertex in $sel_vertices)
{
print ($vertex + "\n");
}



//Determin the Map
$uvMap = `polyListComponentConversion -fv -tuv`;
print $uvMap;


//return the size of the string array $uvmap
if (size($uvMap)>1)
{
error "More than one UV on selected vertex";
}

//is there a way to change so that "if (size($uvMap)>no of vertex)"
//as it is now, it will return an error if one then more vertex is selected
//so i want ti display if a spesefic vertex has more then one map, and list all the
//vetex with more then one



//how can i get this part who follows here to be applyed to all selected vertexec? As it is now
//it only return the value of one. I would also like to have a command like :
// "print Vertex1UV = 1 1
// Vertex1UV = 1 2


// Query the UV for this mapping
float $uv[2]=`polyEditUV -q $uvMap`;
print $uv[0];
print $uv[1];

//using the UV position for the position of the vertex
setAttr "pCubeShape1.pnts[2].pntx" $uv[0];
setAttr "pCubeShape1.pnts[2].pnty" $uv[1];
setAttr "pCubeShape1.pnts[2].pntz" 0;

-------------------

Thanks again :)

Clanker
02-16-2006, 05:51 PM
Still can't see clearly what do you tend to do...
Unfolding your mesh regarding your UV's ?

H3ro
02-16-2006, 06:08 PM
Yes, that is what i want. I want to use the position of the UV on the Vertex

1. Make a poly object
2. make a UV map for that object
3. Use the UV map to modefy the poly object

So say this is the positon of the vertex <<1,0,0>>
then i want o change it to <<U,V,0>>

so, I kind of unwrap my object inside of the veiw port

I hope that make some sense?

If not, you could allways add me on msn, I might be able to help some of you an other day (just not with mel maybe :P)

http://www.storedyret.com/iB_html/uploads/post-8-18205-what_i_want.JPG

Clanker
02-17-2006, 11:12 AM
Ok, this is my very simple solution.
I'm not a mel professional, so this script is not very clean, because of the components conversions, but it runs !:)

Select your mesh and run the script.

global proc unfoldmesh()
{
string $sel[]; //a variable to store selected vertices
string $obj[]=` ls -sl`; //a variable to store your mesh
polyChipOff -kft false -dup false; //extract all faces, so there's just one uv affected on each vertex
ConvertSelectionToVertices; //convert the mesh to vertices
$sel = `ls -sl -fl`; //list vertices

for ($s in $sel) //for a vertex in vertices
{
select $s; //select the current vertex
ConvertSelectionToUVs;
string $uvMap[]=` ls -sl`;
float $uv[2]=`polyEditUV -q $uvMap`;
ConvertSelectionToVertices;
move $uv[0] $uv[1] 0;
}

select $obj;
ConvertSelectionToVertices;
polyMergeVertex -d 0.0001;
}

H3ro
02-17-2006, 01:57 PM
Wow thanks man :)

But there is an error in the script, it does not return a syntax error, but nothing really happes.
I think there is an error in this part of the script, as if i only use the first part, the object splits into different faces. And if i use the last part as well it is all merged again

----

for ($s in $sel) //for a vertex in vertices
{
select $s; //select the current vertex
ConvertSelectionToUVs;
string $uvMap[]=` ls -sl`;
float $uv[2]=`polyEditUV -q $uvMap`;
ConvertSelectionToVertices;
move $uv[0] $uv[1] 0;
}

---

The idea with spliting into faces was superb :D

Thanks

EDIT : the object i tryed to use the script on was a polySylinder where i had deleted the top and bottom faces

Clanker
02-17-2006, 04:08 PM
I've no trouble...The script works well for me :$

H3ro
02-17-2006, 04:14 PM
What version of maya do you use? Have you tried with a cylinder?

I use maya 7.0

EDIT: A dude i know tested it in maya 6, it worked there

EDIT2: By removing the "global proc unfoldmesh()" line, the script workes perfect


Thanks a lot :D

(This bosted my inderstanding of mel, thanks )

Clanker
02-18-2006, 11:47 AM
:)
Hi guy,
a global proc is just a fonction (a procedure) that encapsulate your script. Execute the script, then execute the name of the proc:

unfoldmesh;

If your script is in a maya script directory, you don't need to execute it each time, just enter the name of your main fonction.

CGTalk Moderation
02-18-2006, 11:47 AM
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.