-
Notifications
You must be signed in to change notification settings - Fork 46
/
bakelab_map.py
492 lines (464 loc) · 19 KB
/
bakelab_map.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
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
import bpy
from bpy.types import (
Operator,
PropertyGroup,
Panel
)
from bpy.props import (
IntProperty,
EnumProperty,
BoolProperty,
FloatProperty,
StringProperty,
PointerProperty,
CollectionProperty
)
class BakeLabMap(PropertyGroup):
enabled : BoolProperty(name = '', default = True)
type : EnumProperty(
name = 'Type',
items = (
('Albedo', 'Albedo',''),
('Normal', 'Normal',''),
('Glossy', 'Glossy',''),
('Roughness', 'Roughness',''),
('Emission', 'Emission',''),
('Diffuse', 'Diffuse',''),
('Subsurface', 'Subsurface',''),
('Transmission','Transmission',''),
('Shadow', 'Shadow',''),
('Environment', 'Environment',''),
('UV', 'UV',''),
None,
('Combined', 'Combined',''),
('CustomPass', 'Custom Pass',''),
('AO', 'Ambient Occlusion',''),
('Displacement','Displacement','')
),
default = 'Albedo'
)
pass_name : StringProperty(name = 'Property name', default = 'Color,Base Color,Albedo,Paint Color')
deep_search : BoolProperty(
name = 'Deep Search',
description = 'Search inside of node groups',
default = True
)
img_name : StringProperty(name = 'Image name', default = '*')
width : IntProperty(
name = 'Width',
default = 1024 ,
min = 1, soft_max = 16384
)
height : IntProperty(
name = 'Height',
default = 1024,
min = 1, soft_max = 16384
)
target_width : IntProperty(name = 'Target Width')
target_height : IntProperty(name = 'Target Height')
image_scale : FloatProperty(
name = 'Image Scale',
default = 1,
min = 0
)
aa_override : IntProperty(
name = 'Anti-alias Override',
description = 'Use individual anti-aliasing (0 to use global value)',
default = 0,
min = 0, soft_max = 8
)
final_aa : IntProperty(name = 'Final Anti-alias')
float_depth: BoolProperty(name = '32 bit float', default = False)
color_space : EnumProperty(
name = 'Color Space',
description = 'Color Space',
items = (('sRGB','sRGB',''),
('Non-Color','Non-Color','')),
default = 'sRGB'
)
file_format : EnumProperty(
name = 'Format',
items = (
('PNG', 'PNG', ''),
('JPEG', 'JPEG', ''),
('OPEN_EXR', 'OpenEXR', '')
)
)
png_channels : EnumProperty(
name = 'Color',
items = (('BW','BW',''),
('RGB','RGB',''),
('RGBA','RGBA','')),
default = 'RGB'
)
png_depth : EnumProperty(
name = 'Depth',
description = 'Color Depth',
items = (('8','8 byte',''),
('16','16 byte','')),
default = '8'
)
png_compression : IntProperty(
name = 'Compression',
default = 15,
description = 'Compression',
min = 0, max = 100
)
jpg_channels : EnumProperty(
name = 'Color',
items = (('BW','BW',''),
('RGB','RGB','')),
default = 'RGB'
)
jpg_quality : IntProperty(
name = 'Quality',
default = 90,
description = 'Quality',
min = 0, max = 100
)
exr_channels : EnumProperty(
name = 'Color',
items = (('RGB','RGB',''),
('RGBA','RGBA','')),
default = 'RGB'
)
exr_depth : EnumProperty(
name = 'Color Depth',
description = 'Bits depth per channel',
items = (('16', 'Half (16)',''),
('32', 'Full (32)','')),
default = '32'
)
exr_codec_32 : EnumProperty(
name = 'Codec',
items = (
('NONE', 'None', ''),
('PXR24','Pxr24 (lossy)', ''),
('ZIP', 'ZIP (lossless)', ''),
('PIZ', 'PIZ (lossless)', ''),
('RLE', 'RLE (lossless)', ''),
('ZIPS', 'ZIPS (lossless)',''),
('DWAA', 'DWAA (lossy)', '')
),
default = 'ZIP'
)
exr_codec_16 : EnumProperty(
name = 'Codec',
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)', '')
),
default = 'ZIP'
)
samples : IntProperty(
name = 'Samples',default = 6,
description = 'Amount of Samples',
min = 1, soft_max = 1024
)
normal_space : EnumProperty(
name = 'Normal Space',
items = (
('TANGENT','Tangent Space',''),
('OBJECT', 'Object Space','')
)
)
bake_direct : BoolProperty(name = 'Direct', default = False)
bake_indirect : BoolProperty(name = 'Indirect', default = False)
bake_color : BoolProperty(name = 'Color', default = True)
combined_direct : BoolProperty(name = 'Direct', default = True)
combined_indirect : BoolProperty(name = 'Indirect', default = True)
combined_diffuse : BoolProperty(name = 'Diffuse', default = True)
combined_glossy : BoolProperty(name = 'Glossy', default = True)
combined_transmission : BoolProperty(name = 'Transmission', default = True)
#combined_subsurface : BoolProperty(name = 'Subsurface', default = True)
#combined_ambient_occlusion : BoolProperty(name = 'AO', default = True)
combined_emit : BoolProperty(name = 'Emit', default = True)
################################################################
################################################################
class BakeLabAddMapItem(bpy.types.Operator):
"""Add a new bake map"""
bl_idname = "bakelab.newmapitem"
bl_label = "Add bake map"
bl_options = {'REGISTER','UNDO'}
type: EnumProperty(
name = 'Type',
items = (
('Albedo', 'Albedo',''),
('Normal', 'Normal',''),
('Glossy', 'Glossy',''),
('Roughness', 'Roughness',''),
('Emission', 'Emission',''),
('Diffuse', 'Diffuse',''),
('Subsurface', 'Subsurface',''),
('Transmission','Transmission',''),
('Shadow', 'Shadow',''),
('Environment', 'Environment',''),
('UV', 'UV',''),
None,
('Combined', 'Combined',''),
('CustomPass', 'Custom Pass',''),
('AO', 'Ambient Occlusion',''),
('Displacement','Displacement','')
),
default = 'Albedo'
)
width: IntProperty(name = 'Width',default = 1024,
min = 1, soft_max = 16384)
height: IntProperty(name = 'Height',default = 1024,
min = 1, soft_max = 16384)
image_scale: FloatProperty(name = 'Image Scale',default = 1,
min = 0)
float_depth: BoolProperty(name = '32 bit float', default = False)
file_format : EnumProperty(
name = 'Format',
items = (
('PNG', 'PNG', ''),
('JPEG', 'JPEG', ''),
('OPEN_EXR', 'OpenEXR', '')
)
)
png_channels : EnumProperty(
name = 'Color',
items = (('BW','BW',''),
('RGB','RGB',''),
('RGBA','RGBA','')),
default = 'RGB'
)
png_depth : EnumProperty(
name = 'Depth',
description = 'Color Depth',
items = (('8','8 byte',''),
('16','16 byte','')),
default = '8'
)
png_compression : IntProperty(
name = 'Compression',
default = 15,
description = 'Compression',
min = 0, max = 100
)
jpg_channels : EnumProperty(
name = 'Color',
items = (('BW','BW',''),
('RGB','RGB','')),
default = 'RGB'
)
jpg_quality : IntProperty(
name = 'Quality',
default = 90,
description = 'Quality',
min = 0, max = 100
)
exr_channels : EnumProperty(
name = 'Color',
items = (('RGB','RGB',''),
('RGBA','RGBA','')),
default = 'RGB'
)
exr_depth : EnumProperty(
name = 'Color Depth',
description = 'Bits depth per channel',
items = (('16', 'Half (16)',''),
('32', 'Full (32)','')),
default = '32'
)
exr_codec_32 : EnumProperty(
name = 'Codec',
items = (
('NONE', 'None', ''),
('PXR24','Pxr24 (lossy)', ''),
('ZIP', 'ZIP (lossless)', ''),
('PIZ', 'PIZ (lossless)', ''),
('RLE', 'RLE (lossless)', ''),
('ZIPS', 'ZIPS (lossless)',''),
('DWAA', 'DWAA (lossy)', '')
),
default = 'ZIP'
)
exr_codec_16 : EnumProperty(
name = 'Codec',
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)', '')
),
default = 'ZIP'
)
def calcItemSettings(self,context,item):
if self.type == 'Albedo':
item.img_name = '*_t'
item.samples = 4
if self.type == 'Combined':
item.img_name = '*_c'
item.samples = 64
if self.type == 'Normal':
item.img_name = '*_n'
item.samples = 16
item.color_space = 'Non-Color'
item.aa_override = 1 #Because cycles has buildin anti-aliasing for normals
if self.type == 'Displacement':
item.img_name = '*_h'
item.samples = 4
item.color_space = 'Non-Color'
if self.type == 'AO':
item.img_name = '*_ao'
item.samples = 64
item.color_space = 'Non-Color'
if self.type == 'Shadow':
item.img_name = '*_sh'
item.samples = 32
if self.type == 'Glossy':
item.img_name = '*_s'
item.samples = 8
if self.type == 'Roughness':
item.img_name = '*_r'
item.samples = 4
item.color_space = 'Non-Color'
if self.type == 'Diffuse':
item.img_name = '*_d'
item.samples = 8
if self.type == 'Emission':
item.img_name = '*_e'
item.samples = 4
if self.type == 'Transmission':
item.img_name = '*_a'
item.samples = 8
if self.type == 'UV':
item.img_name = '*_uv'
item.samples = 1
if self.type == 'Environment':
item.img_name = '*_env'
item.samples = 16
if self.type == 'Subsurface':
item.img_name = '*_sss'
item.samples = 64
if self.type == 'CustomPass':
item.img_name = '*_pass'
item.samples = 4
item.color_space = 'Non-Color'
def draw(self,context):
layout = self.layout
props = context.scene.BakeLabProps
layout.use_property_split = True
layout.use_property_decorate = False
layout.prop(self, "type")
if props.image_size == 'FIXED':
col = layout.column(align = True)
col.prop(self, "width")
col.prop(self, "height")
elif props.image_size == 'ADAPTIVE':
layout.prop(self, "image_scale")
layout.prop(self, "float_depth")
if props.save_or_pack == 'SAVE':
row = layout.row()
row.prop(self, "file_format")
col = layout.column()
if self.file_format == "PNG":
row = col.row()
row.prop(self, "png_channels", expand = True)
row = col.row()
row.prop(self, "png_depth", expand = True)
col.prop(self, "png_compression")
if self.file_format == "JPEG":
row = col.row()
row.prop(self, "jpg_channels", expand = True)
col.prop(self, "jpg_quality")
if self.file_format == "OPEN_EXR":
row = col.row()
row.prop(self, "exr_channels", expand = True)
row = col.row()
row.prop(self, "exr_depth", expand = True)
if self.exr_depth == '32':
col.prop(self, "exr_codec_32")
if self.exr_depth == '16':
col.prop(self, "exr_codec_16")
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
def execute(self,context):
context.area.tag_redraw()
item = context.scene.BakeLabMaps.add()
item.type = self.type
item.width = self.width
item.height = self.height
item.image_scale = self.image_scale
item.float_depth = self.float_depth
item.file_format = self.file_format
item.png_channels = self.png_channels
item.png_depth = self.png_depth
item.png_compression = self.png_compression
item.jpg_channels = self.jpg_channels
item.jpg_quality = self.jpg_quality
item.exr_channels = self.exr_channels
item.exr_depth = self.exr_depth
item.exr_codec_32 = self.exr_codec_32
item.exr_codec_16 = self.exr_codec_16
self.calcItemSettings(context, item)
context.scene.BakeLabMapIndex = len(context.scene.BakeLabMaps)-1
return {'FINISHED'}
class BakeLabRemoveMapItem(bpy.types.Operator):
"""Remove selected bake map"""
bl_idname = "bakelab.removemapitem"
bl_label = "remove bake map"
bl_options = {'REGISTER','UNDO'}
@classmethod
def poll(cls,context):
return context.scene.BakeLabMaps
def execute(self,context):
context.area.tag_redraw()
context.scene.BakeLabMaps.remove(context.scene.BakeLabMapIndex)
context.scene.BakeLabMapIndex = max(context.scene.BakeLabMapIndex - 1,0)
context.scene.BakeLabMapIndex = min(context.scene.BakeLabMapIndex, len(context.scene.BakeLabMaps))
return {'FINISHED'}
class BakeLabShowPassPresets(Operator):
"""Show Presets"""
bl_idname = "bakelab.show_pass_presets"
bl_label = "BakeLab Show Pass Presets"
pass_presets : EnumProperty(
name = 'Pass Presets',
items = (
('Color,Base Color,Albedo,Paint Color', 'Color/Albedo',''),
('Metallic', 'Metallic',''),
('Specular,Glossiness,Glossy', 'Specular',''),
('Roughness', 'Roughness',''),
('Anisotropic', 'Anisotropic',''),
('Sheen', 'Sheen',''),
('Clearcoat', 'Clearcoat',''),
('Transmission', 'Transmission ',''),
('Alpha', 'Alpha ','')
)
)
def execute(self,context):
context.area.tag_redraw()
scene = context.scene
if scene.BakeLabMapIndex>=0 and scene.BakeLabMaps:
item = scene.BakeLabMaps[scene.BakeLabMapIndex]
if item:
item.pass_name = self.pass_presets
return {'FINISHED'}
################################################################
class BakeLabMapListUI(bpy.types.UIList):
bl_idname = "BAKELAB_MAP_UL_list"
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
if item.type == 'CustomPass':
layout.label(text = item.pass_name, icon = 'NONE')
else:
layout.label(text = item.type, icon = 'NONE')
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text = "", icon = 'TEXTURE')
layout.prop(item, 'enabled')