import bpy, math import os from mathutils import Matrix # Specify OBJ files model_files = [ 'objOut/data/level/lv_0', 'objOut/data/level/lv_1', 'objOut/data/level/lv_2', 'objOut/data/level/lv_3', 'objOut/data/level/lv_4', 'objOut/data/level/lv_5', 'objOut/data/level/lv_6', 'objOut/data/level/lv_7', 'objOut/data/level/lv_8', 'objOut/data/level/lv_9', 'objOut/data/level/lv_a', 'objOut/data/level/lv_b', 'objOut/data/level/lv_c', 'objOut/data/level/lv_d', 'objOut/data/level/lv_e', 'objOut/data/level/lv_f', 'objOut/data/level/lv_g', 'objOut/data/level/lv_h', 'objOut/data/level/lv_i', 'objOut/data/level/lv_j' ] # Remove default cube bpy.data.objects.remove(bpy.data.objects["Cube"], do_unlink=True) # Set camera and light position/angle for each map/frame bpy.context.scene.objects.keys() cam = bpy.data.objects['Camera'] light = bpy.data.objects['Light'] cam.matrix_world = Matrix.Identity(4) cam.matrix_world @= Matrix.Translation((0.0, 57.0, 36.0)) cam.matrix_world @= Matrix.Rotation(math.radians(122.0), 4, 'X') @ Matrix.Rotation(math.radians(180.0), 4, 'Y') @ Matrix.Rotation(math.radians(0.0), 4, 'Z') light.matrix_world = Matrix.Identity(4) light.matrix_world @= Matrix.Translation((0.0, 0.0, 10.0)) for frame in range(20): bpy.context.scene.frame_set(frame + 1) cam.matrix_world = Matrix.Identity(4) cam.matrix_world @= Matrix.Translation((frame * 70.0 - 700.0, 57.0, 36.0)) cam.matrix_world @= Matrix.Rotation(math.radians(122.0), 4, 'X') @ Matrix.Rotation(math.radians(180.0), 4, 'Y') @ Matrix.Rotation(math.radians(0.0), 4, 'Z') cam.keyframe_insert(data_path="location", index=-1) light.matrix_world = Matrix.Identity(4) light.matrix_world @= Matrix.Translation((frame * 70.0 - 700.0, 0.0, 10.0)) light.keyframe_insert(data_path="location", index=-1) # Load OBJ file in scene i = 0 for f in model_files: head, collection_name = os.path.split(f) f_path = str(f + '/mapmesh.obj') bpy.ops.import_scene.obj(filepath=f_path) myCol = bpy.data.collections.new(collection_name) bpy.context.scene.collection.children.link(myCol) for ob in bpy.context.selected_objects: myCol.objects.link(ob) ob.matrix_world = Matrix.Identity(4) ob.matrix_world @= Matrix.Rotation(math.radians(90.0), 4, 'X') ob.matrix_world @= Matrix.Translation((i * 70.0 - 700.0, 0.0, 0.0)) i += 1