예제 #1
0
    def build(self):
        '''
        '''
        super(Neck, self).build()
        jointList = eval(self.jointList)
        self.spline = spline.SplineBase(jointList=jointList +
                                        [self._skullBind],
                                        splineName=self._splineName)
        self.spline.create()
        grp = mc.rename(self.name, "{}_grp".format(self.name))

        # Neck
        neckNul, neckOrt, neckCtrl = control.create(name="neck",
                                                    controlType="cube",
                                                    color=common.BLUE,
                                                    hierarchy=['nul', "ort"])

        matrix = mc.xform(jointList[0], q=True, ws=True, matrix=True)
        mc.xform(neckNul, ws=True, matrix=matrix)

        # Parent the entire ik group to the neck
        mc.parent(self.spline.getGroup(), neckCtrl)

        # head
        headNul, headCtrl = control.create(name="head",
                                           controlType="cube",
                                           color=common.BLUE,
                                           hierarchy=['nul'])

        # head gimabl control
        # head
        headGimbalNul, headGimbalCtrl = control.create(name="head_gimbal",
                                                       controlType="cube",
                                                       color=common.BLUE,
                                                       hierarchy=['nul'],
                                                       parent=headCtrl)

        clusters = self.spline._clusters
        con = mc.pointConstraint(jointList[0], self._skullBind, headNul)
        mc.delete(con)
        mc.parent(headNul, neckCtrl)
        mc.parent(clusters[2:], headGimbalCtrl)
        mc.orientConstraint(headGimbalCtrl, self.spline._endTwistNul, mo=1)
        skullOffset = mc.duplicate(self._skullBind,
                                   po=True,
                                   rr=True,
                                   name="{}_offset".format(self._skullBind))[0]
        mc.parent(skullOffset, headGimbalCtrl)
        mc.orientConstraint(skullOffset, self.spline._ikJointList[-1], mo=1)
        #mc.connectAttr(headCtrl+'.s', self._skullBind+'.s')

        anchor = self.getAttributeByName('anchor').getValue()
        if mc.objExists(anchor):
            mc.parentConstraint(anchor, neckNul, mo=1)
        else:
            mc.warning('Anchor object [ {} ] does not exist.'.format(anchor))

        mc.parent(neckNul, grp)
        mc.hide(self.spline._group, clusters)
예제 #2
0
    def build(self):
        '''
        '''
        super(Tongue, self).build()
        jointList = eval(self.jointList)
        self.spline = spline.SplineBase(jointList=jointList, splineName=self._splineName)
        self.spline.create()

        # Tongue Base
        tonugeBaseNul, tonugeBaseCtrl = control.create(name="tonuge_base", 
                                          controlType=None,
                                          color=common.RED,
                                          hierarchy=['nul'])

        matrix = mc.xform(jointList[0], q=True, ws=True, matrix=True)
        mc.xform(tonugeBaseNul, ws=True, matrix=matrix)

        # Parent the entire ik group to the neck
        mc.parent(self.spline.getGroup(), tonugeBaseCtrl) 

        # tongue Mid
        tonugeMidNul, tonugeMidCtrl = control.create(name="tonuge_mid", 
                                          controlType=None,
                                          color=common.RED,
                                          hierarchy=['nul'])

        # move the middle control between the last the middle joints
        mc.delete(mc.parentConstraint(jointList[-2], jointList[1], tonugeMidNul))

        mc.parent(tonugeMidNul, tonugeBaseCtrl) 

        # tongue Tip
        tonugeTipNul, tonugeTipCtrl = control.create(name="tonuge_tip", 
                                          controlType=None,
                                          color=common.RED,
                                          hierarchy=['nul'])

        # make the tongue tip matches the last joint in the chain
        matrix=mc.xform(jointList[-1], q=True, ws=True, matrix=True)
        mc.xform(tonugeTipNul, ws=True, matrix=matrix)

        clusters = self.spline._clusters
        mc.parent(tonugeTipNul, tonugeMidCtrl) 
        mc.parent(clusters[2:], tonugeTipCtrl)
        mc.orientConstraint(tonugeTipCtrl, self.spline._endTwistNul, mo=1)
        #mc.parentConstraint(tonugeTipCtrl, self._skullBind, mo=1)
        #mc.connectAttr(headCtrl+'.s', self._skullBind+'.s')

        anchor = self.getAttributeByName('anchor').getValue()
        if mc.objExists(anchor):
            mc.parentConstraint(anchor, tonugeBaseNul, mo=1)
        else:
            mc.warning('Anchor object [ {} ] does not exist.'.format(anchor)) 

        mc.parent(tonugeBaseNul, self.name)
        mc.hide(self.spline._group, clusters)
