def performQuicksnap(): # options # width = int(mc.text('resTextW', query=True, label=True)) height = int(mc.text('resTextH', query=True, label=True)) if mc.checkBox('doubleRes', query=True, value=True): width *= 2 height *= 2 autoLoad = mc.checkBox('autoLoad', query=True, value=True) antiAlias = mc.checkBox('antiAliasing', query=True, value=True) fileName = 'outUV' format = mc.optionMenuGrp('fileFormat', query=True, value=True) filePath = mc.textField('pathField', query=True, text=True) + '/' + fileName + '.' + format uis.setUiState() # # # Perform # # # mc.uvSnapshot(name=filePath, xr=width, yr=height, o=True, aa=antiAlias, ff=format) if autoLoad: os.startfile(filePath)
def uvSnapshot(self): valBase = 1 projectFileName = mc.file(query=True, list=True) UVFolder = projectFileName[0].split('/') del UVFolder[-1] UVFolder[6] = "sourceimages" print ">> : ", UVFolder[9] propsName = UVFolder[9] UVFolder = '/'.join(UVFolder) UVFolder = UVFolder + "/uv" if not os.path.exists(UVFolder): os.makedirs(UVFolder) from os import listdir from os.path import isfile, join onlyfiles = [f for f in listdir(UVFolder) if isfile(join(UVFolder, f))] countFile = len(onlyfiles) print ">> : ", countFile + valBase valBase = valBase + countFile # fileName = "UV_%s" % valBase fileName = "uv_" + str(propsName) + "_v" + str(valBase) filePathName = UVFolder + "/" + fileName + '.png' print ">> : ", fileName mc.uvSnapshot(o=True, ff="png", n=filePathName, xr=4096, yr=4096)
def _uvSnaps(self, assetName): selection = cmds.ls(sl=True) validShapes = cmds.listRelatives(selection, ad=True, type=["mesh", "nurbsSurface"]) if len(validShapes) > 10: msg = "There are %s objects for UV snapshots.\nAre you sure you want to include snapshots to the Asset?" %(len(validShapes)) state = cmds.confirmDialog(title='Too many objects for UV Snapshot', message=msg, button=['Ok', 'Cancel']) # cmds.warning("There are unknown nodes in the scene. Cannot proceed with %s extension. Do you want to proceed with %s?" %(ext, origExt)) if state == "Ok": pass else: cmds.warning("Uv snapshots skipped") return assetDirectory = os.path.join(self.directory, assetName) UVdir = os.path.join(assetDirectory, "UV_snaps") if not os.path.isdir(os.path.normpath(UVdir)): os.makedirs(os.path.normpath(UVdir)) for i in range(0, len(validShapes)): objName = validShapes[i].replace(":", "_") UVpath = os.path.join(UVdir, '%s_uv.jpg' % objName) cmds.select(validShapes[i]) try: cmds.uvSnapshot(o=True, ff="jpg", n=UVpath, xr=1600, yr=1600) except: cmds.warning("Cannot create UV snapshot for %s" % validShapes[i]) cmds.select(selection)
def takeUvSnapshot(self, *args): fileName = cmds.textField(self.uvImagePath, q=True, text=True) resolution = cmds.optionMenuGrp( self.uvImageResolution, q=True, value=True) imageFormat = cmds.optionMenuGrp( self.uvImageFormat, q=True, value=True) tileNumber = cmds.optionMenuGrp( self.uvImageTileNumber, q=True, value=True) if (tileNumber[3] == "0" or tileNumber[3] == 0): uMin = 9.0 vMin = float(int(tileNumber[2]) - 1) else: uMin = float(int(tileNumber[3]) - 1) vMin = float(tileNumber[2]) uMax = float(uMin + 1.0) vMax = float(vMin + 1.0) if resolution == "8k": xRes = 8192 yRes = 8192 elif resolution == "4k": xRes = 4096 yRes = 4096 elif resolution == "2k": xRes = 2048 yRes = 2048 elif resolution == "1k": xRes = 1024 yRes = 1024 elif resolution == "512": xRes = 512 yRes = 512 cmds.uvSnapshot( name=fileName, aa=True, fileFormat=imageFormat, xResolution=xRes, yResolution=yRes, overwrite=True, redColor=255, greenColor=255, blueColor=255, uMax=uMax, uMin=uMin, vMax=vMax, vMin=vMin)
def takeUvSnapshot(self, *args): fileName = cmds.textField(self.uvImagePath, q=True, text=True) resolution = cmds.optionMenuGrp(self.uvImageResolution, q=True, value=True) imageFormat = cmds.optionMenuGrp(self.uvImageFormat, q=True, value=True) tileNumber = cmds.optionMenuGrp(self.uvImageTileNumber, q=True, value=True) if (tileNumber[3] == "0" or tileNumber[3] == 0): uMin = 9.0 vMin = float(int(tileNumber[2]) - 1) else: uMin = float(int(tileNumber[3]) - 1) vMin = float(tileNumber[2]) uMax = float(uMin + 1.0) vMax = float(vMin + 1.0) if resolution == "8k": xRes = 8192 yRes = 8192 elif resolution == "4k": xRes = 4096 yRes = 4096 elif resolution == "2k": xRes = 2048 yRes = 2048 elif resolution == "1k": xRes = 1024 yRes = 1024 elif resolution == "512": xRes = 512 yRes = 512 cmds.uvSnapshot(name=fileName, aa=True, fileFormat=imageFormat, xResolution=xRes, yResolution=yRes, overwrite=True, redColor=255, greenColor=255, blueColor=255, uMax=uMax, uMin=uMin, vMax=vMax, vMin=vMin)
def main(): """docstring for main""" sel = cmds.ls(sl=True)[0] scene_path = cmds.file(sn=True, q=True) scene_name = os.path.basename(scene_path) export_path = os.path.join(os.path.dirname(scene_path), '..', '..', 'exports') out_filename = '_'.join( [os.path.splitext(scene_name)[0], convert_filename(sel), 'uv.png']) out_file = os.path.abspath(os.path.join(export_path, out_filename)) if not os.path.exists(export_path): os.makedirs(export_path) cmds.uvSnapshot(aa=True, n=out_file, xr=4096, yr=4096, r=255, g=255, b=255, o=True, ff='png')
def createUVTexture (SelectedShapes): try: #get temp dir TmpDir = cmds.internalVar(userTmpDir=True) #filepath uvsnapshotfile_path = TmpDir + 'pt_uvsnapshot.jpg' #delete file with uv snapshot cmds.sysFile (uvsnapshotfile_path, delete=True ) cmds.uvSnapshot(antiAliased=True, fileFormat="jpg", o=True, n=uvsnapshotfile_path, xr=1024, yr=1024 ) #create and assign mat pt_2dTUV = cmds.shadingNode('place2dTexture', name='pt_2dTUV', asUtility=True) pt_uv_texture = cmds.shadingNode('file', name='pt_uv_texture', asTexture=True) pt_checker = cmds.shadingNode('lambert', asShader=True, name="pt_uv_shader") cmds.setAttr('pt_uv_texture'+'.fileTextureName', uvsnapshotfile_path , type="string") pt_shading_group_uv = cmds.sets(name='pt_shading_group_uv', renderable=True, empty=True) cmds.disconnectAttr('lambert1.outColor', 'pt_shading_group_uv.surfaceShader') cmds.connectAttr('pt_uv_shader'+'.outColor','pt_shading_group_uv'+'.surfaceShader') cmds.connectAttr('pt_uv_texture'+'.outColor','pt_uv_shader'+'.color') cmds.connectAttr('pt_2dTUV'+'.outUV','pt_uv_texture'+'.uvCoord') #turn on textures in viewport CurrentState = cmds.modelEditor('modelPanel4', q = True, displayTextures=True) if CurrentState == False: cmds.modelEditor( modelPanel='modelPanel4', da="smoothShaded", displayTextures=True, displayLights="default", cameras=False, activeView=True) print ("PolygonTools. Texture based on UV-layout was created!") except: cmds.warning ("PolygonTools. Cant create UV-texture.")
def publish(self, settings, item): """ Executes the publish logic for the given item and settings. Any raised exceptions will indicate that the publish pass has failed and the publisher will stop execution. :param dict settings: The keys are strings, matching the keys returned in the :data:`settings` property. The values are :class:`~.processing.Setting` instances. :param item: The :class:`~.processing.Item` instance to validate. """ # keep track of everything currently selected. we will restore at the # end of the publish method # get the path to create and publish publish_path = item.properties["publish_path"] # ensure the publish folder exists: publish_folder = os.path.dirname(publish_path) self.parent.ensure_folder_exists(publish_folder) # get camera frame range uvmap_name = item.properties['uvmap_name'] # fbx_export_cmd = 'FBXExport -f "%s" -s' % (publish_path.replace(os.path.sep, "/"),) # print "publish path:",publish_path.replace(os.path.sep, "/") uvmap_path = '' # print "publish_path:",publish_path # \\3par\ibrix01\shotgun\shotgun_work\tdprojects\sequences\sc001\sh003\LAY\publish\maya\cameras\camMain_LAY.v006.abc # if publish_path.startswith("\\"): # sp = publish_path.split('\\') # sp.pop(0) # root = "//" + sp[0] # temp_path = '/'.join(sp[1:]) # if "\t" in temp_path: # temp_path = temp_path.replace('\t', '/t') # uvmap_path = os.path.join(root, temp_path) # uvmap_path = uvmap_path.replace("\\", '/') # else: # if "\t" in publish_path: # temp_path = publish_path.replace('\t', '/t') # uvmap_path = temp_path.replace(os.path.sep, '/') current_dir = os.path.dirname(__file__) _hooks = os.path.dirname(os.path.dirname(current_dir)) import sys if _hooks not in sys.path: sys.path.append(_hooks) from func import replace_special_character as rsc publish_path = rsc.replaceSpecialCharacter(publish_path) self.logger.info("A Publish will be created in Shotgun and linked to:") self.logger.info(" %s" % (publish_path)) _format = "tif" _xr = _yr = 2048 cmds.uvSnapshot(uvmap_name, o=True, ff=_format, xr=_xr, yr=_yr, aa=True, n=publish_path) item.properties["publish_type"] = "Image" # Now that the path has been generated, hand it off to the super(MayaUVMapPublishPlugin, self).publish(settings, item)
def exportUDIM(): global uMax global vMax global amount global outputDir global maxUval global maxVval cntu = 1 getObjUVsName = mc.textScrollList('getUDIMObj', q=True, ai=True) for polySel in getObjUVsName: amount = 0.0 mc.progressBar('progBar', e=True, pr=amount, st='working') UDIM = 1 polyShp = mc.listRelatives(polySel, ni=True, s=True) if mc.nodeType(polyShp) == 'mesh': getUVTiles() uMax = maxUval vMax = maxVval imageFormat = mc.optionMenu('imgFormat', q=True, value=True) onek = mc.checkBox('uvRes1', q=True, v=True) twok = mc.checkBox('uvRes2', q=True, v=True) fourk = mc.checkBox('uvRes3', q=True, v=True) eightk = mc.checkBox('uvRes4', q=True, v=True) if onek == True: uvRes = 1024 elif twok == True: uvRes = 2048 elif fourk == True: uvRes = 4096 elif eightk == True: uvRes = 8192 else: mc.error('Select a UV resolution') totalUDIM = float(uMax * vMax) for incv in range(vMax): #Check the U & V UDIM = UDIM + 1000 r = 0 for incu in range(uMax): print incu, incv dirUVOutput = (outputDir + polySel + '_UV.' + str(UDIM + r) + '.' + imageFormat) mc.uvSnapshot(polySel, aa=True, umn=incu, umx=incu, vmn=incv, vmx=incv, n=(dirUVOutput), xr=uvRes, yr=uvRes, r=0, g=0, b=0, o=True, ff=imageFormat) mc.progressBar('progBar', e=True, pr=amount, st='working') amount = ((cntu / totalUDIM) * 100) r += 1 cntu += 1 amount = 100 mc.progressBar('progBar', e=True, pr=amount, st='working') else: mc.error('Current selection is not a polygonal mesh') amount = 0 mc.progressBar('progBar', e=True, pr=amount, st='working')
# -*- coding: utf-8 -*- import maya.cmds as mc number_of_udims = 3 path = "C:\\Users\\thibaulth\\Documents\\maya\\projects\\default\\images\\" res = 2048 for i in range(number_of_udims): mc.uvSnapshot(aa=True, uMin=i, uMax=i+1, vMin=0, vMax=1, n=path + "udim.{0}.png".format(1001+i), xr=res, yr=res, r=255, g=255, b=255, o=True, ff="png")
def main(self): texturesPath = self.texturePath.text() uvPath = self.uvFolder.text() uvSuffix = self.uvSuffix.text() fileExtension = self.fileExtension.currentText() mapResolution = self.resolution.currentText() color = self.color.currentText() meshes = mc.ls(selection=True) print('EXPORT STARTED') for mesh in meshes: shapes = mc.listRelatives(mesh, children=True, shapes=True) if shapes: for shape in shapes: if mc.objectType(shape) == 'mesh': mc.select(shape, replace=True) uvSets = mc.polyUVSet(allUVSets=True, query=True) for uvSet in uvSets: if color == 'green': red = blue = 0 green = 255 elif color == 'blue': red = green = 0 blue = 255 elif color == 'red': green = blue = 0 red = 255 elif color == 'pink': red = blue = 255 green = 0 elif color == 'yellow': red = green = 255 blue = 0 elif color == 'white': red = green = blue = 255 elif color == 'black': red = green = blue = 0 fileName = texturesPath + '/' + uvPath if not fileName == texturesPath: fileName += '/' if not os.path.exists(fileName): os.makedirs(fileName) fileName += mesh + '_' + uvSet + uvSuffix + '.' + fileExtension mc.polyUVSet(currentUVSet=True, uvSet=uvSet) mc.uvSnapshot(overwrite=True, fileFormat=fileExtension, xResolution=int(mapResolution), yResolution=int(mapResolution), antiAliased=True, redColor=red, greenColor=green, blueColor=blue, name=fileName) print fileName + ' as been created' mc.select(meshes, replace=True) print('EXPORT FINISHED')
def uvSnapshot(export_path, ext, res, colorSymbol, source=0): if not export_path: mc.warning('Please enter a output folder!') return -1 if not isdir(export_path): mc.warning('The directory is invalid : {0}'.format(export_path)) return -1 pairs_mesh = {} # Get source 0: from display layer, 1:from sets, 2:from selected if source == 0: pairs_mesh = _getPolygonFromDisplayLayers() elif source == 1: pairs_mesh = _getPolygonsFromSets() elif source == 2: selections = mc.ls(sl=True, l=True) if selections: pairs_mesh = {'uv_snapshot': selections} else: mc.warning('# Please select objects!') return -1 if not pairs_mesh: mc.warning('No any meshs can be snapshot') return -1 if not _userConfirm('UV Snapshot', '\n'.join(pairs_mesh.keys())): return # Store previous selections store_selections = mc.ls(sl=True) amout = 0 process_max = len(pairs_mesh) # UV Snapshot Color R, G, B = 0, 1, 2 if colorSymbol == 'Black': color = (0, 0, 0) elif colorSymbol == 'White': color = (255, 255, 255) elif colorSymbol == 'Red': color = (255, 0, 0) else: color = (255, 255, 255) # Progress Window mc.progressWindow(title='UV Snapshot', progress=amout, status='Snapshot start...', isInterruptable=True, max=process_max) # for key in pairs_mesh.keys(): mc.select(cl=True) fullpath = '{0}/{1}.{2}'.format(export_path, key , ext) try: mc.select(pairs_mesh[key], r=True) mc.uvSnapshot(overwrite=True, redColor=color[R], greenColor=color[G], blueColor=color[B], xResolution=int(res), yResolution=int(res), fileFormat=ext, antiAliased=True, name=fullpath) amout += 1 mc.progressWindow(e=True, progress=amout, status='Snapshot : {0} / {1}'.format( amout, process_max)) except: mc.progressWindow(endProgress=True) raise print('UV Snapshot > '+fullpath) # End the progress window mc.progressWindow(endProgress=True) if store_selections: mc.select(store_selections, r=True) else: mc.select(cl=True)