Example #1
0
def uvUnfold(*args):

    weightSolver_Val = cmds.floatSliderGrp("weightSolver", q=1, value=1)
    optimizeToOriginal_Val = cmds.floatSliderGrp("optimizeToOriginal",
                                                 q=1,
                                                 value=1)
    maxIterations_Val = cmds.intSliderGrp("unfoldMaxIterations", q=1, value=1)
    stopThresh_Val = cmds.floatSliderGrp("stopThresh", q=1, value=1)

    if (cmds.radioButtonGrp("unfoldCheckBox", q=True, sl=1) == 1):
        pinBordBool = 1
        pinUVBool = 0
    if (cmds.radioButtonGrp("unfoldCheckBox", q=True, sl=1) == 2):
        pinUVBool = 1
        pinBordBool = 0
    if (cmds.radioButtonGrp("unfoldCheckBox", q=True, sl=1) == 3):
        pinUVBool = 0
        pinBordBool = 0

    cmds.unfold(oa=0,
                gb=weightSolver_Val,
                gmb=optimizeToOriginal_Val,
                i=maxIterations_Val,
                ss=stopThresh_Val,
                pub=pinBordBool,
                ps=pinUVBool,
                us=0)
Example #2
0
    def setRatio(*args):
        resW = float(mc.text('resTextW', q=True, l=True))
        resH = float(mc.text('resTextH', q=True, l=True))

        #mult
        mult = setRatioMultiplier()

        #Define selection and convert it to uvs
        selection = mc.ls(sl=True)
        selection = mc.polyListComponentConversion(selection, tuv=True)

        #Find center of selection
        pivot = mc.polyEvaluate(selection, bc2=True)
        pu = ((pivot[0][0] + pivot[0][1]) * 0.5)
        pv = ((pivot[1][0] + pivot[1][1]) * 0.5)

        #Correct texture/scaling ratio before rotating.
        if resH != resW:
            scaleV = resH / resW
            mc.polyEditUV(pu=pu, pv=pv, su=0, sv=scaleV)

            mc.unfold(i=0,
                      us=True,
                      s=mc.floatField('ratioField', q=True, v=True))

            #Reverse correction
            scaleV = resW / resH
            mc.polyEditUV(pu=pu, pv=pv, su=0, sv=scaleV)
        else:
            mc.unfold(i=0,
                      us=True,
                      s=mc.floatField('ratioField', q=True, v=True))

        mc.select(selection, replace=True)
        return
Example #3
0
 def scaleUVRatio(self, *args):
     res = 1024
     mult = 1
     mult = (mult * (8192 / res)) / 8
     densityField = cmds.intField("ratioFld", q=1, v=1)
     unfold = 0.0009765625 * densityField
     ratioField = unfold * mult
     cmds.unfold(i=0, us=True, s=ratioField)
Example #4
0
 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)
Example #5
0
def unfoldPipe(dir):
    # Defining direction
    if (dir == 1):
        first = 1
        second = 2
    elif (dir == 2):
        first = 2
        second = 1
    cmds.unfold(oa=first, us=False)
    maya.mel.eval("polySelectBorderShell 0;")  # Selecting UV Shell
    cmds.unfold(oa=second, us=False)
