如何通过 python 将蒙皮权重从一根骨骼转移到另一根骨骼
How to transfer skin weights from one bone to another via python
我想将蒙皮权重从一根骨头转移到另一根骨头。谁能告诉我该怎么做?
此代码假定您一次只选择两个骨骼
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;
看起来你几乎已经成功了,但只是命令出现了一些语法错误。我知道你的代码只是试图从一个关节转移,但这个例子将遍历所有匹配正确命名的关节。只要 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
。
文档提到它只会从 selected 顶点转移权重,所以在这个例子中我只是 select 所有顶点。
这已经用一个球体和 2 个旧关节到 2 个新关节进行了测试。
我想将蒙皮权重从一根骨头转移到另一根骨头。谁能告诉我该怎么做?
此代码假定您一次只选择两个骨骼
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;
看起来你几乎已经成功了,但只是命令出现了一些语法错误。我知道你的代码只是试图从一个关节转移,但这个例子将遍历所有匹配正确命名的关节。只要 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
。
文档提到它只会从 selected 顶点转移权重,所以在这个例子中我只是 select 所有顶点。
这已经用一个球体和 2 个旧关节到 2 个新关节进行了测试。