Beispiel #1
0
 def mirror(self, side=common.LEFT):
     """
     This will mirror across from side given to the opposite side
     
     :see: japeto.libs.joint.mirror
     
     :param side: Side to use to mirror from
     :type side: str
     """
     if side == common.LEFT:
         for node in self.nodes():
             if not isinstance(node, component.Component):
                 continue
             if node._getSide() == side:
                 guides = node.getGuides()
                 guides.insert(0, node.masterGuide)
                 for guide in guides:
                     description = common.getDescription(guide)
                     joint.mirror(guide, "%s_%s" % (common.LEFT, description), "%s_%s" % (common.RIGHT, description))
     elif side == common.RIGHT:
         for node in self.nodes():
             if not isinstance(node, component.Component):
                 continue
             if node._getSide() == side:
                 guides = node.getGuides()
                 guides.insert(0, node.masterGuide)
                 for guide in guides:
                     description = common.getDescription(guide)
                     joint.mirror(guide, "%s_%s" % (common.RIGHT, description), "%s_%s" % (common.LEFT, description))
Beispiel #2
0
    def initialize(self,**kwargs):
        super(Chain,self).initialize(**kwargs)
        
        self.addArgument('numJoints', 2, 2)
        self.addArgument('stretch', True, 3)
        
        self.addArgument('startJoint',
                '%s_start%s_%s_%s' % (self._getPrefix(),
                common.getDescription(self.name()),
                common.SKINCLUSTER,
                common.JOINT), 5)

        self.addArgument('endJoint',
                '%s_end%s_%s_%s' % (self._getPrefix(),
                common.getDescription(self.name()),
                common.SKINCLUSTER,
                common.JOINT), 6)
Beispiel #3
0
 def _ikControlSetup(self, drivers):
     '''
     Takes driver joints that drive the IK spine and create controls for them
     
     @param drivers: list of drivers you want to put controls on
     @type drivers: *list* or *tuple* or *str* 
     
     @return: IK controls which were created to drive the driver joints passed in
     @rtype: *list*
     '''
     #create an empty list to store ik controls in so we can return them
     ikControls = list()
     
     drivers = common.toList(drivers)
     
     for i,driver in enumerate(drivers):
         nameDescription = common.getDescription(driver)
         ctrlName = '%s_%s_%s' % (self._getSide(),nameDescription,common.IK)
         ctrl = control.create(ctrlName, type = 'cube',
                               parent = self.controlsGrp,
                               color = common.SIDE_COLOR[self._getSide()])
         ctrlZero = common.getParent(ctrl)
         #driverParent = common.getParent(driver)
         #move control in to position of driver jnt
         transform.matchXform(driver, ctrlZero, 'pose')
         #cmds.parent(ctrlZero, driverParent)
         #cmds.parent(driver, ctrl)
         cmds.parentConstraint(ctrl, driver,mo = True)
         
         
         #connect ik/fk attr from group to  visibility of shapes
         reverse = cmds.createNode('reverse', n = '%s_%s_%s' % (self.name(),
                                                             common.IK,
                                                             common.REVERSE
                                                             ))
         attribute.connect('%s.ikfk' % self.ikFkGroup,'%s.inputX' % reverse)
         for shape in common.getShapes(ctrl):
             if self.ikFkGroup:
                 attribute.connect('%s.outputX' % reverse,
                                   '%s.v' % shape)
             #end if
         #end loop
         
         ikControls.append(ctrl)
         
         
         
     #end loop
         
     return ikControls
     
