// =========================================================================== // 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. // =========================================================================== // // Script: AEcolorRemap.mel // // SYNOPSIS // Creates a color re-map node on a texture. // global proc AEcolorRemap( string $targetname) { string $tmp; string $connection; // Should test that this also includes children of this compound attr. APP 18jun97 string $compoundConnection[] = `listConnections -source false -destination true -plugs true $targetname`; int $numConnects = size($compoundConnection); // If the first node connected to is an RgbToHsv, we warn the user // that this node is probably already color remapped. if ($numConnects > 0) { $connection = $compoundConnection[0]; //print ("Checking if " + $connection + " is an rgbToHsv node.\n"); $tmp = `nodeType $connection`; //print ("Nodetype is " + $tmp + "\n"); if ($tmp == "rgbToHsv") { string $cancel = (uiRes("m_AEcolorRemap.kCancel")); $tmp = `confirmDialog -title (uiRes("m_AEcolorRemap.kOutColorRemapped")) -message (uiRes("m_AEcolorRemap.kOutColorMessage")) -button (uiRes("m_AEcolorRemap.kContinue")) -button $cancel -defaultButton $cancel -cancelButton $cancel -dismissString $cancel`; //print ("confirmDialog returned " + $tmp + "\n"); if ($tmp == $cancel) { return; } } } // Create the rgb to hsv node so that we can transform the color to use ramp properly. $tmp = `shadingNode -asUtility rgbToHsv`; string $nameB = "RemapRgbToHsv#"; $nameB = `rename $tmp $nameB`; // Create the ramp node which will remap the color based on the value of the textures' color. $tmp = `shadingNode -asTexture ramp`; string $nameC = "RemapRamp#"; $nameC = `rename $tmp $nameC`; // Connect the newly created nodes to each other. connectAttr -force ($targetname) ($nameB + ".inRgb"); connectAttr -force ($nameB + ".outHsvH") ($nameC + ".uCoord"); connectAttr -force ($nameB + ".outHsvV") ($nameC + ".vCoord"); // Now change the connections to be to the remap ramp rather than the texture. // print ("There are " + $numConnects + " connections to " + $targetname + "\n"); for ( $connection in $compoundConnection ) { // print ("TRYING TO CONNECT " + $nameC + ".outColor" + " TO " + $connection + "\n"); catch ( `connectAttr -force ($nameC + ".outColor") $connection` ) ; } }