Skip to content

Commit

Permalink
More H2 shader gen work
Browse files Browse the repository at this point in the history
  • Loading branch information
General-101 committed Oct 29, 2024
1 parent 0c30052 commit 2407dbc
Show file tree
Hide file tree
Showing 18 changed files with 667 additions and 675 deletions.
4 changes: 2 additions & 2 deletions io_scene_halo/file_tag/build_scene/generate_h2_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def generate_skies(context, level_root, tag_block, report):
ob = bpy.data.objects.new(name, light_data)

ob.data.color = (radiosity_color[0], radiosity_color[1], radiosity_color[2])
ob.data.energy = radiosity_power
ob.data.energy = radiosity_power * 10
ob.parent = level_root

rotation = Euler((radians(0.0), radians(90.0), radians(0.0)), 'XYZ')
Expand Down Expand Up @@ -354,7 +354,7 @@ def generate_light_volumes_elements(level_root, collection_name, palette, tag_bl
light_size = max(tag_light_size_min, tag_light_size_max)
light_size *= scnr_light_scale

light_data_element.energy = (100 * light_size)
light_data_element.energy = (100 * light_size) * 1000

root = bpy.data.objects.new(light_name, light_data_element)
asset_collection.objects.link(root)
Expand Down
2 changes: 1 addition & 1 deletion io_scene_halo/file_tag/h1/file_weapon/process_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
DistributionFunctionEnum
)

XML_OUTPUT = True
XML_OUTPUT = False

def read_weapon_predicted_resources(WEAPON, TAG, input_stream, tag_node, XML_OUTPUT):
predicted_resources_node = tag_format.get_xml_node(XML_OUTPUT, WEAPON.weapon_predicted_resources_tag_block.count, tag_node, "name", "weapon predicted resources")
Expand Down
85 changes: 85 additions & 0 deletions io_scene_halo/file_tag/h2/file_functions/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# ##### BEGIN MIT LICENSE BLOCK #####
#
# MIT License
#
# Copyright (c) 2023 Steven Garcia
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ##### END MIT LICENSE BLOCK #####

from enum import Flag, Enum, auto

class FunctionTypeEnum(Enum):
identity = 0
constant = auto()
transition = auto()
periodic = auto()
linear = auto()
linear_key = auto()
multi_linear_key = auto()
spline = auto()
multi_spline = auto()
exponent = auto()
spline2 = auto()

class OutputTypeFlags(Flag):
scalar_intensity = 0
_range = 1
constant = 16
_2_color = 32
_3_color = 48
_4_color = 64

class TransitionExponentEnum(Enum):
linear = 0
early = auto()
very_early = auto()
late = auto()
very_late = auto()
cosine = auto()
one = auto()
zero = auto()

class Function():
def __init__(self, SCFN_header=None, MAPP_header=None, function_header=None, function_type=0, output_type=0, lower_bound=0.0, upper_bound=0.0,
color_a=(0.0, 0.0, 0.0, 1.0), color_b=(0.0, 0.0, 0.0, 1.0), color_c=(0.0, 0.0, 0.0, 1.0), color_d=(0.0, 0.0, 0.0, 1.0), input_function_data=None,
range_function_data=None):
self.SCFN_header = SCFN_header
self.MAPP_header = MAPP_header
self.function_header = function_header
self.function_type = function_type
self.output_type = output_type
self.lower_bound = lower_bound
self.upper_bound = upper_bound
self.color_a = color_a
self.color_b = color_b
self.color_c = color_c
self.color_d = color_d
self.input_function_data = input_function_data
self.range_function_data = range_function_data

class FunctionData:
def __init__(self, function_min=0.0, function_max=1.0, exponent=0, frequency=1.0, phase=0.0, points=None):
self.function_min = function_min
self.function_max = function_max
self.exponent = exponent
self.frequency = frequency
self.phase = phase
self.points = points
142 changes: 142 additions & 0 deletions io_scene_halo/file_tag/h2/file_functions/process_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# ##### BEGIN MIT LICENSE BLOCK #####
#
# MIT License
#
# Copyright (c) 2023 Steven Garcia
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ##### END MIT LICENSE BLOCK #####

from ....global_functions import tag_format
from .format import (
FunctionTypeEnum,
OutputTypeFlags,
TransitionExponentEnum,
FunctionData
)

def read_function(TAG, input_stream, xml_node, halo_function):
halo_function.input_function_data = FunctionData()
halo_function.range_function_data = FunctionData()
halo_function.input_function_data.points = []
halo_function.range_function_data.points = []

