Render Node Utilities (Triple Switch)

tripleSwitch

マテリアルの色のような、 3 つの数値によって構成されるアトリビュートをオブジェクトごとに切替えるには tripleSwitch を使用します。

tripleSwitch の例

2 つの NURBS の球を作成して lambert マテリアルをアサインし、 そのマテリアルに対し、オブジェクトごとに違うテクスチャーをアサインするスクリプトです。

  1. 以下の MEL スクリプトを tripleSwitch1.mel という名前で作ります。
    global proc tripleSwitch1()
    {
    	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 $tsname = `shadingNode -asUtility tripleShadingSwitch`;
    	connectAttr -f ($tsname + ".output") ($sname + ".color");
    
    	string $sphname[] = `listRelatives -s $spname1[0]`;
    	connectAttr ($sphname[0] + ".instObjGroups[0]") ($tsname + ".input[0].inShape");
    	$sphname = `listRelatives -s $spname2[0]`;
    	connectAttr ($sphname[0] + ".instObjGroups[0]") ($tsname + ".input[1].inShape");
    
    	string $txname1 = `shadingNode -asTexture fractal`;
    	string $plname1 = `shadingNode -asUtility place2dTexture`;
    	connectAttr ($plname1 + ".outUV") ($txname1 + ".uv");
    	connectAttr ($plname1 + ".outUvFilterSize") ($txname1 + ".uvFilterSize");
    	connectAttr -f ($txname1 + ".outColor") ($tsname + ".input[0].inTriple");
    
    	string $txname2 = `shadingNode -asTexture noise`;
    	string $plname2 = `shadingNode -asUtility place2dTexture`;
    	connectAttr ($plname2 + ".outUV") ($txname2 + ".uv");
    	connectAttr ($plname2 + ".outUvFilterSize") ($txname2 + ".uvFilterSize");
    	connectAttr -f ($txname2 + ".outColor") ($tsname + ".input[1].inTriple");
    }
    
  2. Script EditorFile → Source Script によって tripleSwitch1.mel を読み込みます。
  3. Script Editor のインプットウインドウで、tripleSwitch1() を実行します。
    (tripleSwitch1() 実行後の図)
    [tripleSwitch1() 実行後の図]
    (tripleSwitch1() 実行後の HyperShade の図)
    [tripleSwitch1() 実行後の HyperShade の図]
  4. レンダリングを実行します。
    それぞれの球に違うテクスチャーがアサインされています。
    [レンダリング実行後の図]

スクリプトの解説

global proc tripleSwitch1()
tripleSwitch1() というプロシージャを宣言します。
string $spname1[] = `sphere`;
1 つ目の NURBS の球を作成します。
string $spname2[] = `sphere`;
2 つ目の NURBS の球を作成します。
move 2 0 0;
2 つ目の NURBS の球を (2, 0, 0) に移動します。
string $sname = `shadingNode -asShader lambert`;
lambert マテリアルを作成します。
string $sgname = `sets -renderable true -noSurfaceShader true -empty`;
オブジェクトをマテリアルにアサインするためのセットを作ります。
-renderable true
作られたセットはシェーディンググループになって、 renderPartition ノードにコネクトされます。
-noSurfaceShader true
デフォールトのマテリアルにコネクトしません。
上で作ったマテリアル $sname にコネクトするからです。
-empty
空のセットを作ります。
セレクトされているオブジェクトがあっても、 このセットに加えないようにします。
connectAttr -f ($sname + ".outColor") ($sgname + ".surfaceShader");
マテリアルの色情報を表す outColor アトリビュートを、 セットの surfaceShader アトリビュートにコネクトします。
これで、マテリアル $sname がレンダリング可能になります。
[マテリアルと set の図]
select -r $spname1[0] $spname2[0];
作成しておいた 2 つの球をセレクトします。
sets -e -forceElement $sgname;
セレクトした 2 つの球を、作成しておいた lambert マテリアルにアサインします。
string $tsname = `shadingNode -asUtility tripleShadingSwitch`;
tripleSwitch (tripleShadingSwitch)を作成します。
connectAttr -f ($tsname + ".output") ($sname + ".color");
tripleSwitch ($tsname)の output アトリビュートを lambert マテリアル($sname)の color アトリビュートにコネクトします。
[tripleSwitch のシェーディングネットワークの図]
string $sphname[] = `listRelatives -s $spname1[0]`;
1 つ目の球のシェープノードの名前を求めて文字列変数 $sphname に代入します。
connectAttr ($sphname[0] + ".instObjGroups[0]") ($tsname + ".input[0].inShape");
1 つ目の球のシェープノード ($sphname)のアトリビュート instObjGroups[0] を tripleSwitch ($tsname)のアトリビュート input[0].inShape とコネクトします。
$sphname = `listRelatives -s $spname2[0]`;
2 つ目の球のシェープノードの名前を求めて文字列変数 $sphname に代入します。
connectAttr ($sphname[0] + ".instObjGroups[0]") ($tsname + ".input[1].inShape");
2 つ目の球のシェープノード ($sphname)のアトリビュート instObjGroups[0] を tripleSwitch ($dsname)のアトリビュート input[1].inShape とコネクトします。
[球とコネクトされた tripleSwitch]
string $txname1 = `shadingNode -asTexture fractal`;
fractal テクスチャーを作成します。
string $plname1 = `shadingNode -asUtility place2dTexture`;
fractal テクスチャーのために place2dTexture を作成します。
connectAttr ($plname1 + ".outUV") ($txname1 + ".uv");
place2dTexture ($plname1)のアトリビュート outUV を fractal テクスチャー($txname1)のアトリビュート uv にコネクトします。
connectAttr ($plname1 + ".outUvFilterSize") ($txname1 + ".uvFilterSize");
place2dTexture ($plname1)のアトリビュート outUvFilterSize を fractal テクスチャー($txname1)のアトリビュート uvFilterSize にコネクトします。
connectAttr -f ($txname1 + ".outColor") ($tsname + ".input[0].inTriple");
fractal テクスチャー($txname1)のアトリビュート outColor を tripleSwitch ($tsname)のアトリビュート input[0].inTriple にコネクトします。
[tripleSwitch にコネクトされた fractal テクスチャー]
string $txname2 = `shadingNode -asTexture noise`;
noise テクスチャーを作成します。
以下は、 fractal テクスチャーに対して行なった操作と同じです。
string $plname2 = `shadingNode -asUtility place2dTexture`;
noise テクスチャーのために place2dTexture を作成します。
connectAttr ($plname2 + ".outUV") ($txname2 + ".uv");
place2dTexture ($plname2)のアトリビュート outUV を noise テクスチャー($txname2)のアトリビュート uv にコネクトします。
connectAttr ($plname2 + ".outUvFilterSize") ($txname2 + ".uvFilterSize");
place2dTexture ($plname2)のアトリビュート outUvFilterSize を noise テクスチャー($txname2)のアトリビュート uvFilterSize にコネクトします。
connectAttr -f ($txname2 + ".outColor") ($tsname + ".input[1].inTriple");
noise テクスチャー($txname2)のアトリビュート outColor を tripleSwitch ($tsname)のアトリビュート input[1].inTriple にコネクトします。
[tripleSwitch にコネクトされた noise テクスチャー]

練習

練習課題

参考


Prev | Next
Home | Contents
Mail