def rebuild_joints(*args):
if not cmds.objExists(ORIENT_GROUP):
return
nodes = cmds.listRelatives(ORIENT_GROUP, ad=True, path=True) or []
joints = []
for node in nodes:
attrs = cmds.listAttr(node, ud=True) or []
if MESSAGE_ATTRIBUTE not in attrs:
continue
joint = cmds.listConnections('{0}.{1}'.format(node, MESSAGE_ATTRIBUTE), d=False)[0]
joints.append(joint)
rotation = cmds.getAttr('{0}.rx'.format(node))
children = cmds.listRelatives(joint, children=True, shapes=False, path=True)
if children:
# First unparent children so change in joint orient does not affect children
children = [cmds.parent(child, world=True)[0] for child in children]
# Add rotation offset to joint orient
orient_x = cmds.getAttr('{0}.jointOrientX'.format(joint))
orient_x += rotation
while orient_x > 180.0:
orient_x -= 360.0
while orient_x < -180.0:
orient_x += 360.0
cmds.setAttr('{0}.jointOrientX'.format(joint), orient_x)
# Reparent child
for child in children:
cmds.parent(child, joint)
else:
# tip joint, just zero out joint orient
cmds.setAttr('%s.jointOrientX' % joint, 0)
cmds.setAttr('%s.jointOrientY' % joint, 0)
cmds.setAttr('%s.jointOrientZ' % joint, 0)
# Untemplate
cmds.setAttr('{0}.template'.format(joint), 0)
# Delete arrow group
cmds.delete(ORIENT_GROUP)
cmds.select(joints)
评论列表
文章目录