Getting mesh triangles in Python API?

Getting mesh triangles in Python API?

Anonymous
Not applicable
2,036 Views
1 Reply
Message 1 of 2

Getting mesh triangles in Python API?

Anonymous
Not applicable

I'm trying to get mesh information to build a custom exporter. I found this link: Polygon_API_Handled_Internally and I've been able to retrieve the vertex indicies, and points using:

 

vertIndices = cmds.getAttr( mesh + ".vrts" , multiIndices=True )
verts = []
for i in vertIndices:
verts.append( cmds.xform( str( mesh ) + ".vtx[" + str( i ) + "]", query=True, translation=True, worldSpace=True ) )

 Is there a way to retrieve all triangles for a mesh? Should I be using OpenMaya? I can't seem to find any clear documentation on how to do this.

 

Thanks,

RJ5

0 Likes
2,037 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

The link you added for the Polygon API is what you want. Using cmds will be incredibly slow for this kind of thing. I see MItMeshPolygon.getTriangles() which seems like what you're looking for.

 

Check out this example. It's not exactly what you need, but if you replace the vertex parts with getTriangles it should work out.

0 Likes