def store(self,info,*a,**kw): """ Store information to an object in maya via case specific attribute. Keyword arguments: info(string) -- must be an object in the scene """ assert mc.objExists(info) is True, "'%s' doesn't exist"%info if info in self.bufferList: guiFactory.warning("'%s' is already stored on '%s'"%(info,self.nameLong)) return userAttrs = attributes.returnUserAttrsToDict(self.nameLong) or {} countList = [] for key in userAttrs.keys(): if 'item_' in key: splitBuffer = key.split('item_') countList.append(int(splitBuffer[-1])) cnt = 0 cntBreak = 0 while cnt in countList and cntBreak < 500: cnt+=1 cntBreak += 1 attributes.storeInfo(self.nameLong,('item_'+str(cnt)),info,*a,**kw) guiFactory.warning("'%s' stored on '%s'"%(info,self.nameLong)) self.bufferList.append(info) self.bufferDict['item_'+str(cnt)] = info
def returnTemplateObjects(moduleNull,types='templateObject'): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns the template null of a module ARGUMENTS: moduleNull(string) RETURNS: templateNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ templateNull = returnTemplateNull(moduleNull) templateNullData = attributes.returnUserAttrsToDict (templateNull) templateObjects = [] coreNamesArray = [] divider = NameFactory.returnCGMDivider() for key in templateNullData.keys(): if (mc.attributeQuery (key,node=templateNull,msg=True)) == True: templateObjects.append(templateNullData[key]) coreNamesArray.append (key) if types == 'all': return templateObjects else: returnBuffer = [] for obj in templateObjects: bufferList = obj.split(divider) if (typesDictionary.get(types)) in bufferList: returnBuffer.append(obj) return returnBuffer
def returnTemplateObjects(moduleNull, types='templateObject'): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns the template null of a module ARGUMENTS: moduleNull(string) RETURNS: templateNull(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ templateNull = returnTemplateNull(moduleNull) templateNullData = attributes.returnUserAttrsToDict(templateNull) templateObjects = [] coreNamesArray = [] divider = NameFactory.returnCGMDivider() for key in templateNullData.keys(): if (mc.attributeQuery(key, node=templateNull, msg=True)) == True: templateObjects.append(templateNullData[key]) coreNamesArray.append(key) if types == 'all': return templateObjects else: returnBuffer = [] for obj in templateObjects: bufferList = obj.split(divider) if (typesDictionary.get(types)) in bufferList: returnBuffer.append(obj) return returnBuffer
def store(self, info, *a, **kw): """ Store information to an object in maya via case specific attribute. Keyword arguments: info(string) -- must be an object in the scene """ assert mc.objExists(info) is True, "'%s' doesn't exist" % info if info in self.bufferList: guiFactory.warning("'%s' is already stored on '%s'" % (info, self.nameLong)) return userAttrs = attributes.returnUserAttrsToDict(self.nameLong) or {} countList = [] for key in userAttrs.keys(): if 'item_' in key: splitBuffer = key.split('item_') countList.append(int(splitBuffer[-1])) cnt = 0 cntBreak = 0 while cnt in countList and cntBreak < 500: cnt += 1 cntBreak += 1 attributes.storeInfo(self.nameLong, ('item_' + str(cnt)), info, *a, **kw) guiFactory.warning("'%s' stored on '%s'" % (info, self.nameLong)) self.bufferList.append(info) self.bufferDict['item_' + str(cnt)] = info
def getAttrs(self): """ Stores the dictionary of userAttrs of an object.""" self.userAttrsDict = attributes.returnUserAttrsToDict(self.nameLong) or {} self.userAttrs = mc.listAttr(self.nameLong, userDefined = True) or [] self.attrs = mc.listAttr(self.nameLong) or [] self.keyableAttrs = mc.listAttr(self.nameLong, keyable = True) or [] self.transformAttrs = [] for attr in 'translate','translateX','translateY','translateZ','rotate','rotateX','rotateY','rotateZ','scaleX','scale','scaleY','scaleZ','visibility','rotateOrder': if mc.objExists(self.nameLong+'.'+attr): self.transformAttrs.append(attr)
def returnNextAvailableCnt(self): """ Get's the next available item number """ userAttrs = attributes.returnUserAttrsToDict(self.nameLong) countList = [] for key in userAttrs.keys(): if 'item_' in key: splitBuffer = key.split('item_') countList.append(int(splitBuffer[-1])) cnt = 0 cntBreak = 0 while cnt in countList and cntBreak < 500: cnt+=1 cntBreak += 1 return cnt
def returnNextAvailableCnt(self): """ Get's the next available item number """ userAttrs = attributes.returnUserAttrsToDict(self.nameLong) countList = [] for key in userAttrs.keys(): if 'item_' in key: splitBuffer = key.split('item_') countList.append(int(splitBuffer[-1])) cnt = 0 cntBreak = 0 while cnt in countList and cntBreak < 500: cnt += 1 cntBreak += 1 return cnt
def returnInfoNullsFromModule(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns all info nulls of a module as a dictionary ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ moduleInfoNull = attributes.returnMessageObject(moduleNull,'info') return attributes.returnUserAttrsToDict(moduleInfoNull)
def returnInfoNullsFromModule(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns all info nulls of a module as a dictionary ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ moduleInfoNull = attributes.returnMessageObject(moduleNull, 'info') return attributes.returnUserAttrsToDict(moduleInfoNull)
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)
def buildBlendShapeNode(targetObject, blendShapeTargets, nameBlendShape = False): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Builds a blendshape node, while looking for in between shapes and connecting them accordingly ARGUMENTS: targetObject(string) blendShapeTargets(list) - nameBlendShape(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied RETURNS: blendShapeNode(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ # Name stuff if nameBlendShape != False: blendShapeNodeName = (nameBlendShape + '_bsNode') else: blendShapeNodeName = (targetObject + '_bsNode') #First look through the targetObjects for inbetween shapes baseTargets = [] inbetweenTargets = [] for object in blendShapeTargets: if mc.objExists(object+'.cgmBlendShapeTargetParent'): inbetweenTargets.append(object) else: baseTargets.append(object) # Make the blendshape node blendShapeNode = mc.blendShape(baseTargets,targetObject, n = blendShapeNodeName) blendShapeChannels = returnBlendShapeAttributes(blendShapeNode[0]) # Handle the inbetweens for object in inbetweenTargets: objAttrs = attributes.returnUserAttrsToDict(object) targetParent = objAttrs.get('cgmBlendShapeTargetParent') targetValue = float(objAttrs.get('cgmBlendShapeInbetweenWeight')) bsIndice = blendShapeChannels.index(targetParent) mc.blendShape(blendShapeNode[0], edit = True, ib = True , target = [targetObject,bsIndice,object,targetValue]) return blendShapeNode[0]
def doPurgeNull(null): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Delete all non 'cgm' type user attributes on an object ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ userAttrsData = attributes.returnUserAttrsToDict(null) if not userAttrsData: return False for attr in userAttrsData.keys(): if 'cgm' not in attr: attributes.doDeleteAttr(null, attr) guiFactory.warning("Deleted: '%s.%s'" % (null, attr))
def doPurgeNull(null): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Delete all non 'cgm' type user attributes on an object ARGUMENTS: moduleNull(string) RETURNS: infoNullDict(dict) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ userAttrsData = attributes.returnUserAttrsToDict(null) if not userAttrsData: return False for attr in userAttrsData.keys(): if 'cgm' not in attr: attributes.doDeleteAttr(null,attr) guiFactory.warning("Deleted: '%s.%s'"%(null,attr))
def cgmTagToFloatAttr(obj,cgmTag,*a, **kw): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Lays out a seies of objects in column and row format ARGUMENTS: objectList(string) columnNumber(int) - number of columns RETURNS: Nada >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ userAttrsData = attributes.returnUserAttrsToDict(obj) success = False for key in userAttrsData.keys(): if key == cgmTag: try: return attributes.addFloatAttributeToObject (obj, userAttrsData.get(key),*a, **kw ) except: return False
def cgmTagToFloatAttr(obj, cgmTag, *a, **kw): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Lays out a seies of objects in column and row format ARGUMENTS: objectList(string) columnNumber(int) - number of columns RETURNS: Nada >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ userAttrsData = attributes.returnUserAttrsToDict(obj) success = False for key in userAttrsData.keys(): if key == cgmTag: try: return attributes.addFloatAttributeToObject( obj, userAttrsData.get(key), *a, **kw) except: return False
def __init__(self,module,forceNew = True,loadTemplatePose = True,tryTemplateUpdate = False, **kws): """ To do: Add rotation order settting Add module parent check to make sure parent is templated to be able to move forward, or to constrain Add any other piece meal data necessary Add a cleaner to force a rebuild """ # Get our base info #============== #>>> module null data log.debug(">>> TemplateFactory.go.__init__") assert module.isModule(),"Not a module" self.m = module# Link for shortness log.info("loadTemplatePose: %s"%loadTemplatePose) if tryTemplateUpdate: log.info("Trying template update...") if updateTemplate(module,**kws): if loadTemplatePose: log.info("Trying loadTemplatePose...") self.m.loadTemplatePose() return if module.isTemplated(): if forceNew: module.deleteTemplate() else: log.warning("'%s' has already been templated"%module.getShortName()) return self.cls = "TemplateFactory.go" self.moduleNullData = attributes.returnUserAttrsToDict(self.m.mNode) self.templateNull = self.m.getMessage('templateNull')[0] or False self.i_templateNull = self.m.templateNull#link self.rigNull = self.m.getMessage('rigNull')[0] or False self.moduleParent = self.moduleNullData.get('moduleParent') self.moduleColors = self.m.getModuleColors() self.l_coreNames = self.m.i_coreNames.value self.corePosList = self.i_templateNull.templateStarterData self.foundDirections = False #Placeholder to see if we have it assert len(self.l_coreNames) == len(self.corePosList),"coreNames length and corePosList doesn't match" #>>> part name self.partName = self.m.getPartNameBase() self.partType = self.m.moduleType or False self.direction = None if self.m.hasAttr('cgmDirection'): self.direction = self.m.cgmDirection or None #>>> template null self.templateNullData = attributes.returnUserAttrsToDict(self.templateNull) self.curveDegree = self.i_templateNull.curveDegree self.rollOverride = self.i_templateNull.rollOverride log.debug("Module: %s"%self.m.getShortName()) log.debug("moduleNullData: %s"%self.moduleNullData) log.debug("partType: %s"%self.partType) log.debug("direction: %s"%self.direction) log.debug("colors: %s"%self.moduleColors) log.debug("coreNames: %s"%self.l_coreNames) log.debug("corePosList: %s"%self.corePosList) if self.m.mClass == 'cgmLimb': log.debug("mode: cgmLimb Template") doMakeLimbTemplate(self) doTagChildren(self) else: raise NotImplementedError,"haven't implemented '%s' templatizing yet"%self.m.mClass #>>> store template settings if loadTemplatePose:self.m.loadTemplatePose()
def saveTemplateToModule(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: * Save the new positional information from the template objects * Collect all names of objects for a delete list * If anything in the module doesn't belong there, un parent it, report it * like a template object parented to another obect ARGUMENTS: moduleNull(string) RETURNS: limbJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Variables #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Get our base info """ module null data """ moduleNullData = attributes.returnUserAttrsToDict(moduleNull) """ part name """ partName = NameFactory.returnUniqueGeneratedName(moduleNull, ignore = 'cgmType') partType = moduleNullData.get('cgmModuleType') direction = moduleNullData.get('cgmDirection') """ template null """ templateNull = moduleNullData.get('templateNull') templateNullData = attributes.returnUserAttrsToDict(templateNull) """ template object nulls """ templatePosObjectsInfoNull = returnInfoTypeNull(moduleNull,'templatePosObjects') templatePosObjectsInfoData = attributes.returnUserAttrsToDict (templatePosObjectsInfoNull) templateControlObjectsNull = returnInfoTypeNull(moduleNull,'templateControlObjects') templateControlObjectsData = attributes.returnUserAttrsToDict (templateControlObjectsNull) """ rig null """ rigNull = moduleNullData.get('rigNull') """ Start objects stuff """ templateStarterDataInfoNull = returnInfoTypeNull(moduleNull,'templateStarterData') templateControlObjectsDataNull = returnInfoTypeNull(moduleNull,'templateControlObjectsData') """ AutonameStuff """ divider = NameFactory.returnCGMDivider() moduleRootBuffer = returnInfoNullObjects(moduleNull,'templatePosObjects',types='templateRoot') moduleRoot = moduleRootBuffer[0] templateObjects = [] coreNamesArray = [] #>>>TemplateInfo for key in templatePosObjectsInfoData.keys(): if (mc.attributeQuery (key,node=templatePosObjectsInfoNull,msg=True)) == True: templateObjects.append (templatePosObjectsInfoData[key]) coreNamesArray.append (key) posTemplateObjects = [] """ Get the positional template objects""" for obj in templateObjects: bufferList = obj.split(divider) if (typesDictionary.get('templateObject')) in bufferList: posTemplateObjects.append(obj) """ get our control template objects """ controlTemplateObjects=[] for key in templateControlObjectsData.keys(): if (mc.attributeQuery (key,node=templateControlObjectsNull,msg=True)) == True: controlTemplateObjects.append (templateControlObjectsData[key]) """put objects in order of closeness to root""" posTemplateObjects = distance.returnDistanceSortedList(moduleRoot,posTemplateObjects) controlTemplateObjects = distance.returnDistanceSortedList(moduleRoot,controlTemplateObjects) curve = (templatePosObjectsInfoData['curve']) #>>> get our orientation helpers helperObjects = [] for obj in posTemplateObjects: helperObjects.append(attributes.returnMessageObject(obj,'orientHelper')) masterOrient = (attributes.returnMessageObject(moduleRoot,'orientHelper')) print ('%s%s'% (moduleNull,' data acquired...')) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Save Data #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Get the data """ pos objects """ storageData = [] for obj in posTemplateObjects: storageData.append(mc.xform (obj, q=True, ws=True, sp=True)) """ orientation helpers """ for obj in helperObjects: storageData.append(mc.xform (obj, q=True, os=True, ro=True)) storageData.append(mc.xform (masterOrient, q=True, os=True, ro=True)) print storageData """ template control objects data""" tempateControlObjectsStorageData = [] for obj in controlTemplateObjects: print obj tempateControlObjectsStorageData.append(mc.xform (obj, q=True, ws=True, t=True)) tempateControlObjectsStorageData.append(mc.xform (obj, q=True, os=True, ro=True)) rootScale = (mc.xform (moduleRoot, q=True, relative = True, scale=True)) objScaleBuffer = (mc.xform (obj, q=True, relative = True, scale=True)) objScale = [] cnt = 0 for scale in objScaleBuffer: objScale.append(scale*rootScale[cnt]) cnt+=1 tempateControlObjectsStorageData.append(objScale) print tempateControlObjectsStorageData #>>> Store the data to the initial objects pos """ Get the attributes to store to""" initialObjectsTemplateDataBuffer = attributes.returnUserAttrsToList(templateStarterDataInfoNull) initialObjectsPosData = lists.removeMatchedIndexEntries(initialObjectsTemplateDataBuffer,'cgm') """ store it""" cnt=0 for set in initialObjectsPosData: attrBuffer = set[0] xBuffer = (templateStarterDataInfoNull+'.'+attrBuffer+'X') yBuffer = (templateStarterDataInfoNull+'.'+attrBuffer+'Y') zBuffer = (templateStarterDataInfoNull+'.'+attrBuffer+'Z') dataSet = storageData[cnt] mc.setAttr (xBuffer, dataSet[0]) mc.setAttr (yBuffer, dataSet[1]) mc.setAttr (zBuffer, dataSet[2]) cnt+=1 #>>> Store the data to the initial objects pos """ Get the attributes to store to""" templateControlObjectsDataNullBuffer = attributes.returnUserAttrsToList(templateControlObjectsDataNull) templateControlObjectsData = lists.removeMatchedIndexEntries(templateControlObjectsDataNullBuffer,'cgm') """ store it""" cnt=0 for set in templateControlObjectsData: attrBuffer = set[0] xBuffer = (templateControlObjectsDataNull+'.'+attrBuffer+'X') yBuffer = (templateControlObjectsDataNull+'.'+attrBuffer+'Y') zBuffer = (templateControlObjectsDataNull+'.'+attrBuffer+'Z') dataSet = tempateControlObjectsStorageData[cnt] mc.setAttr (xBuffer, dataSet[0]) mc.setAttr (yBuffer, dataSet[1]) mc.setAttr (zBuffer, dataSet[2]) cnt+=1 #>>>>>>need to add locking>>>>>>>>>>>>>>>>>>>>>>>>>>>> print ('%s%s'% (moduleNull,' template object positional/rotational/scale data stored...')) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Save skin joints to skin joints null #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Delete stuff #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Gather our objects""" toDeleteList = search.returnObjectsOwnedByModuleNull(templateNull) print toDeleteList for obj in toDeleteList: if mc.objExists(obj) == True: print ('%s%s'% (obj,' deleted...')) mc.delete(obj) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Change Tag #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> mc.setAttr ((moduleNull+'.templateState'), 0) mc.setAttr ((moduleNull+'.skeletonState'), 1) #add locking print ('%s%s'% (moduleNull,' done')) return 'done'
def makeLimbTemplate (self): #>>>Curve degree finder if self.optionCurveDegree.get() == 0: doCurveDegree = 1 else: if len(corePositionList) <= 3: doCurveDegree = 1 else: doCurveDegree = len(corePositionList) - 1 #Make some storage vehicles self.templatePosObjectsBuffer = BufferFactory(self.infoNulls['templatePosObjects'].get()) self.templatePosObjectsBuffer.purge() LocatorCatcher = ObjectFactory('') LocatorBuffer = BufferFactory(LocatorCatcher.nameLong) LocatorBuffer.purge() returnList = [] self.templHandleList = [] moduleColors = modules.returnModuleColors(self.ModuleNull.nameShort) #>>>Scale stuff moduleParent = self.msgModuleParent.get() if not moduleParent: length = (distance.returnDistanceBetweenPoints (corePositionList[0],corePositionList[-1])) size = length / self.optionHandles.get() else: #>>>>>>>>>>>>>>>>>>>>> NOT TOUCHED YET parentTemplatePosObjectsInfoNull = modules.returnInfoTypeNull(moduleParent,'templatePosObjects') parentTemplatePosObjectsInfoData = attributes.returnUserAttrsToDict (parentTemplatePosObjectsInfoNull) parentTemplateObjects = [] for key in parentTemplatePosObjectsInfoData.keys(): if (mc.attributeQuery (key,node=parentTemplatePosObjectsInfoNull,msg=True)) == True: if search.returnTagInfo((parentTemplatePosObjectsInfoData[key]),'cgmType') != 'templateCurve': parentTemplateObjects.append (parentTemplatePosObjectsInfoData[key]) createBuffer = curves.createControlCurve('sphere',1) pos = corePositionList[0] mc.move (pos[0], pos[1], pos[2], createBuffer, a=True) closestParentObject = distance.returnClosestObject(createBuffer,parentTemplateObjects) boundingBoxSize = distance.returnBoundingBoxSize (closestParentObject) maxSize = max(boundingBoxSize) size = maxSize *.25 mc.delete(createBuffer) if partType == 'clavicle': size = size * .5 elif partType == 'head': size = size * .75 if (search.returnTagInfo(moduleParent,'cgmModuleType')) == 'clavicle': size = size * 2 #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Making the template objects #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> self.TemplateObject = {} #>>> Template objects for cnt,pos in enumerate(corePositionList): #Size multiplier based on PuppetMode, make it take into account module mode eventually if PuppetInstance.optionPuppetMode.get() == 0: if cnt == 0: sizeMultiplier = 1 elif cnt == len(corePositionList) -1: sizeMultiplier = .8 else: sizeMultiplier = .5 else: sizeMultiplier = 1 #make a sphere and move it createBuffer = curves.createControlCurve('sphere',(size * sizeMultiplier)) self.TemplateObject[cnt] = ObjectFactory(createBuffer) # Instance the control to our module obj = self.TemplateObject[cnt] curves.setCurveColorByName(obj.nameLong,moduleColors[0]) obj.store('cgmName',coreNames[cnt]) obj.getNameTagsFromObject(self.ModuleNull.nameLong,['cgmName','cgmType']) obj.store('cgmType','templateObject') obj.doName() mc.move (pos[0], pos[1], pos[2], [obj.nameLong], a=True) #adds it to the list self.templHandleList.append (obj.nameLong) self.templatePosObjectsBuffer.store(obj.nameLong) #Aim the objects position.aimObjects(self.templHandleList, dictionary.axisDirectionsByString[ self.optionAimAxis.get() ], dictionary.axisDirectionsByString[ self.optionUpAxis.get() ], dictionary.axisDirectionsByString[ PuppetInstance.optionUpAxis.get() ]) #>>> Template curve crvName = mc.curve (d=doCurveDegree, p = corePositionList , os=True, n=('%s_%s' %(partName,(typesDictionary.get('templateCurve'))))) self.afTemplateCurve = AttrFactory(self.infoNulls['templatePosObjects'].get(), 'curve','message', value=crvName)# connect it back to our template objects info null curve = ObjectFactory(crvName) # instance it curve.getNameTagsFromObject(self.ModuleNull.nameLong,['cgmType']) #get name tags from the module attributes.storeInfo(crvName,'cgmType','templateCurve') # store type curves.setCurveColorByName(crvName,moduleColors[1]) # set curve color # Make locators to connect the cv's to for cnt,obj in enumerate(self.templHandleList): pointLoc = locators.locMeObject(obj) # make the loc loc = ObjectFactory(pointLoc) #instance it mc.setAttr ((loc.nameShort+'.visibility'),0) # turn off visibility mc.parentConstraint ([obj],[loc.nameShort],mo=False) # parent constrain mc.connectAttr ( (loc.nameShort+'.translate'), ('%s.controlPoints[%i]' % (crvName, cnt)), f=True ) # connect the cv to the loc self.TemplateObject[cnt].store('loc',loc.nameLong) LocatorBuffer.store(loc.nameLong) #>>> Direction and size Stuff """ # Directional data derived from joints generalDirection = logic.returnHorizontalOrVertical(self.templHandleList) 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] """ # Create root control templateNull = self.msgTemplateNull.get() handleList = copy.copy(self.templatePosObjectsBuffer.bufferList) rootSize = (distance.returnBoundingBoxSizeToAverage(self.templHandleList[0])*1.5) rootCtrl = ObjectFactory(curves.createControlCurve('cube',rootSize)) rootCtrl.getNameTagsFromObject(self.ModuleNull.nameLong) self.msgTemplateRoot = AttrFactory(self.infoNulls['templatePosObjects'].get(), 'root', 'message', value = rootCtrl.nameLong) curves.setCurveColorByName(rootCtrl.nameLong,moduleColors[0]) # move the root if self.afModuleType.get() == 'clavicle': position.movePointSnap(rootCtrl.nameLong,self.templHandleList[0]) else: position.movePointSnap(rootCtrl.nameLong,self.templHandleList[0]) # aim the root position.aimSnap(rootCtrl.nameShort,self.templHandleList[-1], dictionary.axisDirectionsByString[ self.optionAimAxis.get() ], dictionary.axisDirectionsByString[ self.optionUpAxis.get() ], dictionary.axisDirectionsByString[ PuppetInstance.optionUpAxis.get() ]) rootCtrl.store('cgmType','templateRoot') rootCtrl.doName() #>>> Parent the main objcts rootGroup = rootCtrl.doGroup() rootGroup = rigging.doParentReturnName(rootGroup,templateNull) curve.doParent(templateNull) for obj in LocatorBuffer.bufferList: rigging.doParentReturnName(obj,templateNull) mc.delete(LocatorCatcher.nameShort) # delete the locator buffer obj #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>> Orientation helpers #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Make our Orientation Helpers """ orientHelpersReturn = template.addOrientationHelpers(self) masterOrient = orientHelpersReturn[0] orientObjects = orientHelpersReturn[1] return #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>> Control helpers #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> print orientObjects print self.ModuleNull.nameShort print (templateNull+'.visControlHelpers') controlHelpersReturn = addControlHelpers(orientObjects,self.ModuleNull.nameShort,(templateNull+'.visControlHelpers'))""" #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>> Input the saved values if there are any #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Orientation Helpers """rotBuffer = coreRotationList[-1] #actualName = mc.spaceLocator (n= wantedName) rotCheck = sum(rotBuffer) if rotCheck != 0: mc.rotate(rotBuffer[0],rotBuffer[1],rotBuffer[2],masterOrient,os=True) cnt = 0 for obj in orientObjects: rotBuffer = coreRotationList[cnt] rotCheck = sum(rotBuffer) if rotCheck != 0: mc.rotate(rotBuffer[0],rotBuffer[1],rotBuffer[2],obj,os=True) cnt +=1 # Control Helpers controlHelpers = controlHelpersReturn[0] cnt = 0 for obj in controlHelpers: posBuffer = controlPositionList[cnt] posCheck = sum(posBuffer) if posCheck != 0: mc.xform(obj,t=[posBuffer[0],posBuffer[1],posBuffer[2]],ws=True) rotBuffer = controlRotationList[cnt] rotCheck = sum(rotBuffer) if rotCheck != 0: mc.rotate(rotBuffer[0],rotBuffer[1],rotBuffer[2],obj,ws=True) scaleBuffer = controlScaleList[cnt] scaleCheck = sum(scaleBuffer) if scaleCheck != 0: mc.scale(scaleBuffer[0],scaleBuffer[1],scaleBuffer[2],obj,absolute=True) cnt +=1 """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>> Final stuff #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ returnList.append(templObjNameList) returnList.append(self.templHandleList) returnList.append(rootCtrl)""" return True
def saveTemplateToModule(moduleNull): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: * Save the new positional information from the template objects * Collect all names of objects for a delete list * If anything in the module doesn't belong there, un parent it, report it * like a template object parented to another obect ARGUMENTS: moduleNull(string) RETURNS: limbJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Variables #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Get our base info """ module null data """ moduleNullData = attributes.returnUserAttrsToDict(moduleNull) """ part name """ partName = NameFactory.returnUniqueGeneratedName(moduleNull, ignore='cgmType') partType = moduleNullData.get('cgmModuleType') direction = moduleNullData.get('cgmDirection') """ template null """ templateNull = moduleNullData.get('templateNull') templateNullData = attributes.returnUserAttrsToDict(templateNull) """ template object nulls """ templatePosObjectsInfoNull = returnInfoTypeNull(moduleNull, 'templatePosObjects') templatePosObjectsInfoData = attributes.returnUserAttrsToDict( templatePosObjectsInfoNull) templateControlObjectsNull = returnInfoTypeNull(moduleNull, 'templateControlObjects') templateControlObjectsData = attributes.returnUserAttrsToDict( templateControlObjectsNull) """ rig null """ rigNull = moduleNullData.get('rigNull') """ Start objects stuff """ templateStarterDataInfoNull = returnInfoTypeNull(moduleNull, 'templateStarterData') templateControlObjectsDataNull = returnInfoTypeNull( moduleNull, 'templateControlObjectsData') """ AutonameStuff """ divider = NameFactory.returnCGMDivider() moduleRootBuffer = returnInfoNullObjects(moduleNull, 'templatePosObjects', types='templateRoot') moduleRoot = moduleRootBuffer[0] templateObjects = [] coreNamesArray = [] #>>>TemplateInfo for key in templatePosObjectsInfoData.keys(): if (mc.attributeQuery(key, node=templatePosObjectsInfoNull, msg=True)) == True: templateObjects.append(templatePosObjectsInfoData[key]) coreNamesArray.append(key) posTemplateObjects = [] """ Get the positional template objects""" for obj in templateObjects: bufferList = obj.split(divider) if (typesDictionary.get('templateObject')) in bufferList: posTemplateObjects.append(obj) """ get our control template objects """ controlTemplateObjects = [] for key in templateControlObjectsData.keys(): if (mc.attributeQuery(key, node=templateControlObjectsNull, msg=True)) == True: controlTemplateObjects.append(templateControlObjectsData[key]) """put objects in order of closeness to root""" posTemplateObjects = distance.returnDistanceSortedList( moduleRoot, posTemplateObjects) controlTemplateObjects = distance.returnDistanceSortedList( moduleRoot, controlTemplateObjects) curve = (templatePosObjectsInfoData['curve']) #>>> get our orientation helpers helperObjects = [] for obj in posTemplateObjects: helperObjects.append( attributes.returnMessageObject(obj, 'orientHelper')) masterOrient = (attributes.returnMessageObject(moduleRoot, 'orientHelper')) print('%s%s' % (moduleNull, ' data acquired...')) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Save Data #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Get the data """ pos objects """ storageData = [] for obj in posTemplateObjects: storageData.append(mc.xform(obj, q=True, ws=True, sp=True)) """ orientation helpers """ for obj in helperObjects: storageData.append(mc.xform(obj, q=True, os=True, ro=True)) storageData.append(mc.xform(masterOrient, q=True, os=True, ro=True)) print storageData """ template control objects data""" tempateControlObjectsStorageData = [] for obj in controlTemplateObjects: print obj tempateControlObjectsStorageData.append( mc.xform(obj, q=True, ws=True, t=True)) tempateControlObjectsStorageData.append( mc.xform(obj, q=True, os=True, ro=True)) rootScale = (mc.xform(moduleRoot, q=True, relative=True, scale=True)) objScaleBuffer = (mc.xform(obj, q=True, relative=True, scale=True)) objScale = [] cnt = 0 for scale in objScaleBuffer: objScale.append(scale * rootScale[cnt]) cnt += 1 tempateControlObjectsStorageData.append(objScale) print tempateControlObjectsStorageData #>>> Store the data to the initial objects pos """ Get the attributes to store to""" initialObjectsTemplateDataBuffer = attributes.returnUserAttrsToList( templateStarterDataInfoNull) initialObjectsPosData = lists.removeMatchedIndexEntries( initialObjectsTemplateDataBuffer, 'cgm') """ store it""" cnt = 0 for set in initialObjectsPosData: attrBuffer = set[0] xBuffer = (templateStarterDataInfoNull + '.' + attrBuffer + 'X') yBuffer = (templateStarterDataInfoNull + '.' + attrBuffer + 'Y') zBuffer = (templateStarterDataInfoNull + '.' + attrBuffer + 'Z') dataSet = storageData[cnt] mc.setAttr(xBuffer, dataSet[0]) mc.setAttr(yBuffer, dataSet[1]) mc.setAttr(zBuffer, dataSet[2]) cnt += 1 #>>> Store the data to the initial objects pos """ Get the attributes to store to""" templateControlObjectsDataNullBuffer = attributes.returnUserAttrsToList( templateControlObjectsDataNull) templateControlObjectsData = lists.removeMatchedIndexEntries( templateControlObjectsDataNullBuffer, 'cgm') """ store it""" cnt = 0 for set in templateControlObjectsData: attrBuffer = set[0] xBuffer = (templateControlObjectsDataNull + '.' + attrBuffer + 'X') yBuffer = (templateControlObjectsDataNull + '.' + attrBuffer + 'Y') zBuffer = (templateControlObjectsDataNull + '.' + attrBuffer + 'Z') dataSet = tempateControlObjectsStorageData[cnt] mc.setAttr(xBuffer, dataSet[0]) mc.setAttr(yBuffer, dataSet[1]) mc.setAttr(zBuffer, dataSet[2]) cnt += 1 #>>>>>>need to add locking>>>>>>>>>>>>>>>>>>>>>>>>>>>> print('%s%s' % (moduleNull, ' template object positional/rotational/scale data stored...')) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Save skin joints to skin joints null #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Delete stuff #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Gather our objects""" toDeleteList = search.returnObjectsOwnedByModuleNull(templateNull) print toDeleteList for obj in toDeleteList: if mc.objExists(obj) == True: print('%s%s' % (obj, ' deleted...')) mc.delete(obj) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Change Tag #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> mc.setAttr((moduleNull + '.templateState'), 0) mc.setAttr((moduleNull + '.skeletonState'), 1) #add locking print('%s%s' % (moduleNull, ' done')) return 'done'
def skeletonize(moduleNull, stiffIndex=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Basic limb skeletonizer ARGUMENTS: moduleNull(string) stiffIndex(int) - the index of the template objects you want to not have roll joints For example, a value of -1 will let the chest portion of a spine segment be solid instead of having a roll segment. Default is '0' which will put roll joints in every segment RETURNS: limbJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>Get our info #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> partName = NameFactory.returnUniqueGeneratedName(moduleNull, ignore='cgmType') """ template null """ templateNull = modules.returnTemplateNull(moduleNull) templateNullData = attributes.returnUserAttrsToDict(templateNull) """ template object nulls """ templatePosObjectsInfoNull = modules.returnInfoTypeNull( moduleNull, 'templatePosObjects') templateControlObjectsNull = modules.returnInfoTypeNull( moduleNull, 'templateControlObjects') templatePosObjectsInfoData = attributes.returnUserAttrsToDict( templatePosObjectsInfoNull) templateControlObjectsData = attributes.returnUserAttrsToDict( templateControlObjectsNull) jointOrientation = modules.returnSettingsData('jointOrientation') moduleRootBuffer = modules.returnInfoNullObjects(moduleNull, 'templatePosObjects', types='templateRoot') moduleRoot = moduleRootBuffer[0] stiffIndex = templateNullData.get('stiffIndex') rollJoints = templateNullData.get('rollJoints') """ AutonameStuff """ divider = NameFactory.returnCGMDivider() skinJointsNull = modules.returnInfoTypeNull(moduleNull, 'skinJoints') templateObjects = [] coreNamesArray = [] #>>>TemplateInfo for key in templatePosObjectsInfoData.keys(): if (mc.attributeQuery(key, node=templatePosObjectsInfoNull, msg=True)) == True: templateObjects.append(templatePosObjectsInfoData[key]) coreNamesArray.append(key) posTemplateObjects = [] """ Get the positional template objects""" for obj in templateObjects: bufferList = obj.split(divider) if (typesDictionary.get('templateObject')) in bufferList: posTemplateObjects.append(obj + divider + typesDictionary.get('locator')) """put objects in order of closeness to root""" posTemplateObjects = distance.returnDistanceSortedList( moduleRoot, posTemplateObjects) curve = (templatePosObjectsInfoData['curve']) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Actually making the skeleton with consideration for roll joints and the stiffIndex! #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if stiffIndex == 0: """ If no roll joints """ limbJoints = joints.createJointsFromCurve(curve, partName, rollJoints) else: rolledJoints = joints.createJointsFromCurve(curve, partName, rollJoints) if rollJoints == 0: limbJoints = rolledJoints else: if stiffIndex < 0: """ Get our to delete number in a rolledJoints[-4:] format""" #searchIndex = (int('%s%s' %('-',(rollJoints+1)))*abs(stiffIndex)-1) searchIndex = (int('%s%s' % ('-', (rollJoints + 1))) * abs(stiffIndex)) toDelete = rolledJoints[searchIndex:] """ delete out the roll joints we don't want""" mc.delete(toDelete[0]) for name in toDelete: rolledJoints.remove(name) """ make our stiff joints """ jointPositions = [] if abs(stiffIndex) == 1: jointPositions.append( distance.returnClosestUPosition( posTemplateObjects[stiffIndex], curve)) else: for obj in posTemplateObjects[stiffIndex:]: jointPositions.append( distance.returnClosestUPosition(obj, curve)) stiffJoints = joints.createJointsFromPosListName( jointPositions, 'partName') """ connect em up """ mc.parent(stiffJoints[0], rolledJoints[-1]) limbJoints = [] for joint in rolledJoints: limbJoints.append(joint) for joint in stiffJoints: limbJoints.append(joint) else: """ if it's not negative, it's positive....""" searchIndex = ((rollJoints + 1) * abs(stiffIndex)) toDelete = rolledJoints[:searchIndex] toKeep = rolledJoints[searchIndex:] """ delete out the roll joints we don't want""" mc.parent(toKeep[0], world=True) mc.delete(toDelete[0]) for name in toDelete: rolledJoints.remove(name) """ make our stiff joints """ jointPositions = [] if abs(stiffIndex) == 1: jointPositions.append( distance.returnClosestUPosition( posTemplateObjects[stiffIndex - 1], curve)) else: for obj in posTemplateObjects[:stiffIndex]: jointPositions.append( distance.returnClosestUPosition(obj, curve)) stiffJoints = joints.createJointsFromPosListName( jointPositions, 'partName') """ connect em up """ mc.parent(rolledJoints[0], stiffJoints[-1]) limbJoints = [] for joint in stiffJoints: limbJoints.append(joint) for joint in rolledJoints: limbJoints.append(joint) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Naming #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Copy naming information from template objects to the joints closest to them copy over a cgmNameModifier tag from the module first """ attributes.copyUserAttrs(moduleNull, limbJoints[0], attrsToCopy=['cgmNameModifier']) """ First we need to find our matches """ for obj in posTemplateObjects: closestJoint = distance.returnClosestObject(obj, limbJoints) transferObj = attributes.returnMessageObject(obj, 'cgmName') """Then we copy it""" attributes.copyUserAttrs( transferObj, closestJoint, attrsToCopy=['cgmNameModifier', 'cgmDirection', 'cgmName']) limbJointsBuffer = NameFactory.doRenameHeir(limbJoints[0]) limbJoints = [] limbJoints.append(limbJointsBuffer[0]) for joint in limbJointsBuffer[1]: limbJoints.append(joint) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Orientation #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> limbJoints = orientSegment(limbJoints, posTemplateObjects, jointOrientation) #>>> Set its radius and toggle axis visbility on #averageDistance = distance.returnAverageDistanceBetweenObjects (limbJoints) jointSize = ( distance.returnDistanceBetweenObjects(limbJoints[0], limbJoints[-1]) / 6) for jnt in limbJoints: mc.setAttr((jnt + '.radi'), jointSize * .2) #>>>>>>> TEMP joints.toggleJntLocalAxisDisplay(jnt) print 'to orientation' #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Storing data #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> skinJointsNull = modules.returnInfoTypeNull(moduleNull, 'skinJoints') skinJointsNullData = attributes.returnUserAttrsToList(skinJointsNull) existingSkinJoints = lists.removeMatchedIndexEntries( skinJointsNullData, 'cgm') print existingSkinJoints if len(existingSkinJoints) > 0: for entry in existingSkinJoints: attrBuffer = (skinJointsNull + '.' + entry[0]) print attrBuffer attributes.doDeleteAttr(skinJointsNull, entry[0]) for i in range(len(limbJoints)): buffer = ('%s%s' % ('joint_', i)) attributes.storeInfo(skinJointsNull, buffer, limbJoints[i]) return limbJoints
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)