def createCenterOfMass(*args):
'''
Create a center of mass node, and constrain it to the
character based on the selected root node.
'''
sel = mc.ls(sl=True)
if not len(sel) == 1:
raise RuntimeError('Please select the root control of your puppet.')
print 'Create Center Of Mass Node'
print '--------------------------'
meshes = meshesFromReference(sel[0]) or meshesFromHistory(sel[0])
if not meshes:
raise RuntimeError('Could not determine geomerty from selected control. Make sure geo is visible.')
mc.select(meshes)
mc.refresh()
print 'Discovered Meshes:'
for mesh in meshes:
print '\t',mesh
skinnedMeshes = []
for mesh in meshes:
if utl.getSkinCluster(mesh):
skinnedMeshes.append(mesh)
continue
hist = mc.listHistory(mesh, breadthFirst=True)
skins = mc.ls(hist, type='skinCluster')
if not skins:
warnings.warn('Could not find a skinned mesh affecting {}'.format(mesh))
continue
outGeo = mc.listConnections(skins[0]+'.outputGeometry[0]', source=False)
outGeo = mc.ls(outGeo, type=['mesh','transform'])
if not outGeo:
warnings.warn('Could not find a skinned mesh affecting {}'.format(mesh))
continue
skinnedMeshes.append(outGeo[0])
if not skinnedMeshes:
raise RuntimeError('Could not determine skinned geometry from selected control. This tool will only work if geo is skinned.')
locator = centerOfMassLocator(skinnedMeshes)
mc.addAttr(locator, longName=COM_ATTR, attributeType='message')
mc.connectAttr('.'.join((sel[0],'message')), '.'.join((locator,COM_ATTR)))
mc.select(sel)
return locator
评论列表
文章目录