如何通过python将蒙皮权重从一个骨骼传递到另一个骨骼

2024-09-27 00:23:16 发布

您现在位置: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中那样从一个骨骼应用到另一个骨骼。在

以下是Mel代码:

^{pr2}$

Tags: 代码importtruetypels权重骨骼sl
1条回答
网友
1楼 · 发布于 2024-09-27 00:23:16

看起来你差点就搞定了,只是命令有一些语法错误。我知道你的代码只尝试从一个关节传输,但这个例子将循环通过所有匹配正确命名的关节。只要旧jnt名称与newJnt正确匹配,它就应该从正确的jnt转移权重:

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。在

文档中提到它只会从选定的顶点传递权重,所以在这个例子中我只选择所有顶点。在

这已经用一个球体和两个旧关节到两个新关节进行了测试。在

相关问题 更多 >

    热门问题