Blender GPU / CPU Render (#81)

* Add script to get GPU information from Blender

* Change run_python_script to allow it to run without a project file

* Simplify run_python_script code

* Fix mistake

* Add system_info to engine classes and api_server. /api/renderer_info now supports standard and full response modes.

* Get full renderer_info response for add job UI

* Enable setting specific Blender render_device using args

* Add Blender render device options to UI
This commit is contained in:
2024-08-03 18:26:56 -05:00
committed by GitHub
parent 9bc490acae
commit ef4fc0e42e
8 changed files with 107 additions and 42 deletions

View File

@@ -14,11 +14,6 @@ class BlenderRenderWorker(BaseRenderWorker):
def __init__(self, input_path, output_path, engine_path, args=None, parent=None, name=None):
super(BlenderRenderWorker, self).__init__(input_path=input_path, output_path=output_path, engine_path=engine_path, args=args, parent=parent, name=name)
# Args
self.blender_engine = self.args.get('engine', 'BLENDER_EEVEE').upper()
self.export_format = self.args.get('export_format', None) or 'JPEG'
self.camera = self.args.get('camera', None)
# Stats
self.__frame_percent_complete = 0.0
@@ -36,16 +31,39 @@ class BlenderRenderWorker(BaseRenderWorker):
cmd.append('-b')
cmd.append(self.input_path)
# Python expressions
# Start Python expressions - # todo: investigate splitting into separate 'setup' script
cmd.append('--python-expr')
python_exp = 'import bpy; bpy.context.scene.render.use_overwrite = False;'
if self.camera:
python_exp = python_exp + f"bpy.context.scene.camera = bpy.data.objects['{self.camera}'];"
# insert any other python exp checks here
# Setup Custom Camera
custom_camera = self.args.get('camera', None)
if custom_camera:
python_exp = python_exp + f"bpy.context.scene.camera = bpy.data.objects['{custom_camera}'];"
# Set Render Device (gpu/cpu/any)
blender_engine = self.args.get('engine', 'BLENDER_EEVEE').upper()
if blender_engine == 'CYCLES':
render_device = self.args.get('render_device', 'any').lower()
if render_device not in {'any', 'gpu', 'cpu'}:
raise AttributeError(f"Invalid Cycles render device: {render_device}")
use_gpu = render_device in {'any', 'gpu'}
use_cpu = render_device in {'any', 'cpu'}
python_exp = python_exp + ("exec(\"for device in bpy.context.preferences.addons["
f"'cycles'].preferences.devices: device.use = {use_cpu} if device.type == 'CPU'"
f" else {use_gpu}\")")
# -- insert any other python exp checks / generators here --
# End Python expressions here
cmd.append(python_exp)
# Export format
export_format = self.args.get('export_format', None) or 'JPEG'
path_without_ext = os.path.splitext(self.output_path)[0] + "_"
cmd.extend(['-E', self.blender_engine, '-o', path_without_ext, '-F', self.export_format])
cmd.extend(['-E', blender_engine, '-o', path_without_ext, '-F', export_format])
# set frame range
cmd.extend(['-s', self.start_frame, '-e', self.end_frame, '-a'])