def selection_mode(mode): """ Function for vertex selection mode buttons """ if mode == 1: pm.mel.eval('PolySelectTraverse 1') elif mode == 2: pm.mel.eval('PolySelectTraverse 2') elif mode == 3: pm.polySelectSp(loop=True) elif mode == 4: pm.polySelectSp(ring=True)
def getOrderedLoops(self, vtxL): comp = {"edge1": [], "edge2": []} for v in vtxL: ring = [] ring.append(v) neigh = v.connectedVertices() for n in neigh: if n in vtxL: ring.append(n) pym.select(ring) pym.polySelectSp(l=1) edge = pym.ls(sl=1, fl=1) if edge == comp["edge1"]: continue if len(comp["edge1"]) == 0 and len(comp["edge2"]) == 0: comp["edge1"] = edge continue comp["edge2"] = edge # aqui se calcula el vertice mas cercano de todos los vertices seleccionados loc = pym.PyNode('head_Loc') pos = loc.getRotatePivot(space='world') closestVert = None minLength = None secMinLength = None secClosestVert = None for v in vtxL: thisLength = (pos - v.getPosition(space='world')).length() if minLength is None or thisLength < minLength: minLength = thisLength closestVert = v # a partir del vtx mas cercano, comparamos con el loop mas cercano originEdge = [ comp[edge] for edge in comp if closestVert in comp[edge] ][0] # ahora encontramos el segundo mas cercano, para tener el orden de loop for neighb in closestVert.connectedVertices(): if neighb not in originEdge: continue thisLength = (pos - neighb.getPosition(space='world')).length() if secMinLength is None or thisLength < secMinLength: secMinLength = thisLength secClosestVert = neighb # ahora loopeamos a traves de todos los loops en orden, recursividad. # se nos genera "loopDict" un dict con todos los loops fullVerts = [] loopDict = {} loopNumber = 0 self.findAllLoops(originEdge, fullVerts, loopDict, loopNumber, closestVert, secClosestVert) return loopDict
def getVertList(vert1, vert2): currentSelection = pm.ls(selection=True) loop = pm.polySelectSp(vert1, vert2, q=True, loop=True) pm.select(loop) # We want to do the select and ls steps because they give us a list of Mesh Vertieces in stead of list of strings edge = pm.ls(selection=True) edgeVerts = list() for vertMesh in edge: for vert in vertMesh: edgeVerts.append(vert) pm.select(currentSelection) return sortVertList(vert1, vert2, edgeVerts)
def createTrailUv(poly,*args): sel = pm.ls(sl=1,type='transform') if sel: poly=sel[0] if poly == '': pm.warning('No trail selected / found') return startEdge = pm.ls(poly+ '.e[0]',fl=1)[0] edges = pm.polySelectSp(startEdge,ring=1) pm.select(cl=1) ringEdges = pm.ls(edges,fl=1) leftSideVtx = [] rightSideVtx = [] ''' for edge in ringEdges[1:-1]: sew = pm.polyMapSewMove(edge,nf=10,lps=0, ch=1) #pm.delete(sew) pm.select(poly) norm = pm.polyNormalizeUV (normalizeType=1 ,preserveAspectRatio=0) #pm.delete(norm) ''' for edge in ringEdges: vtxs = edge.connectedVertices() leftSideVtx.append(vtxs[0]) rightSideVtx.append(vtxs[1]) leftLength = getTotalEdgesLength(leftSideVtx) #print leftLength rightLength = getTotalEdgesLength(rightSideVtx) #print rightLength uvDistorted = pm.checkBox('cbUV',q=1,v=1) setPosUv(leftSideVtx,leftLength,'left',uvDistorted) setPosUv(rightSideVtx,rightLength,'right',uvDistorted) pm.select(poly)