Ejemplo n.º 1
0
 def makeCube():
     squareCrv = dtLib.makeSquare()
     squareCrv2 = dtLib.makeSquare()
     squareCrv2.setRotation([90, 0,0])
     squareCrv2.setTranslation([0,0.5,-0.5])
     pm.makeIdentity(apply=True, translate=True, rotate=True, scale=True, normal=1)
     
     crvs = squareCrv2.getShapes()
     
     for current in crvs:
         pm.parent(current, squareCrv, relative=True, shape=True)
     pm.delete(squareCrv2)
     
     pm.select(squareCrv)
     dupCrv = pm.duplicate()
     dupCrv[0].setRotation([180, 0, 0])
     dupCrv[0].setTranslation([0,0,-1])
     pm.makeIdentity(apply=True, translate=True, rotate=True, scale=True, normal=1)
     crvs = dupCrv[0].getShapes()
     for current in crvs:
         pm.parent(current, squareCrv, relative=True, shape=True)
         
     pm.delete(dupCrv)
     #中央にピポットを移動
     pm.select(squareCrv)
     pm.xform(cp=True)
     return pm.selected()
Ejemplo n.º 2
0
def make_stabilized_node(nodeName=None, centered=True):
    '''
    Very simple proc to generate a Stabilized node for
    raw MoCap tracking purposes... First selected node
    is used as the Aim axis, second selected is used as this
    aim's worldUp
    '''
    RequiredMarkers = pm.ls(sl=True, l=True)
    #pos = pm.xform(WorldUpObj, q=True, ws=True, t=True)
    curve = pm.curve(ws=True, d=1, p=(0, 0, 0), k=0)
    
    if centered:
        AimAt = RequiredMarkers[0]
        WorldUpObj = RequiredMarkers[1]
        pm.pointConstraint(RequiredMarkers, curve)
    else:
        AimAt = RequiredMarkers[1]
        WorldUpObj = RequiredMarkers[2]
        pm.pointConstraint(RequiredMarkers[0], curve)

    pm.aimConstraint((AimAt, curve),
                     weight=1,
                     aimVector=(0, 0, 1),
                     upVector=(0, 1, 0),
                     worldUpType="object",
                     worldUpObject=WorldUpObj)
        
    #Snap a curveKnot to the pivot of all referenceMarkers
    for node in RequiredMarkers:
        pm.curve(curve, a=True, ws=True, p=(pm.xform(node, q=True, ws=True, t=True)))
    pm.curve(curve, a=True, ws=True, p=(pm.xform(AimAt, q=True, ws=True, t=True)))
    
    return curve
Ejemplo n.º 3
0
    def buildChains(self, *args):
        """
        Build joint chains based on locator positions.
        """
        self.jointChain = []
        self.ikChain = []
        self.fkChain = []

        loc1Pos = pm.xform(self.loc1, q=True, ws=True, t=True)
        loc2Pos = pm.xform(self.loc2, q=True, ws=True, t=True)
        loc3Pos = pm.xform(self.loc3, q=True, ws=True, t=True)

        jnt1='%s_shldrJnt'%self.prefix
        jnt2='%s_elbow1Jnt'%self.prefix
        jnt3='%s_wristJnt'%self.prefix

        self.jointChain.append(pm.PyNode(pm.joint(p=loc1Pos, n=jnt1))) 
        self.jointChain.append(pm.PyNode(pm.joint(p=loc2Pos, n=jnt2)))
        self.jointChain.append(pm.PyNode(pm.joint(p=loc3Pos, n=jnt3)))

        #--- Orient the chain
        self.orientChain()

        #--- Creating duplicate ik/fk joint chains
        for each in pm.duplicate(self.jointChain, rc=True):
            # Slice off number maya adds during duplication
            each.rename('%s_ik' % each[:-1])
            self.ikChain.append(pm.PyNode(each))

        for each in pm.duplicate(self.jointChain, rc=True):
            each.rename('%s_fk' % each[:-1])
            self.fkChain.append(pm.PyNode(each))
