/////////////////////////////////////////////////////////// // James Deschenes - Texture Exporter v1.0 // // Created March 4th, 2008 // /////////////////////////////////////////////////////////// // WHAT IS THIS? // This is a photoshop script which will let you quickly export layer groups as texture files to various formats // including the 3delight TDL format. // // HOW DO I USE IT? // 1. Make a photoshop file, create some groups (such as "diffuse", "specular", "bump", "self_illumination" ect...) // 2. Save this file to the location you will be keeping all your texture files and name it accordingly. // 3. Run the script (either by going to file/scripts/browse or placing it in your preset scripts folder in the photoshop directory // 4. Check the boxes of the layers you wish to export, then select what formats you want to save them as. // 5. The script will do the rest, exporting what you have selected to the same folder as where the photoshop document is saved // and using the original documents name and layer group names to create the texture filenames. var checkDoc = true; try { // Grab the active document docRef = activeDocument } catch(err) { alert("You must have a document open first!") checkDoc = false; } // If you have a document open, then run the rest of the code. if (checkDoc == true) { main(); } function main() { var numGroups = docRef.layerSets.length // Find the location of the above asset folder var groupID // This will store the id number of the assetFolder group for later use // UI Code var windowHeight = 310; var mainBounds = {x:100 ,y:100 , width:200 , height:windowHeight} var exportDlg = new Window('dialog', 'James Deschenes - 3dl Texture Exporter',mainBounds ); var panelBounds = {x:10, y:10, width:180, height:170} exportDlg.msgPnl = exportDlg.add("panel", panelBounds, "Textures to export") exportDlg.msgPnl.alignChildren = "left" var checkboxArray = new Array(); // Storing all our checkboxes in here that we are about to create in our loop below var layerNameArray = new Array(); // Storing all our layer names in here for (g=0; g= 7) && (g < 14)) { var offset_colB = ((g - 7) * 17) + 15; var exportLayer = exportDlg.msgPnl.add('checkbox',[165, offset_colB, 310, offset_colB + 17],cleanGroupName); exportDlg.size = [300, windowHeight]; exportDlg.msgPnl.size = [280, 170]; } if (g >= 14) { var offset_colC = ((g - 14) * 17) + 15; var exportLayer = exportDlg.msgPnl.add('checkbox',[320, offset_colC, 465, offset_colC + 17],cleanGroupName); exportDlg.size = [470, windowHeight]; exportDlg.msgPnl.size = [450, 170]; } exportLayer.value = true; checkboxArray.push(exportLayer); layerNameArray.push(cleanGroupName); } //BUTTON SIZE ORDER is left, top, right, bottom // Select No Layers Button var selectNone = exportDlg.msgPnl.add('button',[75, 135, 135, 155], "None"); selectNone.onClick = function() { for (g in checkboxArray) { checkboxArray[g].value = false; } } // Select All Layers Button var selectAll = exportDlg.msgPnl.add('button',[10, 135, 70, 155], "All"); selectAll.onClick = function() { for (g in checkboxArray) { checkboxArray[g].value = true; } } var panelBounds = {x:10, y:190, width:180, height:80} exportDlg.formatPnl = exportDlg.add("panel", panelBounds, "Texture Format") var exportCustomFiles = exportDlg.formatPnl.add('dropdownlist',[25, 10, 130, 25]); exportCustomFiles.add("item", "TIF"); exportCustomFiles.add("item", "TGA"); exportCustomFiles.add("item", "PNG"); exportCustomFiles.add("item", "JPG"); exportCustomFiles.selection = 0; var radio_exportCustomFiles = exportDlg.formatPnl.add('radiobutton',[10, 15, 130, 30], ""); var radio_exportTdlFiles = exportDlg.formatPnl.add('radiobutton',[10, 35, 160, 50], "3delight TDL"); var radio_exportBothFiles = exportDlg.formatPnl.add('radiobutton',[10, 55, 160, 70], "Both Above Formats"); radio_exportBothFiles.value = true; //////////////////////////////////////////////////////////////////////////////////////////////// // CODE TO HIDE ALL THE LAYERS AND GROUPS // //////////////////////////////////////////////////////////////////////////////////////////////// function hideLayers() { var numLayers = docRef.artLayers.length; var numGroups = docRef.layerSets.length; for (g=0; g NUL"); if (keepOriginal == false) { bat.writeln("del \"" + inputfile + "\" > NUL"); } bat.close(); bat.execute(); } tdlmake.createTexture = function(inputfile, outputfile, keepOriginal) { tdlmake.execute(["\"" + inputfile + "\" \"" + outputfile + "\""], keepOriginal, inputfile); } function exportTexture(method, format, texturename) { ///////////////////////////////////////////// // Various Save Options // ///////////////////////////////////////////// // TIFF tiffSaveOptions = new TiffSaveOptions(); tiffSaveOptions.alphaChannels = true; tiffSaveOptions.byteOrder = ByteOrder.IBM; tiffSaveOptions.imageCompression = TIFFEncoding.NONE; tiffSaveOptions.layers = false; // TGA targaSaveOptions = new TargaSaveOptions(); targaSaveOptions.alphaChannels = true; targaSaveOptions.resolution = TargaBitsPerPixels.THIRTYTWO; targaSaveOptions.rleCompression = false; // PNG pngSaveOptions = new PNGSaveOptions(); pngSaveOptions.interlaced = false; // JPEG jpegSaveOptions = new JPEGSaveOptions(); jpegSaveOptions.quality = 12; ///////////////////////////////////////////////////////////////////////////////////////// // COMMON CODE TO ALL EXPORT OPTIONS // ///////////////////////////////////////////////////////////////////////////////////////// switch (format) { case "TIF": var saveFormat = tiffSaveOptions; break; case "TGA": var saveFormat = targaSaveOptions; break; case "PNG": var saveFormat = pngSaveOptions; break; case "JPG": var saveFormat = jpegSaveOptions; break; default: var saveFormat = tiffSaveOptions; break; } var basename = docRef.name.substring(0, docRef.name.length - 4 ); exportFile = new File( docRef.path + "/" + basename + "_" + texturename.toLowerCase() + "." + format.toLowerCase() ); tdlFile = new File( docRef.path + "/" + basename + "_" + texturename.toLowerCase() + ".tdl" ); /////////////////////////////////////////////////// // SWITCH STARTS HERE // ////////////////////////////////////////////////// switch (method) { ////////////////////////////////////////////////////////////////////// // EXPORT ONLY CUSTOM FORMAT // ////////////////////////////////////////////////////////////////////// case "custom_only": docRef.saveAs (exportFile, saveFormat, true); break; //////////////////////////////////////////////////////////// // EXPORT ONLY TDL FORMAT // //////////////////////////////////////////////////////////// case "tdl_only": docRef.saveAs (exportFile, saveFormat, true); tdlmake.createTexture(exportFile.fsName, tdlFile.fsName, false); break; /////////////////////////////////////////////////////// // EXPORT BOTH FORMATS // ////////////////////////////////////////////////////// case "both": docRef.saveAs (exportFile, saveFormat, true); tdlmake.createTexture(exportFile.fsName, tdlFile.fsName, true); break; //////////////////////////////////////////////////////////// // DEFAULT BEHAVIOR - OOPS // //////////////////////////////////////////////////////////// default: alert("Something went wrong"); } } var doExport = exportDlg.add('button',[105, 280, 190, 300], "Export"); var cancelExport = exportDlg.add('button',[10, 280, 95, 300], "Cancel"); doExport.onClick = function() { var format = exportCustomFiles.selection.toString(); for (i in layerNameArray) { //docRef.layerSets[g].visible = checkboxArray[g].value; if (checkboxArray[i].value == true) { hideLayers(); docRef.layerSets[i].visible = checkboxArray[i].value; if (radio_exportCustomFiles.value == true) { exportTexture("custom_only", format, layerNameArray[i]); } else if (radio_exportTdlFiles.value == true) { exportTexture("tdl_only", "TIF", layerNameArray[i]); } else if (radio_exportBothFiles.value == true) { exportTexture("both", format, layerNameArray[i]); } } } showLayers(); exportDlg.close(); } // Display our window exportDlg.center(); exportDlg.show(); }