Beispiel #4
0
    def setupRig(self):
        if super(Chain, self).setupRig():
            return True
        
        self.skinClusterJnts = [self.startJoint, self.endJoint]
                
        if self._getSide() == common.LEFT:
            positions = (
            [self.position[0] + 2, self.position[1], self.position[2]],
            [self.position[0] + 9, self.position[1], self.position[2]]
            )
            
            aimCtrlPosition = [positions[0][0],
                    positions[0][1] + 5,
                    positions[0][2]]
        #end if    
        elif self._getSide() == common.RIGHT:
            positions = (
            [self.position[0] - 2, self.position[1], self.position[2]],
            [self.position[0] - 9, self.position[1], self.position[2]]
            )
            
            aimCtrlPosition = [positions[0][0],
                    positions[0][1] + 5,
                    positions[0][2]]
        #end elif    
            
        else:
            positions = (
            [self.position[0], self.position[1], self.position[2]],
            [self.position[0], self.position[1] + 9, self.position[2]]
            )
            
            aimCtrlPosition = [positions[0][0],
                    positions[0][1],
                    positions[0][2] + 5]
        #end elif
        for i,jnt in enumerate(self.skinClusterJnts):
            if not common.isValid(jnt):
                cmds.joint(n = jnt,position = positions[i])
            
            if i == 0:
                cmds.parent(jnt, self.skeletonGrp)
                #place Master Guide control in the same position
                #  as the first joint
                transform.matchXform(jnt,
                        common.getParent(self.masterGuide),
                        type = 'position')
            else:
                cmds.parent(jnt, self.skinClusterJnts[i - 1])
            #end if/else
                
            ctrl = self.setupCtrl(jnt.replace('_%s' % common.JOINT, ''),jnt)
            #create template control
            #control.createTemplate(ctrl)
            cmds.select(cl = True)
        #end loop
        

        # ----------------------------------------------------------------------
        # CREATE GUIDES
        startJointGuide = self.startJoint.replace(common.JOINT, common.GUIDES)
        endJointGuide   = self.endJoint.replace(common.JOINT, common.GUIDES)



        # ----------------------------------------------------------------------
        # ORIENTATION 
        #
        if self._getSide() == common.RIGHT:
            aimVectorAttr = attribute.switch ('aimVector',
                    node= self.masterGuide,
                    value=4,
                    choices=['x','y','z','-x','-y','-z'],
                    outputs=[(1,0,0),(0,1,0),(0,0,1),(-1,0,0),(0,-1,0),(0,0,-1)])
            upVectorAttr  = attribute.switch ('upVector',
                    node=self.masterGuide,
                    value=3,
                    choices=['x','y','z','-x','-y','-z'],
                    outputs=[(1,0,0),(0,1,0),(0,0,1),(-1,0,0),(0,-1,0),(0,0,-1)])
        else:
            aimVectorAttr = attribute.switch ('aimVector',
                    node=self.masterGuide,
                    value=1,
                    choices=['x','y','z','-x','-y','-z'],
                    outputs=[(1,0,0),(0,1,0),(0,0,1),(-1,0,0),(0,-1,0),(0,0,-1)])

            upVectorAttr  = attribute.switch ('upVector',
                    node=self.masterGuide,
                    value=3,
                    choices=['x','y','z','-x','-y','-z'],
                    outputs=[(1,0,0),(0,1,0),(0,0,1),(-1,0,0),(0,-1,0),(0,0,-1)])
        
        #create in-between joints and guides and make connections 
        step   = 1.0 / (self.numJoints - 1)
        parent = self.startJoint
        for i in range( 1, self.numJoints - 1 ):
            j = '%s_%s_%s_%s_%s' % (self._getPrefix(),
                    common.getDescription(self.name()),
                    common.padNumber(i,3),
                    common.SKINCLUSTER,
                    common.JOINT)
            if not common.isValid(j):
                joint.create( name= j)

            transform.matchXform( self.startJoint,j, type='rotate' )
            ctrl = self.setupCtrl(j.replace('_%s' % common.JOINT, ''),j)
            ctrlParent = common.getParent(ctrl)
            #create point constraint and figure out percentage for position
            constraint = cmds.pointConstraint( self.startJoint,
                    endJointGuide, ctrlParent )[0]

            weightAliasList = cmds.pointConstraint( constraint,
                    q=True,
                    weightAliasList=True)

            cmds.setAttr( '%s.%s' % (constraint, weightAliasList[0]), 1-(step*i) )
            cmds.setAttr( '%s.%s' % (constraint, weightAliasList[1]),  step*i )

            #adding the joint to skincluster joints list
            self.skinClusterJnts.insert(-1, j)
            relatives = cmds.listRelatives(j, p = True)
            if not relatives:
                cmds.parent(j, parent)
            parent = j

            if i == self.numJoints - 2:
                cmds.parent(self.endJoint, j)
                constraint = cmds.orientConstraint(j, self.endJoint)[0]
                #add constraints to setup constraint list
                self._addSetupConstraints(constraint)


        #create aim control
        aimLocator = self._createAimLocator(aimCtrlPosition,
                color = common.SIDE_COLOR_SECONDARY[self._getSide()])
        
        #create aim constraints
        for i, jnt in enumerate(self.skinClusterJnts):
            if jnt == self.endJoint:
                break
            constraint = cmds.aimConstraint(
                    self.skinClusterJnts[i+1].replace('_%s' % common.JOINT, '_%s' % common.GUIDES),
                    jnt,
                    worldUpType = "object",
                    worldUpObject = aimLocator)[0]

            attribute.connect(aimVectorAttr, '%s.aimVector' % constraint)
            attribute.connect(upVectorAttr, '%s.upVector' % constraint)
            #add constraints to setup constraint list
            self._addSetupConstraints(constraint)