先日Pythonでレンダリング設定を動的に設定することを実行しました。
今回はこの設定をプリセットとして出力し、再利用可能とするための出力部を作成します。
〇環境
・Blender4.1
・Windows11PC
〇設定をjsonで出力する
今回は任意のパスにjsonとして出力するコードを作成しました。
import bpy
import json
# 現在のレンダリング設定を取得
render_settings = {
"engine": bpy.context.scene.render.engine,
"device": bpy.context.scene.cycles.device,
"compute_device_type": bpy.context.preferences.addons['cycles'].preferences.compute_device_type,
"samples": bpy.context.scene.cycles.samples,
"preview_samples": bpy.context.scene.cycles.preview_samples,
}
# ファイルに保存
file_path = "C:/Users/seiri/Documents/Development/BlenderProject\RenderSettings/render_settings.json"
with open(file_path, 'w') as f:
json.dump(render_settings, f, indent=4)
print(f"レンダリング設定を {file_path} に保存しました。")
上記コードを実行すると指定したパスに以下のようなjsonファイルが作成されます。
{
"engine": "BLENDER_EEVEE",
"device": "CPU",
"compute_device_type": "OPTIX",
"samples": 4096,
"preview_samples": 1024
}
これはPythonでレンダリング設定を行う際の変数をKey,Valueの形で出力しています。
この情報を次回使用してプリセットとして使用できるようにしていきます。
本日は以上です。