Skip to content

Commit

Permalink
Add vertex color support to lightmapper
Browse files Browse the repository at this point in the history
  • Loading branch information
General-101 committed Oct 23, 2024
1 parent cb0526d commit 0cf6c2e
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 159 deletions.
241 changes: 134 additions & 107 deletions io_scene_halo/file_qua/process_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,14 @@
from .format import QUAAsset
from ..global_functions import global_functions

def parse_legacy_file(QUA):
QUA.units = []
QUA.scenery = []
QUA.effects_scenery = []
QUA.objects = []
QUA.shots = []
QUA.extra_cameras = []

QUA.version = int(QUA.next())
if not QUA.version == 5:
raise global_functions.ParseError("Importer does not support this %s version" % "QUA")

if QUA.version >= 5:
QUA.scene_name = QUA.next()
shot_count = int(QUA.next())
unit_count = int(QUA.next())
for unit_idx in range(unit_count):
qua_object = QUAAsset.Object()
qua_object.export_name = QUA.next()
qua_object.object_path = QUA.next()
qua_object.bits = []
def parse_legacy_unit(QUA, unit_version):
unit_count = int(QUA.next())
for unit_idx in range(unit_count):
qua_object = QUAAsset.Object()
qua_object.export_name = QUA.next()
qua_object.object_path = QUA.next()
qua_object.bits = []
if unit_version >= 3:
bit_list = QUA.next().split()
for bit in bit_list:
# Inverting this here for Blender
Expand All @@ -58,122 +45,162 @@ def parse_legacy_file(QUA):
elif bit == "1":
qua_object.bits.append(False)

QUA.units.append(qua_object)
QUA.units.append(qua_object)

scenery_count = int(QUA.next())
for scenery_idx in range(scenery_count):
qua_object = QUAAsset.Object()
qua_object.export_name = QUA.next()
qua_object.object_path = QUA.next()
qua_object.bits = []
def parse_legacy_scenery(QUA, scenery_version):
scenery_count = int(QUA.next())
for scenery_idx in range(scenery_count):
qua_object = QUAAsset.Object()
qua_object.export_name = QUA.next()
qua_object.object_path = QUA.next()
qua_object.bits = []
if scenery_version >= 3:
bit_list = QUA.next().split()
for bit in bit_list:
if bit == "0":
qua_object.bits.append(True)
elif bit == "1":
qua_object.bits.append(False)

QUA.scenery.append(qua_object)
QUA.scenery.append(qua_object)

effect_scenery_count = int(QUA.next())
for effect_scenery_idx in range(effect_scenery_count):
qua_object = QUAAsset.Object()
qua_object.export_name = QUA.next()
qua_object.object_path = QUA.next()
qua_object.bits = []
bit_list = QUA.next().split()
for bit in bit_list:
if bit == "0":
qua_object.bits.append(True)
elif bit == "1":
qua_object.bits.append(False)
def parse_legacy_effect_scenery(QUA):
scenery_count = int(QUA.next())
for scenery_idx in range(scenery_count):
qua_object = QUAAsset.Object()
qua_object.export_name = QUA.next()
qua_object.object_path = QUA.next()
qua_object.bits = []
bit_list = QUA.next().split()
for bit in bit_list:
if bit == "0":
qua_object.bits.append(True)
elif bit == "1":
qua_object.bits.append(False)

QUA.effects_scenery.append(qua_object)
QUA.scenery.append(qua_object)

for shot_idx in range(shot_count):
shot = QUAAsset.Shots()
shot.audio_data_version = 0
shot.custom_script_data_version = 0
shot.effect_data_version = 0
shot.frames = []
shot.audio_data = []
shot.custom_script_data = []
shot.effect_data = []
def parse_legacy_shot(QUA, shot_count, shot_version):
for shot_idx in range(shot_count):
shot = QUAAsset.Shots()
shot.audio_data_version = 0
shot.custom_script_data_version = 0
shot.effect_data_version = 0
shot.frames = []
shot.audio_data = []
shot.custom_script_data = []
shot.effect_data = []

frame_count = int(QUA.next())
for frame_idx in range(frame_count):
frame = QUAAsset.Frames()
frame.position = QUA.next_vector_space()
frame.up = QUA.next_vector_space()
frame.forward = QUA.next_vector_space()
frame.fov = float(QUA.next())
frame_count = int(QUA.next())
for frame_idx in range(frame_count):
frame = QUAAsset.Frames()
frame.position = QUA.next_vector_space()
frame.up = QUA.next_vector_space()
frame.forward = QUA.next_vector_space()
frame.fov = float(QUA.next())
if shot_version >= 4:
frame.aperture = float(QUA.next())
frame.focal_length = float(QUA.next())
frame.depth_of_field = bool(int(QUA.next()))
frame.near_focal = float(QUA.next())
frame.far_focal = float(QUA.next())
frame.focal_depth = float(QUA.next())
frame.blur_amount = float(QUA.next())

