示例#1
0
    def install(self):

        controlZroGrp = cmds.listConnections(cmds.listConnections(self.nodes['control']+".controlMetadata")[0] + ".zeroGroup")
        
        if not cmds.objExists(self.nodes['switcher']):
            utils_transforms.createZeroGroup(controlZroGrp, name=self.nodes['switcher'])
          
        # translate Spaces
        for space in self.translateSpaces:
            spaceGrp = space + "_space"
            attrName = self.nodes['control']+"_translateSpace"
            
            if cmds.attributeQuery(attrName, n = self.customAttribute, exists=True):
                enumName = cmds.addAttr(self.customAttribute +'.'+ attrName, q=True, enumName=True)
                enumName = enumName + ":" + space
                cmds.addAttr(self.customAttribute +'.'+ attrName, e=True, enumName=enumName, k=True)
            else:            
                cmds.addAttr(self.customAttribute, at='enum', enumName = space, ln=attrName, k=len(self.translateSpaces) > 1)
                            
            ## space locator
            spaceLoc = self.nodes['control'] + "_AT_" + space
            if not cmds.objExists(spaceLoc):
                cmds.spaceLocator(name = spaceLoc)[0]
                cmds.setAttr(spaceLoc+".visibility", 0)
                cmds.delete(cmds.parentConstraint(self.nodes['switcher'], spaceLoc, maintainOffset=False))
                cmds.parent(spaceLoc, spaceGrp , absolute=True)
    
            pCon = cmds.pointConstraint(spaceLoc, self.nodes['switcher'], name = self.nodes['switcher'] + "_pointConst")[0]
            transWeights = cmds.pointConstraint(pCon, q=True, wal=True)
            pCondition = self.enumCondition(self.customAttribute + '.' + self.nodes['control'] + "_translateSpace", self.nodes['control']+"_AT_"+ space + "_translateSpace_condition")
            cmds.connectAttr(pCondition+".outColorR", pCon + "." + transWeights[-1])
    
        # orient Spaces
        for space in self.orientSpaces:
            spaceGrp = space + "_space"
            attrName = self.nodes['control']+"_orientSpace"
            
            if cmds.attributeQuery(attrName, n = self.customAttribute, exists=True):
                enumName = cmds.addAttr(self.customAttribute +'.'+ attrName, q=True, enumName=True)
                enumName = enumName + ":" + space
                cmds.addAttr(self.customAttribute +'.'+ attrName, e=True, enumName=enumName, k=True)
            else:            
                cmds.addAttr(self.customAttribute, at='enum', enumName = space, ln=attrName, k=len(self.orientSpaces) > 1)
                            
            ## space locator
            spaceLoc = self.nodes['control'] + "_AT_" + space
            if not cmds.objExists(spaceLoc):
                cmds.spaceLocator(name = spaceLoc)[0]
                cmds.setAttr(spaceLoc+".visibility", 0)
                cmds.delete(cmds.parentConstraint(self.nodes['switcher'], spaceLoc, maintainOffset=False))
                cmds.parent(spaceLoc, spaceGrp , absolute=True)
                
            oCon = cmds.orientConstraint(spaceLoc, self.nodes['switcher'], name = self.nodes['switcher'] + "_orientConst")[0]
            orientWeights = cmds.orientConstraint(oCon, q=True, wal=True)
            oCondition = self.enumCondition(self.customAttribute + '.' + self.nodes['control'] + "_orientSpace", self.nodes['control']+"_AT_"+space + "_orientSpace_condition")      
            cmds.connectAttr(oCondition+".outColorR", oCon + "." + orientWeights[-1])   
        
        return
