Esempio n. 1
0
    def makeFK(self, limbJoints, topFingerJoints, rigScale, rigmodule):
        """
        Do FK Arm/Leg, Metacarpal and Finger/Toe ctrl
        :param limbJoints: list(str), Arm/leg joints
        :param topFingerJoints: list(str), Metacarpal joints
        :param rigScale: float
        :param rigmodule: dict
        :return:
        """

        limbCtrlInstanceList = []
        handFeetCtrlInstanceList = []

        limbCtrlConstraintList = []
        handFeetCtrlConstraintList = []

        # Arm/Leg
        for jnt in limbJoints:
            prefix = name.removeSuffix(jnt)

            parent = rigmodule.controlsGrp
            if len(limbCtrlInstanceList) > 0:
                parent = limbCtrlInstanceList[-1].C

            ctrl = control.Control(prefix=prefix,
                                   translateTo=jnt,
                                   rotateTo=jnt,
                                   parent=parent,
                                   shape='circleX')

            orientCnst = pm.orientConstraint(ctrl.getControl(), jnt, mo=True)

            limbCtrlConstraintList.append(orientCnst)
            limbCtrlInstanceList.append(ctrl)

        # Hand/Foot
        for topJntList in topFingerJoints:
            fnjJntList = joint.listHierarchy(topJntList, withEndJoints=False)

            fingerJointList = []
            for jnt in fnjJntList:
                prefix = name.removeSuffix(jnt)

                parent = limbCtrlInstanceList[-1].C
                if len(fingerJointList) > 0:
                    parent = fingerJointList[-1].C

                ctrl = control.Control(prefix=prefix,
                                       translateTo=jnt,
                                       rotateTo=jnt,
                                       parent=parent,
                                       shape='circleX')

                orientCnst = pm.orientConstraint(ctrl.getControl(), jnt)
                fingerJointList.append(ctrl)
                handFeetCtrlConstraintList.append(orientCnst)

            handFeetCtrlInstanceList.extend(fingerJointList)

        return limbCtrlInstanceList, limbCtrlConstraintList, handFeetCtrlInstanceList, handFeetCtrlConstraintList
