2012年2月18日土曜日

MAXScript メッシュの作成 (1)

SplineShapeを作成 -> 押し出して何かするテスト

-- 制御点の配列
gPosArray = #()
append gPosArray [20,  10,  0]
append gPosArray [20, -10, 0]
append gPosArray [-20,-20, 0]
append gPosArray [-20, 25, 0]

-- シンプルなメッシュの作成
-- SplineShapeを作成して押し出す
-- posArray 制御点の配列
-- Height       SplineShapeを押し出す高さ
-- Outline      輪郭の押し出し値
fn CreateSimpleMesh posArray Height Outline= (
    
    -- SplineShapeを作成
    local sp = splineShape()
    idx = addnewSpline sp
    for i = 1 to posArray.Count do (
        addKnot sp idx #corner #line posArray[ i ]
    )
    close sp idx
    updateShape sp

    -- メッシュに変換
    convertToMesh sp

    -- 全面の押し出し
    meshop.extrudeFaces sp #{ 1.. sp.numfaces } Height Outline

    -- メッシュの面のマテリアルIDを変更
    newMtlID = 2
    setFaceMatID sp 1 newMtlID  -- Face 1
    setFaceMatID sp 2 newMtlID  -- Face 2
/*  
    -- 面のマテリアルIDを取得
    for i = 1 to sp.numfaces do (
        format "Face % Mtl ID = %\n" i ( getFaceMatID sp i )
    )
*/
    -- UVWMapモディファイアの追加
    addModifier sp (UVWMap maptype:4) -- maptype 4:Box
    
    sp
)

-- メッシュを作成
mesh1 = CreateSimpleMesh gPosArray 100.0 -2.0
mesh1.pos = [100, 0, 0]

mesh2 = CreateSimpleMesh gPosArray 50.0 0.0
mesh2.pos = [0, 50, 0]

mesh3 = CreateSimpleMesh gPosArray 25.87 15.0
mesh3.pos = [-50, -80, 0]

0 件のコメント:

コメントを投稿