示例#2
0
    def __init__(self, joints=[], prefix=[], jointCount=5):
        
        if len(joints) !=3:
            raise Warning("No Start Node, Mid Node and End Node Defined, Aborting..")
            return

        prefix[0] or joints[0].replace("_joint", "")
        prefix[1] or joints[1].replace("_joint", "")

        #=======================================================================
        # GET MASTER METADATA
        #=======================================================================
        master_metadata = 'master_metadata'
        
        if not cmds.objExists(master_metadata):
            raise Warning ("No Master Group Found, Aborting...")
            return

        deformerGroup = cmds.listConnections('master_metadata.deformerGroup')[0]

        #=======================================================================
        # INSTALL
        #=======================================================================
        ribbonHingeGrp = prefix[0] + "_ribbonHinge_grp"
        cmds.group(name=ribbonHingeGrp, empty=True)
        cmds.parent(ribbonHingeGrp, deformerGroup)        
        
        midLoc = cmds.group(name = prefix[1] + "_offset", empty=True)
        midLocZro = utils_transforms.createZeroGroup(midLoc, name = midLoc + "_zro")
        cmds.parentConstraint(joints[1], midLocZro, maintainOffset=False)
        
        r1 = Ribbon(prefix = prefix[0], startNode=joints[0], endNode=midLoc, jointCount=jointCount)
        r2 = Ribbon(prefix = prefix[1], startNode=midLoc, endNode=joints[2], jointCount=jointCount)
        
        cmds.parent(midLocZro, r1.moduleGrp, r2.moduleGrp, ribbonHingeGrp)
        
        #create control
        c = control.Control(target=midLoc, name=midLoc+"_ctrl", controlShape='square', lod=2)
        cmds.parentConstraint(joints[1], c.nodes['zeroGroup'], maintainOffset=False)        
示例#3
0
    def install(self):
                               
        #create bind joint
        cmds.select(clear=True)
        bindJoint = cmds.joint(name= self.joint.replace("_joint", "_bind"), radius= cmds.getAttr(self.joint + ".radius"))

        zro = utils_transforms.createZeroGroup(bindJoint, name = bindJoint+"_zro")
        
        #parent
        parentJoint = cmds.listRelatives(self.joint, p=True, type='joint')
        if not parentJoint:
            cmds.parent(zro, self.bindGroup, absolute=True)

            parents = cmds.listRelatives(self.joint, p=True)
            if not parents or self.jointGrp not in parents:
                cmds.parent(self.joint, self.jointGrp, absolute=True)
            
        else:              
            cmds.parent(zro, parentJoint[0].replace('joint', 'bind'), absolute=True)


        self.poseParentConstraint(zro)

        return
示例#4
0
    def install(self):
        
