Example #1
0
def addPushOutLoc():
    '''
    '''
    locGrpNames = [
        '_back', '_left', '_front', '_right', '_leftBack', '_rightBack',
        '_rightFront', '_leftFront'
    ]

    for grpName in locGrpNames:

        # create orient for consLoc (loc at the top of the chain)
        consLoc = pm.PyNode('jacketStart' + grpName + '_loc')

        orientLoc = pm.spaceLocator(n=consLoc.name() + '_orient')
        pm.pointConstraint(consLoc, orientLoc)
        mp = pm.PyNode('CT_jacketLocsAlign%s_mp' % grpName)
        mp.rotate >> orientLoc.r

        # add offsetLoc that can be constrained to shoulders later
        offsetLoc = pm.spaceLocator(n=consLoc.name() + '_offset')
        orientLoc | offsetLoc
        offsetLoc.setMatrix(dt.Matrix.identity)

        for locId in range(1, 10):

            loc = pm.PyNode('torsoReader_%d%s_loc' % (locId, grpName))
            newLoc = pm.spaceLocator(n=loc.name() + '_pushOutLoc')
            newLoc.localScale.set(0.25, 0.25, 0.25)
            matrix = loc.getMatrix(worldSpace=True)
            newLoc.setMatrix(matrix, worldSpace=True)
            loc | newLoc
            newLoc.setLimit('translateMinZ', 0)

            pm.pointConstraint(offsetLoc, newLoc, skip=('x', 'y'))
Example #2
0
def Ik_To_Fk_Switch_Button():
	selection = pm.ls(sl=True)
	namespace_correct = selection[0].split(':')[:-1]
	if len(selection)>0:
		side = selection[0].split('_')[1]
		shoulderSwitchCtrl = namespace_correct[0]+':'+'FK_shoulder_switch_'+side+'_Ctrl'
		ElbowSwitchCtrl = namespace_correct[0]+':'+'FK_Elbow_switch_'+side+'_Ctrl'
		wristSwitchCtrl = namespace_correct[0]+':'+'FK_wrist_switch_'+side+'_Ctrl'
		FKShoulder_CTRL = namespace_correct[0]+':'+'FKShoulder_'+side+'_CTRL'
		temp_loc = namespace_correct[0]+':'+'temp_loc'
		switch_ctrl = namespace_correct[0]+':'+'FKIKArm_'+side+'_CTRL'
		FKElbow_CTRL = namespace_correct[0]+':'+'FKElbow_'+side+'_CTRL'
		FKWrist_CTRL = namespace_correct[0]+':'+'FKWrist_'+side+'_CTRL'
		
		
		temp_loc = pm.spaceLocator(n=temp_loc)
		pm.delete(pm.parentConstraint(shoulderSwitchCtrl,temp_loc))
		pm.delete(pm.parentConstraint(temp_loc,FKShoulder_CTRL),temp_loc)
		
		
		temp_loc = pm.spaceLocator(n=temp_loc)
		pm.delete(pm.parentConstraint(ElbowSwitchCtrl,temp_loc))
		pm.delete(pm.parentConstraint(temp_loc,FKElbow_CTRL),temp_loc)
		
		
		temp_loc = pm.spaceLocator(n=temp_loc)
		pm.delete(pm.parentConstraint(wristSwitchCtrl,temp_loc))
		pm.delete(pm.parentConstraint(temp_loc,FKWrist_CTRL),temp_loc)
		
		pm.setAttr(switch_ctrl+'.FKIKBlend',0)	
			
	else:
		print 'select switch controller',
def create_planar_locators(nLocators, length=10.0, name='test', size=1):
  
    root = pm.spaceLocator(name='%s_root' %name)
    root.add_shape(shape='double_cross', axis='+z', size=size)
    locators=[root]    

    for i in range(nLocators):
        spacing = length / (nLocators - 1)
        tx = i * spacing        
        
        locator = pm.spaceLocator(name='%s_locator_%d' %(name, i+1))
        locator.getShape().localScale.set([size,size,size])
        #locator.add_parent_group()
       
        pm.parent(locator, root)
        locator.translateX.set(tx)
        
        
        locators.append(locator)

    for i in range(2, len(locators)):
        pm.aimConstraint(locators[i], locators[i-1], mo=False, aimVector=[1,0,0], upVector=[0,0,1], worldUpType='objectrotation', worldUpVector = [0,0,1], worldUpObject=root)

    for locator in locators[1:]:
        locator.tz.lock()
        locator.rotate.lock()
        
    for locator in locators[1:-1]:
        locator.add_rotate_arrows(size=size)

    return locators
        
    
Example #4
0
    def distance_between_points_measure(self, point_01, point_02):
        transform_start_point = "startPoint"
        transform_end_point = "endPoint"

        transform_start_point = pm.spaceLocator(name=transform_start_point)
        self.name_convention.rename_name_in_format(transform_start_point,
                                                   useName=True)
        transform_end_point = pm.spaceLocator(name=transform_end_point)
        self.name_convention.rename_name_in_format(transform_end_point,
                                                   useName=True)

        start_point_constraint = pm.pointConstraint(point_01,
                                                    transform_start_point)
        end_point_constraint = pm.pointConstraint(point_02,
                                                  transform_end_point)

        distance_node = pm.shadingNode("distanceBetween",
                                       asUtility=True,
                                       name="DistanceNode")
        self.name_convention.rename_based_on_base_name(point_01,
                                                       distance_node,
                                                       name=distance_node)

        pm.connectAttr("%s.worldPosition[0]" % transform_start_point,
                       "%s.point1" % distance_node,
                       f=True)
        pm.connectAttr("%s.worldPosition[0]" % transform_end_point,
                       "%s.point2" % distance_node,
                       f=True)

        return [transform_start_point, transform_end_point], distance_node
Example #5
0
    def getJointDistance(self, ikHandle):
        '''
        Return the lenght of ikHandle
        :param ikHandle: select an ikHandle
        :return: Return the lenght og ikHandle
        '''

        # Put all three joints in a variable based on a selected ikHandle
        selJoints = ikHandle.getJointList()
        pm.select(selJoints[-1])
        pm.pickWalk(d='down')
        newJoints = pm.ls(sl=True)
        selJoints.append(newJoints[0])
        loc0 = pm.spaceLocator()
        loc1 = pm.spaceLocator()
        constraint0 = pm.pointConstraint(selJoints[0], loc0)
        constraint1 = pm.pointConstraint(selJoints[2], loc1)

        def ctr_dist(objA, objB):
            Ax, Ay, Az = objA.getTranslation(space="world")
            Bx, By, Bz = objB.getTranslation(space="world")
            return ((Ax - Bx)**2 + (Ay - By)**2 + (Az - Bz)**2)**0.5

        distance = ctr_dist(loc0, loc1)
        pm.delete(constraint0, constraint1, loc0, loc1)
        return distance
Example #6
0
def Fk_To_Ik_Switch_Button():
    selection = pm.ls(sl=True)
    namespace_correct = selection[0].split(':')[:-1]
    if len(selection) > 0:
        side = selection[0].split('_')[1]
        locFoot = namespace_correct[0] + ':' + 'tempFootLOC'
        FootdummyCtrl = namespace_correct[
            0] + ':' + 'legSwitch_' + side + '_CTRL'
        ikFootCtrl = namespace_correct[0] + ':' + 'IKLeg_' + side + '_CTRL'
        locKnee = namespace_correct[0] + ':' + 'tempKneeLOC'
        KneedummyCtrl = namespace_correct[
            0] + ':' + 'kneeSwitch_' + side + '_CTRL'
        poleLeg = namespace_correct[0] + ':' + 'PoleLeg_' + side + '_CTRL'

        locFoot = pm.spaceLocator(n=locFoot)
        snaploc = pm.delete(pm.parentConstraint(FootdummyCtrl, locFoot))
        pm.delete(pm.parentConstraint(locFoot, ikFootCtrl, mo=False), locFoot)

        ###Switch between FK To IK Leg###

        locKnee = pm.spaceLocator(n=locKnee)
        snaploc = pm.delete(pm.parentConstraint(KneedummyCtrl, locKnee))
        pm.delete(pm.pointConstraint(locKnee, poleLeg, mo=False), locKnee)

        pm.setAttr(selection[0] + '.FKIKBlend', 10)
    else:
        print 'select switch controller',
Example #7
0
def Ik_To_Fk_Switch_Button():
    selection = pm.ls(sl=True)
    namespace_correct = selection[0].split(':')[:-1]
    if len(selection) > 0:
        side = selection[0].split('_')[1]
        hipSwitchCtrl = namespace_correct[
            0] + ':' + 'FK_hip_switch_' + side + '_Ctrl'
        kneeSwitchCtrl = namespace_correct[
            0] + ':' + 'FK_knee_switch_' + side + '_Ctrl'
        ankleSwitchCtrl = namespace_correct[
            0] + ':' + 'FK_ankle_switch_' + side + '_Ctrl'
        FKHip_CTRL = namespace_correct[0] + ':' + 'FKHip_' + side + '_CTRL'
        temp_loc = namespace_correct[0] + ':' + 'temp_loc'
        switch_ctrl = namespace_correct[0] + ':' + 'FKIKLeg_' + side + '_CTRL'
        FKKnee_CTRL = namespace_correct[0] + ':' + 'FKKnee_' + side + '_CTRL'
        FKAnkle_CTRL = namespace_correct[0] + ':' + 'FKAnkle_' + side + '_CTRL'

        temp_loc = pm.spaceLocator(n=temp_loc)
        pm.delete(pm.parentConstraint(hipSwitchCtrl, temp_loc))
        pm.delete(pm.parentConstraint(temp_loc, FKHip_CTRL), temp_loc)

        temp_loc = pm.spaceLocator(n=temp_loc)
        pm.delete(pm.parentConstraint(kneeSwitchCtrl, temp_loc))
        pm.delete(pm.parentConstraint(temp_loc, FKKnee_CTRL), temp_loc)

        temp_loc = pm.spaceLocator(n=temp_loc)
        pm.delete(pm.parentConstraint(ankleSwitchCtrl, temp_loc))
        pm.delete(pm.parentConstraint(temp_loc, FKAnkle_CTRL), temp_loc)

        pm.setAttr(switch_ctrl + '.FKIKBlend', 0)
    else:
        print 'select switch controller',
