コード例 #1
1
def CentreUVs():
	objSel = cmds.ls(sl=True)
	
	try:
		for item, x in enumerate(objSel):
			cmds.select('%s.map[*]' %objSel[item])
			mm.eval("PolySelectConvert 4;")
			mm.eval('TranslateToolWithSnapMarkingMenu')
			objPiv = cmds.getAttr('%s.uvPivot' %objSel[0])
			mm.eval('MarkingMenuPopDown')
			objCenterU = 0.5 - objPiv[0][0]
			objCenterV = 0.5 - objPiv[0][1]
			cmds.polyEditUV(u=objCenterU, v=objCenterV, r=1)
			cmds.select(objSel)
	except ValueError:
	
		objQuery = cmds.listRelatives(objSel[0], ap=True)
		cmds.select('%s.map[*]' %objQuery[0])
		mm.eval("PolySelectConvert 4;")
		mm.eval('TranslateToolWithSnapMarkingMenu')
		objPiv = cmds.getAttr('%s.uvPivot' %objQuery[0])
		mm.eval('MarkingMenuPopDown')
		objCenterU = 0.5 - objPiv[0][0]
		objCenterV = 0.5 - objPiv[0][1]
		cmds.polyEditUV(u=objCenterU, v=objCenterV, r=1)
		cmds.select(objQuery)
コード例 #2
0
 def layoutUVsToUDIM(self, *args):
     sels = cmds.ls(sl=1)
     for i, x in enumerate(sels):
         x = cmds.listRelatives(x,s=True)[0]
         cmds.select('{0}.map[:]'.format(x), r=1)
         cmds.polyEditUV(u=i % 10, v=int(math.floor(i / 10)))
     cmds.select(sels, r=1)
コード例 #3
0
    def setUpClass(cls):
        standalone.initialize('usd')
        cmds.loadPlugin('pxrUsd')

        if not UsdMaya.WriteUtil.WriteUVAsFloat2():
            cmds.file(os.path.abspath('UsdExportUVSetsTest.ma'), open=True,
                       force=True)
        else:
            cmds.file(os.path.abspath('UsdExportUVSetsTest_Float.ma'), open=True,
                       force=True)

        # Make some live edits to the box with weird UVs for the
        # testExportUvVersusUvIndexFromIterator test.
        cmds.select("box.map[0:299]", r=True)
        cmds.polyEditUV(u=1.0, v=1.0)

        usdFilePath = os.path.abspath('UsdExportUVSetsTest.usda')
        cmds.usdExport(mergeTransformAndShape=True,
            file=usdFilePath,
            shadingMode='none',
            exportColorSets=False,
            exportDisplayColor=False,
            exportUVs=True)

        cls._stage = Usd.Stage.Open(usdFilePath)
コード例 #4
0
ファイル: uvsUtilities.py プロジェクト: elanifegnirf/Snippets
def prescaleUVsShells(object):
	"""
	This definition prescales object UVs shells.

	:param objects: Object. ( String )
	:return: Definition succes. ( Boolean )
	"""

	uvs = getUVsFromComponents(object)
	uMin, vMin, uMax, vMax = getComponentsBoundingBox(uvs)
	uCenter, vCenter = (uMin + uMax) / 2.0, (vMin + vMax) / 2.0
	width, height = uMax - uMin, vMax - vMin
	scale = max(width, height)

	cmds.polyMultiLayoutUV(object, lm=0, sc=1, rbf=0, fr=False, ps=0.2, l=2, psc=True)

	currentUMin, currentVMin, currentUMax, currentVMax = getComponentsBoundingBox(uvs)
	currentUCenter, currentVCenter = (currentUMin + currentUMax) / 2.0, (currentVMin + currentVMax) / 2.0
	currentWidth, currentHeight = currentUMax - currentUMin, currentVMax - currentVMin
	currentScale = max(currentWidth, currentHeight)

	scaleFactor = scale / currentScale

	cmds.polyEditUV(uvs, u=uCenter - currentUCenter, v=vCenter - currentVCenter)
	scaleComponentsUVs(uvs, su=scaleFactor, sv=scaleFactor)
	return True
コード例 #5
0
ファイル: unfoldBand.py プロジェクト: elanifegnirf/Snippets
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)
コード例 #6
0
 def extrude_edge_uv(self):
     self.ex_edges = []
     sel = cmds.ls(sl=True)
     self.s_edges = common.conv_comp(sel, mode='edge')
     s_vtx = common.conv_comp(sel, mode='vtx')
     #self.saw_uvs(mode='pre')#事前に押し出し対象のUVを縫い合わせておく
     self.marge_uvs(mode='pre')
     if not self.s_edges:
         return
     ev_dict ,vec_dict, ev_uv_dict = self.make_edge_vtx_dict(self.s_edges)
     #print 'ev_dict :', ev_dict
     #print 'vec_dict :', vec_dict
     #押し出しを実行する
     cmds.polyExtrudeEdge(self.s_edges,
                         keepFacesTogether=True,
                         smoothingAngle=self.soft_angle.value(),
                         translate=[0, 0, 0])
     self.ex_edges = cmds.ls(sl=True)
     n_edges = common.conv_comp(self.ex_edges, mode='edge')
     n_faces = common.conv_comp(self.ex_edges, mode='face')
     self.n_uvs = common.conv_comp(n_faces, mode='uv')
     #print 'pre_move_uvs :', self.n_uvs
     #根本の位置合わせする
     new_vec_dict = {}
     for nuv in self.n_uvs[:]:
         vtx = common.conv_comp(nuv, mode='vtx')[0]
         edge = common.conv_comp(nuv, mode='edge')[0]
         if edge+' '+vtx in ev_dict.keys():
             uv_pos = ev_dict[edge+' '+vtx]
             #print 'get_uv_pos', nuv, uv_pos
             cmds.polyEditUV(nuv, u=uv_pos[0], v=uv_pos[1] ,r=False)
             self.n_uvs.remove(nuv)
             key_uv = ev_uv_dict[edge+' '+vtx]
             new_vec_dict[nuv] = vec_dict[key_uv]
     #print 'post push uvs :', self.n_uvs
     #押し出し先を根本につけて押し出しベクトル辞書をつくる
     self.uv_vec_dict = {}
     self.base_pos_dict = {}
     for nuv in self.n_uvs:
         edges = common.conv_comp(nuv, mode='edge')
         face = common.conv_comp(nuv, mode='face')
         f_uvs = common.conv_comp(face, mode='uv')
         for edge in edges:
             if edge in n_edges:
                 continue
             #print 'get new edge :', edge
             e_uvs = common.conv_comp(edge, mode='uv')
             l_uvs = list(set(f_uvs) & set(e_uvs))
             #print 'new edge uvs :', l_uvs
             for uv in l_uvs:
                 if not uv in new_vec_dict.keys():
                     continue
                 uv_pos = cmds.polyEditUV(uv, query=True)
                 cmds.polyEditUV(nuv, u=uv_pos[0], v=uv_pos[1] ,r=False)
                 self.uv_vec_dict[nuv] = new_vec_dict[uv]
                 self.base_pos_dict[nuv] = uv_pos
                 self.saw_edges.append(edge)#縫い合わせ用リストに入れておく
     self.push_out()
     cmds.setToolTo('moveSuperContext')
