// =========================================================================== // 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: addTextureToShaderLayered // // Description: // // Add a file texture to a shader node's color connection // with either adding a new layered texture in between, // or adding a new layer to an existing layered texture // connection // // Arguments: // shader : shader / shading engine to add to // thisTexture : texture to add // killColorLayer : replace color layer in layered texture // connectAlpha : connect alpha of texture to layered texture alpha // // Last Updated : 07/18/00 // global proc addTextureToShaderLayered(string $shader, string $thisTexture, int $blendMode, int $killColorLayer, int $connectAlpha) { //if (size($shader) == 0) // error ("No shader name passed to addTextureToShaderLayered()"); //if (size($thisTexture) == 0); // error ("No texture name passed to addTextureToShaderLayered()"); // Check to see if we got passed in a shading engine string $shaderAttr = ".color"; string $sType[] = `ls -showType $shader`; if ($sType[1] == "shadingEngine") { string $shaders[] = `listConnections -d 1 ($shader+".surfaceShader")`; $shader = $shaders[0]; if (size($shader) == 0) $shaderAttr = ".surfaceShader"; } // Check if the shader already has a layered texture // if so use it. string $colorCons[] = `listConnections -d on -p on ($shader+$shaderAttr)`; string $layeredTx = ""; string $existingTx = ""; if (size($colorCons)) { string $node = `plugNode $colorCons[0]`; string $nType[] = `ls -showType $node`; if ($nType[1] == "layeredTexture") { $layeredTx = $nType[0]; } // See if its any kind of texture else { string $allTex[] = `ls -tex`; for ($i = 0; $i < size($allTex); $i++) { if ($node == $allTex[$i]) { $existingTx = $node; break; } } } } // Break old non-layered texture connection if (size($layeredTx) == 0) { if (size($colorCons)) { disconnectAttr ($colorCons[0]) ($shader+$shaderAttr); // If there was an existing texture than hook that up // to the layered texture first. if (size($existingTx)) { $layeredTx = addToLayeredTx( $layeredTx, $existingTx, $blendMode, 0, 0); //print ("Add existing to layered tex " + $layeredTx + "\n"); } } // Hook the file texture to the layered texture. $layeredTx = addToLayeredTx( $layeredTx, $thisTexture, $blendMode, $killColorLayer, $connectAlpha ); // Hook the layered texture up to the shader connectAttr ($layeredTx+".outColor") ($shader+$shaderAttr); } else { // If there was an existing texture than hook that up // to the layered texture first. // Just hook up the file texture to the existin layered texture addToLayeredTx( $layeredTx, $thisTexture, $blendMode, $killColorLayer, $connectAlpha ); } }