#        startJoint = cmds.duplicate(self.joints[0], name=self.nodes['joint_01'], parentOnly=True)[0]
#        endJoint = cmds.duplicate(self.joints[-1], name=self.nodes['joint_%02d' %(self.ikCount)], parentOnly=True)[0]
#        cmds.parent(endJoint, startJoint, absolute=True)
#        cmds.parent(startJoint, world=True)
        
        startJoint = cmds.joint(name=self.nodes['joint_01'])
        endJoint = cmds.joint(name=self.nodes['joint_%02d' %(self.ikCount)])
        
        cmds.delete(cmds.parentConstraint(self.joints[0], startJoint, maintainOffset=False))
        cmds.delete(cmds.parentConstraint(self.joints[-1], endJoint, maintainOffset=False))
        
        
        splitJoints = utils_rigging.splitJoint(joint=startJoint, split=self.ikCount-1, prefix=self.prefix)

        for i in range(1, self.ikCount-1):
            cmds.rename(splitJoints[i], self.nodes['joint_%02d' %(i+1)])
            
        for i in range(0, self.ikCount):
            bJoint.BindJoint(joint=self.nodes['joint_%02d' %(i+1)])

        cmds.group(name=self.moduleGrp, empty=True)
        cmds.parent(self.moduleGrp, self.deformerGroup)
       
        startJointPos = cmds.xform(startJoint, ws=True, q=True, translation=True)
        endJointPos = cmds.xform(endJoint, ws=True, q=True, translation=True)

        ikCurve = cmds.curve(d=1, p=[(startJointPos[0],startJointPos[1],startJointPos[2]), (endJointPos[0], endJointPos[1], endJointPos[2])], name=self.prefix+"_ikCurve")
        cmds.rebuildCurve(ikCurve, ch=0, s=2, d=3)
        
        cmds.setAttr(ikCurve + ".inheritsTransform", 0)
        cmds.parent(ikCurve, self.moduleGrp)
        
        cvCount = len(cmds.getAttr(ikCurve+".cv[*]"))
        cvList = []
        cvCluster = []
        cvClusterHandle = []
        for x in range(0, cvCount):
            cvClusterInfo = cmds.cluster(ikCurve+".cv[%d]" %x, name=self.prefix+ "_cv%d" %x + "_cluster")
            cvCluster.append(cvClusterInfo[0])
            cvClusterHandle.append(cvClusterInfo[1])
            cmds.setAttr(cvClusterInfo[1] + ".visibility", 0)            
            cvList.append(ikCurve+".cv[%d]" %x)

        startGrp = cmds.group(empty=True, name=self.prefix+"_start")
        cmds.delete(cmds.parentConstraint(startJoint, startGrp, maintainOffset=False))
        cmds.parent(cvClusterHandle[0], startGrp, absolute=True)
   
        endGrp = cmds.group(empty=True, name=self.prefix+"_end")
        cmds.delete(cmds.parentConstraint(endJoint, endGrp, maintainOffset=False))        
        cmds.parent(cvClusterHandle[-1], endGrp, absolute=True)

        startGrpZro = utils_transforms.createZeroGroup(startGrp, name=startGrp+'_zro')        
        endGrpZro = utils_transforms.createZeroGroup(endGrp, name=endGrp+'_zro')
                
        cmds.parent(startGrpZro, endGrpZro, self.moduleGrp)

        counter = 1
        for c in cvClusterHandle[1:-1]:
            weight = 1.0 / (cvCount - 1) * counter
            counter += 1
            
            cGrp = cmds.group(empty=True, name=c+"_rotate")
            
            cmds.delete(cmds.pointConstraint(c, cGrp, maintainOffset=False))
                        
            cGrpX = cmds.duplicate(cGrp, name=c+'_x')[0]
            cGrpY = cmds.duplicate(cGrp, name=c+'_y')[0]
            cGrpZ = cmds.duplicate(cGrp, name=c+'_z')[0]

            cmds.parent(c, cGrp, absolute=True)
            cmds.parent(cGrp, cGrpZ, absolute=True)            
            cmds.parent(cGrpZ, cGrpY, absolute=True)
            cmds.parent(cGrpY, cGrpX, absolute=True)
            cmds.parent(cGrpX, self.moduleGrp, absolute=True)

            for grp, skipTranslate in zip ([cGrp, cGrpX, cGrpY, cGrpZ], [['x','y','z'], ['y','z'],['x','z'],['x','y']]):
                if grp == cGrp :
                    pCon = cmds.parentConstraint(startGrp, endGrp, grp, maintainOffset=True, skipTranslate=skipTranslate, name=grp+"_pConst")[0]                    
                else:
                    pCon = cmds.parentConstraint(startGrp, endGrp, grp, maintainOffset=True, skipTranslate=skipTranslate, skipRotate=['x','y','z'], name=grp+"_pConst")[0]
                    
                targets = cmds.parentConstraint(pCon, q=True, wal=True)
                
                attr = grp+"_blend"
                cmds.addAttr(self.customAttribute, at='float', ln=attr, k=True, max=1, min=0, dv=weight)                
                cmds.connectAttr(self.customAttribute + "." + attr, pCon+"."+targets[1])
                
                grpPM = cmds.createNode('plusMinusAverage', name = grp+"_plusMinus")
                cmds.setAttr(grpPM + ".operation", 2) #subtract
                cmds.setAttr(grpPM + ".input1D[0]", 1)
                cmds.connectAttr(self.customAttribute + "." + attr, grpPM + ".input1D[1]")
                cmds.connectAttr(grpPM+".output1D", pCon+"."+targets[0])
                
        ikHandle, ikEffector = cmds.ikHandle(sj=startJoint, ee=endJoint, sol='ikSplineSolver', ccv=False, pcv=False, curve=ikCurve, ns=4, name=self.prefix+"_ikHandle")
        cmds.rename(ikEffector, self.prefix+'_ikEffector')
        cmds.parent(ikHandle, self.moduleGrp)
        cmds.setAttr(ikHandle+".visibility", 0)
        
        #build strechty
        curveInfo = cmds.arclen(ikCurve, ch=True)
        curveInfo = cmds.rename(curveInfo, self.prefix+"_curveInfo" )
        length = cmds.getAttr(curveInfo + ".arcLength")
        
        normalizedScaleMD = cmds.createNode('multiplyDivide', name = self.prefix + "_normalizedScaleMD")
        cmds.setAttr(normalizedScaleMD+'.operation', 2)
                
        globalScaleMD = cmds.createNode('multiplyDivide', name = self.prefix + "_globalScaleMD")

        cmds.connectAttr(self.customAttribute + '.globalScale', globalScaleMD + ".input1X")
        cmds.setAttr(globalScaleMD + ".input2X", length)
        
        cmds.connectAttr(curveInfo + ".arcLength", normalizedScaleMD + ".input1X")
        cmds.connectAttr(globalScaleMD + '.outputX', normalizedScaleMD + ".input2X")

        for i in range(0, self.ikCount):
            cmds.connectAttr(normalizedScaleMD + '.outputX', self.nodes['joint_%02d' %(i+1)] + ".scaleX")
