Maya においてシェーディングネットワークを構成する場合に Render Node Utilities を使用すると、
複雑なシェーダーを作ることができます。
今回は Render Node Utilities の中から doubleSwitch を使用した MEL スクリプトを作ってみましょう。
doubleSwitch によって、 2 つの数値からなるアトリビュートをオブジェクトごとに切替えることができるようになります。 例えば、多くのオブジェクトに同じマテリアルとテクスチャーをアサインして、 テクスチャーの一部のアトリビュートだけをそれぞれ違う数値にすることができます。
2 つの NURBS の球を作り、 それぞれに同じマテリアルとテクスチャー(checker)をアサインし、 テクスチャーの repeatUV アトリビュートをオブジェクトごとに切替える MEL スクリプトを作ってみましょう。
global proc doubleSwitch1()
{
string $spname1[] = `sphere`;
string $spname2[] = `sphere`;
move 2 0 0;
string $sname = `shadingNode -asShader lambert`;
string $sgname = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($sname + ".outColor") ($sgname + ".surfaceShader");
select -r $spname1[0] $spname2[0];
sets -e -forceElement $sgname;
string $chname = `shadingNode -asTexture checker`;
string $plname = `shadingNode -asUtility place2dTexture`;
connectAttr ($plname + ".outUV") ($chname + ".uv");
connectAttr ($plname + ".outUvFilterSize") ($chname + ".uvFilterSize");
connectAttr -f ($chname + ".outColor") ($sname + ".color");
string $dsname = `shadingNode -asUtility doubleShadingSwitch`;
connectAttr -f ($dsname + ".output") ($plname + ".repeatUV");
string $sphname[] = `listRelatives -s $spname1[0]`;
connectAttr ($sphname[0] + ".instObjGroups[0]") ($dsname + ".input[0].inShape");
$sphname = `listRelatives -s $spname2[0]`;
connectAttr ($sphname[0] + ".instObjGroups[0]") ($dsname + ".input[1].inShape");
$plname = `shadingNode -asUtility place2dTexture`;
connectAttr -f ($plname + ".repeatUV") ($dsname + ".input[0].inDouble");
$plname = `shadingNode -asUtility place2dTexture`;
connectAttr -f ($plname + ".repeatUV") ($dsname + ".input[1].inDouble");
}
global proc doubleSwitch1()
string $spname1[] = `sphere`;
string $spname2[] = `sphere`;
move 2 0 0;
string $sname = `shadingNode -asShader lambert`;
string $sgname = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($sname + ".outColor") ($sgname + ".surfaceShader");
select -r $spname1[0] $spname2[0];
sets -e -forceElement $sgname;
string $chname = `shadingNode -asTexture checker`;
string $plname = `shadingNode -asUtility place2dTexture`;
connectAttr ($plname + ".outUV") ($chname + ".uv");
connectAttr ($plname + ".outUvFilterSize") ($chname + ".uvFilterSize");
connectAttr -f ($chname + ".outColor") ($sname + ".color");
string $dsname = `shadingNode -asUtility doubleShadingSwitch`;
connectAttr -f ($dsname + ".output") ($plname + ".repeatUV");
string $sphname[] = `listRelatives -s $spname1[0]`;
connectAttr ($sphname[0] + ".instObjGroups[0]") ($dsname + ".input[0].inShape");
$sphname = `listRelatives -s $spname2[0]`;
connectAttr ($sphname[0] + ".instObjGroups[0]") ($dsname + ".input[1].inShape");
$plname = `shadingNode -asUtility place2dTexture`;
connectAttr -f ($plname + ".repeatUV") ($dsname + ".input[0].inDouble");
$plname = `shadingNode -asUtility place2dTexture`;
connectAttr -f ($plname + ".repeatUV") ($dsname + ".input[1].inDouble");