// =========================================================================== // 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. // =========================================================================== // // Procedure: addToLayeredTx // // Description: // // Add a file texture to a layered texture node. // If $layeredTx is specified as an empty string // than a new layered texture node is created. // // Arguments: // layeredTx : layered texture to add to // newTexture : texture to add // killColorLayer : if the right-most layer is a color, replace it. // connectAlpha : connect textures alpha up to the layered texture alpha // // Last Updated : 07/18/00 // global proc string addToLayeredTx(string $layeredTx, string $newTexture, int $blendMode, int $killColorLayer, int $connectAlpha) { if (size($newTexture) == 0) error ((uiRes("m_addToLayeredTx.kNoTextureName"))); // Create a new layered texture if none if (size($layeredTx) == 0) $layeredTx = `shadingNode -asTexture layeredTexture`; int $idx = `getAttr -s ($layeredTx+".inputs")`; // If layer to connect to has no input, than overwrite it if ($killColorLayer && ($idx > 0)) { int $idx1 = $idx - 1; string $connected[] = `listConnections -s 1 ($layeredTx+".inputs["+$idx1+"].color")`; if (size($connected) == 0) $idx = $idx - 1; } // Just in case something weird happens... if ($idx < 0) $idx = 0; // Hook up the file texture to the layered texture while (catch( `connectAttr ($newTexture+".outColor") ($layeredTx+".inputs["+$idx+"].color")`)) { $idx = $idx + 1; } if ($connectAlpha) { while (catch (`connectAttr ($newTexture+".outAlpha") ($layeredTx+".inputs["+$idx+"].alpha")`)) { $idx = $idx + 1; } } //print ("Final index used = " + $idx + "\n"); // Set the blend mode. Leave it at none, if its the first texture if ($idx != 0) { setAttr ($layeredTx + ".inputs[" + $idx + "].blendMode ") $blendMode; } return $layeredTx; }