blender_worker refactoring

This commit is contained in:
Brett Williams
2023-05-22 18:55:54 -05:00
parent c73b6d1da7
commit 074b802d45

View File

@@ -4,14 +4,39 @@ import re
from .render_worker import *
class Blender(BaseRenderEngine):
install_paths = ['/Applications/Blender.app/Contents/MacOS/Blender']
supported_extensions = ['.blend']
@classmethod
def version(cls):
version = None
try:
render_path = cls.renderer_path()
if render_path:
ver_out = subprocess.check_output([render_path, '-v'])
version = ver_out.decode('utf-8').splitlines()[0].replace('Blender', '').strip()
except Exception as e:
logging.error(f'Failed to get Blender version: {e}')
return version
@classmethod
def get_formats(cls):
format_string = cls.get_help().split('Format Options')[-1].split('Animation Playback Options')[0]
formats = re.findall(r"'([A-Z_0-9]+)'", format_string)
return formats
@classmethod
def full_report(cls):
return {'version': cls.version(),
'help_text': cls.get_help(),
'formats': cls.get_formats()}
class BlenderRenderWorker(BaseRenderWorker):
renderer = 'Blender'
render_engine = 'blender'
supported_extensions = ['.blend']
install_paths = ['/Applications/Blender.app/Contents/MacOS/Blender']
supported_export_formats = ['TGA', 'RAWTGA', 'JPEG', 'IRIS', 'IRIZ', 'AVIRAW', 'AVIJPEG', 'PNG', 'BMP', 'HDR',
'TIFF', 'OPEN_EXR', 'OPEN_EXR_MULTILAYER', 'MPEG', 'CINEON', 'DPX', 'DDS', 'JP2']
engine = Blender
def __init__(self, input_path, output_path, args=None):
super(BlenderRenderWorker, self).__init__(input_path=input_path, output_path=output_path,
@@ -34,21 +59,9 @@ class BlenderRenderWorker(BaseRenderWorker):
if self.render_all_frames else 1
self.current_frame = int(self.scene_info.get('frame_start', 0))
@classmethod
def version(cls):
version = None
try:
render_path = cls.renderer_path()
if render_path:
ver_out = subprocess.check_output([render_path, '-v'])
version = ver_out.decode('utf-8').splitlines()[0].replace('Blender', '').strip()
except Exception as e:
logging.error(f'Failed to get {cls.renderer} version: {e}')
return version
def generate_worker_subprocess(self):
cmd = [self.renderer_path()]
cmd = [self.engine.renderer_path()]
if self.args.get('background', True): # optionally run render not in background
cmd.append('-b')
cmd.append(self.input_path)
@@ -131,7 +144,7 @@ class BlenderRenderWorker(BaseRenderWorker):
def run_python_expression_in_blend(path, python_expression):
if os.path.exists(path):
try:
return subprocess.run([BlenderRenderWorker.renderer_path(), '-b', path, '--python-expr', python_expression],
return subprocess.run([Blender.renderer_path(), '-b', path, '--python-expr', python_expression],
capture_output=True)
except Exception as e:
logger.warning(f"Error running python expression in blender: {e}")
@@ -143,8 +156,7 @@ def run_python_expression_in_blend(path, python_expression):
def run_python_script_in_blend(path, python_path):
if os.path.exists(path) and os.path.exists(python_path):
try:
return subprocess.run([BlenderRenderWorker.renderer_path(), '-b', path, '--python', python_path],
capture_output=True)
return subprocess.run([Blender.renderer_path(), '-b', path, '--python', python_path], capture_output=True)
except Exception as e:
logger.warning(f"Error running python expression in blender: {e}")
pass
@@ -201,12 +213,14 @@ def get_scene_info(path):
if __name__ == '__main__':
print(Blender.full_report())
# x = pack_blender_files('/Users/brett/Blender Files/temple_animatic.blend')
# print(x)
logging.basicConfig(format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S', level=logging.DEBUG)
r = BlenderRenderWorker('/Users/brett/Blender Files/temple_animatic.blend', '/Users/brett/testing1234')
# r.engine = 'CYCLES'
r.start()
while r.is_running():
time.sleep(1)
# logging.basicConfig(format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S', level=logging.DEBUG)
# r = BlenderRenderWorker('/Users/brett/Blender Files/temple_animatic.blend', '/Users/brett/testing1234')
# # r.engine = 'CYCLES'
# r.start()
# while r.is_running():
# time.sleep(1)