shot.frames.append(frame)
frame.focal_length = float(QUA.next())
frame.depth_of_field = bool(int(QUA.next()))
frame.near_focal = float(QUA.next())
frame.far_focal = float(QUA.next())
frame.focal_depth = float(QUA.next())
frame.blur_amount = float(QUA.next())

audio_count = int(QUA.next())
for audio_idx in range(audio_count):
audio = QUAAsset.AudioData()
audio.audio_filename = QUA.next()
audio.frame = int(QUA.next())
audio.character = QUA.next()
shot.frames.append(frame)

shot.audio_data.append(audio)
audio_count = int(QUA.next())
for audio_idx in range(audio_count):
audio = QUAAsset.AudioData()
audio.audio_filename = QUA.next()
audio.frame = int(QUA.next())
audio.character = QUA.next()

QUA.shots.append(shot)
shot.audio_data.append(audio)

extra_camera_count = int(QUA.next())
for extra_camera_idx in range(extra_camera_count):
extra_camera = QUAAsset.ExtraCamera()
extra_camera.name = QUA.next()
extra_camera.camera_type = QUA.next()
extra_camera.extra_shots = []
for shot in QUA.shots:
extra_shot = QUAAsset.Shots()
extra_shot.frames = []
extra_shot.audio_data = []
QUA.shots.append(shot)

for frame in shot.frames:
extra_frame = QUAAsset.Frames()
camera_is_enabled = bool(int(QUA.next()))
if camera_is_enabled:
extra_frame.camera_is_enabled = False
else:
extra_frame.camera_is_enabled = True
extra_frame.position = QUA.next_vector_space()
extra_frame.up = QUA.next_vector_space()
extra_frame.forward = QUA.next_vector_space()
extra_frame.fov = float(QUA.next())
extra_frame.focal_length = float(QUA.next())
extra_frame.depth_of_field = bool(int(QUA.next()))
extra_frame.near_focal = float(QUA.next())
extra_frame.far_focal = float(QUA.next())
extra_frame.focal_depth = float(QUA.next())
extra_frame.blur_amount = float(QUA.next())
def parse_legacy_extra_cameras(QUA):
extra_camera_count = int(QUA.next())
for extra_camera_idx in range(extra_camera_count):
extra_camera = QUAAsset.ExtraCamera()
extra_camera.name = QUA.next()
extra_camera.camera_type = QUA.next()
extra_camera.extra_shots = []
for shot in QUA.shots:
extra_shot = QUAAsset.Shots()
extra_shot.frames = []
extra_shot.audio_data = []

extra_shot.frames.append(extra_frame)
for frame in shot.frames:
extra_frame = QUAAsset.Frames()
camera_is_enabled = bool(int(QUA.next()))
if camera_is_enabled:
extra_frame.camera_is_enabled = False
else:
extra_frame.camera_is_enabled = True
extra_frame.position = QUA.next_vector_space()
extra_frame.up = QUA.next_vector_space()
extra_frame.forward = QUA.next_vector_space()
extra_frame.fov = float(QUA.next())
extra_frame.focal_length = float(QUA.next())
extra_frame.depth_of_field = bool(int(QUA.next()))
extra_frame.near_focal = float(QUA.next())
extra_frame.far_focal = float(QUA.next())
extra_frame.focal_depth = float(QUA.next())
extra_frame.blur_amount = float(QUA.next())

extra_camera.extra_shots.append(extra_shot)
extra_shot.frames.append(extra_frame)

QUA.extra_cameras.append(extra_camera)
extra_camera.extra_shots.append(extra_shot)

QUA.extra_cameras.append(extra_camera)

def parse_legacy_file(QUA):
QUA.units = []
QUA.scenery = []
QUA.effects_scenery = []
QUA.objects = []
QUA.shots = []
QUA.extra_cameras = []

QUA.version = int(QUA.next())
if QUA.version >= 5:
QUA.scene_name = QUA.next()
shot_count = int(QUA.next())
parse_legacy_unit(QUA, 5)
parse_legacy_scenery(QUA, 5)
parse_legacy_effect_scenery(QUA)
parse_legacy_shot(QUA, shot_count, 5)
parse_legacy_extra_cameras(QUA)

