[Bf-extensions-cvs] [e8279e84] blender2.8: major refactoring

Kalle-Samuli Riihikoski noreply at git.blender.org
Sun Aug 12 18:52:40 CEST 2018


Commit: e8279e84a2e03dbf38d1b3fde9e244e1d6134c6c
Author: Kalle-Samuli Riihikoski
Date:   Sun Aug 12 16:51:02 2018 +0300
Branches: blender2.8
https://developer.blender.org/rBAe8279e84a2e03dbf38d1b3fde9e244e1d6134c6c

major refactoring

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

M	io_coat3D/__init__.py

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

diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py
index ba09b92c..af5f0d90 100644
--- a/io_coat3D/__init__.py
+++ b/io_coat3D/__init__.py
@@ -342,152 +342,150 @@ class SCENE_OT_import(bpy.types.Operator):
         if(new_object == False):
 
             #Blender -> 3DC -> Blender workflow
-
-            for objekti in bpy.context.collection.objects:
-                if(objekti.type == 'MESH'):
+            #First check if objects needs to be imported, if imported it will then delete extra mat and objs.
+
+            old_materials = bpy.data.materials.keys()
+            old_objects = bpy.data.objects.keys()
+            object_list = []
+            import_list = []
+            for objekti in bpy.context.scene.collection.all_objects:
+                if (objekti.type == 'MESH'):
+                    object_list.append(objekti.name)
                     obj_coat = objekti.coat3D
