示例#1
0
文件: arm.py 项目: jonntd/japeto
	def setupRig(self):
		if super(Arm,self).setupRig():
			return True
		
		self.skinClusterJnts.remove(self.endJoint)
		self.skinClusterJnts.insert(0,self.clavicleJoint)
		
		#delete end joint and end guide
		endJntGuide = self.endJoint.replace(common.JOINT, common.GUIDES)
		if common.isValid(self.endJoint):
			cmds.delete(self.endJoint)
		if common.isValid(endJntGuide):
			cmds.delete(endJntGuide)
			

		if self._getSide() == common.LEFT:
			positions = (
				[self.position[0] + .5, self.position[1], self.position[2] + 1],
				[self.position[0] + 2, self.position[1], self.position[2]],
				[self.position[0] + 5, self.position[1], self.position[2] - 1],
				[self.position[0] + 8, self.position[1], self.position[2]]
				)
		elif self._getSide() == common.RIGHT:
			positions = (
				[self.position[0] + -.5, self.position[1], self.position[2] + 1],
				[self.position[0] - 2, self.position[1], self.position[2]],
				[self.position[0] - 5, self.position[1], self.position[2] - 1],
				[self.position[0] - 8, self.position[1], self.position[2]]
				)
		else:
			positions = (
				[self.position[0] + .5, self.position[1], self.position[2] + 1],
				[self.position[0] + 2, self.position[1], self.position[2]],
				[self.position[0] + 5, self.position[1], self.position[2] - 1],
				[self.position[0] + 8, self.position[1], self.position[2]]
				)


		#create pelvis joint and parent leg under pelvis
		if not common.isValid(self.clavicleJoint):
			joint.create(name = self.clavicleJoint, parent = self.skeletonGrp, position = positions[0])
		
		cmds.parent(self.startJoint, self.clavicleJoint)
		
		#declare guides
		clavicleJointGuide = self.setupCtrl(self.clavicleJoint.replace('_%s' % common.JOINT, ''),self.clavicleJoint)
		startJointGuide  = self.startJoint.replace(common.JOINT, common.GUIDES)
		midJointGuide    = self.midJoint.replace(common.JOINT, common.GUIDES)
		tipJointGuide    = self.tipJoint.replace(common.JOINT, common.GUIDES)
		
		#move master guide to clavicle position
		for i, guide in enumerate([clavicleJointGuide,startJointGuide,midJointGuide, tipJointGuide]):
			zeroGroup = common.getParent(guide)
			if i == 0:
				cmds.xform(common.getParent(self.masterGuide), ws = True, t = positions[i])
			cmds.xform(zeroGroup, ws = True, t = positions[i])
