Esempio n. 1
0
    def __init__( self, node ):
        super( Spaces, self ).__init__()

        # If node == spaceAttrNode
        if cmds.objExists( '%s.spaceNode' % node):
            self.spaceNode = cmds.getAttr( '%s.spaceNode' % node )
        # If node == spaceNode
        elif cmds.objExists( '%s.spaceGrp' % node ) and cmds.objExists( '%s.spaceAttrNode' % node ) and cmds.objExists( '%s.spaceConstraint' % node ):
            self.spaceNode = node
        # Else
        else:
            raise RuntimeError, 'No "space" attributes found in: "%s"' % node

        # get variables
        self.spaceGrp        = attribute.getConnections('spaceGrp', self.spaceNode, plugs = False)[0]
        self.spaceAttrNode   = attribute.getConnections('spaceAttrNode', self.spaceNode, plugs = False)[0]
        self.spaceConstraint = attribute.getConnections('spaceConstraint', self.spaceNode, plugs = False)[0]
Esempio n. 2
0
File: rig.py Progetto: jonntd/japeto
    def getJoints(cls, asset):
        """
        Get joints based on whether or not the given asset has
        a tag_joints attribute.

        .. warning: This is probably going to change because it's unstable to change.
        
        .. todo: get this working with just an attribute connected to all the deform joints
        
        :param asset: Asset you want to get controls from
        :type asset: str
        
        :return: Returns controls on the given asset
        :rtype: list | None
        """
        # if the attribute is valid then get connections and return
        jointAttr = "%s.displayJnts" % asset
        if common.isValid(jointAttr):
            joints = attribute.getConnections(jointAttr, plugs=False)
            if joints:
                return joints
        # if there is no "displayJnts" attribute, we check for a puppet node
        # in the scene. If there is one, we will check connections to that and
        # traverse through the connections until we get to the joints
        if cmds.ls(type="puppet"):
            puppet = cmds.ls(type="puppet")
            joints = list()
            if puppet:
                for node in attribute.getConnections("%s.puppet_nodes" % puppet[0], plugs=False):
                    jointAttr = "%s.displayAxis" % node
                    # get the connections to the "displayAxis" attribute on the node
                    # and if there is a connection, it should be the "masterGuide" control.
                    if common.isValid(jointAttr):
                        masterGuides = attribute.getConnections(jointAttr, plugs=False)
                        # get the connections to the masterGuide control, which should contain the joints
                        if masterGuides:
                            for guide in masterGuides:
                                jnts = attribute.getConnections(jointAttr.replace(node, guide), plugs=False)
                                # removes the node from the jnts list, since it is
                                # connected to the "displayAxis" attribute
                                if node in jnts:
                                    jnts.pop(jnts.index(node))
                                joints.extend(jnts)
                return joints

        return None
Esempio n. 3
0
 def getGuides(self):
     '''
     Grabs the guides from the guides group created from the setup process
     '''
     guides = list()
     guideAttrs = attribute.getConnections('tag_guides', self.setupRigGrp)
     if guideAttrs:
         for attr in guideAttrs:
             guides.append(attr.split('.')[0])
     return guides
Esempio n. 4
0
File: rig.py Progetto: jonntd/japeto
    def getControls(cls, asset):
        """
        Get controls based on whether or not the given asset has
        a tag_controls attribute.
        
        :param asset: Asset you want to get controls from
        :type asset: str
        
        :return: Returns controls on the given asset
        :rtype: list | None
        """
        controlAttr = "%s.tag_controls" % asset

        if common.isValid(controlAttr):
            return attribute.getConnections(controlAttr, plugs=False)
        # end if

        return None
Esempio n. 5
0
File: rig.py Progetto: jonntd/japeto
    def build(self):
        """
        build rig hierarchy and attach components
        """
        # if there is no rig node in the scene, we will run the setup first
        if not cmds.ls(type="rig"):
            self.preBuild()
            self.run()

        for node in self.nodes():
            if not isinstance(node, component.Component):
                continue

            if not common.isValid(node.rigGrp):
                node.runRig()

            trsChildren = cmds.listRelatives(self._trsCtrl, c=True)
            if node.controlsGrp in trsChildren:
                continue
            cmds.parent(node.controlsGrp, self._trsCtrl)
            cmds.parent(node.jointsGrp, self.jointsGrp)
            for attr in ["displayJnts", "jointVis"]:
                fullAttrPath = "%s.%s" % (self.rigGrp, attr)
                componentAttr = "%s.%s" % (node.rigGrp, attr)
                if cmds.objExists(componentAttr):
                    if not cmds.objExists(fullAttrPath):
                        attribute.copy(attr, node.rigGrp, self.rigGrp, reverseConnect=False)
                    # end if

                    connectedAttrs = attribute.getConnections(attr, node.rigGrp, incoming=False)
                    if connectedAttrs:
                        for connectedAttr in connectedAttrs:
                            cmds.disconnectAttr(componentAttr, connectedAttr)
                            attribute.connect(fullAttrPath, connectedAttr)
                        # end for
                    # end if
                # end if
            # end for
            cmds.delete(node.rigGrp)
