Exemple #1
0
 def push_average(self, dir):
     uvs = UV()
     center = uvs.get_pivot()
     if dir == 'u':
         pm.polyEditUV(uvs.uvs, r=False, u=center[0])
     if dir == 'v':
         pm.polyEditUV(uvs.uvs, r=False, v=center[1])
Exemple #2
0
def move_face_shell(faces, u=0, v=0):
    """ Move all uvs related to arg faces by u and v values
    """
    udim = uv_udim_convert([u,v])
    uvs = pm.polyListComponentConversion(faces, tuv=True)
    pm.polyEditUV(uvs, u=-(u-1), v=-(v-1))
    pm.sets(faces, n=set_name%str(udim))
Exemple #3
0
 def uv_scale_sel_components(self, scale_factor):
     """
     scale selected components' uv
     """
     # convert selected components to uvs
     current_sel = pm.ls(sl=True)
     pm.select(d=True)
     for i in current_sel:
         pm.select(pm.polyListComponentConversion(i, toUV=True), add=True)
     # get uvs class
     current_sel_uvs = pm.ls(sl=True)
     # get selected uvs' center
     num_uvs = 0
     uvs_center_u = 0
     uvs_center_v = 0
     for uvs in current_sel_uvs:
         num_uvs += len(uvs)
         for uv in uvs:
             uvs_center_u += pm.polyEditUV(uv, query=True)[0]
             uvs_center_v += pm.polyEditUV(uv, query=True)[1]
     uvs_center_u = uvs_center_u / num_uvs
     uvs_center_v = uvs_center_v / num_uvs
     # do scale
     pm.polyEditUV(pivotU=uvs_center_u,
                   pivotV=uvs_center_v,
                   scaleU=scale_factor,
                   scaleV=scale_factor)
Exemple #4
0
def get_closest_component(ob, mesh_node, uv=True, pos=False):
    ob_pos = ob.getTranslation(space='world')
    closest_info = get_closest_info(ob_pos, mesh_node)
    closest_vert_pos = closest_info['Closest Vertex'].getPosition(
        space='world')
    closest_components = [closest_vert_pos, closest_info['Closest Mid Edge']]
    distance_cmp = [ob_pos.distanceTo(cp) for cp in closest_components]
    if distance_cmp[0] < distance_cmp[1]:
        result = closest_info['Closest Vertex']
        if pos:
            result = result.getPosition(space='world')
            uv = False
        if uv:
            vert_uv = pm.polyListComponentConversion(result, fv=True, tuv=True)
            result = pm.polyEditUV(vert_uv, q=True)
    else:
        result = closest_info['Closest Edge']
        if pos:
            result = closest_info['Closest Mid Edge']
            uv = False
        if uv:
            edge_uv = pm.polyListComponentConversion(result, fe=True, tuv=True)
            edge_uv_coor = pm.polyEditUV(edge_uv, q=True)
            mid_edge_uv = ((edge_uv_coor[0] + edge_uv_coor[2]) / 2,
                           (edge_uv_coor[1] + edge_uv_coor[3]) / 2)
            result = mid_edge_uv
    return result
Exemple #5
0
    def flip(self, axis='u'):
        if axis == 'u':
            u = -1
            v = 1
        elif axis == 'v':
            u = 1
            v = -1

        pm.polyEditUV(pu=self.piv_loc()[0], scaleU=u, scaleV=v)
Exemple #6
0
    def rotate(self, angle=None, dir='ccw'):
        if angle is None:
            angle = self.manipValue.getValue()

        if dir == 'ccw':
            dir = 1
        elif dir == 'cw':
            dir = -1

        pm.polyEditUV(pu=self.piv_loc()[0], pv=self.piv_loc()[1], angle=angle * dir)
Exemple #7
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)
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)
Exemple #9
0
    def scale(self, axis=None, flip=False):
        if axis == 'u':
            u = self.manipValue.getValue()
            v = 0
        elif axis == 'v':
            u = 0
            v = self.manipValue.getValue()
        else:
            u = self.manipValue.getValue()
            v = self.manipValue.getValue()

        pm.polyEditUV(pu=self.piv_loc()[0], pv=self.piv_loc()[1], su=u, sv=v)
Exemple #10
0
    def uvLayoutFast(self, geo):
        pm.u3dLayout(geo, res=256, mutations=1, rot=2, scl=0, box=[0, 1, 0, 1], shellSpacing=0.0009765625,
                     tileMargin=0.0009765625, layoutScaleMode=1)

        shellList = self.getUVShell(geo)
        pm.select(shellList)
        mel.eval('texStackShells {};')
        mel.eval('texSnapShells bottomLeft;')
        mel.eval('texAlignShells minV {} "";')
        mel.eval('texAlignShells minU {} "";')

        pm.polyEditUV(shellList, u=0.001, v=0.001)
Exemple #11
0
 def draw_cubes(self, lod=None):
     for id, level, location in sorted(self.vox.read_points(lod)):
         
         size = pow(2, level)
         offset = pow(2, level - 1) - 0.5
         #multiplier, movement = move_offsets(level)
         
         cube = pm.polyCube(w=size, h=size, d=size)[0]
         pm.move(cube, [i + offset for i in location])
         
         #Set attribute and UV map
         pm.addAttr(cube, shortName='bid', longName='BlockID', attributeType='byte')
         pm.setAttr('{}.bid'.format(cube), id)
         UVSize = size
         pm.polyEditUV('{}.map[:]'.format(cube), su=UVSize*3, sv=UVSize*4)
def afUnfoldUDIM():
    #select UV shells
    curSelUVs = pm.ls(sl=True)

    mm.eval("PolySelectConvert 1")
    
    UVBbox = pm.polyEvaluate(curSelUVs, bc2 = True)
    UPos = int(math.floor(UVBbox[0][0]))
    VPos = int(math.floor(UVBbox[1][0]))
    #udim = int(VPos*10 + UPos + 1001)
    
    mm.eval("RoadkillProOrganic")
    
    pm.polyEditUV(u=UPos,v=VPos,r=True)
    mm.eval("PolySelectConvert 4")
Exemple #13
0
    def moveUVs(self):
        for i, mesh_name in enumerate(self.mesh_names):
            meshes = pm.ls([mesh_name + '_*', mesh_name + 'FBX*'],
                           type='transform')

            for tile, face_ranges in self.uv_adjustments[i].items():
                face_sets = [
                    mesh.f[face_range[0]:face_range[1]] for mesh in meshes
                    for face_range in face_ranges
                ]
                offsets = [
                    tile - int(face_set.getUVs()[0][0])
                    for face_set in face_sets
                ]
                for face_set, offset in zip(face_sets, offsets):
                    pm.polyEditUV(face_set, uValue=offset, relative=True)
Exemple #14
0
    def checkUVInBoundaries(self, shell):
        uvs = pm.polyListComponentConversion(shell, tuv=True)

        uMax = 1
        uMin = 0
        vMax = 1
        vMin = 0
        for i, uv in zip(list(range(len(pm.ls(uvs, fl=True)))),
                         pm.ls(uvs, fl=True)):
            u, v = pm.polyEditUV(uv, q=True, u=True, v=True)

            if i > 0:
                if (u > uMin) and (u < uMax) and (v > vMin) and (v < vMax):
                    pass
                    # return True
                else:
                    return False

            uMax = int(u) + 1
            uMin = int(u)

            vMax = int(v) + 1
            vMin = int(v)

        return True
Exemple #15
0
def bdCreateFolSnp():
    '''
    Category: Snappers
    '''
    selection = pm.ls(sl=1)
    last_flc = max([
        int(token.getParent().name().split('_')[-1])
        for token in pm.ls('head_snappers_flc_*', type='follicle')
    ])
    if selection:
        for vtx in selection:
            last_flc += 1
            shapeStr = vtx.name().split('.')[0]
            shape = pm.ls(shapeStr)[0]

            flcShape = pm.createNode('follicle',
                                     name='head_snappers_flc_' +
                                     str(last_flc) + 'Shape')
            flcTransform = flcShape.getParent()
            # flcTransform.rename('head_snappers_flc_')

            shape.outMesh.connect(flcShape.inputMesh)
            shape.worldMatrix[0].connect(flcShape.inputWorldMatrix)

            flcShape.outRotate.connect(flcTransform.rotate)
            flcShape.outTranslate.connect(flcTransform.translate)

            uvPos = vtx.getUV(uvSet=shape.getCurrentUVSetName())
            uv = pm.polyListComponentConversion(vtx, tuv=True)[0]
            u, v = pm.polyEditUV(uv, q=1)

            flcShape.parameterU.set(u)
            flcShape.parameterV.set(v)
Exemple #16
0
def bdCreateFol():
    '''
    Category: Rig
    '''
    selection = pm.ls(sl=1, fl=1)
    if selection:
        for vtx in selection:
            shapeStr = vtx.name().split('.')[0]
            shape = pm.ls(shapeStr)[0]

            flcShape = pm.createNode('follicle')
            flcTransform = flcShape.getParent()
            # flcTransform.rename('head_snappers_flc_')

            shape.outMesh.connect(flcShape.inputMesh)
            shape.worldMatrix[0].connect(flcShape.inputWorldMatrix)

            flcShape.outRotate.connect(flcTransform.rotate)
            flcShape.outTranslate.connect(flcTransform.translate)

            uv_m = pm.polyListComponentConversion(vtx, tuv=True)[0]
            uv = pm.ls(uv_m, fl=1)[0]
            try:
                u, v = pm.polyEditUV(uv, q=1)
            except:
                pm.warning('Total fail')

            flcShape.parameterU.set(u)
            flcShape.parameterV.set(v)
Exemple #17
0
def udim_to_sg(node, mapping):
    print '\nUDIM to SG'

    # iterate over Shading group > UDIM mapping
    print 'MAPPING', mapping
    for udim, sgstring in mapping.iteritems():
        
        faces = faces_from_udim(node, udim)
        sg = sg_from_string(sgstring)
        print 'DEBUG', sgstring, '>' , sg, faces, 'UDIM', udim
        if not sg or len(faces) < 1:
            print 'material could not be found or no faces: SG:', sgstring, sg, 'faces', faces
        else:
            pm.sets(sg, e = True, forceElement = faces)
            pm.mel.polySplitTextureUV()
            pm.polyEditUV(faces, relative=True, uValue=-udim)
Exemple #18
0
    def finalLayoutUV(self, geoList, area=1):
        tileNumber = math.ceil(area)
        tileValue = tileNumber / 2
        uCount = tileValue if tileValue % 2 else tileValue + 1
        vCount = tileValue + 1

        print(('UV: ', math.ceil(uCount), math.ceil(vCount)))
        self.uvLayoutNoScale(geoList, math.ceil(uCount), math.ceil(vCount))

        badShellList = []
        for geo in geoList:
            for shell in self.getUVShell(geo):
                if not self.checkUVInBoundaries(shell):
                    badShellList.append(shell)
        if len(badShellList) > 0:
            print('Bad Shells')
            self.uvLayoutNoScale(badShellList, 1, 1)
            pm.polyEditUV(badShellList, u=0, v=vCount)
Exemple #19
0
def uvmp_align_cardinal(*args, **kwargs):
    '''
    automaticaly rotate uv shell to align selected edge vertically or horizontally
    '''

    edges = pm.filterExpand(sm=32, ex=True)
    if edges:
        uvs = pm.polyListComponentConversion(edges[0], toUV=True)
        uvs = pm.filterExpand(uvs, sm=35, ex=True)
        uvA = pm.polyEditUV(uvs[0], q=True)
        uvB = pm.polyEditUV(uvs[1], q=True)
        pm.select(uvs, replace=True)

        xDiff = uvA[0] - uvB[0]
        yDiff = uvA[1] - uvB[1]
        angle = math.degrees(math.atan2(yDiff, xDiff))

        # find the quadrant of the vector and flip the rotation if needed
        sign = 1
        if angle <= 45 and angle > -180:
            sign = -1

        # find the minimum angle
        while abs(angle) > 45:
            if angle > 0:
                angle = 90 - angle
            else:
                angle = 90 + angle

        angle = sign * angle  # invert or not

        try:
            texDim = lcTexture.TextureEditor().getTextureDimensions()
            uvCenter = lcGeometry.UV().getBoundingBoxCenter()
            lcGeometry.UV().grabShell()
            lcGeometry.UV().rotate(angle, uvCenter, texDim)
        except:
            lcUtility.Utility.lc_print_exception('something went wrong')
        finally:
            pm.select(edges, replace=True)
    else:
        lcUtility.Utility.lc_print('Please select an edge to straighten along',
                                   mode='warning')
 def UVFix(self):
     oldSel = pm.ls(sl = 1)
     selected = pm.ls(sl = 1, o = 1)
     pm.select(cl = 1)
     for s in selected:
         #############get info from other nodes
         myCurrentUvSet =  pm.polyUVSet(s, q = True , currentUVSet = True )[0]
         pair1, pair2 = self.findTips(s, myCurrentUvSet)
         ###############select and store roots and tips
         tipsUV = []
         rootEdges =  pm.ls(    pm.polySelect(    s, ass = 1 ,shortestEdgePath = (pair2[0].index(), pair2[1].index()    )    ), fl = 1)
         tipsUV.append(  pm.ls(  pm.polyListComponentConversion(  rootEdges, fe =1, tuv =1), fl = True  )    )
         tipEdges =  pm.ls(    pm.polySelect(    s,  ass = 1 ,shortestEdgePath = (pair1[0].index(), pair1[1].index()    )    ), fl = 1)
         tipsUV.append(  pm.ls(  pm.polyListComponentConversion(  tipEdges, fe =1, tuv =1),  fl = True )    )
         #########select and unfold the middle part of the mesh
         pm.select(  pm.ls(tipsUV, fl = 1), replace = True  )
         pm.runtime.InvertSelection()
         if self.squareCheckBox.getValue() == 1:
             pm.unfold(ps=0, us=False, i=4312, gmb=0.9457, pub=0, oa=1, ss=15.5797, gb=0.7597)
             ###########selecting length boarders
             side1 = pm.ls(pm.polySelect(ebp = [  tipEdges[0].index(), rootEdges[0].index()], ass = True ), fl = 1)
             side1 = [n for n in side1 if n not in rootEdges and n not in tipEdges]
             side2 = pm.ls(pm.polySelect(ebp = [  tipEdges[-1].index(), rootEdges[-1].index()], ass = True ), fl = 1)
             side2 = [n for n in side2 if n not in rootEdges and n not in tipEdges]
             ##########calculate all the averages
             boarder1Avg = self.tupleAvg([pair1[0].getUV(uvSet = myCurrentUvSet), pair2[0].getUV(uvSet = myCurrentUvSet)])
             boarder2Avg = self.tupleAvg([pair1[1].getUV(uvSet = myCurrentUvSet), pair2[1].getUV(uvSet = myCurrentUvSet)])
             islandAvg = self.tupleAvg([boarder1Avg, boarder2Avg])
             #########straighten length boarders
             for x in side1:
                 pm.polyEditUV(x,  u = boarder1Avg[0], r = False, uvSetName = myCurrentUvSet)
             for x in side2:
                 pm.polyEditUV(x,  u = boarder2Avg[0],  r = False, uvSetName = myCurrentUvSet)
             ##########get the perimeter of the uv island
             borderUVs = ['{}.map[{}]'.format(s,x.getUVIndices()[0]) for x in pm.ls(s.vtx, fl = 1) if x.isOnBoundary()]
             pm.select(borderUVs)
             pm.runtime.InvertSelection()
             pm.Unfold3D(pm.selected(),rs=2, ite=0, bi=1, p=0, u=1, ms=1024, tf=1)
         else: pm.Unfold3D(pm.selected(),rs=2, ite=0, bi=1, p=0, u=1, ms=1024, tf=1)
     pm.select(oldSel)
Exemple #21
0
    def cutUVTile(self, shell):
        for tile in self.checkUVBoundaries(shell):
            tmpBuffer = []
            uvs = pm.polyListComponentConversion(shell, tuv=True)

            for uv in pm.ls(uvs, fl=True):
                u, v = pm.polyEditUV(uv, q=True, u=True, v=True)
                if u > tile[0] and u < tile[1] and v > tile[2] and v < tile[3]:
                    tmpBuffer.append(uv)

            faces = pm.polyListComponentConversion(pm.ls(tmpBuffer), tuv=True)
            pm.select(faces)
            mel.eval('CreateUVShellAlongBorder;')
Exemple #22
0
    def match_shell(self, maxrange):  # FIXME MAX Range set

        snapuvs = pm.ls(pm.polyListComponentConversion(tuv=True), sl=True, fl=True)  # getUVs to match

        objs = [i.getShape() for i in pm.ls(hl=True, fl=True)]
        alluvs = pm.ls(pm.polyListComponentConversion(objs, tuv=True), fl=True)
        alluvs = sorted(set(alluvs) - set(snapuvs))  # get all uvs and subtract from snap uvs

        snappos = [pm.polyEditUV(i, q=True) for i in snapuvs]  # Get pos for snap and all
        allpos = [pm.polyEditUV(i, q=True) for i in alluvs]

        for i in range(len(snapuvs)):
            inrange = []
            for j in range(len(alluvs)):
                x = snappos[i][0] - allpos[j][0]
                y = snappos[i][1] - allpos[j][1]
                dist = math.sqrt((x ** 2) + (y ** 2))
                if dist < maxrange:
                    inrange.append((allpos[j], dist))

            if inrange:
                inrange = min(inrange, key=lambda x: x[1])
                pm.polyEditUV(snapuvs[i], u=inrange[0][0], v=inrange[0][1], r=False)
 def rotate(self, angle, pivot, aspect, *args, **kwargs):
     scaleDownU = float(aspect[0]) / float(aspect[1])
     scaleUpU = float(aspect[1]) / float(aspect[0])
     pm.polyEditUV(pivotU=pivot[0],
                   pivotV=pivot[1],
                   r=False,
                   scaleU=scaleDownU)
     pm.polyEditUV(pivotU=pivot[0], pivotV=pivot[1], a=angle)
     pm.polyEditUV(pivotU=pivot[0],
                   pivotV=pivot[1],
                   r=False,
                   scaleU=scaleUpU)
Exemple #24
0
    def checkUVBoundaries(self, shell):
        uvs = pm.polyListComponentConversion(shell, tuv=True)
        uvTileRange = []

        for i, uv in zip(range(len(pm.ls(uvs, fl=True))), pm.ls(uvs, fl=True)):
            u, v = pm.polyEditUV(uv, q=True, u=True, v=True)

            uMax = int(u) + 1
            uMin = int(u)

            vMax = int(v) + 1
            vMin = int(v)

            tile = [uMin, uMax, vMin, vMax]
            if tile not in uvTileRange:
                uvTileRange.append([uMin, uMax, vMin, vMax])

        return uvTileRange
Exemple #25
0
def face_avg_uv(face):
    """ Gets the average uv position for all the uv points on a face and return the uv floor value
    Args:
        face (pm.general.MeshFace): given face to be queried
    Returns: [int, int]: list 2 integers representing u and v coordinates
    """
    face_uvs = pm.ls(pm.polyListComponentConversion(face, tuv=True), fl=True)
    uvs = {}
    for face_uv in face_uvs:
        u, v = pm.polyEditUV(face_uv, q=True)
        uvs.setdefault('u',[])
        uvs.setdefault('v',[])
        uvs['u'].append(u)
        uvs['v'].append(v)
    
    avg_u = int(math.floor(sum(uvs['u'])/len(uvs['u'])))
    avg_v = int(math.floor(sum(uvs['v'])/len(uvs['v'])))
    
    return [avg_u+1, avg_v+1]
Exemple #26
0
def set_symmetry_axis(components):
    """
    Given a list of components, set the UV symmetry mirror axis and axis position.

    If the components only have 1 UV, the axis position will be set based on the
    currently selected axis.
    """
    uvs = pm.polyEditUV(components, q=True)
    uvs = [(u, v) for u, v in zip(uvs[0::2], uvs[1::2])]

    # Find the bounding box of the selection.
    bounds_u = min(u for u, v in uvs), max(u for u, v in uvs)
    bounds_v = min(v for u, v in uvs), max(v for u, v in uvs)

    # Choose a vertical or horizontal axis based on the bounding box.
    width = abs(bounds_u[0] - bounds_u[1])
    height = abs(bounds_v[0] - bounds_v[1])

    # Do a quick sanity check to make sure the selection is vertical or horizontal.ww
    angle = math.atan2(width, height) * 180 / math.pi
    tol = 10
    if abs(angle) > tol and abs(90 - angle) > tol:
        om.MGlobal.displayInfo('Selected symmetry plane isn\'t axis-aligned')
        return

    if width == 0 and height == 0:
        # If the size is 0, a single UV was selected.  Just set the axis based on the current mode.
        u_axis = pm.optionVar(q='polySymmetrizeUVAxis')
    else:
        # If the bounding box is vertical, the seam is on the V plane.
        u_axis = width > height
        pm.optionVar(iv=('polySymmetrizeUVAxis', 1 if u_axis else 0))

    # Use the average of the selection as the mirror plane.  If there's only one UV selected, this will
    # be its position.
    if u_axis:
        offset = (bounds_v[0] + bounds_v[1]) / 2
    else:
        offset = (bounds_u[0] + bounds_u[1]) / 2

    pm.optionVar(fv=('polySymmetrizeUVAxisOffset', offset))
Exemple #27
0
def bdJointsOnEdge():
    '''
    Category: Joint
    Creates joints on the selected edges.
    The edges are converted to vertices, locators and joints are created at the position of those vertices and the joints are point constrained to the locators
    '''
    if pm.ls(sl=1) > 0:
        selection = pm.ls(sl=True, fl=1)
        edgeSelection = []
        if isinstance(selection[0], (pm.MeshEdge)):
            edgeSelection = selection
        else:
            pm.error('Selection is not an edge')
            return
        vertices = pm.polyListComponentConversion(edgeSelection,
                                                  fromEdge=1,
                                                  tv=1)
        pm.select(vertices)
        vertices = pm.ls(sl=1, fl=1)

        mesh = vertices[0].name().split('.')[0].replace('Shape', '')
        locators = []

        for vert in vertices:
            # vertUV = vert.getUV()
            uv = pm.polyListComponentConversion(vert, fromVertex=1, tuv=1)
            vertUV = pm.polyEditUV(uv[0], query=True)
            locator = pm.spaceLocator(n='loc_%s' % vert)
            locators.append(locator)
            cnstr = pm.animation.pointOnPolyConstraint(vert, locator)
            pm.setAttr('%s.%sU0' % (cnstr, mesh), vertUV[0])
            pm.setAttr('%s.%sV0' % (cnstr, mesh), vertUV[1])

        for loc in locators:
            pm.select(cl=1)
            jnt = pm.joint(p=(0, 0, 0), name=loc.name().replace('loc', 'jnt'))
            pm.pointConstraint(loc, jnt, mo=False)