コード例 #7
0
def ArrangeUVByMat(shape, mat, su=1.0, sv=1.0, u=0.0, v=0.0):
    print 'ArrangeUVByMat shape={0} mat={1} scale=[{2}, {3}], translate=[{4}, {5}]'.format(
        shape, mat, su, sv, u, v)
    faces = GetFacesByMat(shape, mat)
    cmds.select(faces)
    cmds.select(cmds.polyListComponentConversion(tuv=True), r=True)
    cmds.polyEditUV(su=su, sv=sv)
    cmds.polyEditUV(u=u, v=v)
    cmds.select(clear=True)
コード例 #8
0
ファイル: miUvUtils.py プロジェクト: minoue/miUV
def flipUVsByLocal(*args):
    sel = cmds.ls(sl=True, fl=True, long=True)
    u = 0.0
    for i in sel:
        uv = cmds.polyEditUV(i, relative=False, q=True, uValue=True)
        u += uv[0]
    uAve = u / len(sel)
    u_tile = int(str(uAve)[0])
    flipAxis = u_tile + 0.5
    cmds.polyEditUV(relative=False, pivotU=flipAxis, scaleU=-1)    
コード例 #9
0
def flipUVsByLocal(*args):
    sel = cmds.ls(sl=True, fl=True, long=True)
    u = 0.0
    for i in sel:
        uv = cmds.polyEditUV(i, relative=False, q=True, uValue=True)
        u += uv[0]
    uAve = u / len(sel)
    u_tile = int(str(uAve)[0])
    flipAxis = u_tile + 0.5
    cmds.polyEditUV(relative=False, pivotU=flipAxis, scaleU=-1)
コード例 #10
0
ファイル: uv_atlas.py プロジェクト: teionn/easy_atlas
def createAtlas(aItems):
    '''Create UV atlas.'''
    
    mel.eval('scriptEditorInfo -e -suppressWarnings true;')  # @UndefinedVariable
       
    for k in aItems:
        
        cmds.select("%s.map[0:]" % k.mesh)  # @UndefinedVariable
        cmds.polyEditUV(pivotU=0, pivotV=1, scaleU=k.sizeX, scaleV=k.sizeY)  # @UndefinedVariable
        cmds.polyMoveUV(tu=k.posX, tv=-k.posY)  # @UndefinedVariable
コード例 #11
0
ファイル: vertexAnimTool.py プロジェクト: wassse/Scripts
def modifyUVs(item, id, *args):
    cmds.select(item)

    cmds.select(cmds.polyListComponentConversion(tuv=True), r=True)
    uvs = cmds.ls(sl=True, fl=True)

    number = 0.5 + id

    for uv in uvs:
        cmds.select(uv)
        cmds.polyEditUV(uv, relative=False, uValue=number, vValue=0.5)
コード例 #12
0
ファイル: PaintLines.py プロジェクト: wandth/MayaPy
 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)
コード例 #13
0
ファイル: uvdeluxe.py プロジェクト: xbxcw/scripts
 def move(dTuple, *args):
     if not mc.polyListComponentConversion(fuv=True):
         mel.eval('warning "Please select some UVs"')
     else:
         steps = mc.floatField('steps', q=True, v=True)
         sel = mc.ls(sl=True)
         mel.eval('polySelectBorderShell 0')
         mc.polyEditUV(u=(steps * dTuple[0]), v=(steps * dTuple[1]))
         #Refocus selection
         mc.select(sel, r=True)
     return
コード例 #14
0
def _get_uvmap_uvmin_uvmax(poly_name):
    vertex_num = cmds.polyEvaluate(poly_name, v=True)
    u_values = cmds.polyEditUV("%s.map[%d:%d]" % (poly_name, 0, vertex_num),
                               q=True,
                               u=True)
    u_min, u_max = _get_min_max(u_values)
    v_values = cmds.polyEditUV("%s.map[%d:%d]" % (poly_name, 0, vertex_num),
                               q=True,
                               v=True)
    v_min, v_max = _get_min_max(v_values)
    return u_min, u_max, v_min, v_max
コード例 #15
0
ファイル: uvdeluxe.py プロジェクト: xbxcw/scripts
    def setMinMax(self):
        xPositions = sorted(
            [mc.polyEditUV(i, query=True)[0] for i in self.uvs])
        yPositions = sorted(
            [mc.polyEditUV(i, query=True)[1] for i in self.uvs])

        self.minMax = (xPositions[0], xPositions[-1]), (yPositions[0],
                                                        yPositions[-1])
        self.xMin = self.minMax[0][0]
        self.xMax = self.minMax[0][1]
        self.yMin = self.minMax[1][0]
        self.yMax = self.minMax[1][1]
コード例 #16
0
def stackShells():
    shellBox = mc.polyEvaluate(bc2=True)
    MPU = 0.5 * (shellBox[0][0] + shellBox[0][1])
    MPV = 0.5 * (shellBox[1][0] + shellBox[1][1])
    shells = uvShells()
    for shell in shells:
        shellBox = mc.polyEvaluate(shell, bc2=True)
        piU = 0.5 * (shellBox[0][0] + shellBox[0][1])
        piV = 0.5 * (shellBox[1][0] + shellBox[1][1])
        posU = MPU - piU
        posV = MPV - piV
        mc.polyEditUV(shell, pu=piU, pv=piV, u=posU, v=posV)
コード例 #17
0
ファイル: uvdeluxe.py プロジェクト: xbxcw/scripts
def findAngle(tuple):
    #Returns angle of two UV points
    uv0 = tuple[0]
    uv1 = tuple[1]
    p1 = mc.polyEditUV(uv0, q=True)
    p2 = mc.polyEditUV(uv1, q=True)
    X = (p2[0] - p1[0])
    Y = (p2[1] - p1[1])

    radians = math.atan2(Y, X)
    angle = radians * 57.2957795

    return angle
コード例 #18
0
ファイル: uvsUtilities.py プロジェクト: elanifegnirf/Snippets
def moveComponentsUVs(components, u=0, v=0):
	"""
	This definition moves given components UVs.

	:param components: Components. ( Tuple / List )
	:param u: U value. ( Float )
	:param v: V value. ( Float )
	:return: Definition succes. ( Boolean )
	"""

	uvs = getUVsFromComponents(components, flatten=False)
	cmds.polyEditUV(uvs, u=u, v=v)
	return True
コード例 #19
0
def multi_merge(threshold):
    selected_uv = cmds.ls(sl=True, flatten=True)
    selected_uv_pos = cmds.polyEditUV(query=True)
    length = len(selected_uv_pos)
    pos_u = [selected_uv_pos[i] for i in range(length) if i % 2 == 0]
    pos_v = [selected_uv_pos[i] for i in range(length) if i % 2 != 0]
    for name in selected_uv:
        current_u, current_v = cmds.polyEditUV(name, query=True)
        for i in range(length / 2):
            if sqrt( (pos_u[i] - current_u) ** 2 + (pos_v[i] - current_v) ** 2 ) < threshold:
                cmds.select(selected_uv[i], r=True)
                cmds.polyEditUV(u=current_u, v=current_v, r=False)
    cmds.select(selected_uv)
