Beispiel #1
0
    def __init__(self,
                 limbJoints,
                 topFingerJoints,
                 clavicleJoint='',
                 scapulaJnt='',
                 visibilityIKFKCtrl='ikfk_CTRL',
                 doFK=True,
                 doIK=True,
                 useMetacarpalJoint=False,
                 doSmartFootRool=True,
                 prefix=None,
                 rigScale=1.0,
                 baseRig=None):
        """
        :param limbJoints: list( str ), shoulder - elbow - hand - toe - end toe
        :param topFingerJoints: list( str ), top metacarpal toe joints
        :param scapulaJnt: str, optional, scapula joint, parent of top leg joint
        :param doFK: bool, do FK controls
        :param doIK: bool, do IK controls
        :param prefix: str, prefix to name new objects
        :param rigScale: float, scale factor for size of controls
        :param baseRig: baseRig: instance of base.module.Base class
        :return: dictionary with rig module objects
        """
        # :param pvLocator: str, reference locator for position of Pole Vector control

        # prefix
        if not prefix:
            prefix = name.removeSuffix(limbJoints[0])

        # make rig module
        rigmodule = module.Module(prefix=prefix, baseObj=baseRig)

        # make attach groups
        bodyAttachGrp = pm.group(n=prefix + 'BodyAttach_GRP',
                                 em=1,
                                 p=rigmodule.partsGrp)
        baseAttachGrp = pm.group(n=prefix + 'BaseAttach_GRP',
                                 em=1,
                                 p=rigmodule.partsGrp)

        self.rigmodule = rigmodule
        self.baseAttachGrp = baseAttachGrp
        self.bodyAttachGrp = bodyAttachGrp

        if doFK:
            fkLimbCtrls, fkLimbCnst, fkHandsFeetCtrls, fkHandsFeetCnst = self.makeFK(
                limbJoints, topFingerJoints, rigScale, rigmodule)

        if doIK:
            mainIKCtrl, ikHandle, fngCtrls, fngIKs, ballIKs, handIKOrientCnst = self.makeIK(
                limbJoints, topFingerJoints, rigScale, rigmodule,
                useMetacarpalJoint)
            poleVectorCtrl, poleVectorLoc = self.makePoleVector(
                ikHandle, mainIKCtrl.getControl(), rigScale, rigmodule)

        if doFK and doIK:
            # IK/FK switch
            if visibilityIKFKCtrl:
                IKFKCtrl = pm.ls(visibilityIKFKCtrl)[0]
                self.switchIKFK(prefix, IKFKCtrl, fkLimbCtrls, fkLimbCnst,
                                fkHandsFeetCtrls, fkHandsFeetCnst, mainIKCtrl,
                                ikHandle, fngCtrls, fngIKs, ballIKs,
                                poleVectorCtrl, handIKOrientCnst)

        # clavicle
        if clavicleJoint != '' and pm.objExists(clavicleJoint):
            clavicleCtrl = self.makeClavicle(prefix, limbJoints, clavicleJoint,
                                             rigScale, rigmodule)
            pm.parentConstraint(clavicleCtrl.getControl(),
                                fkLimbCtrls[0].getTop(),
                                mo=1)
        else:
            pm.parentConstraint(self.baseAttachGrp,
                                fkLimbCtrls[0].getTop(),
                                mo=1)

        # scapula
        if scapulaJnt != '' and pm.objExists(scapulaJnt):
            scpJnt = pm.ls(limbJoints)[0].getParent()
            scapulaCtrl = None
            if scpJnt.name() == pm.ls(scapulaJnt)[0].name():
                # simple scapula
                scapulaCtrl = self.makeSimpleScapula(prefix, limbJoints,
                                                     scapulaJnt, rigScale,
                                                     rigmodule)
            else:
                # dynamic scapula
                self.makeDynamicScapula(limbJoints, rigmodule)

            # constriant FK limb
            if scapulaCtrl:
                pm.parentConstraint(scapulaCtrl.getControl(),
                                    fkLimbCtrls[0].getTop(),
                                    mo=1)

        self.limbIK = ikHandle
        self.mainIKControl = mainIKCtrl
Beispiel #2
0
    def __init__(self,
                 chainJoints,
                 prefix='tail',
                 rigScale=1.0,
                 doDynamic=False,
                 smallestScalePercent=0.1,
                 fkParenting=True,
                 baseRig=None):
        """
        :param chainJoints: list( str ), list of chain joints
        :param prefix: str, prefix to name new objects
        :param rigScale: float, scale factor for size of controls
        :param smallestScalePercent: float, scale of smallest control at the end of chain compared to rigScale
        :param doDynamic: bool, setup dynamic curve
        :param fkParenting: bool, parent each control to previous one to make FK chain
        :param baseRig: instance of base.module.Base class
        :return: dictionary with rig module objects
        """
        # :param chainCurve: str, name of chain cubic curve

        # make rig module
        self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig)

        # collision point
        collisionPoint = int(len(chainJoints))

        # make IK handle
        chainIk, effector, chainCurve = pm.ikHandle(
            n=prefix + '_IKH',
            sol='ikSplineSolver',
            sj=chainJoints[0],
            ee=chainJoints[-1],  # -2
            createCurve=True,
            numSpans=collisionPoint)

        # rename curve
        pm.rename(chainCurve, prefix + '_CRV')

        # create ctrlCurve
        ctrlCurve = pm.duplicate(chainCurve, n=prefix + 'Ctrl_CRV')[0]

        # make chain curve clusters
        chainCurveCVs = pm.ls(ctrlCurve + '.cv[*]', fl=1)
        numChainCVs = len(chainCurveCVs)
        chainCurveClusters = []

        for i in range(numChainCVs):
            cls = pm.cluster(chainCurveCVs[i],
                             n=prefix + 'Cluster%d' % (i + 1))[1]
            chainCurveClusters.append(cls)

        pm.hide(chainCurveClusters)

        # parent chain curve
        pm.parent(chainCurve, self.rigmodule.partsNoTransGrp)
        pm.parent(ctrlCurve, self.rigmodule.partsNoTransGrp)

        # make attach groups
        self.baseAttachGrp = pm.group(n=prefix + 'BaseAttach_GRP',
                                      em=1,
                                      p=self.rigmodule.partsGrp)

        pm.delete(pm.pointConstraint(chainJoints[0], self.baseAttachGrp))

        # make controls
        chainControls = []
        controlScaleIncrement = (1.0 - smallestScalePercent) / numChainCVs
        mainCtrlScaleFactor = 1.0  # 5.0

        for i in range(numChainCVs):
            ctrlScale = rigScale * mainCtrlScaleFactor * (
                1.0 - (i * controlScaleIncrement))
            ctrl = control.Control(prefix=prefix + '%d' % (i + 1),
                                   translateTo=chainCurveClusters[i],
                                   scale=ctrlScale,
                                   parent=self.rigmodule.controlsGrp,
                                   shape='sphere')

            chainControls.append(ctrl)

        # parent controls
        if fkParenting:
            for i in range(numChainCVs):
                if i == 0:
                    continue
                pm.parent(chainControls[i].Off, chainControls[i - 1].C)

        # attach clusters
        for i in range(numChainCVs):
            pm.parent(chainCurveClusters[i], chainControls[i].C)

        # attach controls
        pm.parentConstraint(self.baseAttachGrp, chainControls[0].Off, mo=1)

        pm.hide(chainIk)
        pm.parent(chainIk, self.rigmodule.partsNoTransGrp)

        # add twist attribute
        twistAt = 'twist'
        pm.addAttr(chainControls[-1].C, ln=twistAt, k=1)
        pm.connectAttr(chainControls[-1].C + '.' + twistAt, chainIk + '.twist')

        # save class attribute
        self.chainCurve = chainCurve
        self.controlCurve = ctrlCurve

        if doDynamic:
            self.dynCurve = self.makeDynamic(prefix, baseRig, self.rigmodule,
                                             chainControls, chainCurveClusters)

            deform.blendShapeDeformer(self.dynCurve.getInputCurve(),
                                      [self.controlCurve],
                                      nodeName=prefix + 'BlendShape',
                                      frontOfChain=True)
            deform.blendShapeDeformer(self.chainCurve,
                                      [self.dynCurve.getOutputCurve()],
                                      nodeName=prefix + 'BlendShape',
                                      frontOfChain=True)
        else:
            deform.blendShapeDeformer(self.chainCurve, [self.controlCurve],
                                      nodeName=prefix + 'BlendShape',
                                      frontOfChain=True)
Beispiel #3
0
    def __init__(self,
                 neckJoints,
                 headJnt,
                 # neckCurve,
                 prefix='neck',
                 rigScale=1.0,
                 baseRig=None
                 ):
        """
        :param neckJoints: list( str ), list of neck joints
        :param headJnt: str, head joint at the end of neck joint chain
        :param prefix: str, prefix to name new objects
        :param rigScale: float, scale factor for size of controls
        :param baseRig: instance of base.module.Base class
        :return: dictionary with rig module objects
        """
        # :param neckCurve: str, name of neck cubic curve with 5 CVs matching neck joints

        # make rig module
        self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig)

        # make IK handle
        neckIk, effector, neckCurve = pm.ikHandle(n=prefix + '_IKH', sol='ikSplineSolver', sj=neckJoints[0],
                                                  ee=neckJoints[-1],
                                                  createCurve=True, numSpans=2)

        # rename curve
        pm.rename(neckCurve, prefix + '_CRV')

        # make neck curve clusters
        neckCurveCVs = pm.ls(neckCurve + '.cv[*]', fl=1)
        numNeckCVs = len(neckCurveCVs)
        neckCurveClusters = []

        for i in range(numNeckCVs):
            cls = pm.cluster(neckCurveCVs[i], n=prefix + 'Cluster%d' % (i + 1))[1]
            neckCurveClusters.append(cls)

        pm.hide(neckCurveClusters)

        # parent neck curve
        pm.parent(neckCurve, self.rigmodule.partsNoTransGrp)

        # make attach groups
        self.bodyAttachGrp = pm.group(n=prefix + 'BodyAttach_GRP', em=1, p=self.rigmodule.partsGrp)
        self.baseAttachGrp = pm.group(n=prefix + 'BaseAttach_GRP', em=1, p=self.rigmodule.partsGrp)

        pm.delete(pm.pointConstraint(neckJoints[0], self.baseAttachGrp))

        # make controls
        headMainCtrl = control.Control(prefix=prefix + 'HeadMain', translateTo=neckJoints[-1], rotateTo=headJnt,
                                       scale=rigScale * 5,
                                       parent=self.rigmodule.controlsGrp, shape='head')

        headLocalCtrl = control.Control(prefix=prefix + 'HeadLocal', translateTo=headJnt, rotateTo=headJnt,
                                        scale=rigScale * 4, parent=headMainCtrl.C, shape='circleX', lockChannels=['t'])

        middleCtrl = control.Control(prefix=prefix + 'Middle', translateTo=neckCurveClusters[2], rotateTo=neckJoints[2],
                                     scale=rigScale * 4, parent=self.rigmodule.controlsGrp, shape='circleX',
                                     lockChannels=['r'])

        # attach controls
        pm.parentConstraint(headMainCtrl.C, self.baseAttachGrp, middleCtrl.Off, sr=['x', 'y', 'z'], mo=1)
        pm.orientConstraint(self.baseAttachGrp, middleCtrl.Off, mo=1)
        pm.parentConstraint(self.bodyAttachGrp, headMainCtrl.Off, mo=1)

        # attach clusters
        pm.parent(neckCurveClusters[3:], headMainCtrl.C)
        pm.parent(neckCurveClusters[2], middleCtrl.C)
        pm.parent(neckCurveClusters[:2], self.baseAttachGrp)

        # attach joints
        pm.orientConstraint(headLocalCtrl.C, headJnt, mo=1)

        pm.hide(neckIk)
        pm.parent(neckIk, self.rigmodule.partsNoTransGrp)

        # setup IK twist
        pm.setAttr(neckIk + '.dTwistControlEnable', 1)
        pm.setAttr(neckIk + '.dWorldUpType', 4)
        pm.connectAttr(headMainCtrl.C + '.worldMatrix[0]', neckIk + '.dWorldUpMatrixEnd')
        pm.connectAttr(self.baseAttachGrp + '.worldMatrix[0]', neckIk + '.dWorldUpMatrix')
