From a605f4b6a90e71ecc5bc69220f33741c7d2a6e30 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Tue, 7 Feb 2023 22:18:26 +0100 Subject: [PATCH] Added Blender map renderer tool --- tools/map_render.py | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tools/map_render.py diff --git a/tools/map_render.py b/tools/map_render.py new file mode 100644 index 0000000..b552278 --- /dev/null +++ b/tools/map_render.py @@ -0,0 +1,67 @@ +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 + \ No newline at end of file