Example #8
0
def Fk_To_Ik_Switch_Button():
	selection = pm.ls(sl=True)
	namespace_correct = selection[0].split(':')[:-1]
	if len(selection)>0:
		side = selection[0].split('_')[1]
		locArm = namespace_correct[0]+':'+'tempArmLOC'
		ArmdummyCtrl = namespace_correct[0]+':'+'ArmSwitch_'+side+'_CTRL'
		ikArmCtrl = namespace_correct[0]+':'+'IKArm_'+side+'_CTRL'
		locElbow = namespace_correct[0]+':'+'tempElbowLOC'
		ElbowdummyCtrl = namespace_correct[0]+':'+'ElbowSwitch_'+side+'_CTRL'
		poleArm = namespace_correct[0]+':'+'PoleArm_'+side+'_CTRL'
		
		
		
		
		locArm = pm.spaceLocator(n=locArm)
		snaploc = pm.delete(pm.parentConstraint(ArmdummyCtrl,locArm))
		pm.delete(pm.parentConstraint(locArm,ikArmCtrl,mo=False),locArm)
		
		###Switch between FK To IK Leg###
		
		locElbow = pm.spaceLocator(n=locElbow)
		snaploc = pm.delete(pm.parentConstraint(ElbowdummyCtrl,locElbow))
		pm.delete(pm.pointConstraint(locElbow,poleArm,mo=False),locElbow)
		
		pm.setAttr(selection[0]+'.FKIKBlend',10)
		
	else:
		print 'select switch controller',
Example #9
0
    def build(self):
        """builds it self
        """
        self.curve = curve(d=1, p=[(1, 0, 0), (-1, 0, 0)], k=(0, 1))
        self.corner1_locator = spaceLocator()
        self.corner2_locator = spaceLocator()
        select(self.curve)
        ClusterCurve()

        # try to find the clusterHandles
        curve_shape = curve.getShape()
        clusters = []
        handles = []
        for node in curve_shape.listHistroy():
            if isinstance(node, ClusterHandle):
                handles.append(node)
            elif isinstance(node, Cluster):
                clusters.append(node)

        self.cluster1 = clusters[0]
        self.cluster2 = clusters[0]

        self.cluster_handle1 = handles[0]
        self.cluster_handle2 = handles[1]

        # set clusters to absolute
        self.cluster1.setAttr('relative', 0)
        self.cluster2.setAttr('relative', 0)
Example #10
0
 def createNoiseControl(self):
     # Create locator
     control = '%s%s' % (self.camera, self._CONTROL_SUFIX)
     pc.spaceLocator(n=control)
     # Create attribute for turning noise on/off
     pc.addAttr(ln='NOISE_SWITCH', k=False, at='enum', en='-:')
     pc.setAttr('%s.NOISE_SWITCH' % control, lock=True, cb=True)
     pc.addAttr(ln='Noise', k=False, at='enum', en='Off:On:')
     pc.setAttr('%s.Noise' % control, 1, cb=True)
     # Create translation noise attributes: frequency, amplitude (x, y, z), jitter and seed
     for noise_type in ['T', 'R']:
         nname = 'TRANSLATION' if noise_type == 'T' else 'ROTATION'
         pc.addAttr(ln='%s_NOISE' % nname, k=False, at='enum', en='-:')
         pc.setAttr('%s.%s_NOISE' % (control, nname), lock=True, cb=True)
         for axis in ['X', 'Y', 'Z']:
             pc.addAttr(ln='Frequency_%s%s' % (noise_type, axis),
                        k=True,
                        at='double',
                        min=0)
             pc.addAttr(ln='Amplitude_%s%s' % (noise_type, axis),
                        k=True,
                        at='double',
                        min=0)
         pc.addAttr(ln='Jitter_%s' % noise_type, k=True, at='double', min=0)
         pc.addAttr(ln='Seed_%s' % noise_type,
                    k=False,
                    at='short',
                    dv=random.randint(0, 9999))
         pc.setAttr('%s.Seed_%s' % (control, noise_type), cb=True)
     # Create extra attributes for camera position offset
     pc.addAttr(ln='CAM_OFFSET', k=False, at='enum', en='-:')
     pc.setAttr('%s.CAM_OFFSET' % control, lock=True, cb=True)
     for axis in ['X', 'Y', 'Z']:
         pc.addAttr(ln='Offset_%s' % axis, k=True, at='double')
     return control
 def install_subMetaRig_proxy(self):
     logger.debug("Function Called ( %s )"%inspect.stack()[0][3])
     
     #retrieve components   
     prefix = self.prefix.get()
     if self.side.get():
         prefix = "%s_%s"%(self.prefix.get(), self.side.get())
     
     #build components
     proxy_gr = pm.group(empty=True, name='%s_proxy_gr' %prefix)
     proxy_1 = pm.spaceLocator(name='%s_proxy_1' %prefix)
     proxy_2 = pm.spaceLocator(name='%s_proxy_2' %prefix)
     
     joint_1 = pm.joint(name='%s_joint_1' %prefix)
     joint_2 = pm.joint(name='%s_joint_2' %prefix)
     
     pm.parent( proxy_1, proxy_2, joint_1, joint_2, proxy_gr)
     
     #store components
     joint_1.message >> self.joint_1
     joint_2.message >> self.joint_2
     proxy_1.message >> self.proxy_1
     proxy_2.message >> self.proxy_2
     proxy_gr.message >> self.proxy_gr
     
     pass
Example #12
0
def infoStore(storeName, storeValue=False):
    storeName = str(storeName)
    #Create info store if it doesn't exist
    try:
        py.ls('infoStore')[0]
    except:
        originalSelection = py.ls(selection=True)
        py.spaceLocator(n='infoStore')
        py.addAttr('infoStore',
                   shortName='progress',
                   longName='ProgressBarName',
                   dataType='string')
        py.select(originalSelection)
        py.hide('infoStore')
    #Get value from info store or create new attribute
    try:
        storedValue = ast.literal_eval(py.getAttr('infoStore.' + storeName))
    except:
        py.addAttr('infoStore', longName=storeName, dataType='string')
        py.setAttr('infoStore.' + storeName, '{}')
        storedValue = ast.literal_eval(py.getAttr('infoStore.' + storeName))
    #Write values to info store
    if storeValue != False:
        py.setAttr('infoStore.' + storeName, str(storeValue))
    return storedValue
Example #13
0
def connectJacketLoc(twistCrv, untwistCrv, param, name='', addCrvs=[]):
    '''
    '''
    mp = pm.createNode('motionPath', n=twistCrv+name+'_mp')
    untwistCrv.worldSpace >> mp.geometryPath
    mp.u.set(param)
    
    npc = pm.createNode('nearestPointOnCurve', n=twistCrv+name+'_npc')
    mp.allCoordinates >> npc.inPosition
    twistCrv.worldSpace >> npc.inputCurve
    
    allLocs = []
    loc = pm.spaceLocator(n=twistCrv+name+'_loc')
    npc.position >> loc.translate
    allLocs.append(loc)
    
    for crv in addCrvs:
        pci = pm.createNode('pointOnCurveInfo', n=crv+name+'_pci')
        npc.parameter >> pci.parameter
        crv.worldSpace >> pci.inputCurve
        loc = pm.spaceLocator(n=crv+name+'_loc')
        pci.position >> loc.translate
        allLocs.append(loc)
    
    pm.select(allLocs)
Example #14
0
def connectJacketLoc(twistCrv, untwistCrv, param, name='', addCrvs=[]):
    '''
    '''
    mp = pm.createNode('motionPath', n=twistCrv + name + '_mp')
    untwistCrv.worldSpace >> mp.geometryPath
    mp.u.set(param)

    npc = pm.createNode('nearestPointOnCurve', n=twistCrv + name + '_npc')
    mp.allCoordinates >> npc.inPosition
    twistCrv.worldSpace >> npc.inputCurve

    allLocs = []
    loc = pm.spaceLocator(n=twistCrv + name + '_loc')
    npc.position >> loc.translate
    allLocs.append(loc)

    for crv in addCrvs:
        pci = pm.createNode('pointOnCurveInfo', n=crv + name + '_pci')
        npc.parameter >> pci.parameter
        crv.worldSpace >> pci.inputCurve
        loc = pm.spaceLocator(n=crv + name + '_loc')
        pci.position >> loc.translate
        allLocs.append(loc)

    pm.select(allLocs)
Example #15
0
    def prebuild(self):
        self.guide_names = [
            "{0}_tentacle_start_GUIDE".format(self.model.module_name),
            "{0}_tentacle_end_GUIDE".format(self.model.module_name)
        ]

        if self.guide_check(self.guide_names):
            self.guides = pmc.ls(self.guide_names)
            self.guides_grp = pmc.ls("{0}_guides".format(
                self.model.module_name))[0]
            self.guides_grp.setAttr("visibility", 1)
            self.view.refresh_view()
            pmc.select(d=1)
            return

        tentacle_start_guide = pmc.spaceLocator(p=(0, 0, 0),
                                                n=self.guide_names[0])
        tentacle_end_guide = pmc.spaceLocator(p=(0, 0, 0),
                                              n=self.guide_names[1])
        tentacle_start_guide.setAttr("translate", (0, 2, 0))
        tentacle_end_guide.setAttr("translate", (0, 0, 0))

        self.guides = [tentacle_start_guide, tentacle_end_guide]
        self.guides_grp = self.group_guides(self.guides)

        self.view.refresh_view()
        pmc.select(d=1)
