Example #1
0
 def rigWrist(self):
     self.m_wristCtrl = rg.stripMiddle(self.m_joints.m_wrist, 0, 1)+"_CTRL"
     self.m_wristCtrl = cmds.spaceLocator(n = self.m_wristCtrl)[0]
     rc.orientControl(self.m_wristCtrl, self.m_joints.m_wrist)
     rg.add3Groups(self.m_wristCtrl, ["_SDK", "_CONST", "_0"])
     cmds.parent(self.m_wristCtrl+"_0", self.m_group, r=1)
     # Add to controls
     rc.addToControlDict(self.m_allControls, "%s_IKWrist" %(self.m_baseName), self.m_wristCtrl)
     rc.addToLayer(self.m_sceneData, "mainCtrl", self.m_wristCtrl)
Example #2
0
 def __init__(self, _sceneData, _joints, _name, _baseName, _isMirrored=False, _twistAxis="y"):
     self.m_sceneData = _sceneData
     self.m_joints = aj.ArmJoints(_joints)
     self.m_name = _name
     self.m_baseName = _baseName
     tmp = rg.stripMiddle(self.m_joints.m_shoulder, 0, 3)
     self.m_group = _name+"_GRP"
     self.m_group = cmds.group(n=self.m_group, em=1)
     cmds.parent(self.m_joints.m_shoulder, self.m_group, r=1)
     self.m_poleVecPinAttr = "polePin"
     self.m_maxStretchAttr = "maxStretchOffset"
     self.m_isMirrored = False
     self.m_twistAxis = _twistAxis
     self.m_allControls = {}
     self.m_isGenerated = False
Example #3
0
    def setupPoleVec(self):
        middleName = rg.stripMiddle(self.m_joints.m_shoulder, 0, 3)
        desiredName = self.m_name+"PoleVec_LOC"
        self.m_poleVec = cmds.spaceLocator(n = desiredName)[0]
        # Add to controls
        rc.addToControlDict(self.m_allControls, "%s_IKPoleVec" %(self.m_baseName), self.m_poleVec)
        rc.addToLayer(self.m_sceneData, "mainCtrl", self.m_poleVec)
        cmds.addAttr(
            self.m_poleVec, 
            ln=self.m_poleVecPinAttr, 
            min=0, 
            max=1, 
            k=True, 
            dv=0
            )
        cmds.addAttr(
            self.m_poleVec, 
            ln=self.m_maxStretchAttr, 
            at = "float", 
            min=0, 
            dv=10, 
            k=1
            )
        self.m_maxStretch = "%s.%s" %(self.m_poleVec, self.m_maxStretchAttr)
        rc.orientControl(self.m_poleVec, self.m_joints.m_elbow1)
        groups = rg.add3Groups(self.m_poleVec, ["_SDK", "_CONST", "_0"])
        cmds.poleVectorConstraint(self.m_poleVec, self.m_ikHandle)
        cmds.parent(groups[-1], self.m_group, r=1)
        # Lock unused attributes
        rc.lockAttrs(
            self.m_poleVec,
            ["scale", "rotate"],
            True,
            False
            )


        axis , offset = self.getPoleVecAxis(2)
        if axis != "":
            cmds.setAttr("%s.t%s" %(groups[1], axis), offset) 

        #Create line
        midGroup = cmds.group(em=1, n=self.m_name+"PoleVec_GRP")
        cmds.parent(midGroup, self.m_group)
        cmds.pointConstraint(self.m_joints.m_elbow1, midGroup)
        cmds.pointConstraint(self.m_joints.m_elbow2, midGroup)
        lineNodes = rc.createLine([self.m_poleVec, midGroup], self.m_sceneData, "mainCtrl")
        cmds.parent(lineNodes[0], self.m_group)
