def connectBlendShapeNodeToPoseBuffer(blendShapeNode,poseBuffer): blendShapeChannels = search.returnBlendShapeAttributes(blendShapeNode) poseBufferAttributes = attributes.returnUserAttributes(poseBuffer) for blendShapeChannel in blendShapeChannels: if blendShapeChannel in poseBufferAttributes: attributes.doConnectAttr((poseBuffer+'.'+blendShapeChannel),(blendShapeNode+'.'+blendShapeChannel),False)
def blendShapeNodeToPoseBuffer(name,blendShapeNode,doConnect = True, transferConnections = True): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Takes the attributes of a blendshape, adds them as attributes, connects them and transfers any driver should you choose ARGUMENTS: name(string) blendShapeNode(string) doConnect(bool) - (True) - if you want to connect the atributes to the new ones transferConnections(bool) - (True) - if you wanna transfer exisiting connections or not RETURNS: returnList(list) - [poseBuffer(string),newAttrs(list)] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ first get the blendshape attrs """ blendShapeAttrs = search.returnBlendShapeAttributes(blendShapeNode) returnList = nodes.createPoseBuffer(name,blendShapeAttrs) newAttrs = returnList[1] if doConnect == True: for attr in blendShapeAttrs: listIndex = blendShapeAttrs.index(attr) attributes.doConnectAttr((newAttrs[listIndex]),(blendShapeNode+'.'+attr),False,transferConnections) return returnList
def blendShapeNodeToPoseBuffer(name, blendShapeNode, doConnect=True, transferConnections=True): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Takes the attributes of a blendshape, adds them as attributes, connects them and transfers any driver should you choose ARGUMENTS: name(string) blendShapeNode(string) doConnect(bool) - (True) - if you want to connect the atributes to the new ones transferConnections(bool) - (True) - if you wanna transfer exisiting connections or not RETURNS: returnList(list) - [poseBuffer(string),newAttrs(list)] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ first get the blendshape attrs """ blendShapeAttrs = search.returnBlendShapeAttributes(blendShapeNode) returnList = createPoseBuffer(name, blendShapeAttrs) newAttrs = returnList[1] if doConnect == True: for attr in blendShapeAttrs: listIndex = blendShapeAttrs.index(attr) attributes.doConnectAttr((newAttrs[listIndex]), (blendShapeNode + "." + attr), False, transferConnections) return returnList
def updateBlendShapeNodeToPoseBuffer(poseBuffer,blendShapeNode,doConnect = True, transferConnections = True, removeMissingShapes = True): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Updates a blendshape to posebuffer connection with new attrs (need to make it remove non existing ones, maybe make the creation one tag it's parent blendshape node) ARGUMENTS: poseBuffer(string) blendShapeNode(string) doConnect(bool) - (True) - if you want to connect the atributes to the new ones transferConnections(bool) - (True) - if you wanna transfer exisiting connections or not RETURNS: returnList(list) - [poseBuffer(string),newAttrs(list)] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ first get the blendshape attrs """ blendShapeAttrs = search.returnBlendShapeAttributes(blendShapeNode) initialPoseBufferAttrs = attributes.returnUserAttributes(poseBuffer) removeAttrsBuffer = lists.returnMissingList(blendShapeAttrs,initialPoseBufferAttrs) newAttrs = lists.returnMissingList(initialPoseBufferAttrs,blendShapeAttrs) newAttrs = attributes.addFloatAttrsToObj(poseBuffer, newAttrs,dv = 0) poseBufferAttrs = attributes.returnUserAttributes(poseBuffer) if doConnect: for attr in newAttrs: try: attributes.doConnectAttr((poseBuffer+'.'+attr),(blendShapeNode+'.'+attr),False,transferConnections) except: guiFactory.warning('%s%s%s%s' % ((poseBuffer+'.'+attr),' to ',(blendShapeNode+'.'+attr),' failed!' )) removeAttrs = [] if removeMissingShapes: for attr in removeAttrsBuffer: if 'cgm' not in attr: removeAttrs.append((poseBuffer+'.'+attr)) mc.deleteAttr((poseBuffer+'.'+attr)) return [newAttrs,removeAttrs]
def bakeCombinedBlendShapeNode(sourceObject, blendShapeNode, baseNameToUse = False, directions=['left','right']): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Function for baking a series of blendshapes out from one object that have a split type ARGUMENTS: sourceObject(string) sourceObject(string) blendShapeNode(string) the node to bake from baseName(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied directions[list] = (['left','right']) RETURNS: Success(bool) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Prep #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ declare variables """ returnList = [] blendShapeNamesBaked = [] blendShapeConnections = [] currentConnections = [] bakedGeo = [] """ size """ sizeBuffer = distance.returnBoundingBoxSize(sourceObject) sizeX = sizeBuffer[0] sizeY = sizeBuffer[1] """ base name """ if baseNameToUse == False: baseName = '' else: baseName = baseNameToUse + '_' #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Meat of it #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> blendShapeNodeChannels = search.returnBlendShapeAttributes(blendShapeNode) blendShapeShortNames = [] """ first loop stores and sets everything to 0 """ for shape in blendShapeNodeChannels: blendShapeBuffer = (blendShapeNode+'.'+shape) blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer)) """break it """ attributes.doBreakConnection(blendShapeBuffer) attributes.doSetAttr(blendShapeBuffer,0) """ Find pairs """ blendshapePairs = lists.returnMatchedStrippedEndList(blendShapeNodeChannels,directions) """ first loop stores and sets everything to 0 """ for pair in blendshapePairs: blendShapeBuffer = (blendShapeNode+'.'+pair[0]) splitBuffer = pair[0].split('_') nameBuffer = splitBuffer[:-1] pairBaseName = '_'.join(nameBuffer) if '_' in list(pairBaseName): newSplitBuffer = pair[0].split('_') newNameBuffer = newSplitBuffer[1:] blendShapeShortNames.append('_'.join(newNameBuffer)) else: blendShapeShortNames.append(pairBaseName) t=1 pair = 0 for i in range (len(blendshapePairs)): row = i//5 if t>5: t=1 """ start extracting """ blendShapeNodeChannelsBuffer = blendshapePairs[pair] shape1 = blendShapeNodeChannelsBuffer[0] shape2 = blendShapeNodeChannelsBuffer[1] blendShape1Buffer = (blendShapeNode+'.'+shape1) blendShape2Buffer = (blendShapeNode+'.'+shape2) attributes.doSetAttr(blendShape1Buffer,1) attributes.doSetAttr(blendShape2Buffer,1) dupBuffer = mc.duplicate(sourceObject) splitBuffer = blendShapeShortNames[pair].split('_') if len(splitBuffer)>1: nameBuffer = splitBuffer[:-1] else: nameBuffer = splitBuffer shortName = '_'.join(nameBuffer) dupBuffer = mc.rename (dupBuffer,(baseName+shortName)) """ Unlock it """ attributes.doSetLockHideKeyableAttr(dupBuffer,False,True,True) mc.xform(dupBuffer,r=True,t=[((sizeX*(t+1.2))*1.5),(sizeY*row*-1.5),0]) bakedGeo.append(dupBuffer) attributes.doSetAttr(blendShape1Buffer,0) attributes.doSetAttr(blendShape2Buffer,0) pair +=1 t+=1 """ restore connections """ for shape in blendShapeNodeChannels: currentIndex = blendShapeNodeChannels.index(shape) blendShapeBuffer = (blendShapeNode+'.'+shape) """ Restore the connection """ if blendShapeConnections[currentIndex] != False: attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Finish out #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ group for geo """ meshGroup = mc.group( em=True) attributes.storeInfo(meshGroup,'cgmName', baseNameToUse) attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo') meshGroup = NameFactory.doNameObject(meshGroup) for geo in bakedGeo: rigging.doParentReturnName(geo,meshGroup) returnList.append(meshGroup) returnList.append(bakedGeo) return returnList
def bakeCombinedBlendShapeNodeToTargetObject(targetObject,sourceObject, blendShapeNode, baseName = False, directions=['left','right']): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Function for baking a series of blendshapes from one object to another when you have a left/right variant ARGUMENTS: targetObject(string) sourceObject(string) blendShapeNode(string) the node to bake from baseName(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied directions[list] = (['left','right']) RETURNS: Success(bool) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Prep #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ declare variables """ returnList = [] blendShapeNamesBaked = [] blendShapeConnections = [] currentConnections = [] bakedGeo = [] """ size """ sizeBuffer = distance.returnBoundingBoxSize(targetObject) sizeX = sizeBuffer[0] sizeY = sizeBuffer[1] """ base name """ if baseName == False: baseName = '' else: baseName = baseName + '_' """reference check """ refPrefix = search.returnReferencePrefix(sourceObject) if refPrefix != False: referencePrefix = (search.returnReferencePrefix(sourceObject) + ':') else: referencePrefix = '' """ wrap deform object """ wrapBuffer = wrapDeformObject(targetObject,sourceObject,True) targetObjectBaked = wrapBuffer[1] #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Meat of it #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #setAttr ($wrapDeformer[0] + ".autoWeightThreshold") 1; """ cause maya is stupid and doesn't have a python equivalent""" mc.select(targetObjectBaked,r=True) mc.select(sourceObject,tgl=True) mel.eval('AddWrapInfluence') mc.select(cl=True) """ may need to add this in later //reorders deformation order for proper baking of skinned mesh //reorderDeformers "tweak1" "face_skinCluster" $deformerGeo; """ blendShapeNodeChannels = search.returnBlendShapeAttributes(blendShapeNode) blendShapeShortNames = [] """ first loop stores and sets everything to 0 """ for shape in blendShapeNodeChannels: blendShapeBuffer = (blendShapeNode+'.'+shape) blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer)) """break it """ attributes.doBreakConnection(blendShapeBuffer) attributes.doSetAttr(blendShapeNode,shape,0) """ Find pairs """ blendshapePairs = lists.returnMatchedStrippedEndList(blendShapeNodeChannels,directions) """ first loop stores and sets everything to 0 """ for pair in blendshapePairs: blendShapeBuffer = (blendShapeNode+'.'+pair[0]) splitBuffer = pair[0].split('_') nameBuffer = splitBuffer[:-1] pairBaseName = '_'.join(nameBuffer) if '_' in list(pairBaseName): newSplitBuffer = pair[0].split('_') newNameBuffer = newSplitBuffer[1:] blendShapeShortNames.append('_'.join(newNameBuffer)) else: blendShapeShortNames.append(pairBaseName) t=1 pair = 0 for i in range (len(blendshapePairs)): row = i//5 if t>5: t=1 """ start extracting """ blendShapeNodeChannelsBuffer = blendshapePairs[pair] shape1 = blendShapeNodeChannelsBuffer[0] shape2 = blendShapeNodeChannelsBuffer[1] attributes.doSetAttr(blendShapeNode,shape1,1) attributes.doSetAttr(blendShapeNode,shape2,1) dupBuffer = mc.duplicate(targetObjectBaked) splitBuffer = blendShapeShortNames[pair].split('_') nameBuffer = splitBuffer[:-1] shortName = '_'.join(nameBuffer) dupBuffer = mc.rename (dupBuffer,(baseName+shortName)) mc.xform(dupBuffer,r=True,t=[((sizeX*(t+1.2))*1.5),(sizeY*row*-1.5),0]) bakedGeo.append(dupBuffer) attributes.doSetAttr(blendShapeNode,shape1,0) attributes.doSetAttr(blendShapeNode,shape2,0) pair +=1 t+=1 """ restore connections """ for shape in blendShapeNodeChannels: currentIndex = blendShapeNodeChannels.index(shape) blendShapeBuffer = (blendShapeNode+'.'+shape) """ Restore the connection """ if blendShapeConnections[currentIndex] != False: attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer) """delete the wrap""" mc.delete(wrapBuffer[0]) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Finish out #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ group for geo """ meshGroup = mc.group( em=True) attributes.storeInfo(meshGroup,'cgmName', baseName) attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo') meshGroup = NameFactory.doNameObject(meshGroup) for geo in bakedGeo: rigging.doParentReturnName(geo,meshGroup) returnList.append(meshGroup) returnList.append(bakedGeo) mc.delete(targetObjectBaked) return returnList