I’m trying to get a better understanding of how openmaya works, especially on how to construct my own geometry. I started the most basic example using chatGPT, create a face with the given 4 point:
import maya.api.OpenMaya as om
def createFace():
# Define the points
points = [om.MPoint(1, 0, 1), om.MPoint(-1, 0, 1),
om.MPoint(-1, 0, -1), om.MPoint(1, 0, -1)]
# Convert to MFloatPointArray
floatPoints = om.MFloatPointArray()
for point in points:
floatPoints.append(om.MFloatPoint(point.x, point.y, point.z))
# Create the mesh
meshFn = om.MFnMesh()
numVertices = 4
numPolygons = 1
# Polygon counts (number of vertices per face)
polygonCounts = [4]
# Polygon connects (vertex indices for each face)
polygonConnects = om.MIntArray([0, 1, 2, 3])
# Create the face
meshFn.create(numVertices, numPolygons, floatPoints, polygonCounts, polygonConnects)
# Run the function
createFace()
And it Failed, maya gave a crazy error message:
Error: SystemError: file line 25: <built-in method length_hint of iterator object at 0x00000239AE5D3C70> returned a result with an exception set
chatGPT 3.5 or 4.0 can’t make sense of this error, keep changing point’s data type to different maya object, but maya still throws out the same error when calling meshFn.create().
I can easily create this face with
cmds.polyCreateFacet(p=[(1, 0, 1), (-1, 0, 1), (-1, 0, -1), (1, 0, -1)])
Even thought it’s normal is flip, but that’s the next thing I need to worry about…
Hope someone can help!