コード例 #20
0
ファイル: modeling.py プロジェクト: shrimo/dmptools
def alignUVs(doU, minU, doV, inV):
    """
    align selected uvs based on the one most on top, bottom, left, right
    """
    # get the selected UVs from current selection
    selectedItems = cmds.filterExpand(ex=False, sm=35) # 35 means UVs
    uvMin = []
    uvMax = []
    # get the 3d bounding box of selection
    uvInfo = cmds.polyEvaluate(bc2=True)
    uvMin[0] = uvInfo[0]
    uvMin[1] = uvInfo[2]
    uvMax[0] = uvInfo[1]
    uvMax[1] = uvInfo[3]

    if doU:
        if minU:
            cmds.polyEditUV(r=False, u=uvMin[0])
        else:
            cmds.polyEditUV(r=False, u=uvMax[0])
    if doV:
        if minV:
            cmds.polyEditUV(r=False, v=uvMin[1])
        else:
            cmds.polyEditUV(r=False, v=uvMax[1])
コード例 #21
0
ファイル: character.py プロジェクト: cgriders/jcScripts
def mirrorGeometry(*args, **keywords):
# Mirror geometry together with UV. The UV of character can be splited into a number of U regions.
# usage: select geometry which is present in the +x side and UVs in U=0.5-1 region (and U=1.5-2, U=2.5-3, ...)

	meshes = cmds.listRelatives(s=True, type="mesh", ni=True, f=True)

	if meshes == None:
		raise Exception, "No mesh selected"

	results = []
	for mesh in cmds.listRelatives(meshes, p=True, f=True):
		verticesInRegion = {}

		parent = cmds.listRelatives(mesh, p=True, f=True, pa=True)
		mesh1 = cmds.duplicate(mesh)
		mesh2 = cmds.duplicate(mesh)

		cmds.scale(-1, 1, 1, mesh2, r=True)

		# detect uv regions
		#		scan all vertices

		vertices = cmds.ls(cmds.polyListComponentConversion(mesh2, tuv=True), fl=True)
		for vertex in vertices:
			uv = cmds.polyEditUV(vertex, query=True)
			region = math.ceil(uv[0]) - 1
			if region < 0:
				region = 1
			if not verticesInRegion.has_key(region):
				verticesInRegion[region] = []
			verticesInRegion[region].append(vertex)

		#		choose vertices in regions
		#			flip uv upon middle of regions

		for region,vertices in verticesInRegion.iteritems():
			cmds.select(vertices, r=True)
			cmds.polyEditUV(pu=(region + 0.5), pv=0.5, su=-1, sv=1)

		#	combine objects and merge vertices

		combined = cmds.polyUnite(mesh1, mesh2, ch=False)
		if parent:
			results += cmds.parent(combined, parent)
		else:
			results += combined
		cmds.polyMergeVertex(d=0.005, ch=0)

	cmds.select(results, r=True)
	return results
コード例 #22
0
ファイル: meshUtils.py プロジェクト: GuidoPollini/MuTools
def getUVFaceNormal( facepath ):
	uvs = getWindingOrder(facepath)

	if len(uvs) < 3: return (1,0,0) #if there are less than 3 uvs we have no uv area so bail

	#get edge vectors and cross them to get the uv face normal
	uvAPos = cmd.polyEditUV(uvs[0], query=True, uValue=True, vValue=True)
	uvBPos = cmd.polyEditUV(uvs[1], query=True, uValue=True, vValue=True)
	uvCPos = cmd.polyEditUV(uvs[2], query=True, uValue=True, vValue=True)
	uvAB = Vector( [uvBPos[0]-uvAPos[0], uvBPos[1]-uvAPos[1], 0] )
	uvBC = Vector( [uvCPos[0]-uvBPos[0], uvCPos[1]-uvBPos[1], 0] )
	uvNormal = uvAB.cross( uvBC ).normalize()

	return uvNormal
コード例 #23
0
def getUVFaceNormal( facepath ):
	uvs = getWindingOrder(facepath)

	if len(uvs) < 3: return (1,0,0) #if there are less than 3 uvs we have no uv area so bail

	#get edge vectors and cross them to get the uv face normal
	uvAPos = cmd.polyEditUV(uvs[0], query=True, uValue=True, vValue=True)
	uvBPos = cmd.polyEditUV(uvs[1], query=True, uValue=True, vValue=True)
	uvCPos = cmd.polyEditUV(uvs[2], query=True, uValue=True, vValue=True)
	uvAB = Vector( [uvBPos[0]-uvAPos[0], uvBPos[1]-uvAPos[1]] )
	uvBC = Vector( [uvCPos[0]-uvBPos[0], uvCPos[1]-uvBPos[1]] )
	uvNormal = (uvAB ^ uvBC).normalize()

	return uvNormal
コード例 #24
0
ファイル: uvsUtilities.py プロジェクト: elanifegnirf/Snippets
def centerComponentsUVs(components):
	"""
	This definition centers given components UVs.

	:param components: Components. ( Tuple / List )
	:return: Definition succes. ( Boolean )
	"""

	uvs = getUVsFromComponents(components)
	uMin, vMin, uMax, vMax = getComponentsBoundingBox(uvs)
	uCenter, vCenter = (uMin + uMax) / 2.0, (vMin + vMax) / 2.0
	uTargetCenter, vTargetCenter = math.floor(uCenter), math.floor(vCenter)
	cmds.polyEditUV(uvs, u=uTargetCenter - uCenter + 0.5, v=vTargetCenter - vCenter + 0.5)
	return True
コード例 #25
0
def scaleUV ( SelectedShapes, Action, sU, sV ):
    
    print "UV Scale:"

    try:
        for i in range(len(SelectedShapes)):
            SelectedFacesTemp = [ SelectedShapes[i] + '.f[:]']
            cmds.select(SelectedFacesTemp)
            cmds.polyEditUV( pivotU=0, pivotV=0, scaleU=sU, scaleV=sV )
            print "PolygonTools. UV successfully scaled", Action, "for", gen_func.shortNamer(SelectedShapes[i])
        
        cmds.select(SelectedShapes)

    except:
        pass
コード例 #26
0
def moveUV ( SelectedShapes, Action, vU, vV ):
    
    print "UV Move:"
    
    try:
        for i in range(len(SelectedShapes)):
            SelectedFacesTemp = [ SelectedShapes[i] + '.f[:]']
            cmds.select(SelectedFacesTemp)
            cmds.polyEditUV( uValue = vU, vValue = vV )
            print "PolygonTools. UV successfully moved", Action, "for", gen_func.shortNamer(SelectedShapes[i])
        
        cmds.select(SelectedShapes)

    except:
        pass
コード例 #27
0
        def add_UV_grid_atter(self):
            ## make mi_object local
            mi_object = self.mi_object

            ## get all UVs
            UV_locations = mc.polyEditUV(mi_object.mNode + ".map[:]",
                                         q=True,
                                         u=True,
                                         v=False)

            ## make a list for U and one for V
            U_gridSpaces = []
            V_gridSpaces = []
            for i in range(len(UV_locations)):
                if i % 2 == 0:  #Why are you doing this? i in this case is going to always be an int, no?
                    #Check U'''
                    GridSpace = int(UV_locations[i])
                    if GridSpace not in U_gridSpaces:
                        U_gridSpaces.append(GridSpace)
                else:
                    GridSpace = int(UV_locations[i])
                    if GridSpace not in V_gridSpaces:
                        V_gridSpaces.append(GridSpace)

            ## add atter to metaObject
            mi_object.addAttr("U_gridSpace", U_gridSpaces)
            mi_object.addAttr("V_gridSpace", V_gridSpaces)
