How to calculate the area of a face in UV

How to calculate the area of a face in UV

243202504
Enthusiast Enthusiast
2,088 Views
12 Replies
Message 1 of 13

How to calculate the area of a face in UV

243202504
Enthusiast
Enthusiast

Solved: How to return to UV after selecting the face. - Autodesk Community - Maya

here raise the new problem!

I selected a face, and this face is composed of 4 vertices, 0, 1, 2, and 3. Then I went to get the coordinates of these 4 vertices from the UV, which can also be obtained. Unfortunately, the original model is a quadrilateral surrounded by 0, 2, 3, and 1 in order. The resulting list of UV coordinates is in the order of 0, 1, 2, 3, so I got the wrong value when calculating the area.

cmds.select(cmds.polyListComponentConversion(tuv = True))
lUVCoordinate = cmds.polyEditUV(query = True, relative=False)
print lUVCoordinate

So is there a better way to get the UV area or get these points in order. The Helen formula I used to calculate the area. Also, if they are all triangles, there is no such problem. However, the model has triangular and quadrilateral faces. If the length of the side is wrong and the diagonal is taken, the calculation will be wrong.

Accepted solutions (1)
2,089 Views
12 Replies
Replies (12)
Message 2 of 13

243202504
Enthusiast
Enthusiast

I tried to loop the sides of the face after selecting the face so that the diagonal line is not selected. This method can solve the problem, but it is very troublesome.

0 Likes
Message 3 of 13

mcw0
Advisor
Advisor

Why not triangulate your model first?  

0 Likes
Message 4 of 13

243202504
Enthusiast
Enthusiast

The model was not made by me, and I don't know how to convert it into a triangle.

0 Likes
Message 5 of 13

mcw0
Advisor
Advisor

polyTriangulate.  You can give it specific faces.

Message 6 of 13

243202504
Enthusiast
Enthusiast

aha,This command does make it more convenient for me to calculate the area, but I don't have the permission to change the model.I can only calculate the area of each surface UV when the triangles and quadrilaterals exist at the same time.

 

0 Likes
Message 7 of 13

mcw0
Advisor
Advisor

Try duplicating the mesh.  Use the duplicate to do any alterations to facilitate getting what you want.

0 Likes
Message 8 of 13

243202504
Enthusiast
Enthusiast

This is a method, but it is not what I want. I have tried to convert the model to a triangle. The number of cycles required to traverse the loop has doubled. It can't help me to write this method at the beginning to speed up, because although the speed It's very fast, but the increase in the number of loops causes the actual running time of the code to not change much.

0 Likes
Message 9 of 13

243202504
Enthusiast
Enthusiast

I currently think that if I can find the api corresponding to MAYA-Python or use the shader, it should be solved, but I can't find the relevant information. I temporarily used Python's powerful data processing functions to complete the code.

0 Likes
Message 10 of 13

mcw0
Advisor
Advisor

Sorry I don't quite understand your reply.  It sounds like you said the script is reasonably fast and the increase in the number of loops hasn't impacted the running time of the script.  So I'm not sure what the problem is.

 

I'm not sure if I made it clear that you don't have to triangulate the entire model.  You can just triangulate the quads that you want to query.  This might speed things up a bit.

0 Likes
Message 11 of 13

243202504
Enthusiast
Enthusiast

At the beginning, I made a script to query the accuracy of each facet of the model and put different colors on it. Because of the query accuracy, mel is called, so it is very slow.

 

density = mel.eval('texGetTexelDensity(%i)' % map_size)

 

I found that 80% of the code time was spent on this line. I want to speed up, so I implement the method to get the model pixel accuracy by myself.

When writing the code to calculate the pixel accuracy, I encountered many problems. One of them is that when calculating the four sides, after the four points of the UV are taken, the program does not know how to form a quadrilateral, and the side lengths obtained are not correct, resulting in some sides. Calculating the UV area will be wrong. But this error is completely random. I solved this problem through Python, constructing List and other methods, and finally completed this function without an error, but the code is very long, so I come to ask for help, is there any command that allows me to get the four sides directly or very quickly UV area.

Converting four-sided faces to triangular faces is a way to avoid errors in area calculation. However, a model equivalent to 10,000 faces originally only needs to calculate 10,000 cycles, but now it needs 20,000 cycles. For what you said, it is not necessary to perform quadrilateral to triangle operation on every face. Because I don’t know which quadrilateral the problem will occur, sometimes I don’t report an error, but in fact, because the side length is wrong, the calculation accuracy is wrong. I have to calculate every face, so I loop like this The frequency will double.

Thank you for your answer. I have gained more knowledge, that is, you can use cmds.polyTriangulate() to turn a quadrilateral into a triangle, but my ultimate goal is to make my code run faster and the data obtained is okay, so this is not what I want .

 

0 Likes
Message 12 of 13

mcw0
Advisor
Advisor
Accepted solution

I didn't test the following.  I just typed it out here.  But I believe the logic is sound.  I gathered from your reply that the issue is sorting the edges/sides of a face so that you can be guaranteed of getting the correct result from your area calculation.

 

string $face = "mesh.f[0]";

string $edges[] = ls("-flatten", `polyListComponentConversion -ff -te $face`);

string $orderedEdges[];

//  ARBITRARY STARTING EDGE

$orderedEdges[0] = $edges[0];

//  LOOP THROUGH REMAINING EDGES TO GET ORDER

string $pts[] = ls("-flatten", `polyListComponentConversion -fe -tv $orderedEdges[size($orderedEdges)]`);

//  REMOVE STARTING EDGE FROM EDGES

$edges = stringArrayRemove($orderedEdges, $edges);

while(size($edges))

{

    //  LOOP THROUGH REMAINING EDGES TO FIND NEXT EDGE

    for($edge in $edges)

    {

       //  CONVERT EDGE TO VERTS TO MATCH LAST VERTEX

        string $pts1[] = ls("-flatten", `polyListComponentConversion -fe -tv $edge`);

        //  IF REMOVING THE LAST VERTEX FROM PTS LIST FROM PTS1 RESULTS IN ONLY 1 VERTEX,

        //  THEN NEXT EDGE FOUND

        if(size(stringArrayRemove({$pts[size($pts)-1]}, $pts1))==1)

        {

            //  UPDATE ORDERED EDGES

            $orderedEdges[size($orderedEdges)] = $edge;

            //  UPDATE EDGES

            $edges = stringArrayRemove($orderedEdges, $edges);

            //  UPDATE PTS LIST

            $pts = stringArrayRemoveDuplicates(stringArrayCatenate($pts, $pts1));

        }

    }

}

 

//  EDGES IN ORDER

print $orderedEdges;

 

 

Message 13 of 13

243202504
Enthusiast
Enthusiast

I don't use Mel, but I translated it. The method you use is what I am using now. After selecting the four vertices, get the coordinates, and then select the edges to get the coordinates. After the comparison, remove the extra point coordinates.

Sorry, my native language is not English, I use Google Translate to communicate with you.

 

0 Likes