def get_data(root):
"""Get the data dictionary that makes up a joint/transform hierarchy. Non-transform
branches will be skipped.
:param root: The root node of the hierarchy to export.
:return: A dictionary containing all data required to rebuild the hierarchy in Maya.
"""
node_type = cmds.nodeType(root)
shapes = cmds.listRelatives(root, children=True, shapes=True)
if node_type not in ['joint', 'transform'] or (shapes and node_type == 'transform'):
# Skip nodes that are not joints or transforms or if there are shapes below.
return None
# Store everything we need to recreate the node
data = {
'nodeType': node_type,
'name': root,
'translate': [truncate(x) for x in cmds.getAttr('{0}.t'.format(root))[0]],
'rotate': [truncate(x) for x in cmds.getAttr('{0}.r'.format(root))[0]],
'scale': [truncate(x) for x in cmds.getAttr('{0}.s'.format(root))[0]],
'rotateOrder': cmds.getAttr('{0}.rotateOrder'.format(root)),
'rotateAxis': [truncate(x) for x in cmds.getAttr('{0}.ra'.format(root))[0]],
'children': [],
}
if node_type == 'joint':
data['jointOrient'] = [truncate(x) for x in cmds.getAttr('{0}.jo'.format(root))[0]]
data['radius'] = cmds.getAttr('{0}.radius'.format(root))
data['side'] = cmds.getAttr('{0}.side'.format(root))
data['type'] = cmds.getAttr('{0}.type'.format(root))
data['otherType'] = cmds.getAttr('{0}.otherType'.format(root))
data['jointTypeX'] = cmds.getAttr('{0}.jointTypeX'.format(root))
data['jointTypeY'] = cmds.getAttr('{0}.jointTypeX'.format(root))
data['jointTypeZ'] = cmds.getAttr('{0}.jointTypeX'.format(root))
# Recurse down to all the children
children = cmds.listRelatives(root, children=True, path=True) or []
for child in children:
child_data = get_data(child)
if child_data:
data['children'].append(child_data)
return data
评论列表
文章目录