コード例 #28
0
ファイル: mayaCommands.py プロジェクト: jonntd/dmptools
def udimFromNode(node):
    uPos, vPos = cmds.polyEditUV(node+'.map[1]', q=True)
    uTile = int(math.floor(uPos))
    vTile = int(math.floor(vPos))
    udim = 1000+(uTile+1)+(vTile*10)
    
    return udim, uTile, vTile
コード例 #29
0
    def getUVs(self):

        # Getting current uvset
        currUVSet = cmds.polyUVSet(self.name, q=True, currentUVSet=True)[0]

        for i, uvSet in enumerate(self.uvSets):
            self.uvs[uvSet] = []
            # Setting uvSet temp
            cmds.polyUVSet(self.name, currentUVSet=True, uvSet=uvSet)

            # Get uv maps
            uvMaps = cmds.polyListComponentConversion(self.name, ff=1, tuv=1)

            if (uvMaps):
                uvMaps = [
                    cmds.polyListComponentConversion(vtxFace, tuv=1)
                    for vtxFace in self.vtxFaceNames
                ]

                # Check to make sure there are uv's on this face.
                for uvMap in uvMaps:
                    # Get my uvValues
                    uvCoords = cmds.polyEditUV(uvMap, q=True)
                    self.uvs[uvSet].append(uvCoords)

        # Returning to orginal uvSet
        cmds.polyUVSet(self.name, currentUVSet=True, uvSet=currUVSet)
コード例 #30
0
    def resize(self, new_ratio):
        """
        Resize ratio
        """
        scale_amt = new_ratio / self.ratio

        for i, transform in enumerate(self.transforms):
            cmds.polyEditUV(
                ["{0}.map[{1}]".format(transform, m)
                 for m in self.uv_indexes[i]],
                pivotU=self.centers[i][0],
                pivotV=self.centers[i][1],
                scaleU=scale_amt,
                scaleV=scale_amt)

        self.ratio = new_ratio
コード例 #31
0
def StickObjectToMesh(vertex, mesh):
    #***********   Get parent name ******************

    ObjectParent = cmds.listRelatives(mesh, p=True)
    #***********   Get object position ******************
    position = cmds.xform(vertex, q=True, ws=True, t=True)
    #******* Create a group driven by pointOnPolyContraint **********
    groupName = cmds.group(em=True, name=("grp_ptc_" + mesh))
    cmds.parent(groupName, ObjectParent[0])
    #******* Get the UV map relationed with the vtx **********
    mapList = cmds.polyListComponentConversion(vertex, fv=- True, tuv=True)
    #******* Create a pointOnPolyContraint **********
    contraintNames = cmds.pointOnPolyConstraint(vertex,
                                                groupName,
                                                mo=False,
                                                o=[0, 0, 0],
                                                w=1)
    #*************  Disconnect rotation  chanel  ****************************************
    mel.eval("CBdeleteConnection " + groupName + ".rotateX;")
    mel.eval("CBdeleteConnection " + groupName + ".rotateY;")
    mel.eval("CBdeleteConnection " + groupName + ".rotateZ;")
    #******* Get U and V values from map array **********
    uvvalues = cmds.polyEditUV(mapList, q=True)
    contraintAttr = cmds.listAttr(contraintNames[0], k=True)
    #******* Assign the U and V values respectively from maplist **********
    cmds.setAttr((contraintNames[0] + "." + contraintAttr[10]), uvvalues[0])
    cmds.setAttr((contraintNames[0] + "." + contraintAttr[11]), uvvalues[1])
    groupDrv = _2GrpUp(mesh)
    cmds.parent(groupDrv, groupName)
    GrpSubsTranslation(mesh)
コード例 #32
0
def makeFollicle():
    selection = cm.ls(sl=True)
    
    for i in range(0, len(selection)):  
        pos = cm.xform(selection[i], q=True, t=True, ws=True)
        follicleShape = cm.createNode('follicle')
        maya.mel.eval('pickWalk -d up;')
        follicle = cm.listRelatives(follicleShape, p=True)
        follicle = follicle[0]
        cm.move(pos[0], pos[1], pos[2], follicleShape, ws=True)
        
        mesh = selection[0].split('.vtx')[0]
        
        cm.connectAttr(mesh+'.outMesh', follicleShape+'.inputMesh', f=True)
        cm.connectAttr(mesh+'.worldMatrix', follicleShape+'.inputWorldMatrix', f=True)
        cm.connectAttr(follicleShape+'.outRotate', follicle+'.rotate', f=True)
        cm.connectAttr(follicleShape+'.outTranslate', follicle+'.translate', f=True)
    
        VtxToUV = cm.polyListComponentConversion(selection[i], fv=True, tuv=True)
        cm.select(VtxToUV)
        UV = cm.polyEditUV( query=True,)
        print UV, mesh
    
        cm.setAttr(follicleShape+'.parameterU', UV[0])
        cm.setAttr(follicleShape+'.parameterV', UV[1])
コード例 #33
0
def centerComponentsUVs(components):
	"""
	Centers given components UVs.

	:param components: Components.
	:type components: tuple or list
	:return: Definition succes.
	:rtype: bool
	"""

	uvs = getUVsFromComponents(components)
	uMin, vMin, uMax, vMax = getComponentsBoundingBox(uvs)
	uCenter, vCenter = (uMin + uMax) / 2.0, (vMin + vMax) / 2.0
	uTargetCenter, vTargetCenter = math.floor(uCenter), math.floor(vCenter)
	cmds.polyEditUV(uvs, u=uTargetCenter - uCenter + 0.5, v=vTargetCenter - vCenter + 0.5)
	return True
コード例 #34
0
ファイル: MayaScripts.py プロジェクト: Owacle/reference-code
def createFollicle():

    sel = cmds.ls(sl = True,fl = True)
    
    for i in range(len(sel)):
    
        surfaceTransform = sel[i].split('.')[0]
        surfaceShape = cmds.listRelatives(surfaceTransform,type = 'shape')[0]
        uvPoint = sel[i]
        
        uvValues = cmds.polyEditUV(uvPoint,query = True)
        uValue = uvValues[0]
        vValue = uvValues[1]
        
            
        follicle = cmds.createNode('follicle')
        follicleTransform = cmds.listRelatives(follicle,parent = True)[0]
        cmds.connectAttr('%s.outTranslate'%follicle,'%s.translate'%follicleTransform)
        cmds.connectAttr('%s.outRotate'%follicle,'%s.rotate'%follicleTransform)
        
        cmds.setAttr('%s.parameterU'%follicle,uValue)
        cmds.setAttr('%s.parameterV'%follicle,vValue)
        
        cmds.connectAttr('%s.outMesh'%surfaceShape, '%s.inputMesh'%follicle,f = True)
        cmds.connectAttr('%s.worldMatrix[0]'%surfaceShape, '%s.inputWorldMatrix'%follicle)
