示例#1
0
 def createJoints(self):
     if not self.m_userJoints:
         self.m_bindJoints = []
         startPos = cmds.xform(self.m_parent1, q=1, t=1, ws=1)
         endPos = cmds.xform(self.m_parent2, q=1, t=1, ws=1)
         stepVec = vec.divide(
             vec.subtract(endPos, startPos), 
             self.m_numJoints - 1
             )
         currentPos = startPos
         for i in range(self.m_numJoints):
             newJoint = self.m_name+"_"+str(i)+"_BIND_JNT"
             newJoint = cmds.joint(n=newJoint, p=currentPos)
             cmds.setAttr("%s.radius" %(newJoint), 0.1)
             self.m_bindJoints.append(newJoint)
             currentPos = vec.add(currentPos, stepVec)
         #fix orientations
         cmds.joint(
             self.m_bindJoints[0], 
             e=1, 
             oj="xyz", 
             sao = "yup", 
             ch=1, 
             zso=1
             )
     else:
         # Duplicate joints and rename
         newJoints = cmds.duplicate(self.m_userJoints[0], rc=1)
         for i in range(len(newJoints)):
             newJoint = "%s_%d_BIND_JNT" %(self.m_name, i)
             newJoints[i] = cmds.rename(newJoints[i], newJoint)
         self.m_bindJoints = newJoints
     #Put it in the right group
     cmds.parent(self.m_bindJoints[0], self.m_group)
     rc.addToLayer(self.m_sceneData, "ref", self.m_bindJoints[0])
     #Strip sets
     for joint in self.m_bindJoints:
         rc.stripSets(joint)
     #Add all except first and last to bind set
     for joint in self.m_bindJoints[:-1]:
         rc.addToSet(self.m_sceneData, "bind", joint)
示例#2
0
    def createControls(self):
        #If no blend control is speified add one
        if not self.m_blendControl:
            self.m_blendControl = cmds.circle(n=self.m_name+"Blend_CTRL")[0]
            cmds.parent(self.m_blendControl, self.m_group)
            self.m_allControls.append(self.m_blendControl)
            rc.addToControlDict(
                self.m_allControls,
                "%s_StretchChainCtrl" %(self.m_baseName),
                self.m_blendControl
                )

        cmds.addAttr(
            self.m_blendControl,
            ln=self.m_attrHeading,
            k=True,
            at = "enum",
            en = "---------:"
            )

        if self.m_isAutoBend:
            cmds.addAttr(
                self.m_blendControl, 
                ln=self.m_blendAttrName, 
                k=1, min=0, max=1, dv=0
                )
            blendNodeAttr = self.m_blendControl+"."+self.m_blendAttrName
            oppBlendNodeAttr = rc.create1MinusNode(
                blendNodeAttr, 
                self.m_name+"OppBlend_CTRL" 
                )
        
        self.m_controls = []
        self.m_parentCtrls = []
        self.m_pointCtrls = []
        startPos = cmds.xform(self.m_parent1, q=1, t=1, ws=1)
        endPos = cmds.xform(self.m_parent2, q=1, t=1, ws=1)
        stepVec = vec.divide(
            vec.subtract(endPos, startPos), 
            self.m_numCtrls + 1
            )
        currentPos = vec.add(startPos, stepVec)
        for i in range(self.m_numCtrls):
            newCtrl = self.m_name+"_"+str(i)+"_CTRL"
            parentCtrl = self.m_name+"_"+str(i)+"_parent_CTRL"
            pointCtrl = self.m_name+"_"+str(i)+"_point_CTRL"
            
            newCtrl = cmds.spaceLocator(n=newCtrl)[0]
            self.m_controls.append(newCtrl)
            cmds.parent(newCtrl, self.m_group)
            cmds.xform(newCtrl, t=currentPos, ws=1)
            newCtrlGroups = rg.add3Groups(newCtrl, ["_SDK", "_CONST", "_0"])
            
            if self.m_isAutoBend:
                parentCtrl = cmds.duplicate(newCtrl, n=parentCtrl)[0]
                cmds.parent(parentCtrl, newCtrlGroups[2])
                #cmds.setAttr(parentCtrl+".visibility", 0)
                pointCtrl = cmds.duplicate(newCtrl, n=pointCtrl)[0]
                cmds.parent(pointCtrl, newCtrlGroups[2])
                #cmds.setAttr(pointCtrl+".visibility", 0)

                rc.addToLayer(self.m_sceneData, "hidden", [parentCtrl, pointCtrl])

                #Create blend between parent and point setups
                blendConst = cmds.pointConstraint(parentCtrl, newCtrlGroups[1])
                cmds.connectAttr(blendNodeAttr, blendConst[0]+"."+parentCtrl+"W0")
                blendConst = cmds.pointConstraint(pointCtrl, newCtrlGroups[1])
                cmds.connectAttr(oppBlendNodeAttr, blendConst[0]+"."+pointCtrl+"W1")
                
                
                self.m_parentCtrls.append(parentCtrl)
                self.m_pointCtrls.append(pointCtrl)
                
                grandParent = cmds.listRelatives(self.m_parent1, p=1)
                if grandParent == None or not self.m_isParentBend:
                    grandParent = self.m_parent1
                
                parentConst = rc.applyWeightedConstraint(
                    grandParent, 
                    parentCtrl, 
                    self.m_parent2, 
                    cmds.parentConstraint
                    )
                pointConst = rc.applyWeightedConstraint(
                    self.m_parent1, 
                    pointCtrl, 
                    self.m_parent2, 
                    cmds.pointConstraint
                    )
            cmds.aimConstraint(
                    self.m_parent2,
                    newCtrlGroups[1]
                    )
            currentPos = vec.add(currentPos, stepVec)
            #lock attrs
            cmds.setAttr(newCtrl+".rotate", l=1)
            cmds.setAttr(newCtrl+".scale", l=1)
        rc.addToLayer(self.m_sceneData, "detailCtrl", self.m_controls)
        # Add controls
        i=0
        for control in self.m_controls:
            rc.addToControlDict(self.m_allControls, "%s_%d_detail" %(self.m_baseName, i), control)
            i+=1