def register( controlObject=None, #(mObject - None) -- The object to use as a control typeModifier=None, #(string - None) -- Tag for cgmTypeModifier for naming copyTransform=None, #(mObject - None) -- Object to copy the transform of for our control object copyPivot=None, #(mObject - None) -- Object to copy the pivot of for our control object shapeParentTo=None, #'(mObject - None) -- Object to shape parent our control curve to to use that transform useShape=None, #'(mObject - None) -- Object to use the curve shape of for our control setRotateOrder=None, #'(rotateOrder - None) -- Argument for a rotate order to set autoLockNHide=None, #'(bool - None) -- Try to set lock and hide mirrorAxis=None, #'(string - None) -- Mirror axis to set - using red9's setup terms mirrorSide=None, #'(string/int - None) -- Mirror side - using red9's setup terms makeMirrorable=True, #'(bool - True) -- Setup for mirrorability (using red9) -- implied by other mirror args addDynParentGroup=False, #'(False) -- Add a dynParent group setup addExtraGroups=False, #'(int - False) -- Number of nested extra groups desired addConstraintGroup=False, #'(bool - False) -- If a group just above the control is desired for consraining freezeAll=False, #'(bool - False) -- Freeze all transforms on the control object noFreeze=False, addSpacePivots=False, #'(int - False) -- Number of space pivots to generate and connect controlType=None, #'(string - None) -- Tag for cgmType aim=None, #'(string/int - None) -- aim axis to use up=None, #'(string/int - None) -- up axis to use out=None, #'(string/int - None) -- out axis to use makeAimable=None, #'(mObject - False) -- Make object aimable -- implied by aim/up/out): **kws): _str_func = 'register' """ [{'step':'validate','call':self._validate}, {'step':'Copy Transform','call':self._copyTransform}, {'step':'Shape Parent','call':self._shapeParent}, {'step':'Copy Pivot','call':self._copyPivot}, {'step':'Naming','call':self._naming}, {'step':'Aim Setup','call':self._aimSetup}, {'step':'Rotate Order','call':self._rotateOrder}, {'step':'Initial Freeze','call':self._initialFreeze}, {'step':'Groups Setup','call':self._groupsSetup}, {'step':'Space Pivot','call':self._spacePivots}, {'step':'Mirror Setup','call':self._mirrorSetup}, {'step':'Freeze','call':self._freeze}, {'step':'Mirror Attribute Bridges','call':self._mirrorAttributeBridges_}, {'step':'lock N Hide','call':self._lockNHide}, {'step':'Return build','call':self._returnBuild}] """ try: #Validate ================================================================================================ mi_control = cgmMeta.validateObjArg(controlObject, 'cgmControl', setClass=True) str_mirrorAxis = VALID.stringArg(mirrorAxis, calledFrom=_str_func) str_mirrorSide = cgmGeneral.verify_mirrorSideArg( mirrorSide) #VALID.stringArg(mirrorSide,calledFrom = _str_func) b_makeMirrorable = VALID.boolArg(makeMirrorable, calledFrom=_str_func) _addMirrorAttributeBridges = kws.get('addMirrorAttributeBridges', False) addForwardBack = kws.get('addForwardBack', False) if _addMirrorAttributeBridges: if type(_addMirrorAttributeBridges) not in [list, tuple]: raise ValueError, "[Bad addMirrorAttributeBridge arg]{arg: %s}" % _addMirrorAttributeBridge for i, l in enumerate(_addMirrorAttributeBridges): if type(l) not in [list, tuple]: raise ValueError, "[Bad addMirrorAttributeBridge arg: %s]{arg: %s}" % ( i, l) # Running lists ------------------------------------------------------------------------------------------ ml_groups = [] #Holder for groups ml_constraintGroups = [] ml_spacePivots = [] #Copy Transform ================================================================================================ if copyTransform is not None: mTarget = cgmMeta.validateObjArg(copyTransform, 'cgmObject', noneValid=True) if not mTarget: raise StandardError, "Failed to find suitable copyTransform object: '%s" % copyTransform #Need to move this to default cgmNode stuff mBuffer = mi_control i_newTransform = cgmMeta.cgmObject( rigging.groupMeObject(mTarget.mNode, False)) for a in mc.listAttr(mi_control.mNode, userDefined=True): ATTR.copy_to(mi_control.mNode, a, i_newTransform.mNode) curves.parentShapeInPlace(i_newTransform.mNode, mi_control.mNode) #Parent shape i_newTransform.parent = mi_control.parent #Copy parent mi_control = cgmMeta.asMeta(i_newTransform, 'cgmControl', setClass=True) mc.delete(mBuffer.mNode) #ShapeParent ================================================================================================ if shapeParentTo: i_target = cgmMeta.validateObjArg(shapeParentTo, 'cgmObject') CORERIG.shapeParent_in_place(i_target.mNode, mi_control.mNode) i_target = cgmMeta.asMeta(i_target, 'cgmControl', setClass=True) #mi_control.delete() mi_control = i_target #replace the control with the joint if useShape is not None: i_shape = cgmMeta.validateObjArg(useShape, cgmMeta.cgmObject, mayaType='nurbsCurve') curves.parentShapeInPlace(mi_control.mNode, i_shape.mNode) #Copy Pivot ============================================================================================ if copyPivot is not None: if issubclass(type(copyPivot), cgmMeta.cgmNode): i_target = copyPivot elif mc.objExists(copyPivot): i_target = cgmMeta.cgmObject(copyPivot) else: raise StandardError, "Failed to find suitable copyTransform object: '%s" % copyPivot #Need to move this to default cgmNode stuff mi_control.doCopyPivot(i_target.mNode) #Naming ============================================================================================ mi_control.addAttr('cgmType', 'controlAnim', lock=True) if typeModifier is not None: mi_control.addAttr('cgmTypeModifier', str(typeModifier), lock=True) mi_control.doName() #mi_control.doName(nameShapes=True) #Rotate Order ============================================================================================ _rotateOrder = False if setRotateOrder is not None: _rotateOrder = setRotateOrder elif controlType in __d_rotateOrderDefaults__.keys(): _rotateOrder = __d_rotateOrderDefaults__[controlType] elif mi_control.getAttr('cgmName') in __d_rotateOrderDefaults__.keys(): _rotateOrder = __d_rotateOrderDefaults__[mi_control.getAttr( 'cgmName')] else: log.debug("|{0}| >> Rotate order not set on: {1}".format( _str_func, mi_control.p_nameShort)) #Set it --------------------------------------------------------------- if _rotateOrder: mRotateOrder = VALID.simpleOrientation(_rotateOrder) #dictionary.validateRotateOrderString(_rotateOrder) mc.xform(mi_control.mNode, rotateOrder=mRotateOrder.p_string) #Initial Freeze ============================================================================================ if freezeAll: mc.makeIdentity(mi_control.mNode, apply=True, t=1, r=1, s=1, n=0) #Groups ============================================================================================ if addDynParentGroup or addSpacePivots or mi_control.getAttr( 'cgmName') == 'cog' or _addMirrorAttributeBridges: mi_control.addAttr('________________', attrType='int', keyable=False, hidden=False, lock=True) ATTR.reorder(mi_control.mNode, '________________', top=True) #Aim Setup ============================================================================================ if aim is not None or up is not None or makeAimable: mi_control._verifyAimable() #First our master group: i_masterGroup = (cgmMeta.asMeta(mi_control.doGroup(True), 'cgmObject', setClass=True)) i_masterGroup.doStore('cgmName', mi_control) i_masterGroup.addAttr('cgmTypeModifier', 'master', lock=True) i_masterGroup.doName() mi_control.connectChildNode(i_masterGroup, 'masterGroup', 'groupChild') if addDynParentGroup: i_dynGroup = (cgmMeta.cgmObject(mi_control.doGroup(True))) i_dynGroup = cgmRigMeta.cgmDynParentGroup(dynChild=mi_control, dynGroup=i_dynGroup) i_dynGroup.doName() """ i_zeroGroup = (cgmMeta.cgmObject(mi_control.doGroup(True))) i_zeroGroup.addAttr('cgmTypeModifier','zero',lock=True) i_zeroGroup.doName() mi_control.connectChildNode(i_zeroGroup,'zeroGroup','groupChild')""" if addExtraGroups: for i in range(addExtraGroups): i_group = (cgmMeta.asMeta(mi_control.doGroup(True), 'cgmObject', setClass=True)) if type( addExtraGroups ) == int and addExtraGroups > 1: #Add iterator if necessary i_group.addAttr('cgmIterator', str(i + 1), lock=True) i_group.doName() ml_groups.append(i_group) mi_control.msgList_connect("extraGroups", ml_groups, 'groupChild') if addConstraintGroup: #ConstraintGroups i_constraintGroup = (cgmMeta.asMeta(mi_control.doGroup(True), 'cgmObject', setClass=True)) i_constraintGroup.addAttr('cgmTypeModifier', 'constraint', lock=True) i_constraintGroup.doName() ml_constraintGroups.append(i_constraintGroup) mi_control.connectChildNode(i_constraintGroup, 'constraintGroup', 'groupChild') #Space Pivot ============================================================================================ if addSpacePivots: parent = mi_control.getMessage('masterGroup')[0] for i in range(int(addSpacePivots)): #i_pivot = rUtils.create_spaceLocatorForObject(mi_control.mNode,parent) i_pivot = SPACEPIVOTS.create(mi_control.mNode, parent) ml_spacePivots.append(i_pivot) #log.info("spacePivot created: {0}".format(i_pivot.p_nameShort)) #Mirror Setup ============================================================================================ if str_mirrorSide is not None or b_makeMirrorable: for mObj in [mi_control] + ml_spacePivots: mi_control._verifyMirrorable() l_enum = cgmMeta.cgmAttr(mi_control, 'mirrorSide').p_enum if str_mirrorSide in l_enum: #log.debug("|{0}| >> Rotate order not set on: {1}".format(_str_func,mi_control.p_nameShort)) #log.debug("%s >> %s >> found in : %s"%(_str_funcCombined, "mirrorSetup", l_enum)) mi_control.mirrorSide = l_enum.index(str_mirrorSide) if str_mirrorAxis: mi_control.mirrorAxis = str_mirrorAxis for mObj in mi_control.msgList_get('spacePivots'): mObj._verifyMirrorable() mi_control.doConnectOut('mirrorAxis', mObj.mNode + '.mirrorAxis') mi_control.doConnectOut('mirrorSide', mObj.mNode + '.mirrorSide') #cgmMeta.cgmAttr(mObj,'mirrorSide').doConnectIn(mi_control,'mirrorSide') #cgmMeta.cgmAttr(mi_control,'mirrorAxis').doCopyTo(mObj,connectTargetToSource = 1) #ATTR.connect(mObj.mNode + '.mirrorAxis',"{0}.mirrorAxis".format(mi_control.mNode)) #ATTR.connect(mObj.mNode + 'mirrorSide',"{0}.mirrorSide".format(mi_control.mNode)) #Freeze ============================================================================================ if not shapeParentTo and noFreeze is not True: if not freezeAll: if mi_control.getAttr( 'cgmName' ) == 'cog' or controlType in __l_fullFreezeTypes__: mc.makeIdentity(mi_control.mNode, apply=True, t=1, r=1, s=1, n=0) else: mc.makeIdentity(mi_control.mNode, apply=True, t=1, r=0, s=1, n=0) else: mc.makeIdentity(mi_control.mNode, apply=True, t=1, r=1, s=1, n=0) #Mirror attriubte Bridges ========================================================================== if addForwardBack: mPlug_forwardBackDriver = cgmMeta.cgmAttr(mi_control, "forwardBack", attrType='float', keyable=True) try: mPlug_forwardBackDriven = cgmMeta.validateAttrArg( [mi_control, addForwardBack])['mi_plug'] except Exception, error: raise StandardError, "push pull driver | %s" % (error) if str_mirrorSide.lower() == 'right': arg_forwardBack = "%s = -%s" % ( mPlug_forwardBackDriven.p_combinedShortName, mPlug_forwardBackDriver.p_combinedShortName) else: arg_forwardBack = "%s = %s" % ( mPlug_forwardBackDriven.p_combinedShortName, mPlug_forwardBackDriver.p_combinedShortName) mPlug_forwardBackDriven.p_locked = True mPlug_forwardBackDriven.p_hidden = True mPlug_forwardBackDriven.p_keyable = False NodeF.argsToNodes(arg_forwardBack).doBuild() if _addMirrorAttributeBridges: for l_bridge in _addMirrorAttributeBridges: _attrName = VALID.stringArg(l_bridge[0]) _attrToBridge = VALID.stringArg(l_bridge[1]) if not mi_control.hasAttr(_attrToBridge): raise StandardError, "['%s' lacks the bridge attr '%s']" % ( mi_control.p_nameShort, _attrToBridge) mPlug_attrBridgeDriver = cgmMeta.cgmAttr(mi_control, _attrName, attrType='float', keyable=True) try: mPlug_attrBridgeDriven = cgmMeta.validateAttrArg( [mi_control, _attrToBridge])['mi_plug'] except Exception, error: raise StandardError, "[validate control attribute bridge attr]{%s}" % ( error) if str_mirrorSide.lower() == 'right': arg_attributeBridge = "%s = -%s" % ( mPlug_attrBridgeDriven.p_combinedShortName, mPlug_attrBridgeDriver.p_combinedShortName) else: arg_attributeBridge = "%s = %s" % ( mPlug_attrBridgeDriven.p_combinedShortName, mPlug_attrBridgeDriver.p_combinedShortName) mPlug_attrBridgeDriven.p_locked = True mPlug_attrBridgeDriven.p_hidden = True mPlug_attrBridgeDriven.p_keyable = False NodeF.argsToNodes(arg_attributeBridge).doBuild()
def eyeLook_verify(self): _str_func = 'eyeLook_verify' try: log.debug("|{0}| >> ".format(_str_func)+ '-'*80) log.debug("{0}".format(self)) mBlock = self.mBlock mModule = self.mModule mRigNull = self.mRigNull mPuppet = self.mPuppet mHandleFactory = mBlock.asHandleFactory() _eyeLook = eyeLook_get(self) if _eyeLook: log.debug("|{0}| >> Found existing eyeLook...".format(_str_func)) return _eyeLook if mBlock.blockType not in ['eye']: raise ValueError,"blocktype must be eye. Found {0} | {1}".format(mBlock.blockType,mBlock) #Data... ----------------------------------------------------------------------- log.debug("|{0}| >> Get data...".format(_str_func)) #_size = mHandleFactory.get_axisBox_size(mBlock.getMessage('bbHelper')) try: _size = self.v_baseSize _sizeAvg = self.f_sizeAvg except: _size = [mBlock.blockScale * v for v in mBlock.baseSize] _sizeAvg = MATH.average(_size) #Create shape... ----------------------------------------------------------------------- log.debug("|{0}| >> Creating shape...".format(_str_func)) mCrv = cgmMeta.asMeta( CURVES.create_fromName('arrow4Fat', direction = 'z+', size = _sizeAvg , absoluteSize=False),'cgmObject',setClass=True) mCrv.doSnapTo(mBlock.mNode,rotation=False) pos = mBlock.getPositionByAxisDistance('z+', _sizeAvg * 8) mCrv.p_position = 0,pos[1],pos[2] mBlockParent = mBlock.p_blockParent if mBlockParent: mCrv.doStore('cgmName',mBlockParent.cgmName + '_eyeLook') mBlockParent.asHandleFactory().color(mCrv.mNode) else: mCrv.doStore('cgmName','eyeLook') mHandleFactory.color(mCrv.mNode) mCrv.doName() #Register control... ----------------------------------------------------------------------- log.debug("|{0}| >> Registering Control... ".format(_str_func)) d_buffer = MODULECONTROL.register(mCrv, mirrorSide= 'center', mirrorAxis="translateX,rotateY,rotateZ", addSpacePivots = 2) mCrv = d_buffer['mObj'] #Dynparent... ----------------------------------------------------------------------- log.debug("|{0}| >> Dynparent setup.. ".format(_str_func)) ml_dynParents = copy.copy(self.ml_dynParentsAbove) mHead = False for mParent in ml_dynParents: log.debug("|{0}| >> mParent: {1}".format(_str_func,mParent)) if mParent.getMayaAttr('cgmName') == 'head': log.debug("|{0}| >> found head_direct...".format(_str_func)) mHead = mParent break if mHead: ml_dynParents.insert(0,mHead) #if mBlock.attachPoint == 'end': #ml_dynParents.reverse() ml_dynParents.extend(mCrv.msgList_get('spacePivots')) ml_dynParents.extend(copy.copy(self.ml_dynEndParents)) ml_dynParents = LISTS.get_noDuplicates(ml_dynParents) mDynParent = cgmRIGMETA.cgmDynParentGroup(dynChild=mCrv,dynMode=0) for o in ml_dynParents: mDynParent.addDynParent(o) mDynParent.rebuild() #Connections... ----------------------------------------------------------------------- log.debug("|{0}| >> Connections... ".format(_str_func)) mModule.connectChildNode(mCrv,'eyeLook') mPuppet.msgList_append('eyeLook',mCrv,'puppet') if mBlockParent: log.debug("|{0}| >> Adding to blockParent...".format(_str_func)) mModuleParent = mBlockParent.moduleTarget mModuleParent.connectChildNode(mCrv,'eyeLook') if mModuleParent.mClass == 'cgmRigModule': mBlockParentRigNull = mModuleParent.rigNull mBlockParentRigNull.msgList_append('controlsAll',mCrv) mBlockParentRigNull.moduleSet.append(mCrv) mRigNull.faceSet.append(mCrv) mCrv.connectParentNode(mBlockParentRigNull,'rigNull') else: mModuleParent.puppetSet.append(mCrv) mModuleParent.msgList_append('controlsAll',mCrv) mModuleParent.faceSet.append(mCrv) #Connections... ----------------------------------------------------------------------- log.debug("|{0}| >> Heirarchy... ".format(_str_func)) mCrv.masterGroup.p_parent = self.mDeformNull for link in 'masterGroup','dynParentGroup': if mCrv.getMessage(link): mCrv.getMessageAsMeta(link).dagLock(True) mCrv.addAttr('cgmControlDat','','string') mCrv.cgmControlDat = {'tags':['ik']} return mCrv except Exception,error: cgmGEN.cgmExceptCB(Exception,error,msg=vars())
def rig_cleanUp(self): try: _short = self.d_block['shortName'] _str_func = 'rig_cleanUp'.format(_short) log.debug("|{0}| >> ".format(_str_func) + '-' * 80) log.debug("{0}".format(self)) #_start = time.clock() mBlock = self.mBlock mMasterControl = self.d_module['mMasterControl'] mMasterDeformGroup = self.d_module['mMasterDeformGroup'] mMasterNull = self.d_module['mMasterNull'] mPlug_globalScale = self.d_module['mPlug_globalScale'] _spacePivots = mBlock.numSpacePivots ml_controlsAll = [] #DynParents ============================================================================= self.UTILS.get_dynParentTargetsDat(self) log.debug(cgmGEN._str_subLine) mModule = self.mModule mRigNull = self.mRigNull mPuppet = self.mPuppet mHandleFactory = mBlock.asHandleFactory() """ _eyeLook = eyeLook_get(self) if _eyeLook: log.debug("|{0}| >> Found existing eyeLook...".format(_str_func)) return _eyeLook if mBlock.blockType not in ['eye']: raise ValueError,"blocktype must be eye. Found {0} | {1}".format(mBlock.blockType,mBlock) """ #Data... ----------------------------------------------------------------------- log.debug("|{0}| >> Get data...".format(_str_func)) #_size = mHandleFactory.get_axisBox_size(mBlock.getMessage('bbHelper')) try: _size = self.v_baseSize _sizeAvg = self.f_sizeAvg except: _size = [mBlock.blockScale * v for v in mBlock.baseSize] _sizeAvg = MATH.average(_size) #Create shape... ----------------------------------------------------------------------- log.debug("|{0}| >> Creating shape...".format(_str_func)) mCrv = cgmMeta.asMeta(CURVES.create_fromName('arrow4Fat', direction='z+', size=_sizeAvg, absoluteSize=False), 'cgmObject', setClass=True) mCrv.doSnapTo(mBlock.mNode, rotation=False) pos = mBlock.p_position mCrv.p_position = pos mBlockParent = mBlock.p_blockParent if mBlockParent: _parentName = mBlockParent.getMayaAttr( 'cgmName') or mBlockParent.p_nameShort mCrv.doStore('cgmName', _parentName + '_eyeLook') mBlockParent.asHandleFactory().color(mCrv.mNode) else: mCrv.doStore('cgmName', 'eyeLook') mHandleFactory.color(mCrv.mNode) mCrv.doName() #Register control... ----------------------------------------------------------------------- log.debug("|{0}| >> Registering Control... ".format(_str_func)) d_controlSpaces = self.atBuilderUtils('get_controlSpaceSetupDict') d_buffer = MODULECONTROL.register( mCrv, mirrorSide='center', mirrorAxis="translateX,rotateY,rotateZ", **d_controlSpaces) mCrv = d_buffer['mObj'] #Dynparent... ----------------------------------------------------------------------- log.debug("|{0}| >> Dynparent setup.. ".format(_str_func)) ml_dynParents = copy.copy(self.ml_dynParentsAbove) mHead = False for mParent in ml_dynParents: log.debug("|{0}| >> mParent: {1}".format(_str_func, mParent)) if mParent.getMayaAttr('cgmName') == 'head': log.debug("|{0}| >> found head_direct...".format(_str_func)) mHead = mParent break if mHead: ml_dynParents.insert(0, mHead) #if mBlock.attachPoint == 'end': #ml_dynParents.reverse() ml_dynParents.extend(mCrv.msgList_get('spacePivots')) ml_dynParents.extend(copy.copy(self.ml_dynEndParents)) ml_dynParents = LISTS.get_noDuplicates(ml_dynParents) mDynParent = cgmRIGMETA.cgmDynParentGroup(dynChild=mCrv, dynMode=0) for o in ml_dynParents: mDynParent.addDynParent(o) mDynParent.rebuild() #Connections... ----------------------------------------------------------------------- log.debug("|{0}| >> Connections... ".format(_str_func)) mModule.connectChildNode(mCrv, 'eyeLook') mPuppet.msgList_append('eyeLook', mCrv, 'puppet') if mBlockParent: log.debug("|{0}| >> Adding to blockParent...".format(_str_func)) mModuleParent = mBlockParent.moduleTarget mModuleParent.connectChildNode(mCrv, 'eyeLook') if mModuleParent.mClass == 'cgmRigModule': mBlockParentRigNull = mModuleParent.rigNull mBlockParentRigNull.msgList_append('controlsAll', mCrv) mBlockParentRigNull.moduleSet.append(mCrv) #mRigNull.faceSet.append(mCrv) #mCrv.connectParentNode(mBlockParentRigNull,'rigNull') else: mModuleParent.puppetSet.append(mCrv) mModuleParent.msgList_append('controlsAll', mCrv) #mModuleParent.faceSet.append(mCrv) #Connections... ----------------------------------------------------------------------- log.debug("|{0}| >> Heirarchy... ".format(_str_func)) mCrv.masterGroup.p_parent = self.mDeformNull for link in 'masterGroup', 'dynParentGroup': if mCrv.getMessage(link): mCrv.getMessageAsMeta(link).dagLock(True) mCrv.addAttr('cgmControlDat', '', 'string') mCrv.cgmControlDat = {'tags': ['ik']} mBlock.template = True return True try: #moduleParent Stuff ======================================================= if mi_moduleParent: try: for mCtrl in self.ml_controlsAll: mi_parentRigNull.msgList_append('controlsAll', mCtrl) except Exception, error: raise Exception, "!Controls all connect!| %s" % error try: mi_parentRigNull.moduleSet.extend(self.ml_controlsAll) except Exception, error: raise Exception, "!Failed to set module objectSet! | %s" % error except Exception, error: raise Exception, "!Module Parent registration! | %s" % (error)
a.doMatch(0) cgmMeta.cgmNode('nurbsSphere1').dynMatchDriver_fkik.doMatch(0) cgmMeta.cgmNode('nurbsSphere1').dynMatchDriver_fkik.doMatch(1) a.dynDrivers[0].dynMatchAttrs = ['translate', 'rotate', 'scale'] cgmMeta.cgmNode('nurbsSphere1').fkik_dynMatchDriver.doMatch(match=0) cgmMeta.cgmNode('nurbsSphere1').fkik_dynMatchDriver.doMatch(match=1) cgmMeta.cgmNode('nurbsSphere1').fkik_dynMatchDriver.doSnap(0) cgmMeta.cgmNode('nurbsSphere1').fkik_dynMatchDriver.doSnap(1) #>>> Dynamic group #======================================================= parents = mc.ls(sl=True) dParents = [u'parent1', u'parent2', u'parent3'] dynMode = 'follow' a = cgmRigMeta.cgmDynParentGroup(dynChild='dynChild', dynParents=dParents, dynMode=dynMode) a.rebuild() #Hips dynParents = [u'cog_anim', u'worldCenter_loc'] #hips dynGroup = 'hips_anim_grp' dynChild = 'dynChild' a = cgmRigMeta.cgmDynParentGroup(dynChild=dynChild, dynParents=dynParents, dynGroup=dynGroup, dynMode=dynMode) #Shoulders c1 = r9Meta.MetaClass('shoulders_ik_anim') c1.dynParentGroup c1.dynParentGroup.dynChild
class fncWrap(cgmGeneral.cgmFuncCls): def __init__(self,*args,**kws): """ """ super(fncWrap, self).__init__(*args, **kws) if args:self.mi_control = cgmMeta.validateObjArg(args[0],cgmMeta.cgmObject,noneValid=False) try:self._str_funcName = "registerControl(%s)"%self.mi_control.p_nameShort except:self._str_funcName = "registerControl" self._l_ARGS_KWS_DEFAULTS = [{'kw':'controlObject', "default":None, 'help':"The object to use as a control", "argType":"mObject"}, {'kw':'copyTransform', "default":None, 'help':"Object to copy the transform of for our control object", "argType":"mObject"}, {'kw':'copyPivot', "default":None, 'help':"Object to copy the pivot of for our control object", "argType":"mObject"}, {'kw':'shapeParentTo',"default":None,'help':"Object to shape parent our control curve to to use that transform","argType":"mObject"}, {'kw':'useShape',"default":None,'help':"Object to use the curve shape of for our control","argType":"mObject"}, {'kw':'setRotateOrder',"default":None,'help':"Argument for a rotate order to set","argType":"rotateOrder"}, {'kw':'autoLockNHide',"default":None,'help':"Try to set lock and hide","argType":"bool"}, {'kw':'mirrorAxis',"default":None,'help':"Mirror axis to set - using red9's setup terms","argType":"string"}, {'kw':'mirrorSide',"default":None,'help':"Mirror side - using red9's setup terms","argType":"string/int"}, {'kw':'makeMirrorable',"default":True,'help':"Setup for mirrorability (using red9) -- implied by other mirror args","argType":"bool"}, {'kw':'addDynParentGroup',"default":False,'help':"Add a dynParent group setup"}, {'kw':'addExtraGroups',"default":False,'help':"Number of nested extra groups desired","argType":"int"}, {'kw':'addConstraintGroup',"default":False,'help':"If a group just above the control is desired for consraining","argType":"bool"}, {'kw':'freezeAll',"default":False,'help':"Freeze all transforms on the control object","argType":"bool"}, {'kw':'addSpacePivots',"default":False,'help':"Number of space pivots to generate and connect","argType":"int"}, {'kw':'controlType',"default":None,'help':"Tag for cgmType","argType":"string"}, {'kw':'typeModifier', "default":None, 'help':"Tag for cgmTypeModifier for naming", "argType":"string"}, {'kw':'addForwardBack',"default":None,'help':"Forward Back driver setup. Looking for an attribute to drive","argType":"mAttr"}, {'kw':'addMirrorAttributeBridges',"default":None,'help':"Attribute to drive the same channel on mirrored objects. Looking for an nested list [[attrName,attr],...]","argType":"nested list"}, {'kw':'aim',"default":None,'help':"aim axis to use","argType":"string/int"}, {'kw':'up',"default":None,'help':"up axis to use","argType":"string/int"}, {'kw':'out',"default":None,'help':"out axis to use","argType":"string/int"}, {'kw':'makeAimable',"default":False,'help':"Make object aimable -- implied by aim/up/out","argType":"mObject"},] self.__dataBind__(*args,**kws) #================================================================= self.l_funcSteps = [{'step':'validate','call':self._validate}, {'step':'Copy Transform','call':self._copyTransform}, {'step':'Shape Parent','call':self._shapeParent}, {'step':'Copy Pivot','call':self._copyPivot}, {'step':'Naming','call':self._naming}, {'step':'Aim Setup','call':self._aimSetup}, {'step':'Rotate Order','call':self._rotateOrder}, {'step':'Initial Freeze','call':self._initialFreeze}, {'step':'Groups Setup','call':self._groupsSetup}, {'step':'Space Pivot','call':self._spacePivots}, {'step':'Mirror Setup','call':self._mirrorSetup}, {'step':'Freeze','call':self._freeze}, {'step':'Mirror Attribute Bridges','call':self._mirrorAttributeBridges_}, {'step':'lock N Hide','call':self._lockNHide}, {'step':'Return build','call':self._returnBuild}] def _validate(self): assert type(self.d_kws['addExtraGroups']) in [int,bool] assert type(self.d_kws['addSpacePivots']) in [int,bool] i_obj = self.mi_control self.mi_control = cgmMeta.asMeta(i_obj,'cgmControl', setClass=True) self.str_mirrorAxis = VALID.stringArg(self.d_kws['mirrorAxis'],calledFrom = self._str_funcCombined) self.str_mirrorSide = VALID.stringArg(self.d_kws['mirrorSide'],calledFrom = self._str_funcCombined) self.b_makeMirrorable = VALID.boolArg(self.d_kws['makeMirrorable'],calledFrom = self._str_funcCombined) self._addMirrorAttributeBridges = self.d_kws.get('addMirrorAttributeBridges') or False if self._addMirrorAttributeBridges : if type(self._addMirrorAttributeBridges ) not in [list,tuple]:raise StandardError,"[Bad addMirrorAttributeBridge arg]{arg: %s}"%self._addMirrorAttributeBridge for i,l in enumerate(self._addMirrorAttributeBridges): if type(l) not in [list,tuple]:raise StandardError,"[Bad addMirrorAttributeBridge arg: %s]{arg: %s}"%(i,l) # Running lists ------------------------------------------------------------------------------------------ self.ml_groups = []#Holder for groups self.ml_constraintGroups = [] self.ml_spacePivots = [] def _copyTransform(self): copyTransform = self.d_kws['copyTransform'] if copyTransform is not None: if issubclass(type(copyTransform),cgmMeta.cgmNode): i_target = copyTransform elif mc.objExists(copyTransform): i_target = cgmMeta.cgmObject(copyTransform) else: raise StandardError,"Failed to find suitable copyTransform object: '%s"%copyTransform #Need to move this to default cgmNode stuff mBuffer = self.mi_control i_newTransform = cgmMeta.cgmObject( rigging.groupMeObject(i_target.mNode,False) ) for a in mc.listAttr(self.mi_control.mNode, userDefined = True): attributes.doCopyAttr(self.mi_control.mNode,a,i_newTransform.mNode) curves.parentShapeInPlace(i_newTransform.mNode,self.mi_control.mNode)#Parent shape i_newTransform.parent = self.mi_control.parent#Copy parent self.mi_control = cgmMeta.asMeta(i_newTransform,'cgmControl', setClass=True) mc.delete(mBuffer.mNode) def _shapeParent(self): shapeParentTo = self.d_kws['shapeParentTo'] if shapeParentTo: try: i_target = cgmMeta.validateObjArg(shapeParentTo,cgmMeta.cgmObject) curves.parentShapeInPlace(i_target.mNode,self.mi_control.mNode) i_target = cgmMeta.asMeta(i_target,'cgmControl',setClass = True) #self.mi_control.delete() self.mi_control = i_target#replace the control with the joint except Exception,error:raise StandardError,"shapeParentTo | %s"%error useShape = self.d_kws['useShape'] if useShape is not None: try: i_shape = cgmMeta.validateObjArg(useShape,cgmMeta.cgmObject,mayaType='nurbsCurve') curves.parentShapeInPlace(self.mi_control.mNode,i_shape.mNode) except Exception,error:raise StandardError,"useShape | %s"%error def _copyPivot(self): copyPivot = self.d_kws['copyPivot'] if copyPivot is not None: try: if issubclass(type(copyPivot),cgmMeta.cgmNode): i_target = copyPivot elif mc.objExists(copyPivot): i_target = cgmMeta.cgmObject(copyPivot) else: raise StandardError,"Failed to find suitable copyTransform object: '%s"%copyPivot #Need to move this to default cgmNode stuff self.mi_control.doCopyPivot(i_target.mNode) except Exception,error:raise StandardError,"copyPivot | %s"%error def _naming(self): typeModifier = self.d_kws['typeModifier'] self.mi_control.addAttr('cgmType','controlAnim',lock=True) if typeModifier is not None: self.mi_control.addAttr('cgmTypeModifier',str(typeModifier),lock=True) self.mi_control.doName()#self.mi_control.doName(nameShapes=True) def _aimSetup(self): aim = self.d_kws['aim'] up = self.d_kws['up'] makeAimable = self.d_kws['makeAimable'] if aim is not None or up is not None or makeAimable: self.mi_control._verifyAimable() def _rotateOrder(self): controlType = self.d_kws['controlType'] setRotateOrder = self.d_kws['setRotateOrder'] _rotateOrder = False if setRotateOrder is not None: _rotateOrder = setRotateOrder elif controlType in __d_rotateOrderDefaults__.keys(): _rotateOrder = __d_rotateOrderDefaults__[controlType] elif self.mi_control.getAttr('cgmName') in __d_rotateOrderDefaults__.keys(): _rotateOrder = __d_rotateOrderDefaults__[self.mi_control.getAttr('cgmName')] else: log.debug("%s rotateOrder not set on: '%s'"%(self._str_reportStart,self.mi_control.p_nameShort)) #Set it --------------------------------------------------------------- if _rotateOrder: _rotateOrder = dictionary.validateRotateOrderString(_rotateOrder) mc.xform(self.mi_control.mNode, rotateOrder = _rotateOrder) def _initialFreeze(self): freezeAll = self.d_kws['freezeAll'] if freezeAll: mc.makeIdentity(self.mi_control.mNode, apply=True,t=1,r=1,s=1,n=0) def _groupsSetup(self): addDynParentGroup = self.d_kws['addDynParentGroup'] addSpacePivots = self.d_kws['addSpacePivots'] shapeParentTo = self.d_kws['shapeParentTo'] addExtraGroups = self.d_kws['addExtraGroups'] addConstraintGroup = self.d_kws['addConstraintGroup'] try: if addDynParentGroup or addSpacePivots or self.mi_control.getAttr('cgmName') == 'cog' or self._addMirrorAttributeBridges: self.mi_control.addAttr('________________',attrType = 'int',keyable = False,hidden = False,lock=True) except Exception,error: raise StandardError,"spacer | %s"%(error) #==================================================== if not shapeParentTo: #First our master group: try: i_masterGroup = (cgmMeta.asMeta(self.mi_control.doGroup(True), 'cgmObject', setClass=True)) i_masterGroup.addAttr('cgmTypeModifier','master',lock=True) i_masterGroup.doName() self.mi_control.connectChildNode(i_masterGroup,'masterGroup','groupChild') except Exception,error:raise StandardError,"masterGroup | %s"%(error) if addDynParentGroup: try: i_dynGroup = (cgmMeta.cgmObject(self.mi_control.doGroup(True))) i_dynGroup = cgmRigMeta.cgmDynParentGroup(dynChild=self.mi_control,dynGroup=i_dynGroup) i_dynGroup.doName() i_zeroGroup = (cgmMeta.cgmObject(self.mi_control.doGroup(True))) i_zeroGroup.addAttr('cgmTypeModifier','zero',lock=True) i_zeroGroup.doName() self.mi_control.connectChildNode(i_zeroGroup,'zeroGroup','groupChild') except Exception,error:raise StandardError,"dynGroup | %s"%(error) if addExtraGroups: try: for i in range(addExtraGroups): i_group = (cgmMeta.asMeta(self.mi_control.doGroup(True),'cgmObject',setClass=True)) if type(addExtraGroups)==int and addExtraGroups>1:#Add iterator if necessary i_group.addAttr('cgmIterator',str(i+1),lock=True) i_group.doName() self.ml_groups.append(i_group) self.mi_control.msgList_connect("extraGroups",self.ml_groups,'groupChild') except Exception,error:raise StandardError,"extra Groups | %s"%(error) if addConstraintGroup:#ConstraintGroups try: i_constraintGroup = (cgmMeta.asMeta(self.mi_control.doGroup(True),'cgmObject',setClass=True)) i_constraintGroup.addAttr('cgmTypeModifier','constraint',lock=True) i_constraintGroup.doName() self.ml_constraintGroups.append(i_constraintGroup) self.mi_control.connectChildNode(i_constraintGroup,'constraintGroup','groupChild') except Exception,error:raise StandardError,"constraintGroup | %s"%(error)
setClass=True)) i_masterGroup.addAttr('cgmTypeModifier', 'master', lock=True) i_masterGroup.doName() self.mi_control.connectChildNode(i_masterGroup, 'masterGroup', 'groupChild') except Exception, error: raise StandardError, "masterGroup | %s" % (error) if addDynParentGroup: try: i_dynGroup = (cgmMeta.cgmObject( self.mi_control.doGroup(True))) i_dynGroup = cgmRigMeta.cgmDynParentGroup( dynChild=self.mi_control, dynGroup=i_dynGroup) i_dynGroup.doName() i_zeroGroup = (cgmMeta.cgmObject( self.mi_control.doGroup(True))) i_zeroGroup.addAttr('cgmTypeModifier', 'zero', lock=True) i_zeroGroup.doName() self.mi_control.connectChildNode( i_zeroGroup, 'zeroGroup', 'groupChild') except Exception, error: raise StandardError, "dynGroup | %s" % (error) if addExtraGroups: try: