[Bf-extensions-cvs] [b091487d] blender2.8: fixes crash when pressing update button

Kalle-Samuli Riihikoski noreply at git.blender.org
Thu Dec 6 23:28:12 CET 2018


Commit: b091487d7087dfa3dc494327973e4c319a8f935a
Author: Kalle-Samuli Riihikoski
Date:   Fri Dec 7 00:24:47 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBAb091487d7087dfa3dc494327973e4c319a8f935a

fixes crash when pressing update button

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

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

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

diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py
index 826a5fa4..e55daa67 100644
--- a/io_coat3D/__init__.py
+++ b/io_coat3D/__init__.py
@@ -59,6 +59,14 @@ bpy.coat3D = dict()
 bpy.coat3D['active_coat'] = ''
 bpy.coat3D['status'] = 0
 
+def update_exe_path():
+    if (bpy.context.scene.coat3D.coat3D_exe != ''):
+        importfile = bpy.context.scene.coat3D.exchangedir
+        importfile += ('%scoat3D_exe.txt' % (os.sep))
+        file = open(importfile, "w")
+        file.write("%s" % (bpy.context.scene.coat3D.coat3D_exe))
+        file.close()
+
 def folder_size(path):
 
     tosi = True
@@ -79,9 +87,12 @@ def set_exchange_folder():
     Blender_export = ""
 
     if(platform == 'win32'):
-        exchange = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3D-CoatV4' + os.sep +'Exchange'
+        exchange = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3D-CoatV48' + os.sep +'Exchange'
         if not(os.path.isdir(exchange)):
-            exchange = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3D-CoatV3' + os.sep +'Exchange'
+            exchange = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3D-CoatV4' + os.sep +'Exchange'
+        if not (os.path.isdir(exchange)):
+            exchange = os.path.expanduser("~") + os.sep + 'Documents' + os.sep + '3D-CoatV3' + os.sep + 'Exchange'
+
     else:
         exchange = os.path.expanduser("~") + os.sep + '3D-CoatV4' + os.sep + 'Exchange'
         if not(os.path.isdir(exchange)):
@@ -209,7 +220,7 @@ def updatemesh(objekti, proxy):
         index = 0
         for uv_layer in objekti.data.uv_layers:
             if (uv_layer != objekti.data.uv_layers[0]):
-                proxy.data.uv_layers.new(uv_layer.name)
+                proxy.data.uv_layers.new(name=uv_layer.name)
                 proxy.data.uv_layers.active_index = index
                 objekti.data.uv_layers.active_index = index
                 bpy.ops.object.join_uvs()
@@ -263,26 +274,30 @@ class SCENE_OT_opencoat(bpy.types.Operator):
     bl_options = {'UNDO'}
 
     def invoke(self, context, event):
+
+        update_exe_path()
+
+        exefile = bpy.context.scene.coat3D.exchangedir
+        exefile += ('%scoat3D_exe.txt' % (os.sep))
+        exe_path = ''
+        if (os.path.isfile(exefile)):
+
+            ex_pathh = open(exefile)
+            for line in ex_pathh:
+                exe_path = line
+                break
+            ex_pathh.close()
+
         coat3D = bpy.context.selected_objects[0].coat3D.applink_3b_path
         platform = os.sys.platform
         prog_path = os.environ['PROGRAMFILES']
         if (platform == 'win32'):
-            index = 0
-            for file in os.listdir(prog_path):
-                if index == 0:
-                    if file.startswith('3D-Coat-V4'):
-                        modi = os.path.getmtime(prog_path + os.sep + file)
-                        active_3dcoat = prog_path + os.sep + file
-                        index += 1
-                else:
-                    if file.startswith('3D-Coat-V4'):
-                        if(os.path.getmtime(prog_path + os.sep + file) > modi):
-                            modi = os.path.getmtime(prog_path + os.sep + file)
-                            active_3dcoat = prog_path + os.sep + file
 
-            if running() == False:
+            active_3dcoat = exe_path
 
-                os.popen('"' + active_3dcoat + os.sep + '3D-CoatDX64C.exe' '" ' + coat3D)
+            if running() == False:
+                print('tulele tanne')
+                os.popen('"' + active_3dcoat + '" ' + coat3D)
             else:
                 importfile = bpy.context.scene.coat3D.exchangedir
                 importfile += ('%simport.txt' % (os.sep))
@@ -317,6 +332,8 @@ class SCENE_OT_export(bpy.types.Operator):
 
     def invoke(self, context, event):
 
+        update_exe_path()
+
         for mesh in bpy.data.meshes:
             if (mesh.users == 0 and mesh.coat3D.name == '3DC'):
                 bpy.data.meshes.remove(mesh)
@@ -456,6 +473,13 @@ class SCENE_OT_import(bpy.types.Operator):
     bl_options = {'UNDO'}
 
     def invoke(self, context, event):
+
+        update_exe_path()
+
+        for node_group in bpy.data.node_groups:
+            if(node_group.users == 0):
+                bpy.data.node_groups.remove(node_group)
+
         for mesh in bpy.data.meshes:
             if(mesh.users == 0 and mesh.coat3D.name == '3DC'):
                 bpy.data.meshes.remove(mesh)
@@ -563,6 +587,9 @@ class SCENE_OT_import(bpy.types.Operator):
                 objekti = bpy.data.objects[oname]
                 print('BASE_OBJECT:', objekti,objekti.coat3D.applink_address)
                 if(objekti.coat3D.applink_mesh == True):
