2012年2月17日金曜日

MAXScript マテリアルエディタの操作 (2) マルチ


マルチマテリアルを作成するスクリプト

・作成するスロット番号を選択
・サブマテリアル数を選択
・Createボタンを押す
・画像選択ダイアログで画像選択


-- dropdownlist作成用の配列
slotNoArray = #()
subMtlNumArray = #()

-- デフォルト値
defaultSlotNo = 1           -- スロット番号
defaultSubMtlNum = 2        -- サブマテリアル数

-- 初期化処理
fn Init = (
    -- スロット番号
    for i = 1 to 24 do (
        append slotNoArray ( i as string )
    )
    -- サブマテリアル数
    for i = 1 to 10 do (
        append subMtlNumArray ( i as string )
    )
)

-- マルチマテリアルを作成
-- slotNo: スロット番号
-- subMtlNum: サブマテリアル数
fn CreateMultiMtl slotNo subMtlNum = (

    -- モードのセット
    MatEditor.mode = #basic

    -- 状態取得
    isOpen = MatEditor.isOpen()
    
    -- マテリアルエディタを開く
    if false == isOpen do ( MatEditor.Open() )

    -- マルチマテリアルを作成
    newMtl = multimaterial ()
    
    -- 画像を読み込む
    for i = 1 to subMtlNum do (
        -- Captionの文字列
        ss = stringStream ""
        format "Select SubMtl Texture %" i to:ss
        seek ss 0
        str = ( readLine ss )

        -- 画像を選択
        local img = selectBitMap caption:str
        if undefined == img do ( return undefined )
        
        -- 選択画像からBitmapTextureを作成
        local bmTex = BitmapTexture bitmap:img

        -- マテリアルを作成
        local mtl = standardMaterial diffuseMap:bmTex showInViewport:true
        
        newMtl[i] = mtl
    )
    -- マテリアルをスロットにセット
    setMeditMaterial slotNo newMtl
)
-- ロールアウト
rollout RolloutMtl "CreateMultiMaterial" 
(
    -- スロット数選択用
    dropdownlist dSlotNo "Slot No:" pos:[16, 16] \
            items:slotNoArray width:80

    -- サブマテリアル数選択用
    dropdownlist dNumSubMtl "Sub Material Num:" pos:[120, 16] \
            items:subMtlNumArray width:80 selection:defaultSubMtlNum

    -- 作成ボタン
    button btnCreate "Create" width:96 height:24    pos:[64, 64]
    
    on  btnCreate pressed do (
        CreateMultiMtl dSlotNo.selection dNumSubMtl.selection
    )
)
Init()
createDialog RolloutMtl width:240 height:100

0 件のコメント:

コメントを投稿