2005年04月13日

MergePoints

LWのMergePointsみたいなスクリプト

 

--
--  同じ座標にある面頂点を一つの頂点にまとめます
--
macroScript mergePoints category:"HowTo"
(
  --一つのオブジェクトが選択されていて、そのオブジェクトがメッシュ、ポリゴン、パッチの時だけ実行できる
  on isEnabled return
  (
    local result = false
    if selection.count == 1 then
    (
      if classof selection[1].baseobject == Editable_mesh then result = true
      if classof selection[1].baseobject == Editable_Poly then result = true
      if classof selection[1].baseobject == Editable_Patch then result = true
    )
    result
  )
 
  on execute do
  (
    --プログレスバー表示用のパネル作成
    rollout progressPanel "MergePoints"
    (
      progressbar prog
    )
    --プログレスバーの初期化
    progressPanel.prog.value = 0.0
    --パネルを開く
    try (destroyDialog progressPanel)catch()
    createDialog progressPanel
   
    --処理開始
    local obj_mesh = selection[1].mesh
    local num_verts = obj_mesh.numVerts
    local num_faces = obj_mesh.numFaces
    for v=1 to num_verts do
    (
      local pos = getVert obj_mesh v
      for vv=1 to num_verts do
      (
        local temp = getVert obj_mesh vv
        if temp == pos then
        (
          for f=1 to num_faces do
          (
            local tempFace = getFace obj_mesh f
            local isChanged = false
            if vv == tempFace.x then
            (
              tempFace.x = v
              isChanged = true
            )
            if vv == tempFace.y then
            (
              tempFace.y = v
              isChanged = true
            )
            if vv == tempFace.z then
            (
              tempFace.z = v
              isChanged = true
            )
            if isChanged == true then
            (
              setFace selection[1].mesh f tempFace
            )
          )-- for f
        )-- if pos
      )-- for vv
      progressPanel.prog.value = 100.0 * v / num_verts
    )-- for v
   
    --孤立頂点を削除
    meshop.deleteIsoVerts selection[1].mesh
    update selection[1].mesh
   
    --パネルを閉じる
    try (destroyDialog progressPanel)catch()
   
    --処理結果表示
    local msgtxt = num_verts as string
    msgtxt += "  ->  "
    msgtxt += selection[1].mesh.numVerts as string
    messageBox msgtxt
   
    --パネルの表示が残ってしまうので画面を再描画する
    redrawViews()
  )--execute
)

 

【関連する記事】
posted by toka at 14:38| Comment(0) | TrackBack(0) | MAXScript | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:


この記事へのトラックバック