Esempio n. 2
0
    def makeIK(self,
               limbJoints,
               topFingerJoints,
               rigScale,
               rigmodule,
               useMetacarpalJoint=False,
               smartFootRoll=True,
               lSide='l_'):
        """
        Do IK Arm/Leg, Metacarpal and Finger/Toe ctrl
        :param limbJoints: list(str), Arm/leg joints
        :param topFingerJoints: list(str), Metacarpal joints
        :param rigScale: float
        :param rigmodule: dict
        :return:
        """

        metacarpalJointList = topFingerJoints
        topFngJntList = []
        endFngJntList = []
        for mtJnt in metacarpalJointList:
            if useMetacarpalJoint:
                fngJnt = pm.listRelatives(mtJnt, type='joint',
                                          children=True)[0]
            else:
                fngJnt = mtJnt

            fngEndJnt = joint.listHierarchy(mtJnt, withEndJoints=True)[-1]
            topFngJntList.append(fngJnt)
            endFngJntList.append(fngEndJnt)

        footRoolInstance = footRoll.FootRoll(limbJoints[0], limbJoints[2],
                                             topFngJntList, endFngJntList)
        footRollGrpList = footRoolInstance.getGroupList()
        pm.parent(footRollGrpList[-1], rigmodule.partsNoTransGrp)

        prefix = name.removeSuffix(limbJoints[2])

        # make controls
        mainIKCtrl = control.Control(prefix=prefix + 'IK',
                                     translateTo=limbJoints[2],
                                     rotateTo=limbJoints[2],
                                     parent=rigmodule.controlsGrp,
                                     shape='circleY')

        midFngIKIndex = int(
            round(len(footRoolInstance.getIkFingerList()) / 2.0)) - 1
        midFngJnt = footRoolInstance.getIkFingerList(
        )[midFngIKIndex].getJointList()[0]
        ballCtrl = control.Control(prefix=prefix + 'BallIK',
                                   translateTo=midFngJnt,
                                   rotateTo=midFngJnt,
                                   parent=mainIKCtrl.C,
                                   shape='circleZ')

        toeIkControls = []
        for topToeJnt in topFingerJoints:
            toePrefix = name.removeSuffix(topToeJnt)
            toeEndJnt = pm.listRelatives(topToeJnt, ad=1, type='joint')[0]

            toeIkCtrl = control.Control(prefix=toePrefix,
                                        translateTo=toeEndJnt,
                                        scale=rigScale,
                                        parent=ballCtrl.C,
                                        shape='circleY')

            toeIkControls.append(toeIkCtrl)

        # constraint IK
        for i, toeIK in enumerate(footRoolInstance.getIkFingerList()):
            pm.parentConstraint(toeIkControls[i].C, toeIK)

        pm.parentConstraint(mainIKCtrl.C, footRollGrpList[-1], mo=True)
        pm.parentConstraint(footRollGrpList[1],
                            ballCtrl.getOffsetGrp(),
                            mo=True)
        handIKOrientContraint = pm.orientConstraint(mainIKCtrl.C,
                                                    limbJoints[2],
                                                    mo=True)

        ballRollGrp = footRollGrpList[0]
        toeTapGrp = footRollGrpList[1]
        tippyToeGrp = footRollGrpList[2]
        frontRollGrp, backRollGrp, innerRollGrp, outerRollGrp = footRollGrpList[
            3:-1]
        if smartFootRoll and frontRollGrp and ballRollGrp and innerRollGrp and outerRollGrp:
            rollAttr = attributes.addFloatAttribute(mainIKCtrl.getControl(),
                                                    'roll',
                                                    defaultValue=0,
                                                    keyable=True,
                                                    minValue=-120,
                                                    maxValue=120)
            bendLimitAttr = attributes.addFloatAttribute(
                mainIKCtrl.getControl(),
                'bendLimitAngle',
                defaultValue=45,
                keyable=False)
            straightAngleAttr = attributes.addFloatAttribute(
                mainIKCtrl.getControl(),
                'toeStraightAngle',
                defaultValue=70,
                keyable=False)

            heelClampNode = pm.shadingNode('clamp',
                                           asUtility=True,
                                           n=prefix + '_heelRotClamp')
            pm.connectAttr(rollAttr, heelClampNode.inputR)
            heelClampNode.minR.set(-90)
            pm.connectAttr(heelClampNode.outputR, backRollGrp.rotateX)

            ballClampNode = pm.shadingNode('clamp',
                                           asUtility=True,
                                           n=prefix + '_zeroToBendClamp')
            pm.connectAttr(rollAttr, ballClampNode.inputR)
            #heelClampNode.maxR.set(90)
            #pm.connectAttr(ballClampNode.outputR, ballRollGrp.rotateX)

            bendToStraightClampNode = pm.shadingNode('clamp',
                                                     asUtility=True,
                                                     n=prefix +
                                                     '_bendToStraightClamp')
            pm.connectAttr(bendLimitAttr, bendToStraightClampNode.minR)
            pm.connectAttr(straightAngleAttr, bendToStraightClampNode.maxR)
            pm.connectAttr(rollAttr, bendToStraightClampNode.inputR)

            bendToStraightSetRangeNode = pm.shadingNode(
                'setRange',
                asUtility=True,
                n=prefix + '_bendToStraightPercent')
            pm.connectAttr(bendToStraightClampNode.minR,
                           bendToStraightSetRangeNode.oldMinX)
            pm.connectAttr(bendToStraightClampNode.maxR,
                           bendToStraightSetRangeNode.oldMaxX)
            bendToStraightSetRangeNode.maxX.set(1)
            pm.connectAttr(bendToStraightClampNode.inputR,
                           bendToStraightSetRangeNode.valueX)

            rollMultDivNode = pm.shadingNode('multiplyDivide',
                                             asUtility=True,
                                             n=prefix + '_rollMultDiv')
            pm.connectAttr(bendToStraightSetRangeNode.outValueX,
                           rollMultDivNode.input1X)
            pm.connectAttr(bendToStraightClampNode.inputR,
                           rollMultDivNode.input2X)
            pm.connectAttr(rollMultDivNode.outputX, tippyToeGrp.rotateX)

            pm.connectAttr(bendLimitAttr, ballClampNode.maxR)
            zeroToBendSetRangeNode = pm.shadingNode('setRange',
                                                    asUtility=True,
                                                    n=prefix +
                                                    '_zeroToBendPercent')
            pm.connectAttr(ballClampNode.minR, zeroToBendSetRangeNode.oldMinX)
            pm.connectAttr(ballClampNode.maxR, zeroToBendSetRangeNode.oldMaxX)
            zeroToBendSetRangeNode.maxX.set(1)
            pm.connectAttr(ballClampNode.inputR, zeroToBendSetRangeNode.valueX)

            invertPercentNode = pm.shadingNode('plusMinusAverage',
                                               asUtility=True,
                                               n=prefix + '_invertPercent')
            invertPercentNode.input1D[0].set(1)
            invertPercentNode.input1D[1].set(1)
            pm.connectAttr(bendToStraightSetRangeNode.outValueX,
                           invertPercentNode.input1D[1])
            invertPercentNode.operation.set(2)

            ballPercentMultDivNode = pm.shadingNode('multiplyDivide',
                                                    asUtility=True,
                                                    n=prefix +
                                                    '_ballPercentMultDiv')
            pm.connectAttr(zeroToBendSetRangeNode.outValueX,
                           ballPercentMultDivNode.input1X)
            pm.connectAttr(invertPercentNode.output1D,
                           ballPercentMultDivNode.input2X)

            ballRollMultDivNode = pm.shadingNode('multiplyDivide',
                                                 asUtility=True,
                                                 n=prefix + '_ballRollMultDiv')
            pm.connectAttr(ballPercentMultDivNode.outputX,
                           ballRollMultDivNode.input1X)
            pm.connectAttr(rollAttr, ballRollMultDivNode.input2X)

            pm.connectAttr(ballRollMultDivNode.outputX, ballRollGrp.rotateX)

            # Tilt
            tiltAttr = attributes.addFloatAttribute(mainIKCtrl.getControl(),
                                                    'tilt',
                                                    defaultValue=0,
                                                    keyable=True,
                                                    minValue=-90,
                                                    maxValue=90)
            if lSide in prefix:
                common.setDrivenKey(tiltAttr, [-90, 0, 90],
                                    innerRollGrp.rotateZ, [90, 0, 0])
                common.setDrivenKey(tiltAttr, [-90, 0, 90],
                                    outerRollGrp.rotateZ, [0, 0, -90])
            else:
                common.setDrivenKey(tiltAttr, [-90, 0, 90],
                                    innerRollGrp.rotateZ, [-90, 0, 0])
                common.setDrivenKey(tiltAttr, [-90, 0, 90],
                                    outerRollGrp.rotateZ, [0, 0, 90])

            # lean
            leanAttr = attributes.addFloatAttribute(mainIKCtrl.getControl(),
                                                    'lean',
                                                    defaultValue=0,
                                                    keyable=True,
                                                    minValue=-90,
                                                    maxValue=90)
            pm.connectAttr(leanAttr, ballRollGrp.rotateZ)

            # toeSpin
            toeSpinAttr = attributes.addFloatAttribute(mainIKCtrl.getControl(),
                                                       'toeSpin',
                                                       defaultValue=0,
                                                       keyable=True,
                                                       minValue=-90,
                                                       maxValue=90)
            pm.connectAttr(toeSpinAttr, tippyToeGrp.rotateY)
            tippyToeGrp.rotateOrder.set(2)

            # toeWiggle
            toeWiggleAttr = attributes.addFloatAttribute(
                mainIKCtrl.getControl(),
                'toeWiggle',
                defaultValue=0,
                keyable=True,
                minValue=-90,
                maxValue=90)
            pm.connectAttr(toeWiggleAttr, toeTapGrp.rotateX)

        return mainIKCtrl, footRoolInstance.getLimbIK(), [
            [ballCtrl], toeIkControls
        ], footRoolInstance.getIkFingerList(), footRoolInstance.getIkBallList(
        ), handIKOrientContraint