Ejemplo n.º 4
0
def GuideCrv ( startGuider=None , endGuider=None ):

	if startGuider==None or endGuider==None:
		startGuider,endGuider = pm.ls(sl=True)
	
	pm.select(clear=True)
	
	startJnt = pm.joint ( n = startGuider.name()+"_guideCrvJnt")
	pm.parent (startJnt , startGuider)
	startJnt.translate.set (0,0,0)
	startJnt.visibility.set (0)
	pm.setAttr ( startJnt.visibility , lock=True  )
	
	
	endJnt = pm.joint (  n = endGuider.name()+"_guideCrvJnt" )
	pm.parent (endJnt , endGuider)
	endJnt.translate.set (0,0,0)
	endJnt.visibility.set (0)
	pm.setAttr ( endJnt.visibility , lock=True  )
	
	startJntPos = pm.xform ( startJnt , q=True , ws=True , t=True)
	endJntPos = pm.xform ( endJnt , q=True , ws=True , t=True)
	
	guideCrv = pm.curve ( degree=1 , p = (startJntPos ,endJntPos) , k=(1,2)  )
	
	pm.rename ( guideCrv , startGuider.name()+"_guideCrv")
	
	pm.skinCluster ( guideCrv , startJnt , endJnt  )
	
	guideCrv.inheritsTransform.set(0)
	guideCrv.template.set(1)
	
	pm.select(clear=True)
	
	return guideCrv
	def vis_orbits(self):
		global vis_orbGrp
		vis_orbGrp = pm.group(n='olp_visOrbits', em=True)

		intervValue = self.interv_int.value()
		distValue = self.distance_float.value()
		orbitValue = self.orbit_int.value()

		global all_orbitObjs
		all_orbitObjs = []
		for orbit in range(orbitValue):
			orbitRot = orbit * 360/float(orbitValue*2)
			
			orbit_visObject = pm.circle(n='olp_orbCircle{0}'.format(orbit+1), r=distValue, s=intervValue*2, nr=[1, 0, 0], ch=True)[0]
			pm.parent(orbit_visObject, vis_orbGrp)

			orbit_visObject.overrideEnabled.set(1)
			orbit_visObject.overrideColorRGB.set(0, 1, 1)
			orbit_visObject.overrideRGBColors.set(1)

			pm.xform(orbit_visObject, ro=[0, 0, orbitRot])

			all_orbitObjs.append(orbit_visObject)

		pm.xform(vis_orbGrp, a=True, t=sel_center)
		pm.parent(vis_orbGrp, vis_mainGrp)
		pm.select(sel_objects, r=True)
		return vis_orbGrp
Ejemplo n.º 6
0
    def create_hook(cls, asset="asset", side="c",  part="part",
                    snap_to=None, in_out='in'):
        """
        Settings for generating hooks in the autorig.

        :parameters:
            asset: For naming convention.
            side: For naming convention. (l, r, c)
            part: For naming convention.
            snap_to: Object to snap to.
            in_out: default value.
        """
        hook_name = NameUtils.get_unique_name(asset, side, part, "loc")
        hook = pm.createNode(settings.HOOK_NODE_TYPE, n=hook_name)

        if settings.HOOK_NODE_TYPE == "locator":
            hook = hook.getParent()
            hook.rename(hook_name)

        digit_type = 0
        if in_out == 'out':
            digit_type = 1

        hook.addAttr('hookType', at='float', dv=digit_type)
        hook.attr('hookType').lock(1)
        if snap_to:
            pm.xform(hook, ws=1, matrix=snap_to.wm.get())
        return hook
Ejemplo n.º 7
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) ) 
Ejemplo n.º 8
0
def create_bind_proxy(jnt):
    if jnt.getChildren():
        name=jnt.name() + "_bindProxy"
         
        distance = jnt.getChildren()[0].translateX.get()
        if not pm.objExists(name):
            proxy = pm.polyCylinder(r=0.25, h=0.5, sx=12, sy=4, sz=4, ax=[1,0,0], rcp=1, cuv=0, ch=0, name=name)[0]
            pm.xform(proxy, piv=[-0.5, 0, 0])
             
            pm.parent(proxy, 'bind_proxy')
             
            pm.delete(pm.parentConstraint(jnt, proxy, mo=False))
            proxy.scale.set(distance, distance, distance)
             
            try:
                jnt.addAttr('iterations', at='long', min=1, max=5, dv=3, k=True)
                jnt.addAttr('bind_proxy', at='message')
            except:
                pass            
                 
        else:
            proxy = pm.PyNode(name)

        
        pm.skinCluster( jnt, proxy, tsb=True)
        proxy.message >> jnt.bind_proxy            