#        
#        for joint in ikJoints:
#            cmds.connectAttr(normalizedScaleMD + '.outputX', joint + ".scaleX")
            
        #twist
        cmds.setAttr(ikHandle+".dTwistControlEnable", 1)
        cmds.setAttr(ikHandle+".dWorldUpType", 4) #object rotation up (start/endFollow)        

        cmds.setAttr(ikHandle+".dWorldUpAxis", 0)
        cmds.setAttr(ikHandle+".dWorldUpVectorY", 1)
        cmds.setAttr(ikHandle+".dWorldUpVectorEndY", 1)
        
        cmds.connectAttr(startGrp+".worldMatrix[0]", ikHandle+".dWorldUpMatrix")
        cmds.connectAttr(endGrp+".worldMatrix[0]", ikHandle+".dWorldUpMatrixEnd")        

        #=======================================================================
        #parent ik start / end
        #=======================================================================
        if self.nodes['endFollow']:
            cmds.parentConstraint(self.nodes['endFollow'], endGrp, maintainOffset=True)

        if self.nodes['rootFollow']:
            cmds.parentConstraint(self.nodes['rootFollow'], startGrp, maintainOffset=True)
示例#5
0
    def install(self):

        # =======================================================================
        # CONTROL
        # =======================================================================
        cmds.file(PATH + self.controlShape + ".ma", i=True, rdn=True, rpr=self.nodes["control"])
        cmds.rename("control", self.nodes["control"])

        # add offsetCtrl
        cmds.addAttr(self.nodes["control"], at="bool", ln="offsetCtrl", dv=1)
        cmds.setAttr(self.nodes["control"] + ".offsetCtrl", k=False, cb=True)

        # show rotate Order
        cmds.setAttr(self.nodes["control"] + ".rotateOrder", k=False, cb=True)

        # icon self.size
        #        cmds.addAttr(self.nodes['control'], at='double', ln="iconSize", min=0.1, dv=self.size)
        #        cmds.setAttr(self.nodes['control'] + ".iconSize", k=False, cb=True)

        # parent
        utils_transforms.createZeroGroup(self.nodes["control"], name=self.nodes["zeroGroup"])
        cmds.parent(self.nodes["zeroGroup"], self.localOffsetControl, absolute=True)

        # =======================================================================
        # OFFSET CONTROL
        # =======================================================================
        # import ctrl from library
        cmds.file(PATH + "locator.ma", i=True, rdn=True, rpr=self.nodes["offsetControl"])
        cmds.rename("control", self.nodes["offsetControl"])

        cmds.parent(self.nodes["offsetControl"], self.nodes["control"])

        offsetCtrlShapes = cmds.listRelatives(self.nodes["offsetControl"], shapes=True)
        for offsetCtrlShape in offsetCtrlShapes:
            cmds.connectAttr(self.nodes["control"] + ".offsetCtrl", offsetCtrlShape + ".visibility")

        # ===========================================================
        # CLUSTER
        # ===========================================================
        # controller icon cluster
        iconCluster = cmds.cluster(self.nodes["control"], name=self.nodes["control"] + "iconCluster")
        cmds.setAttr(iconCluster[0] + ".relative", 1)

        cmds.rename(iconCluster[1], self.nodes["icon"])
        cmds.xform(self.nodes["icon"], rotatePivot=[0, 0, 0], scalePivot=[0, 0, 0])
        cmds.setAttr(self.nodes["icon"] + ".scale", self.size, self.size, self.size)

        #        cmds.addAttr(self.nodes['icon'], at='double', ln="scaleOffsetX", min=0.1, dv=1)
        #        cmds.addAttr(self.nodes['icon'], at='double', ln="scaleOffsetY", min=0.1, dv=1)
        #        cmds.addAttr(self.nodes['icon'], at='double', ln="scaleOffsetZ", min=0.1, dv=1)

        cmds.setAttr(self.nodes["icon"] + ".visibility", 0)
        cmds.parent(self.nodes["icon"], self.nodes["control"])
        cmds.xform(self.nodes["icon"], rotatePivot=[0, 0, 0], scalePivot=[0, 0, 0])

        #        cmds.createNode('multiplyDivide', name=self.nodes['icon']+"_sizeMD")

        #        cmds.connectAttr(self.nodes['control'] + ".iconSize", self.nodes['icon']+"_sizeMD.input1X")
        #        cmds.connectAttr(self.nodes['control'] + ".iconSize", self.nodes['icon']+"_sizeMD.input1Y")
        #        cmds.connectAttr(self.nodes['control'] + ".iconSize", self.nodes['icon']+"_sizeMD.input1Z")
        #
        #        cmds.connectAttr(self.nodes['icon']+".scaleOffsetX", self.nodes['icon']+"_sizeMD.input2X")
        #        cmds.connectAttr(self.nodes['icon']+".scaleOffsetY", self.nodes['icon']+"_sizeMD.input2Y")
        #        cmds.connectAttr(self.nodes['icon']+".scaleOffsetZ", self.nodes['icon']+"_sizeMD.input2Z")

        #        cmds.connectAttr(self.nodes['icon']+"_sizeMD.output", self.nodes['icon']+ ".scale")

        # turn offsetCtrl off after cluster
        cmds.setAttr(self.nodes["control"] + ".offsetCtrl", 0)

        # ========================================================================
        # SETUP
        # ========================================================================
        cmds.delete(cmds.parentConstraint(self.nodes["target"], self.nodes["zeroGroup"], maintainOffset=False))
        cmds.parentConstraint(
            self.nodes["offsetControl"],
            self.nodes["target"],
            maintainOffset=True,
            name=self.nodes["control"] + "_pConst",
        )

        # =======================================================================
        # PARENT
        # =======================================================================
        parentJoint = cmds.listRelatives(self.nodes["target"], p=True, type="joint")
        if parentJoint:
            if cmds.objExists(parentJoint[0] + ".controlMetadata"):
                parent = cmds.listConnections(
                    cmds.listConnections(parentJoint[0] + ".controlMetadata")[0] + ".offsetControl"
                )
                cmds.parent(self.nodes["zeroGroup"], parent, absolute=True)

        # =======================================================================
        # LOD
        # =======================================================================
        maxLOD = 4

        if not cmds.attributeQuery("controlLOD", n=self.masterGroup, exists=True):
            cmds.addAttr(self.masterGroup, at="long", ln="controlLOD", k=True, dv=maxLOD, min=1, max=maxLOD)
            cmds.setAttr(self.masterGroup + ".controlLOD", k=False, cb=True)

            for i in range(1, maxLOD + 1):
                condition = cmds.createNode("condition", name="lod_%02d_vis_condition" % i)
                cmds.connectAttr(self.masterGroup + ".controlLOD", condition + ".firstTerm")
                cmds.setAttr(condition + ".operation", 3)  # > or =
                cmds.setAttr(condition + ".secondTerm", i)
                cmds.setAttr(condition + ".colorIfTrueR", 1)
                cmds.setAttr(condition + ".colorIfFalseR", 0)

        offsetCtrlShapes = cmds.listRelatives(self.nodes["offsetControl"], shapes=True)
        for offsetCtrlShape in offsetCtrlShapes:
            cmds.connectAttr("lod_%02d_vis_condition.outColorR" % self.lod, offsetCtrlShape + ".lodVisibility")

        ctrlShapes = cmds.listRelatives(self.nodes["control"], shapes=True)
        for ctrlShape in ctrlShapes:
            cmds.connectAttr("lod_%02d_vis_condition.outColorR" % self.lod, ctrlShape + ".lodVisibility")

        cmds.setAttr(self.nodes["control"] + ".visibility", keyable=False)

        # =======================================================================
        # BIND JOINT
        # =======================================================================
        if self.bindJoint:
            bJoint.BindJoint(joint=self.nodes["target"])

        return