Example #16
0
def createHighlight(mesh, lightType=mayaLights["Spot"], offset=6):
    """ Create Light based on curve drawn on object """
    # Get the currently selected curve
    curveA = getSelection()

    # Get the start and end points of the curve as Vectors
    crv_posA = dt.Vector(pm.pointOnCurve(curveA, pr=0))
    crv_posB = dt.Vector(pm.pointOnCurve(curveA, pr=curveA.maxValue.get()))

    # Calculate the mid point
    midPoint = (crv_posA + crv_posB) / 2

    # Get closest point & normal on mesh
    pointOnMesh_set = mesh.getClosestPointAndNormal(midPoint, space="world")
    pointOnMesh = pointOnMesh_set[0]
    pointOnMesh_normal = pointOnMesh_set[1]

    pm.spaceLocator(p=pointOnMesh)  # For debug/vis

    # Create dummy camera
    cam = pm.camera()
    camera = cam[0]
    camera.setTranslation(pointOnMesh + pointOnMesh_normal * offset)
    pm.viewLookAt(camera, pos=pointOnMesh)

    # Create light
    createLight(lightType, camera.getTranslation(), camera.getRotation())

    # Delete dummy camera
    pm.delete(camera)
Example #17
0
    def _ctrlDBL(self, controls):

        pmc.undoInfo(openChunk=True)

        if controls == []:
            controls = pmc.ls(sl=True)

        for control in controls:
            control_roo = pmc.xform(control, q=True, roo=True)
            control_mtx = pmc.xform(control, q=True, m=True, ws=True)
            control_parent = pmc.listRelatives(control, p=True)
            pmc.select(cl=True)

            locdbl_parent = pmc.spaceLocator(n='locDBL_parent_' + control)
            locdbl_offset = pmc.spaceLocator(n='locDBL_offset_' + control)

            pmc.xform(locdbl_parent, ws=True, m=control_mtx)
            pmc.xform(locdbl_offset, ws=True, m=control_mtx)

            pmc.parent(locdbl_offset, locdbl_parent)
            pmc.parent(locdbl_parent, control_parent)
            pmc.parent(control, locdbl_offset)

            if control_roo == 'xyz':
                pmc.xform(locdbl_offset, roo='zyx')
            if control_roo == 'yzx':
                pmc.xform(locdbl_offset, roo='xzy')
            if control_roo == 'zxy':
                pmc.xform(locdbl_offset, roo='yxz')
            if control_roo == 'xzy':
                pmc.xform(locdbl_offset, roo='yzx')
            if control_roo == 'yxz':
                pmc.xform(locdbl_offset, roo='zxy')
            if control_roo == 'zyx':
                pmc.xform(locdbl_offset, roo='xyz')

            md_trns = pmc.createNode('multiplyDivide',
                                     n='mdTRNS_locDBL_' + control)
            md_rot = pmc.createNode('multiplyDivide',
                                    n='mdROT_locDBL_' + control)
            md_scl = pmc.createNode('multiplyDivide',
                                    n='mdSCL_locDBL_' + control)

            pmc.setAttr(md_trns + '.input1', [-1, -1, -1])
            pmc.setAttr(md_rot.input1, [-1, -1, -1])
            pmc.setAttr(md_scl.input1, [1, 1, 1])
            pmc.setAttr(md_scl.operation, 2)

            pmc.connectAttr(control + '.translate', md_trns + '.input2')
            pmc.connectAttr(control + '.rotate', md_rot + '.input2')
            pmc.connectAttr(control + '.scale', md_scl + '.input2')

            pmc.connectAttr(md_trns + '.output', locdbl_offset + '.translate')
            pmc.connectAttr(md_rot + '.output', locdbl_offset + '.rotate')
            pmc.connectAttr(md_scl + '.output', locdbl_offset + '.scale')

            pmc.setAttr(locdbl_parent + 'Shape.visibility', 0)
            pmc.setAttr(locdbl_offset + 'Shape.visibility', 0)

        pmc.undoInfo(closeChunk=True)
Example #18
0
	def createDynamicChainLocators(self, prefix = ''):
		
		#set instance prefix var
		self.setPrefix(prefix)
		
		pm.select(cl = True)
		
		#Create Space locators and translate
		self.dynamic_chain_locator_base = pm.spaceLocator(n = self.prefix + '_dynamic_chain_locator_base')
		self.dynamic_chain_locator_base.translate.set(0, 0, 0)
		pm.select(cl = True)
		
		self.dynamic_chain_locator_tip = pm.spaceLocator(n = self.prefix + '_dynamic_chain_locator_tip')
		self.dynamic_chain_locator_tip.translate.set(0, 10, 0)
		pm.select(cl = True)
		
		
		
		#Create Annotations and rename
		self.annotation_dynamic_chain_locator_base = pm.annotate( self.dynamic_chain_locator_base, tx = self.prefix +'_dynamic_chain_base' )
		pm.rename(self.annotation_dynamic_chain_locator_base.getParent().name(), self.prefix + '_dynamic_chain_base_annotation')
		
		self.annotation_dynamic_chain_locator_tip = pm.annotate( self.dynamic_chain_locator_tip, tx = self.prefix +'_dynamic_chain_tip' )
		pm.rename(self.annotation_dynamic_chain_locator_tip.getParent().name(), self.prefix + '_dynamic_chain_tip_annotation')
		
		pm.select(cl = True)
		
		#Parent constrain annotation transforms
		pm.parentConstraint(self.dynamic_chain_locator_base, self.annotation_dynamic_chain_locator_base.getParent(), mo = False)
		pm.parentConstraint(self.dynamic_chain_locator_tip, self.annotation_dynamic_chain_locator_tip.getParent(), mo = False)
Example #19
0
def setNodeAxisVectors(node, oldA1="posY", oldA2="posX", newA1="posY", newA2="posX", orient=True):

    node = pm.PyNode(node)
    #these are world space vectors

    oldV1 = getNodeAxisVector(node, oldA1)
    oldV2 = getNodeAxisVector(node, oldA2)
    _logger.debug("%s vector: %s; %s vector: %s" % (oldA1, str(oldV1), oldA2, str(oldV2)))
    newV1 = g_vectorMap[newA1]
    newV2 = g_vectorMap[newA2]


    posL = pm.spaceLocator()
    aimL = pm.spaceLocator()
    upL = pm.spaceLocator()
    aimL.setParent(posL)
    upL.setParent(posL)
    pm.delete(pm.pointConstraint(node, posL, mo=False))

    aimL.translate.set(oldV1)
    upL.translate.set(oldV2)
    pm.delete(pm.aimConstraint(aimL, node, aimVector=newV1, upVector=newV2, worldUpType='object', worldUpObject=upL))
    pm.delete(posL)

    if orient:
        node.jox.set(node.jox.get() + node.rotateX.get())
        node.joy.set(node.joy.get() + node.rotateY.get())
        node.joz.set(node.joz.get() + node.rotateZ.get())
        node.rotate.set([0, 0, 0])
Example #20
0
def makeNodeSet(pointValueList, transNodeType):
    
    for x in pointValueList:
        if transNodeType == 'locator':
            pm.spaceLocator().t.set(x)
        else:
            pm.createNode(transNodeType).t.set(x)
Example #21
0
    def build(self):
        """builds it self
        """
        self.curve = curve(d=1, p=[(1, 0, 0), (-1, 0, 0)], k=(0, 1))
        self.corner1_locator = spaceLocator()
        self.corner2_locator = spaceLocator()
        select(self.curve)
        ClusterCurve()

        # try to find the clusterHandles
        curve_shape = curve.getShape()
        clusters = []
        handles = []
        for node in curve_shape.listHistroy():
            if isinstance(node, ClusterHandle):
                handles.append(node)
            elif isinstance(node, Cluster):
                clusters.append(node)

        self.cluster1 = clusters[0]
        self.cluster2 = clusters[0]

        self.cluster_handle1 = handles[0]
        self.cluster_handle2 = handles[1]

        # set clusters to absolute
        self.cluster1.setAttr('relative', 0)
        self.cluster2.setAttr('relative', 0)
Example #22
0
def makeNull():
    #pm.melGlobals.initVar( 'string[]', 'KinectSkelNames' )
    i = 0
    for i in range(0, 24):
        pm.spaceLocator(p=(0, 0, 0), n=KinectSkelNames[i])

    pm.spaceLocator(p=(0, 0, 0), n="KINECT_HAND")

    for i in range(0, 15):
        point[i] = [0.0, 0.0, 0.0]

    makeSkel()

    for i in range(0, 15):
        pm.rename('joint' + str(i + 1), KinectSkelJoints[i] + '_jt')

    for i in range(0, 15):
        pm.pointConstraint(KinectSkelJoints[i], KinectSkelJoints[i] + '_jt')
        pm.orientConstraint(KinectSkelJoints[i], KinectSkelJoints[i] + '_jt')

#Create Camera
    cam = pm.camera()[1]
    #print pm.camera(cam, query=True, aspectRatio=True)
    cam.setAspectRatio(3)
    print cam.getAspectRatio()
Example #23
0
    def createDrivers(self):
        # surfaceRbn_BS = surfaceRbn.duplicate()[0]
        # surfaceRbn_BS.rename(name + '_BS')
        # surfaceRbn_BS.translateX.set(segments * 0.5 )
        # blendshapeNode = pm.blendShape(surfaceRbn_BS,surfaceRbn,name=surfaceRbn.name() + '_blendShape')[0]
        # blendshapeNode.attr(surfaceRbn_BS.name()).set(1)

        startLocator = pm.spaceLocator(name=self.name + '_start_loc')
        startLocatorGrp = pm.group(startLocator, name=startLocator.name() + '_grp')
        startLocatorGrp.translate.set(self.start)

        midLocator = pm.spaceLocator(name=self.name + '_mid_loc')
        midLocatorGrp = pm.group(midLocator, name=midLocator.name() + '_grp')

        endLocator = pm.spaceLocator(name=self.name + '_end_loc')
        endLocatorGrp = pm.group(endLocator, name=endLocator.name() + '_grp')
        endLocatorGrp.translate.set(self.end)

        self.rbnLocs.append(startLocator)
        self.rbnLocs.append(midLocator)
        self.rbnLocs.append(endLocator)
        #
        pm.pointConstraint(startLocator, endLocator, midLocatorGrp)

        self.rbnLocGrp = pm.group([startLocatorGrp, midLocatorGrp, endLocatorGrp], n=self.name + '_drv_loc_grp')
        #
        #
        curveDrv = pm.curve(d=2, p=[self.start, (0, 0, 0), self.end], k=[0, 0, 1, 1])
        curveDrv.rename(self.name + '_wire_crv')
        self.wireCrv = curveDrv
        wireSrf = pm.duplicate(self.rbnSrf, name=self.name + '_wire_srf')[0]

        wireDef = pm.wire(wireSrf, w=curveDrv, en=1, gw=False, ce=0, li=0, dds=[(0, 20)], n=self.name + '_wire')
Example #24
0
 def createNoiseControl(self):
     # Create locator
     control = '%s%s'%(self.camera, self._CONTROL_SUFIX)
     pc.spaceLocator(n=control)
     # Create attribute for turning noise on/off
     pc.addAttr(ln='NOISE_SWITCH', k=False, at='enum', en='-:')
     pc.setAttr('%s.NOISE_SWITCH'%control, lock=True, cb=True)
     pc.addAttr(ln='Noise', k=False, at='enum', en='Off:On:')
     pc.setAttr('%s.Noise'%control, 1, cb=True)
     # Create translation noise attributes: frequency, amplitude (x, y, z), jitter and seed
     for noise_type in ['T', 'R']:
         nname = 'TRANSLATION' if noise_type == 'T' else 'ROTATION'
         pc.addAttr(ln='%s_NOISE'%nname, k=False, at='enum', en='-:')
         pc.setAttr('%s.%s_NOISE'%(control, nname), lock=True, cb=True)
         for axis in ['X', 'Y', 'Z']:
             pc.addAttr(ln='Frequency_%s%s'%(noise_type, axis), k=True, at='double', min=0)
             pc.addAttr(ln='Amplitude_%s%s'%(noise_type, axis), k=True, at='double', min=0)
         pc.addAttr(ln='Jitter_%s'%noise_type, k=True, at='double', min=0)
         pc.addAttr(ln='Seed_%s'%noise_type, k=False, at='short', dv=random.randint(0, 9999))
         pc.setAttr('%s.Seed_%s'%(control, noise_type), cb=True)
     # Create extra attributes for camera position offset
     pc.addAttr(ln='CAM_OFFSET', k=False, at='enum', en='-:')
     pc.setAttr('%s.CAM_OFFSET'%control, lock=True, cb=True)
     for axis in ['X', 'Y', 'Z']:
         pc.addAttr(ln='Offset_%s'%axis, k=True, at='double')
     return control
def makeNull():
	#pm.melGlobals.initVar( 'string[]', 'KinectSkelNames' )
	i=0
	for i in range(0,24):
		pm.spaceLocator(p=(0, 0, 0),n=KinectSkelNames[i])
		
	pm.spaceLocator(p=(0, 0, 0),n="KINECT_HAND")
	

	for i in range(0,15):
		point[i] = [0.0,0.0,0.0]

	makeSkel()
	
	for i in range(0,15):
	    pm.rename('joint'+str(i+1), KinectSkelJoints[i]+'_jt')

		
	for i in range(0,15):
	    pm.pointConstraint( KinectSkelJoints[i], KinectSkelJoints[i]+'_jt' )
	    pm.orientConstraint( KinectSkelJoints[i], KinectSkelJoints[i]+'_jt' )

    #Create Camera
	cam = pm.camera()[1]
	#print pm.camera(cam, query=True, aspectRatio=True)
	cam.setAspectRatio(3)
	print cam.getAspectRatio()
Example #26
0
    def _ctrlDBL(self, controls):
        
        pmc.undoInfo(openChunk=True)
        
        if controls == []:
            controls = pmc.ls(sl=True)

        for control in controls:
            control_roo = pmc.xform(control, q=True, roo=True)
            control_mtx = pmc.xform(control, q=True, m=True, ws=True)
            control_parent = pmc.listRelatives(control, p=True)
            pmc.select(cl=True)
            
            locdbl_parent = pmc.spaceLocator(n='locDBL_parent_' + control)
            locdbl_offset = pmc.spaceLocator(n='locDBL_offset_' + control)

            pmc.xform(locdbl_parent, ws=True, m=control_mtx)
            pmc.xform(locdbl_offset, ws=True, m=control_mtx)
                
            pmc.parent(locdbl_offset, locdbl_parent)
            pmc.parent(locdbl_parent, control_parent)
            pmc.parent(control, locdbl_offset)
            
            if control_roo == 'xyz':
                pmc.xform(locdbl_offset, roo='zyx')
            if control_roo == 'yzx':
                pmc.xform(locdbl_offset, roo='xzy')        
            if control_roo == 'zxy':
                pmc.xform(locdbl_offset, roo='yxz')        
            if control_roo == 'xzy':
                pmc.xform(locdbl_offset, roo='yzx')
            if control_roo == 'yxz':
                pmc.xform(locdbl_offset, roo='zxy')            
            if control_roo == 'zyx':
                pmc.xform(locdbl_offset, roo='xyz')
                            
            md_trns = pmc.createNode('multiplyDivide', n='mdTRNS_locDBL_' + control)
            md_rot = pmc.createNode('multiplyDivide', n='mdROT_locDBL_' + control)
            md_scl = pmc.createNode('multiplyDivide', n='mdSCL_locDBL_' + control)
            
            pmc.setAttr(md_trns + '.input1', [-1,-1,-1])
            pmc.setAttr(md_rot.input1, [-1,-1,-1])
            pmc.setAttr(md_scl.input1, [ 1, 1, 1])
            pmc.setAttr(md_scl.operation, 2)

            
            pmc.connectAttr(control + '.translate', md_trns + '.input2')
            pmc.connectAttr(control + '.rotate', md_rot + '.input2')
            pmc.connectAttr(control + '.scale', md_scl + '.input2')
            
            pmc.connectAttr(md_trns + '.output', locdbl_offset + '.translate')
            pmc.connectAttr(md_rot + '.output', locdbl_offset + '.rotate')
            pmc.connectAttr(md_scl + '.output', locdbl_offset + '.scale')
            
            pmc.setAttr(locdbl_parent + 'Shape.visibility', 0)
            pmc.setAttr(locdbl_offset + 'Shape.visibility', 0)
            
        pmc.undoInfo(closeChunk=True)
Example #27
0
def directPlacementMode(card):

    assert len(card.joints) == 3

    grp = group(em=True, n='DirectPlacement_Deletable')

    ctrls = []
    for bpj in card.joints:
        ctrl = tempWidget()
        pdil.dagObj.matchTo(ctrl, bpj)
        ctrls.append(ctrl)
        ctrl.setParent(grp)

    base, up, aim = ctrls

    aimLoc = spaceLocator()
    aimLoc.setParent(aim)
    aimLoc.t.set(0, 0, 0)

    baseLoc = spaceLocator()
    baseLoc.setParent(base)
    baseLoc.t.set(0, 0, 0)

    dist = distanceDimension(baseLoc, aimLoc)
    dist.getParent().setParent(grp)
    hide(dist)

    pointConstraint(base, card, mo=True)

    aimConstraint(aim,
                  card,
                  wut='object',
                  wuo=up,
                  aim=[0, -1, 0],
                  u=[0, 0, -1],
                  mo=True)

    # save base dimension
    # current dimesion / base dimension
    # multiply x, z by card's existing scale

    dist.addAttr('baseDist', at='double', dv=dist.distance.get())

    scaled = pdil.math.divide(dist.distance, dist.baseDist)

    mult = createNode('multiplyDivide')

    scaled >> mult.input1X
    scaled >> mult.input1Y
    scaled >> mult.input1Z

    mult.input2Y.set(card.sy.get())
    mult.input2Z.set(card.sz.get())

    mult.outputY >> card.sy
    mult.outputZ >> card.sz

    pointConstraint(up, card.joints[1], sk='x')
Example #28
0
    def FKIK_query_guide_orient(self, *args):
        print 'Querying the rotations of the guides which were placed.'
        POS_list = self.FKIK_query_guide_translation()

        # TODO:
        #     Replace all this code with something a little
        #     more elegant.

        #     Likely something with OpenMaya for querying the
        #     actual vectors and orientations of the objects
        #     in world space?

        #     Using cross products to determine the correct
        #     planar relationships between guide positions.

        A_LOC = pm.spaceLocator()
        B_LOC = pm.spaceLocator()
        C_LOC = pm.spaceLocator()

        if self.debugging: print 'Created:', A_LOC, B_LOC, C_LOC

        A_LOC.setTranslation(POS_list[0])
        B_LOC.setTranslation(POS_list[1])
        C_LOC.setTranslation(POS_list[2])

        A_orient = pm.aimConstraint(B_LOC,
                                    A_LOC,
                                    aimVector=[1, 0, 0],
                                    upVector=[0, 1, 0],
                                    worldUpType='object',
                                    worldUpObject=C_LOC)
        B_orient = pm.aimConstraint(C_LOC,
                                    B_LOC,
                                    aimVector=[1, 0, 0],
                                    upVector=[0, 1, 0],
                                    worldUpType='object',
                                    worldUpObject=A_LOC)
        C_orient = pm.aimConstraint(A_LOC,
                                    C_LOC,
                                    aimVector=[-1, 0, 0],
                                    upVector=[0, -1, 0],
                                    worldUpType='object',
                                    worldUpObject=B_LOC)

        A_value = A_LOC.getRotation()
        B_value = B_LOC.getRotation()
        C_value = C_LOC.getRotation()

        if not self.debugging:
            pm.delete(A_orient, B_orient, C_orient, A_LOC, B_LOC, C_LOC)

        else:
            print(
                'Successfully completed the creation and query of guide orientation'
            )
            print A_value, B_value, C_value

        return [A_value, B_value, C_value]
Example #29
0
def jointChainOrient( objs=[] ): # wip
    '''
    update : 2015-04-29
    '''
    if objs:
        pm.selec(objs)
    objs = pm.ls(sl=True, o=True)
    if not objs:
        raise

    joints = pm.ls(sl=True, type='joint')
    if not joints:
        raise

    upMeshs = []
    if pm.filterExpand(sm=12):    
        upMeshs = [pm.PyNode(c) for c in pm.filterExpand(sm=12) ] # 업축으로 사용할 메쉬

    # 조인트 오리엔트 조정: 메쉬의 가장 가까운 점의 노말을 조인트의 up으로 설정
    if upMeshs:
        for jnt in joints:
            parentJnt = jnt.getParent()
            if parentJnt:
                # point에서 가장 가까운 Vertex의 Normal을 up으로 설정
                pos   = parentJnt.getTranslation( ws=True)
                vtx   = getClosestVertexOnMesh( upMeshs[0], pos )
                pos   = vtx.getPosition()
                norm  = vtx.getNormal()
                upPos = pos + norm * 1000000 # 노말 위치가 가까우면 방향이 틀어져 버림.. 그래서 큰 수를 곱함.

                upLoc = pm.spaceLocator(n='parentJnt_upLoc#')
                upLoc.t.set( upPos )

                jntOrient( [parentJnt, jnt, upLoc] )
                #pm.joint( parentJnt, edit=True, zso=True, oj='xyz', sao='yup' )
                pm.delete( upLoc )

    else:
        for jnt in joints:
            parentJnt = jnt.getParent()
            if parentJnt and parentJnt.type()=='joint':
                print jnt
                up = pm.spaceLocator()

                grandParent = parentJnt.getParent()
                if grandParent and grandParent.type()=='joint':
                    pm.delete( pm.parentConstraint( grandParent, up ) )                    
                else:
                    pm.delete( pm.parentConstraint( parentJnt, up ) )

                jntOrient( [parentJnt, jnt, up], worldUpType='objectrotation' )
                pm.refresh()
                pm.select(jnt)
                pm.delete(up)

    # 끝 조인트 오리엔트 조정
    if len(joints)>1:    
        pm.joint( joints[-1], edit=True, oj='none' )
Example #30
0
def createLimbFootRollLocatorsReference(ankleJnt):
    prefix = name.removeSuffix(ankleJnt)
    frontLoc = pm.spaceLocator(n=prefix + '_frontRoll_LOC')
    backLoc = pm.spaceLocator(n=prefix + '_backRoll_LOC')
    innerLoc = pm.spaceLocator(n=prefix + '_innerRoll_LOC')
    outerLoc = pm.spaceLocator(n=prefix + '_outerRoll_LOC')
    locGrp = pm.group(frontLoc, backLoc, innerLoc, outerLoc, n=prefix+'FootRollLocators_GRP')

    return locGrp
def toony_jaw():
	grp = pm.group(n="ToonyJawSetup")
	toonyJaw = pm.spaceLocator(n="ToonyJaw_LOC",p=[0,4,0])
	toonyJawEnd = pm.spaceLocator(n="ToonyJawEnd_LOC",p=[0,-3,0])
	pm.parent([toonyJaw,toonyJawEnd],grp)
	locHier = pm.listRelatives(grp,c=True)
	for i in range(len(locHier)):
		pm.xform(locHier[i],cp=True)
	pm.parent(toonyJawEnd,toonyJaw)
Example #32
0
def bdSwitchParent():
	selection = pm.ls(sl=1,type='transform')
	if selection:
		ctrl = selection[0]
		try:
			currentParent = ctrl.attr('Parent').get()
		except:
			pm.warning('Current selection has no Parent attribute, aborting!')
			return
		print currentParent 
		switchFrame = pm.currentTime(q=1)
		
	
		pm.currentTime(switchFrame-1,e=1)
		pm.setKeyframe(ctrl)
		pm.currentTime(switchFrame,e=1)

		#World Parent
		if currentParent == 1:
			print 'Frow World to hand'
			tempLoc = pm.spaceLocator(n='temp')
			tempCnstr = pm.parentConstraint(ctrl,tempLoc)
			pm.delete(tempCnstr)

			ctrl.attr('Parent').set(0)

			worldPos = tempLoc.getTranslation(space='world')
			worldRot = tempLoc.getRotation(space='world')


			ctrl.setTranslation(worldPos,space='world')
			ctrl.setRotation(worldRot,space='world')
			
			pm.delete(tempLoc)
			pm.setKeyframe(ctrl )

		else :
			print 'From hand to world'
			tempLoc = pm.spaceLocator(n='temp')
			tempCnstr = pm.parentConstraint(ctrl,tempLoc)
			pm.delete(tempCnstr)

			ctrl.attr('Parent').set(1)

			worldPos = tempLoc.getTranslation(space='world')
			worldRot = tempLoc.getRotation(space='world')


			ctrl.setTranslation(worldPos,space='world')
			ctrl.setRotation(worldRot,space='world')
			
			pm.delete(tempLoc)
			pm.setKeyframe(ctrl )


	else:
		pm.warning('Select a ticket ctrl or the pound bill ctrl')
Example #33
0
 def guide(self):
     """Implement guide method"""
     self.guide_base = pm.spaceLocator(n='%s_base_guide_srt' % self.name)
     self.guide_tip = pm.spaceLocator(n='%s_tip_guide_srt' % self.name)
     self.guide_tip.ty.set(1)
     pm.parent(self.guide_base, self.guide_tip, self.guide_grp)
     scale = maya_math.get_bb_size(cmds.ls(type='mesh')) * 0.5
     self.guide_base.getShape().localScale.set(scale, scale, scale)
     self.guide_tip.getShape().localScale.set(scale, scale, scale)
Example #34
0
    def poleVector_direction(self):
        start = pm.xform(self.topJoint, q=1, ws=1, t=1)
        mid = pm.xform(self.halfJoint, q=1, ws=1, t=1)
        end = pm.xform(self.targetJoint, q=1, ws=1, t=1)

        #get postion of joints
        startV = OpenMaya.MVector(start[0], start[1], start[2])
        midV = OpenMaya.MVector(mid[0], mid[1], mid[2])
        endV = OpenMaya.MVector(end[0], end[1], end[2])
        #get vectors from start to end and start to mid
        startEnd = endV - startV
        startMid = midV - startV
        #get the vector between
        dotP = startMid * startEnd
        #get pole vector position
        projLen = float(dotP) / float(startEnd.length())
        startEndN = startEnd.normal()
        projV = startEndN * projLen
        arrowV = startMid - projV
        finalV = arrowV + midV

        cross1 = startEnd - startMid
        cross1.normalize()
        cross2 = cross1 ^ arrowV
        cross2.normalize()
        arrowV.normalize()

        matrixV = [
            arrowV.x, arrowV.y, arrowV.z, 0, cross1.x, cross1.y, cross1.z, 0,
            cross2.x, cross2.y, cross2.z, 0, 0, 0, 0, 1
        ]

        matrixM = OpenMaya.MMatrix()

        OpenMaya.MScriptUtil.createMatrixFromList(matrixV, matrixM)
        matrixFn = OpenMaya.MTransformationMatrix(matrixM)
        rot = matrixFn.eulerRotation()

        self.loc = pm.spaceLocator(name="%s_DELLOC" % self.grpRig)
        self.locMov = pm.spaceLocator(name="%s_DELLOCPARENT" % self.grpRig)
        self.locMov.setParent(self.loc)
        pm.xform(self.loc, ws=1, t=(finalV.x, finalV.y, finalV.z))
        pm.xform(self.loc,
                 ws=1,
                 rotation=((rot.x / math.pi * 180.0),
                           (rot.y / math.pi * 180.0),
                           (rot.z / math.pi * 180.0)))

        self.locMov.translateX.set(self.offset)
        pm.delete(
            pm.pointConstraint(self.locMov,
                               self.grpMcNul,
                               maintainOffset=False))
        self.grpMcNul.translateX.set(0)
        self.grpMcNul.translateZ.set(0)
        pm.delete(self.loc)
Example #35
0
def create_loc(source_node, target_loc):
    """ Creates a locator to given source nodes position and name it with target_loc
    :param source_node: source node is given to move the locators position
    :param target_loc: name of the locator and locator's group
    :return: locator's group name
    """
    pm.spaceLocator(n=target_loc)
    loc_grp = pm.group(target_loc, n=target_loc + '_grp')
    pm.xform(loc_grp, t=source_node)
    return loc_grp
Example #36
0
def create_loc(source_pos, target_loc):
    """ Creates a locator to given source nodes position and name it with target_loc
    :param source_pos: float array, position of the source node
    :param target_loc: str, target loc name
    :return: str, loc_grp locator's group name
    """
    pm.spaceLocator(n=target_loc)
    loc_grp = pm.group(target_loc, n=target_loc + '_grp')
    pm.xform(loc_grp, t=source_pos)
    return loc_grp
Example #37
0
    def test_distance(self):

        import pymel.core as pmc
        loc1 = pmc.spaceLocator()
        loc2 = pmc.spaceLocator()
        loc2.tx.set(10.0)

        self.assertEquals(Distance(loc1.translate, loc2.translate).get(), 10.0)
        self.assertEquals(
            Distance(loc1.worldMatrix, loc2.worldMatrix).get(), 10.0)
Example #38
0
	def setupHandBehavior(self):
		"""
		Main proc for creating the IK / FK arm switch
		"""
		handRootNode =  pm.PyNode(self.side + '_hand0_jnt')
		handRootPos = handRootNode.getTranslation('world')

		# create locators for the blending FK/IK arm and groups.
		# to set hand position into the right place
		orientFKLoc = pm.spaceLocator(name=self.side + '_armFKOrient_loc')
		orientIKLoc = pm.spaceLocator(name=self.side + '_armIKOrient_loc')

		orientFKGrp = pm.group(name=self.side + '_armFKOrient_grp', em=True)
		orientIKGrp = pm.group(name=self.side + '_armIKOrient_grp', em=True)

		locFKShape = pm.listRelatives(orientFKLoc, s=1)[0]
		locIKShape = pm.listRelatives(orientIKLoc, s=1)[0]

		# setup a smaller locator and move it to the wrist joint (handRoot)
		for loc in [locFKShape, locIKShape]:
			for scale in ['.localScaleX', '.localScaleY', '.localScaleZ']:
				pm.setAttr(loc + scale, 0.0005)

			pm.move(loc, (handRootPos[0], handRootPos[1], handRootPos[2]))

		# parent each locator to the corresponding group
		for loc, grp in zip([orientFKLoc, orientIKLoc], [orientFKGrp, orientIKGrp]):
			pm.parent(loc, grp)

		# parent each locator group (IK and FK) to the right place
		pm.parent(orientFKGrp, self.side + '_arm1_jnt')
		pm.parent(orientIKGrp, self.side + '_arm_ik_ctrl')

		self.handOrientConst = pm.orientConstraint(orientIKLoc, orientFKLoc, self.side + '_hand_grp')

		# pointConstraint blend arm joint and handGrp
		pm.pointConstraint(self.side + '_arm2_jnt', self.side + '_hand_grp')

		# connect orientConstraint weights to handCtrl to be able to switch the weights from the FK/IK attribute
		pm.connectAttr(self.side + '_hand_ctrl.FK_IK',
					   self.handOrientConst + '.' + self.side + '_armFKOrient_locW1')
		handReverseNode = pm.createNode('reverse', name=self.side + '_handRev')

		pm.connectAttr(self.side + '_hand_ctrl.FK_IK', handReverseNode + '.input.inputX')
		pm.connectAttr(handReverseNode + '.output.outputX',
					   self.handOrientConst + '.' + self.side + '_armIKOrient_locW0')

		# orient constraint hand module with the bind joints
		#pm.orientConstraint(self.side + '_hand_IK_jnt', self.side + '_hand0_jnt', mo=True)
		pm.parent(self.side + '_arm_limb_ikh',self.side + '_arm_ik_ctrl')

		pm.parent(self.side + '_hand_grp', 'main_ctrl')

		rigUtils.hideAttributes(ctrl=self.side + '_hand_ctrl', trans=True, scale=False, rot=False, vis=True, radius=False)