コード例 #35
0
    def testPolyUVs(self):
        MayaCmds.polyCube(name='cube')
        cubeObj = getObjFromName('cubeShape')
        fnMesh = OpenMaya.MFnMesh(cubeObj)

        # get the name of the current UV set
        uvSetName = fnMesh.currentUVSetName()

        uArray = OpenMaya.MFloatArray()
        vArray = OpenMaya.MFloatArray()
        fnMesh.getUVs(uArray, vArray, uvSetName)

        newUArray = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 2, -1, -1]
        newVArray = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 1, 0, 1]
        for i in range(0, 14):
            uArray[i] = newUArray[i]
            vArray[i] = newVArray[i]
        fnMesh.setUVs(uArray, vArray, uvSetName)

        self.__files.append(util.expandFileName('polyUvsTest.abc'))
        MayaCmds.AbcExport(j='-uv -root cube -file ' + self.__files[-1])

        # reading test
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        MayaCmds.select('cube.map[0:13]', replace=True)
        uvs = MayaCmds.polyEditUV(query=True)
        for i in range(0, 14):
            self.failUnlessAlmostEqual(newUArray[i], uvs[2 * i], 4,
                                       'map[%d].u is not the same' % i)
            self.failUnlessAlmostEqual(newVArray[i], uvs[2 * i + 1], 4,
                                       'map[%d].v is not the same' % i)
コード例 #36
0
    def testPolyUVs(self):
        MayaCmds.polyCube(name = 'cube')
        cubeObj = getObjFromName('cubeShape')
        fnMesh = OpenMaya.MFnMesh(cubeObj)

        # get the name of the current UV set
        uvSetName = fnMesh.currentUVSetName()

        uArray = OpenMaya.MFloatArray()
        vArray = OpenMaya.MFloatArray()
        fnMesh.getUVs(uArray, vArray, uvSetName)

        newUArray = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 2, -1, -1]
        newVArray = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 1 , 0,  1]
        for i in range(0, 14):
            uArray[i] = newUArray[i]
            vArray[i] = newVArray[i]
        fnMesh.setUVs(uArray, vArray, uvSetName)

        self.__files.append(util.expandFileName('polyUvsTest.abc'))
        MayaCmds.AbcExport(j='-uv -root cube -file ' + self.__files[-1])

        # reading test
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        MayaCmds.select('cube.map[0:13]', replace=True)
        uvs = MayaCmds.polyEditUV(query=True)
        for i in range(0, 14):
            self.failUnlessAlmostEqual(newUArray[i], uvs[2*i], 4,
                'map[%d].u is not the same' % i)
            self.failUnlessAlmostEqual(newVArray[i], uvs[2*i+1], 4,
                'map[%d].v is not the same' % i)
コード例 #37
0
def flatten_marvelous_shells(shells):
    """
    Usage:
        flatten_marvelous_shells(mc.ls(sl=True))
    """
    for obj in shells:
        start_vert, end_vert = mc.ls(
            mc.polyListComponentConversion(cmds.ls(obj + ".e[0]")[0], fe=True, tv=True), fl=True
        )

        start_scale = distance.euclidean(
            mc.xform(start_vert, q=True, t=True, ws=True), mc.xform(end_vert, q=True, t=True, ws=True)
        )

        for uv in cmds.ls(obj + ".map[:]", fl=True):
            uv_pos = mc.polyEditUV(uv, q=True)
            uv_index = re.findall("\[([0-9]+)\]", uv)[0]
            vertex = mc.polyListComponentConversion(uv, fuv=True, tv=True)[0]
            mc.xform(vertex, t=[uv_pos[0]] + [0] + [uv_pos[1]], ws=True)

        # Finally, scale it
        end_scale = distance.euclidean(
            mc.xform(start_vert, q=True, t=True, ws=True), mc.xform(end_vert, q=True, t=True, ws=True)
        )
        scale_by = start_scale / end_scale

        mc.xform(mc.ls(obj + ".vtx[:]"), s=[scale_by, scale_by, scale_by], ws=True)
コード例 #38
0
ファイル: export_uv.py プロジェクト: creuter23/fs-tech-artist
	def getUVs(self):
		
		# Getting current uvset
		currUVSet = cmds.polyUVSet( self.name, q=True, currentUVSet=True )[0]
		
		for i, uvSet in enumerate(self.uvSets):
			self.uvs[uvSet] = []
			# Setting uvSet temp
			cmds.polyUVSet( self.name, currentUVSet=True, uvSet=uvSet )
			
			# Get uv maps
			uvMaps = cmds.polyListComponentConversion( self.name, ff=1, tuv=1 )
			# verts = PolyFace.findWindingOrder(self.name)
			
			# print(self.vtxFaceNames)
			# cmds.polyListComponentConversion('pPlane2.vtxFace[2][1]', tuv=1 )

			if( uvMaps ):
				# uvMaps = cmds.filterExpand( uvMaps, expand=True, sm=35 )	
				uvMaps = [cmds.polyListComponentConversion(vtxFace, tuv=1 ) for vtxFace in self.vtxFaceNames ]	

				# Check to make sure there are uv's on this face.				
				for uvMap in uvMaps:
					# Get my uvValues 
					uvCoords = cmds.polyEditUV( uvMap, q=True )
					self.uvs[uvSet].append(uvCoords)
			
		# Returning to orginal uvSet	
		cmds.polyUVSet( self.name, currentUVSet=True, uvSet=currUVSet)	
コード例 #39
0
ファイル: uvsUtilities.py プロジェクト: elanifegnirf/Snippets
def rotateComponentsUVs(components, value, clockWise=True):
	"""
	This definition rotates given components UVs.

	:param components: Components. ( Tuple / List )
	:param value: Rotation value. ( Float )
	:param clockWise: Rotation direction. ( Boolean )
	:return: Definition succes. ( Boolean )
	"""

	uvs = getUVsFromComponents(components)
	uCenter, vCenter = getComponentsUVsCenter(uvs)
	if not clockWise:
		value = -value
	cmds.polyEditUV(uvs, pu=uCenter, pv=vCenter, a= -value)
	return True
コード例 #40
0
ファイル: han.py プロジェクト: xbxcw/scripts
    def hSewUvs(self, *args):
        nodes = mc.ls(sl=True)
        edges = mc.ls(mc.polyListComponentConversion(te=True), fl=True)
        a = []
        b = []
        for edge in edges:
            mc.select(edge)
            uvs = mc.ls(mc.polyListComponentConversion(tuv=True), fl=True)
            for uv in uvs:
                p = mc.polyEditUV(uv, query=True)
                a.append(p)
            if len(a) == 4:

                if a[0] == a[1] and a[2] == a[3]:
                    b.append(edge)
                elif a[0] == a[2] and a[1] == a[3]:
                    b.append(edge)
                elif a[0] == a[3] and a[1] == a[2]:
                    b.append(edge)
            a = []
            mc.progressBar(self.progress,
                           edit=True,
                           step=1,
                           maxValue=len(edges))
        mc.select(b)
        mc.SewUVs()
        mc.select(nodes)
