'rootGroup': 'Arm_l_grp', 'baseName': 'l_arm' } _dshoulderTwist_r = { 'blendJoints': [u'r_shoulder_blend', u'r_elbow_blend', u'r_wrist_blend'], 'settings': 'r_arm_root', 'segmentHandle': 'r_elbow_direct', 'rootGroup': 'Arm_r_grp', 'baseName': 'r_arm' } SPECTRA.shoulderTwist(**_dshoulderTwist_l) import cgm.core.classes.NodeFactory as NODEF NODEF.createSingleBlendNetwork( 'l_arm_root.stableShoulder', 'l_shoulder_rig_orientConstraint1.l_shoulder_rig_stable_aimW0', 'l_shoulder_rig_orientConstraint1.l_shoulder_rig_follow_aimW1', maxValue=1, minValue=0) #...Legs ----------------------------------------------------------------------- d_l_front = { 'fkJoints': [u'l_front_hip_fk', u'l_front_knee_fk', u'l_front_ankle_fk'], 'ikJoints': [u'l_front_hip_ik', u'l_front_knee_ik', u'l_front_ankle_ik'], 'blendJoints': [u'l_front_hip_blend', u'l_front_knee_blend', u'l_front_ankle_blend'], 'settings': 'l_front_leg_root', 'orientation': 'xyz', 'fkGroup': 'l_front_leg_fk_grp',
def ik_rp(self, mStart, mEnd, ml_ikFrame=None, mIKControl=None, mIKBaseControl=None, mIKHandleDriver=None, mRoot=None, mIKGroup=None, mIKControlEnd=None, ml_ikFullChain=None): try: _str_func = "ik_rp" log.debug("|{0}| >> {1}...".format(_str_func, _str_func) + '-' * 60) mRigNull = self.mRigNull mBlock = self.mBlock if not ml_ikFrame: ml_ikFrame = self.ml_handleTargetsCulled if not mIKControl: raise ValueError, "Must have mIKControl" if not mIKHandleDriver: raise ValueError, "Must have mIKHandleDriver" if not mRoot: raise ValueError, "Must have mRoot" log.debug("|{0}| >> rp setup...".format(_str_func)) mIKMid = mRigNull.controlIKMid str_ikEnd = mBlock.getEnumValueString('ikEnd') #Measture ====================================================== log.debug("|{0}| >> measure... ".format(_str_func) + '-' * 30) res_ikScale = self.UTILS.get_blockScale( self, '{0}_ikMeasure'.format(self.d_module['partName'], ), ml_ikFrame) mPlug_masterScale = res_ikScale[0] mMasterCurve = res_ikScale[1] mMasterCurve.p_parent = mRoot self.fnc_connect_toRigGutsVis(mMasterCurve) mMasterCurve.dagLock(True) #Unparent the children from the end while we set stuff up... log.debug("|{0}| >> end unparent ...".format(_str_func) + '-' * 30) ml_end_children = mEnd.getChildren(asMeta=True) if ml_end_children: for mChild in ml_end_children: mChild.parent = False #Build the IK --------------------------------------------------------------------- reload(IK) """ if mIKControlEnd and str_ikEnd in ['tipCombo']: mMainIKControl = mIKControlEnd else: mMainIKControl = mIKControl """ _d_ik = { 'globalScaleAttr': mPlug_masterScale. p_combinedName, #mPlug_globalScale.p_combinedName, 'stretch': 'translate', 'lockMid': True, 'rpHandle': mIKMid.mNode, 'nameSuffix': 'ik', 'baseName': '{0}_ikRP'.format(self.d_module['partName']), 'controlObject': mIKControl.mNode, 'moduleInstance': self.mModule.mNode } d_ikReturn = IK.handle(mStart.mNode, mEnd.mNode, **_d_ik) mIKHandle = d_ikReturn['mHandle'] ml_distHandlesNF = d_ikReturn['ml_distHandles'] mRPHandleNF = d_ikReturn['mRPHandle'] #>>>Parent IK handles ----------------------------------------------------------------- log.debug("|{0}| >> parent IK stuff ...".format(_str_func) + '-' * 30) mIKHandle.parent = mIKHandleDriver.mNode #handle to control for mObj in ml_distHandlesNF[:-1]: mObj.parent = mRoot ml_distHandlesNF[-1].parent = mIKHandleDriver.mNode #handle to control ml_distHandlesNF[1].parent = mIKMid ml_distHandlesNF[1].t = 0, 0, 0 ml_distHandlesNF[1].r = 0, 0, 0 if mIKBaseControl: ml_distHandlesNF[0].parent = mIKBaseControl #>>> Fix our ik_handle twist at the end of all of the parenting IK.handle_fixTwist(mIKHandle, self.d_orientation['str'][0]) #Fix the twist if mIKControlEnd: mIKEndDriver = mIKControlEnd else: mIKEndDriver = mIKControl if ml_end_children: for mChild in ml_end_children: mChild.parent = mEnd #mc.scaleConstraint([mIKControl.mNode], # ml_ikFrame[self.int_handleEndIdx].mNode, # maintainOffset = True) #if mIKBaseControl: #ml_ikFrame[0].parent = mRigNull.controlIKBase #if mIKBaseControl: #mc.pointConstraint(mIKBaseControl.mNode, ml_ikFrame[0].mNode,maintainOffset=True) #Make a spin group =========================================================== log.debug("|{0}| >> spin group ...".format(_str_func) + '-' * 30) mSpinGroup = mStart.doGroup(False, False, asMeta=True) mSpinGroup.doCopyNameTagsFromObject(self.mModule.mNode, ignore=['cgmName', 'cgmType']) mSpinGroup.addAttr('cgmName', '{0}NoFlipSpin'.format(self.d_module['partName'])) mSpinGroup.doName() ATTR.set(mSpinGroup.mNode, 'rotateOrder', self.d_orientation['str']) mSpinGroup.parent = mIKGroup mSpinGroup.doGroup(True, True, typeModifier='zero') mSpinGroupAdd = mSpinGroup.doDuplicate() mSpinGroupAdd.doStore('cgmTypeModifier', 'addSpin') mSpinGroupAdd.doName() mSpinGroupAdd.p_parent = mSpinGroup if mIKBaseControl: mc.pointConstraint(mIKBaseControl.mNode, mSpinGroup.mNode, maintainOffset=True) #Setup arg #mPlug_spin = cgmMeta.cgmAttr(mIKControl,'spin',attrType='float',keyable=True, defaultValue = 0, hidden = False) #mPlug_spin.doConnectOut("%s.r%s"%(mSpinGroup.mNode,_jointOrientation[0])) mSpinTarget = mIKControl if mBlock.getMayaAttr('ikRPAim'): mc.aimConstraint(mSpinTarget.mNode, mSpinGroup.mNode, maintainOffset=False, aimVector=[0, 0, 1], upVector=[0, 1, 0], worldUpType='none') else: mc.aimConstraint(mSpinTarget.mNode, mSpinGroup.mNode, maintainOffset=False, aimVector=[0, 0, 1], upVector=[0, 1, 0], worldUpObject=mSpinTarget.mNode, worldUpType='objectrotation', worldUpVector=self.v_twistUp) mPlug_spinMid = cgmMeta.cgmAttr(mSpinTarget, 'spinMid', attrType='float', defaultValue=0, keyable=True, lock=False, hidden=False) _direction = self.d_module.get('direction') or 'center' if _direction.lower() == 'right': str_arg = "{0}.r{1} = -{2}".format( mSpinGroupAdd.mNode, self.d_orientation['str'][0].lower(), mPlug_spinMid.p_combinedShortName) log.debug("|{0}| >> Right knee spin: {1}".format( _str_func, str_arg)) NODEFACTORY.argsToNodes(str_arg).doBuild() else: mPlug_spinMid.doConnectOut("{0}.r{1}".format( mSpinGroupAdd.mNode, self.d_orientation['str'][0])) mSpinGroup.dagLock(True) mSpinGroupAdd.dagLock(True) #>>> mBallRotationControl ========================================================== mIKBallRotationControl = mRigNull.getMessageAsMeta( 'controlBallRotation') if mIKBallRotationControl: # and str_ikEnd not in ['tipCombo']: log.debug("|{0}| >> mIKBallRotationControl...".format(_str_func) + '-' * 30) mBallOrientGroup = cgmMeta.validateObjArg( mIKBallRotationControl.doGroup(True, False, asMeta=True, typeModifier='orient'), 'cgmObject', setClass=True) ATTR.set(mBallOrientGroup.mNode, 'rotateOrder', self.d_orientation['str']) mLocBase = mIKBallRotationControl.doCreateAt() mLocAim = mIKBallRotationControl.doCreateAt() mLocAim.doStore('cgmTypeModifier', 'extendedIK') mLocBase = mIKBallRotationControl.doCreateAt() mLocBase.doName() mLocAim.doName() mLocAim.p_parent = ml_ikFullChain[-1] mLocBase.p_parent = mIKBallRotationControl.masterGroup const = mc.orientConstraint([mLocAim.mNode, mLocBase.mNode], mBallOrientGroup.mNode, maintainOffset=True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork( [mIKControl.mNode, 'extendIK'], [mIKControl.mNode, 'resRootFollow'], [mIKControl.mNode, 'resFullFollow'], keyable=True) targetWeights = mc.orientConstraint(const, q=True, weightAliasList=True, maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut( '%s.%s' % (const, targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut( '%s.%s' % (const, targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mBallOrientGroup.dagLock(True) mLocAim.dagLock(True) mLocBase.dagLock(True) mIKBallRotationControl.p_parent = mBallOrientGroup #Joint constraint ------------------------- mIKBallRotationControl.masterGroup.p_parent = mPivotResultDriver mc.orientConstraint([mIKBallRotationControl.mNode], ml_ikFrame[self.int_handleEndIdx].mNode, maintainOffset=True) mc.parentConstraint([mPivotResultDriver.mNode], ml_ikFrame[self.int_handleEndIdx + 1].mNode, maintainOffset=True) ATTR.set_default(mIKControl.mNode, 'extendIK', 1.0) mIKControl.extendIK = 0.0 elif str_ikEnd == 'bank': mc.orientConstraint([mPivotResultDriver.mNode], ml_ikFrame[self.int_handleEndIdx].mNode, maintainOffset=True) elif str_ikEnd == 'pad': mc.orientConstraint([mPivotResultDriver.mNode], ml_ikFrame[self.int_handleEndIdx].mNode, maintainOffset=True) else: mc.orientConstraint([mIKEndDriver.mNode], ml_ikFrame[self.int_handleEndIdx].mNode, maintainOffset=True) #Mid IK driver ----------------------------------------------------------------------- log.debug("|{0}| >> mid Ik driver...".format(_str_func) + '-' * 30) log.debug("|{0}| >> mid IK driver.".format(_str_func)) mMidControlDriver = mIKMid.doCreateAt() mMidControlDriver.addAttr( 'cgmName', '{0}_midIK'.format(self.d_module['partName'])) mMidControlDriver.addAttr('cgmType', 'driver') mMidControlDriver.doName() mMidControlDriver.addAttr('cgmAlias', 'midDriver') if mIKBaseControl: l_midDrivers = [mIKBaseControl.mNode] else: l_midDrivers = [mRoot.mNode] if str_ikEnd in ['tipCombo'] and mIKControlEnd: log.debug("|{0}| >> mIKControlEnd + tipCombo...".format(_str_func)) l_midDrivers.append(mIKControl.mNode) else: l_midDrivers.append(mIKHandleDriver.mNode) mc.pointConstraint(l_midDrivers, mMidControlDriver.mNode) mMidControlDriver.parent = mSpinGroupAdd #mIKGroup mIKMid.masterGroup.parent = mMidControlDriver mMidControlDriver.dagLock(True) #Mid IK trace log.debug("|{0}| >> midIK track Crv".format(_str_func, mIKMid)) trackcrv, clusters = CORERIG.create_at( [ mIKMid.mNode, ml_ikFrame[MATH.get_midIndex( len(ml_ikFrame))].mNode ], #ml_handleJoints[1]], 'linearTrack', baseName='{0}_midTrack'.format(self.d_module['partName'])) mTrackCrv = cgmMeta.asMeta(trackcrv) mTrackCrv.p_parent = self.mModule mHandleFactory = mBlock.asHandleFactory() mHandleFactory.color(mTrackCrv.mNode, controlType='sub') for s in mTrackCrv.getShapes(asMeta=True): s.overrideEnabled = 1 s.overrideDisplayType = 2 mTrackCrv.doConnectIn('visibility', "{0}.v".format(mIKGroup.mNode)) #Full IK chain ----------------------------------------------------------------------- if ml_ikFullChain: log.debug("|{0}| >> Full IK Chain...".format(_str_func)) _d_ik = { 'globalScaleAttr': mPlug_masterScale. p_combinedName, #mPlug_globalScale.p_combinedName, 'stretch': 'translate', 'lockMid': False, 'rpHandle': mIKMid.mNode, 'baseName': '{0}_ikFullChain'.format(self.d_module['partName']), 'nameSuffix': 'ikFull', 'controlObject': mIKControl.mNode, 'moduleInstance': self.mModule.mNode } d_ikReturn = IK.handle(ml_ikFullChain[0], ml_ikFullChain[-1], **_d_ik) mIKHandle = d_ikReturn['mHandle'] ml_distHandlesNF = d_ikReturn['ml_distHandles'] mRPHandleNF = d_ikReturn['mRPHandle'] mIKHandle.parent = mIKControl.mNode #handle to control for mObj in ml_distHandlesNF[:-1]: mObj.parent = mRoot ml_distHandlesNF[-1].parent = mIKControl.mNode #handle to control #ml_distHandlesNF[1].parent = mIKMid #ml_distHandlesNF[1].t = 0,0,0 #ml_distHandlesNF[1].r = 0,0,0 #>>> Fix our ik_handle twist at the end of all of the parenting IK.handle_fixTwist(mIKHandle, self.d_orientation['str'][0]) #Fix the twist #mIKControl.masterGroup.p_parent = ml_ikFullChain[-2] ######mc.parentConstraint([mIKControl.mNode], ml_ikFrame[-1].mNode, maintainOffset = True) if mIKBaseControl: ml_ikFrame[0].parent = mIKBaseControl #if mIKBaseControl: #mc.pointConstraint(mIKBaseControl.mNode, ml_ikFrame[0].mNode,maintainOffset=True) except Exception, err: cgmGEN.cgmExceptCB(Exception, err, localDat=vars())
def segment_handles(self, ml_handles=None, ml_handleParents=None, mIKBaseControl=None, mRoot=None, str_ikBase=None, upMode='asdf'): try: _str_func = 'segment_handles' log_start(_str_func) mBlock = self.mBlock mRigNull = self.mRigNull _offset = self.v_offset _jointOrientation = self.d_orientation['str'] if not ml_handles: raise ValueError, "{0} | ml_handles required".format(_str_func) if not ml_handleParents: raise ValueError, "{0} | ml_handleParents required".format( _str_func) ml_ribbonIkHandles = mRigNull.msgList_get('ribbonIKDrivers') if not ml_ribbonIkHandles: ml_ribbonIkHandles = ml_handleParents #raise ValueError,"No ribbon IKDriversFound" if str_ikBase == None: str_ikBase = mBlock.getEnumValueString('ikBase') _aim = self.d_orientation['vectorAim'] _aimNeg = self.d_orientation['vectorAimNeg'] _up = self.d_orientation['vectorUp'] _out = self.d_orientation['vectorOut'] if str_ikBase == 'hips': log.debug("|{0}| >> hips setup...".format(_str_func)) if len(ml_handles) == 1: mHipHandle = ml_handles[0] RIGCONSTRAINT.build_aimSequence( ml_handles, ml_ribbonIkHandles, [mIKBaseControl], #ml_handleParents, mode='singleBlend', upMode='objectRotation') else: if str_ikBase == 'hips': log.debug("|{0}| >> hips handles...".format(_str_func)) ml_handles[0].masterGroup.p_parent = mIKBaseControl mHipHandle = ml_handles[1] mHipHandle.masterGroup.p_parent = mRoot mc.pointConstraint(mIKBaseControl.mNode, mHipHandle.masterGroup.mNode, maintainOffset=True) RIGCONSTRAINT.build_aimSequence( ml_handles[1], ml_ribbonIkHandles, [mIKBaseControl], #ml_handleParents, mode='singleBlend', upParent=self.d_orientation['vectorOut'], upMode='objectRotation') """ RIGCONSTRAINT.build_aimSequence(ml_handles[-1], ml_ribbonIkHandles, #[mRigNull.controlIK.mNode],#ml_handleParents, mode = 'singleBlend', upMode = 'objectRotation')""" for i, mHandle in enumerate(ml_handles): if mHandle in ml_handles[:2]: # + [ml_handles[-1]]: continue mHandle.masterGroup.parent = ml_handleParents[i] s_rootTarget = False s_targetForward = False s_targetBack = False mMasterGroup = mHandle.masterGroup b_first = False if mHandle == ml_handles[0]: log.debug("|{0}| >> First handle: {1}".format( _str_func, mHandle)) if len(ml_handles) <= 2: s_targetForward = ml_handleParents[-1].mNode else: s_targetForward = ml_handles[i + 1].getMessage( 'masterGroup')[0] s_rootTarget = mRoot.mNode b_first = True elif mHandle == ml_handles[-1]: log.debug("|{0}| >> Last handle: {1}".format( _str_func, mHandle)) s_rootTarget = ml_handleParents[i].mNode s_targetBack = ml_handles[i - 1].getMessage( 'masterGroup')[0] else: log.debug("|{0}| >> Reg handle: {1}".format( _str_func, mHandle)) s_targetForward = ml_handles[i + 1].getMessage( 'masterGroup')[0] s_targetBack = ml_handles[i - 1].getMessage( 'masterGroup')[0] #Decompose matrix for parent... if upMode == 'matrix': mUpDecomp = cgmMeta.cgmNode(nodeType='decomposeMatrix') mUpDecomp.doStore('cgmName', ml_handleParents[i]) mUpDecomp.addAttr('cgmType', 'aimMatrix', attrType='string', lock=True) mUpDecomp.doName() ATTR.connect( "%s.worldMatrix" % (ml_handleParents[i].mNode), "%s.%s" % (mUpDecomp.mNode, 'inputMatrix')) _d_up = { 'aimVector': _aim, 'upVector': _out, 'worldUpObject': ml_handleParents[i].mNode, 'worldUpType': 'vector', 'worldUpVector': [0, 0, 0] } else: _d_up = { 'aimVector': _aim, 'upVector': _out, 'worldUpObject': ml_handleParents[i].mNode, 'worldUpType': 'objectRotation', 'worldUpVector': [1, 0, 0] } if s_targetForward: mAimForward = mHandle.doCreateAt() mAimForward.parent = mMasterGroup mAimForward.doStore('cgmTypeModifier', 'forward') mAimForward.doStore('cgmType', 'aimer') mAimForward.doName() _const = mc.aimConstraint(s_targetForward, mAimForward.mNode, maintainOffset=True, **_d_up) s_targetForward = mAimForward.mNode if upMode == 'matrix': ATTR.connect( "%s.%s" % (mUpDecomp.mNode, "outputRotate"), "%s.%s" % (_const[0], "upVector")) else: s_targetForward = ml_handleParents[i].mNode if s_targetBack: mAimBack = mHandle.doCreateAt() mAimBack.parent = mMasterGroup mAimBack.doStore('cgmTypeModifier', 'back') mAimBack.doStore('cgmType', 'aimer') mAimBack.doName() _d_up['aimVector'] = _aimNeg _const = mc.aimConstraint(s_targetBack, mAimBack.mNode, maintainOffset=True, **_d_up) s_targetBack = mAimBack.mNode if upMode == 'matrix': ATTR.connect( "%s.%s" % (mUpDecomp.mNode, "outputRotate"), "%s.%s" % (_const[0], "upVector")) else: s_targetBack = s_rootTarget #ml_handleParents[i].mNode #pprint.pprint([s_targetForward,s_targetBack]) mAimGroup = mHandle.doGroup(True, asMeta=True, typeModifier='aim') mHandle.parent = False if b_first: const = mc.orientConstraint( [s_targetBack, s_targetForward], mAimGroup.mNode, maintainOffset=True)[0] else: const = mc.orientConstraint( [s_targetForward, s_targetBack], mAimGroup.mNode, maintainOffset=True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork( [mHandle.mNode, 'followRoot'], [mHandle.mNode, 'resultRootFollow'], [mHandle.mNode, 'resultAimFollow'], keyable=True) targetWeights = mc.orientConstraint(const, q=True, weightAliasList=True, maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut( '%s.%s' % (const, targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut( '%s.%s' % (const, targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mHandle.parent = mAimGroup #...parent back else: log.debug("|{0}| >> reg handles...".format(_str_func)) for i, mHandle in enumerate(ml_handles): mHandle.masterGroup.parent = ml_handleParents[i] s_rootTarget = False s_targetForward = False s_targetBack = False mMasterGroup = mHandle.masterGroup b_first = False if mHandle == ml_handles[0]: log.debug("|{0}| >> First handle: {1}".format( _str_func, mHandle)) if len(ml_handles) <= 2: s_targetForward = ml_handleParents[-1].mNode else: s_targetForward = ml_handles[i + 1].getMessage( 'masterGroup')[0] s_rootTarget = mRoot.mNode b_first = True elif mHandle == ml_handles[-1]: log.debug("|{0}| >> Last handle: {1}".format( _str_func, mHandle)) s_rootTarget = ml_handleParents[i].mNode s_targetBack = ml_handles[i - 1].getMessage( 'masterGroup')[0] else: log.debug("|{0}| >> Reg handle: {1}".format( _str_func, mHandle)) s_targetForward = ml_handles[i + 1].getMessage( 'masterGroup')[0] s_targetBack = ml_handles[i - 1].getMessage( 'masterGroup')[0] #Decompose matrix for parent... mUpDecomp = cgmMeta.cgmNode(nodeType='decomposeMatrix') mUpDecomp.doStore('cgmName', ml_handleParents[i]) mUpDecomp.addAttr('cgmType', 'aimMatrix', attrType='string', lock=True) mUpDecomp.doName() ATTR.connect( "%s.worldMatrix" % (ml_handleParents[i].mNode), "%s.%s" % (mUpDecomp.mNode, 'inputMatrix')) if s_targetForward: mAimForward = mHandle.doCreateAt() mAimForward.parent = mMasterGroup mAimForward.doStore('cgmTypeModifier', 'forward') mAimForward.doStore('cgmType', 'aimer') mAimForward.doName() _const = mc.aimConstraint( s_targetForward, mAimForward.mNode, maintainOffset=True, #skip = 'z', aimVector=_aim, upVector=_out, worldUpObject=ml_handleParents[i].mNode, worldUpType='vector', worldUpVector=[0, 0, 0]) s_targetForward = mAimForward.mNode ATTR.connect( "%s.%s" % (mUpDecomp.mNode, "outputRotate"), "%s.%s" % (_const[0], "upVector")) else: s_targetForward = ml_handleParents[i].mNode if s_targetBack: mAimBack = mHandle.doCreateAt() mAimBack.parent = mMasterGroup mAimBack.doStore('cgmTypeModifier', 'back') mAimBack.doStore('cgmType', 'aimer') mAimBack.doName() _const = mc.aimConstraint( s_targetBack, mAimBack.mNode, maintainOffset=True, #skip = 'z', aimVector=_aimNeg, upVector=_out, worldUpObject=ml_handleParents[i].mNode, worldUpType='vector', worldUpVector=[0, 0, 0]) s_targetBack = mAimBack.mNode ATTR.connect( "%s.%s" % (mUpDecomp.mNode, "outputRotate"), "%s.%s" % (_const[0], "upVector")) else: s_targetBack = s_rootTarget #ml_handleParents[i].mNode #pprint.pprint([s_targetForward,s_targetBack]) mAimGroup = mHandle.doGroup(True, asMeta=True, typeModifier='aim') mHandle.parent = False if b_first: const = mc.orientConstraint( [s_targetBack, s_targetForward], mAimGroup.mNode, maintainOffset=True)[0] else: const = mc.orientConstraint( [s_targetForward, s_targetBack], mAimGroup.mNode, maintainOffset=True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork( [mHandle.mNode, 'followRoot'], [mHandle.mNode, 'resultRootFollow'], [mHandle.mNode, 'resultAimFollow'], keyable=True) targetWeights = mc.orientConstraint(const, q=True, weightAliasList=True, maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut( '%s.%s' % (const, targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut( '%s.%s' % (const, targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mHandle.parent = mAimGroup #...parent back for mHandle in ml_handles: if mHandle in [ml_handles[0], ml_handles[-1]]: mHandle.followRoot = 1 ATTR.set_default(mHandle.mNode, 'followRoot', 1.0) else: mHandle.followRoot = .5 ATTR.set_default(mHandle.mNode, 'followRoot', .5) except Exception, err: cgmGEN.cgmExceptCB(Exception, err, localDat=vars())
def build_aimSequence(l_driven = None, l_targets = None, l_parents = None, l_upTargets = None, msgLink_masterGroup = 'masterGroup', aim = [0,0,1], up = [0,1,0], mode = 'sequence',#sequence,singleBlend upMode = 'objRotation',#objRotation,decomposeMatrix upParent = [0,1,0], rootTargetEnd = None, rootTargetStart=None,#specify root targets by index and mObj mRoot = None,#need for sequence interpType = None, maintainOffset = False): """ This kind of setup is for setting up a blended constraint so that obj2 in an obj1/obj2/obj3 sequence can aim forward or back as can obj3. :parameters: l_jointChain1 - First set of objects :returns: :raises: Exception | if reached """ _str_func = 'build_aimSequence' ml_driven = cgmMeta.validateObjListArg(l_driven,'cgmObject') ml_targets = cgmMeta.validateObjListArg(l_targets,'cgmObject',noneValid=True) ml_parents = cgmMeta.validateObjListArg(l_parents,'cgmObject',noneValid=True) ml_upTargets = cgmMeta.validateObjListArg(l_upTargets,'cgmObject',noneValid=True) if not ml_upTargets: ml_upTargets = ml_parents axis_aim = VALID.simpleAxis(aim) axis_aimNeg = axis_aim.inverse axis_up = VALID.simpleAxis(up) v_aim = axis_aim.p_vector#aimVector v_aimNeg = axis_aimNeg.p_vector#aimVectorNegative v_up = axis_up.p_vector #upVector #cgmGEN.func_snapShot(vars()) if mode == 'singleBlend': if len(ml_targets) != 2: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 2 targets.".format(_str_func)) if len(ml_driven) != 1: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 1 driven obj.".format(_str_func)) if not ml_parents: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have handleParents.".format(_str_func)) if len(ml_parents) != 1: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 1 handleParent.".format(_str_func)) mDriven = ml_driven[0] if not mDriven.getMessage(msgLink_masterGroup): log.debug("|{0}| >> No master group, creating...".format(_str_func)) raise ValueError, log.error("|{0}| >> Add the create masterGroup setup, Josh".format(_str_func)) mMasterGroup = mDriven.getMessage(msgLink_masterGroup,asMeta=True)[0] s_rootTarget = False s_targetForward = ml_targets[-1].mNode s_targetBack = ml_targets[0].mNode i = 0 mMasterGroup.p_parent = ml_parents[i] mUpDecomp = None if upMode == 'decomposeMatrix': #Decompose matrix for parent... mUpDecomp = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mUpDecomp.rename("{0}_aimMatrix".format(ml_parents[i].p_nameBase)) #mUpDecomp.doStore('cgmName',ml_parents[i]) #mUpDecomp.addAttr('cgmType','aimMatrix',attrType='string',lock=True) #mUpDecomp.doName() ATTR.connect("{0}.worldMatrix".format(ml_parents[i].mNode),"{0}.{1}".format(mUpDecomp.mNode,'inputMatrix')) d_worldUp = {'worldUpObject' : ml_parents[i].mNode, 'worldUpType' : 'vector', 'worldUpVector': [0,0,0]} elif upMode == 'objectRotation': d_worldUp = {'worldUpObject' : ml_parents[i].mNode, 'worldUpType' : 'objectRotation', 'worldUpVector': upParent} else: raise ValueError, log.error("|{0}| >> Unknown upMode: {1}".format(_str_func,upMode)) if s_targetForward: mAimForward = mDriven.doCreateAt() mAimForward.parent = mMasterGroup mAimForward.doStore('cgmTypeModifier','forward') mAimForward.doStore('cgmType','aimer') mAimForward.doName() _const=mc.aimConstraint(s_targetForward, mAimForward.mNode, maintainOffset = True, #skip = 'z', aimVector = v_aim, upVector = v_up, **d_worldUp) s_targetForward = mAimForward.mNode if mUpDecomp: ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetForward = ml_parents[i].mNode if s_targetBack: mAimBack = mDriven.doCreateAt() mAimBack.parent = mMasterGroup mAimBack.doStore('cgmTypeModifier','back') mAimBack.doStore('cgmType','aimer') mAimBack.doName() _const = mc.aimConstraint(s_targetBack, mAimBack.mNode, maintainOffset = True, #skip = 'z', aimVector = v_aimNeg, upVector = v_up, **d_worldUp) s_targetBack = mAimBack.mNode if mUpDecomp: ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetBack = s_rootTarget #ml_parents[i].mNode pprint.pprint([s_targetForward,s_targetBack]) mAimGroup = mDriven.doGroup(True,asMeta=True,typeModifier = 'aim') mDriven.parent = False const = mc.orientConstraint([s_targetForward, s_targetBack], mAimGroup.mNode, maintainOffset = True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork([mDriven.mNode,'followRoot'], [mDriven.mNode,'resultRootFollow'], [mDriven.mNode,'resultAimFollow'], keyable=True) targetWeights = mc.orientConstraint(const,q=True, weightAliasList=True,maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mDriven.parent = mAimGroup#...parent back mDriven.followRoot = .5 return True elif mode == 'sequence': """ if len(ml_targets) != 2: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 2 targets.".format(_str_func)) if len(ml_driven) != 1: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 1 driven obj.".format(_str_func)) if not ml_parents: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have handleParents.".format(_str_func)) if len(ml_parents) != 1: cgmGEN.func_snapShot(vars()) return log.error("|{0}| >> Single blend mode must have 1 handleParent.".format(_str_func)) """ for i,mDriven in enumerate(ml_driven): log.debug("|{0}| >> on: {1} | {2}".format(_str_func,i,mDriven)) mUpDecomp = False if not mDriven.getMessage(msgLink_masterGroup): log.debug("|{0}| >> No master group, creating...".format(_str_func)) raise ValueError, log.error("|{0}| >> Add the create masterGroup setup, Josh".format(_str_func)) mDriven.masterGroup.parent = ml_parents[i] if upMode == 'decomposeMatrix': #Decompose matrix for parent... mUpDecomp = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mUpDecomp.rename("{0}_aimMatrix".format(ml_parents[i].p_nameBase)) #mUpDecomp.doStore('cgmName',ml_parents[i]) #mUpDecomp.addAttr('cgmType','aimMatrix',attrType='string',lock=True) #mUpDecomp.doName() ATTR.connect("{0}.worldMatrix".format(ml_upTargets[i].mNode),"{0}.{1}".format(mUpDecomp.mNode,'inputMatrix')) d_worldUp = {'worldUpObject' : ml_upTargets[i].mNode, 'worldUpType' : 'vector', 'worldUpVector': [0,0,0]} elif upMode == 'objectRotation': d_worldUp = {'worldUpObject' : ml_upTargets[i].mNode, 'worldUpType' : 'objectRotation', 'worldUpVector': upParent} else: raise ValueError, log.error("|{0}| >> Unknown upMode: {1}".format(_str_func,upMode)) s_rootTarget = False s_targetForward = False s_targetBack = False mMasterGroup = mDriven.masterGroup b_first = False if mDriven == ml_driven[0]: log.debug("|{0}| >> First handle: {1}".format(_str_func,mDriven)) if len(ml_driven) <=2: s_targetForward = ml_parents[-1].mNode else: s_targetForward = ml_driven[i+1].getMessage('masterGroup')[0] if rootTargetStart: s_rootTarget = rootTargetStart.mNode else: s_rootTarget = mRoot.mNode b_first = True elif mDriven == ml_driven[-1]: log.debug("|{0}| >> Last handle: {1}".format(_str_func,mDriven)) if rootTargetEnd: s_rootTarget = rootTargetEnd.mNode else: s_rootTarget = ml_parents[i].mNode s_targetBack = ml_driven[i-1].getMessage('masterGroup')[0] else: log.debug("|{0}| >> Reg handle: {1}".format(_str_func,mDriven)) s_targetForward = ml_driven[i+1].getMessage('masterGroup')[0] s_targetBack = ml_driven[i-1].getMessage('masterGroup')[0] #Decompose matrix for parent... """ mUpDecomp = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mUpDecomp.doStore('cgmName',ml_parents[i]) mUpDecomp.addAttr('cgmType','aimMatrix',attrType='string',lock=True) mUpDecomp.doName() ATTR.connect("%s.worldMatrix"%(ml_parents[i].mNode),"%s.%s"%(mUpDecomp.mNode,'inputMatrix')) """ if s_targetForward: mAimForward = mDriven.doCreateAt() mAimForward.parent = mMasterGroup mAimForward.doStore('cgmTypeModifier','forward') mAimForward.doStore('cgmType','aimer') mAimForward.doName() _const=mc.aimConstraint(s_targetForward, mAimForward.mNode, maintainOffset = True, #skip = 'z', aimVector = v_aim, upVector = v_up,**d_worldUp) s_targetForward = mAimForward.mNode if mUpDecomp: ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) elif s_rootTarget: s_targetForward = s_rootTarget else: s_targetForward = ml_parents[i].mNode if s_targetBack: mAimBack = mDriven.doCreateAt() mAimBack.parent = mMasterGroup mAimBack.doStore('cgmTypeModifier','back') mAimBack.doStore('cgmType','aimer') mAimBack.doName() _const = mc.aimConstraint(s_targetBack, mAimBack.mNode, maintainOffset = True, #skip = 'z', aimVector = v_aimNeg, upVector = v_up, **d_worldUp) s_targetBack = mAimBack.mNode if mUpDecomp: ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetBack = s_rootTarget #ml_parents[i].mNode #pprint.pprint([s_targetForward,s_targetBack]) mAimGroup = mDriven.doGroup(True,asMeta=True,typeModifier = 'aim') mDriven.parent = False log.debug("|{0}| >> obj: {1} | {2}".format(_str_func,i,mDriven)) log.debug("|{0}| >> forward: {1}".format(_str_func,s_targetForward)) log.debug("|{0}| >> back: {1}".format(_str_func,s_targetBack)) log.debug(cgmGEN._str_subLine) if b_first: const = mc.orientConstraint([s_targetBack, s_targetForward], mAimGroup.mNode, maintainOffset = True)[0] else: const = mc.orientConstraint([s_targetForward, s_targetBack], mAimGroup.mNode, maintainOffset = True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork([mDriven.mNode,'followRoot'], [mDriven.mNode,'resultRootFollow'], [mDriven.mNode,'resultAimFollow'], keyable=True) targetWeights = mc.orientConstraint(const,q=True, weightAliasList=True,maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mDriven.parent = mAimGroup#...parent back if interpType: ATTR.set(const,'interpType',interpType) #if mDriven in [ml_driven[0],ml_driven[-1]]: # mDriven.followRoot = 1 #else: mDriven.followRoot = .5 return True raise ValueError,"Not done..." return for i,mObj in enumerate(ml_driven): return mObj.masterGroup.parent = ml_parents[i] s_rootTarget = False s_targetForward = False s_targetBack = False mMasterGroup = mObj.masterGroup b_first = False if mObj == ml_driven[0]: log.debug("|{0}| >> First handle: {1}".format(_str_func,mObj)) if len(ml_driven) <=2: s_targetForward = ml_parents[-1].mNode else: s_targetForward = ml_driven[i+1].getMessage('masterGroup')[0] s_rootTarget = mRoot.mNode b_first = True elif mObj == ml_driven[-1]: log.debug("|{0}| >> Last handle: {1}".format(_str_func,mObj)) s_rootTarget = ml_parents[i].mNode s_targetBack = ml_driven[i-1].getMessage('masterGroup')[0] else: log.debug("|{0}| >> Reg handle: {1}".format(_str_func,mObj)) s_targetForward = ml_driven[i+1].getMessage('masterGroup')[0] s_targetBack = ml_driven[i-1].getMessage('masterGroup')[0] #Decompose matrix for parent... mUpDecomp = cgmMeta.cgmNode(nodeType = 'decomposeMatrix') mUpDecomp.doStore('cgmName',ml_parents[i]) mUpDecomp.addAttr('cgmType','aimMatrix',attrType='string',lock=True) mUpDecomp.doName() ATTR.connect("%s.worldMatrix"%(ml_parents[i].mNode),"%s.%s"%(mUpDecomp.mNode,'inputMatrix')) if s_targetForward: mAimForward = mObj.doCreateAt() mAimForward.parent = mMasterGroup mAimForward.doStore('cgmTypeModifier','forward') mAimForward.doStore('cgmType','aimer') mAimForward.doName() _const=mc.aimConstraint(s_targetForward, mAimForward.mNode, maintainOffset = True, #skip = 'z', aimVector = [0,0,1], upVector = [1,0,0], worldUpObject = ml_parents[i].mNode, worldUpType = 'vector', worldUpVector = [0,0,0]) s_targetForward = mAimForward.mNode ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetForward = ml_parents[i].mNode if s_targetBack: mAimBack = mObj.doCreateAt() mAimBack.parent = mMasterGroup mAimBack.doStore('cgmTypeModifier','back') mAimBack.doStore('cgmType','aimer') mAimBack.doName() _const = mc.aimConstraint(s_targetBack, mAimBack.mNode, maintainOffset = True, #skip = 'z', aimVector = [0,0,-1], upVector = [1,0,0], worldUpObject = ml_parents[i].mNode, worldUpType = 'vector', worldUpVector = [0,0,0]) s_targetBack = mAimBack.mNode ATTR.connect("%s.%s"%(mUpDecomp.mNode,"outputRotate"),"%s.%s"%(_const[0],"upVector")) else: s_targetBack = s_rootTarget #ml_parents[i].mNode pprint.pprint([s_targetForward,s_targetBack]) mAimGroup = mObj.doGroup(True,asMeta=True,typeModifier = 'aim') mObj.parent = False if b_first: const = mc.orientConstraint([s_targetBack, s_targetForward], mAimGroup.mNode, maintainOffset = True)[0] else: const = mc.orientConstraint([s_targetForward, s_targetBack], mAimGroup.mNode, maintainOffset = True)[0] d_blendReturn = NODEFACTORY.createSingleBlendNetwork([mObj.mNode,'followRoot'], [mObj.mNode,'resultRootFollow'], [mObj.mNode,'resultAimFollow'], keyable=True) targetWeights = mc.orientConstraint(const,q=True, weightAliasList=True,maintainOffset=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut('%s.%s' % (const,targetWeights[1])) d_blendReturn['d_result1']['mi_plug'].p_hidden = True d_blendReturn['d_result2']['mi_plug'].p_hidden = True mObj.parent = mAimGroup#...parent back if mObj in [ml_driven[0],ml_driven[-1]]: mObj.followRoot = 1 else: mObj.followRoot = .5
def blendChainsBy(l_jointChain1 = None, l_jointChain2 = None, l_blendChain = None, driver = None, l_constraints = ['point','orient'], d_scale = {}, d_point = {}, d_parent = {}, d_orient = {}, maintainOffset = False): """ :parameters: l_jointChain1 - First set of objects l_jointChain2 - Second set of objects l_blendChain - blend set driver - Attribute to drive our blend l_constraints - constraints to be driven by the setup. Default is ['point','orient'] :returns: :raises: Exception | if reached """ _str_func = 'blendChainsBy' d_funcs = {'point':mc.pointConstraint, 'orient':mc.orientConstraint, 'scale':mc.scaleConstraint, 'parent':mc.parentConstraint} for c in l_constraints: if c not in ['point','orient','scale','parent']: log.warning("|{0}| >> Bad constraint arg. Removing: {1}".format(_str_func, c)) l_constraints.remove(c) if not l_constraints: raise StandardError,"Need valid constraints" ml_jointChain1 = cgmMeta.validateObjListArg(l_jointChain1,'cgmObject',noneValid=False) ml_jointChain2 = cgmMeta.validateObjListArg(l_jointChain2,'cgmObject',noneValid=False) ml_blendChain = cgmMeta.validateObjListArg(l_blendChain,'cgmObject',noneValid=False) d_driver = cgmMeta.validateAttrArg(driver,noneValid=True) d_blendReturn = {} mi_driver = False if d_driver: mi_driver = d_driver.get('mi_plug') or False else: raise ValueError,"Invalid driver: {0}".format(driver) if not len(ml_jointChain1) >= len(ml_blendChain) or not len(ml_jointChain2) >= len(ml_blendChain): raise StandardError,"Joint chains aren't equal lengths: l_jointChain1: %s | l_jointChain2: %s | l_blendChain: %s"%(len(l_jointChain1),len(l_jointChain2),len(l_blendChain)) ml_nodes = [] #>>> Actual meat =========================================================== _creates = [] for i,i_jnt in enumerate(ml_blendChain): log.debug(i_jnt) for constraint in l_constraints: _d = {} if constraint == 'scale': _d = d_scale """ log.debug("connectBlendChainByConstraint>>> %s || %s = %s | %s"%(ml_jointChain1[i].mNode, ml_jointChain2[i].mNode, ml_blendChain[i].mNode, constraint))""" _buff = d_funcs[constraint]([ml_jointChain2[i].mNode,ml_jointChain1[i].mNode], ml_blendChain[i].mNode, maintainOffset = maintainOffset,**_d) #func = getattr(mc,'{0}Constraint'.format(constraint)) #_buff = func([ml_jointChain2[i].mNode,ml_jointChain1[i].mNode], # ml_blendChain[i].mNode, # maintainOffset = maintainOffset,**_d) _creates.append(_buff) mConst = cgmMeta.cgmNode(_buff[0]) if constraint in ['parent','orient']: mConst.interpType = 2 targetWeights = d_funcs[constraint](mConst.mNode,q=True, weightAliasList=True) if len(targetWeights)>2: raise StandardError,"Too many weight targets: obj: %s | weights: %s"%(i_jnt.mNode,targetWeights) if mi_driver: d_blendReturn = NODEFACTORY.createSingleBlendNetwork(mi_driver, [mConst.mNode,'result_%s_%s'%(constraint,ml_jointChain1[i].getBaseName())], [mConst.mNode,'result_%s_%s'%(constraint,ml_jointChain2[i].getBaseName())], keyable=True) #Connect d_blendReturn['d_result1']['mi_plug'].doConnectOut('%s.%s' % (mConst.mNode,targetWeights[0])) d_blendReturn['d_result2']['mi_plug'].doConnectOut('%s.%s' % (mConst.mNode,targetWeights[1])) ml_nodes.append(mConst) d_blendReturn['ml_nodes'] = ml_nodes #pprint.pprint(vars()) return d_blendReturn
def ribbon_seal( driven1=None, driven2=None, influences1=None, influences2=None, msgDriver=None, #...msgLink on joint to a driver group for constaint purposes extendEnds=False, loftAxis='z', orientation='zyx', secondaryAxis='y+', baseName=None, baseName1=None, baseName2=None, connectBy='constraint', sectionSpans=1, settingsControl=None, specialMode=None, sealSplit=False, sealDriver1=None, sealDriver2=None, sealDriverMid=None, sealName1='left', sealName2='right', sealNameMid='center', maxValue=10.0, moduleInstance=None, parentGutsTo=None): try: _str_func = 'ribbon_seal' ml_rigObjectsToConnect = [] md_drivers = {} md_base = {} md_seal = {} md_blend = {} md_follicles = {} md_follicleShapes = {} d_dat = {1: {}, 2: {}} if msgDriver: ml_missingDrivers = [] def check_msgDriver(mObj): mDriver = mObj.getMessageAsMeta(msgDriver) if mDriver: md_drivers[mObj] = mDriver else: log.error("|{0}| >> Missing driver: {1}".format( _str_func, mObj)) ml_missingDrivers.append(mObj) return False #>>> Verify =================================================================================== log.debug("|{0}| >> driven1 [Check]...".format(_str_func)) d_dat[1]['driven'] = cgmMeta.validateObjListArg(driven1, mType='cgmObject', mayaType=['joint'], noneValid=False) log.debug("|{0}| >> driven2 [Check]...".format(_str_func)) d_dat[2]['driven'] = cgmMeta.validateObjListArg(driven2, mType='cgmObject', mayaType=['joint'], noneValid=False) #Check our msgDrivers ----------------------------------------------------------- if msgDriver: log.debug("|{0}| >> msgDriver [Check]...".format(_str_func)) for mObj in d_dat[1]['driven'] + d_dat[2]['driven']: if mObj not in ml_missingDrivers: check_msgDriver(mObj) if ml_missingDrivers: raise ValueError, "Missing drivers. See errors." log.debug("|{0}| >> msgDriver [Pass]...".format(_str_func)) d_dat[1]['int_driven'] = len(d_dat[1]['driven']) d_dat[2]['int_driven'] = len(d_dat[2]['driven']) log.debug("|{0}| >> Driven lengths {1} | {2}".format( _str_func, d_dat[1]['int_driven'], d_dat[2]['int_driven'])) log.debug("|{0}| >> influences1 [Check]...".format(_str_func)) d_dat[1]['mInfluences'] = cgmMeta.validateObjListArg( influences1, mType='cgmObject', mayaType=['joint'], noneValid=False) log.debug("|{0}| >> influences2 [Check]...".format(_str_func)) d_dat[2]['mInfluences'] = cgmMeta.validateObjListArg( influences2, mType='cgmObject', mayaType=['joint'], noneValid=False) d_dat[1]['int_influences'] = len(d_dat[1]['mInfluences']) d_dat[2]['int_influences'] = len(d_dat[2]['mInfluences']) log.debug("|{0}| >> Influence lengths {1} | {2}".format( _str_func, d_dat[1]['int_influences'], d_dat[2]['mInfluences'])) mi_mayaOrientation = VALID.simpleOrientation(orientation) str_orientation = mi_mayaOrientation.p_string str_secondaryAxis = VALID.stringArg(secondaryAxis, noneValid=True) if specialMode and specialMode not in [ 'noStartEnd', 'endsToInfluences' ]: raise ValueError, "Unknown special mode: {0}".format(specialMode) #module ----------------------------------------------------------------------------------------------- mModule = cgmMeta.validateObjArg(moduleInstance, noneValid=True) #try:mModule.isModule() #except:mModule = False mi_rigNull = False if mModule: log.debug("|{0}| >> mModule [Check]...".format(_str_func)) mi_rigNull = mModule.rigNull if str_baseName is None: str_baseName = mModule.getPartNameBase() #Get part base name if not baseName: baseName = 'testRibbonSeal' if not baseName1: baseName1 = 'ribbon1' if not baseName2: baseName2 = 'ribbon2' d_check = { 'driven1': d_dat[1]['int_driven'], 'driven2': d_dat[2]['int_driven'] } for k, i in d_check.iteritems(): if i < 3: raise ValueError, "needs at least three driven. Found : {0} | {1}".format( k, i) log.debug("|{0}| >> Group [Check]...".format(_str_func)) if parentGutsTo is None: mGroup = cgmMeta.cgmObject(name='newgroup') mGroup.addAttr('cgmName', str(baseName), lock=True) mGroup.addAttr('cgmTypeModifier', 'segmentStuff', lock=True) mGroup.doName() else: mGroup = cgmMeta.validateObjArg(parentGutsTo, 'cgmObject', False) if mModule: mGroup.parent = mModule.rigNull #Good way to verify an instance list? #validate orientation #> axis ------------------------------------------------------------- """ axis_aim = VALID.simpleAxis("{0}+".format(str_orientation[0])) axis_aimNeg = axis_aim.inverse axis_up = VALID.simpleAxis("{0}+".format(str_orientation [1])) axis_out = VALID.simpleAxis("{0}+".format(str_orientation [2])) v_aim = axis_aim.p_vector#aimVector v_aimNeg = axis_aimNeg.p_vector#aimVectorNegative v_up = axis_up.p_vector #upVector v_out = axis_out.p_vector str_up = axis_up.p_string loftAxis2 = False #Figure out our loft axis stuff if loftAxis not in orientation: _lower_loftAxis = loftAxis.lower() if _lower_loftAxis in ['out','up']: if _lower_loftAxis == 'out': loftAxis = str_orientation[2] else: loftAxis = str_orientation[1] else: raise ValueError,"Not sure what to do with loftAxis: {0}".format(loftAxis) """ outChannel = str_orientation[2] #outChannel upChannel = str_orientation[1] #upChannel = '{0}up'.format(str_orientation[1])#upChannel #>>> Ribbon Surface ============================================================================ log.debug("|{0}| >> Ribbons generating...".format(_str_func)) l_surfaceReturn1 = IK.ribbon_createSurface(d_dat[1]['driven'], loftAxis, sectionSpans, extendEnds) d_dat[1]['mSurf'] = cgmMeta.validateObjArg(l_surfaceReturn1[0], 'cgmObject', setClass=True) d_dat[1]['mSurf'].addAttr('cgmName', str(baseName1), attrType='string', lock=True) d_dat[1]['mSurf'].addAttr('cgmType', 'controlSurface', attrType='string', lock=True) d_dat[1]['mSurf'].doName() l_surfaceReturn2 = IK.ribbon_createSurface(d_dat[2]['driven'], loftAxis, sectionSpans, extendEnds) d_dat[2]['mSurf'] = cgmMeta.validateObjArg(l_surfaceReturn1[0], 'cgmObject', setClass=True) d_dat[2]['mSurf'].addAttr('cgmName', str(baseName2), attrType='string', lock=True) d_dat[2]['mSurf'].addAttr('cgmType', 'controlSurface', attrType='string', lock=True) d_dat[2]['mSurf'].doName() log.debug("d_dat[1]['mSurf']: {0}".format(d_dat[1]['mSurf'])) log.debug("d_dat[2]['mSurf']: {0}".format(d_dat[2]['mSurf'])) ml_toConnect = [] ml_toConnect.extend([d_dat[1]['mSurf'], d_dat[2]['mSurf']]) #Special Mode ================================================================================= if specialMode in ['noStartEnd', 'endsToInfluences']: log.debug( "|{0}| >> Special Mode: {1}".format(_str_func, specialMode) + cgmGEN._str_subLine) if specialMode == 'endsToInfluences': d_special = { '1start': { 'mObj': d_dat[1]['driven'][0], 'mDriver': d_dat[1]['mInfluences'][0] }, '1end': { 'mObj': d_dat[1]['driven'][-1], 'mDriver': d_dat[1]['mInfluences'][-1] }, '2start': { 'mObj': d_dat[2]['driven'][0], 'mDriver': d_dat[2]['mInfluences'][0] }, '2end': { 'mObj': d_dat[2]['driven'][-1], 'mDriver': d_dat[2]['mInfluences'][-1] } } for n, dat in d_special.iteritems(): mObj = dat['mObj'] mDriven = md_drivers[mObj] mDriver = dat['mDriver'] log.debug("|{0}| >> {1} | Driver: {2}".format( _str_func, i, mDriven)) _const = mc.parentConstraint([mDriver.mNode], mDriven.mNode, maintainOffset=True)[0] ATTR.set(_const, 'interpType', 2) d_dat[1]['driven'] = d_dat[1]['driven'][1:-1] d_dat[2]['driven'] = d_dat[2]['driven'][1:-1] driven1 = driven1[1:-1] driven2 = driven2[1:-1] #>>> Setup our Attributes ================================================================ log.debug("|{0}| >> Settings...".format(_str_func)) if settingsControl: mSettings = cgmMeta.validateObjArg(settingsControl, 'cgmObject') else: mSettings = d_dat[1]['mSurf'] mPlug_sealHeight = cgmMeta.cgmAttr(mSettings.mNode, 'sealHeight', attrType='float', lock=False, keyable=True) mPlug_sealHeight.doDefault(.5) mPlug_sealHeight.value = .5 #>>> Setup blend results -------------------------------------------------------------------- if sealSplit: d_split = split_blends( driven1, #d_dat[1]['driven'], driven2, #d_dat[2]['driven'], sealDriver1, sealDriver2, sealDriverMid, nameSeal1=sealName1, nameSeal2=sealName2, nameSealMid=sealNameMid, settingsControl=mSettings, maxValue=maxValue) for k, d in d_split.iteritems(): d_dat[k]['mPlugs'] = d['mPlugs'] else: mPlug_seal = cgmMeta.cgmAttr(mSettings.mNode, 'seal', attrType='float', lock=False, keyable=True) mPlug_sealOn = cgmMeta.cgmAttr(mSettings, 'result_sealOn', attrType='float', defaultValue=0, keyable=False, lock=True, hidden=False) mPlug_sealOff = cgmMeta.cgmAttr(mSettings, 'result_sealOff', attrType='float', defaultValue=0, keyable=False, lock=True, hidden=False) NODEFACTORY.createSingleBlendNetwork(mPlug_seal.p_combinedName, mPlug_sealOn.p_combinedName, mPlug_sealOff.p_combinedName) d_dat[1]['mPlug_sealOn'] = mPlug_sealOn d_dat[1]['mPlug_sealOff'] = mPlug_sealOff d_dat[2]['mPlug_sealOn'] = mPlug_sealOn d_dat[2]['mPlug_sealOff'] = mPlug_sealOff mPlug_FavorOneMe = cgmMeta.cgmAttr(mSettings, 'result_sealOneMe', attrType='float', defaultValue=0, keyable=False, lock=True, hidden=False) mPlug_FavorOneThee = cgmMeta.cgmAttr(mSettings, 'result_sealOneThee', attrType='float', defaultValue=0, keyable=False, lock=True, hidden=False) mPlug_FavorTwoMe = cgmMeta.cgmAttr(mSettings, 'result_sealTwoMe', attrType='float', defaultValue=0, keyable=False, lock=True, hidden=False) mPlug_FavorTwoThee = cgmMeta.cgmAttr(mSettings, 'result_sealTwoThee', attrType='float', defaultValue=0, keyable=False, lock=True, hidden=False) NODEFACTORY.createSingleBlendNetwork(mPlug_sealHeight.p_combinedName, mPlug_FavorOneThee.p_combinedName, mPlug_FavorOneMe.p_combinedName) NODEFACTORY.createSingleBlendNetwork(mPlug_sealHeight.p_combinedName, mPlug_FavorTwoThee.p_combinedName, mPlug_FavorTwoMe.p_combinedName) d_dat[1]['mPlug_me'] = mPlug_FavorOneMe d_dat[1]['mPlug_thee'] = mPlug_FavorOneThee d_dat[2]['mPlug_me'] = mPlug_FavorTwoMe d_dat[2]['mPlug_thee'] = mPlug_FavorTwoThee """ b_attachToInfluences = False if attachEndsToInfluences: log.debug("|{0}| >> attachEndsToInfluences flag. Checking...".format(_str_func)) if influences and len(influences) > 1: b_attachToInfluences = True log.debug("|{0}| >> b_attachToInfluences: {1}".format(_str_func,b_attachToInfluences)) """ #>>> Skinning ============================================================================ log.debug("|{0}| >> Skinning Ribbons...".format(_str_func)) for idx, dat in d_dat.iteritems(): max_influences = 2 mode_tighten = 'twoBlend' blendLength = int(dat['int_driven'] / 2) blendMin = 2 _hardLength = 2 if extendEnds: blendMin = 4 _hardLength = 4 mode_tighten = None if dat['int_influences'] > 2: mode_tighten = None #blendLength = int(int_lenInfluences/2) max_influences = MATH.Clamp(blendLength, 2, 4) blendLength = MATH.Clamp(int(dat['int_influences'] / 2), 2, 6) if dat['int_influences'] == dat['int_driven']: _hardLength = 3 #Tighten the weights... mSkinCluster = cgmMeta.validateObjArg(mc.skinCluster( [mObj.mNode for mObj in dat['mInfluences']], dat['mSurf'].mNode, tsb=True, maximumInfluences=max_influences, normalizeWeights=1, dropoffRate=5.0), 'cgmNode', setClass=True) mSkinCluster.doStore('cgmName', dat['mSurf']) mSkinCluster.doName() #Tighten the weights... RIGSKIN.surface_tightenEnds(dat['mSurf'].mNode, hardLength=_hardLength, blendLength=blendLength, mode=mode_tighten) #>>> Meat ============================================================================ ml_processed = [] for idx, dat in d_dat.iteritems(): idx_seal = 1 if idx == 1: idx_seal = 2 dat_seal = d_dat[idx_seal] log.debug("|{0}| >> Building [{1}] | seal idx: {2} |".format( _str_func, idx, idx_seal) + cgmGEN._str_subLine) mSurfBase = dat['mSurf'] mSurfSeal = dat_seal['mSurf'] for i, mObj in enumerate(dat['driven']): if mObj in ml_processed: log.debug("|{0}| >> Already completed: {1}".format( _str_func, mObj)) continue ml_processed.append(mObj) log.debug("|{0}| >> {1} | Driven: {2}".format( _str_func, i, mObj)) mDriven = md_drivers[mObj] log.debug("|{0}| >> {1} | Driver: {2}".format( _str_func, i, mDriven)) log.debug("|{0}| >> Create track drivers...".format(_str_func)) mTrackBase = mDriven.doCreateAt(setClass=True) mTrackBase.doStore('cgmName', mObj) mTrackSeal = mTrackBase.doDuplicate() mTrackBlend = mTrackBase.doDuplicate() mTrackSeal.doStore('cgmType', 'trackSeal') mTrackBase.doStore('cgmType', 'trackBase') mTrackBlend.doStore('cgmType', 'trackBlend') for mTrack in mTrackBase, mTrackSeal, mTrackBlend: mTrack.doName() log.debug("|{0}| >> Attach drivers...".format(_str_func)) d_tmp = { 'base': { 'mSurf': mSurfBase, 'mTrack': mTrackBase }, 'seal': { 'mSurf': mSurfSeal, 'mTrack': mTrackSeal }, } for n, d in d_tmp.iteritems(): mTrack = d['mTrack'] mSurf = d['mSurf'] _res = RIGCONSTRAINTS.attach_toShape( mTrack.mNode, mSurf.mNode, 'parent') mFollicle = _res[-1][ 'mFollicle'] #cgmMeta.asMeta(follicle) mFollShape = _res[-1][ 'mFollicleShape'] #cgmMeta.asMeta(shape) md_follicleShapes[mObj] = mFollShape md_follicles[mObj] = mFollicle mFollicle.parent = mGroup.mNode if mModule: #if we have a module, connect vis mFollicle.overrideEnabled = 1 cgmMeta.cgmAttr( mModule.rigNull.mNode, 'gutsVis', lock=False).doConnectOut( "%s.%s" % (mFollicle.mNode, 'overrideVisibility')) cgmMeta.cgmAttr( mModule.rigNull.mNode, 'gutsLock', lock=False).doConnectOut( "%s.%s" % (mFollicle.mNode, 'overrideDisplayType')) #Blend point -------------------------------------------------------------------- _const = mc.parentConstraint( [mTrackBase.mNode, mTrackSeal.mNode], mTrackBlend.mNode)[0] ATTR.set(_const, 'interpType', 2) targetWeights = mc.parentConstraint(_const, q=True, weightAliasList=True) #Connect if idx == 1: dat['mPlug_thee'].doConnectOut('%s.%s' % (_const, targetWeights[0])) dat['mPlug_me'].doConnectOut('%s.%s' % (_const, targetWeights[1])) else: dat['mPlug_me'].doConnectOut('%s.%s' % (_const, targetWeights[0])) dat['mPlug_thee'].doConnectOut('%s.%s' % (_const, targetWeights[1])) #seal -------------------------------------------------------------------- _const = mc.parentConstraint( [mTrackBase.mNode, mTrackBlend.mNode], mDriven.mNode)[0] ATTR.set(_const, 'interpType', 2) targetWeights = mc.parentConstraint(_const, q=True, weightAliasList=True) if sealSplit: dat['mPlugs']['off'][i].doConnectOut( '%s.%s' % (_const, targetWeights[0])) dat['mPlugs']['on'][i].doConnectOut( '%s.%s' % (_const, targetWeights[1])) else: dat['mPlug_sealOff'].doConnectOut( '%s.%s' % (_const, targetWeights[0])) dat['mPlug_sealOn'].doConnectOut( '%s.%s' % (_const, targetWeights[1])) log.debug("|{0}| >> Blend drivers...".format(_str_func)) """ #Simple contrain if b_attachToInfluences and mJnt in [ml_joints[0],ml_joints[-1]]: if mJnt == ml_joints[0]: mUse = ml_influences[0] else: mUse = ml_influences[-1] mc.parentConstraint([mUse.mNode], mDriven.mNode, maintainOffset=True) else: mc.parentConstraint([mDriver.mNode], mDriven.mNode, maintainOffset=True) """ #pprint.pprint(d_dat) return except Exception, err: cgmGEN.cgmExceptCB(Exception, err, msg=vars())
rUtils.connectBlendChainByConstraint(ml_fkUse,ml_ikJoints,ml_blendJoints, driver = mPlug_FKIK.p_combinedName,l_constraints=['point','orient']) #>>> Settings - constrain mi_settings.masterGroup.parent = self._go._i_constrainNull.mNode mc.pointConstraint(ml_blendJoints[1].mNode, mi_settings.masterGroup.mNode, maintainOffset = True) mc.orientConstraint(ml_blendJoints[1].mNode, mi_settings.masterGroup.mNode, maintainOffset = True) #>>> Setup a vis blend result mPlug_FKon = cgmMeta.cgmAttr(mi_settings,'result_FKon',attrType='float',defaultValue = 0,keyable = False,lock=True,hidden=True) mPlug_IKon = cgmMeta.cgmAttr(mi_settings,'result_IKon',attrType='float',defaultValue = 0,keyable = False,lock=True,hidden=True) NodeF.createSingleBlendNetwork(mPlug_FKIK.p_combinedName,mPlug_IKon.p_combinedName,mPlug_FKon.p_combinedName) mPlug_FKon.doConnectOut("%s.visibility"%self._go._i_constrainNull.controlsFK.mNode) mPlug_IKon.doConnectOut("%s.visibility"%self._go._i_constrainNull.controlsIK.mNode) except Exception,error: raise Exception,"%s.build_FKIK>>> blend connect error: %s"%(self._go._strShortName,error) log.info("%s.build_FKIK complete!"%self._go._mi_module.getShortName()) return True return fncWrap(goInstance).go() def build_rig(goInstance = None): class fncWrap(modUtils.rigStep): def __init__(self,goInstance = None):
NodeF.connect_controlWiring('mouth_anim',_obj,_wiringDict,baseName = 33) NodeF.connect_controlWiring('upper_lipRoll_anim',_obj,_wiringDict,baseName = 33) #>>> createAndConnectBlendColors #======================================================= NodeF.createAndConnectBlendColors('l_knee_seg_0_jnt_Transform_anchor','l_knee_seg_0_jnt_Transform_aim','l_knee_seg_0_jnt_Transform_attach','l_knee_ik_1_anim.followRoot','rotate') #>>> single blend #======================================================= driver = 'null1.FKIK' result1 = 'null1.resultFK' result2 = 'null1.resultIK' NodeF.createSingleBlendNetwork(driver, result1, result2,keyable=True) #>>> puppet adding controls i_node = a.masterControl.controlSettings str_nodeShort = str(i_node.getShortName()) d_attrKWs = {'skeleton':{'value':0,'defaultValue':0}, 'geo':{'value':1,'defaultValue':1}} l_buildCatch = [] i_node = a.masterControl.controlSettings str_nodeShort = str(i_node.getShortName()) #Skeleton/geo settings for attr in ['skeleton','geo',]: i_node.addAttr(attr,enumName = 'off:lock:on', defaultValue = 1, attrType = 'enum',keyable = False,hidden = False)