从 Maya C++ 中的变换节点获取网格节点 API
Get a mesh node from a transform node in Maya C++ API
我想在 Maya 中激活的变换节点下获得一个 shape/mesh 对象。
如果我在 Maya 中 select 和对象(例如多边形球体),当调用 getActiveSelectionList
方法时,它 returns 是一个变换节点,而不是 shape/mesh 一个。
我正在阅读 API 类 (MDagPath, MSelectionList, MFnDependencyNode
) 和实现该目标的方法,但我找不到实现它的方法。
所以,我想通过 C++ API.
在 Maya GUI 中获取 selected/active 多边形对象的信息(顶点坐标)
您想获得通向转换的 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
我想在 Maya 中激活的变换节点下获得一个 shape/mesh 对象。
如果我在 Maya 中 select 和对象(例如多边形球体),当调用 getActiveSelectionList
方法时,它 returns 是一个变换节点,而不是 shape/mesh 一个。
我正在阅读 API 类 (MDagPath, MSelectionList, MFnDependencyNode
) 和实现该目标的方法,但我找不到实现它的方法。
所以,我想通过 C++ API.
在 Maya GUI 中获取 selected/active 多边形对象的信息(顶点坐标)您想获得通向转换的 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