0
0

More than 1 year has passed since last update.

スクリプトでモディファイアを適用したメッシュを作成する

Posted at

チャットでBlenderのモディファイアを付けた状態のメッシュを作成する話題があったのでメモ

因みに単純にモディファイアを適用したメッシュを取得したいだけなら
オブジェクトメニューの変換>メッシュで 「オリジナルを保持」をチェックして変換するのが楽
image.png

アクティブオブジェクトのモディファイアを適用したオブジェクトを作成したい場合

import bpy
obj = bpy.context.active_object
depsgraph = bpy.context.evaluated_depsgraph_get()
modified = obj.evaluated_get(depsgraph)
mesh = bpy.data.meshes.new_from_object(modified)
new_obj = bpy.data.objects.new( "new_obj", mesh)
bpy.context.scene.collection.objects.link(new_obj)

スクリプト内で変換した頂点データ等を取得する場合のコード
(modifiedはMeshのデータなもののデータブロックは作成されない)

import bpy
def getModifiedMesh28(obj):
    depsgraph = bpy.context.evaluated_depsgraph_get()
    modified = obj.evaluated_get(depsgraph).to_mesh
    return(modified)
obj = bpy.context.active_object
modified = getModifiedMesh28(obj)

Blender2.8以降で変更になった部分で
他サイトを参考に以前のコードと挙動を揃えるために使ったことがあるだけなので
細かいことはちょっとわかってない・・・ので単なるメモ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0