Esempio n. 6
0
    def rig(self):
        if not self._puppetNode:
            self.runSetupRig()
        if cmds.objExists('%s.master_guide' % self.setupRigGrp):
            self.masterGuide = attribute.getConnections('master_guide', self.setupRigGrp)[0].split('.')[0]
        if common.isValid(self.masterGuide):
            #get orientations for controls
            fkOrient  = self.__fkOrient()
            ikOrient  = self.__ikOrient()
            upVector  = self.upVector
            aimVector = self.aimVector

        #call parent class rig function
        if super(Limb, self).rig():
            return True
        
        #create ik fk switch
        ikfkDict = ikfk.create(jointChain = [self.startJoint, self.midJoint, self.tipJoint], stretch = self.stretch)
        ikfkDict['group'] = cmds.rename(ikfkDict['group'], '%s_%s' % (self.name(),ikfkDict['group']))

        #set the visibility on the ik/fk/blend joints to off
        cmds.setAttr('%s.v' % ikfkDict['fkJoints'][0], 0)
        cmds.setAttr('%s.v' % ikfkDict['ikJoints'][0], 0)
        cmds.setAttr('%s.v' % ikfkDict['blendJoints'][0], 0)

        ikfkAttr = attribute.addAttr(self.rigGrp, attr = 'ikfk', attrType = 'enum', defValue = ['off','on'],value = 0)

        cmds.connectAttr(ikfkAttr, '%s.ikfk' % ikfkDict['group'], l = True, f = True)

        #parent ikfk group under joints group
        cmds.parent(ikfkDict['group'], self.jointsGrp)

        #rename all ik and blend joints
        for i,jnt in enumerate(ikfkDict['ikJoints']):
            jnt = cmds.rename(jnt, jnt.replace('%s_%s_%s' % (common.SKINCLUSTER,common.JOINT, common.IK), '%s_%s' % (common.IK, common.JOINT)))
            ikfkDict['ikJoints'][i] = jnt

        for i,jnt in enumerate(ikfkDict['blendJoints']):
            jnt = cmds.rename(jnt, jnt.replace('%s_%s_%s' % (common.SKINCLUSTER,common.JOINT, common.BLEND), '%s_%s' % (common.BLEND, common.JOINT)))
            ikfkDict['blendJoints'][i] = jnt

        #create ik setup
        ikCtrl = control.create(name = ikfkDict['ikJoints'][2].replace('_%s' % common.JOINT, ''),type = 'cube', parent = self.controlsGrp, color = common.SIDE_COLOR[self._getSide()])
        ikCtrlZero = common.getParent(ikCtrl)
        attribute.copy('stretch', ikfkDict['group'], destination = ikCtrl, connect = True,reverseConnect = False)
        attribute.copy('stretchTop', ikfkDict['group'], destination = ikCtrl, connect = True,reverseConnect = False)
        attribute.copy('stretchBottom', ikfkDict['group'], destination = ikCtrl, connect = True,reverseConnect = False)

        if ikOrient == 'Local':
            transform.matchXform(ikfkDict['ikJoints'][2], ikCtrlZero, type = 'pose')
        else:
            transform.matchXform(ikfkDict['ikJoints'][2], ikCtrlZero, type = 'position')
            cmds.orientConstraint(ikCtrl, ikfkDict['ikJoints'][2], mo = True)
            common.setColor(ikCtrl, common.SIDE_COLOR[self._getSide()])

            #setup poleVector
            pvCtrl = control.create(name = ikfkDict['ikJoints'][2].replace('_%s' % common.JOINT, '_%s' % common.POLEVECTOR),type = 'cube', parent = self.controlsGrp, color = common.SIDE_COLOR[self._getSide()])
            #size polevector control

        for i in range(len(common.getShapes(pvCtrl))):
            control.scaleShape(pvCtrl, scale = [self.controlScale * .5, self.controlScale * .5, self.controlScale * .5], index = i)

        pvCtrlZero = common.getParent(pvCtrl)
        pvDisplayLineAttr = attribute.addAttr(pvCtrl, attr = 'pvLine', attrType = 'enum', defValue = 'off:on', value = 1)
        transform.matchXform(ikfkDict['ikJoints'][1], pvCtrlZero, type = 'position')
        #cmds.parent(ikfkDict['ikHandle'], w = True)
        pvPos = ikfk.getPoleVectorPosition(ikfkDict['ikJoints'][1], ikfkDict['ikHandle'])
        cmds.xform(pvCtrlZero, ws = True, t = pvPos)
        common.setColor(pvCtrlZero, common.SIDE_COLOR[self._getSide()])

        #create polevector constraint and parent under control
        cmds.poleVectorConstraint(pvCtrl, ikfkDict['ikHandle'])
        targetConstraint = cmds.pointConstraint(ikCtrl, ikfkDict['targetJnts'][1], mo = True) #ikhandle is under target joint
        pvDisplayLine = control.displayLine(ikfkDict['ikJoints'][0], pvCtrl, name = pvCtrl.replace(common.CONTROL, common.DISPLAYLINE), parent = self.controlsGrp)


        cmds.orientConstraint(ikCtrl,ikfkDict['ikJoints'][0], mo = True)

        #adding attribute to ik ctrl
        ikTwistAttr = attribute.addAttr(ikCtrl, attr = 'twist')
        cmds.connectAttr(ikTwistAttr, '%s.twist' % ikfkDict['ikHandle'], f = True)

        #connecting to shapes
        ikfkReverse = cmds.createNode('reverse', n = ikCtrl.replace('%s_%s' % (common.IK, common.CONTROL), '%s_%s' % (common.REVERSE, common.UTILITY)))
        attribute.connect('%s.ikfk' % ikfkDict['group'], '%s.inputX' % ikfkReverse)
        for shape in common.getShapes(ikCtrl):
            attribute.connect('%s.outputX' % ikfkReverse,'%s.v' % shape)

        for shape in common.getShapes(pvCtrl):
            attribute.connect('%s.outputX' % ikfkReverse,'%s.v' % shape)

        #connect pvDisplayLineAttr in pvDisplayLine visibility
        displayLineMultiply = cmds.createNode('multiplyDivide', n = pvDisplayLine.replace(common.DISPLAYLINE, common.MULTIPLYDIVIDE))
        attribute.connect(pvDisplayLineAttr, '%s.input1X' % displayLineMultiply)
        attribute.connect('%s.outputX' % ikfkReverse, '%s.input2X' % displayLineMultiply)
        attribute.connect('%s.outputX' % displayLineMultiply, '%s.v' % common.getChildren(pvDisplayLine)[0])

        #create fk setup
        fkCtrls = list()
        parent = self.controlsGrp
        for i,jnt in enumerate(ikfkDict['fkJoints']):
            cmds.select(cl = True)
            #rename fk joint
            jnt = cmds.rename(jnt,jnt.replace('%s_%s_%s' % (common.SKINCLUSTER,common.JOINT,common.FK), '%s_%s' % (common.FK,common.JOINT)))
            ikfkDict['fkJoints'][i] = jnt #re-assign fk joint intop ikfkDict
            #create controls, set color, and make connections
            fkCtrl = control.create(name = jnt.replace('_%s' % common.JOINT, ''),type = 'circle', parent = parent, color = common.SIDE_COLOR[self._getSide()])
            fkCtrlZero = common.getParent(fkCtrl)
            
            if fkOrient == 'Local':
                transform.matchXform(jnt, fkCtrlZero, type = 'pose')
            #end if
            else:
                transform.matchXform(jnt, fkCtrlZero, type = 'position')
            #end else
            
            cmds.connectAttr('%s.ikfk' % ikfkDict['group'], '%s.v' % common.getShapes(fkCtrl)[0], f = True)
            cmds.parentConstraint(fkCtrl, jnt, mo = True)
            attribute.lockAndHide('t', fkCtrl)
            attribute.lockAndHide('s', fkCtrl)
            attribute.lockAndHide('v', fkCtrl)
            #get joint rotate order and apply to control and parent group
            rotateOrder = attribute.getValue('rotateOrder', jnt)
            for node in [fkCtrl, fkCtrlZero]:
                cmds.setAttr('%s.rotateOrder' % node, rotateOrder)
    
                fkCtrls.append(fkCtrl)
                parent = fkCtrl
            #end loop
        #end loop

        aimAxis = transform.getAimAxis(ikfkDict['blendJoints'][0], allowNegative = False)    
        #Up Twist Joint Setup
        if self.upTwistJnts:
            noTwistJnt = common.duplicate(self.startJoint, name = self.startJoint.replace('%s' % common.SKINCLUSTER, 'NoTwist_%s' % common.SKINCLUSTER), parent = self.startJoint)

            inverseMultNode = cmds.createNode('multiplyDivide', n = noTwistJnt.replace('%s_%s' % (common.SKINCLUSTER,common.JOINT), '%s_%s' % (common.UTILITY, common.MULTIPLYDIVIDE)))
            cmds.connectAttr('%s.r%s' % (ikfkDict['blendJoints'][0], aimAxis), '%s.input1X' % inverseMultNode, f = True)
            cmds.setAttr('%s.input2X' % inverseMultNode, -1)
            cmds.connectAttr('%s.outputX' % inverseMultNode, '%s.r%s' % (noTwistJnt, aimAxis), f = True)


            step   = 1.0 / (len(self.upTwistJnts) +1)
            for i in range( 1, (len(self.upTwistJnts)+1) ):
                twsitMultNode = cmds.createNode('multiplyDivide', n = self.upTwistJnts[i - 1].replace('%s_%s' % (common.SKINCLUSTER,common.JOINT), '%s_%s' % (common.UTILITY, common.MULTIPLYDIVIDE)))
                cmds.connectAttr('%s.r%s' % (ikfkDict['blendJoints'][0], aimAxis), '%s.input1X' % twsitMultNode, f = True)
                cmds.setAttr('%s.input2X' % twsitMultNode, -(1-(step*i))  )
                cmds.connectAttr('%s.outputX' % twsitMultNode, '%s.r%s' % (self.upTwistJnts[i -1], aimAxis),f = True)
            #end loop

            self.upTwistJnts.insert(0, noTwistJnt)
        #end if

        if self.loTwistJnts:
            twistJnt = common.duplicate(self.midJoint,name = self.midJoint.replace('%s' % common.SKINCLUSTER, 'loTwist_%s' % common.SKINCLUSTER), parent = self.midJoint)
            constraint = cmds.aimConstraint(ikfkDict['blendJoints'][2],twistJnt,aimVector =  aimVector, upVector  = upVector,  worldUpType ="objectrotation", worldUpVector = upVector, worldUpObject = self.tipJoint)
            cmds.setAttr('%s.v' % twistJnt, 0)
        #end if

        step   = 1.0 / (len(self.loTwistJnts) +1)
        for i in range( 1, (len(self.loTwistJnts)+1) ):
            twsitMultNode = cmds.createNode('multiplyDivide', n = self.loTwistJnts[i - 1].replace('%s_%s' % (common.SKINCLUSTER,common.JOINT), '%s_%s' % (common.UTILITY, common.MULTIPLYDIVIDE)))
            cmds.connectAttr('%s.r%s' % (ikfkDict['blendJoints'][2], aimAxis), '%s.input1X' % twsitMultNode, f = True)
            cmds.setAttr('%s.input2X' % twsitMultNode, 1-(step*i) )
            cmds.connectAttr('%s.outputX' % twsitMultNode, '%s.r%s' % (self.loTwistJnts[i -1], aimAxis),f = True)
        #end loop

        #------------------------
        #Add to class variables
        #------------------------
        #assign joints to the joints list
        self.joints = {'ik' : ikfkDict['ikJoints'], 'fk' : ikfkDict['fkJoints'], 'blend' : ikfkDict['blendJoints'], 'target' : ikfkDict['targetJnts']}
        #assign controls to the controls list
        #assign fkCtrls into the controls dictionary 
        self.controls = {'ik' : [ikCtrl, pvCtrl],'fk' : fkCtrls }
        self.ikfkGroup = ikfkDict['group']
        #assign hooks
        self.hookRoot = [ikfkDict['ikJoints'][0], common.getParent(fkCtrls[0]), ikCtrl, ikfkDict['targetJnts'][-1]]
        self.hookPoint = [ikfkDict['blendJoints'][-1]]
        #add no twist joint to the skincluster list
        self.skinClusterJnts.append(noTwistJnt)