Ejemplo n.º 9
0
    def __areaSkin(self,*args):

        geo = pm.ls(sl = 1)[0]
        skinCluster = mel.eval('findRelatedSkinCluster ' + geo)
        vertex = pm.polyEvaluate(geo,v = 1)
        joints = pm.skinCluster(skinCluster,q = 1,inf = 1)
        skinList = {}

        for num in range(0,vertex):
            vertex = geo + '.vtx[' + str(num) + ']'
            vertPos = pm.xform(vertex,q = 1,t = 1,ws = 1)
            tempDict = {}
          
            for joint in joints:
                jntPos = pm.xform(joint,q = 1,t = 1,ws = 1)
                dist = math.sqrt(pow(vertPos[0] - jntPos[0],2) + pow(vertPos[1] - jntPos[1],2) + pow(vertPos[2] - jntPos[2],2))
                tempDict.setdefault(joint,dist)
                  
            minDistVal = min(distVal for distVal in tempDict.values())
          
            for joint in tempDict.keys(): 
                if minDistVal == tempDict[joint]:
                    if joint not in skinList:
                        skinList[joint] = []
                    skinList[joint].append(vertex)
                      
        for item in skinList.items():
            joint =  item[0]
            vertex = item[1]
            for vert in vertex:
                pm.skinPercent(skinCluster,vert,transformValue = (joint,1))        
Ejemplo n.º 10
0
def set_newPivot(*args):
    sel = pm.ls(sl=True)
    source = sel[-1]
    piv = pm.xform (source, piv=True, q=True, ws=True)
    
    for obj in sel[:-1]:
        pm.xform (obj, ws=True, piv=(piv[0], piv[1], piv[2]) )
Ejemplo n.º 11
0
def locatorGrid(width, height, depth, offset, centered=True):
	'''Create a grid of locators to test upon
	Args:
		width (int): Width of the grid
		height (int): Height of the grid
		offset (float): Adds an offset multiplier to the locator positions
		centered (bool): determines whether it's centered in world space
	Returns (pm.PyNode): The top group of the locator grid
	Usage: locatorGrid(5,5,5,2)
	'''
	if not pm.objExists('locatorGrid'):
		grp=pm.group(em=True,n='locatorGrid')
		for d in range(0,depth):
			for w in range(0,width):
				for h in range(0,height):
					loc = pm.polyCube(w=.5, h=.5, d=.5, ch=0)[0]
					pm.move(loc,(w*offset,h*offset,d*offset), rpr=True)
					loc.setParent(grp)
					if loc.getShape().type() == "locator":
						loc.localScale.set(.2,.2,.2)
		if centered:
			pm.xform(grp, cp=1)
			pm.move(grp, (0, 0, 0), rpr=1)
			pm.makeIdentity(grp, apply=True, r=1,s=1,t=1)
		return grp
Ejemplo n.º 12
0
def setPosUv(vtxs,length,side,uvDistorted):
    startUv = pm.ls(pm.polyListComponentConversion(vtxs[0],fv=1,tuv=1),fl=1)

    if side == 'left':
        pm.polyEditUV(startUv,r=0,u=0,v=0)
    else:
        pm.polyEditUV(startUv,r=0,u=1,v=0)
    

    for i in range(1,len(vtxs)):
        vtx1Pos = pm.xform(vtxs[i-1],q=1,t=1,ws=1)
        vtx2Pos = pm.xform(vtxs[i],q=1,t=1,ws=1)
        vtx1PosVec = MVector(vtx1Pos[0],vtx1Pos[1],vtx1Pos[2])
        vtx2PosVec = MVector(vtx2Pos[0],vtx2Pos[1],vtx2Pos[2])
        dist = (vtx2PosVec  - vtx1PosVec).length()
        
        factor=0.0
        if uvDistorted:
            factor = dist / length
        else:
            factor = 1.0 / (len(vtxs) - 1)
            
                             
        uv1 = pm.ls(pm.polyListComponentConversion(vtxs[i-1],fv=1,tuv=1),fl=1)
        uv2 = pm.ls(pm.polyListComponentConversion(vtxs[i],fv=1,tuv=1),fl=1)
        uv1Pos = pm.polyEditUV(uv1,q=1)
        uv2Pos = uv1Pos[1] + factor
        if side == 'left':
            pm.polyEditUV(uv2,r=0,u=0,v=uv2Pos)
        else:
            pm.polyEditUV(uv2,r=0,u=1,v=uv2Pos)
Ejemplo n.º 13
0
    def generateShape(self, *args):
        sel = pm.ls(sl=1)
        if len(sel) != 4:
            pm.mel.warning('Must select: Neutral, TargetA, TargetB, TargetC meshes')
            return
        
        meshN = sel[0]
        meshA = sel[1]
        meshB = sel[2]
        meshC = sel[3]
        
        # Create new mesh
        new = pm.duplicate(meshN, n='Corrective')[0]
        
        # Per vertex, translate in world space: C-(A+B)
        for vtx in new.vtx:
            vert = vtx.split('.')[1]
            n_pos = pmd.Point(pm.xform( vtx, query=True, ws=True, t=True))
            a_pos = pmd.Point(pm.xform( meshA + '.' + vert, query=True, ws=True, t=True))
            b_pos = pmd.Point(pm.xform( meshB + '.' + vert, query=True, ws=True, t=True))
            c_pos = pmd.Point(pm.xform( meshC + '.' + vert, query=True, ws=True, t=True))
            
            aVec = a_pos - n_pos
            bVec = b_pos - n_pos
            cVec = c_pos - n_pos

            delta = cVec - (aVec + bVec)
            
            pm.move(vtx, delta, r=1)
Ejemplo n.º 14
0
	def ChangeNumberOfJoints(self, *args):
		self.blueprint_UI_instance.DeleteScriptJob()
		
		# Collect information from current spline module
		joints = self.GetJoints()
		numJoints = len(joints)
		
		newNumJoints = pm.intField(self.numberOfJointsField, query = True, value = True)
		
		startPos = pm.xform(self.GetTranslationControl(joints[0]), query = True, worldSpace = True, translation = True)
		endPos = pm.xform(self.GetTranslationControl(joints[numJoints - 1]), query = True, worldSpace = True, translation = True)
		
		hookObj = self.FindHookObjectForLock()
		
		rotateOrder = pm.getAttr("%s.rotateOrder" %joints[0])
		sao_local = pm.getAttr("%s:module_grp.sao_local" %self.moduleNamespace)
		sao_world = pm.getAttr("%s:module_grp.sao_world" %self.moduleNamespace)
		
		# Delete current spline module
		self.Delete()
		
		# Create new spline module with new joint count
		newInstance = Spline(self.userSpecifiedName, hookObj, newNumJoints, startPos, endPos)
		newInstance.Install()
		
		# Apply previous attribute values
		newJoints = newInstance.GetJoints()
		pm.setAttr("%s.rotateOrder" %newJoints[0], rotateOrder)
		pm.setAttr("%s:module_grp.sao_local" %newInstance.moduleNamespace, sao_local)
		pm.setAttr("%s:module_grp.sao_world" %newInstance.moduleNamespace, sao_world)
		
		self.blueprint_UI_instance.CreateScriptJob()
		
		pm.select("%s:module_transform" %newInstance.moduleNamespace, replace = True)
Ejemplo n.º 15
0
 def build_between_points(cls, start_xform, end_xform, num_joints, name={'name':'chain'}, freeze=True, chain=True, parent=None, offset=False):
     """ Create joints based on given 3D spatial positions/rotations e.g. [[[10,5.3,1.4],[0,90,0]],...,nPos]
     Args:
         start_xform [pm.nt.Transform]: starting position
         end_xform [pm.nt.Transform]: ending position
         name (str): base name for the chain
         chain (bool): whether or not to make a chain, or isolated joints
         offset (bool): whether or not to build in offset groups for the joints
         parent (pm.nt.Transform): final parent of the joints, empty if kept at root level
     Returns:
         [pm.nt.Joint]: list of joints
     Usage:
         Joint.build_between_points(pm.ls(sl=True)[0], pm.ls(sl=True)[1], 5, chain=True, offset=True, freeze=True)
     """
     xform_interps = transform.spatial_interpolate(pm.xform(start_xform, q=True, t=True, ws=True),
                                                   pm.xform(end_xform, q=True, t=True, ws=True),
                                                   num_joints)
     
     rotation_interps = transform.spatial_interpolate(pm.xform(start_xform, q=True, ro=True, ws=True),
                                                      pm.xform(end_xform, q=True, ro=True, ws=True),
                                                      num_joints)
     
     positions = [[xform_interp, rotation_interp] for xform_interp, rotation_interp in zip(xform_interps, rotation_interps)]
     
     return cls.build_from_points(positions, name=name, chain=chain, parent=parent, offset=offset, freeze=freeze)
Ejemplo n.º 16
0
def getShapePos(*nodes, **kwargs):
    """
    @return: dictionary of {shapePyNode: [pointPositionList],...}
    """
    ws = kwargs.get('ws', False)
    if ws:
        space = 'world'
    else:
        space = 'preTransform'

    vertObjs, crvObjs, surfObjs = filterShapes(*nodes)
    result = {}

    for obj in vertObjs:
        assert isinstance(obj, pm.nodetypes.Mesh)
        result[obj] = obj.getPoints(space=space)

    for obj in crvObjs:
        assert (isinstance(obj, pm.nodetypes.NurbsCurve))
        result[obj] = []
        for i in range(obj.numCVs()):
            result[obj].append(pm.xform(obj.cv[i], q=True, ws=ws, t=True))
        #this might have a bug?
        #result[obj] = obj.getCVs(space='world')
        #result[obj].append(.getPosition(space='world'))
    for obj in surfObjs:
        assert(isinstance(obj, pm.nodetypes.NurbsSurface))
        result[obj] = []
        for u in range(obj.numCVsInU()):
            for v in range(obj.numCVsInV()):
                result[obj].append(pm.xform(obj.cv[u][v], q=True, ws=ws, t=True))
    return result
Ejemplo n.º 17
0
def mirror_nurb(patches, negative_x=True, reverse=False):
    """
    Args:
        patches (pm.nt.Transform): nurbsies
        negative_x (bool): mirror from +x => -x or vice versa
    Usage:
        mirror_nurb(pm.ls(sl=True, type='transform'), negative_x=True, reverse=False)
    """
    for patch in patches:
        shape = patch.getShape()
        cvu, cvv = shape.numCVsInU(), shape.numCVsInV()
        if reverse:
            cvu, cvv = shape.numCVsInV(), shape.numCVsInU()
        
        for column in range(cvv):
            even_odd = cvu % 2
            
            for row in range(cvu/2):
                if negative_x:
                    row_mirrored = row
                    row = (row*-1) - 1
                else:
                    row_mirrored = (row*-1) - 1
                
                pos = pm.xform(shape.cv[row][column], q=True,ws=True,t=True)
                pos_mirrored = [a*b for a,b in zip(pos, [-1,1,1])]
                pm.xform(shape.cv[row_mirrored][column], t=pos_mirrored, ws=True)
                
Ejemplo n.º 18
0
def strokePath(node, radius=.1):
    """
    Create a nurbs surface from a curve control
    """
    curveNodes = separateShapes(node)
    for curveNode in curveNodes:
        shape = curveNode.listRelatives(type='nurbsCurve')[0]
        t = pm.pointOnCurve(shape, p=0, nt=1)
        pos = pm.pointOnCurve(shape, p=0)
        cir = pm.circle(r=radius)[0]
        pm.xform(cir, t=pos, ws=1)

        #align the circule along the curve
        l = pm.spaceLocator()
        pm.xform(l, t=[pos[0]+t[0], pos[1]+t[1], pos[2]+t[2]], ws=1)
        pm.delete(pm.aimConstraint(l, cir, aimVector=[0,0,1]))
        pm.delete(l)

        newxf = pm.extrude(cir, curveNode, rn=False, po=0, et=2, ucp=1,
                            fpt=1, upn=1, scale=1, rsp=1, ch=1)[0]
        pm.delete(cir)
        pm.delete(curveNode.listRelatives(type='nurbsCurve'))
        parentShape(curveNode, newxf)
    if len(curveNodes) > 1:
        for i in range(1, len(curveNodes)):
            parentShape(curveNodes[0], curveNodes[i])
    return curveNodes[0]
