1 # ***** BEGIN GPL LICENSE BLOCK *****
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # ***** END GPL LICENCE BLOCK *****
25 def find_index(objekti
):
28 for tex
in objekti
.active_material
.texture_slots
:
29 if(not(hasattr(tex
,'texture'))):
35 def RemoveFbxNodes(objekti
):
36 Node_Tree
= objekti
.active_material
.node_tree
37 for node
in Node_Tree
.nodes
:
38 if node
.type != 'OUTPUT_MATERIAL':
39 Node_Tree
.nodes
.remove(node
)
42 output
.location
= 340,400
43 Prin_mat
= Node_Tree
.nodes
.new(type="ShaderNodeBsdfPrincipled")
44 Prin_mat
.location
= 13, 375
46 Node_Tree
.links
.new(Prin_mat
.outputs
[0], output
.inputs
[0])
49 def UVTiling(objekti
, index
, texturelist
):
50 """ Checks what Tiles are linked with Material """
52 objekti
.coat3D
.applink_scale
= objekti
.scale
55 for poly
in objekti
.data
.polygons
:
56 if (poly
.material_index
== (index
)):
57 loop_index
= poly
.loop_indices
[0]
58 uv_x
= objekti
.data
.uv_layers
.active
.data
[loop_index
].uv
[0]
59 if(uv_x
>= 0 and uv_x
<=1):
61 elif (uv_x
>= 1 and uv_x
<= 2):
63 elif (uv_x
>= 2 and uv_x
<= 3):
65 elif (uv_x
>= 3 and uv_x
<= 4):
67 elif (uv_x
>= 4 and uv_x
<= 5):
69 elif (uv_x
>= 5 and uv_x
<= 6):
71 elif (uv_x
>= 6 and uv_x
<= 7):
73 elif (uv_x
>= 7 and uv_x
<= 8):
75 elif (uv_x
>= 8 and uv_x
<= 9):
78 uv_y
= objekti
.data
.uv_layers
.active
.data
[loop_index
].uv
[1]
79 if (uv_y
>= 0 and uv_y
<= 1):
81 elif (uv_y
>= 1 and uv_y
<= 2):
83 elif (uv_x
>= 2 and uv_y
<= 3):
85 elif (uv_x
>= 3 and uv_y
<= 4):
87 elif (uv_x
>= 4 and uv_y
<= 5):
89 elif (uv_x
>= 5 and uv_y
<= 6):
91 elif (uv_x
>= 6 and uv_y
<= 7):
93 elif (uv_x
>= 7 and uv_y
<= 8):
95 elif (uv_x
>= 8 and uv_y
<= 9):
98 tile_number
= '10' + tile_number_y
+ tile_number_x
100 if tile_number
not in tiles_index
:
101 tiles_index
.append(tile_number
)
105 def updatetextures(objekti
): # Update 3DC textures
107 for index_mat
in objekti
.material_slots
:
109 for node
in index_mat
.material
.node_tree
.nodes
:
110 if (node
.type == 'TEX_IMAGE'):
111 if (node
.name
== '3DC_color'):
113 elif (node
.name
== '3DC_metalness'):
115 elif (node
.name
== '3DC_rough'):
117 elif (node
.name
== '3DC_nmap'):
119 elif (node
.name
== '3DC_displacement'):
121 elif (node
.name
== '3DC_emissive'):
123 elif (node
.name
== '3DC_AO'):
125 elif (node
.name
== '3DC_alpha'):
128 for index_node_group
in bpy
.data
.node_groups
:
130 for node
in index_node_group
.nodes
:
131 if (node
.type == 'TEX_IMAGE'):
132 if (node
.name
== '3DC_color'):
134 elif (node
.name
== '3DC_metalness'):
136 elif (node
.name
== '3DC_rough'):
138 elif (node
.name
== '3DC_nmap'):
140 elif (node
.name
== '3DC_displacement'):
142 elif (node
.name
== '3DC_emissive'):
144 elif (node
.name
== '3DC_AO'):
146 elif (node
.name
== '3DC_alpha'):
150 def readtexturefolder(objekti
, mat_list
, texturelist
, is_new
, udim_textures
): #read textures from texture file
152 # Let's check are we UVSet or MATERIAL modee
154 for ind
, index_mat
in enumerate(objekti
.material_slots
):
157 tile_list
= UVTiling(objekti
,ind
, texturelist
)
162 texcoat
['color'] = []
164 texcoat
['rough'] = []
165 texcoat
['metalness'] = []
167 texcoat
['emissive'] = []
168 texcoat
['emissive_power'] = []
169 texcoat
['displacement'] = []
170 texcoat
['alpha'] = []
172 create_group_node
= False
173 if(udim_textures
== False):
174 for slot_index
, texture_info
in enumerate(texturelist
):
177 for index
, layer
in enumerate(objekti
.data
.uv_layers
):
178 if(layer
.name
== texturelist
[slot_index
][0]):
183 print(texture_info
[0])
185 if(texture_info
[0] == index_mat
.name
):
186 if texture_info
[2] == 'color' or texture_info
[2] == 'diffuse':
187 if(index_mat
.material
.coat3D_diffuse
):
189 texcoat
['color'].append(texture_info
[3])
192 os
.remove(texture_info
[3])
194 elif texture_info
[2] == 'metalness' or texture_info
[2] == 'specular' or texture_info
[2] == 'reflection':
195 if (index_mat
.material
.coat3D_metalness
):
196 texcoat
['metalness'].append(texture_info
[3])
199 os
.remove(texture_info
[3])
201 elif texture_info
[2] == 'rough' or texture_info
[2] == 'roughness':
202 if (index_mat
.material
.coat3D_roughness
):
203 texcoat
['rough'].append(texture_info
[3])
206 os
.remove(texture_info
[3])
208 elif texture_info
[2] == 'nmap' or texture_info
[2] == 'normalmap' or texture_info
[2] == 'normal_map' or texture_info
[2] == 'normal':
209 if (index_mat
.material
.coat3D_normal
):
210 texcoat
['nmap'].append(texture_info
[3])
213 os
.remove(texture_info
[3])
215 elif texture_info
[2] == 'emissive':
216 if (index_mat
.material
.coat3D_emissive
):
217 texcoat
['emissive'].append(texture_info
[3])
220 os
.remove(texture_info
[3])
222 elif texture_info
[2] == 'emissive_power':
223 if (index_mat
.material
.coat3D_emissive
):
224 texcoat
['emissive_power'].append(texture_info
[3])
227 os
.remove(texture_info
[3])
229 elif texture_info
[2] == 'ao':
230 if (index_mat
.material
.coat3D_ao
):
231 texcoat
['ao'].append(texture_info
[3])
234 os
.remove(texture_info
[3])
236 elif texture_info
[2].startswith('displacement'):
237 if (index_mat
.material
.coat3D_displacement
):
238 texcoat
['displacement'].append(texture_info
[3])
241 os
.remove(texture_info
[3])
243 elif texture_info
[2] == 'alpha' or texture_info
[2] == 'opacity':
244 if (index_mat
.material
.coat3D_alpha
):
245 texcoat
['alpha'].append(texture_info
[3])
248 os
.remove(texture_info
[3])
250 create_group_node
= True
253 for texture_info
in texturelist
:
255 if texture_info
[2] == 'color' or texture_info
[2] == 'diffuse':
256 texcoat
['color'].append([texture_info
[0],texture_info
[3]])
258 elif texture_info
[2] == 'metalness' or texture_info
[2] == 'specular' or texture_info
[
260 texcoat
['metalness'].append([texture_info
[0],texture_info
[3]])
262 elif texture_info
[2] == 'rough' or texture_info
[2] == 'roughness':
263 texcoat
['rough'].append([texture_info
[0],texture_info
[3]])
265 elif texture_info
[2] == 'nmap' or texture_info
[2] == 'normalmap' or texture_info
[
266 2] == 'normal_map' or texture_info
[2] == 'normal':
267 texcoat
['nmap'].append([texture_info
[0],texture_info
[3]])
269 elif texture_info
[2] == 'emissive':
270 texcoat
['emissive'].append([texture_info
[0],texture_info
[3]])
272 elif texture_info
[2] == 'emissive_power':
273 texcoat
['emissive_power'].append([texture_info
[0],texture_info
[3]])
275 elif texture_info
[2] == 'ao':
276 texcoat
['ao'].append([texture_info
[0],texture_info
[3]])
278 elif texture_info
[2].startswith('displacement'):
279 texcoat
['displacement'].append([texture_info
[0],texture_info
[3]])
281 if texture_info
[2] == 'alpha' or texture_info
[2] == 'opacity':
282 texcoat
['alpha'].append([texture_info
[0], texture_info
[3]])
284 create_group_node
= True
287 coat3D
= bpy
.context
.scene
.coat3D
288 path3b_n
= coat3D
.exchangedir
289 path3b_n
+= ('%slast_saved_3b_file.txt' % (os
.sep
))
291 if (os
.path
.isfile(path3b_n
)):
292 export_file
= open(path3b_n
)
293 for line
in export_file
:
294 objekti
.coat3D
.applink_3b_path
= line
296 coat3D
.remove_path
= True
297 createnodes(index_mat
, texcoat
, create_group_node
, tile_list
, objekti
, ind
, is_new
)
299 def createnodes(active_mat
,texcoat
, create_group_node
, tile_list
, objekti
, ind
, is_new
): # Creates new nodes and link textures into them
300 bring_color
= True # Meaning of these is to check if we can only update textures or do we need to create new nodes
301 bring_metalness
= True
302 bring_roughness
= True
304 bring_displacement
= True
305 bring_emissive
= True
309 coat3D
= bpy
.context
.scene
.coat3D
310 coatMat
= active_mat
.material
312 if(coatMat
.use_nodes
== False):
313 coatMat
.use_nodes
= True
315 act_material
= coatMat
.node_tree
316 main_material
= coatMat
.node_tree
317 applink_group_node
= False
319 # First go through all image nodes and let's check if it starts with 3DC and reload if needed
321 for node
in coatMat
.node_tree
.nodes
:
322 if (node
.type == 'OUTPUT_MATERIAL'):
326 for node
in act_material
.nodes
:
327 if(node
.name
== '3DC_Applink' and node
.type == 'GROUP'):
328 applink_group_node
= True
329 act_material
= node
.node_tree
333 for node
in act_material
.nodes
:
334 if (node
.type != 'GROUP'):
335 if (node
.type != 'GROUP_OUTPUT'):
336 if (node
.type == 'TEX_IMAGE'):
337 if (node
.name
== '3DC_color'):
339 elif (node
.name
== '3DC_metalness'):
340 bring_metalness
= False
341 elif (node
.name
== '3DC_rough'):
342 bring_roughness
= False
343 elif (node
.name
== '3DC_nmap'):
345 elif (node
.name
== '3DC_displacement'):
346 bring_displacement
= False
347 elif (node
.name
== '3DC_emissive'):
348 bring_emissive
= False
349 elif (node
.name
== '3DC_AO'):
351 elif (node
.name
== '3DC_alpha'):
353 elif (node
.type == 'GROUP' and node
.name
.startswith('3DC_')):
354 if (node
.name
== '3DC_color'):
356 elif (node
.name
== '3DC_metalness'):
357 bring_metalness
= False
358 elif (node
.name
== '3DC_rough'):
359 bring_roughness
= False
360 elif (node
.name
== '3DC_nmap'):
362 elif (node
.name
== '3DC_displacement'):
363 bring_displacement
= False
364 elif (node
.name
== '3DC_emissive'):
365 bring_emissive
= False
366 elif (node
.name
== '3DC_AO'):
368 elif (node
.name
== '3DC_alpha'):
371 #Let's start to build new node tree. Let's start linking with Material Output
373 if(create_group_node
):
374 if(applink_group_node
== False):
375 main_mat2
= out_mat
.inputs
['Surface'].links
[0].from_node
376 for input_ind
in main_mat2
.inputs
:
377 if(input_ind
.is_linked
):
378 main_mat3
= input_ind
.links
[0].from_node
379 if(main_mat3
.type == 'BSDF_PRINCIPLED'):
382 group_tree
= bpy
.data
.node_groups
.new( type="ShaderNodeTree", name
="3DC_Applink")
383 group_tree
.outputs
.new("NodeSocketColor", "Color")
384 group_tree
.outputs
.new("NodeSocketColor", "Metallic")
385 group_tree
.outputs
.new("NodeSocketColor", "Roughness")
386 group_tree
.outputs
.new("NodeSocketVector", "Normal map")
387 group_tree
.outputs
.new("NodeSocketColor", "Emissive")
388 group_tree
.outputs
.new("NodeSocketColor", "Displacement")
389 group_tree
.outputs
.new("NodeSocketColor", "Emissive Power")
390 group_tree
.outputs
.new("NodeSocketColor", "AO")
391 group_tree
.outputs
.new("NodeSocketColor", "Alpha")
392 applink_tree
= act_material
.nodes
.new('ShaderNodeGroup')
393 applink_tree
.name
= '3DC_Applink'
394 applink_tree
.node_tree
= group_tree
395 applink_tree
.location
= -400, -100
396 act_material
= group_tree
397 notegroup
= act_material
.nodes
.new('NodeGroupOutput')
398 notegroup
.location
= 220, -260
400 if(texcoat
['emissive'] != []):
401 from_output
= out_mat
.inputs
['Surface'].links
[0].from_node
402 if(from_output
.type == 'BSDF_PRINCIPLED'):
403 add_shader
= main_material
.nodes
.new('ShaderNodeAddShader')
404 emission_shader
= main_material
.nodes
.new('ShaderNodeEmission')
406 emission_shader
.name
= '3DC_Emission'
408 add_shader
.location
= 420, 110
409 emission_shader
.location
= 70, -330
410 out_mat
.location
= 670, 130
412 main_material
.links
.new(from_output
.outputs
[0], add_shader
.inputs
[0])
413 main_material
.links
.new(add_shader
.outputs
[0], out_mat
.inputs
[0])
414 main_material
.links
.new(emission_shader
.outputs
[0], add_shader
.inputs
[1])
415 main_mat
= from_output
417 main_mat
= out_mat
.inputs
['Surface'].links
[0].from_node
420 main_mat
= out_mat
.inputs
['Surface'].links
[0].from_node
422 for node
in coatMat
.node_tree
.nodes
:
423 if (node
.type == 'GROUP' and node
.name
=='3DC_Applink'):
424 for in_node
in node
.node_tree
.nodes
:
425 if(in_node
.type == 'GROUP_OUTPUT'):
432 # READ DATA.JSON FILE
434 json_address
= os
.path
.dirname(bpy
.app
.binary_path
) + os
.sep
+ str(bpy
.app
.version
[0]) + '.' + str(bpy
.app
.version
[1]) + os
.sep
+ 'scripts' + os
.sep
+ 'addons' + os
.sep
+ 'io_coat3D' + os
.sep
+ 'data.json'
435 with
open(json_address
, encoding
='utf-8') as data_file
:
436 data
= json
.loads(data_file
.read())
438 if(out_mat
.inputs
['Surface'].is_linked
== True):
439 if(bring_color
== True and texcoat
['color'] != []):
440 CreateTextureLine(data
['color'], act_material
, main_mat
, texcoat
, coat3D
, notegroup
,
441 main_material
, applink_tree
, out_mat
, coatMat
, tile_list
, objekti
, ind
, is_new
)
443 if(bring_metalness
== True and texcoat
['metalness'] != []):
444 CreateTextureLine(data
['metalness'], act_material
, main_mat
, texcoat
, coat3D
, notegroup
,
445 main_material
, applink_tree
, out_mat
, coatMat
, tile_list
, objekti
, ind
, is_new
)
447 if(bring_roughness
== True and texcoat
['rough'] != []):
448 CreateTextureLine(data
['rough'], act_material
, main_mat
, texcoat
, coat3D
, notegroup
,
449 main_material
, applink_tree
, out_mat
, coatMat
,tile_list
, objekti
, ind
, is_new
)
451 if(bring_normal
== True and texcoat
['nmap'] != []):
452 CreateTextureLine(data
['nmap'], act_material
, main_mat
, texcoat
, coat3D
, notegroup
,
453 main_material
, applink_tree
, out_mat
, coatMat
, tile_list
, objekti
, ind
, is_new
)
455 if (bring_emissive
== True and texcoat
['emissive'] != []):
456 CreateTextureLine(data
['emissive'], act_material
, main_mat
, texcoat
, coat3D
, notegroup
,
457 main_material
, applink_tree
, out_mat
, coatMat
, tile_list
, objekti
, ind
, is_new
)
459 if (bring_displacement
== True and texcoat
['displacement'] != []):
460 CreateTextureLine(data
['displacement'], act_material
, main_mat
, texcoat
, coat3D
, notegroup
,
461 main_material
, applink_tree
, out_mat
, coatMat
, tile_list
, objekti
, ind
, is_new
)
462 if (bring_alpha
== True and texcoat
['alpha'] != []):
463 CreateTextureLine(data
['alpha'], act_material
, main_mat
, texcoat
, coat3D
, notegroup
,
464 main_material
, applink_tree
, out_mat
, coatMat
, tile_list
, objekti
, ind
, is_new
)
467 def CreateTextureLine(type, act_material
, main_mat
, texcoat
, coat3D
, notegroup
, main_material
, applink_tree
, out_mat
, coatMat
, tile_list
, objekti
, ind
, is_new
):
470 texture_name
= coatMat
.name
+ '_' + type['name']
471 texture_tree
= bpy
.data
.node_groups
.new(type="ShaderNodeTree", name
=texture_name
)
472 texture_tree
.outputs
.new("NodeSocketColor", "Color")
473 texture_tree
.outputs
.new("NodeSocketColor", "Alpha")
474 texture_node_tree
= act_material
.nodes
.new('ShaderNodeGroup')
475 texture_node_tree
.name
= '3DC_' + type['name']
476 texture_node_tree
.node_tree
= texture_tree
477 texture_node_tree
.location
[0] = type['node_location'][0]
478 texture_node_tree
.location
[0] -= 400
479 texture_node_tree
.location
[1] = type['node_location'][1]
480 notegroupend
= texture_tree
.nodes
.new('NodeGroupOutput')
482 count
= len(tile_list
)
483 uv_loc
= [-1400, 200]
484 map_loc
= [-1100, 200]
485 tex_loc
= [-700, 200]
486 mix_loc
= [-400, 100]
490 for index
, tile
in enumerate(tile_list
):
492 tex_img_node
= texture_tree
.nodes
.new('ShaderNodeTexImage')
494 for ind
, tex_index
in enumerate(texcoat
[type['name']]):
495 if(tex_index
[0] == tile
):
496 tex_img_node
.image
= bpy
.data
.images
.load(texcoat
[type['name']][ind
][1])
498 tex_img_node
.location
= tex_loc
500 if tex_img_node
.image
and type['colorspace'] != 'color':
501 tex_img_node
.image
.colorspace_settings
.is_data
= True
503 tex_uv_node
= texture_tree
.nodes
.new('ShaderNodeUVMap')
504 tex_uv_node
.location
= uv_loc
506 tex_uv_node
.uv_map
= objekti
.data
.uv_layers
[ind
].name
508 tex_uv_node
.uv_map
= objekti
.data
.uv_layers
[0].name
510 map_node
= texture_tree
.nodes
.new('ShaderNodeMapping')
511 map_node
.location
= map_loc
512 map_node
.name
= '3DC_' + tile
513 map_node
.vector_type
= 'TEXTURE'
515 tile_int_x
= int(tile
[3])
516 tile_int_y
= int(tile
[2])
518 min_node
= texture_tree
.nodes
.new('ShaderNodeVectorMath')
519 min_node
.operation
= "MINIMUM"
520 min_node
.inputs
[1].default_value
[0] = tile_int_x
- 1
521 min_node
.inputs
[1].default_value
[1] = tile_int_y
523 max_node
= texture_tree
.nodes
.new('ShaderNodeVectorMath')
524 max_node
.operation
= "MAXIMUM"
525 max_node
.inputs
[1].default_value
[0] = tile_int_x
526 max_node
.inputs
[1].default_value
[1] = tile_int_y
+ 1
530 nodes
.append(tex_img_node
.name
)
532 texture_tree
.links
.new(tex_img_node
.outputs
[0], notegroupend
.inputs
[0])
533 texture_tree
.links
.new(tex_img_node
.outputs
[1], notegroupend
.inputs
[1])
536 mix_node
= texture_tree
.nodes
.new('ShaderNodeMixRGB')
537 mix_node
.blend_type
= 'ADD'
538 mix_node
.inputs
[0].default_value
= 1
539 mix_node
.location
= mix_loc
541 texture_tree
.links
.new(tex_img_node
.outputs
[0], mix_node
.inputs
[2])
542 texture_tree
.links
.new(texture_tree
.nodes
[nodes
[0]].outputs
[0], mix_node
.inputs
[1])
543 mix_node_alpha
= texture_tree
.nodes
.new('ShaderNodeMath')
544 mix_node_alpha
.location
= mix_loc
546 texture_tree
.links
.new(tex_img_node
.outputs
[1], mix_node_alpha
.inputs
[1])
547 texture_tree
.links
.new(texture_tree
.nodes
[nodes
[0]].outputs
[1], mix_node_alpha
.inputs
[0])
549 nodes
.append(tex_img_node
.name
)
550 nodes
.append(mix_node
.name
)
551 nodes
.append(mix_node_alpha
.name
)
555 mix_node
= texture_tree
.nodes
.new('ShaderNodeMixRGB')
556 mix_node
.blend_type
= 'ADD'
557 mix_node
.inputs
[0].default_value
= 1
558 mix_node
.location
= mix_loc
560 texture_tree
.links
.new(texture_tree
.nodes
[nodes
[1]].outputs
[0], mix_node
.inputs
[1])
561 texture_tree
.links
.new(tex_img_node
.outputs
[0], mix_node
.inputs
[2])
562 mix_node_alpha
= texture_tree
.nodes
.new('ShaderNodeMath')
563 mix_node_alpha
.location
= mix_loc
565 texture_tree
.links
.new(texture_tree
.nodes
[nodes
[2]].outputs
[0], mix_node_alpha
.inputs
[0])
566 texture_tree
.links
.new(tex_img_node
.outputs
[1], mix_node_alpha
.inputs
[1])
569 nodes
.append(tex_img_node
.name
)
570 nodes
.append(mix_node
.name
)
571 nodes
.append(mix_node_alpha
.name
)
577 texture_tree
.links
.new(tex_uv_node
.outputs
[0], map_node
.inputs
[0])
578 texture_tree
.links
.new(map_node
.outputs
[0], min_node
.inputs
[0])
579 texture_tree
.links
.new(min_node
.outputs
['Vector'], max_node
.inputs
[0])
580 texture_tree
.links
.new(max_node
.outputs
['Vector'], tex_img_node
.inputs
[0])
583 texture_tree
.links
.new(mix_node
.outputs
[0], notegroupend
.inputs
[0])
584 texture_tree
.links
.new(mix_node_alpha
.outputs
[0], notegroupend
.inputs
[1])
587 node
= texture_node_tree
588 if(texcoat
['alpha'] != []):
589 if (type['name'] == 'color'):
590 act_material
.links
.new(node
.outputs
[1], notegroup
.inputs
[8])
592 if(type['name'] == 'alpha'):
593 act_material
.links
.new(node
.outputs
[1], notegroup
.inputs
[8])
597 node
= act_material
.nodes
.new('ShaderNodeTexImage')
598 uv_node
= act_material
.nodes
.new('ShaderNodeUVMap')
600 uv_node
.uv_map
= objekti
.data
.uv_layers
[0].name
601 act_material
.links
.new(uv_node
.outputs
[0], node
.inputs
[0])
602 uv_node
.use_custom_color
= True
603 uv_node
.color
= (type['node_color'][0], type['node_color'][1], type['node_color'][2])
605 node
.use_custom_color
= True
606 node
.color
= (type['node_color'][0],type['node_color'][1],type['node_color'][2])
609 if type['name'] == 'nmap':
610 normal_node
= act_material
.nodes
.new('ShaderNodeNormalMap')
611 normal_node
.use_custom_color
= True
612 normal_node
.color
= (type['node_color'][0], type['node_color'][1], type['node_color'][2])
614 node
.location
= -671, -510
616 uv_node
.location
= -750, -600
617 normal_node
.location
= -350, -350
618 normal_node
.name
= '3DC_normalnode'
620 elif type['name'] == 'displacement':
621 disp_node
= main_material
.nodes
.new('ShaderNodeDisplacement')
623 node
.location
= -630, -1160
624 disp_node
.location
= 90, -460
625 disp_node
.inputs
[2].default_value
= 0.1
626 disp_node
.name
= '3DC_dispnode'
628 node
.name
= '3DC_' + type['name']
629 node
.label
= type['name']
631 if (type['name'] != 'displacement'):
632 for input_index
in type['find_input']:
633 input_color
= main_mat
.inputs
.find(input_index
)
634 if(input_color
!= -1):
637 if (tile_list
== []):
641 for image
in bpy
.data
.images
:
642 if(texcoat
[type['name']][0] == image
.filepath
):
648 node
.image
= bpy
.data
.images
.load(texcoat
[type['name']][0])
650 if node
.image
and type['colorspace'] == 'noncolor':
651 node
.image
.colorspace_settings
.is_data
= True
653 if (coat3D
.createnodes
):
655 if(type['name'] == 'nmap'):
656 act_material
.links
.new(node
.outputs
[0], normal_node
.inputs
[1])
657 if(input_color
!= -1):
658 act_material
.links
.new(normal_node
.outputs
[0], main_mat
.inputs
[input_color
])
660 act_material
.links
.new(normal_node
.outputs
[0], notegroup
.inputs
[type['input']])
661 if (main_mat
.inputs
[input_color
].name
== 'Normal' and input_color
!= -1):
662 main_material
.links
.new(applink_tree
.outputs
[type['input']], main_mat
.inputs
[input_color
])
664 elif (type['name'] == 'displacement'):
666 rampnode
= act_material
.nodes
.new('ShaderNodeValToRGB')
667 rampnode
.name
= '3DC_ColorRamp'
668 rampnode
.use_custom_color
= True
669 rampnode
.color
= (type['node_color'][0], type['node_color'][1], type['node_color'][2])
670 rampnode
.location
= -270, -956
672 act_material
.links
.new(node
.outputs
[0], rampnode
.inputs
[0])
673 act_material
.links
.new(rampnode
.outputs
[0], notegroup
.inputs
[5])
675 main_material
.links
.new(applink_tree
.outputs
[5], disp_node
.inputs
[0])
676 main_material
.links
.new(disp_node
.outputs
[0], out_mat
.inputs
[2])
677 coatMat
.cycles
.displacement_method
= 'BOTH'
680 if (texcoat
['alpha'] != []):
681 if (type['name'] == 'alpha'):
682 act_material
.links
.new(node
.outputs
[1], notegroup
.inputs
[8])
684 if (type['name'] == 'color'):
685 act_material
.links
.new(node
.outputs
[1], notegroup
.inputs
[8])
686 if(type['name'] != 'alpha'):
687 huenode
= createExtraNodes(act_material
, node
, type, notegroup
)
690 huenode
.location
= -100, -800
692 if(type['name'] != 'alpha'):
693 act_material
.links
.new(huenode
.outputs
[0], notegroup
.inputs
[type['input']])
694 if (main_mat
.type != 'MIX_SHADER' and input_color
!= -1):
695 main_material
.links
.new(applink_tree
.outputs
[type['input']], main_mat
.inputs
[input_color
])
696 if(type['name'] == 'color'): #Alpha connection into Principled shader
697 main_material
.links
.new(applink_tree
.outputs
['Alpha'], main_mat
.inputs
['Alpha'])
700 location
= main_mat
.location
701 #applink_tree.location = main_mat.location[0], main_mat.location[1] + 200
703 if(type['name'] == 'emissive'):
704 for material
in main_material
.nodes
:
705 if(material
.name
== '3DC_Emission'):
706 main_material
.links
.new(applink_tree
.outputs
[type['input']], material
.inputs
[0])
709 uv_node
.location
= node
.location
710 uv_node
.location
[0] -= 300
711 uv_node
.location
[1] -= 200
714 node
.location
= type['node_location'][0], type['node_location'][1]
715 if (tile_list
== []):
716 uv_node
.location
= node
.location
717 uv_node
.location
[0] -= 300
718 act_material
.links
.new(node
.outputs
[0], notegroup
.inputs
[type['input']])
719 if (input_color
!= -1):
720 main_material
.links
.new(applink_tree
.outputs
[type['input']], main_mat
.inputs
[input_color
])
723 def createExtraNodes(act_material
, node
, type, notegroup
):
725 curvenode
= act_material
.nodes
.new('ShaderNodeRGBCurve')
726 curvenode
.name
= '3DC_RGBCurve'
727 curvenode
.use_custom_color
= True
728 curvenode
.color
= (type['node_color'][0], type['node_color'][1], type['node_color'][2])
730 if(type['huenode'] == 'yes'):
731 huenode
= act_material
.nodes
.new('ShaderNodeHueSaturation')
732 huenode
.name
= '3DC_HueSaturation'
733 huenode
.use_custom_color
= True
734 huenode
.color
= (type['node_color'][0], type['node_color'][1], type['node_color'][2])
736 huenode
= act_material
.nodes
.new('ShaderNodeMath')
737 huenode
.name
= '3DC_HueSaturation'
738 huenode
.operation
= 'MULTIPLY'
739 huenode
.inputs
[1].default_value
= 1
740 huenode
.use_custom_color
= True
741 huenode
.color
= (type['node_color'][0], type['node_color'][1], type['node_color'][2])
744 if(type['rampnode'] == 'yes'):
745 rampnode
= act_material
.nodes
.new('ShaderNodeValToRGB')
746 rampnode
.name
= '3DC_ColorRamp'
747 rampnode
.use_custom_color
= True
748 rampnode
.color
= (type['node_color'][0], type['node_color'][1], type['node_color'][2])
750 if (type['rampnode'] == 'yes'):
751 act_material
.links
.new(node
.outputs
[0], curvenode
.inputs
[1])
752 act_material
.links
.new(curvenode
.outputs
[0], rampnode
.inputs
[0])
753 if(type['huenode'] == 'yes'):
754 act_material
.links
.new(rampnode
.outputs
[0], huenode
.inputs
[4])
756 act_material
.links
.new(rampnode
.outputs
[0], huenode
.inputs
[0])
758 act_material
.links
.new(node
.outputs
[0], curvenode
.inputs
[1])
759 if (type['huenode'] == 'yes'):
760 act_material
.links
.new(curvenode
.outputs
[0], huenode
.inputs
[4])
762 act_material
.links
.new(curvenode
.outputs
[0], huenode
.inputs
[0])
764 if type['name'] == 'metalness':
765 node
.location
= -1300, 119
766 curvenode
.location
= -1000, 113
767 rampnode
.location
= -670, 115
768 huenode
.location
= -345, 118
770 elif type['name'] == 'rough':
771 node
.location
= -1300, -276
772 curvenode
.location
= -1000, -245
773 rampnode
.location
= -670, -200
774 huenode
.location
= -340, -100
776 elif type['name'] == 'color':
777 node
.location
= -990, 530
778 curvenode
.location
= -660, 480
779 huenode
.location
= -337, 335
781 elif type['name'] == 'emissive':
782 node
.location
= -1200, -900
783 curvenode
.location
= -900, -900
784 huenode
.location
= -340, -700
786 elif type['name'] == 'alpha':
787 node
.location
= -1200, -1200
788 curvenode
.location
= -900, -1250
789 rampnode
.location
= -600, -1200
790 huenode
.location
= -300, -1200
792 if(type['name'] == 'color'):
793 node_vertex
= act_material
.nodes
.new('ShaderNodeVertexColor')
794 node_mixRGB
= act_material
.nodes
.new('ShaderNodeMixRGB')
795 node_vectormath
= act_material
.nodes
.new('ShaderNodeVectorMath')
797 node_mixRGB
.blend_type
= 'MULTIPLY'
798 node_mixRGB
.inputs
[0].default_value
= 1
800 node_vectormath
.operation
= 'MULTIPLY'
801 node_vectormath
.inputs
[1].default_value
= [2,2,2]
803 node_vertex
.layer_name
= 'Col'
805 node_vertex
.location
= -337, 525
806 node_mixRGB
.location
= 0, 425
808 act_material
.links
.new(node_vertex
.outputs
[0], node_mixRGB
.inputs
[1])
809 act_material
.links
.new(huenode
.outputs
[0], node_mixRGB
.inputs
[2])
810 act_material
.links
.new(node_vertex
.outputs
[1], notegroup
.inputs
[8])
811 act_material
.links
.new(node_mixRGB
.outputs
[0], node_vectormath
.inputs
[0])
813 return node_vectormath
817 def matlab(objekti
,mat_list
,texturelist
,is_new
):
819 print('Welcome facture matlab function')
821 ''' FBX Materials: remove all nodes and create princibles node'''
823 RemoveFbxNodes(objekti
)
825 '''Main Loop for Texture Update'''
827 updatetextures(objekti
)
829 ''' Check if bind textures with UVs or Materials '''
831 if(texturelist
!= []):
833 udim_textures
= False
834 if texturelist
[0][0].startswith('100'):
837 if(udim_textures
== False):
838 readtexturefolder(objekti
,mat_list
,texturelist
,is_new
, udim_textures
)
840 path
= texturelist
[0][3]
841 only_name
= os
.path
.basename(path
)
842 if(only_name
.startswith(objekti
.coat3D
.applink_index
)):
843 readtexturefolder(objekti
, mat_list
, texturelist
, is_new
, udim_textures
)