Example #39
0
def makeLocators():
    jointnamelist = []
    jointnamelist.append(pm.textField(thigh, q=True, tx=True))
    jointnamelist.append(pm.textField(leg, q=True, tx=True))
    jointnamelist.append(pm.textField(ancle, q=True, tx=True))
    jointnamelist.append(pm.textField(foot, q=True, tx=True))
    jointnamelist.append(pm.textField(toe, q=True, tx=True))
    jointnamelist.append(pm.textField(heel, q=True, tx=True))
    for jnt in jointnamelist:
        pm.spaceLocator(n=jnt)
    return jointnamelist
def nose_setup():
	l_noseLoc = pm.spaceLocator(n="SneerLoc_L",p=[0.5,3,0])
	r_noseLoc = pm.spaceLocator(n="SneerLoc_R",p=[-0.5,3,0])
	muzzleLoc = pm.spaceLocator(n="MuzzleLoc",p=[0,5.5,0])
	noseGrp = pm.group(n="NoseSetup")
	pm.parent([l_noseLoc,r_noseLoc],noseGrp)
	noseGrpHier = pm.listRelatives(noseGrp,c=True)
	for i in range(len(noseGrpHier)):
		pm.xform(noseGrpHier[i]	,cp=True)
		
	pm.select(cl=True)
Example #41
0
def curve_drive(curve):
	grp_crv = 'curveDrive_GRP'
	sel = pm.ls(sl=True)
	for obj in sel:
		if curve.getShape().type() == 'nurbsCurve':
			CPOC = curve.closestPoint(obj.t.get())
			if not pm.objExists(grp_crv):
				grp = pm.group(em=True,n=grp_crv)
				grp.visibility.set(0)
			print curve, CPOC
			pm.spaceLocator(p=CPOC)
Example #42
0
 def __init__(self, nameObj, textObj, positionObj=[], scaleObj=[]):
     self.nameObj = nameObj
     self.textObj = textObj
     self.positionObj = positionObj
     self.scaleObj = scaleObj
     pm.spaceLocator(n=self.textObj)
     #pm.xform( self.textObj, cp=True)
     pm.xform(self.textObj,
              r=True,
              t=(self.positionObj[0], self.positionObj[1],
                 self.positionObj[2]))
Example #43
0
def create_radian_trigger(prefix):
    prefix = ("%s_radianTrigger") %prefix

    display = pm.group(empty=True, name="%s_display" %prefix)
    display.overrideEnabled.set(1)
    display.overrideDisplayType.set(2)
        
    grp = pm.group(empty=True, name="%s_grp" %prefix)
    loc = pm.spaceLocator(name = "%s_target" %prefix)
    pm.addAttr(loc, at='double', ln="radical", k=True)
    pm.addAttr(loc, at='double', ln="angle", k=True)
    
    pos = pm.spaceLocator(name = "%s_pos" %prefix)
    
    loc.ty.set(1)
    loc.tz.set(1)
    pos.tz.set(1)    

    radical_exp = '%s.radical = rad_to_deg( atan2(  %s.translateY , %s.translateX ) )' %(loc.name(), loc.name(), loc.name())
    angle_exp = "%s.angle = rad_to_deg( acos( %s.translateZ / (sqrt( pow(%s.translateX, 2) + pow(%s.translateY, 2) + pow(%s.translateZ, 2) ) ) ) )" %(loc.name(), loc.name(), loc.name(), loc.name(), loc.name())
    pm.expression( o=loc, s= radical_exp, name="%s_radical_exp" %prefix)
    pm.expression( o=loc, s= angle_exp, name="%s_angle_exp" %prefix)
    
    planer_curve = "curve -d 1 -p 0 0 0 -p -1 0 0 -p -0.965926 0.258819 0 -p -0.765926 0.258819 0 -p -0.865926 0.258819 0 -p -0.865926 0.358819 0 -p -0.865926 0.158819 0 -p -0.865926 0.258819 0 -p -0.965926 0.258819 0 -p -0.866025 0.5 0 -p -0.707107 0.707107 0 -p -0.353553 0.353553 0 -p -0.707107 0.707107 0 -p -0.5 0.866025 0 -p -0.258819 0.965926 0 -p 0 1 0 -p 0 0.5 0 -p 0 1 0 -p 0.258819 0.965926 0 -p 0.5 0.866025 0 -p 0.707107 0.707107 0 -p 0.353553 0.353553 0 -p 0.707107 0.707107 0 -p 0.866025 0.5 0 -p 0.965926 0.258819 0 -p 1 0 0 -p 0.5 0 0 -p 1 0 0 -p 0.965926 -0.258819 0 -p 0.866025 -0.5 0 -p 0.707107 -0.707107 0 -p 0.353553 -0.353553 0 -p 0.707107 -0.707107 0 -p 0.5 -0.866025 0 -p 0.258819 -0.965926 0 -p 0 -1 0 -p 0 -0.5 0 -p 0 -1 0 -p -0.258819 -0.965926 0 -p -0.5 -0.866025 0 -p -0.707107 -0.707107 0 -p -0.353553 -0.353553 0 -p -0.707107 -0.707107 0 -p -0.866025 -0.5 0 -p -0.965926 -0.258819 0 -p -0.765926 -0.258819 0 -p -0.965926 -0.258819 0 -p -1 0 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 18 -k 19 -k 20 -k 21 -k 22 -k 23 -k 24 -k 25 -k 26 -k 27 -k 28 -k 29 -k 30 -k 31 -k 32 -k 33 -k 34 -k 35 -k 36 -k 37 -k 38 -k 39 -k 40 -k 41 -k 42 -k 43 -k 44 -k 45 -k 46 -k 47"
    planer = pm.PyNode(pm.mel.eval(planer_curve))
    planer.rename("%s_planer" %prefix)

    arrow_curve = 'curve -d 1 -p 0 0 0 -p 0 0.377909 0 -p -0.0449662 0.378085 0 -p 0 0.460303 0 -p 0.0449662 0.378085 0 -p 0 0.377909 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 ;'
    arrow = pm.PyNode(pm.mel.eval(arrow_curve))
    pm.makeIdentity(arrow, apply=True, t=True, r=True, s=True)    
    arrow.rename("%s_arrow" %prefix)

    angle_curves = pm.circle(name="%s_angleCurve" %prefix, r=0.5)
    pm.aimConstraint(pos, angle_curves[0], mo=False, aimVector=[0,1,0], upVector=[-1,0,0], worldUpType='object', worldUpObject=loc)
    pm.parent(arrow, angle_curves)
    
    loc.angle >> angle_curves[-1].sweep

    posPointer = pm.curve(name='%s_posPointer'%prefix, d = 1, p = [(0,0,0), (0,0,1)])

    pointer = pm.curve(name='%s_targetPointer'%prefix, d = 1, p = [(0,0,0), (0,0,0)])
    pointer.inheritsTransform.set(0)
    
    cls1 = pm.cluster(pointer.cv[0], name='%s_pointerClusterStart' %prefix)
    cls2 = pm.cluster(pointer.cv[1], name='%s_pointerClusterEnd' %prefix)
    
    pm.parent(pos, planer, angle_curves[0], cls1, pointer, posPointer, display)
    pm.parent(display, loc, grp)
    pm.parent(cls2, loc, r=True)
    
    cls1[1].v.set(0)
    cls2[1].v.set(0)
    pos.v.set(0)
