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 doConnectOut(self, target, *a, **kw): """ Attempts to make a connection from instanced attribute to a target Keyword arguments: target(string) - object or attribute to connect to *a, **kw """ assert mc.objExists(target), "'%s' doesn't exist" % target if '.' in target: try: attributes.doConnectAttr(self.nameCombined, target) except: guiFactory.warning("'%s' failed to connect to '%s'!" % (self.nameCombined, target)) else: #If the object has a transform matchAttr = attributes.returnMatchNameAttrsDict( self.obj.nameShort, target, [self.nameLong]) or [] if matchAttr: #If it has a matching attribute try: attributes.doConnectAttr( self.nameCombined, ('%s.%s' % (target, matchAttr.get(self.nameLong)))) except: guiFactory.warning("'%s' failed to connect to '%s'!" % (self.nameCombined, target)) else: print "Target object doesn't have this particular attribute"
def doConnectIn(self,source,*a, **kw): """ Attempts to make a connection from a source to our instanced attribute Keyword arguments: source(string) - object or attribute to connect to *a, **kw """ assert mc.objExists(source),"'%s' doesn't exist"%source if '.' in source: try: attributes.doConnectAttr(source,self.nameCombined) except: guiFactory.warning("'%s' failed to connect to '%s'!"%(source,self.nameCombined)) else: #If the object has a transform matchAttr = attributes.returnMatchNameAttrsDict(self.obj.nameShort,source,[self.nameLong]) or [] if matchAttr: #If it has a matching attribute try: attributes.doConnectAttr(('%s.%s'%(source,matchAttr.get(self.nameLong))),self.nameCombined) except: guiFactory.warning("'%s' failed to connect to '%s'!"%(source,self.nameCombined)) else: print "Source object doesn't have this particular attribute"
def createCurveLengthNode(curve): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Creates a curve lenght measuring node ARGUMENTS: polyFace(string) - face of a poly RETURNS: length(float) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ objType = search.returnObjectType(curve) shapes = [] if objType == 'shape': shapes.append(curve) else: shapes = mc.listRelatives(curve,shapes=True) #first see if there's a length node isConnected = attributes.returnDrivenAttribute(shapes[0]+'.worldSpace[0]') if isConnected !=False: return (attributes.returnDrivenObject(shapes[0]+'.worldSpace')) else: infoNode = nodes.createNamedNode(curve,'curveInfo') attributes.doConnectAttr((shapes[0]+'.worldSpace'),(infoNode+'.inputCurve')) return infoNode
def doConnectIn(self, source, *a, **kw): """ Attempts to make a connection from a source to our instanced attribute Keyword arguments: source(string) - object or attribute to connect to *a, **kw """ assert mc.objExists(source), "'%s' doesn't exist" % source if '.' in source: try: attributes.doConnectAttr(source, self.nameCombined) except: guiFactory.warning("'%s' failed to connect to '%s'!" % (source, self.nameCombined)) else: #If the object has a transform matchAttr = attributes.returnMatchNameAttrsDict( self.obj.nameShort, source, [self.nameLong]) or [] if matchAttr: #If it has a matching attribute try: attributes.doConnectAttr( ('%s.%s' % (source, matchAttr.get(self.nameLong))), self.nameCombined) except: guiFactory.warning("'%s' failed to connect to '%s'!" % (source, self.nameCombined)) else: print "Source object doesn't have this particular attribute"
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 doConnectOut(self,target,*a, **kw): """ Attempts to make a connection from instanced attribute to a target Keyword arguments: target(string) - object or attribute to connect to *a, **kw """ assert mc.objExists(target),"'%s' doesn't exist"%target if '.' in target: try: attributes.doConnectAttr(self.nameCombined,target) except: guiFactory.warning("'%s' failed to connect to '%s'!"%(self.nameCombined,target)) else: #If the object has a transform matchAttr = attributes.returnMatchNameAttrsDict(self.obj.nameShort,target,[self.nameLong]) or [] if matchAttr: #If it has a matching attribute try: attributes.doConnectAttr(self.nameCombined,('%s.%s'%(target,matchAttr.get(self.nameLong)))) except: guiFactory.warning("'%s' failed to connect to '%s'!"%(self.nameCombined,target)) else: print "Target object doesn't have this particular attribute"
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 createFollicleOnMesh(targetSurface, name='follicle'): """ Creates named follicle node on a mesh Keywords mesh -- mesh to attach to name -- base name to use ('follicle' default) Returns [follicleNode,follicleTransform] """ if SEARCH.is_shape(targetSurface): l_shapes = [targetSurface] else: l_shapes = mc.listRelatives(targetSurface, s=True, fullPath=True) if not l_shapes: raise ValueError, "Must have shapes to check." _shape = l_shapes[0] log.debug("_shape: {0}".format(_shape)) _type = VALID.get_mayaType(_shape) #objType = search.returnObjectType(mesh) #assert objType in ['mesh','nurbsSurface'],("'%s' isn't a mesh"%mesh) follicleNode = create((name), 'follicle') """ make the closest point node """ #closestPointNode = createNamedNode((targetObj+'_to_'+mesh),'closestPointOnMesh') #controlSurface = mc.listRelatives(_shape,shapes=True)[0] follicleTransform = mc.listRelatives(follicleNode, p=True, fullPath=True)[0] attributes.doConnectAttr( (_shape + '.worldMatrix[0]'), (follicleNode + '.inputWorldMatrix')) #surface to follicle node if _type == 'mesh': attributes.doConnectAttr( (_shape + '.outMesh'), (follicleNode + '.inputMesh')) #surface mesh to follicle input mesh else: attributes.doConnectAttr( (_shape + '.local'), (follicleNode + '.inputSurface')) #surface mesh to follicle input mesh attributes.doConnectAttr((follicleNode + '.outTranslate'), (follicleTransform + '.translate')) attributes.doConnectAttr((follicleNode + '.outRotate'), (follicleTransform + '.rotate')) attributes.doSetLockHideKeyableAttr(follicleTransform) return [follicleNode, follicleTransform]
def returnConnectedClosestPointOnMeshNode(targetObj, mesh): """ make the closest point node """ closestPointNode = createNamedNode((targetObj + "_to_" + mesh), "closestPointOnMesh") controlSurface = mc.listRelatives(mesh, shapes=True) """ to account for target objects in heirarchies """ attributes.doConnectAttr((targetObj + ".translate"), (closestPointNode + ".inPosition")) attributes.doConnectAttr((controlSurface[0] + ".worldMesh"), (closestPointNode + ".inMesh")) return closestPointNode
def set_primeScaleAxis(control=None, primeAxis=None, slaveOthers=False, alias=None): """ Set a single axis of scale for a given control. The other channels are locked and hidden. :parameters: control(str): Object to change primeAxis(str/idx): X,Y,Z or index slaveOthers(bool): Whether to drive the remaining attributes of the given channel alias(str): If given, will attempt to alias the primeAxis :returns success(bool) """ _str_func = 'set_primeAxis' _l = ['X', 'Y', 'Z'] _primeAxis = cgmValid.kw_fromList(primeAxis, _l) _idx = _l.index(_primeAxis) _attr_prime = 'scale{0}'.format(_primeAxis) _l_others = [] for i, v in enumerate(_l): if i != _idx: _l_others.append(v) log.debug("{0} || control:{1}".format(_str_func, control)) log.debug("{0} || primeAxis:{1}".format(_str_func, _primeAxis)) log.debug("{0} || slaveOthers:{1}".format(_str_func, slaveOthers)) log.debug("{0} || alias:{1}".format(_str_func, alias)) log.debug("{0} || prime attr:{1}".format(_str_func, _attr_prime)) log.debug("{0} || other attrs:{1}".format(_str_func, _l_others)) if alias: coreAttr.alias_set("{0}.{1}".format(control, _attr_prime), alias) for attr in _l_others: if slaveOthers: try: attributes.doConnectAttr( "{0}.{1}".format(control, _attr_prime), "{0}.scale{1}".format(control, attr.capitalize()), transferConnection=True) except: pass attributes.doSetLockHideKeyableAttr( control, lock=True, visible=False, keyable=False, channels=['s{0}'.format(attr.lower())]) return True
def returnConnectedClosestPointOnMeshNode(targetObj, mesh): """ make the closest point node """ closestPointNode = createNamedNode((targetObj + '_to_' + mesh), 'closestPointOnMesh') controlSurface = mc.listRelatives(mesh, shapes=True) """ to account for target objects in heirarchies """ attributes.doConnectAttr((targetObj + '.translate'), (closestPointNode + '.inPosition')) attributes.doConnectAttr((controlSurface[0] + '.worldMesh'), (closestPointNode + '.inMesh')) return closestPointNode
def returnClosestPointOnSurfaceInfo(targetObj, surface): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns pertinent info of the closest point of a mesh to a target object - position, normal, parameterU,parameterV,closestFaceIndex,closestVertexIndex ARGUMENTS: targetObj(string) mesh(string) RETURNS: closestPointInfo(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ # make the closest point node # closestPointNode = mc.createNode ('closestPointOnSurface') pointOnSurfaceNode = mc.createNode ('pointOnSurfaceInfo') controlSurface = mc.listRelatives(surface,shapes=True) #>>>Surface Info #Thanks - http://www.kylenikolich.com/scripting/lod/parentToSurface.mel f_minU = attributes.doGetAttr(controlSurface[0],'mnu') f_maxU = attributes.doGetAttr(controlSurface[0],'mxu') f_sizeU = f_maxU - f_minU f_minV = attributes.doGetAttr(controlSurface[0],'mnv') f_maxV = attributes.doGetAttr(controlSurface[0],'mxv') f_sizeV = f_maxV - f_minV # to account for target objects in heirarchies # pos = returnWorldSpacePosition(targetObj) attributes.doSetAttr(closestPointNode,'inPositionX',pos[0]) attributes.doSetAttr(closestPointNode,'inPositionY',pos[1]) attributes.doSetAttr(closestPointNode,'inPositionZ',pos[2]) attributes.doConnectAttr((controlSurface[0]+'.worldSpace'),(closestPointNode+'.inputSurface')) # Connect the info node to the surface # attributes.doConnectAttr ((controlSurface[0]+'.local'),(pointOnSurfaceNode+'.inputSurface')) # Contect the pos group to the info node# attributes.doConnectAttr ((closestPointNode+'.parameterU'),(pointOnSurfaceNode+'.parameterU')) attributes.doConnectAttr ((closestPointNode+'.parameterV'),(pointOnSurfaceNode+'.parameterV')) pointInfo = {} pointInfo['position']=attributes.doGetAttr(pointOnSurfaceNode,'position') pointInfo['normal']=attributes.doGetAttr(pointOnSurfaceNode,'normal') pointInfo['parameterU']=mc.getAttr(pointOnSurfaceNode+'.parameterU') pointInfo['parameterV']=mc.getAttr(pointOnSurfaceNode+'.parameterV') pointInfo['normalizedU'] = (pointInfo['parameterU'] + f_minU)/f_sizeU pointInfo['normalizedV'] = (pointInfo['parameterV'] + f_minV)/f_sizeV pointInfo['tangentU']=mc.getAttr(pointOnSurfaceNode+'.tangentU') pointInfo['tangentV']=mc.getAttr(pointOnSurfaceNode+'.tangentV') mc.delete(closestPointNode) mc.delete(pointOnSurfaceNode) log.debug(pointInfo) return pointInfo
def add_follicle(mesh, name='follicle'): """ Creates named follicle node on a mesh :parameters: mesh(str): Surface to attach to name(str): base name for the follicle :returns [newNode, newTransform] """ _str_func = "add_follicle" _node = create(name, 'follicle') if SEARCH.is_shape(mesh): _surface = mesh else: _surface = mc.listRelatives(mesh, shapes=True, fullPath=True)[0] _type = VALID.get_mayaType(_surface) _trans = SEARCH.get_transform(_node) attributes.doConnectAttr( (_surface + '.worldMatrix[0]'), (_node + '.inputWorldMatrix')) #surface to follicle node if _type == 'mesh': attributes.doConnectAttr( (_surface + '.outMesh'), (_node + '.inputMesh')) #surface mesh to follicle input mesh else: attributes.doConnectAttr( (_surface + '.local'), (_node + '.inputSurface')) #surface mesh to follicle input mesh attributes.doConnectAttr((_node + '.outTranslate'), (_trans + '.translate')) attributes.doConnectAttr((_node + '.outRotate'), (_trans + '.rotate')) #ATTR.set_message(_node,'follTrans',_trans) #ATTR.set_message(_trans,'follNode',_node) attributes.doSetLockHideKeyableAttr(_trans) return [_node, _trans] """follicleNode = createNamedNode((name),'follicle')
def groupToConditionNodeSet(group, chooseAttr='switcher', controlObject=None, connectTo='visibility'): """ Hack job for the gig to make a visibility switcher for all the first level of children of a group """ children = search.returnChildrenObjects(group) #Check for children if not children: #If none, break out guiFactory("'%s' has no children! Aborted." % group) return False if controlObject is None: controlObject = group #Make our attr a = AttrFactory.AttrFactory(controlObject, chooseAttr, 'enum') children.insert(0, 'none') print children if len(children) == 2: a.setEnum('off:on') else: a.setEnum(':'.join(children)) for i, c in enumerate(children[1:]): print i print c #see if the node exists condNodeTest = attributes.returnDriverObject('%s.%s' % (c, connectTo)) if condNodeTest: buffer = condNodeTest else: if mc.objExists('%s_condNode' % c): mc.delete('%s_condNode' % c) buffer = nodes.createNamedNode('%s_picker' % c, 'condition') #Make our node print buffer attributes.doSetAttr(buffer, 'secondTerm', i + 1) attributes.doSetAttr(buffer, 'colorIfTrueR', 1) attributes.doSetAttr(buffer, 'colorIfFalseR', 0) a.doConnectOut('%s.firstTerm' % buffer) attributes.doConnectAttr('%s.outColorR' % buffer, '%s.%s' % (c, connectTo))
def createFollicleOnMesh(mesh, name='follicle'): """ Creates named follicle node on a mesh Keywords mesh -- mesh to attach to name -- base name to use ('follicle' default) Returns [follicleNode,follicleTransform] """ assert mc.objExists(mesh), "'%s' doesn't exist!" % mesh #objType = search.returnObjectType(mesh) #assert objType in ['mesh','nurbsSurface'],("'%s' isn't a mesh"%mesh) follicleNode = createNamedNode((name), 'follicle') """ make the closest point node """ #closestPointNode = createNamedNode((targetObj+'_to_'+mesh),'closestPointOnMesh') controlSurface = mc.listRelatives(mesh, shapes=True)[0] follicleTransform = mc.listRelatives(follicleNode, p=True)[0] attributes.doConnectAttr( (controlSurface + '.worldMatrix[0]'), (follicleNode + '.inputWorldMatrix')) #surface to follicle node if objType == 'mesh': attributes.doConnectAttr( (controlSurface + '.outMesh'), (follicleNode + '.inputMesh')) #surface mesh to follicle input mesh else: attributes.doConnectAttr( (controlSurface + '.local'), (follicleNode + '.inputSurface')) #surface mesh to follicle input mesh attributes.doConnectAttr((follicleNode + '.outTranslate'), (follicleTransform + '.translate')) attributes.doConnectAttr((follicleNode + '.outRotate'), (follicleTransform + '.rotate')) attributes.doSetLockHideKeyableAttr(follicleTransform) return [follicleNode, follicleTransform]
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 singleObjectVisToggle(obj,chooseAttr = 'switcher', controlObject = None, connectTo = 'visibility'): #Make our attr a = AttrFactory.AttrFactory(controlObject,chooseAttr,'enum') a.setEnum('off:on') condNodeTest = attributes.returnDriverObject('%s.%s'%(obj,connectTo)) if condNodeTest: buffer = condNodeTest else: if mc.objExists('%s_condNode'%obj): mc.delete('%s_condNode'%obj) buffer = nodes.createNamedNode('%s_picker'%obj,'condition') #Make our node print buffer attributes.doSetAttr(buffer,'secondTerm',1) attributes.doSetAttr(buffer,'colorIfTrueR',1) attributes.doSetAttr(buffer,'colorIfFalseR',0) a.doConnectOut('%s.firstTerm'%buffer) attributes.doConnectAttr('%s.outColorR'%buffer,'%s.%s'%(obj,connectTo))
def plasticConstraintsAndScaleFromObjectToTransform(): selection = mc.ls(sl=True, flatten=True) for obj in selection: #Make a transform group = rigging.groupMeObject(obj,maintainParent = True) #Get scale connections objScaleConnections = [] for s in 'sx','sy','sz': buffer = attributes.returnDriverAttribute(obj+'.'+s) attributes.doBreakConnection(obj+'.'+s) attributes.doConnectAttr(buffer,(group+'.'+s)) # Get constraint info from obj objConstraints = constraints.returnObjectConstraints(obj) for const in objConstraints: constraintTargets = constraints.returnConstraintTargets(const) mc.delete(const) mc.parentConstraint(constraintTargets,group, maintainOffset = True)
def returnClosestPointOnMeshInfo(targetObj, mesh): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns pertinent info of the closest point of a mesh to a target object - position, normal, parameterU,parameterV,closestFaceIndex,closestVertexIndex ARGUMENTS: targetObj(string) mesh(string) RETURNS: closestPointInfo(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ make the closest point node """ closestPointNode = mc.createNode ('closestPointOnMesh') controlSurface = mc.listRelatives(mesh,shapes=True) """ to account for target objects in heirarchies """ attributes.doConnectAttr((targetObj+'.translate'),(closestPointNode+'.inPosition')) attributes.doConnectAttr((controlSurface[0]+'.worldMesh'),(closestPointNode+'.inMesh')) attributes.doConnectAttr((controlSurface[0]+'.matrix'),(closestPointNode+'.inputMatrix')) pointInfo = {} pointInfo['position']=attributes.doGetAttr(closestPointNode,'position') pointInfo['normal']=attributes.doGetAttr(closestPointNode,'normal') pointInfo['parameterU']=mc.getAttr(closestPointNode+'.parameterU') pointInfo['parameterV']=mc.getAttr(closestPointNode+'.parameterV') pointInfo['closestFaceIndex']=mc.getAttr(closestPointNode+'.closestFaceIndex') pointInfo['closestVertexIndex']=mc.getAttr(closestPointNode+'.closestVertexIndex') mc.delete(closestPointNode) return pointInfo
def insertMulitiplyDivideBridge(drivenAttribute, newDriver): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Inserts a multiplyDivide bridge node for help taking care of compound scales 1) get the driver 2) create node >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ # >>> Get variables driverAttribute = attributes.returnDriverAttribute(drivenAttribute) print driverAttribute driverBuffer = driverAttribute.split(".") drivenBuffer = drivenAttribute.split(".") # >>> Create bridgeMDNode = createNamedNode((driverBuffer[0] + "_to_" + newDriver), "multiplyDivide") # >>> Connect attributes.doConnectAttr(driverAttribute, (bridgeMDNode + ".input1")) attributes.doConnectAttr(newDriver, (bridgeMDNode + ".input2")) attributes.doConnectAttr((bridgeMDNode + ".output"), drivenAttribute) """
def insertMulitiplyDivideBridge(drivenAttribute, newDriver): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Inserts a multiplyDivide bridge node for help taking care of compound scales 1) get the driver 2) create node >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>> Get variables driverAttribute = attributes.returnDriverAttribute(drivenAttribute) print driverAttribute driverBuffer = driverAttribute.split('.') drivenBuffer = drivenAttribute.split('.') #>>> Create bridgeMDNode = createNamedNode((driverBuffer[0] + '_to_' + newDriver), 'multiplyDivide') #>>> Connect attributes.doConnectAttr(driverAttribute, (bridgeMDNode + '.input1')) attributes.doConnectAttr(newDriver, (bridgeMDNode + '.input2')) attributes.doConnectAttr((bridgeMDNode + '.output'), drivenAttribute) """
def createFollicleOnMesh(mesh, name="follicle"): """ Creates named follicle node on a mesh Keywords mesh -- mesh to attach to name -- base name to use ('follicle' default) Returns [follicleNode,follicleTransform] """ assert mc.objExists(mesh), "'%s' doesn't exist!" % mesh objType = search.returnObjectType(mesh) assert objType in ["mesh", "nurbsSurface"], "'%s' isn't a mesh" % mesh follicleNode = createNamedNode((name), "follicle") """ make the closest point node """ # closestPointNode = createNamedNode((targetObj+'_to_'+mesh),'closestPointOnMesh') controlSurface = mc.listRelatives(mesh, shapes=True)[0] follicleTransform = mc.listRelatives(follicleNode, p=True)[0] attributes.doConnectAttr( (controlSurface + ".worldMatrix[0]"), (follicleNode + ".inputWorldMatrix") ) # surface to follicle node if objType == "mesh": attributes.doConnectAttr( (controlSurface + ".outMesh"), (follicleNode + ".inputMesh") ) # surface mesh to follicle input mesh else: attributes.doConnectAttr( (controlSurface + ".local"), (follicleNode + ".inputSurface") ) # surface mesh to follicle input mesh attributes.doConnectAttr((follicleNode + ".outTranslate"), (follicleTransform + ".translate")) attributes.doConnectAttr((follicleNode + ".outRotate"), (follicleTransform + ".rotate")) attributes.doSetLockHideKeyableAttr(follicleTransform) return [follicleNode, follicleTransform]
def groupToConditionNodeSet(group,chooseAttr = 'switcher', controlObject = None, connectTo = 'visibility'): """ Hack job for the gig to make a visibility switcher for all the first level of children of a group """ children = search.returnChildrenObjects(group) #Check for children if not children: #If none, break out guiFactory("'%s' has no children! Aborted."%group) return False if controlObject is None: controlObject = group #Make our attr a = AttrFactory.AttrFactory(controlObject,chooseAttr,'enum') children.insert(0,'none') print children if len(children) == 2: a.setEnum('off:on') else: a.setEnum(':'.join(children)) for i,c in enumerate(children[1:]): print i print c #see if the node exists condNodeTest = attributes.returnDriverObject('%s.%s'%(c,connectTo)) if condNodeTest: buffer = condNodeTest else: if mc.objExists('%s_condNode'%c): mc.delete('%s_condNode'%c) buffer = nodes.createNamedNode('%s_picker'%c,'condition') #Make our node print buffer attributes.doSetAttr(buffer,'secondTerm',i+1) attributes.doSetAttr(buffer,'colorIfTrueR',1) attributes.doSetAttr(buffer,'colorIfFalseR',0) a.doConnectOut('%s.firstTerm'%buffer) attributes.doConnectAttr('%s.outColorR'%buffer,'%s.%s'%(c,connectTo))
def singleObjectVisToggle(obj, chooseAttr='switcher', controlObject=None, connectTo='visibility'): #Make our attr a = AttrFactory.AttrFactory(controlObject, chooseAttr, 'enum') a.setEnum('off:on') condNodeTest = attributes.returnDriverObject('%s.%s' % (obj, connectTo)) if condNodeTest: buffer = condNodeTest else: if mc.objExists('%s_condNode' % obj): mc.delete('%s_condNode' % obj) buffer = nodes.createNamedNode('%s_picker' % obj, 'condition') #Make our node print buffer attributes.doSetAttr(buffer, 'secondTerm', 1) attributes.doSetAttr(buffer, 'colorIfTrueR', 1) attributes.doSetAttr(buffer, 'colorIfFalseR', 0) a.doConnectOut('%s.firstTerm' % buffer) attributes.doConnectAttr('%s.outColorR' % buffer, '%s.%s' % (obj, connectTo))
def attachObjectToMesh(obj, mesh, aim=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Rotation not working! DESCRIPTION: Script to rename a joint chain list ARGUMENTS: jointList(list) - list of joints in order startJointName(string) - what you want the root named interiorJointRootName(string) - what you want the iterative name to be RETURNS: newJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ Make a transform group """ surfaceFollowGroup = mc.group(w=True, empty=True) originalPosGroup = rigging.groupMeObject(obj, False) surfaceFollowGroup = mc.rename(surfaceFollowGroup, (obj + '_surfaceFollowGroup')) attributes.storeInfo(surfaceFollowGroup, 'object', obj) """ make the closest point node """ closestPointNode = mc.createNode('closestPointOnMesh') controlSurface = mc.listRelatives(mesh, shapes=True) """ to account for target objects in heirarchies """ attributes.doConnectAttr((originalPosGroup + '.translate'), (closestPointNode + '.inPosition')) attributes.doConnectAttr((controlSurface[0] + '.worldMesh'), (closestPointNode + '.inMesh')) attributes.doConnectAttr((controlSurface[0] + '.worldMatrix'), (closestPointNode + '.inputMatrix')) """ Contect the locator to the info node""" attributes.doConnectAttr((closestPointNode + '.position'), (surfaceFollowGroup + '.translate')) mc.normalConstraint(mesh, surfaceFollowGroup, worldUpType='object', worldUpObject=originalPosGroup) mc.parentConstraint(mesh, originalPosGroup, maintainOffset=True) return [surfaceFollowGroup]
def attachObjectToMesh (obj, mesh, aim=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Rotation not working! DESCRIPTION: Script to rename a joint chain list ARGUMENTS: jointList(list) - list of joints in order startJointName(string) - what you want the root named interiorJointRootName(string) - what you want the iterative name to be RETURNS: newJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ Make a transform group """ surfaceFollowGroup = mc.group (w=True, empty=True) originalPosGroup = rigging.groupMeObject(obj,False) surfaceFollowGroup = mc.rename(surfaceFollowGroup,(obj+'_surfaceFollowGroup')) attributes.storeInfo(surfaceFollowGroup,'object',obj) """ make the closest point node """ closestPointNode = mc.createNode ('closestPointOnMesh') controlSurface = mc.listRelatives(mesh,shapes=True) """ to account for target objects in heirarchies """ attributes.doConnectAttr((originalPosGroup+'.translate'),(closestPointNode+'.inPosition')) attributes.doConnectAttr((controlSurface[0]+'.worldMesh'),(closestPointNode+'.inMesh')) attributes.doConnectAttr((controlSurface[0]+'.worldMatrix'),(closestPointNode+'.inputMatrix')) """ Contect the locator to the info node""" attributes.doConnectAttr ((closestPointNode+'.position'),(surfaceFollowGroup+'.translate')) mc.normalConstraint(mesh,surfaceFollowGroup,worldUpType='object',worldUpObject=originalPosGroup) mc.parentConstraint(mesh,originalPosGroup, maintainOffset = True) return [surfaceFollowGroup]
def locMeClosestPointOnMesh(obj, mesh): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the closest point of a mesh to a target object ARGUMENTS: obj(string) mesh(string) RETURNS: locatorName(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ locatorName = locMeObject(obj) """ make the closest point node """ closestPointNode = mc.createNode ('closestPointOnMesh') controlSurface = mc.listRelatives(mesh,shapes=True) """ to account for target objects in heirarchies """ attributes.doConnectAttr((obj+'.translate'),(closestPointNode+'.inPosition')) attributes.doConnectAttr((controlSurface[0]+'.worldMesh'),(closestPointNode+'.inMesh')) attributes.doConnectAttr((controlSurface[0]+'.worldMatrix'),(closestPointNode+'.inputMatrix')) """ Contect the locator to the info node""" attributes.doConnectAttr ((closestPointNode+'.position'),(locatorName+'.translate')) faceIndex = mc.getAttr(closestPointNode+'.closestFaceIndex') face = ('%s%s%i%s' %(mesh,'.f[',faceIndex,']')) mc.delete(closestPointNode) #Rotate constBuffer = mc.normalConstraint(face,locatorName) mc.delete(constBuffer[0]) return locatorName
def locMeClosestPointOnMesh(obj, mesh): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the closest point of a mesh to a target object ARGUMENTS: obj(string) mesh(string) RETURNS: locatorName(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ locatorName = locMeObject(obj) """ make the closest point node """ closestPointNode = mc.createNode('closestPointOnMesh') controlSurface = mc.listRelatives(mesh, shapes=True) """ to account for target objects in heirarchies """ attributes.doConnectAttr((obj + '.translate'), (closestPointNode + '.inPosition')) attributes.doConnectAttr((controlSurface[0] + '.worldMesh'), (closestPointNode + '.inMesh')) attributes.doConnectAttr((controlSurface[0] + '.worldMatrix'), (closestPointNode + '.inputMatrix')) """ Contect the locator to the info node""" attributes.doConnectAttr((closestPointNode + '.position'), (locatorName + '.translate')) faceIndex = mc.getAttr(closestPointNode + '.closestFaceIndex') face = ('%s%s%i%s' % (mesh, '.f[', faceIndex, ']')) mc.delete(closestPointNode) #Rotate constBuffer = mc.normalConstraint(face, locatorName) mc.delete(constBuffer[0]) return locatorName
def returnClosestPointOnMeshInfoFromPos(pos, mesh): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns pertinent info of the closest point of a mesh to a position in space - position, normal, parameterU,parameterV,closestFaceIndex,closestVertexIndex ARGUMENTS: pos(string) mesh(string) RETURNS: closestPointInfo(dict) Keys: position normal parameterU parameterV closestFaceIndex closestVertexIndex >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ make the closest point node """ closestPointNode = mc.createNode ('closestPointOnMesh') controlSurface = mc.listRelatives(mesh,shapes=True) """ to account for target objects in heirarchies """ locBuffer = mc.spaceLocator() mc.move (pos[0],pos[1],pos[2], locBuffer[0]) attributes.doConnectAttr((locBuffer[0]+'.translate'),(closestPointNode+'.inPosition')) attributes.doConnectAttr((controlSurface[0]+'.worldMesh'),(closestPointNode+'.inMesh')) attributes.doConnectAttr((locBuffer[0]+'.matrix'),(closestPointNode+'.inputMatrix')) pointInfo = {} pointInfo['position']=attributes.doGetAttr(closestPointNode,'position') pointInfo['normal']=attributes.doGetAttr(closestPointNode,'normal') pointInfo['parameterU']=mc.getAttr(closestPointNode+'.parameterU') pointInfo['parameterV']=mc.getAttr(closestPointNode+'.parameterV') pointInfo['closestFaceIndex']=mc.getAttr(closestPointNode+'.closestFaceIndex') pointInfo['closestVertexIndex']=mc.getAttr(closestPointNode+'.closestVertexIndex') mc.delete(closestPointNode) mc.delete(locBuffer[0]) return pointInfo
def doConnectScaleToCGMTagOnObject(objectList, cgmTag, storageObject): attributeList = [] for obj in objectList: userAttrsData = attributes.returnUserAttrsToDict(obj) success = False for key in userAttrsData.keys(): if key == cgmTag: success = True buffer = attributes.addFloatAttributeToObject (storageObject, userAttrsData.get(key), dv = 1 ) if success: attributes.doConnectAttr(buffer,(obj+'.scaleX')) attributes.doConnectAttr(buffer,(obj+'.scaleY')) attributes.doConnectAttr(buffer,(obj+'.scaleZ')) attributeList.append(buffer)
self.md_return["controlLoc"] = mi_controlLoc if self.b_attachControlLoc: mi_group = cgmMeta.asMeta(mi_controlLoc.doGroup(), 'cgmObject', setClass=True) mi_group.parent = mi_follicleAttachTrans #Create decompose node -------------------------------------------------------------- mi_worldTranslate = cgmMeta.cgmNode(nodeType='decomposeMatrix') mi_worldTranslate.doStore('cgmName', self.mi_obj) mi_worldTranslate.doName() self.mi_worldTranslate = mi_worldTranslate attributes.doConnectAttr( "%s.worldMatrix" % (mi_controlLoc.mNode), "%s.%s" % (mi_worldTranslate.mNode, 'inputMatrix')) #Create node -------------------------------------------------------------- mi_cpos = NodeF.createNormalizedClosestPointNode( self.mi_obj, self.mi_targetSurface) attributes.doConnectAttr( (mi_cpos.mNode + '.out_uNormal'), (mi_follicleFollowShape.mNode + '.parameterU')) attributes.doConnectAttr( (mi_cpos.mNode + '.out_vNormal'), (mi_follicleFollowShape.mNode + '.parameterV')) #attributes.doConnectAttr ((mi_controlLoc.mNode+'.translate'),(mi_cpos.mNode+'.inPosition')) attributes.doConnectAttr( (mi_worldTranslate.mNode + '.outputTranslate'),
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
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 bakeBlendShapeNodeToTargetObject(targetObject,sourceObject, blendShapeNode, baseNameToUse = False, stripPrefix = False,ignoreInbetweens = False, ignoreTargets = False, transferConnections = True): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Function for baking a series of blendshapes from one object to another ARGUMENTS: targetObject(string) sourceObject(string) blendShapeNode(string) the node to bake from baseNameToUse(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied stripPrefix(bool) ignoreInbetweens(bool) ignoreTargets(list) - list of targets to ignore transferConnections(bool) - if True, builds a new blendshape node and transfers the connections from our base objects 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 baseNameToUse == False: baseName = '' else: baseName = baseNameToUse + '_' """ wrap deform object """ wrapBuffer = wrapDeformObject(targetObject,sourceObject,True) targetObjectBaked = wrapBuffer[1] #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Meat of it #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> blendShapeNodeChannels = returnBlendShapeAttributes(blendShapeNode) blendShapeShortNames = [] """ first loop stores and sets everything to 0 """ for shape in blendShapeNodeChannels: keepGoing = True if ignoreTargets != False: if shape in ignoreTargets: keepGoing = False else: keepGoing = True blendShapeBuffer = (blendShapeNode + '.' + shape) """ get the connection """ blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer)) if keepGoing == True: print ('breaking....' + blendShapeBuffer) """break it """ attributes.doBreakConnection(blendShapeBuffer) attributes.doSetAttr(blendShapeNode,shape,0) # Bake it bakedGeo = bakeBlendShapes(sourceObject, targetObjectBaked, blendShapeNode, baseNameToUse, stripPrefix, ignoreInbetweens, ignoreTargets) """ restore connections """ for shape in blendShapeNodeChannels: keepGoing = True if ignoreTargets != False: if shape in ignoreTargets: keepGoing = False else: keepGoing = True currentIndex = blendShapeNodeChannels.index(shape) blendShapeBuffer = (blendShapeNode+'.'+shape) """ Restore the connection """ if keepGoing == True: print ('connecting....' + blendShapeBuffer) print blendShapeConnections[currentIndex] if blendShapeConnections[currentIndex] != False: attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer) # Need to build a new blendshape node? if transferConnections == True: # Build it newBlendShapeNode = buildBlendShapeNode(targetObject, bakedGeo, baseNameToUse) newBlendShapeChannels = returnBlendShapeAttributes(newBlendShapeNode) for shape in newBlendShapeChannels: blendShapeBuffer = (newBlendShapeNode+'.'+shape) currentIndex = newBlendShapeChannels.index(shape) 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) if baseNameToUse != False: 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) mc.delete(targetObjectBaked) return returnList
def locMeClosestUVOnSurface(obj, surface, pivotOnSurfaceOnly=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's of a surface ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ locBuffer = locMeObject(obj) pivotLoc = locMeObject(obj) controlSurface = mc.listRelatives(surface, shapes=True) """ make the closest point node """ closestPointNode = mc.createNode('closestPointOnSurface') """ to account for target objects in heirarchies """ attributes.doConnectAttr((locBuffer + '.translate'), (closestPointNode + '.inPosition')) attributes.doConnectAttr((controlSurface[0] + '.worldSpace'), (closestPointNode + '.inputSurface')) """ make the pointOnSurfaceNode """ pointOnSurfaceNode = mc.createNode('pointOnSurfaceInfo') """ Connect the info node to the surface """ attributes.doConnectAttr((controlSurface[0] + '.worldSpace'), (pointOnSurfaceNode + '.inputSurface')) """ Contect the pos group to the info node""" attributes.doConnectAttr((pointOnSurfaceNode + '.position'), (pivotLoc + '.translate')) attributes.doConnectAttr((closestPointNode + '.parameterU'), (pointOnSurfaceNode + '.parameterU')) attributes.doConnectAttr((closestPointNode + '.parameterV'), (pointOnSurfaceNode + '.parameterV')) if pivotOnSurfaceOnly != True: position.movePointSnap(locBuffer, pivotLoc) else: rigging.copyPivot(locBuffer, pivotLoc) mc.delete(closestPointNode) mc.delete(pointOnSurfaceNode) mc.delete(pivotLoc) #Rotate constBuffer = mc.normalConstraint(surface, locBuffer) mc.delete(constBuffer[0]) return locBuffer
mc.connectAttr("%s.outputG"%mi_clampUpr.mNode,"%s.r%s"%(mi_resultLoc.mNode,orientation[1])) from cgm.lib import attributes #Lwr lid """ Need Only want a value greater than the lwrDnStart should start to push things down """ mc.createNode('clamp') mc.createNode('setRange') mc.createNode('remapValue') mi_clampLwr = cgmMeta.cgmNode('clamp2') mi_remapLwr = cgmMeta.cgmNode('remapValue1') mi_remapLwr.outValue mi_lwrResultLoc = cgmMeta.cgmObject('lwrLid_result') mi_controlObject = mi_lwrResultLoc mPlug_lwrUpLimit = cgmMeta.cgmAttr(mi_controlObject,"lwrUpLimit",attrType='float',value=-26,keyable=False,hidden=False) mPlug_lwrDnLimit = cgmMeta.cgmAttr(mi_controlObject,"lwrDnLimit",attrType='float',value=35,keyable=False,hidden=False) mPlug_lwrDnStart = cgmMeta.cgmAttr(mi_controlObject,"lwrDnStart",attrType='float',value=5,keyable=False,hidden=False) mPlug_driverUp.doConnectOut("%s.inputValue"%mi_remapLwr.mNode) mPlug_lwrDnStart.doConnectOut("%s.inputMin"%mi_remapLwr.mNode) mi_remapLwr.inputLimit = 50 mPlug_lwrDnLimit.doConnectOut("%s.outputLimit"%mi_remapLwr.mNode) attributes.doConnectAttr("%s.outValue"%mi_remapLwr.mNode,"%s.r%s"%(mi_lwrResultLoc.mNode,orientation[2])) mPlug_driverUp.doConnectOut("%s.inputR"%mi_clampLwr.mNode) mPlug_lwrDnLimit.doConnectOut("%s.maxR"%mi_clampLwr.mNode) mPlug_lwrUpLimit.doConnectOut("%s.minR"%mi_clampLwr.mNode) mc.connectAttr("%s.outputR"%mi_clampLwr.mNode,"%s.r%s"%(mi_lwrResultLoc.mNode,orientation[2])) mc.connectAttr("%s.outputG"%mi_clampUpr.mNode,"%s.r%s"%(mi_lwrResultLoc.mNode,orientation[1]))
def attachAimedObjectToSurface(obj, surface, aimObject, parent=True): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Script to rename a joint chain list ARGUMENTS: jointList(list) - list of joints in order startJointName(string) - what you want the root named interiorJointRootName(string) - what you want the iterative name to be RETURNS: newJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ Make a transform group """ surfaceLoc = locators.locMeClosestUVOnSurface(obj, surface) surfaceFollowGroup = rigging.groupMeObject(surfaceLoc, False) transformGroup = rigging.groupMeObject(obj, False) surfaceFollowGroup = mc.rename(surfaceFollowGroup, (obj + '_surfaceFollowGroup')) attributes.storeInfo(surfaceFollowGroup, 'object', obj) transformGroup = mc.rename(transformGroup, (obj + '_surfaceFollowTransformGroup')) attributes.storeInfo(transformGroup, 'object', obj) controlSurface = mc.listRelatives(surface, shapes=True) """ make the node """ closestPointNode = mc.createNode('closestPointOnSurface', name=(obj + '_closestPointInfoNode')) """ to account for target objects in heirarchies """ attributes.doConnectAttr((surfaceLoc + '.translate'), (closestPointNode + '.inPosition')) attributes.doConnectAttr((controlSurface[0] + '.worldSpace'), (closestPointNode + '.inputSurface')) pointOnSurfaceNode = mc.createNode('pointOnSurfaceInfo', name=(obj + '_posInfoNode')) """ Connect the info node to the surface """ attributes.doConnectAttr((controlSurface[0] + '.worldSpace'), (pointOnSurfaceNode + '.inputSurface')) """ Contect the pos group to the info node""" attributes.doConnectAttr((pointOnSurfaceNode + '.position'), (surfaceFollowGroup + '.translate')) attributes.doConnectAttr((closestPointNode + '.parameterU'), (pointOnSurfaceNode + '.parameterU')) attributes.doConnectAttr((closestPointNode + '.parameterV'), (pointOnSurfaceNode + '.parameterV')) """ if we wanna aim """ if aimObject != False: """ make some locs """ upLoc = locators.locMeObject(surface) aimLoc = locators.locMeObject(aimObject) attributes.storeInfo(upLoc, 'cgmName', obj) attributes.storeInfo(upLoc, 'cgmTypeModifier', 'up') upLoc = NameFactory.doNameObject(upLoc) attributes.storeInfo(aimLoc, 'cgmName', aimObject) attributes.storeInfo(aimLoc, 'cgmTypeModifier', 'aim') aimLoc = NameFactory.doNameObject(aimLoc) attributes.storeInfo(surfaceFollowGroup, 'locatorUp', upLoc) attributes.storeInfo(surfaceFollowGroup, 'aimLoc', aimLoc) #mc.parent(upLoc,aimObject) boundingBoxSize = distance.returnBoundingBoxSize(surface) distance = max(boundingBoxSize) * 2 mc.xform(upLoc, t=[0, distance, 0], ws=True, r=True) attributes.doConnectAttr((aimLoc + '.translate'), (closestPointNode + '.inPosition')) """ constrain the aim loc to the aim object """ pointConstraintBuffer = mc.pointConstraint(aimObject, aimLoc, maintainOffset=True, weight=1) """ aim it """ aimConstraintBuffer = mc.aimConstraint(aimLoc, surfaceFollowGroup, maintainOffset=True, weight=1, aimVector=[0, 0, 1], upVector=[0, 1, 0], worldUpObject=upLoc, worldUpType='object') """ aim the controller back at the obj""" aimConstraintBuffer = mc.aimConstraint(obj, aimLoc, maintainOffset=True, weight=1, aimVector=[0, 0, -1], upVector=[0, 1, 0], worldUpObject=upLoc, worldUpType='object') mc.parent(upLoc, aimObject) else: mc.delete(closestPointNode) transformGroup = rigging.doParentReturnName(transformGroup, surfaceFollowGroup) """finally parent it""" if parent == True: mc.parent(obj, transformGroup) if parent == 'constrain': mc.parentConstraint(transformGroup, obj, maintainOffset=True) mc.delete(surfaceLoc) return [transformGroup, surfaceFollowGroup]
def attachAimedObjectToSurface (obj, surface, aimObject, parent = True): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Script to rename a joint chain list ARGUMENTS: jointList(list) - list of joints in order startJointName(string) - what you want the root named interiorJointRootName(string) - what you want the iterative name to be RETURNS: newJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ """ Make a transform group """ surfaceLoc = locators.locMeClosestUVOnSurface(obj,surface) surfaceFollowGroup = rigging.groupMeObject(surfaceLoc,False) transformGroup = rigging.groupMeObject(obj,False) surfaceFollowGroup = mc.rename(surfaceFollowGroup,(obj+'_surfaceFollowGroup')) attributes.storeInfo(surfaceFollowGroup,'object',obj) transformGroup = mc.rename(transformGroup,(obj+'_surfaceFollowTransformGroup')) attributes.storeInfo(transformGroup,'object',obj) controlSurface = mc.listRelatives(surface,shapes=True) """ make the node """ closestPointNode = mc.createNode ('closestPointOnSurface',name= (obj+'_closestPointInfoNode')) """ to account for target objects in heirarchies """ attributes.doConnectAttr((surfaceLoc+'.translate'),(closestPointNode+'.inPosition')) attributes.doConnectAttr((controlSurface[0]+'.worldSpace'),(closestPointNode+'.inputSurface')) pointOnSurfaceNode = mc.createNode ('pointOnSurfaceInfo',name= (obj+'_posInfoNode')) """ Connect the info node to the surface """ attributes.doConnectAttr ((controlSurface[0]+'.worldSpace'),(pointOnSurfaceNode+'.inputSurface')) """ Contect the pos group to the info node""" attributes.doConnectAttr ((pointOnSurfaceNode+'.position'),(surfaceFollowGroup+'.translate')) attributes.doConnectAttr ((closestPointNode+'.parameterU'),(pointOnSurfaceNode+'.parameterU')) attributes.doConnectAttr ((closestPointNode+'.parameterV'),(pointOnSurfaceNode+'.parameterV')) """ if we wanna aim """ if aimObject != False: """ make some locs """ upLoc = locators.locMeObject(surface) aimLoc = locators.locMeObject(aimObject) attributes.storeInfo(upLoc,'cgmName',obj) attributes.storeInfo(upLoc,'cgmTypeModifier','up') upLoc = NameFactoryOld.doNameObject(upLoc) attributes.storeInfo(aimLoc,'cgmName',aimObject) attributes.storeInfo(aimLoc,'cgmTypeModifier','aim') aimLoc = NameFactoryOld.doNameObject(aimLoc) attributes.storeInfo(surfaceFollowGroup,'locatorUp',upLoc) attributes.storeInfo(surfaceFollowGroup,'aimLoc',aimLoc) #mc.parent(upLoc,aimObject) boundingBoxSize = distance.returnBoundingBoxSize(surface) distance = max(boundingBoxSize)*2 mc.xform(upLoc,t = [0,distance,0],ws=True,r=True) attributes.doConnectAttr((aimLoc+'.translate'),(closestPointNode+'.inPosition')) """ constrain the aim loc to the aim object """ pointConstraintBuffer = mc.pointConstraint(aimObject,aimLoc,maintainOffset = True, weight = 1) """ aim it """ aimConstraintBuffer = mc.aimConstraint(aimLoc,surfaceFollowGroup,maintainOffset = True, weight = 1, aimVector = [0,0,1], upVector = [0,1,0], worldUpObject = upLoc, worldUpType = 'object' ) """ aim the controller back at the obj""" aimConstraintBuffer = mc.aimConstraint(obj,aimLoc,maintainOffset = True, weight = 1, aimVector = [0,0,-1], upVector = [0,1,0], worldUpObject = upLoc, worldUpType = 'object' ) mc.parent(upLoc,aimObject) else: mc.delete(closestPointNode) transformGroup = rigging.doParentReturnName(transformGroup,surfaceFollowGroup) """finally parent it""" if parent == True: mc.parent(obj,transformGroup) if parent == 'constrain': mc.parentConstraint(transformGroup,obj,maintainOffset = True) mc.delete(surfaceLoc) return [transformGroup,surfaceFollowGroup]
#1==driver #2>1:1,4 #3>1,4:4 #4>1:6 #5>4:6 #6 == driver driver1 = ['test','asdf'] assert type(driver1) is list and len(driver1) == 2,"Driver1 wrong: %s"%driver1 [[u'spine_1_surfaceJoint', u'spine_2_surfaceJoint',u'sternum_surfaceJoint'], [u'spine_1_surfaceJoint', u'spine_1_1_surfaceJoint', u'spine_2_surfaceJoint'], [u'spine_2_surfaceJoint', u'spine_2_1_surfaceJoint', u'sternum_surfaceJoint']] # #Working 2 joint split from cgm.lib import attributes attributes.doConnectAttr('pelvis_influenceJoint.rotateZ','plusMinusAverage1.input1D[0]') attributes.doConnectAttr('spine_2_influenceJoint.rotateZ','plusMinusAverage1.input1D[1]') mc.ls('spine_2_1_surfaceJoint_ikH_poleVectorConstraint1',sn = True) attributes.doConnectAttr('plusMinusAverage1.output1D','plusMinusAverage2.input1D[0]') attributes.doConnectAttr('pelvis_influenceJoint.rotateZ','plusMinusAverage2.input1D[1]') attributes.doConnectAttr('plusMinusAverage1.output1D','plusMinusAverage3.input1D[0]') attributes.doConnectAttr('spine_2_influenceJoint.rotateZ','plusMinusAverage3.input1D[1]') attributes.doConnectAttr('plusMinusAverage2.output1D','spine_1_surfaceJoint_rotate_grp.ry') attributes.doConnectAttr('plusMinusAverage3.output1D','spine_1_1_surfaceJoint_rotate_grp.ry') attributes.doConnectAttr('plusMinusAverage1.output1D','multiplyDivide1.input1X') #mode 2 attributes.doSetAttr('multiplyDivide1','input2X',2)
def locMeClosestUVOnSurface(obj, surface, pivotOnSurfaceOnly = False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's of a surface ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ locBuffer = locMeObject(obj) pivotLoc = locMeObject(obj) controlSurface = mc.listRelatives(surface,shapes=True) """ make the closest point node """ closestPointNode = mc.createNode ('closestPointOnSurface') """ to account for target objects in heirarchies """ attributes.doConnectAttr((locBuffer+'.translate'),(closestPointNode+'.inPosition')) attributes.doConnectAttr((controlSurface[0]+'.worldSpace'),(closestPointNode+'.inputSurface')) """ make the pointOnSurfaceNode """ pointOnSurfaceNode = mc.createNode ('pointOnSurfaceInfo') """ Connect the info node to the surface """ attributes.doConnectAttr ((controlSurface[0]+'.worldSpace'),(pointOnSurfaceNode+'.inputSurface')) """ Contect the pos group to the info node""" attributes.doConnectAttr ((pointOnSurfaceNode+'.position'),(pivotLoc+'.translate')) attributes.doConnectAttr ((closestPointNode+'.parameterU'),(pointOnSurfaceNode+'.parameterU')) attributes.doConnectAttr ((closestPointNode+'.parameterV'),(pointOnSurfaceNode+'.parameterV')) if pivotOnSurfaceOnly != True: position.movePointSnap(locBuffer,pivotLoc) else: rigging.copyPivot(locBuffer,pivotLoc) mc.delete(closestPointNode) mc.delete(pointOnSurfaceNode) mc.delete(pivotLoc) #Rotate constBuffer = mc.normalConstraint(surface,locBuffer) mc.delete(constBuffer[0]) return locBuffer
def _create(self): #>> Quick links ============================================================================ d_closestInfo = self.d_closestInfo if self.b_attachControlLoc or not self.b_createControlLoc: try:#>>> Follicle ============================================================================ l_follicleInfo = nodes.createFollicleOnMesh(self.mi_targetSurface.mNode) mi_follicleAttachTrans = cgmMeta.asMeta(l_follicleInfo[1],'cgmObject',setClass=True) mi_follicleAttachShape = cgmMeta.asMeta(l_follicleInfo[0],'cgmNode') #> Name ---------------------------------------------------------------------------------- mi_follicleAttachTrans.doStore('cgmName',self.mi_obj.mNode) mi_follicleAttachTrans.addAttr('cgmTypeModifier','attach',lock=True) mi_follicleAttachTrans.doName() #>Set follicle value --------------------------------------------------------------------- mi_follicleAttachShape.parameterU = d_closestInfo['normalizedU'] mi_follicleAttachShape.parameterV = d_closestInfo['normalizedV'] self.mi_follicleAttachTrans = mi_follicleAttachTrans#link self.mi_follicleAttachShape = mi_follicleAttachShape#link self.mi_obj.connectChildNode(mi_follicleAttachTrans,"follicleAttach","targetObject") self.md_return["follicleAttach"] = mi_follicleAttachTrans self.md_return["follicleAttachShape"] = mi_follicleAttachShape except Exception,error:raise StandardError,"!Attach Follicle! | %s"%(error) if not self.b_createControlLoc:#If we don't have a control loc setup, we're just attaching to the surface try:#Groups ======================================================================================= mi_followGroup = self.mi_obj.doDuplicateTransform(True) mi_followGroup.doStore('cgmName',self.mi_obj.mNode) mi_followGroup.addAttr('cgmTypeModifier','follow',lock=True) mi_followGroup.doName() mi_followGroup.parent = mi_follicleAttachTrans if self.b_parentToFollowGroup: #raise StandardError,"shouldn't be here" self.mi_obj.parent = mi_followGroup self.md_return["followGroup"] = mi_followGroup else: #Driver loc ----------------------------------------------------------------------- mi_driverLoc = self.mi_obj.doLoc() mi_driverLoc.doStore('cgmName',self.mi_obj.mNode) mi_driverLoc.addAttr('cgmTypeModifier','driver',lock=True) mi_driverLoc.doName() self.mi_driverLoc = mi_driverLoc mi_driverLoc.parent = mi_followGroup mi_driverLoc.visibility = False self.md_return["driverLoc"] = mi_driverLoc #Constrain ===================================================================== #mc.pointConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset = True) #mc.orientConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset = True) if self.b_pointAttach: mc.pointConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset = True) else: mc.parentConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset = True) except Exception,error:raise StandardError,"!Groups - no control Loc setup! | %s"%(error) else:#Setup control loc stuff try:#>>> Follicle ============================================================================ l_follicleInfo = nodes.createFollicleOnMesh(self.mi_targetSurface.mNode) mi_follicleFollowTrans = cgmMeta.asMeta(l_follicleInfo[1],'cgmObject',setClass=True) mi_follicleFollowShape = cgmMeta.asMeta(l_follicleInfo[0],'cgmNode') #> Name ---------------------------------------------------------------------------------- mi_follicleFollowTrans.doStore('cgmName',self.mi_obj.mNode) mi_follicleFollowTrans.addAttr('cgmTypeModifier','follow',lock=True) mi_follicleFollowTrans.doName() #>Set follicle value --------------------------------------------------------------------- mi_follicleFollowShape.parameterU = d_closestInfo['normalizedU'] mi_follicleFollowShape.parameterV = d_closestInfo['normalizedV'] self.mi_follicleFollowTrans = mi_follicleFollowTrans#link self.mi_follicleFollowShape = mi_follicleFollowShape#link self.md_return["follicleFollow"] = mi_follicleFollowTrans self.md_return["follicleFollowShape"] = mi_follicleFollowShape self.mi_obj.connectChildNode(mi_follicleFollowTrans,"follicleFollow") #Groups ======================================================================================= mi_followGroup = mi_follicleFollowTrans.duplicateTransform() mi_followGroup.doStore('cgmName',self.mi_obj.mNode) mi_followGroup.addAttr('cgmTypeModifier','follow',lock=True) mi_followGroup.doName() self.mi_followGroup = mi_followGroup self.mi_followGroup.parent = mi_follicleFollowTrans self.md_return["followGroup"] = mi_followGroup except Exception,error:raise StandardError,"!Follicle - attach Loc setup! | %s"%(error) mi_offsetGroup = self.mi_obj.duplicateTransform() mi_offsetGroup.doStore('cgmName',self.mi_obj.mNode) mi_offsetGroup.addAttr('cgmTypeModifier','offset',lock=True) mi_offsetGroup.doName() mi_offsetGroup.parent = mi_followGroup self.mi_offsetGroup = mi_offsetGroup self.md_return["offsetGroup"] = mi_offsetGroup if self.b_attachControlLoc:mi_follicleFollowTrans.connectChildNode(mi_offsetGroup,"followOffsetGroup","follicle") mi_zeroGroup = cgmMeta.asMeta( mi_offsetGroup.doGroup(True),'cgmObject',setClass=True) mi_zeroGroup.doStore('cgmName',self.mi_obj.mNode) mi_zeroGroup.addAttr('cgmTypeModifier','zero',lock=True) mi_zeroGroup.doName() mi_zeroGroup.parent = mi_followGroup self.mi_zeroGroup = mi_zeroGroup self.md_return["zeroGroup"] = mi_zeroGroup #Driver loc ----------------------------------------------------------------------- mi_driverLoc = self.mi_obj.doLoc() mi_driverLoc.doStore('cgmName',self.mi_obj.mNode) mi_driverLoc.addAttr('cgmTypeModifier','driver',lock=True) mi_driverLoc.doName() self.mi_driverLoc = mi_driverLoc mi_driverLoc.parent = mi_offsetGroup mi_driverLoc.visibility = False self.md_return["driverLoc"] = mi_driverLoc #Closest setup ===================================================================== mi_controlLoc = self.mi_obj.doLoc() mi_controlLoc.doStore('cgmName',self.mi_obj.mNode) mi_controlLoc.addAttr('cgmTypeModifier','control',lock=True) mi_controlLoc.doName() self.mi_controlLoc = mi_controlLoc self.md_return["controlLoc"] = mi_controlLoc if self.b_attachControlLoc: mi_group = cgmMeta.asMeta( mi_controlLoc.doGroup(),'cgmObject',setClass=True ) mi_group.parent = mi_follicleAttachTrans #Create decompose node -------------------------------------------------------------- mi_worldTranslate = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mi_worldTranslate.doStore('cgmName',self.mi_obj.mNode) mi_worldTranslate.doName() self.mi_worldTranslate = mi_worldTranslate attributes.doConnectAttr("%s.worldMatrix"%(mi_controlLoc.mNode),"%s.%s"%(mi_worldTranslate.mNode,'inputMatrix')) #Create node -------------------------------------------------------------- mi_cpos = NodeF.createNormalizedClosestPointNode(self.mi_obj,self.mi_targetSurface) attributes.doConnectAttr ((mi_cpos.mNode+'.out_uNormal'),(mi_follicleFollowShape.mNode+'.parameterU')) attributes.doConnectAttr ((mi_cpos.mNode+'.out_vNormal'),(mi_follicleFollowShape.mNode+'.parameterV')) #attributes.doConnectAttr ((mi_controlLoc.mNode+'.translate'),(mi_cpos.mNode+'.inPosition')) attributes.doConnectAttr ((mi_worldTranslate.mNode+'.outputTranslate'),(mi_cpos.mNode+'.inPosition')) #Constrain ===================================================================== #mc.pointConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset = True) #mc.orientConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset = True) if self.b_pointAttach: mc.pointConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset = True) else: mc.parentConstraint(self.mi_driverLoc.mNode, self.mi_obj.mNode, maintainOffset = True) if self.b_attachControlLoc: for attr in self.mi_orientation.p_string[0]: attributes.doConnectAttr ((mi_controlLoc.mNode+'.t%s'%attr),(mi_offsetGroup.mNode+'.t%s'%attr)) if self.b_createUpLoc:#Make our up loc ============================================================= mi_upLoc = mi_zeroGroup.doLoc() mi_upLoc.doStore('cgmName',self.mi_obj.mNode) mi_upLoc.addAttr('cgmTypeModifier','up',lock=True) mi_upLoc.doName() mi_upLoc.parent = mi_zeroGroup self.md_return["upLoc"] = mi_upLoc mi_follicleFollowTrans.connectChildNode(mi_upLoc,"followUpLoc","follicle") #Move it ---------------------------------------------------------------------------------------- mi_upLoc.__setattr__("t%s"%self.mi_orientation.p_string[0],self.f_offset) if self.md_return.get("follicleFollow"): mi_follicleFollowTrans.connectChild(mi_driverLoc,"driverLoc","follicle") return self.md_return
def bakeBlendShapeNode(sourceObject, blendShapeNode, baseNameToUse = False, stripPrefix = False, ignoreInbetweens = False, ignoreTargets = False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Function for exporting an object's blendshapes 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 stripPrefix(bool) - whether to strip the first '_' segment ignoreInbetweens(bool) ignoreTargets(list) - targets to ignore in the processing RETURNS: Success(bool) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Prep #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ declare variables """ returnList = [] blendShapeNamesBaked = [] blendShapeConnections = [] currentConnections = [] """ base name """ if baseNameToUse == False: baseName = '' else: baseName = baseNameToUse + '_' #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Meat of it #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> targetDict = returnBlendShapeTargetsAndWeights(sourceObject,blendShapeNode) targetSets = [] blendShapeNodeChannels = [] for key in targetDict.keys(): targetSetBuffer = targetDict.get(key) targetSets.append(targetSetBuffer) baseSet = targetSetBuffer[-1] blendShapeNodeChannels.append(baseSet[0]) blendShapeShortNames = [] """ first loop gets connections, breaks them and sets everything to 0 """ for shape in blendShapeNodeChannels: blendShapeBuffer = (blendShapeNode+'.'+shape) """ get the connection """ blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer)) print blendShapeConnections """break it """ attributes.doBreakConnection(blendShapeBuffer) attributes.doSetAttr(blendShapeBuffer,0) # Bake it bakedGeo = bakeBlendShapes(sourceObject, sourceObject, blendShapeNode, baseNameToUse, stripPrefix, ignoreInbetweens, ignoreTargets) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Finish out #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ 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) """ group for geo """ meshGroup = mc.group( em=True) if baseNameToUse != False: 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