MRが楽しい

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

Blenderで利用可能なpythonスクリプトを作る その22(シェーディング設定の変更と環境照明の設定)

本日は Blender の技術調査枠です。
Blenderで利用可能なpythonスクリプトを作ります。
bluebirdofoz.hatenablog.com

シェーディング設定の変更

全ての3Dビューのシェーディング設定を「マテリアル」に設定します。
・shading_change.py

# bpyインポート
import bpy

# 全ての3Dビューのシェーディングを「マテリアル」に設定する
# 引数
# 戻り値
def shading_change_material():
  # 全てのスクリーンを走査する
  for area in bpy.context.screen.areas:
    # エリアタイプが3Dビューであるか
    if area.type == 'VIEW_3D':
      # エリア内の各スペースを走査する
      for space in area.spaces:
        # スペースが3Dビューの表示領域であるか
        if space.type == 'VIEW_3D':
          # シェーディングを「マテリアル」に設定する
          space.viewport_shade='MATERIAL'
  return


# 関数の実行例
shading_change_material()

f:id:bluebirdofoz:20190714155142j:plain

環境照明の設定

ワールドの環境証明を有効化します。
・lighting_environment.py

# bpyインポート
import bpy

# 環境照明を設定する
# 引数
# 戻り値
def lighting_add_environment():
  # blender内のワールドを取得する
  env_world=bpy.context.scene.world
  # ワールドの環境照明を有効化する
  env_world.light_settings.use_environment_light=True
  return


# 関数の実行例
lighting_add_environment()

f:id:bluebirdofoz:20190714155155j:plain