Exemple #28
0
def bdJointsOnEdge():
    edgeSelection = pm.ls(sl=True)
    vertices = pm.polyListComponentConversion(edgeSelection, fromEdge=1, tv=1)
    pm.select(vertices)
    vertices = pm.ls(sl=1, fl=1)

    mesh = vertices[0].name().split('.')[0].replace('Shape', '')
    locators = []

    for vert in vertices:
        #vertUV = vert.getUV()
        uv = pm.polyListComponentConversion(vert, fromVertex=1, tuv=1)
        vertUV = pm.polyEditUV(uv[0], query=True)
        locator = pm.spaceLocator(n='loc_%s' % vert)
        locators.append(locator)
        cnstr = pm.animation.pointOnPolyConstraint(vert, locator)
        pm.setAttr('%s.%sU0' % (cnstr, mesh), vertUV[0])
        pm.setAttr('%s.%sV0' % (cnstr, mesh), vertUV[1])

    for loc in locators:
        pm.select(cl=1)
        jnt = pm.joint(p=(0, 0, 0), name=loc.name().replace('loc', 'jnt'))
        print jnt
        pm.pointConstraint(loc, jnt, mo=False)
Exemple #29
0
def bdJointsOnEdge():
    edgeSelection = pm.ls(sl=True)
    vertices = pm.polyListComponentConversion(edgeSelection, fromEdge=1 , tv=1)
    pm.select(vertices)
    vertices = pm.ls(sl=1,fl=1)

    mesh = vertices[0].name().split('.')[0].replace('Shape','')
    locators = []

    for vert in vertices:
        #vertUV = vert.getUV()
        uv = pm.polyListComponentConversion(vert, fromVertex =1 , tuv=1)
        vertUV = pm.polyEditUV(uv[0] , query = True)
        locator = pm.spaceLocator(n='loc_%s'%vert)
        locators.append(locator)
        cnstr = pm.animation.pointOnPolyConstraint(vert,locator)
        pm.setAttr('%s.%sU0'%(cnstr,mesh),vertUV[0])
        pm.setAttr('%s.%sV0'%(cnstr,mesh),vertUV[1])

    for loc in locators:
        pm.select(cl=1)
        jnt = pm.joint(p=(0,0,0),name=loc.name().replace('loc','jnt'))
        print jnt
        pm.pointConstraint(loc,jnt,mo=False)
Exemple #30
0
 def move(self, u=0, v=0):
     pm.polyEditUV(uValue=self.manipValue.getValue() * u, vValue=self.manipValue.getValue() * v)
Exemple #31
0
    def snap_uvs(self, pos):
        uvs = UV()

        piv = uvs.get_pivot()
        bounds = uvs.get_bounds()
        centeru = 0.5 - piv[0]
        centerv = 0.5 - piv[1]

        left = -bounds[0][0]
        right = 1 - bounds[0][1]
        top = 1 - bounds[1][1]
        bottom = -bounds[1][0]

        if pos == 'topLeft':
            pm.polyEditUV(uvs.uvs, u=left, v=top)
        if pos == 'topCenter':
            pm.polyEditUV(uvs.uvs, u=centeru, v=top)
        if pos == 'topRight':
            pm.polyEditUV(uvs.uvs, u=right, v=top)
        if pos == 'centerLeft':
            pm.polyEditUV(uvs.uvs, u=left, v=centerv)
        if pos == 'center':
            pm.polyEditUV(uvs.uvs, u=centeru, v=centerv)
        if pos == 'centerRight':
            pm.polyEditUV(uvs.uvs, u=right, v=centerv)
        if pos == 'bottomLeft':
            pm.polyEditUV(uvs.uvs, u=left, v=bottom)
        if pos == 'bottomCenter':
            pm.polyEditUV(uvs.uvs, u=centeru, v=bottom)
        if pos == 'bottomRight':
            pm.polyEditUV(uvs.uvs, u=right, v=bottom)
