From 343e415b5ecc3894c4c40e3862edabea3bc053c1 Mon Sep 17 00:00:00 2001 From: Skarn Date: Mon, 8 Jan 2018 00:37:59 +0300 Subject: [PATCH] implement basic m2 caching --- io_scene_wmo/wmo/ui/operators.py | 34 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/io_scene_wmo/wmo/ui/operators.py b/io_scene_wmo/wmo/ui/operators.py index c342e97..0eabd73 100644 --- a/io_scene_wmo/wmo/ui/operators.py +++ b/io_scene_wmo/wmo/ui/operators.py @@ -120,15 +120,27 @@ def execute(self, context): wmo_instances[data[1]] = entry + instance_cache = {} + + # import M2s for uid, instance in m2_instances.items(): - obj = None doodad_path = m2_paths[int(instance[0])] - try: - obj = m2.m2_to_blender_mesh(save_dir, doodad_path, game_data) - except: - bpy.ops.mesh.primitive_cube_add() - obj = bpy.context.scene.objects.active - print("\nFailed to import model: <<{}>>. Placeholder is imported instead.".format(doodad_path)) + cached_obj = instance_cache.get(doodad_path) + + if cached_obj: + obj = cached_obj.copy() + obj.data = cached_obj.data.copy() + bpy.context.scene.objects.link(obj) + + else: + try: + obj = m2.m2_to_blender_mesh(save_dir, doodad_path, game_data) + except: + bpy.ops.mesh.primitive_cube_add() + obj = bpy.context.scene.objects.active + print("\nFailed to import model: <<{}>>. Placeholder is imported instead.".format(doodad_path)) + + instance_cache[doodad_path] = obj obj.name += ".m2" obj.location = ((-float(instance[1])), (float(instance[3])), float(instance[2])) @@ -144,12 +156,15 @@ def execute(self, context): if self.group_objects: obj.parent = parent - + # import WMOs from .. import import_wmo for uid, instance in wmo_instances.items(): - obj = None + wmo_path = wmo_paths[int(instance[0])] + cached_obj = instance_cache.get(wmo_path) + + game_data.extract_files(save_dir, (wmo_path,)) i = 0 @@ -166,6 +181,7 @@ def execute(self, context): obj = bpy.context.scene.objects.active print("\nFailed to import model: <<{}>>. Placeholder is imported instead.".format(wmo_path)) + obj.location = ((-float(instance[1])), (float(instance[3])), float(instance[2])) obj.rotation_euler = (math.radians(float(instance[6])), math.radians(float(instance[4])),