Exemplo n.º 1
0
    def rigEyes(self,*args):
        """
        Constrain joints to controls, so user can simply
        parent to the locators.
        """
        #--- Get eye positions
        l_pos = xform('l_eye_loc',q=True,ws=True,t=True)
        r_pos = xform('r_eye_loc',q=True,ws=True,t=True)
        
        #--- Create a follow and fk joint at each eye, all children of headjnt
        l_fkJoint = joint(p=l_pos,n='l_fkEye_jnt',a=True)
        r_fkJoint = joint(p=r_pos,n='r_fkEye_jnt',a=True)
        l_aimJoint = joint(p=l_pos,n='l_aimEye_jnt',a=True)
        r_aimJoint = joint(p=r_pos,n='r_aimEye_jnt',a=True)
        
        # Parent joints to fk control so it controls all position/scale
        parent(self.sNames.headJoints['left_eye'], self.sNames.controlNames['left_eye_fk'])
        parent(self.sNames.headJoints['right_eye'], self.sNames.controlNames['right_eye_fk'])
        parent(l_fkJoint, self.sNames.controlNames['left_eye_fk'])
        parent(r_fkJoint, self.sNames.controlNames['right_eye_fk'])
        parent(l_aimJoint, self.sNames.controlNames['left_eye_fk'])
        parent(r_aimJoint, self.sNames.controlNames['right_eye_fk'])
        
        # Parent the fk eye controllers to the head
        parent('%s_buffer'%self.sNames.controlNames['left_eye_fk'],self.sNames.headJoints['head'])
        parent('%s_buffer'%self.sNames.controlNames['right_eye_fk'],self.sNames.headJoints['head'])
        
        #--- Aim the follow joints to their respective controllers
        aimConstraint( self.sNames.controlNames['left_eye_aim'],l_aimJoint, offset = (0, 0, 0), weight = 1, aimVector = (1, 0, 0), 
                       upVector = (0, 1, 0), worldUpType = "vector", worldUpVector = (0, 1, 0),mo = True )
        aimConstraint( self.sNames.controlNames['right_eye_aim'], r_aimJoint, offset = (0, 0, 0), weight = 1, aimVector = (1, 0, 0), 
                       upVector = (0, 1, 0), worldUpType = "vector", worldUpVector = (0, 1, 0),mo = True )
        
        #--- Create eye switch attributes on head controller: Aim or fk 
        addAttr(self.sNames.controlNames['head'],ln='Eyes_Follow',at='float',k=True)
        setAttr('%s.Eyes_Follow'%self.sNames.controlNames['head'],lock=True)
        addAttr(self.sNames.controlNames['head'],ln='aim',at='float',dv=0,min=0,max=1,k=True)
        addAttr(self.sNames.controlNames['head'],ln='fk',at='float',dv=0,min=0,max=1,k=True)
        
        #--- Parent constraint eye joint to the follow and the fk joints. 
        l_pConst = parentConstraint(l_fkJoint,l_aimJoint,self.sNames.headJoints['left_eye'],mo=True)
        r_pConst = parentConstraint(r_fkJoint,r_aimJoint,self.sNames.headJoints['right_eye'],mo=True)
        
        #--- Connect constraint to head_cnt attributes
        connectAttr('%s.fk'%self.sNames.controlNames['head'],'%s.l_fkEye_jntW0'%l_pConst, f=True)
        connectAttr('%s.fk'%self.sNames.controlNames['head'],'%s.r_fkEye_jntW0'%r_pConst, f=True)
        
        connectAttr('%s.aim'%self.sNames.controlNames['head'],'%s.l_aimEye_jntW1'%l_pConst,f=True)
        connectAttr('%s.aim'%self.sNames.controlNames['head'],'%s.r_aimEye_jntW1'%r_pConst,f=True)
    
        #--- Create head/world switch on eye Follow control
        spaceSwitch.spaceSwitch(   constObj='%s_buffer'%self.sNames.controlNames['eyes_follow'],
                                    control=self.sNames.controlNames['eyes_follow'],
                                    attName='follow',
                                    op1Name='world',
                                    op2Name='head',
                                    op3Name='',
                                    op4Name='',
                                    op5Name='',
                                    op6Name='',
                                    op7Name='',
                                    op8Name='',
                                    object1=self.sNames.controlNames['main'],
                                    object2=self.sNames.controlNames['head'],
                                    object3='',
                                    object4='',
                                    object5='',
                                    object6='',
                                    object7='',
                                    object8=''  )
        
        # Parent to world
        parent('%s_buffer'%self.sNames.controlNames['eyes_follow'], self.sNames.controlNames['main'])
        
        setAttr('%s.world'%self.sNames.controlNames['eyes_follow'], 1)
        
        # lock and hide Eyes_Follow
        setAttr('%s.rotateX' % self.sNames.controlNames['eyes_follow'], lock=True, keyable=False)
        setAttr('%s.rotateY' % self.sNames.controlNames['eyes_follow'], lock=True, keyable=False)
        setAttr('%s.rotateZ' % self.sNames.controlNames['eyes_follow'], lock=True, keyable=False)
        setAttr('%s.scaleX' % self.sNames.controlNames['eyes_follow'], lock=True, keyable=False)
        setAttr('%s.scaleY' % self.sNames.controlNames['eyes_follow'], lock=True, keyable=False)
        setAttr('%s.scaleZ' % self.sNames.controlNames['eyes_follow'], lock=True, keyable=False) 

        setAttr('%s.rotateX' % self.sNames.controlNames['left_eye_aim'], lock=True, keyable=False)
        setAttr('%s.rotateY' % self.sNames.controlNames['left_eye_aim'], lock=True, keyable=False)
        setAttr('%s.rotateZ' % self.sNames.controlNames['left_eye_aim'], lock=True, keyable=False)
        setAttr('%s.scaleX' % self.sNames.controlNames['left_eye_aim'], lock=True, keyable=False)
        setAttr('%s.scaleY' % self.sNames.controlNames['left_eye_aim'], lock=True, keyable=False)
        setAttr('%s.scaleZ' % self.sNames.controlNames['left_eye_aim'], lock=True, keyable=False)
        setAttr('%s.visibility' % self.sNames.controlNames['left_eye_aim'], lock=True, keyable=False)   
        
        setAttr('%s.rotateX' % self.sNames.controlNames['right_eye_aim'], lock=True, keyable=False)
        setAttr('%s.rotateY' % self.sNames.controlNames['right_eye_aim'], lock=True, keyable=False)
        setAttr('%s.rotateZ' % self.sNames.controlNames['right_eye_aim'], lock=True, keyable=False)
        setAttr('%s.scaleX' % self.sNames.controlNames['right_eye_aim'], lock=True, keyable=False)
        setAttr('%s.scaleY' % self.sNames.controlNames['right_eye_aim'], lock=True, keyable=False)
        setAttr('%s.scaleZ' % self.sNames.controlNames['right_eye_aim'], lock=True, keyable=False)
        setAttr('%s.visibility' % self.sNames.controlNames['right_eye_aim'], lock=True, keyable=False)  
