def invoke(self, context, event): coat3D = bpy.context.scene.coat3D scene = context.scene Blender_folder = ("%s%sBlender" % (coat3D.exchangedir, os.sep)) Blender_export = Blender_folder path3b_now = coat3D.exchangedir path3b_now += ('last_saved_3b_file.txt') Blender_export += ('%sexport.txt' % (os.sep)) import_no = 0 mat_list = [] obj_path = '' obj_pathh = open(Blender_export) for line in obj_pathh: obj_path = line break obj_pathh.close() export = obj_path mod_time = os.path.getmtime(obj_path) mtl_list = obj_path.replace('.obj', '.mtl') if (os.path.isfile(mtl_list)): os.remove(mtl_list) if (os.path.isfile(path3b_now)): path3b_file = open(path3b_now) for lin in path3b_file: path_export = lin path_on = 1 path3b_file.close() os.remove(path3b_now) else: path_on = 0 for palikka in bpy.context.scene.objects: if (palikka.type == 'MESH'): if (palikka.coat3D.objectdir == export): import_no = 1 target = palikka break if (import_no): new_obj = palikka import_no = 0 else: bpy.ops.import_scene.obj(filepath=obj_path, axis_forward='X', axis_up='Y') bpy.ops.object.transform_apply(rotation=True) new_obj = scene.objects[0] scene.objects[0].coat3D.objectdir = export if (path_on): scene.objects[0].coat3D.path3b = path_export os.remove(Blender_export) bpy.context.scene.objects.active = new_obj bpy.ops.object.shade_smooth() Blender_tex = ("%s%stextures.txt" % (coat3D.exchangedir, os.sep)) mat_list.append(new_obj.material_slots[0].material) tex.gettex(mat_list, new_obj, scene, export) return {'FINISHED'}
def draw(self, context): layout = self.layout scene = context.scene me = context.scene.objects mat_list = [] import_no = 0 coat = bpy.coat3D coat3D = bpy.context.scene.coat3D if (bpy.context.scene.objects.active): coa = bpy.context.scene.objects.active.coat3D if (os.path.isdir(coat3D.exchangedir)): foldder = coat3D.exchangedir if (foldder.rfind('Exchange') >= 0): coat['status'] = 1 else: coat['status'] = 0 else: coat['status'] = 0 #Here you add your GUI row = layout.row() row.prop(coat3D, "type", text="") row = layout.row() colL = row.column() colR = row.column() if (context.selected_objects): if (context.selected_objects[0].type == 'MESH'): row.active = True else: row.active = False else: row.active = False colL.operator("export_applink.pilgway_3d_coat", text="Export") colL.label(text="Export Settings:") colL.prop(coat3D, "exportover") if (coat3D.exportover): colL.prop(coat3D, "exportmod") colL.prop(coat3D, "exportfile") colL.prop(coat3D, "export_pos") colR.operator("import_applink.pilgway_3d_coat", text="Import") colR.label(text="Import Settings:") colR.prop(coat3D, "importmesh") colR.prop(coat3D, "importmod") colR.prop(coat3D, "smooth_on") colR.prop(coat3D, "importtextures") row = layout.row() if (bpy.context.selected_objects): if (context.selected_objects[0].type == 'MESH'): coa = context.selected_objects[0].coat3D colL = row.column() colR = row.column() colL.label(text="Object Path:") if (coa.path3b): colR.active = True else: colR.active = False colR.operator("import_applink.pilgway_3d_coat_3b", text="Load 3b") row = layout.row() row.prop(coa, "objectdir", text="") row = layout.row() if (coat['status'] == 1): Blender_folder = ("%s%sBlender" % (coat3D.exchangedir, os.sep)) Blender_export = Blender_folder Blender_export = Blender_folder path3b_now = coat3D.exchangedir path3b_now += ('last_saved_3b_file.txt') Blender_export += ('%sexport.txt' % (os.sep)) if (not (os.path.isdir(Blender_folder))): os.makedirs(Blender_folder) Blender_folder = os.path.join(Blender_folder, "run.txt") file = open(Blender_folder, "w") file.close() if (os.path.isfile(Blender_export)): obj_path = '' obj_pathh = open(Blender_export) for line in obj_pathh: obj_path = line break obj_pathh.close() export = obj_path mod_time = os.path.getmtime(obj_path) mtl_list = obj_path.replace('.obj', '.mtl') if (os.path.isfile(mtl_list)): os.remove(mtl_list) if (os.path.isfile(path3b_now)): path3b_file = open(path3b_now) for lin in path3b_file: path_export = lin path_on = 1 path3b_file.close() os.remove(path3b_now) else: print("ei toimi") path_on = 0 for palikka in bpy.context.scene.objects: if (palikka.type == 'MESH'): if (palikka.coat3D.objectdir == export): import_no = 1 target = palikka break if (import_no): new_obj = palikka import_no = 0 else: bpy.ops.import_scene.obj(filepath=obj_path) new_obj = scene.objects[0] scene.objects[0].coat3D.objectdir = export if (path_on): scene.objects[0].coat3D.path3b = path_export os.remove(Blender_export) bpy.context.scene.objects.active = new_obj if (coat3D.smooth_on): bpy.ops.object.shade_smooth() else: bpy.ops.object.shade_flat() Blender_tex = ("%s%stextures.txt" % (coat3D.exchangedir, os.sep)) mat_list.append(new_obj.material_slots[0].material) tex.gettex(mat_list, new_obj, scene, export) if (context.selected_objects): if (context.selected_objects[0].type == 'MESH'): coa = bpy.context.selected_objects[0].coat3D row = layout.row() row.label(text="Texture output folder:") row = layout.row() row.prop(coa, "texturefolder", text="") row = layout.row() if (coat['status'] == 0): row.label(text="Exchange Folder: not connected") else: row.label(text="Exchange Folder: connected")
def invoke(self, context, event): scene = context.scene coat3D = bpy.context.scene.coat3D coat = bpy.coat3D test = bpy.context.selected_objects act_first = bpy.context.scene.objects.active for act_name in test: if act_name.type == 'MESH' and os.path.isfile( act_name.coat3D.objectdir): multires_on = False activeobj = act_name.name mat_list = [] scene.objects[activeobj].select = True objekti = scene.objects[activeobj] coat3D.loca = objekti.location coat3D.rota = objekti.rotation_euler coa = act_name.coat3D #See if there is multres modifier. for modifiers in objekti.modifiers: if modifiers.type == 'MULTIRES' and (modifiers.total_levels > 0): if (not (coat3D.importlevel)): bpy.ops.object.multires_external_pack() multires = coat3D.exchangedir multires += ('%stemp.btx' % (os.sep)) bpy.ops.object.multires_external_save( filepath=multires) #bpy.ops.object.multires_external_pack() multires_on = True multires_name = modifiers.name break exportfile = coat3D.exchangedir path3b_n = coat3D.exchangedir path3b_n += ('last_saved_3b_file.txt') 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() os.remove(exportfile) if (objekti.material_slots): act_mat_index = objekti.active_material_index if (not (hasattr(objekti.active_material, 'texture_slots'))): materials_old = bpy.data.materials.keys() bpy.ops.material.new() materials_new = bpy.data.materials.keys() new_ma = list( set(materials_new).difference(set(materials_old))) new_mat = new_ma[0] ki = bpy.data.materials[new_mat] objekti.material_slots[act_mat_index].material = ki for obj_mat in objekti.material_slots: mat_list.append(obj_mat.material) if (coat3D.importmesh and os.path.isfile(coa.objectdir)): mtl = coa.objectdir mtl = mtl.replace('.obj', '.mtl') if (os.path.isfile(mtl)): os.remove(mtl) bpy.ops.import_scene.obj( filepath=act_name.coat3D.objectdir, axis_forward='X', axis_up='Y') obj_proxy = scene.objects[0] bpy.ops.object.select_all(action='TOGGLE') obj_proxy.select = True if (coa.export_on): bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') bpy.ops.object.transform_apply(rotation=True) proxy_mat = obj_proxy.material_slots[0].material obj_proxy.data.materials.pop(0, 1) proxy_mat.user_clear() bpy.data.materials.remove(proxy_mat) bpy.ops.object.select_all(action='TOGGLE') if (coat3D.importlevel): obj_proxy.select = True obj_proxy.modifiers.new(name='temp', type='MULTIRES') objekti.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 obj_data = objekti.data.id_data objekti.data = obj_proxy.data.id_data if (bpy.data.meshes[obj_data.name].users == 0): bpy.data.meshes.remove(obj_data) objekti.data.id_data.name = obj_data.name obj_proxy.select = True bpy.ops.object.delete() objekti.select = True bpy.context.scene.objects.active = objekti 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(coa.objectdir))): coat3D.importmesh = False if (mat_list and coat3D.importmesh): for mat_one in mat_list: objekti.data.materials.append(mat_one) objekti.active_material_index = act_mat_index if (mat_list): for obj_mate in objekti.material_slots: if (hasattr(obj_mate.material, 'texture_slots')): for tex_slot in obj_mate.material.texture_slots: if (hasattr(tex_slot, 'texture')): if (tex_slot.texture.type == 'IMAGE'): if tex_slot.texture.image is not None: tex_slot.texture.image.reload() if (coat3D.importmod): for mod_index in objekti.modifiers[:]: objekti.modifiers.remove(mod_index) if (coat3D.importtextures): export = '' tex.gettex(mat_list, objekti, scene, export) if (multires_on): temp_file = coat3D.exchangedir temp_file += ('%stemp2.btx' % (os.sep)) if (objekti.modifiers[multires_name].levels == 0): objekti.modifiers[multires_name].levels = 1 bpy.ops.object.multires_external_save( filepath=temp_file) objekti.modifiers[multires_name].filepath = multires objekti.modifiers[multires_name].levels = 0 else: bpy.ops.object.multires_external_save( filepath=temp_file) objekti.modifiers[multires_name].filepath = multires #bpy.ops.object.multires_external_pack() bpy.ops.object.shade_smooth() for act_name in test: act_name.select = True bpy.context.scene.objects.active = act_first return {'FINISHED'}
def invoke(self, context, event): coat3D = bpy.context.scene.coat3D scene = context.scene Blender_folder = ("%s%sBlender"%(coat3D.exchangedir,os.sep)) Blender_export = Blender_folder path3b_now = coat3D.exchangedir path3b_now += ('last_saved_3b_file.txt') Blender_export += ('%sexport.txt'%(os.sep)) import_no = 0 mat_list = [] obj_path ='' obj_pathh = open(Blender_export) for line in obj_pathh: obj_path = line break obj_pathh.close() export = obj_path mod_time = os.path.getmtime(obj_path) mtl_list = obj_path.replace('.obj','.mtl') if(os.path.isfile(mtl_list)): os.remove(mtl_list) if(os.path.isfile(path3b_now)): path3b_file = open(path3b_now) for lin in path3b_file: path_export = lin path_on = 1 path3b_file.close() os.remove(path3b_now) else: path_on = 0 for palikka in bpy.context.scene.objects: if(palikka.type == 'MESH'): if(palikka.coat3D.objectdir == export): import_no = 1 target = palikka break if(import_no): new_obj = palikka import_no = 0 else: bpy.ops.import_scene.obj(filepath=obj_path,axis_forward='X',axis_up='Y') bpy.ops.object.transform_apply(rotation=True) new_obj = scene.objects[0] scene.objects[0].coat3D.objectdir = export if(path_on): scene.objects[0].coat3D.path3b = path_export os.remove(Blender_export) bpy.context.scene.objects.active = new_obj bpy.ops.object.shade_smooth() Blender_tex = ("%s%stextures.txt"%(coat3D.exchangedir,os.sep)) mat_list.append(new_obj.material_slots[0].material) tex.gettex(mat_list, new_obj, scene,export) return {'FINISHED'}
def invoke(self, context, event): scene = context.scene coat3D = bpy.context.scene.coat3D coat = bpy.coat3D activeobj = bpy.context.active_object.name mat_list = [] scene.objects[activeobj].select = True objekti = scene.objects[activeobj] coat3D.loca = objekti.location coat3D.rota = objekti.rotation_euler coa = bpy.context.scene.objects.active.coat3D exportfile = coat3D.exchangedir path3b_n = coat3D.exchangedir path3b_n += ('last_saved_3b_file.txt') 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() os.remove(exportfile) if (objekti.material_slots): for obj_mat in objekti.material_slots: mat_list.append(obj_mat.material) act_mat_index = objekti.active_material_index if (coat3D.importmesh and os.path.isfile(coa.objectdir)): mtl = coa.objectdir mtl = mtl.replace('.obj', '.mtl') if (os.path.isfile(mtl)): os.remove(mtl) bpy.ops.import_scene.obj(filepath=coa.objectdir) obj_proxy = scene.objects[0] proxy_mat = obj_proxy.material_slots[0].material obj_proxy.data.materials.pop(0) proxy_mat.user_clear() bpy.data.materials.remove(proxy_mat) bpy.ops.object.select_all(action='TOGGLE') if (coat3D.export_pos): scene.objects.active = objekti objekti.select = True coat3D.cursor = bpy.context.scene.cursor_location bpy.context.scene.cursor_location = (0.0, 0.0, 0.0) bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN') scene.objects.active = obj_proxy obj_data = objekti.data.id_data objekti.data = obj_proxy.data.id_data if (coat3D.export_on): objekti.scale = (1, 1, 1) objekti.rotation_euler = (0, 0, 0) if (bpy.data.meshes[obj_data.name].users == 0): bpy.data.meshes.remove(obj_data) objekti.data.id_data.name = obj_data.name bpy.ops.object.select_all(action='TOGGLE') obj_proxy.select = True bpy.ops.object.delete() objekti.select = True bpy.context.scene.objects.active = objekti if (coat3D.export_on): bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') coat3D.export_on = False else: objekti.location = coat3D.loca objekti.rotation_euler = coat3D.rota bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN') else: scene.objects.active = obj_proxy obj_data = objekti.data.id_data objekti.data = obj_proxy.data.id_data if (bpy.data.meshes[obj_data.name].users == 0): bpy.data.meshes.remove(obj_data) objekti.data.id_data.name = obj_data.name obj_proxy.select = True bpy.ops.object.delete() objekti.select = True bpy.context.scene.objects.active = objekti if (coat3D.smooth_on): bpy.ops.object.shade_smooth() else: bpy.ops.object.shade_flat() 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(coa.objectdir))): coat3D.importmesh = False if (mat_list and coat3D.importmesh): for mat_one in mat_list: objekti.data.materials.append(mat_one) objekti.active_material_index = act_mat_index if (mat_list): for obj_mate in objekti.material_slots: for tex_slot in obj_mate.material.texture_slots: if (hasattr(tex_slot, 'texture')): if (tex_slot.texture.type == 'IMAGE'): tex_slot.texture.image.reload() if (coat3D.importmod): mod_list = [] for mod_index in objekti.modifiers: objekti.modifiers.remove(mod_index) if (coat3D.importtextures): export = '' tex.gettex(mat_list, objekti, scene, export) return ('FINISHED')
def invoke(self, context, event): scene = context.scene coat3D = bpy.context.scene.coat3D coat = bpy.coat3D test = bpy.context.selected_objects act_first = bpy.context.scene.objects.active for act_name in test: if act_name.type == 'MESH' and os.path.isfile(act_name.coat3D.objectdir): multires_on = False activeobj = act_name.name mat_list = [] scene.objects[activeobj].select = True objekti = scene.objects[activeobj] coat3D.loca = objekti.location coat3D.rota = objekti.rotation_euler coa = act_name.coat3D #See if there is multres modifier. for modifiers in objekti.modifiers: if modifiers.type == 'MULTIRES' and (modifiers.total_levels > 0): if(not(coat3D.importlevel)): bpy.ops.object.multires_external_pack() multires = coat3D.exchangedir multires += ('%stemp.btx'%(os.sep)) bpy.ops.object.multires_external_save(filepath=multires) #bpy.ops.object.multires_external_pack() multires_on = True multires_name = modifiers.name break exportfile = coat3D.exchangedir path3b_n = coat3D.exchangedir path3b_n += ('last_saved_3b_file.txt') 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() os.remove(exportfile) if(objekti.material_slots): act_mat_index = objekti.active_material_index if(not(hasattr(objekti.active_material,'texture_slots'))): materials_old = bpy.data.materials.keys() bpy.ops.material.new() materials_new = bpy.data.materials.keys() new_ma = list(set(materials_new).difference(set(materials_old))) new_mat = new_ma[0] ki = bpy.data.materials[new_mat] objekti.material_slots[act_mat_index].material = ki for obj_mat in objekti.material_slots: mat_list.append(obj_mat.material) if(coat3D.importmesh and os.path.isfile(coa.objectdir)): mtl = coa.objectdir mtl = mtl.replace('.obj','.mtl') if(os.path.isfile(mtl)): os.remove(mtl) bpy.ops.import_scene.obj(filepath=act_name.coat3D.objectdir,axis_forward='X',axis_up='Y') obj_proxy = scene.objects[0] bpy.ops.object.select_all(action='TOGGLE') obj_proxy.select = True if(coa.export_on): bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') bpy.ops.object.transform_apply(rotation=True) proxy_mat = obj_proxy.material_slots[0].material obj_proxy.data.materials.pop(0,1) proxy_mat.user_clear() bpy.data.materials.remove(proxy_mat) bpy.ops.object.select_all(action='TOGGLE') if(coat3D.importlevel): obj_proxy.select = True obj_proxy.modifiers.new(name='temp',type='MULTIRES') objekti.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 obj_data = objekti.data.id_data objekti.data = obj_proxy.data.id_data if(bpy.data.meshes[obj_data.name].users == 0): bpy.data.meshes.remove(obj_data) objekti.data.id_data.name = obj_data.name obj_proxy.select = True bpy.ops.object.delete() objekti.select = True bpy.context.scene.objects.active = objekti 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(coa.objectdir))): coat3D.importmesh = False if(mat_list and coat3D.importmesh): for mat_one in mat_list: objekti.data.materials.append(mat_one) objekti.active_material_index = act_mat_index if(mat_list): for obj_mate in objekti.material_slots: if(hasattr(obj_mate.material,'texture_slots')): for tex_slot in obj_mate.material.texture_slots: if(hasattr(tex_slot,'texture')): if(tex_slot.texture.type == 'IMAGE'): if tex_slot.texture.image is not None: tex_slot.texture.image.reload() if(coat3D.importmod): for mod_index in objekti.modifiers[:]: objekti.modifiers.remove(mod_index) if(coat3D.importtextures): export = '' tex.gettex(mat_list,objekti,scene,export) if(multires_on): temp_file = coat3D.exchangedir temp_file += ('%stemp2.btx'%(os.sep)) if(objekti.modifiers[multires_name].levels == 0): objekti.modifiers[multires_name].levels = 1 bpy.ops.object.multires_external_save(filepath=temp_file) objekti.modifiers[multires_name].filepath = multires objekti.modifiers[multires_name].levels = 0 else: bpy.ops.object.multires_external_save(filepath=temp_file) objekti.modifiers[multires_name].filepath = multires #bpy.ops.object.multires_external_pack() bpy.ops.object.shade_smooth() for act_name in test: act_name.select = True bpy.context.scene.objects.active = act_first return {'FINISHED'}
def invoke(self, context, event): scene = context.scene coat3D = bpy.context.scene.coat3D coat = bpy.coat3D test = bpy.context.selected_objects act_first = bpy.context.scene.objects.active bpy.context.scene.game_settings.material_mode = 'GLSL' coat3D.exchangedir = set_exchange_folder() folder_objects, folder_textures = set_working_folders() Blender_folder = ("%s%sBlender" % (coat3D.exchangedir, os.sep)) Blender_export = Blender_folder path3b_now = coat3D.exchangedir path3b_now += ('last_saved_3b_file.txt') Blender_export += ('%sexport.txt' % (os.sep)) new_applink_name = 'False' new_object = False if (os.path.isfile(Blender_export)): obj_pathh = open(Blender_export) new_object = True for line in obj_pathh: new_applink_name = line break obj_pathh.close() for scene_objects in bpy.context.scene.objects: if (scene_objects.type == 'MESH'): if (scene_objects.coat3D.applink_name == new_applink_name): new_object = False for act_name in test: coa = act_name.coat3D path_object = coa.applink_name if act_name.type == 'MESH' and os.path.isfile(path_object): multires_on = False activeobj = act_name.name mat_list = [] scene.objects[activeobj].select = True objekti = scene.objects[activeobj] coat3D.loca = objekti.location coat3D.rota = objekti.rotation_euler coat3D.dime = objekti.scale #See if there is multres modifier. for modifiers in objekti.modifiers: if modifiers.type == 'MULTIRES' and (modifiers.total_levels > 0): if (not (coat3D.importlevel)): bpy.ops.object.multires_external_pack() multires = coat3D.exchangedir multires += ('%stemp.btx' % (os.sep)) bpy.ops.object.multires_external_save( filepath=multires) #bpy.ops.object.multires_external_pack() multires_on = True multires_name = modifiers.name break exportfile = coat3D.exchangedir path3b_n = coat3D.exchangedir path3b_n += ('last_saved_3b_file.txt') 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() os.remove(exportfile) if (len(objekti.material_slots) == 0): delete_material = False else: delete_material = True if (not (objekti.active_material) and objekti.material_slots): act_mat_index = objekti.active_material_index materials_old = bpy.data.materials.keys() bpy.ops.material.new() materials_new = bpy.data.materials.keys() new_ma = list( set(materials_new).difference(set(materials_old))) new_mat = new_ma[0] ki = bpy.data.materials[new_mat] objekti.material_slots[act_mat_index].material = ki if (os.path.isfile(path_object) and (coa.objecttime != str(os.path.getmtime(path_object)))): if (objekti.material_slots): act_mat_index = objekti.active_material_index for obj_mat in objekti.material_slots: mat_list.append(obj_mat.material) coa.dime = objekti.dimensions coa.objecttime = str(os.path.getmtime(path_object)) mtl = coa.applink_name mtl = mtl.replace('.obj', '.mtl') if (os.path.isfile(mtl)): os.remove(mtl) bpy.ops.import_scene.obj(filepath=path_object, axis_forward='X', axis_up='Y') obj_proxy = scene.objects[0] bpy.ops.object.select_all(action='TOGGLE') obj_proxy.select = True bpy.ops.object.transform_apply(rotation=True) proxy_mat = obj_proxy.material_slots[0].material if (delete_material): obj_proxy.data.materials.pop(0, 1) proxy_mat.user_clear() bpy.data.materials.remove(proxy_mat) bpy.ops.object.select_all(action='TOGGLE') if (coat3D.importlevel): obj_proxy.select = True obj_proxy.modifiers.new(name='temp', type='MULTIRES') objekti.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 obj_data = objekti.data.id_data objekti.data = obj_proxy.data.id_data if (bpy.data.meshes[obj_data.name].users == 0): bpy.data.meshes.remove(obj_data) objekti.data.id_data.name = obj_data.name obj_proxy.select = True bpy.ops.object.delete() objekti.select = True objekti.scale = coat3D.dime bpy.context.scene.objects.active = objekti 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(path_object))): coat3D.importmesh = False if (mat_list and coat3D.importmesh): for mat_one in mat_list: objekti.data.materials.append(mat_one) objekti.active_material_index = act_mat_index if (mat_list): for obj_mate in objekti.material_slots: if (hasattr(obj_mate.material, 'texture_slots')): for tex_slot in obj_mate.material.texture_slots: if (hasattr(tex_slot, 'texture')): if (tex_slot.texture.type == 'IMAGE'): if tex_slot.texture.image is not None: tex_slot.texture.image.reload() if (coat3D.importtextures): export = '' tex.gettex(mat_list, objekti, scene, export) if (multires_on): temp_file = coat3D.exchangedir temp_file += ('%stemp2.btx' % (os.sep)) if (objekti.modifiers[multires_name].levels == 0): objekti.modifiers[multires_name].levels = 1 bpy.ops.object.multires_external_save( filepath=temp_file) objekti.modifiers[multires_name].filepath = multires objekti.modifiers[multires_name].levels = 0 else: bpy.ops.object.multires_external_save( filepath=temp_file) objekti.modifiers[multires_name].filepath = multires #bpy.ops.object.multires_external_pack() bpy.ops.object.shade_smooth() for act_name in test: act_name.select = True bpy.context.scene.objects.active = act_first if (new_object == True): coat3D = bpy.context.scene.coat3D scene = context.scene Blender_folder = ("%s%sBlender" % (coat3D.exchangedir, os.sep)) Blender_export = Blender_folder path3b_now = coat3D.exchangedir path3b_now += ('last_saved_3b_file.txt') Blender_export += ('%sexport.txt' % (os.sep)) mat_list = [] obj_path = '' export = new_applink_name mod_time = os.path.getmtime(new_applink_name) mtl_list = new_applink_name.replace('.obj', '.mtl') if (os.path.isfile(mtl_list)): os.remove(mtl_list) bpy.ops.import_scene.obj(filepath=new_applink_name, axis_forward='X', axis_up='Y') bpy.ops.object.transform_apply(rotation=True) new_obj = scene.objects[0] new_obj.coat3D.applink_name = obj_path scene.objects[ 0].coat3D.applink_name = export #objectdir muutettava os.remove(Blender_export) bpy.context.scene.objects.active = new_obj bpy.ops.object.shade_smooth() Blender_tex = ("%s%stextures.txt" % (coat3D.exchangedir, os.sep)) mat_list.append(new_obj.material_slots[0].material) tex.gettex(mat_list, new_obj, scene, export) return {'FINISHED'}
def invoke(self, context, event): scene = context.scene coat3D = bpy.context.scene.coat3D coat = bpy.coat3D test = bpy.context.selected_objects act_first = bpy.context.scene.objects.active bpy.context.scene.game_settings.material_mode = 'GLSL' coat3D.exchangedir = set_exchange_folder() folder_objects,folder_textures = set_working_folders() Blender_folder = ("%s%sBlender"%(coat3D.exchangedir,os.sep)) Blender_export = Blender_folder path3b_now = coat3D.exchangedir path3b_now += ('last_saved_3b_file.txt') Blender_export += ('%sexport.txt'%(os.sep)) new_applink_name = 'False' new_object = False if(os.path.isfile(Blender_export)): obj_pathh = open(Blender_export) new_object = True for line in obj_pathh: new_applink_name = line break obj_pathh.close() for scene_objects in bpy.context.scene.objects: if(scene_objects.type == 'MESH'): if(scene_objects.coat3D.applink_name == new_applink_name): new_object = False for act_name in test: coa = act_name.coat3D path_object = coa.applink_name if act_name.type == 'MESH' and os.path.isfile(path_object): multires_on = False activeobj = act_name.name mat_list = [] scene.objects[activeobj].select = True objekti = scene.objects[activeobj] coat3D.loca = objekti.location coat3D.rota = objekti.rotation_euler coat3D.dime = objekti.scale #See if there is multres modifier. for modifiers in objekti.modifiers: if modifiers.type == 'MULTIRES' and (modifiers.total_levels > 0): if(not(coat3D.importlevel)): bpy.ops.object.multires_external_pack() multires = coat3D.exchangedir multires += ('%stemp.btx'%(os.sep)) bpy.ops.object.multires_external_save(filepath=multires) #bpy.ops.object.multires_external_pack() multires_on = True multires_name = modifiers.name break exportfile = coat3D.exchangedir path3b_n = coat3D.exchangedir path3b_n += ('last_saved_3b_file.txt') 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() os.remove(exportfile) if(len(objekti.material_slots) == 0): delete_material = False else: delete_material = True if(not(objekti.active_material) and objekti.material_slots): act_mat_index = objekti.active_material_index materials_old = bpy.data.materials.keys() bpy.ops.material.new() materials_new = bpy.data.materials.keys() new_ma = list(set(materials_new).difference(set(materials_old))) new_mat = new_ma[0] ki = bpy.data.materials[new_mat] objekti.material_slots[act_mat_index].material = ki if(os.path.isfile(path_object) and (coa.objecttime != str(os.path.getmtime(path_object)))): if(objekti.material_slots): act_mat_index = objekti.active_material_index for obj_mat in objekti.material_slots: mat_list.append(obj_mat.material) coa.dime = objekti.dimensions coa.objecttime = str(os.path.getmtime(path_object)) mtl = coa.applink_name mtl = mtl.replace('.obj','.mtl') if(os.path.isfile(mtl)): os.remove(mtl) bpy.ops.import_scene.obj(filepath=path_object,axis_forward='-Z',axis_up='Y',use_image_search=False) obj_proxy = scene.objects[0] bpy.ops.object.select_all(action='TOGGLE') obj_proxy.select = True bpy.ops.object.transform_apply(rotation=True) proxy_mat = obj_proxy.material_slots[0].material if(delete_material): while(list(obj_proxy.data.materials) != []): proxy_mat = obj_proxy.material_slots[0].material obj_proxy.data.materials.pop(0,1) proxy_mat.user_clear() bpy.data.materials.remove(proxy_mat) bpy.ops.object.select_all(action='TOGGLE') if(coat3D.importlevel): obj_proxy.select = True obj_proxy.modifiers.new(name='temp',type='MULTIRES') objekti.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 obj_data = objekti.data.id_data objekti.data = obj_proxy.data.id_data if(bpy.data.meshes[obj_data.name].users == 0): objekti.data.id_data.name = obj_data.name bpy.data.meshes.remove(obj_data) obj_proxy.select = True bpy.ops.object.delete() objekti.select = True objekti.scale = coat3D.dime bpy.context.scene.objects.active = objekti 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(path_object))): coat3D.importmesh = False if(mat_list and coat3D.importmesh): for mat_one in mat_list: objekti.data.materials.append(mat_one) objekti.active_material_index = act_mat_index if(mat_list): for obj_mate in objekti.material_slots: if(hasattr(obj_mate.material,'texture_slots')): for tex_slot in obj_mate.material.texture_slots: if(hasattr(tex_slot,'texture')): if(tex_slot.texture.type == 'IMAGE'): if tex_slot.texture.image is not None: tex_slot.texture.image.reload() if(coat3D.importtextures): export = '' tex.gettex(mat_list,objekti,scene,export) if(multires_on): temp_file = coat3D.exchangedir temp_file += ('%stemp2.btx'%(os.sep)) if(objekti.modifiers[multires_name].levels == 0): objekti.modifiers[multires_name].levels = 1 bpy.ops.object.multires_external_save(filepath=temp_file) objekti.modifiers[multires_name].filepath = multires objekti.modifiers[multires_name].levels = 0 else: bpy.ops.object.multires_external_save(filepath=temp_file) objekti.modifiers[multires_name].filepath = multires #bpy.ops.object.multires_external_pack() bpy.ops.object.shade_smooth() for act_name in test: act_name.select = True bpy.context.scene.objects.active = act_first if(new_object == True): coat3D = bpy.context.scene.coat3D scene = context.scene Blender_folder = ("%s%sBlender"%(coat3D.exchangedir,os.sep)) Blender_export = Blender_folder path3b_now = coat3D.exchangedir path3b_now += ('last_saved_3b_file.txt') Blender_export += ('%sexport.txt'%(os.sep)) mat_list = [] obj_path ='' export = new_applink_name mod_time = os.path.getmtime(new_applink_name) mtl_list = new_applink_name.replace('.obj','.mtl') if(os.path.isfile(mtl_list)): os.remove(mtl_list) bpy.ops.import_scene.obj(filepath=new_applink_name,axis_forward='-Z',axis_up='Y') bpy.ops.object.transform_apply(rotation=True) new_obj = scene.objects[0] new_obj.coat3D.applink_name = obj_path scene.objects[0].coat3D.applink_name = export #objectdir muutettava os.remove(Blender_export) bpy.context.scene.objects.active = new_obj bpy.ops.object.shade_smooth() Blender_tex = ("%s%stextures.txt"%(coat3D.exchangedir,os.sep)) mat_list.append(new_obj.material_slots[0].material) tex.gettex(mat_list, new_obj, scene,export) return {'FINISHED'}
def draw(self, context): layout = self.layout scene = context.scene me = context.scene.objects mat_list = [] import_no = 0 coat = bpy.coat3D coat3D = bpy.context.scene.coat3D if bpy.context.scene.objects.active: coa = bpy.context.scene.objects.active.coat3D if os.path.isdir(coat3D.exchangedir): foldder = coat3D.exchangedir if foldder.rfind("Exchange") >= 0: coat["status"] = 1 else: coat["status"] = 0 else: coat["status"] = 0 # Here you add your GUI row = layout.row() row.prop(coat3D, "type", text="") row = layout.row() colL = row.column() colR = row.column() if context.selected_objects: if context.selected_objects[0].type == "MESH": row.active = True else: row.active = False else: row.active = False colL.operator("export_applink.pilgway_3d_coat", text="Export") colL.label(text="Export Settings:") colL.prop(coat3D, "exportover") if coat3D.exportover: colL.prop(coat3D, "exportmod") colL.prop(coat3D, "exportfile") colL.prop(coat3D, "export_pos") colR.operator("import_applink.pilgway_3d_coat", text="Import") colR.label(text="Import Settings:") colR.prop(coat3D, "importmesh") colR.prop(coat3D, "importmod") colR.prop(coat3D, "smooth_on") colR.prop(coat3D, "importtextures") row = layout.row() if bpy.context.selected_objects: if context.selected_objects[0].type == "MESH": coa = context.selected_objects[0].coat3D colL = row.column() colR = row.column() colL.label(text="Object Path:") if coa.path3b: colR.active = True else: colR.active = False colR.operator("import_applink.pilgway_3d_coat_3b", text="Load 3b") row = layout.row() row.prop(coa, "objectdir", text="") row = layout.row() if coat["status"] == 1: Blender_folder = "%s%sBlender" % (coat3D.exchangedir, os.sep) Blender_export = Blender_folder Blender_export = Blender_folder path3b_now = coat3D.exchangedir path3b_now += "last_saved_3b_file.txt" Blender_export += "%sexport.txt" % (os.sep) if not (os.path.isdir(Blender_folder)): os.makedirs(Blender_folder) Blender_folder = os.path.join(Blender_folder, "run.txt") file = open(Blender_folder, "w") file.close() if os.path.isfile(Blender_export): obj_path = "" obj_pathh = open(Blender_export) for line in obj_pathh: obj_path = line break obj_pathh.close() export = obj_path mod_time = os.path.getmtime(obj_path) mtl_list = obj_path.replace(".obj", ".mtl") if os.path.isfile(mtl_list): os.remove(mtl_list) if os.path.isfile(path3b_now): path3b_file = open(path3b_now) for lin in path3b_file: path_export = lin path_on = 1 path3b_file.close() os.remove(path3b_now) else: print("ei toimi") path_on = 0 for palikka in bpy.context.scene.objects: if palikka.type == "MESH": if palikka.coat3D.objectdir == export: import_no = 1 target = palikka break if import_no: new_obj = palikka import_no = 0 else: bpy.ops.import_scene.obj(filepath=obj_path) new_obj = scene.objects[0] scene.objects[0].coat3D.objectdir = export if path_on: scene.objects[0].coat3D.path3b = path_export os.remove(Blender_export) bpy.context.scene.objects.active = new_obj if coat3D.smooth_on: bpy.ops.object.shade_smooth() else: bpy.ops.object.shade_flat() Blender_tex = "%s%stextures.txt" % (coat3D.exchangedir, os.sep) mat_list.append(new_obj.material_slots[0].material) tex.gettex(mat_list, new_obj, scene, export) if context.selected_objects: if context.selected_objects[0].type == "MESH": coa = bpy.context.selected_objects[0].coat3D row = layout.row() row.label(text="Texture output folder:") row = layout.row() row.prop(coa, "texturefolder", text="") row = layout.row() if coat["status"] == 0: row.label(text="Exchange Folder: not connected") else: row.label(text="Exchange Folder: connected")
def invoke(self, context, event): scene = context.scene coat3D = bpy.context.scene.coat3D coat = bpy.coat3D activeobj = bpy.context.active_object.name mat_list = [] scene.objects[activeobj].select = True objekti = scene.objects[activeobj] coat3D.loca = objekti.location coat3D.rota = objekti.rotation_euler coa = bpy.context.scene.objects.active.coat3D exportfile = coat3D.exchangedir path3b_n = coat3D.exchangedir path3b_n += "last_saved_3b_file.txt" 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() os.remove(exportfile) if objekti.material_slots: for obj_mat in objekti.material_slots: mat_list.append(obj_mat.material) act_mat_index = objekti.active_material_index if coat3D.importmesh and os.path.isfile(coa.objectdir): mtl = coa.objectdir mtl = mtl.replace(".obj", ".mtl") if os.path.isfile(mtl): os.remove(mtl) bpy.ops.import_scene.obj(filepath=coa.objectdir) obj_proxy = scene.objects[0] proxy_mat = obj_proxy.material_slots[0].material obj_proxy.data.materials.pop(0) proxy_mat.user_clear() bpy.data.materials.remove(proxy_mat) bpy.ops.object.select_all(action="TOGGLE") if coat3D.export_pos: scene.objects.active = objekti objekti.select = True coat3D.cursor = bpy.context.scene.cursor_location bpy.context.scene.cursor_location = (0.0, 0.0, 0.0) bpy.ops.object.origin_set(type="ORIGIN_CURSOR", center="MEDIAN") scene.objects.active = obj_proxy obj_data = objekti.data.id_data objekti.data = obj_proxy.data.id_data if coat3D.export_on: objekti.scale = (1, 1, 1) objekti.rotation_euler = (0, 0, 0) if bpy.data.meshes[obj_data.name].users == 0: bpy.data.meshes.remove(obj_data) objekti.data.id_data.name = obj_data.name bpy.ops.object.select_all(action="TOGGLE") obj_proxy.select = True bpy.ops.object.delete() objekti.select = True bpy.context.scene.objects.active = objekti if coat3D.export_on: bpy.ops.object.origin_set(type="ORIGIN_GEOMETRY", center="MEDIAN") coat3D.export_on = False else: objekti.location = coat3D.loca objekti.rotation_euler = coat3D.rota bpy.ops.object.origin_set(type="GEOMETRY_ORIGIN", center="MEDIAN") else: scene.objects.active = obj_proxy obj_data = objekti.data.id_data objekti.data = obj_proxy.data.id_data if bpy.data.meshes[obj_data.name].users == 0: bpy.data.meshes.remove(obj_data) objekti.data.id_data.name = obj_data.name obj_proxy.select = True bpy.ops.object.delete() objekti.select = True bpy.context.scene.objects.active = objekti if coat3D.smooth_on: bpy.ops.object.shade_smooth() else: bpy.ops.object.shade_flat() 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(coa.objectdir)): coat3D.importmesh = False if mat_list and coat3D.importmesh: for mat_one in mat_list: objekti.data.materials.append(mat_one) objekti.active_material_index = act_mat_index if mat_list: for obj_mate in objekti.material_slots: for tex_slot in obj_mate.material.texture_slots: if hasattr(tex_slot, "texture"): if tex_slot.texture.type == "IMAGE": tex_slot.texture.image.reload() if coat3D.importmod: mod_list = [] for mod_index in objekti.modifiers: objekti.modifiers.remove(mod_index) if coat3D.importtextures: export = "" tex.gettex(mat_list, objekti, scene, export) return "FINISHED"