From 4a0c61b46758759e87c3101b66f92f4c1a83ac4f Mon Sep 17 00:00:00 2001 From: Samuli Date: Sat, 18 Jul 2020 14:38:43 +0300 Subject: io_coat3D: version number updated --- io_coat3D/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py index 77318c74..666fddf5 100644 --- a/io_coat3D/__init__.py +++ b/io_coat3D/__init__.py @@ -19,7 +19,7 @@ bl_info = { "name": "3D-Coat Applink", "author": "Kalle-Samuli Riihikoski (haikalle)", - "version": (4, 9, 34), + "version": (5, 20, 20), "blender": (2, 80, 0), "location": "Scene > 3D-Coat Applink", "description": "Transfer data between 3D-Coat/Blender", -- cgit v1.2.3 From 809ee38132d51972972a084e202a132cbd8615c8 Mon Sep 17 00:00:00 2001 From: Samuli Date: Sun, 16 Aug 2020 08:25:41 +0300 Subject: io_coat3D: support for mac. ignores all types except MESH --- io_coat3D/__init__.py | 277 ++++++++++++++++++++++++++------------------------ 1 file changed, 145 insertions(+), 132 deletions(-) diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py index 666fddf5..5679f638 100644 --- a/io_coat3D/__init__.py +++ b/io_coat3D/__init__.py @@ -19,7 +19,7 @@ bl_info = { "name": "3D-Coat Applink", "author": "Kalle-Samuli Riihikoski (haikalle)", - "version": (5, 20, 20), + "version": (4, 9, 34), "blender": (2, 80, 0), "location": "Scene > 3D-Coat Applink", "description": "Transfer data between 3D-Coat/Blender", @@ -39,6 +39,7 @@ from io_coat3D import tex from io_coat3D import texVR import os +import platform import ntpath import re import shutil @@ -93,7 +94,7 @@ def set_exchange_folder(): platform = os.sys.platform coat3D = bpy.context.scene.coat3D - if(platform == 'win32'): + if(platform == 'win32' or platform == 'darwin'): exchange = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + 'Applinks' + os.sep + '3D-Coat' + os.sep +'Exchange' else: exchange = os.path.expanduser("~") + os.sep + '3D-CoatV4' + os.sep + 'Exchange' @@ -105,7 +106,7 @@ def set_exchange_folder(): if(os.path.isdir(exchange)): bpy.coat3D['status'] = 1 - if(platform == 'win32'): + if(platform == 'win32' or platform == 'darwin'): exchange_path = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' + os.sep + 'Exchange_folder.txt' applink_folder = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' @@ -144,7 +145,7 @@ def set_exchange_folder(): exchange = source else: - if(platform == 'win32'): + if(platform == 'win32' or platform == 'darwin'): exchange_path = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3DC2Blender' + os.sep + 'Exchange_folder.txt' else: exchange_path = os.path.expanduser("~") + os.sep + '3DC2Blender' + os.sep + 'Exchange_folder.txt' @@ -193,7 +194,7 @@ def set_working_folders(): platform = os.sys.platform coat3D = bpy.context.scene.coat3D - if(platform == 'win32'): + if(platform == 'win32' or platform == 'darwin'): if (coat3D.defaultfolder != '' and os.path.isdir(coat3D.defaultfolder)): return coat3D.defaultfolder else: @@ -379,7 +380,7 @@ class SCENE_OT_opencoat(bpy.types.Operator): coat3D = bpy.context.selected_objects[0].coat3D.applink_3b_path platform = os.sys.platform - if (platform == 'win32'): + if (platform == 'win32' or platform == 'darwin'): importfile = bpy.context.scene.coat3D.exchangedir importfile += ('%simport.txt' % (os.sep)) file = open(importfile, "w") @@ -653,13 +654,14 @@ class SCENE_OT_export(bpy.types.Operator): matindex = 0 for objekti in bpy.context.selected_objects: - objekti.name = '__' + objekti.name - if(objekti.material_slots.keys() == []): - newmat = bpy.data.materials.new('Material') - newmat.use_nodes = True - objekti.data.materials.append(newmat) - matindex += 1 - objekti.coat3D.applink_name = objekti.name + if objekti.type == 'MESH': + objekti.name = '__' + objekti.name + if(objekti.material_slots.keys() == []): + newmat = bpy.data.materials.new('Material') + newmat.use_nodes = True + objekti.data.materials.append(newmat) + matindex += 1 + objekti.coat3D.applink_name = objekti.name mod_mat_list = {} @@ -672,106 +674,107 @@ class SCENE_OT_export(bpy.types.Operator): temp_string = '' for objekti in bpy.context.selected_objects: - mod_mat_list[objekti.name] = [] - objekti.coat3D.applink_scale = objekti.scale - objekti.coat3D.retopo = False - - ''' Checks what materials are linked into UV ''' - - if(coat3D.type == 'ppp'): - final_material_indexs = [] - uvtiles_index = [] - for poly in objekti.data.polygons: - if(poly.material_index not in final_material_indexs): - final_material_indexs.append(poly.material_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 - - material_index = 0 - if (len(final_material_indexs) != len(objekti.material_slots)): - for material in objekti.material_slots: - if material_index not in final_material_indexs: - temp_mat = material.material - material.material = objekti.material_slots[0].material - mod_mat_list[objekti.name].append([material_index, temp_mat]) - material_index = material_index + 1 - - bake_list = [] - if(coat3D.bake_diffuse): - bake_list.append(['DIFFUSE', '$LOADTEX']) - if (coat3D.bake_ao): - bake_list.append(['AO', '$ExternalAO']) - if (coat3D.bake_normal): - bake_list.append(['NORMAL', '$LOADLOPOLYTANG']) - if (coat3D.bake_roughness): - bake_list.append(['ROUGHNESS', '$LOADROUGHNESS']) - - if(coat3D.bake_resolution == 'res_64'): - res_size = 64 - elif (coat3D.bake_resolution == 'res_128'): - res_size = 128 - elif (coat3D.bake_resolution == 'res_256'): - res_size = 256 - elif (coat3D.bake_resolution == 'res_512'): - res_size = 512 - elif (coat3D.bake_resolution == 'res_1024'): - res_size = 1024 - elif (coat3D.bake_resolution == 'res_2048'): - res_size = 2048 - elif (coat3D.bake_resolution == 'res_4096'): - res_size = 4096 - elif (coat3D.bake_resolution == 'res_8192'): - res_size = 8192 - - if(len(bake_list) > 0): - index_bake_tex = 0 - while(index_bake_tex < len(bake_list)): - bake_index = 0 - for bake_mat_index in final_material_indexs: - bake_node = objekti.material_slots[bake_mat_index].material.node_tree.nodes.new('ShaderNodeTexImage') - bake_node.name = 'ApplinkBake' + str(bake_index) - bpy.ops.image.new(name=bake_node.name, width=res_size, height=res_size) - bake_node.image = bpy.data.images[bake_node.name] - objekti.material_slots[bake_mat_index].material.node_tree.nodes.active = bake_node - - bake_index += 1 - if(bpy.context.scene.render.engine != 'CYCLES'): - bpy.context.scene.render.engine = 'CYCLES' - bpy.context.scene.render.bake.use_pass_direct = False - bpy.context.scene.render.bake.use_pass_indirect = False - bpy.context.scene.render.bake.use_pass_color = True - - bpy.ops.object.bake(type=bake_list[index_bake_tex][0], margin=1, width=res_size, height=res_size) - - bake_index = 0 - for bake_mat_index in final_material_indexs: - bake_image = 'ApplinkBake' + str(bake_index) - bpy.data.images[bake_image].filepath_raw = bake_location + os.sep + objekti.name + '_' + bake_image + '_' + bake_list[index_bake_tex][0] + ".png" - image_bake_name = bpy.data.images[bake_image].filepath_raw - tie = image_bake_name.split(os.sep) - toi = '' - for sana in tie: - toi += sana - toi += "/" - final_bake_name = toi[:-1] - bpy.data.images[bake_image].save() - temp_string += '''\n[script ImportTexture("''' + bake_list[index_bake_tex][1] + '''","''' + objekti.material_slots[bake_mat_index].material.name + '''","''' + final_bake_name + '''");]''' - - bake_index += 1 - + if objekti.type == 'MESH': + mod_mat_list[objekti.name] = [] + objekti.coat3D.applink_scale = objekti.scale + objekti.coat3D.retopo = False + + ''' Checks what materials are linked into UV ''' + + if(coat3D.type == 'ppp'): + final_material_indexs = [] + uvtiles_index = [] + for poly in objekti.data.polygons: + if(poly.material_index not in final_material_indexs): + final_material_indexs.append(poly.material_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 + + material_index = 0 + if (len(final_material_indexs) != len(objekti.material_slots)): for material in objekti.material_slots: - if material.material.use_nodes == True: - for node in material.material.node_tree.nodes: - if (node.name.startswith('ApplinkBake') == True): - material.material.node_tree.nodes.remove(node) - - for image in bpy.data.images: - if (image.name.startswith('ApplinkBake') == True): - bpy.data.images.remove(image) - - index_bake_tex += 1 + if material_index not in final_material_indexs: + temp_mat = material.material + material.material = objekti.material_slots[0].material + mod_mat_list[objekti.name].append([material_index, temp_mat]) + material_index = material_index + 1 + + bake_list = [] + if(coat3D.bake_diffuse): + bake_list.append(['DIFFUSE', '$LOADTEX']) + if (coat3D.bake_ao): + bake_list.append(['AO', '$ExternalAO']) + if (coat3D.bake_normal): + bake_list.append(['NORMAL', '$LOADLOPOLYTANG']) + if (coat3D.bake_roughness): + bake_list.append(['ROUGHNESS', '$LOADROUGHNESS']) + + if(coat3D.bake_resolution == 'res_64'): + res_size = 64 + elif (coat3D.bake_resolution == 'res_128'): + res_size = 128 + elif (coat3D.bake_resolution == 'res_256'): + res_size = 256 + elif (coat3D.bake_resolution == 'res_512'): + res_size = 512 + elif (coat3D.bake_resolution == 'res_1024'): + res_size = 1024 + elif (coat3D.bake_resolution == 'res_2048'): + res_size = 2048 + elif (coat3D.bake_resolution == 'res_4096'): + res_size = 4096 + elif (coat3D.bake_resolution == 'res_8192'): + res_size = 8192 + + if(len(bake_list) > 0): + index_bake_tex = 0 + while(index_bake_tex < len(bake_list)): + bake_index = 0 + for bake_mat_index in final_material_indexs: + bake_node = objekti.material_slots[bake_mat_index].material.node_tree.nodes.new('ShaderNodeTexImage') + bake_node.name = 'ApplinkBake' + str(bake_index) + bpy.ops.image.new(name=bake_node.name, width=res_size, height=res_size) + bake_node.image = bpy.data.images[bake_node.name] + objekti.material_slots[bake_mat_index].material.node_tree.nodes.active = bake_node + + bake_index += 1 + if(bpy.context.scene.render.engine != 'CYCLES'): + bpy.context.scene.render.engine = 'CYCLES' + bpy.context.scene.render.bake.use_pass_direct = False + bpy.context.scene.render.bake.use_pass_indirect = False + bpy.context.scene.render.bake.use_pass_color = True + + bpy.ops.object.bake(type=bake_list[index_bake_tex][0], margin=1, width=res_size, height=res_size) + + bake_index = 0 + for bake_mat_index in final_material_indexs: + bake_image = 'ApplinkBake' + str(bake_index) + bpy.data.images[bake_image].filepath_raw = bake_location + os.sep + objekti.name + '_' + bake_image + '_' + bake_list[index_bake_tex][0] + ".png" + image_bake_name = bpy.data.images[bake_image].filepath_raw + tie = image_bake_name.split(os.sep) + toi = '' + for sana in tie: + toi += sana + toi += "/" + final_bake_name = toi[:-1] + bpy.data.images[bake_image].save() + temp_string += '''\n[script ImportTexture("''' + bake_list[index_bake_tex][1] + '''","''' + objekti.material_slots[bake_mat_index].material.name + '''","''' + final_bake_name + '''");]''' + + bake_index += 1 + + for material in objekti.material_slots: + if material.material.use_nodes == True: + for node in material.material.node_tree.nodes: + if (node.name.startswith('ApplinkBake') == True): + material.material.node_tree.nodes.remove(node) + + for image in bpy.data.images: + if (image.name.startswith('ApplinkBake') == True): + bpy.data.images.remove(image) + + index_bake_tex += 1 #bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY') if(len(bpy.context.selected_objects) > 1 and coat3D.type != 'vox'): @@ -801,34 +804,44 @@ class SCENE_OT_export(bpy.types.Operator): file.close() for idx, objekti in enumerate(bpy.context.selected_objects): - objekti.name = objekti.name[2:] - if(len(bpy.context.selected_objects) == 1): - objekti.coat3D.applink_onlyone = True - 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 - objekti.coat3D.objecttime = str(os.path.getmtime(objekti.coat3D.applink_address)) - objekti.data.coat3D.name = '3DC' + if objekti.type == 'MESH': + objekti.name = objekti.name[2:] + if(len(bpy.context.selected_objects) == 1): + objekti.coat3D.applink_onlyone = True + objekti.coat3D.type = coat3D.type + objekti.coat3D.applink_mesh = True + objekti.coat3D.obj_mat = '' + objekti.coat3D.applink_index = ("3DC%.3d" % (object_index)) - if(coat3D.type != 'vox'): - if(objekti.material_slots.keys() != []): - for material in objekti.material_slots: - if material.material.use_nodes == True: - for node in material.material.node_tree.nodes: - if(node.name.startswith('3DC_') == True): - material.material.node_tree.nodes.remove(node) + objekti.coat3D.applink_firsttime = True + if(coat3D.type != 'autopo'): + objekti.coat3D.applink_address = coa.applink_address + objekti.coat3D.objecttime = str(os.path.getmtime(objekti.coat3D.applink_address)) + objekti.data.coat3D.name = '3DC' + + if(coat3D.type != 'vox'): + if(objekti.material_slots.keys() != []): + for material in objekti.material_slots: + if material.material.use_nodes == True: + for node in material.material.node_tree.nodes: + if(node.name.startswith('3DC_') == True): + material.material.node_tree.nodes.remove(node) +<<<<<<< HEAD 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] +======= + + 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] + +>>>>>>> 215ebd2a... io_coat3D: support for mac. ignores all types except MESH bpy.context.scene.render.engine = active_render return {'FINISHED'} -- cgit v1.2.3 From 6ba9c816f3d8b342633cce3f874876f19b19118e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 17 Aug 2020 12:00:46 +0200 Subject: Fix syntax error by resolving merge conflict --- io_coat3D/__init__.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py index 5679f638..574d9869 100644 --- a/io_coat3D/__init__.py +++ b/io_coat3D/__init__.py @@ -827,21 +827,11 @@ class SCENE_OT_export(bpy.types.Operator): if(node.name.startswith('3DC_') == True): material.material.node_tree.nodes.remove(node) -<<<<<<< HEAD - - 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] - -======= - 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] - ->>>>>>> 215ebd2a... io_coat3D: support for mac. ignores all types except MESH + bpy.context.scene.render.engine = active_render return {'FINISHED'} -- cgit v1.2.3