【发布时间】:2018-08-13 09:41:12
【问题描述】:
我正在编写一个脚本来更改由给定特定向量的挤出命令创建的顶点的位置。但我找不到获取新生成的顶点/面/边的方法。
我尝试在cmds.getAttr('polyExtrudeFace1') 或cmds.polyExtrudeFacet 的查询模式中查找,但找不到正确的属性/标志来获取我需要的内容。
【问题讨论】:
我正在编写一个脚本来更改由给定特定向量的挤出命令创建的顶点的位置。但我找不到获取新生成的顶点/面/边的方法。
我尝试在cmds.getAttr('polyExtrudeFace1') 或cmds.polyExtrudeFacet 的查询模式中查找,但找不到正确的属性/标志来获取我需要的内容。
【问题讨论】:
我不确定是否有一个很好的方法来获取新的挤压组件 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()
【讨论】:
将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.
【讨论】: