Ejemplo n.º 1
0
    def UI(self, parentLayout):
        ikHandleControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":ikHandleControl"

        if cmds.objExists(ikHandleControl):
            controlObjectInstance = controlObject.ControlObject(
                ikHandleControl)
            controlObjectInstance.UI(parentLayout)

            cmds.attrControlGrp(attribute=ikHandleControl + ".stretchiness",
                                label="Stretchiness")

        twistControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":twistControl"

        controlObjectInstance = controlObject.ControlObject(twistControl)
        controlObjectInstance.UI(parentLayout)
Ejemplo n.º 2
0
    def initFKControl(self, joint, spaceSwitchable=False):
        translationControl = False
        jointName = utils.stripAllNamespaces(joint)[1]
        blueprintJoint = self.blueprintNamespace + ":blueprint_" + jointName

        if cmds.objExists(blueprintJoint + "_addTranslate"):
            translationControl = True

        name = jointName + "_fkControl"

        controlObjectInstance = controlObject.ControlObject()

        fkControlInfo = controlObjectInstance.create(
            name,
            "fourArrowControl.ma",
            self,
            lod=1,
            translation=translationControl,
            rotation=True,
            globalScale=False,
            spaceSwitching=spaceSwitchable)
        fkControl = fkControlInfo[0]

        cmds.connectAttr(joint + ".rotateOrder", fkControl + ".rotateOrder")

        return (fkControlInfo[0], fkControlInfo[1], translationControl)
    def createRootEndControl(self, name, orientJoint, posJoint, translation,
                             containedNodes, moduleGrp):
        # Create control object
        controlObjectInstance = controlObject.ControlObject()
        controlObjectInfo = controlObjectInstance.create(
            name,
            "flattenedCube.ma",
            self,
            lod=1,
            translation=translation,
            rotation=True,
            globalScale=False,
            spaceSwitching=True)

        controlObj = controlObjectInfo[0]
        controlParent = controlObjectInfo[1]
        # Create a pre-transform to orient the control
        preTransform = cmds.group(empty=True, n=controlObj + "_preTransform")
        containedNodes.append(preTransform)

        cmds.parent(controlObj, preTransform, relative=True)
        cmds.parent(preTransform, controlParent, relative=True)

        # Get the true worldSpace orientation of the joint
        tempOrientationLocator = cmds.spaceLocator()[0]
        tempOrientConstraint = cmds.orientConstraint(orientJoint,
                                                     tempOrientationLocator,
                                                     maintainOffset=False)[0]

        targetOrientation = cmds.xform(tempOrientationLocator,
                                       q=True,
                                       worldSpace=True,
                                       rotation=True)

        cmds.delete(tempOrientConstraint)
        cmds.delete(tempOrientationLocator)

        cmds.xform(preTransform,
                   worldSpace=True,
                   absolute=True,
                   rotation=targetOrientation)

        cmds.parent(controlParent, moduleGrp, relative=True)
        cmds.setAttr(controlObj + ".rotateOrder",
                     cmds.getAttr(orientJoint + ".rotateOrder"))

        cmds.xform(controlObj,
                   worldSpace=True,
                   absolute=True,
                   translation=cmds.xform(posJoint,
                                          q=True,
                                          worldSpace=True,
                                          translation=True))

        return (controlObj, controlParent)
Ejemplo n.º 4
0
 def UI(self, parentLayout):
     footControl = self.blueprintNamespace+":"+self.moduleNamespace+":footControl"
     
     controlObjectInstance = controlObject.ControlObject(footControl)
     controlObjectInstance.UI(parentLayout)
     
     cmds.attrControlGrp(attribute=footControl+".stretchiness", label="Stretchiness")
     
     circleIK.CircleControlStretchyIK.UI(self, parentLayout)
     
     jointsGrp = self.blueprintNamespace+":"+self.moduleNamespace+":joints_grp"
     joints = utils.findJointChain(jointsGrp)
     
     ballJoint = joints[4]
     toeJoint = joints[5]
     
     for joint in [ballJoint, toeJoint]:
         jointControl = joint+"_ryControl"
         controlObjectInstance = controlObject.ControlObject(jointControl)
         controlObjectInstance.UI(parentLayout)
    def UI(self, parentLayout):
        rootControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":rootControl"
        if cmds.objExists(rootControl):
            controlObjectInstance = controlObject.ControlObject(rootControl)
            controlObjectInstance.UI(parentLayout)

        jointsGrp = self.blueprintNamespace + ":" + self.moduleNamespace + ":joints_grp"
        joints = utils.findJointChain(jointsGrp)

        joints.pop(0)
        joints.pop(0)
        joints.pop()

        for joint in joints:
            offsetControl = joint + "_offsetControl"
            controlObjectInstance = controlObject.ControlObject(offsetControl)
            controlObjectInstance.UI(parentLayout)

        endControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":endControl"
        controlObjectInstance = controlObject.ControlObject(endControl)
        controlObjectInstance.UI(parentLayout)
Ejemplo n.º 6
0
    def UI(self, parentLayout):
        jointsGrp = self.blueprintNamespace + ":" + self.moduleNamespace + ":joints_grp"
        joints = utils.findJointChain(jointsGrp)
        joints.pop(0)
        joints.pop()

        for joint in joints:
            fkControl = joint + "_fkControl"
            controlObjectInstance = controlObject.ControlObject(fkControl)
            controlObjectInstance.UI(parentLayout)

            cmds.attrControlGrp(attribute=fkControl + ".stretch",
                                label="Stretch")
Ejemplo n.º 7
0
    def UI(self, parentLayout):
        armControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":armControl"

        controlObjectInstance = controlObject.ControlObject(armControl)
        controlObjectInstance.UI(parentLayout)

        cmds.attrControlGrp(attribute=armControl + ".stretchiness",
                            label="Stretchiness")

        circleIK.CircleControlStretchyIK.UI(self, parentLayout)

        jointsGrp = self.blueprintNamespace + ":" + self.moduleNamespace + ":joints_grp"
        joints = utils.findJointChain(jointsGrp)
Ejemplo n.º 8
0
 def UI(self, parentLayout):
     jointsGrp = self.blueprintNamespace + ":" + self.moduleNamespace + ":joints_grp"
     
     joints = utils.findJointChain(jointsGrp)
     joints.pop(0)
     
     numJoints = len(joints)
     if numJoints > 1:
         numJoints -= 1
         
     for i in range(numJoints):
         fkControl = joints[i] + "_fkControl"
         controlObjectInstance = controlObject.ControlObject(fkControl)
         controlObjectInstance.UI(parentLayout)
Ejemplo n.º 9
0
    def install_custom(self, joints, moduleGrp, moduleContainer):
        joint = joints[1]
        name = "globalControl"

        controlObjectInstance = controlObject.ControlObject()
        globalControlInfo = controlObjectInstance.create(name,
                                                         "cubeLocator.ma",
                                                         self,
                                                         lod=1,
                                                         translation=True,
                                                         rotation=True,
                                                         globalScale=True,
                                                         spaceSwitching=True)
        globalControl = globalControlInfo[0]
        globalControl_rootParent = globalControlInfo[1]

        # Position and orient control object
        pos = cmds.xform(joint, q=True, worldSpace=True, translation=True)
        orient = cmds.xform(joint, q=True, worldSpace=True, rotation=True)

        cmds.xform(globalControl,
                   worldSpace=True,
                   absolute=True,
                   translation=pos)
        cmds.xform(globalControl,
                   worldSpace=True,
                   absolute=True,
                   rotation=orient)
        """ Try freezing transforms """
        #cmds.makeIdentity(globalControl, apply=True, t=True, r=False, s=False)

        cmds.parent(globalControl_rootParent, moduleGrp, absolute=True)

        cmds.connectAttr(joint + ".rotateOrder",
                         globalControl + ".rotateOrder")

        parentConstraint = cmds.parentConstraint(globalControl,
                                                 joint,
                                                 maintainOffset=False,
                                                 n=joint +
                                                 "_parentConstraint")[0]
        scaleConstraint = cmds.scaleConstraint(globalControl,
                                               joint,
                                               maintainOffset=False,
                                               n=joint + "_scaleConstraint")[0]

        utils.addNodeToContainer(moduleContainer,
                                 [parentConstraint, scaleConstraint])
