def transfer_uvs(meshes): """ **NOT UNDOABLE** Transfer UVs from first mesh(source) in meshes list to remaining(targets). :param meshes: PyNode Transforms, not Shape Nodes. """ def mfn_object(mesh): """Get shape mesh function""" sel_list = om2.MGlobal.getSelectionListByName(mesh.name()) base = sel_list.getDagPath(0) mfn_object = om2.MFnMesh(base) return mfn_object # Get source UVs source_dag = mfn_object(meshes[0]) source_uvs = source_dag.getUVs() # Find Orig Shape if exists in targets. for mesh in meshes[1:]: target_mesh_function = None # Try to find Orig shape. This will exist for skinned meshes. for shape in mesh.listRelatives(): if shape.find('Orig') != -1: target_mesh_function = mfn_object(shape) if not target_mesh_function: target_mesh_function = mfn_object(mesh.getShape()) target_mesh_function.setUVs(source_uvs[0], source_uvs[1], uvSet='map1') pymel.ogs(reset=True) # update the viewport, clean out cached geo pymel.dgdirty( allPlugs=True) # Making sure everything in the scene has evaluated.
def changeActiveCallbacks(self): self.clearCallbacks() # make new dirty plug callbacks for each # FK/IK thing that needs one sL = om.MSelectionList() for s in self.fkikDict: ld = self.fkikDict[s] ctrl = self.ns + ld["ctrl"] if not pmc.objExists(ctrl): if self.ns != ":": pmc.warning("FKIK ctrl not found in namespace" " \"{0}\"".format(self.ns)) return sL.add(ctrl) n = om.MObject() sL.getDependNode(0, n) # attributeChangedCallback, dirtyPlugCallback provides dirty data callbackID = om.MNodeMessage.addAttributeChangedCallback( n, self.updateFkIk, s) sL.remove(0) self.callbackIDs.append(callbackID) # force update pmc.dgdirty(ctrl)
def set_DG_dirty(self): """sets the DG to dirty for parentConstraint, constrainedParent and stabilizerParent """ pm.dgdirty( self._parent_constraint, self._constrained_parent, self._stabilizer_parent )
def mirror_obj(this, mir, ref_mtx, behavior_mtx): """Perform a reflection about given matrix on t and its children with respect to mir. Also copies user-defined attribute values.""" try: reflected_target = pmc.dt.TransformationMatrix(behavior_mtx * mir.wm.get() * ref_mtx) reflected_target.setScale((1, 1, 1), space="transform") this.setMatrix(reflected_target, ws=True) # refresh (cause maya can be dumb) pmc.dgdirty(this) except AttributeError: pass except: raise
def transfer_weights_replace(source, target): """ Quickly transfer weight for a source to a target by swapping the connection. Fast but only usefull when you are willing to lose the weights stored in target. """ skinToReset = set() #TODO : Ensure that the transfered lockInfluenceWeight attr work correctly (The lock icon doesn't appear in the skinCluster) if source.hasAttr('lockInfluenceWeights'): attr_lockInfluenceWeights_src = source.lockInfluenceWeights #The target bone could possibly not have the attribute if target.hasAttr('lockInfluenceWeights'): attr_lockInfluenceWeights_dst = target.lockInfluenceWeights else: target.addAttr("lockInfluenceWeights", at="bool") attr_lockInfluenceWeights_dst = target.lockInfluenceWeights attr_lockInfluenceWeights_dst.set(attr_lockInfluenceWeights_src.get()) for plug in attr_lockInfluenceWeights_src.outputs(plugs=True): if isinstance(plug.node(), pymel.nodetypes.SkinCluster): skinToReset.add(plug.node()) pymel.disconnectAttr(attr_lockInfluenceWeights_src, plug) pymel.connectAttr(attr_lockInfluenceWeights_dst, plug) attr_objectColorRGB_src = source.attr('objectColorRGB') attr_objectColorRGB_dst = target.attr('objectColorRGB') for plug in attr_objectColorRGB_src.outputs(plugs=True): if isinstance(plug.node(), pymel.nodetypes.SkinCluster): pymel.disconnectAttr(attr_objectColorRGB_src, plug) pymel.connectAttr(attr_objectColorRGB_dst, plug) attr_worldMatrix_dst = target.worldMatrix for attr_worldMatrix_src in source.worldMatrix: for plug in attr_worldMatrix_src.outputs(plugs=True): if isinstance(plug.node(), pymel.nodetypes.SkinCluster): pymel.disconnectAttr(attr_worldMatrix_src, plug) pymel.connectAttr(attr_worldMatrix_dst, plug) #HACK : Evaluate back all skinCluster in which we changed connections pymel.dgdirty(skinToReset) '''
def _set_dg_dirty(self): """sets the DG to dirty for _object, currentPivot and futurePivot """ pm.dgdirty(self._object, self._futurePivot)
def __init__(self, **kwds): self.character = defaultReturn('jerry', 'character', param=kwds) self.rigBound = defaultReturn(None, 'rigBound', param=kwds) self.rigVersion = defaultReturn(0, 'version', param=kwds) self.buildInScene = defaultReturn(0, 'buildInScene', param=kwds) if self.buildInScene == 0: pm.newFile(f=True) print "START: rigPuppet build " + self.character pm.timer(s=True) pm.undoInfo(state=False) pm.evaluationManager(mode='serial') try: self.charModule = importlib.import_module('char.' + self.character + 'Puppet') print self.charModule pm.workspace(update=True) projectRoot = pm.workspace( q=True, rd=True) + 'scenes/release/rigBound/' + self.character + '/' print ' project root ' + projectRoot + ' found' if self.rigVersion == 0: puppetPath = pm.workspace( q=True, rd=True ) + 'scenes/release/rigPuppet/' + self.character + '/' # find what is next puppet version puppetList = [] os.chdir(puppetPath) for f in glob.glob("*.ma"): puppetList.append(f) self.rigVersion = len(puppetList) + 1 print 'rigVersion = ' + str(self.rigVersion) if self.rigBound is None: #projectRoot = pm.workspace(q=True, rd=True) + 'scenes/release/rigBound/' fileList = [] os.chdir(projectRoot) for f in glob.glob("*.ma"): fileList.append(f) fileList.sort() latestFile = fileList[-1:][0] self.rigBound = projectRoot + latestFile print 'latestFile = ' + latestFile #else: # self.rigBound = projectRoot + self.rigBound + '.ma' if self.buildInScene == 0: print 'rigBound file path = ' + self.rigBound # import rigBound file try: #filePath = cmds.file(self.rigBound, f=True, ignoreVersion=True, # typ="mayaAscii", o=True) filePath = cmds.file(self.rigBound, i=True, ignoreVersion=True, ra=False, mergeNamespacesOnClash=False, typ="mayaAscii", loadReferenceDepth='none') except RuntimeError: print self.rigBound + ' file not found' cmds.dgdirty(allPlugs=True) cmds.refresh() # unparent skeleton rootJoint = cmds.parent(cmds.listRelatives('skeleton_GRP', typ='joint'), w=True)[0] loadPose(rootJoint, 'tPose') pm.rename('globalOffset_GRP', 'globalOffset_GRPx') pm.rename('global_CTRL', 'global_CTRLx') self.globalCtrl = rig_control(name='global', colour='white', shape='arrows', con=0, showAttrs=['sx', 'sy', 'sz']) self.globalCtrl.gimbal = createCtrlGimbal(self.globalCtrl).ctrl self.topNode = rig_transform(0, name=self.character + 'RigPuppetTop', child=self.globalCtrl.offset).object topNode = pm.PyNode(self.topNode) pm.addAttr(topNode, ln='rpAuthor', at='enum', enumName='JerryLee', k=True) topNode.rpAuthor.setLocked(True) pm.addAttr(topNode, ln='rpVersion', at='enum', enumName=str(self.rigVersion), k=True) topNode.rpVersion.setLocked(True) topNode.translate.setLocked(True) topNode.rotate.setLocked(True) topNode.scale.setLocked(True) for cb in ('t', 'r', 's'): for at in ('x', 'y', 'z'): cbAttr = getattr(topNode, cb + at) cbAttr.setKeyable(False) try: self.rigGrp = pm.parent('rig_GRP', self.globalCtrl.gimbal)[0] except Exception as e: self.rigGrp = rig_transform( 0, name='rig', parent=self.globalCtrl.gimbal).object pm.addAttr(self.rigGrp, longName='worldScale', at='float', k=True, min=0, defaultValue=1) self.rigGrp.worldScale.set(cb=True) try: self.rigModule = pm.parent('rigModules_GRP', self.globalCtrl.gimbal)[0] except Exception as e: self.rigModule = rig_transform( 0, name='rigModules', parent=self.globalCtrl.gimbal).object try: self.model = pm.parent('model_GRP', self.topNode)[0] except Exception as e: self.model = rig_transform(0, name='model', parent=self.topNode).object try: self.rigModel = pm.parent('rigModel_GRP', self.model)[0] except Exception as e: self.rigModel = rig_transform(0, name='rigModel', parent=self.model).object self.worldSpace = rig_transform( 0, name='worldSpace', parent=self.globalCtrl.gimbal).object try: pm.delete("|*RigBoundTop_GRP") except pm.MayaNodeError: print 'RigBound top node does not exist' # create attributes on global ctrl pm.addAttr(self.globalCtrl.ctrl, ln='puppetSettings', at='enum', enumName='___________', k=True) self.globalCtrl.ctrl.puppetSettings.setLocked(True) # model and skeleton vis # model connectAttrToVisObj(self.globalCtrl.ctrl, 'modelVis', self.model, defaultValue=1) # skeleton pm.addAttr(self.globalCtrl.ctrl, longName='skeletonVis', at='long', k=True, min=0, max=1, defaultValue=0) self.globalCtrl.ctrl.skeletonVis.set(cb=True) # controls pm.addAttr(self.globalCtrl.ctrl, longName='controlsVis', at='long', k=True, min=0, max=1, defaultValue=1) self.globalCtrl.ctrl.controlsVis.set(cb=True) # referencing and selecting pm.addAttr(self.globalCtrl.ctrl, ln='model', at='enum', enumName='Selectable:Reference', k=True, defaultValue=1) pm.addAttr(self.globalCtrl.ctrl, ln='skeleton', at='enum', enumName='Selectable:Reference', k=True, defaultValue=1) # LOD vis pm.addAttr(self.globalCtrl.ctrl, ln='lodSetting', at='enum', enumName='___________', k=True) self.globalCtrl.ctrl.lodSetting.setLocked(True) pm.addAttr(self.globalCtrl.ctrl, ln='lodDisplay', at='enum', enumName='Low:Mid:High', k=True, defaultValue=0) lodModel = [ 'lowLOD_GRP', 'lowMidLOD_GRP', 'midLOD_GRP', 'midHighLOD_GRP', 'highLOD_GRP' ] for lod in lodModel: if pm.objExists(lod): lodGRP = pm.PyNode(lod) if 'low' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=0) if 'mid' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=0) if 'high' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=1) if 'lowMid' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=0) if 'midHigh' in lod: pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=0, v=0) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=1, v=1) pm.setDrivenKeyframe( lodGRP.visibility, cd=self.globalCtrl.ctrl.lodDisplay, dv=2, v=1) if cmds.objExists('allModel_GRP'): cmds.setAttr("allModel_GRP.visibility", 1) # scale global control self.bbox = self.model.boundingBox() width = self.bbox.width() * 0.3 cvsGlobal = pm.PyNode(self.globalCtrl.ctrl + '.cv[:]') cvsGimbal = pm.PyNode(self.globalCtrl.gimbal + '.cv[:]') pm.scale(cvsGlobal, width, width, width) pm.scale(cvsGimbal, width / 1.5, width / 1.5, width / 1.5) # make display toggle self.displayTransform = pm.circle( name='displayModulesToggleControl', sw=360, nr=(0, 1, 0), ch=0)[0] pm.delete(self.displayTransform.getShape()) displayCurves = pm.PyNode( pm.textCurves(f="Quartz|wt:50|sz:28|sl:n|st:100", t="Display", ch=0, fzn=True)[0]) pm.setAttr(displayCurves.translateX, -1.7) pm.move(0, 0, 0, displayCurves.rotatePivot, p=True, ws=True) pm.move(0, 0, 0, displayCurves.scalePivot, p=True, ws=True) pm.move(0, (self.bbox.height() + (self.bbox.height() * 0.1)), 0, displayCurves, r=True) displayScale = self.bbox[1][0] / 4 pm.scale(displayCurves, displayScale, displayScale, displayScale) allCurves = pm.listRelatives(displayCurves, ad=True, c=True, type="nurbsCurve") parentCurves = [] for crv in allCurves: parentTransform = pm.listRelatives(crv, p=True)[0] pm.parent(parentTransform, w=True) pm.makeIdentity(parentTransform, apply=True, t=1, r=1, s=1) pm.parent(crv, self.displayTransform, shape=True, add=True) parentCurves.append(parentTransform) pm.dgdirty(allPlugs=True) pm.refresh() pm.delete(parentCurves, s=False) pm.delete(displayCurves) pm.parent(self.displayTransform, self.globalCtrl.ctrl) for at in [ 'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ', 'visibility' ]: #getattr(self.displayTransform, at).set(k=False) self.displayTransform.attr(at).set(k=False) self.displayTransform.attr(at).setLocked(True) pm.connectAttr(self.globalCtrl.ctrl + '.scaleX', self.rigGrp.worldScale) pm.hide(self.rigGrp, self.rigModel) pm.addAttr(self.globalCtrl.ctrl, ln='rigAuthor', at='enum', enumName='Jerry:Lee', k=False, dv=0) self.prepareRig() self.createRigModules() self.finishRig() pm.select(cl=True) #self.sup = super(puppet, self) #self.sup.__init__(self.topNode, **kwds) except Exception as e: print "*************************************" print "=========== Error happened =========" raise finally: pm.evaluationManager(mode='parallel') mayaTimer = pm.timer(e=True) pm.undoInfo(state=True) print '' print '' print "END: rigPuppet built in %g seconds" % mayaTimer print ''
guide_set.dagSetMembers, nextAvailable=True) pm.parent(new_curve, parent_object) list_curves_must_transfer.append((curve, new_curve)) else: pm.error( "you must not select other object type then a nurbsCurve transform. Problematic object:" + curve.name()) #yeti needs to trigger to refresh, You need to force the redraw of the viewport + using dirty all just in case #forcing evaluation to let Yeti create his own attributes yeti_node.visibility.set(True) pm.dgdirty(a=True) pm.refresh(f=True) yeti_node.visibility.set(False) pm.dgdirty(a=True) pm.refresh(f=True) #listing the only yeti attributes that an artist would change by himself on a guide important_attr_list = [ '.weight', '.lengthWeight', '.innerRadius', '.outerRadius', '.density', '.baseAttraction', '.tipAttraction', '.attractionBias', '.randomAttraction', '.twist', '.surfaceDirectionLimit', '.surfaceDirectionLimitFalloff' ] #transfering values of old_curves to new_curves for all yeti attributes for old_curve, new_curve in list_curves_must_transfer:
def fkikMatch(fkwrist, fkellbow, fkshldr, ikwrist, ikpv, switchCtrl, switchAttr, switch0isfk=1, switchAttrRange=1, rotOffset=[0, 0, 0], side='R', limb='arm'): ''' Match fk to ik. Recreate the ik chain Args: fkwrist: fkellbow: fkshldr: ikwrist: ikpv: switchCtrl: switchAttr: switch0isfk: rotOffset: Returns: ''' switch = '%s.%s' % (switchCtrl, switchAttr) if pm.objExists('snapGrp'): pm.delete('snapGrp') snapGrp = pm.createNode('transform', name='snapGrp') clist = [] # dup controls to constrain fk_wristDup = pm.duplicate(fkwrist, parentOnly=1, n='fk_wristDup')[0] unlockAttributes([fk_wristDup]) pm.parent(fk_wristDup, snapGrp) # go to fk mode to match correct position if switch0isfk == 0: pm.setAttr(switch, switchAttrRange) # 0 is fk else: pm.setAttr(switch, 0) # store fk keyframes on attribute or not: fkwrist_key, fkellbow_key, fkshldr_key = pm.keyframe(fkwrist, q=1, t=pm.currentTime()),\ pm.keyframe(fkellbow, q=1, t=pm.currentTime()),\ pm.keyframe(fkshldr, q=1, t=pm.currentTime()) # get positions from fk fkwRaw = pm.xform(fkwrist, ws=1, q=1, t=1) fkwPos = om.MVector(fkwRaw[0], fkwRaw[1], fkwRaw[2]) fkeRaw = pm.xform(fkellbow, ws=1, q=1, t=1) fkePos = om.MVector(fkeRaw[0], fkeRaw[1], fkeRaw[2]) fksRaw = pm.xform(fkshldr, ws=1, q=1, t=1) fksPos = om.MVector(fksRaw[0], fksRaw[1], fksRaw[2]) # store rotation fkwRotRaw = pm.xform(fkwrist, q=1, ro=1) fkeRotRaw = pm.xform(fkellbow, q=1, ro=1) fksRotRaw = pm.xform(fkshldr, q=1, ro=1) # zero out fk pm.xform(fkshldr, ro=(0, 0, 0)) pm.xform(fkellbow, ro=(0, 0, 0)) pm.xform(fkwrist, ro=(0, 0, 0)) snap(fkwrist, fk_wristDup) # create orig ik wrist dup to get offset pm.xform(ikwrist, ro=(0, 0, 0)) ik_wristDup = pm.duplicate(ikwrist, parentOnly=1, n='ik_wristDup')[0] unlockAttributes([ik_wristDup]) pm.parent(ik_wristDup, fk_wristDup) snap(fk_wristDup, ik_wristDup, pos=1, rot=1) #snap(ikwrist, ik_wristDup, pos=0, rot=1) ik_wristDupOffset = pm.duplicate(ik_wristDup, parentOnly=1, n='ik_wristDup_offset')[0] pm.parent(ik_wristDupOffset, ik_wristDup) clist.append(pm.parentConstraint(fkwrist, fk_wristDup, mo=0)) # restore fk pm.xform(fkshldr, ro=fksRotRaw) pm.xform(fkellbow, ro=fkeRotRaw) pm.xform(fkwrist, ro=fkwRotRaw) #considering rotation offset pm.setAttr('%s.rx' % ik_wristDupOffset, rotOffset[0]) pm.setAttr('%s.ry' % ik_wristDupOffset, rotOffset[1]) pm.setAttr('%s.rz' % ik_wristDupOffset, rotOffset[2]) # pole vector fkshldr_dup = pm.spaceLocator(n='fkShld_dup') snap(fkshldr, fkshldr_dup) pm.parent(fkshldr_dup, snapGrp) fkellbow_dup = pm.spaceLocator(n='fkEllbow_dup') snap(fkellbow, fkellbow_dup) pm.parent(fkellbow_dup, snapGrp) fkwrist_dup = pm.spaceLocator(n='fkwrist_dup') snap(fkwrist, fkwrist_dup) pm.parent(fkwrist_dup, snapGrp) pvLoc = poleVectorPosition(fkshldr_dup, fkellbow_dup, fkwrist_dup, length=12, createLoc=1) pm.select([fkshldr, fkellbow, fkwrist]) pm.parent(pvLoc, snapGrp) # # snap ik for ctrl in [ikwrist, ikpv]: if len(pm.keyframe(ctrl, q=1)) > 0: pm.cutKey(ctrl, t=pm.currentTime()) snap(ik_wristDupOffset, ikwrist) snap(pvLoc, ikpv, pos=1, rot=0) for ctrl in [ikwrist, ikpv, fkshldr, fkellbow, fkwrist]: if len(pm.keyframe(ctrl, q=1)) > 0: pm.setKeyframe(ctrl, t=pm.currentTime(), s=0) if debug == True: clist.append(pm.parentConstraint(ik_wristDupOffset, ikwrist)) # clean up if debug == False: pm.delete(clist) pm.delete(snapGrp) #pm.delete(pvLoc) #if not debug: pm.delete(fkRotLocWs) # clean up eventually created keyframe on fk ctrl on switch frame if len(fkwrist_key) == 0: try: pm.cutKey(fkwrist, t=pm.currentTime()) except: pass if len(fkellbow_key) == 0: try: pm.cutKey(fkellbow, t=pm.currentTime()) except: pass if len(fkshldr_key) == 0: try: pm.cutKey(fkshldr, t=pm.currentTime()) except: pass # # go to ik mode # if switch0isfk == 0: pm.setAttr(switch, 0) # else: pm.setAttr(switch, switchAttrRange) pm.dgdirty([ikwrist, ikpv]) pm.dgdirty([fkwrist, fkellbow, fkshldr]) logger.info('Done matching FK to IK.')
def ikfkMatch(fkwrist, fkellbow, fkshldr, ikwrist, ikpv, switchCtrl, switchAttr, switch0isfk=1, switchAttrRange=1, rotOffset=[0, 0, 0], side='R', limb='arm', guessUp=1, bendKneeAxis='+X'): ''' Snap fk to ik controls by building ik joint from fk control position and lining up to ik Args: Returns: ''' ns = fkwrist.split(':')[0] switch = '%s.%s' % (switchCtrl, switchAttr) clist = [] if pm.objExists('snapGrp'): pm.delete('snapGrp') snapGrp = pm.createNode('transform', name='snapGrp') # store if keyframe on ik attribute or not: ikwrist_key = pm.keyframe(ikwrist, q=1, t=pm.currentTime()) ikpv_key = pm.keyframe(ikpv, q=1, t=pm.currentTime()) logger.info('matching. switch attr range is %s' % switchAttrRange) # go to fk mode to match correct position (some riggs use same foot ctrl for ik and fk) if switch0isfk == 0: pm.setAttr(switch, switchAttrRange) # 0 is fk else: pm.setAttr(switch, 0) # zero out fk pm.xform(fkshldr, ro=(0, 0, 0)) pm.xform(fkellbow, ro=(0, 0, 0)) pm.xform(fkwrist, ro=(0, 0, 0)) try: pm.xform(fkshldr, t=(0, 0, 0)) except: pass try: pm.xform(fkellbow, t=(0, 0, 0)) except: pass try: pm.xform(fkwrist, t=(0, 0, 0)) except: pass logger.info('root loc') pm.dgdirty([fkshldr, fkellbow, fkwrist]) root_loc = pm.group(empty=1, n='fk_shld_root') pm.parent(root_loc, snapGrp) snap(fkshldr, root_loc) fkshldr_dup = pm.duplicate(fkshldr, parentOnly=1)[0] fkellbow_dup = pm.duplicate(fkellbow, parentOnly=1)[0] fkwrist_dup = pm.duplicate(fkwrist, parentOnly=1)[0] #unlock all of duplicate A's arrtibutes basicTransforms = [ 'translateX', 'translateY', 'translateZ', 'translate', 'rotateX', ' rotateY', 'rotateZ', 'rotate' ] for attr in basicTransforms: #unlock attr pm.setAttr((fkshldr_dup + '.' + attr), lock=False, k=True) pm.setAttr((fkellbow_dup + '.' + attr), lock=False, k=True) pm.setAttr((fkwrist_dup + '.' + attr), lock=False, k=True) pm.select([fkshldr_dup, fkellbow_dup, fkwrist_dup]) logger.info('line up fk duplicates to fk controlssss %s %s %s' % (fkshldr_dup, fkellbow_dup, fkwrist_dup)) # line up fk duplicates to fk controls pm.parent(fkshldr_dup, snapGrp) snap(fkshldr, fkshldr_dup, pos=1, rot=1) pm.parent(fkellbow_dup, fkshldr_dup) snap(fkellbow, fkellbow_dup, pos=1, rot=1) pm.parent(fkwrist_dup, fkellbow_dup) snap(fkwrist, fkwrist_dup, pos=1, rot=1) pm.select(snapGrp) logger.info('snapping fk shoulder to ik') root_ikSnap = pm.joint(n='root_ikSnap', p=pm.xform(fkshldr, t=1, q=1, ws=1), orientation=(0, 0, 0)) pm.parent(root_ikSnap, root_loc) snap(fkshldr, root_ikSnap, rot=1, pos=1) ikshldr_jnt = pm.joint(n='ikshldr_jnt', p=pm.xform(fkshldr, t=1, q=1, ws=1), orientation=(0, 0, 0)) snap(fkellbow, ikshldr_jnt, rot=1, pos=0) try: snap(fkshldr, ikshldr_jnt, rot=0, pos=1) except: pass logger.info('snapping fk ellbow to ik') ikellbow_jnt = pm.joint(n='ikellbow_jnt', p=pm.xform(fkellbow, t=1, q=1, ws=1), orientation=(0, 0, 0)) snap(fkellbow, ikellbow_jnt, rot=1, pos=0) try: snap(fkellbow, ikellbow_jnt, rot=0, pos=1) except: pass logger.info('snapping fk wrist to ik') ikwrist_jnt = pm.joint(n='ikwrist_jnt', p=pm.xform(fkwrist, t=1, q=1, ws=1), orientation=(0, 0, 0)) snap(fkellbow, ikwrist_jnt, rot=1, pos=0) try: snap(fkwrist, ikwrist_jnt, rot=0, pos=1) except: pass #aimaxis = max(pm.getAttr('%s.tx'%ikellbow_jnt), pm.getAttr('%s.tx'%ikellbow_jnt), pm.getAttr('%s.tx'%ikellbow_jnt)) logger.info('freeze transform') pm.makeIdentity(ikshldr_jnt, apply=1) pm.makeIdentity(ikellbow_jnt, apply=1) pm.makeIdentity(ikwrist_jnt, apply=1) multiplyer = 1 if bendKneeAxis[0] == '-': mutliplyer = -1 if abs(pm.getAttr('%s.jointOrient%s' % (ikellbow_jnt, bendKneeAxis[1]))) < 0.1: pm.warning('Warning small joint orient. Setting Prefferec Angle to Y ') pm.setAttr('%s.preferredAngle%s' % (ikellbow_jnt, bendKneeAxis[1]), 12.0 * multiplyer) pm.setAttr('%s.jointOrient%s' % (ikellbow_jnt, bendKneeAxis[1]), 0.01 * multiplyer) # pole vector pole_ikSnap = pm.spaceLocator(n='pole_ikSnap') pm.parent(pole_ikSnap, fkellbow_dup) logger.info('snap pole ik to fkellbow knee bend axis is %s' % bendKneeAxis) # temp pole vector position. use the ellbow could use poleVectorPos as well snap(fkellbow_dup, pole_ikSnap) logger.info('considering kneebendaxis. %s' % bendKneeAxis) reverse = 1 if side == 'L': reverse = -1 if bendKneeAxis == '-X': pole_ikSnap.tz.set(pole_ikSnap.tz.get() + 0.5 * reverse) elif bendKneeAxis == '+X': pole_ikSnap.tz.set(pole_ikSnap.tz.get() - 0.5 * reverse) elif bendKneeAxis == '-Y': pole_ikSnap.tz.set(pole_ikSnap.tz.get() + 0.5 * reverse) elif bendKneeAxis == '+Y': pole_ikSnap.tz.set(pole_ikSnap.tx.get() - 0.5 * reverse) elif bendKneeAxis == '-Z': pole_ikSnap.ty.set(pole_ikSnap.ty.get() - 0.5 * reverse) elif bendKneeAxis == '+Z': pole_ikSnap.ty.set(pole_ikSnap.ty.get() + 0.5 * reverse) pm.parent(pole_ikSnap, snapGrp) # ik handle ikHandle_ikSnap = pm.ikHandle(sj=ikshldr_jnt, ee=ikwrist_jnt, sol='ikRPsolver') pm.parent(ikHandle_ikSnap[0], snapGrp) pm.poleVectorConstraint(pole_ikSnap, ikHandle_ikSnap[0]) logger.info('done polevector constraint') # wrist offset locator line up to zero out ikwrist ikrot = pm.xform(ikwrist, q=1, ro=1) pm.xform(ikwrist, ro=(0, 0, 0)) ikwrist_loc = pm.spaceLocator(n='ikwrist_loc') pm.setAttr('%s.rotateOrder' % ikwrist_loc, pm.getAttr('%s.rotateOrder' % ikwrist)) pm.parent(ikwrist_loc, fkwrist_dup) snap(fkwrist, ikwrist_loc, rot=0, pos=1) snap(fkwrist, ikwrist_loc, rot=1, pos=0) ikwrist_loc_offset = pm.spaceLocator(n='ikwrist_loc_offset') pm.setAttr('%s.rotateOrder' % ikwrist_loc_offset, pm.getAttr('%s.rotateOrder' % ikwrist)) pm.parent(ikwrist_loc_offset, ikwrist_loc) snap(ikwrist_jnt, ikwrist_loc_offset, rot=0, pos=1) snap(fkwrist, ikwrist_loc_offset, rot=1, pos=0) # considering rotation offset (reverse) logger.info('considering rotation offset') fkwrist_rotOrder = pm.getAttr('%s.rotateOrder' % fkwrist) ikwrist_rotOrder = pm.getAttr('%s.rotateOrder' % ikwrist) logger.debug('rotation order ikwrist: %s. fkwrist: %s' % (fkwrist_rotOrder, ikwrist_rotOrder)) pm.setAttr('%s.rx' % ikwrist_loc_offset, rotOffset[0]) pm.setAttr('%s.ry' % ikwrist_loc_offset, rotOffset[1]) pm.setAttr('%s.rz' % ikwrist_loc_offset, rotOffset[2]) # constrain fk ctrl dups to ikSnap locs logger.info('constrain fk ctrl dups to ikSnap locs') clist.append( pm.parentConstraint(ikshldr_jnt, fkshldr_dup, skipTranslate=['x', 'y', 'z'], mo=1)) clist.append( pm.parentConstraint(ikellbow_jnt, fkellbow_dup, skipTranslate=['x', 'y', 'z'], mo=1)) clist.append(pm.parentConstraint(ikwrist_jnt, fkwrist_dup, mo=1)) fkwrist_loc = pm.spaceLocator(n='fkwrist_loc') pm.setAttr('%s.rotateOrder' % fkwrist_loc, pm.getAttr('%s.rotateOrder' % fkwrist)) pm.parent(fkwrist_loc, ikwrist_loc_offset) snap(fkwrist, fkwrist_loc) pm.setAttr('%s.rx' % ikwrist_loc_offset, 0) pm.setAttr('%s.ry' % ikwrist_loc_offset, 0) pm.setAttr('%s.rz' % ikwrist_loc_offset, 0) # rotate back ik logger.info('rotate back ik') pm.xform(ikwrist, ro=ikrot) clist.append(pm.parentConstraint(ikwrist, ikwrist_loc, mo=0)) if debugZero: return # switch to ik mode (some riggs use same foot ctrl for ik and fk) if switch0isfk == 0: pm.setAttr(switch, 0) # 0 is fk else: pm.setAttr(switch, switchAttrRange) # line up to ik wrist and pole logger.info('line up to ik wrist and pole') clist.append(pm.pointConstraint(ikwrist, ikHandle_ikSnap[0])) snap(ikpv, pole_ikSnap, rot=0, pos=1) # get wrist rotation #snap(ikwrist, fkwrist_loc, rot=1, pos=0) # snap(fkshldr_loc, fkshldr, rot=1, pos=0) # snap(fkellbow_loc, fkellbow, rot=1, pos=0) # snap(fkwrist_loc, fkwrist, rot=1, pos=0) logger.debug('snapping back to original fk') # snap back to original fk ctlrs for ctrl in [fkshldr, fkellbow, fkwrist]: if len(pm.keyframe(ctrl, q=1)) > 0: pm.cutKey(ctrl, t=pm.currentTime()) logger.info('snap fk shoulder') snap(fkshldr_dup, fkshldr, rot=1, pos=0) try: snap(fkshldr_dup, fkshldr, pos=1) except: pass logger.info('snap fk ellbow') snap(fkellbow_dup, fkellbow, rot=1, pos=0) try: snap(fkellbow_dup, fkellbow, pos=1) except: pass logger.info('snap fk wrist') snap(fkwrist_loc, fkwrist, rot=1, pos=0) try: snap(fkwrist_loc, fkwrist, pos=1) except: pass for ctrl in [ikwrist, ikpv, fkshldr, fkellbow, fkwrist]: if len(pm.keyframe(ctrl, q=1)) > 0: pm.setKeyframe(ctrl, t=pm.currentTime(), s=0) pm.dgdirty([fkshldr, fkellbow, fkwrist]) # debug mode if debug == True: pm.parentConstraint(fkwrist_loc, fkwrist, mo=0, st=('x', 'y', 'z')) # clean up if debug == False: pm.delete(clist) pm.delete(snapGrp) print("fk controls matched to ik and switch to ik") # clean up eventually created keyframe on ik ctrl on switch frame if len(ikwrist_key) == 0: try: pm.cutKey(ikwrist, t=pm.currentTime()) except: pass if len(ikpv_key) == 0: try: pm.cutKey(ikpv, t=pm.currentTime()) except: pass