Ejemplo n.º 19
0
def Snap(target, source, translation=True, rotation=True):
    ''' Snaps source object to target object.
    If point is True, translation will snap.
    If orient is True, orientation will snap.
    If source is None, then it looks for lists for translation,rotation and scale
    '''

    #if source doesnt exists and passing in transform lists
    if not source:
        if isinstance(translation, list):
            pm.xform(target, ws=True, translation=translation)
        if isinstance(rotation, list):
            pm.xform(target, ws=True, rotation=rotation)

        return

    #translation
    if translation:
        trans = pm.xform(source, q=True, ws=True, translation=True)
        pm.xform(target, ws=True, translation=trans)

    #orientation
    if rotation:
        rot = pm.xform(source, q=True, ws=True, rotation=True)
        pm.xform(target, ws=True, rotation=rot)
Ejemplo n.º 20
0
def getXProductFromNodes(midObj, topObj, btmObj):
    """
    get a cross product based upon the position of the first three objects in objList
    Returns the cross product of two vectors: midObj to topObj and midObj to btmObj
    """

    #get the vectors
    midPos = pm.xform(midObj, q=True, worldSpace=True, translation=True)
    topPos = pm.xform(topObj, q=True, worldSpace=True, translation=True)
    btmPos = pm.xform(btmObj, q=True, worldSpace=True, translation=True)

    topVector = [topPos[0] - midPos[0], topPos[1] - midPos[1], topPos[2] - midPos[2]]
    btmVector = [btmPos[0] - midPos[0], btmPos[1] - midPos[1], btmPos[2] - midPos[2]]

    #create a temporary vectorProduct node
    vp = pm.createNode("vectorProduct")
    #set to cross product
    vp.operation.set(2)
    vp.input1.set(btmVector)
    vp.input2.set(topVector)

    #store the cross product
    cp = vp.output.get()

    #delete the vector node
    pm.delete(vp)
    return cp
Ejemplo n.º 21
0
    def mirrorPose(self):
        lf='lf_'
        rt='rt_'
        center = 'ctr_'
        sel = pm.ls(sl=1)
        pm.select(clear=True)
        commands = []
        for s in sel:

            mirrorObject = ""
            if str(s).startswith(lf):
                mirrorObject = rt + s[3:]
            elif str(s).startswith(rt):
                mirrorObject = lf + s[3:]
            elif str(s).startswith(center):
                mirrorObject = center + s[4:]

            pos = pm.xform(s, q=1, ws=1, rp=1)
            rot = pm.xform(s, q=1, ws=1, ro=1)
            scale = pm.xform(s, q=1, r=1, s=1)

            commands.append( 'move %s %s %s  -ws -rpr "%s"'%(-pos[0],pos[1],pos[2],mirrorObject) )
            commands.append( 'rotate -a %s %s %s -ws "%s" '%(rot[0],-rot[1],-rot[2],mirrorObject) )
            commands.append( 'scale %s %s %s "%s"'%(scale[0],scale[1],scale[2],mirrorObject) )

            pm.select(mirrorObject,add=True)

        for c in commands:
            pm.mel.eval(c)
