Hey guys
i wanted to start learning scripting, and that's why i want to write a small script helping me UV unwrap
what i want to create is a tool that allows me to select 2 vertices in my uv editor and align them on the U or V axis by rotating the entire cluster.
could you guys help me or give me any advice how to start with something like that?
thank you guys in advance!
Replies
If you still want to code this yourself then you need to calculate the arc tangent in degrees. You will get a result ranging between -90 and +90 degrees - which is the value that you need to orient the UV shell. Use a switch-statement (MEL) or a big if/elif/else -statement (Python). Also, before orienting you wanna calculate the centerpoint of the bounding box of the selection. This can be done with polyEvaluate() using the boundingBoxComponent2d -flag.
Also if you wanna do this on multiple shells then you need to create a function which calculates all UV shells in the selection. This can be done by the function getUvShellsIds() on a mesh (Python only).
But basically just store the X/Y of each vertex, treat them as a right triangle to get their X/Y distances and hypotenuse, then get the rotation angle in degrees and rotate the entire shell based on that.
no i never scripted before
are there any tutorial out there, where i could learn what i need to konw to write such a script?
[ame="http://www.amazon.com/Maya-Python-Games-Film-Reference/dp/0123785782"]Maya Python for Games and Film: A Complete Reference for Maya Python and the Maya Python API: Adam Mechtley, Ryan Trowbridge: 9780123785787: Amazon.com: Books[/ame]
float $uv1[]=`polyEditUV -q $listuv[0]`;
float $uv2[]=`polyEditUV -q $listuv[1]`; //
This should save you a couple of lines
float $uvresult[];
$uvresult[0]=`abs ($uv2[0]-$uv1[0])`;
$uvresult[1]=`abs ($uv2[1]-$uv1[1])`;
float $angle=`atan ($uvresult[1]/$uvresult[0])`;
$angle=`rad_to_deg ($angle)`; //
And there you have the angle
polyEditUVShell -pu $uv1 [0] -pv $uv1[1] -r 0 -a $angle;
thats what i have so far ...
somehow it works somethimes, and sometimes not
can you guys tell me where i made the mistake?
For more accuracy you may want to use Python's Math module. It gives you similar atan method along with pi and degrees.
why is is more accurate to use python?
and whats the difference?
markup menus do not support phyton -.-
Accuracy - when you have 2 positions of a straight line, you can use math to find the exact angpe that line is doing. You know, math stuff. Python offers you the function to do exactly that.
In a sense you can re-write that function yourself if you know the math behind it.
i'm talking about the marktin menu in maya, my bad
-Much faster (something which becomes clear when you deal with many objects/components or perform math-based operations)
-Much better syntax - more readable and not as hard to fuck up with
-You still have access to all MEL-commands via the python modules pymel.core.mel and maya.mel
-Classes
Then, when you need even more speed you will have to learn the Maya API and C++ (you can code Maya API with python as well but the usage is more limited. With C++ you have full access to Maya's API)
I started out learning MEL, then Python > Maya.cmds > PyMEL and now I really don't see ANY use of MEL unless you want to become a
Technical Artist. Python is simply less troublesome.
Now, you still need to get your head around the Maya commands so learning MEL isn't a waste obviously. Just don't get too caved-in on it.