【问题标题】:How to retrieve the created vertices of cmds.polyExtrude on Maya如何在 Maya 上检索 cmds.polyExtrude 创建的顶点
【发布时间】:2018-08-13 09:41:12
【问题描述】:

我正在编写一个脚本来更改由给定特定向量的挤出命令创建的顶点的位置。但我找不到获取新生成的顶点/面/边的方法。

我尝试在cmds.getAttr('polyExtrudeFace1')cmds.polyExtrudeFacet 的查询模式中查找,但找不到正确的属性/标志来获取我需要的内容。

【问题讨论】:

    标签: python maya


    【解决方案1】:

    我不确定是否有一个很好的方法来获取新的挤压组件 ID,但如果你有一个工具来获取之前的状态,你可以很容易地找到它。 另一种方法是停用每个构造节点,逐个启用 polyExtrudeFace 并填充 dic,然后重新启用所有内容。 这是一个选择挤出对象上最新顶点的示例:

    '''
    This script only work on the last polyExtrudeFace and on vertex
    '''
    # get the object
    sel = cmds.ls(sl=True, o=True)
    # get the extrude nodes, useful to create a dic with all polyExtrudeFace new component ids 
    extrudenodes = [e for e in cmds.listHistory(sel) if cmds.nodeType(e) == 'polyExtrudeFace']
    #current vtx count
    current_vtx_nb = cmds.polyEvaluate(sel, v=1)
    # disable a polyExtude
    cmds.setAttr("{}.nodeState".format(extrudenodes[0]), 1)
    # get the previous number
    previous_vtx_nb = cmds.polyEvaluate(sel, v=1)
    # re-enable it
    cmds.setAttr("{}.nodeState".format(extrudenodes[0]), 0)
    # get the range
    nb = current_vtx_nb - previous_vtx_nb
    mrang = [current_vtx_nb-nb,current_vtx_nb]
    # recreate the vtx s3election
    out = ['{}.vtx[{}]'.format(sel[0], i) for i in range(*mrang)]
    # select the vertex
    cmds.select(out)
    

    编辑:

    这是构建字典循环的示例:

    import maya.cmds as cmds
    
    '''
    This script build the vertices data loop
    '''
    
    class Counter:
        idCounter = 0
        def __init__(self):
            Counter.idCounter += 1
    
    
    def loopIncSel():
        'relaunch the command to loop throught all key of the dic'
        if sorted(dataExtrude.keys()):
            count = Counter().idCounter % len(dataExtrude.keys())
            k = dataExtrude.keys()[count]
            cmds.select(dataExtrude[k])
    
    
    # get the object
    sel = cmds.ls(sl=True, o=True)
    # get the extrude nodes, useful to create a dic with all polyExtrudeFace new component ids 
    extrudenodes = [e for e in cmds.listHistory(sel) if cmds.nodeType(e) == 'polyExtrudeFace']
    # dic data :
    dataExtrude = {}
    for n in extrudenodes:
        cmds.setAttr("{}.nodeState".format(n), 1)
    
    # reverse the processus to re-enable, 
    # note that if there is node in between creating vertices and faces, it won't work
    for n in extrudenodes[::-1]:
        # get the previous number
        previous_vtx_nb = cmds.polyEvaluate(sel, v=1)
        # re-enable it
        cmds.setAttr("{}.nodeState".format(n), 0)
        #current vtx count
        current_vtx_nb = cmds.polyEvaluate(sel, v=1)
    
        # get the range
        nb = current_vtx_nb - previous_vtx_nb
        mrang = [current_vtx_nb-nb,current_vtx_nb]
        # recreate the vtx s3election
        dataExtrude[n] = ['{}.vtx[{}]'.format(sel[0], i) for i in range(*mrang)]
    # select the vertex
    # cmds.select(dataExtrude['polyExtrudeFace3'])
    loopIncSel()
    

    【讨论】:

    • 感谢您的回答,使用顶点数差异的巧妙技巧。现在,我只需要找到一种方法来过滤结果以将正确的向量应用于正确的顶点。我正在考虑挤出所有边缘,并在所有处理之后重新创建面部。但这是我的问题。
    • 第二个例子非常感谢您。
    【解决方案2】:

    cmds.polyExtrudeFacet 应用到网格时,Maya 将自动选择新面。知道了这一点,就很容易将面组件转换为新的顶点:

    cmds.polySphere(name="pSphere1") # Create a sphere to test with.
    cmds.polyExtrudeFacet("pSphere1.f[10]") # Extrude a random face.
    sel = cmds.polyListComponentConversion(cmds.ls("*.f[*]", sl=True), fromFace=True, toVertex=True) # Convert faces to verts. Filter `ls` to only get face selections.
    cmds.select(sel) # Select the newly created vertexes.
    

    【讨论】:

    • 这是一个非常有用的属性。并且比其他解决方案更有效,即使它更灵活。谢谢!
    • 请记住,您只能在创建时使用此方法,如果您的目标是随机用户,他将不得不使用您的工具来创建拉伸。
    猜你喜欢
    • 2017-03-08
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多