コード例 #41
0
ファイル: uvsUtilities.py プロジェクト: elanifegnirf/Snippets
def mirrorComponentsUVs(components, horizontal=True):
	"""
	This definition mirrors given components UVs.

	:param components: Components. ( Tuple / List )
	:param horizontal: Horizontal mirror. ( Boolean )
	:return: Definition succes. ( Boolean )
	"""

	uvs = getUVsFromComponents(components)
	uCenter, vCenter = (math.floor(value) for value in getComponentsUVsCenter(uvs))
	if horizontal:
		cmds.polyEditUV(uvs, pu=uCenter + 0.5, pv=vCenter + 0.5, su= -1)
	else:
		cmds.polyEditUV(uvs, pu=uCenter + 0.5, pv=vCenter + 0.5, sv= -1)
	return True
コード例 #42
0
ファイル: extrude_edge.py プロジェクト: moChen0607/SISideBar
    def saw_uvs(self, mode='after'):
        if mode == 'after':
            saw_edges = self.saw_edges
            self.n_uvs = []
        else:
            saw_edges = common.conv_comp(self.s_edges, mode='vtx')
            saw_edges = common.conv_comp(saw_edges, mode='edge')
            for edge in self.s_edges:
                saw_edges.remove(edge)
        if not saw_edges:
            return
        checked_edges = []
        for edge in saw_edges:
            uvs = common.conv_comp(edge, mode='uv')
            uv_pos = [
                str(map(lambda x: round(x, 5), cmds.polyEditUV(uv, q=True)))
                for uv in uvs
            ]
            #print len(uv_pos)
            uv_pos = list(set(uv_pos))
            #if mode=='pre':
            #print edge, len(uv_pos)
            if len(uv_pos) > 2:
                continue
            checked_edges.append(edge)
        if checked_edges:
            cmds.polyMapSew(checked_edges, ch=True)
        cmds.polyMapSew(self.s_edges, ch=True)  #付け根のUVを縫合する
        self.saw_edges = []
        cmds.select(self.ex_edges, r=True)


#ExtrudeEdgeUV()._init_ui()
コード例 #43
0
    def to_vals(self):
        """Get UV values.

        Returns:
            (float tuple): U/V values
        """
        return cmds.polyEditUV(self, query=True)
コード例 #44
0
    def getUVs(self):

        # Getting current uvset
        currUVSet = cmds.polyUVSet(self.name, q=True, currentUVSet=True)[0]

        for i, uvSet in enumerate(self.uvSets):
            self.uvs[uvSet] = []
            # Setting uvSet temp
            cmds.polyUVSet(self.name, currentUVSet=True, uvSet=uvSet)

            # Get uv maps
            uvMaps = cmds.polyListComponentConversion(self.name, ff=1, tuv=1)
            # verts = PolyFace.findWindingOrder(self.name)

            # print(self.vtxFaceNames)
            # cmds.polyListComponentConversion('pPlane2.vtxFace[2][1]', tuv=1 )

            if (uvMaps):
                # uvMaps = cmds.filterExpand( uvMaps, expand=True, sm=35 )
                uvMaps = [
                    cmds.polyListComponentConversion(vtxFace, tuv=1)
                    for vtxFace in self.vtxFaceNames
                ]

                # Check to make sure there are uv's on this face.
                for uvMap in uvMaps:
                    # Get my uvValues
                    uvCoords = cmds.polyEditUV(uvMap, q=True)
                    self.uvs[uvSet].append(uvCoords)

        # Returning to orginal uvSet
        cmds.polyUVSet(self.name, currentUVSet=True, uvSet=currUVSet)
コード例 #45
0
def set_UV_ratio(obj):
    try:
        print active_ratio
    except:
        om.MGlobal.displayError("Please pick a checker size first")
        return

    orig_sele = cmds.ls(sl=True, fl=True)
    if len(orig_sele) == 0:
        om.MGlobal.displayError("Select at least one object")
        return
    prog = 0.00
    cmds.progressBar(progressControl, edit=True, visible=True)
    cmds.progressBar(progressControl, edit=True, beginProgress=True)

    for i in range(0, len(orig_sele)):
        if (len(orig_sele) != 0):
            if (obj == 1):
                prog += (i * 1.000 / len(orig_sele) * 1.000) * 20
                cmds.progressBar(progressControl, edit=True, pr=prog)
            else:
                prog += (i * 1.000 / len(orig_sele) * 1.000) * 15
                cmds.progressBar(progressControl, edit=True, pr=4 + prog)
        cmds.select(cl=True)
        mel.eval("select " + orig_sele[i])
        current_ratio = get_sel_faces_UV_ratio(0)
        if current_ratio == 0:
            current_ratio = 1
        scale_factor = active_ratio / current_ratio
        scale_factor = math.sqrt(scale_factor)
        mel.eval("PolySelectConvert 4")
        UV_bounds = cmds.polyEvaluate(bc2=True)
        u_pivot = (UV_bounds[0][0] + UV_bounds[0][1]) / 2
        v_pivot = (UV_bounds[1][0] + UV_bounds[1][1]) / 2

        cmds.polyEditUV(pu=u_pivot,
                        pv=v_pivot,
                        su=scale_factor,
                        sv=scale_factor)

    cmds.select(cl=True)
    for i in range(0, len(orig_sele)):
        mel.eval("select -add " + orig_sele[i])

    cmds.progressBar(progressControl, edit=True, endProgress=True)
    cmds.progressBar(progressControl, edit=True, visible=False)
    om.MGlobal.displayInfo("Done")
コード例 #46
0
	def getCurrentCoords( vertex ):
		uv = cmds.polyListComponentConversion( vertex, fv=True, tuv=True )
		if( uv ):
			uvAll = cmds.filterExpand( uv, expand=True, sm=35 )
			uvCoords = cmds.polyEditUV( uvAll , q=True )		
			return uvCoords
		else:
			return []
コード例 #47
0
 def move_uv(self, face):
     #print 'uv_edge :', self.uv_edge
     uvs = common.conv_comp(face, mode='uv')  #作成したフェースのUV
     edge_uvs = common.conv_comp(self.uv_edge, mode='uv')  #選択エッジのUV
     for uv in uvs:
         try:
             vtx = common.conv_comp(uv, mode='vtx')  #UVが属する頂点
             vtx_uv = common.conv_comp(vtx, mode='uv')  #頂点の共有UVたち
             target_uv = list((set(vtx_uv) & set(edge_uvs)) - set(uvs))
             #print 'get_target uv', target_uv, uv
             pos = cmds.polyEditUV(target_uv[0], query=True)
             cmds.polyEditUV(uv, u=pos[0], v=pos[1], r=False)
         except:
             return
     #UVつないでおく
     face_edges = common.conv_comp(face, mode='edge')
     cmds.polyMergeUV(face_edges, ch=1, d=0.01)
コード例 #48
0
ファイル: solidify.py プロジェクト: KelSolaar/Snippets
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)
コード例 #49
0
ファイル: uvsUtilities.py プロジェクト: KelSolaar/Snippets
def moveComponentsUVs(components, u=0, v=0):
	"""
	Moves given components UVs.

	:param components: Components.
	:type components: tuple or list
	:param u: U value.
	:type u: float
	:param v: V value.
	:type v: float
	:return: Definition succes.
	:rtype: bool
	"""

	uvs = getUVsFromComponents(components, flatten=False)
	cmds.polyEditUV(uvs, u=u, v=v)
	return True
コード例 #50
0
 def getCurrentCoords(vertex):
     uv = cmds.polyListComponentConversion(vertex, fv=True, tuv=True)
     if (uv):
         uvAll = cmds.filterExpand(uv, expand=True, sm=35)
         uvCoords = cmds.polyEditUV(uvAll, q=True)
         return uvCoords
     else:
         return []
コード例 #51
0
def setmesh(nodename):
    cmds.select(nodename)

    exts = getnames()
    va, na, pa, uva = exts
    nva, nna, npa, nuva = [nodename+"."+ext for ext in exts]

    # Vertices first.
    vl = cmds.xform(nodename+'.vtx[:]', q=True, os=True, t=True)
    cmds.addAttr(longName=va, dt="string")
    cmds.setAttr(nva, str(vl), type="string")

    # Polygons (called faces in Maya).
    pcnt = cmds.polyEvaluate(f=True)
    cmds.addAttr(longName=pa, dt="string")
    pll = []
    for x in range(pcnt):
        fvl = cmds.polyInfo(nodename+".f[%i]" % x, faceToVertex=True)
        p = fvl[0].split()[2:]
        pll += ["[" + ",".join(p) + "]"]
    pll = "[" + ",".join(pll) + "]"
    cmds.setAttr(npa, pll, type="string")
    pl = eval(pll)

    # Normals and UVs (needs polygons).
    nll = []
    # UVs are only used if user has set a non-default UV-set
    # name (use right-click menu).
    cmds.select(nodename)
    hasUv = (cmds.polyUVSet(q=True, allUVSets=True) != ['map1'])
    uvcnt = 0
    #print("Set is: "+str(cmds.polyUVSet(q=True, allUVSets=True)))
    cmds.addAttr(longName=na, dt="string")
    if hasUv:
        cmds.addAttr(longName=uva, dt="string")
        uvll = []
    for polyidx in range(pcnt):
        poly = pl[polyidx]
        for vtxidx in poly:
            sel = nodename+".vtxFace["+str(vtxidx)+"]["+str(polyidx)+"]"
            cmds.select(sel)
            n = cmds.polyNormalPerVertex(q=True, xyz=True);
            nll += n
            if hasUv:
                uv_names = cmds.polyListComponentConversion(fromVertexFace=True, toUV=True)
                if uv_names:
                    uv_name = uv_names[0]
                    cmds.select(uv_name)
                    uv = cmds.polyEditUV(q=True)
                    uvll += uv
                    uvcnt += 1
    #print "Normals: "+str(nll)
    cmds.setAttr(nna, str(nll), type='string')
    if hasUv:
        #print "UVs: "+str(uvll)
        cmds.setAttr(nuva, str(uvll), type='string')

    return (1, len(vl)/3+len(pl)+len(nll)/3+uvcnt)
コード例 #52
0
ファイル: uvsUtilities.py プロジェクト: KelSolaar/Snippets
def stackObjectsUVs(objects, alignement="center", horizontal=True, margin=0):
	"""
	Stacks given objects UVs.

	:param objects: Objects.
	:type objects: tuple or list
	:param alignement: Alignement ( "bottom", "top", "left", "right", "center" ).
	:type alignement: str
	:param horizontal: Horizontal stack.
	:type horizontal: bool
	:return: Definition succes.
	:rtype: bool
	"""

	if not objects:
		return

	uvs = getUVsFromComponents(objects.pop(0))
	uCenter, vCenter = getComponentsUVsCenter(uvs)
	uMin, vMin, uMax, vMax = getComponentsBoundingBox(uvs)
	uBorder = uMax - uMin + uMin
	vBorder = vMax - vMin + vMin
	for object in objects:
		uvs = getUVsFromComponents(object)
		currentUMin, currentVMin, currentUMax, currentVMax = getComponentsBoundingBox(uvs)
		if horizontal:
			offsetU = uBorder - currentUMin + margin
			if alignement == "bottom":
				offsetV = vMin - currentVMin
			elif alignement == "center":
				offsetV = (vMin - currentVMin) / 2 + (vMax - currentVMax) / 2
			elif alignement == "top":
				offsetV = vMax - currentVMax
			uBorder = uBorder + currentUMax - currentUMin + margin
		else:
			offsetV = vBorder - currentVMin + margin
			if alignement == "left":
				offsetU = uMin - currentUMin
			elif alignement == "center":
				offsetU = (uMin - currentUMin) / 2 + (uMax - currentUMax) / 2
			elif alignement == "right":
				offsetU = uMax - currentUMax
			vBorder = vBorder + currentVMax - currentVMin + margin
		cmds.polyEditUV(uvs, u=offsetU, v=offsetV)
	return True
コード例 #53
0
ファイル: atom_reindeer_lib.py プロジェクト: boochos/work
 def surfCts(name, vertSets):
     '''
     jntsIks[0] = lists of 3 joint sets
     jntsIks[1] = list of ik handles, one for each three joint set
     '''
     #controllers, constraints
     geoParent = []
     j = 0
     for vSet in vertSets:
         i = 0
         setName = ["", "_aim", "_up"]
         rootCtGp = None
         aimCt = None
         upCt = None
         for point in vSet:
             if i < 3:
                 # controller
                 diamond = place.Controller(name + '_' + str(('%0' + str(2) + 'd') % (j)) + setName[i], point, False, 'diamond_ctrl', 5, 12, 8, 1, (0, 0, 1), True, True)
                 DiamondCt = diamond.createController()
                 place.cleanUp(DiamondCt[0], Ctrl=True)
                 cnst = cmds.pointOnPolyConstraint(point, DiamondCt[0])[0]
                 # convert vertex to uv
                 uv = cmds.polyListComponentConversion(point, fv=True, tuv=True)
                 # get uv space
                 space = cmds.polyEditUV(uv, q=True)
                 # set uv attrs on constraint
                 cmds.setAttr(cnst + '.' + point.rsplit('.')[0] + 'U0', space[0])
                 cmds.setAttr(cnst + '.' + point.rsplit('.')[0] + 'V0', space[1])
                 # append geoParent
                 if i == 0:
                     geoParent.append(DiamondCt[4])
                     rootCtGp = DiamondCt[1]
                 elif i == 1:
                     aimCt = DiamondCt[4]
                     cmds.setAttr(DiamondCt[0] + '.visibility', False)
                 elif i == 2:
                     upCt = DiamondCt[4]
                     cmds.setAttr(DiamondCt[0] + '.visibility', False)
                 # constraint
                 '''
                 if i==1:
                     ##ik
                     cmds.pointConstraint(DiamondCt[4], jntsIks[1][j])
                 else:
                     ##joint
                     cmds.pointConstraint(DiamondCt[4], jntsIks[0][j][i])
                     '''
             else:
                 # constrain joint to first controller of vert set list
                 cmds.parentConstraint(geoParent[j], point, mo=True)
             i = i + 1
         # aim constraint
         cmds.aimConstraint(aimCt, rootCtGp, mo=True,
                            aimVector=(0, 0, 1), upVector=(0, 1, 0),
                            worldUpType='object', worldUpObject=upCt)
         j = j + 1
     return geoParent
