// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // Description: // Go through all shaders in the scene, find the file texture nodes directly connected // to the color attribute. For each file texture connected to the color attribute, we // connect the outTransparency too if and only if: // // - There isn't anything connected to the shader's transparency attribute. // - The file texture contains some transparent pixels (ie: fileTexture.fileHasAlpha == 1) // global proc useTextureAlphasForTransparency() { string $materials[]; // Get a list of all material nodes in the scene // $materials = `ls -materials`; int $i; for ($i = 0; $i < size($materials); $i++) { if ( (size(`ls ($materials[$i] + ".color")`) != 0) && (size(`ls ($materials[$i] + ".transparency")`) != 0)) { // // The material has color and transparency attributes // // Determine the source node of the color attribute of the material // (if any) // string $colorSrc[]; $colorSrc = `listConnections -source true -destination false ($materials[$i] + ".color")`; // Determine the source node of the transparency attribute of the // material (if any) // string $transparencySrc[]; $transparencySrc = `listConnections -source true -destination false ($materials[$i] + ".transparency")`; string $colorTextureName = $colorSrc[0]; int $fileHasAlpha = ($colorTextureName != "") && (`nodeType $colorTextureName` == "file") && (`getAttr ($colorTextureName+".fileHasAlpha")`); if ($fileHasAlpha && ($colorSrc[0] != "") && ($transparencySrc[0] == "")) { // // The color attribute has a source node, and the transparency // attribute doesn't // if (size(`ls ($colorSrc[0] + ".outTransparency")`) != 0) { // The source node of the color attribute of the material // also has an outTransparency attribute, so we will // connect it to the transparency attribute of the // material. // connectAttr ($colorSrc[0] + ".outTransparency") ($materials[$i] + ".transparency"); } } } } }