def createPoseBuffer(name, poseList): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns the colors used on the shapes of a curve as a list in order of volume used ARGUMENTS: curve(string RETURNS: Success(bool) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ returnList = [] poseBuffer = mc.group(em=True) attributes.storeInfo(poseBuffer, "cgmName", name) attributes.storeInfo(poseBuffer, "cgmType", "poseBuffer") poseBuffer = NameFactoryOld.doNameObject(poseBuffer) returnList.append(poseBuffer) returnList.append(attributes.addFloatAttrsToObj(poseBuffer, poseList, dv=0, keyable=True)) attributes.doSetLockHideKeyableAttr(poseBuffer, True, False, False) return returnList
def uiNameLoadedAutoNameObject(self): autoNameObject = mc.textField(self.AutoNameObjectField, q=True, text=True) if autoNameObject: newName = NameFactoryOld.doNameObject(autoNameObject, True) mc.textField(self.AutoNameObjectField, e=True, text=newName) else: guiFactory.warning('No current autoname object loaded!')
def locMeCenter(objList,forceBBCenter = False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Pass an object into it and get a named locator with stored info for updating it ARGUMENTS: obj(string) RETURNS: name(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ # make it nameBuffer = mc.spaceLocator() #store info attributes.storeInfo(nameBuffer[0],'cgmSource',(','.join(objList)),False) attributes.storeInfo(nameBuffer[0],'cgmLocMode','selectCenter',False) attributes.storeInfo(nameBuffer[0],'cgmName',(str('_to_'.join(objList))),False) attributes.storeInfo(nameBuffer[0],'cgmTypeModifier','midPoint',False) posList = [] for obj in objList: if mc.objExists(obj) == True: objInfo = returnInfoForLoc(obj,forceBBCenter) posList.append(objInfo['position']) objTrans = distance.returnAveragePointPosition(posList) mc.move (objTrans[0],objTrans[1],objTrans[2], nameBuffer[0]) return ( NameFactory.doNameObject(nameBuffer[0]) )
def uiNameLoadedAutoNameObject(self): autoNameObject = mc.textField(self.AutoNameObjectField,q=True,text = True) if autoNameObject: newName = NameFactoryOld.doNameObject(autoNameObject,True) mc.textField(self.AutoNameObjectField,e = True,text = newName) else: guiFactory.warning('No current autoname object loaded!')
def createPoseBuffer(name, poseList): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns the colors used on the shapes of a curve as a list in order of volume used ARGUMENTS: curve(string RETURNS: Success(bool) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ returnList = [] poseBuffer = mc.group(em=True) attributes.storeInfo(poseBuffer, 'cgmName', name) attributes.storeInfo(poseBuffer, 'cgmType', 'poseBuffer') poseBuffer = NameFactory.doNameObject(poseBuffer) returnList.append(poseBuffer) returnList.append( attributes.addFloatAttrsToObj(poseBuffer, poseList, dv=0, keyable=True)) attributes.doSetLockHideKeyableAttr(poseBuffer, True, False, False) return returnList
def uiNameObject(self, sceneUnique): selected = mc.ls(sl=True, flatten=True, long=True) newNames = [] if not selected: guiFactory.warning('Must have something selected') return elif len(selected) > 1: tmpGroup = mc.group(em=True) cnt = 1 for o in selected: attributes.storeInfo(tmpGroup, ('name' + str(cnt)), o) cnt += 1 toNameAttrs = attributes.returnUserAttributes(tmpGroup) mayaMainProgressBar = guiFactory.doStartMayaProgressBar( len(toNameAttrs), 'Naming...') for attr in toNameAttrs: if mc.progressBar(mayaMainProgressBar, query=True, isCancelled=True): break objectToName = (attributes.returnMessageObject(tmpGroup, attr)) mc.progressBar(mayaMainProgressBar, edit=True, status=("Naming '%s'" % objectToName), step=1) try: buffer = NameFactoryOld.doNameObject(objectToName, sceneUnique) except: guiFactory.warning("'%s' failed" % objectToName) if buffer: newNames.append(buffer) guiFactory.doEndMayaProgressBar(mayaMainProgressBar) mc.delete(tmpGroup) else: NameFactoryOld.doNameObject(selected[0], sceneUnique) if newNames: print("The following were named: %s" % ','.join(newNames))
def point(*a, **kw): buffer = mc.pointConstraint(*a, **kw) if buffer: returnList = [] for c in buffer: returnList.append(NameFactory.doNameObject(c)) return returnList else: return False
def orient(*a, **kw): buffer = mc.orientConstraint(*a, **kw) if buffer: returnList = [] for c in buffer: returnList.append(NameFactory.doNameObject(c)) return returnList else: return False
def uiNameObject(self,sceneUnique): selected = mc.ls(sl=True,flatten=True,long=True) newNames = [] if not selected: guiFactory.warning('Must have something selected') return elif len(selected) > 1: tmpGroup = mc.group(em=True) cnt = 1 for o in selected: attributes.storeInfo(tmpGroup,('name'+str(cnt)),o) cnt += 1 toNameAttrs = attributes.returnUserAttributes(tmpGroup) mayaMainProgressBar = guiFactory.doStartMayaProgressBar(len(toNameAttrs),'Naming...') for attr in toNameAttrs: if mc.progressBar(mayaMainProgressBar, query=True, isCancelled=True ) : break objectToName = (attributes.returnMessageObject(tmpGroup,attr)) mc.progressBar(mayaMainProgressBar, edit=True, status = ("Naming '%s'"%objectToName), step=1) try: buffer = NameFactoryOld.doNameObject( objectToName,sceneUnique ) except: guiFactory.warning("'%s' failed"%objectToName) if buffer: newNames.append(buffer) guiFactory.doEndMayaProgressBar(mayaMainProgressBar) mc.delete(tmpGroup) else: NameFactoryOld.doNameObject(selected[0],sceneUnique) if newNames: print ("The following were named: %s" %','.join(newNames))
def groupMeObject(obj,parent=True,maintainParent=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Pass an object into it and return group placed at the pivots - matching translation, rotation and rotation order and grouping it under the grp ARGUMENTS: obj(string) parent(bool) - Whether to parent the object to the group RETURNS: groupName(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if maintainParent == True: oldParent = mc.listRelatives(obj,parent=True,fullPath = True) if oldParent:oldParent = oldParent[0] returnBuffer = [] rotationOrderDictionary = {'xyz':0,'yzx':1 ,'zxy':2 ,'xzy':3 ,'yxz':4,'zyx':5,'none':6} """return stuff to transfer""" objTrans = mc.xform (obj, q=True, ws=True, rp=True) objRot = mc.xform (obj, q=True, ws=True, ro=True) objRoo = mc.xform (obj, q=True, roo=True ) """return rotation order""" correctRo = rotationOrderDictionary[objRoo] groupBuffer = mc.group (w=True, empty=True) mc.setAttr ((groupBuffer+'.rotateOrder'), correctRo) mc.move (objTrans[0],objTrans[1],objTrans[2], [groupBuffer]) mc.rotate (objRot[0], objRot[1], objRot[2], [groupBuffer], ws=True) mc.xform (groupBuffer, cp=True) if maintainParent == True and oldParent: #for attr in ['tx','ty','tz','rx','ry','rz','sx','sy','sz']: groupBuffer = doParentReturnName(groupBuffer,oldParent) if parent: _wasLocked = [] for attr in ['tx','ty','tz','rx','ry','rz','sx','sy','sz']: attrBuffer = '%s.%s'%(obj,attr) if mc.getAttr(attrBuffer,lock=True): _wasLocked.append(attr) mc.setAttr(attrBuffer,lock=False) #attributes.doSetAttr(obj,attr,0) obj = doParentReturnName(obj,groupBuffer) #for attr in ['tx','ty','tz','rx','ry','rz']: #if attributes.doGetAttr(obj,attr): #attributes.doSetAttr(obj,attr,0) if _wasLocked: for attr in _wasLocked: attrBuffer = '%s.%s'%(obj,attr) mc.setAttr(attrBuffer,lock=True) return NameFactoryOld.doNameObject(groupBuffer,True)
def doName(self,sceneUnique=False): """ Function for naming a maya instanced object using the cgm.NameFactory class. Keyword arguments: sceneUnique(bool) -- Whether to run a full scene dictionary check or the faster just objExists check (default False) """ assert not self.refState, "Cannot change the name of a referenced set" assert not self.mayaSetState, "Cannot change name of a maya default set" buffer = NameFactory.doNameObject(self.nameLong,sceneUnique) self.storeNameStrings(buffer) return buffer
def doName(self, sceneUnique=False): """ Function for naming a maya instanced object using the cgm.NameFactory class. Keyword arguments: sceneUnique(bool) -- Whether to run a full scene dictionary check or the faster just objExists check (default False) """ assert not self.refState, "Cannot change the name of a referenced set" assert not self.mayaSetState, "Cannot change name of a maya default set" buffer = NameFactory.doNameObject(self.nameLong, sceneUnique) self.storeNameStrings(buffer) return buffer
def create(self, setType): """ Creates a set object honoring our quick select set options """ set = mc.sets(em=True) attributes.storeInfo(set, 'cgmName', self.baseName) if setType: self.setType = setType if setType in setTypes.keys(): doType = setTypes.get(setType) else: doType = setType attributes.storeInfo(set, 'cgmType', setType) set = NameFactory.doNameObject(set, True) self.storeNameStrings(set) if self.qssState: self.isQss(self.qssState)
def create(self,setType): """ Creates a set object honoring our quick select set options """ set = mc.sets(em=True) attributes.storeInfo(set,'cgmName',self.baseName) if setType: self.setType = setType if setType in setTypes.keys(): doType = setTypes.get(setType) else: doType = setType attributes.storeInfo(set,'cgmType',setType) set = NameFactory.doNameObject(set,True) self.storeNameStrings(set) if self.qssState: self.isQss(self.qssState)
def basicEyeJointSurfaceSetup(jointList, jointRoot, surface): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ baseDistance = distance.returnAverageDistanceBetweenObjectsAndRoot (jointList,jointRoot) controls = [] groups = [] for joint in jointList: """ make the control """ jointControl = curves.createControlCurve('circle',1) scaleFactor = baseDistance*.25 mc.setAttr((jointControl+'.sx'),scaleFactor) mc.setAttr((jointControl+'.sy'),scaleFactor) mc.setAttr((jointControl+'.sz'),scaleFactor) position.movePointSnap(jointControl,joint) position.aimSnap(jointControl,jointRoot,[0,0,-1]) mc.xform(jointControl,t=[0,0,baseDistance*.4],os=True, r=True) mc.makeIdentity(jointControl, apply = True, s=True) """ naming it """ attributes.storeInfo(jointControl,'cgmName',joint,True) attributes.storeInfo(jointControl,'cgmType','controlAnim') jointControl = NameFactoryOld.doNameObject(jointControl) controls.append(jointControl) groups.append( rigging.zeroTransformMeObject(jointControl) ) for control in controls: indexCount = controls.index(control) attachAimedObjectToSurface (jointList[indexCount], surface, control, 'constrain')
def createInfoNull(infoType): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Creates an infoNull ARGUMENTS: infoType(string) RETURNS: infoNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ createBuffer = mc.group(empty=True) attributes.storeInfo(createBuffer, 'cgmName', infoType) attributes.storeInfo(createBuffer, 'cgmType', 'infoNull') mc.xform(createBuffer, os=True, piv=(0, 0, 0)) infoNull = NameFactory.doNameObject(createBuffer, True) return infoNull
def basicEyeJointSurfaceSetup(jointList, jointRoot, surface): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ baseDistance = distance.returnAverageDistanceBetweenObjectsAndRoot( jointList, jointRoot) controls = [] groups = [] for joint in jointList: """ make the control """ jointControl = curves.createControlCurve('circle', 1) scaleFactor = baseDistance * .25 mc.setAttr((jointControl + '.sx'), scaleFactor) mc.setAttr((jointControl + '.sy'), scaleFactor) mc.setAttr((jointControl + '.sz'), scaleFactor) position.movePointSnap(jointControl, joint) position.aimSnap(jointControl, jointRoot, [0, 0, -1]) mc.xform(jointControl, t=[0, 0, baseDistance * .4], os=True, r=True) mc.makeIdentity(jointControl, apply=True, s=True) """ naming it """ attributes.storeInfo(jointControl, 'cgmName', joint, True) attributes.storeInfo(jointControl, 'cgmType', 'controlAnim') jointControl = NameFactory.doNameObject(jointControl) controls.append(jointControl) groups.append(rigging.zeroTransformMeObject(jointControl)) for control in controls: indexCount = controls.index(control) attachAimedObjectToSurface(jointList[indexCount], surface, control, 'constrain')
def createInfoNull(infoType): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Creates an infoNull ARGUMENTS: infoType(string) RETURNS: infoNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ createBuffer = mc.group (empty=True) attributes.storeInfo(createBuffer,'cgmName',infoType) attributes.storeInfo(createBuffer,'cgmType','infoNull') mc.xform (createBuffer, os=True, piv= (0,0,0)) infoNull = NameFactory.doNameObject(createBuffer,True) return infoNull
def doName(self,sceneUnique=False,nameChildren=False): """ Function for naming a maya instanced object using the cgm.NameFactory class. Keyword arguments: sceneUnique(bool) -- Whether to run a full scene dictionary check or the faster just objExists check (default False) """ if self.refState: return guiFactory.warning("'%s' is referenced. Cannot change name"%self.nameShort) if nameChildren: buffer = NameFactory.doRenameHeir(self.nameLong,sceneUnique) if buffer: self.update(buffer[0]) else: buffer = NameFactory.doNameObject(self.nameLong,sceneUnique) if buffer: self.update(buffer)
def createLocFromObject(obj): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Pass an object into it and get a named locator with stored info for updating it ARGUMENTS: obj(string) RETURNS: name(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ # make it nameBuffer = mc.spaceLocator() buffer = mc.ls(obj,shortNames=True) #store info attributes.storeInfo(nameBuffer[0],'cgmName',buffer[0],False) attributes.storeInfo(nameBuffer[0],'cgmLocMode','fromObject',False) return ( NameFactory.doNameObject(nameBuffer[0]) )
def createLocFromObject(obj): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Pass an object into it and get a named locator with stored info for updating it ARGUMENTS: obj(string) RETURNS: name(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ # make it nameBuffer = mc.spaceLocator() #store info attributes.storeInfo(nameBuffer[0], 'cgmName', obj, False) attributes.storeInfo(nameBuffer[0], 'cgmLocMode', 'fromObject', False) return (NameFactory.doNameObject(nameBuffer[0]))
def groupMeObject(obj,parent=True,maintainParent=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Pass an object into it and return group placed at the pivots - matching translation, rotation and rotation order and grouping it under the grp ARGUMENTS: obj(string) parent(bool) - Whether to parent the object to the group RETURNS: groupName(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if maintainParent == True: oldParent = mc.listRelatives(obj,parent=True) if oldParent:oldParent = oldParent[0] returnBuffer = [] rotationOrderDictionary = {'xyz':0,'yzx':1 ,'zxy':2 ,'xzy':3 ,'yxz':4,'zyx':5,'none':6} """return stuff to transfer""" objTrans = mc.xform (obj, q=True, ws=True, sp=True) objRot = mc.xform (obj, q=True, ws=True, ro=True) objRoo = mc.xform (obj, q=True, roo=True ) """return rotation order""" correctRo = rotationOrderDictionary[objRoo] groupBuffer = mc.group (w=True, empty=True) mc.setAttr ((groupBuffer+'.rotateOrder'), correctRo) mc.move (objTrans[0],objTrans[1],objTrans[2], [groupBuffer]) mc.rotate (objRot[0], objRot[1], objRot[2], [groupBuffer], ws=True) mc.xform (groupBuffer, cp=True) if maintainParent == True and oldParent: groupBuffer = doParentReturnName(groupBuffer,oldParent) if parent == True: obj = doParentReturnName(obj,groupBuffer) return NameFactory.doNameObject(groupBuffer,True)
def locMeCenter(objList, forceBBCenter=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Pass an object into it and get a named locator with stored info for updating it ARGUMENTS: obj(string) RETURNS: name(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ # make it nameBuffer = mc.spaceLocator() #store info attributes.storeInfo(nameBuffer[0], 'cgmSource', (','.join(objList)), False) attributes.storeInfo(nameBuffer[0], 'cgmLocMode', 'selectCenter', False) attributes.storeInfo(nameBuffer[0], 'cgmName', (str('_to_'.join(objList))), False) attributes.storeInfo(nameBuffer[0], 'cgmTypeModifier', 'midPoint', False) posList = [] for obj in objList: if mc.objExists(obj) == True: objInfo = returnInfoForLoc(obj, forceBBCenter) posList.append(objInfo['position']) objTrans = distance.returnAveragePointPosition(posList) mc.move(objTrans[0], objTrans[1], objTrans[2], nameBuffer[0]) return (NameFactory.doNameObject(nameBuffer[0]))
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 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
import maya.cmds as mc import Red9.core.Red9_Meta as r9Meta reload(r9Meta) from cgm.lib.classes import NameFactory as nameF reload(nameF) nameF.doNameObject() from cgm.core.rigger import MorpheusFactory as morphyF from cgm.core.rigger import ModuleFactory as mFactory from cgm.core.rigger import TemplateFactory as tFactory from cgm.core.rigger import JointFactory as jFactory from cgm.core import cgm_PuppetMeta as cgmPM reload(morphyF) reload(mFactory) reload(tFactory) reload(jFactory) import logging logging.basicConfig() log = logging.getLogger(__name__) log.setLevel(logging.INFO) obj = mc.ls(sl=True)[0] or False obj = '' objList = [] import cgm.core cgm.core._reload() #>>> Morpheus
def zeroTransformMeObject(obj, scaleZero=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Makes sure an object is zeroed out, parents the zero group back to the original objects parent ARGUMENTS: obj(string) RETURNS: groupName(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ parent = mc.listRelatives(obj, parent=True, fullPath=True) group = groupMeObject(obj, True, True) group2 = '' attributes.storeInfo(group, 'cgmTypeModifier', 'zero') objScale = [] objScale.append(mc.getAttr(obj + '.sx')) objScale.append(mc.getAttr(obj + '.sy')) objScale.append(mc.getAttr(obj + '.sz')) #Check if we got zero translates zeroCheck = mc.xform(obj, q=True, os=True, rp=True) if zeroCheck: if scaleZero: mc.makeIdentity(obj, apply=True, t=0, r=0, s=1) group2 = groupMeObject(obj, True, True) zeroCheck = mc.xform(obj, q=True, os=True, rp=True) zeroCheck = cgmMath.multiplyLists([objScale, zeroCheck]) mc.xform(group2, t=(-zeroCheck[0], -zeroCheck[1], -zeroCheck[2]), os=True) attributes.storeInfo(group, 'cgmTypeModifier', 'zeroParent') attributes.storeInfo(group2, 'cgmTypeModifier', 'zero') group2 = NameFactoryOld.doNameObject(group2) for attr in 'tx', 'ty', 'tz': attributes.doSetAttr(obj, attr, 0) #Check for zero rotates rotateCheck = mc.xform(obj, q=True, os=True, ro=True) if rotateCheck: if not group2: group2 = groupMeObject(obj, True, True) attributes.storeInfo(group, 'cgmTypeModifier', 'zeroParent') attributes.storeInfo(group2, 'cgmTypeModifier', 'zero') NameFactoryOld.doNameObject(group2) mc.xform(group2, ro=(rotateCheck[0], rotateCheck[1], rotateCheck[2]), os=True) for attr in 'rx', 'ry', 'rz': attributes.doSetAttr(obj, attr, 0) """ objScale = [] objScale.append(mc.getAttr(obj+'.sx')) objScale.append(mc.getAttr(obj+'.sy')) objScale.append(mc.getAttr(obj+'.sz')) grpScale = [] grpScale.append(mc.getAttr(group+'.sx')) grpScale.append(mc.getAttr(group+'.sy')) grpScale.append(mc.getAttr(group+'.sz')) multScale = cgmMath.multiplyLists([objScale,grpScale]) mc.scale(multScale[0], multScale[1], multScale[2],[group]) for attr in 'sx','sy','sz': attributes.doSetAttr(obj,attr,1) """ return NameFactoryOld.doNameObject(group)
def createMasterNull(characterName='nothingNothing'): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Creates a masterNull for a character/asset ARGUMENTS: characterName(string) RETURNS: masterNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if characterName == 'nothingNothing': randomOptions = ['David','Josh','NameMe','Homer','Georgie'] characterName = random.choice(randomOptions) #Create main null masterNullBuffer = mc.group (empty=True) attributes.storeInfo(masterNullBuffer,'cgmName',characterName) attributes.storeInfo(masterNullBuffer,'cgmType','ignore') attributes.storeInfo(masterNullBuffer,'cgmModuleType','master') masterNull = NameFactory.doNameObject(masterNullBuffer) #Create modules container null modulesGroupBuffer = mc.group (empty=True) attributes.storeInfo(modulesGroupBuffer,'cgmName','modules') attributes.storeInfo(modulesGroupBuffer,'cgmType','group') modulesGroup = NameFactory.doNameObject(modulesGroupBuffer) modulesGroup = rigging.doParentReturnName(modulesGroup,masterNull) attributes.storeObjectToMessage (modulesGroup, masterNull, 'modulesGroup') #Create modules container null meshGroupBuffer = mc.group (empty=True) attributes.storeInfo(meshGroupBuffer,'cgmName','geo') attributes.storeInfo(modulesGroupBuffer,'cgmType','group') meshGroup = NameFactory.doNameObject(modulesGroupBuffer) meshGroup = rigging.doParentReturnName(meshGroup,masterNull) attributes.storeObjectToMessage (meshGroup, masterNull, 'geoGroup') #Create master info null masterInfoNull = createInfoNull('master') attributes.storeObjectToMessage (masterInfoNull, masterNull, 'info') masterInfoNull = rigging.doParentReturnName(masterInfoNull,masterNull) #Create modules info null modulesInfoNull = createInfoNull('modules') attributes.storeObjectToMessage (modulesInfoNull, masterInfoNull, 'modules') modulesInfoNull = rigging.doParentReturnName(modulesInfoNull,masterInfoNull) #Create mesh info null meshInfoNull = createInfoNull('geo') attributes.storeObjectToMessage (meshInfoNull, masterInfoNull, 'geo') modulesInfoNull = rigging.doParentReturnName(meshInfoNull,masterInfoNull) #Create global settings info null settingsInfoNull = createInfoNull('settings') attributes.storeObjectToMessage (settingsInfoNull, masterInfoNull, 'settings') settingsInfoNull = rigging.doParentReturnName(settingsInfoNull,masterInfoNull) defaultFont = returnSettingsData('defaultTextFont') attributes.storeInfo(settingsInfoNull,'font',defaultFont) return masterNull
def locClosest(objectList, targetObject): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Creates a locator on the surface of the last object in a selection set closest to each remaining object in the selection ARGUMENTS: objectList RETURNS: locatorList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ bufferList = [] lastObjectType = search.returnObjectType(targetObject) #Get our source objects locators as sometimes the pivot has no correlation to the objects pivot - like a cv fromObjects = [] for item in objectList: fromObjects.append(locMeObject(item)) if lastObjectType == 'mesh': if mayaVersion >= 2011: for item in fromObjects: bufferList.append(locMeClosestPointOnMesh(item, targetObject)) else: guiFactory.warning( 'Apologies, but in maya 2010 and below this only supports nurbsSurface target objects' ) return False elif lastObjectType == 'nurbsSurface': for item in fromObjects: bufferList.append(locMeClosestUVOnSurface(item, targetObject)) elif lastObjectType == 'nurbsCurve': if mayaVersion >= 2011: for item in fromObjects: bufferList.append(locMeClosestPointOnCurve(item, targetObject)) else: guiFactory.warning( 'Apologies, but in maya 2010 and below this only supports nurbsSurface target objects' ) return False else: guiFactory.warning( 'Your target object must be a mesh, nurbsSurface, or nurbsCurve') return False for loc in fromObjects: mc.delete(loc) for loc in bufferList: cnt = bufferList.index(loc) storeList = [] storeList = objectList storeList.append(targetObject) attributes.storeInfo(loc, 'cgmName', ('%s_to_%s' % (objectList[0], objectList[-1])), False) attributes.storeInfo(loc, 'cgmSource', (','.join(storeList)), False) attributes.storeInfo(loc, 'cgmLocMode', 'closestPoint', False) attributes.storeInfo(loc, 'cgmTypeModifier', 'closestPoint', False) bufferList[cnt] = NameFactory.doNameObject(loc) return bufferList[0]
def createMasterNull(characterName='nothingNothing'): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Creates a masterNull for a character/asset ARGUMENTS: characterName(string) RETURNS: masterNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if characterName == 'nothingNothing': randomOptions = ['David', 'Josh', 'NameMe', 'Homer', 'Georgie'] characterName = random.choice(randomOptions) #Create main null masterNullBuffer = mc.group(empty=True) attributes.storeInfo(masterNullBuffer, 'cgmName', characterName) attributes.storeInfo(masterNullBuffer, 'cgmType', 'ignore') attributes.storeInfo(masterNullBuffer, 'cgmModuleType', 'master') masterNull = NameFactory.doNameObject(masterNullBuffer) #Create modules container null modulesGroupBuffer = mc.group(empty=True) attributes.storeInfo(modulesGroupBuffer, 'cgmName', 'modules') attributes.storeInfo(modulesGroupBuffer, 'cgmType', 'group') modulesGroup = NameFactory.doNameObject(modulesGroupBuffer) modulesGroup = rigging.doParentReturnName(modulesGroup, masterNull) attributes.storeObjectToMessage(modulesGroup, masterNull, 'modulesGroup') #Create modules container null meshGroupBuffer = mc.group(empty=True) attributes.storeInfo(meshGroupBuffer, 'cgmName', 'geo') attributes.storeInfo(modulesGroupBuffer, 'cgmType', 'group') meshGroup = NameFactory.doNameObject(modulesGroupBuffer) meshGroup = rigging.doParentReturnName(meshGroup, masterNull) attributes.storeObjectToMessage(meshGroup, masterNull, 'geoGroup') #Create master info null masterInfoNull = createInfoNull('master') attributes.storeObjectToMessage(masterInfoNull, masterNull, 'info') masterInfoNull = rigging.doParentReturnName(masterInfoNull, masterNull) #Create modules info null modulesInfoNull = createInfoNull('modules') attributes.storeObjectToMessage(modulesInfoNull, masterInfoNull, 'modules') modulesInfoNull = rigging.doParentReturnName(modulesInfoNull, masterInfoNull) #Create mesh info null meshInfoNull = createInfoNull('geo') attributes.storeObjectToMessage(meshInfoNull, masterInfoNull, 'geo') modulesInfoNull = rigging.doParentReturnName(meshInfoNull, masterInfoNull) #Create global settings info null settingsInfoNull = createInfoNull('settings') attributes.storeObjectToMessage(settingsInfoNull, masterInfoNull, 'settings') settingsInfoNull = rigging.doParentReturnName(settingsInfoNull, masterInfoNull) defaultFont = returnSettingsData('defaultTextFont') attributes.storeInfo(settingsInfoNull, 'font', defaultFont) return masterNull
def rigSpine(moduleNull): #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>Get our info #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> partName = NameFactory.returnUniqueGeneratedName(moduleNull, ignore='cgmType') """ template null """ templateNull = modules.returnTemplateNull(moduleNull) templateNullData = attributes.returnUserAttrsToDict(templateNull) jointOrientation = modules.returnSettingsData('jointOrientation') templateRoot = modules.returnInfoNullObjects(moduleNull, 'templatePosObjects', types='templateRoot') """ AutonameStuff """ divider = NameFactory.returnCGMDivider() """ control helper objects """ controlTemplateObjects = modules.returnInfoNullObjects( moduleNull, 'templateControlObjects', types='all') controlTemplateObjects = distance.returnDistanceSortedList( templateRoot, controlTemplateObjects) print 'controlTemplateObjects...' print controlTemplateObjects """size list of template control objects """ controlTemplateObjectsSizes = [] for obj in controlTemplateObjects: controlTemplateObjectsSizes.append( distance.returnAbsoluteSizeCurve(obj)) print 'sizes...' print controlTemplateObjectsSizes """ Skin Joints """ skinJoints = modules.returnInfoNullObjects(moduleNull, 'skinJoints', types='all') skinJoints = distance.returnDistanceSortedList(templateRoot, skinJoints) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Make Controls #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ control options """ fk = templateNullData.get('fk') ik = templateNullData.get('ik') stretch = templateNullData.get('stretch') bend = templateNullData.get('bend') """controls to make """ controlsToMake = [] controlsToMake.append('cog') if fk == True: controlsToMake.append('segmentControls') controlsToMake.append('hips') if ik == True: controlsToMake.append('vectorHandles') controlsToMake.append('spineIKHandle') controlsDict = modules.limbControlMaker(moduleNull, controlsToMake) print controlsDict #>>> Organize em segmentControls = controlsDict.get('segmentControls') spineIKHandle = controlsDict.get('spineIKHandle') cog = controlsDict.get('cog') hips = controlsDict.get('hips') vectorHandles = controlsDict.get('vectorHandles') for handle in vectorHandles[-1:]: mc.delete(handle) vectorHandles.remove(handle) #>>> Parent em rigging.parentListToHeirarchy(segmentControls) mc.parent(spineIKHandle, segmentControls[-1]) mc.parent(segmentControls[0], cog) mc.parent(hips, cog) for obj in segmentControls: rigging.zeroTransformMeObject(obj) mc.makeIdentity(obj, apply=True, translate=True) for obj in vectorHandles: mc.makeIdentity(obj, apply=True, translate=True) """ hips anchor locator """ locBuffer = locators.locMeObject(hips) attributes.storeInfo(locBuffer, 'cgmName', hips) attributes.storeInfo(locBuffer, 'cgmTypeModifier', 'anchor') hipsAnchor = NameFactory.doNameObject(locBuffer) mc.setAttr((hipsAnchor + '.rotateOrder'), 5) pointConstraintBuffer = mc.pointConstraint(hips, hipsAnchor, maintainOffset=False, weight=1) orientConstraintBuffer = mc.orientConstraint(hips, hipsAnchor, maintainOffset=False, skip=['x', 'y'], weight=1) """ hips anchor group constraint """ groupBuffer = rigging.groupMeObject(hipsAnchor) attributes.storeInfo(groupBuffer, 'cgmName', hipsAnchor) attributes.storeInfo(groupBuffer, 'cgmTypeModifier', 'orient') hipsAnchorOrGroup = NameFactory.doNameObject(groupBuffer) orientConstraintBuffer = mc.orientConstraint(segmentControls[0], hipsAnchorOrGroup, maintainOffset=False, weight=1) """ end anchor locator """ locBuffer = locators.locMeObject(segmentControls[-1]) attributes.storeInfo(locBuffer, 'cgmName', segmentControls[-1]) attributes.storeInfo(locBuffer, 'cgmTypeModifier', 'anchor') endAnchor = NameFactory.doNameObject(locBuffer) mc.setAttr((endAnchor + '.rotateOrder'), 5) mc.parent(endAnchor, spineIKHandle) #>>> set up follow chains constraintChain = [] constraintChain.append(hipsAnchor) constraintChain = constraintChain + vectorHandles constraintChain.append(endAnchor) constraintChainReturn = constraints.doSegmentAimPointConstraint( constraintChain) print constraintChainReturn vectorHandlesZeroGroups = [] for obj in vectorHandles: vectorHandlesZeroGroups.append(rigging.zeroTransformMeObject(obj)) """ parent the last group to our IK handle """ #mc.parent(vectorHandlesZeroGroups[-1],spineIKHandle) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Joint Chains #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ surface chain """ dupJointsBuffer = mc.duplicate(skinJoints[:-1], po=True, rc=True) surfaceJoints = [] for joint in dupJointsBuffer: attributes.storeInfo(joint, 'cgmType', 'surfaceJoint') surfaceJoints.append(NameFactory.doNameObject(joint)) """ firm start """ startJointsBuffer = mc.duplicate(skinJoints[0], po=True, rc=True) startJoints = [] for joint in startJointsBuffer: attributes.storeInfo(joint, 'cgmType', 'deformationJoint') startJoints.append(NameFactory.doNameObject(joint)) """ firm end """ endJointsBuffer = mc.duplicate(skinJoints[-2:], po=True, rc=True) endJoints = [] for joint in endJointsBuffer: attributes.storeInfo(joint, 'cgmType', 'deformationJoint') endJoints.append(NameFactory.doNameObject(joint)) mc.parent(endJoints[0], world=True) #>>> Influence chain """ get the root joints from our main chain searching by "cgmName" tags...maybe not the best way Maybe should change to search to closest joints """ influenceJointsBuffer = [] for obj in surfaceJoints: if (search.returnTagInfo(obj, 'cgmName')) != False: influenceJointsBuffer.append(obj) """ make our influence joints """ influenceJoints = [] for joint in influenceJointsBuffer: buffer = mc.duplicate(joint, po=True) closestObject = distance.returnClosestObject(buffer[0], surfaceJoints) attributes.storeInfo(buffer[0], 'cgmName', closestObject) attributes.storeInfo(buffer[0], 'cgmType', 'influenceJoint') rigging.doParentToWorld(buffer[0]) influenceJoints.append(NameFactory.doNameObject(buffer[0])) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Put our deformation joints in the rig #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ############### need better way of doing this for iterative mc.parent(endJoints[0], spineIKHandle) mc.parent(startJoints[0], hips) mc.parent(influenceJoints[0], hipsAnchor) mc.parent(influenceJoints[1], vectorHandles[0]) mc.parent(influenceJoints[2], spineIKHandle) #mc.parent(influenceJoints[3],spineIKHandle) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Control Surface #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ create """ orientationBuffer = list(jointOrientation) outChannel = orientationBuffer[2] upChannel = (orientationBuffer[1] + 'up') print upChannel surfaceBuffer = joints.loftSurfaceFromJointList(surfaceJoints, outChannel) controlSurface = surfaceBuffer[0] attributes.copyUserAttrs(moduleNull, controlSurface, attrsToCopy=['cgmName']) attributes.storeInfo(controlSurface, 'cgmType', 'controlSurface', True) controlSurface = NameFactory.doNameObject(controlSurface) """ connect joints to surface""" surfaceConnectReturn = joints.attachJointChainToSurface( surfaceJoints, controlSurface, jointOrientation, upChannel, 'animCrv') print surfaceConnectReturn """ surface influence joints skinning""" surfaceSkinCluster = mc.skinCluster(influenceJoints, controlSurface, tsb=True, n=(controlSurface + '_skinCluster'), maximumInfluences=3, normalizeWeights=1, dropoffRate=1) #surfaceSkinCluster = mc.skinCluster (influenceJoints,controlSurface,tsb=True, n=(controlSurface+'_skinCluster'),maximumInfluences = 3, normalizeWeights = 1, dropoffRate=1,smoothWeights=.5,obeyMaxInfluences=True, weight = 1) controlSurfaceSkinCluster = surfaceSkinCluster[0] """ smooth skin weights """ skinning.simpleControlSurfaceSmoothWeights(controlSurface) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Connect skin joints to surface joints #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> deformationJoints = [] deformationJoints.append(startJoints[0]) deformationJoints = deformationJoints + surfaceJoints[1:-2] deformationJoints = deformationJoints + endJoints for joint in skinJoints: attachJoint = distance.returnClosestObject(joint, deformationJoints) pntConstBuffer = mc.pointConstraint(attachJoint, joint, maintainOffset=False, weight=1) orConstBuffer = mc.orientConstraint(attachJoint, joint, maintainOffset=False, weight=1) #mc.connectAttr((attachJoint+'.t'),(joint+'.t')) #mc.connectAttr((attachJoint+'.r'),(joint+'.r')) mc.connectAttr((attachJoint + '.s'), (joint + '.s')) pntConstBuffer = mc.pointConstraint(attachJoint, joint, maintainOffset=False, weight=1) orConstBuffer = mc.orientConstraint(attachJoint, joint, maintainOffset=False, weight=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 = 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]
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 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
def verifyModule(self,forceNew = False): """ Verifies the integrity of the base module class null. Repairing and restoring broken connections or deleted items. """ for k in defaultSettings.keys(): try: self.__dict__[k] except: self.__dict__[k] = defaultSettings[k] #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Nulls creation #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #need a check to see if it exists from specfic name call if not self.ModuleNull or forceNew: #See if one exists from the name dict buffer = NameFactory.returnCombinedNameFromDict(self.generateNameDict()) if mc.objExists(buffer): if forceNew: cnt = NameFactory.returnIterateNumber(buffer) self.ModuleNull = ObjectFactory(mc.group(empty=True)) self.ModuleNull.store('cgmIterator',cnt) else: self.ModuleNull = ObjectFactory(buffer) #if we still don't have one, make it if not self.ModuleNull: self.ModuleNull = ObjectFactory(mc.group(empty=True)) #Initialize the module parent attr self.msgModuleParent = AttrFactory(self.ModuleNull,'moduleParent','message',self.moduleParent) #Naming stuff self.ModuleNull.store('cgmName',self.nameBase,True) self.ModuleNull.store('cgmType','module') self.afModuleType = AttrFactory(self.ModuleNull,'moduleType',initialValue='None') #Store any naming tags from the init call for k in self.callTags.keys(): if self.callTags.get(k): self.ModuleNull.store(k,self.callTags.get(k),True) elif k in self.parentTagDict.keys(): self.ModuleNull.store(k,'%s.%s'%(self.msgModuleParent.value,k)) self.ModuleNull.doName(True) mc.xform (self.ModuleNull.nameShort, os=True, piv= (0,0,0)) for flag in moduleStates: self.__dict__["af%sState"%flag.capitalize()] = AttrFactory(self.ModuleNull,'%sState'%flag,'bool',initialValue=0,lock=True) attributes.doSetLockHideKeyableAttr(self.ModuleNull.nameShort,channels=['tx','ty','tz','rx','ry','rz','sx','sy','sz']) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Main Nulls #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> self.msgRigNull = AttrFactory(self.ModuleNull,'rigNull','message') self.msgTemplateNull = AttrFactory(self.ModuleNull,'templateNull','message') self.msgInfoNull = AttrFactory(self.ModuleNull,'info','message') nullAttributes = [self.msgRigNull, self.msgTemplateNull, self.msgInfoNull] nullInstances = ['RigNull', 'TemplateNull', 'InfoNull'] for i,null in enumerate(nullAttributes): created = False if not null.get(): #If there's nothing connected to our message, we're gonna make our null guiFactory.report("'%s' not found. Creating"%null.attr) self.__dict__[ nullInstances[i] ] = ObjectFactory(mc.group(empty=True)) created = True else: self.__dict__[ nullInstances[i] ] = ObjectFactory(null.value) if null.attr == 'info': #Special case stuff for the master info null self.__dict__[ nullInstances[i] ].store('cgmName','master',True) self.__dict__[ nullInstances[i] ].store('cgmType','infoNull') else: self.__dict__[ nullInstances[i] ].store('cgmType',null.attr) mc.xform (self.__dict__[ nullInstances[i] ].nameShort, os=True, piv= (0,0,0)) self.__dict__[ nullInstances[i] ].doParent(self.ModuleNull.nameShort) if created and self.__dict__[ nullInstances[i] ].nameLong != null.value: null.doStore(self.__dict__[ nullInstances[i] ].nameLong) attributes.doSetLockHideKeyableAttr(self.__dict__[ nullInstances[i] ].nameShort) self.__dict__[ nullInstances[i] ].doName(True) null.updateData() #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Info Nulls #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> for k in InfoNullsNames: self.infoNulls[k] = AttrFactory(self.InfoNull,k,'message') if not self.infoNulls[k].value: guiFactory.report("'%s' not found. Creating"%k) createBuffer = modules.createInfoNull(k) self.infoNulls[k].doStore(createBuffer) if self.infoNulls[k].value: attributes.doSetLockHideKeyableAttr(self.infoNulls[k].value) if rigging.doParentReturnName( self.infoNulls[k].value,self.msgInfoNull.value): buffer = NameFactory.doNameObject(self.infoNulls[k].value) if buffer != self.infoNulls[k].value: self.infoNulls[k].doStore(buffer) else: self.infoNulls[k].updateData() else: guiFactory.warning("'%s' has failed to initialize"%k) if self.infoNulls['setupOptions']: self.SetupOptionsNull = ObjectFactory( self.infoNulls['setupOptions'].get() ) self.optionHandles = AttrFactory(self.SetupOptionsNull,'handles','int',initialValue=self.handles) if self.infoNulls['settings']: self.optionAimAxis = AttrFactory(self.infoNulls['settings'].get(),'axisAim','enum',enum = 'x+:y+:z+:x-:y-:z-',initialValue=2) self.optionUpAxis = AttrFactory(self.infoNulls['settings'].get(),'axisUp','enum',enum = 'x+:y+:z+:x-:y-:z-',initialValue=1) self.optionOutAxis = AttrFactory(self.infoNulls['settings'].get(),'axisOut','enum',enum = 'x+:y+:z+:x-:y-:z-',initialValue=0) return True
def create(self): """ Creates a cgm buffer object """ buffer = mc.group(em=True) attributes.storeInfo(buffer,'cgmName',self.baseName) buffer = NameFactory.doNameObject(buffer,True) self.storeNameStrings(buffer)
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 create(self): """ Creates a cgm buffer object """ buffer = mc.group(em=True) attributes.storeInfo(buffer, 'cgmName', self.baseName) buffer = NameFactory.doNameObject(buffer, True) self.storeNameStrings(buffer)
def createSizeTemplateControl(self): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Generates a sizeTemplateObject. It's been deleted, it recreates it. Guess the size based off of there being a mesh there. If there is no mesh, it sets sets an intial size of a [155,170,29] unit character. ARGUMENTS: self.PuppetNull.nameShort(string) RETURNS: returnList(list) = [startCrv(string),EndCrv(list)] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Get info #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> startColors = modules.returnSettingsData('colorStart') endColors = modules.returnSettingsData('colorEnd') font = mc.getAttr((self.msgSettingsInfo.get() + '.font')) """ checks for there being anything in our geo group """ if not self.geo: return guiFactory.warning( 'Need some geo defined to make this tool worthwhile') boundingBoxSize = modules.returnSettingsDataAsFloat( 'meshlessSizeTemplate') else: boundingBoxSize = distance.returnBoundingBoxSize( self.msgGeoGroup.get()) boundingBox = mc.exactWorldBoundingBox(self.msgGeoGroup.get()) """determine orienation """ maxSize = max(boundingBoxSize) matchIndex = boundingBoxSize.index(maxSize) """Find the pivot of the bounding box """ pivotPosition = distance.returnCenterPivotPosition( self.msgGeoGroup.get()) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Get our positions #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if self.optionPuppetMode.get() == 0: #If bio... if matchIndex == 1 or matchIndex == 0: #Vertical posBuffers = [[0, .5, 0], [0, .75, 0]] width = (boundingBoxSize[0] / 2) height = (boundingBoxSize[1]) depth = boundingBoxSize[2] for cnt, pos in enumerate(posBuffers): posBuffer = posBuffers[cnt] posBuffer[0] = 0 posBuffer[1] = (posBuffer[1] * height) posBuffer[2] = 0 elif matchIndex == 2: #Horizontal posBuffers = [[0, 0, -.33], [0, 0, .66]] width = boundingBoxSize[1] height = boundingBoxSize[2] / 2 depth = (boundingBoxSize[0]) for cnt, pos in enumerate(posBuffers): posBuffer = posBuffers[cnt] posBuffer[0] = 0 posBuffer[1] = boundingBoxSize[1] * .75 posBuffer[2] = (posBuffer[2] * height) else: #Otherwise if matchIndex == 1 or matchIndex == 0: #Vertical width = (boundingBoxSize[0] / 2) height = (boundingBoxSize[1]) depth = boundingBoxSize[2] posBuffers = [[0, boundingBox[1], 0], [0, boundingBox[4], 0]] elif matchIndex == 2: #Horizontal width = boundingBoxSize[0] height = boundingBoxSize[2] / 2 depth = (boundingBoxSize[1]) startHeight = max([boundingBox[4], boundingBox[1]]) - depth / 2 print startHeight posBuffers = [[0, startHeight, boundingBox[2]], [0, startHeight, boundingBox[5]]] # Simple reverse of start pos buffers if the object is pointing negative if self.optionAimAxis < 2: posBuffers.reverse() #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Making the controls #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ make our control object """ startCurves = [] startCurve = curves.createControlCurve('circle', depth * .8) mc.xform(startCurve, t=posBuffers[0], ws=True) attributes.doSetAttr(startCurve, 'rotateOrder', 5) curves.setCurveColorByName(startCurve, startColors[1]) startCurves.append(startCurve) startText = curves.createTextCurve('start', size=depth * .75, font=font) mc.xform(startText, t=posBuffers[0], ws=True) curves.setCurveColorByName(startText, startColors[0]) startCurves.append(startText) endCurves = [] endCurve = curves.createControlCurve('circle', depth * .8) mc.xform(endCurve, t=posBuffers[1], ws=True) curves.setCurveColorByName(endCurve, endColors[1]) attributes.doSetAttr(endCurve, 'rotateOrder', 5) endCurves.append(endCurve) endText = curves.createTextCurve('end', size=depth * .6, font=font) mc.xform(endText, t=posBuffers[1], ws=True) curves.setCurveColorByName(endText, endColors[0]) endCurves.append(endText) """ aiming """ position.aimSnap(startCurve, endCurve, [0, 0, 1], [0, 1, 0]) position.aimSnap(startText, endCurve, [0, 0, 1], [0, 1, 0]) position.aimSnap(endCurve, startCurve, [0, 0, -1], [0, 1, 0]) position.aimSnap(endText, startCurve, [0, 0, -1], [0, 1, 0]) sizeCurveControlStart = curves.combineCurves(startCurves) sizeCurveControlEnd = curves.combineCurves(endCurves) """ store our info to name our objects""" attributes.storeInfo(sizeCurveControlStart, 'cgmName', (self.PuppetNull.nameShort + '.cgmName')) attributes.storeInfo(sizeCurveControlStart, 'cgmDirection', 'start') attributes.storeInfo(sizeCurveControlStart, 'cgmType', 'templateSizeObject') sizeCurveControlStart = NameFactory.doNameObject(sizeCurveControlStart) mc.makeIdentity(sizeCurveControlStart, apply=True, t=True, s=True, r=True) attributes.storeInfo(sizeCurveControlEnd, 'cgmName', (self.PuppetNull.nameShort + '.cgmName')) attributes.storeInfo(sizeCurveControlEnd, 'cgmDirection', 'end') attributes.storeInfo(sizeCurveControlEnd, 'cgmType', 'templateSizeObject') sizeCurveControlEnd = NameFactory.doNameObject(sizeCurveControlEnd) endGroup = rigging.groupMeObject(sizeCurveControlEnd) mc.makeIdentity(sizeCurveControlEnd, apply=True, t=True, s=True, r=True) mc.parentConstraint(sizeCurveControlStart, endGroup, maintainOffset=True) """ make control group """ controlGroup = rigging.groupMeObject(sizeCurveControlStart) attributes.storeInfo(controlGroup, 'cgmName', (self.PuppetNull.nameShort + '.cgmName')) attributes.storeInfo(controlGroup, 'cgmType', 'templateSizeObjectGroup') controlGroup = NameFactory.doNameObject(controlGroup) endGroup = rigging.doParentReturnName(endGroup, controlGroup) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Getting data ready #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> attributes.storeInfo(controlGroup, 'controlStart', sizeCurveControlStart) attributes.storeInfo(controlGroup, 'controlEnd', sizeCurveControlEnd) attributes.storeInfo(self.PuppetNull.nameShort, 'templateSizeObject', controlGroup) self.templateSizeObjects['root'] = controlGroup self.templateSizeObjects['start'] = sizeCurveControlStart self.templateSizeObjects['end'] = sizeCurveControlEnd returnList = [] returnList.append(sizeCurveControlStart) returnList.append(sizeCurveControlEnd) return returnList
def locClosest(objectList,targetObject): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Creates a locator on the surface of the last object in a selection set closest to each remaining object in the selection ARGUMENTS: objectList RETURNS: locatorList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ bufferList = [] lastObjectType = search.returnObjectType(targetObject) #Get our source objects locators as sometimes the pivot has no correlation to the objects pivot - like a cv fromObjects = [] for item in objectList: fromObjects.append(locMeObject(item)) if lastObjectType == 'mesh': if mayaVersion >=2011: for item in fromObjects: bufferList.append( locMeClosestPointOnMesh(item, targetObject) ) else: guiFactory.warning('Apologies, but in maya 2010 and below this only supports nurbsSurface target objects') return False elif lastObjectType == 'nurbsSurface': for item in fromObjects: bufferList.append( locMeClosestUVOnSurface(item, targetObject) ) elif lastObjectType == 'nurbsCurve': if mayaVersion >=2011: for item in fromObjects: bufferList.append( locMeClosestPointOnCurve(item, targetObject) ) else: guiFactory.warning('Apologies, but in maya 2010 and below this only supports nurbsSurface target objects') return False else: guiFactory.warning('Your target object must be a mesh, nurbsSurface, or nurbsCurve') return False for loc in fromObjects: mc.delete(loc) for loc in bufferList: cnt = bufferList.index(loc) storeList = [] storeList = objectList storeList.append(targetObject) attributes.storeInfo(loc,'cgmName',('%s_to_%s'%(objectList[0],objectList[-1])),False) attributes.storeInfo(loc,'cgmSource',(','.join(storeList)),False) attributes.storeInfo(loc,'cgmLocMode','closestPoint',False) attributes.storeInfo(loc,'cgmTypeModifier','closestPoint',False) bufferList[cnt] = NameFactory.doNameObject(loc) return bufferList[0]
def groupMeObject(obj, parent=True, maintainParent=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Pass an object into it and return group placed at the pivots - matching translation, rotation and rotation order and grouping it under the grp ARGUMENTS: obj(string) parent(bool) - Whether to parent the object to the group RETURNS: groupName(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if maintainParent == True: oldParent = mc.listRelatives(obj, parent=True, fullPath=True) if oldParent: oldParent = oldParent[0] returnBuffer = [] rotationOrderDictionary = { 'xyz': 0, 'yzx': 1, 'zxy': 2, 'xzy': 3, 'yxz': 4, 'zyx': 5, 'none': 6 } #_matrix = mc.xform (obj, q=True, m =True) #groupBuffer = mc.group (w=True, empty=True) #mc.xform(groupBuffer, m = _matrix) #mc.xform(groupBuffer,ra=[0,0,0],p=True) #mc.xform(groupBuffer, roo = 'xyz', p=True)#...always do pushing values in xyz #objRot = mc.xform(groupBuffer, q=True, os = True, ro=True) #objRa = mc.xform(groupBuffer, q=True, os = True, ra=True) #mc.xform(groupBuffer, os = True, ra=[v + objRot[i] for i,v in enumerate(objRa)]) #mc.xform(groupBuffer,os=True, ro = [0,0,0])#...clear #mc.xform(groupBuffer, roo = mc.xform (obj, q=True, roo=True ), p=True)#...match rotateOrder #return stuff to transfer objTrans = mc.xform(obj, q=True, ws=True, rp=True) objRot = mc.xform(obj, q=True, ws=True, ro=True) objRotAxis = mc.xform(obj, q=True, ws=True, ra=True) #return rotation order groupBuffer = mc.group(w=True, empty=True) #mc.setAttr ((groupBuffer+'.rotateOrder'), correctRo) mc.xform(groupBuffer, roo=mc.xform(obj, q=True, roo=True)) #...match rotateOrder mc.move(objTrans[0], objTrans[1], objTrans[2], [groupBuffer]) #for i,a in enumerate(['X','Y','Z']): #attributes.doSetAttr(groupBuffer, 'rotateAxis{0}'.format(a), objRotAxis[i]) #mc.rotate(objRot[0], objRot[1], objRot[2], [groupBuffer], ws=True) mc.xform(groupBuffer, ws=True, ro=objRot, p=False) mc.xform(groupBuffer, ws=True, ra=objRotAxis, p=False) #mc.xform (groupBuffer, cp=True) if maintainParent == True and oldParent: #for attr in ['tx','ty','tz','rx','ry','rz','sx','sy','sz']: groupBuffer = doParentReturnName(groupBuffer, oldParent) if parent: _wasLocked = [] for attr in ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz']: attrBuffer = '%s.%s' % (obj, attr) if mc.getAttr(attrBuffer, lock=True): _wasLocked.append(attr) mc.setAttr(attrBuffer, lock=False) #attributes.doSetAttr(obj,attr,0) obj = doParentReturnName(obj, groupBuffer) #for attr in ['tx','ty','tz','rx','ry','rz']: #if attributes.doGetAttr(obj,attr): #attributes.doSetAttr(obj,attr,0) if _wasLocked: for attr in _wasLocked: attrBuffer = '%s.%s' % (obj, attr) mc.setAttr(attrBuffer, lock=True) return NameFactoryOld.doNameObject(groupBuffer, True)
def doPointAimConstraintObjectGroup(targets,object,mode=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ACKNOWLEDGEMENT: Idea for this stype of constraint setup is from http://td-matt.blogspot.com/2011/01/spine-control-rig.html DESCRIPTION: Groups an object and constrains that group to the other objects ARGUMENTS: targets(list) - should be in format of from to back with the last one being the aim object object(string) mode(int) - 0 - equal influence 1 - distance spread RETURNS: group(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ returnList = [] """ figure out which is the aim direction """ aimVector = logic.returnLocalAimDirection(object,targets[-1]) upVector = logic.returnLocalUp(aimVector) """ create locators """ locs = [] toMake = ['point','aim','up'] for type in toMake: locBuffer = locators.locMeObject(object) attributes.storeInfo(locBuffer,'cgmName',object) attributes.storeInfo(locBuffer,'cgmTypeModifier',type) locs.append(NameFactory.doNameObject(locBuffer)) pointLoc = locs[0] aimLoc = locs[1] upLoc = locs[2] """ move the locators """ mc.xform(aimLoc,t=aimVector,r=True,os=True) mc.xform(upLoc,t=upVector,r=True,os=True) """group constraint""" objGroup = rigging.groupMeObject(object,True,True) attributes.storeInfo(objGroup,'cgmName',object) attributes.storeInfo(objGroup,'cgmTypeModifier','follow') objGroup = NameFactory.doNameObject(objGroup) pointConstraintBuffer = mc.pointConstraint (pointLoc,objGroup, maintainOffset=False) aimConstraintBuffer = mc.aimConstraint(aimLoc,objGroup,maintainOffset = False, weight = 1, aimVector = aimVector, upVector = upVector, worldUpObject = upLoc, worldUpType = 'object' ) """loc constraints""" locConstraints = [] for loc in locs: parentConstraintBuffer = mc.parentConstraint (targets,loc, maintainOffset=True) locConstraints.append(parentConstraintBuffer[0]) if mode == 1: distances = [] for target in targets: distances.append(distance.returnDistanceBetweenObjects(target,objGroup)) normalizedDistances = cgmMath.normList(distances) for constraint in locConstraints: targetWeights = mc.parentConstraint(constraint,q=True, weightAliasList=True) cnt=1 for value in normalizedDistances: mc.setAttr(('%s%s%s' % (constraint,'.',targetWeights[cnt])),value ) cnt-=1 returnList.append(objGroup) returnList.append(locs) return returnList
def doPointAimConstraintObjectGroup(targets, object, mode=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ACKNOWLEDGEMENT: Idea for this stype of constraint setup is from http://td-matt.blogspot.com/2011/01/spine-control-rig.html DESCRIPTION: Groups an object and constrains that group to the other objects ARGUMENTS: targets(list) - should be in format of from to back with the last one being the aim object object(string) mode(int) - 0 - equal influence 1 - distance spread RETURNS: group(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ returnList = [] """ figure out which is the aim direction """ aimVector = logic.returnLocalAimDirection(object, targets[-1]) upVector = logic.returnLocalUp(aimVector) """ create locators """ locs = [] toMake = ['point', 'aim', 'up'] for type in toMake: locBuffer = locators.locMeObject(object) attributes.storeInfo(locBuffer, 'cgmName', object) attributes.storeInfo(locBuffer, 'cgmTypeModifier', type) locs.append(NameFactory.doNameObject(locBuffer)) pointLoc = locs[0] aimLoc = locs[1] upLoc = locs[2] """ move the locators """ mc.xform(aimLoc, t=aimVector, r=True, os=True) mc.xform(upLoc, t=upVector, r=True, os=True) """group constraint""" objGroup = rigging.groupMeObject(object, True, True) attributes.storeInfo(objGroup, 'cgmName', object) attributes.storeInfo(objGroup, 'cgmTypeModifier', 'follow') objGroup = NameFactory.doNameObject(objGroup) pointConstraintBuffer = mc.pointConstraint(pointLoc, objGroup, maintainOffset=False) aimConstraintBuffer = mc.aimConstraint(aimLoc, objGroup, maintainOffset=False, weight=1, aimVector=aimVector, upVector=upVector, worldUpObject=upLoc, worldUpType='object') """loc constraints""" locConstraints = [] for loc in locs: parentConstraintBuffer = mc.parentConstraint(targets, loc, maintainOffset=True) locConstraints.append(parentConstraintBuffer[0]) if mode == 1: distances = [] for target in targets: distances.append( distance.returnDistanceBetweenObjects(target, objGroup)) normalizedDistances = cgmMath.normList(distances) for constraint in locConstraints: targetWeights = mc.parentConstraint(constraint, q=True, weightAliasList=True) cnt = 1 for value in normalizedDistances: mc.setAttr(('%s%s%s' % (constraint, '.', targetWeights[cnt])), value) cnt -= 1 returnList.append(objGroup) returnList.append(locs) return returnList
def zeroTransformMeObject(obj,scaleZero=False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Makes sure an object is zeroed out, parents the zero group back to the original objects parent ARGUMENTS: obj(string) RETURNS: groupName(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ parent = mc.listRelatives(obj,parent=True,fullPath = True) group = groupMeObject(obj,True,True) group2 = '' attributes.storeInfo(group,'cgmTypeModifier','zero') objScale = [] objScale.append(mc.getAttr(obj+'.sx')) objScale.append(mc.getAttr(obj+'.sy')) objScale.append(mc.getAttr(obj+'.sz')) #Check if we got zero translates zeroCheck = mc.xform (obj, q=True, os=True, rp=True) if zeroCheck: if scaleZero: mc.makeIdentity(obj,apply=True,t=0,r=0,s=1) group2 = groupMeObject(obj,True,True) zeroCheck = mc.xform (obj, q=True, os=True, rp=True) zeroCheck = cgmMath.multiplyLists([objScale,zeroCheck]) mc.xform (group2,t=(-zeroCheck[0],-zeroCheck[1],-zeroCheck[2]), os=True) attributes.storeInfo(group,'cgmTypeModifier','zeroParent') attributes.storeInfo(group2,'cgmTypeModifier','zero') group2 = NameFactoryOld.doNameObject(group2) for attr in 'tx','ty','tz': attributes.doSetAttr(obj, attr, 0) #Check for zero rotates rotateCheck = mc.xform(obj, q=True, os=True, ro=True) if rotateCheck: if not group2: group2 = groupMeObject(obj,True,True) attributes.storeInfo(group,'cgmTypeModifier','zeroParent') attributes.storeInfo(group2,'cgmTypeModifier','zero') NameFactoryOld.doNameObject(group2) mc.xform (group2,ro=(rotateCheck[0],rotateCheck[1],rotateCheck[2]), os=True) for attr in 'rx','ry','rz': attributes.doSetAttr(obj, attr, 0) """ objScale = [] objScale.append(mc.getAttr(obj+'.sx')) objScale.append(mc.getAttr(obj+'.sy')) objScale.append(mc.getAttr(obj+'.sz')) grpScale = [] grpScale.append(mc.getAttr(group+'.sx')) grpScale.append(mc.getAttr(group+'.sy')) grpScale.append(mc.getAttr(group+'.sz')) multScale = cgmMath.multiplyLists([objScale,grpScale]) mc.scale(multScale[0], multScale[1], multScale[2],[group]) for attr in 'sx','sy','sz': attributes.doSetAttr(obj,attr,1) """ return NameFactoryOld.doNameObject(group)
def addOrientationHelpers(self): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Adds orientation helpers to a template chain ARGUMENTS: objects(list) root(string) - root control of the limb chain moduleType(string) RETURNS: returnList(list) = [rootHelper(string),helperObjects(list),helperObjectGroups(list)] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ moduleColors = modules.returnModuleColors(self.ModuleNull.nameLong) helperObjects = [] helperObjectGroups = [] returnBuffer = [] root = self.msgTemplateRoot.getMessage() visAttr = "%s.visOrientHelpers" % self.infoNulls['visibilityOptions'].get() objects = self.templatePosObjectsBuffer.bufferList #>>> Direction and size Stuff """ Directional data derived from joints """ generalDirection = logic.returnHorizontalOrVertical(objects) if generalDirection == 'vertical' and 'leg' not in self.afModuleType.get(): worldUpVector = [0, 0, -1] elif generalDirection == 'vertical' and 'leg' in self.afModuleType.get(): worldUpVector = [0, 0, 1] else: worldUpVector = [0, 1, 0] #Get Size size = (distance.returnBoundingBoxSizeToAverage(objects[0]) * 2) #>>> Master Orient helper createBuffer = curves.createControlCurve('circleArrow1', (size * 2), 'z+') # make the curve curves.setCurveColorByName(createBuffer, moduleColors[0]) attributes.storeInfo(createBuffer, 'cgmType', 'templateOrientRoot') #copy the name attr mainOrientHelperObj = NameFactory.doNameObject(createBuffer) attributes.storeObjectToMessage( mainOrientHelperObj, self.msgTemplateRoot.get(), 'orientHelper') #store the object to it's respective object returnBuffer.append(mainOrientHelperObj) # Snapping position.movePointSnap(mainOrientHelperObj, root) constBuffer = mc.aimConstraint(objects[1], mainOrientHelperObj, maintainOffset=False, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpVector=worldUpVector, worldUpType='vector') mc.delete(constBuffer[0]) # Follow Groups mainOrientHelperGroupBuffer = rigging.groupMeObject(mainOrientHelperObj) mainOrientHelperGroupBuffer = NameFactory.doNameObject( mainOrientHelperGroupBuffer) mainOrientHelperGroup = rigging.doParentReturnName( mainOrientHelperGroupBuffer, root) mc.pointConstraint(objects[0], mainOrientHelperGroupBuffer, maintainOffset=False) helperObjectGroups.append(mainOrientHelperGroup) # set up constraints mc.aimConstraint(objects[-1], mainOrientHelperGroup, maintainOffset=True, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpObject=root, worldUpType='objectRotation') # lock and hide stuff attributes.doSetLockHideKeyableAttr( mainOrientHelperObj, True, False, False, ['tx', 'ty', 'tz', 'rz', 'ry', 'sx', 'sy', 'sz', 'v']) #>>> The sub helpers """ make our pair lists """ pairList = lists.parseListToPairs(objects) """ make our controls """ helperObjects = [] for pair in pairList: """ Get Size """ size = (distance.returnBoundingBoxSizeToAverage(pair[0]) * 2) """ make the curve""" createBuffer = curves.createControlCurve('circleArrow2Axis', size, 'y-') curves.setCurveColorByName(createBuffer, moduleColors[1]) """ copy the name attr""" attributes.copyUserAttrs(pair[0], createBuffer, ['cgmName']) attributes.storeInfo(createBuffer, 'cgmType', 'templateOrientObject') helperObj = NameFactory.doNameObject(createBuffer) """ store the object to it's respective object and to an object list """ attributes.storeObjectToMessage(helperObj, pair[0], 'orientHelper') helperObjects.append(helperObj) """ initial snapping """ position.movePointSnap(helperObj, pair[0]) constBuffer = mc.aimConstraint(pair[1], helperObj, maintainOffset=False, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpVector=worldUpVector, worldUpType='vector') mc.delete(constBuffer[0]) """ follow groups """ helperGroupBuffer = rigging.groupMeObject(helperObj) helperGroup = NameFactory.doNameObject(helperGroupBuffer) helperGroup = rigging.doParentReturnName(helperGroup, pair[0]) helperObjectGroups.append(helperGroup) """ set up constraints """ mc.aimConstraint(pair[1], helperGroup, maintainOffset=False, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpVector=[0, 1, 0], worldUpObject=mainOrientHelperObj, worldUpType='objectrotation') """ lock and hide stuff """ helperObj = attributes.returnMessageObject(pair[0], 'orientHelper') mc.connectAttr((visAttr), (helperObj + '.v')) attributes.doSetLockHideKeyableAttr( helperObj, True, False, False, ['tx', 'ty', 'tz', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) #>>> For the last object in the chain for obj in objects[-1:]: """ Get Size """ size = (distance.returnBoundingBoxSizeToAverage(obj) * 2) """ make the curve""" createBuffer = curves.createControlCurve('circleArrow2Axis', size, 'y-') curves.setCurveColorByName(createBuffer, moduleColors[1]) """ copy the name attr""" attributes.copyUserAttrs(obj, createBuffer, ['cgmName']) attributes.storeInfo(createBuffer, 'cgmType', 'templateOrientObject') helperObj = NameFactory.doNameObject(createBuffer) """ store the object to it's respective object """ attributes.storeObjectToMessage(helperObj, obj, 'orientHelper') """ initial snapping """ position.movePointSnap(helperObj, obj) constBuffer = mc.aimConstraint(objects[-2], helperObj, maintainOffset=False, weight=1, aimVector=[1, 0, 0], upVector=[0, 1, 0], worldUpVector=worldUpVector, worldUpType='vector') mc.delete(constBuffer[0]) """ follow groups """ helperGroupBuffer = rigging.groupMeObject(helperObj) helperGroup = NameFactory.doNameObject(helperGroupBuffer) helperGroup = rigging.doParentReturnName(helperGroup, obj) helperObjectGroups.append(helperGroup) """ set up constraints """ secondToLastHelperObject = attributes.returnMessageObject( objects[-2], 'orientHelper') mc.orientConstraint(secondToLastHelperObject, helperGroup, maintainOffset=False, weight=1) """ lock and hide stuff """ helperObj = attributes.returnMessageObject(obj, 'orientHelper') mc.connectAttr((visAttr), (helperObj + '.v')) attributes.doSetLockHideKeyableAttr( helperObj, True, False, False, ['tx', 'ty', 'tz', 'sx', 'sy', 'sz', 'v']) helperObjects.append(helperObj) returnBuffer.append(helperObjects) returnBuffer.append(helperObjectGroups) return returnBuffer