def unfoldBandUVs(object, divisions=1, history=True): """ This definition unfolds object band UVs. :param object: Object. ( String ) :param divisions: Extrusion divisions. ( Integer ) :param history: Keep construction history. ( Boolean ) """ edgesCount = cmds.polyEvaluate(object, edge=True) edges = cmds.ls(object + ".e[0:" + str(edgesCount - 1) + "]", fl=True, l=True) cmds.select(object) cmds.polySelectConstraint(m=3, t=0x8000, w=1) cmds.polySelectConstraint(m=0) for i in range(divisions): mel.eval("GrowPolygonSelectionRegion();") bandEdges = cmds.ls(sl=True, fl=True, l=True) bandFaces = cmds.ls(cmds.polyListComponentConversion(bandEdges, fe=True, tf=True), fl=True) cmds.select(bandFaces) cmds.polyForceUV(unitize=True) cmds.polySelectConstraint(m=3, t=0x8000, sm=1) seamsEdges = cmds.ls(sl=True, fl=True, l=True) weldEdges = list(set(bandEdges).difference(set(seamsEdges))) cmds.polyMapSewMove(weldEdges) cmds.polyLayoutUV(bandFaces, scale=1, rotateForBestFit=0, layout=1) uvs = cmds.polyListComponentConversion(bandFaces, toUV=1) cmds.polyEditUV(uvs, u=1, v=0) not history and cmds.delete(object, ch=True)
def unfoldBandUVs(object, divisions=1, history=True): """ Unfolds object band UVs. :param object: Object. :type object: str :param divisions: Extrusion divisions. :type divisions: int :param history: Keep construction history. :type history: bool """ edgesCount = cmds.polyEvaluate(object, edge=True) edges = cmds.ls(object + ".e[0:" + str(edgesCount - 1) + "]", fl=True, l=True) cmds.select(object) cmds.polySelectConstraint(m=3, t=0x8000, w=1) cmds.polySelectConstraint(m=0) for i in range(divisions): mel.eval("GrowPolygonSelectionRegion();") bandEdges = cmds.ls(sl=True, fl=True, l=True) bandFaces = cmds.ls(cmds.polyListComponentConversion(bandEdges, fe=True, tf=True), fl=True) cmds.select(bandFaces) cmds.polyForceUV(unitize=True) cmds.polySelectConstraint(m=3, t=0x8000, sm=1) seamsEdges = cmds.ls(sl=True, fl=True, l=True) weldEdges = list(set(bandEdges).difference(set(seamsEdges))) cmds.polyMapSewMove(weldEdges) cmds.polyLayoutUV(bandFaces, scale=1, rotateForBestFit=0, layout=1) uvs = cmds.polyListComponentConversion(bandFaces, toUV=1) cmds.polyEditUV(uvs, u=1, v=0) not history and cmds.delete(object, ch=True)
def faceUnwarp(selFaces): selEdges = cmds.polyListComponentConversion(selFaces,ff=1,te=1) selEdges = cmds.ls(selEdges, fl=1) selBorderEdges = cmds.polyListComponentConversion(selFaces,bo=1,ff=1,te=1) selBorderEdges = cmds.ls(selBorderEdges, fl=1) selInnerEdges = list( set(selEdges) - set(selBorderEdges)) cmds.polyMapCut(selEdges,ch=1) cmds.polyForceUV(selFaces,unitize=1) cmds.polyMapSewMove(selInnerEdges)
def createUv(self,mesh): cmds.polyForceUV(mesh, unitize = True) edges = cmds.polyEvaluate(mesh, e = True) cmds.select('%s.e[2:%s]' %(mesh, (edges-1)), r=True) cmds.StitchTogether() bbox = cmds.polyEvaluate(mesh, bc2 = True) if bbox[0]>bbox[1]: cmds.polyEditUV (mesh, r = True, a = 90) cmds.polyNormalizeUV(mesh,normalizeType = 1, pa = True, cot = False, nd = 1) cmds.unfold(mesh, i = 5000, ss=0.001, gb = 0, pub = False, ps = False, oa = 1, us = False) cmds.select(cl=True)
def unwrapRibbon(): selList = cmds.ls(sl=1,o=1) selListPoly = cmds.filterExpand(selList,sm=12) selListEdge = cmds.polyListComponentConversion(selListPoly,te=1) selListFace = cmds.polyListComponentConversion(selListPoly,tf=1) selListUV = cmds.polyListComponentConversion(selListPoly,tuv=1) selListEdge = map(lambda x: x+'.e[*]', selListPoly) for i in selListEdge: cmds.polyMapCut(i,ch=1) cmds.polyForceUV(selListFace,unitize=1) for i in selListEdge: cmds.polyMapSewMove(i)
def Action_Apply(self): maya_cmds.undoInfo(openChunk=True) try: items = self.window.Text_Items.toPlainText().strip().split('\n') if self.window.Check_Unitize.isChecked(): maya_cmds.polyForceUV(items, unitize=True) maya_cmds.polyMapSewMove(items, caching=True) if self.window.Check_Cut.isChecked(): cutType = self.window.Combo_CutType.currentText() if cutType == 'Automatic': maya_cmds.u3dAutoSeam(items, splitShells=self.window.Float_CutTolerance.value()) elif cutType == 'Manual': maya_cmds.polyMapCut(maya_cmds.sets(self.window.Line_CutName.text().strip(), q=True)) if self.window.Check_Unfold.isChecked(): maya_cmds.u3dUnfold(items, iterations=self.window.Int_UnfoldIteration.value(), pack=False) if self.window.Check_Optimize.isChecked(): maya_cmds.u3dOptimize(items, iterations=self.window.Int_OptimizeIteration.value()) if self.window.Check_Layout.isChecked(): paramRotate = {} if self.window.Check_LayoutRotation.isChecked(): paramRotate = { 'rotateStep': self.window.Float_LayoutRotationStep.value(), 'rotateMin': self.window.Float_LayoutRotationMin.value(), 'rotateMax': self.window.Float_LayoutRotationMax.value() } maya_cmds.u3dLayout( items, mutations=self.window.Int_LayoutIteration.value(), resolution=self.window.Int_LayoutResolution.value(), preRotateMode=self.window.Combo_LayoutAlign.currentIndex(), preScaleMode=1, tileMargin=self.window.Int_LayoutTileSpaceL.value() / float(self.window.Int_LayoutTileSpaceH.value()), shellSpacing=self.window.Int_LayoutShellSpaceL.value() / float(self.window.Int_LayoutShellSpaceH.value()), **paramRotate ) self.Event_ItemsCoverage() except Exception as e: print >> stderr, str(e) maya_cmds.undoInfo(closeChunk=True)
def unitizeAndSew(): # store UV seam as vertex becase f**k you Maya eval("PolySelectConvert 3") vtx_seam = cmds.ls(selection=True) eval("PolySelectConvert 4") #select UV shell, and convert to faces and unitize eval("polySelectBorderShell 0") eval("PolySelectConvert 1") cmds.polyForceUV(unitize=True) #convert shell to vertex and subtract the stored vertex seam, and then convert back to UV, because f**k you Maya eval("PolySelectConvert 3") cmds.select(vtx_seam, deselect=True) eval("PolySelectConvert 4") #stitch together the UV's that are not by the seam cmds.polyMapSewMove()
def unwrapCylindrical(): # Variables and selection mode = cmds.radioButtonGrp('mode', q=True, select=True) seam = cmds.ls(sl=True) cmds.SelectEdgeRingSp() cmds.ConvertSelectionToContainedFaces() body = cmds.ls(sl=True) # Chooses desired seams numEdges = (len(seam)) if (numEdges == 1): seamSel = (seam[0]) else: seamSel = (seam[0:numEdges]) bodySel = (body[0:(len(body))]) # Unwraps with or without unfolding if (mode == 1): cmds.polyPlanarProjection() cmds.select(seamSel, r=True) cmds.polyMapCut() cmds.unfold() elif (mode == 2): cmds.select(bodySel, r=True) cmds.ConvertSelectionToFaces() shell = cmds.ls(sl=True) cmds.polyForceUV(unitize=True) cmds.ConvertSelectionToContainedEdges() cmds.select(seamSel, d=True) cmds.polyMapSewMove() cmds.select(shell, r=True) cmds.ConvertSelectionToUVs() cmds.polyLayoutUV() cmds.select(shell, r=True)
def unfoldBandRegular(seamsEdges, history=False): """ This definition unfolds object band UVs using given seamsEdges. :param seamsEdges: Seams edges. ( List ) :param history: Keep construction history. ( Boolean ) """ seamsEdges = filter(lambda x: re.search(r"e\[\d+\]", x), cmds.ls(seamsEdges, fl=True, l=True)) if not seamsEdges: return object = seamsEdges[0].split(".")[0] edgesCount = cmds.polyEvaluate(object, edge=True) edges = cmds.ls(object + ".e[0:{0}]".format(str(edgesCount - 1)), fl=True, l=True) cmds.polyForceUV(object, unitize=True) print edges, seamsEdges cmds.select(list(set(edges).difference(seamsEdges))) cmds.polyMapSewMove(list(set(edges).difference(seamsEdges)), ch=True) not history and cmds.delete(object, ch=True)
def unwrapByAngle(): unf = cmds.checkBox('unf', q=True, v=True) lyt = cmds.checkBox('lyt', q=True, v=True) cmds.polyForceUV(unitize=True) cmds.selectType(pe=True) cmds.polySelectConstraint(m=3, t=0x8000, sm=2) # Constrains selection to soft edges selEdges = cmds.ls(sl=True) cmds.polyMapSewMove() cmds.polySelectConstraint(sm=0) # Turns off constraint # Unfold if chosen if (unf == 1): cmds.unfold() # Layout if chosen if (lyt == 1): cmds.select(selEdges) cmds.ConvertSelectionToShell() cmds.ConvertSelectionToUVs() cmds.polyLayoutUV(sc=1, ws=True, rbf=2)
def unwrapBySeams(): # Variables and Selection unf = cmds.checkBox('unf', q=True, v=True) lyt = cmds.checkBox('lyt', q=True, v=True) selEdges = cmds.ls(sl=True) cmds.ConvertSelectionToShell() cmds.polyForceUV(unitize=True) cmds.ConvertSelectionToEdges() cmds.select(selEdges, d=True) cmds.polyMapSewMove() # Unfold if chosen if (unf == 1): cmds.unfold() # Layout if chosen if (lyt == 1): cmds.select(selEdges) cmds.ConvertSelectionToShell() cmds.ConvertSelectionToUVs() cmds.polyLayoutUV(sc=1, ws=True, rbf=2)
def unfoldBandRegular(seamsEdges, history=False): """ Unfolds object band UVs using given seamsEdges. :param seamsEdges: Seams edges. :type seamsEdges: list :param history: Keep construction history. :type history: bool """ seamsEdges = filter(lambda x: re.search(r"e\[\d+\]", x), cmds.ls(seamsEdges, fl=True, l=True)) if not seamsEdges: return object = seamsEdges[0].split(".")[0] edgesCount = cmds.polyEvaluate(object, edge=True) edges = cmds.ls(object + ".e[0:{0}]".format(str(edgesCount - 1)), fl=True, l=True) cmds.polyForceUV(object, unitize=True) print edges, seamsEdges cmds.select(list(set(edges).difference(seamsEdges))) cmds.polyMapSewMove(list(set(edges).difference(seamsEdges)), ch=True) not history and cmds.delete(object, ch=True)