很多時候 做臉部表情的 rig 時都會需要用到 cluster 來控指變形範圍或當 constraint 使用. 以下的程式可以把 polygon 的 soft selection 轉換成一個 cluster. 個人是覺得還蠻好用的,所以在此分享給大家. 這段程式是從 這網頁 轉貼過來的, thanks to THNKR for providing the code.
轉換程式:
import maya.OpenMaya as om
import maya.cmds as mc
richSel = om.MRichSelection()
richSelList = om.MSelectionList()
om.MGlobal.getRichSelection(richSel)
richSel.getSelection(richSelList)
cluster = mc.cluster( rel=True )
clusterSet = mc.listConnections( cluster, type="objectSet" )
for idx in range(richSelList.length()):
dag = om.MDagPath()
component = om.MObject()
richSelList.getDagPath(idx, dag, component)
componentFn = om.MFnSingleIndexedComponent(component)
meshName = dag.partialPathName()
for cidx in range(componentFn.elementCount()):
weight = componentFn.weight(cidx)
v = componentFn.element(cidx)
w = weight.influence()
vtx = (meshName+'.vtx[%d]') % v
mc.sets(vtx, add=clusterSet[0])
mc.percent(cluster[0], vtx, v=w )
mc.select(cluster)
這是個 python 程式, 所以要貼在 script editor 裡的 python tab 裡, 然後可以用 File->Save Script to Shelf 把它存成一個 shelf 按鈕.
很讚的工具
回覆刪除恩,相当实用啊!之前也幻想过会有这样的工具!
回覆刪除好屌的功能
回覆刪除能再問個小問題嗎?
假如我想在Mel中呼叫python可以嗎?
或者是說,mel有command可以自外部呼叫python的script?
感謝~
有.
回覆刪除你可以把程式存成一個 .py 檔 (例如 clusterFromSoft.py), 然後放到 maya/scripts 目錄裡.
然後在 mel 裡可以用以下這一行來執行該py 程式:
python("import clusterFromSoft");
thanks, it's useful for rigging, but seems doesnt work on nurbs, does it?
回覆刪除yeah, the current code doesn't work with nurbs, but with little modification it will, i think. I'll try to add nurbs option when i have time.
回覆刪除