Example #4
0
    def __init__(
            self, 
            _sceneData,
            _joints,
            _name,
            _baseName,
            _controlObject,
            _numUpperControls,
            _numLowerControls,
            _numUpperJoints,
            _numLowerJoints,
            _upperStretchJoint,
            _lowerStretchJoint,
            _isMirrored=False,
            _twistAxis = "y",
            _rigWrist = True,
            ):
        self.m_sceneData = _sceneData
        self.m_isMirrored = _isMirrored
        self.m_joints = aj.ArmJoints(_joints)
        self.m_name = _name
        self.m_baseName = _baseName
        self.m_controlObject = _controlObject
        self.m_twistAxis = _twistAxis
        self.m_rigWrist = _rigWrist
        tmp = rg.stripMiddle(self.m_joints.m_shoulder, 0, 3)
        self.m_group = self.m_name+"_GRP"
        self.m_group = cmds.group(n=self.m_group, em=1)
        cmds.parent(self.m_joints.m_shoulder, self.m_group, r=1)
        #Add transform group
        self.m_mainTransform = rg.addGroup(
            self.m_joints.m_shoulder, 
            "%s_0" %(self.m_joints.m_shoulder)
            )
        self.m_allControls = {}
        self.m_isGenerated = False
        self.m_elbowTwistJoints = []

        # stretch chain parameters
        self.m_numUpperControls = _numUpperControls
        self.m_numLowerControls = _numLowerControls
        self.m_numUpperJoints = _numUpperJoints
        self.m_numLowerJoints = _numLowerJoints
        self.m_upperStretchJoints = _upperStretchJoint
        self.m_lowerStretchJoints = _lowerStretchJoint
Example #5
0
    def connectIKFK(self):
        blendAttrName = "IK_FK_Blend"
        self.m_blendAttr = self.m_blendControl + "." + blendAttrName
        try:
            cmds.setAttr(self.m_blendAttr, 0)
            print "WARNING, IK_FK_Blend attribute already exsits"
        except:
            cmds.addAttr(
                self.m_blendControl, 
                ln=blendAttrName, 
                min = 0, 
                max = 1, 
                k = 1
                )
        self.m_blendAttr = self.m_blendControl + "." + blendAttrName
        self.m_blendOppAttr = rc.create1MinusNode(
            self.m_blendAttr, 
            self.m_name+"_IKFKBlendOpp_CTRL"
            )
        # Attach each joint to BIND
        bindJoints = self.m_bindRig.m_joints
        ikJoints = self.m_ikRig.m_joints
        fkJoints = self.m_fkRig.m_joints
        for i in range(0, len(bindJoints) - 1):
            #Orientation
            const1 = cmds.parentConstraint(
                ikJoints[i], 
                bindJoints[i],
                st = ["x", "y", "z"]
                )
            const1 = const1[0]
            const2 = cmds.parentConstraint(
                fkJoints[i], 
                bindJoints[i],
                st = ["x", "y", "z"]
                )
            const2 = const2[0]
            cmds.connectAttr(
                self.m_blendOppAttr, 
                "%s.blendParent2" %(bindJoints[i])
                )
            # Set rotation method to quarternion
            #   get pair blend node
            pairBlend = cmds.listConnections(
                "%s.constraintRotateX" %(const1), 
                d=True
                )
            pairBlend = pairBlend[0]
            cmds.setAttr("%s.rotInterpolation" %(pairBlend), 1)

        for i in range(1, len(bindJoints)):
            # Connect up blended lengths
            blendedAttr = self.createBlendAttr(
                rg.stripMiddle(ikJoints[i], 0, 1), 
                ikJoints[i] + ".translateX", 
                fkJoints[i] + ".translateX", 
                self.m_blendAttr, self.m_blendOppAttr
                )
            cmds.connectAttr(blendedAttr, bindJoints[i] + ".translateX")

        # Fix wrist rotations
        self.m_bindRig.aimWrist(self.m_ikRig.getIKControl(), [self.m_blendAttr, self.m_blendOppAttr])