halo_function.MAPP_header = TAG.TagBlockHeader().read(input_stream, TAG)
halo_function.function_header = TAG.TagBlockHeader().read(input_stream, TAG)
halo_function.function_type = TAG.read_enum_unsigned_byte(input_stream, TAG, tag_format.XMLData(xml_node, "function type", FunctionTypeEnum))
halo_function.output_type = TAG.read_flag_unsigned_byte(input_stream, TAG, tag_format.XMLData(xml_node, "output type", OutputTypeFlags))
halo_function.input_function_data.exponent = TAG.read_enum_unsigned_byte(input_stream, TAG, tag_format.XMLData(xml_node, "exponent", TransitionExponentEnum))
halo_function.range_function_data.exponent = TAG.read_enum_unsigned_byte(input_stream, TAG, tag_format.XMLData(xml_node, "exponent", TransitionExponentEnum))

output_type_flags = OutputTypeFlags(halo_function.output_type)
if OutputTypeFlags._2_color in output_type_flags:
halo_function.color_a = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color a"))
input_stream.read(8) # Padding?
halo_function.color_b = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color b"))

elif OutputTypeFlags._3_color in output_type_flags:
halo_function.color_a = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color a"))
halo_function.color_b = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color b"))
input_stream.read(4) # Padding?
halo_function.color_c = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color c"))

elif OutputTypeFlags._4_color in output_type_flags:
halo_function.color_a = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color a"))
halo_function.color_b = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color b"))
halo_function.color_c = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color c"))
halo_function.color_d = TAG.read_bgr_byte(input_stream, TAG, tag_format.XMLData(xml_node, "color d"))

else:
halo_function.lower_bound = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "lower bound"))
halo_function.upper_bound = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "upper bound"))
input_stream.read(8) # Padding?

if FunctionTypeEnum.constant == FunctionTypeEnum(halo_function.function_type):
input_stream.read(8) # Padding?

elif FunctionTypeEnum.transition == FunctionTypeEnum(halo_function.function_type):
halo_function.input_function_data.function_min = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "min"))
halo_function.input_function_data.function_max = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "max"))
halo_function.range_function_data.function_min = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "min"))
halo_function.range_function_data.function_max = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "max"))

elif FunctionTypeEnum.periodic == FunctionTypeEnum(halo_function.function_type):
halo_function.input_function_data.frequency = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "frequency"))
halo_function.input_function_data.phase = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "phase"))
halo_function.input_function_data.function_min = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "min"))
halo_function.input_function_data.function_max = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "max"))
halo_function.range_function_data.frequency = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "frequency"))
halo_function.range_function_data.phase = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "phase"))
halo_function.range_function_data.function_min = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "min"))
halo_function.range_function_data.function_max = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "max"))

elif FunctionTypeEnum.linear == FunctionTypeEnum(halo_function.function_type):
for point_idx in range(2):
halo_function.input_function_data.points.append(TAG.read_point_2d(input_stream, TAG, tag_format.XMLData(xml_node, "position")))

input_stream.read(8) # Padding?
for point_idx in range(2):
halo_function.range_function_data.points.append(TAG.read_point_2d(input_stream, TAG, tag_format.XMLData(xml_node, "position")))

input_stream.read(8) # Padding?

elif FunctionTypeEnum.linear_key == FunctionTypeEnum(halo_function.function_type):
for point_idx in range(4):
halo_function.input_function_data.points.append(TAG.read_point_2d(input_stream, TAG, tag_format.XMLData(xml_node, "position")))

input_stream.read(48) # Padding?
for point_idx in range(4):
halo_function.range_function_data.points.append(TAG.read_point_2d(input_stream, TAG, tag_format.XMLData(xml_node, "position")))

input_stream.read(48) # Padding?

elif FunctionTypeEnum.multi_linear_key == FunctionTypeEnum(halo_function.function_type):
input_stream.read(256) # Padding?

elif FunctionTypeEnum.spline == FunctionTypeEnum(halo_function.function_type):
for point_idx in range(4):
halo_function.input_function_data.points.append(TAG.read_point_2d(input_stream, TAG, tag_format.XMLData(xml_node, "position")))

input_stream.read(16) # Padding?
for point_idx in range(4):
halo_function.range_function_data.points.append(TAG.read_point_2d(input_stream, TAG, tag_format.XMLData(xml_node, "position")))

input_stream.read(16) # Padding?

elif FunctionTypeEnum.multi_spline == FunctionTypeEnum(halo_function.function_type):
input_stream.read(40) # Padding?