Ejemplo n.º 22
0
def FindPVposition( objs=pm.ls(sl=True) ):

	if not len(objs) == 3:
		pm.error( 'ehm_tools...findPVposition: objs arguments takes exactly 3 objects. %s was given.'%len(objs) )

	base = objs[0]
	mid  = objs[1]
	tip  = objs[2]

	A = dt.Vector( pm.xform( base, q=True, t=True, ws=True ) )
	B = dt.Vector( pm.xform( mid, q=True, t=True, ws=True ) )
	C = dt.Vector( pm.xform( tip, q=True, t=True, ws=True ) )

	AC = C - A
	AB = B - A

	D =  A + ( (dt.dot(AB,AC.normal()))  * AC.normal() ) # AB projected on AC

	position =  B + B - D
	
	if (position[0]  - B[0] < 0.001) and (position[1]  - B[1] < 0.001) and (position[2]  - B[2] < 0.001):
		pm.warning( 'ehm_tools...FindPVposition: Limbs were straight. None was returned!' )
		return None
	else:
		return position
	def createLight(self, position):
		value = self.distance_float.value()
		if self.lightType_menu.currentIndex() == 1:
			light = pm.shadingNode('areaLight', asLight=True)
			
			pm.setAttr(light + '.intensity', 500)
			pm.setAttr(light + '.decayRate', 2)
			pm.setAttr(light + '.areaLight', 1)

		elif self.lightType_menu.currentIndex() == 2:
			light = pm.shadingNode('spotLight', asLight=True)

			pm.setAttr(light + '.intensity', 500)
			pm.setAttr(light + '.decayRate', 2)

		elif self.lightType_menu.currentIndex() == 3:
			light = pm.shadingNode('directionalLight', asLight=True)

		elif self.lightType_menu.currentIndex() == 4:
			light = pm.shadingNode('pointLight', asLight=True)

			pm.setAttr(light + '.intensity', 500)
			pm.setAttr(light + '.decayRate', 2)

		pm.rename(light, light_name)
		pm.xform(light, a=True, t=position)
		pm.xform(light, r=True, t=(0, 0, value))

		return light
Ejemplo n.º 24
0
def createCOG(*args):
   
    newCog = createCircle()[0]
    cvsToSelect = (newCOG.cv[::2])
    pm.select(cvsToSelect)
    pm.xform(s = [.5, .5, .5])
    return newCog
	def change_distance(self):
		intervValue = self.interv_int.value()
		value = self.distance_float.value()

		pm.setAttr(rigLight+'.translateZ', value)
		pm.xform(vis_mainGrp, s=[value, value, value])
		vis_mainGrp
Ejemplo n.º 26
0
def load_position(obj):
	'''Finds all of the positions for the selected object and applies them
	Args:
		obj (pm.PyNode): the object to apply to
	Returns (dict): position
	Usage:
		get_positions(pm.ls(sl=True)[0])
	'''
	#Current version folder nonsense
	folder = os.path.join( environ.POSITIONS, obj )
	versionFolder = lib_env.folder_detectVersions( folder, versionUp = False )
	if versionFolder:
		folder = versionFolder
	else:
		pm.warning('Folder does not exist')
	
	#Handling shit
	if os.path.exists(folder):
		os.chdir(folder)
		positions = []
		for file in glob.glob("*.pos"):
			position = import_position(file)
			print position
			pm.xform(obj, t=position['translate'], ro=position['rotate'], s=position['scale'], ws=True)
	else:
		pm.warning('Object: %s does not have any deformers available in folder: %s'%(obj,folder))
Ejemplo n.º 27
0
def transfer_shape(source, target, flip=True):
    """it will replace the shape of selected number 2 with the shapes of selected number 1"""

    target_shape = target.getShape(noIntermediate=True)
    target_shape_orig = get_orig_shape(target_shape)

    dup = pymel.duplicate(source, rc=1)[0]
    tmp = pymel.createNode('transform')
    pymel.parent(tmp, dup)
    pymel.xform(tmp, t=(0, 0, 0), ro=(0, 0, 0), scale=(1, 1, 1))
    pymel.parent(tmp, w=1)
    for sh in dup.getShapes(noIntermediate=True):
        pymel.parent(sh, tmp, r=1, s=1)

    pymel.delete(dup)
    temp_grp_negScale = pymel.createNode('transform')
    pymel.parent(tmp, temp_grp_negScale)
    if flip:
        temp_grp_negScale.scaleX.set(-1)

    pymel.parent(tmp, target)
    pymel.delete(temp_grp_negScale)

    pymel.makeIdentity(tmp, t=True)  # this brings translate values at 0 before scale freezing
    pymel.makeIdentity(tmp, apply=True, t=True, r=True, s=True)
    pymel.parent(tmp, w=1)

    color_info, vis_master = get_previous_controller_info(target)

    shapes_has_been_deleted = False
    for sh in tmp.getShapes():
        if target_shape_orig:
            adapt_to_orig_shape(sh, target.getShape())
        else:
            if not shapes_has_been_deleted:
                shapesDel = target.getShapes()
                if shapesDel: pymel.delete(shapesDel)
                shapes_has_been_deleted = True

            pymel.parent(sh, target, r=1, s=1)
            pymel.rename(sh.name(), target.name() + "Shape")

            if color_info[0]:
                if color_info[1]:
                    sh.overrideEnabled.set(True)
                    sh.overrideRGBColors.set(1)
                    sh.overrideColorRGB.set(color_info[2])

                else:
                    sh.overrideEnabled.set(True)
                    sh.overrideRGBColors.set(0)
                    sh.overrideColor.set(color_info[2])

            else:
                sh.overrideEnabled.set(False)

            if vis_master:
                vis_master.connect(sh.visibility)

    pymel.delete(tmp)