Exemple #32
0
def createHairMesh(profilesList,
                   name="hairMesh#",
                   cSet="hairCrease",
                   mat="",
                   lengthDivs=7,
                   widthDivs=4):
    '''create a Hair Tube with auto crease and material from list of Curve Profiles'''
    print profilesList
    if not profilesList or all(
        [type(o.getShape()) != pm.nodetypes.NurbsCurve for o in profilesList]):
        print "no Profiles"
        return
    pm.select(profilesList)
    pm.nurbsToPolygonsPref(pt=1, un=4, vn=7, f=2, ut=2, vt=2)
    HairMesh = pm.loft(n=name,
                       po=1,
                       ch=1,
                       u=1,
                       c=0,
                       ar=1,
                       d=3,
                       ss=1,
                       rn=0,
                       rsn=True)
    ###
    #lock all Transform
    lockTransform(HairMesh[0])
    #custom Attribute add
    HairMesh[0].addAttr('lengthDivisions', min=1, at='long', dv=lengthDivs)
    HairMesh[0].addAttr('widthDivisions', min=4, at='long', dv=widthDivs)
    HairMesh[0].setAttr('lengthDivisions', e=1, k=1)
    HairMesh[0].setAttr('widthDivisions', e=1, k=1)
    HairTess = pm.listConnections(HairMesh)[-1]
    HairMesh[0].connectAttr('widthDivisions', HairTess + ".uNumber")
    HairMesh[0].connectAttr('lengthDivisions', HairTess + ".vNumber")
    HairMeshShape = HairMesh[0].getShape()
    ###
    #set Crease
    pm.select(HairMeshShape.e[0, 2], r=1)
    pm.runtime.SelectEdgeLoopSp()
    sideEdges = pm.selected()
    if bool(pm.ls(cSet, type=pm.nodetypes.CreaseSet)):
        hsSet = pm.ls(cSet, type=pm.nodetypes.CreaseSet)[0]
    else:
        hsSet = pm.nodetypes.CreaseSet(name=cSet)
        hsSet.setAttr('creaseLevel', 2.0)
    for e in sideEdges:
        pm.sets(hsSet, forceElement=e)
    #assign Texture
    HairUV = HairMeshShape.map
    pm.polyEditUV(HairUV, pu=0.5, pv=0.5, su=0.3, sv=1)
    pm.polyEditUV(HairUV, u=rand.uniform(-0.1, 0.1))
    ###
    #Add Vray OpenSubdiv
    pm.select(HairMesh[0], r=1)
    addVrayOpenSubdivAttr()
    ###
    #set Smoothness
    pm.displaySmoothness(po=3)
    ###
    #set Material
    if bool(pm.ls(mat, type=pm.nodetypes.ShadingEngine)):
        pm.sets(pm.ls(mat)[0], forceElement=HairMesh[0])
    return HairMesh
Exemple #33
0
def randU(offset=0.1):
    sel = pm.selected()
    if not sel:
        return
    for o in sel:
        pm.polyEditUV(o.map, u=rand.uniform(-offset, offset))
Exemple #34
0
def LeaveFace(uvls=None,**op):
    if uvls is None: uvls=[]
    if op.get('tg'):
        tgMesh=op.get('tg')
    else: tgMesh='Null'
    if tgMesh=='Null' or len(uvls)==0: return None    
    pm.select( pm.polyListComponentConversion(tgMesh, tf=1) )
    tgAllFace=pm.ls(sl=1,fl=1)
    pm.select( pm.polyListComponentConversion(uvls, tf=1) )
    tgSlFace=pm.ls(sl=1,fl=1)
    delFaceLs=list( set(tgAllFace)-set(tgSlFace) )
    pm.delete(delFaceLs)
    
slMesh=pm.ls(sl=1)[0]
uvShellLs=UVShell(slMesh)
copyMeshLs=[]
for i in xrange(len(uvShellLs)):
    copyMeshLs.append( pm.duplicate(slMesh, n='%sCopy%d_geo'% (slMesh.name(),i+1) )[0] )
    slTgUVLs=ChangeUVListTarget(uvShellLs[i],tg=copyMeshLs[i])
    LeaveFace(slTgUVLs, tg=copyMeshLs[i])
if len(copyMeshLs)>1:
    dvdMesh=pm.polyUnite(copyMeshLs,ch=0,muv=1, cp=0,n='%sDvd_geo'% slMesh.name() )[0]
else: dvdMesh=copyMeshLs[0].rename('%sDvd_geo'% slMesh.name())
unfoldMesh=pm.duplicate(dvdMesh, n='%sUnfold_geo'% slMesh.name() )[0]
pm.select( pm.polyListComponentConversion(unfoldMesh, tuv=1) )
unfoldMeshUVLs=pm.ls(sl=1,fl=1)
for ufuv in unfoldMeshUVLs:
    uvCoor=pm.polyEditUV(ufuv,q=1,u=1)
    tgVtx=pm.polyListComponentConversion(ufuv, tv=1)[0]
    pm.move(tgVtx,[ uvCoor[0]*5, 0.0, uvCoor[1]*-5 ],ws=1)
