import os import shutil import json import subprocess import tempfile class ViewRenderUtil: blender_path = r"C:\Program Files\Blender Foundation\Blender 4.0\blender.exe" @staticmethod def render_view(cam_pose, scene_path, script_path): with tempfile.TemporaryDirectory() as temp_dir: params = { "cam_pose": cam_pose.tolist(), "scene_path": scene_path } scene_info_path = os.path.join(scene_path, "scene_info.json") shutil.copy(scene_info_path, os.path.join(temp_dir, "scene_info.json")) params_data_path = os.path.join(temp_dir, "params.json") with open(params_data_path, 'w') as f: json.dump(params, f) import ipdb; ipdb.set_trace() result = subprocess.run([ ViewRenderUtil.blender_path, '-b', '-P', script_path, '--', temp_dir ], capture_output=True, text=True) print(result.stdout) print(result.stderr) path = os.path.join(temp_dir, "tmp") return None if __name__ == "__main__": import numpy as np idx = 0 cam_param_path = r"D:\Project\nbv_rec\data\google_scan-backpack_0288\camera_params\{}.json" cam_pose = json.load(open(cam_param_path.format(idx))) cam_pose = np.array(cam_pose["extrinsic"]) scene_path = r"D:\Project\nbv_rec\data\google_scan-backpack_0288" script_path = r"D:\Project\nbv_rec\nbv_rec_blender_render\data_renderer.py" ViewRenderUtil.render_view(cam_pose, scene_path, script_path)