import bpy import os # if global is defined, it overrides next 3 parameters global_name = "pitt23_notextures" txt_name = "" folder_name = "" save_filename = "" # check if values are hardset or not if len(global_name) > 0: txt_name = global_name + "/octants.txt" folder_name = global_name save_filename = global_name + ".blend" max_depth = "23" prefix = '/home/tristan/Documents/earth-reverse-engineering/exporter/' # create our empty #bpy.ops.object.add(type='EMPTY', align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) my_empty = bpy.data.objects['Empty-col']#bpy.context.active_object # create collection underneath parent coll def create_coll(parent_layer_collection, collection_name): new_col = bpy.data.collections.new(collection_name) parent_layer_collection.collection.children.link(new_col) new_child_layer_coll = parent_layer_collection.children.get(new_col.name) bpy.context.view_layer.active_layer_collection = new_child_layer_coll return new_child_layer_coll # create a master collection to batch import the files to master_collection = bpy.context.view_layer.active_layer_collection new_collection = create_coll(master_collection, "earth").collection # helper to change shading def set_shading(object, OnOff=True): """ Set the shading mode of an object True means turn smooth shading on. False means turn smooth shading off. """ if not object: return if not object.type == 'MESH': return if not object.data: return polygons = object.data.polygons polygons.foreach_set('use_smooth', [OnOff] * len(polygons)) object.data.update() # read in all model names with open(prefix + txt_name, 'r') as fi: files = fi.read() files_list = [f for f in files.split("\n") if os.path.isfile(prefix + folder_name + '/obj/' + f + '-' + max_depth + '-925/model.obj')] # iterate over the files and import them count = 0 for f in files.split("\n"): if count < 5000: obj_filename = prefix + folder_name + '/obj/' + f + '-' + max_depth + '-925/model.obj' #obj_filename = "/home/tristan/Documents/earth-reverse-engineering/exporter/thingyyy5/obj/30604060734141415403-23-900/model.obj" if os.path.isfile(obj_filename): bpy.ops.import_scene.obj(filepath=obj_filename, axis_up='Y', use_smooth_groups=False, use_split_objects=False) #new_o.parent = my_empty print("[" + str(count) + "/" + str(len(files_list)) + "]") #if count % 50 == 0: # bpy.ops.wm.save_as_mainfile(filepath=prefix+save_filename) count += 1 for x in bpy.data.textures: x.extension = 'EXTEND' #for o in bpy.data.objects: # # enable back culling for m in bpy.data.materials: m.use_backface_culling = True # disable shading and append -col to obj for o in bpy.data.objects: set_shading(o, False) o.name = o.name + "-col" if "Empty" not in o.name: o.parent = my_empty # disable auto-smooth for m in bpy.data.meshes: m.use_auto_smooth = False # save file bpy.ops.wm.save_as_mainfile(filepath=prefix+save_filename)