forked from prman-pixar/RenderManForBlender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspool.py
193 lines (170 loc) · 8.84 KB
/
spool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import bpy
import os
import time
from .util import user_path
def end_block(f, indent_level):
f.write("%s}\n" % ('\t' * indent_level))
def write_parent_task_line(f, title, serial_subtasks, indent_level):
f.write("%sTask {%s} -serialsubtasks %d -subtasks {\n" %
('\t' * indent_level, title, int(serial_subtasks)))
def write_cmd_task_line(f, title, cmds, indent_level):
f.write("%sTask {%s} -cmds {\n" % ('\t' * indent_level, title))
for key, cmd in cmds:
f.write("%sRemoteCmd -service {%s} {%s}\n" % ('\t' * (indent_level + 1),
key, " ".join(cmd)))
f.write("%s}\n" % ('\t' * indent_level))
def txmake_task(f, title, in_name, out_name, options, indent_level):
cmd = ['txmake'] + options + ['-newer'] + [in_name, out_name]
write_cmd_task_line(f, title, [('PixarRender', cmd)], indent_level)
def quote(filename):
return '"%s"' % filename
def spool_render(rman_version_short, rib_files, denoise_files, denoise_aov_files, frame_begin, frame_end=None, denoise=None, context=None,
job_texture_cmds=[], frame_texture_cmds={}, rpass=None):
prefs = bpy.context.user_preferences.addons[__package__].preferences
out_dir = prefs.env_vars.out
cdir = user_path(out_dir)
scene = context.scene
rm = scene.renderman
alf_file = os.path.join(cdir, 'spool_%s.alf' %
time.strftime("%m%d%y%H%M%S"))
per_frame_denoise = denoise == 'frame'
crossframe_denoise = denoise == 'crossframe'
# open file
f = open(alf_file, 'w')
# write header
f.write('##AlfredToDo 3.0\n')
# job line
job_title = 'untitled' if not bpy.data.filepath else \
os.path.splitext(os.path.split(bpy.data.filepath)[1])[0]
job_title += " frames %d-%d" % (frame_begin, frame_end) if frame_end \
else " frame %d" % frame_begin
if per_frame_denoise:
job_title += ' per-frame denoise'
elif crossframe_denoise:
job_title += ' crossframe_denoise'
job_params = {
'title': job_title,
'serialsubtasks': 1,
'envkey': 'prman-%s' % rman_version_short,
'comment': 'Created by RenderMan for Blender'
}
job_str = 'Job'
for key, val in job_params.items():
if key == 'serialsubtasks':
job_str += " -%s %s" % (key, str(val))
else:
job_str += " -%s {%s}" % (key, str(val))
f.write(job_str + ' -subtasks {' + '\n')
# collect textures find frame specific and job specific
if job_texture_cmds:
write_parent_task_line(f, 'Job Textures', False, 1)
# do job tx makes
for in_name, out_name, options in job_texture_cmds:
in_name = bpy.path.abspath(in_name)
out_name = os.path.join(rpass.paths['texture_output'], out_name)
txmake_task(f, "TxMake %s" % os.path.split(in_name)
[-1], quote(in_name), quote(out_name), options, 2)
if job_texture_cmds:
end_block(f, 1)
write_parent_task_line(f, 'Frame Renders', False, 1)
# for frame
if frame_end is None:
frame_end = frame_begin
for frame_num in range(frame_begin, frame_end + 1):
if frame_num in frame_texture_cmds or denoise:
write_parent_task_line(f, 'Frame %d' % frame_num, True, 2)
# do frame specic txmake
if frame_num in frame_texture_cmds:
write_parent_task_line(f, 'Frame %d textures' %
frame_num, False, 3)
for in_name, out_name, options in frame_texture_cmds[frame_num]:
in_name = bpy.path.abspath(in_name)
out_name = os.path.join(
rpass.paths['texture_output'], out_name)
txmake_task(f, "TxMake %s" % os.path.split(in_name)
[-1], quote(in_name), quote(out_name), options, 4)
end_block(f, 3)
# render frame
cmd_str = ['prman', '-Progress', '-cwd', quote(cdir), '-t:%d' %
rm.threads, quote(rib_files[frame_num - frame_begin])]
if rm.enable_checkpoint:
if rm.render_limit == 0:
cmd_str.insert(5, '-checkpoint %d%s' %
(rm.checkpoint_interval, rm.checkpoint_type))
else:
cmd_str.insert(5, '-checkpoint %d%s,%d%s' % (
rm.checkpoint_interval, rm.checkpoint_type, rm.render_limit, rm.checkpoint_type))
if rm.recover:
cmd_str.insert(5, '-recover 1')
if rm.custom_cmd != '':
cmd_str.insert(5, rm.custom_cmd)
write_cmd_task_line(f, 'Render frame %d' % frame_num, [('PixarRender',
cmd_str)], 3)
# denoise frame
if per_frame_denoise:
denoise_options = []
if rm.denoise_cmd != '':
denoise_options.append(rm.denoise_cmd)
if rm.spool_denoise_aov and denoise_aov_files != []:
denoise_options.insert(0, '--filtervariance 1')
cmd_str = ['denoise'] + denoise_options + [quote(denoise_files[
frame_num - frame_begin][0])] + [" ".join([quote(file) for file in
denoise_aov_files[frame_num - frame_begin]])]
else:
if rm.denoise_gpu:
denoise_options.append('--override gpuIndex 0 --')
cmd_str = ['denoise'] + denoise_options + \
[quote(denoise_files[
frame_num - frame_begin][0])]
write_cmd_task_line(f, 'Denoise frame %d' % frame_num,
[('PixarRender', cmd_str)], 3)
elif crossframe_denoise:
denoise_options = ['--crossframe -v variance', '-F 1', '-L 1']
if rm.spool_denoise_aov and denoise_aov_files != []:
denoise_options.append('--filtervariance 1')
if rm.denoise_cmd != '':
denoise_options.append(rm.denoise_cmd)
if rm.denoise_gpu and not rm.spool_denoise_aov:
denoise_options.append('--override gpuIndex 0 --')
if frame_num - frame_begin < 1:
pass
elif frame_num - frame_begin == 1:
denoise_options.remove('-F 1')
cmd_str = ['denoise'] + denoise_options + [quote(f[0])
for f in denoise_files[0:2]]
if rm.spool_denoise_aov and denoise_aov_files != []:
files = [quote(item) for sublist in denoise_aov_files[0:2]
for item in sublist]
cmd_str = ['denoise'] + denoise_options + [quote(f[0])
for f in denoise_files[0:2]] + files
write_cmd_task_line(f, 'Denoise frame %d' % (frame_num - 1),
[('PixarRender', cmd_str)], 3)
else:
cmd_str = ['denoise'] + denoise_options + [quote(f[0])
for f in denoise_files[frame_num - frame_begin - 2: frame_num - frame_begin + 1]]
if rm.spool_denoise_aov and denoise_aov_files != []:
files = [quote(item) for sublist in denoise_aov_files[
frame_num - frame_begin - 2: frame_num - frame_begin + 1] for item in sublist]
cmd_str = ['denoise'] + denoise_options + [quote(f[0])
for f in denoise_files[frame_num - frame_begin - 2: frame_num - frame_begin + 1]] + files
write_cmd_task_line(f, 'Denoise frame %d' % (frame_num - 1),
[('PixarRender', cmd_str)], 3)
if frame_num == frame_end:
denoise_options.remove('-L 1')
cmd_str = ['denoise'] + denoise_options + [quote(f[0])
for f in denoise_files[frame_num - frame_begin - 1: frame_num - frame_begin + 1]]
if rm.spool_denoise_aov and denoise_aov_files != []:
files = [quote(item) for sublist in denoise_aov_files[
frame_num - frame_begin - 1: frame_num - frame_begin + 1] for item in sublist]
cmd_str = ['denoise'] + denoise_options + [quote(f[0])
for f in denoise_files[frame_num - frame_begin - 1: frame_num - frame_begin + 1]] + files
write_cmd_task_line(f, 'Denoise frame %d' % frame_num,
[('PixarRender', cmd_str)], 3)
# if len(frame_texture_cmds) or per_frame_denoise:
if denoise or frame_num in frame_texture_cmds:
end_block(f, 2)
end_block(f, 1)
# end job
f.write("}\n")
f.close()
return alf_file