def autoSkinToVolumeMesh( mesh, skeletonMeshRoot ): ''' given a mesh and the root node for a hierarchy mesh volumes, this function will create a skeleton with the same hierarchy and skin the mesh to this skeleton using the mesh volumes to determine skin weights ''' #grab a list of meshes under the hierarchy - we need to grab this geo, parent it to a skeleton and transfer defacto weighting to the given mesh volumes = listRelatives( skeletonMeshRoot, ad=True, type='mesh', pa=True ) #now generate the skeleton transforms = removeDupes( listRelatives( volumes, p=True, type='transform', pa=True ) or [] ) jointRemap = {} for t in transforms: select( cl=True ) jName = '%s_joint' % t if objExists( jName ): jName += '#' j = joint( n=jName ) jointRemap[ t ] = j #now do parenting for t, j in jointRemap.iteritems(): tParent = listRelatives( t, p=True, pa=True ) if tParent: tParent = tParent[0] jParent = jointRemap.get( tParent, None ) else: jParent = None if jParent is not None: parent( j, jParent ) #now do positioning for t in apiExtensions.sortByHierarchy( transforms ): j = jointRemap[ t ] pos = xform( t, q=True, ws=True, rp=True ) move( pos[0], pos[1], pos[2], j, ws=True, rpr=True ) #duplicate the geometry and parent the geo to the joints in the skeleton we just created - store the duplicates so we can delete them later dupes = [] for t, j in jointRemap.iteritems(): dupe = apiExtensions.asMObject( duplicate( t, returnRootsOnly=True, renameChildren=True )[0] ) children = listRelatives( dupe, type='transform', pa=True ) or [] if children: delete( children ) parent( dupe, j ) dupes.append( dupe ) f = saveWeights( map( str, dupes ) ) loadWeights( [mesh], f, usePosition=True, tolerance=0.5, averageVerts=True, jointNameRemapDict=jointRemap ) delete( dupes ) return jointRemap
def iterPairAndObj( objs ): ''' yields a 2-tuple containing the pair node and the initializing object ''' pairNodesVisited = set() for obj in apiExtensions.sortByHierarchy( objs ): pairNode = ControlPair.GetPairNode( obj ) if pairNode: if pairNode in pairNodesVisited: continue pair = ControlPair( pairNode ) yield pair, obj pairNodesVisited.add( pairNode )
def iterPairAndObj(objs): ''' yields a 2-tuple containing the pair node and the initializing object ''' pairNodesVisited = set() for obj in apiExtensions.sortByHierarchy(objs): pairNode = ControlPair.GetPairNode(obj) if pairNode: if pairNode in pairNodesVisited: continue pair = ControlPair(pairNode) yield pair, obj pairNodesVisited.add(pairNode)