・参考
Blender 2.8 で Python スクリプトを実行してみる
・Sceneの抽出(どちらも同じ)
bpy.context.scene
bpy.data.scenes['Scene']
・Objectsの抽出(どちらも同じ)
bpy.context.scene.objects
bpy.data.objects
・Object種類の抽出
for o in bpy.data.objects:
print(o.type)
python - How to get the Class of selected object in Blender 2.8? - Blender Stack Exchange
・メッシュの抽出
for mesh in bpy.data.meshes:Blender PythonのMeshデータアクセスのチートシート - Qiita
・マテリアルの抽出
for material in bpy.data.materials: # 全マテリアル
for o in bpy.data.objects:
if o.type == 'MESH':
for m in o.material_slots: # そのメッシュに使われているマテリアル
・モード切替
for o in bpy.data.objects:
bpy.context.view_layer.objects.active = o
bpy.ops.object.mode_set(mode = 'EDIT') # 戻すときはmode = 'OBJECT'
・レンダリング画像のファイル出力(1枚)
bpy.ops.render.render() # opsはOperator
bpy.data.images['Render Result'].save_render('C:/kaggle/render.png')
・レンダリング画像のファイル出力(1枚)
scene = bpy.context.scene
scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = 'C:/kaggle/render'
bpy.ops.render.render(write_still=True)
・レンダリングの設定
scene = bpy.context.scene
scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = 'C:/kaggle/render'
scene.render.resolution_x = 800 # 解像度
scene.render.resolution_percentage = 100 # プレビュー解像度
scene.render.use_persistent_data = True # 再レンダリングの効率化
scene.render.film_transparent = True # 背景の透過
scene.render.dither_intensity = 0.0 # ディザの強さ
・オブジェクトの位置の指定
cube = bpy.data.objects['Cube']
cube.location = (0, 0, 0)
・カメラの姿勢の指定
def look_at(cam, obj):
# カメラからオブジェクトへのベクトルを算出
direction = obj.matrix_world.to_translation() - cam.matrix_world.to_translation()
# カメラの視線方向(-Z)がそのベクトルの向きとなる姿勢をカメラの姿勢とする
cam.rotation_quaternion = direction.to_track_quat('-Z', 'Y')
python - Pointing the camera in a particular direction programmatically - Blender Stack Exchange
Blenderでワールドマトリクスからオブジェクトの軸方向を取得 - Blenderとか3DCGとか
Blenderのカメラの向きを操作しよう | Rafkaの実験室
・キーフレームの設定
Blender pythonでノードにキーフレームを追加 | ぬの部屋(仮)
・アニメーション確認
for obj in bpy.data.objects:
fcurves = obj.animation_data.action.fcurves
for fc in fcurves:
for kp in fc.keyframe_points:
data_type = fc.data_path # location, rotation, scaleなど
frame = int(kp.co[0]) # フレーム番号
axis = fc_array_index # x, y, zなど
value = kp.co[1]
・ボーン情報の取得①
armature = bpy.data.objects['Armature']
for bone in armature.data.bones:
print(bone.name)
for bone in armature.pose.bones:
print(bone.location)
print(bone.rotation_quaternion)
print(bone.rotation_euler)
・ボーン情報の取得②
Blender2.8で利用可能なpythonスクリプトを作る その16(ボーンの操作、ポーズの適用) - MRが楽しい
・最初と最後のキーフレーム番号を取得
Blender でスクリプトを使ってレンダリング - tkaaad97’s diary
frame_start = int(armature.animation_data.action.frame_range[0])
frame_end = int(armature.animation_data.action.frame_range[1])