我一般編程Unity3D相關的東西,我還是很新的Maya的python API。如何在Maya中獲取正常臉部平均值?
我試圖做的是獲得當前選擇的面法線平均:
我實現到現在爲止是根據移動機械手定位於立方體的一個實例。
import maya.cmds as cmds
import re #regular expression
# get current position of the move manipulator
pos = cmds.manipMoveContext('Move', q=True, p=True)
# get the current selection
selection = cmds.ls(sl=True)
# trying to get the face normal angles of the current selection
polyInfo = cmds.polyInfo(selection, fn=True)
polyInfoArray = re.findall(r"[\w.-]+", polyInfo[0]) # convert the string to array with regular expression
polyInfoX = float(polyInfoArray[2])
polyInfoY = float(polyInfoArray[3])
polyInfoZ = float(polyInfoArray[4])
print str(polyInfoX) + ', ' + str(polyInfoY) + ', ' + str(polyInfoZ)
target = cmds.polyCube()
cmds.move(pos[0], pos[1], pos[2], target)
現在我唯一需要的是旋轉立方體的選擇
請面對平均法線,這方面有任何想法?
Maya有任何方法給我這些角度?我嘗試使用polyInfo與面法線旋轉,但我覺得我失去了一些東西......
編輯:
最終的解決方案(感謝@theodox)
import maya.cmds as cmds
# get current position of the move manipulator
pos = cmds.manipMoveContext('Move', query=True, position=True)
# get the current selection
selection = cmds.ls(selection=True)
target = cmds.polyCube()
cmds.move(pos[0], pos[1], pos[2], target)
constr = cmds.normalConstraint(selection, target, aimVector = (0,0,1), worldUpType= 0)
cmds.delete(constr)
非常感謝@theodox!正常的約束解決了我的問題就像一個魅力,感謝替代! –