Skip to content

Commit

Permalink
Sync up public and beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Garcia committed Apr 12, 2024
1 parent 9306922 commit 1749beb
Show file tree
Hide file tree
Showing 95 changed files with 8,969 additions and 1,568 deletions.
2 changes: 1 addition & 1 deletion io_scene_halo/file_jma/build_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def get_pose_bone(arm: bpy.types.Object, node_name: str) -> bpy.types.PoseBone |
for bone in arm.pose.bones:
if bone.name.lower() == node_name.lower():
return bone

# If a bone hasn't been found yet, test whether the node name matches a bone name stripped of prefixes
for bone in arm.pose.bones:
if remove_node_prefix(bone.name).lower() == node_name.lower():
Expand Down
1 change: 0 additions & 1 deletion io_scene_halo/file_jma/process_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def process_scene(context, extension, jma_version, game_title, generate_checksum
node_list.append(obj)

JMA.node_count = len(node_list)

sorted_list = global_functions.sort_list(node_list, armature, game_title, jma_version, True)
joined_list = sorted_list[0]
reversed_joined_list = sorted_list[1]
Expand Down
1 change: 1 addition & 0 deletions io_scene_halo/file_qua/export_qua.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#
# ##### END MIT LICENSE BLOCK #####

import os
import bpy

from decimal import *
Expand Down
62 changes: 54 additions & 8 deletions io_scene_halo/file_tag/build_scene/build_bsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
import bpy
import bmesh

from ... import config
from sys import float_info
from math import radians, log
from mathutils import Matrix, Vector
from ..h2.file_scenario_structure_bsp.format import ClusterPortalFlags as H2ClusterPortalFlags, SurfaceFlags as H2SurfaceFlags, PartFlags
from ..h2.file_scenario_structure_bsp.format import ClusterPortalFlags as H2ClusterPortalFlags, SurfaceFlags as H2SurfaceFlags, PartFlags, PropertyTypeEnum
from ...global_functions import shader_processing, mesh_processing, global_functions
from ..h1.file_scenario_structure_bsp.format import ClusterPortalFlags as H1ClusterPortalFlags, SurfaceFlags as H1SurfaceFlags

Expand Down Expand Up @@ -502,11 +503,46 @@ def build_scene(context, LEVEL, game_version, game_title, file_version, fix_rota
mesh.materials.append(mat)

else:
shader_collection_dic = {}
shader_collection_path = os.path.join(config.HALO_2_TAG_PATH, r"scenarios\shaders\shader_collections.shader_collections")
shader_collection_file = open(shader_collection_path, "r")
for line in shader_collection_file.readlines():
if not global_functions.string_empty_check(line) and not line.startswith(";"):
split_result = line.split()
if len(split_result) == 2:
prefix = split_result[0]
path = split_result[1]
shader_collection_dic[path] = prefix

materials = []
for material in LEVEL.materials:
material_name = os.path.basename(material.shader.name)
if global_functions.string_empty_check(material_name):
material_name = os.path.basename(material.old_shader.name)
material_path = material.shader.name
if global_functions.string_empty_check(material_path):
material_path = material.old_shader.name

material_directory = os.path.dirname(material_path)
material_name = os.path.basename(material_path)

collection_prefix = shader_collection_dic.get(material_directory)
if not collection_prefix == None:
material_name = "%s %s" % (collection_prefix, material_name)
else:
print("Could not find a collection for: %s" % material_path)

for material_property in material.properties:
property_enum = PropertyTypeEnum(material_property.property_type)
property_value = material_property.real_value
if PropertyTypeEnum.lightmap_resolution == property_enum:
material_name += " lm:%s" % property_value

elif PropertyTypeEnum.lightmap_power == property_enum:
material_name += " lp:%s" % property_value

elif PropertyTypeEnum.lightmap_half_life == property_enum:
material_name += " hl:%s" % property_value

elif PropertyTypeEnum.lightmap_diffuse_scale == property_enum:
material_name += " ds:%s" % property_value

mat = bpy.data.materials.new(name=material_name)
shader_processing.generate_h2_shader(mat, material.shader, report)
Expand Down Expand Up @@ -542,7 +578,7 @@ def build_scene(context, LEVEL, game_version, game_title, file_version, fix_rota
object_mesh = bpy.data.objects.new(ob_name, mesh)
object_mesh.tag_view.data_type_enum = '16'
object_mesh.tag_view.instance_lightmap_policy_enum = str(instanced_geometry_instance.lightmapping_policy)

object_mesh.parent = level_root
cluster_collection_override.objects.link(object_mesh)

Expand Down Expand Up @@ -652,11 +688,21 @@ def build_scene(context, LEVEL, game_version, game_title, file_version, fix_rota

if not ngon_material_index == -1:
if game_title == "halo1":
shader = mat.shader_tag_ref
shader_path = mat.shader_tag_ref.name
material_name = os.path.basename(shader_path)
else:
shader = mat.new_shader
shader_path = mat.new_shader.name

material_directory = os.path.dirname(shader_path)
material_name = os.path.basename(shader_path)

collection_prefix = shader_collection_dic.get(material_directory)
if not collection_prefix == None:
material_name = "%s %s" % (collection_prefix, material_name)
else:
print("Could not find a collection for: %s" % material_path)

material_name = os.path.basename(shader.name)

if game_title == "halo1":
if H1SurfaceFlags.two_sided in H1SurfaceFlags(surface.flags):
material_name += "%"
Expand Down
22 changes: 15 additions & 7 deletions io_scene_halo/file_tag/build_scene/build_collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ def build_pathfinding_spheres(context, armature, COLLISION, fix_rotations, empty
parent_idx = pathfinding_sphere.node
object_name = '#pathfinding_sphere_%s' % pathfinding_sphere_idx

mesh = bpy.data.meshes.new(object_name)
object_mesh = bpy.data.objects.new(object_name, mesh)
if empty_markers:
object_mesh = bpy.data.objects.new(object_name, None)

else:
mesh = bpy.data.meshes.new(object_name)
object_mesh = bpy.data.objects.new(object_name, mesh)

collection.objects.link(object_mesh)

bm = bmesh.new()
bmesh.ops.create_uvsphere(bm, u_segments=32, v_segments=16, radius=1)
bm.to_mesh(mesh)
bm.free()
if not empty_markers:
bm = bmesh.new()
bmesh.ops.create_uvsphere(bm, u_segments=32, v_segments=16, radius=1)
bm.to_mesh(mesh)
bm.free()

matrix_translate = Matrix.Translation(pathfinding_sphere.center)

Expand Down Expand Up @@ -77,7 +83,9 @@ def build_pathfinding_spheres(context, armature, COLLISION, fix_rotations, empty
object_mesh.parent = armature

object_mesh.matrix_world = transform_matrix
object_mesh.data.ass_jms.Object_Type = 'SPHERE'
if not empty_markers:
object_mesh.data.ass_jms.Object_Type = 'SPHERE'

object_mesh.ass_jms.marker_mask_type = '1'
object_mesh.select_set(False)
armature.select_set(False)
Expand Down
28 changes: 20 additions & 8 deletions io_scene_halo/file_tag/build_scene/build_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def build_scene(context, PHYSICS, game_version, game_title, file_version, fix_ro

if armature:
for mass_point_idx, mass_point in enumerate(PHYSICS.mass_points):
if game_title == "halo2" and mass_point.powered_mass_point < 0:
continue

parent_idx = mass_point.model_node
object_name_prefix = '#%s' % mass_point.name
Expand All @@ -48,16 +50,22 @@ def build_scene(context, PHYSICS, game_version, game_title, file_version, fix_ro
if context.scene.objects.get('#%s' % mass_point.name):
marker_name_override = mass_point.name

mesh = bpy.data.meshes.new(object_name_prefix)
object_mesh = bpy.data.objects.new(object_name_prefix, mesh)
if empty_markers:
object_mesh = bpy.data.objects.new(object_name_prefix, None)

else:
mesh = bpy.data.meshes.new(object_name_prefix)
object_mesh = bpy.data.objects.new(object_name_prefix, mesh)

collection.objects.link(object_mesh)

object_mesh.ass_jms.name_override = marker_name_override

bm = bmesh.new()
bmesh.ops.create_uvsphere(bm, u_segments=32, v_segments=16, radius=1)
bm.to_mesh(mesh)
bm.free()
if not empty_markers:
bm = bmesh.new()
bmesh.ops.create_uvsphere(bm, u_segments=32, v_segments=16, radius=1)
bm.to_mesh(mesh)
bm.free()

node_count = len(armature.data.bones)
if not parent_idx == -1 and not parent_idx >= node_count:
Expand All @@ -83,8 +91,12 @@ def build_scene(context, PHYSICS, game_version, game_title, file_version, fix_ro
transform_matrix = matrix_translate @ matrix_rotation @ scale

object_mesh.matrix_world = transform_matrix
object_mesh.data.ass_jms.Object_Type = 'SPHERE'
object_mesh.ass_jms.marker_mask_type = '2'
if not empty_markers:
object_mesh.data.ass_jms.Object_Type = 'SPHERE'
if game_title == "halo2":
object_mesh.ass_jms.marker_mask_type = '0'
else:
object_mesh.ass_jms.marker_mask_type = '2'

else:
report({'ERROR'}, "No valid armature is active. Import will now be aborted")
3 changes: 3 additions & 0 deletions io_scene_halo/file_tag/build_scene/generate_h2_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ def generate_object_elements(level_root, collection_name, palette, tag_block, co

root.parent = level_root
root.location = element.position * 100
ob_scale = element.scale
if ob_scale > 0.0:
root.scale = (ob_scale, ob_scale, ob_scale)

get_data_type(collection_name, root, pallete_item.name, element)

Expand Down
1 change: 1 addition & 0 deletions io_scene_halo/file_tag/h1/file_model/build_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def build_mesh_layout(asset, geometry, region_name, object_name, game_version, i

region_attribute = mesh.get_custom_attribute()
mesh.normals_split_custom_set_from_vertices(vertex_normals)

for vertex_idx, vertex in enumerate(vertex_data):
node_0_index = vertex.node_0_index
node_1_index = vertex.node_1_index
Expand Down
2 changes: 1 addition & 1 deletion io_scene_halo/file_tag/h1/file_model/process_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def process_file(input_stream, report):
MODEL.mode_body.stubbs_unk_tag_block = TAG.TagBlock().read(input_stream, TAG, tag_format.XMLData(tag_node, "stubbs_unk_arr"))
else:
input_stream.read(12) # Padding?

MODEL.mode_body.markers_tag_block = TAG.TagBlock().read(input_stream, TAG, tag_format.XMLData(tag_node, "markers"))
MODEL.mode_body.nodes_tag_block = TAG.TagBlock().read(input_stream, TAG, tag_format.XMLData(tag_node, "nodes"))
MODEL.mode_body.regions_tag_block = TAG.TagBlock().read(input_stream, TAG, tag_format.XMLData(tag_node, "regions"))
Expand Down
6 changes: 1 addition & 5 deletions io_scene_halo/file_tag/h1/file_physics/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def __init__(self):
class PhysBody:
def __init__(self, radius=0.0, moment_scale=0.0, mass=0.0, center_of_mass=Vector(), density=0.0, gravity_scale=0.0, ground_friction=0.0, ground_depth=0.0,
ground_damp_fraction=0.0, ground_normal_k1=0.0, ground_normal_k0=0.0, water_friction=0.0, water_depth=0.0, water_density=0.0, air_friction=0.0,
xx_moment=0.0, yy_moment=0.0, zz_moment=0.0, inertial_matrix_and_inverse_tag_block=None, powered_mass_points_tag_block=None, mass_points_tag_block=None,
inertial_matrix_and_inverse=None, powered_mass_points=None, mass_points=None):
xx_moment=0.0, yy_moment=0.0, zz_moment=0.0, inertial_matrix_and_inverse_tag_block=None, powered_mass_points_tag_block=None, mass_points_tag_block=None):
self.radius = radius
self.moment_scale = moment_scale
self.mass = mass
Expand All @@ -79,9 +78,6 @@ def __init__(self, radius=0.0, moment_scale=0.0, mass=0.0, center_of_mass=Vector
self.inertial_matrix_and_inverse_tag_block = inertial_matrix_and_inverse_tag_block
self.powered_mass_points_tag_block = powered_mass_points_tag_block
self.mass_points_tag_block = mass_points_tag_block
self.inertial_matrix_and_inverse = inertial_matrix_and_inverse
self.powered_mass_points = powered_mass_points
self.mass_points = mass_points

class InertialMatrixAndInverse:
def __init__(self, yy_zz_xy_zx=Vector(), xy_zz_xx_yz=Vector(), zx_yz_xx_yy=Vector()):
Expand Down
Loading

0 comments on commit 1749beb

Please sign in to comment.