Beispiel #4
0
    def __init__(self,
                 spineJoints,
                 rootJnt,
                 prefix='spine',
                 rigScale=1.0,
                 baseRig=None,
                 bodyLocator='',
                 chestLocator='',
                 pelvisLocator=''):
        """
        :param spineJoints: list( str ), list of 6 spine joints
        :param rootJnt: str, root joint
        :param prefix: str, prefix to name new objects
        :param rigScale: float, scale factor for size of controls
        :param baseRig: instance of base.module.Base class
        :param bodyLocator: str, reference transform for position of body control
        :param chestLocator: str, reference transform for position of chest control
        :param pelvisLocator: str, reference transform for position of pelvis control
        :return: dictionary with rig module objects
        """
        # :param spineCurve: str, name of spine cubic curve with 5 CVs matching first 5 spine joints

        # make rig module
        self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig)

        # control locator reference position
        if bodyLocator == '' or chestLocator == '' or pelvisLocator == '':
            pass
        bodyLocator, chestLocator, pelvisLocator = self.makeControlLocatorReferencePosition(
            spineJoints)

        # make IK handle
        spineIk, effector, spineCurve = pm.ikHandle(
            n=prefix + '_IKH',
            sol='ikSplineSolver',
            sj=spineJoints[0],
            ee=spineJoints[-1],  # -2
            createCurve=True,
            numSpans=2)

        # rename curve
        pm.rename(spineCurve, prefix + '_CRV')

        # make spine curve clusters
        spineCurveCVs = pm.ls(spineCurve + '.cv[*]', fl=1)
        numSpineCVs = len(spineCurveCVs)
        spineCurveClusters = []

        for i in range(numSpineCVs):
            cls = pm.cluster(spineCurveCVs[i],
                             n=prefix + 'Cluster%d' % (i + 1))[1]
            spineCurveClusters.append(cls)

        pm.hide(spineCurveClusters)

        # parent spine curve
        pm.parent(spineCurve, self.rigmodule.partsNoTransGrp)

        # make controls
        self.bodyCtrl = control.Control(prefix=prefix + 'Body',
                                        translateTo=bodyLocator,
                                        rotateTo=spineJoints[-1],
                                        scale=rigScale * 4,
                                        parent=self.rigmodule.controlsGrp,
                                        shape='spine')

        chestCtrl = control.Control(prefix=prefix + 'Chest',
                                    translateTo=chestLocator,
                                    rotateTo=spineJoints[-1],
                                    scale=rigScale * 6,
                                    parent=self.bodyCtrl.C,
                                    shape='chest')

        pelvisCtrl = control.Control(prefix=prefix + 'Pelvis',
                                     translateTo=pelvisLocator,
                                     rotateTo=pelvisLocator,
                                     scale=rigScale * 6,
                                     parent=self.bodyCtrl.C,
                                     shape='hip')

        middleCtrl = control.Control(prefix=prefix + 'Middle',
                                     translateTo=spineCurveClusters[2],
                                     scale=rigScale * 3,
                                     parent=self.bodyCtrl.C,
                                     shape='sphere',
                                     lockChannels=['r'])

        # attach controls
        pm.parentConstraint(chestCtrl.C,
                            pelvisCtrl.C,
                            middleCtrl.Off,
                            sr=['x', 'y', 'z'],
                            mo=1)

        # attach clusters
        pm.parent(spineCurveClusters[3:], chestCtrl.C)
        pm.parent(spineCurveClusters[2], middleCtrl.C)
        pm.parent(spineCurveClusters[:2], pelvisCtrl.C)

        # attach chest joint
        pm.orientConstraint(chestCtrl.C, spineJoints[-1], mo=1)  # -2

        pm.hide(spineIk)
        pm.parent(spineIk, self.rigmodule.partsNoTransGrp)

        # setup IK twist
        pm.setAttr(spineIk + '.dTwistControlEnable', 1)
        pm.setAttr(spineIk + '.dWorldUpType', 4)
        pm.connectAttr(chestCtrl.C + '.worldMatrix[0]',
                       spineIk + '.dWorldUpMatrixEnd')
        pm.connectAttr(pelvisCtrl.C + '.worldMatrix[0]',
                       spineIk + '.dWorldUpMatrix')

        # attach root joint
        pm.parentConstraint(pelvisCtrl.C, rootJnt, mo=1)

        # clean locators
        pm.delete(bodyLocator, chestLocator, pelvisLocator)
Beispiel #5
0
    def __init__(self,
                 clavicleJoint,
                 shoulderJoint,
                 forearmJoint,
                 wristJoint,
                 scapulaJnt='',
                 visibilityIKFKCtrl='ikfk_CTRL',
                 doFK=True,
                 doIK=True,
                 prefix=None,
                 rigScale=1.0,
                 baseRig=None):
        """
        :param clavicleJoint: pynode
        :param shoulderJoint: pynode
        :param forearmJoint: pynode
        :param scapulaJnt: pynode
        :param wristJoint: pynode
        :param doFK: bool, do FK controls
        :param doIK: bool, do IK controls
        :param prefix: str, prefix to name new objects
        :param rigScale: float, scale factor for size of controls
        :param baseRig: baseRig: instance of base.module.Base class
        :return: dictionary with rig module objects
        """
        # :param pvLocator: str, reference locator for position of Pole Vector control

        # prefix
        if not prefix:
            prefix = name.removeSuffix(
                pm.ls(clavicleJoint, shoulderJoint, forearmJoint, wristJoint,
                      scapulaJnt))

        # make rig module
        rigmodule = module.Module(prefix=prefix, baseObj=baseRig)

        # make attach groups
        bodyAttachGrp = pm.group(n=prefix + 'BodyAttach_GRP',
                                 em=1,
                                 p=rigmodule.partsGrp)
        baseAttachGrp = pm.group(n=prefix + 'BaseAttach_GRP',
                                 em=1,
                                 p=rigmodule.partsGrp)

        self.rigmodule = rigmodule
        self.baseAttachGrp = baseAttachGrp
        self.bodyAttachGrp = bodyAttachGrp

        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)
