0
我正在寫python的瑪雅腳本來交換頂點位置從一邊到另一邊。 因爲我想要翻轉爲基於拓撲,我使用拓撲對稱選擇工具來查找頂點對應。 我設法使用filterExpand和xform來做到這一點。 問題是,它在一個大的聚合網格上很慢,我想知道如何使用openMaya來完成。瑪雅python迭代大量的頂點
進口maya.cmds作爲CMDS
def flipMesh():
sel=cmds.ls(sl=1)
axis={'x':0,'y':1,'z':2}
reverse=[1.0,1.0,1.0]
#quring the axtive symmetry axis
activeaxis=cmds.symmetricModelling(q=1, axis=1)
reverse[axis[activeaxis]]=-1.0
#getting the vertex count
verts=cmds.polyEvaluate(v=1)
#selecting all vertex
cmds.select(sel[0]+'.vtx[0:'+str(verts)+']')
#getting all the positive vertex
posit=cmds.filterExpand(sm=31,ex=1,smp=1)
seam=cmds.filterExpand(sm=31,ex=1,sms=1)
#swapping position on the positive side with the negative side
for pos in posit:
cmds.select(pos, sym=True)
neg=cmds.filterExpand(sm=31,ex=1,smn=1)
posT=cmds.xform(pos, q=1, t=1)
negT=cmds.xform(neg[0], q=1, t=1)
cmds.xform(pos,t=[a*b for a,b in zip(negT,reverse)])
cmds.xform(neg[0],t=[a*b for a,b in zip(posT,reverse)])
#inverting position on the seam
for each in seam:
seamP=cmds.xform(each, q=1, t=1)
seaminvP=[a*b for a,b in zip(seamP,reverse)]
cmds.xform(each, t=(seaminvP))
cmds.select(sel)
感謝 莫里吉奧
您是否試圖使鏡像平面的一側的頂點與另一側的頂點匹配?或者你是否試圖將vert從一側交換到另一側? – theodox
該腳本實際上已經將頂點的位置從一側交換到另一側。問題更多的是如何使用開放的瑪雅圖書館來做到這一點 –