So I came up with this script as a solution to what I wanted...
Hopefully I'm not reinventing the wheel, the reason why I came up with this script is if you set resolution, haltspp or halttime quality and resolution settings from a python script, then the python script is executing the renderer. If calling blender from the command line, blender is setting the start and end frame and iterating through each frame to do the render. It seemed redundant at first to rewrite a loop to iterate through frames but I didn't see any way around it while maintaining a central location to specify render settings from a script. Also the script needed to force luxconsole mode as some of the blend files may have luxrender GUI mode saved in the settings.
So here's what I came up with so far:
- Code: Select all
# --------------------------------------------------------------------------
# Blender 2.5 LuxRender Console Headless Renderer Script
# Version: 0.1
# Author: ZukaZuka
#
# Usage: ./blender -b blendfile.blend -P lux_headless_render.py
#
# This script is designed to render frames from blend file with luxconsole from the command
# line. It allows you to alter parameters such as resolution and quality from one
# place so you can iterate through a series of blend files and have the same output
# settings applied to all of them.
#
# This script will write image output file name and render time to a logfile so you can easily
# keep track of render times for each file frame without having to grep through other
# logs to extract info and match render times to blend files.
# --------------------------------------------------------------------------
import bpy
import os.path
import time
import functools
log_file_name = 'lux_render_times.log'
# must have trailing slash on output path
output_path = './'
bpy.context.scene.render.resolution_x=1920
bpy.context.scene.render.resolution_y=1080
bpy.context.scene.render.resolution_percentage=50
# max number of frames to render, zero for all frames defined by start frame and end frame in blend file
max_frames=1
bpy.context.scene.luxrender_sampler.haltspp=5
bpy.context.scene.luxrender_sampler.halttime=0
# Force console mode
bpy.context.scene.luxrender_engine.binary_name='luxconsole'
# If render server has different path for luxconsole binary
#scene.luxrender_engine.install_path=
def logStatus(s):
print(s)
logfile.write(s + "\r\n")
def secondsToStr(t):
rediv = lambda ll,b : list(divmod(ll[0],b)) + ll[1:]
return "%d:%02d:%02d.%03d" % tuple(functools.reduce(rediv,[[t*1000,],1000,60,60]))
logfile = open(log_file_name, 'a')
logStatus("haltspp: %d halttime: %d" %(bpy.context.scene.luxrender_sampler.haltspp,bpy.context.scene.luxrender_sampler.halttime))
# File format example: JPEG or PNG
image_file_extension = "PNG"
bpy.context.scene.render.file_format=image_file_extension
frame_start = bpy.context.scene.frame_start
frame_end = bpy.context.scene.frame_end
blend_file = os.path.basename(bpy.context.blend_data.filepath)
filename_without_extension = os.path.splitext(blend_file)[0]
frames_rendered=0
for current_frame in range(frame_start,frame_end):
if max_frames==0 or frames_rendered<max_frames:
frames_rendered = frames_rendered+1
output_filename = '%s.%04d.%s' %(filename_without_extension,current_frame,str.lower(image_file_extension))
render_start = time.time()
render_result = bpy.ops.render.render(animation=False, write_still=False, layer="", scene="")
render_end = time.time()
print('Frame ' + str(current_frame) + ' rendered OK')
if 'FINISHED' in render_result:
full_output_image_path = output_path + output_filename
bpy.data.images['Render Result'].save_render(filepath=full_output_image_path)
status_text = '%s Time: %s' %(output_filename, secondsToStr(render_end-render_start))
logStatus(status_text)
print("Saved to: " + full_output_image_path)
logfile.close()
It works pretty good on blender 2.57b, lux 0.8rc3, ubuntu 10.04 32bit