elif FunctionTypeEnum.exponent == FunctionTypeEnum(halo_function.function_type):
halo_function.input_function_data.function_min = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "min"))
halo_function.input_function_data.function_max = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "max"))
halo_function.input_function_data.exponent = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "exponent"))
halo_function.range_function_data.function_min = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "min"))
halo_function.range_function_data.function_max = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "max"))
halo_function.range_function_data.exponent = TAG.read_float(input_stream, TAG, tag_format.XMLData(xml_node, "exponent"))

elif FunctionTypeEnum.spline2 == FunctionTypeEnum(halo_function.function_type):
for point_idx in range(4):
halo_function.input_function_data.points.append(TAG.read_point_2d(input_stream, TAG, tag_format.XMLData(xml_node, "position")))

input_stream.read(16) # Padding?
for point_idx in range(4):
halo_function.range_function_data.points.append(TAG.read_point_2d(input_stream, TAG, tag_format.XMLData(xml_node, "position")))

input_stream.read(16) # Padding?
2 changes: 1 addition & 1 deletion io_scene_halo/file_tag/h2/file_light/process_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
FadeEnum,
AnimationFlags)

XML_OUTPUT = True
XML_OUTPUT = False

def initilize_light(LIGHT):
LIGHT.brightness_animation = []
Expand Down
34 changes: 6 additions & 28 deletions io_scene_halo/file_tag/h2/file_object/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from mathutils import Vector
from enum import Flag, Enum, auto

from ....file_tag.h2.file_functions.format import Function

class ObjectFlags(Flag):
does_not_cast_shadow = auto()
search_cardinal_direction_lightmaps_on_failure = auto()
Expand Down Expand Up @@ -231,12 +233,10 @@ def __init__(self, ai_flags=0, ai_type_name="", ai_type_name_length=0, ai_size=0
self.ai_size = ai_size
self.leap_jump_speed = leap_jump_speed

class Function:
class ObjectFunction(Function):
def __init__(self, flags=0, import_name="", import_name_length=0, export_name="", export_name_length=0, turn_off_with="", turn_off_with_length=0, min_value=0,
scale_by="", scale_by_length=0, MAPP_header=None, function_header=None, function_type=0, output_type=0, lower_bound=0.0, upper_bound=0.0,
function_min=0.0, function_max=0.0, exponent=0.0, frequency=0.0, phase=0.0, points=None, range_function_min=0.0, range_function_max=0.0,
range_exponent=0.0, range_frequency=0.0, range_phase=0.0, range_points=None, color_a=(0.0, 0.0, 0.0, 1.0), color_b=(0.0, 0.0, 0.0, 1.0),
color_c=(0.0, 0.0, 0.0, 1.0), color_d=(0.0, 0.0, 0.0, 1.0)):
scale_by="", scale_by_length=0):
super().__init__()
self.flags = flags
self.import_name = import_name
self.import_name_length = import_name_length
Expand All @@ -247,28 +247,6 @@ def __init__(self, flags=0, import_name="", import_name_length=0, export_name=""
self.min_value = min_value
self.scale_by = scale_by
self.scale_by_length = scale_by_length
self.MAPP_header = MAPP_header
self.function_header = function_header
self.function_type = function_type
self.output_type = output_type
self.lower_bound = lower_bound
self.upper_bound = upper_bound
self.function_min = function_min
self.function_max = function_max
self.exponent = exponent
self.frequency = frequency
self.phase = phase
self.points = points
self.range_function_min = range_function_min
self.range_function_max = range_function_max
self.range_exponent = range_exponent
self.range_frequency = range_frequency
self.range_phase = range_phase
self.range_points = range_points
self.color_a = color_a
self.color_b = color_b
self.color_c = color_c
self.color_d = color_d

class Attachment:
def __init__(self, attachment_type=None, marker="", marker_length=0, change_color=0, primary_scale="", primary_scale_length=0, secondary_scale="", secondary_scale_length=0):
Expand Down Expand Up @@ -304,7 +282,7 @@ def __init__(self, weight=0.0, color_lower_bound=(0, 0, 0, 0), color_upper_bound
self.variant_name = variant_name
self.variant_name_length = variant_name_length

class Function:
class ColorFunction():
def __init__(self, scale_flags=0, color_lower_bound=(0, 0, 0, 0), color_upper_bound=(0, 0, 0, 0), darken_by="", darken_by_length=0, scale_by="", scale_by_length=0):
self.scale_flags = scale_flags
self.color_lower_bound = color_lower_bound
Expand Down
Loading

0 comments on commit 2407dbc

Please sign in to comment.