Ejemplo n.º 10
0
    def install_custom(self, joints, moduleGrp, moduleContainer):
        moduleNamespace = self.blueprintNamespace + ":" + self.moduleNamespace
        """ Assign the joint indices to a variable """
        ankleJoint = joints[3]
        ballJoint = joints[4]
        toeJoint = joints[5]
        """ Create a list of objects that need to be added to a namespace """
        namespaceObjects = []
        """ Get the module positions by creating a temp locator which is parented to each module in turn.
        Use xform on the locator and save it's position to a new variable.
        """
        """ Temp locator used to get the module positions """
        tempLocator = cmds.spaceLocator()[0]
        """ Ball Joint """
        cmds.parent(tempLocator, ballJoint, relative=True)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        ballJoint_modulePos = [
            cmds.getAttr(tempLocator + ".translateX"),
            cmds.getAttr(tempLocator + ".translateY"),
            cmds.getAttr(tempLocator + ".translateZ")
        ]
        """ Ankle Joint """
        cmds.parent(tempLocator, ankleJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator + attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        ankleJoint_modulePos = [
            cmds.getAttr(tempLocator + ".translateX"),
            cmds.getAttr(tempLocator + ".translateY"),
            cmds.getAttr(tempLocator + ".translateZ")
        ]
        """ Toe Joint """
        cmds.parent(tempLocator, toeJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator + attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        toeJoint_modulePos = [
            cmds.getAttr(tempLocator + ".translateX"),
            cmds.getAttr(tempLocator + ".translateY"),
            cmds.getAttr(tempLocator + ".translateZ")
        ]
        """ Delete the temp locator """
        cmds.delete(tempLocator)
        """ containedNodes is an empty list that will store all the nodes that should be added to the animation module container """
        containedNodes = []
        """ Pass in functionality from basic IK """
        ikNodes = circleIK.CircleControlStretchyIK.install_custom(
            self,
            joints,
            moduleGrp,
            moduleContainer,
            createHandleControl=False,
            poleVectorAtRoot=False)
        ikEndPosLocator = ikNodes["endLocator"]
        ikPoleVectorLocator = ikNodes["poleVectorObject"]
        #namespaceObjects.append(ikEndPosLocator)
        #namespaceObjects.append(ikPoleVectorLocator)

        stretchinessAttribute = ikNodes["stretchinessAttribute"]
        """ Import the foot control """
        name = "footControl"
        controlObjectInstance = controlObject.ControlObject()
        footControlInfo = controlObjectInstance.create(name,
                                                       "footControl.ma",
                                                       self,
                                                       lod=1,
                                                       translation=True,
                                                       rotation=True,
                                                       globalScale=False,
                                                       spaceSwitching=True)
        footControl = footControlInfo[0]
        footControlRootParent = footControlInfo[1]
        """ Create control attributes on the foot control """
        footControlAttributes = ('roll', 'roll_break', 'toe_twist',
                                 'ball_twist', 'heel_twist', 'bank',
                                 'toe_flap')
        cmds.select(footControl)
        for attr in footControlAttributes:
            cmds.addAttr(shortName=attr, defaultValue=0.0, k=True)
            self.publishNameToModuleContainer(footControl + '.' + attr,
                                              attr,
                                              publishToOuterContainers=True)

        #footControlAttributes = ('pv_follow')
        #cmds.select(footControl)

        #cmds.addAttr(shortName=footControlAttributes[0], at='enum', en='off:on', k=True)
        """ Publish attributes to the top level character container """
        #self.publishNameToModuleContainer(footControl + '.' + attr, attr, publishToOuterContainers=True)
        """ Parent foot control to root parent"""
        cmds.parent(footControlRootParent, moduleGrp, relative=True)
        """ Position and orient foot control"""
        footControlPos = [
            ankleJoint_modulePos[0], ballJoint_modulePos[1],
            ankleJoint_modulePos[2]
        ]
        cmds.xform(footControl,
                   objectSpace=True,
                   absolute=True,
                   translation=footControlPos)
        """ Position the foot control pivot at the ankle """
        cmds.xform(footControl,
                   ws=True,
                   p=True,
                   piv=[
                       ankleJoint_modulePos[0], ankleJoint_modulePos[1],
                       ankleJoint_modulePos[2]
                   ])

        cmds.setAttr(footControl + ".rotateOrder", 3)  #3 = xyz

        orientationVector = [
            toeJoint_modulePos[0] - ankleJoint_modulePos[0],
            toeJoint_modulePos[2] - ankleJoint_modulePos[2]
        ]

        footControlRotation = atan2(orientationVector[1], orientationVector[0])
        cmds.setAttr(footControl + ".rotateY", -degrees(footControlRotation))

        # Hookup stretchiness attribute
        cmds.select(footControl)
        cmds.addAttr(at="float",
                     minValue=0.0,
                     maxValue=1.0,
                     defaultValue=1.0,
                     keyable=True,
                     longName="stretchiness")
        self.publishNameToModuleContainer(footControl + ".stretchiness",
                                          "stretchiness",
                                          publishToOuterContainers=True)

        cmds.connectAttr(footControl + ".stretchiness",
                         stretchinessAttribute,
                         force=True)
        """ Setup for ball and Toe controls"""
        ballToeControls = []
        ballToeControl_orientGrps = []
        rootParents = []
        for joint in [ankleJoint, ballJoint]:
            controlObjectInstance = controlObject.ControlObject()
            jointName = utils.stripAllNamespaces(joint)[1]
            name = jointName + "_pivotControl"

            ryControlInfo = controlObjectInstance.create(name,
                                                         "needleControl.ma",
                                                         self,
                                                         lod=2,
                                                         translation=True,
                                                         rotation=False,
                                                         globalScale=False,
                                                         spaceSwitching=False)
            ryControl = ryControlInfo[0]
            ryControlRootParent = ryControlInfo[0]

            ballToeControls.append(ryControl)
            rootParents.append(ryControlInfo[0])

            orientGrp = cmds.group(empty=True, n=ryControl + "_orientGrp")
            containedNodes.append(orientGrp)
            ballToeControl_orientGrps.append(orientGrp)

            cmds.parent(ryControl, orientGrp, relative=True)

        cmds.xform(ballToeControl_orientGrps[0],
                   objectSpace=True,
                   absolute=True,
                   translation=ankleJoint_modulePos)
        cmds.xform(ballToeControl_orientGrps[1],
                   objectSpace=True,
                   absolute=True,
                   translation=ballJoint_modulePos)

        heelControlRootParent = rootParents[0]
        bankControlRootParent = rootParents[1]

        for grp in ballToeControl_orientGrps:
            cmds.parent(grp, moduleGrp, absolute=True)
        """ This aligns the leg """
        #cmds.parent(ikEndPosLocator, ballToeControls[0], absolute=True)
        """ Ankle IK """
        ankleIKNodes = cmds.ikHandle(sj=ankleJoint,
                                     ee=ballJoint,
                                     solver="ikSCsolver",
                                     n=ankleJoint + "_ikHandle")
        ankleIKNodes[1] = cmds.rename(ankleIKNodes[1],
                                      ankleIKNodes[1] + "_ikEffector")
        containedNodes.extend(ankleIKNodes)
        namespaceObjects.append(ankleIKNodes[0])
        namespaceObjects.append(ankleIKNodes[1])

        cmds.setAttr(ankleIKNodes[0] + ".visibility", 0)
        """ Ball IK  """
        ballIKNodes = cmds.ikHandle(sj=ballJoint,
                                    ee=toeJoint,
                                    solver="ikSCsolver",
                                    n=ballJoint + "_ikHandle")
        ballIKNodes[1] = cmds.rename(ballIKNodes[1],
                                     ballIKNodes[1] + "_ikEffector")
        containedNodes.extend(ballIKNodes)
        namespaceObjects.append(ballIKNodes[0])
        namespaceObjects.append(ballIKNodes[1])

        cmds.setAttr(ballIKNodes[0] + ".visibility", 0)

        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
        """ Empty the contained nodes list """
        containedNodes = []
        """ Create the IK_Groups """
        ikGroups = []
        """ These groups go at the ankle """
        ikGrp = cmds.group(em=True, name='footIK_grp')
        cmds.xform(ikGrp, a=True, t=ankleJoint_modulePos)
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
        """ These go at the ball """
        groupNames = ('bank_grp', 'ballTwist_grp', 'ballRoll_grp',
                      'toeFlap_grp')
        for group in groupNames:
            cmds.group(em=True, name=group)
            cmds.xform(group, a=True, t=ballJoint_modulePos)
            ikGroups.append(group)
            containedNodes.append(group)
        """ These go at the toe """
        ikGrp = cmds.group(em=True, name='toeRoll_grp')
        cmds.xform(ikGrp, a=True, t=toeJoint_modulePos)
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
        """ Create a heel roll group """
        """ TODO:  How do I get this to sit at the heel without adding a joint for it? """
        ikGrp = cmds.group(em=True, name='heelRoll_grp')
        cmds.xform(ikGrp,
                   a=True,
                   t=(ankleJoint_modulePos[0], 0, ankleJoint_modulePos[2]))
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
        """ Create 3 locators to be used for roll attribute """
        rollLctrs = []
        dynRollLctr = cmds.spaceLocator(name='dynRoll_lctr')[0]
        cmds.xform(dynRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(dynRollLctr)
        containedNodes.append(dynRollLctr)

        statRollLctr = cmds.spaceLocator(name='statRoll_lctr')[0]
        cmds.xform(statRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(statRollLctr)
        containedNodes.append(statRollLctr)
        """ heelRoll_lctr """
        heelRollLctr = cmds.spaceLocator(name='heelRoll_lctr')[0]
        cmds.xform(heelRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(heelRollLctr)
        containedNodes.append(heelRollLctr)

        for locator in rollLctrs:
            cmds.setAttr(locator + '.visibility', 0)
        """ Parent the adjustment controls to the foot control """
        cmds.parent(heelControlRootParent, ikGroups[3], absolute=True)
        cmds.makeIdentity(heelControlRootParent, apply=True, translate=True)
        cmds.parent(bankControlRootParent, ikGroups[3], absolute=True)
        """ Parent the ikHandles under the appropriate group """
        cmds.parent(ankleIKNodes[0], ikGroups[3])
        cmds.parent(ikEndPosLocator, ikGroups[3])

        cmds.parent(ballIKNodes[0], ikGroups[4])

        cmds.parent(ikGroups[3], ikGroups[5])  #ballRoll  toeRoll
        cmds.parent(ikGroups[4], ikGroups[5])  #toeFlap toeRoll
        cmds.parent(ikGroups[5], ikGroups[2])  #toeRoll  ballTwist
        cmds.parent(ikGroups[2], ikGroups[1])  #ballTwist  bank
        cmds.parent(ikGroups[1], ikGroups[6])  #bank  heelRoll
        cmds.parent(ikGroups[6], ikGroups[0])  #heelRoll  footIK

        cmds.parent(dynRollLctr, ikGroups[0])
        cmds.parent(heelRollLctr, ikGroups[0])
        cmds.parent(statRollLctr, ikGroups[6])
        """ Parent constrain ball and toe groups to roll_lctrs """
        parentConstraints = []
        rollParentConstraint = cmds.parentConstraint(dynRollLctr,
                                                     ikGroups[3],
                                                     mo=True,
                                                     st=('x', 'y', 'z'),
                                                     sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(statRollLctr,
                                                     ikGroups[3],
                                                     mo=True,
                                                     st=('x', 'y', 'z'),
                                                     sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(statRollLctr,
                                                     ikGroups[5],
                                                     mo=True,
                                                     st=('x', 'y', 'z'),
                                                     sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(dynRollLctr,
                                                     ikGroups[5],
                                                     mo=True,
                                                     st=('x', 'y', 'z'),
                                                     sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])

        for constraint in parentConstraints:
            print constraint
            newName = moduleNamespace + ':' + constraint
            cmds.rename(constraint, newName)
        """ Create a remap value node to control foot roll """
        cmds.createNode('remapValue', name='roll_rv')
        cmds.setAttr('roll_rv.inputMax', 180.0)
        """ Connect to the remap value node """
        """" Connect the output of dynRollLctr to roll_rv input value """
        cmds.connectAttr(dynRollLctr + '.rx', 'roll_rv.inputValue')
        """ roll_break to input min """
        cmds.setAttr(footControl + '.roll_break', 45.0)
        cmds.connectAttr(footControl + '.roll_break', 'roll_rv.inputMin')
        """ roll_break to parent constraint switches """
        cmds.connectAttr('roll_rv.outColorG', ikGroups[3] + '.blendParent2')
        cmds.connectAttr('roll_rv.outColorR', ikGroups[5] + '.blendParent2')
        namespaceObjects.append('roll_rv')
        """ constrain the heelRoll_grp to heelRoll_lctr.  Switch off the constraint when greater than 0 """
        cmds.createNode('condition', name='roll_cond')
        heelOrientConstraint = cmds.orientConstraint(heelRollLctr,
                                                     ikGroups[6],
                                                     skip=('y', 'z'),
                                                     mo=True)
        heelOrientAttr = (heelOrientConstraint[0] + '.' + heelRollLctr + 'W0')
        cmds.connectAttr('roll_cond.outColorR', heelOrientAttr)
        cmds.connectAttr(heelRollLctr + '.rx', 'roll_cond.firstTerm')
        cmds.setAttr('roll_cond.operation', 3)
        newName = moduleNamespace + ':' + heelOrientConstraint[0]
        cmds.rename(heelOrientConstraint[0], newName)
        namespaceObjects.append('roll_cond')
        """ Connect the foot attributes to respective groups and locators """
        cmds.connectAttr(footControl + ".roll", heelRollLctr + '.rx')
        cmds.connectAttr(footControl + ".roll", 'dynRoll_lctr.rx')
        cmds.connectAttr(footControl + ".toe_twist", 'toeRoll_grp.ry')
        cmds.connectAttr(footControl + ".ball_twist", 'ballTwist_grp.ry')
        cmds.connectAttr(footControl + ".heel_twist", 'heelRoll_grp.ry')
        cmds.connectAttr(footControl + ".bank", 'bank_grp.rz')
        cmds.connectAttr(footControl + ".toe_flap", 'toeFlap_grp.rx')
        """ Connect pivot controls to the rotatePivot of appropriate group """
        cmds.connectAttr(rootParents[1] + '.translate', 'bank_grp.rotatePivot')
        cmds.connectAttr(rootParents[0] + '.translate',
                         'heelRoll_grp.rotatePivot')
        """ Parent the footIK_grp to the foot control """
        cmds.parent('footIK_grp', footControl, absolute=True)

        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)

        for node in containedNodes:
            newName = moduleNamespace + ':' + node
            cmds.rename(node, newName)
        """ Add the namespaceObjects to the moduleNamespace """

        for node in namespaceObjects:
            print node
            newName = moduleNamespace + ':' + node
            cmds.rename(node, newName)
Ejemplo n.º 11
0
    def install_custom(self,
                       joints,
                       moduleGrp,
                       moduleContainer,
                       createHandleControl=True,
                       poleVectorAtRoot=True):
        rootJoint = joints[1]
        hingeJoint = joints[2]
        endJoint = joints[3]

        containedNodes = []

        twistRotationAimer = cmds.group(empty=True,
                                        n=rootJoint + "_twistRotationAimer")
        containedNodes.append(twistRotationAimer)

        containedNodes.append(
            cmds.pointConstraint(rootJoint,
                                 twistRotationAimer,
                                 maintainOffset=False,
                                 n=twistRotationAimer + "_pointConstraint")[0])
        cmds.pointConstraint(endJoint,
                             twistRotationAimer,
                             maintainOffset=False)

        upVectorTarget = cmds.group(empty=True,
                                    n=rootJoint +
                                    "_twistRotationAimer_upVectorTarget")
        containedNodes.append(upVectorTarget)

        cmds.parent(upVectorTarget, hingeJoint, relative=True)
        cmds.setAttr(upVectorTarget + ".translateZ",
                     cmds.getAttr(hingeJoint + ".translateX"))

        containedNodes.append(
            cmds.aimConstraint(endJoint,
                               twistRotationAimer,
                               maintainOffset=False,
                               n=twistRotationAimer + "_aimConstraint",
                               aimVector=[0.0, 0.0, 1.0],
                               upVector=[1.0, 0.0, 0.0],
                               worldUpType="object",
                               worldUpObject=upVectorTarget)[0])

        tempLocator = cmds.spaceLocator()[0]
        cmds.parent(tempLocator, twistRotationAimer, relative=True)
        cmds.setAttr(tempLocator + ".translateY", 10)

        twistRotationAimerPos = cmds.xform(twistRotationAimer,
                                           q=True,
                                           worldSpace=True,
                                           translation=True)
        tempLocatorPos = cmds.xform(tempLocator,
                                    q=True,
                                    worldSpace=True,
                                    translation=True)

        offsetVector = [
            tempLocatorPos[0] - twistRotationAimerPos[0],
            tempLocatorPos[1] - twistRotationAimerPos[1],
            tempLocatorPos[2] - twistRotationAimerPos[2]
        ]

        cmds.delete(tempLocator)

        ikNodes = utils.basic_stretchy_IK(
            rootJoint,
            endJoint,
            container=moduleContainer,
            scaleCorrectionAttribute=self.blueprintNamespace +
            ":module_grp.hierarchicalScale")
        ikHandle = ikNodes["ikHandle"]
        rootPosLocator = ikNodes["rootLocator"]
        endPosLocator = ikNodes["endLocator"]
        poleVectorLocator = ikNodes["poleVectorObject"]
        stretchinessAttribute = ikNodes["stretchinessAttribute"]

        for node in [
                ikHandle, rootPosLocator, endPosLocator, poleVectorLocator
        ]:
            cmds.parent(node, moduleGrp, absolute=True)

        if poleVectorAtRoot:
            poleVectorPos = cmds.xform(rootJoint,
                                       q=True,
                                       worldSpace=True,
                                       translation=True)
        else:
            poleVectorPos = cmds.xform(endJoint,
                                       q=True,
                                       worldSpace=True,
                                       translation=True)

        poleVectorPos[0] += offsetVector[0]
        poleVectorPos[1] += offsetVector[1]
        poleVectorPos[2] += offsetVector[2]
        cmds.xform(poleVectorLocator,
                   worldSpace=True,
                   absolute=True,
                   translation=poleVectorPos)

        if createHandleControl:
            name = "ikHandleControl"

            controlObjectInstance = controlObject.ControlObject()
            handleControlInfo = controlObjectInstance.create(
                name,
                "cubeLocator.ma",
                self,
                lod=1,
                translation=True,
                rotation=True,
                globalScale=False,
                spaceSwitching=True)
            handleControl = handleControlInfo[0]
            handleRootParent = handleControlInfo[1]

            cmds.parent(handleRootParent, moduleGrp, relative=True)
            cmds.xform(handleControl,
                       worldSpace=True,
                       absolute=True,
                       translation=cmds.xform(endPosLocator,
                                              q=True,
                                              worldSpace=True,
                                              translation=True))

            pointConstraint = cmds.pointConstraint(handleControl,
                                                   endPosLocator,
                                                   maintainOffset=False,
                                                   n=endPosLocator +
                                                   "_pointConstraint")[0]
            containedNodes.append(pointConstraint)

            cmds.select(handleControl)
            cmds.addAttr(at="float",
                         minValue=0.0,
                         maxValue=1.0,
                         defaultValue=1.0,
                         keyable=True,
                         longName="stretchiness")
            cmds.connectAttr(handleControl + ".stretchiness",
                             stretchinessAttribute)

            self.publishNameToModuleContainer(handleControl + ".stretchiness",
                                              "stretchiness",
                                              publishToOuterContainers=True)

        rotationCancellation = cmds.group(empty=True,
                                          n=self.blueprintNamespace + ":" +
                                          self.moduleNamespace +
                                          ":twistRotationCancellation")
        containedNodes.append(rotationCancellation)

        cmds.parent(rotationCancellation, twistRotationAimer, relative=True)

        twistControlOffset = cmds.group(empty=True,
                                        n=self.blueprintNamespace + ":" +
                                        self.moduleNamespace +
                                        ":twistControlOffset")
        containedNodes.append(twistControlOffset)

        cmds.parent(twistControlOffset, rotationCancellation, relative=True)

        twistControlObjectInstance = controlObject.ControlObject()
        twistControlInfo = twistControlObjectInstance.create(
            "twistControl",
            "zAxisCircle.ma",
            self,
            lod=2,
            translation=False,
            rotation=[False, False, True],
            globalScale=False,
            spaceSwitching=True)
        twistControl = twistControlInfo[0]

        cmds.parent(twistControl, twistControlOffset, relative=True)
        cmds.connectAttr(twistControl + ".rotateZ", ikHandle + ".twist")

        pivotMultNode = cmds.shadingNode("multiplyDivide",
                                         asUtility=True,
                                         n=twistControl + "_invertOffset")
        containedNodes.append(pivotMultNode)

        cmds.connectAttr(twistControlOffset + ".translateX",
                         pivotMultNode + ".input1X")
        cmds.setAttr(pivotMultNode + ".input2X", -1)
        cmds.connectAttr(pivotMultNode + ".output",
                         twistControl + ".rotatePivot")

        multNode = cmds.shadingNode("multiplyDivide",
                                    asUtility=True,
                                    n=rotationCancellation + "_invertRotateZ")
        containedNodes.append(multNode)

        cmds.connectAttr(twistControl + ".rotateZ", multNode + ".input1X")
        cmds.setAttr(multNode + ".input2X", -1)
        cmds.connectAttr(multNode + ".outputX",
                         rotationCancellation + ".rotateZ")

        cmds.parent(twistRotationAimer, moduleGrp, absolute=True)

        ikJoints = [joints[1], joints[2], joints[3]]

        jointName = utils.stripAllNamespaces(joints[1])[1]
        creationPoseRoot = self.blueprintNamespace + ":creationPose_" + jointName
        creationPoseJoints = utils.findJointChain(creationPoseRoot)

        targetJoints = [
            creationPoseJoints[0], creationPoseJoints[1], creationPoseJoints[2]
        ]

        utils.matchTwistAngle(twistControl + ".rotateZ", ikJoints,
                              targetJoints)

        offsetNode = cmds.shadingNode("plusMinusAverage",
                                      asUtility=True,
                                      n=twistControl + "_twistOffset")
        containedNodes.append(offsetNode)

        cmds.setAttr(offsetNode + ".input1D[0]",
                     cmds.getAttr(twistControl + ".rotateZ"))
        cmds.connectAttr(twistControl + ".rotateZ", offsetNode + ".input1D[1]")
        cmds.connectAttr(offsetNode + ".output1D",
                         ikHandle + ".twist",
                         force=True)

        utils.forceSceneUpdate()
        cmds.setAttr(twistControl + ".rotateZ", 0)

        utils.addNodeToContainer(moduleContainer, containedNodes)

        self.publishNameToModuleContainer(twistControlOffset + ".translateX",
                                          "twistControlOffset",
                                          publishToOuterContainers=True)

        cmds.setAttr(moduleGrp + ".lod", 2)

        return (ikNodes)
Ejemplo n.º 12
0
    def install_custom(self, joints, moduleGrp, moduleContainer):
        wristJoint = joints[3]
        handJoint = joints[4]
        """ The temp locator is used to find the position of each joint """
        tempLocator = cmds.spaceLocator()[0]
        cmds.parent(tempLocator, handJoint, relative=True)
        cmds.parent(tempLocator, moduleGrp, absolute=True)

        handJoint_modulePos = [
            cmds.getAttr(tempLocator + ".translateX"),
            cmds.getAttr(tempLocator + ".translateY"),
            cmds.getAttr(tempLocator + ".translateZ")
        ]

        cmds.parent(tempLocator, wristJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator + attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)

        wristJoint_modulePos = [
            cmds.getAttr(tempLocator + ".translateX"),
            cmds.getAttr(tempLocator + ".translateY"),
            cmds.getAttr(tempLocator + ".translateZ")
        ]

        cmds.delete(tempLocator)

        containedNodes = []
        """ Pass in functionality from basic IK  """
        ikNodes = circleIK.CircleControlStretchyIK.install_custom(
            self,
            joints,
            moduleGrp,
            moduleContainer,
            createHandleControl=False,
            poleVectorAtRoot=False)
        ikEndPosLocator = ikNodes["endLocator"]
        ikPoleVectorLocator = ikNodes["poleVectorObject"]

        stretchinessAttribute = ikNodes["stretchinessAttribute"]

        name = "armControl"
        controlObjectInstance = controlObject.ControlObject()
        handControlInfo = controlObjectInstance.create(name,
                                                       "handControl.ma",
                                                       self,
                                                       lod=1,
                                                       translation=True,
                                                       rotation=True,
                                                       globalScale=False,
                                                       spaceSwitching=True)
        handControl = handControlInfo[0]
        handControlRootParent = handControlInfo[1]
        """ Parent foot control to root parent """
        cmds.parent(handControlRootParent, moduleGrp, relative=True)
        """ Position and orient foot control """
        handControlPos = [
            wristJoint_modulePos[0], handJoint_modulePos[1],
            wristJoint_modulePos[2]
        ]
        cmds.xform(handControl,
                   objectSpace=True,
                   absolute=True,
                   translation=handControlPos)

        cmds.setAttr(handControl + ".rotateOrder", 3)  #3 = xyz

        orientationVector = [
            handJoint_modulePos[0] - wristJoint_modulePos[0],
            handJoint_modulePos[2] - wristJoint_modulePos[2]
        ]

        handControlRotation = atan2(orientationVector[1], orientationVector[0])
        cmds.setAttr(handControl + ".rotateY", -degrees(handControlRotation))

        pointConstraint = cmds.pointConstraint(handControl,
                                               ikEndPosLocator,
                                               maintainOffset=False,
                                               n=ikEndPosLocator +
                                               "_pointConstraint")[0]
        containedNodes.append(pointConstraint)
        """ Hookup stretchiness attribute """
        cmds.select(handControl)
        cmds.addAttr(at="float",
                     minValue=0.0,
                     maxValue=1.0,
                     defaultValue=1.0,
                     keyable=True,
                     longName="stretchiness")
        self.publishNameToModuleContainer(handControl + ".stretchiness",
                                          "stretchiness",
                                          publishToOuterContainers=True)

        cmds.connectAttr(handControl + ".stretchiness",
                         stretchinessAttribute,
                         force=True)
        """ Hand IK """
        handIKNodes = cmds.ikHandle(sj=wristJoint,
                                    ee=handJoint,
                                    solver="ikRPsolver",
                                    n=handJoint + "_ikHandle")
        handIKNodes[1] = cmds.rename(handIKNodes[1],
                                     handIKNodes[1] + "_ikEffector")
        containedNodes.extend(handIKNodes)

        cmds.parent(handIKNodes[0], handControl)
        cmds.setAttr(handIKNodes[0] + ".visibility", 0)

        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
    def install_custom(self, joints, moduleGrp, moduleContainer):
        result = cmds.confirmDialog(
            title="Interpolation-based Stretchy Spline",
            message="please specify the root control type:",
            button=["Translation and Rotation", "Rotation Only", "None"],
            defaultButton="Translation and Rotation",
            cancelButton="None",
            dismissString="None")

        rootControlTranslation = (result == "Translation and Rotation")
        createRootControl = not (result == "None")

        containedNodes = []

        creationPoseJoints = []
        for joint in joints:
            jointName = utils.stripAllNamespaces(joint)[1]
            creationPoseJoint = self.blueprintNamespace + ":creationPose_" + jointName
            creationPoseJoints.append(creationPoseJoint)

        # Create root and end controls
        rootControlObject = moduleGrp
        if createRootControl:
            rootControlObjectInfo = self.createRootEndControl(
                "rootControl", creationPoseJoints[1], creationPoseJoints[1],
                rootControlTranslation, containedNodes, moduleGrp)

            #"Return Tuple.  [0] is object, [1] parent"
            rootControlObject = rootControlObjectInfo[0]
            rootControlParent = rootControlObjectInfo[1]

            if not rootControlTranslation:
                containedNodes.append(
                    cmds.pointConstraint(moduleGrp,
                                         rootControlParent,
                                         maintainOffset=True)[0])
        # Orient end joint based off second to last joint
        endControlObjectInfo = self.createRootEndControl(
            "endControl", creationPoseJoints[len(creationPoseJoints) - 2],
            creationPoseJoints[len(creationPoseJoints) - 1], True,
            containedNodes, moduleGrp)
        endControlObject = endControlObjectInfo[0]

        # Setup splineIK
        # Duplicate stretchyIKJoints and rename
        stretchyIKJoints = cmds.duplicate(joints, renameChildren=True)
        index = 0
        for joint in stretchyIKJoints:
            stretchyIKJoints[index] = cmds.rename(
                joint, joints[index] + "_stretchyIKJoint")
            index += 1

        containedNodes.extend(stretchyIKJoints)

        # Get the ws position of the root and end joints
        rootJoint = stretchyIKJoints[1]
        endJoint = stretchyIKJoints[len(stretchyIKJoints) - 1]
        secondJoint = stretchyIKJoints[2]
        secondToLastJoint = stretchyIKJoints[len(stretchyIKJoints) - 2]

        rootPos = cmds.xform(rootJoint, q=True, ws=True, translation=True)
        endPos = cmds.xform(endJoint, q=True, ws=True, translation=True)

        rootLocator = cmds.spaceLocator(n=stretchyIKJoints[0] +
                                        "_systemStretch_rootLocator")[0]
        cmds.xform(rootLocator, ws=True, absolute=True, translation=rootPos)
        #containedNodes.append(rootLocator)

        endLocator = cmds.spaceLocator(n=stretchyIKJoints[0] +
                                       "_systemStretch_endLocator")[0]
        cmds.xform(endLocator, ws=True, absolute=True, translation=endPos)
        #containedNodes.append(endLocator)

        # Hide locators
        for loc in [rootLocator, endLocator]:
            cmds.setAttr(loc + ".visibility", 0)

        #parent locators to controls
        cmds.parent(rootLocator, rootControlObject, absolute=True)
        cmds.parent(endLocator, endControlObject, absolute=True)

        index = 0
        for joint in stretchyIKJoints:
            if index > 2 and index < len(stretchyIKJoints) - 1:
                cmds.select(stretchyIKJoints[index], replace=True)
                cmds.addAttr(at="float", longName="originalLength")
                originalLength = cmds.getAttr(stretchyIKJoints[index] +
                                              ".translateX")
                cmds.setAttr(stretchyIKJoints[index] + ".originalLength",
                             originalLength)

            index += 1

        # Setup the scale factor
        scaleFactorAttr = self.createDistanceCalculations(
            rootLocator, endLocator, containedNodes)

        rootScaler = self.createScalar(rootLocator, scaleFactorAttr,
                                       containedNodes)
        endScaler = self.createScalar(endLocator, scaleFactorAttr,
                                      containedNodes)

        rootIKLocators = self.setupBasicStretchyIK(rootJoint, secondJoint,
                                                   creationPoseJoints[1],
                                                   rootControlObject,
                                                   moduleContainer, moduleGrp)
        rootIK_rootLocator = rootIKLocators[0]
        rootIK_endLocator = rootIKLocators[1]

        cmds.parent(rootIK_endLocator, rootScaler, absolute=True)

        endIKLocators = self.setupBasicStretchyIK(
            secondToLastJoint, endJoint,
            creationPoseJoints[len(creationPoseJoints) - 2], endControlObject,
            moduleContainer, moduleGrp)
        endIK_rootLocator = endIKLocators[0]
        endIK_endLocator = endIKLocators[1]

        cmds.parent(endIK_endLocator, endControlObject, absolute=True)

        ikNodes = cmds.ikHandle(sj=secondJoint,
                                ee=secondToLastJoint,
                                n=secondJoint + "_splineIKHandle",
                                sol="ikSplineSolver",
                                rootOnCurve=False,
                                createCurve=True)

        ikNodes[1] = cmds.rename(ikNodes[1], secondJoint + "_splineIKEffector")
        ikNodes[2] = cmds.rename(ikNodes[2], secondJoint + "_splineIKCurve")

        splineIKhandle = ikNodes[0]
        splineIKCurve = ikNodes[2]

        containedNodes.extend(ikNodes)

        cmds.parent(splineIKhandle, moduleGrp, absolute=True)
        cmds.setAttr(splineIKhandle + ".visibility", 0)
        cmds.setAttr(splineIKCurve + ".visibility", 0)

        cmds.parent(splineIKCurve, world=True, absolute=True)
        cmds.setAttr(splineIKCurve + ".inheritsTransform", 0)
        cmds.parent(splineIKCurve, moduleGrp, relative=True)

        # Create a cluster for the CV's on the curve.
        cmds.select(splineIKCurve + ".cv[0:1]", replace=True)
        clusterNodes = cmds.cluster(n=splineIKCurve + "_rootCluster")
        cmds.container(moduleContainer,
                       edit=True,
                       addNode=clusterNodes,
                       ihb=True,
                       includeNetwork=True)
        rootClusterHandle = clusterNodes[1]

        cmds.select(splineIKCurve + ".cv[2:3]", replace=True)
        clusterNodes = cmds.cluster(n=splineIKCurve + "_endCluster")
        cmds.container(moduleContainer,
                       edit=True,
                       addNode=clusterNodes,
                       ihb=True,
                       includeNetwork=True)
        endClusterHandle = clusterNodes[1]

        for handle in [rootClusterHandle, endClusterHandle]:
            cmds.setAttr(handle + ".visibility", 0)

        cmds.parent(rootClusterHandle, rootScaler, absolute=True)
        cmds.parent(endClusterHandle, endScaler, absolute=True)

        containedNodes.append(
            cmds.parentConstraint(rootControlObject,
                                  rootJoint,
                                  maintainOffset=True)[0])

        targetLocatorNodes = cmds.duplicate(endIK_rootLocator,
                                            name=endIK_rootLocator +
                                            "_duplicateTarget")
        targetLocator = targetLocatorNodes[0]
        cmds.delete(targetLocatorNodes[1])
        cmds.parent(targetLocator, endScaler, absolute=True)

        splineScaleFactorAttr = self.createDistanceCalculations(
            rootIK_endLocator, targetLocator, containedNodes)

        # Use scaleFactor on each of the joints
        index = 0
        for joint in stretchyIKJoints:
            if index > 2 and index < len(stretchyIKJoints) - 1:
                multNode = cmds.shadingNode("multiplyDivide",
                                            asUtility=True,
                                            n=joint + "_jointScale")
                containedNodes.append(multNode)
                cmds.connectAttr(scaleFactorAttr, multNode + ".input1X")
                cmds.setAttr(multNode + ".input2X",
                             cmds.getAttr(joint + ".originalLength"))

                cmds.connectAttr(multNode + ".outputX", joint + ".translateX")
            index += 1

        cmds.setAttr(splineIKhandle + ".dTwistControlEnable", 1)
        cmds.setAttr(splineIKhandle + ".dWorldUpType", 4)
        cmds.setAttr(splineIKhandle + ".dWorldUpAxis", 5)

        cmds.setAttr(splineIKhandle + ".dWorldUpVector",
                     0.0,
                     0.0,
                     1.0,
                     type="double3")
        cmds.setAttr(splineIKhandle + ".dWorldUpVectorEnd",
                     0.0,
                     0.0,
                     1.0,
                     type="double3")

        if createRootControl:
            cmds.connectAttr(rootControlObject + ".worldMatrix[0]",
                             splineIKhandle + ".dWorldUpMatrix")
        else:
            dummyNode = cmds.duplicate(rootJoint,
                                       parentOnly=True,
                                       n=rootJoint + "_dummyDuplicate")[0]
            containedNodes.append(dummyNode)
            cmds.parent(dummyNode, moduleGrp, absolute=True)
            cmds.connectAttr(dummyNode + ".worldMatrix[0]",
                             splineIKhandle + ".dWorldUpMatrix")

        cmds.connectAttr(endControlObject + ".worldMatrix[0]",
                         splineIKhandle + ".dWorldUpMatrixEnd")
        # Create 2 attributes for "offsetY and offsetZ".
        cmds.select(moduleGrp)
        cmds.addAttr(at="float",
                     defaultValue=0.0,
                     softMinValue=-10.0,
                     softMaxValue=10.0,
                     keyable=True,
                     longName="offsetY")
        cmds.addAttr(at="float",
                     defaultValue=0.0,
                     softMinValue=-10.0,
                     softMaxValue=10.0,
                     keyable=True,
                     longName="offsetZ")
        # Publish new attrs to container
        self.publishNameToModuleContainer(moduleGrp + ".offsetY",
                                          "interpolator_offsetY",
                                          publishToOuterContainers=True)
        self.publishNameToModuleContainer(moduleGrp + ".offsetZ",
                                          "interpolator_offsetZ",
                                          publishToOuterContainers=True)
        # Create a node to inverse offset
        inverseNode = cmds.shadingNode("multiplyDivide",
                                       asUtility=True,
                                       n=moduleGrp + "_offsetInverse")
        containedNodes.append(inverseNode)

        cmds.connectAttr(moduleGrp + ".offsetY", inverseNode + ".input1Y")
        cmds.connectAttr(moduleGrp + ".offsetZ", inverseNode + ".input1Z")
        cmds.setAttr(inverseNode + ".input2Y", -1)
        cmds.setAttr(inverseNode + ".input2Z", -1)
        # Setup interpolators
        numStretchyIKJoints = len(stretchyIKJoints) - 1

        interpolators_ikParents = []
        aimChildren = []

        for i in range(1, numStretchyIKJoints):
            if i > 1:
                # Create a group to follow each joint
                jointFollower = cmds.group(empty=True,
                                           n=stretchyIKJoints[i] + "_follower")
                containedNodes.append(jointFollower)
                # Parent the group to the joint we are following
                cmds.parent(jointFollower, moduleGrp, relative=True)
                containedNodes.append(
                    cmds.parentConstraint(stretchyIKJoints[i],
                                          jointFollower,
                                          maintainOffset=False,
                                          n=jointFollower +
                                          "_parentConstraint")[0])

                offset = cmds.group(empty=True,
                                    n=stretchyIKJoints[i] +
                                    "_interpolatorOffset")
                containedNodes.append(offset)
                # parent the offset group to the follower group
                cmds.parent(offset, jointFollower, relative=True)

                cmds.connectAttr(moduleGrp + ".offsetY",
                                 offset + ".translateY")
                cmds.connectAttr(moduleGrp + ".offsetZ",
                                 offset + ".translateZ")

                name = utils.stripAllNamespaces(
                    joints[i])[1] + "_offsetControl"
                controlObjectInstance = controlObject.ControlObject()
                offsetControlObject = controlObjectInstance.create(
                    name,
                    "cubeLocator.ma",
                    self,
                    lod=2,
                    translation=True,
                    rotation=False,
                    globalScale=False,
                    spaceSwitching=False)[0]
                # parent control object under offset group
                cmds.parent(offsetControlObject, offset, relative=True)

                offsetCancelation = cmds.group(empty=True,
                                               n=stretchyIKJoints[i] +
                                               "interpolatorOffsetCancelation")
                containedNodes.append(offsetCancelation)
                cmds.parent(offsetCancelation,
                            offsetControlObject,
                            relative=True)

                cmds.connectAttr(inverseNode + ".outputY",
                                 offsetCancelation + ".translateY")
                cmds.connectAttr(inverseNode + ".outputZ",
                                 offsetCancelation + ".translateZ")

                interpolators_ikParents.append(offsetCancelation)

            aimChild = cmds.group(empty=True,
                                  n=stretchyIKJoints[i] + "_aimChild")
            containedNodes.append(aimChild)
            aimChildren.append(aimChild)

            if i > 1:
                cmds.parent(aimChild, offsetCancelation, relative=True)
                print "parent offset cancel"
            else:
                cmds.parent(aimChild, stretchyIKJoints[i], relative=True)

            cmds.setAttr(aimChild + ".translateY", -1)
        # Make use of interpolation nodes
        for i in range(1, numStretchyIKJoints):
            ikNodes = utils.basic_stretchy_IK(
                joints[i],
                joints[i + 1],
                container=moduleContainer,
                scaleCorrectionAttribute=self.blueprintNamespace +
                ":module_grp.hierarchicalScale",
                lockMinimumLength=False,
                poleVectorObject=aimChildren[i - 1])
            ikHandle = ikNodes["ikHandle"]
            rootLocator = ikNodes["rootLocator"]
            endLocator = ikNodes["endLocator"]

            for loc in (ikHandle, rootLocator):
                cmds.parent(loc, moduleGrp, absolute=True)

            utils.matchTwistAngle(ikHandle + ".twist", [
                joints[i],
            ], [
                stretchyIKJoints[i],
            ])

            if i == 1:
                if createRootControl:
                    containedNodes.append(
                        cmds.pointConstraint(rootControlObject,
                                             joints[i],
                                             maintainOffset=False,
                                             n=joints[i] +
                                             "_pointConstraint")[0])

            cmds.setAttr(endLocator + ".translate",
                         0.0,
                         0.0,
                         0.0,
                         type="double3")
            if i < numStretchyIKJoints - 1:
                cmds.parent(endLocator,
                            interpolators_ikParents[i - 1],
                            relative=True)
            else:
                cmds.parent(endLocator, endControlObject, relative=True)

        cmds.setAttr(moduleGrp + ".lod", 2)

        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
        # Publish joints to module container.
        for joint in stretchyIKJoints:
            jointName = utils.stripAllNamespaces(joint)[1]
            self.publishNameToModuleContainer(joint + ".rotate",
                                              jointName + "_R",
                                              publishToOuterContainers=False)
            self.publishNameToModuleContainer(joint + ".translate",
                                              jointName + "_T",
                                              publishToOuterContainers=False)
Ejemplo n.º 14
0
    def UI(self, parentLayout):
        globalControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":globalControl"

        controlObjectInstance = controlObject.ControlObject(globalControl)
        controlObjectInstance.UI(parentLayout)
Ejemplo n.º 15
0
 def spaceSwitching_spaceSwitch(self, controlObj, targetObject, *args):
     controlObjectInstance = controlObject.ControlObject(controlObj)
     controlObjectInstance.switchSpace_UI(targetObject)
Ejemplo n.º 16
0
    def install_custom(self, joints, moduleGrp, moduleContainer):
        ankleJoint = joints[3]
        ballJoint = joints[4]
        toeJoint = joints[5]
        
        tempLocator = cmds.spaceLocator()[0]
        cmds.parent(tempLocator, ballJoint, relative=True)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        
        ballJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
       
        cmds.parent(tempLocator, ankleJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator+attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        
        ankleJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
        
        cmds.parent(tempLocator, toeJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator+attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        
        toeJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
        
        cmds.delete(tempLocator)  
        
        containedNodes = []

        # Pass in functionality from basic IK        
        ikNodes = circleIK.CircleControlStretchyIK.install_custom(self, joints, moduleGrp, moduleContainer, createHandleControl=False, poleVectorAtRoot=False)
        ikEndPosLocator = ikNodes["endLocator"]
        ikPoleVectorLocator = ikNodes["poleVectorObject"]
        
        stretchinessAttribute = ikNodes["stretchinessAttribute"]
        
        name = "footControl"
        controlObjectInstance = controlObject.ControlObject()
        footControlInfo = controlObjectInstance.create(name, "footControl.ma", self, lod=1, translation=True, rotation=True, globalScale=False, spaceSwitching=True)
        footControl = footControlInfo[0]
        footControlRootParent = footControlInfo[1]
        
        # Parent foot control to root parent
        cmds.parent(footControlRootParent, moduleGrp, relative=True)
        
        # Position and orient foot control
        footControlPos = [ankleJoint_modulePos[0], ballJoint_modulePos[1], ankleJoint_modulePos[2]]
        cmds.xform(footControl, objectSpace=True, absolute=True, translation=footControlPos)
        
        cmds.setAttr(footControl+".rotateOrder", 3) #3 = xyz
        
        orientationVector = [toeJoint_modulePos[0] - ankleJoint_modulePos[0], toeJoint_modulePos[2] - ankleJoint_modulePos[2] ]
        
        footControlRotation = atan2(orientationVector[1], orientationVector[0])
        cmds.setAttr(footControl+".rotateY", -degrees(footControlRotation))
        
        # Hookup stretchiness attribute
        cmds.select(footControl)
        cmds.addAttr(at="float", minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName="stretchiness")
        self.publishNameToModuleContainer(footControl+".stretchiness", "stretchiness", publishToOuterContainers=True)
        
        cmds.connectAttr(footControl+".stretchiness", stretchinessAttribute, force=True)
        
        # Setup for ball and Toe controls
        ballToeControls = []
        ballToeControl_orientGrps = []
        for joint in [ballJoint, toeJoint]:
            controlObjectInstance = controlObject.ControlObject()
            jointName = utils.stripAllNamespaces(joint)[1]
            name = jointName + "_ryControl"
            
            ryControlInfo = controlObjectInstance.create(name, "yAxisCircle.ma", self, lod=2, translation=False, rotation=[True, True, True], globalScale=False, spaceSwitching=False)
            ryControl = ryControlInfo[0]
            
            ballToeControls.append(ryControl)
            
            orientGrp = cmds.group(empty=True, n=ryControl+"_orientGrp")
            containedNodes.append(orientGrp)
            ballToeControl_orientGrps.append(orientGrp)
            
            # Constrain to inherit orientations
            orientGrp_parentConstraint = cmds.parentConstraint(joint, orientGrp, maintainOffset=False)
            cmds.delete(orientGrp_parentConstraint)
            
            cmds.parent(ryControl, orientGrp, relative=True)
            
        for grp in ballToeControl_orientGrps:
            cmds.parent(grp, moduleGrp, absolute=True)
        # Constrain ball control    
        containedNodes.append(cmds.parentConstraint(footControl, ballToeControl_orientGrps[1], maintainOffset=True, n=ballToeControl_orientGrps[1] + "_parentConstraint")[0])
        # Constrain toe control 
        containedNodes.append(cmds.parentConstraint(ballToeControls[1], ballToeControl_orientGrps[0], maintainOffset=True, n=ballToeControl_orientGrps[0] + "_parentConstraint")[0])
        # Connect IK handles
        cmds.parent(ikEndPosLocator, ballToeControls[0], absolute=True)
        cmds.parent(ikPoleVectorLocator, ballToeControls[0], absolute=True)
       
        # Ankle IK
        ankleIKNodes = cmds.ikHandle(sj=ankleJoint, ee=ballJoint, solver="ikSCsolver", n=ankleJoint+"_ikHandle")
        ankleIKNodes[1] = cmds.rename(ankleIKNodes[1], ankleIKNodes[1]+"_ikEffector")
        containedNodes.extend(ankleIKNodes)
        
        cmds.parent(ankleIKNodes[0], ballToeControls[0])
        cmds.setAttr(ankleIKNodes[0]+".visibility", 0)
        
        #Ball IK 
        ballIKNodes = cmds.ikHandle(sj=ballJoint, ee=toeJoint, solver="ikSCsolver", n=ballJoint+"_ikHandle")
        ballIKNodes[1] = cmds.rename(ballIKNodes[1], ballIKNodes[1]+"_ikEffector")
        containedNodes.extend(ballIKNodes)
        
        cmds.parent(ballIKNodes[0], ballToeControls[1])
        cmds.setAttr(ballIKNodes[0]+".visibility", 0)
        
        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
Ejemplo n.º 17
0
 def install_custom(self, joints, moduleGrp, moduleContainer):
     containedNodes = []
     rootJoint = joints[1]
     endJoint = joints[len(joints)-1]
     
     ikNodes = utils.basic_stretchy_IK(rootJoint, endJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace+":module_grp.hierarchicalScale")
     ikHandle = ikNodes["ikHandle"]
     rootLocator = ikNodes["rootLocator"]
     endLocator = ikNodes["endLocator"]
     poleVectorLocator = ikNodes["poleVectorObject"]
     stretchinessAttribute = ikNodes["stretchinessAttribute"]
     
     # Create controls and parent ikHandles
     for node in [rootLocator, ikHandle, poleVectorLocator]:
         cmds.parent(node, moduleGrp, absolute=True)
         
     name = "ikHandleControl"
     # controlObject class
     controlObjectInstance = controlObject.ControlObject()
     handleControlInfo = controlObjectInstance.create(name, "cubeLocator.ma", self, lod=1, translation=True, rotation=False, globalScale=False, spaceSwitching=True)
     handleControl = handleControlInfo[0]
     handleRootParent = handleControlInfo[1]
     
     cmds.parent(handleRootParent, moduleGrp, relative=True)
     
     cmds.xform(handleControl, worldSpace=True, absolute=True, translation=cmds.xform(endLocator, q=True, worldSpace=True, translation=True))
     
     cmds.parent(endLocator, handleControl, absolute=True)
     
     # Create a pre-transform node that sits above the control object.
     handleControlParent = cmds.listRelatives(handleControl, parent=True)[0]
     preTransform = cmds.group(empty=True, n=handleControl+"_preTransform")
     containedNodes.append(preTransform)
     
     cmds.parent(preTransform, handleControl, relative=True)
     cmds.parent(preTransform, handleControlParent, absolute=True)
     cmds.parent(handleControl, preTransform, absolute=True)
     
     #Add attributes to control
     cmds.select(handleControl)
     cmds.addAttr(at="float", minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName="stretchiness")
     cmds.addAttr(at="float", softMinValue=-360.0, softMaxValue=360.0, defaultValue=0.0, keyable=True, longName="twist")
     
     #connect attrs
     cmds.connectAttr(handleControl+".twist", ikHandle+".twist")
     cmds.connectAttr(handleControl+".stretchiness", stretchinessAttribute)
     
     # Add attrs to container
     self.publishNameToModuleContainer(handleControl+".twist", "twist", publishToOuterContainers=True)
     self.publishNameToModuleContainer(handleControl+".stretchiness", "stretchiness", publishToOuterContainers=True)
     
     # 171 >
     jointName = utils.stripAllNamespaces(rootJoint)[1]
     ikJoints = utils.findJointChain(rootJoint)
     targetJoints = utils.findJointChain(self.blueprintNamespace+":creationPose_"+jointName)
     
     utils.matchTwistAngle(handleControl+".twist", ikJoints, targetJoints)
     
     offsetNode = cmds.shadingNode("plusMinusAverage", asUtility=True, n=handleControl+"_twistOffset")
     containedNodes.append(offsetNode)
     
     cmds.setAttr(offsetNode+".input1D[0]", cmds.getAttr(handleControl+".twist"))
     cmds.connectAttr(handleControl+".twist", offsetNode+".input1D[1]")
     cmds.connectAttr(offsetNode+".output1D", ikHandle+".twist", force=True)
     
     cmds.setAttr(handleControl+".twist", 0.0)
     # < 171
     utils.addNodeToContainer(moduleContainer, containedNodes)