Skip to content

Commit

Permalink
H2 lightmap operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Garcia committed Nov 25, 2023
1 parent 624fe37 commit 02282e3
Show file tree
Hide file tree
Showing 15 changed files with 346 additions and 192 deletions.
4 changes: 2 additions & 2 deletions io_scene_halo/file_tag/build_scene/build_lightmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def build_clusters(lightmap_group, SBSP_ASSET, level_root, random_color_gen, col
U = vertex.primary_lightmap_texcoord[0]
V = vertex.primary_lightmap_texcoord[1]

layer_uv.data[loop_index].uv = (U, 1 - V)
layer_uv.data[loop_index].uv = (U, V)

triangle_start = 0
for part in cache_data.parts:
Expand Down Expand Up @@ -152,7 +152,7 @@ def build_poops(lightmap_group, SBSP_ASSET, level_root, random_color_gen, collec
U = vertex.primary_lightmap_texcoord[0]
V = vertex.primary_lightmap_texcoord[1]

layer_uv.data[loop_index].uv = (U, 1 - V)
layer_uv.data[loop_index].uv = (U, V)

triangle_start = 0
for part in render_data.parts:
Expand Down
6 changes: 4 additions & 2 deletions io_scene_halo/file_tag/h1/file_bitmap/process_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ def process_file(input_stream, tag_format, report):
BITMAP.bitmap_body.sequences_tag_block = TAG.TagBlock().read(input_stream, TAG, tag_format.XMLData(tag_node, "sequences"))
BITMAP.bitmap_body.bitmaps_tag_block = TAG.TagBlock().read(input_stream, TAG, tag_format.XMLData(tag_node, "bitmaps"))

BITMAP.bitmap_body.compressed_color_plate = input_stream.read(BITMAP.bitmap_body.compressed_color_plate_data.size)
BITMAP.bitmap_body.processed_pixels = input_stream.read(BITMAP.bitmap_body.processed_pixel_data.size)
input_stream.seek(BITMAP.bitmap_body.compressed_color_plate_data.size, 1)
input_stream.seek(BITMAP.bitmap_body.processed_pixel_data.size, 1)
BITMAP.bitmap_body.compressed_color_plate = bytes()
BITMAP.bitmap_body.processed_pixels = bytes()

BITMAP.sequences = []
sequence_node = tag_format.get_xml_node(XML_OUTPUT, BITMAP.bitmap_body.sequences_tag_block.count, tag_node, "name", "sequences")
Expand Down
2 changes: 0 additions & 2 deletions io_scene_halo/file_tag/h1/file_bitmap/upgrade_bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#
# ##### END MIT LICENSE BLOCK #####

import os

from .format import (
BitmapAsset as H1BitmapAsset,
BitmapTypeEnum as H1BitmapTypeEnum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
ExtraFlags,
)

XML_OUTPUT = True
XML_OUTPUT = False

def process_file(input_stream, tag_format, report):
TAG = tag_format.TagAsset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
AlphaOutputEnum
)

XML_OUTPUT = True
XML_OUTPUT = False

def process_file(input_stream, tag_format, report):
TAG = tag_format.TagAsset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ChannelSourceEnum
)

XML_OUTPUT = True
XML_OUTPUT = False

def process_file(input_stream, tag_format, report):
TAG = tag_format.TagAsset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
WaterFlags
)

XML_OUTPUT = True
XML_OUTPUT = False

def process_file(input_stream, tag_format, report):
TAG = tag_format.TagAsset()
Expand Down
62 changes: 31 additions & 31 deletions io_scene_halo/file_tag/h2/file_bitmap/build_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,55 +58,55 @@ def write_sequences(output_stream, BITMAP, TAG):
if len(BITMAP.sequences) > 0:
BITMAP.sequence_header.write(output_stream, TAG, True)
for sequence in BITMAP.sequences:
output_stream.write(struct.pack('>31sx', TAG.string_to_bytes(sequence.name, False)))
output_stream.write(struct.pack('>h', sequence.first_bitmap_index))
output_stream.write(struct.pack('>h', sequence.bitmap_count))
output_stream.write(struct.pack('>16x'))
output_stream.write(struct.pack('<31sx', TAG.string_to_bytes(sequence.name, False)))
output_stream.write(struct.pack('<h', sequence.first_bitmap_index))
output_stream.write(struct.pack('<h', sequence.bitmap_count))
output_stream.write(struct.pack('<16x'))
sequence.sprites_tag_block.write(output_stream, False)

for sequence in BITMAP.sequences:
if len(sequence.sprites) > 0:
sequence.sprites_header.write(output_stream, TAG, True)
for sprite in sequence.sprites:
output_stream.write(struct.pack('>h', sprite.bitmap_index))
output_stream.write(struct.pack('>6x'))
output_stream.write(struct.pack('>f', sprite.left))
output_stream.write(struct.pack('>f', sprite.right))
output_stream.write(struct.pack('>f', sprite.top))
output_stream.write(struct.pack('>f', sprite.bottom))
output_stream.write(struct.pack('>ff', sprite.registration_point[0], sprite.registration_point[1]))
output_stream.write(struct.pack('<h', sprite.bitmap_index))
output_stream.write(struct.pack('<6x'))
output_stream.write(struct.pack('<f', sprite.left))
output_stream.write(struct.pack('<f', sprite.right))
output_stream.write(struct.pack('<f', sprite.top))
output_stream.write(struct.pack('<f', sprite.bottom))
output_stream.write(struct.pack('<ff', sprite.registration_point[0], sprite.registration_point[1]))

def write_bitmaps(output_stream, BITMAP, TAG):
if len(BITMAP.bitmaps) > 0:
BITMAP.bitmap_header.write(output_stream, TAG, True)
for bitmap in BITMAP.bitmaps:
output_stream.write(struct.pack('>4s', TAG.string_to_bytes(bitmap.signature, False)))
output_stream.write(struct.pack('>h', bitmap.width))
output_stream.write(struct.pack('>h', bitmap.height))
output_stream.write(struct.pack('>b', bitmap.depth))
output_stream.write(struct.pack('>b', bitmap.more_flags))
output_stream.write(struct.pack('>h', bitmap.bitmap_type))
output_stream.write(struct.pack('>h', bitmap.bitmap_format))
output_stream.write(struct.pack('>h', bitmap.flags))
output_stream.write(struct.pack('>hh', bitmap.registration_point[0], bitmap.registration_point[1]))
output_stream.write(struct.pack('>h', bitmap.mipmap_count))
output_stream.write(struct.pack('>b', bitmap.lod_adjust))
output_stream.write(struct.pack('>b', bitmap.cache_usage))
output_stream.write(struct.pack('>i', bitmap.pixels_offset))
output_stream.write(struct.pack('>4x'))
output_stream.write(struct.pack('<4s', TAG.string_to_bytes(bitmap.signature, True)))
output_stream.write(struct.pack('<h', bitmap.width))
output_stream.write(struct.pack('<h', bitmap.height))
output_stream.write(struct.pack('<b', bitmap.depth))
output_stream.write(struct.pack('<b', bitmap.more_flags))
output_stream.write(struct.pack('<h', bitmap.bitmap_type))
output_stream.write(struct.pack('<h', bitmap.bitmap_format))
output_stream.write(struct.pack('<h', bitmap.flags))
output_stream.write(struct.pack('<hh', bitmap.registration_point[0], bitmap.registration_point[1]))
output_stream.write(struct.pack('<h', bitmap.mipmap_count))
output_stream.write(struct.pack('<b', bitmap.lod_adjust))
output_stream.write(struct.pack('<b', bitmap.cache_usage))
output_stream.write(struct.pack('<i', bitmap.pixels_offset))
output_stream.write(struct.pack('<4x'))
bitmap.native_mipmap_info_tag_block.write(output_stream, False)
output_stream.write(struct.pack('>i', bitmap.native_size))
output_stream.write(struct.pack('>i', bitmap.tile_mode))
output_stream.write(struct.pack('>88x'))
output_stream.write(struct.pack('<i', bitmap.native_size))
output_stream.write(struct.pack('<i', bitmap.tile_mode))
output_stream.write(struct.pack('<88x'))

for bitmap in BITMAP.bitmaps:
bitmap.nbmi_header.write(output_stream, TAG, True)
if len(bitmap.native_mipmap_info) > 0:
bitmap.native_mipmap_info_header.write(output_stream, TAG, True)
for native_mipmap_info in bitmap.native_mipmap_info:
output_stream.write(struct.pack('>i', native_mipmap_info.offset))
output_stream.write(struct.pack('>i', native_mipmap_info.pitch_row))
output_stream.write(struct.pack('>i', native_mipmap_info.pitch_slice))
output_stream.write(struct.pack('<i', native_mipmap_info.offset))
output_stream.write(struct.pack('<i', native_mipmap_info.pitch_row))
output_stream.write(struct.pack('<i', native_mipmap_info.pitch_slice))

