Issues with MFnMesh object

Issues with MFnMesh object

jonah_reinhart
Contributor Contributor
158 Views
3 Replies
Message 1 of 4

Issues with MFnMesh object

jonah_reinhart
Contributor
Contributor

 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())

 

 

0 Likes
159 Views
3 Replies
Replies (3)
Message 2 of 4

BurkhardRammner
Collaborator
Collaborator

I only 'know' the c++ API.
When you use the create method, you get 2 outputs. When MFnMesh was initialized with a MObject that was constructed using MFnMeshData, then you get:
1. the 'mesh object' as the return object
2. the 'mesh data', which you can output to the DG
When you then want to continue to do work with the result, you got to set a MFnMesh to the 'mesh object'.
Thats the only really save way to do it.

0 Likes
Message 3 of 4

jonah_reinhart
Contributor
Contributor
When you then want to continue to do work with the result, you got to set a MFnMesh to the 'mesh object'.
Thats the only really save way to do it.

Yes, you can see that in the example I provided. After setObject it returns the expected thing, but the behavior prior to doing that is somewhat mixed.  

The question is whether this is intended behavior, and the documentation is inaccurate, or if this is a bug.

0 Likes
Message 4 of 4

BurkhardRammner
Collaborator
Collaborator

No AD employee will tell you. Its unpredictable and the only save way is to reset the function set to the resulting mesh object.

0 Likes