Subsurface Scattering 作成 MEL スクリプト

MEL スクリプトの例

前回の Subsurface Scattering (misss_fast_simple_maya)シェーダーの作成を MEL スクリプトで自動化してみましょう。

  1. 以下の MEL スクリプトを misss1.mel という名前で作ります。
    global proc misss1()
    {
    	nurbsPlane -ax 0 1 0;
    	scale 30 30 30;
    	string $sname[] = `sphere`;
    	move 0 1 0 ;
    	pointLight;
    	move 3.0 3.3 3.0;
    	pointLight;
    	move -3.0 -1.0 -3.0;
    
    	string $misss = `shadingNode -asShader misss_fast_simple_maya`;
    	string $sg = `sets -renderable true -noSurfaceShader true -empty`;
    	connectAttr ($misss + ".message") ($sg + ".miMaterialShader");
    	select $sname[0];
    	sets -e -forceElement $sg;
    
    	string $textureNode = `createNode mentalrayTexture`;
    	connectAttr -f ($textureNode + ".message") ($misss + ".lightmap");
    	setAttr ($textureNode + ".miWritable") 1;
    	setAttr ($textureNode + ".miWidth") 1280;
    	setAttr ($textureNode + ".miHeight") 480;
    	setAttr ($textureNode + ".miDepth") 4;
    
    	string $lmap = `shadingNode -asUtility misss_fast_lmap_maya`;
    	connectAttr -f ($lmap + ".message") ($sg + ".miLightMapShader");
    	connectAttr -f ($textureNode + ".message") ($lmap + ".lightmap");
    	setAttr ($misss + ".front_sss_color") -type double3 1 0 0 ;
    	setAttr ($misss + ".back_sss_color") -type double3 0 0 1 ;
    	setAttr ($misss + ".front_sss_weight") 1;
    	setAttr ($misss + ".back_sss_weight") 3;
    	setAttr ($misss + ".samples") 256;
    }
    
  2. Script EditorFile → Source Script によって misss1.mel を読み込みます。
  3. Script Editor のインプットウインドウで、misss1() を実行します。
    (misss1() 実行後の図)
    [misss1() 実行後の図]
    [レンダリング実行図]
    [HyperShade の図]

スクリプトの解説

global proc misss1()
misss_fast_lmap_maya を使ったシェーダを作成するプロシージャの宣言です。
nurbsPlane -ax 0 1 0;
NURBS の平面を作成します。
-ax
平面の上の方向を現す軸
scale 30 30 30;
X, Y, Z 方向に 30 のスケールをかけます。
string $sname[] = `sphere`;
NURBS の球体を作成します。
$sname[0] に transform ノード名、$sname[1] に makeNurbSphere ノード名が代入されます。
move 0 1 0 ;
NURBS の球体を (0, 1, 0) に移動します。
pointLight;
点光源を作成します。
move 3.0 3.3 3.0;
点光源を (3.0, 3.3, 3.0) に移動します。
pointLight;
点光源をもうひとつ作成します。
move -3.0 -1.0 -3.0;
2 つ目の点光源を (-3.0, -1.0, -3.0) に移動します。
string $misss = `shadingNode -asShader misss_fast_simple_maya`;
misss_fast_simple_maya ノードをシェーダとして作成します。
string $sg = `sets -renderable true -noSurfaceShader true -empty`;
シェーディンググループ(set ノード)を作成し、その名前を $sg に代入します。
-renderable true
作られたセットはシェーディンググループになって、 renderPartition ノードにコネクトされます。
-noSurfaceShader true
デフォールトのシェーダーにコネクトしません。
上で作った surfaceShader $sname[0] にコネクトするためです。
-empty
空のセットを作ります。
セレクトされているオブジェクトがあっても、 このセットに加えません。
connectAttr ($misss + ".message") ($sg + ".miMaterialShader");
misss_fast_simple_maya ノードの message アトリビュートと、 シェーディンググループの miMaterialShader アトリビュートをコネクトします。
select $sname[0];
NURBS の球体($sname)を選択します。
sets -e -forceElement $sg;
選択された $obj をシェーディングループであるセット $sg に追加します。
-e
編集モードにします。
-forceElement
選択されているオブジェクトを強制的にセットに追加します。
選択されているオブジェクト別のセットのメンバーである場合は、 別のセットから削除されます。
string $textureNode = `createNode mentalrayTexture`;
mentalrayTexture ノードを作成します。
connectAttr -f ($textureNode + ".message") ($misss + ".lightmap");
mentalrayTexture ノードの message アトリビュートと、 misss_fast_simple_maya ノードの lightmap アトリビュートをコネクトします。
setAttr ($textureNode + ".miWritable") 1;
mentalrayTexture ノードの miWritable アトリビュートに 1 を設定します。
シェーダによって作られたテクスチャがファイルに書き込まれます。
これによって、miWidth, miHeight, miDepthアトリビュートなどが有効になります。
setAttr ($textureNode + ".miWidth") 1280;
mentalrayTexture ノードの miWidth アトリビュートに 1280 を設定します。
ファイルに書き込まれるテクスチャの横の解像度が 1280 になります。
setAttr ($textureNode + ".miHeight") 480;
mentalrayTexture ノードの miHeight アトリビュートに 480 を設定します。
ファイルに書き込まれるテクスチャの縦の解像度が 480 になります。
setAttr ($textureNode + ".miDepth") 4;
mentalrayTexture ノードの miDepth アトリビュートに 4 を設定します。
ファイルに書き込まれるテクスチャの深度が 32 bit になります。
他に設定できる数値は、1 または 2 で以下のような深度になります。
1
8 bit
2
16 bit
string $lmap = `shadingNode -asUtility misss_fast_lmap_maya`;
misss_fast_lmap_maya ノードを作成します。
connectAttr -f ($lmap + ".message") ($sg + ".miLightMapShader");
misss_fast_lmap_maya ノードの message アトリビュートと、 シェーディンググループの miLightMapShader アトリビュートをコネクトします。
connectAttr -f ($textureNode + ".message") ($lmap + ".lightmap");
mentalrayTexture ノードの message アトリビュートと、 misss_fast_lmap_maya ノードの lightmap アトリビュートをコネクトします。
setAttr ($misss + ".front_sss_color") -type double3 1 0 0 ;
misss_fast_simple_maya ノードの front_sss_color を 1 0 0 (赤)にします。
setAttr ($misss + ".back_sss_color") -type double3 0 0 1 ;
misss_fast_simple_maya ノードの back_sss_color を 0 0 1 (青)にします。
setAttr ($misss + ".front_sss_weight") 1;
misss_fast_simple_maya ノードの front_sss_weight を 1 にします。
setAttr ($misss + ".back_sss_weight") 3;
misss_fast_simple_maya ノードの back_sss_weight を 3 にします。
setAttr ($misss + ".samples") 256;
misss_fast_simple_maya ノードの samples を 256 にします。
レンダリング結果をきれいにしたい場合は、 512, 1024, 2048 などの数値にしてゆきます。

練習

練習課題

参考


Prev | Next
Home | Contents
Mail