Esempio n. 3
0
    def makeIK(self,
               limbJoints,
               topFingerJoints,
               rigScale,
               rigmodule,
               useMetacarpalJoint=False,
               smartFootRoll=True,
               lSide='l_'):
        """
        Do IK Arm/Leg, Metacarpal and Finger/Toe ctrl
        :param limbJoints: list(str), Arm/leg joints
        :param topFingerJoints: list(str), Metacarpal joints
        :param rigScale: float
        :param rigmodule: dict
        :return:
        """

        metacarpalJointList = topFingerJoints
        topFngJntList = []
        endFngJntList = []
        for mtJnt in metacarpalJointList:
            if useMetacarpalJoint:
                fngJnt = pm.listRelatives(mtJnt, type='joint',
                                          children=True)[0]
            else:
                fngJnt = mtJnt

            fngEndJnt = joint.listHierarchy(mtJnt, withEndJoints=True)[-1]
            topFngJntList.append(fngJnt)
            endFngJntList.append(fngEndJnt)

        footRoolInstance = footRoll.FootRoll(limbJoints[0], limbJoints[2],
                                             topFngJntList, endFngJntList)
        footRollGrpList = footRoolInstance.getGroupList()
        pm.parent(footRollGrpList[-1], rigmodule.partsNoTransGrp)

        prefix = name.removeSuffix(limbJoints[2])

        # make controls
        mainIKCtrl = control.Control(prefix=prefix + 'IK',
                                     translateTo=limbJoints[2],
                                     rotateTo=limbJoints[2],
                                     parent=rigmodule.controlsGrp,
                                     shape='circleY')

        midFngIKIndex = int(
            round(len(footRoolInstance.getIkFingerList()) / 2.0)) - 1
        midFngJnt = footRoolInstance.getIkFingerList(
        )[midFngIKIndex].getJointList()[0]
        ballCtrl = control.Control(prefix=prefix + 'BallIK',
                                   translateTo=midFngJnt,
                                   rotateTo=midFngJnt,
                                   parent=rigmodule.controlsGrp,
                                   shape='circleZ')

        # pm.parentConstraint(mainIKCtrl.C, ballCtrl.getTop(), mo=True)

        pm.parentConstraint(mainIKCtrl.C, footRollGrpList[-1], mo=True)
        pm.parentConstraint(footRollGrpList[1],
                            ballCtrl.getOffsetGrp(),
                            mo=True)
        handIKOrientContraint = pm.orientConstraint(mainIKCtrl.C,
                                                    limbJoints[2],
                                                    mo=True)