我想将皮肤重量从一根骨头转移到另一根骨头。谁能告诉我我该怎么做?
此代码假定您一次仅选择两个骨骼
import pymel.core as pm
oldjnt = pm.ls("*_oldJnt", sl=True, type='joint')[0]
newjnt = pm.ls("*_newJnt", sl=True, type='joint')[0]
pm.skinCluster( "skinCluster1", e=True, selectInfluenceVerts=oldjnt,)
pm.skinPercent(tmw=oldjnt, tmw=newjnt, "skinCluster1")
我不确定如何将transformMoveWeights(tmw)像在Mel中一样从一个骨骼应用于另一个骨骼。
这是梅尔代码:
skinCluster -e -selectInfluenceVerts Jnt_oldJnt skinCluster1;
skinPercent -tmw Jnt_oldJnt -tmw Jnt_newJnt skinCluster1;
答案 0 :(得分:1)
看起来像您几乎拥有它,但是该命令仅出现一些语法错误。我知道您的代码仅尝试从一个关节转移,但是此示例将遍历所有匹配正确命名的关节。只要oldJnt名称与newJnt正确匹配,它就应该从正确的权重传递权重:
import maya.cmds as cmds
# Select all vertexes from your mesh.
cmds.select("pSphere1.vtx[*]")
# We use sorted so that if the objects are names properly, the order of the objects should match indexes.
old_objs = sorted(cmds.ls("*_oldJnt")) # Get a list of all of your old joints.
new_objs = sorted(cmds.ls("*_newJnt")) # Get a list of all of your new joints.
# Use zip to loop through both old and new joints.
for old_jnt, new_jnt in zip(old_objs, new_objs):
cmds.skinPercent("skinCluster1", tmw=[old_jnt, new_jnt]) # Transfer weights from the old joint to the new one.
# Clear vertex selection.
cmds.select(clear=True)
我在这里使用cmds
,但您也可以根据需要将其切换为pymel
。
文档提到它只会从选定的顶点传输权重,因此在此示例中,我仅选择所有顶点。
这已通过球体和2个旧关节到2个新关节的测试。