示例#6
0
    def install(self):
        
        cmds.group(name=self.moduleGrp, empty=True)
        cmds.parent(self.moduleGrp, self.deformerGroup)        
       
        #create fk and ik joints
        for i in range(0 , len(self.joints)):
            cmds.duplicate(self.nodes['joint_%02d' %(i+1)], parentOnly=True, name=self.nodes['fkJoint_%02d' %(i+1)])[0]
            cmds.duplicate(self.nodes['joint_%02d' %(i+1)], parentOnly=True, name=self.nodes['ikJoint_%02d' %(i+1)])[0]
            if i != 0:
                cmds.parent(self.nodes['fkJoint_%02d' %(i+1)], self.nodes['fkJoint_%02d' %i])
                cmds.parent(self.nodes['ikJoint_%02d' %(i+1)], self.nodes['ikJoint_%02d' %i])

        #ik setup
        footIkHandle, footIkHandleEffector = cmds.ikHandle(sj=self.nodes['ikJoint_01'], ee=self.nodes['ikJoint_03'], sol='ikRPsolver', name=self.prefix + "_foot_ikHandle")
        cmds.rename(footIkHandleEffector, self.prefix + "_foot_ikEffector")

        ballIkHandle, ballIkHandleEffector = cmds.ikHandle(sj=self.nodes['ikJoint_03'], ee=self.nodes['ikJoint_04'], sol='ikRPsolver', name=self.prefix + "_ball_ikHandle")   
        cmds.rename(ballIkHandleEffector, self.prefix + "_ball_ikEffector")

        toeIkHandle, toeIkHandleEffector = cmds.ikHandle(sj=self.nodes['ikJoint_04'], ee=self.nodes['ikJoint_05'], sol='ikRPsolver', name=self.prefix + "_toe_ikHandle")     
        cmds.rename(toeIkHandleEffector, self.prefix + "_ball_ikEffector")
        #=======================================================================
        # NO FLIP IK
        #=======================================================================
        poleVector = cmds.spaceLocator(name=self.prefix + "_poleVector")[0]
        poleVectorPos = cmds.xform(self.nodes['joint_01'], q=True, ws=True, translation=True)
        cmds.xform(poleVector, ws=True, translation=[0, poleVectorPos[1], poleVectorPos[2]])
 
        if poleVectorPos[0] > 0: # left
            defaultOffset = -90
        else:
            defaultOffset = 90
        
        twistAttr = self.prefix + "_kneeTwist"
        twistOffsetAttr = self.prefix + "_kneeTwistOffset"
        cmds.addAttr(self.customAttribute, at='double', ln=twistAttr, k=True)
        cmds.addAttr(self.customAttribute, at='double', ln=twistOffsetAttr, k=True, dv=defaultOffset)
        
        cmds.poleVectorConstraint(poleVector, footIkHandle)
        addNode = cmds.createNode('addDoubleLinear', name=self.prefix + "_ikTwist_addDoubleLinear")

        cmds.connectAttr(self.customAttribute + "." + twistAttr, addNode + ".input1")
        cmds.connectAttr(self.customAttribute + "." + twistOffsetAttr, addNode + ".input2")
        cmds.connectAttr(addNode+".output", footIkHandle + ".twist")

        cmds.setAttr(footIkHandle + ".visibility", 0)
        cmds.setAttr(ballIkHandle + ".visibility", 0)
        cmds.setAttr(toeIkHandle + ".visibility", 0)
        cmds.setAttr(poleVector + ".visibility", 0)
        
        #=======================================================================
        # FOOT ROLL
        #=======================================================================
        footRollGrp = utils_transforms.createZeroGroup(footIkHandle, name=self.prefix + "_roll_grp")

        heelRollGrp = self.createRollGrp(parent=footRollGrp, pivot=self.nodes['joint_03'] , name=self.prefix + "_heelRoll")        
        toeRollGrp = self.createRollGrp(parent=heelRollGrp,  pivot=self.nodes['joint_05'] ,name=self.prefix + "_toeRoll")                         
        ballRollGrp = self.createRollGrp(parent=toeRollGrp, pivot=self.nodes['joint_04'] , name=self.prefix + "_ballRoll")
        toeWiggleGrp = self.createRollGrp(parent=toeRollGrp, pivot=self.nodes['joint_04'] , name=self.prefix + "_toeWiggle")

        cmds.addAttr(self.customAttribute, at='double', ln=self.prefix + "_ballRoll", k=True)
        cmds.addAttr(self.customAttribute, at='double', ln=self.prefix + "_toeRoll", k=True)
        cmds.addAttr(self.customAttribute, at='double', ln=self.prefix + "_heelRoll", k=True)
        cmds.addAttr(self.customAttribute, at='double', ln=self.prefix + "_toeWiggle", k=True)
        
        cmds.connectAttr(self.customAttribute + "." + self.prefix + "_ballRoll", ballRollGrp + ".rotateX")
        cmds.connectAttr(self.customAttribute + "." + self.prefix + "_toeRoll", toeRollGrp + ".rotateX")
        cmds.connectAttr(self.customAttribute + "." + self.prefix + "_heelRoll", heelRollGrp + ".rotateX")
        cmds.connectAttr(self.customAttribute + "." + self.prefix + "_toeWiggle", toeWiggleGrp + ".rotateX")
        
        cmds.parent(ballIkHandle, toeRollGrp, absolute=True)
        cmds.parent(footIkHandle, ballRollGrp, absolute=True)
        cmds.parent(toeIkHandle, toeWiggleGrp, absolute=True)
        
        #=======================================================================
        # CONTROL 
        #=======================================================================
        #create ik and fk controls
        control.Control(target=self.nodes['fkJoint_01'], name=self.nodes['fkControl_01'], controlShape='disc')
        control.Control(target=self.nodes['fkJoint_02'], name=self.nodes['fkControl_02'], controlShape='disc')
        control.Control(target=self.nodes['fkJoint_03'], name=self.nodes['fkControl_03'], controlShape='disc')
        control.Control(target=self.nodes['fkJoint_04'], name=self.nodes['fkControl_04'], controlShape='disc')
        control.Control(target=self.nodes['fkJoint_05'], name=self.nodes['fkControl_05'], controlShape='disc')
                
        control.Control(target=self.nodes['ikJoint_01'], name=self.nodes['ikControl_01'], controlShape='cube', lod=2)
        control.Control(target=footRollGrp, name=self.nodes['ikControl_02'], controlShape='cube')
        control.Control(target=poleVector, name=self.nodes['pvControl'], controlShape='locator')
        
        #parenting
        cmds.parent(footRollGrp, self.moduleGrp, absolute=True)
        cmds.parent(poleVector, self.moduleGrp, absolute=True)
        
        #hide controls
        cmds.setAttr(self.nodes['fkControl_05'] + ".visibility", 0)
        cmds.setAttr(self.nodes['pvControl'] + ".visibility", 0)
        
        
        #=======================================================================
        # SWITCH
        #=======================================================================
        attrName = self.infos['switchAttribute']
        
        cmds.addAttr(self.customAttribute, at='enum', enumName = 'ik:fk', ln=attrName, k=True)
        
        reverseNode = cmds.createNode('reverse', name=attrName+'_vis_reverse')
        cmds.connectAttr(self.customAttribute+"."+attrName, reverseNode+".inputX")
        
        for ikNode in ['ikJoint_01', 'ikJoint_02', 'ikJoint_03', 'ikJoint_04', 'ikJoint_05', 'ikControl_01', 'ikControl_02']:
            cmds.connectAttr(reverseNode + ".outputX", self.nodes[ikNode] + ".visibility")
        
        for fkNode in ['fkJoint_01', 'fkJoint_02', 'fkJoint_03', 'fkJoint_04', 'fkJoint_05', 'fkControl_01', 'fkControl_02', 'fkControl_03', 'fkControl_04']:
            cmds.connectAttr(self.customAttribute+"."+attrName, self.nodes[fkNode] + ".visibility")
            
        #choices
        for joint, ikJoint, fkJoint in zip(['joint_01', 'joint_02', 'joint_03', 'joint_04', 'joint_05'], ['ikJoint_01', 'ikJoint_02', 'ikJoint_03', 'ikJoint_04', 'ikJoint_05'], ['fkJoint_01', 'fkJoint_02', 'fkJoint_03', 'fkJoint_04', 'fkJoint_05']):
            
            rotateChoice = cmds.createNode('choice', name=self.prefix + "_rotate_choice")
            translateChoice = cmds.createNode('choice', name=self.prefix + "_translate_choice")

            cmds.connectAttr(self.nodes[ikJoint]+".rotate", rotateChoice+".input[0]")
            cmds.connectAttr(self.nodes[fkJoint]+".rotate", rotateChoice+".input[1]")            
            cmds.connectAttr(rotateChoice+".output", self.nodes[joint]+".rotate")
            cmds.connectAttr(self.customAttribute+'.'+attrName, rotateChoice+'.selector')                    

            cmds.connectAttr(self.nodes[ikJoint]+".translate", translateChoice+".input[0]")
            cmds.connectAttr(self.nodes[fkJoint]+".translate", translateChoice+".input[1]")
            cmds.connectAttr(translateChoice+".output", self.nodes[joint]+".translate")
            cmds.connectAttr(self.customAttribute+'.'+attrName, translateChoice+'.selector')

        #=======================================================================
        # BIND JOINT
        #=======================================================================
        for joint in self.joints:
            bJoint.BindJoint(joint = joint)         