Example #6
0
def adjUV(*args):
    i = 0
    testVal = cmds.intField("uvAdjustVal", q=1, v=1)

    while (i <= testVal):

        weightSolver_Val = cmds.floatSliderGrp("weightSolver", q=1, value=1)
        optimizeToOriginal_Val = cmds.floatSliderGrp("optimizeToOriginal",
                                                     q=1,
                                                     value=1)
        maxIterations_Val = cmds.intSliderGrp("unfoldMaxIterations",
                                              q=1,
                                              value=1)
        stopThresh_Val = cmds.floatSliderGrp("stopThresh", q=1, value=1)

        if (cmds.radioButtonGrp("unfoldCheckBox", q=True, sl=1) == 1):
            pinBordBool = 1
            pinUVBool = 0
        if (cmds.radioButtonGrp("unfoldCheckBox", q=True, sl=1) == 2):
            pinUVBool = 1
            pinBordBool = 0
        if (cmds.radioButtonGrp("unfoldCheckBox", q=True, sl=1) == 3):
            pinUVBool = 0
            pinBordBool = 0

        cmds.unfold(oa=0,
                    gb=weightSolver_Val,
                    gmb=optimizeToOriginal_Val,
                    i=maxIterations_Val,
                    ss=stopThresh_Val,
                    pub=pinBordBool,
                    ps=pinUVBool,
                    us=0)

        maxIterations_Val = cmds.intSliderGrp("relaxMaxIterations",
                                              q=1,
                                              value=1)

        if (cmds.radioButtonGrp("relaxCheckBox", q=True, sl=1) == 1):
            pinBordBool = 1
            pinUVBool = 0
        if (cmds.radioButtonGrp("relaxCheckBox", q=True, sl=1) == 2):
            pinUVBool = 1
            pinBordBool = 0
        if (cmds.radioButtonGrp("relaxCheckBox", q=True, sl=1) == 3):
            pinUVBool = 0
            pinBordBool = 0

        cmds.untangleUV(r="harmonic",
                        pb=pinBordBool,
                        ps=pinUVBool,
                        mri=maxIterations_Val)

        i = i + 1
Example #7
0
def autoMap(uvMin, uvMax, proporcion=1, firstHalfOfMeshUVArray=firstHalfOfMeshUVs, secondHalfOfMeshUVArray=secondHalfOfMeshUVs):
	'''
	Cycles through two lists of uv ids.
	First action gets the mapping in the desired horizontal position
	Second action distributes the vertices vertically through an unfold method
	'''
	for uv in firstHalfOfMeshUVArray:
		cmds.select (uv, replace=True)
		moveUVHorizontal(uvMin)

	for uv in secondHalfOfMeshUVArray:
		cmds.select(uv, replace=True)
		moveUVHorizontal(uvMax)

	cmds.select(firstHalfOfMeshUVArray, replace=True)
	cmds.select(secondHalfOfMeshUVArray, add=True)
	cmds.unfold(iterations=10000, optimizeAxis=1, globalMethodBlend=0, stoppingThreshold=0, globalBlend=0, pinUvBorder=0, useScale=False)
	corregirProporcionAutomap(proporcion)
Example #8
0
def layoutUV(obj, type=0):

    totalFaces = cmds.polyEvaluate(obj, face=True)

    oneThird = totalFaces / 3

    if (type == 0):
        startFace = 0
        endFace = oneThird - 1
        cmds.polyProjection(obj + '.f[' + str(startFace) + ':' + str(endFace) +
                            ']',
                            type="planar")

    if (type == 1):
        startFace = oneThird
        endFace = (oneThird * 2) - 1
        cmds.polyProjection(obj + '.f[' + str(startFace) + ':' + str(endFace) +
                            ']',
                            type="cylindrical")

    if (type == 2):
        startFace = (oneThird * 2)
        endFace = totalFaces - 1
        cmds.polyProjection(obj + '.f[' + str(startFace) + ':' + str(endFace) +
                            ']',
                            type="spherical")

    if (type == 3):
        cmds.polyCylindricalProjection(obj + '.f[*]')
        cmds.polyMapCut(
            obj + '.e[17]'
        )  # WARNING: this does not always select a verticle edge as a cut line
        cmds.unfold(obj + '.map[*]',
                    i=5000,
                    ss=0.001,
                    gb=0,
                    gmb=0.5,
                    pub=0,
                    ps=0,
                    oa=2,
                    us=False)
