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

Commit

Permalink
extract wmos and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skarndev committed Jan 7, 2018
1 parent aed6b53 commit 8d554b9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion io_scene_wmo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class WMOPreferences(bpy.types.AddonPreferences):

fileinfo_path = StringProperty(
name="Path to fileinfo.exe",
subtype='DIR_PATH'
subtype='FILE_PATH'
)

wmv_path = StringProperty(
Expand Down
4 changes: 2 additions & 2 deletions io_scene_wmo/wmo/import_wmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def import_wmo_to_blender_scene(filepath, load_textures, import_doodads, group_o
if group_objects:
bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0))
parent = bpy.context.scene.objects.active
parent.name = wmo.display_name
parent.name = wmo.display_name + ".wmo"
wmo.parent = parent

# load all materials in root file
Expand All @@ -53,7 +53,7 @@ def import_wmo_to_blender_scene(filepath, load_textures, import_doodads, group_o
for group in wmo.groups:
obj_name = wmo.mogn.get_string(group.mogp.GroupNameOfs)
print("\nImporting group <<{}>>".format(obj_name))
group.load_object(wmo, obj_name, import_doodads)
group.load_object(obj_name, import_doodads)

wmo.load_portals()

Expand Down
27 changes: 22 additions & 5 deletions io_scene_wmo/wmo/ui/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ def execute(self, context):
break
i += 1

bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0))
parent = bpy.context.scene.objects.active
parent.name = group_name

for filename in os.listdir(dir):

if filename.endswith(".adt"):
filepath = os.path.join(dir, filename)
subprocess.call([fileinfo_path, filepath])
subprocess.call([fileinfo_path, filepath] )

with open(os.path.splitext(filepath)[0] + ".txt", 'r') as f:

Expand Down Expand Up @@ -115,6 +119,7 @@ def execute(self, context):
entry.insert(0, data[0])
wmo_instances[data[1]] = entry


for uid, instance in m2_instances.items():
obj = None
doodad_path = m2_paths[int(instance[0])]
Expand All @@ -125,6 +130,7 @@ def execute(self, context):
obj = bpy.context.scene.objects.active
print("\nFailed to import model: <<{}>>. Placeholder is imported instead.".format(doodad_path))

obj.name += ".m2"
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 All @@ -136,27 +142,38 @@ def execute(self, context):
obj.WoWDoodad.Path = doodad_path

if self.group_objects:
bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0))
parent = bpy.context.scene.objects.active
parent.name = group_name
obj.parent = parent


from .. import import_wmo
for uid, instance in wmo_instances.items():
obj = None
wmo_path = wmo_paths[int(instance[0])]

game_data.extract_files(save_dir, (wmo_path,))

i = 0
while True:
result = game_data.extract_files(save_dir, (wmo_path[:-4] + "_" + str(i).zfill(3) + ".wmo",))
if not result:
break
i += 1

try:
obj = import_wmo.import_wmo_to_blender_scene(os.path.join(save_dir, wmo_path), True, True, True)
except:
bpy.ops.mesh.primitive_cube_add()
obj = bpy.context.scene.objects.active
print("#nFailed to import model: <<{}>>. Placeholder is imported instead.".format(wmo_path))
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])),
math.radians(float(instance[5]) + 90))

if self.group_objects:
obj.parent = parent

return {'FINISHED'}

def invoke(self, context, event):
Expand Down
17 changes: 10 additions & 7 deletions io_scene_wmo/wmo/wmo_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ def load_liquids(self, group_name, pos):
obj.WowLiquid.LiquidType = str(real_liquid_type)
obj.WowLiquid.WMOGroup = group_name

if self.root.parent:
obj.parent = self.root.parent

# Return faces indices
def get_bsp_node_indices(self, i_node, nodes, faces, indices):
""" Get indices of a WMO BSP tree nodes """
Expand Down Expand Up @@ -304,7 +307,7 @@ def get_collision_indices(self):
return indices

# Create mesh from file data
def load_object(self, root, obj_name, editable_doodads):
def load_object(self, obj_name, editable_doodads):
""" Load WoW WMO group as an object to the Blender scene """
custom_normals = []
faces = []
Expand Down Expand Up @@ -489,10 +492,10 @@ def load_object(self, root, obj_name, editable_doodads):
nobj.WowWMOGroup.GroupDesc = self.root.mogn.get_string(self.mogp.DescGroupNameOfs)
nobj.WowWMOGroup.GroupDBCid = int(self.mogp.GroupID)

nobj.WowWMOGroup.Fog1 = root.display_name + "_Fog_" + str(self.mogp.FogIndices[0]).zfill(2)
nobj.WowWMOGroup.Fog2 = root.display_name + "_Fog_" + str(self.mogp.FogIndices[1]).zfill(2)
nobj.WowWMOGroup.Fog3 = root.display_name + "_Fog_" + str(self.mogp.FogIndices[2]).zfill(2)
nobj.WowWMOGroup.Fog4 = root.display_name + "_Fog_" + str(self.mogp.FogIndices[3]).zfill(2)
nobj.WowWMOGroup.Fog1 = self.root.display_name + "_Fog_" + str(self.mogp.FogIndices[0]).zfill(2)
nobj.WowWMOGroup.Fog2 = self.root.display_name + "_Fog_" + str(self.mogp.FogIndices[1]).zfill(2)
nobj.WowWMOGroup.Fog3 = self.root.display_name + "_Fog_" + str(self.mogp.FogIndices[2]).zfill(2)
nobj.WowWMOGroup.Fog4 = self.root.display_name + "_Fog_" + str(self.mogp.FogIndices[3]).zfill(2)

if self.mogp.Flags & MOGP_FLAG.HasWater:
self.load_liquids(obj_name, nobj.location)
Expand Down Expand Up @@ -544,8 +547,8 @@ def load_object(self, root, obj_name, editable_doodads):
if scn.objects.active is None or scn.objects.active.mode == 'OBJECT':
scn.objects.active = nobj

if root.parent:
nobj.parent = root.parent
if self.root.parent:
nobj.parent = self.root.parent

def get_portal_direction(self, portal_obj, group_obj):
""" Get the direction of MOPR portal relation given a portal object and a target group """
Expand Down

0 comments on commit 8d554b9

Please sign in to comment.