Skip to content
This repository was archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
implement basic m2 caching
Browse files Browse the repository at this point in the history
  • Loading branch information
skarndev committed Jan 7, 2018
1 parent 8d554b9 commit 343e415
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions io_scene_wmo/wmo/ui/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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
Expand All @@ -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])),
Expand Down

0 comments on commit 343e415

Please sign in to comment.