Example #9
0
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)
Example #10
0
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)
Example #11
0
def unfoldAndRotate(sel):
    # unfold horizontal
    cmds.unfold(sel+'.map[*]',
        i=5000,
        ss=0.001,
        gb=0.0,
        gmb=0.5,
        pub=False,
        ps= False,
        oa=2, # 1: vertical, 2:horizontal
        us=False)
    # unfold vertical
    cmds.unfold(sel+'.map[*]',
        i=5000,
        ss=0.001,
        gb=0.0,
        gmb=0.5,
        pub=False,
        ps= False,
        oa=1, # 1: vertical, 2:horizontal
        us=False)
    # rotate UVs
    cmds.polyEditUV(pivotU=0.5, pivotV=0.5, angle=90)
Example #12
0
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)
Example #13
0
    def createLightmap(self, *args):

        selection = cmds.ls(sl=True)
        if len(selection) == 0:
            return
        mesh = selection[0]

        if cmds.checkBox("cbDeleteHistory", q=True, v=True) == True:
            cmds.delete(mesh, ch=True)

        maxArc = cmds.textFieldGrp("tTolerance", q=True, text=True)
        if re.search("[a-zA-Z]", maxArc) != None:
            cmds.textFieldGrp("tTolerance", e=True, text="5")
        maxArc = int(cmds.textFieldGrp("tTolerance", q=True, text=True))

        # 1. Create a new UV Set
        if "lightmap" in cmds.polyUVSet(q=True, auv=True):
            cmds.polyUVSet(uvs="lightmap", delete=True)

        faceCount = cmds.polyEvaluate(mesh, f=True)
        cmds.polyUVSet(copy=True, nuv="lightmap")
        cmds.polyUVSet(mesh, cuv=True, uvs="lightmap")

        # 2. Cut every UV Edge
        edgeCount = cmds.polyEvaluate(mesh, e=True)
        cmds.polyMapCut(mesh + ".e[0:" + str(edgeCount - 1) + "]", cch=True, ch=False)

        cmds.progressWindow(
            title="Creating Lightmap...",
            progress=0,
            maxValue=faceCount + 1,
            isInterruptable=True,
            status="Facecount: " + str(faceCount),
        )
        # 3. Check if faces are connected and facing the same direction, if they do, then sew the uv edge
        i = 0
        while i < faceCount:
            if cmds.progressWindow(query=True, isCancelled=True):
                break

            face = mesh + ".f[" + str(i) + "]"
            adjacentFaces = self.getAdjacentFaces(mesh, i)

            normal1 = self.getFaceNormal(face)

            for adj in adjacentFaces:
                normal2 = self.getFaceNormal(adj)

                arc = self.getAngle(normal1, normal2)

                if arc < maxArc:
                    self.sewFaces(face, adj)

            cmds.progressWindow(edit=True, progress=i)
            i += 1

        cmds.select(mesh)

        # 4. unfold
        cmds.unfold(i=5000, ss=0.001, gb=False, gmb=0.5, ps=0, oa=0, us=True)

        # 5. layout
        preset = self.maps[cmds.optionMenuGrp("omTexSize", q=True, value=True)]
        cmds.polyMultiLayoutUV(lm=1, sc=1, rbf=1, fr=True, l=2, ps=preset)

        cmds.progressWindow(endProgress=True)
Example #14
0
def unfld(*args):
	cmds.unfold(i=5000, ss=0.001, gb=0, gmb=0.5, pub=0, ps=0, oa=0, us=False)
Example #15
0
def unwrapSelectedFaces():
    cmds.polyPlanarProjection()
    cmds.unfold()
