Maya Python:“选择 y = 0 以下的所有顶点”

使用 maya.cmds,我想选择 y = 0 以下的所有顶点,以便我可以删除它们。我将如何实现这一点?此外,我正在处理大量 .obj 网格,因此我需要遍历每个网格并执行相同的操作。要遍历每个文件,我应该使用什么技术?


import maya.cmds as cmds

import maya.api.OpenMaya as om2


# Select all objects

selection = cmds.select(all = True)

# Rotate -90 degrees on the x axis

# cmds.rotate(-90)


def vertexOm2():

    """

    Using Maya Python API 2.0

    """

    #___________Selection___________

    # 1 # Query the selection list

    selectionLs = om2.MGlobal.getActiveSelectionList()

    

    # 2 # Get the dag path of the first item in the selection list

    selObj = selectionLs.getDagPath(0)

    

    #___________Query vertex position ___________

    # create a Mesh functionset from our dag object

    mfnObject = om2.MFnMesh(selObj)

    

    return mfnObject.getPoints()

    

vertexOm2()

这将返回“类型错误:项目不是 DAG 路径”


或者使用 cmds:


def vertexCmds():

 """

 Using Maya Cmds

 """

 #___________Selection___________

 # query the currently selected object

 selTemp = str(cmds.ls(selection=True))

 # edit retrieved string so we can feed it into commands

 sel = selTemp.split("'")[1]

 

 

 #___________Query vertex position ___________

 # use the xform command with the ".vtx[*]" to retrieve all vertex positions at once

 vertPosTemp = cmds.xform(sel + '.vtx[*]', q=True, ws=True, t=True)

 

 # split the resulting list into sets of 3

 vertPos = zip(*[iter(vertPosTemp)]*3)

 

 return vertPos

我从这里得到了这两个。


largeQ
浏览 134回答 2
2回答

慕桂英546537

我会得出一个低于 y == 0 的网格列表,这样我就可以对它们打折扣。您可以通过查询每个网格的边界框来解决这个问题。1 索引表示最小 y 值:pm.exactWorldBoundingBox(node)[1]然后处理它们,我可以列出每个网格中的所有顶点以构建删除列表。def get_vertex_positions(node):     return [pm.xform(node.vtx[vid], q=True, ws=True, translation=True) for vid in range(pm.polyEvaluate(node, v=True))]一旦有了这些,您就可以删除相应的顶点。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python