示例#2
0
文件: hand.py 项目: jonntd/japeto
    def setupRig(self):
        if super(Hand, self).setupRig():
            return True
        

        if self._getSide() == common.LEFT:
        #move master  guide into position
            cmds.xform(common.getParent(self.masterGuide), ws = True,
                       t = self.handPosition)

            for i,obj in enumerate(self.fingers):
                self.__fingers[obj] = finger.Finger('%s_%s' % (self._getPrefix(),
                                                               obj))
                self.__fingers[obj].initialize(numJoints = self.numJoints,
                                               position=[self.position[0] + 10,
                                                 self.position[1],
                                                 (self.position[2] + 2 )- i],
                                               parent = self.parent)
                self.__fingers[obj].setupRig()

                cmds.parentConstraint(self.masterGuide,
                            common.getParent(self.__fingers[obj].masterGuide),
                            mo = True)
                for guide in self.__fingers[obj].getGuides():
                    #tag the guide control with a tag_guides attribute
                    tagAttr = attribute.addAttr(guide, 'hand_guides',
                                                attrType = 'message')
                    attribute.connect('%s.tag_guides' % self.setupRigGrp,
                                      tagAttr)
                #end loop
            #end loop
        #end if

        elif self._getSide() == common.RIGHT:
        #move master  guide into position
            cmds.xform(common.getParent(self.masterGuide), ws = True, t = self.handPosition)

            for i,obj in enumerate(self.fingers):
                self.__fingers[obj] = finger.Finger('%s_%s' % (self._getPrefix(), obj))
                self.__fingers[obj].initialize(numJoints = self.numJoints, position = [self.position[0] - 10, self.position[1], (self.position[2] + 2 ) - i], parent = self.parent)
                self.__fingers[obj].setupRig()
            
                cmds.parentConstraint(self.masterGuide, common.getParent(self.__fingers[obj].masterGuide), mo = True)
        
                for guide in self.__fingers[obj].getGuides():
                    #tag the guide control with a tag_guides attribute
                    tagAttr = attribute.addAttr(guide, 'hand_guides', attrType = 'message')
                    attribute.connect('%s.tag_guides' % self.setupRigGrp, tagAttr)
                #end loop
            #end loop
        #end elif
        else:
        #move master  guide into position
            cmds.xform(common.getParent(self.masterGuide), ws = True, t = self.handPosition)

            for i,obj in enumerate(self.fingers):
                self.__fingers[obj] = finger.Finger('%s_%s' % (self._getPrefix(), obj))
                self.__fingers[obj].initialize(numJoints = self.numJoints, position = [self.position[0] - 10, self.position[1], (self.position[2] + 2 ) - i], parent = self.parent)
                self.__fingers[obj].setupRig()
            
                cmds.parentConstraint(self.masterGuide, common.getParent(self.__fingers[obj].masterGuide), mo = True)
        
                for guide in self.__fingers[obj].getGuides():
                    #tag the guide control with a tag_guides attribute
                    tagAttr = attribute.addAttr(guide, 'hand_guides', attrType = 'message')
                    attribute.connect('%s.tag_guides' % self.setupRigGrp, tagAttr)
                #end loop
            #end loop
        #end elif
        
        
        #create joint and guide
        if not common.isValid(self.handJoint):
            joint.create(self.handJoint, self.skeletonGrp, self.handPosition)
        if not common.isValid(self.handJoint.replace(common.JOINT,common.CONTROL)):
            self.setupCtrl(self.handGuide,self.handJoint, common.SIDE_COLOR[self._getSide()])
示例#3
0
文件: chain.py 项目: jonntd/japeto
    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)
