Repository navigation
Expand file tree
/
Copy pathproperties.py
More file actions
493 lines (457 loc) · 15.6 KB
/
Copy pathproperties.py
File metadata and controls
493 lines (457 loc) · 15.6 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This file is part of the Blender addon "Renderlayer Manager".
#
# The addon "Renderlayer Manager" is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation version 3 of the License or
# any later version.
#
# The addon "Renderlayer Manager" is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the addon. If not, see <http://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
import os
from . import utils
def switch_viewlayer(self, context):
scn = context.scene
idx = scn.rlm.active_renderlayer_index
view_layers = scn.view_layers
active_renderlayer = view_layers[idx].name
context.window.view_layer = view_layers[active_renderlayer]
def update_paths(self, context):
if context.scene.rlm.auto_update_paths:
utils.set_output_paths(context, selection=False)
def update_denoiser_settings(self, context):
view_layer = context.view_layer
if hasattr(view_layer, 'cycles'):
if self.denoiser_type != 'NONE':
view_layer.cycles.use_denoising = True
if hasattr(view_layer.cycles, 'denoiser'):
if self.denoiser_type == 'OPTIX':
view_layer.cycles.denoiser = 'OPTIX'
elif self.denoiser_type == 'OPENIMAGEDENOISE':
view_layer.cycles.denoiser = 'OPENIMAGEDENOISE'
elif self.denoiser_type == 'BLENDER':
view_layer.cycles.denoiser = 'NONE'
else:
view_layer.cycles.use_denoising = False
def get_color_mode_items(self, context):
items = (
('BW', 'BW', ''),
('RGB', 'RGB', ''),
('RGBA', 'RGBA', '')
)
if self.file_format in ['BMP', 'JPEG', 'CINEON', 'HDR']:
items = (
('BW', 'BW', ''),
('RGB', 'RGB', '')
)
return items
def get_color_depth_items(self, context):
items = (
('8', '8', ''),
('10', '10', ''),
('12', '12', ''),
('16', '16', ''),
('32', '32', ''),
)
if self.file_format in ['PNG', 'TIFF']:
items = (
('8', '8', ''),
('16', '16', ''),
)
if self.file_format in ['JPEG2000']:
items = (
('8', '8', ''),
('12', '12', ''),
('16', '16', ''),
)
if self.file_format in ['DPX']:
items = (
('8', '8', ''),
('10', '10', ''),
('12', '12', ''),
('16', '16', ''),
)
if self.file_format in ['OPEN_EXR', 'OPEN_EXR_MULTILAYER']:
items = (
('16', 'Float (Half)', ''),
('32', 'Float (Full)', ''),
)
return items
def get_color_space_items(self, context):
items = [('---', '---', '')]
img_settings = context.scene.render.image_settings
enums = img_settings.linear_colorspace_settings.bl_rna.properties['name'].enum_items
for item in enums:
items.append((item.identifier, item.name, item.description))
return items
def get_display_device_items(self, context):
items = [('---', '---', '')]
displays = utils.get_ocio_settings()['displays']
for item in displays:
items.append((item, item, ''))
return items
def get_view_transform_items(self, context):
items = [('---', '---', '')]
views = utils.get_ocio_settings()['views']
for item in views:
items.append((item, item, ''))
return items
def update_lightgroup_name(self, context):
view_layer = context.view_layer
try:
utils.set_cycles_lightgroups_from_settings(view_layer)
except Exception:
pass
def update_image_settings_file_format(self, context):
if self.file_format in ['BMP', 'JPEG', 'CINEON', 'HDR']:
self.color_mode = 'RGB'
else:
self.color_mode = 'RGBA'
self.color_depth = '16'
if self.file_format in ['OPEN_EXR', 'OPEN_EXR_MULTILAYER']:
self.color_depth = '32'
class RenderlayerManagerProperties(bpy.types.PropertyGroup):
active_renderlayer_index: bpy.props.IntProperty(
name='Active Renderlayer',
description='',
default=0,
update=switch_viewlayer,
)
output_dir: bpy.props.StringProperty(
name='Output Directory',
description='',
default=r'\tmp/',
subtype='DIR_PATH',
update=update_paths,
)
output_name: bpy.props.StringProperty(
name='Output Name',
description='',
default=bpy.context.preferences.addons[__package__].preferences.output_name,
subtype='FILE_NAME',
update=update_paths,
)
auto_update_paths: bpy.props.BoolProperty(
name='Auto-Update Paths',
description='Automatically update all file output paths',
default=True,
update=update_paths,
)
use_exr_for_data_pass: bpy.props.BoolProperty(
name='OpenEXR Data Passes',
description='Use EXR format with high color depth for data passes',
default=False,
)
use_cryptomatte_multilayer_exr: bpy.props.BoolProperty(
name='Cryptomatte Multilayer EXR',
description='Use a EXR-Multilayer output for all cryptomatte passes',
default=False,
)
version: bpy.props.IntProperty(
name='Version Number',
description='',
default=1,
min=1,
max=99,
update=update_paths,
)
write_alpha: bpy.props.BoolProperty(
name="Write Alpha",
description="Enable alpha pass file output",
default=False,
)
write_noisy_image: bpy.props.BoolProperty(
name="Write Noisy Image",
description="Enable noisy image pass file output",
default=False,
)
active_pass_idx: bpy.props.IntProperty(
default=0,
)
include_all_scenes: bpy.props.BoolProperty(
name='Include All Scenes',
default=False,
description='Add renderlayer nodes of all scenes'
)
class ImageFormatSettings(bpy.types.PropertyGroup):
file_format: bpy.props.EnumProperty(
name='File Format',
description='File format to save the rendered images as',
items=(
('---', '---', '', '', 0),
('BMP', 'BMP', '', 'IMAGE_DATA', 1),
('IRIS', 'IRIS', '', 'IMAGE_DATA', 2),
('PNG', 'PNG', '', 'IMAGE_DATA', 3),
('JPEG', 'JPEG', '', 'IMAGE_DATA', 4),
('JPEG2000', 'JPEG2000', '', 'IMAGE_DATA', 5),
('TARGA', 'TARGA', '', 'IMAGE_DATA', 6),
('TARGA_RAW', 'TARGA_RAW', '', 'IMAGE_DATA', 7),
('CINEON', 'CINEON', '', 'IMAGE_DATA', 8),
('DPX', 'DPX', '', 'IMAGE_DATA', 9),
('OPEN_EXR_MULTILAYER', 'OPEN_EXR_MULTILAYER', '', 'IMAGE_DATA', 10),
('OPEN_EXR', 'OPEN_EXR', '', 'IMAGE_DATA', 11),
('HDR', 'HDR', '', 'IMAGE_DATA', 12),
('TIFF', 'TIFF', '', 'IMAGE_DATA', 13),
('WEBP', 'WEBP', '', 'IMAGE_DATA', 14),
),
default='---',
update=update_image_settings_file_format,
)
color_mode: bpy.props.EnumProperty(
name='Color Mode',
description='Choose BW for saving grayscale images, RGB for saving red, green and blue channels, and RGBA for saving red, green, blue and alpha channels',
items=get_color_mode_items,
)
color_depth: bpy.props.EnumProperty(
name='Color Depth',
description='Bit depth per channel',
items=get_color_depth_items,
)
display_device: bpy.props.EnumProperty(
name='Display Device',
description='Display device name',
items=get_display_device_items,
)
compression: bpy.props.IntProperty(
name="Compression",
description='Amount of time to determine best compression: 0 = no compression with fast file output, 100 = maximum lossless compression with slow file output',
min=0,
max=100,
default=15,
)
exr_codec: bpy.props.EnumProperty(
name='Codec',
description='Codec settings for OpenEXR',
items=(
('NONE', 'None', ''),
('PXR24', 'Pxr24 (lossy)', ''),
('ZIP', 'ZIP (lossless)', ''),
('PIZ', 'PIZ (lossless)', ''),
('RLE', 'RLE (lossless)', ''),
('ZIPS', 'ZIPS (lossless)', ''),
('B44', 'B44 (lossy)', ''),
('B44A', 'B44A (lossy)', ''),
('DWAA', 'DWAA (lossy)', ''),
('DWAB', 'DWAB (lossy)', ''),
),
default='ZIP',
)
jpeg2k_codec: bpy.props.EnumProperty(
name='Codec',
description='Codec settings for Jpeg2000',
items=(
('JP2', 'JP2', ''),
('J2K', 'J2K', ''),
),
default='JP2',
)
quality: bpy.props.IntProperty(
name="Quality",
description='Quality for image formats that support lossy compression',
min=0,
max=100,
default=90,
)
tiff_codec: bpy.props.EnumProperty(
name='Compression',
description='Compression mode for TIFF',
items=(
('NONE', 'None', ''),
('DEFLATE', 'Deflate', ''),
('LZW', 'LZW', ''),
('PACKBITS', 'Pack Bits', ''),
),
default='DEFLATE',
)
use_cineon_log: bpy.props.BoolProperty(
name='Log',
description='Convert to logarithmic color space',
default=False,
)
use_jpeg2k_cinema_48: bpy.props.BoolProperty(
name='Cinema (48)',
description='Use Openjpeg Cinema Preset (48fps)',
default=False,
)
use_jpeg2k_cinema_preset: bpy.props.BoolProperty(
name='Cinema',
description='Use Openjpeg Cinema Preset',
default=False,
)
use_jpeg2k_ycc: bpy.props.BoolProperty(
name='YCC',
description='Save luminance-chrominance-chrominance channels instead of RGB colors',
default=False,
)
use_preview: bpy.props.BoolProperty(
name='Preview',
description='When rendering animations, save JPG preview images in same directory',
default=False,
)
use_zbuffer: bpy.props.BoolProperty(
name='Z Buffer',
description='Save the z-depth per pixel (32-bit unsigned integer z-buffer)',
default=False,
)
color_space: bpy.props.EnumProperty(
name='Color Space',
description='Color space in the image file, to convert to and from when saving and loading the image',
items=get_color_space_items,
)
view_transform: bpy.props.EnumProperty(
name='View Transform',
description='View used when converting image to a display space',
items=get_view_transform_items,
)
save_as_render: bpy.props.BoolProperty(
name='Save As Render',
default=True,
)
class RenderlayerManagerPasses(bpy.types.PropertyGroup):
custom_name: bpy.props.StringProperty(
name='Custom Name',
default=bpy.context.preferences.addons[__package__].preferences.output_passes['Image'].custom_name,
)
selected: bpy.props.BoolProperty(
name='Selected',
default=False,
)
image_settings: bpy.props.PointerProperty(
type=ImageFormatSettings,
)
denoise: bpy.props.BoolProperty(
name='Denoise',
default=True,
)
class RenderlayerManagerLightgroup(bpy.types.PropertyGroup):
name: bpy.props.StringProperty(
name='Lightgroup Name',
default='',
update=update_lightgroup_name,
)
denoise: bpy.props.BoolProperty(
name='Denoise',
default=True,
)
file_format: bpy.props.EnumProperty(
name='File Format',
description='File format to save the rendered images as',
items=(
('---', '---', ''),
('BMP', 'BMP', ''),
('IRIS', 'IRIS', ''),
('PNG', 'PNG', ''),
('JPEG', 'JPEG', ''),
('JPEG2000', 'JPEG2000', ''),
('TARGA', 'TARGA', ''),
('TARGA_RAW', 'TARGA_RAW', ''),
('CINEON', 'CINEON', ''),
('DPX', 'DPX', ''),
('OPEN_EXR_MULTILAYER', 'OPEN_EXR_MULTILAYER', ''),
('OPEN_EXR', 'OPEN_EXR', ''),
('HDR', 'HDR', ''),
('TIFF', 'TIFF', ''),
('WEBP', 'WEBP', ''),
),
default='---',
)
classes = (
ImageFormatSettings,
RenderlayerManagerPasses,
RenderlayerManagerLightgroup,
RenderlayerManagerProperties,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.rlm = bpy.props.PointerProperty(
type=RenderlayerManagerProperties,
)
bpy.types.ViewLayer.image_settings = bpy.props.PointerProperty(
type=ImageFormatSettings,
)
bpy.types.ViewLayer.color = bpy.props.FloatVectorProperty(
name='Renderlayer Color',
subtype='COLOR_GAMMA',
description='Preview color',
default=(0.36, 0.36, 0.36),
min=0,
max=1,
)
bpy.types.ViewLayer.composite = bpy.props.BoolProperty(
name='Enable Composite',
description='Enable renderlayer for compositing',
default=False,
)
bpy.types.ViewLayer.override_file_format = bpy.props.BoolProperty(
name='Override File Format',
description='Override file format for active renderlayer',
default=False,
)
bpy.types.ViewLayer.passes = bpy.props.CollectionProperty(
type=RenderlayerManagerPasses,
)
bpy.types.ViewLayer.active_pass_idx = bpy.props.IntProperty(
name='Active Pass Index',
default=0,
)
bpy.types.ViewLayer.order = bpy.props.IntProperty(
name='Order',
default=-1,
)
bpy.types.ViewLayer.image = bpy.props.PointerProperty(
type=RenderlayerManagerPasses,
)
bpy.types.ViewLayer.lightgroup_settings = bpy.props.CollectionProperty(
type=RenderlayerManagerLightgroup,
)
bpy.types.ViewLayer.rlm_active_lightgroup_index = bpy.props.IntProperty(
name='RLM Active Lightgroup Index',
default=0,
)
bpy.types.ViewLayer.use_denoiser = bpy.props.BoolProperty(
name='Use Denoiser',
default=False,
)
bpy.types.ViewLayer.denoiser_type = bpy.props.EnumProperty(
name='Denoiser Type',
items=(
('NONE', 'None', 'No denoising'),
('BLENDER', 'Blender', 'Blender built-in denoiser'),
('OPTIX', 'OptiX', 'NVIDIA OptiX AI denoiser'),
('OPENIMAGEDENOISE', 'OpenImageDenoise', 'Intel Open Image Denoise'),
),
default='BLENDER',
update=update_denoiser_settings,
)
bpy.types.ViewLayer.denoiser_passes = bpy.props.EnumProperty(
name='Denoiser Passes',
items=(
('DIFFDIR', 'DiffDir', 'Apply denoising to DiffDir pass'),
('DIFFIND', 'DiffInd', 'Apply denoising to DiffInd pass'),
('BOTH', 'Both', 'Apply denoising to both DiffDir and DiffInd passes'),
),
default='DIFFDIR',
)
def unregister():
del bpy.types.ViewLayer.denoiser_passes
del bpy.types.ViewLayer.denoiser_type
del bpy.types.ViewLayer.use_denoiser
del bpy.types.ViewLayer.rlm_active_lightgroup_index
del bpy.types.ViewLayer.lightgroup_settings
del bpy.types.ViewLayer.override_file_format
del bpy.types.ViewLayer.composite
del bpy.types.ViewLayer.color
del bpy.types.ViewLayer.image_settings
del bpy.types.Scene.rlm
for cls in classes:
bpy.utils.unregister_class(cls)