Beispiel #6
0
    def __init__(self,
                 cvList,
                 skinGeo,
                 prefix='face',
                 headJnt='head_JNT',
                 pointsNumber=5,
                 scale=0.1,
                 baseRig=None
                 ):
        """
        Build Facial Setup
        :param cvList: list of facial curves
        :param prefix: str, prefix to name new objects
        :param rigScale: float, scale factor for size of controls
        :param baseRig: instance of base.module.Base class
        """

        cvList = pm.ls(cvList)
        skinGeo = pm.ls(skinGeo)[0]
        headJnt = pm.ls(headJnt)[0]

        # make rig module
        self.rigmodule = module.Module(prefix=prefix, baseObj=baseRig)

        # attributes
        self.spacing = 1.0 / (pointsNumber - 1)

        # setup deformation
        # geo setup
        faceGeo = pm.duplicate(skinGeo, n=prefix + '_GEO')[0]
        pm.parent(faceGeo, self.rigmodule.partsNoTransGrp)
        deform.blendShapeDeformer(skinGeo, [faceGeo], 'face_BS', frontOfChain=True)

        # joints setup
        headFaceJnt = pm.duplicate(headJnt, renameChildren=True)[0]
        jointsDuplicates = pm.listRelatives(headFaceJnt, c=True, ad=True)
        jointsDuplicates.append(headFaceJnt)

        for jnt in jointsDuplicates:
            pm.rename(jnt, str(jnt.name()).replace('_JNT1', 'Face_JNT'))
        pm.parent(jointsDuplicates[-1], self.rigmodule.jointsGrp)

        pm.skinCluster(faceGeo, headFaceJnt)

        faceGeoSkincluster = skin.findRelatedSkinCluster(faceGeo)
        pm.skinCluster(faceGeo, edit=True, ai=cvList, ug=True)
        faceGeoSkincluster.useComponents.set(1)

        pm.parent(pm.ls('*_CRVBase'), self.rigmodule.partsNoTransGrp)

        fullLocList = []
        fullClusterList = []
        for cv in pm.ls(cvList):
            pm.rebuildCurve(cv, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=1, kt=0, s=4, d=1, tol=0.01)
            pm.rebuildCurve(cv, ch=0, rpo=1, rt=0, end=1, kr=0, kcp=1, kep=1, kt=0, s=4, d=3, tol=0.01)

            pm.parent(cv, self.rigmodule.partsNoTransGrp)
            locList = self.setupCurve(cv, pointsNumber)
            fullLocList.extend(locList)

            # cluster
            chainCurveCVs = pm.ls(cv + '.cv[*]', fl=1)
            numChainCVs = len(chainCurveCVs)

            curveClusters = []
            for i in range(numChainCVs):
                cls = pm.cluster(chainCurveCVs[i], n=str(cv.name()) + 'Cluster%d' % (i + 1))[1]
                curveClusters.append(cls)

            fullClusterList.extend(curveClusters)

        clusterGrp = pm.group(fullClusterList, n='faceCluster_GRP', p=self.rigmodule.partsNoTransGrp)

        follicleList = []
        for loc, cls in zip(fullLocList, fullClusterList):
            ctrl = control.Control(str(loc.name()).replace('_LOC', ''),
                                   translateTo=loc,
                                   shape='sphere',
                                   parent=self.rigmodule.controlsGrp,
                                   doModify=True,
                                   scale=scale)

            follicle = followCtrl.makeControlFollowSkin(skinGeo, ctrl.getControl(), cls)[-1]
            follicleList.extend([follicle])
        follicleGrp = pm.group(follicleList, n='faceFollicle_GRP', p=self.rigmodule.partsNoTransGrp)