+                    exportfile = coat3D.exchangedir
+                    path3b_n = coat3D.exchangedir
+                    path3b_n += ('%slast_saved_3b_file.txt' % (os.sep))
                     print('totta vai tarua:',objekti.coat3D.applink_mesh)
                     if(objekti.coat3D.import_mesh and coat3D.importmesh == True):
                         print('ONAME:', oname)
@@ -885,7 +912,7 @@ class SCENE_PT_Settings_Folders(ObjectButtonsPanel, bpy.types.Panel):
 
     def draw(self, context):
         layout = self.layout
-        layout.use_property_split = True
+        layout.use_property_split = False
         coat3D = bpy.context.scene.coat3D
 
         rd = context.scene.render
@@ -1044,7 +1071,7 @@ class SceneCoat3D(PropertyGroup):
     )
     coat3D_exe: StringProperty(
         name="FilePath",
-        subtype="DIR_PATH",
+        subtype="FILE_PATH",
     )
     cursor_loc: FloatVectorProperty(
         name="Cursor_loc",
@@ -1164,7 +1191,7 @@ class SceneCoat3D(PropertyGroup):
     importmesh: BoolProperty(
         name="Mesh",
         description="Import Mesh",
-        default=True
+        default=False
     )
 
     # copy location
diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py
index 6b936f0d..5e7db59e 100644
--- a/io_coat3D/tex.py
+++ b/io_coat3D/tex.py
@@ -42,31 +42,50 @@ def RemoveFbxNodes(objekti):
 
     Node_Tree.links.new(Prin_mat.outputs[0], output.inputs[0])
 
-def readtexturefolder(mat_list,texturelist,is_new): #read textures from texture file
-
-    texcoat = {}
-    texcoat['color'] = []
-    texcoat['metalness'] = []
-    texcoat['rough'] = []
-    texcoat['nmap'] = []
-    texcoat['disp'] = []
-    texcoat['emissive'] = []
-
-
-    for texture_info in texturelist:
-        if texture_info[0] == mat_list[0].name:
-            if texture_info[2] == 'color' or texture_info[2] == 'diffuse':
-                texcoat['color'].append(texture_info[3])
-            if texture_info[2] == 'metalness' or texture_info[2] == 'specular' or texture_info[2] == 'reflection':
-                texcoat['metalness'].append(texture_info[3])
-            if texture_info[2] == 'rough' or texture_info[2] == 'roughness':
-                texcoat['rough'].append(texture_info[3])
-            if texture_info[2] == 'nmap' or texture_info[2] == 'normalmap' or texture_info[2] == 'normal_map':
-                texcoat['nmap'].append(texture_info[3])
-            if texture_info[2] == 'emissive':
-                texcoat['emissive'].append(texture_info[3])
-
-    createnodes(mat_list, texcoat)
+def readtexturefolder(objekti, mat_list, texturelist, is_new): #read textures from texture file
+
+    create_nodes = False
+    for index_mat in objekti.material_slots:
+
+        texcoat = {}
+        texcoat['color'] = []
+        texcoat['metalness'] = []
+        texcoat['rough'] = []
+        texcoat['nmap'] = []
+        texcoat['disp'] = []
+        texcoat['emissive'] = []
+
+
+        for texture_info in texturelist:
+            if texture_info[0] == index_mat.name:
+                if texture_info[2] == 'color' or texture_info[2] == 'diffuse':
+                    texcoat['color'].append(texture_info[3])
+                    create_nodes = True
+                if texture_info[2] == 'metalness' or texture_info[2] == 'specular' or texture_info[2] == 'reflection':
+                    texcoat['metalness'].append(texture_info[3])
+                    create_nodes = True
+                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':
+                    texcoat['nmap'].append(texture_info[3])
+                    create_nodes = True
+                if texture_info[2] == 'emissive':
+                    texcoat['emissive'].append(texture_info[3])
+                    create_nodes = True
+
+        if(create_nodes):
+            coat3D = bpy.context.scene.coat3D
+            path3b_n = coat3D.exchangedir
+            path3b_n += ('%slast_saved_3b_file.txt' % (os.sep))
+
+            if (os.path.isfile(path3b_n)):
+                export_file = open(path3b_n)
+                for line in export_file:
+                    objekti.coat3D.applink_3b_path = line
+                export_file.close()
+                coat3D.remove_path = True
+            createnodes(index_mat, texcoat)
 
 def checkmaterial(mat_list, objekti): #check how many materials object has
     mat_list = []
@@ -75,14 +94,14 @@ 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(mat_list,texcoat): #luo nodes palikat ja linkittaa tekstuurit niihin
+def createnodes(active_mat,texcoat): #luo nodes palikat ja linkittaa tekstuurit niihin
     bring_color = True #naiden tarkoitus on tsekata onko tarvetta luoda uusi node vai riittaako paivitys
     bring_metalness = True
     bring_roughness = True
     bring_normal = True
     bring_disp = True
     coat3D = bpy.context.scene.coat3D
-    coatMat = mat_list[0]
+    coatMat = active_mat.material
 
     if(coatMat.use_nodes == False):
         coatMat.use_nodes = True
@@ -91,9 +110,9 @@ def createnodes(mat_list,texcoat): #luo nodes palikat ja linkittaa tekstuurit ni
     applink_group_node = False
     

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list