示例#4
0
文件: limb.py 项目: jonntd/japeto
    def setupRig(self):
        if super(Limb,self).setupRig():
            return True

        self.skinClusterJnts = [ self.startJoint,
                                 self.midJoint,
                                 self.tipJoint,
                                 self.endJoint ]

        if self._getSide() == common.LEFT:
            positions = (
            [self.position[0] + 2, self.position[1], self.position[2]],
            [self.position[0] + 5, self.position[1], self.position[2] - 1],
            [self.position[0] + 8, self.position[1], self.position[2]],
                [self.position[0] + 9, self.position[1], self.position[2]]
            )
        elif self._getSide() == common.RIGHT:
            positions = (
            [self.position[0] - 2, self.position[1], self.position[2]],
            [self.position[0] - 5, self.position[1], self.position[2] - 1],
            [self.position[0] - 8, self.position[1], self.position[2]],
            [self.position[0] - 9, self.position[1], self.position[2]]
            )
        else:
            positions = (
            [self.position[0] - 2, self.position[1], self.position[2]],
            [self.position[0] - 5, self.position[1], self.position[2] - 1],
            [self.position[0] - 8, self.position[1], self.position[2]],
            [self.position[0] - 9, self.position[1], self.position[2]]
            )

        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])

            ctrl = self.setupCtrl(jnt.replace('_%s' % common.JOINT, ''),jnt)
            #create template control
            #control.createTemplate(ctrl)
            cmds.select(cl = True)


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

        #templateNullGroup = cmds.createNode('transform', n = endJointGuide.replace(common.GUIDES, common.GROUP))
        #transform.matchXform(locator, endJointGuide, type = 'position')
        #cmds.pointConstraint(tipJointGuide, templateNullGroup)
        #cmds.parent(templateNullGroup, self.guidesGrp)
        #control.createTemplate(templateNullGroup, defaultType = 'implicitSphere')


        # ----------------------------------------------------------------------
        # 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)])

        #Get Vectors for the cross product
        #Decompose matrix nodes 
        startJointDcm = \
            cmds.createNode('decomposeMatrix',
                name = self.startJoint.replace('%s_%s' % (common.SKINCLUSTER, common.JOINT), common.DECOMPOSEMATRIX ))

        attribute.connect('%s.worldMatrix' % startJointGuide,'%s.inputMatrix' % startJointDcm)

        midJointDcm = \
            cmds.createNode('decomposeMatrix', name = self.midJoint.replace('%s_%s' % (common.SKINCLUSTER, common.JOINT), common.DECOMPOSEMATRIX ))

        attribute.connect('%s.worldMatrix' % midJointGuide, '%s.inputMatrix' % midJointDcm)

        tipJointDcm = \
            cmds.createNode('decomposeMatrix', name = self.tipJoint.replace('%s_%s' % (common.SKINCLUSTER, common.JOINT), common.DECOMPOSEMATRIX ))
        attribute.connect('%s.worldMatrix' % tipJointGuide, '%s.inputMatrix' % tipJointDcm)

        #plus minus average nodes
        v1Node = cmds.createNode('plusMinusAverage')
        v2Node = cmds.createNode('plusMinusAverage')
        cmds.setAttr('%s.operation' % v1Node, 2)
        cmds.setAttr('%s.operation' % v2Node, 2)

        #connect Decompose Matrix and Plus Minus Average nodes
        attribute.connect('%s.outputTranslate' % tipJointDcm, '%s.input3D[0]' % v1Node)
        attribute.connect('%s.outputTranslate' % startJointDcm, '%s.input3D[1]' % v1Node)
        attribute.connect('%s.outputTranslate' % midJointDcm, '%s.input3D[0]' % v2Node)
        attribute.connect('%s.outputTranslate' % startJointDcm, '%s.input3D[1]' % v2Node)

        #Get the cross product
        crossNode = cmds.createNode('vectorProduct')
        cmds.setAttr( '%s.%s' % (crossNode,'operation') , 2 )
        attribute.connect( '%s.%s' % (v1Node,'output3D'), '%s.%s' % (crossNode,'input1') )
        attribute.connect( '%s.%s' % (v2Node,'output3D'), '%s.%s' % (crossNode,'input2') )
        crossVectorAttr = '%s.%s' % (crossNode,'output')

        #Aim start joint to the middle joint
        constraint = \
            cmds.aimConstraint(midJointGuide,
                    self.startJoint,
                    aimVector = (1,0,0),
                    upVector = (0,1,0),
                    worldUpType = 'vector',
                    worldUpVector = (0,1,0))[0]

        attribute.connect(aimVectorAttr, '%s.aimVector' % constraint)
        attribute.connect(upVectorAttr, '%s.upVector' % constraint)
        attribute.connect(crossVectorAttr, '%s.worldUpVector' % constraint)
        self.setupConstraints.append(constraint)

        #Aim middle joint to the tip joint
        constraint = \
            cmds.aimConstraint(tipJointGuide,
                    self.midJoint,
                    aimVector = (1,0,0),
                    upVector = (0,1,0),
                    worldUpType = 'vector',
                    worldUpVector = (0,1,0))[0]

        attribute.connect(aimVectorAttr, '%s.aimVector' % constraint)
        attribute.connect(upVectorAttr, '%s.upVector' % constraint)
        attribute.connect(crossVectorAttr, '%s.worldUpVector' % constraint)
        self.setupConstraints.append(constraint)

        constraint = cmds.orientConstraint(self.midJoint, self.tipJoint)[0]
        self.setupConstraints.append(constraint)

        cmds.setAttr('%s.normalizeOutput' % crossNode, True)

        self.upTwistJnts = list()
        step   = 1.0 / (self.numSegments + 1)
        parent = self.startJoint
        for i in range( 1, self.numSegments + 1 ):
            j = joint.create( name='%s' % (self.startJoint.replace('_%s' % common.SKINCLUSTER, 'Twist_%s_%s' % (common.padNumber(i,3), common.SKINCLUSTER))), parent=parent )
            transform.matchXform( self.startJoint,j, type='rotate' )
            constraint = cmds.pointConstraint( self.startJoint, self.midJoint, j )[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 )
            self.upTwistJnts.append(j)
            self.skinClusterJnts.append(j) #adding the joint to skincluster joints list

        # Create MiddleJoint Segments
        self.loTwistJnts = list()
        parent = self.midJoint
        for i in range( 1, self.numSegments + 1):
            j = joint.create( name='%s' % (self.midJoint.replace('_%s' % common.SKINCLUSTER, 'Twist_%s_%s' % (common.padNumber(i,3), common.SKINCLUSTER))), parent=parent )
            transform.matchXform( self.midJoint,j, type='rotate' )
            constraint = cmds.pointConstraint( self.midJoint, self.tipJoint, j )[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 )
            self.loTwistJnts.append(j)
            self.skinClusterJnts.append(j) #adding the joint to skincluster joints list