// =========================================================================== // 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 Name: // getComponentShader // // Description: // this script returns the shader assigned to a given // poly, nurbs or subd face // // Input Arguments: // string $component: the component to get the shader for // // Returns: // string: the shader assigned to the given component global proc string getComponentShader(string $component){ // find the shape node string $shape[] = `listRelatives -parent $component`; // find the shading engine string $connections[] = `listConnections -source false -type "shadingEngine" $shape[0]`; // there may be more than one shading group connected to the // geometry so find the exact one $connections = `stringArrayRemoveDuplicates $connections`; string $shadingGroup;//shadingGroup attached to component string $shader[];//shader attached to component via shadingGroup for ($connection in $connections){ int $result = `sets -isMember $connection $component`; if ($result == 1) {$shadingGroup = $connection;} } // if no shading group has been found, the components must not be // mapped - this means the shape is mapped if ($shadingGroup == ""){ for ($connection in $connections){ int $result = `sets -isMember $connection $shape[0]`; if ($result == 1) {$shadingGroup = $connection;} } } if ($shadingGroup != ""){ // find the shader connected to the shading group string $shaderConnection = `connectionInfo -sourceFromDestination ($shadingGroup + ".surfaceShader")`; tokenize $shaderConnection "." $shader; } else { string $msgFormat = (uiRes("m_getComponentShader.kNoShaderFound")); error (`format -s $component $msgFormat`); } return $shader[0]; }