PDA

View Full Version : Calculating UV shell area


DeadlyNightshade
08-12-2012, 12:51 PM
Ok so I know how to do this in theory, but what I need help with is the code.

The idea is to make a procedure that runs a set of command "for" each selected face.
The following is the pseudo code part:

$faces = polyEvaluate -f;

for each face/polygon(

select face
convert face selection to uv's
numPoints = selected uv count
enter each uv coordinate into two arrays, one for X and one for Y
(so that $X[0] is the X and $Y[0] is the y of the same coordinates)

Then run the following function (JAVA!! Has to be converted to MEL):
function polygonArea(X, Y, numPoints)
{
area = 0; // Accumulates area in the loop
j = numPoints-1; // The last vertex is the 'previous' one to the first

for (i=0; i<numPoints; i++)
{ area = area + (X[j]+X[i]) * (Y[j]-Y[i]);
j = i; //j is previous vertex to i
}
return area/2;
}

I started by looking up the Shoelace formula (aka Gauss area formula) which calculates the area of a polygon based on it's coordinates. But then I found out that someone has already made a computer algoritm for this at mathopenref:
http://www.mathopenref.com/coordpolygonarea2.html

Converting the JAVA to MEL is the lesser problem. My bigger problem is constructing a good for-loop that selects one face, inserts it's UV's into two arrays, runs the algoritm and then moves on to the next face in the selection.

Any help is appreaciated.

NaughtyNathan
08-12-2012, 04:30 PM
Maya already handles all of this, and both its internal API methods to do so and the MEL/py equivalents have already been discussed on this forum. Just do a search for UV area or similar and you should find what you need right here...

DeadlyNightshade
08-12-2012, 08:40 PM
I only find a thread explaining this functionality in Maya Python API.
I know that the Maya API class "MItMeshPolygon" has a function called getUVArea() that can be used for this. But I have no idea how to use that information in a MEL script - I know nothing about Python and nothing about Maya API/C++ (or PyMEL for that matter).

Anyways, I found out that someone has already made what I'm looking for:
gn_CalcUVStats - http://www.creativecrash.com/maya/downloads/scripts-plugins/c/gn_calcuvstats--2
And it uses the Maya Python API. However, that python script doesn't seem to work with every version of Maya - it works in 2012 but not 2009 for example (even though it claims to run in 2009).

CGTalk Moderation
08-12-2012, 08:40 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.