Exemple #35
0
 def move(self, uvw, *args, **kwargs):
   ''' moves a selection of uv's '''
   pm.polyEditUV(uValue=uvw[0],vValue=uvw[1])
Exemple #36
0
import pymel.core as pm
from maya import mel

edge_list = [
    sel for sel in pm.ls(sl=1, fl=1) if type(sel) is pm.general.MeshEdge
]
pm.select(edge_list)
# # NOTE 切断 UV
# pm.polyMapCut(edge_list)

# NOTE 转换到 UV
mel.eval(
    "ConvertSelectionToUVs;selectType -ocm -alc false;selectType -ocm -polymeshUV true"
)
uv_list = pm.ls(sl=1, fl=1)

for pt in uv_list:
    u, v = pm.polyEditUV(pt, q=1, u=1)
    pm.polyEditUV(pt, v=-v)
import pymel.core as pm
import maya.mel as mel

allSets = pm.ls(sl=1,type="objectSet")

for i in range(0,len(allSets)):
    if i<10:
        pm.select(allSets[i],r=1,ne=1)
        pm.select(hierarchy=1)
        mel.eval("ConvertSelectionToUVs;")
        pm.polyEditUV(u=i,v=0)
    elif i>=10<20:
        pm.select(allSets[i],r=1,ne=1)
        pm.select(hierarchy=1)
        mel.eval("ConvertSelectionToUVs;")
        pm.polyEditUV(u=i-10,v=1)
    elif i>=20<30:
        pm.select(allSets[i],r=1,ne=1)
        pm.select(hierarchy=1)
        mel.eval("ConvertSelectionToUVs;")
        pm.polyEditUV(u=i-20,v=2)
    elif i>=30<40:
        pm.select(allSets[i],r=1,ne=1)
        pm.select(hierarchy=1)
        mel.eval("ConvertSelectionToUVs;")
        pm.polyEditUV(u=i-30,v=3)
Exemple #38
0
def transform_udim(node, udim_source, udim_target, faces):
    pm.mel.polySplitTextureUV()
    print 'mv u', node, udim_source+udim_target
    pm.polyEditUV(faces, relative=True, uValue=udim_source+udim_target)
 def move(self, uvw, *args, **kwargs):
     ''' moves a selection of uv's '''
     pm.polyEditUV(uValue=uvw[0], vValue=uvw[1])
Exemple #40
0
    def align_shells(self, align):
        sel = UV()
        sel.get_shells()

        shellsuvs = []
        for shell in sel.shells:
            for uv in shell.uvs:
                shellsuvs.append(uv)

        alluvs = UV(shellsuvs)
        alluvs.get_bounds()

        for shell in sel.shells:
            if align == 'left':
                pm.polyEditUV(shell.uvs, u=alluvs.xMin - shell.xMin)
            elif align == 'centerU':
                pm.polyEditUV(shell.uvs, u=(alluvs.xMin + alluvs.xMax) / 2 - (shell.xMax + shell.xMin) / 2)
            elif align == 'right':
                pm.polyEditUV(shell.uvs, u=alluvs.xMin - shell.xMin)

            elif align == 'top':
                pm.polyEditUV(shell.uvs, v=alluvs.yMax - shell.yMax)
            elif align == 'centerV':
                pm.polyEditUV(shell.uvs, v=(alluvs.yMin + alluvs.yMax) / 2 - (shell.yMax + shell.xMin) / 2)
            elif align == 'bottom':
                pm.polyEditUV(shell.uvs, v=alluvs.yMin - shell.yMin)
Exemple #41
0
 def rotate(self, angle, pivot, aspect, *args, **kwargs):
   scaleDownU = float(aspect[0])/float(aspect[1])
   scaleUpU = float(aspect[1])/float(aspect[0])
   pm.polyEditUV(pivotU=pivot[0], pivotV=pivot[1], r=False, scaleU=scaleDownU)
   pm.polyEditUV(pivotU=pivot[0], pivotV=pivot[1], a=angle)
   pm.polyEditUV(pivotU=pivot[0], pivotV=pivot[1], r=False, scaleU=scaleUpU)
Exemple #42
0
 def scale(self, uv, pivot, *args, **kwargs): 
   pm.polyEditUV(pivotU=pivot[0], pivotV=pivot[1], scaleU=uv[0], scaleV=uv[1])
 def scale(self, uv, pivot, *args, **kwargs):
     pm.polyEditUV(pivotU=pivot[0],
                   pivotV=pivot[1],
                   scaleU=uv[0],
                   scaleV=uv[1])