elif QUA.version == 4:
print("Not Implemented")
QUA.scene_name = QUA.next()
shot_count = int(QUA.next())
parse_legacy_unit(QUA, 4)
parse_legacy_scenery(QUA, 4)
parse_legacy_shot(QUA, shot_count, 4)
parse_legacy_extra_cameras(QUA)

elif QUA.version >= 3:
print("Not Implemented")
QUA.scene_name = QUA.next()
shot_count = int(QUA.next())
parse_legacy_unit(QUA, 3)
parse_legacy_scenery(QUA, 3)
parse_legacy_shot(QUA, shot_count, 3)
parse_legacy_extra_cameras(QUA)

elif QUA.version == 2:
print("Not Implemented")
QUA.scene_name = QUA.next()
parse_legacy_unit(QUA, 2)
parse_legacy_scenery(QUA, 2)
shot_count = int(QUA.next())
parse_legacy_shot(QUA, shot_count, 2)
parse_legacy_extra_cameras(QUA)

elif QUA.version == 1:
print("Not Implemented")
raise global_functions.ParseError("Importer does not support this %s version" % "QUA")

def parse_type_main_file(QUA):
QUA.scene_version = int(QUA.next())
Expand Down
50 changes: 11 additions & 39 deletions io_scene_halo/file_tag/build_scene/build_lightmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,20 @@
def process_mesh(SBSP_ASSET, random_color_gen, tag_block, poop_name, material_count, shader_collection_dic):
mesh = None
for render_data in tag_block.cache_data:
vertex_map = [-1 for raw_vertex in render_data.raw_vertices]
vertices = []
triangles = []
triangle_materials = []
vertex_idx = 0
for part in render_data.parts:
if not PartTypeEnum.transparent.value == part.part_type:
strip_length = part.strip_length
strip_start = part.strip_start_index

triangle_indices = render_data.strip_indices[strip_start : (strip_start + strip_length)]
triangle_length = int(len(triangle_indices) / 3)
for idx in range(triangle_length):
triangle_index = (idx * 3)
v0 = triangle_indices[triangle_index]
if vertex_map[v0] == -1:
vertex_map[v0] = vertex_idx
vertices.append(render_data.raw_vertices[v0])
vertex_idx += 1

v1 = triangle_indices[triangle_index + 1]
if vertex_map[v1] == -1:
vertex_map[v1] = vertex_idx
vertices.append(render_data.raw_vertices[v1])
vertex_idx += 1

v2 = triangle_indices[triangle_index + 2]
if vertex_map[v2] == -1:
vertex_map[v2] = vertex_idx
vertices.append(render_data.raw_vertices[v2])
vertex_idx += 1

triangles.append((vertex_map[v0], vertex_map[v1], vertex_map[v2]))
triangle_materials.append(part.material_index)
vertices = [raw_vertex.position * 100 for raw_vertex in render_data.raw_vertices]

if len(vertices) > 0:
mesh_vertices = []
for vertex in vertices:
mesh_vertices.append(vertex.position * 100)
triangle_length = int(len(render_data.strip_indices) / 3)
for idx in range(triangle_length):
triangle_index = (idx * 3)
v0 = render_data.strip_indices[triangle_index]
v1 = render_data.strip_indices[triangle_index + 1]
v2 = render_data.strip_indices[triangle_index + 2]
triangles.append((v0, v1, v2))

if len(vertices) > 0:
mesh = bpy.data.meshes.new(poop_name)
mesh.from_pydata(mesh_vertices, [], triangles)
mesh.from_pydata(vertices, [], triangles)
for poly in mesh.polygons:
poly.use_smooth = True

Expand Down Expand Up @@ -104,7 +76,7 @@ def process_mesh(SBSP_ASSET, random_color_gen, tag_block, poop_name, material_co
v1 = triangle_indices[triangle_index + 1]
v2 = triangle_indices[triangle_index + 2]

vertex_list = [vertices[vertex_map[v0]], vertices[vertex_map[v1]], vertices[vertex_map[v2]]]
vertex_list = [render_data.raw_vertices[v0], render_data.raw_vertices[v1], render_data.raw_vertices[v2]]
for vertex_idx, vertex in enumerate(vertex_list):
loop_index = (triangle_start * 3) + triangle_index + vertex_idx

Expand Down
Loading

0 comments on commit 0cf6c2e

Please sign in to comment.