///////////////////////////////////////////////////////////////////////////////////////////////////////// // James Deschenes - Selected Texture Exporter v1.0 // // Created March 4th, 2008 // // Change these three variables below to suit your needs // ///////////////////////////////////////////////////////////////////////////////////////////////////////// var exportFormat = "TIF" // Can be TIF TGA PNG JPG (If you plan to convert to TDL, I would use TIF) also must be in CAPITAL LETTERS var keepExport = true; // True/False wether you want to keep in initial export file (the tif/tga/jpg/png file) var convertToTDL = true; // True/False wether you want to convert it to the 3delight texture format // WHAT IS THIS? // This script is a one-click version of my Advanced Texture Exporter script. It was created so you can easily setup the script once by editing it // then just run it everytime you want to do a quick single export without having to keep configuring the same options over and over. // // WHAT DOES IT DO AGAIN? // It will export your currently active layer out as it's own texture file and convert it to a 3delight TDL file if you want. // // HOW DO I USE IT? // 1. Make a photoshop file, create some groups or layers (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. Select the layer or group you want to save out. // 4. Make sure this script file is configured to your liking (check out the initial three variables at the top of this file) // 4. Run the script (either by going to file/scripts/browse or placing it in your preset scripts folder in the photoshop directory // 5. Your done. ////////////////////////////////////////////////////////// // REAL CODE BEGINS HERE // ////////////////////////////////////////////////////////// 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() { ////////////////////////////////////////////////// // GET SELECTED LAYER // ////////////////////////////////////////////////// var groupName = app.activeDocument.activeLayer; var cleanGroupName = groupName.toString().slice(10, groupName.toString().length - 1); //////////////////////////////////////////////////////////////////////////////////////////////// // 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); } /////////////////////////////////////////// // EXPORT TEXTURE // ////////////////////////////////////////// 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"); } } //////////////////////////////////////////////////////////////////////////// // Ok now we begin what we need to do // // in the proper order too! // //////////////////////////////////////////////////////////////////////////// rememberLayers(); hideLayers(); displaySelected(); // Do what we need to do based on the user set varibles at the begining of this script if ((keepExport == true) && (convertToTDL == true)) { exportTexture("both", exportFormat, cleanGroupName); } if ((keepExport == false) && (convertToTDL == true)) { exportTexture("tdl_only", exportFormat, cleanGroupName); } if ((keepExport == true) && (convertToTDL == false)) { exportTexture("custom_only", exportFormat, cleanGroupName); } if ((keepExport == false) && (convertToTDL == false)) { alert("Your script file has been configured wrong, it's set to export a " + exportFormat + " then delete it and do nothing... which is useless?"); } showLayers(); }