MRが楽しい

MRやVRについて学習したことを書き残す

Blenderのビルド手順 その5(組み込み用Blenderでのアドオン利用)

本日は Blender の技術調査です。
前回記事では Blender を ptyon のモジュールとしてビルドして python に取り込みました。
今回は ptyon のモジュールとしてビルドした Blender にアドオンを追加する手順を記事にします。
f:id:bluebirdofoz:20190709193807j:plain
前回記事の続きです。
bluebirdofoz.hatenablog.com

サンプルスクリプト

確認のため、以下の gltf ファイルを出力するスクリプトを用意します。
・glbexport.py

# bpy インポート
import bpy

# GLBファイルの出力(デフォルト設定)
glb_filepath='C:\\WORK\\Models\\GLBExport'
bpy.ops.export_scene.glb(filepath=glb_filepath,
  export_copyright='', export_embed_buffers=False, export_embed_images=False, export_strip=False,
  export_indices='UNSIGNED_INT', export_force_indices=False, export_texcoords=True, export_normals=True,
  export_tangents=True, export_materials=True, export_colors=True, export_cameras=False,
  export_camera_infinite=False, export_selected=False, export_layers=True, export_extras=False,
  export_yup=True, export_apply=False,  export_animations=True, export_frame_range=True, export_frame_step=1,
  export_move_keyframes=True, export_force_sampling=False, export_current_frame=True, export_skins=True,
  export_bake_skins=False, export_morph=True, export_morph_normal=True, export_morph_tangent=True,
  export_lights=False, export_displacement=False, will_save_settings=False
)

bpy.ops.export_scene.glb を利用するには glTF-Exporter のアドオンが必要になります。
bluebirdofoz.hatenablog.com

アドオンのインストール

python ディレクトリの直下にコピーしたバージョン番号(2.79)のディレクトリを開きます。
scripts\addons ディレクトリ配下に glTF-Exporter アドオンの io_scene_gltf2 フォルダをコピーします。
glTF-Exporter アドオンの取得方法は前述の記事を参照してください。
f:id:bluebirdofoz:20190709193828j:plain

glTF-Exporter アドオンを利用するにはユーザ設定でアドオンを有効にする必要があります。
python スクリプト内でアドオンの有効化も記述可能です。
スクリプトに io_scene_gltf2 を有効化する一文を追加します。
・glbexport.py

# bpy インポート
import bpy

# ユーザ設定での gltf-Exporter アドオンの有効化
bpy.ops.wm.addon_enable(module='io_scene_gltf2')

# GLBファイルの出力(デフォルト設定)
glb_filepath='C:\\WORK\\Models\\GLBExport'
bpy.ops.export_scene.glb(filepath=glb_filepath,
  export_copyright='', export_embed_buffers=False, export_embed_images=False, export_strip=False,
  export_indices='UNSIGNED_INT', export_force_indices=False, export_texcoords=True, export_normals=True,
  export_tangents=True, export_materials=True, export_colors=True, export_cameras=False,
  export_camera_infinite=False, export_selected=False, export_layers=True, export_extras=False,
  export_yup=True, export_apply=False,  export_animations=True, export_frame_range=True, export_frame_step=1,
  export_move_keyframes=True, export_force_sampling=False, export_current_frame=True, export_skins=True,
  export_bake_skins=False, export_morph=True, export_morph_normal=True, export_morph_tangent=True,
  export_lights=False, export_displacement=False, will_save_settings=False
)

glTF-Exporter アドオンを取り込んだ Ptyon でスクリプトを実行します。
・(Pythonディレクトリ)\python.exe .\glbexport.py
f:id:bluebirdofoz:20190709193837j:plain

以下の通り、glb形式の3Dデータが出力されれば成功です。
f:id:bluebirdofoz:20190709193845j:plain