diff options
author | Kalle-Samuli Riihikoski <haikalle@gmail.com> | 2018-11-12 14:00:03 +0300 |
---|---|---|
committer | Kalle-Samuli Riihikoski <haikalle@gmail.com> | 2018-11-12 14:00:03 +0300 |
commit | fef76df87cbf6058fd19c87f643755ca05cbe08b (patch) | |
tree | ab3ae9a2fa35a136d65bf6801a4e111952c2162e /io_coat3D | |
parent | a4d7aa618baa4c4b6f0b567f988efb0831956f6e (diff) |
MAterial bug fixed
Diffstat (limited to 'io_coat3D')
-rw-r--r-- | io_coat3D/__init__.py | 149 | ||||
-rw-r--r-- | io_coat3D/tex.py | 10 |
2 files changed, 75 insertions, 84 deletions
diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py index 8f62d4b4..cb6202ee 100644 --- a/io_coat3D/__init__.py +++ b/io_coat3D/__init__.py @@ -194,15 +194,15 @@ def updatemesh(objekti, proxy): if(objekti.vertex_groups.keys() != []): bpy.ops.object.select_all(action='DESELECT') - proxy.select_set(True) - objekti.select_set(True) + proxy.select_set('SELECT') + objekti.select_set('SELECT') bpy.ops.object.vertex_group_copy_to_selected() bpy.ops.object.select_all(action='DESELECT') # UV Set Copy - proxy.select_set(True) - objekti.select_set(True) + proxy.select_set('SELECT') + objekti.select_set('SELECT') if len(objekti.data.uv_layers) > 1: obj_uv_index = objekti.data.uv_layers.active_index @@ -220,51 +220,13 @@ def updatemesh(objekti, proxy): #Mesh Copy - proxy.select_set(True) + proxy.select_set('SELECT') 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) - - -class SCENE_PT_Main(bpy.types.Panel): - bl_label = "3D-Coat Applink" - bl_space_type = "VIEW_3D" - bl_region_type = "TOOLS" - bl_context = "objectmode" - bl_options = {'DEFAULT_CLOSED'} - - def draw(self, context): - layout = self.layout - coat = bpy.coat3D - coat3D = bpy.context.scene.coat3D - if(bpy.context.active_object): - coa = bpy.context.active_object.coat3D - - if(coat['status'] == 0): - row = layout.row() - row.label(text="Applink didn't find your 3d-Coat/Excahnge folder.") - row = layout.row() - row.label("Please select it before using Applink.") - row = layout.row() - row.prop(coat3D,"exchangedir",text="") - row = layout.row() - row.operator("update_exchange_folder.pilgway_3d_coat", text="Apply folder") - - else: - #Here you add your GUI - row = layout.row() - row.prop(coat3D,"type",text = "") - row = layout.row() - colL = row.column() - colR = row.column() - - colR.operator("export_applink.pilgway_3d_coat", text="Transfer") - colL.operator("import_applink.pilgway_3d_coat", text="Update") - - def running(): n=0# number of instances of the program running prog=[line.split() for line in subprocess.check_output("tasklist").splitlines()] @@ -397,8 +359,8 @@ class SCENE_OT_export(bpy.types.Operator): object_index = 0 while(looking == True): - checkname = folder_objects + os.sep + activeobj - checkname = ("%s%.2d.fbx"%(checkname,object_index)) + checkname = folder_objects + os.sep + "3DC" + checkname = ("%s%.3d.fbx"%(checkname,object_index)) if(os.path.isfile(checkname)): object_index += 1 else: @@ -407,12 +369,23 @@ class SCENE_OT_export(bpy.types.Operator): coa.applink_address = checkname matindex = 0 + name_list = [] + for objekti in bpy.context.selected_objects: if(objekti.material_slots.keys() == []): newmat = bpy.data.materials.new('Material') newmat.use_nodes = True objekti.data.materials.append(newmat) matindex += 1 + name_list.append(objekti.data.name) + new_name = objekti.data.name + name_boxs = new_name.split('.') + if(len(name_boxs)>1): + objekti.name = name_boxs[0] + name_boxs[1] + objekti.data.name = name_boxs[0] + name_boxs[1] + else: + objekti.name = name_boxs[0] + objekti.data.name = name_boxs[0] for objekti in bpy.context.selected_objects: objekti.coat3D.applink_scale = objekti.scale @@ -433,7 +406,7 @@ class SCENE_OT_export(bpy.types.Operator): file.close() group_index = -1.0 - for objekti in bpy.context.selected_objects: + for idx, objekti in enumerate(bpy.context.selected_objects): nimi = '' for koko in bpy.context.selected_objects: nimi += koko.data.name + ':::' @@ -566,40 +539,16 @@ class SCENE_OT_import(bpy.types.Operator): objekti = bpy.data.objects[oname] if(objekti.coat3D.import_mesh and coat3D.importmesh == True): objekti.coat3D.import_mesh = False - objekti.select_set(True) + objekti.select_set('SELECT') new_name = objekti.data.name name_boxs = new_name.split('.') - if len(name_boxs) > 1: - if len(name_boxs[-1]) == 3: - luku = int(name_boxs[-1]) - luku +=1 - uusi_nimi = ("%s.%.3d" % (new_name[:-4], luku)) - find_name = uusi_nimi - else: - find_name = objekti.data.name - tosi = True - luku = 1 - find_name = ("%s.%.3d" % (objekti.data.name, luku)) - loyty = False - while tosi: - for obj in bpy.data.meshes: - if (obj.name == find_name): - loyty = True - break - if(loyty == True): - luku += 1 - find_name = ("%s.%.3d" % (objekti.data.name, luku)) - loyty = False - else: - find_name = ("%s.%.3d" % (objekti.data.name, luku-1)) - tosi = False - - for proxy_objects in diff_objects: - if (bpy.data.objects[proxy_objects].data.name == find_name): + print('diff_objects: ', diff_objects) + for idx, proxy_objects in enumerate(diff_objects): + print('proxy_object', proxy_objects) + if (proxy_objects.startswith(name_boxs[0])): obj_proxy = bpy.data.objects[proxy_objects] break - exportfile = coat3D.exchangedir path3b_n = coat3D.exchangedir path3b_n += ('last_saved_3b_file.txt') @@ -627,7 +576,7 @@ class SCENE_OT_import(bpy.types.Operator): mat_list.append(obj_mat.material) bpy.ops.object.select_all(action='DESELECT') - obj_proxy.select_set(True) + obj_proxy.select_set('SELECT') bpy.ops.object.select_all(action='TOGGLE') @@ -650,7 +599,7 @@ class SCENE_OT_import(bpy.types.Operator): #tärkee että saadaan oikein käännettyä objekt - objekti.select_set(True) + objekti.select_set('SELECT') bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN') objekti.data.materials.pop() @@ -675,14 +624,14 @@ class SCENE_OT_import(bpy.types.Operator): if(coat3D.importmesh and not(os.path.isfile(objekti.coat3D.applink_address))): coat3D.importmesh = False - objekti.select_set(True) + objekti.select_set('SELECT') if(coat3D.importtextures): is_new = False print('matlist: ', mat_list) print('objekti: ', objekti) print('is_new: ', is_new) tex.matlab(objekti,mat_list,texturelist,is_new) - objekti.select_set(False) + objekti.select_set('DESELECT') else: mat_list = [] @@ -696,13 +645,13 @@ class SCENE_OT_import(bpy.types.Operator): print('objekti: ', objekti) print('is_new: ', is_new) tex.matlab(objekti,mat_list,texturelist, is_new) - objekti.select_set(False) + objekti.select_set('DESELECT') bpy.ops.object.select_all(action='DESELECT') if(import_list): for del_obj in diff_objects: - bpy.context.collection.all_objects[del_obj].select_set(True) + bpy.context.collection.all_objects[del_obj].select_set('SELECT') bpy.ops.object.delete() @@ -760,12 +709,12 @@ class SCENE_OT_import(bpy.types.Operator): if(new_obj.coat3D.applink_old == False): nimi += new_obj.data.name + ':::' - new_obj.select_set(True) + new_obj.select_set('SELECT') #bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN') new_obj.rotation_euler = (0, 0, 0) new_obj.scale = (1, 1, 1) new_obj.coat3D.applink_firsttime = False - new_obj.select_set(False) + new_obj.select_set('DESELECT') new_obj.coat3D.applink_address = new_applink_address new_obj.coat3D.objecttime = str(os.path.getmtime(new_obj.coat3D.applink_address)) splittext = ntpath.basename(new_applink_address) @@ -800,6 +749,40 @@ class SCENE_OT_import(bpy.types.Operator): from bpy import * from mathutils import Vector, Matrix +class SCENE_PT_Main(bpy.types.Panel): + bl_label = "3D-Coat Applink" + bl_space_type = "VIEW_3D" + bl_region_type = "TOOLS" + bl_context = "objectmode" + bl_options = {'DEFAULT_CLOSED'} + + def draw(self, context): + layout = self.layout + coat = bpy.coat3D + coat3D = bpy.context.scene.coat3D + if(bpy.context.active_object): + coa = bpy.context.active_object.coat3D + if(coat['status'] == 0): + row = layout.row() + row.label(text="Applink didn't find your 3d-Coat/Excahnge folder.") + row = layout.row() + row.label("Please select it before using Applink.") + row = layout.row() + row.prop(coat3D,"exchangedir",text="") + row = layout.row() + row.operator("update_exchange_folder.pilgway_3d_coat", text="Apply folder") + + else: + #Here you add your GUI + row = layout.row() + row.prop(coat3D,"type",text = "") + row = layout.row() + colL = row.column() + colR = row.column() + + colR.operator("export_applink.pilgway_3d_coat", text="Transfer") + colL.operator("import_applink.pilgway_3d_coat", text="Update") + class ObjectButtonsPanel(): bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py index bb6ffe68..94ba4cd8 100644 --- a/io_coat3D/tex.py +++ b/io_coat3D/tex.py @@ -85,15 +85,23 @@ def createnodes(mat_list,texcoat): #luo nodes palikat ja linkittaa tekstuurit ni coat3D = bpy.context.scene.coat3D coatMat = mat_list[0] + print('matlist[0]', mat_list[0]) if(coatMat.use_nodes == False): coatMat.use_nodes = True act_material = coatMat.node_tree + print('tuleeko materiaali:',act_material.name) main_material = coatMat.node_tree applink_group_node = False #ensimmaiseksi kaydaan kaikki image nodet lapi ja tarkistetaan onko nimi 3DC alkunen jos on niin reload print('texcoat:',texcoat) + + for node in act_material.nodes: + if (node.type == 'OUTPUT_MATERIAL'): + main_mat = node + break + for node in act_material.nodes: if(node.name == '3DC_Applink' and node.type == 'GROUP'): applink_group_node = True @@ -125,8 +133,8 @@ def createnodes(mat_list,texcoat): #luo nodes palikat ja linkittaa tekstuurit ni applink_tree.location = -400, 300 act_material = group_tree notegroup = act_material.nodes.new('NodeGroupOutput') + print('active material:', act_material.name) - main_mat = main_material.nodes['Material Output'] if(main_mat.inputs['Surface'].is_linked == True): glue_mat = main_mat.inputs['Surface'].links[0].from_node if(glue_mat.inputs.find('Base Color') == -1): |