+1 tag for Google+

Thursday, 15 September 2016

Finding the Centre Position of a Polygon Face: Maya Python API

In the past few days I found myself having to find the position of face centres of a polygon.

Looking through the Maya documentations I find no MEL or Python commands that can do this. So I had to do a Google search the answer.

The most useful solution I found was from a discussion in Google Groups, in a reply by Justin Israel (who works in Weta Digital according to his Google+ profile):
https://groups.google.com/d/msg/python_inside_maya/UoMVxr0deVo/OJ2K8IpevxQJ

Here is an excerpt of Justin's answer:
import pymel.core as pm
import maya.OpenMaya as OpenMaya

face = pm.MeshFace("pCube1.f[64]")
pt = face.__apimfn__().center(OpenMaya.MSpace.kWorld)
centerPoint = pm.datatypes.Point(pt)

Here is another interesting article discussing how we can go about finding the centre position of a face: http://mayastation.typepad.com/maya-station/2009/11/where-is-the-center-of-a-polygon.html

No comments:

Post a Comment