diff options
author | Kalle-Samuli Riihikoski <haikalle@gmail.com> | 2019-03-06 16:54:46 +0300 |
---|---|---|
committer | Kalle-Samuli Riihikoski <haikalle@gmail.com> | 2019-03-06 16:54:46 +0300 |
commit | 68867dbb2b2006411f3cdb87767756f768aaa561 (patch) | |
tree | bf68948ded8dc1f4fd18a79a98a30769742b9e47 /io_coat3D | |
parent | 7137867f34916113809d14923cc288223761fa01 (diff) |
support for udim textures and buttons for easily remove applink nodes
Diffstat (limited to 'io_coat3D')
-rw-r--r-- | io_coat3D/__init__.py | 298 | ||||
-rw-r--r-- | io_coat3D/data.json | 12 | ||||
-rw-r--r-- | io_coat3D/tex.py | 305 |
3 files changed, 505 insertions, 110 deletions
diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py index 315de893..d8d086f5 100644 --- a/io_coat3D/__init__.py +++ b/io_coat3D/__init__.py @@ -210,7 +210,7 @@ def make_texture_list(texturefolder): #Updating objects MESH part ( Mesh, Vertex Groups, Vertex Colors ) ''' -def updatemesh(objekti, proxy): +def updatemesh(objekti, proxy, texturelist): # Vertex colors if(len(proxy.data.vertex_colors) > 0): @@ -243,42 +243,35 @@ def updatemesh(objekti, proxy): # UV -Sets + udim_textures = False + if(texturelist[0][0].startswith('100')): + udim_textures =True + proxy.select_set(True) objekti.select_set(True) - Create_uv = True - if(len(proxy.data.uv_layers) > 0): - for proxy_layer in proxy.data.uv_layers: - for objekti_layer in objekti.data.uv_layers: - uv_new_name = '3DC_' + proxy_layer.name - if(objekti_layer.name == uv_new_name): - for poly in objekti.data.polygons: - for indi in poly.loop_indices: - objekti_layer.data[indi].uv[0] = proxy_layer.data[indi].uv[0] - objekti_layer.data[indi].uv[1] = proxy_layer.data[indi].uv[1] - Create_uv = False - break - if(Create_uv): - name = '3DC_' + proxy_layer.name - objekti.data.uv_layers.new(name=name) - for poly in objekti.data.polygons: - for indi in poly.loop_indices: - objekti.data.uv_layers[-1].data[indi].uv[0] = proxy_layer.data[indi].uv[0] - objekti.data.uv_layers[-1].data[indi].uv[1] = proxy_layer.data[indi].uv[1] + uv_count = len(proxy.data.uv_layers) + index = 0 + while(index < uv_count): + for poly in proxy.data.polygons: + for indi in poly.loop_indices: + if(proxy.data.uv_layers[index].data[indi].uv[0] != -1): + + if(udim_textures): + udim = proxy.data.uv_layers[index].name + udim_index = int(udim[2:]) - 1 + + objekti.data.uv_layers[0].data[indi].uv[0] = proxy.data.uv_layers[index].data[indi].uv[0] + objekti.data.uv_layers[0].data[indi].uv[1] = proxy.data.uv_layers[index].data[indi].uv[1] + if(udim_textures): + objekti.data.uv_layers[0].data[indi].uv[0] += udim_index + index = index + 1 # Mesh Copy for ind, v in enumerate(objekti.data.vertices): v.co = proxy.data.vertices[ind].co - ''' - proxy.select_set(True) - obj_data = objekti.data.id_data - objekti.data = proxy.data.id_data - objekti.data.id_data.name = obj_data.name - if (bpy.data.meshes[obj_data.name].users == 0): - bpy.data.meshes.remove(obj_data) - ''' def running(): n=0# number of instances of the program running prog=[line.split() for line in subprocess.check_output("tasklist").splitlines()] @@ -363,6 +356,170 @@ class SCENE_OT_opencoat(bpy.types.Operator): return {'FINISHED'} +def deleteNodes(type): + + deletelist = [] + deleteimages = [] + deletegroup =[] + delete_images = bpy.context.scene.coat3D.delete_images + + if type == 'Material': + if(len(bpy.context.selected_objects) == 1): + material = bpy.context.selected_objects[0].active_material + if(material.use_nodes): + for node in material.node_tree.nodes: + if(node.name.startswith('3DC')): + if (node.type == 'GROUP'): + deletegroup.append(node.node_tree.name) + deletelist.append(node.name) + if node.type == 'TEX_IMAGE' and delete_images == True: + deleteimages.append(node.image.name) + if deletelist: + for node in deletelist: + material.node_tree.nodes.remove(material.node_tree.nodes[node]) + if deleteimages: + for image in deleteimages: + bpy.data.images.remove(bpy.data.images[image]) + + elif type == 'Object': + if (len(bpy.context.selected_objects) > 0): + for objekti in bpy.context.selected_objects: + for material in objekti.material_slots: + if (material.material.use_nodes): + for node in material.material.node_tree.nodes: + if (node.name.startswith('3DC')): + if(node.type == 'GROUP'): + deletegroup.append(node.node_tree.name) + deletelist.append(node.name) + if node.type == 'TEX_IMAGE' and delete_images == True: + deleteimages.append(node.image.name) + if deletelist: + for node in deletelist: + material.material.node_tree.nodes.remove(material.material.node_tree.nodes[node]) + deletelist = [] + + if deleteimages: + for image in deleteimages: + bpy.data.images.remove(bpy.data.images[image]) + deleteimages = [] + + elif type == 'Collection': + for collection_object in bpy.context.view_layer.active_layer_collection.collection.all_objects: + if(collection_object.type == 'MESH'): + for material in collection_object.material_slots: + if (material.material.use_nodes): + for node in material.material.node_tree.nodes: + if (node.name.startswith('3DC')): + if (node.type == 'GROUP'): + deletegroup.append(node.node_tree.name) + deletelist.append(node.name) + if node.type == 'TEX_IMAGE' and delete_images == True: + deleteimages.append(node.image.name) + + if deletelist: + for node in deletelist: + material.material.node_tree.nodes.remove(material.material.node_tree.nodes[node]) + deletelist = [] + + if deleteimages: + for image in deleteimages: + bpy.data.images.remove(bpy.data.images[image]) + deleteimages = [] + + elif type == 'Scene': + for collection in bpy.data.collections: + for collection_object in collection.all_objects: + if (collection_object.type == 'MESH'): + for material in collection_object.material_slots: + if (material.material.use_nodes): + for node in material.material.node_tree.nodes: + if (node.name.startswith('3DC')): + if (node.type == 'GROUP'): + deletegroup.append(node.node_tree.name) + + deletelist.append(node.name) + if node.type == 'TEX_IMAGE' and delete_images == True: + deleteimages.append(node.image.name) + if deletelist: + for node in deletelist: + material.material.node_tree.nodes.remove(material.material.node_tree.nodes[node]) + deletelist = [] + + if deleteimages: + for image in deleteimages: + bpy.data.images.remove(bpy.data.images[image]) + deleteimages = [] + + if(deletelist): + for node in deletelist: + bpy.data.node_groups.remove(bpy.data.node_groups[node]) + + for image in bpy.data.images: + if (image.name.startswith('3DC') and image.name[6] == '_'): + deleteimages.append(image.name) + + + if(deletegroup): + for node in deletegroup: + bpy.data.node_groups.remove(bpy.data.node_groups[node]) + + if deleteimages: + for image in deleteimages: + bpy.data.images.remove(bpy.data.images[image]) + + + + + +''' DELETE NODES BUTTONS''' + +class SCENE_OT_delete_material_nodes(bpy.types.Operator): + bl_idname = "delete_material_nodes.pilgway_3d_coat" + bl_label = "Delete material nodes" + bl_description = "Delete material nodes" + bl_options = {'UNDO'} + + def invoke(self, context, event): + type = bpy.context.scene.coat3D.deleteMode = 'Material' + deleteNodes(type) + return {'FINISHED'} + +class SCENE_OT_delete_object_nodes(bpy.types.Operator): + bl_idname = "delete_object_nodes.pilgway_3d_coat" + bl_label = "Delete material nodes" + bl_description = "Delete material nodes" + bl_options = {'UNDO'} + + def invoke(self, context, event): + type = bpy.context.scene.coat3D.deleteMode = 'Object' + deleteNodes(type) + return {'FINISHED'} + +class SCENE_OT_delete_collection_nodes(bpy.types.Operator): + bl_idname = "delete_collection_nodes.pilgway_3d_coat" + bl_label = "Delete material nodes" + bl_description = "Delete material nodes" + bl_options = {'UNDO'} + + def invoke(self, context, event): + type = bpy.context.scene.coat3D.deleteMode = 'Collection' + deleteNodes(type) + return {'FINISHED'} + +class SCENE_OT_delete_scene_nodes(bpy.types.Operator): + bl_idname = "delete_scene_nodes.pilgway_3d_coat" + bl_label = "Delete material nodes" + bl_description = "Delete material nodes" + bl_options = {'UNDO'} + + def invoke(self, context, event): + type = bpy.context.scene.coat3D.deleteMode = 'Scene' + deleteNodes(type) + return {'FINISHED'} + + +''' TRANSFER AND UPDATE BUTTONS''' + class SCENE_OT_export(bpy.types.Operator): bl_idname = "export_applink.pilgway_3d_coat" bl_label = "Export your custom property" @@ -614,6 +771,8 @@ class SCENE_OT_export(bpy.types.Operator): objekti.coat3D.type = coat3D.type objekti.coat3D.applink_mesh = True objekti.coat3D.obj_mat = '' + objekti.coat3D.applink_index = ("3DC%.3d" % (object_index)) + objekti.coat3D.applink_firsttime = True if(coat3D.type != 'autopo'): objekti.coat3D.applink_address = coa.applink_address @@ -667,6 +826,16 @@ class SCENE_OT_import(bpy.types.Operator): bpy.data.materials.remove(material) + image_del_list = [] + for image in bpy.data.images: + if (image.name.startswith('3DC')): + if image.users == 0: + image_del_list.append(image.name) + + if (image_del_list != []): + for image in image_del_list: + bpy.data.images.remove(bpy.data.images[image]) + coat3D = bpy.context.scene.coat3D coat = bpy.coat3D coat3D.exchangedir = set_exchange_folder() @@ -850,7 +1019,7 @@ class SCENE_OT_import(bpy.types.Operator): for index, material in enumerate(objekti.material_slots): obj_proxy.material_slots[index-1].material = material.material - updatemesh(objekti,obj_proxy) + updatemesh(objekti,obj_proxy, texturelist) bpy.context.view_layer.objects.active = objekti @@ -1150,6 +1319,32 @@ class SCENE_PT_Settings_Folders(ObjectButtonsPanel, bpy.types.Panel): col = flow.column() col.prop(coat3D, "coat3D_exe", text="3D-Coat.exe") +class SCENE_PT_Settings_DeleteNodes(ObjectButtonsPanel, bpy.types.Panel): + bl_label = "Delete 3DC nodes from selected..." + bl_parent_id = "SCENE_PT_Settings" + COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'} + + def draw(self, context): + layout = self.layout + layout.use_property_split = False + coat3D = bpy.context.scene.coat3D + + layout.active = True + + flow = layout.grid_flow(row_major=True, columns=0, even_columns=False, even_rows=False, align=True) + + col = flow.column() + col.operator("delete_material_nodes.pilgway_3d_coat", text="Material") + + col.operator("delete_object_nodes.pilgway_3d_coat", text="Object(s)") + + col = flow.column() + col.operator("delete_collection_nodes.pilgway_3d_coat", text="Collection") + + col.operator("delete_scene_nodes.pilgway_3d_coat", text="Scene") + col = flow.column() + col.prop(coat3D, "delete_images", text="Delete nodes images") + # 3D-Coat Dynamic Menu @@ -1164,19 +1359,38 @@ class VIEW3D_MT_Coat_Dynamic_Menu(bpy.types.Menu): ob = context if ob.mode == 'OBJECT': if(len(context.selected_objects) > 0): - layout.operator("import_applink.pilgway_3d_coat", text="Update Scene") + layout.operator("import_applink.pilgway_3d_coat", + text="Update Scene") layout.separator() - layout.operator("export_applink.pilgway_3d_coat", text="Copy selected object(s) into 3D-Coat") + layout.operator("export_applink.pilgway_3d_coat", + text="Copy selected object(s) into 3D-Coat") layout.separator() + if(context.selected_objects[0].coat3D.applink_3b_path != ''): - layout.operator("open_3dcoat.pilgway_3d_coat", text="Open .3b file" +context.selected_objects[0].coat3D.applink_3b_just_name) + layout.operator("open_3dcoat.pilgway_3d_coat", + text="Open .3b file" +context.selected_objects[0].coat3D.applink_3b_just_name) layout.separator() else: - layout.operator("import_applink.pilgway_3d_coat", text="Update Scene") + layout.operator("import_applink.pilgway_3d_coat", + text="Update Scene") layout.separator() + if (len(context.selected_objects) > 0): + layout.operator("delete_material_nodes.pilgway_3d_coat", + text="Delete 3D-Coat nodes from active material") + + layout.operator("delete_object_nodes.pilgway_3d_coat", + text="Delete 3D-Coat nodes from selected obejcts") + + layout.operator("delete_object_nodes.pilgway_3d_coat", + text="Delete 3D-Coat nodes from active collection") + + layout.operator("delete_object_nodes.pilgway_3d_coat", + text="Delete all 3D-Coat nodes") + layout.separator() + class ObjectCoat3D(PropertyGroup): @@ -1188,6 +1402,9 @@ class ObjectCoat3D(PropertyGroup): applink_address: StringProperty( name="Object_Applink_address" ) + applink_index: StringProperty( + name="Object_Applink_address" + ) applink_3b_path: StringProperty( name="Object_3B_Path" ) @@ -1263,6 +1480,11 @@ class SceneCoat3D(PropertyGroup): name="FilePath", subtype="DIR_PATH", ) + deleteMode: StringProperty( + name="FilePath", + subtype="DIR_PATH", + default='' + ) coat3D_exe: StringProperty( name="FilePath", subtype="FILE_PATH", @@ -1280,6 +1502,11 @@ class SceneCoat3D(PropertyGroup): description="Allows to skip import dialog", default=False ) + delete_images: BoolProperty( + name="Import window", + description="Allows to skip import dialog", + default=True + ) bring_retopo_path: StringProperty( name="FilePath", subtype="DIR_PATH", @@ -1447,10 +1674,15 @@ classes = ( SCENE_PT_Settings_Update, SCENE_PT_Bake_Settings, SCENE_PT_Settings_Folders, + SCENE_PT_Settings_DeleteNodes, SCENE_OT_folder, SCENE_OT_opencoat, SCENE_OT_export, SCENE_OT_import, + SCENE_OT_delete_material_nodes, + SCENE_OT_delete_object_nodes, + SCENE_OT_delete_collection_nodes, + SCENE_OT_delete_scene_nodes, VIEW3D_MT_Coat_Dynamic_Menu, ObjectCoat3D, SceneCoat3D, diff --git a/io_coat3D/data.json b/io_coat3D/data.json index 0e3b846f..e6eccae1 100644 --- a/io_coat3D/data.json +++ b/io_coat3D/data.json @@ -15,7 +15,7 @@ "metalness": { "name": "metalness", - "colorspace": "color", + "colorspace": "noncolor", "normal": "no", "displacement": "no", "find_input": [ "Metallic" ], @@ -28,7 +28,7 @@ "rough": { "name": "rough", - "colorspace": "color", + "colorspace": "noncolor", "normal": "no", "displacement": "no", "find_input": [ "Roughness" ], @@ -55,11 +55,12 @@ "displacement": { "name": "displacement", - "colorspace": "color", + "colorspace": "noncolor", "normal": "no", "displacement": "yes", "rampnode": "yes", "huenode": "no", + "node_location": [ 100, 100 ], "input": 5, "node_color": [ 0.608, 0.591, 0.498 ] }, @@ -72,6 +73,7 @@ "find_input": [ "Emissive" ], "rampnode": "no", "huenode": "yes", + "node_location": [ 100, 100 ], "input": 4, "node_color": [ 0.0, 0.0, 0.0 ] }, @@ -83,16 +85,18 @@ "displacement": "no", "rampnode": "no", "huenode": "no", + "node_location": [ 100, 100 ], "node_color": [ 0.0, 0.0, 0.0 ] }, "ao": { "name": "ao", - "colorspace": "color", + "colorspace": "noncolor", "normal": "no", "displacement": "no", "rampnode": "yes", "huenode": "no", + "node_location": [ 100, 100 ], "node_color": [ 0.1, 0.5, 0.1 ] } diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py index 822f91d4..4b7b457c 100644 --- a/io_coat3D/tex.py +++ b/io_coat3D/tex.py @@ -46,32 +46,41 @@ def RemoveFbxNodes(objekti): Node_Tree.links.new(Prin_mat.outputs[0], output.inputs[0]) -def UVTiling(objekti, texturelist): - """ Checks what materials are linked into UV """ +def UVTiling(objekti, index, texturelist): + """ Checks what Tiles are linked with Material """ objekti.coat3D.applink_scale = objekti.scale - final_material_indexs = [] - uvtiles_index = [] - + tiles_index = [] + tile_number ='' for poly in objekti.data.polygons: - if (poly.material_index not in final_material_indexs): - final_material_indexs.append(poly.material_index) + if (poly.material_index == (index)): loop_index = poly.loop_indices[0] - uvtiles_index.append([poly.material_index, objekti.data.uv_layers.active.data[loop_index].uv[0]]) - if (len(final_material_indexs) == len(objekti.material_slots)): - break - - for texture_info in texturelist: - name = texture_info[0] - final_name = name[1:] - tiling_number = int(final_name) - - for list_tiles in uvtiles_index: - if(list_tiles[1] >= (tiling_number - 1) and list_tiles[1] <= tiling_number ): - texture_info[0] = objekti.material_slots[list_tiles[0]].material.name - break - - return texturelist + uv_x = objekti.data.uv_layers.active.data[loop_index].uv[0] + if(uv_x >= 0 and uv_x <=1): + tile_number = '1001' + elif (uv_x >= 1 and uv_x <= 2): + tile_number = '1002' + elif (uv_x >= 2 and uv_x <= 3): + tile_number = '1003' + elif (uv_x >= 3 and uv_x <= 4): + tile_number = '1004' + elif (uv_x >= 4 and uv_x <= 5): + tile_number = '1005' + elif (uv_x >= 5 and uv_x <= 6): + tile_number = '1006' + elif (uv_x >= 6 and uv_x <= 7): + tile_number = '1007' + elif (uv_x >= 7 and uv_x <= 8): + tile_number = '1008' + elif (uv_x >= 8 and uv_x <= 9): + tile_number = '1009' + elif (uv_x >= 9 and uv_x <= 10): + tile_number = '1010' + + if tile_number not in tiles_index: + tiles_index.append(tile_number) + + return tiles_index def updatetextures(objekti): # Update 3DC textures @@ -113,25 +122,28 @@ def updatetextures(objekti): # Update 3DC textures elif (node.name == '3DC_AO'): node.image.reload() +def link_material_into_uvset(objekti, material, material_index): -def readtexturefolder(objekti, mat_list, texturelist, is_new): #read textures from texture file + for layer in objekti.data.uv_layers: + for face in objekti.data.polygons: + for vert_idx, loop_idx in zip(face.vertices, face.loop_indices): + uv_coords = layer.data[loop_idx].uv - # Let's check are we UVSet or MATERIAL mode - uv_name = texturelist[0][0] - Main_mode = '' - for uv_set in objekti.data.uv_layers: - if(uv_name == uv_set.name): - Main_mode = uv_set.name - break +def readtexturefolder(objekti, mat_list, texturelist, is_new, udim_textures): #read textures from texture file + # Let's check are we UVSet or MATERIAL mode create_nodes = False - if texturelist[0][0].startswith('100'): - print('This is UVTiling') - texturelist = UVTiling(objekti, texturelist) - for index_mat in objekti.material_slots: + for ind, index_mat in enumerate(objekti.material_slots): + + active_uvset = link_material_into_uvset(objekti, index_mat, ind) + + if(udim_textures): + tile_list = UVTiling(objekti,ind, texturelist) + else: + tile_list = [] texcoat = {} texcoat['color'] = [] @@ -144,33 +156,66 @@ def readtexturefolder(objekti, mat_list, texturelist, is_new): #read textures fr texcoat['displacement'] = [] create_group_node = False - for texture_info in texturelist: - if texture_info[0] == index_mat.name: + if(udim_textures == False): + for texture_info in texturelist: + + if texture_info[0] == index_mat.name: + if texture_info[2] == 'color' or texture_info[2] == 'diffuse': + texcoat['color'].append(texture_info[3]) + create_nodes = True + elif texture_info[2] == 'metalness' or texture_info[2] == 'specular' or texture_info[2] == 'reflection': + texcoat['metalness'].append(texture_info[3]) + create_nodes = True + elif texture_info[2] == 'rough' or texture_info[2] == 'roughness': + texcoat['rough'].append(texture_info[3]) + create_nodes = True + elif texture_info[2] == 'nmap' or texture_info[2] == 'normalmap' or texture_info[2] == 'normal_map' or texture_info[2] == 'normal': + texcoat['nmap'].append(texture_info[3]) + create_nodes = True + elif texture_info[2] == 'emissive': + texcoat['emissive'].append(texture_info[3]) + create_nodes = True + elif texture_info[2] == 'emissive_power': + texcoat['emissive_power'].append(texture_info[3]) + create_nodes = True + elif texture_info[2] == 'ao': + texcoat['ao'].append(texture_info[3]) + create_nodes = True + elif texture_info[2].startswith('displacement'): + texcoat['displacement'].append(texture_info[3]) + create_nodes = True + create_group_node = True + else: + for texture_info in texturelist: + if texture_info[2] == 'color' or texture_info[2] == 'diffuse': - texcoat['color'].append(texture_info[3]) + texcoat['color'].append([texture_info[0],texture_info[3]]) create_nodes = True - elif texture_info[2] == 'metalness' or texture_info[2] == 'specular' or texture_info[2] == 'reflection': - texcoat['metalness'].append(texture_info[3]) + elif texture_info[2] == 'metalness' or texture_info[2] == 'specular' or texture_info[ + 2] == 'reflection': + texcoat['metalness'].append([texture_info[0],texture_info[3]]) create_nodes = True elif texture_info[2] == 'rough' or texture_info[2] == 'roughness': - texcoat['rough'].append(texture_info[3]) + texcoat['rough'].append([texture_info[0],texture_info[3]]) create_nodes = True - elif texture_info[2] == 'nmap' or texture_info[2] == 'normalmap' or texture_info[2] == 'normal_map' or texture_info[2] == 'normal': - texcoat['nmap'].append(texture_info[3]) + elif texture_info[2] == 'nmap' or texture_info[2] == 'normalmap' or texture_info[ + 2] == 'normal_map' or texture_info[2] == 'normal': + texcoat['nmap'].append([texture_info[0],texture_info[3]]) create_nodes = True elif texture_info[2] == 'emissive': - texcoat['emissive'].append(texture_info[3]) + texcoat['emissive'].append([texture_info[0],texture_info[3]]) create_nodes = True elif texture_info[2] == 'emissive_power': - texcoat['emissive_power'].append(texture_info[3]) + texcoat['emissive_power'].append([texture_info[0],texture_info[3]]) create_nodes = True elif texture_info[2] == 'ao': - texcoat['ao'].append(texture_info[3]) + texcoat['ao'].append([texture_info[0],texture_info[3]]) create_nodes = True elif texture_info[2].startswith('displacement'): - texcoat['displacement'].append(texture_info[3]) + texcoat['displacement'].append([texture_info[0],texture_info[3]]) create_nodes = True create_group_node = True + if(create_nodes): coat3D = bpy.context.scene.coat3D path3b_n = coat3D.exchangedir @@ -182,10 +227,11 @@ def readtexturefolder(objekti, mat_list, texturelist, is_new): #read textures fr objekti.coat3D.applink_3b_path = line export_file.close() coat3D.remove_path = True - createnodes(index_mat, texcoat, create_group_node) + createnodes(index_mat, texcoat, create_group_node, tile_list, objekti) -def createnodes(active_mat,texcoat, create_group_node): # Cretes new nodes and link textures into them + +def createnodes(active_mat,texcoat, create_group_node, tile_list, objekti): # Cretes new nodes and link textures into them bring_color = True # Meaning of these is to check if we can only update textures or do we need to create new nodes bring_metalness = True bring_roughness = True @@ -303,37 +349,135 @@ def createnodes(active_mat,texcoat, create_group_node): # Cretes new nodes and l if(out_mat.inputs['Surface'].is_linked == True): if(bring_color == True and texcoat['color'] != []): - CreateTextureLine(data['color'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat) + CreateTextureLine(data['color'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, tile_list, objekti) if(bring_metalness == True and texcoat['metalness'] != []): - CreateTextureLine(data['metalness'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat) + CreateTextureLine(data['metalness'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, tile_list, objekti) if(bring_roughness == True and texcoat['rough'] != []): - CreateTextureLine(data['rough'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat) + CreateTextureLine(data['rough'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat,tile_list, objekti) if(bring_normal == True and texcoat['nmap'] != []): - CreateTextureLine(data['nmap'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat) + CreateTextureLine(data['nmap'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, tile_list, objekti) if (bring_emissive == True and texcoat['emissive'] != []): - CreateTextureLine(data['emissive'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat) + CreateTextureLine(data['emissive'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, tile_list, objekti) if (bring_displacement == True and texcoat['displacement'] != []): CreateTextureLine(data['displacement'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, - applink_tree, out_mat, coatMat) + applink_tree, out_mat, coatMat, tile_list, objekti) -def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat): +def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, tile_list, objekti): - node = act_material.nodes.new('ShaderNodeTexImage') - uv_node = act_material.nodes.new('ShaderNodeUVMap') - uv_node.uv_map = '3DC_' + coatMat.name - act_material.links.new(uv_node.outputs[0], node.inputs[0]) + if(tile_list): + texture_name = coatMat.name + '_' + type['name'] + texture_tree = bpy.data.node_groups.new(type="ShaderNodeTree", name=texture_name) + texture_tree.outputs.new("NodeSocketColor", "Color") + texture_node_tree = act_material.nodes.new('ShaderNodeGroup') + texture_node_tree.name = '3DC_' + type['name'] + texture_node_tree.node_tree = texture_tree + texture_node_tree.location[0] = type['node_location'][0] + texture_node_tree.location[0] -= 400 + texture_node_tree.location[1] = type['node_location'][1] + notegroupend = texture_tree.nodes.new('NodeGroupOutput') - node.use_custom_color = True - uv_node.use_custom_color = True + count = len(tile_list) + uv_loc = [-1400, 200] + map_loc = [-1100, 200] + tex_loc = [-700, 200] + mix_loc = [-400, 100] + + nodes = [] + + for index, tile in enumerate(tile_list): + + tex_img_node = texture_tree.nodes.new('ShaderNodeTexImage') + + if(type['colorspace'] == 'color' ): + tex_img_node.color_space = 'COLOR' + else: + tex_img_node.color_space = 'NONE' + + + for ind, tex_index in enumerate(texcoat[type['name']]): + if(tex_index[0] == tile): + tex_img_node.image = bpy.data.images.load(texcoat[type['name']][ind][1]) + break + tex_img_node.location = tex_loc + + tex_uv_node = texture_tree.nodes.new('ShaderNodeUVMap') + tex_uv_node.location = uv_loc + tex_uv_node.uv_map = objekti.data.uv_layers[0].name + + map_node = texture_tree.nodes.new('ShaderNodeMapping') + map_node.location = map_loc + map_node.name = '3DC_' + tile + map_node.vector_type = 'TEXTURE' + map_node.use_min = True + map_node.use_max = True + + tile_int = int(tile[2:]) + + map_node.min[0] = tile_int - 1 + map_node.max[0] = tile_int + + + if(index == 0): + nodes.append(tex_img_node.name) + if(count == 1): + texture_tree.links.new(tex_img_node.outputs[0], notegroupend.inputs[0]) + + if(index > 0): + mix_node = texture_tree.nodes.new('ShaderNodeMixRGB') + mix_node.blend_type = 'ADD' + mix_node.inputs[0].default_value = 1 + mix_node.location = mix_loc + mix_loc[1] -= 300 + texture_tree.links.new(tex_img_node.outputs[0], mix_node.inputs[2]) + texture_tree.links.new(texture_tree.nodes[nodes[0]].outputs[0], mix_node.inputs[1]) + nodes.clear() + nodes.append(mix_node.name) + + + elif(index > 1): + mix_node = texture_tree.nodes.new('ShaderNodeMixRGB') + mix_node.blend_type = 'ADD' + mix_node.inputs[0].default_value = 1 + mix_node.location = mix_loc + mix_loc[1] -= 300 + texture_tree.links.new(texture_tree.nodes[nodes[0]].outputs[0], mix_node.inputs[1]) + texture_tree.links.new(tex_img_node.outputs[0], mix_node.inputs[2]) + nodes.clear() + nodes.append(tex_img_node.name) + nodes.append(mix_node.name) + + tex_loc[1] -= 300 + uv_loc[1] -= 300 + map_loc[1] -= 300 + + texture_tree.links.new(tex_uv_node.outputs[0], map_node.inputs[0]) + texture_tree.links.new(map_node.outputs[0], tex_img_node.inputs[0]) + + if(count > 1): + texture_tree.links.new(mix_node.outputs[0], notegroupend.inputs[0]) + + + if(tile_list): + node = texture_node_tree + + else: + node = act_material.nodes.new('ShaderNodeTexImage') + uv_node = act_material.nodes.new('ShaderNodeUVMap') + uv_node.uv_map = objekti.data.uv_layers[0].name + act_material.links.new(uv_node.outputs[0], node.inputs[0]) + uv_node.use_custom_color = True + uv_node.color = (type['node_color'][0], type['node_color'][1], type['node_color'][2]) + + node.use_custom_color = True node.color = (type['node_color'][0],type['node_color'][1],type['node_color'][2]) - uv_node.color = (type['node_color'][0], type['node_color'][1], type['node_color'][2]) + if type['name'] == 'nmap': normal_node = act_material.nodes.new('ShaderNodeNormalMap') @@ -341,7 +485,8 @@ def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, normal_node.color = (type['node_color'][0], type['node_color'][1], type['node_color'][2]) node.location = -671, -510 - uv_node.location = -750, -600 + if(tile_list == []): + uv_node.location = -750, -600 normal_node.location = -350, -350 normal_node.name = '3DC_normalnode' @@ -362,9 +507,10 @@ def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, if(input_color != -1): break - node.image = bpy.data.images.load(texcoat[type['name']][0]) - if(type['colorspace'] == 'noncolor'): - node.color_space = 'NONE' + if(tile_list == []): + node.image = bpy.data.images.load(texcoat[type['name']][0]) + if(type['colorspace'] == 'noncolor'): + node.color_space = 'NONE' if (coat3D.createnodes): @@ -408,15 +554,16 @@ def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, if(material.name == '3DC_Emission'): main_material.links.new(applink_tree.outputs[type['input']], material.inputs[0]) break - - uv_node.location = node.location - uv_node.location[0] -= 300 - uv_node.location[1] -= 200 + if(tile_list == []): + uv_node.location = node.location + uv_node.location[0] -= 300 + uv_node.location[1] -= 200 else: node.location = type['node_location'][0], type['node_location'][1] - uv_node.location = node.location - uv_node.location[0] -= 300 + if (tile_list == []): + uv_node.location = node.location + uv_node.location[0] -= 300 act_material.links.new(node.outputs[0], notegroup.inputs[type['input']]) if (input_color != -1): main_material.links.new(applink_tree.outputs[type['input']], main_mat.inputs[input_color]) @@ -496,6 +643,18 @@ def matlab(objekti,mat_list,texturelist,is_new): updatetextures(objekti) if(texturelist != []): - readtexturefolder(objekti,mat_list,texturelist,is_new) + udim_textures = False + if texturelist[0][0].startswith('100'): + udim_textures = True + + if(udim_textures == False): + + readtexturefolder(objekti,mat_list,texturelist,is_new, udim_textures) + else: + path = texturelist[0][3] + only_name = os.path.basename(path) + if(only_name.startswith(objekti.coat3D.applink_index)): + readtexturefolder(objekti, mat_list, texturelist, is_new, udim_textures) + return('FINISHED') |