mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 16:58:12 +00:00
Consolidate Blender methods
This commit is contained in:
@@ -33,6 +33,30 @@ class Blender(BaseRenderEngine):
|
|||||||
'help_text': cls.get_help(),
|
'help_text': cls.get_help(),
|
||||||
'formats': cls.get_formats()}
|
'formats': cls.get_formats()}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run_python_expression(cls, path, python_expression):
|
||||||
|
if os.path.exists(path):
|
||||||
|
try:
|
||||||
|
return subprocess.run([cls.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}")
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run_python_script(cls, path, python_path):
|
||||||
|
if os.path.exists(path) and os.path.exists(python_path):
|
||||||
|
try:
|
||||||
|
return subprocess.run([cls.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
|
||||||
|
else:
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
|
||||||
class BlenderRenderWorker(BaseRenderWorker):
|
class BlenderRenderWorker(BaseRenderWorker):
|
||||||
|
|
||||||
@@ -141,29 +165,6 @@ class BlenderRenderWorker(BaseRenderWorker):
|
|||||||
return max(total_percent, 0)
|
return max(total_percent, 0)
|
||||||
|
|
||||||
|
|
||||||
def run_python_expression_in_blend(path, python_expression):
|
|
||||||
if os.path.exists(path):
|
|
||||||
try:
|
|
||||||
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}")
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise FileNotFoundError
|
|
||||||
|
|
||||||
|
|
||||||
def run_python_script_in_blend(path, python_path):
|
|
||||||
if os.path.exists(path) and os.path.exists(python_path):
|
|
||||||
try:
|
|
||||||
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
|
|
||||||
else:
|
|
||||||
raise FileNotFoundError
|
|
||||||
|
|
||||||
|
|
||||||
def pack_blender_files(path):
|
def pack_blender_files(path):
|
||||||
# Credit to L0Lock for pack script - https://blender.stackexchange.com/a/243935
|
# Credit to L0Lock for pack script - https://blender.stackexchange.com/a/243935
|
||||||
pack_script = "import bpy\n" \
|
pack_script = "import bpy\n" \
|
||||||
@@ -173,7 +174,7 @@ def pack_blender_files(path):
|
|||||||
"bpy.ops.wm.save_as_mainfile(filepath=myPath[:-6]+'_packed'+myPath[-6:])"
|
"bpy.ops.wm.save_as_mainfile(filepath=myPath[:-6]+'_packed'+myPath[-6:])"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results = run_python_expression_in_blend(path, pack_script)
|
results = Blender.run_python_script(path, pack_script)
|
||||||
|
|
||||||
result_text = results.stdout.decode()
|
result_text = results.stdout.decode()
|
||||||
dir_name = os.path.dirname(path)
|
dir_name = os.path.dirname(path)
|
||||||
@@ -198,7 +199,7 @@ def get_scene_info(path):
|
|||||||
|
|
||||||
scene_info = None
|
scene_info = None
|
||||||
try:
|
try:
|
||||||
results = run_python_script_in_blend(path, os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
results = Blender.run_python_script(path, os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||||
'scripts', 'get_blender_info.py'))
|
'scripts', 'get_blender_info.py'))
|
||||||
result_text = results.stdout.decode()
|
result_text = results.stdout.decode()
|
||||||
for line in result_text.splitlines():
|
for line in result_text.splitlines():
|
||||||
|
|||||||
Reference in New Issue
Block a user