def placeHighLight(*args):
    ### UI setup 
    global UI_name
    UI_name = [ 'txtBtn_light', 'txtBtn_camera', 'txtBtn_object', 'txtBtn_HLitPoint', 'btn_placeHLit', 'chk_interaction' ]
    
    if pm.window( 'winPlaceHLit', exists=True ):
        pm.deleteUI( 'winPlaceHLit', window=True )
        
    ui_layout['window'] = pm.window( 'winPlaceHLit', title='Place Highlight', sizeable=False, h=100, w=250 )
    ui_layout['mainLayout'] = pm.columnLayout( columnAlign='left', columnAttach=['left', 0] )
    
    #// get active camera
    activeViewCamera = getActiveCam()
    
    '''loc_light_probe = pm.createNode('locator', name='light_probe')
    pm.lockNode(loc_light_probe, lock=False)'''

    #// sub layout
    #// sub1
    ui_layout['ui_sub1'] = pm.rowLayout(nc=2, cw=[(1, 210), (2, 40)], p=ui_layout['mainLayout'] )
    pm.textFieldButtonGrp( UI_name[0], label='Light: ', text='', buttonLabel='Pick',editable=False, buttonCommand='pickLit()', cw=[(1,50), (2,120), (3,40)], p=ui_layout['ui_sub1'] )
    pm.button( 'btn_sel_light' ,label='Sel', command=pm.Callback( doSelItem, UI_name[0] ), p=ui_layout['ui_sub1'] )
    
    #// sub2
    ui_layout['ui_sub2'] = pm.rowLayout(nc=2, cw=[(1, 210), (2, 40)], p=ui_layout['mainLayout'] )
    pm.textFieldButtonGrp( UI_name[1], label='Camera: ', text=activeViewCamera, buttonLabel='Pick', editable=False, buttonCommand='pickCam()', cw=[(1,50), (2,120), (3,40)], p=ui_layout['ui_sub2'] )
    pm.button( 'btn_sel_camera' ,label='Sel', command=pm.Callback( doSelItem, UI_name[1] ), p=ui_layout['ui_sub2'] )
    
    #// sub3
    ui_layout['ui_sub3'] = pm.rowLayout(nc=2, cw=[(1, 210), (2, 40)], p=ui_layout['mainLayout'] )
    pm.textFieldButtonGrp( UI_name[2], label='Object: ', text='', buttonLabel='Pick', editable=False, buttonCommand='pickTgtObj()', cw=[(1,50), (2,120), (3,40)], p=ui_layout['ui_sub3'] )
    pm.button( 'btn_sel_obj' ,label='Sel', command=pm.Callback( doSelItem, UI_name[2] ), p=ui_layout['ui_sub3'] )
    
    #// sub4
    ui_layout['ui_sub4'] = pm.rowLayout(nc=2, cw=[(1, 210), (2, 40)], p=ui_layout['mainLayout'] )    
    pm.textFieldButtonGrp( UI_name[3], label='Point: ', text='', buttonLabel='Pick', editable=False, buttonCommand='pickHLitPt()', cw=[(1,50), (2,120), (3,40)], p=ui_layout['ui_sub4'] )
    pm.button( 'btn_sel_point' ,label='Sel', command=pm.Callback( doSelItem, UI_name[3] ), p=ui_layout['ui_sub4'] )
    
    #// sub5
    ui_layout['ui_sub5'] = pm.rowLayout(nc=2, cw=[(1, 70), (2, 50)], p=ui_layout['mainLayout'] )
    pm.button( UI_name[4] ,label='Place Light!', command='doPlaceHLight()', p=ui_layout['ui_sub5'] )    
    pm.checkBox( UI_name[5], label='interactive mode', onCommand=pm.Callback( doInteractionON ), offCommand=pm.Callback( doInteractionOFF ), p=ui_layout['ui_sub5'] )
    
    
    pm.showWindow( ui_layout['window'] )
    
    pm.spaceLocator( name='light_probe' )
    pm.lockNode( 'light_probe', lock=True )
    pm.textFieldButtonGrp( 'txtBtn_HLitPoint', edit=True, text='light_probe' )
    
    #// clean make live and scriptJob after exit script
    pm.scriptJob( uiDeleted=[ ui_layout['window'], pm.Callback( flushScript ) ] )
Example #45
0
	def createPoleVectorLocatorAndLinkingCurve(self):
	
		pm.select(cl = True)
		
		#PoleVector
		#----------------------------------------------------
		
		#Create leg ik pole vector loc
		self.leg_ik_pole_vector_locator = pm.spaceLocator(n = self.prefix +'_leg_ik_pole_vector_locator')
		pm.select(cl = True)
		
		#Group leg ik pole vec
		self.leg_ik_pole_vector_locator_grp = pm.group(self.leg_ik_pole_vector_locator, n = self.prefix + '_leg_ik_pole_vector_locator_grp')
		pm.select(cl = True)
		
		#Translate leg_ik_pole_vector_locator_grp
		self.leg_ik_pole_vector_locator_grp.translate.set(self.leg_locator_poleVector_worldCoords)
		
		
		
		#LinkingCurve
		#----------------------------------------------------
		
		#Create linking curve loc
		self.leg_ik_pole_vector_locator_linking_curve_locator = pm.spaceLocator(n = self.prefix +'_leg_ik_pole_vector_locator_linking_curve_locator')
		pm.select(cl = True)
		
		#point con linking curve loc to leg ik j base
		pm.pointConstraint(self.leg_ik_j_base, self.leg_ik_pole_vector_locator_linking_curve_locator , mo = False)
		
		
		#Create Pole vector Linking Curve
		self.pole_vector_linking_curve = pm.curve(p = [self.leg_locator_base_worldCoords , self.leg_locator_poleVector_worldCoords], d = 1, n = self.prefix +'_pole_vector_linking_curve')
		pm.select(cl = True)
		
		#make curve not selectable
		pm.setAttr(self.pole_vector_linking_curve.getShape().overrideEnabled, 1)
		pm.setAttr(self.pole_vector_linking_curve.getShape().overrideDisplayType, 2)
		pm.select(cl = True)
		
		#Connect loc world space coords to curve points
		self.leg_ik_pole_vector_locator_linking_curve_locator.getShape().worldPosition[0] >> self.pole_vector_linking_curve.getShape().controlPoints[0]
		self.leg_ik_pole_vector_locator.getShape().worldPosition[0] >> self.pole_vector_linking_curve.getShape().controlPoints[1]
		pm.select(cl = True)
		
		#Create grp
		self.pole_vector_linking_curve_grp = pm.group( n = self.prefix +'_pole_vector_linking_curve_grp')
		pm.select(cl = True)
		
		#parent objects in group
		pm.parent(self.leg_ik_pole_vector_locator_linking_curve_locator, self.pole_vector_linking_curve ,self.pole_vector_linking_curve_grp)
		pm.select(cl = True)
Example #46
0
def getAimUpAxis( originObj, aimObj, upObj):
    '''originObj기준의 aim축과 up축을 리턴함.
    자동으로 aimVector와 upVector를 파악
    '''

    originObj = pm.PyNode(originObj)
    aimObj    = pm.PyNode(aimObj)
    upObj     = pm.PyNode(upObj)

    o = pm.spaceLocator()
    a = pm.spaceLocator()
    u = pm.spaceLocator()
    snap( originObj, o, type='parent' )
    snap( aimObj,    a, type='parent' )
    snap( upObj,     u, type='parent' )

    # getAimVec
    pm.parent( a, o)
    aim_translate = a.t.get()                                       # child의 위치값으로 확인 하려고 함.
    pm.parent( a, w=True )

    aim_abs = pm.dt.Vector( [abs(item) for item in aim_translate] ) # 절대값으로 조정
    aim_id = aim_abs.index( aim_abs.max() )[0]                      # 절대값중 값이 큰 id
    aim_sign = -1.0 if aim_translate[aim_id]<0 else 1               # 음수인지 양수인지 확인
    aimVector = pm.dt.Vector(0,0,0)
    aimVector[ aim_id ] = aim_sign

    # 오리진 축 조정
    tmpUpVec = pm.dt.Vector(0,1,0) if not aimVector==pm.dt.Vector(0,1,0) else pm.dt.Vector(0,1,0) # 이부분 다시 생각해볼것
    tmpWoldUpObj = pm.spaceLocator()
    snap( o, tmpWoldUpObj, type='parent' )
    tmpWoldUpObj.translateBy( tmpUpVec , space='preTransform' )
    pm.delete( pm.aimConstraint( a, o, aim=aimVector, u=tmpUpVec, wuo=tmpWoldUpObj, wut='object'  ) )

    # getUpVec
    pm.parent( u, o)
    up_translate = u.t.get()
    pm.parent( u, w=True )
    up_translate[aim_id] = 0.0                                    # aim축 값은 무시, 겹치는 방향은 무용지물.

    up_abs = pm.dt.Vector( [abs(item) for item in up_translate] ) # 절대값으로 조정
    up_id = up_abs.index( up_abs.max() )[0]                       # 절대값중 값이 큰 id
    up_sign = -1.0 if up_translate[up_id]<0 else 1                # 음수인지 양수인지 확인
    upVector = pm.dt.Vector( 0,0,0 )
    upVector[ up_id ] = up_sign

    # 클린업
    pm.delete( o,a,u,tmpWoldUpObj )

    return aimVector, upVector
Example #47
0
    def buildGuides(self):
        """
        This function setups our guide system
        
        WILL PROBABLY BE ANOTHER CLASS WHEN WE EXPAND AS IT'S GOING TO BE COMPLEX
        """
        
        self.guides = []
        
        for i,p in enumerate(self.posArray):
            
            name = nameUtils.getUniqueName(self.baseNames[i],self.side,"GUIDE")
            loc = pm.spaceLocator(n=name)
            loc.t.set(p)
            loc.r.set(self.rotArray[i])
            self.guides.append(loc)
            
        tempGuides = list(self.guides)
        tempGuides.reverse()

        for i in range(len(tempGuides)):
            if i != (len(tempGuides)-1):
                pm.parent(tempGuides[i],tempGuides[i+1])
        
        name = nameUtils.getUniqueName(self.baseName+"_guides",self.side,"grp")
        self.guidesGrp = pm.createNode("transform",n=name)
        
        self.guides[0].setParent(self.guidesGrp)
Example #48
0
def lock(*args, **kwargs):
    if args:
        pm.select(args)
    sel = pm.ls(sl=True, o=True )

    t = kwargs.get('t', True)
    r = kwargs.get('r', True)

    locs=[]
    for item in sel:
        loc = pm.spaceLocator()
        loc.rename( 'lock_'+item )
        pm.delete( pm.parentConstraint( item, loc) )

        if t:
            skip = []
            for attr, axis in zip(['tx','ty','tz'],['x','y','z']):
                if pm.Attribute( item + '.' + attr).isLocked():
                    skip.append(axis)
            const = pm.pointConstraint(loc, item, skip=skip)
            pm.parent(const, loc)

        if r:
            skip = []
            for attr, axis in zip(['rx','ry','rz'],['x','y','z']):
                if pm.Attribute( item + '.' + attr).isLocked():
                    skip.append(axis)
            const = pm.orientConstraint(loc, item, skip=skip)
            pm.parent(const, loc)

        locs.append( loc )

    if sel:
        pm.select(locs)