コード例 #54
0
ファイル: uvsUtilities.py プロジェクト: elanifegnirf/Snippets
def scaleCenterComponentsUVs(components, coverage=DEFAULT_SCALE_COVERAGE):
	"""
	This definition scales / centers given components UVs.

	:param components: Components. ( Tuple / List )
	:return: Definition succes. ( Boolean )
	"""

	uvs = getUVsFromComponents(components)
	uMin, vMin, uMax, vMax = getComponentsBoundingBox(uvs)
	uCenter, vCenter = (uMin + uMax) / 2.0, (vMin + vMax) / 2.0
	uTargetCenter, vTargetCenter = math.floor(uCenter), math.floor(vCenter)
	cmds.polyEditUV(uvs, u=uTargetCenter - uCenter + 0.5, v=vTargetCenter - vCenter + 0.5)
	uScale = math.fabs(uMin - uMax)
	vScale = math.fabs(vMin - vMax)
	scaleFactor = 1 / max(uScale, vScale) * coverage
	cmds.polyEditUV(uvs, pu=uTargetCenter + 0.5, pv=vTargetCenter + 0.5, su=scaleFactor, sv=scaleFactor)
	return True
コード例 #55
0
ファイル: uvsUtilities.py プロジェクト: elanifegnirf/Snippets
def scaleComponentsUVs(components, su=1, sv=1):
	"""
	This definition scales given components UVs.

	:param components: Components. ( Tuple / List )
	:param su: Scale U value. ( Float )
	:param sv: Scale V value. ( Float )
	:return: Definition succes. ( Boolean )
	"""

	if su == 0.0:
		su = 1e-15
	if sv == 0.0:
		sv = 1e-15
	uvs = getUVsFromComponents(components)
	uCenter, vCenter = getComponentsUVsCenter(uvs)
	cmds.polyEditUV(uvs, pu=uCenter, pv=vCenter, su=su, sv=sv)
	return True
コード例 #56
0
    def lineup_V_in_UDIM(self,*args):
        sels = cmds.ls(os=1)
        gap_w = cmds.floatField("gapWValueField", q=True, v=True)
        gap_h = cmds.floatField("gapHValueField", q=True, v=True)
        initGap = 0.003
        fst_in_UDIM = 0

        for i, x in enumerate(sels):
            cmds.select('{0}.map[:]'.format(x), r=1)

            if i == 0:
                # move to the init place
                cmds.polyEditUV(u=-cmds.polyEvaluate(x, b2=1)[0][0] + initGap, v=-cmds.polyEvaluate(x, b2=1)[1][0] + initGap)

            elif i >= 1:
                # get the size of the last shell
                w_last = cmds.polyEvaluate(sels[i-1], b2=1)[0][1]-cmds.polyEvaluate(sels[i-1], b2=1)[0][0]
                h_last = cmds.polyEvaluate(sels[i-1], b2=1)[1][1]-cmds.polyEvaluate(sels[i-1], b2=1)[1][0]
                # calc the distance to the last shell
                dist_u = cmds.polyEvaluate(x, b2=1)[0][0]-cmds.polyEvaluate(sels[i-1], b2=1)[0][0]
                dist_v = cmds.polyEvaluate(x, b2=1)[1][0]-cmds.polyEvaluate(sels[i-1], b2=1)[1][0]
                # move current shell to the last shell
                cmds.polyEditUV(u=-dist_u, v=-dist_v+h_last+gap_h)
                # get the UDIM ID of the current shell and the last shell
                UDIM = int((math.floor(cmds.polyEvaluate(x, b2=1)[0][1])+1)+(math.floor(cmds.polyEvaluate(x, b2=1)[1][1])*10))
                UDIM_last = int((math.floor(cmds.polyEvaluate(sels[i-1], b2=1)[0][1])+1)+(math.floor(cmds.polyEvaluate(sels[i-1], b2=1)[1][1])*10))
                # if shell V is out of UDIM
                if int((math.floor(cmds.polyEvaluate(x, b2=1)[0][1])+1)+(math.floor(cmds.polyEvaluate(x, b2=1)[1][1])*10))-UDIM_last==10:
                    new_u = -(cmds.polyEvaluate(x, b2=1)[0][0]-cmds.polyEvaluate(sels[fst_in_UDIM:i], b2=1)[0][1])+gap_w
                    new_v = -(cmds.polyEvaluate(x, b2=1)[1][0]-initGap)#+int(math.floor((UDIM-11) / 10))
                    cmds.polyEditUV(u=new_u, v=new_v)
                    if int((math.floor(cmds.polyEvaluate(x, b2=1)[0][1])+1)+(math.floor(cmds.polyEvaluate(x, b2=1)[1][1])*10))-UDIM_last==1:
                        new_u = -(cmds.polyEvaluate(x, b2=1)[0][0]-initGap)+(int((math.floor(cmds.polyEvaluate(x, b2=1)[0][1])+1)+(math.floor(cmds.polyEvaluate(x, b2=1)[1][1])*10))-1)
                        new_v = -(cmds.polyEvaluate(x, b2=1)[1][0]-initGap)#+int(math.floor((UDIM-11) / 10))
                        cmds.polyEditUV(u=new_u, v=new_v)
                    # elif cmds.polyEvaluate(x, b2=1)[0][0] > 10:
                    #     new_u = -cmds.polyEvaluate(x, b2=1)[0][0]+initGap
                    #     new_v = cmds.polyEvaluate(x, b2=1)[1][0]+1
                    #     cmds.polyEditUV(u=new_u, v=new_v)
                elif int((math.floor(cmds.polyEvaluate(x, b2=1)[0][1])+1)+(math.floor(cmds.polyEvaluate(x, b2=1)[1][1])*10))-UDIM_last==1:
                    new_u = -(cmds.polyEvaluate(x, b2=1)[0][0]-cmds.polyEvaluate(sels[fst_in_UDIM:i], b2=1)[0][1])+gap_w
                    new_v = -(cmds.polyEvaluate(x, b2=1)[1][0]-initGap)+int(math.floor((UDIM-11) / 10))
                    cmds.polyEditUV(u=new_u, v=new_v)
        cmds.select(sels,r=1)
コード例 #57
0
ファイル: rigTools.py プロジェクト: myCodeTD/pkmel
def uvOffsetor() :

	sels = mc.ls( sl=True )

	for ix in range( len( sels ) ) :

		obj = sels[ix]
		

		vtxNo = mc.polyEvaluate( obj , v=True )

		mc.select( '%s.vtx[0:%d]' % ( obj , vtxNo ) , r=True )

		cmd = 'PolySelectConvert 4;'
		mm.eval( cmd )

		mc.polyEditUV( u=ix )

	mc.select( sels )
コード例 #58
0
ファイル: uvsUtilities.py プロジェクト: elanifegnirf/Snippets
def getComponentUVDims(component):
	"""
	This definition returns the UVDims of the given component.

	:param component: Component to retrieve the UVDims. ( String )
	:return: UVDims. ( Tuple )
	"""

	u, v = cmds.polyEditUV(component, q=True, uValue=True, vValue=True)
	return int(u), int(v)