-
Notifications
You must be signed in to change notification settings - Fork 1
/
bt_utils.py
724 lines (592 loc) · 27.5 KB
/
bt_utils.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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# Copyright (C) Cogumelo Softworks
# License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
import bpy
import blf
import bgl
import imbuf
import os, sys
import json
import io
import time
import subprocess
from bpy_extras.node_shader_utils import PrincipledBSDFWrapper
from . bt_autopack import *
# Helper para propriedades do objeto na lista
class TargetGroup():
name = ""
uv = ""
def __init__(self,_name,_uv):
self.name = _name
self.uv = _uv
def duplicateObject(scene, name, copyobj):
# Create new mesh
mesh = bpy.data.meshes.new(name)
# Create new object associated with the mesh
ob_new = bpy.data.objects.new(name, mesh)
# Copy data block from the old object into the new object
ob_new.data = copyobj.data.copy()
#ob_new.scale = copyobj.scale
#ob_new.location = copyobj.location
ob_new.matrix_world = copyobj.matrix_world
# Link new object to the given scene and select it
scene.collection.objects.link(ob_new)
ob_new.select_set(True)
return ob_new
def CheckVisible(ListObj):
#Verifica visibilidade do Objeto na cena e se o objeto está em um layer ativo
for item in ListObj:
for obj in bpy.context.scene.objects:
if bpy.context.scene.objects[item.name] not in bpy.context.visible_objects:
return (False,obj)
return (True,None)
def GetObjectListJob(activeJob,settings,isAtlas):
listObjects = []
if settings.target != "" and isAtlas == True:
# A lista é preenchida com os dados do Target
target = bpy.context.scene.objects[settings.target]
targetProps = TargetGroup(settings.target,settings.target_uv)
listObjects.append((target,targetProps))
else:
for obj_name in activeJob.job_objs.coll:
for obj in bpy.context.scene.objects:
if obj_name.name == obj.name:
listObjects.append((obj,obj_name))
return listObjects
def GetActivePasses(activeJob):
passList = []
for job in activeJob.job_pass.Pass:
if job.enabled:
passList.append(job)
return passList
def FixUVNodes(mat,objData):
for f in objData[0].data.uv_layers:
if(f.active_render):
baseUV = f.name
node_tree = mat.node_tree
for node in node_tree.nodes:
if node.type == "TEX_IMAGE":
imageUVInput = node.inputs[0]
if len(node.inputs[0].links) == 0:
uv_node = node_tree.nodes.new('ShaderNodeUVMap')
uv_node.uv_map = baseUV
uvNodeOutput = uv_node.outputs[0]
node_tree.links.new(imageUVInput,uvNodeOutput)
print("-------- FIXED UV ----------")
def CreateImageNode(mat,tempImage):
# Cria Image Nodes
image_node = mat.node_tree.nodes.new('ShaderNodeTexImage')
image_node.location = (100,100)
image_node.image = tempImage
image_node.select = True
image_node.update()
# Torna Imagem Ativa
mat.node_tree.nodes.active = image_node
def SetTextureOvenUV(objData):
active_uv = None
for f in objData[0].data.uv_layers:
if(f.name == objData[1].uv):
f.active = True
f.active_render = True
f.active_clone = True
data = f.data
active_uv = f
objData[0].data.update()
def CreateImageAtlas(activeJob,currentObject,jobPass):
# Cria nova imagem com o nome do Objeto + Passo se não houver
hasit = False
tempImage = None
for image in bpy.data.images:
if image.name == activeJob.name + "_" + jobPass.name:
hasit = True
tempImage = image
if not hasit:
tempImage = bpy.data.images.new(name = activeJob.name + "_" + jobPass.name, width = int(jobPass.size), height= int(jobPass.size),alpha=True,float_buffer=True)
tempImage.source = "GENERATED"
tempImage.use_generated_float = True;
tempImage.generated_width = int(jobPass.size)
tempImage.generated_height = int(jobPass.size)
return tempImage
def CreateImage(activeJob,currentObject,jobPass,isAtlas):
# Cria nova imagem com o nome do Objeto + Passo se não houver
hasit = False
tempImage = None
size = int(jobPass.size)
print("---------------------------- ALIASING")
print(jobPass.aliasing)
if(jobPass.aliasing == "2x"):
size *= 2
if(jobPass.aliasing == "4x"):
size *= 4
if(isAtlas):
name = activeJob.name + "_" + jobPass.name
else:
name = activeJob.name + "_" + currentObject.name + "_" + jobPass.name
for image in bpy.data.images:
if image.name == name :
hasit = True
tempImage = image
if not hasit:
if isAtlas:
tempImage = bpy.data.images.new(name = name, width = size, height= size, alpha=True, float_buffer=True)
else:
tempImage = bpy.data.images.new(name = name, width = size, height= size, alpha=True, float_buffer=True)
tempImage.source = "GENERATED"
tempImage.use_generated_float = True;
tempImage.generated_width = int(size)
tempImage.generated_height = int(size)
# Configure ColorSpace
tempImage.colorspace_settings.name = jobPass.colors_space
return tempImage
def SaveImage(activeJob,currentObject,jobPass,tempImage,isAtlas):
settings = activeJob.job_settings
if(isAtlas):
name = activeJob.name + "_" + jobPass.name
else:
name = activeJob.name + "_" + currentObject.name + "_" + jobPass.name
if settings.path != "":
cacheType = bpy.context.scene.render.image_settings.file_format
cacheColorMode = bpy.context.scene.render.image_settings.color_mode
cacheColorDept = bpy.context.scene.render.image_settings.color_depth
cacheCompression = bpy.context.scene.render.image_settings.compression
cacheQuality = bpy.context.scene.render.image_settings.quality
bpy.context.scene.render.image_settings.file_format = settings.format
try:
bpy.context.scene.render.image_settings.color_mode = "RGBA"
except:
bpy.context.scene.render.image_settings.color_mode = "RGB"
try:
bpy.context.scene.render.image_settings.color_depth = "32"
except:
try:
bpy.context.scene.render.image_settings.color_depth = "16"
except:
bpy.context.scene.render.image_settings.color_depth = "8"
path_format = ""
if settings.format == "JPEG":
path_format = ".jpeg"
if settings.format == "PNG":
path_format = ".png"
if settings.format == "TIFF":
path_format = ".tiff"
if settings.format == "OPEN_EXR":
path_format = ".exr"
if settings.format == "TARGA":
path_format = ".tga"
bpy.context.scene.render.image_settings.compression = 100
bpy.context.scene.render.image_settings.quality = 100
path = bpy.path.abspath(settings.path) + name + path_format
tempImage.save_render(path)
#Apply AA
if(jobPass.aliasing != "None"):
imgSize = int(jobPass.size)
img = imbuf.load(path)
img.resize((int(imgSize), int(imgSize)))
imbuf.write(img,path)
return path
def CheckBake(context,jobList):
# Verifica se o arquivo está salvo
if not bpy.data.is_saved:
status = 'TEXTUREOVEN ABORTED: Save the File before bake'
return status
for activeJob in jobList:
if not activeJob.enabled:
continue
objectList = activeJob.job_objs.coll
if(len(objectList) == 0):
status = 'TEXTUREOVEN ABORTED: on the job: "' + activeJob.name + '" - No valid object to bake in Bake List'
return status
# Verifica se existe um path válido para salvar as imagens
if(not os.path.exists(bpy.path.abspath(activeJob.job_settings.path))):
status = "TEXTUREOVEN ABORTED: on the job: ''" + activeJob.name + ". save path do not exist"
return status
# Verifica se existem objetos na lista e se todos os objetos da lista estão visíveis
checkstatus,objError = CheckVisible(objectList)
if(checkstatus == False):
status = "TEXTUREOVEN ABORTED: on the job: ''" + activeJob.name + "''. Object ''" + objError.name + "'' is not visible in the scene"
return status
#Seta Objeto Ativo para Objetct Mode se não estiver
try:
bpy.ops.object.mode_set(mode="OBJECT")
except:
pass
listObjects = []
settings = activeJob.job_settings
ErrorMessage = ""
# Verifica se irá fazer Atlas e se irá utilizar Target
if settings.mode == "ATLAS" and settings.target != "":
'''
target = context.scene.objects[settings.target]
if not target.is_visible(context.scene):
status = 'TEXTUREOVEN ABORTED: "' + activeJob.name + '" - Active Target object is not visible'
return status
'''
for obj_name in activeJob.job_objs.coll:
if obj_name.name == settings.target:
status = 'TEXTUREOVEN ABORTED: "' + activeJob.name + '" - Target object is in the source list, change it'
return status
# A lista é preenchida com os dados do Target
target = context.scene.objects[settings.target]
targetProps = TargetGroup(settings.target,settings.target_uv)
listObjects.append((target,targetProps))
else:
# Cria lista com os objetos baseado em seus nomes e propriedades
for obj_name in activeJob.job_objs.coll:
for obj in context.scene.objects:
if obj_name.name == obj.name:
listObjects.append((obj,obj_name))
# Verifica se os objetos da Lista possuem material do Cycles:
for obj in listObjects:
if len(obj[0].material_slots) == 0:
status = 'TEXTUREOVEN ABORTED: "' + activeJob.name + '" - One or more objects in the List to Bake do not have a valid material: ' + obj[0].name
return status
for mat in obj[0].material_slots:
if mat.material == None:
status = 'TEXTUREOVEN ABORTED: "' + activeJob.name + '" - One or more objects in the List to Bake do not have a valid material: ' + obj[0].name
return status
else:
valid = False
if mat.material.use_nodes == True:
for node in mat.material.node_tree.nodes:
if node.bl_idname == "ShaderNodeOutputMaterial":
valid = True
if not valid:
status = 'TEXTUREOVEN ABORTED: "' + activeJob.name + '" - One or more objects in the List to Bake do not have a valid node material'
return status
else:
status = 'TEXTUREOVEN ABORTED: "' + activeJob.name + '" - One or more objects in the List to Bake don not have a valid cycles node material'
return status
# Verifica se os objetos da Lista possuem UV ativa se não estiver gerando UVs:
if( not activeJob.job_settings.generate_uvwrap):
for obj in listObjects:
if(obj[1].uv == ""):
status = 'TEXTUREOVEN ABORTED: "' + activeJob.name + '" - Object in the List to Bake do not have a valid uv set'
return status
# Verifica se existe ao menos 1 passo habilitado
hasPass = False
for job in activeJob.job_pass.Pass[:]:
if job.enabled:
hasPass = True
if not hasPass:
status = 'TEXTUREOVEN ABORTED: "' + activeJob.name + '" You need at least one enabled pass to Bake'
return status
print ("--------------------- STATUS CHECK -----------------")
return True
def MakeUVs(context,jobList):
# UV Unwrapper Systemm
for activeJob in jobList:
# Abre a UV de cada objeto de cada Job que precisa
#listObjects = []
if(activeJob.job_settings.generate_uvwrap):
if(activeJob.job_settings.target == ""):
for obj in activeJob.job_objs.coll:
if(obj.overwriteUV != ""):
obj.uv = obj.overwriteUV
else:
obj.uv = DoUnwrapper( obj.name,
context,
activeJob.job_settings.uvwrapper_margin,
activeJob.job_settings.uvwrapper_angle,
activeJob.name)
else:
activeJob.job_settings.target_uv = DoUnwrapper( activeJob.job_settings.target,
context,
activeJob.job_settings.uvwrapper_margin,
activeJob.job_settings.uvwrapper_angle,
activeJob.name)
# Aplica Pack em cada job que precisa
if activeJob.job_settings.mode == "ATLAS" and activeJob.job_settings.target == "" and activeJob.job_settings.atlas_autoPack:
DoAtlas(context,activeJob)
def SaveBakeReport(reports):
script_file = os.path.realpath(__file__)
directory = os.path.dirname(script_file)
with open(directory + "/report.json", 'w') as file:
json.dump(reports, file, indent=2)
def LoadBakeReports():
script_file = os.path.realpath(__file__)
directory = os.path.dirname(script_file)
try:
reports = json.loads(open(directory + "/report.json").read())
except:
("Can't Load Report Trying again")
time.sleep(1) # Delays for 5 seconds. You can also use a float value.
reports = json.loads(open(directory + "/report.json").read())
return reports
def SetCustomMaterial(obj,mat,jobPass,settings):
print("--------------- SET CUSTOM MATERIAL ------------------------")
node_tree = mat.node_tree
if(jobPass.custom_output != ""): # Custom Output
print(jobPass.name + " Using Custom Output")
originalOut = GetOutputByName(node_tree.nodes,jobPass.custom_output)
if(originalOut != None):
SetActiveNode(node_tree,originalOut)
print(originalOut.name)
else:
originalOut = GetActiveNode(node_tree.nodes)
else:
originalOut = GetActiveNode(node_tree.nodes)
bprincipled = originalOut.inputs[0].links[0].from_node
# print(bprincipled.inputs[10].default_value)
nodeOut = node_tree.nodes.new('ShaderNodeOutputMaterial')
if(settings.profile_type != "BLENDER"):
#fix the issue, that metallic value darken the diffuse
if(jobPass.type_simple == "ALBEDO"):
try:
principled = originalOut.inputs[0].links[0].from_node
if(principled.type == "BSDF_PRINCIPLED"):
if(principled.inputs[6].is_linked):
link = principled.inputs[6].links[0]
node_tree.links.new(link.from_socket, principled.inputs[10])
node_tree.links.remove(link)
if (principled.inputs[6].default_value > 0.0):
principled.inputs[10].default_value = principled.inputs[6].default_value
principled.inputs[6].default_value = 0.0
except:
pass
if(jobPass.type_simple == "SPECULAR"):
try:
# Get current Principled
principled = originalOut.inputs[0].links[0].from_node
if(principled.type == "BSDF_PRINCIPLED"):
# Get specular value or texture and connect to the new output
if(principled.inputs[12].is_linked):
texture = principled.inputs[12].links[0].from_socket
mat.node_tree.links.new(texture, nodeOut.inputs[0])
else:
nodeValue = node_tree.nodes.new('ShaderNodeValue')
nodeValue.outputs[0].default_value = principled.inputs[12].default_value
mat.node_tree.links.new(nodeValue.outputs[0], nodeOut.inputs[0])
SetActiveNode(node_tree,nodeOut)
except:
pass
if(jobPass.type_simple == "ALPHA"):
try:
# Get current Principled
principled = originalOut.inputs[0].links[0].from_node
if(principled.type == "BSDF_PRINCIPLED"):
# Get specular value or texture and connect to the new output
if(principled.inputs["Alpha"].is_linked):
texture = principled.inputs["Alpha"].links[0].from_socket
mat.node_tree.links.new(texture, nodeOut.inputs[0])
else:
nodeValue = node_tree.nodes.new('ShaderNodeValue')
nodeValue.outputs[0].default_value = principled.inputs["Alpha"].default_value
mat.node_tree.links.new(nodeValue.outputs[0], nodeOut.inputs[0])
SetActiveNode(node_tree,nodeOut)
except:
pass
if(jobPass.type_simple == "METALLIC"):
try:
# Get current Principled
principled = originalOut.inputs[0].links[0].from_node
if(principled.type == "BSDF_PRINCIPLED"):
# Get metallic value or texture and connect to the new output
if(principled.inputs[1].is_linked):
texture = principled.inputs[1].links[0].from_socket
mat.node_tree.links.new(texture, nodeOut.inputs[0])
else:
nodeValue = node_tree.nodes.new('ShaderNodeValue')
nodeValue.outputs[0].default_value = principled.inputs[1].default_value
mat.node_tree.links.new(nodeValue.outputs[0], nodeOut.inputs[0])
SetActiveNode(node_tree,nodeOut)
except:
pass
if(jobPass.type_simple == "ID"):
try:
script_file = os.path.realpath(__file__)
directory = os.path.dirname(script_file)
filepath = directory + "/ressources/mat.blend"
with bpy.data.libraries.load(filepath, link=False) as (data_from, data_to):
data_to.node_groups = data_from.node_groups
group = node_tree.nodes.new("ShaderNodeGroup")
group.node_tree = bpy.data.node_groups['TO_ID']
mat.node_tree.links.new(group.outputs[0], nodeOut.inputs[0])
SetActiveNode(node_tree,nodeOut)
except:
pass
return originalOut
"""
def RestoreMaterials(List):
print("----------------- RESTORE ORIGINAL MATERIALS ------------------")
for idx in range(len(List)):
obj = List[idx][0]
mat = List[idx][1]
obj.material_slots[idx].material = mat
"""
def RestoreCustomOutput(List):
for element in List:
print("------------- RESTORE ORIGINAL OUTPUTS -----------")
print(element[0])
print(element[1])
node_tree = element[0]
output = element[1]
for node in node_tree.nodes:
if node.type == "OUTPUT_MATERIAL":
node.is_active_output = False
output.is_active_output = True
def SetActiveNode(node_tree,output):
for node in node_tree.nodes:
if node.type == "OUTPUT_MATERIAL":
node.is_active_output = False
for node in node_tree.nodes:
if node.type == "OUTPUT_MATERIAL":
if(node == output):
node.is_active_output = True
def GetActiveNode(nodes):
for node in nodes :
if node.type == 'OUTPUT_MATERIAL' and node.is_active_output :
return node
for node in nodes :
if node.type == 'OUTPUT_MATERIAL' :
return node
def GetOutputByName(nodes,name):
for node in nodes:
if node.type == "OUTPUT_MATERIAL" and node.name == name:
print("FOUND NODE: " + node.name)
return node
def SetRenderSettings(jobPass,jobSettings):
# Muda o Numero de Samples
bpy.context.scene.cycles.samples = jobPass.samples
# Configura o Device
bpy.context.scene.cycles.device = jobSettings.render_device
# Seta o Denoise
bpy.context.scene.cycles.use_denoising = jobPass.use_denoising
# Configura o Render Pass
bpy.context.scene.render.bake.use_pass_diffuse = jobPass.use_pass_diffuse
bpy.context.scene.render.bake.use_pass_glossy = jobPass.use_pass_glossy
bpy.context.scene.render.bake.use_pass_transmission = jobPass.use_pass_transmission
#bpy.context.scene.render.bake.use_pass_ambient_occlusion = jobPass.use_pass_ambient_occlusion
bpy.context.scene.render.bake.use_pass_emit = jobPass.use_pass_emit
# Cycles sub passes properties
bpy.context.scene.render.bake.use_pass_color = jobPass.use_pass_color
bpy.context.scene.render.bake.use_pass_direct = jobPass.use_pass_direct
bpy.context.scene.render.bake.use_pass_indirect = jobPass.use_pass_indirect
def CreateIndividualEveeScene(activeJob):
print("-------- CREATE EVEE SCENE ----------------")
listObj = GetObjectListJob(activeJob,activeJob.job_settings,False)
bpy.ops.object.select_all(action="DESELECT")
# Remove Collection
tempCollection = False
for col in bpy.context.scene.collection.children:
if(col.name == "TEXTUREOVEN_" + activeJob.name):
for obj in col.objects:
bpy.data.objects.remove(obj)
bpy.data.collections.remove(col)
# Create collection
tempCollection = bpy.data.collections.new("TEXTUREOVEN_" + activeJob.name)
bpy.context.scene.collection.children.link(tempCollection)
# Atlas mode
if(activeJob.job_settings.mode == "ATLAS"):
pass
# Create Objects
for obj in listObj:
# Duplicate Object
#obj[0].select_set(True)
obj = obj[0]
newObj = obj.copy() # duplicate linked
newObj.data = obj.data.copy() # optional: make this a real duplicate (not linked)
newObj.name = "BK_" + obj.name
newObj.data.uv_layers.active = obj.data.uv_layers.active
for f in newObj.data.uv_layers:
if("TEXTUREOVEN_" + activeJob.job_settings.name in f.name):
f.active = True
f.active_render = True
f.active_clone = True
# Assing objects to collection
tempCollection.objects.link(newObj)
newObj.data.materials.clear()
# Cria Material
mat = bpy.data.materials.get("TEXTUREOVEN_" + activeJob.name + "_" + obj.name)
if(mat is None):
mat = bpy.data.materials.new(name="TEXTUREOVEN_" + activeJob.name + "_" + obj.name)
newObj.data.materials.append(mat)
# Configure Material
mat.use_nodes = True
for p in range(len(activeJob.job_pass.Pass)):
'''
if(activeJob.job_settings.profile_type != "TEXTUREOVEN"):
jobTypeName = activeJob.job_pass.Pass[p].type
else:
jobTypeName = activeJob.job_pass.Pass[p].type_simple
'''
jobName = activeJob.job_pass.Pass[p].name
# Check if Has Image node and Create if Not
imgNode = None
for node in mat.node_tree.nodes:
if(node.type == "TEX_IMAGE" and node.name == "TEXTUREOVEN_" + jobName + "_" + obj.name):
imgNode = node
if(imgNode == None):
# Create image Node
imgNode = mat.node_tree.nodes.new('ShaderNodeTexImage')
imgNode.name = "TEXTUREOVEN_" + jobName + "_" + obj.name
img = bpy.data.images[activeJob.name + "_" + obj.name + "_" + jobName]
imgNode.image = img
print(img)
# Get Output
for node in mat.node_tree.nodes:
if node.type == "OUTPUT_MATERIAL":
mat.node_tree.links.new(node.inputs[0],imgNode.outputs[0])
# REMOVE Principled
for node in mat.node_tree.nodes:
if node.type == "BSDF_PRINCIPLED":
mat.node_tree.nodes.remove(node)
#mat.node_tree.links.new(node.inputs[0],imgNode.outputs[0])
def SetupTextureOvenPass(jobPass,jobSettings):
RemoveColorManagement()
# BLENDER PROFILES
if(jobSettings.profile_type == "BLENDER"):
if(jobPass.type == "NORMAL"):
return" NORMAL"
if(jobPass.type_simple == "SUBSURFACE"):
return "SUBSURFACE"
if(jobPass.type_simple == "ALBEDO"):
return "DIFFUSE"
# TEXTUREOVEN PROFILES
else:
if(jobPass.type_simple == "NORMAL"):
if(jobPass.normal_simple_mode == "+Y"):
bpy.context.scene.render.bake.normal_g = "POS_Y"
if(jobPass.normal_simple_mode == "-Y"):
bpy.context.scene.render.bake.normal_g = "NEG_Y"
return "NORMAL"
if(jobPass.type_simple == "SUBSURFACE"):
bpy.context.scene.render.bake.use_pass_color = True
bpy.context.scene.render.bake.use_pass_direct = True
bpy.context.scene.render.bake.use_pass_indirect = True
return "SUBSURFACE"
if(jobPass.type_simple == "ALBEDO"):
bpy.context.scene.cycles.samples = 8
bpy.context.scene.render.bake.use_pass_color = True
bpy.context.scene.render.bake.use_pass_direct = False
bpy.context.scene.render.bake.use_pass_indirect = False
return "DIFFUSE"
if(jobPass.type_simple == "AO"):
return "AO"
if(jobPass.type_simple == "SHADOWS"):
return "SHADOW"
if(jobPass.type_simple == "ROUGHNESS"):
return "ROUGHNESS"
if(jobPass.type_simple == "METALLIC"):
bpy.context.scene.cycles.samples = 8
return "EMIT"
if(jobPass.type_simple == "SPECULAR"):
bpy.context.scene.cycles.samples = 8
return "EMIT"
if(jobPass.type_simple == "ALPHA"):
bpy.context.scene.cycles.samples = 8
return "EMIT"
if(jobPass.type_simple == "ID"):
bpy.context.scene.cycles.samples = 8
return "EMIT"
def RemoveColorManagement():
bpy.context.scene.display_settings.display_device = "sRGB"
bpy.context.scene.view_settings.view_transform = "Standard"
bpy.context.scene.view_settings.look = "None"
bpy.context.scene.view_settings.exposure = 0
bpy.context.scene.view_settings.gamma = 1
def GetFixedMargin(jobPass):
margin = jobPass.margin
if(jobPass.aliasing == "2x"):
margin *= 2
if(jobPass.aliasing == "4x"):
margin *= 4
return margin