def build_asset(output_stream, BITMAP, tag_format, report):
TAG = tag_format.TagAsset()
Expand Down
2 changes: 1 addition & 1 deletion io_scene_halo/file_tag/h2/file_bitmap/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init__(self, bitmap_index=0, left=0, right=0, top=0, bottom=0, registratio
self.registration_point = registration_point

class Bitmap:
def __init__(self, signature="", width=0, height=0, depth=0, more_flags=0, bitmap_type=0, bitmap_format=0, flags=0, registration_point=(0.0, 0.0), mipmap_count=0,
def __init__(self, signature="", width=0, height=0, depth=0, more_flags=0, bitmap_type=0, bitmap_format=0, flags=0, registration_point=(0, 0), mipmap_count=0,
lod_adjust=0, cache_usage=0, pixels_offset=0, native_mipmap_info_tag_block=None, native_mipmap_info_header=None, native_mipmap_info=None, native_size=0,
tile_mode=0, nbmi_header=None):
self.signature = signature
Expand Down
8 changes: 5 additions & 3 deletions io_scene_halo/file_tag/h2/file_bitmap/process_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
CacheUsageEnum
)

XML_OUTPUT = True
XML_OUTPUT = False

def initilize_bitmap(BITMAP):
BITMAP.sequences = []
Expand Down Expand Up @@ -216,8 +216,10 @@ def process_file(input_stream, tag_format, report):

initilize_bitmap(BITMAP)
read_bitmap_body(BITMAP, TAG, input_stream, tag_format, tag_node, XML_OUTPUT)
BITMAP.bitmap_body.compressed_color_plate = input_stream.read(BITMAP.bitmap_body.compressed_color_plate_data.size)
BITMAP.bitmap_body.processed_pixels = input_stream.read(BITMAP.bitmap_body.processed_pixel_data.size)
input_stream.seek(BITMAP.bitmap_body.compressed_color_plate_data.size, 1)
input_stream.seek(BITMAP.bitmap_body.processed_pixel_data.size, 1)
BITMAP.bitmap_body.compressed_color_plate = bytes()
BITMAP.bitmap_body.processed_pixels = bytes()
read_sequences(BITMAP, TAG, input_stream, tag_format, tag_node, XML_OUTPUT)
read_bitmaps(BITMAP, TAG, input_stream, tag_format, tag_node, XML_OUTPUT)

Expand Down
2 changes: 1 addition & 1 deletion io_scene_halo/file_tag/h2/file_scenario/process_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
SALT_SIZE
)

XML_OUTPUT = True
XML_OUTPUT = False

def get_predicted_resource(input_stream, SCENARIO, TAG, tag_format, node_element):
predicted_resource = SCENARIO.PredictedResource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
LightmappingPolicyEnum
)

XML_OUTPUT = True
XML_OUTPUT = False

def initilize_scenario(LEVEL):
LEVEL.import_info = []
Expand Down
2 changes: 1 addition & 1 deletion io_scene_halo/file_tag/import_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def load_file(context, file_path, game_title, fix_rotations, empty_markers, repo


elif tag_group == "scnr":
context.scene.halo_tag.game_title = game_title
context.scene.halo.game_title = game_title
context.scene.halo_tag.scenario_path = file_path
build_scene = build_scenario
if game_title == "halo1":
Expand Down
14 changes: 9 additions & 5 deletions io_scene_halo/global_functions/tag_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

from ..file_tag.h2.file_scenario_structure_bsp.process_file import process_file as process_h2_structure_bsp
from ..file_tag.h2.file_scenario_structure_lightmap.process_file import process_file as process_h2_structure_lightmap
from ..file_tag.h2.file_bitmap.process_file import process_file as process_h2_bitmap
from ..file_tag.h2.file_model.process_file import process_file as process_h2_model
from ..file_tag.h2.file_render_model.process_file import process_file as process_h2_render
from ..file_tag.h2.file_scenery.process_file import process_file as process_h2_scenery
Expand Down Expand Up @@ -399,15 +400,11 @@ def read_flag_unsigned_short(self, input_stream, tag, xml_data=None):

return flags

def read_point_2d_short(self, input_stream, tag, xml_data=None, increase_scale=False):
def read_point_2d_short(self, input_stream, tag, xml_data=None):
short_a, short_b = struct.unpack('%shh' % get_endian_symbol(tag.big_endian), input_stream.read(4))
if not tag.xml_doc == None and not xml_data == None:
xml_data.xml_node.appendChild(create_xml_node("field", [("name", xml_data.element_name), ("type", "short point 2d")], xml_bounds_short(short_a, short_b)))

if increase_scale:
short_a *= 100
short_b *= 100

return (short_a, short_b)

def read_signed_integer(self, input_stream, tag, xml_data=None):
Expand Down Expand Up @@ -963,6 +960,13 @@ def parse_tag(self, tag_format, report, game_title, game_version):
ASSET = process_h2_structure_lightmap(input_stream, tag_format, report)
input_stream.close()

elif self.tag_group == "bitm":
input_file = os.path.join(config.HALO_2_TAG_PATH, "%s.bitmap" % self.name)
if os.path.exists(input_file):
input_stream = open(input_file, 'rb')
ASSET = process_h2_bitmap(input_stream, tag_format, report)
input_stream.close()

elif self.tag_group == "hlmt":
input_file = os.path.join(config.HALO_2_TAG_PATH, "%s.model" % self.name)
if os.path.exists(input_file):
Expand Down
Loading

0 comments on commit 02282e3

Please sign in to comment.