Ejemplo n.º 28
0
    def generate( self, size = 10, iterations = 1, grid = 3, holes = [ 4, 10, 12, 13, 14, 16, 22 ] ):

        self.size       = size
        self.iterations = iterations
        self.grid       = grid
        self.holes      = holes

        print( "%s radius %f iterations %i" % ( self.__class__.__name__, self.size, self.iterations ) )
    
        cubeSize = float(self.size) /  util.pow( float(self.grid), float(self.iterations) )
        cube     = self.mesh( width = cubeSize, height = cubeSize, depth = cubeSize )    
        cubes    = [ cube ]
        
        for i in range( iterations ):

            mesh     = self.__generateMesh( cubes[ 0 ], cubeSize, ( i + 1 ) )
            cubeSize = cubeSize * self.grid
            cubes    = [ mesh ]


        pm.xform( mesh[ 0 ], centerPivots = True )

        print( "Construction complete" )

        return mesh
Ejemplo n.º 29
0
    def generate( self, radius = 10, iterations = 1 ):
        
        self.radius     = radius
        self.iterations = iterations
        
        print( "%s radius %f iterations %i" % ( self.__class__.__name__, self.radius, self.iterations ) )

        octahedronRadius = float(self.radius) / util.pow( float(2), float(self.iterations ) )
        octahedron       = self.mesh( radius = octahedronRadius )
        octahedra        = [ octahedron ]
        
        pm.polySoftEdge( angle = 0 )   

        octahedronHeight = octahedron[ 1 ].getSideLength() / util.sqrt( 2 )
    
        for i in range( iterations ):
            
            mesh = self.__generateMesh( octahedra[ 0 ], octahedronHeight, octahedronRadius, ( i + 1 ) )
            
            octahedronHeight *= 2            
            octahedronRadius *= 2            
            
            octahedra = [ mesh ]
        

        pm.xform( mesh[ 0 ], centerPivots = True )

        print( "Construction complete" )
        
        return mesh
def add_text_shape(ctrl, text):
    text_curve = pm.PyNode( pm.textCurves(ch=False, font="Arial Black", text=text, name='text_curve')[0] )
    text_curve_length = text_curve.boundingBox()[1][0] #max X
    text_curve_height = text_curve.boundingBox()[1][1] #max Y
    
    shapes = pm.listRelatives(text_curve, ad=True, type="shape")
    
    pm.xform(text_curve, piv=[0,text_curve_height,0], ws=True)

    pm.move(text_curve, 0, -text_curve_height , 0)

    scale = 1 / text_curve_length
    pm.scale(text_curve, scale, scale, scale)
            
    pm.makeIdentity(text_curve, apply=True, t=True, r=True, s=True)

    display_attr = ("%s_text_display"%text)
    if not ctrl.hasAttr(display_attr):
        ctrl.addAttr(display_attr, at='bool', k=True, dv=1)

    for s in shapes:
        pm.parent(s, ctrl, s=True, r=True)
        s.rename('%sText'%text)
        pm.connectAttr("%s.%s" %(ctrl.name(), display_attr), s.visibility)

    pm.delete(text_curve)