Issues with MFnMesh object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In the documentation for MFnMesh::create it says:
Creates a new polygonal mesh given an array of vertices, edge and polygon connection data and sets this function set to operate on the new surface.
If parentOrOwner is kMeshData, then it doesn't appear to operate on the newly created mesh data. In the code I initially encountered the issue (which was C++) in I had to run setObject() to make my closestIntersection call work.
Som functionality seemed to work without doing that though, like checking the number of vertices.
I thought that maybe it was just something unique about the kMeshData use case, that the documentation didn't mention. But I did some testing, and MFnMesh has the tendency to return inaccurate information about the object it is set to.
I encountered this issue with Maya 2026.2 on Windows 11
Below is a simple example to show some of the odd behavior:
import maya.api.OpenMaya as om
points = om.MPointArray([
om.MPoint(0, 0, 0),
om.MPoint(1, 0, 0),
om.MPoint(0, 1, 0)
])
polygon_counts = [3]
polygon_connects = [0, 1, 2]
mesh_data_obj = om.MFnMeshData().create()
mesh_fn = om.MFnMesh()
mesh_geom = mesh_fn.create(
points,
polygon_counts,
polygon_connects,
parent=mesh_data_obj
)
print("mesh_data:", mesh_data_obj.apiTypeStr)
print("mesh_geom:", mesh_geom.apiTypeStr)
print(mesh_fn.object().apiTypeStr)
print(mesh_fn.object().isNull())
mesh_fn.setObject(mesh_data_obj)
print(mesh_fn.object().apiTypeStr)
print(mesh_fn.object().isNull())