def BT_AddPose(set = None, poseName = '', index = None):
prefixedPoseName = 'BT_' +poseName
if not set:
return False
if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
return False
if BT_IsSetupConnected(set = set):
cmds.warning('Disconnect setup first!')
return False
blendNode = cmds.getAttr(set +'.Blend_Node')
if not cmds.objExists(blendNode) or not cmds.objExists(set):
return False
if cmds.attributeQuery(prefixedPoseName, ex = True, n = set):
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
numTransforms = len(transforms)
poseIndex = cmds.getAttr(blendNode +'.transforms[0].poses', size = True)
if index is not None:
poseIndex = index
if index is None:
cmds.addAttr(set, ln = prefixedPoseName, nn = poseName, k = True, min = 0, max = 1.0, at = 'double')
# print ('Num poses = ' +str(numPoses))
for i in range(0, numTransforms):
#get the base matrix
baseScale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseScale')[0]
baseMatrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseMatrix')
#store the scale and set it
transformScale = cmds.getAttr(transforms[i] +'.scale')[0]
#set the scale back to 1.0
cmds.setAttr(transforms[i] +'.scale', 1.0, 1.0, 1.0, type = 'double3')
transformMatrix = cmds.xform(transforms[i], q = True, m = True)
poseMatrix = [x-y for x, y in zip(transformMatrix, baseMatrix)]
poseScale = [x-y for x, y in zip(transformScale, baseScale)]
#set the scale back to what the user had it at
cmds.setAttr(transforms[i] +'.scale', transformScale[0], transformScale[1], transformScale[2], type = 'double3')
cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].matrix', poseMatrix, type = 'matrix')
BT_Double3ValuesToNode(values = poseScale, node = blendNode, attr = 'transforms[' +str(i) +'].poses[' +str(poseIndex) +'].scale' )
if index is None:
cmds.connectAttr(set +'.' +prefixedPoseName, blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].weight')
return True
BlendTransforms.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录