export background
This commit is contained in:
+56
-1
@@ -2,9 +2,19 @@
|
||||
"""
|
||||
Generic Blender functions
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import json
|
||||
from textwrap import dedent
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
def abspath(path):
|
||||
path = os.path.abspath(bpy.path.abspath(path))
|
||||
return Path(path)
|
||||
|
||||
def get_scene_settings():
|
||||
return bpy.context.scene.vsetb_settings
|
||||
|
||||
@@ -17,7 +27,27 @@ def get_strip_settings():
|
||||
|
||||
return strip.vsetb_strip_settings
|
||||
|
||||
def get_bl_cmd(blender=None, background=False, focus=True, blendfile=None, script=None, **kargs):
|
||||
def norm_arg(arg_name):
|
||||
return "--" + arg_name.replace(' ', '-')
|
||||
|
||||
def norm_value(value):
|
||||
if isinstance(value, (tuple, list)):
|
||||
values = []
|
||||
for v in value:
|
||||
if not isinstance(v, str):
|
||||
v = json.dumps(v)
|
||||
values.append(v)
|
||||
|
||||
return values
|
||||
|
||||
if isinstance(value, Path):
|
||||
return str(value)
|
||||
|
||||
if not isinstance(value, str):
|
||||
value = json.dumps(value)
|
||||
return value
|
||||
|
||||
def get_bl_cmd(blender=None, background=False, focus=True, blendfile=None, script=None, output=None, **kargs):
|
||||
cmd = [str(blender)] if blender else [bpy.app.binary_path]
|
||||
|
||||
if background:
|
||||
@@ -31,6 +61,9 @@ def get_bl_cmd(blender=None, background=False, focus=True, blendfile=None, scrip
|
||||
|
||||
if blendfile:
|
||||
cmd += [str(blendfile)]
|
||||
|
||||
if output:
|
||||
cmd += ['-o', str(output)]
|
||||
|
||||
if script:
|
||||
cmd += ['--python', str(script)]
|
||||
@@ -49,6 +82,28 @@ def get_bl_cmd(blender=None, background=False, focus=True, blendfile=None, scrip
|
||||
|
||||
return cmd
|
||||
|
||||
|
||||
def background_render(output=None):
|
||||
#bpy.context.scene.render.filepath = '{output}'
|
||||
script_code = dedent(f"""
|
||||
import bpy
|
||||
bpy.context.scene.render.filepath = '{str(output)}'
|
||||
bpy.ops.render.render(animation=True)
|
||||
bpy.ops.wm.quit_blender()
|
||||
""")
|
||||
|
||||
tmp_blend = Path(bpy.app.tempdir) / Path(bpy.data.filepath).name
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(tmp_blend))
|
||||
|
||||
script_path = Path(bpy.app.tempdir) / 'render_blender_background.py'
|
||||
script_path.write_text(script_code)
|
||||
|
||||
cmd = get_bl_cmd(blendfile=tmp_blend, script=script_path, background=True)
|
||||
|
||||
print('Background Render...')
|
||||
print(cmd)
|
||||
subprocess.Popen(cmd)
|
||||
|
||||
def get_addon_prefs():
|
||||
addon_name = __package__.split('.')[0]
|
||||
return bpy.context.preferences.addons[addon_name].preferences
|
||||
|
||||
Reference in New Issue
Block a user