Example #1
0
def select_inside_loop():
	# get selected face loop and one inner face, convert to edges
	get_sel = cmds.ls(os=1,fl=1)
	if _cmds().is_component(get_sel) == "face":
		mesh = cmds.ls(sl=1,fl=1,o=1)
		edge_from_face = cmds.ls(cmds.polyListComponentConversion(get_sel[:-1],te=1,bo=1),fl=1)
		
		# create temp uvset for uv projection
		current_uvset = cmds.polyUVSet(mesh,q=1,cuv=1)[0]
		for uvset in cmds.polyUVSet(mesh,q=1,auv=1):
			if uvset == "af_tmp_select_uvset":
				cmds.polyUVSet(mesh,delete=1,uvSet="af_tmp_select_uvset")
				cmds.polyUVSet(mesh,create=1,uvSet="af_tmp_select_uvset")
				cmds.polyUVSet(mesh,e=1,cuv=1,uvSet="af_tmp_select_uvset")
			else:
				cmds.polyUVSet(mesh,create=1,uvSet="af_tmp_select_uvset")
				cmds.polyUVSet(mesh,e=1,cuv=1,uvSet="af_tmp_select_uvset")
		
		cmds.polyProjection(mesh,ch=0,type="Planar",ibd=1,md="y")
		cmds.polyMapCut(edge_from_face,e=0)
		
		# get inner selection
		cmds.select(cmds.polyListComponentConversion(get_sel[-1],tuv=1),r=1)
		mm.eval("polySelectBorderShell 0;ConvertSelectionToFaces;")
		inner = cmds.ls(sl=1,fl=1)
		
		# cleanup
		cmds.polyUVSet(mesh,e=1,cuv=1,uvSet=current_uvset)
		cmds.polyUVSet(mesh,delete=1,uvSet="af_tmp_select_uvset")
		cmds.delete(mesh,ch=1)
		
		# select fill
		cmds.select((inner+get_sel[:-1]),r=1)
Example #2
0
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)
Example #3
0
def tear_off():
    """
    Creates a new uv shell from selected faces.
    """
    s = mampy.selected()

    for comp in s.itercomps():
        if not comp.is_face():
            continue

        edges = comp.to_edge(border=True)
        cmds.polyMapCut(list(edges))
    cmds.select(list(s))
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)
Example #5
0
def solidifyObject(object, height=1, divisions=2, history=True):
	"""
	Solidifies given object.

	:param object: Object.
	:type object: str
	:param height: Extrusion height.
	:type height: float
	:param division: Extrusion divisions.
	:type division: float
	:param history: Keep construction history.
	:type history: bool
	"""

	if hasBorderEdges(object):
		transform = getTransform(object)
		vertices = cmds.ls(cmds.polyListComponentConversion(object, toVertex=True), fl=True)

		barycenters = cmds.xform(vertices, q=True, t=True, ws=True)
		barycenter = getAverageVector([(barycenters[i], barycenters[i + 1], barycenters[i + 2]) for i in range(0, len(barycenters), 3)])

		normals = cmds.polyNormalPerVertex(cmds.polyListComponentConversion(object, toVertexFace=True), q=True, xyz=True)
		normals = [(normals[i], normals[i + 1], normals[i + 2]) for i in range(0, len(normals), 3)]
		averageNormal = vectorMatrixMultiplication(normalize(getAverageVector(normals)), cmds.xform(transform, query=True, matrix=True, worldSpace=True))

		facesCount = cmds.polyEvaluate(object, face=True)
		faces = object + ".f[0:" + str(facesCount - 1) + "]"
		extrude = cmds.polyExtrudeFacet(faces, constructionHistory=1, keepFacesTogether=1, divisions=divisions)
		cmds.setAttr(extrude[0] + ".localTranslateZ", height)
		borderEdges = cmds.polyListComponentConversion(faces, te=True, bo=True)
		cmds.polyMapCut(borderEdges)
		uvs = cmds.polyListComponentConversion(object + ".f[0:" + str(facesCount - 1) + "]", toUV=1)
		cmds.polyEditUV(uvs, u=0, v=-5)

		extendedFaces = cmds.ls(faces, fl=True)
		for i in range(divisions):
			adjacentEdges = cmds.polyListComponentConversion(extendedFaces, ff=True, te=True)
			extendedFaces.extend(cmds.ls(cmds.polyListComponentConversion(adjacentEdges, fe=True, tf=True), fl=True))

		borderFaces = list(set(extendedFaces).difference(set(cmds.ls(faces, fl=True))))
		cmds.select(borderFaces)
		cmds.polyAutoProjection(borderFaces, t=barycenter, ry=getAngle((0, 0, 1), averageNormal), rz=getAngle((1, 0, 0), averageNormal))
		uvs = cmds.polyListComponentConversion(borderFaces, toUV=1)
		cmds.polyEditUV(uvs, u=0, v=-5)

		not history and cmds.delete(object, ch=True)