예제 #3
0
    def build(self):
        '''
        This will build the rig.
        '''
        super(Mouth, self).build()
        lipMainCurve = self.getAttributeByName('lipMainCurve').getValue()
        lipCurve = self.getAttributeByName('lipCurve').getValue()
        parentGroup = self.getAttributeByName('systemParent').getValue()
        geometry = self.getAttributeByName('geometry').getValue()
        headPinTrs = self.getAttributeByName('headPin').getValue()
        jawPinTrs = self.getAttributeByName('jawPin').getValue()
        orientFile = self.getAttributeByName('orientFile').getValue()
        
        bindmeshGeometry, follicleList, lipMainControlHieracrchyList, jointList = self.__buildCurveRig(lipMainCurve, "lip_main" , parentGroup)
        # delete the controls, tparent joint to the node above the control
        mainBaseCurveJointList = list()
        for jnt, lipMainControlList in zip(jointList, lipMainControlHieracrchyList):
            # create the joint that we will use later to deform the base wire.
            baseCurveJoint = mc.joint(name=jnt.replace("_jnt","_baseCurve_jnt"))
            mainBaseCurveJointList.append(baseCurveJoint)
            # hide the base curve joint. Then parent it under the null node
            mc.setAttr("{}.v".format(baseCurveJoint), 0)
            mc.parent(baseCurveJoint, lipMainControlList[1])
            mc.setAttr("{}.t".format(baseCurveJoint), 0, 0, 0)
            mc.parent(jnt,lipMainControlList[-2])
            mc.delete(lipMainControlList.pop(-1))

        # create a bindMesh for mouth corner controls.
        jointListPos = [mc.xform(joint, q=True, ws=True, t=True) for joint in jointList]
        jointListPosX = [round(pos[0], 3) for pos in jointListPos]
        cornerPos = [jointListPos[jointListPosX.index(max(jointListPosX))],
                     jointListPos[jointListPosX.index(min(jointListPosX))]]

        # create the bindmesh 
        bindmeshGeometry, follicleList = bindmesh.create("{}_corner".format(self.name), cornerPos)
        # set the visibility of the bindmesh
        mc.setAttr("{}.v".format(bindmeshGeometry), 0 )
        mouthCorner_l_follicle = mc.rename(follicleList[0], follicleList[0].replace('_0_','_l_'))
        mouthCorner_r_follicle = mc.rename(follicleList[1], follicleList[1].replace('_1_','_r_'))
        mc.parent([mouthCorner_l_follicle, mouthCorner_r_follicle, bindmeshGeometry], self.name)

        controlPrefix = "lip_main"
        # get the position of the controls for lip tweakers
        upperLeft = list()
        upperLeftPosXList = list()
        upperRight = list()
        upperRightPosXList = list()
        lowerLeft = list()
        lowerLeftPosXList = list()
        lowerRight = list()
        lowerRightPosXList = list()
        mouthCornerLeftPosY = round(mc.xform(mouthCorner_l_follicle, q=True, ws=True, t=True)[1], 3)
        mouthCornerRightPosY = round(mc.xform(mouthCorner_r_follicle, q=True, ws=True, t=True)[1], 3)
        for controlHieracrchy in lipMainControlHieracrchyList:
            #position of control
            controlPosition = mc.xform(controlHieracrchy[0], q=True, ws=True, t=True)
            posX = round(controlPosition[0], 3)
            posY = round(controlPosition[1], 3)
            if posX > .001:
                if round(abs(posY-mouthCornerLeftPosY),3) <.003:
                    lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_corner_l")) for ctrl in controlHieracrchy]
                elif posY > mouthCornerLeftPosY:
                    upperLeft.append(controlHieracrchy)
                    upperLeftPosXList.append(posY)
                elif posY < mouthCornerLeftPosY:
                    lowerLeft.append(controlHieracrchy)
                    lowerLeftPosXList.append(posY)

            elif posX < -.001:
                if round(abs(posY-mouthCornerLeftPosY),3) <.003:
                    lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_corner_r")) for ctrl in controlHieracrchy]
                elif posY > mouthCornerRightPosY:
                    upperRight.append(controlHieracrchy)
                    upperRightPosXList.append(posY)
                elif posY < mouthCornerRightPosY:
                    lowerRight.append(controlHieracrchy)
                    lowerRightPosXList.append(posY)
            else:
                if posY > mouthCornerLeftPosY:
                    lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_center_up")) for ctrl in controlHieracrchy]
                elif posY < mouthCornerLeftPosY:
                    lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_center_low")) for ctrl in controlHieracrchy]
        # reorder controls
        upperLeftPosXListCopy = list(upperLeftPosXList)
        upperLeftPosXList.sort()
        # rename the controls for left and right.
        for i, pos in enumerate(upperLeftPosXListCopy):
            # rename the center controls.
            lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(upperLeft[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_up_{}_l".format(upperLeftPosXList.index(pos)))) for ctrl in upperLeft[i]]

        # reorder controls
        upperRightPosXListCopy = list(upperRightPosXList)
        upperRightPosXList.sort()
        # rename the controls for left and right.
        for i, pos in enumerate(upperRightPosXListCopy):
            # rename the center controls.
           lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(upperRight[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_up_{}_r".format(upperRightPosXList.index(pos)))) for ctrl in upperRight[i]]

        # reorder controls
        lowerLeftPosXListCopy = list(lowerLeftPosXList)
        lowerLeftPosXList.sort()
        lowerLeftPosXList.reverse()
        # rename the controls for left and right.
        for i, pos in enumerate(lowerLeftPosXListCopy):
            # rename the center controls.
            lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(lowerLeft[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_low_{}_l".format(lowerLeftPosXList.index(pos)))) for ctrl in lowerLeft[i]]

        # reorder controls
        lowerRightPosXListCopy = list(lowerRightPosXList)
        lowerRightPosXList.sort()
        lowerRightPosXList.reverse()
        # rename the controls for left and right.
        for i, pos in enumerate(lowerRightPosXListCopy):
            # rename the center controls.
            lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(lowerRight[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_low_{}_r".format(lowerRightPosXList.index(pos)))) for ctrl in lowerRight[i]]


        # create the controls
        # If there is a hierarchy argument passed in. We will loop through and create the hiearchy.
        # move the orients
        nodeDataObj = None
        if os.path.isfile(orientFile):
            nodeDataObj = node_data.NodeData()
            nodeDataObj.read(orientFile)

        for follicle in (mouthCorner_l_follicle, mouthCorner_r_follicle):
            parent = follicle
            controlName = follicle.split("_follicle")[0]
            # create the control with a large enough hierarchy to create proper SDK's
            ctrlHierarchy = control.create(name=controlName, 
                controlType="square", 
                hierarchy=['nul','ort', 'auto'], 
                color=common.BLACK,
                parent=parent)
            driverMouthCorner = mc.createNode("joint", name="{}_driver".format(controlName))
            # mover the driver to the orient and parent it under the orient
            mc.parent(driverMouthCorner, ctrlHierarchy[1])
            #mc.xform(driverMouthCorner, ws=True, matrix=mc.xform(ctrlHierarchy[1], q=True, ws=True, matrix=True))
            
            # turn off the visibility of the driver
            mc.setAttr("{}.drawStyle".format(driverMouthCorner), 2)
            # turn on the handle for the mouth corner control and move it 
            mc.setAttr("{}.displayHandle".format(ctrlHierarchy[-1]), 1)
            mc.setAttr("{}.selectHandleX".format(ctrlHierarchy[-1]) ,0.2)
            # zero out the mouth corner hierarchy so it's in the correct position.
            mc.setAttr("{}.translate".format(ctrlHierarchy[0]), 0,0,0)
            #mc.setAttr("{}.rotate".format(ctrlHierarchy[0]), 0,0,0)
            mc.delete(mc.listRelatives(ctrlHierarchy[-1], c=True, shapes=True)[0])

            # create the drivers for the lip_L/R
            neutral = mc.createNode("transform", name="{}_neutral".format(controlName))
            headPin = mc.createNode("transform", name="{}_headPin".format(controlName))
            jawPin = mc.createNode("transform", name="{}_jawPin".format(controlName))

            for pinGrp in [neutral, headPin, jawPin]:
                mc.xform(pinGrp, ws=True, matrix=mc.xform(ctrlHierarchy[1], q=True, ws=True, matrix=True))
                mc.parent(pinGrp, ctrlHierarchy[1])
                cst = mc.parentConstraint(pinGrp, ctrlHierarchy[2])[0]

            # constrain the driver to the control
            mc.pointConstraint(ctrlHierarchy[-1], driverMouthCorner, mo=True)

            if nodeDataObj:
                nodeDataObj.applyData([ctrlHierarchy[1]])

            # constrain the head and jaw pinning.
            mc.parentConstraint(jawPinTrs, jawPin, mo=True)
            mc.parentConstraint(headPinTrs, headPin, mo=True)

            # create the head and jaw pinning.
            mc.addAttr(controlName, ln="pinning", nn="----------", at="enum", enumName="Pinning", keyable=True)
            attribute.lock(controlName, "pinning")
            mc.addAttr(controlName, ln="pin", at="double", min=-10, max=10, dv=0, keyable=True)
            mc.setDrivenKeyframe("{}.{}W0".format(cst,neutral), 
                cd="{}.pin".format(controlName), v=1, dv=0)
            mc.setDrivenKeyframe("{}.{}W1".format(cst,headPin), 
                cd="{}.pin".format(controlName), v=0, dv=0)
            mc.setDrivenKeyframe("{}.{}W2".format(cst,jawPin), 
                cd="{}.pin".format(controlName), v=0, dv=0)
            mc.setDrivenKeyframe("{}.{}W0".format(cst,neutral), 
                cd="{}.pin".format(controlName), v=0, dv=-10)
            mc.setDrivenKeyframe("{}.{}W1".format(cst,headPin), 
                cd="{}.pin".format(controlName), v=0, dv=-10)
            mc.setDrivenKeyframe("{}.{}W2".format(cst,jawPin), 
                cd="{}.pin".format(controlName), v=1, dv=-10)
            mc.setDrivenKeyframe("{}.{}W0".format(cst,neutral), 
                cd="{}.pin".format(controlName), v=0, dv=10)
            mc.setDrivenKeyframe("{}.{}W1".format(cst,headPin), 
                cd="{}.pin".format(controlName), v=1, dv=10)
            mc.setDrivenKeyframe("{}.{}W2".format(cst,jawPin), 
                cd="{}.pin".format(controlName), v=0, dv=10)

            # create the set driven keyframes
            for attr in ['x','y','z']:
                for lipMainControl in lipMainControlHieracrchyList:
                    if "_l_" in lipMainControl[3] and follicle == mouthCorner_l_follicle:
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=1, dv=1)
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=-1, dv=-1)
                        if attr == "x":
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=10, dv=1)
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=-10, dv=-1)
                    elif  "_r_" in lipMainControl[3] and follicle == mouthCorner_r_follicle:
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=1, dv=1)
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=-1, dv=-1)
                        if attr == "x":
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=10, dv=1)
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=-10, dv=-1)

        # control prefix for the lips
        controlPrefix = "lip"
        bindmeshGeometry, follicleList, controlHieracrchyList, jointList = self.__buildCurveRig(lipCurve, controlPrefix , parentGroup)

        # get the position of the controls for lip tweakers
        upperLeft = list()
        upperLeftPosXList = list()
        upperRight = list()
        upperRightPosXList = list()
        lowerLeft = list()
        lowerLeftPosXList = list()
        lowerRight = list()
        lowerRightPosXList = list()
        mouthCornerLeftPosY = round(mc.xform(mouthCorner_l_follicle, q=True, ws=True, t=True)[1], 3)
        mouthCornerRightPosY = round(mc.xform(mouthCorner_r_follicle, q=True, ws=True, t=True)[1], 3)
        for controlHieracrchy in controlHieracrchyList:
            # create the joint that we will use later to deform the base wire.
            baseCurveJoint = mc.joint(name=jointList[controlHieracrchyList.index(controlHieracrchy)].replace("_jnt","_baseCurve_jnt"))
            # hide the base curve joint. Then parent it under the null node
            mc.setAttr("{}.v".format(baseCurveJoint), 0)
            mc.parent(baseCurveJoint, controlHieracrchy[0])
            #position of control
            controlPosition = mc.xform(controlHieracrchy[0], q=True, ws=True, t=True)
            posX = round(controlPosition[0], 3)
            posY = round(controlPosition[1], 3)
            if posX > .001:
                if round(abs(posY-mouthCornerLeftPosY),3) <.003:
                    controlHieracrchyList[controlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_corner_l")) for ctrl in controlHieracrchy]
                elif posY > mouthCornerLeftPosY:
                    upperLeft.append(controlHieracrchy)
                    upperLeftPosXList.append(posY)
                elif posY < mouthCornerLeftPosY:
                    lowerLeft.append(controlHieracrchy)
                    lowerLeftPosXList.append(posY)

            elif posX < -.001:
                if round(abs(posY-mouthCornerLeftPosY),3) <.003:
                    controlHieracrchyList[controlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_corner_r")) for ctrl in controlHieracrchy]
                elif posY > mouthCornerRightPosY:
                    upperRight.append(controlHieracrchy)
                    upperRightPosXList.append(posY)
                elif posY < mouthCornerRightPosY:
                    lowerRight.append(controlHieracrchy)
                    lowerRightPosXList.append(posY)
            else:
                if posY > mouthCornerLeftPosY:
                    controlHieracrchyList[controlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_center_up")) for ctrl in controlHieracrchy]
                elif posY < mouthCornerLeftPosY:
                    controlHieracrchyList[controlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_center_low")) for ctrl in controlHieracrchy]
        # reorder controls
        upperLeftPosXListCopy = list(upperLeftPosXList)
        upperLeftPosXList.sort()
        # rename the controls for left and right.
        for i, pos in enumerate(upperLeftPosXListCopy):
            # rename the center controls.
            controlHieracrchyList[controlHieracrchyList.index(upperLeft[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_up_{}_l".format(upperLeftPosXList.index(pos)))) for ctrl in upperLeft[i]]

        # reorder controls
        upperRightPosXListCopy = list(upperRightPosXList)
        upperRightPosXList.sort()
        # rename the controls for left and right.
        for i, pos in enumerate(upperRightPosXListCopy):
            # rename the center controls.
           controlHieracrchyList[controlHieracrchyList.index(upperRight[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_up_{}_r".format(upperRightPosXList.index(pos)))) for ctrl in upperRight[i]]

        # reorder controls
        lowerLeftPosXListCopy = list(lowerLeftPosXList)
        lowerLeftPosXList.sort()
        lowerLeftPosXList.reverse()
        # rename the controls for left and right.
        for i, pos in enumerate(lowerLeftPosXListCopy):
            # rename the center controls.
            controlHieracrchyList[controlHieracrchyList.index(lowerLeft[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_low_{}_l".format(lowerLeftPosXList.index(pos)))) for ctrl in lowerLeft[i]]

        # reorder controls
        lowerRightPosXListCopy = list(lowerRightPosXList)
        lowerRightPosXList.sort()
        lowerRightPosXList.reverse()
        # rename the controls for left and right.
        for i, pos in enumerate(lowerRightPosXListCopy):
            # rename the center controls.
            controlHieracrchyList[controlHieracrchyList.index(lowerRight[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_low_{}_r".format(lowerRightPosXList.index(pos)))) for ctrl in lowerRight[i]]


        # parent the curves to their respective systems
        mc.parent(lipMainCurve, "lip_main")
        mc.parent(lipCurve, "lip")

        #deform the lip bindmesh with the lip_main curve using a wire deformer.
        wireDeformer = mc.wire(bindmeshGeometry, gw=False, en=1.00, ce=0.00, li=0.00, 
                w=lipMainCurve, name="{}_wire".format(lipMainCurve))[0]
        # set the default values for the wire deformer
        mc.setAttr("{}.rotation".format(wireDeformer), 0)
        mc.setAttr("{}.dropoffDistance[0]".format(wireDeformer), 100)

        # create skinCluster for the base wire
        baseCurve = "{}BaseWire".format(lipMainCurve)
        lipMainBaseCurveSkin = mc.skinCluster(*mainBaseCurveJointList+mc.ls(baseCurve), 
                                    n="{}_skinCluster".format(baseCurve),
                                    tsb=True)[0]
        # set the weights to have proper weighting
        wtObj = rigrepo.libs.weights.getWeights(lipMainBaseCurveSkin)
        weightList = list()
        for i, inf in enumerate(wtObj):
            array = numpy.zeros_like(wtObj.getWeights(inf))[0]
            array[i] = 1
            weightList.append(array)
        wtObj.setWeights(weightList)
        rigrepo.libs.weights.setWeights(lipMainBaseCurveSkin, wtObj)

        # create all of the lip clusters
        lipControls = list(set(mc.ls("lip_*.__control__", o=True)).difference(set(mc.ls(["lip_upper","lip_lower"]))))
        for node in lipControls:
            rigrepo.libs.cluster.create(geometry, 
                                        "{}_cluster".format(node), 
                                        contraintTypes=["orient","scale"], 
                                        parent="{}_def_auto".format(node), 
                                        parallel=False)
            nul = "{}_cluster_nul".format(node)
            mc.xform(nul, ws=True, matrix=mc.xform(node, q=True, ws=True, matrix=True))
            mc.connectAttr("{}.t".format(node), "{}_cluster_auto.t".format(node), f=True)
            mc.connectAttr("{}.r".format(node), "{}_cluster_ctrl.r".format(node), f=True)
            mc.connectAttr("{}.s".format(node), "{}_cluster_ctrl.s".format(node), f=True)
예제 #4
0
    def __buildCurveRig(self, curve, name='lip', parent=None):
        '''
        This will build a rig setup based on the curve that is passed in.

        :param curve: NurbsCurve name you want to build the rig on.
        :type curve: str

        :param name: This will be used to name the control hierachy and joints in the rig.
        :type name: str

        :return: This method will return the data needed to make adjustments to rig.
        :rtype: tuple
        '''
        # Do some check
        if not mc.objExists(curve):
            raise RuntimeError("{} doesn't exist in the current Maya session.".format(curve))
        # If the name passed in doesn't exist, we will create a transform as the parent group
        # for the rig.
        if not mc.objExists(name):
            mc.createNode("transform", n=name)
        # create the bindmesh 
        #
        # follicleList = (follicle transform, follicle shape) 
        # bindmeshGeometry = geometry name of bindmesh
        #
        bindmeshGeometry, follicleList = bindmesh.createFromCurve(name, curve)
        # emptry list to append controls to in the loop
        controlHieracrchyList = list()
        jointList = list()

        # loop through and create controls on the follicles so we have controls to deform the wire.
        for follicle in follicleList:
            # get the follicle transform so we can use it to parent the control to it.
            follicleIndex = follicleList.index(follicle)
            # create the control with a large enough hierarchy to create proper SDK's
            ctrlHierarchy = control.create(name="{}_{}".format(name, follicleIndex), 
                controlType="square", 
                hierarchy=['nul','ort','rot_def_auto','def_auto'], 
                parent=follicle)

            # create the joint that will drive the curve.
            jnt = mc.joint(n="{}_{}_jnt".format(name, follicleIndex))
            # make sure the joint is in the correct space
            mc.setAttr("{}.translate".format(jnt), 0,0,0)
            mc.setAttr("{}.rotate".format(jnt), 0,0,0)
            mc.setAttr("{}.drawStyle".format(jnt),2)
            mc.setAttr("{}.displayHandle".format(ctrlHierarchy[-1]), 1)
            mc.delete(mc.listRelatives(ctrlHierarchy[-1], c=True, shapes=True)[0])

            # zero out the nul for the control hierarchy so it's in the correct position.
            mc.setAttr("{}.translate".format(ctrlHierarchy[0]), 0,0,0)
            #mc.setAttr("{}.rotate".format(ctrlHierarchy[0]), 0,0,0)
            # set the visibility of the shape node for the follicle to be off.
            # append the control and the follicle transform to their lists
            controlHieracrchyList.append(ctrlHierarchy)
            jointList.append(jnt)

        # This will parent all of the data for the rig to the system group "name"
        for data in (bindmeshGeometry, follicleList):
            mc.parent(data, name)

        # If parent the parent is passed in we will parent the system to the parent.
        if parent:
            if not mc.objExists(parent):
                mc.warning('Created the system but the current parent "{}" does not exist in the \
                    current Maya session.'.format(parent))
            else:
                mc.parent(name, parent)

        # create the skinCluster for the lipMainCurve
        mc.skinCluster(*jointList + [curve], tsb=True, name="{}_skinCluster".format(curve))

        # set the visibility of the bindmesh.
        mc.setAttr("{}.v".format(bindmeshGeometry), 0 )
        mc.setAttr("{}.v".format(curve), 0 )
        return bindmeshGeometry, follicleList, controlHieracrchyList, jointList
예제 #5
0
파일: spine.py 프로젝트: rombick/rigrepo
    def build(self):
        '''
        '''
        super(Spine, self).build()

        # store the joint list
        jointList = eval(self.jointList)

        # initialize the spline class
        scaleFactor = self.getAttributeByName('scaleFactor').getValue()
        self.spline = spline.SplineBase(jointList=jointList +
                                        [self._chestBind],
                                        splineName=self._splineName,
                                        scaleFactor=scaleFactor)
        # create the spline
        self.spline.create()

        # get the name of the curveInfo node. This is hard coded to be this way in the
        # spline  code. If that changes, this will not work. We can change the code below
        # to use the API to get the length of the curve instead of this node, but for now, this
        # is quicker because it's available already.
        spineCurveInfo = self._splineName + "_curveInfo"

        # get the attributes from the user
        geometry = self.getAttributeByName("geometry").getValue()
        bendyCurve = self.getAttributeByName("bendyCurve").getValue()
        createBendySpline = self.getAttributeByName(
            "createBendySpline").getValue()
        hipSwivelPivotValue = self.getAttributeByName(
            "hipSwivelPivot").getValue()
        chestPivotValue = self.getAttributeByName("chestPivot").getValue()
        # Hips
        hipMatrix = mc.xform(self._hipsBind, q=True, ws=True, matrix=True)
        hipsPivotNul, hipsPivotCtrl = control.create(
            name="hipsPivot",
            controlType="cube",
            hideAttrs=["sx", "sy", "sz", "v"],
            hierarchy=['nul'],
            color=rigrepo.libs.common.RED)

        # create the grp that we will use to move the pivot of the hips
        movablePivotGrp = mc.createNode("transform",
                                        name="{}_grp".format(hipsPivotCtrl))
        mc.xform(hipsPivotNul, ws=True, matrix=hipMatrix)
        mc.xform(movablePivotGrp, ws=True, matrix=hipMatrix)
        mc.parent(movablePivotGrp, hipsPivotNul)

        # connect the movable pivot control to the grp
        mc.connectAttr("{}.t".format(hipsPivotCtrl),
                       "{}.rotatePivot".format(movablePivotGrp),
                       f=True)
        mc.connectAttr("{}.r".format(hipsPivotCtrl),
                       "{}.r".format(movablePivotGrp),
                       f=True)

        hipsCtrlHierarchy = control.create(name="hips",
                                           controlType="cube",
                                           hideAttrs=["sx", "sy", "sz", "v"],
                                           hierarchy=['nul'])

        hipsCtrl = hipsCtrlHierarchy[-1]
        hipsNul = hipsCtrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(hipsCtrl, ["sx", "sy", "sz", "v"])
        mc.xform(hipsNul, ws=True, matrix=hipMatrix)

        hipsGimbalCtrlHierarchy = control.create(
            name="hips_gimbal",
            controlType="cube",
            hierarchy=['nul'],
            hideAttrs=["sx", "sy", "sz", "v"],
            parent=hipsCtrl)
        hipsGimbalCtrl = hipsGimbalCtrlHierarchy[-1]
        hipsGimbalNul = hipsGimbalCtrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(hipsGimbalCtrl,
                                           ["sx", "sy", "sz", "v"])
        mc.xform(hipsGimbalNul, ws=True, matrix=hipMatrix)

        # hip swivel
        ctrlHierarchy = control.create(name="hip_swivel",
                                       controlType="cube",
                                       color=common.GREEN,
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        hipSwivelCtrl = ctrlHierarchy[-1]
        hipSwivelNul = ctrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(hipSwivelCtrl,
                                           ["sx", "sy", "sz", "v"])
        mc.xform(hipSwivelNul, ws=True, matrix=hipMatrix)
        averagePos = rigrepo.libs.transform.getAveragePosition([jointList[0]])
        mc.xform(hipSwivelNul,
                 ws=True,
                 t=mc.xform(jointList[0], q=True, ws=True, t=True))

        mc.parent(hipSwivelNul, hipsGimbalCtrl)
        clusters = self.spline._clusters

        # create a group that is driven by the ctrl
        hipSwivelGrp = mc.createNode("transform", n="hips_swivel_grp")

        # move the group into the same matrix as the control
        mc.xform(hipSwivelGrp,
                 ws=True,
                 matrix=mc.xform(hipSwivelCtrl, q=True, ws=True, matrix=True))
        # parent the group into the same space as the control
        mc.parent(hipSwivelGrp, hipSwivelCtrl)
        mc.parent(clusters[0:2], hipSwivelGrp)
        mc.orientConstraint(hipSwivelGrp, self.spline._startTwistNul, mo=1)

        # Parent the entire ik group to the hips
        mc.parent(self.spline.getGroup(), hipsGimbalCtrl)

        # torso
        ctrlHierarchy = control.create(name="torso",
                                       controlType="cube",
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        torsoCtrl = ctrlHierarchy[-1]
        torsoNul = ctrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(torsoCtrl, ["sx", "sy", "sz", "v"])
        rotation = mc.xform(hipsCtrl, q=True, ws=True, rotation=True)
        averagePos = rigrepo.libs.transform.getAveragePosition(jointList[:2])
        mc.xform(torsoNul, ws=True, rotation=rotation)
        mc.xform(torsoNul, ws=True, t=averagePos)
        mc.parent(torsoNul, hipsGimbalCtrl)

        # chest
        ctrlHierarchy = control.create(name="chest",
                                       controlType="cube",
                                       color=common.GREEN,
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        chestCtrl = ctrlHierarchy[-1]
        chestNul = ctrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(chestCtrl, ["sx", "sy", "sz", "v"])
        matrix = mc.xform(self._chestBind, q=True, ws=True, matrix=True)

        mc.xform(chestNul, ws=True, matrix=matrix)
        mc.parent(chestNul, torsoCtrl)

        # chest IK
        ctrlHierarchy = control.create(name="chest_ik",
                                       controlType="cube",
                                       color=common.GREEN,
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        chestIkCtrl = ctrlHierarchy[-1]
        chestIkNul = ctrlHierarchy[0]

        rigrepo.libs.attribute.lockAndHide(chestIkCtrl,
                                           ["sx", "sy", "sz", "v"])

        mc.xform(chestIkNul, ws=True, matrix=matrix)
        mc.parent(chestIkNul, chestCtrl)
        # connect the rotate pivots so the pivots for these two controls are in the same location.
        mc.connectAttr("{}.rp".format(chestCtrl),
                       "{}.rp".format(chestIkCtrl),
                       f=True)

        # chest top
        ctrlHierarchy = control.create(name="chest_top",
                                       controlType="cube",
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        chestTopCtrl = ctrlHierarchy[-1]
        chestTopNul = ctrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(chestTopCtrl,
                                           ["sx", "sy", "sz", "v"])

        mc.xform(chestTopNul, ws=True, matrix=matrix)
        mc.parent(chestTopNul, chestIkCtrl)

        mc.parent(clusters[2:], chestIkCtrl)
        chestTopGrp = mc.createNode("transform", name="chest_top_grp")
        mc.xform(chestTopGrp, ws=True, matrix=matrix)
        mc.parent(chestTopGrp, chestTopCtrl)
        mc.orientConstraint(chestTopGrp, self.spline._endTwistNul, mo=1)

        # ==========================================================================================
        # chest pivot
        # create pivot attributes to use for moving the pivot and tangent heights.
        mc.addAttr(chestCtrl,
                   ln="pivotHeight",
                   at="double",
                   dv=0,
                   min=0,
                   max=10,
                   keyable=True)
        mc.setAttr("{}.pivotHeight".format(chestCtrl), chestPivotValue)

        # create the remap node to use to remap the pivot height to the lenght of the curve
        chestRemapNode = mc.createNode("remapValue", n="chest_pivot_remap")

        # map the 0-10 to the length of the curve on the spine
        curveLength = mc.getAttr("{}.arcLength".format(spineCurveInfo))

        # set the max output value for the remap to be the length of the curve
        mc.setAttr("{}.outputMax".format(chestRemapNode), curveLength)

        # set the input max
        mc.setAttr("{}.inputMax".format(chestRemapNode), 10)

        # connect the slider for pivot to the input max
        mc.connectAttr("{}.pivotHeight".format(chestCtrl),
                       "{}.inputValue".format(chestRemapNode),
                       f=True)

        # get the aim axis
        chestPivotNulGrp = mc.createNode("transform",
                                         name="chestPivot_aim_nul")
        chestPivotAimGrp = mc.createNode("transform",
                                         name="chestPivot_aim_grp")
        chestPivotDriver = mc.createNode("transform",
                                         name="chestPivot_aim_drv")
        mc.parent(chestPivotAimGrp, chestPivotNulGrp)
        mc.parent(chestPivotNulGrp, chestCtrl)
        mc.parent(chestPivotDriver, chestPivotAimGrp)
        mc.xform(chestPivotNulGrp, ws=True, matrix=matrix)
        mc.xform(chestPivotDriver, ws=True, matrix=hipMatrix)
        aimAxis, aimVector = self._getDistanceVector(
            mc.getAttr('{}.t'.format(chestPivotDriver))[0])
        mc.parent(chestPivotNulGrp, chestNul)

        # move the transform back to the skull
        mc.xform(chestPivotDriver, ws=True, matrix=matrix)
        mc.xform(chestPivotNulGrp,
                 ws=True,
                 t=mc.xform(chestNul, q=True, ws=True, t=True))
        mc.orientConstraint(chestNul, chestPivotNulGrp)
        mc.parent(chestPivotDriver, chestNul)
        mc.pointConstraint(chestPivotAimGrp, chestPivotDriver)
        mc.orientConstraint(chestPivotAimGrp, chestPivotDriver)

        if '-' in aimAxis:
            chestCtrlPivotMdl = mc.createNode('multDoubleLinear',
                                              n='chest_pivot_mdl')
            mc.connectAttr('{}.outValue'.format(chestRemapNode),
                           '{}.input1'.format(chestCtrlPivotMdl),
                           f=True)
            mc.setAttr('{}.input2'.format(chestCtrlPivotMdl), -1)
            mc.connectAttr('{}.output'.format(chestCtrlPivotMdl),
                           '{}.t{}'.format(chestPivotAimGrp,
                                           aimAxis.strip('-')),
                           f=True)
            mc.connectAttr('{}.t'.format(chestPivotDriver),
                           '{}.rotatePivot'.format(chestCtrl),
                           f=True)
        else:
            mc.connectAttr('{}.outValue'.format(chestRemapNode),
                           '{}.t{}'.format(chestPivotAimGrp, aimAxis),
                           f=True)
            mc.connectAttr('{}.t'.format(chestPivotDriver),
                           '{}.rotatePivot'.format(chestCtrl),
                           f=True)

        # ==========================================================================================
        # hip swivel pivot

        # create pivot attributes to use for moving the pivot and tangent heights.
        mc.addAttr(hipSwivelCtrl,
                   ln="pivotHeight",
                   at="double",
                   dv=0,
                   min=0,
                   max=10,
                   keyable=False)
        mc.setAttr("{}.pivotHeight".format(hipSwivelCtrl), hipSwivelPivotValue)

        # create the remap node to use to remap the pivot height to the lenght of the curve
        hipSwivelRemapNode = mc.createNode("remapValue",
                                           n="hipSwivel_pivot_remap")

        # set the max output value for the remap to be the length of the curve
        mc.setAttr("{}.outputMax".format(hipSwivelRemapNode), curveLength)

        # set the input max
        mc.setAttr("{}.inputMax".format(hipSwivelRemapNode), 10)

        # connect the slider for pivot to the input max
        mc.connectAttr("{}.pivotHeight".format(hipSwivelCtrl),
                       "{}.inputValue".format(hipSwivelRemapNode),
                       f=True)

        # get the aim axis
        tempNode = mc.createNode("transform", name="temp")
        mc.parent(tempNode, hipSwivelGrp)
        mc.xform(tempNode, ws=True, matrix=matrix)
        aimAxis, aimVector = self._getDistanceVector(
            mc.getAttr('{}.t'.format(tempNode))[0])
        mc.delete(tempNode)
        if '-' in aimAxis:
            hipSwivelPivotMdl = mc.createNode('multDoubleLinear',
                                              n='hipSwivel_pivot_pma')

            mc.connectAttr("{}.outValue".format(hipSwivelRemapNode),
                           '{}.input1'.format(hipSwivelPivotMdl),
                           f=True)

            mc.setAttr('{}.input2'.format(hipSwivelPivotMdl), -1)

            mc.connectAttr('{}.output'.format(hipSwivelPivotMdl),
                           '{}.rotatePivot{}'.format(
                               hipSwivelCtrl,
                               aimAxis.strip('-').capitalize()),
                           f=True)
        else:
            mc.connectAttr("{}.outValue".format(hipSwivelRemapNode),
                           '{}.rotatePivot{}'.format(hipSwivelCtrl,
                                                     aimAxis.capitalize()),
                           f=True)

        self._hipsCtrl = hipsCtrl
        self._hipSwivelCtrl = hipSwivelCtrl
        self._torsoCtrl = torsoCtrl
        self._chestCtrl = chestCtrl
        self._chestTopCtrl = chestTopCtrl
        self._chestIkCtrl = chestIkCtrl

        # Remove existing constraint on chestBind
        orientConstraint = mc.orientConstraint(self._chestBind, q=1)
        pointConstraint = mc.pointConstraint(self._chestBind, q=1)
        if orientConstraint:
            mc.delete(orientConstraint)
        if pointConstraint:
            mc.delete(pointConstraint)

        mc.pointConstraint(chestTopGrp, self._chestBind, mo=1)
        mc.orientConstraint(chestTopGrp, self._chestBind, mo=1)
        #mc.connectAttr(chestTopCtrl+'.s', self._chestBind+'.s')

        mc.parentConstraint(hipSwivelGrp, self._hipsBind, mo=1)
        mc.connectAttr(hipSwivelGrp + '.s', self._hipsBind + '.s')

        mc.parent(hipsPivotNul, self.name)
        mc.parent(hipsNul, movablePivotGrp)

        mc.hide(self.spline._group, clusters)

        if createBendySpline and mc.objExists(bendyCurve):
            bindmeshGeometry, follicleList, controlHieracrchyList, bendJointList = self.__buildCurveRig(
                bendyCurve,
                name='{}_bend'.format(self.getName()),
                parent=self.name)

            if mc.objExists(geometry):
                #deform the lid bindmesh with the lid curve using a wire deformer.
                wireDeformer = mc.wire(geometry,
                                       gw=False,
                                       en=1.00,
                                       ce=0.00,
                                       li=0.00,
                                       w=bendyCurve,
                                       name="{}_wire".format(bendyCurve))[0]
                baseCurveJointList = list()
                i = 0
                for jnt, controlList in zip(bendJointList,
                                            controlHieracrchyList):
                    # create the joint that we will use later to deform the base wire.
                    baseCurveJoint = mc.joint(
                        name=jnt.replace("_jnt", "_baseCurve_jnt"))
                    baseCurveJointList.append(baseCurveJoint)
                    # hide the base curve joint. Then parent it under the null node
                    mc.setAttr("{}.v".format(baseCurveJoint), 0)
                    mc.parent(baseCurveJoint, controlList[1])
                    mc.setAttr("{}.t".format(baseCurveJoint), 0, 0, 0)

                baseCurve = "{}BaseWire".format(bendyCurve)
                mc.parent([bendyCurve, baseCurve], self.name)
                baseCurveSkin = mc.skinCluster(
                    *[baseCurveJointList] + mc.ls(baseCurve),
                    n="{}_skinCluster".format(baseCurve),
                    tsb=True)[0]

                # set the default values for the wire deformer
                mc.setAttr("{}.rotation".format(wireDeformer), 0)
                mc.setAttr("{}.dropoffDistance[0]".format(wireDeformer), 100)

            bindMeshSkin = mc.skinCluster(
                *jointList + [self._hipsBind, self._chestBind] +
                mc.ls(bindmeshGeometry),
                n="{}_skinCluster".format(bindmeshGeometry),
                tsb=True)[0]

            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[0:3]'.format(bindmeshGeometry),
                           transformValue=[(self._hipsBind, 1.0),
                                           (jointList[0], 0.0)])
            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[4:7]'.format(bindmeshGeometry),
                           transformValue=[(jointList[0], 0.0),
                                           (jointList[1], 1.0),
                                           (jointList[2], 0.0)])
            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[8:11]'.format(bindmeshGeometry),
                           transformValue=[(jointList[3], 1.0),
                                           (jointList[1], 0.0)])
            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[12:15]'.format(bindmeshGeometry),
                           transformValue=[(jointList[2], 0.0),
                                           (jointList[4], 0.0),
                                           (self._chestBind, 1.0)])
            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[16:19]'.format(bindmeshGeometry),
                           transformValue=[(self._chestBind, 1.0),
                                           (jointList[1], 0.0),
                                           (jointList[2], 0.0)])

        # ------------------------------------------------------------------------------------
        # Length Preservation
        # ------------------------------------------------------------------------------------
        spline.preserveLength(name='spineIk_length',
                              curve='spineIk_curve',
                              primary_control='chest',
                              rotate_controls=['torso', 'chest', 'chest_ik'],
                              no_rotate_cvs=[2, 3],
                              parent='spine',
                              position_output_child='chest_top_nul')
예제 #6
0
    def build(self):
        '''
        This is where the builds will happen.
        '''
        super(Brow, self).build()

        # get all of the inputs to the node.
        side = self.getAttributeByName("side").getValue()
        anchor = self.getAttributeByName("anchor").getValue()
        browInner = self.getAttributeByName("browInner").getValue().format(
            side=side)
        browMain = self.getAttributeByName("browMain").getValue().format(
            side=side)
        browPeak = self.getAttributeByName("browPeak").getValue().format(
            side=side)
        curve = self.getAttributeByName("curve").getValue().format(side=side)
        browInnerJoint = self.getAttributeByName(
            "browInnerJoint").getValue().format(browInner=browInner)
        browMainJoint = self.getAttributeByName(
            "browMainJoint").getValue().format(browMain=browMain)
        browPeakJoint = self.getAttributeByName(
            "browPeakJoint").getValue().format(browPeak=browPeak)
        driverParent = self.getAttributeByName("driverParent").getValue()
        geometry = self.getAttributeByName("geometry").getValue()
        mc.parent(self.name, driverParent)
        # going to create the control hierarchies.
        browMainNul, browMainOrient, browMainCtrl = control.create(
            name=browMain,
            controlType="null",
            hierarchy=['nul', 'ort'],
            color=common.BLUE,
            parent=anchor,
            type='face')

        browInnerNul, browInnerOrient, browInnerCtrl = control.create(
            name=browInner,
            controlType="null",
            hierarchy=['nul', 'ort'],
            color=common.BLUE,
            parent=anchor,
            type='face')

        browPeakNul, browPeakOrient, browPeakCtrl = control.create(
            name=browPeak,
            controlType="null",
            hierarchy=['nul', 'ort'],
            color=common.BLUE,
            parent=anchor,
            type='face')

        # Position the controls
        #
        # Main
        mc.xform(browMainNul, ws=1, t=mc.xform(browMainJoint, q=1, ws=1, t=1))
        con = mc.orientConstraint(browMainJoint, browMainOrient)[0]
        if '_r_' in browMainJoint:
            mc.setAttr(con + '.offsetZ', -180)
            mc.setAttr(browMainNul + '.ry', -180)
            mc.setAttr(browMainNul + '.sz', -1)
        mc.delete(con)

        # Inner
        mc.xform(browInnerNul,
                 ws=1,
                 t=mc.xform(browInnerJoint, q=1, ws=1, t=1))
        con = mc.orientConstraint(browInnerJoint, browInnerOrient)[0]
        if '_r_' in browInnerJoint:
            mc.setAttr(con + '.offsetZ', -180)
            mc.setAttr(browInnerNul + '.ry', -180)
            mc.setAttr(browInnerNul + '.sz', -1)
        mc.delete(con)

        mc.xform(browPeakNul, ws=1, t=mc.xform(browPeakJoint, q=1, ws=1, t=1))
        con = mc.orientConstraint(browPeakJoint, browPeakOrient)[0]
        if '_r_' in browPeakJoint:
            mc.setAttr(con + '.offsetZ', -180)
            mc.setAttr(browPeakNul + '.ry', -180)
            mc.setAttr(browPeakNul + '.sz', -1)
        mc.delete(con)

        mc.parent(browInnerNul, browMainCtrl)
        mc.parent(browPeakNul, browMainCtrl)

        # create the driver nodes
        browMainDriverNul = mc.createNode(
            "transform",
            name="{}_driver_nul".format(browMain),
            parent=self.name)
        browMainDriverOrt = mc.createNode(
            "transform",
            name="{}_driver_ort".format(browMain),
            parent=browMainDriverNul)
        browMainDriver = mc.createNode("joint",
                                       name="{}_driver".format(browMain),
                                       parent=browMainDriverOrt)

        # position the driver
        mc.xform(browMainDriverNul,
                 ws=True,
                 matrix=mc.xform(browMainNul, q=True, ws=True, matrix=True))
        for attr in ['t', 'r', 's']:
            mc.connectAttr("{}.{}".format(browMainOrient, attr),
                           "{}.{}".format(browMainDriverOrt, attr),
                           f=True)

        mc.pointConstraint(browMainCtrl, browMainDriver)

        # TX and TY isolated drivers
        browMain_TX_driver = mc.duplicate(
            browMainDriver, po=1, name="{}_TX_driver".format(browMain))[0]
        browMain_TY_driver = mc.duplicate(
            browMainDriver, po=1, name="{}_TY_driver".format(browMain))[0]
        mc.connectAttr(browMainDriver + '.tx', browMain_TX_driver + '.tx')
        mc.connectAttr(browMainDriver + '.ty', browMain_TY_driver + '.ty')

        browInnerDriverNul = mc.createNode(
            "transform",
            name="{}_driver_nul".format(browInner),
            parent=self.name)
        browInnerDriverOrt = mc.createNode(
            "transform",
            name="{}_driver_ort".format(browInner),
            parent=browInnerDriverNul)
        browInnerDriver = mc.createNode("joint",
                                        name="{}_driver".format(browInner),
                                        parent=browInnerDriverOrt)

        # position the driver
        mc.xform(browInnerDriverNul,
                 ws=True,
                 matrix=mc.xform(browInnerNul, q=True, ws=True, matrix=True))

        for attr in ['t', 'r', 's']:
            mc.connectAttr("{}.{}".format(browInnerOrient, attr),
                           "{}.{}".format(browInnerDriverOrt, attr),
                           f=True)

        mc.pointConstraint(browInnerCtrl, browInnerDriver)

        # TX and TY isolated drivers
        browInner_TX_driver = mc.duplicate(
            browInnerDriver, po=1, name="{}_TX_driver".format(browInner))[0]
        browInner_TY_driver = mc.duplicate(
            browInnerDriver, po=1, name="{}_TY_driver".format(browInner))[0]
        mc.connectAttr(browInnerDriver + '.tx', browInner_TX_driver + '.tx')
        mc.connectAttr(browInnerDriver + '.ty', browInner_TY_driver + '.ty')

        browPeakDriverNul = mc.createNode(
            "transform",
            name="{}_driver_nul".format(browPeak),
            parent=self.name)
        browPeakDriverOrt = mc.createNode(
            "transform",
            name="{}_driver_ort".format(browPeak),
            parent=browPeakDriverNul)
        browPeakDriver = mc.createNode("joint",
                                       name="{}_driver".format(browPeak),
                                       parent=browPeakDriverOrt)

        # position the driver
        mc.xform(browPeakDriverNul,
                 ws=True,
                 matrix=mc.xform(browPeakNul, q=True, ws=True, matrix=True))

        for attr in ['t', 'r', 's']:
            mc.connectAttr("{}.{}".format(browPeakOrient, attr),
                           "{}.{}".format(browPeakDriverOrt, attr),
                           f=True)

        mc.pointConstraint(browPeakCtrl, browPeakDriver)

        # create the set driven key nodes.
        browMainSdkNul = mc.createNode("transform",
                                       name="{}_sdk_nul".format(browMain),
                                       parent=self.name)
        browMainSdkDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_def_auto".format(browMain),
            parent=browMainSdkNul)
        browMainSdkRotDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_rot_def_auto".format(browMain),
            parent=browMainSdkDefAuto)
        browMainSdk = mc.createNode("transform",
                                    name="{}_sdk".format(browMain),
                                    parent=browMainSdkRotDefAuto)

        # position the SDK nodes thanks
        mc.xform(browMainSdkNul,
                 ws=True,
                 matrix=mc.xform(browMainDriverOrt,
                                 q=True,
                                 ws=True,
                                 matrix=True))

        # create the keys for the brow main sdk nodes
        for attribute in ['x', 'y', 'z']:

            mc.setDrivenKeyframe("{}.t{}".format(browMainSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.t{}".format(browMainSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.t{}".format(browMainSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=-1,
                                 dv=-1)

            mc.setDrivenKeyframe("{}.r{}".format(browMainSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.r{}".format(browMainSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=.1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.r{}".format(browMainSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=-.1,
                                 dv=-1)

        # create the set driven key nodes.
        browInnerSdkNul = mc.createNode("transform",
                                        name="{}_sdk_nul".format(browInner),
                                        parent=self.name)
        browInnerSdkDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_def_auto".format(browInner),
            parent=browInnerSdkNul)
        browInnerSdkRotDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_rot_def_auto".format(browInner),
            parent=browInnerSdkDefAuto)
        browInnerSdk = mc.createNode("transform",
                                     name="{}_sdk".format(browInner),
                                     parent=browInnerSdkRotDefAuto)

        # position the SDK nodes
        mc.xform(browInnerSdkNul,
                 ws=True,
                 matrix=mc.xform(browInnerDriverOrt,
                                 q=True,
                                 ws=True,
                                 matrix=True))

        # create the keys for the brow inner sdk nodes
        for attribute in ['x', 'y', 'z']:
            mc.setDrivenKeyframe("{}.t{}".format(browInnerSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.t{}".format(browInnerSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.t{}".format(browInnerSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=-1,
                                 dv=-1)

            mc.setDrivenKeyframe("{}.r{}".format(browInnerSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.r{}".format(browInnerSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=.1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.r{}".format(browInnerSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=-.1,
                                 dv=-1)

        # create the set driven key nodes.
        browPeakSdkNul = mc.createNode("transform",
                                       name="{}_sdk_nul".format(browPeak),
                                       parent=self.name)
        browPeakSdkDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_def_auto".format(browPeak),
            parent=browPeakSdkNul)
        browPeakSdkRotDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_rot_def_auto".format(browPeak),
            parent=browPeakSdkDefAuto)
        browPeakSdk = mc.createNode("transform",
                                    name="{}_sdk".format(browPeak),
                                    parent=browPeakSdkDefAuto)

        # position the SDK nodes
        mc.xform(browPeakSdkNul,
                 ws=True,
                 matrix=mc.xform(browPeakDriverOrt,
                                 q=True,
                                 ws=True,
                                 matrix=True))

        # create the keys for the brow peak sdk nodes
        for attribute in ['x', 'y', 'z']:
            mc.setDrivenKeyframe("{}.t{}".format(browPeakSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.t{}".format(browPeakSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.t{}".format(browPeakSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=-1,
                                 dv=-1)

            mc.setDrivenKeyframe("{}.r{}".format(browPeakSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.r{}".format(browPeakSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=.1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.r{}".format(browPeakSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=-.1,
                                 dv=-1)

        # constrain the bind joints to the sdk nodes
        for jnt, sdkNode in zip((browMainJoint, browInnerJoint, browPeakJoint),
                                (browMainSdk, browInnerSdk, browPeakSdk)):
            mc.pointConstraint(sdkNode, jnt)
            mc.orientConstraint(sdkNode, jnt)

        # create the corrugator
        corrugatorName = "brow_corrugator_{}".format(side)
        cluster.create(geometry, name=corrugatorName, parent=browInnerCtrl)

        # rename the cluster and control
        mc.rename(corrugatorName, '{}_cluster'.format(corrugatorName))
        mc.rename('{}_ctrl'.format(corrugatorName), corrugatorName)
        mc.xform("{}_nul".format(corrugatorName),
                 ws=True,
                 matrix=mc.xform(browInnerCtrl, q=True, ws=True, matrix=True))
        mc.setAttr("{}.displayHandle".format(corrugatorName), 1)
        control.tagAsControl(corrugatorName, type='face')

        # lock and hide scale and rotates for all of the brow controls
        rigrepo.libs.attribute.lockAndHide(
            [browMainCtrl, browInnerCtrl, browPeakCtrl, corrugatorName],
            ['r', 'rx', 'ry', 'rz', 's', 'sx', 'sy', 'sz'])

        # Set driven keys to be post and pre infinity
        driven_keys = mc.listConnections(browMainDriver, type='animCurveUA')
        driven_keys += mc.listConnections(browMainDriver, type='animCurveUL')
        driven_keys += mc.listConnections(browInnerDriver, type='animCurveUA')
        driven_keys += mc.listConnections(browInnerDriver, type='animCurveUL')
        driven_keys += mc.listConnections(browPeakDriver, type='animCurveUA')
        driven_keys += mc.listConnections(browPeakDriver, type='animCurveUL')

        for x in driven_keys:
            mc.setAttr(x + '.preInfinity', 1)
            mc.setAttr(x + '.postInfinity', 1)
            mc.keyTangent(x, index=(0, 0), inTangentType='spline')
            mc.keyTangent(x, index=(0, 0), outTangentType='spline')
            mc.keyTangent(x, index=(2, 2), inTangentType='spline')
            mc.keyTangent(x, index=(2, 2), outTangentType='spline')

        # create the curve rig for the brows.
        curveControlNames = [
            'brow_bend_{}_{}'.format(index, side)
            for index in range(len(mc.ls('{}.cv'.format(curve), fl=True)))
        ]
        curveRig = rigrepo.libs.wire.buildCurveRig(
            curve,
            name='brow_bend_{}'.format(side),
            ctrl_names=curveControlNames,
            parent=self.rigGroup,
            control_type='face',
            control_color=rigrepo.libs.common.RED)
        bindmeshGeometry, follicleList, controlHieracrchyList, jointList, baseCurveJointList = curveRig

        for controlHieracrchy in controlHieracrchyList:
            shapeNode = mc.listRelatives(controlHieracrchy[-1],
                                         c=True,
                                         shapes=True)[0]
            mc.setAttr('{}.lodv'.format(shapeNode), 0)

        # create the wire deformer.
        # create the skinCluster for the curve
        wireDeformer = mc.wire(geometry,
                               gw=False,
                               en=1.00,
                               ce=0.00,
                               li=0.00,
                               w=curve,
                               name="{}_wire".format(curve))[0]
        # set the default values for the wire deformer
        mc.setAttr("{}.rotation".format(wireDeformer), 0)
        mc.setAttr("{}.dropoffDistance[0]".format(wireDeformer), 100)

        # create skinCluster for the base wire
        baseCurve = "{}BaseWire".format(curve)
        baseCurveSkin = mc.skinCluster(*baseCurveJointList + mc.ls(baseCurve),
                                       n="{}_skinCluster".format(baseCurve),
                                       tsb=True)[0]

        # parent the curves into the hiearchy.
        mc.parent([curve, baseCurve], 'brow_bend_{}_grp'.format(side))
예제 #7
0
    def build(self):
        '''
        This is where the builds will happen.
        '''
        super(Brow, self).build()

        # get all of the inputs to the node.
        side = self.getAttributeByName("side").getValue()
        anchor = self.getAttributeByName("anchor").getValue()
        browInner = self.getAttributeByName("browInner").getValue().format(
            side=side)
        browMain = self.getAttributeByName("browMain").getValue().format(
            side=side)
        browPeak = self.getAttributeByName("browPeak").getValue().format(
            side=side)
        browInnerJoint = self.getAttributeByName(
            "browInnerJoint").getValue().format(browInner=browInner)
        browMainJoint = self.getAttributeByName(
            "browMainJoint").getValue().format(browMain=browMain)
        browPeakJoint = self.getAttributeByName(
            "browPeakJoint").getValue().format(browPeak=browPeak)
        driverParent = self.getAttributeByName("driverParent").getValue()
        geometry = self.getAttributeByName("geometry").getValue()
        mc.parent(self.name, driverParent)
        # going to create the control hierarchies.
        browMainNul, browMainOrient, browMainCtrl = control.create(
            name=browMain,
            controlType="null",
            hierarchy=['nul', 'ort'],
            color=common.BLUE,
            parent=anchor)

        browInnerNul, browInnerOrient, browInnerCtrl = control.create(
            name=browInner,
            controlType="null",
            hierarchy=['nul', 'ort'],
            color=common.BLUE,
            parent=browMainCtrl)

        browPeakNul, browPeakOrient, browPeakCtrl = control.create(
            name=browPeak,
            controlType="null",
            hierarchy=['nul', 'ort'],
            color=common.BLUE,
            parent=browMainCtrl)

        # position the controls
        mc.xform(browMainNul,
                 ws=True,
                 matrix=mc.xform(browMainJoint, q=True, ws=True, matrix=True))
        mc.xform(browInnerNul,
                 ws=True,
                 matrix=mc.xform(browInnerJoint, q=True, ws=True, matrix=True))
        mc.xform(browPeakNul,
                 ws=True,
                 matrix=mc.xform(browPeakJoint, q=True, ws=True, matrix=True))

        # create the driver nodes
        browMainDriverNul = mc.createNode(
            "transform",
            name="{}_driver_nul".format(browMain),
            parent=self.name)
        browMainDriverOrt = mc.createNode(
            "transform",
            name="{}_driver_ort".format(browMain),
            parent=browMainDriverNul)
        browMainDriver = mc.createNode("joint",
                                       name="{}_driver".format(browMain),
                                       parent=browMainDriverOrt)

        # position the driver
        mc.xform(browMainDriverNul,
                 ws=True,
                 matrix=mc.xform(browMainNul, q=True, ws=True, matrix=True))
        for attr in ['t', 'r', 's']:
            mc.connectAttr("{}.{}".format(browMainOrient, attr),
                           "{}.{}".format(browMainDriverOrt, attr),
                           f=True)

        mc.pointConstraint(browMainCtrl, browMainDriver)

        browInnerDriverNul = mc.createNode(
            "transform",
            name="{}_driver_nul".format(browInner),
            parent=self.name)
        browInnerDriverOrt = mc.createNode(
            "transform",
            name="{}_driver_ort".format(browInner),
            parent=browInnerDriverNul)
        browInnerDriver = mc.createNode("joint",
                                        name="{}_driver".format(browInner),
                                        parent=browInnerDriverOrt)

        # position the driver
        mc.xform(browInnerDriverNul,
                 ws=True,
                 matrix=mc.xform(browInnerNul, q=True, ws=True, matrix=True))

        for attr in ['t', 'r', 's']:
            mc.connectAttr("{}.{}".format(browInnerOrient, attr),
                           "{}.{}".format(browInnerDriverOrt, attr),
                           f=True)

        mc.pointConstraint(browInnerCtrl, browInnerDriver)

        browPeakDriverNul = mc.createNode(
            "transform",
            name="{}_driver_nul".format(browPeak),
            parent=self.name)
        browPeakDriverOrt = mc.createNode(
            "transform",
            name="{}_driver_ort".format(browPeak),
            parent=browPeakDriverNul)
        browPeakDriver = mc.createNode("joint",
                                       name="{}_driver".format(browPeak),
                                       parent=browPeakDriverOrt)

        # position the driver
        mc.xform(browPeakDriverNul,
                 ws=True,
                 matrix=mc.xform(browPeakNul, q=True, ws=True, matrix=True))

        for attr in ['t', 'r', 's']:
            mc.connectAttr("{}.{}".format(browPeakOrient, attr),
                           "{}.{}".format(browPeakDriverOrt, attr),
                           f=True)

        mc.pointConstraint(browPeakCtrl, browPeakDriver)

        # create the set driven key nodes.
        browMainSdkNul = mc.createNode("transform",
                                       name="{}_sdk_nul".format(browMain),
                                       parent=self.name)
        browMainSdkDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_def_auto".format(browMain),
            parent=browMainSdkNul)
        browMainSdkRotDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_rot_def_auto".format(browMain),
            parent=browMainSdkDefAuto)
        browMainSdk = mc.createNode("transform",
                                    name="{}_sdk".format(browMain),
                                    parent=browMainSdkRotDefAuto)

        # position the SDK nodes
        mc.xform(browMainSdkNul,
                 ws=True,
                 matrix=mc.xform(browMainDriverOrt,
                                 q=True,
                                 ws=True,
                                 matrix=True))
        mc.connectAttr("{}.s".format(browMainDriverOrt),
                       "{}.s".format(browMainSdkNul),
                       f=True)

        # create the keys for the brow main sdk nodes
        for attribute in ['x', 'y', 'z']:
            mc.setDrivenKeyframe("{}.t{}".format(browMainSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.t{}".format(browMainSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.t{}".format(browMainSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=-1,
                                 dv=-1)
            mc.setDrivenKeyframe("{}.r{}".format(browMainSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.r{}".format(browMainSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=.1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.r{}".format(browMainSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browMainDriver, attribute),
                                 v=-.1,
                                 dv=-1)

        # create the set driven key nodes.
        browInnerSdkNul = mc.createNode("transform",
                                        name="{}_sdk_nul".format(browInner),
                                        parent=self.name)
        browInnerSdkDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_def_auto".format(browInner),
            parent=browInnerSdkNul)
        browInnerSdkRotDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_rot_def_auto".format(browInner),
            parent=browInnerSdkDefAuto)
        browInnerSdk = mc.createNode("transform",
                                     name="{}_sdk".format(browInner),
                                     parent=browInnerSdkRotDefAuto)

        # position the SDK nodes
        mc.xform(browInnerSdkNul,
                 ws=True,
                 matrix=mc.xform(browInnerDriverOrt,
                                 q=True,
                                 ws=True,
                                 matrix=True))
        mc.connectAttr("{}.s".format(browInnerDriverOrt),
                       "{}.s".format(browInnerSdkNul),
                       f=True)

        # create the keys for the brow inner sdk nodes
        for attribute in ['x', 'y', 'z']:
            mc.setDrivenKeyframe("{}.t{}".format(browInnerSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.t{}".format(browInnerSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.t{}".format(browInnerSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=-1,
                                 dv=-1)
            mc.setDrivenKeyframe("{}.r{}".format(browInnerSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.r{}".format(browInnerSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=.1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.r{}".format(browInnerSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browInnerDriver,
                                                    attribute),
                                 v=-.1,
                                 dv=-1)

        # create the set driven key nodes.
        browPeakSdkNul = mc.createNode("transform",
                                       name="{}_sdk_nul".format(browPeak),
                                       parent=self.name)
        browPeakSdkDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_def_auto".format(browPeak),
            parent=browPeakSdkNul)
        browPeakSdkRotDefAuto = mc.createNode(
            "transform",
            name="{}_sdk_rot_def_auto".format(browPeak),
            parent=browPeakSdkDefAuto)
        browPeakSdk = mc.createNode("transform",
                                    name="{}_sdk".format(browPeak),
                                    parent=browPeakSdkDefAuto)

        # position the SDK nodes
        mc.xform(browPeakSdkNul,
                 ws=True,
                 matrix=mc.xform(browPeakDriverOrt,
                                 q=True,
                                 ws=True,
                                 matrix=True))
        mc.connectAttr("{}.s".format(browPeakDriverOrt),
                       "{}.s".format(browPeakSdkNul),
                       f=True)

        # create the keys for the brow peak sdk nodes
        for attribute in ['x', 'y', 'z']:
            mc.setDrivenKeyframe("{}.t{}".format(browPeakSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.t{}".format(browPeakSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.t{}".format(browPeakSdkDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=-1,
                                 dv=-1)
            mc.setDrivenKeyframe("{}.r{}".format(browPeakSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=0,
                                 dv=0)
            mc.setDrivenKeyframe("{}.r{}".format(browPeakSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=.1,
                                 dv=1)
            mc.setDrivenKeyframe("{}.r{}".format(browPeakSdkRotDefAuto,
                                                 attribute),
                                 cd="{}.t{}".format(browPeakDriver, attribute),
                                 v=-.1,
                                 dv=-1)

        # constrain the bind joints to the sdk nodes
        for jnt, sdkNode in zip((browMainJoint, browInnerJoint, browPeakJoint),
                                (browMainSdk, browInnerSdk, browPeakSdk)):
            mc.pointConstraint(sdkNode, jnt)
            mc.orientConstraint(sdkNode, jnt)

        # create the corrugator
        corrugatorName = "brow_corrugator_{}".format(side)
        cluster.create(geometry, name=corrugatorName, parent=browInnerCtrl)

        # rename the cluster and control
        mc.rename(corrugatorName, '{}_cluster'.format(corrugatorName))
        mc.rename('{}_ctrl'.format(corrugatorName), corrugatorName)
        mc.xform("{}_nul".format(corrugatorName),
                 ws=True,
                 matrix=mc.xform(browInnerCtrl, q=True, ws=True, matrix=True))
        mc.setAttr("{}.displayHandle".format(corrugatorName), 1)
        control.tagAsControl(corrugatorName)
예제 #8
0
파일: hand.py 프로젝트: rombick/rigrepo
    def build(self):
        '''
        This executes the build section of the part.
        '''
        super(Hand, self).build()
        anchor = self.getAttributeByName('anchor').getValue()

        # check to make sure the group for this part has been created.
        if not mc.objExists(self._group):
            mc.createNode("transform", n=self._group)

        # check to see if the anchor exists in the scene
        if mc.objExists(anchor):
            mc.pointConstraint(anchor, self._group)
            mc.orientConstraint(anchor, self._group)

            # ------------------
            # Hand Scale
            # ------------------
            mc.connectAttr(anchor + '.scale', self._group + '.s')
            # Turn off scale compensate on children of bind joint
            children = mc.listRelatives(anchor, c=1, type='joint')
            if children:
                for c in children:
                    mc.setAttr(c + '.segmentScaleCompensate', 0)
        else:
            mc.warning("{} doesn't exists in the current Maya session!".format(
                anchor))

        # loop through all of the parent joints in the fingers.
        parent = self._group
        for jnt in self.jointList:
            # get all of the children of the main finger joints we're using. We have to reverse the
            # list to get the order we want.
            children = mc.listRelatives(jnt, ad=True, type="joint")
            children.reverse()

            # create the first finger control
            fingerCtrlHierarchy = control.create(name="{}".format("".join(
                jnt.split("_bind"))),
                                                 controlType="square",
                                                 hierarchy=['nul', 'ort'],
                                                 parent=parent)

            # move the control and then constrain the joint to the control.
            jntPosition = mc.xform(jnt, q=True, ws=True, matrix=True)
            mc.xform(fingerCtrlHierarchy[0], ws=True, matrix=jntPosition)
            mc.pointConstraint(fingerCtrlHierarchy[-1], jnt)
            mc.orientConstraint(fingerCtrlHierarchy[-1], jnt)

            # reset the parent hierarchy to be the control.
            parent = fingerCtrlHierarchy[-1]

            # loop throught the children to create controls for them
            for childJoint in children:
                if childJoint == children[-1]:
                    parent = self._group
                    break
                # create the control for the child joints.
                childCtrlierarchy = control.create(name="{}".format("".join(
                    childJoint.split("_bind"))),
                                                   controlType="square",
                                                   hierarchy=['nul', 'ort'],
                                                   parent=parent)
                childJointPosition = mc.xform(childJoint,
                                              q=True,
                                              ws=True,
                                              matrix=True)

                # move the control and then create the constraints.
                mc.xform(childCtrlierarchy[0],
                         ws=True,
                         matrix=childJointPosition)
                mc.pointConstraint(childCtrlierarchy[-1], childJoint)
                mc.orientConstraint(childCtrlierarchy[-1], childJoint)

                # set the parent to be the control we just created.
                parent = childCtrlierarchy[-1]

        # parent the group the the name of this part
        mc.parent(self._group, self.name)
예제 #9
0
    def build(self):
        '''
        This is where the builds will happen.
        '''
        super(Face, self).build()

        # get all of the inputs to the node.
        jawJoint = self.getAttributeByName("jawJoint").getValue()
        faceUpperJoint = self.getAttributeByName("faceUpperJoint").getValue()
        headTipJoint = self.getAttributeByName("headTipJoint").getValue()
        faceLowerJoint = self.getAttributeByName("faceLowerJoint").getValue()
        faceMidJoint = self.getAttributeByName("faceMidJoint").getValue()
        noseBridgeJoint = self.getAttributeByName("noseBridge").getValue()
        noseJoint = self.getAttributeByName("nose").getValue()
        anchor = self.getAttributeByName("anchor").getValue()
        upperTeeth = self.getAttributeByName("upperTeeth").getValue()
        lowerTeeth = self.getAttributeByName("lowerTeeth").getValue()
        geometry = self.getAttributeByName("geometry").getValue()
        teethUpperJoint = self.getAttributeByName("upperTeeth").getValue()
        teethLowerJoint = self.getAttributeByName("lowerTeeth").getValue()

        # JAW
        if mc.objExists(jawJoint):
            # create the jaw control
            jawNul, jawDefAuto, jawCtrl = control.create(
                name="jaw",
                controlType="null",
                color=common.YELLOW,
                hierarchy=['nul', 'def_auto'],
                type='face')

            rigrepo.libs.attribute.lockAndHide(jawCtrl,
                                               ["v", "sx", "sy", "sz"])

            # position the jaw control and connect the joint to the control
            mc.xform(jawNul,
                     ws=True,
                     matrix=mc.xform(jawJoint, q=True, ws=True, matrix=True))
            mc.pointConstraint(jawCtrl, jawJoint)
            mc.orientConstraint(jawCtrl, jawJoint)
            # create jaw driver, parent it to the jaw nul, then move it to the correct position
            jawDriver = mc.createNode("joint", name="jaw_driver")
            mc.parent(jawDriver, jawNul)
            mc.xform(jawDriver,
                     ws=True,
                     matrix=mc.xform(jawNul, q=True, ws=True, matrix=True))
            mc.orientConstraint(jawCtrl, jawDriver)
            # create normRX on the driver
            mc.addAttr(jawDriver, ln="normRX", at="double", keyable=True)
            multJaw = mc.createNode("multDoubleLinear",
                                    name="jaw_driver_norm_mult")
            mc.connectAttr("{}.rx".format(jawJoint),
                           "{}.input1".format(multJaw),
                           f=True)
            mc.setAttr("{}.input2".format(multJaw), .1)
            mc.connectAttr("{}.output".format(multJaw),
                           "{}.normRX".format(jawDriver),
                           f=True)
            # turn off the visibility of the driver
            mc.setAttr("{}.drawStyle".format(jawDriver), 2)

            # create the lip lower cluster
            lipLower = "lip_lower"
            cluster.create(geometry, name=lipLower, parent=jawCtrl)

            # rename the cluster and control
            mc.rename(lipLower, '{}_cluster'.format(lipLower))
            mc.rename('{}_ctrl'.format(lipLower), lipLower)
            mc.xform("{}_nul".format(lipLower),
                     ws=True,
                     matrix=mc.xform(jawCtrl, q=True, ws=True, matrix=True))
            mc.setAttr("{}.displayHandle".format(lipLower), 1)
            control.tagAsControl(lipLower, type='face')

            for side in ['l', 'r']:
                # create the lip lower cluster
                lipLower_side = "lip_lower_{}".format(side)
                cluster.create(geometry, name=lipLower_side, parent=jawCtrl)

                # rename the cluster and control
                mc.rename(lipLower_side, '{}_cluster'.format(lipLower_side))
                mc.rename('{}_ctrl'.format(lipLower_side), lipLower_side)
                mc.xform("{}_nul".format(lipLower_side),
                         ws=True,
                         matrix=mc.xform(jawCtrl, q=True, ws=True,
                                         matrix=True))
                mc.setAttr("{}.displayHandle".format(lipLower_side), 1)
                control.tagAsControl(lipLower_side, type='face')

            # Lowerteeth control
            if mc.objExists(teethLowerJoint):
                teethLowerNul, teethLowerDefAuto, teethLowerCtrl = control.create(
                    name="teeth_lower",
                    controlType="null",
                    color=common.RED,
                    hierarchy=['nul', 'def_auto'],
                    parent=jawCtrl,
                    type='face')

                mc.xform(teethLowerNul,
                         ws=True,
                         matrix=mc.xform(teethLowerJoint,
                                         q=True,
                                         ws=True,
                                         matrix=True))
                mc.pointConstraint(teethLowerCtrl, teethLowerJoint)
                mc.orientConstraint(teethLowerCtrl, teethLowerJoint)
                mc.connectAttr('{}.s'.format(teethLowerCtrl),
                               '{}.s'.format(teethLowerJoint),
                               f=True)

        # FACE LOWER
        if mc.objExists(faceLowerJoint):
            # Create the faceLower and jaw control
            faceLowerNul, faceLowerCtrl = control.create(name="face_lower",
                                                         controlType="null",
                                                         color=common.YELLOW,
                                                         hierarchy=['nul'],
                                                         parent=anchor,
                                                         type='face')

            rigrepo.libs.attribute.lockAndHide(faceLowerCtrl,
                                               ["v", "sx", "sy", "sz"])
            # position the faceLowerNul and connect the joint to the control
            mc.xform(faceLowerNul,
                     ws=True,
                     matrix=mc.xform(faceLowerJoint,
                                     q=True,
                                     ws=True,
                                     matrix=True))
            mc.pointConstraint(faceLowerCtrl, faceLowerJoint)
            mc.orientConstraint(faceLowerCtrl, faceLowerJoint)

            # parent the jaw to face lower control
            if mc.objExists(jawJoint):
                mc.parent(jawNul, faceLowerCtrl)

            mouthMainName = "mouthMain"
            cluster.create(geometry, name=mouthMainName, parent=faceLowerCtrl)

            # rename the cluster and control
            mc.rename(mouthMainName, '{}_cluster'.format(mouthMainName))
            mc.rename('{}_ctrl'.format(mouthMainName), mouthMainName)
            mc.xform("{}_nul".format(mouthMainName),
                     ws=True,
                     matrix=mc.xform(faceLowerCtrl,
                                     q=True,
                                     ws=True,
                                     matrix=True))
            mc.setAttr("{}.displayHandle".format(mouthMainName), 1)
            control.tagAsControl(mouthMainName, type='face')

        elif mc.objExists(jawJoint) and mc.objExists(anchor):
            mc.parent(jawNul, anchor)

        if mc.objExists(faceUpperJoint):
            # Create the faceLower and jaw control
            faceUpperNul, faceUpperCtrl = control.create(name="face_upper",
                                                         controlType="null",
                                                         color=common.YELLOW,
                                                         hierarchy=['nul'],
                                                         parent=anchor,
                                                         type='face')

            rigrepo.libs.attribute.lockAndHide(faceUpperCtrl,
                                               ["v", "sx", "sy", "sz"])
            # position the faceLowerNul and connect the joint to the control
            mc.xform(faceUpperNul,
                     ws=True,
                     matrix=mc.xform(faceUpperJoint,
                                     q=True,
                                     ws=True,
                                     matrix=True))
            mc.pointConstraint(faceUpperCtrl, faceUpperJoint)
            mc.orientConstraint(faceUpperCtrl, faceUpperJoint)

            # setup the jaw compression
            jawCompressionJnt = "jaw_compression_driver"
            if not mc.objExists(jawCompressionJnt):
                jawCompressionJnt = mc.joint(name="jaw_compression_driver")
                mc.xform(jawCompressionJnt,
                         ws=True,
                         q=True,
                         rotation=mc.xform(faceLowerJoint,
                                           q=True,
                                           ws=True,
                                           rotation=True))
                mc.xform(jawCompressionJnt,
                         ws=True,
                         t=rigrpeo.libs.transform.getAveragePosition(
                             [upperTeeth, lowerTeeth]))

            # create the faceDiff joint and parent it to the faceUpperCtrl
            faceDiff = mc.duplicate("jaw_compression_driver",
                                    po=True,
                                    name="face_upper_diff")[0]
            mc.parent(faceDiff, faceUpperCtrl)
            parent = self.rigGroup
            groupList = [
                "jaw_compression_grp", "jaw_compression_nul",
                "jaw_compression_cnt", "jaw_compressiong_offset"
            ]
            for group in groupList:
                mc.createNode("transform", name=group)
                mc.parent(group, parent)
                parent = group

            # position the jaw groups
            mc.parentConstraint("skull_bind", groupList[0], mo=False)
            mc.xform(groupList[1],
                     ws=True,
                     matrix=mc.xform(jawJoint, q=True, ws=True, matrix=True))
            for attr in ['t', 'r', 's']:
                mc.connectAttr("{}.{}".format(jawCtrl, attr),
                               "{}.{}".format(groupList[2], attr),
                               f=True)

            mc.xform(groupList[-1],
                     ws=True,
                     matrix=mc.xform(jawCompressionJnt,
                                     q=True,
                                     ws=True,
                                     matrix=True))
            # parent the jawCompression joint to the last of the group nodes
            mc.parent(jawCompressionJnt, groupList[-1])
            # point constrain the jawCompression joint to the faceDiff joint
            mc.pointConstraint(faceDiff, jawCompressionJnt, mo=False)

            # turn off the visibility of the joints
            for jnt in [faceDiff, jawCompressionJnt]:
                mc.setAttr("{}.v".format(jnt), 0)

            if mc.objExists(headTipJoint):
                # Create the faceLower and jaw control
                headTipNul, headTipCtrl = control.create(name="head_tip",
                                                         controlType="null",
                                                         color=common.YELLOW,
                                                         hierarchy=['nul'],
                                                         parent=faceUpperCtrl,
                                                         type='face')

            rigrepo.libs.attribute.lockAndHide(headTipCtrl,
                                               ["v", "sx", "sy", "sz"])
            # position the faceLowerNul and connect the joint to the control
            mc.xform(headTipNul,
                     ws=True,
                     matrix=mc.xform(headTipJoint,
                                     q=True,
                                     ws=True,
                                     matrix=True))
            mc.pointConstraint(headTipCtrl, headTipJoint)
            mc.orientConstraint(headTipCtrl, headTipJoint)

        if mc.objExists(noseBridgeJoint):
            # Create the faceLower and jaw control
            noseBridgeNul, noseBridgeDefAuto, noseBridgeRotDefAuto, noseBridgeCtrl = control.create(
                name="nose_bridge",
                controlType="null",
                color=common.YELLOW,
                hierarchy=['nul', 'def_auto', 'rot_def_auto'],
                type='face')

            rigrepo.libs.attribute.lockAndHide(noseBridgeCtrl,
                                               ["v", "sx", "sy", "sz"])

            if mc.objExists(faceUpperJoint):
                mc.parent(noseBridgeNul, faceUpperCtrl)
                # create the setDriven keys for the jaw control
                mc.setDrivenKeyframe("{}.rx".format(noseBridgeRotDefAuto),
                                     cd="{}.ty".format(jawCompressionJnt),
                                     v=15,
                                     dv=-0.7)
                mc.setDrivenKeyframe("{}.rx".format(noseBridgeRotDefAuto),
                                     cd="{}.ty".format(jawCompressionJnt),
                                     v=-0,
                                     dv=0)
                for attr in ['y', 'z']:
                    mc.setDrivenKeyframe("{}.t{}".format(
                        noseBridgeDefAuto, attr),
                                         cd="{}.ty".format(jawCompressionJnt),
                                         v=.01,
                                         dv=-0.7)
                    mc.setDrivenKeyframe("{}.t{}".format(
                        noseBridgeDefAuto, attr),
                                         cd="{}.ty".format(jawCompressionJnt),
                                         v=0,
                                         dv=0)
            else:
                mc.parent(noseBridgeNul, anchor)
            # position the faceLowerNul and connect the joint to the control
            mc.xform(noseBridgeNul,
                     ws=True,
                     matrix=mc.xform(noseBridgeJoint,
                                     q=True,
                                     ws=True,
                                     matrix=True))
            mc.pointConstraint(noseBridgeCtrl, noseBridgeJoint)
            mc.orientConstraint(noseBridgeCtrl, noseBridgeJoint)
            mc.connectAttr(noseBridgeCtrl + '.s', noseBridgeJoint + '.s')

        if mc.objExists(noseJoint):
            # Create the faceLower and jaw control
            noseNul, noseDefAuto, noseCtrl = control.create(
                name="nose",
                controlType="null",
                color=common.YELLOW,
                hierarchy=['nul', 'def_auto'],
                type='face')

            if mc.objExists(noseBridgeJoint):
                mc.parent(noseNul, noseBridgeCtrl)
            else:
                mc.parent(noseNul, anchor)

            # position the faceLowerNul and connect the joint to the control
            mc.xform(noseNul,
                     ws=True,
                     matrix=mc.xform(noseJoint, q=True, ws=True, matrix=True))
            mc.pointConstraint(noseCtrl, noseJoint)
            mc.orientConstraint(noseCtrl, noseJoint)
            mc.connectAttr(noseCtrl + '.s', noseJoint + '.s')

            # create the left sneer cluster
            sneerNameL = "sneer_l"
            cluster.create(geometry, name=sneerNameL, parent=noseCtrl)

            # rename the cluster and control
            mc.rename(sneerNameL, '{}_cluster'.format(sneerNameL))
            mc.rename('{}_ctrl'.format(sneerNameL), sneerNameL)
            mc.xform("{}_nul".format(sneerNameL),
                     ws=True,
                     matrix=mc.xform(noseCtrl, q=True, ws=True, matrix=True))
            mc.setAttr("{}.displayHandle".format(sneerNameL), 1)
            control.tagAsControl(sneerNameL, type='face')

            # create the right sneer cluster
            sneerNameR = "sneer_r"
            cluster.create(geometry, name=sneerNameR, parent=noseCtrl)

            # rename the cluster and control
            mc.rename(sneerNameR, '{}_cluster'.format(sneerNameR))
            mc.rename('{}_ctrl'.format(sneerNameR), sneerNameR)
            mc.xform("{}_nul".format(sneerNameR),
                     ws=True,
                     matrix=mc.xform(noseCtrl, q=True, ws=True, matrix=True))
            mc.setAttr("{}.displayHandle".format(sneerNameR), 1)
            control.tagAsControl(sneerNameR, type='face')

        if mc.objExists(faceMidJoint):
            parent = faceLowerCtrl
            groupList = [
                "face_mid_nul", "face_upper_driver", "face_mid_offset",
                "face_mid_ort", "face_mid_def_auto"
            ]
            for group in groupList:
                mc.createNode("transform", name=group)
                mc.parent(group, parent)
                parent = group

            # make the driver joint and parent it to the def auto and turn off visibility
            midDriver = mc.joint(name="face_mid_driver")
            mc.setAttr("{}.drawStyle".format(midDriver), 2)

            mc.xform(groupList[0],
                     ws=True,
                     matrix=mc.xform(faceUpperCtrl,
                                     q=True,
                                     ws=True,
                                     matrix=True))
            for attr in ['t', 'r', 's']:
                mc.connectAttr("{}.{}".format(faceUpperCtrl, attr),
                               "{}.{}".format(groupList[1], attr),
                               f=True)
            mc.xform(groupList[2],
                     ws=True,
                     matrix=mc.xform(faceMidJoint,
                                     q=True,
                                     ws=True,
                                     matrix=True))
            # create the set drivens
            if mc.objExists(faceUpperJoint):
                # create the setDriven keys for the jaw control
                mc.setDrivenKeyframe("{}.rx".format(groupList[-1]),
                                     cd="{}.ty".format(jawCompressionJnt),
                                     v=10,
                                     dv=-0.7)
                mc.setDrivenKeyframe("{}.rx".format(groupList[-1]),
                                     cd="{}.ty".format(jawCompressionJnt),
                                     v=-0,
                                     dv=0)
                for attr in ['y', 'z']:
                    mc.setDrivenKeyframe("{}.t{}".format(groupList[-1], attr),
                                         cd="{}.ty".format(jawCompressionJnt),
                                         v=-1,
                                         dv=-0.7)
                    mc.setDrivenKeyframe("{}.t{}".format(groupList[-1], attr),
                                         cd="{}.ty".format(jawCompressionJnt),
                                         v=0,
                                         dv=0)

            # constrain the joint to the driver
            mc.pointConstraint(midDriver, faceMidJoint, mo=False)
            mc.orientConstraint(midDriver, faceMidJoint, mo=False)
            # parent the noseBridge to the proper group
            mc.parent(noseBridgeNul, groupList[-1])

            # create the left sneer cluster
            lipUpper = "lip_upper"
            cluster.create(geometry, name=lipUpper, parent=midDriver)

            # rename the cluster and control
            mc.rename(lipUpper, '{}_cluster'.format(lipUpper))
            mc.rename('{}_ctrl'.format(lipUpper), lipUpper)
            mc.xform("{}_nul".format(lipUpper),
                     ws=True,
                     matrix=mc.xform(midDriver, q=True, ws=True, matrix=True))
            mc.setAttr("{}.displayHandle".format(lipUpper), 1)
            control.tagAsControl(lipUpper, type='face')
            # lock and hide the visibility attribute on the lip upper and lower
            rigrepo.libs.attribute.lockAndHide([lipUpper, lipLower], ['v'])

            for side in ['l', 'r']:
                # create the lip lower cluster
                lipUpper_side = "lip_upper_{}".format(side)
                cluster.create(geometry, name=lipUpper_side, parent=midDriver)

                # rename the cluster and control
                mc.rename(lipUpper_side, '{}_cluster'.format(lipUpper_side))
                mc.rename('{}_ctrl'.format(lipUpper_side), lipUpper_side)
                mc.xform("{}_nul".format(lipUpper_side),
                         ws=True,
                         matrix=mc.xform(midDriver,
                                         q=True,
                                         ws=True,
                                         matrix=True))
                mc.setAttr("{}.displayHandle".format(lipUpper_side), 1)
                control.tagAsControl(lipUpper_side, type='face')

            # Lowerteeth control
            if mc.objExists(teethUpperJoint):
                teethUpperNul, teethUpperDefAuto, teethUpperCtrl = control.create(
                    name="teeth_upper",
                    controlType="null",
                    color=common.RED,
                    hierarchy=['nul', 'def_auto'],
                    parent=midDriver,
                    type='face')

                mc.xform(teethUpperNul,
                         ws=True,
                         matrix=mc.xform(teethUpperJoint,
                                         q=True,
                                         ws=True,
                                         matrix=True))
                mc.pointConstraint(teethUpperCtrl, teethUpperJoint)
                mc.orientConstraint(teethUpperCtrl, teethUpperJoint)
                mc.scaleConstraint(teethUpperCtrl, teethUpperJoint)
예제 #10
0
    def build(self):
        '''
        '''
        super(Arm, self).build()
        # get the values from the user. Node attributes in the graph.
        clavicleCtrl = self.getAttributeByName('clavicleCtrl').getValue()
        swingCtrl = self.getAttributeByName('swingCtrl').getValue()
        MirrorSwing = self.getAttributeByName('MirrorSwing').getValue()
        swingNul, swingMirrorOrt, swingOrt, swingCtrl = control.create(name=swingCtrl, 
                                                controlType="square",
                                                hierarchy=['nul','mirror_ort','ort'])
        clavicleNul, clavicleOrt, clavicleCtrl = control.create(name=clavicleCtrl, 
                                                                controlType="square",
                                                                hierarchy=['nul','ort'])

        # position the clavicle in the correct location
        clavicleJointMatrix = mc.xform(self._clavicleJoint, q=True, ws=True, matrix=True)
        mc.xform(clavicleNul, ws=True, matrix=clavicleJointMatrix)
        
        # get the aim direction
        aimDistance = mc.getAttr("{}.t".format(self.jointList[1]))[0]
        aimAttr, aimVector = self._getDistanceVector(aimDistance)
        sidePos = mc.xform(self.jointList[1], q=True, ws=True, t=True)

        # set the Ort node to be mirrored from the other side
        if sidePos[0] < 0:            
            mc.setAttr("{}.r{}".format(clavicleOrt, aimAttr.strip("-")), 180)
            mc.setAttr("{}.s{}".format(clavicleOrt, aimAttr.strip("-")), -1)

            # mirror the swing also if it is required by the build
            if MirrorSwing:
                mc.setAttr("{}.r{}".format(swingMirrorOrt, aimAttr.strip("-")), 180)
                mc.setAttr("{}.s{}".format(swingMirrorOrt, aimAttr.strip("-")), -1)

        # move the shoulderSwing control to the correct location.
        shoulderCtrlMatrix = mc.xform(self._fkControls[0], q=True, ws=True, matrix=True)
        mc.xform(swingNul, ws=True, matrix=shoulderCtrlMatrix)

        # Hookup clavicle connect nul, the direct connection for the rotate allow keeps the auto
        # clav from causint a double rotation on the shoulder
        clavicleConnect = mc.duplicate(clavicleCtrl, po=1, n=clavicleCtrl+'_connect')[0]
        mc.parent(clavicleConnect, clavicleNul)
        mc.connectAttr(clavicleCtrl+'.r', clavicleConnect+'.r')
        mc.connectAttr(clavicleCtrl+'.s', clavicleConnect+'.s')

        # This allows the translates to come through with auto clav
        clavicleConnectTranslate = mc.duplicate(swingNul, po=1, n=clavicleCtrl+'_connect_trans')[0]
        mc.parent(clavicleConnectTranslate, clavicleCtrl)
        mc.pointConstraint(clavicleConnectTranslate, clavicleConnect)

        # getting rid of the point constraint for now. Not sure we need it.
        #mc.pointConstraint(clavicleCtrl, self._clavicleJoint)
        mc.orientConstraint(clavicleCtrl, self._clavicleJoint)

        # parent the shoulderSwing control to the clavicle control.
        mc.parent((self._fkControls[0], self._stretchTargetJointList[0]), swingCtrl)
        mc.parent(swingNul, clavicleConnect)
        
        # Connect to passed anchor
        #
        anchor = self.getAttributeByName('anchor').getValue()
        if mc.objExists(anchor):
            mc.parent(clavicleNul, anchor) 
        else:
            # parent the clavicle to the group of this part.
            mc.parent(clavicleNul, self.name)
            mc.warning('Anchor object [ {} ] does not exist.'.format(anchor)) 


        # set the rotate order for the shoulder control
        mc.setAttr("{}.rotateOrder".format(self._fkControls[0]), 2)
        # set the rotate order for the swing control
        mc.setAttr("{}.rotateOrder".format(swingCtrl), 2)
        #self._fkControls.extend([clavicleCtrl,swingCtrl])

        # PSD driver - transform that picks up the auto clav and anim control rotation
        clavicleDriverPar = mc.duplicate(clavicleConnect, po=1, n=clavicleCtrl+'_driver_par')[0]
        clavicleDriver = mc.duplicate(clavicleConnect, po=1, n=clavicleCtrl+'_driver')[0]
예제 #11
0
    def build(self):
        '''
        '''
        super(ArmOld, self).build()
        clavicleCtrl = self.getAttributeByName('clavicleCtrl').getValue()
        swingCtrl = self.getAttributeByName('swingCtrl').getValue()
        swingCtrlHierarchy = control.create(name=swingCtrl, 
                                                controlType="square",
                                                hierarchy=['nul','ort'])
        clavicleCtrlHierarchy = control.create(name=clavicleCtrl, 
                                                controlType="square",
                                                hierarchy=['nul','ort'])

        

        '''
        clavicle = 'clavicle_l'
        child = 'shoulderSwing_l_nul'

        aimTarget = mc.duplicate(clavicle, po=1, n=clavicle + '_aim_target')[0]
        aim = mc.duplicate(clavicle, po=1, n=clavicle + '_aim')[0]

        mc.delete(mc.pointConstraint(child, aimTarget))
        mc.parent(aimTarget, clavicle)
        mc.setAttr(aimTarget + '.tx', 1)

        mc.aimConstraint(aimTarget, aim, offset=[0, 0, 0],
                         weight=1, aimVector=[1, 0, 0],
                         worldUpType="none",
                         upVector=[0, 0, 0])

        mc.pointConstraint(aimTarget, child)
        '''

        clavicleCtrl = clavicleCtrlHierarchy[-1]
        clavicleNul = clavicleCtrlHierarchy[0]
        swingCtrl = swingCtrlHierarchy[-1]
        swingNul = swingCtrlHierarchy[0]
        clavicleJointMatrix = mc.xform(self._clavicleJoint, q=True, ws=True, matrix=True)
        mc.xform(clavicleNul, ws=True, matrix=clavicleJointMatrix)

        # move the shoulderSwing control to the correct location.
        shoulderCtrlMatrix = mc.xform(self._fkControls[0], q=True, ws=True, matrix=True)
        mc.xform(swingNul, ws=True, matrix=shoulderCtrlMatrix)

        # Hookup clavicle connect nul, the direct connection for the rotate allow keeps the auto
        # clav from causint a double rotation on the shoulder
        clavicleConnect = mc.duplicate(clavicleCtrl, po=1, n=clavicleCtrl+'_connect')[0]
        mc.parent(clavicleConnect, clavicleNul)
        mc.connectAttr(clavicleCtrl+'.r', clavicleConnect+'.r')
        mc.connectAttr(clavicleCtrl+'.s', clavicleConnect+'.s')
        # PSD driver - transform that picks up the auto clav and anim control rotation
        clavicleDriver = mc.duplicate(clavicleConnect, po=1, n=clavicleCtrl+'_driver')[0]
        mc.orientConstraint(clavicleCtrl, clavicleDriver)

        # This allows the translates to come through with auto clav
        clavicleConnectTranslate = mc.duplicate(swingNul, po=1, n=clavicleCtrl+'_connect_trans')[0]
        mc.parent(clavicleConnectTranslate, clavicleCtrl)
        mc.pointConstraint(clavicleConnectTranslate, clavicleConnect)


        mc.pointConstraint(clavicleCtrl, self._clavicleJoint)
        mc.orientConstraint(clavicleCtrl, self._clavicleJoint)

        # parent the shoulderSwing control to the clavicle control.
        mc.parent(("{}_nul".format(self._fkControls[0]), self._stretchTargetJointList[0]), swingCtrl)
        mc.parent(swingNul, clavicleConnect)

        # parent constrain the shoulder ik joint to the clavicle joint.
        mc.parentConstraint(self._clavicleJoint, self.ikfkSystem.getIkJointList()[0], mo=True)

        # parent the clavicle to the group of this part.
        mc.parent(clavicleNul, self.name)
        
        # Connect to passed anchor
        #
        anchor = self.getAttributeByName('anchor').getValue()
        if mc.objExists(anchor):
            mc.parent(clavicleNul, anchor) 
        else:
            mc.warning('Anchor object [ {} ] does not exist.'.format(anchor)) 


        # set the rotate order for the shoulder control
        mc.setAttr("{}.rotateOrder".format(self._fkControls[0]), 2)
        # set the rotate order for the swing control
        mc.setAttr("{}.rotateOrder".format(swingCtrl), 2)
예제 #12
0
파일: neck.py 프로젝트: rombick/rigrepo
    def build(self):
        '''
        '''
        super(Neck, self).build()
        jointList = eval(self.jointList)
        headPivotValue = self.getAttributeByName("headPivot").getValue()
        scaleFactor = self.getAttributeByName('scaleFactor').getValue()
        self.spline = spline.SplineBase(jointList=jointList +
                                        [self._skullBind],
                                        splineName=self._splineName,
                                        scaleFactor=scaleFactor)
        self.spline.create()

        # get the name of the curveInfo node. This is hard coded to be this way in the
        # spline  code. If that changes, this will not work. We can change the code below
        # to use the API to get the length of the curve instead of this node, but for now, this
        # is quicker because it's available already.
        spineCurveInfo = self._splineName + "_curveInfo"

        grp = mc.rename(self.name, "{}_grp".format(self.name))

        # Neck
        neckNul, neckOrt, neckCtrl = control.create(name="neck",
                                                    controlType="cube",
                                                    color=common.BLUE,
                                                    hierarchy=['nul', "ort"])

        matrix = mc.xform(jointList[0], q=True, ws=True, matrix=True)
        mc.xform(neckNul, ws=True, matrix=matrix)

        # Parent the entire ik group to the neck
        mc.parent(self.spline.getGroup(), neckCtrl)

        # head
        headNul, headCtrl = control.create(name="head",
                                           controlType="cube",
                                           color=common.BLUE,
                                           hierarchy=['nul'])

        # head gimabl control
        # head
        headGimbalNul, headGimbalCtrl = control.create(name="head_gimbal",
                                                       controlType="cube",
                                                       color=common.BLUE,
                                                       hierarchy=['nul'],
                                                       parent=headCtrl)

        clusters = self.spline._clusters
        headGimbalGrp = mc.createNode("transform", n="head_gimbal_grp")
        # move the group into the same matrix as the control
        mc.xform(headGimbalGrp,
                 ws=True,
                 matrix=mc.xform(headGimbalCtrl, q=True, ws=True, matrix=True))
        # parent the group into the same space as the control
        mc.parent(headGimbalGrp, headGimbalCtrl)
        # constrain the gimbal group to the gimbal control
        mc.connectAttr("{}.rp".format(headCtrl),
                       "{}.rp".format(headGimbalCtrl),
                       f=True)
        #mc.connectAttr("{}.rp".format(headGimbalCtrl), "{}.rp".format(headGimbalGrp), f=True)
        #mc.pointConstraint(headGimbalCtrl, headGimbalGrp)
        #mc.orientConstraint(headGimbalCtrl, headGimbalGrp)
        #mc.scaleConstraint(headGimbalCtrl, headGimbalGrp)

        # make sure the nul is where the joint is
        mc.xform(headNul,
                 ws=True,
                 t=mc.xform(self._skullBind, q=True, ws=True, t=True))
        # tangent will be figured out later.
        #mc.addAttr(hipSwivelCtrl, ln="tangentHeight", at="double", dv=0, min=0, max=4, keyable=False)
        # make sure the nul is where the joint is
        mc.xform(headNul,
                 ws=True,
                 t=mc.xform(self._skullBind, q=True, ws=True, t=True))

        # create pivot attributes to use for moving the pivot and tangent heights.
        mc.addAttr(headCtrl,
                   ln="pivotHeight",
                   at="double",
                   dv=0,
                   min=0,
                   max=10,
                   keyable=False)
        mc.setAttr("{}.pivotHeight".format(headCtrl), headPivotValue)

        # create the remap node to use to remap the pivot height to the lenght of the curve
        headRemapNode = mc.createNode("remapValue", n="head_pivot_remap")

        # map the 0-10 to the length of the curve on the spine
        curveLength = mc.getAttr("{}.arcLength".format(spineCurveInfo))

        # set the max output value for the remap to be the length of the curve
        mc.setAttr("{}.outputMax".format(headRemapNode), curveLength)

        # set the input max
        mc.setAttr("{}.inputMax".format(headRemapNode), 10)

        # connect the slider for pivot to the input max
        mc.connectAttr("{}.pivotHeight".format(headCtrl),
                       "{}.inputValue".format(headRemapNode),
                       f=True)

        # get the aim axis
        headPivotNulGrp = mc.createNode("transform", name="headPivot_aim_nul")
        headPivotAimGrp = mc.createNode("transform", name="headPivot_aim_grp")
        headPivotDriver = mc.createNode("transform", name="headPivot_aim_drv")
        mc.parent(headPivotAimGrp, headPivotNulGrp)
        mc.parent(headPivotNulGrp, headGimbalGrp)
        mc.parent(headPivotDriver, headPivotAimGrp)
        mc.xform(headPivotNulGrp, ws=True, matrix=matrix)
        # get the aim axis
        aimAxis = rigrepo.libs.transform.getAimAxis(headGimbalGrp)
        mc.parent(headPivotNulGrp, headNul)
        vector = om.MVector(*mc.getAttr("{}.t".format(headPivotNulGrp)))
        vector.normalize()
        distanceValue = max(vector, key=abs)
        index = (vector.x, vector.y, vector.z).index(distanceValue)
        aimVector = list()
        for i in range(len(vector)):
            if i == index:
                aimVector.append(1)
            else:
                aimVector.append(0)

        # move the transform back to the skull
        mc.xform(headPivotNulGrp,
                 ws=True,
                 matrix=mc.xform(headCtrl, q=True, ws=True, matrix=True))
        mc.parent(headPivotDriver, headNul)
        mc.pointConstraint(headPivotAimGrp, headPivotDriver, mo=False)
        mc.orientConstraint(headPivotAimGrp, headPivotDriver, mo=False)

        mc.aimConstraint(neckCtrl,
                         headPivotAimGrp,
                         w=1,
                         upVector=(0, 0, 0),
                         aimVector=aimVector,
                         wut="none")
        if '-' in aimAxis:
            headCtrlPivotMdl = mc.createNode('multDoubleLinear',
                                             n='head_pivot_mdl')
            mc.connectAttr('{}.outValue'.format(headRemapNode),
                           '{}.input1'.format(headCtrlPivotMdl),
                           f=True)
            mc.setAttr('{}.input2'.format(headCtrlPivotMdl), -1)
            mc.connectAttr('{}.output'.format(headCtrlPivotMdl),
                           '{}.t{}'.format(headPivotAimGrp,
                                           aimAxis.strip('-')),
                           f=True)
            mc.connectAttr('{}.t'.format(headPivotDriver),
                           '{}.rotatePivot'.format(headCtrl),
                           f=True)
        else:
            mc.connectAttr('{}.outValue'.format(headRemapNode),
                           '{}.t{}'.format(headPivotAimGrp, aimAxis),
                           f=True)
            mc.connectAttr('{}.t'.format(headPivotDriver),
                           '{}.rotatePivot'.format(headCtrl),
                           f=True)

        mc.parent(headNul, neckCtrl)
        mc.parent(clusters[2:], headGimbalGrp)
        mc.orientConstraint(headGimbalGrp, self.spline._endTwistNul, mo=1)
        # make the offset joint for the skull
        skullOffset = mc.duplicate(self._skullBind,
                                   po=True,
                                   rr=True,
                                   name="{}_offset".format(self._skullBind))[0]
        mc.setAttr(skullOffset + '.v', 0)
        mc.parent(skullOffset, headGimbalGrp)
        mc.orientConstraint(skullOffset, self.spline._ikJointList[-1], mo=1)
        # connect the scale of the gimbal group to the scale of skull bind
        headScaleMdn = mc.createNode("multiplyDivide", n="head_scale_mdn")
        mc.connectAttr("{}.s".format(headCtrl),
                       "{}.input1".format(headScaleMdn),
                       f=True)
        mc.connectAttr("{}.s".format(headGimbalCtrl),
                       "{}.input2".format(headScaleMdn),
                       f=True)
        mc.connectAttr("{}.output".format(headScaleMdn),
                       "{}.s".format(self._skullBind),
                       f=True)

        anchor = self.getAttributeByName('anchor').getValue()
        if mc.objExists(anchor):
            mc.parentConstraint(anchor, neckNul, mo=1)
        else:
            mc.warning('Anchor object [ {} ] does not exist.'.format(anchor))

        mc.parent(neckNul, grp)
        mc.hide(self.spline._group, clusters)

        # Head psd driver
        driver_nul = mc.duplicate(headNul, po=1, n='head_driver_nul')[0]
        driver = mc.createNode('transform', n='head_driver', p=driver_nul)
        mc.orientConstraint(headCtrl, driver)
예제 #13
0
    def build(self):
        '''
        This will build the rig.
        '''
        super(Mouth, self).build()
        lipMainCurve = self.getAttributeByName('lipMainCurve').getValue()
        lipCurve = self.getAttributeByName('lipCurve').getValue()
        parentGroup = self.getAttributeByName('systemParent').getValue()
        geometry = self.getAttributeByName('geometry').getValue()
        headPinTrs = self.getAttributeByName('headPin').getValue()
        jawPinTrs = self.getAttributeByName('jawPin').getValue()
        orientFile = self.getAttributeByName('orientFile').getValue()

        bindmeshGeometry, follicleList, lipMainControlHieracrchyList, jointList = self.__buildCurveRig(lipMainCurve, "lip_main" , parentGroup)
        # delete the controls, tparent joint to the node above the control
        mainBaseCurveJointList = list()
        for jnt, lipMainControlList in zip(jointList, lipMainControlHieracrchyList):
            # create the joint that we will use later to deform the base wire.
            baseCurveJoint = mc.joint(name=jnt.replace("_jnt","_baseCurve_jnt"))
            mainBaseCurveJointList.append(baseCurveJoint)
            # hide the base curve joint. Then parent it under the null node
            mc.setAttr("{}.v".format(baseCurveJoint), 0)
            mc.parent(baseCurveJoint, lipMainControlList[1])
            mc.setAttr("{}.t".format(baseCurveJoint), 0, 0, 0)
            mc.parent(jnt,lipMainControlList[-2])
            mc.delete(lipMainControlList.pop(-1))

        # create a bindMesh for mouth corner controls.
        jointListPos = [mc.xform(joint, q=True, ws=True, t=True) for joint in jointList]
        jointListPosX = [round(pos[0], 3) for pos in jointListPos]
        cornerPos = [jointListPos[jointListPosX.index(max(jointListPosX))],
                     jointListPos[jointListPosX.index(min(jointListPosX))]]

        # create the bindmesh 
        bindmeshGeometry, follicleList = bindmesh.create("{}_corner".format(self.name), cornerPos)
        # set the visibility of the bindmesh
        mc.setAttr("{}.v".format(bindmeshGeometry), 0 )
        mouthCorner_l_follicle = mc.rename(follicleList[0], follicleList[0].replace('_0_','_l_'))
        mouthCorner_r_follicle = mc.rename(follicleList[1], follicleList[1].replace('_1_','_r_'))
        mc.parent([mouthCorner_l_follicle, mouthCorner_r_follicle, bindmeshGeometry], self.name)

        controlPrefix = "lip_main"
        # get the position of the controls for lip tweakers
        upperLeft = list()
        upperLeftPosXList = list()
        upperRight = list()
        upperRightPosXList = list()
        lowerLeft = list()
        lowerLeftPosXList = list()
        lowerRight = list()
        lowerRightPosXList = list()
        mouthCornerLeftPosY = round(mc.xform(mouthCorner_l_follicle, q=True, ws=True, t=True)[1], 3)
        mouthCornerRightPosY = round(mc.xform(mouthCorner_r_follicle, q=True, ws=True, t=True)[1], 3)
        for controlHieracrchy in lipMainControlHieracrchyList:
            #position of control
            controlPosition = mc.xform(controlHieracrchy[0], q=True, ws=True, t=True)
            posX = round(controlPosition[0], 3)
            posY = round(controlPosition[1], 3)
            if posX > .001:
                if round(abs(posY-mouthCornerLeftPosY),3) <.003:
                    lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_corner_l")) for ctrl in controlHieracrchy]
                elif posY > mouthCornerLeftPosY:
                    upperLeft.append(controlHieracrchy)
                    upperLeftPosXList.append(posY)
                elif posY < mouthCornerLeftPosY:
                    lowerLeft.append(controlHieracrchy)
                    lowerLeftPosXList.append(posY)

            elif posX < -.001:
                if round(abs(posY-mouthCornerLeftPosY),3) <.003:
                    lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_corner_r")) for ctrl in controlHieracrchy]
                elif posY > mouthCornerRightPosY:
                    upperRight.append(controlHieracrchy)
                    upperRightPosXList.append(posY)
                elif posY < mouthCornerRightPosY:
                    lowerRight.append(controlHieracrchy)
                    lowerRightPosXList.append(posY)
            else:
                if posY > mouthCornerLeftPosY:
                    lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_center_up")) for ctrl in controlHieracrchy]
                elif posY < mouthCornerLeftPosY:
                    lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_center_low")) for ctrl in controlHieracrchy]
        # reorder controls
        upperLeftPosXListCopy = list(upperLeftPosXList)
        upperLeftPosXList.sort()
        # rename the controls for left and right.
        for i, pos in enumerate(upperLeftPosXListCopy):
            # rename the center controls.
            lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(upperLeft[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_up_{}_l".format(upperLeftPosXList.index(pos)))) for ctrl in upperLeft[i]]

        # reorder controls
        upperRightPosXListCopy = list(upperRightPosXList)
        upperRightPosXList.sort()
        # rename the controls for left and right.
        for i, pos in enumerate(upperRightPosXListCopy):
            # rename the center controls.
           lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(upperRight[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_up_{}_r".format(upperRightPosXList.index(pos)))) for ctrl in upperRight[i]]

        # reorder controls
        lowerLeftPosXListCopy = list(lowerLeftPosXList)
        lowerLeftPosXList.sort()
        lowerLeftPosXList.reverse()
        # rename the controls for left and right.
        for i, pos in enumerate(lowerLeftPosXListCopy):
            # rename the center controls.
            lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(lowerLeft[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_low_{}_l".format(lowerLeftPosXList.index(pos)))) for ctrl in lowerLeft[i]]

        # reorder controls
        lowerRightPosXListCopy = list(lowerRightPosXList)
        lowerRightPosXList.sort()
        lowerRightPosXList.reverse()
        # rename the controls for left and right.
        for i, pos in enumerate(lowerRightPosXListCopy):
            # rename the center controls.
            lipMainControlHieracrchyList[lipMainControlHieracrchyList.index(lowerRight[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lipMain_low_{}_r".format(lowerRightPosXList.index(pos)))) for ctrl in lowerRight[i]]


        # create the controls
        # If there is a hierarchy argument passed in. We will loop through and create the hiearchy.
        # move the orients
        nodeDataObj = None
        if os.path.isfile(orientFile):
            nodeDataObj = node_data.NodeData()
            nodeDataObj.read(orientFile)

        driverMouthCorners = []
        animMouthCorners = []
        cornerControlHierarchyList = []
        jawPins = []
        headPins = []
        for follicle in (mouthCorner_l_follicle, mouthCorner_r_follicle):
            parent = follicle
            controlName = follicle.split("_follicle")[0]
            # Main mouth corner control
            # create the control with a large enough hierarchy to create proper SDK's
            ctrlHierarchy = control.create(name=controlName, 
                controlType="square", 
                hierarchy=['nul','ort', 'auto'], 
                color=common.BLACK,
                parent=parent,
                type='face')
            attribute.lockAndHide(ctrlHierarchy[-1], ['r', 'rx', 'ry', 'rz', 's', 'sx', 'sy', 'sz'])
            cornerControlHierarchyList.append(ctrlHierarchy)
            animMouthCorners.append(controlName)
            driverMouthCorner = mc.createNode("joint", name="{}_driver".format(controlName))
            driverMouthCorners.append(driverMouthCorner)
            # mover the driver to the orient and parent it under the orient
            mc.parent(driverMouthCorner, ctrlHierarchy[1])
            #mc.xform(driverMouthCorner, ws=True, matrix=mc.xform(ctrlHierarchy[1], q=True, ws=True, matrix=True))
            
            # turn off the visibility of the driver
            mc.setAttr("{}.drawStyle".format(driverMouthCorner), 2)
            # turn on the handle for the mouth corner control and move it 
            mc.setAttr("{}.displayHandle".format(ctrlHierarchy[-1]), 1)
            mc.setAttr("{}.selectHandleX".format(ctrlHierarchy[-1]) ,0.2)
            # zero out the mouth corner hierarchy so it's in the correct position.
            mc.setAttr("{}.translate".format(ctrlHierarchy[0]), 0,0,0)
            #mc.setAttr("{}.rotate".format(ctrlHierarchy[0]), 0,0,0)
            mc.delete(mc.listRelatives(ctrlHierarchy[-1], c=True, shapes=True)[0])

            # create the drivers for the lip_L/R
            neutral = mc.createNode("transform", name="{}_neutral".format(controlName), parent=ctrlHierarchy[1])
            headPin = mc.createNode("transform", name="{}_headPin".format(controlName), parent=ctrlHierarchy[1])
            jawPin = mc.createNode("transform", name="{}_jawPin".format(controlName), parent=ctrlHierarchy[1])
            # Store for constraining later
            headPins.append(headPin)
            jawPins.append(jawPin)

            for pinGrp in [neutral, headPin, jawPin]:
                cst = mc.parentConstraint(pinGrp, ctrlHierarchy[2])[0]
                mc.setAttr(cst+'.interpType', 2)

            # constrain the driver to the control
            mc.pointConstraint(ctrlHierarchy[-1], driverMouthCorner, mo=True)

            if nodeDataObj:
                nodeDataObj.applyData([ctrlHierarchy[1]])

            # create the head and jaw pinning.
            mc.addAttr(controlName, ln="pinning", nn="----------", at="enum", enumName="Pinning", keyable=True)
            attribute.lock(controlName, "pinning")
            mc.addAttr(controlName, ln="pin", at="double", min=-10, max=10, dv=0, keyable=True)
            mc.setDrivenKeyframe("{}.{}W0".format(cst,neutral), 
                cd="{}.pin".format(controlName), v=1, dv=0)
            mc.setDrivenKeyframe("{}.{}W1".format(cst,headPin), 
                cd="{}.pin".format(controlName), v=0, dv=0)
            mc.setDrivenKeyframe("{}.{}W2".format(cst,jawPin), 
                cd="{}.pin".format(controlName), v=0, dv=0)
            mc.setDrivenKeyframe("{}.{}W0".format(cst,neutral), 
                cd="{}.pin".format(controlName), v=0, dv=-10)
            mc.setDrivenKeyframe("{}.{}W1".format(cst,headPin), 
                cd="{}.pin".format(controlName), v=0, dv=-10)
            mc.setDrivenKeyframe("{}.{}W2".format(cst,jawPin), 
                cd="{}.pin".format(controlName), v=1, dv=-10)
            mc.setDrivenKeyframe("{}.{}W0".format(cst,neutral), 
                cd="{}.pin".format(controlName), v=0, dv=10)
            mc.setDrivenKeyframe("{}.{}W1".format(cst,headPin), 
                cd="{}.pin".format(controlName), v=1, dv=10)
            mc.setDrivenKeyframe("{}.{}W2".format(cst,jawPin), 
                cd="{}.pin".format(controlName), v=0, dv=10)

            # create the set driven keyframes
            ty_tz_dkeys = []
            for attr in ['x','y','z']:
                for lipMainControl in lipMainControlHieracrchyList:

                    # Translates
                    if "_l_" in lipMainControl[3] and follicle == mouthCorner_l_follicle:
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=1, dv=1)
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=-1, dv=-1)

                        dkey = mc.listConnections("{}.t{}".format(driverMouthCorner,attr), type='animCurveUL')[-1]
                        dkey = mc.rename(dkey, lipMainControl[3]+'_translate'+attr.upper())

                        # RY Rotation driven by TX
                        if attr == "x":
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=10, dv=1)
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=-10, dv=-1)

                        # TY driving TZ
                        if attr == "y":
                            mc.setDrivenKeyframe("{}.tz".format(lipMainControl[3]),
                                                 cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                            mc.setDrivenKeyframe("{}.tz".format(lipMainControl[3]),
                                                 cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=1)
                            mc.setDrivenKeyframe("{}.tz".format(lipMainControl[3]),
                                                 cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=-1)

                            dkey = mc.listConnections("{}.t{}".format(driverMouthCorner,attr), type='animCurveUL')[-1]
                            dkey = mc.rename(dkey, driverMouthCorner+'_TY__'+lipMainControl[3]+'_TZ')
                            ty_tz_dkeys.append(dkey)


                    elif  "_r_" in lipMainControl[3] and follicle == mouthCorner_r_follicle:

                        # Translates
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=1, dv=1)
                        mc.setDrivenKeyframe("{}.t{}".format(lipMainControl[3],attr), 
                            cd="{}.t{}".format(driverMouthCorner,attr), v=-1, dv=-1)

                        dkey = mc.listConnections("{}.t{}".format(driverMouthCorner,attr), type='animCurveUL')[-1]
                        dkey = mc.rename(dkey, lipMainControl[3]+'_translate'+attr.upper())

                        # RY Rotation driven by TX
                        if attr == "x":
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=10, dv=1)
                            mc.setDrivenKeyframe("{}.ry".format(lipMainControl[2]), 
                                cd="{}.t{}".format(driverMouthCorner,attr), v=-10, dv=-1)

                        # TY driving TZ
                        if attr == "y":
                            mc.setDrivenKeyframe("{}.tz".format(lipMainControl[3]),
                                                 cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=0)
                            mc.setDrivenKeyframe("{}.tz".format(lipMainControl[3]),
                                                 cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=1)
                            mc.setDrivenKeyframe("{}.tz".format(lipMainControl[3]),
                                                 cd="{}.t{}".format(driverMouthCorner,attr), v=0, dv=-1)

                            dkey = mc.listConnections("{}.t{}".format(driverMouthCorner,attr), type='animCurveUL')[-1]
                            dkey = mc.rename(dkey, driverMouthCorner+'_TY__'+lipMainControl[3]+'_TZ')
                            ty_tz_dkeys.append(dkey)

        # Set driven keys to be post and pre infinity
        driven_keys = mc.listConnections(driverMouthCorners[0], type='animCurveUL')
        driven_keys += mc.listConnections(driverMouthCorners[1], type='animCurveUL')
        driven_keys += mc.ls('lipMain_*_rot_def_auto*', type='animCurveUA')
        for x in driven_keys:
            mc.setAttr(x + '.preInfinity', 1)
            mc.setAttr(x + '.postInfinity', 1)
            mc.keyTangent(x, index=(0, 0), inTangentType='spline')
            mc.keyTangent(x, index=(0, 0), outTangentType='spline')
            mc.keyTangent(x, index=(2, 2), inTangentType='spline')
            mc.keyTangent(x, index=(2, 2), outTangentType='spline')

        # control prefix for the lips
        controlPrefix = "lip"
        bindmeshGeometry, follicleList, controlHieracrchyList, jointList = self.__buildCurveRig(lipCurve, controlPrefix , parentGroup)

        # get the position of the controls for lip tweakers
        upperLeft = list()
        upperLeftPosXList = list()
        upperRight = list()
        upperRightPosXList = list()
        lowerLeft = list()
        lowerLeftPosXList = list()
        lowerRight = list()
        lowerRightPosXList = list()
        mouthCornerLeftPosY = round(mc.xform(mouthCorner_l_follicle, q=True, ws=True, t=True)[1], 3)
        mouthCornerRightPosY = round(mc.xform(mouthCorner_r_follicle, q=True, ws=True, t=True)[1], 3)
        for controlHieracrchy in controlHieracrchyList:
            # create the joint that we will use later to deform the base wire.
            baseCurveJoint = mc.joint(name=jointList[controlHieracrchyList.index(controlHieracrchy)].replace("_jnt","_baseCurve_jnt"))
            # hide the base curve joint. Then parent it under the null node
            mc.setAttr("{}.v".format(baseCurveJoint), 0)
            mc.parent(baseCurveJoint, controlHieracrchy[0])
            #position of control
            controlPosition = mc.xform(controlHieracrchy[0], q=True, ws=True, t=True)
            posX = round(controlPosition[0], 3)
            posY = round(controlPosition[1], 3)
            if posX > .001:
                if round(abs(posY-mouthCornerLeftPosY),3) <.003:
                    controlHieracrchyList[controlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_corner_l")) for ctrl in controlHieracrchy]
                elif posY > mouthCornerLeftPosY:
                    upperLeft.append(controlHieracrchy)
                    upperLeftPosXList.append(posY)
                elif posY < mouthCornerLeftPosY:
                    lowerLeft.append(controlHieracrchy)
                    lowerLeftPosXList.append(posY)

            elif posX < -.001:
                if round(abs(posY-mouthCornerLeftPosY),3) <.003:
                    controlHieracrchyList[controlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_corner_r")) for ctrl in controlHieracrchy]
                elif posY > mouthCornerRightPosY:
                    upperRight.append(controlHieracrchy)
                    upperRightPosXList.append(posY)
                elif posY < mouthCornerRightPosY:
                    lowerRight.append(controlHieracrchy)
                    lowerRightPosXList.append(posY)
            else:
                if posY > mouthCornerLeftPosY:
                    controlHieracrchyList[controlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_center_up")) for ctrl in controlHieracrchy]
                elif posY < mouthCornerLeftPosY:
                    controlHieracrchyList[controlHieracrchyList.index(controlHieracrchy)] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_center_low")) for ctrl in controlHieracrchy]
        # reorder controls
        upperLeftPosXListCopy = list(upperLeftPosXList)
        upperLeftPosXList.sort()
        # rename the controls for left and right.
        for i, pos in enumerate(upperLeftPosXListCopy):
            # rename the center controls.
            controlHieracrchyList[controlHieracrchyList.index(upperLeft[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_up_{}_l".format(upperLeftPosXList.index(pos)))) for ctrl in upperLeft[i]]

        # reorder controls
        upperRightPosXListCopy = list(upperRightPosXList)
        upperRightPosXList.sort()
        # rename the controls for left and right.
        for i, pos in enumerate(upperRightPosXListCopy):
            # rename the center controls.
           controlHieracrchyList[controlHieracrchyList.index(upperRight[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_up_{}_r".format(upperRightPosXList.index(pos)))) for ctrl in upperRight[i]]

        # reorder controls
        lowerLeftPosXListCopy = list(lowerLeftPosXList)
        lowerLeftPosXList.sort()
        lowerLeftPosXList.reverse()
        # rename the controls for left and right.
        for i, pos in enumerate(lowerLeftPosXListCopy):
            # rename the center controls.
            controlHieracrchyList[controlHieracrchyList.index(lowerLeft[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_low_{}_l".format(lowerLeftPosXList.index(pos)))) for ctrl in lowerLeft[i]]

        # reorder controls
        lowerRightPosXListCopy = list(lowerRightPosXList)
        lowerRightPosXList.sort()
        lowerRightPosXList.reverse()
        # rename the controls for left and right.
        for i, pos in enumerate(lowerRightPosXListCopy):
            # rename the center controls.
            controlHieracrchyList[controlHieracrchyList.index(lowerRight[i])] = [mc.rename(ctrl, "_".join([name for name in ctrl.split("_") if not name.isdigit()]).replace(controlPrefix, "lip_low_{}_r".format(lowerRightPosXList.index(pos)))) for ctrl in lowerRight[i]]


        # parent the curves to their respective systems
        mc.parent(lipMainCurve, "lip_main")
        mc.parent(lipCurve, "lip")

        #deform the lip bindmesh with the lip_main curve using a wire deformer.
        wireDeformer = mc.wire(bindmeshGeometry, gw=False, en=1.00, ce=0.00, li=0.00,
                w=lipMainCurve, name="{}_wire".format(lipMainCurve))[0]
        # set the default values for the wire deformer
        mc.setAttr("{}.rotation".format(wireDeformer), 0)
        mc.setAttr("{}.dropoffDistance[0]".format(wireDeformer), 100)

        # create skinCluster for the base wire
        baseCurve = "{}BaseWire".format(lipMainCurve)
        lipMainBaseCurveSkin = mc.skinCluster(*mainBaseCurveJointList+mc.ls(baseCurve),
                                    n="{}_skinCluster".format(baseCurve),
                                    tsb=True)[0]
        # set the weights to have proper weighting
        wtObj = rigrepo.libs.weights.getWeights(lipMainBaseCurveSkin)
        weightList = list()
        for i, inf in enumerate(wtObj):
            array = numpy.zeros_like(wtObj.getWeights(inf))[0]
            array[i] = 1
            weightList.append(array)
        wtObj.setWeights(weightList)
        rigrepo.libs.weights.setWeights(lipMainBaseCurveSkin, wtObj)

        # create all of the lip clusters
        lipControls = list(set(mc.ls("lip_*.__control__", o=True)).difference(set(mc.ls(["lip_upper", "lip_lower", "lip_upper_?", "lip_lower_?"]))))
        for node in lipControls:
            rigrepo.libs.cluster.create(geometry, 
                                        "{}_cluster".format(node), 
                                        contraintTypes=["orient","scale"], 
                                        parent="{}_def_auto".format(node), 
                                        parallel=False)
            nul = "{}_cluster_nul".format(node)
            mc.xform(nul, ws=True, matrix=mc.xform(node, q=True, ws=True, matrix=True))
            mc.connectAttr("{}.t".format(node), "{}_cluster_auto.t".format(node), f=True)
            mc.connectAttr("{}.r".format(node), "{}_cluster_ctrl.r".format(node), f=True)
            mc.connectAttr("{}.s".format(node), "{}_cluster_ctrl.s".format(node), f=True)

        # Set the right side nuls to be mirrored
        for ctrls in controlHieracrchyList + \
                     lipMainControlHieracrchyList + \
                     cornerControlHierarchyList:
            nul = ctrls[0]
            if nul.endswith('_r_nul'):
                mc.setAttr(nul+'.ry', -180)
                mc.setAttr(nul+'.sz', -1)

        # constrain the head and jaw pinning. Needs to be done after nul's are mirrored
        for jawPin in jawPins:
            mc.parentConstraint(jawPinTrs, jawPin, mo=True)
        for headPin in headPins:
            mc.parentConstraint(headPinTrs, headPin, mo=True)

        # Rig Sets
        #
        rigSets = 'RigSets'
        if not mc.objExists(rigSets):
            mc.sets(n=rigSets, empty=1)
        mouthSet = mc.sets(n='Mouth', empty=1)
        mc.sets(mouthSet, e=1, add=rigSets)
        # Curves
        mc.sets( ['lip_bindmesh', 'lip_main_bindmesh',
                 lipCurve, lipMainCurve], e=1, add=mouthSet)

        # Orient Sets
        #
        corner_set = mc.sets([x[1] for x in cornerControlHierarchyList], n='orients_MouthCorner')
        main_set = mc.sets([x[1] for x in lipMainControlHieracrchyList], n='orients_lipMain')
        tweak_set = mc.sets([x[1] for x in controlHieracrchyList], n='orients_lipTweakers')

        mc.sets([main_set, tweak_set, corner_set], e=1, add=mouthSet)
        # Driven Keys
        #
        #
        for driver_axis in ['x', 'y', 'z']:
            driven_keys = mc.listConnections(driverMouthCorners[0]+'.t'+driver_axis, type='animCurveUL')
            driven_keys += mc.listConnections(driverMouthCorners[1]+'.t'+driver_axis, type='animCurveUL')
            for slave_axis in ['X', 'Y', 'Z']:
                d_keys = [n for n in driven_keys if 'translate' + slave_axis in n]
                if not d_keys:
                    d_keys = [n for n in driven_keys if '_T' + slave_axis in n]
                if d_keys:
                    d_set = mc.sets(d_keys, n='dkeys_T'+driver_axis.upper()+'_T'+slave_axis)
                    mc.sets(d_set, e=1, add=mouthSet)

        # Rot Driven Keys
        #
        rot_def_auto = [x[2] for x in lipMainControlHieracrchyList]
        ry_d_keys = []
        rx_d_keys = []
        for rot in rot_def_auto:
            driven_keys = mc.listConnections(rot, type='animCurveUA')
            if driven_keys:
                for dkey in driven_keys:
                    if 'rotateY' in dkey:
                        ry_d_keys.append(dkey)
                    if 'rotateX' in dkey:
                        rx_d_keys.append(dkey)
        ry_d_keys_set = mc.sets(ry_d_keys, n='dkeys_RY')
        mc.sets([ry_d_keys_set], e=1, add=mouthSet)

        # Anim controls
        #
        animCtrls = animMouthCorners + [x[4] for x in controlHieracrchyList]
        tweak_ctrl = mc.sets(animCtrls, n='anim')
        mc.sets(tweak_ctrl, e=1, add=mouthSet)
예제 #14
0
    def build(self):
        '''
        '''
        super(Spine, self).build()

        jointList = eval(self.jointList)
        self.spline = spline.SplineBase(jointList=jointList +
                                        [self._chestBind],
                                        splineName=self._splineName)
        self.spline.create()
        # get the attributes from the user
        geometry = self.getAttributeByName("geometry").getValue()
        bendyCurve = self.getAttributeByName("bendyCurve").getValue()
        createBendySpline = self.getAttributeByName(
            "createBendySpline").getValue()

        # Hips
        hipsCtrlHierarchy = control.create(name="hips",
                                           controlType="cube",
                                           hideAttrs=["sx", "sy", "sz", "v"],
                                           hierarchy=['nul'])
        hipsCtrl = hipsCtrlHierarchy[-1]
        hipsNul = hipsCtrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(hipsCtrl, ["sx", "sy", "sz", "v"])
        matrix = mc.xform(self._hipsBind, q=True, ws=True, matrix=True)
        mc.xform(hipsNul, ws=True, matrix=matrix)

        hipsGimbalCtrlHierarchy = control.create(
            name="hips_gimbal",
            controlType="cube",
            hierarchy=['nul'],
            hideAttrs=["sx", "sy", "sz", "v"],
            parent=hipsCtrl)
        hipsGimbalCtrl = hipsGimbalCtrlHierarchy[-1]
        hipsGimbalNul = hipsGimbalCtrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(hipsGimbalCtrl,
                                           ["sx", "sy", "sz", "v"])
        mc.xform(hipsGimbalNul, ws=True, matrix=matrix)

        # hip swivel
        ctrlHierarchy = control.create(name="hip_swivel",
                                       controlType="cube",
                                       color=common.GREEN,
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        hipSwivelCtrl = ctrlHierarchy[-1]
        hipSwivelNul = ctrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(hipSwivelCtrl,
                                           ["sx", "sy", "sz", "v"])
        mc.xform(hipSwivelNul, ws=True, matrix=matrix)
        averagePos = rigrepo.libs.transform.getAveragePosition(jointList[0:3])
        mc.xform(hipSwivelNul, ws=True, t=averagePos)
        mc.parent(hipSwivelNul, hipsGimbalCtrl)
        clusters = self.spline._clusters
        mc.parent(clusters[0:2], hipSwivelCtrl)
        mc.orientConstraint(hipSwivelCtrl, self.spline._startTwistNul, mo=1)

        # Parent the entire ik group to the hips
        mc.parent(self.spline.getGroup(), hipsGimbalCtrl)

        # torso
        ctrlHierarchy = control.create(name="torso",
                                       controlType="cube",
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        torsoCtrl = ctrlHierarchy[-1]
        torsoNul = ctrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(torsoCtrl, ["sx", "sy", "sz", "v"])
        rotation = mc.xform(hipsCtrl, q=True, ws=True, rotation=True)
        averagePos = rigrepo.libs.transform.getAveragePosition(jointList[:2])
        mc.xform(torsoNul, ws=True, rotation=rotation)
        mc.xform(torsoNul, ws=True, t=averagePos)
        mc.parent(torsoNul, hipsGimbalCtrl)

        # chest
        ctrlHierarchy = control.create(name="chest",
                                       controlType="cube",
                                       color=common.GREEN,
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        chestCtrl = ctrlHierarchy[-1]
        chestNul = ctrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(chestCtrl, ["sx", "sy", "sz", "v"])
        matrix = mc.xform(jointList[-3], q=True, ws=True, matrix=True)
        averagePos = rigrepo.libs.transform.getAveragePosition(
            jointList[-3:-1])
        mc.xform(chestNul, ws=True, matrix=matrix)
        mc.xform(chestNul, ws=True, t=averagePos)
        mc.parent(chestNul, torsoCtrl)

        # chest IK
        ctrlHierarchy = control.create(name="chest_ik",
                                       controlType="cube",
                                       color=common.GREEN,
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        chestIkCtrl = ctrlHierarchy[-1]
        chestIkNul = ctrlHierarchy[0]

        rigrepo.libs.attribute.lockAndHide(chestIkCtrl,
                                           ["sx", "sy", "sz", "v"])

        mc.xform(chestIkNul, ws=True, matrix=matrix)
        mc.xform(chestIkNul, ws=True, t=averagePos)
        mc.parent(chestIkNul, chestCtrl)

        # chest top
        ctrlHierarchy = control.create(name="chest_top",
                                       controlType="cube",
                                       hideAttrs=["sx", "sy", "sz", "v"],
                                       hierarchy=['nul'])
        chestTopCtrl = ctrlHierarchy[-1]
        chestTopNul = ctrlHierarchy[0]
        rigrepo.libs.attribute.lockAndHide(chestTopCtrl,
                                           ["sx", "sy", "sz", "v"])

        matrix = mc.xform(self._chestBind, q=True, ws=True, matrix=True)
        mc.xform(chestTopNul, ws=True, matrix=matrix)
        mc.parent(chestTopNul, chestIkCtrl)

        mc.parent(clusters[2:], chestIkCtrl)
        mc.orientConstraint(chestTopCtrl, self.spline._endTwistNul, mo=1)

        self._hipsCtrl = hipsCtrl
        self._hipSwivelCtrl = hipSwivelCtrl
        self._torsoCtrl = torsoCtrl
        self._chestCtrl = chestCtrl
        self._chestTopCtrl = chestTopCtrl
        self._chestIkCtrl = chestIkCtrl

        # Remove existing constraint on chestBind
        orientConstraint = mc.orientConstraint(self._chestBind, q=1)
        pointConstraint = mc.pointConstraint(self._chestBind, q=1)
        if orientConstraint:
            mc.delete(orientConstraint)
        if pointConstraint:
            mc.delete(pointConstraint)

        mc.pointConstraint(chestTopCtrl, self._chestBind, mo=1)
        mc.orientConstraint(chestTopCtrl, self._chestBind, mo=1)
        #mc.connectAttr(chestTopCtrl+'.s', self._chestBind+'.s')

        mc.parentConstraint(hipSwivelCtrl, self._hipsBind, mo=1)
        mc.connectAttr(hipSwivelCtrl + '.s', self._hipsBind + '.s')

        mc.parent(hipsNul, self.name)
        mc.hide(self.spline._group, clusters)

        if createBendySpline and mc.objExists(bendyCurve):
            bindmeshGeometry, follicleList, controlHieracrchyList, bendJointList = self.__buildCurveRig(
                bendyCurve,
                name='{}_bend'.format(self.getName()),
                parent=self.name)

            if mc.objExists(geometry):
                #deform the lid bindmesh with the lid curve using a wire deformer.
                wireDeformer = mc.wire(geometry,
                                       gw=False,
                                       en=1.00,
                                       ce=0.00,
                                       li=0.00,
                                       w=bendyCurve,
                                       name="{}_wire".format(bendyCurve))[0]
                baseCurveJointList = list()
                i = 0
                for jnt, controlList in zip(bendJointList,
                                            controlHieracrchyList):
                    # create the joint that we will use later to deform the base wire.
                    baseCurveJoint = mc.joint(
                        name=jnt.replace("_jnt", "_baseCurve_jnt"))
                    baseCurveJointList.append(baseCurveJoint)
                    # hide the base curve joint. Then parent it under the null node
                    mc.setAttr("{}.v".format(baseCurveJoint), 0)
                    mc.parent(baseCurveJoint, controlList[1])
                    mc.setAttr("{}.t".format(baseCurveJoint), 0, 0, 0)

                baseCurve = "{}BaseWire".format(bendyCurve)
                mc.parent([bendyCurve, baseCurve], self.name)
                baseCurveSkin = mc.skinCluster(
                    *[baseCurveJointList] + mc.ls(baseCurve),
                    n="{}_skinCluster".format(baseCurve),
                    tsb=True)[0]

                # set the default values for the wire deformer
                mc.setAttr("{}.rotation".format(wireDeformer), 0)
                mc.setAttr("{}.dropoffDistance[0]".format(wireDeformer), 100)

            bindMeshSkin = mc.skinCluster(
                *jointList + [self._hipsBind, self._chestBind] +
                mc.ls(bindmeshGeometry),
                n="{}_skinCluster".format(bindmeshGeometry),
                tsb=True)[0]

            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[0:3]'.format(bindmeshGeometry),
                           transformValue=[(self._hipsBind, 1.0),
                                           (jointList[0], 0.0)])
            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[4:7]'.format(bindmeshGeometry),
                           transformValue=[(jointList[0], 0.0),
                                           (jointList[1], 0.5),
                                           (jointList[2], 0.0)])
            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[8:11]'.format(bindmeshGeometry),
                           transformValue=[(jointList[3], 1.0),
                                           (jointList[1], 0.0)])
            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[12:15]'.format(bindmeshGeometry),
                           transformValue=[(jointList[2], 0.0),
                                           (jointList[4], 0.5),
                                           (self._chestBind, .5)])
            mc.skinPercent(bindMeshSkin,
                           '{}.vtx[16:19]'.format(bindmeshGeometry),
                           transformValue=[(self._chestBind, 1.0),
                                           (jointList[1], 0.0),
                                           (jointList[2], 0.0)])