Python スクリプトで重複頂点の自動削除

選択したオブジェクトの重複頂点を自動で削除するスクリプトを改良しました。

使い方は至って簡単
  1. Blender で Python Console を表示
  2. 重複頂点を削除したいオブジェクトを選択
  3. 以下のコードを、空行も含めてコピー
  4. Python Console にペーストすると実行される
以上。


重複頂点を自動で削除するスクリプト

選択オブジェクトの重複頂点を削除するスクリプトです。

▼ここから▼

import bpy
for object in bpy.context.selected_objects:
 if object.type == 'MESH':
     bpy.context.scene.objects.active = object 
     # recalculate outside normals:
     bpy.ops.object.mode_set(mode='EDIT') 
     bpy.ops.mesh.select_all() 
     bpy.ops.mesh.normals_make_consistent(inside=False)
     bpy.ops.object.mode_set(mode='OBJECT')
     # remove doubles:
     bpy.ops.object.mode_set(mode='EDIT') 
     bpy.ops.mesh.select_all() 
     bpy.ops.mesh.remove_doubles() 
     bpy.ops.object.mode_set(mode='OBJECT')



▲ここまで▲

実行されると、以下のようなメッセージが処理されたオブジェクト分表示されます。
・・・
{'FINISHED'}
{'FINISHED'}
Info: Removed 42358 vertices

{'FINISHED'}
{'FINISHED'}


Wavefront 経由でインポートしたオブジェクトに実行するスクリプト

Wavefront 経由でインポートしたオブジェクトに対して、以下の処理を行うスクリプトです。
これを Text Editor に貼り付けておいたものを、Startup File としておけばいちいちコピペしなくて便利。
  • 回転角度を 0 度にする
  • スケールを 0.001 倍にする
  • 重複頂点を削除する
  • オブジェクト原点を各オブジェクトの原点にする
  • マテリアルをリムーブする

▼ここから▼

import bpy
for object in bpy.context.selected_objects:
  if object.type == 'MESH':
       object.rotation_euler = (0.0, 0.0, 0.0)
       object.scale = (0.001, 0.001, 0.001)
       bpy.context.scene.objects.active = object
       # recalculate outside normals:
       bpy.ops.object.mode_set(mode='EDIT')
       bpy.ops.mesh.select_all()
       bpy.ops.mesh.normals_make_consistent(inside=False)
       bpy.ops.object.mode_set(mode='OBJECT')
       # remove doubles:
       bpy.ops.object.mode_set(mode='EDIT')
       bpy.ops.mesh.select_all()
       bpy.ops.mesh.remove_doubles()
       bpy.ops.object.mode_set(mode='OBJECT')


for object in bpy.context.selected_objects:
  if object.type == 'MESH':
       # origin set geometry:
       bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')


for object in bpy.context.selected_objects:
   if object.type == 'MESH':
        bpy.ops.object.material_slot_remove()
        bpy.ops.object.material_slot_copy()



▲ここまで▲


オリジナルコードの出所

感謝!Thanks!Danke!



コメントを投稿するには画像の文字を半角数字で入力してください。


画像認証

  • 最終更新:2015-05-26 09:12:29

このWIKIを編集するにはパスワード入力が必要です

認証パスワード