[Bf-extensions-cvs] [92c66013] master: Fixed 3D-Coat -> Blender workflow

Kalle-Samuli Riihikoski noreply at git.blender.org
Thu Mar 7 00:20:04 CET 2019


Commit: 92c66013256f8de3effd0be3f77f156abfdf20f1
Author: Kalle-Samuli Riihikoski
Date:   Thu Mar 7 01:18:31 2019 +0200
Branches: master
https://developer.blender.org/rBA92c66013256f8de3effd0be3f77f156abfdf20f1

Fixed 3D-Coat -> Blender workflow

===================================================================

M	io_coat3D/__init__.py
M	io_coat3D/tex.py

===================================================================

diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py
index 17be77da..6b0e402b 100644
--- a/io_coat3D/__init__.py
+++ b/io_coat3D/__init__.py
@@ -251,7 +251,6 @@ def updatemesh(objekti, proxy, texturelist):
     objekti.select_set(True)
 
     uv_count = len(proxy.data.uv_layers)
-    print('proxy uv layers count:', uv_count)
     index = 0
     while(index < uv_count):
         for poly in proxy.data.polygons:
@@ -469,8 +468,14 @@ def deleteNodes(type):
             bpy.data.images.remove(bpy.data.images[image])
 
 
-
-
+def delete_materials_from_end(keep_materials_count, objekti):
+    bpy.context.object.active_material_index = 0
+    index_t = 0
+    while (index_t < keep_materials_count):
+        temp_len = len(objekti.material_slots)-1
+        bpy.context.object.active_material_index = temp_len
+        bpy.ops.object.material_slot_remove()
+        index_t +=1
 
 ''' DELETE NODES BUTTONS'''
 
@@ -1009,14 +1014,10 @@ class SCENE_OT_import(bpy.types.Operator):
                             else:
 
                                 bpy.context.view_layer.objects.active = obj_proxy
-                                mat_count = len(obj_proxy.material_slots) - len(objekti.material_slots)
-                                bpy.context.object.active_material_index = 0
-                                index_t = 0
-                                while (index_t < mat_count):
-                                    temp_len = len(obj_proxy.material_slots)-1
-                                    bpy.context.object.active_material_index = temp_len
-                                    bpy.ops.object.material_slot_remove()
-                                    index_t +=1
+                                keep_materials_count = len(obj_proxy.material_slots) - len(objekti.material_slots)
+
+                                delete_materials_from_end(keep_materials_count, obj_proxy)
+
                                 for index, material in enumerate(objekti.material_slots):
                                     obj_proxy.material_slots[index-1].material = material.material
 
@@ -1144,7 +1145,7 @@ class SCENE_OT_import(bpy.types.Operator):
 
                 if(new_obj.coat3D.applink_old == False):
                     new_obj.select_set(True)
-                    new_obj.scale = (0.01, 0.01, 0.01)
+                    new_obj.scale = (1, 1, 1)
                     new_obj.coat3D.applink_firsttime = False
                     new_obj.select_set(False)
                     new_obj.coat3D.type = 'ppp'
@@ -1152,9 +1153,13 @@ class SCENE_OT_import(bpy.types.Operator):
                     new_obj.coat3D.applink_mesh = True
                     new_obj.coat3D.objecttime = str(os.path.getmtime(new_obj.coat3D.applink_address))
 
-                    new_obj.coat3D.applink_name = new_obj.material_slots[0].material.name
+                    new_obj.coat3D.applink_name = new_obj.name
                     index = index + 1
 
+                    bpy.context.view_layer.objects.active = new_obj
+                    keep_materials_count = len(new_obj.material_slots) - len(new_obj.data.uv_layers)
+                    delete_materials_from_end(keep_materials_count, new_obj)
+
                     new_obj.coat3D.applink_export = True
                     if(osoite_3b != ''):
                         new_obj.coat3D.applink_3b_path = osoite_3b
diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py
index 5b70c0b4..1d029d21 100644
--- a/io_coat3D/tex.py
+++ b/io_coat3D/tex.py
@@ -250,10 +250,10 @@ 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, tile_list, objekti)
+            createnodes(index_mat, texcoat, create_group_node, tile_list, objekti, ind, is_new)
 
 
-def createnodes(active_mat,texcoat, create_group_node, tile_list, objekti): # Cretes new nodes and link textures into them
+def createnodes(active_mat,texcoat, create_group_node, tile_list, objekti, ind, is_new): # 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
@@ -371,26 +371,31 @@ def createnodes(active_mat,texcoat, create_group_node, tile_list, objekti): # Cr
 
         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, tile_list, objekti)
+                CreateTextureLine(data['color'], act_material, main_mat, texcoat, coat3D, notegroup,
+                                  main_material, applink_tree, out_mat, coatMat, tile_list, objekti, ind, is_new)
 
             if(bring_metalness == True and texcoat['metalness'] != []):
-                CreateTextureLine(data['metalness'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, tile_list, objekti)
+                CreateTextureLine(data['metalness'], act_material, main_mat, texcoat, coat3D, notegroup,
+                                  main_material, applink_tree, out_mat, coatMat, tile_list, objekti, ind, is_new)
 
             if(bring_roughness == True and texcoat['rough'] != []):
-                CreateTextureLine(data['rough'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat,tile_list, objekti)
+                CreateTextureLine(data['rough'], act_material, main_mat, texcoat, coat3D, notegroup,
+                                  main_material, applink_tree, out_mat, coatMat,tile_list, objekti, ind, is_new)
 
             if(bring_normal == True and texcoat['nmap'] != []):
-                CreateTextureLine(data['nmap'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, tile_list, objekti)
+                CreateTextureLine(data['nmap'], act_material, main_mat, texcoat, coat3D, notegroup,
+                                  main_material, applink_tree, out_mat, coatMat, tile_list, objekti, ind, is_new)
 
             if (bring_emissive == True and texcoat['emissive'] != []):
-                CreateTextureLine(data['emissive'], act_material, main_mat, texcoat, coat3D, notegroup, main_material, applink_tree, out_mat, coatMat, tile_list, objekti)
+                CreateTextureLine(data['emissive'], act_material, main_mat, texcoat, coat3D, notegroup,
+                                  main_material, applink_tree, out_mat, coatMat, tile_list, objekti, ind, is_new)
 
             if (bring_displacement == True and texcoat['displacement'] != []):
-                CreateTextureLine(data['displacement'], act_material, main_mat, texcoat, coat3D, notegroup, main_material,
-                                  applink_tree, out_mat, coatMat, tile_list, objekti)
+                CreateTextureLine(data['displacement'], act_material, main_mat, texcoat, coat3D, notegroup,
+                                  main_material, applink_tree, out_mat, coatMat, tile_list, objekti, ind, is_new)
 
 
-def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup, main_material, 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, tile_list, objekti, ind, is_new):
 
     if(tile_list):
         texture_name = coatMat.name + '_' + type['name']
@@ -430,7 +435,10 @@ def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup,
 
             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
+            if(is_new):
+                tex_uv_node.uv_map = objekti.data.uv_layers[ind].name
+            else:
+                tex_uv_node.uv_map = objekti.data.uv_layers[0].name
 
             map_node = texture_tree.nodes.new('ShaderNodeMapping')
             map_node.location = map_loc
@@ -492,7 +500,10 @@ def CreateTextureLine(type, act_material, main_mat, texcoat, coat3D, notegroup,
     else:
         node = act_material.nodes.new('ShaderNodeTexImage')
         uv_node = act_material.nodes.new('ShaderNodeUVMap')
-        uv_node.uv_map = objekti.data.uv_layers[0].name
+        if (is_new):
+            uv_node.uv_map = objekti.data.uv_layers[ind].name
+        else:
+            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])



More information about the Bf-extensions-cvs mailing list