Skip to content

Commit

Permalink
Merge pull request #34 from Brachi/bugfix/ISSUE-33-no-shadows-exported
Browse files Browse the repository at this point in the history
Bugfix/issue 33 no shadows exported
  • Loading branch information
Brachi committed May 28, 2017
2 parents 5b0d62d + f00f08d commit 7eeadf4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
15 changes: 4 additions & 11 deletions albam/engines/mtframework/blender_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ def _export_meshes(blender_meshes, bounding_box, bone_palettes, exported_materia

m156 = meshes_156[mesh_index]
try:
m156.material_index = materials_mapping[blender_mesh.materials[0].name]
blender_material = blender_mesh.materials[0]
m156.material_index = materials_mapping[blender_material.name]
except IndexError:
# TODO: insert an empty generic material in this case
raise ExportError('Mesh {} has no materials'.format(blender_mesh.name))
Expand All @@ -420,19 +421,11 @@ def _export_meshes(blender_meshes, bounding_box, bone_palettes, exported_materia
m156.vertex_index_start_2 = vertex_position
m156.vertex_group_count = 1 # using 'TEST' bounding box
m156.bone_palette_index = bone_palette_index
# Needs research
m156.group_index = 0

# metadata saved
# TODO: use an util function
for field in m156._fields_:
attr_name = field[0]
if not attr_name.startswith('unk_'):
continue
setattr(m156, attr_name, getattr(blender_mesh, attr_name))
m156.use_cast_shadows = int(blender_material.use_cast_shadows)

vertex_position += vertex_count
face_position += index_count

vertex_buffer = (ctypes.c_ubyte * len(vertex_buffer)).from_buffer(vertex_buffer)
index_buffer = (ctypes.c_ushort * (len(index_buffer) // 2)).from_buffer(index_buffer)

Expand Down
17 changes: 7 additions & 10 deletions albam/engines/mtframework/blender_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ def _build_blender_mesh_from_mod(mod, mesh, mesh_index, name, materials):
imported_vertices = _import_vertices(mod, mesh)
vertex_locations = imported_vertices['locations']
indices = get_indices_array(mod, mesh)
if mod.version == 156:
indices = strip_triangles_to_triangles_list(indices)
else:
start_face = min(indices)
indices = [i - start_face for i in indices]
indices = strip_triangles_to_triangles_list(indices)
uvs_per_vertex = imported_vertices['uvs']
weights_per_bone = imported_vertices['weights_per_bone']

Expand All @@ -116,8 +112,11 @@ def _build_blender_mesh_from_mod(mod, mesh, mesh_index, name, materials):
me_ob.polygons.foreach_set("use_smooth", [True] * len(me_ob.polygons))
me_ob.validate()

if materials:
me_ob.materials.append(materials[mesh.material_index])
mesh_material = materials[mesh.material_index]
if not mesh.use_cast_shadows and mesh_material.use_cast_shadows:
mesh_material.use_cast_shadows = False
me_ob.materials.append(mesh_material)

for bone_index, data in weights_per_bone.items():
vg = ob.vertex_groups.new(str(bone_index))
for vertex_index, weight_value in data:
Expand Down Expand Up @@ -150,8 +149,7 @@ def _build_blender_mesh_from_mod(mod, mesh, mesh_index, name, materials):


def _import_vertices(mod, mesh):
if mod.version == 156:
return _import_vertices_mod156(mod, mesh)
return _import_vertices_mod156(mod, mesh)


def _import_vertices_mod156(mod, mesh):
Expand Down Expand Up @@ -235,7 +233,6 @@ def _create_blender_materials_from_mod(mod, model_name, textures):
continue
attr_value = getattr(material, attr_name)
setattr(blender_material, attr_name, attr_value)

materials.append(blender_material)

for texture_code, tex_index in enumerate(material.texture_indices):
Expand Down
2 changes: 1 addition & 1 deletion albam/engines/mtframework/mod_156.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class Mesh156(LittleEndianStructure):
('unk_flag_03', c_uint8, 1),
('unk_flag_04', c_uint8, 1),
('unk_flag_05', c_uint8, 1),
('cast_shadows', c_uint8, 1),
('use_cast_shadows', c_uint8, 1),
('unk_flag_06', c_uint8, 1),
('unk_flag_07', c_uint8, 1),
('vertex_count', c_ushort),
Expand Down

0 comments on commit 7eeadf4

Please sign in to comment.