diff options
author | Samuli Riihikoski <haikalle@gmail.com> | 2020-09-14 18:45:43 +0300 |
---|---|---|
committer | Samuli Riihikoski <haikalle@gmail.com> | 2020-09-14 18:45:43 +0300 |
commit | 6f1fed19af91ce42ad43640703ad34786e299460 (patch) | |
tree | b1df9e45d61aaffc7ae0088eda8f916ee58ef9ca | |
parent | b0405252fac848d6ecf3b599bfd6d7736def4066 (diff) |
io_coat3D: Improve udim workflow
-rw-r--r-- | io_coat3D/__init__.py | 59 | ||||
-rw-r--r-- | io_coat3D/tex.py | 86 |
2 files changed, 87 insertions, 58 deletions
diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py index 574d9869..5b6006e8 100644 --- a/io_coat3D/__init__.py +++ b/io_coat3D/__init__.py @@ -140,7 +140,7 @@ def set_exchange_folder(): file.write("%s"%(coat3D.exchangedir)) file.close() exchange = coat3D.exchangedir - + else: exchange = source @@ -293,16 +293,18 @@ def updatemesh(objekti, proxy, texturelist): 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] - + index = index + 1 # Mesh Copy if(proxy.name.startswith('RetopoGroup')): objekti.data = proxy.data else: + print('objekti: ' + str(len(objekti.data.vertices))) + print('proxy: ' + str(len(proxy.data.vertices))) for ind, v in enumerate(objekti.data.vertices): v.co = proxy.data.vertices[ind].co @@ -313,11 +315,11 @@ class SCENE_OT_getback(bpy.types.Operator): bl_options = {'UNDO'} def invoke(self, context, event): - + global global_exchange_folder global initial_settings path_ex = '' - + if(initial_settings): global_exchange_folder = set_exchange_folder() initial_settings = False @@ -327,29 +329,29 @@ class SCENE_OT_getback(bpy.types.Operator): BlenderFolder = Blender_folder ExportFolder = Export_folder - + Blender_folder += ('%sexport.txt' % (os.sep)) Export_folder += ('%sexport.txt' % (os.sep)) - + if (bpy.app.background == False): if os.path.isfile(Export_folder): print('BLENDER -> 3DC -> BLENDER WORKFLLOW') - DeleteExtra3DC() + DeleteExtra3DC() workflow1(ExportFolder) removeFile(Export_folder) - removeFile(Blender_folder) - - - + removeFile(Blender_folder) + + + elif os.path.isfile(Blender_folder): print('3DC -> BLENDER WORKFLLOW') - DeleteExtra3DC() + DeleteExtra3DC() workflow2(BlenderFolder) removeFile(Blender_folder) - - + + return {'FINISHED'} @@ -577,7 +579,7 @@ class SCENE_OT_export(bpy.types.Operator): def invoke(self, context, event): bpy.ops.export_applink.pilgway_3d_coat() - + return {'FINISHED'} def execute(self, context): @@ -827,11 +829,12 @@ class SCENE_OT_export(bpy.types.Operator): if(node.name.startswith('3DC_') == True): material.material.node_tree.nodes.remove(node) + for ind, mat_list in enumerate(mod_mat_list): if(mat_list == '__' + objekti.name): for ind, mat in enumerate(mod_mat_list[mat_list]): objekti.material_slots[mod_mat_list[mat_list][ind][0]].material = mod_mat_list[mat_list][ind][1] - + bpy.context.scene.render.engine = active_render return {'FINISHED'} @@ -858,7 +861,7 @@ def DeleteExtra3DC(): bpy.data.images.remove(del_img) bpy.data.materials.remove(material) - + image_del_list = [] for image in bpy.data.images: if (image.name.startswith('3DC')): @@ -937,7 +940,7 @@ def new_ref_function(new_applink_address, nimi): def blender_3DC_blender(texturelist): - + coat3D = bpy.context.scene.coat3D old_materials = bpy.data.materials.keys() @@ -1089,7 +1092,7 @@ def blender_3DC_blender(texturelist): #delete_materials_from_end(keep_materials_count, obj_proxy) - + updatemesh(objekti,obj_proxy, texturelist) bpy.context.view_layer.objects.active = objekti @@ -1216,7 +1219,7 @@ def blender_3DC(texturelist, new_applink_address): old_materials = bpy.data.materials.keys() old_objects = bpy.data.objects.keys() - + bpy.ops.import_scene.fbx(filepath=new_applink_address, global_scale = 1, axis_forward='-Z', axis_up='Y') new_materials = bpy.data.materials.keys() @@ -1291,7 +1294,7 @@ def blender_3DC(texturelist, new_applink_address): os.remove(Blender_export) if (os.path.isfile(Blender_folder2)): os.remove(Blender_folder2) - + for material in bpy.data.materials: if material.use_nodes == True: for node in material.node_tree.nodes: @@ -1312,9 +1315,9 @@ def workflow1(ExportFolder): for image in bpy.data.images: if(image.filepath == texturepath[3] and image.users == 0): bpy.data.images.remove(image) - + path3b_now = coat3D.exchangedir - + path3b_now += ('last_saved_3b_file.txt') new_applink_address = 'False' new_object = False @@ -1338,7 +1341,7 @@ def workflow1(ExportFolder): new_ref_object = True nimi = scene_objects.name - + exportfile = coat3D.exchangedir @@ -1371,9 +1374,9 @@ def workflow2(BlenderFolder): kokeilu = coat3D.exchangedir Blender_export = os.path.join(kokeilu, 'Blender') - + path3b_now = coat3D.exchangedir - + path3b_now += ('last_saved_3b_file.txt') Blender_export += ('%sexport.txt'%(os.sep)) new_applink_address = 'False' @@ -2061,7 +2064,7 @@ def register(): bpy.types.Object.coat3D = PointerProperty(type=ObjectCoat3D) bpy.types.Scene.coat3D = PointerProperty(type=SceneCoat3D) bpy.types.Mesh.coat3D = PointerProperty(type=MeshCoat3D) - bpy.types.Material.coat3D = PointerProperty(type=MaterialCoat3D) + bpy.types.Material.coat3D = PointerProperty(type=MaterialCoat3D) kc = bpy.context.window_manager.keyconfigs.addon diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py index 21fa92b3..2a2fbd9a 100644 --- a/io_coat3D/tex.py +++ b/io_coat3D/tex.py @@ -128,26 +128,26 @@ def updatetextures(objekti): # Update 3DC textures def testi(objekti, texture_info, index_mat_name, uv_MODE_mat, mat_index): if uv_MODE_mat == 'UV': - + uv_set_founded = False for uvset in objekti.data.uv_layers: - + if(uvset.name == texture_info): uv_set_founded = True - + break - + if(uv_set_founded): for uv_poly in objekti.data.uv_layers[texture_info].id_data.polygons: if(mat_index == uv_poly.material_index): return True else: return False - + elif uv_MODE_mat == 'MAT': return (texture_info == index_mat_name) -def readtexturefolder(objekti, mat_list, texturelist, is_new, udim_textures): #read textures from texture file +def readtexturefolder(objekti, mat_list, texturelist, is_new, udim_textures, udim_len): #read textures from texture file # Let's check are we UVSet or MATERIAL modee create_nodes = False @@ -168,17 +168,17 @@ def readtexturefolder(objekti, mat_list, texturelist, is_new, udim_textures): #r if(udim_textures == False): for slot_index, texture_info in enumerate(texturelist): - uv_MODE_mat = 'MAT' + uv_MODE_mat = 'MAT' for index, layer in enumerate(objekti.data.uv_layers): if(layer.name == texturelist[slot_index][0]): uv_MODE_mat = 'UV' break - + if(testi(objekti, texturelist[slot_index][0], index_mat.name, uv_MODE_mat, ind)) : if texture_info[2] == 'color' or texture_info[2] == 'diffuse': if(index_mat.material.coat3D_diffuse): - + texcoat['color'].append(texture_info[3]) create_nodes = True else: @@ -241,7 +241,7 @@ def readtexturefolder(objekti, mat_list, texturelist, is_new, udim_textures): #r os.remove(texture_info[3]) create_group_node = True - + else: for texture_info in texturelist: @@ -297,9 +297,9 @@ def readtexturefolder(objekti, mat_list, texturelist, is_new, udim_textures): #r objekti.coat3D.applink_3b_path = line export_file.close() coat3D.remove_path = True - createnodes(index_mat, texcoat, create_group_node, objekti, ind, is_new, udim_textures) + createnodes(index_mat, texcoat, create_group_node, objekti, ind, is_new, udim_textures, udim_len) -def createnodes(active_mat,texcoat, create_group_node, objekti, ind, is_new, udim_textures): # Creates new nodes and link textures into them +def createnodes(active_mat,texcoat, create_group_node, objekti, ind, is_new, udim_textures, udim_len): # Creates 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 @@ -444,33 +444,33 @@ def createnodes(active_mat,texcoat, create_group_node, objekti, ind, is_new, udi 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, objekti, ind, is_new, udim_textures) + main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures, udim_len) if(bring_metalness == True and texcoat['metalness'] != []): CreateTextureLine(data['metalness'], act_material, main_mat, texcoat, coat3D, notegroup, - main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures) + main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures, udim_len) if(bring_roughness == True and texcoat['rough'] != []): CreateTextureLine(data['rough'], act_material, main_mat, texcoat, coat3D, notegroup, - main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures) + main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures, udim_len) if(bring_normal == True and texcoat['nmap'] != []): CreateTextureLine(data['nmap'], act_material, main_mat, texcoat, coat3D, notegroup, - main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures) + main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures, udim_len) if (bring_emissive == True and texcoat['emissive'] != []): CreateTextureLine(data['emissive'], act_material, main_mat, texcoat, coat3D, notegroup, - main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures) + main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures, udim_len) if (bring_displacement == True and texcoat['displacement'] != []): CreateTextureLine(data['displacement'], act_material, main_mat, texcoat, coat3D, notegroup, - main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures) + main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures, udim_len) if (bring_alpha == True and texcoat['alpha'] != []): CreateTextureLine(data['alpha'], act_material, main_mat, texcoat, coat3D, notegroup, - main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures) + main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures, udim_len) -def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures): +def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, objekti, ind, is_new, udim_textures, udim_len): node = act_material.nodes.new('ShaderNodeTexImage') uv_node = act_material.nodes.new('ShaderNodeUVMap') @@ -516,21 +516,36 @@ def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, load_image = True for image in bpy.data.images: - + if(texcoat[type['name']][0] == image.filepath): + load_image = False node.image = image - + + if(udim_textures): + node.image.source = 'TILED' + for udim_index in udim_len: + if (udim_index != 1001): + image.tiles.new(udim_index) + + node.image.reload() + break if (load_image): - print('load_image', texcoat[type['name']][0]) - + node.image = bpy.data.images.load(texcoat[type['name']][0]) - if(udim_textures): - node.image.source = 'TILED' + if(udim_textures): + node.image.source = 'TILED' + + for udim_index in udim_len: + if (udim_index != 1001): + image.tiles.new(udim_index) + + + if node.image and type['colorspace'] == 'noncolor': node.image.colorspace_settings.is_data = True @@ -589,7 +604,7 @@ 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 @@ -688,18 +703,29 @@ def matlab(objekti,mat_list,texturelist,is_new): ''' Check if bind textures with UVs or Materials ''' if(texturelist != []): - + udim_textures = False + udim_count = 0 + udim_indexs = [] + if texturelist[0][0].startswith('100') and len(texturelist[0][0]) == 4: udim_textures = True + + udim_target = '' + udim_target = texturelist[0][2] + for texture in texturelist: + if texture[2] == udim_target: + udim_indexs.append(int(texture[0])) + + udim_indexs.sort() if(udim_textures == False): - readtexturefolder(objekti,mat_list,texturelist,is_new, udim_textures) + readtexturefolder(objekti,mat_list,texturelist,is_new, udim_textures, udim_indexs) 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) + readtexturefolder(objekti, mat_list, texturelist, is_new, udim_textures, udim_indexs) return('FINISHED') |