Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

In Mel looking for a way to rotate selected UV shells to always face the same way in the UV editor.

24 REPLIES 24
Reply
Message 1 of 25
malcolm_341
2899 Views, 24 Replies

In Mel looking for a way to rotate selected UV shells to always face the same way in the UV editor.

Hi everyone, I'm looking for a rock solid way to take an arbitrary UV shell and rotate it so it always faces the same way in the UV editor, V being Y-up basically. I've tried a number of solutions, but I can't seem to find a reliable way to calculate this. If it helps the UV shell will always be a perfect right angle alignment to start, but it needs to work on arbitrary models with arbitrary shapes and normal angles. Does anyone know a method of doing this? Image attached.

malcolm_341_0-1607819299432.png

 

24 REPLIES 24
Message 2 of 25
mcw0
in reply to: malcolm_341

Have you considered using "colorAtPoint" to sample the color value at each corner to determine which rotate action is required to orient the UVs?

Message 3 of 25
malcolm_341
in reply to: malcolm_341

I have not, and I've never heard of colorAtPoint, please explain further? How does it work there aren't any vertex colours on these objects.

Message 4 of 25
mcw0
in reply to: malcolm_341

Since you are using the same image, you can sample the image with `colorAtPoint -output RGB -u 0 -v 0 texturefile`.  Then sample at u=0:v=1 and if that's not enough, then another sample at u=1:v=0 and u=1:v=1.  Depending on the results, you can figure out whether to rotate you're uv shell, + or -.

Message 5 of 25
malcolm_341
in reply to: malcolm_341

Oh that's really interesting, let me look into this further and see if I can make it work.

Message 6 of 25
malcolm_341
in reply to: mcw0

So I looked into colorAtPoint and I'm not sure how this command could be helpful, unless I'm missing something it just returns the colour of the texture at the point you specify, it doesn't have any relation to the mesh UVs so the colours it returns are always the same no matter what UVs you give it. Any other suggestions, this may have worked if it used the mesh UVs.

Message 7 of 25
mcw0
in reply to: malcolm_341

Give this a try:

 

// SELECT THE FIRST VERTEX OF EACH MESH

string $sel[] = `ls -sl`;
string $map = stringArrayToString( ls("-flatten", `polyListComponentConversion -fv -tuv $sel[0]`), " ");
float $uvc[] = `polyEditUV -q $map`;

string $map1 = stringArrayToString( ls("-flatten", `polyListComponentConversion -fv -tuv $sel[1]`), " ");
float $uvc1[] = `polyEditUV -q $map1`;

string $parts[];
tokenize($sel[1], ".", $parts);
string $maps[] = `ls -flatten ($parts[0]+".map[*]")`;

if($uvc[0] < $uvc1[0])
    polyEditUV -pu .5 -pv .5 -angle -90 $maps;
else if($uvc[1] < $uvc1[1])
    polyEditUV -pu .5 -pv .5 -angle 90 $maps;

 

Before running code...select vtx[0]Before running code...select vtx[0]After running codeAfter running code

Message 8 of 25
malcolm_341
in reply to: malcolm_341

That code doens't work for me for whatever reason, it looks like there's a formatting errror so maybe something else was lost when it was pasted as text rather than code into this forum.

 

Also I should've mentioned my model consists of mutliple faces not just a single quad and each face is unitized. I'm basically trying to figure out how to get Maya's unitize command to return UVs that are all rotated the same way.

Message 9 of 25
mcw0
in reply to: malcolm_341

Are you getting errors?

Message 10 of 25
malcolm_341
in reply to: malcolm_341

Yeah looks like it is erroring out here

string $map1 = stringArrayToString( ls("-flatten", `polyListComponentConversion -fv -tuv $sel[1]`), " ");
// Error: line 1: No object matches name: //
// Error: line 1: Error evaluating argument at position 1 in procedure "stringArrayToString". //

Message 11 of 25
mcw0
in reply to: malcolm_341

Did you select vtx[0] on each mesh?
Message 12 of 25
malcolm_341
in reply to: malcolm_341

I did not, I selected only one mesh so I guess that was my problem sorry. The result was unfortunately undesireable after selecting two meshes, and vertex[0] on both though, it rotated the second mesh UVs the wrong way and left the first mesh UVs the way they were. I also don't have multiple meshes so it's not entirely clear if this method could solve my problem because I'm trying to figure out how to rotate one UV shell or a bunch of UV shells to all face the same way in UV space on a single mesh. Positive or negative doesn't matter though, I just want the arrows to face up or down and never sideways. Perhaps my initial diagram was confusing heres another image if helps, I would always like the UVs to face world space Y up.