Example #6
0
	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)
Example #7
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 #8
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 #9
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 #10
0
def polyMapCut(*args, **kwargs):
    res = cmds.polyMapCut(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
Example #11
0
def solidifyObject(object, height=1, divisions=2, history=True):
    """
	Solidifies given object.

	:param object: Object.
	:type object: str
	:param height: Extrusion height.
	:type height: float
	:param division: Extrusion divisions.
	:type division: float
	:param history: Keep construction history.
	:type history: bool
	"""

    if hasBorderEdges(object):
        transform = getTransform(object)
        vertices = cmds.ls(cmds.polyListComponentConversion(object,
                                                            toVertex=True),
                           fl=True)

        barycenters = cmds.xform(vertices, q=True, t=True, ws=True)
        barycenter = getAverageVector([(barycenters[i], barycenters[i + 1],
                                        barycenters[i + 2])
                                       for i in range(0, len(barycenters), 3)])

        normals = cmds.polyNormalPerVertex(cmds.polyListComponentConversion(
            object, toVertexFace=True),
                                           q=True,
                                           xyz=True)
        normals = [(normals[i], normals[i + 1], normals[i + 2])
                   for i in range(0, len(normals), 3)]
        averageNormal = vectorMatrixMultiplication(
            normalize(getAverageVector(normals)),
            cmds.xform(transform, query=True, matrix=True, worldSpace=True))

        facesCount = cmds.polyEvaluate(object, face=True)
        faces = object + ".f[0:" + str(facesCount - 1) + "]"
        extrude = cmds.polyExtrudeFacet(faces,
                                        constructionHistory=1,
                                        keepFacesTogether=1,
                                        divisions=divisions)
        cmds.setAttr(extrude[0] + ".localTranslateZ", height)
        borderEdges = cmds.polyListComponentConversion(faces, te=True, bo=True)
        cmds.polyMapCut(borderEdges)
        uvs = cmds.polyListComponentConversion(object + ".f[0:" +
                                               str(facesCount - 1) + "]",
                                               toUV=1)
        cmds.polyEditUV(uvs, u=0, v=-5)

        extendedFaces = cmds.ls(faces, fl=True)
        for i in range(divisions):
            adjacentEdges = cmds.polyListComponentConversion(extendedFaces,
                                                             ff=True,
                                                             te=True)
            extendedFaces.extend(
                cmds.ls(cmds.polyListComponentConversion(adjacentEdges,
                                                         fe=True,
                                                         tf=True),
                        fl=True))

        borderFaces = list(
            set(extendedFaces).difference(set(cmds.ls(faces, fl=True))))
        cmds.select(borderFaces)
        cmds.polyAutoProjection(borderFaces,
                                t=barycenter,
                                ry=getAngle((0, 0, 1), averageNormal),
                                rz=getAngle((1, 0, 0), averageNormal))
        uvs = cmds.polyListComponentConversion(borderFaces, toUV=1)
        cmds.polyEditUV(uvs, u=0, v=-5)

        not history and cmds.delete(object, ch=True)