Example #16
0
def main():
    if not mel.eval('exists "u3dUnfold"'):
        cmds.loadPlugin('Unfold3D')
        
    selFaces = cmds.ls(sl=1)
    selFaces = cmds.ls(selFaces,fl=1)
    selObj = selFaces[0].split('.')[0]

    faceUnwarp(selFaces)
    selUVs = cmds.polyListComponentConversion(selFaces,ff=1,tuv=1)

    faceDic = getDic(selFaces)
    vtxid_uvid = faceDic[0]
    vtxid_edgeid = faceDic[1]
    edgeid_vtxid = faceDic[2]
    vtxid_faceid = faceDic[3]
    faceid_numTriangles = faceDic[4]
    edgeid_length = faceDic[5]

    triangles = 0
    for faceid in faceid_numTriangles:
        if faceid_numTriangles[faceid] == 1:
            triangles += 1
            
    startVtxid = -1
    for vtxid in vtxid_faceid:
        if len(vtxid_faceid[vtxid]) == 1 and faceid_numTriangles[vtxid_faceid[vtxid][0]] == 1:
            startVtxid = vtxid
    if startVtxid == -1:
        for vtxid in vtxid_faceid:
            if len(vtxid_faceid[vtxid]) == 1:
                startVtxid = vtxid
    vtxCount = len(vtxid_uvid)
    vtxLine0 = []
    vtxLine1 = []

    if triangles == 2 or triangles == 1:
        maxCount = vtxCount/2
        nextEdge0 = vtxid_edgeid[startVtxid][0]
        nextEdge1 = vtxid_edgeid[startVtxid][1]
        currentVtx0 = startVtxid
        currentVtx1 = startVtxid

            
        tempCount = 0
        while tempCount < maxCount:
            tempCount += 1
            nextVtxes = edgeid_vtxid[nextEdge0]
            for i in nextVtxes:
                if i != currentVtx0:
                    currentVtx0 = i
                    break
            vtxLine0.append(currentVtx0)
            nextEdges = vtxid_edgeid[currentVtx0]
            for i in nextEdges:
                if i != nextEdge0:
                    nextEdge0 = i
                    break
                    
        tempCount = 0
        while tempCount < maxCount:
            tempCount += 1
            nextVtxes = edgeid_vtxid[nextEdge1]
            for i in nextVtxes:
                if i != currentVtx1:
                    currentVtx1 = i
                    break
            vtxLine1.append(currentVtx1)
            nextEdges = vtxid_edgeid[currentVtx1]
            for i in nextEdges:
                if i != nextEdge1:
                    nextEdge1 = i
                    break
                    
        vtxLineIntersect = list(set(vtxLine0).intersection(set(vtxLine1)))

        vtxLine0String = []

        for i in vtxLine0:
            if not i in vtxLineIntersect:
                uvid = vtxid_uvid[i]
                vtxLine0String.append( selObj + '.map[' + str(uvid) + ']')
                
        vtxLine1String = []   
        for i in vtxLine1:
            if not i in vtxLineIntersect:
                uvid = vtxid_uvid[i]
                vtxLine1String.append( selObj + '.map[' + str(uvid) + ']')
                
        cmds.select(selFaces,r=1)    
        
        uvbb = cmds.polyEvaluate(selUVs,bc2=1)
        if (uvbb[0][1]-uvbb[0][0]) > (uvbb[1][1]-uvbb[1][0]) :
            cmds.polyEditUV(rot=1,angle=90)
                
        uvbb0 = cmds.polyEvaluate(vtxLine0String,bc2=1)
        uvbb1 = cmds.polyEvaluate(vtxLine1String,bc2=1)
        if uvbb0[0][0]<uvbb1[0][0]:
            cmds.polyEditUV(vtxLine0String, u=-1,r=0)
            cmds.polyEditUV(vtxLine1String, u=-0.9,r=0)
        else:
            cmds.polyEditUV(vtxLine0String, u=-0.9,r=0)
            cmds.polyEditUV(vtxLine1String, u=-1,r=0)    
        cmds.select(selUVs,r=1)
        cmds.select(vtxLine0String,d=1)
        cmds.select(vtxLine1String,d=1)
        cmds.unfold(i=5000,ss=0.001,gb=0,gmb=0.5,pub=0,ps=0,oa=0,us=0)
        cmds.unfold(selUVs,i=5000,ss=0,gb=0,gmb=0,pub=0,ps=0,oa=1,us=0)
        
    else:
        maxCount = vtxCount/2
        nextEdge0 = vtxid_edgeid[startVtxid][0]
        nextEdge1 = vtxid_edgeid[startVtxid][1]
        currentVtx0 = startVtxid
        currentVtx1 = startVtxid

            
        tempCount = 0
        while tempCount < maxCount:
            tempCount += 1
            nextVtxes = edgeid_vtxid[nextEdge0]
            for i in nextVtxes:
                if i != currentVtx0:
                    currentVtx0 = i
                    break
            vtxLine0.append(currentVtx0)
            nextEdges = vtxid_edgeid[currentVtx0]
            for i in nextEdges:
                if i != nextEdge0:
                    nextEdge0 = i
                    break
                    
        tempCount = 0
        while tempCount < maxCount:
            tempCount += 1
            nextVtxes = edgeid_vtxid[nextEdge1]
            for i in nextVtxes:
                if i != currentVtx1:
                    currentVtx1 = i
                    break
            vtxLine1.append(currentVtx1)
            nextEdges = vtxid_edgeid[currentVtx1]
            for i in nextEdges:
                if i != nextEdge1:
                    nextEdge1 = i
                    break
                    
        vtxLineIntersect = list(set(vtxLine0).intersection(set(vtxLine1)))

        vtxLine0String = []

        for i in vtxLine0:
            if not i in vtxLineIntersect:
                uvid = vtxid_uvid[i]
                vtxLine0String.append( selObj + '.map[' + str(uvid) + ']')
                
        vtxLine1String = []   
        for i in vtxLine1:
            if not i in vtxLineIntersect:
                uvid = vtxid_uvid[i]
                vtxLine1String.append( selObj + '.map[' + str(uvid) + ']')
                    
        uvbb = cmds.polyEvaluate(selUVs,bc2=1)
        cmds.select(selFaces,r=1)
        if (uvbb[0][1]-uvbb[0][0]) > (uvbb[1][1]-uvbb[1][0]) :
            cmds.polyEditUV(rot=1,angle=90)
        cmds.unfold(selUVs,i=5000,ss=0,gb=0,gmb=0,pub=0,ps=0,oa=1,us=0)
        
        
    uvbb = cmds.polyEvaluate(selUVs,bc2=1)
    scale = 1/(uvbb[1][1]-uvbb[1][0])
    moveV = 0.5-(uvbb[1][1]+uvbb[1][0])/2
    cmds.polyEditUV(selUVs,v=moveV)
    cmds.polyEditUV(selUVs,s=1,su=scale,sv=scale,pu=-1,pv=0.5)
    length_vtxes = cmds.polyListComponentConversion(vtxLine0String,fuv=1,tv=1)
    length_edges = cmds.polyListComponentConversion(length_vtxes,fv=1,te=1,internal=1)
    cmds.select(vtxLine0String,r=1)
    edgeuvbb = cmds.polyEvaluate(vtxLine0String,bc2=1)
    uvheight = edgeuvbb[1][1] - edgeuvbb[1][0]
    edgesLength = 0
    length_edges = cmds.ls(length_edges,fl=1)
    for edgeid in length_edges:
        edgesLength += edgeid_length[int(edgeid.split('[')[1][:-1])]
    densityScale = edgesLength/uvheight
    cmds.polyEditUV(selUVs,s=1,su=densityScale,sv=densityScale,pu=-1,pv=0.5)
    cmds.select(selUVs,r=1)
Example #17
0
def unfld(*args):
	cmds.unfold(i=5000, ss=0.001, gb=0, gmb=0.5, pub=0, ps=0, oa=0, us=False)
Example #18
0
def straightenUVBorder():
    cmds.polyStraightenUVBorder()
    cmds.unfold(oa=1, us=False)