malcolm_341_0-1610693441023.png

 

Message 13 of 25
malcolm_341
in reply to: malcolm_341

After much searching a found a semi-reliable way to achieve this with some built in Maya commands.

//Rotate shell so Yup is V in UV space
u3dLayout -res 256 -rot 4 -box 0 1 0 1 -ls 1;
//Select shell border and orient to fix rotation bug from above tool not aligning correctly
ConvertSelectionToEdges;
ConvertSelectionToShellBorder;
texOrientEdge;
Message 14 of 25
spaehling
in reply to: malcolm_341

looking for the exact same feature. Sadly your latest solution didn't worked for me. Any hints? I mean it runs the "Orient to Edge" command, but it still not correctly rotated. Makes me a bit crazy 🙂

Message 15 of 25
malcolm_341
in reply to: spaehling

I found a solution to my problem that didn't need shell rotation so I stopped working on this issue. That said, the closest I got was getting the shells to orient Y up, but sometimes they would be Y+ and Y- and the layout command wouldn't work because you have to select between two modes, orient Y straight and orient Y angled. I guess Maya has two different commands if the geometry is right angled or if it's diagonal and you have to choose which command to use for the appropriate shape. Also that won't help with figuring out how to get the sell Y+ it will just randomly make the shell Y aligned.

 

Here are the commands if you want to research further

 

//Orient Y
u3dLayout -res 64 -rot 4 -trs 1 -spc 0.0078125 -mar 0.00390625 -box 0 1 0 1 -ls 1;

 

 //Orient V
u3dLayout -res 64 -rot 2 -trs 1 -spc 0.0078125 -mar 0.00390625 -box 0 1 0 1 -ls 1;

 

 

 

 

Message 16 of 25
spaehling
in reply to: malcolm_341

Hey, 
thanks for your quick answer. I also kept up looking for a solution meanwhile. So was also looking for tools out there and found "Polyraven UV tools". There is a function inside, that does exactly what we want. I work mostly with Z up and works really well for me. The price was at least worth avoided headache the rest of the day, week or whatever :).
I mean not the best solution, but at least it helped me.

spaehling_0-1657733435004.png

 

Message 17 of 25
malcolm_341
in reply to: spaehling

Oh interesting, but does it always work even on geometry that is diagonal. I had already added orient X, Y, Z and horizontal, vertical to my UV tool a while back. I'm wondering if the polyRaven is any better in that respect? You can check out my tool here https://youtu.be/exrJNgaqb20?list=PLAUgGUDpaMENfz8Nd7Zw-LxDK_v5ZflY6&t=104

Buy the script here https://gumroad.com/malcolm341 Click here to subscribe https://www.youtube.com/malcolm341?sub_confirmation=1 New features: -Select UV shells that overlap between tiles -Auto select shells that overflow into the next tile after packing -World space to next now works on XYZ axes
Message 18 of 25
spaehling
in reply to: malcolm_341

about diagonal. That is a good question. So if i understood you correct, yes it works. See screenshot.
Edit: other side of the mesh looks similar. If you have more questions, let me know.

spaehling_0-1657736649513.png

 

Message 19 of 25
malcolm_341
in reply to: spaehling

Could you try making a rectangle geometry in the front view and duplicate and rotate it 20 degrees so it's on an angle, then freeze transforms on both and planar from the front view. Then try the polyRaven button and see if it makes both shapes align correctly.

Message 20 of 25
spaehling
in reply to: malcolm_341

spaehling_0-1657753245189.png

If i did it correct, it worked yes.This are the following steps i did:
1. create both cube (both 1m)
2. rotate left one by 20 degrees
3. Freeze Transformations on both
4. Auto Mapping so each face is single
5. stack sheels (not needed)
6. used the tool exacttly like in my first screenshot in my post above. (UV Space: Auto and World Space Z).

On a car i worked on today, i had the situation where i not worked on the first time. i switched to Hor. instead of auto, clicked, switched back to auto, clicked again and then it worked.

let me know if you have more questions. i hope i don't celebrate to early for you, but for me it works like i want. 🙂
Greets Spaehling

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report