Example #49
0
    def createCtrls(self):
        ctrlList = []
        crv = pm.ls(self.crv)[0]
        pm.select(cl=1)
        self.allCtrlGrp = pm.group(n=self.name + '_ctrl_grp')
        #
        pociNode = pm.shadingNode('pointOnCurveInfo',asUtility = 1)
        pociNode.turnOnPercentage.set(1)
        crv.getShape().worldSpace[0] >> pociNode.inputCurve
        tempLoc = pm.spaceLocator()
        pociNode.position >> tempLoc.translate
        
        segmentLength = 1.0 /( self.numCtrl - 1)

        for i in range(self.numCtrl):
            pociNode.parameter.set(i*segmentLength)
            pos = tempLoc.getTranslation(space='world')
        
            ctrl = self.addCtrl(i)
            self.ctrlList.append(ctrl)
            ctrlMainGrp  = self.getCtrlMainGrp(ctrl)
            ctrlMainGrp.setTranslation(pos)
            pm.parent(ctrlMainGrp,self.allCtrlGrp)
            
        pm.parent(self.allCtrlGrp,self.mainGrp)

        pm.delete([tempLoc,pociNode])
Example #50
0
 def makeLoc(obj=None):
     # Place locator as child to jnt and zero it
     loc = pm.spaceLocator()
     pm.parent(loc, obj)
     loc.setTranslation(0)
     loc.setRotation([0, 0, 0])
     return loc
Example #51
0
    def test_build_joint_chain(self):
        reg_node, chain = utils.build_joint_chain(name='temp',
                                                  crv=self.crv,
                                                  order='xyz',
                                                  num=10,
                                                  loc=self.loc)

        # Confirm right number of joints
        self.assertEqual(len(chain), 10)

        # Confirm expected names
        self.assertEqual([x.name() for x in chain],
                         ['temp_Jnt_%s' % (x+1) for x in range(10)])

        # Check positions match input curves'
        for jnt, pos in zip(chain, self.positions):
            self.assertTrue(transforms.assertLocationIs(jnt, pm.dt.Point(pos)))

        # Check aim axis is x
        for jnt in chain[:-1]:
            self.assertTrue(joints.assertAimAxis(jnt, 'x'))

        # Check for reg_node connection
        self.assertEqual(reg_node.temp_chain_root.listConnections()[0],
                         chain[0])

        # Check y axis pointing backwards (x, y, -1)
        for jnt in chain:
            loc = pm.spaceLocator()
            pm.delete(pm.parentConstraint(jnt, loc, mo=0))
            pm.move(loc, 0, 0, -1, r=1)
            pos = pm.xform(loc, q=1, ws=1, rp=1)
            self.assertAlmostEqual(pos[-1], -1)
            pm.delete(loc)
Example #52
0
def setup_look_at(camera):
    """sets up the look at locator for the given camera
    """

    # just create a locator under the camera
    # and move it to -10

    loc = pm.spaceLocator(n=camera.name() + "vertigo_loc#")

    # create a new attribute under the camera
    global vertigo_attr_name

    camera_shape = camera.getShape()

    if not camera.hasAttr(vertigo_attr_name):
        pm.addAttr(camera, ln=vertigo_attr_name, at="message")

    # connect the message attribute of the locator to the camera
    loc.message >> camera.attr(vertigo_attr_name)

    pm.parent(loc, camera)

    loc.t.set(0, 0, -10)
    loc.r.set(0, 0, 0)

    # lock locators tx, ty and rotate channels
    loc.tx.lock()
    loc.ty.lock()
    loc.r.lock()
Example #53
0
def bdLocOnJnt():
    try:
        rootJnt = pm.ls(sl=True)[0]
    except:
        pm.warning('Nothing selected')
        return
    try:
        crvPath  = pm.ls(sl=True)[1]
    except:
        pm.warning('No curve selected')
        return

    allJnt = rootJnt.listRelatives(f=True, ad=True,type='joint')
    allJnt = allJnt + [rootJnt]
    allJnt.reverse()

    locators = []
    for jnt in allJnt:
        print jnt
        loc = pm.spaceLocator(name = jnt.name().replace( '_jnt','_loc'))
        locGrp = pm.group(n = loc.name() + '_grp')

        tempCnstr = pm.pointConstraint(jnt,locGrp,mo=0);
        pm.delete(tempCnstr )
        locators.append(locGrp)

    bdMultiMotionPath(crvPath, locators)
    bdParentJntToLocs(allJnt)
Example #54
0
def symmetryLayer():

    allCtrls = pm.PyNode('CT_face_ctrl').getChildren(ad=True, type='nurbsCurve')
    allCtrls = set([crv.getParent() for crv in allCtrls])
    
    # new group to hold mirrored locs
    symLocGrp = pm.group(em=True, n='RT_symmetryLoc_grp')
    
    allRightCtrls = [crv for crv in allCtrls if 'RT_' in crv.name()]
    symMatrix = pm.createNode('fourByFourMatrix', n='CT_symmetryMatrix_mat')
    symMatrix.in00.set(-1)
    
    for rightCtl in allRightCtrls:
        leftCtl = pm.PyNode(rightCtl.replace('RT_', 'LT_'))
        loc = pm.spaceLocator(n=rightCtl+'_symLoc')
        symLocGrp | loc
        # connect to left side
        mm = pm.createNode('multMatrix', n=rightCtl+'_sym_mm')
        symMatrix.output >> mm.matrixIn[0]
        leftCtl.worldMatrix >> mm.matrixIn[1]
        symMatrix.output >> mm.matrixIn[2]
        dcm = pm.createNode('decomposeMatrix', n=rightCtl+'_sym_dcm')
        mm.matrixSum >> dcm.inputMatrix
        dcm.ot >> loc.t
        dcm.outputRotate >> loc.r
        # constrain on anim layer
        pm.parentConstraint(loc, rightCtl, l='Symmetry', weight=1)
Example #55
0
def createBendDeformerOnCurve(curveTransforms, upDir=(1,0,0), aimDir=(0,1,0)):
	'''Creates bend deformers on every curve and aims them at the end
	Args:
		curveTransforms ([pm.nt.Transform]): list of transforms with nurbsCurve shapes
		upDir (float, float, float): up direction for aim to orient the bend deformer
	Returns:
		([pm.nt.nonLinear]): list of bend deformers
	Usage:
		createBendDeformerOnCurve(pm.ls(sl=True))
	'''
	bends=[]
	for curveTransform in curveTransforms:
		bendName = curveTransform.name().replace('CRV','BEND')
		bend = pm.nonLinear(curveTransform, type='bend', frontOfChain=True, curvature=0.0, lowBound=0, highBound=1)
		bend[0].rename(bendName.replace('BEND','BENDHDL'))
		bend[1].rename(bendName)
		startPosition = curveTransform.getShape().cv[0].getPosition(space='world')
		endPosition = curveTransform.getShape().cv[-1].getPosition(space='world')
		loc = pm.spaceLocator()
		
		pm.move(loc, endPosition, a=True)
		pm.move(bend[1], startPosition, a=True)
		
		aimConst = pm.aimConstraint( loc, bend[1], upVector=upDir, aimVector=aimDir )
		pm.delete([loc, aimConst])
		bends.append(bend)
	return bends
Example #56
0
def create_point_on_mesh(geo, position, sticky_target, free_rotation=True):
    """
    Create point on mesh setup
    @param position:
    @param geo:
    @parem sticky:
    @return:
    """

    pom = pm.createNode("closestPointOnMesh")
    pom.inPosition.set(position)

    geo.worldMatrix[0] >> pom.inputMatrix
    geo.worldMesh[0] >> pom.inMesh

    pom.position >> sticky_target.translate

    index = pom.closestVertexIndex.get()

    locator = pm.spaceLocator()
    libUtilities.snap(locator, geo.vtx[index], rotate=False)
    libUtilities.freeze_transform(locator)
    pm.pointOnPolyConstraint(geo.vtx[index], locator, maintainOffset=True)

    pm.delete(pom)
    constraint = pm.listRelatives(locator, type="constraint")[0]
    if free_rotation:
        for attr in ["rx", "rz", "ry"]:
            libUtilities.break_connection(locator, attr)
            locator.attr(attr).set(0)
    return {"constraint": constraint, "locator": locator}
    def _createCurves(self, objs=None, axis=None, num=None):
        '''
        Create two curves using .getTranslation() of passed in objects
        '''
        _name = '_createCurves'
        pymelLogger.info('Started: %s' % _name)
        
        positions = []
        for obj in objs:
            loc = pm.spaceLocator()
            pm.parentConstraint(obj, loc, mo=0)
            positions.append(pm.PyNode(loc).getTranslation())
            pm.delete(loc)
        crv1 = pm.PyNode(pm.curve(p=positions, d=1))
        crv2 = pm.PyNode(pm.curve(p=positions, d=1))
        
        move = 0.05
        if axis == 1:
            pm.move(crv1, move, r=1, moveX=1)
            pm.move(crv2, -move, r=1, moveX=1)
        elif axis == 2:
            pm.move(crv1, move, r=1, moveY=1)
            pm.move(crv2, -move, r=1, moveY=1)
        elif axis == 3:
            pm.move(crv1, move, r=1, moveZ=1)
            pm.move(crv2, -move, r=1, moveZ=1)

        pm.rebuildCurve( crv1, rt=0, s=num )
        pm.rebuildCurve( crv2, rt=0, s=num )
    
        pymelLogger.info('Ended: %s' % _name)       
        return crv1, crv2
Example #58
0
def autoPoleVector( baseJnt=None, endJnt=None, side='L' ):

	baseJntPos = pm.xform( baseJnt, q=True, t=True, ws=True )
	endJntPos = pm.xform( endJnt, q=True, t=True, ws=True )

	pm.select(clear=True)
	poleVectorJnt_one = pm.joint( p=baseJntPos )
	poleVectorJnt_two = pm.joint( p=endJntPos )
	poleVectorIKstuff = pm.ikHandle(  sj = poleVectorJnt_one, ee = poleVectorJnt_two, solver = "ikSCsolver"  )

	pv = pm.spaceLocator()
	pv.setParent( poleVectorJnt_two )
	pv.translate.set( 0,0,0 )
	pvZeros = ZeroGrp( pv )

	pm.pointConstraint( poleVectorIKstuff[0], pvZeros[0] )

	if side=='L':
		pv.translateX.set( 1 )
	elif side=='R':
		pv.translateX.set( -1 )


	pvZeros[0].setParent( poleVectorJnt_two )

	return ( pv, poleVectorIKstuff, (poleVectorJnt_one, poleVectorJnt_two) )