-                    if(obj_coat.applink_address != '' and os.path.isfile(obj_coat.applink_address)):
-                        objekti.select_set('SELECT')
-                        exportfile = coat3D.exchangedir
-                        path3b_n = coat3D.exchangedir
-                        path3b_n += ('last_saved_3b_file.txt')
-                        exportfile += ('%sBlender' % (os.sep))
-                        exportfile += ('%sexport.txt'%(os.sep))
-                        if(os.path.isfile(exportfile)):
-                            export_file = open(exportfile)
-                            for line in export_file:
-                                if line.rfind('.3b'):
-                                    objekti.coat3D.coatpath = line
-                                    coat['active_coat'] = line
-                            export_file.close()
-                            print('poistetaan new')
-                            os.remove(exportfile)
-
-
-                        obj_names = objekti.coat3D.applink_group
-                        obj_list = obj_names.split(':::')
-                        applinks = []
-                        mat_list = []
-                        obj_list.pop()
-                        print('obj_list: ',obj_list)
-
-
-                        for app_obj in obj_list:
-                            pnimi = app_obj.lstrip()
-                            listed = re.split(r'[:::]', pnimi)
-                            for tobj in bpy.context.collection.all_objects:
-                                if(tobj.type == 'MESH'):
-                                    print('tobj.data.name: ',tobj.data.name)
-                                    print('app_obj: ',app_obj)
-                                    if(tobj.data.name == app_obj):
-                                        print('applink appends:',tobj)
-                                        applinks.append(tobj)
-
-                        if(obj_coat.objecttime != str(os.path.getmtime(obj_coat.applink_address))):
-                            materials_old = bpy.data.materials.keys()
-                            obj_coat.dime = objekti.dimensions
-                            obj_coat.objecttime = str(os.path.getmtime(obj_coat.applink_address))
-                            bpy.ops.wm.collada_import(filepath=obj_coat.applink_address)
-                            bpy.ops.object.select_all(action='DESELECT')
-
-
-                            materials_new = bpy.data.materials.keys()
-                            new_ma = list(set(materials_new).difference(set(materials_old)))
-                            proxy_index = -1
-                            #bpy.data.materials.remove(bpy.data.materials[-1])
-                            counter = 1
-                            del_list = []
-
-                            for obe in applinks:
-                                print('obe: ',obe)
-                                counter += 1
-
-                                if(obe.coat3D.applink_address == objekti.coat3D.applink_address and obe.type == 'MESH'):
-                                    use_smooth = obe.data.polygons[0].use_smooth
-
-                                    if(obe.material_slots):
-                                        act_mat = obe.active_material
-                                        for obj_mat in obe.material_slots:
-                                            mat_list.append(obj_mat.material)
-
-                                    #finds a object that was imported
-                                    if(obe.coat3D.applink_export == False):
-                                        find_name = obe.data.name + '-mesh'
-                                        find_name = find_name.replace('.', '_')
-                                    else:
-                                        find_name = obe.data.name + '.001'
-                                    for allobjekti in bpy.context.scene.collection.all_objects:
-                                        counter = 0
-
-                                        if(allobjekti.data.name == find_name):
-                                            obj_proxy = allobjekti
-                                            del_list.append(allobjekti)
-                                            break
-
-                                    bpy.ops.object.select_all(action='DESELECT')
-                                    print('obj_proxy: ',obj_proxy)
-                                    obj_proxy.select_set('SELECT')
-
-                                    bpy.ops.object.select_all(action='TOGGLE')
-
-                                    if(coat3D.importlevel):
-                                        obj_proxy.select = True
-                                        obj_proxy.modifiers.new(name='temp',type='MULTIRES')
-                                        obe.select = True
-                                        bpy.ops.object.multires_reshape(modifier=multires_name)
-                                        bpy.ops.object.select_all(action='TOGGLE')
-                                        multires_on = False
-                                    else:
-
-                                        #scene.objects.active = obj_proxy HACKKI
-                                        obj_proxy.select_set('SELECT')
-
-                                        obj_data = obe.data.id_data
-                                        obe.data = obj_proxy.data.id_data
-                                        obe.data.id_data.name = obj_data.name
-                                        if(bpy.data.meshes[obj_data.name].users == 0):
-                                            bpy.data.meshes.remove(obj_data)
-
-
-                                    objekti.select_set('SELECT')
-                                    if (obe.coat3D.applink_firsttime == True):
-                                        obe.scale = (1, 1, 1)
-                                        obe.rotation_euler = (0,0,0)
-                                        obe.coat3D.applink_firsttime = False
-                                    bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN')
-                                    proxy_index -= 1
-                                    obe.material_slots[0].material = act_mat
-
-                                    if (use_smooth):
-                                        for data_mesh in obe.data.polygons:
-                                            data_mesh.use_smooth = True
-
-                            bpy.ops.object.select_all(action='DESELECT')
-                            print('del_list', del_list)
-                            for deleting in del_list:
-                                deleting.select_set(action='SELECT')
-                                bpy.ops.object.delete()
-                            mat_index = 0
-                            for obe in applinks:
-                                bpy.data.materials.remove(bpy.data.materials[new_ma[mat_index]])
-                                mat_index +=1
-
-                        if(os.path.isfile(path3b_n)):
-                            path3b_fil = open(path3b_n)
-                            for lin in path3b_fil:
-                                objekti.coat3D.path3b = lin
-                            path3b_fil.close()
-                            os.remove(path3b_n)
-
-                        if(coat3D.importmesh and not(os.path.isfile(objekti.coat3D.applink_address))):
-                            coat3D.importmesh = False
-
-                        for obe in applinks:
-                            obe.select_set('SELECT')
-                            if(coat3D.importtextures):
-                                is_new = False
-                                tex.matlab(mat_list,obe,bpy.context.scene,is_new)
-                            obe.select_set('DESELECT')
+                    if (obj_coat.objecttime != str(os.path.getmtime(obj_coat.applink_address))):
+                        obj_coat.dime = objekti.dimensions
+                        obj_coat.import_mesh = True
+                        obj_coat.objecttime = str(os.path.getmtime(obj_coat.applink_address))
+                        if(obj_coat.applink_address not in import_list):
+                            import_list.append(obj_coat.applink_address)
+            if(import_list):
+                for list in import_list:
+                    bpy.ops.wm.collada_import(filepath=list)
+                bpy.ops.object.select_all(action='DESELECT')
+
+                new_materials = bpy.data.materials.keys()
+                new_objects = bpy.data.objects.keys()
+
+                diff_mat = [i for i in new_materials if i not in old_materials]
+                diff_objects = [i for i in new_objects if i not in old_objects]
+                for c_index in diff_mat:
+                    bpy.data.materials.remove(bpy.data.materials[c_index])
+
+            #The main Applink Object Loop
+
+            for oname in object_list:
+                print('OOO: ', bpy.data.objects[oname].name)
+                objekti = bpy.data.objects[oname]
+                if(objekti.coat3D.import_mesh):
+                    objekti.coat3D.import_mesh = False
+                    objekti.select_set('SELECT')
+
+                    if (objekti.coat3D.applink_e

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list