从 Maya C++ API 中的变换节点获取网格节点

jgo*_*zac 2 c++ plugins mesh maya

我想在 Maya 中活动的变换节点下获取形状/网格对象。如果我在 Maya 中选择和对象(例如,多边形球体),则在调用getActiveSelectionList方法时,它会返回一个变换节点,而不是形状/网格节点。

我正在疯狂阅读 API 类 ( MDagPath, MSelectionList, MFnDependencyNode) 和实现这一目标的方法,但我找不到办法做到这一点。

所以,我想通过 C++ API 在 Maya GUI 中获取选定/活动多边形对象的信息(顶点坐标)。

the*_*dox 5

您想要获得导致转换的 MDagPath,然后使用.extendToShape.extendToShapeDirectlyBelow()获取形状节点。然后你需要MFnMesh从形状中获取一个并使用它来到达顶点。

这是python版本,这是我手头的全部。除了语法之外,它在 C++ 中的工作方式相同:

# make a selectionList object, populate ite
sel_list = MSelectionList()
MGlobal.getActiveSelectionList(sel_list)

# make a dagPath, fill it using the first selected item
d = MDagPath()
sel_list.getDagPath(0,d)

print d.fullPathName()
# '|pCube1" <- this is the transform
d.extendToShape()
print d.fullPathName()
#  "|pCube1|pCubeShape1" < - now it points at the shape

# get the dependency node as an MFnMesh:
mesh = MFnMesh(d.node())

# now you can call MFnMesh methods to work on the object:
print mesh.numVertices()
# 8
Run Code Online (Sandbox Code Playgroud)