[Bf-extensions-cvs] [e3b63b9a] master: supports UVTiling texture workflow

Kalle-Samuli Riihikoski noreply at git.blender.org
Sun Jan 6 15:47:55 CET 2019


Commit: e3b63b9ab06f33f6d1f263dc719d4edf13c7430c
Author: Kalle-Samuli Riihikoski
Date:   Sun Jan 6 16:44:01 2019 +0200
Branches: master
https://developer.blender.org/rBAe3b63b9ab06f33f6d1f263dc719d4edf13c7430c

supports UVTiling texture workflow

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

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

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

diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py
index 6db1a531..8c4784e4 100644
--- a/io_coat3D/__init__.py
+++ b/io_coat3D/__init__.py
@@ -439,10 +439,35 @@ class SCENE_OT_export(bpy.types.Operator):
                 objekti.name = name_boxs[0]
                 objekti.data.name = name_boxs[0]
             objekti.coat3D.applink_name = objekti.data.name
-
+        mod_mat_list = {}
         for objekti in bpy.context.selected_objects:
+            mod_mat_list[objekti.name] = []
             objekti.coat3D.applink_scale = objekti.scale
 
+            ''' 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
+                print(final_material_indexs)
+
+                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
+
+        print('uvtiles_index', uvtiles_index)
         bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
         if(len(bpy.context.selected_objects) > 1 and coat3D.type != 'vox'):
             bpy.ops.object.transforms_to_deltas(mode='ROT')
@@ -467,10 +492,11 @@ class SCENE_OT_export(bpy.types.Operator):
                 objekti.coat3D.applink_onlyone = True
             objekti.coat3D.type = coat3D.type
             objekti.coat3D.applink_mesh = True
-            objekti.coat3D.applink_address = coa.applink_address
             objekti.coat3D.obj_mat = ''
             objekti.coat3D.applink_firsttime = True
-            objekti.coat3D.objecttime = str(os.path.getmtime(objekti.coat3D.applink_address))
+            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'):
@@ -481,6 +507,14 @@ class SCENE_OT_export(bpy.types.Operator):
                                 if(node.name.startswith('3DC_') == True):
                                     material.material.node_tree.nodes.remove(node)
 
+            print('halloo', mod_mat_list)
+            for ind, mat_list in enumerate(mod_mat_list):
+                print('terve', 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]
+                        print('hipphhhuurrei', mod_mat_list[mat_list][ind][0], mod_mat_list[mat_list][ind][1])
+
         return {'FINISHED'}
 
 class SCENE_OT_import(bpy.types.Operator):
diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py
index 7af4d68e..aae5ba84 100644
--- a/io_coat3D/tex.py
+++ b/io_coat3D/tex.py
@@ -42,9 +42,43 @@ 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 """
+
+    objekti.coat3D.applink_scale = objekti.scale
+    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
+    print(final_material_indexs)
+
+    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
+
+
+    print('uvtiles_index', uvtiles_index)
+    return texturelist
+
 def readtexturefolder(objekti, mat_list, texturelist, is_new): #read textures from texture file
 
     create_nodes = False
+
+    if texturelist[0][0] == '1001':
+        print('This is UVTiling')
+        texturelist = UVTiling(objekti, texturelist)
+    print('texturelist:', texturelist)
+
     for index_mat in objekti.material_slots:
 
         texcoat = {}
@@ -58,7 +92,7 @@ def readtexturefolder(objekti, mat_list, texturelist, is_new): #read textures fr
         texcoat['emissive_power'] = []
         texcoat['displacement'] = []
 
-
+        create_group_node = False
         for texture_info in texturelist:
             if texture_info[0] == index_mat.name:
                 if texture_info[2] == 'color' or texture_info[2] == 'diffuse':
@@ -70,7 +104,7 @@ def readtexturefolder(objekti, mat_list, texturelist, is_new): #read textures fr
                 if texture_info[2] == 'rough' or texture_info[2] == 'roughness':
                     texcoat['rough'].append(texture_info[3])
                     create_nodes = True
-                if texture_info[2] == 'nmap' or texture_info[2] == 'normalmap' or texture_info[2] == 'normal_map':
+                if 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
                 if texture_info[2] == 'emissive':
@@ -85,6 +119,7 @@ def readtexturefolder(objekti, mat_list, texturelist, is_new): #read textures fr
                 if texture_info[2].startswith('displacement'):
                     texcoat['displacement'].append(texture_info[3])
                     create_nodes = True
+                create_group_node = True
         if(create_nodes):
             coat3D = bpy.context.scene.coat3D
             path3b_n = coat3D.exchangedir
@@ -96,7 +131,7 @@ 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)
+            createnodes(index_mat, texcoat, create_group_node)
 
 def checkmaterial(mat_list, objekti): #check how many materials object has
     mat_list = []
@@ -105,7 +140,7 @@ def checkmaterial(mat_list, objekti): #check how many materials object has
         if(obj_mate.material.use_nodes == False):
             obj_mate.material.use_nodes = True
 
-def createnodes(active_mat,texcoat): # Cretes new nodes and link textures into them
+def createnodes(active_mat,texcoat, create_group_node): # 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
@@ -159,228 +194,228 @@ def createnodes(active_mat,texcoat): # Cretes new nodes and link textures into t
                 node.image.reload()
 
     #seuraavaksi lahdemme rakentamaan node tree. Lahdetaan Material Outputista rakentaa
-
-    if(applink_group_node == False and coat3D.creategroup):
-        group_tree = bpy.data.node_groups.new( type="ShaderNodeTree", name="3DC_Applink")
-        group_tree.outputs.new("NodeSocketColor", "Color")
-        group_tree.outputs.new("NodeSocketColor", "Metallic")
-        group_tree.outputs.new("NodeSocketColor", "Roughness")
-        group_tree.outputs.new("NodeSocketVector", "Normal map")
-        group_tree.outputs.new("NodeSocketColor", "Displacement")
-        group_tree.outputs.new("NodeSocketColor", "Emissive")
-        group_tree.outputs.new("NodeSocketColor", "Emissive Power")
-        group_tree.outputs.new("NodeSocketColor", "AO")
-        applink_tree = act_material.nodes.new('ShaderNodeGroup')
-        applink_tree.name = '3DC_Applink'
-        applink_tree.node_tree = group_tree
-        applink_tree.location = -400, 300
-        act_material = group_tree
-        notegroup = act_material.nodes.new('NodeGroupOutput')
-        notegroup.location = 220, -260
-    else:
-        index = 0
-        for node in coatMat.node_tree.nodes:
-            if (node.type == 'GROUP' and node.name =='3DC_Applink'):
-                for in_node in node.node_tree.nodes:
-                    if(in_node.type == 'GROUP_OUTPUT'):
-                        notegroup = in_node
-                        index = 1
-                        break
-            if(index == 1):
-                break
-
-    if(out_mat.inputs['Surface'].is_linked == True):
-        main_mat = out_mat.inputs['Surface'].links[0].from_node
-        if(main_mat.inputs.find('Base Color') == -1):
-            input_color = main_mat.inputs.find('Color')
+    if(create_group_node):
+        if(applink_group_node == False and coat3D.creategroup):
+            group_tree = bpy.data.node_groups.new( type="ShaderNodeTree", name="3DC_Applink")
+            group_tree.outputs.new("NodeSocketColor", "Color")
+            group_tree.outputs.new("NodeSocketColor", "Metallic")
+            group_tree.outputs.new("NodeSocketColor", "Roughness")
+            group_tree.outputs.new("NodeSocketVector", "Normal map")
+            group_tree.outpu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list