Exemplo n.º 2
0
    def rigEyes(self, *args):
        """
        Constrain joints to controls, so user can simply
        parent to the locators.
        """
        #--- Get eye positions
        l_pos = xform('l_eye_loc', q=True, ws=True, t=True)
        r_pos = xform('r_eye_loc', q=True, ws=True, t=True)

        #--- Create a follow and fk joint at each eye, all children of headjnt
        l_fkJoint = joint(p=l_pos, n='l_fkEye_jnt', a=True)
        r_fkJoint = joint(p=r_pos, n='r_fkEye_jnt', a=True)
        l_aimJoint = joint(p=l_pos, n='l_aimEye_jnt', a=True)
        r_aimJoint = joint(p=r_pos, n='r_aimEye_jnt', a=True)

        # Parent joints to fk control so it controls all position/scale
        parent(self.sNames.headJoints['left_eye'],
               self.sNames.controlNames['left_eye_fk'])
        parent(self.sNames.headJoints['right_eye'],
               self.sNames.controlNames['right_eye_fk'])
        parent(l_fkJoint, self.sNames.controlNames['left_eye_fk'])
        parent(r_fkJoint, self.sNames.controlNames['right_eye_fk'])
        parent(l_aimJoint, self.sNames.controlNames['left_eye_fk'])
        parent(r_aimJoint, self.sNames.controlNames['right_eye_fk'])

        # Parent the fk eye controllers to the head
        parent('%s_buffer' % self.sNames.controlNames['left_eye_fk'],
               self.sNames.headJoints['head'])
        parent('%s_buffer' % self.sNames.controlNames['right_eye_fk'],
               self.sNames.headJoints['head'])

        #--- Aim the follow joints to their respective controllers
        aimConstraint(self.sNames.controlNames['left_eye_aim'],
                      l_aimJoint,
                      offset=(0, 0, 0),
                      weight=1,
                      aimVector=(1, 0, 0),
                      upVector=(0, 1, 0),
                      worldUpType="vector",
                      worldUpVector=(0, 1, 0),
                      mo=True)
        aimConstraint(self.sNames.controlNames['right_eye_aim'],
                      r_aimJoint,
                      offset=(0, 0, 0),
                      weight=1,
                      aimVector=(1, 0, 0),
                      upVector=(0, 1, 0),
                      worldUpType="vector",
                      worldUpVector=(0, 1, 0),
                      mo=True)

        #--- Create eye switch attributes on head controller: Aim or fk
        addAttr(self.sNames.controlNames['head'],
                ln='Eyes_Follow',
                at='float',
                k=True)
        setAttr('%s.Eyes_Follow' % self.sNames.controlNames['head'], lock=True)
        addAttr(self.sNames.controlNames['head'],
                ln='aim',
                at='float',
                dv=0,
                min=0,
                max=1,
                k=True)
        addAttr(self.sNames.controlNames['head'],
                ln='fk',
                at='float',
                dv=0,
                min=0,
                max=1,
                k=True)

        #--- Parent constraint eye joint to the follow and the fk joints.
        l_pConst = parentConstraint(l_fkJoint,
                                    l_aimJoint,
                                    self.sNames.headJoints['left_eye'],
                                    mo=True)
        r_pConst = parentConstraint(r_fkJoint,
                                    r_aimJoint,
                                    self.sNames.headJoints['right_eye'],
                                    mo=True)

        #--- Connect constraint to head_cnt attributes
        connectAttr('%s.fk' % self.sNames.controlNames['head'],
                    '%s.l_fkEye_jntW0' % l_pConst,
                    f=True)
        connectAttr('%s.fk' % self.sNames.controlNames['head'],
                    '%s.r_fkEye_jntW0' % r_pConst,
                    f=True)

        connectAttr('%s.aim' % self.sNames.controlNames['head'],
                    '%s.l_aimEye_jntW1' % l_pConst,
                    f=True)
        connectAttr('%s.aim' % self.sNames.controlNames['head'],
                    '%s.r_aimEye_jntW1' % r_pConst,
                    f=True)

        #--- Create head/world switch on eye Follow control
        spaceSwitch.spaceSwitch(
            constObj='%s_buffer' % self.sNames.controlNames['eyes_follow'],
            control=self.sNames.controlNames['eyes_follow'],
            attName='follow',
            op1Name='world',
            op2Name='head',
            op3Name='',
            op4Name='',
            op5Name='',
            op6Name='',
            op7Name='',
            op8Name='',
            object1=self.sNames.controlNames['main'],
            object2=self.sNames.controlNames['head'],
            object3='',
            object4='',
            object5='',
            object6='',
            object7='',
            object8='')

        # Parent to world
        parent('%s_buffer' % self.sNames.controlNames['eyes_follow'],
               self.sNames.controlNames['main'])

        setAttr('%s.world' % self.sNames.controlNames['eyes_follow'], 1)

        # lock and hide Eyes_Follow
        setAttr('%s.rotateX' % self.sNames.controlNames['eyes_follow'],
                lock=True,
                keyable=False)
        setAttr('%s.rotateY' % self.sNames.controlNames['eyes_follow'],
                lock=True,
                keyable=False)
        setAttr('%s.rotateZ' % self.sNames.controlNames['eyes_follow'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleX' % self.sNames.controlNames['eyes_follow'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleY' % self.sNames.controlNames['eyes_follow'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleZ' % self.sNames.controlNames['eyes_follow'],
                lock=True,
                keyable=False)

        setAttr('%s.rotateX' % self.sNames.controlNames['left_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.rotateY' % self.sNames.controlNames['left_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.rotateZ' % self.sNames.controlNames['left_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleX' % self.sNames.controlNames['left_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleY' % self.sNames.controlNames['left_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleZ' % self.sNames.controlNames['left_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.visibility' % self.sNames.controlNames['left_eye_aim'],
                lock=True,
                keyable=False)

        setAttr('%s.rotateX' % self.sNames.controlNames['right_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.rotateY' % self.sNames.controlNames['right_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.rotateZ' % self.sNames.controlNames['right_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleX' % self.sNames.controlNames['right_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleY' % self.sNames.controlNames['right_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.scaleZ' % self.sNames.controlNames['right_eye_aim'],
                lock=True,
                keyable=False)
        setAttr('%s.visibility' % self.sNames.controlNames['right_eye_aim'],
                lock=True,
                keyable=False)
Exemplo n.º 3
0
    def buildIK(self, *args):
        """
            Build the IK leg
        """
        #Setup variables
        #@Todo - Is this actually working?
        self.normal = (1,0,0)
        if self.normalAxis == 1:
            self.normal = (1, 0, 0)
        if self.normalAxis == 2:
            self.normal = (0, 1, 0)
        if self.normalAxis == 3:
            self.normal = (0, 0, 1)   

        #Create IK control
        name = ''
        if self.side == 1:
            name = self.sNames.controlNames['left_footIk']
        if self.side == 2:
            name = self.sNames.controlNames['right_footIk']
            
        self.ikControl = circle(nr=self.normal, r=self.radius,n=name)
        select(self.ikControl[0],r=True)
        mel.eval("DeleteHistory;")
        
        if self.side == 1:
            # Set the color
            setAttr('%s.overrideEnabled'%self.ikControl[0], 1)
            setAttr('%s.ovc'%self.ikControl[0], 13)
            
        else:
            # Set the color
            setAttr('%s.overrideEnabled'%self.ikControl[0], 1)
            setAttr('%s.ovc'%self.ikControl[0], 6)

        # Set rotate orders
        setAttr('%s.rotateOrder'%self.ikControl[0], self.rotateOrderInt) # ZXY

        #Parent circle under third joint
        parent(self.ikControl[0], self.ikChain[2])  
          
        #Zero it so it snaps to joint position/orientation   
        move(self.ikControl[0], 0, 0, 0,os=True)             
        parent(self.ikControl[0],w=True)
        
        #Zero it's values and create the buffer node
        ikBuffer01 = self.lib.zero(self.ikControl[0])             
             
        #Create RP IK
        self.leg_ikHandle = ikHandle(sj=self.ikChain[0], ee=self.ikChain[2], solver='ikRPsolver', name=(self.prefix + '_legIkHandle'))
        setAttr(self.leg_ikHandle[0] + '.visibility', 0)
        
        #Parent IK Handle to the ikHandle_cnt
        parent(self.leg_ikHandle[0], self.ikControl[0])
        self.createdNodes['ik_handle'] = self.leg_ikHandle[0]

        # Creates: self.pv_cnt
        self.createPoleVector(self.leg_ikHandle[0], self.ikControl, self.sNames.controlNames['main'])
        
        # Setup space switch for ik control
        # first, re-zero ik control to have an other node above it.
        ikBuffer02 = self.lib.zero(ikBuffer01)  
        self.createdNodes['buffer'] = ikBuffer02
        ss.spaceSwitch(   constObj=ikBuffer02,
                            control=self.ikControl[0],
                            attName='space_switches',
                            op1Name='world_space',
                            op2Name='cog_space',
                            op3Name='hips_space',
                            op4Name='',
                            op5Name='',
                            op6Name='',
                            op7Name='',
                            op8Name='',
                            object1=self.world,
                            object2=self.cog,
                            object3=self.hips,
                            object4='',
                            object5='',
                            object6='',
                            object7='',
                            object8=''  )
Exemplo n.º 4
0
	def buildIK(self, *args):
		"""
			Build the IK arm
		"""
		#Setup variables
		#@todo - Is this actually working?
		self.normal = (1,0,0)
		if self.normalAxis == 2:
			self.normal = (0, 1, 0)
		if self.normalAxis == 3:
			self.normal = (0, 0, 1)   

		#Create IK control
		if self.prefix == 'l_arm':
			self.ikControl = circle(nr=self.normal, r=self.radius,n=self.sNames.controlNames['left_armIk'])
			# Set the color
			setAttr('%s.overrideEnabled'%self.ikControl[0], 1)
			setAttr('%s.ovc'%self.ikControl[0], 13)
		
		if self.prefix == 'r_arm':
			self.ikControl = circle(nr=self.normal, r=self.radius,n=self.sNames.controlNames['right_armIk'])
			# Set the color
			setAttr('%s.overrideEnabled'%self.ikControl[0], 1)
			setAttr('%s.ovc'%self.ikControl[0], 6)
		
		select(self.ikControl[0],r=True)
		
		mel.eval("DeleteHistory;")

		# Set rotate orders
		setAttr('%s.rotateOrder'%self.ikControl[0], self.rotateOrderInt) #ZXY

		#Parent circle under wrist joint
		parent(self.ikControl[0], self.ikChain[2])  
		  
		#Zero it so it snaps to joint position/orientation   
		move(self.ikControl[0], 0, 0, 0,os=True)			 
		parent(self.ikControl[0],w=True)
		
		#Zero it's values and create the buffer node
		ikBuffer01 = self.lib.zero(self.ikControl[0])			 
			 
		#Create RP IK

		self.arm_ikHandle = ikHandle(sj=self.ikChain[0], ee=self.ikChain[2], solver='ikRPsolver', name=(self.prefix + '_armIkHandle'))
		setAttr(self.arm_ikHandle[0] + '.visibility', 0)
		
		#Parent IK Handle to the ikWrist_cnt
		parent(self.arm_ikHandle[0], self.ikControl[0])

		# Creates: self.pv_cnt
		self.createPoleVector(self.arm_ikHandle[0],self.ikControl[0],self.world)
		
		# Setup space switch
		# first, re-zero ik control to have an other node above it.
		ikBuffer02 = self.lib.zero(ikBuffer01)  
		ss.spaceSwitch(   constObj=ikBuffer02,
							control=self.ikControl[0],
							attName='space_switches',
							op1Name='world_space',
							op2Name='cog_space',
							op3Name='hips_space',
							op4Name='shoulders_space',
							op5Name='head_space',
							op6Name='',
							op7Name='',
							op8Name='',
							object1=self.world,
							object2=self.cog,
							object3=self.hips,
							object4=self.shoulder,
							object5=self.head,
							object6='',
							object7='',
							object8=''  )
		
		#@todo - Works at orienting ik control to hand, but causes propagation issues
		#			when a value is directly enter for the ik controller, the follow chain
		#			blendColor nodes do not update. Weird but verified.
		# Constrain IK control to hand control
		#orientConstraint(self.hand,self.ikControl[0],mo=True)
		
		# Add the top buffer node to return it to client
		self.createdNodes['ikCntBuffer'] = ikBuffer02