Update
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# @Site : Virtuos Games
|
||||
# @Author : ZHou Shuhua
|
||||
|
||||
try:
|
||||
import pymel.core as pm
|
||||
except ImportError:
|
||||
@@ -112,8 +118,8 @@ def getSkinClusterInfo(objectName, saveJointInfo=False):
|
||||
|
||||
def getSkinJointInformation(influences):
|
||||
"""
|
||||
获取骨骼信息(父节点、矩阵、旋转、关节方向)
|
||||
兼容 PyMEL 和 cmds,处理无父节点的情况
|
||||
Retrieve skeletal information (parent node, matrix, rotation, joint orientation)
|
||||
Compatible with PyMEL and cmds, handling cases without parent nodes.
|
||||
"""
|
||||
jointInformation = {}
|
||||
|
||||
@@ -122,7 +128,7 @@ def getSkinJointInformation(influences):
|
||||
try:
|
||||
if pm:
|
||||
infNode = pm.PyNode(inf)
|
||||
# 安全获取父节点,避免 None.name() 错误
|
||||
# Safely retrieve the parent node and avoid the None.name() error.
|
||||
parent = infNode.getParent()
|
||||
jointInfo["parent"] = str(parent.name()) if parent else ""
|
||||
jointInfo["matrix"] = infNode.getMatrix(worldSpace=True)
|
||||
@@ -130,7 +136,7 @@ def getSkinJointInformation(influences):
|
||||
jointInfo["jointOrient"] = infNode.getAttr("jointOrient")
|
||||
jointInformation[str(infNode)] = copy.deepcopy(jointInfo)
|
||||
else:
|
||||
# cmds 版本
|
||||
# cmds verison
|
||||
infName = str(inf)
|
||||
parents = cmds.listRelatives(infName, parent=True)
|
||||
jointInfo["parent"] = parents[0] if parents else ""
|
||||
@@ -140,7 +146,7 @@ def getSkinJointInformation(influences):
|
||||
jointInformation[infName] = copy.deepcopy(jointInfo)
|
||||
except Exception as e:
|
||||
print(f"Warning: Failed to get joint information for {inf}: {e}")
|
||||
# 使用默认值
|
||||
# Use default values
|
||||
jointInfo["parent"] = ""
|
||||
jointInfo["matrix"] = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
|
||||
jointInfo["rotation"] = [0, 0, 0]
|
||||
@@ -368,11 +374,11 @@ def buildSkinWeightsDict(objectList, showLoadingBar=True, saveJointInfo=False):
|
||||
for object in objectList:
|
||||
try:
|
||||
if pm:
|
||||
# 安全转换为字符串,处理可能的 None 或无效对象
|
||||
# Safely convert to string, handling possible None or invalid objects.
|
||||
obj_node = pm.PyNode(object) if not isinstance(object, pm.PyNode) else object
|
||||
objectAsString = str(obj_node.name()) if obj_node else str(object)
|
||||
else:
|
||||
# cmds 版本 - object 已经是字符串
|
||||
# cmds version - object is already a string
|
||||
objectAsString = str(object)
|
||||
except Exception as e:
|
||||
print(f"Warning: Failed to process object {object}: {e}")
|
||||
@@ -416,7 +422,7 @@ def transferSkinWeights(transferNodes=None, showLoadingBar=True):
|
||||
if len(transferNodes):
|
||||
|
||||
sourceObj = transferNodes[0]
|
||||
# 安全获取名称
|
||||
# Get name
|
||||
try:
|
||||
sourceName = str(sourceObj.name()) if hasattr(sourceObj, 'name') else str(sourceObj)
|
||||
except:
|
||||
@@ -436,7 +442,7 @@ def transferSkinWeights(transferNodes=None, showLoadingBar=True):
|
||||
# deep copy because: Mutable datatypes
|
||||
sourceWeightDictCopy = copy.deepcopy(sourceWeightDict)
|
||||
|
||||
# 安全获取名称
|
||||
# Get name
|
||||
try:
|
||||
targetName = str(tgtObject.name()) if hasattr(tgtObject, 'name') else str(tgtObject)
|
||||
except:
|
||||
@@ -526,7 +532,7 @@ def skinClusterBuilder(objName, weightDict, deleteHist=True, stripJointNamespace
|
||||
joint.setMatrix(jointInfo.get("matrix"), worldSpace=True)
|
||||
pm.select(cl=True)
|
||||
else:
|
||||
# cmds 版本
|
||||
# cmds version
|
||||
cmds.select(clear=True)
|
||||
joint = cmds.joint(position=(0, 0, 0), name=jointName)
|
||||
# putting joint in the hierarchy and setting matrix
|
||||
@@ -557,7 +563,7 @@ def skinClusterBuilder(objName, weightDict, deleteHist=True, stripJointNamespace
|
||||
pm.setAttr('%s.normalizeWeights' % clusterNode, 1)
|
||||
clusterNodeName = str(clusterNode)
|
||||
else:
|
||||
# cmds 版本
|
||||
# cmds verison
|
||||
clusterNode = cmds.skinCluster(clusterJoints, objName, tsb=True, mi=clusterMaxInf, omi=True)[0]
|
||||
# turn of normalization to nuke weights to 0, this is to get a true 1->1 application of old weights
|
||||
cmds.setAttr('%s.normalizeWeights' % clusterNode, 0)
|
||||
|
||||
Reference in New Issue
Block a user