示例#7
0
    def install(self):
        cmds.group(name=self.moduleGrp, empty=True)
        cmds.parent(self.moduleGrp, self.deformerGroup)
        
        #create Ribbon geo        
        ribbon = cmds.nurbsPlane(ax=[0,1,0], w=5, lr=0.1, d=3, u=2, v=1, ch=False, name = (self.prefix + "_ribbon"))[0]
        ribbonShape = cmds.listRelatives(ribbon)[0]
        
        ribbonGeoGrp = cmds.group(ribbon, name=(self.prefix + "_ribbonGeo_grp"))
        cmds.setAttr(ribbonGeoGrp+".visibility", 0) 

        #create start joint
        cmds.select(clear=True)
        
        startJoint = cmds.joint(name=self.prefix+"_ribbon_start_joint", p=[-2.5, 0, 0])
        startJointConst = utils_transforms.createZeroGroup(startJoint, name = startJoint.replace('_joint', '_const'))
        startJointAim = utils_transforms.createZeroGroup(startJoint, name = startJoint.replace('_joint', '_aim'))
        startJointTwist = utils_transforms.createZeroGroup(startJoint, name = startJoint.replace('_joint', '_twist'))
        cmds.setAttr(startJoint+".visibility", 0)

        #create end joint
        cmds.select(clear=True)
                        
        endJoint = cmds.joint(name=self.prefix+"_ribbon_end_joint", p=[2.5, 0 , 0])
        endJointConst = utils_transforms.createZeroGroup(endJoint, name = endJoint.replace('_joint', '_const'))
        endJointAim = utils_transforms.createZeroGroup(endJoint, name = endJoint.replace('_joint', '_aim'))
        endJointTwist = utils_transforms.createZeroGroup(endJoint, name = endJoint.replace('_joint', '_twist'))        
        cmds.setAttr(endJoint+".visibility", 0)        

        #create aim target
        aimTarget = cmds.spaceLocator(name=self.prefix+"_aimTarget")[0]
        aimTargetUp = cmds.duplicate(aimTarget, name = self.prefix+"_aimTargetUp")[0]
        cmds.parent(aimTargetUp, aimTarget)
        cmds.setAttr(aimTargetUp + ".translateY", 1)
        cmds.setAttr(aimTargetUp+".visibility", 0)             
        aimTargetConst = utils_transforms.createZeroGroup(aimTarget, name = aimTarget + "_const")
        cmds.pointConstraint(startJointConst, endJointConst, aimTargetConst, maintainOffset=False)

        startAimVector = [1,0,0]
        endAimVector = [-1,0,0]
        
        translate = cmds.xform(self.nodes['startNode'], q=True, ws=True, translation=True)
        if translate[0] < 0 : #mirrored joints
            startAimVector = [-1,0,0]
            endAimVector = [1,0,0]        
        

        startJointAim = cmds.aimConstraint(aimTarget, startJointAim, aimVector = startAimVector , upVector=[0,1,0],  worldUpType="object", worldUpObject = aimTargetUp, maintainOffset=False)
        endJointAim = cmds.aimConstraint(aimTarget, endJointAim, aimVector = endAimVector, upVector=[0,1,0],  worldUpType="object", worldUpObject = aimTargetUp, maintainOffset=False)

        #binding base ribbon
        cmds.skinCluster([startJoint, endJoint, ribbon])

        #create ribbon joints
        ribbonJointInfo = self.createRibbonJoint(ribbonShape, self.prefix, self.jointCount, startAimVector)
        ribbonJointGrp = cmds.group(ribbonJointInfo[0], n=(self.prefix + "_ribbonJoint_grp"))
        
        #position to nodes
        cmds.pointConstraint(self.nodes['startNode'], startJointConst, maintainOffset=False)
        cmds.pointConstraint(self.nodes['endNode'], endJointConst, maintainOffset=False)        
        
        #twist
        if self.rootTwist:
            cmds.orientConstraint(self.nodes['startNode'], startJointTwist, skip=['y', 'z'], maintainOffset=False)
            
        if self.endTwist:
            cmds.orientConstraint(self.nodes['endNode'], endJointTwist, skip=['y', 'z'], maintainOffset=False)                   

        cmds.orientConstraint(self.nodes['startNode'], aimTargetConst, maintainOffset=False)

        #parent to module
        cmds.parent(startJointConst, endJointConst, aimTargetConst, ribbonJointGrp, ribbonGeoGrp, self.moduleGrp)        

        #create bind joints
        for j in ribbonJointInfo[1]:
            bJoint.BindJoint(joint=j)
        
        #create control    
        #control.Control(target=aimTarget, name=aimTarget+"_ctrl", controlShape='disc', lod=2)
                              
        return