ON-BLOG

CGのこと、あれこれ書いてます。

XSIユーザーから観たMELスクリプトについて 其の五

ではここでイメージを変えて、「Window作成」にいこう。
※XSIでいうPPG

このMELウィンドウ相当良い感じでした。
ではまずは超かんたんなコード

window -title "ウィンドウ 3";
columnLayout;
button -label "球体" -command "sphere";
button -label "コーン" -command "cone";
button -label "立方体" -command "nurbsCube";
showWindow;

実行するとこんな感じです。
f:id:tommy_on:20130615020837p:plain
ボタン押せば名前のオブジェクトができます。
これを元にほんの少しだけカスタムしたのがこれ
↓↓↓

window -title "ウィンドウ 1";
columnLayout;
button -label "半径  5" -command "circlesphere1(5.0,5)";
button -label "半径 10" -command "circlesphere1(10.0,10)";
showWindow;

global proc circlesphere1(float $rad,int $num)
{
        int $i;
        float $r = 0.0;
        float $add = 360.0 / $num;


        for($i = 0; $i < $num ; $i ++)
                {
                sphere;
                move $rad 0 0;
                rotate -ws -p 0 0 0 0 $r 0;
                $r += $add;
                
                }


}


このスクリプトは実行すると、
ウィンドウが立ち上がり、「半径5」「半径10」
のボタンが現れ、それを押すと
半径5の位置に球が5個作成されます。
半径10も同様です。
f:id:tommy_on:20130615020927p:plain
シンプルなコードです。
繰り返しますが、このMELのwindowはかなり便利です。
windowだけ空のものができるので、コードが簡素化されるかも。。
あとこのコードで注目したいのは、

columnLayout;

これは縦(列)に並べますってやつです。
横(行)だと

ROWLayout;

になりますね。
これも便利。
あとこれ

button -label "半径  5" -command "circlesphere1(5.0,5)";

これがSIでいう、LogicとPPGLayoutを合わせたものですね。
「button -label "半径 5」ボタンを作成して、表示名前を「半径 5」にしてます。

-command "circlesphere1(5.0,5)";

「-command」でこれ以降に書かれているコマンドを実行します。
という意味です。
実行文は「""」で括り、複数実行する場合は「;」で間はさみます。



とまぁこんな感じでした。
ちなみにSIでやると、

var oP = XSIFactory.CreateObject( "CustomProperty" );
oP.name = "ウィンドウ 1";
var oL, oItem;
oL = oP.PPGLayout;
oL.AddRow();
     oL.AddGroup( "", true, 300);
                                oItem = oL.AddButton( "H5", "半径  5" );
                                oItem = oL.AddButton( "H10", "半径  10" );
          oL.EndGroup();
oL.EndRow();
     ////////////////////////////////////////
     oL.Language = "JScript";
     oL.Logic = H5_OnClicked.toString()+
                             H10_OnClicked.toString()+
                        circlesphere;
     ////////////////////////////////////////
          function H5_OnClicked()
                             {
                                     circlesphere(5.0,2.0,5);
                             }
          function H10_OnClicked()
                             {
                                     circlesphere(10.0,2.0,10);
                             }
                             
                    
         function circlesphere(rad,pai,num)
                        {
                        var r = 0.0;
                        var add = 360.0 / num;
        
                        for(var i = 0; i < num ; i++)
                                {
                                var Sphere= CreatePrim("Sphere", "NurbsSurface");
                                SetValue(Sphere+".sphere.radius", 1);
                                Scale(Sphere, pai, pai, pai);
                                Translate(Sphere, rad, 0, 0, siRelative, siGlobal, siObj, siXYZ, null, null, null, null, null, null, null, null, null, 0, null);
                                TranslatePivot(Sphere,0,0,0);
                                Rotate(Sphere, 0, 0, r , siRelative, siGlobal, siObj, siXYZ, null, null, null, null, null, null, null, 0, null);
                                r += add;
                                }
                        }
        InspectObj( oP, null, null, siLock );

f:id:tommy_on:20130615021210p:plain
え~長いです。
もっとスリム化できると思うんですが、とりあえず。。
こう見るとWindow自体の操作は圧倒的にMELがいいですね。
けどSIもSIで、ロジックの書き方等解りやすい点もあるんですが。。


とまぁこれだけ
次はスライダー関係

では…