From 12d26cb3c551750dbdcdeb5b2ecbbe5d69e00e5e Mon Sep 17 00:00:00 2001 From: Steven Garcia Date: Tue, 4 Jun 2024 18:42:30 -0500 Subject: [PATCH] Clean up JMS builder and QUA support --- io_scene_halo/file_jms/build_asset.py | 3694 +++++++++++------ io_scene_halo/file_qua/__init__.py | 121 +- io_scene_halo/file_qua/build_asset.py | 216 + io_scene_halo/file_qua/build_scene.py | 201 + io_scene_halo/file_qua/export_qua.py | 356 +- io_scene_halo/file_qua/format.py | 91 + io_scene_halo/file_qua/import_qua.py | 83 +- io_scene_halo/file_qua/process_file.py | 169 + io_scene_halo/file_qua/process_scene.py | 201 + .../global_functions/global_functions.py | 15 + io_scene_halo/global_ui/__init__.py | 7 +- io_scene_halo/global_ui/object_ui.py | 81 + 12 files changed, 3481 insertions(+), 1754 deletions(-) create mode 100644 io_scene_halo/file_qua/build_asset.py create mode 100644 io_scene_halo/file_qua/build_scene.py create mode 100644 io_scene_halo/file_qua/format.py create mode 100644 io_scene_halo/file_qua/process_file.py create mode 100644 io_scene_halo/file_qua/process_scene.py diff --git a/io_scene_halo/file_jms/build_asset.py b/io_scene_halo/file_jms/build_asset.py index 74645a8e1..301a2417a 100644 --- a/io_scene_halo/file_jms/build_asset.py +++ b/io_scene_halo/file_jms/build_asset.py @@ -30,1370 +30,2428 @@ from .process_scene import process_scene from ..global_functions import global_functions -def build_asset(context, blend_scene, filepath, jms_version, game_title, generate_checksum, fix_rotations, use_maya_sorting, folder_structure, folder_type, model_type, is_jmi, permutation_ce, level_of_detail_ce, custom_scale, loop_normals, write_textures, report): - JMS = process_scene(context, jms_version, game_title, generate_checksum, fix_rotations, use_maya_sorting, model_type, blend_scene, custom_scale, loop_normals, write_textures) +DECIMAL_POINT = "6" +DECIMAL_1 = '\n%0.{decimal_point}f'.format(decimal_point=DECIMAL_POINT) +DECIMAL_2 = '\n%0.{decimal_point}f\t%0.{decimal_point}f'.format(decimal_point=DECIMAL_POINT) +DECIMAL_3 = '\n%0.{decimal_point}f\t%0.{decimal_point}f\t%0.{decimal_point}f'.format(decimal_point=DECIMAL_POINT) +DECIMAL_4 = '\n%0.{decimal_point}f\t%0.{decimal_point}f\t%0.{decimal_point}f\t%0.{decimal_point}f'.format(decimal_point=DECIMAL_POINT) - is_text = True +def write_version(file, jms_version, version_bounds, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack(' 8209: - decimal_1 = '\n%0.10f' - decimal_2 = '\n%0.10f\t%0.10f' - decimal_3 = '\n%0.10f\t%0.10f\t%0.10f' - decimal_4 = '\n%0.10f\t%0.10f\t%0.10f\t%0.10f' + else: + if write_comments: + file.write(';### VERSION ###') + file.write('\n') + + file.write('%s' % (jms_version)) + + if write_comments: + file.write('\n;\t<%s>' % (version_bounds)) + + if write_whitespace: + file.write('\n') + +def write_checksum(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('= 8205: - version_bounds = '8197-8210' - if game_title == "halo3": - version_bounds = '8197-8213' - - file.write( - ';### VERSION ###' + - '\n%s' % (jms_version) + - '\n;\t<%s>\n' % (version_bounds) - ) - - else: - file.write( - '%s' % (jms_version) + - '\n%s' % (JMS.node_checksum) - ) - - if jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Frames###' - ) - - file.write( - '\n%s' % (len(JMS.nodes)) - ) - - if jms_version >= 8205: - file.write( - '\n;### NODES ###' + - '\n%s' % (len(JMS.nodes)) + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>\n' - ) + if write_whitespace: + file.write('\n') +def write_nodes_8197(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('= 8205: - file.write( - '\n;NODE %s' % (idx) + - '\n%s' % (node.name) + - '\n%s' % (node.parent) + - decimal_4 % (transform.rotation) + - decimal_3 % (transform.translation) + - '\n' - ) - - else: - file.write( - '\n%s' % (node.name) + - '\n%s' % (node.child) + - '\n%s' % (node.sibling) + - decimal_4 % (transform.rotation) + - decimal_3 % (transform.translation) - ) - - if jms_version >= 8205: - file.write( - '\n;### MATERIALS ###' + - '\n%s' % (len(JMS.materials)) + - '\n;\t' + - '\n;\t<(Material Slot Index) LOD Permutation Region>\n' - ) - - else: - if jms_version >= 8202 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Materials###' - ) - - file.write( - '\n%s' % (len(JMS.materials)) - ) + file.write(struct.pack('<%ssx' % (len(node.name)), bytes(node.name, 'utf-8'))) + file.write(struct.pack('= 8205: - file.write( - '\n;MATERIAL %s' % (idx) + - '\n%s' % (material.name) + - '\n%s\n' % (material_definition) - ) - - else: - file.write('\n%s' % (material.name)) - if jms_version >= 8202 and jms_version <= 8204: - file.write('\n%s' % (material.texture_path)) - - file.write('\n%s' % (material_definition)) - - if jms_version >= 8205: - file.write( - '\n;### MARKERS ###' + - '\n%s' % (len(JMS.markers)) + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t\n' - ) - - else: - if jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Markers###' - ) - - file.write( - '\n%s' % (len(JMS.markers)) - ) + else: + if write_comments: + file.write('\n;### NODES ###') + + file.write('\n%s' % (len(JMS.nodes))) + if write_comments: + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') - for idx, marker in enumerate(JMS.markers): - if jms_version >= 8205: - file.write( - '\n;MARKER %s' % (idx) - ) + for idx, node in enumerate(JMS.nodes): + if write_comments: + file.write('\n;NODE %s' % idx) - file.write('\n%s' % (marker.name)) + transform = JMS.transforms[idx] + file.write('\n%s' % (node.name)) + file.write('\n%s' % (node.child)) + file.write('\n%s' % (node.sibling)) + file.write(DECIMAL_4 % (transform.rotation)) + file.write(DECIMAL_3 % (transform.translation)) + if write_whitespace: + file.write('\n') - if jms_version >= 8198 and jms_version <= 8204: - file.write('\n%s' % (marker.region)) - - file.write( - '\n%s' % (marker.parent) + - decimal_4 % (marker.rotation) + - decimal_3 % (marker.translation) - ) - - if jms_version >= 8200: - file.write(decimal_1 % (marker.radius)) - - if jms_version >= 8205: - file.write('\n') - - if jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Instances###' - ) - - if jms_version >= 8203: - if jms_version >= 8206: - file.write( - '\n;### INSTANCE XREF PATHS ###' + - '\n%s' % (len(JMS.xref_instances)) + - '\n;\t' + - '\n;\t\n' - ) - - elif jms_version == 8205: - file.write( - '\n;### INSTANCE XREF PATHS ###' + - '\n%s' % (len(JMS.xref_instances)) + - '\n;\t\n' - ) - - elif jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Instance xref paths###' + - '\n%s' % (len(JMS.xref_instances)) - ) - - for idx, xref_instance in enumerate(JMS.xref_instances): - if jms_version >= 8205: - file.write( - '\n;XREF %s' % (idx) + - '\n%s' % (xref_instance.path) + - '\n%s\n' % (xref_instance.name) - ) - - else: - file.write( - '\n%s' % (xref_instance.path) + - '\n%s\n' % (xref_instance.name) - ) - - if jms_version >= 8205: - file.write( - '\n;### INSTANCE MARKERS ###' + - '\n%s' % (len(JMS.xref_markers)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>\n' - ) - - elif jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Instance markers###' + - '\n%s' % (len(JMS.xref_markers)) - ) - - for idx, xref_marker in enumerate(JMS.xref_markers): - if jms_version >= 8205: - file.write( - '\n;XREF OBJECT %s' % (idx) + - '\n%s' % (xref_marker.name) + - '\n%s' % (xref_marker.unique_identifier) + - '\n%s' % (xref_marker.index) + - decimal_4 % (xref_marker.rotation) + - decimal_3 % (xref_marker.translation) + - '\n' - ) - - else: - file.write( - '\n%s' % (xref_marker.name) + - '\n%s' % (xref_marker.unique_identifier) + - '\n%s' % (xref_marker.index) + - decimal_4 % (xref_marker.rotation) + - decimal_3 % (xref_marker.translation) + - '\n' - ) - - if jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Skin data###' - ) - - if jms_version <= 8204: - if jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Regions###' - ) - - file.write( - '\n%s' % (len(JMS.regions)) - ) - - for region in JMS.regions: - file.write( - '\n%s' % (region.name) - ) - - if jms_version >= 8205: - file.write( - '\n;### VERTICES ###' + - '\n%s' % (len(JMS.vertices)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\t' + - '\n;\t\t' + - '\n;\t' + - '\n;\t\t>\n' - ) - - if jms_version >= 8211: - file.write( - ';\t>\n' - ) - else: - if jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Vertices###' - ) - - file.write( - '\n%s' % (len(JMS.vertices)) - ) +def write_nodes_8201(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('= 8205: - file.write( - '\n;VERTEX %s' % (idx) + - decimal_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2]) + - decimal_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2]) + - '\n%s' % (len(vertex.node_set)) - ) - for node in vertex.node_set: - node_index = node[0] - node_weight = node[1] - file.write( - '\n%s' % (node_index) + - decimal_1 % (node_weight) - ) - - file.write('\n%s' % (len(vertex.uv_set))) - - for uv in vertex.uv_set: - tex_u = uv[0] - tex_v = uv[1] - file.write(decimal_2 % (tex_u, tex_v)) - - if jms_version >= 8211: - file.write( - decimal_3 % (vertex.color[0], vertex.color[1], vertex.color[2]) - ) - - file.write('\n') - - else: - uv_0 = vertex.uv_set[0] - tex_u_0 = uv_0[0] - tex_v_0 = uv_0[1] - - uv_1 = None - tex_u_1 = 0.0 - tex_v_1 = 0.0 - if len(vertex.uv_set) > 1: - uv_1 = vertex.uv_set[1] - tex_u_1 = uv_1[0] - tex_v_1 = uv_1[1] - - uv_2 = None - tex_u_2 = 0.0 - tex_v_2 = 0.0 - if len(vertex.uv_set) > 2: - uv_2 = vertex.uv_set[2] - tex_u_2 = uv_2[0] - tex_v_2 = uv_2[1] - - uv_3 = None - tex_u_3 = 0.0 - tex_v_3 = 0.0 - if len(vertex.uv_set) > 3: - uv_3 = vertex.uv_set[3] - tex_u_3 = uv_3[0] - tex_v_3 = uv_3[1] - - if jms_version < 8198: - file.write( - '\n%s' % (vertex.region) - ) - - node0 = (int(-1), float(0.0)) - if len(vertex.node_set) > 0: - node0 = vertex.node_set[0] - - node1 = (int(-1), float(0.0)) - if len(vertex.node_set) > 1: - node1 = vertex.node_set[1] - - node2 = (int(-1), float(0.0)) - if len(vertex.node_set) > 2: - node2 = vertex.node_set[2] - - node3 = (int(-1), float(0.0)) - if len(vertex.node_set) > 3: - node3 = vertex.node_set[3] - - node0_index = node0[0] - node0_weight = node0[1] - - node1_index = node1[0] - node1_weight = node1[1] - - node2_index = node2[0] - node2_weight = node2[1] - - node3_index = node3[0] - node3_weight = node3[1] - - if jms_version < 8202: - if not node1_index == -1: - node1_weight = 1.0 - node0_weight - - if node1_weight == 0: - node1_index = -1 - - if node1_weight == 1: - node0_index = node1[0] - node1_index = -1 - node1_weight = 0.0 - - if jms_version >= 8204: - file.write( - '\n%s' % (node0_index) + - decimal_1 % (node0_weight) + - decimal_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2]) + - decimal_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2]) + - '\n%s' % (node1_index) + - decimal_1 % (node1_weight) + - '\n%s' % (node2_index) + - decimal_1 % (node2_weight) + - '\n%s' % (node3_index) + - decimal_1 % (node3_weight) - ) - - else: - file.write( - '\n%s' % (node0_index) + - decimal_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2]) + - decimal_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2]) + - '\n%s' % (node1_index) + - decimal_1 % (node1_weight) - ) - - if jms_version >= 8200: - if jms_version >= 8202 and jms_version <= 8204: - file.write( - decimal_2 % (tex_u_0, tex_v_0) + - decimal_2 % (tex_u_1, tex_v_1) + - decimal_2 % (tex_u_2, tex_v_2) + - decimal_2 % (tex_u_3, tex_v_3) - ) - - else: - file.write( - decimal_1 % (tex_u_0) + - decimal_1 % (tex_v_0) - ) - - else: - file.write(decimal_2 % (tex_u_0, tex_v_0)) - - if jms_version >= 8199: - unused_flag = 0 - file.write('\n%s' % (unused_flag)) - - if jms_version >= 8205: - file.write( - '\n;### TRIANGLES ###' + - '\n%s' % (len(JMS.triangles)) + - '\n;\t' + - '\n;\t>\n' - ) - - else: - if jms_version >= 8203 and jms_version <= 8204: - file.write( - '\n;' + - '\n;###Faces###' - ) - - file.write( - '\n%s' % (len(JMS.triangles)) - ) + else: + if write_comments: + file.write('\n;') + file.write('\n;###Frames###') - for idx, triangle in enumerate(JMS.triangles): - if jms_version >= 8205: - file.write( - '\n;TRIANGLE %s' % (idx) + - '\n%s' % (triangle.material_index) + - '\n%s\t%s\t%s\n' % (triangle.v0, triangle.v1, triangle.v2) - ) - - else: - if jms_version >= 8198: - file.write('\n%s' % (triangle.region)) - - file.write( - '\n%s' % (triangle.material_index) + - '\n%s\t%s\t%s' % (triangle.v0, triangle.v1, triangle.v2) - ) - - if jms_version <= 8204: - file.write('\n') + file.write('\n%s' % (len(JMS.nodes))) + for idx, node in enumerate(JMS.nodes): + transform = JMS.transforms[idx] + file.write('\n%s' % (node.name)) + file.write('\n%s' % (node.child)) + file.write('\n%s' % (node.sibling)) + file.write(DECIMAL_4 % (transform.rotation)) + file.write(DECIMAL_3 % (transform.translation)) + if write_whitespace: + file.write('\n') - if jms_version >= 8206: - file.write( - '\n;### SPHERES ###' + - '\n%s' % (len(JMS.spheres)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t\n' - ) - - #write sphere - for idx, sphere in enumerate(JMS.spheres): - file.write( - '\n;SPHERE %s' % (idx) + - '\n%s' % (sphere.name) + - '\n%s' % (sphere.parent_index) + - '\n%s' % (sphere.material_index) + - decimal_4 % (sphere.rotation) + - decimal_3 % (sphere.translation) + - decimal_1 % (sphere.radius) + - '\n' - ) - - #write boxes - file.write( - '\n;### BOXES ###' + - '\n%s' % (len(JMS.boxes)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, box in enumerate(JMS.boxes): - file.write( - '\n;BOXES %s' % (idx) + - '\n%s' % (box.name) + - '\n%s' % (box.parent_index) + - '\n%s' % (box.material_index) + - decimal_4 % (box.rotation) + - decimal_3 % (box.translation) + - decimal_1 % (box.width) + - decimal_1 % (box.length) + - decimal_1 % (box.height) + - '\n' - ) - - #write capsules - file.write( - '\n;### CAPSULES ###' + - '\n%s' % (len(JMS.capsules)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, capsule in enumerate(JMS.capsules): - file.write( - '\n;CAPSULES %s' % (idx) + - '\n%s' % (capsule.name) + - '\n%s' % (capsule.parent_index) + - '\n%s' % (capsule.material_index) + - decimal_4 % (capsule.rotation) + - decimal_3 % (capsule.translation) + - decimal_1 % (capsule.height) + - decimal_1 % (capsule.radius) + - '\n' - ) - - #write convex shapes - file.write( - '\n;### CONVEX SHAPES ###' + - '\n%s' % (len(JMS.convex_shapes)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t' + - '\n;\t<...vertices>\n' - ) - - for idx, convex_shape in enumerate(JMS.convex_shapes): - file.write( - '\n;CONVEX %s' % (idx) + - '\n%s' % (convex_shape.name) + - '\n%s' % (convex_shape.parent_index) + - '\n%s' % (convex_shape.material_index) + - decimal_4 % (convex_shape.rotation) + - decimal_3 % (convex_shape.translation) + - '\n%s' % (len(convex_shape.verts)) - ) - - for vertex in convex_shape.verts: - file.write(decimal_3 % (vertex.translation)) - - file.write('\n') - - #write rag dolls - file.write( - '\n;### RAGDOLLS ###' + - '\n%s' % (len(JMS.ragdolls)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - if jms_version == 8213: - file.write(';\t\n') - - for idx, ragdoll in enumerate(JMS.ragdolls): - file.write( - '\n;RAGDOLL %s' % (idx) + - '\n%s' % (ragdoll.name) + - '\n%s' % (ragdoll.attached_index) + - '\n%s' % (ragdoll.referenced_index) + - decimal_4 % (ragdoll.attached_rotation) + - decimal_3 % (ragdoll.attached_translation) + - decimal_4 % (ragdoll.referenced_rotation) + - decimal_3 % (ragdoll.referenced_translation) + - decimal_1 % (ragdoll.min_twist) + - decimal_1 % (ragdoll.max_twist) + - decimal_1 % (ragdoll.min_cone) + - decimal_1 % (ragdoll.max_cone) + - decimal_1 % (ragdoll.min_plane) + - decimal_1 % (ragdoll.max_plane) - ) - - if jms_version == 8213: - file.write(decimal_1 % (ragdoll.friction_limit)) - file.write('\n') - - #write hinges - file.write( - '\n;### HINGES ###' + - '\n%s' % (len(JMS.hinges)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, hinge in enumerate(JMS.hinges): - file.write( - '\n;HINGE %s' % (idx) + - '\n%s' % (hinge.name) + - '\n%s' % (hinge.body_a_index) + - '\n%s' % (hinge.body_b_index) + - decimal_4 % (hinge.body_a_rotation) + - decimal_3 % (hinge.body_a_translation) + - decimal_4 % (hinge.body_b_rotation) + - decimal_3 % (hinge.body_b_translation) + - '\n%s' % (hinge.is_limited) + - decimal_1 % (hinge.friction_limit) + - decimal_1 % (hinge.min_angle) + - decimal_1 % (hinge.max_angle) + - '\n' - ) - - if jms_version > 8209: - #write car wheel - file.write( - '\n;### CAR WHEEL ###' + - '\n%s' % (len(JMS.car_wheels)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, car_wheel in enumerate(JMS.car_wheels): - file.write( - '\n;CAR WHEEL %s' % (idx) + - '\n%s' % (car_wheel.name) + - '\n%s' % (car_wheel.chassis_index) + - '\n%s' % (car_wheel.wheel_index) + - decimal_4 % (car_wheel.chassis_rotation) + - decimal_3 % (car_wheel.chassis_translation) + - decimal_4 % (car_wheel.wheel_rotation) + - decimal_3 % (car_wheel.wheel_translation) + - decimal_4 % (car_wheel.suspension_rotation) + - decimal_3 % (car_wheel.suspension_translation) + - decimal_1 % (car_wheel.suspension_min_limit) + - decimal_1 % (car_wheel.suspension_max_limit) + - decimal_1 % (car_wheel.friction_limit) + - decimal_1 % (car_wheel.velocity) + - decimal_1 % (car_wheel.gain) + - '\n' - ) - - #write point to point - file.write( - '\n;### POINT TO POINT ###' + - '\n%s' % (len(JMS.point_to_points)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, point_to_point in enumerate(JMS.point_to_points): - file.write( - '\n;POINT_TO_POINT %s' % (idx) + - '\n%s' % (point_to_point.name) + - '\n%s' % (point_to_point.body_a_index) + - '\n%s' % (point_to_point.body_b_index) + - decimal_4 % (point_to_point.body_b_rotation) + - decimal_3 % (point_to_point.body_b_translation) + - decimal_4 % (point_to_point.body_a_rotation) + - decimal_3 % (point_to_point.body_a_translation) + - '\n%s' % (point_to_point.constraint_type) + - decimal_1 % (point_to_point.x_min_limit) + - decimal_1 % (point_to_point.x_max_limit) + - decimal_1 % (point_to_point.y_min_limit) + - decimal_1 % (point_to_point.y_max_limit) + - decimal_1 % (point_to_point.z_min_limit) + - decimal_1 % (point_to_point.z_max_limit) + - decimal_1 % (point_to_point.spring_length) + - '\n' - ) - - #write prismatic - file.write( - '\n;### PRISMATIC ###' + - '\n%s' % (len(JMS.prismatics)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, prismatic in enumerate(JMS.prismatics): - file.write( - '\n;PRISMATIC %s' % (idx) + - '\n%s' % (prismatic.name) + - '\n%s' % (prismatic.body_a_index) + - '\n%s' % (prismatic.body_b_index) + - decimal_4 % (prismatic.body_a_rotation) + - decimal_3 % (prismatic.body_a_translation) + - decimal_4 % (prismatic.body_b_rotation) + - decimal_3 % (prismatic.body_b_translation) + - '\n%s' % (prismatic.is_limited) + - decimal_1 % (prismatic.friction_limit) + - decimal_1 % (prismatic.min_limit) + - decimal_1 % (prismatic.max_limit) + - '\n' - ) - - if jms_version >= 8209: - #write bounding sphere - file.write( - '\n;### BOUNDING SPHERE ###' + - '\n%s' % (len(JMS.bounding_spheres)) + - '\n;\t>' + - '\n;\t\n' - ) - - for idx, bounding_sphere in enumerate(JMS.bounding_spheres): - file.write( - '\n;BOUNDING SPHERE %s' % (idx) + - decimal_3 % (bounding_sphere.translation) + - decimal_1 % (bounding_sphere.radius) + - '\n' - ) - - if jms_version >= 8212: - #write skylight - file.write( - '\n;### SKYLIGHT ###' + - '\n%s' % (len(JMS.skylights)) + - '\n;\t>' + - '\n;\t>' + - '\n;\t\n' - ) - - for idx, light in enumerate(JMS.skylights): - file.write( - '\n;SKYLIGHT %s' % (idx) + - decimal_3 % light.direction + - decimal_3 % light.radiant_intensity + - decimal_1 % light.solid_angle + - '\n' - ) +def write_nodes_8205(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') - file.write(struct.pack('= 8205: - file.write(struct.pack('') + file.write('\n;\t') + if write_whitespace: + file.write('\n') - file.write(struct.pack('') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, material in enumerate(JMS.materials): + if write_comments: + file.write('\n;MATERIAL %s' % idx) + + material_definition = '(%s)' % (material.slot) + if not material.lod == None: + material_definition += ' %s' % (material.lod) - if jms_version >= 8205: - material_definition = '(%s)' % (material.slot) - if not material.lod == None: - material_definition += ' %s' % (material.lod) + if not material.permutation == '': + material_definition += ' %s' % (material.permutation) - if not material.permutation == '': - material_definition += ' %s' % (material.permutation) + if not material.region == '': + material_definition += ' %s' % (material.region) - if not material.region == '': - material_definition += ' %s' % (material.region) + file.write('\n%s' % (material.name)) + file.write('\n%s' % (material_definition)) + if write_whitespace: + file.write('\n') + +def write_markers_8197(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') + + for idx, marker in enumerate(JMS.markers): + if write_comments: + file.write('\n;MARKER %s' % idx) + + file.write('\n%s' % (marker.name)) + file.write('\n%s' % (marker.parent)) + file.write(DECIMAL_4 % (marker.rotation)) + file.write(DECIMAL_3 % (marker.translation)) + if write_whitespace: + file.write('\n') - file.write(struct.pack('= 8198 and jms_version <= 8204: - file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') + for idx, marker in enumerate(JMS.markers): + if write_comments: + file.write('\n;MARKER %s' % idx) + + file.write('\n%s' % (marker.name)) + file.write('\n%s' % (marker.region)) + file.write('\n%s' % (marker.parent)) + file.write(DECIMAL_4 % (marker.rotation)) + file.write(DECIMAL_3 % (marker.translation)) + if write_whitespace: + file.write('\n') + +def write_markers_8200(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('= 8200: - file.write(struct.pack('= 8203: - file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, marker in enumerate(JMS.markers): + if write_comments: + file.write('\n;MARKER %s' % idx) + + file.write('\n%s' % (marker.name)) + file.write('\n%s' % (marker.region)) + file.write('\n%s' % (marker.parent)) + file.write(DECIMAL_4 % (marker.rotation)) + file.write(DECIMAL_3 % (marker.translation)) + file.write(DECIMAL_1 % (marker.radius)) + if write_whitespace: + file.write('\n') + +def write_markers_8201(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, marker in enumerate(JMS.markers): + if write_comments: + file.write('\n;MARKER %s' % idx) + + file.write('\n%s' % (marker.name)) + file.write('\n%s' % (marker.region)) + file.write('\n%s' % (marker.parent)) + file.write(DECIMAL_4 % (marker.rotation)) + file.write(DECIMAL_3 % (marker.translation)) + file.write(DECIMAL_1 % (marker.radius)) + if write_whitespace: + file.write('\n') + +def write_instance_xref_paths_8201(file, JMS, binary, write_comments, write_whitespace): + if binary: + file.write(struct.pack('') + if write_whitespace: + file.write('\n') + + for idx, xref_instance in enumerate(JMS.xref_instances): + if write_comments: + file.write('\n;XREF %s' % idx) + + file.write('\n%s' % (xref_instance.path)) + if write_whitespace: + file.write('\n') + +def write_instance_xref_paths_8208(file, JMS, binary, write_comments, write_whitespace): + if binary: + file.write(struct.pack('') + if write_whitespace: + file.write('\n') + + for idx, xref_instance in enumerate(JMS.xref_instances): + if write_comments: + file.write('\n;XREF %s' % idx) + + file.write('\n%s' % (xref_instance.path)) + file.write('\n%s' % (xref_instance.name)) + if write_whitespace: + file.write('\n') + +def write_instance_markers_8201(file, JMS, binary, write_comments, write_whitespace): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') + + for idx, xref_marker in enumerate(JMS.xref_markers): + if write_comments: + file.write('\n;XREF OBJECT %s' % idx) + + file.write('\n%s' % (xref_marker.name)) + file.write('\n%s' % (xref_marker.unique_identifier)) + file.write('\n%s' % (xref_marker.index)) + file.write(DECIMAL_4 % (xref_marker.rotation)) + file.write(DECIMAL_3 % (xref_marker.translation)) + if write_whitespace: + file.write('\n') + +def write_regions_8197(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + if write_whitespace: + file.write('\n') + + for idx, region in enumerate(JMS.regions): + if write_comments: + file.write('\n;REGION %s' % idx) + + file.write('\n%s' % (region.name)) + if write_whitespace: + file.write('\n') + +def write_regions_8201(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('= 8205: - file.write(struct.pack('= 8211: - file.write(struct.pack(' 1: - uv_1 = vertex.uv_set[1] - tex_u_1 = uv_1[0] - tex_v_1 = uv_1[1] - - uv_2 = None - tex_u_2 = 0.0 - tex_v_2 = 0.0 - if len(vertex.uv_set) > 2: - uv_2 = vertex.uv_set[2] - tex_u_2 = uv_2[0] - tex_v_2 = uv_2[1] - - uv_3 = None - tex_u_3 = 0.0 - tex_v_3 = 0.0 - if len(vertex.uv_set) > 3: - uv_3 = vertex.uv_set[3] - tex_u_3 = uv_3[0] - tex_v_3 = uv_3[1] - - if jms_version < 8198: - file.write( - '\n%s' % (vertex.region) - ) - - node0 = (int(-1), float(0.0)) - if len(vertex.node_set) > 0: - node0 = vertex.node_set[0] - - node1 = (int(-1), float(0.0)) - if len(vertex.node_set) > 1: - node1 = vertex.node_set[1] - - node2 = (int(-1), float(0.0)) - if len(vertex.node_set) > 2: - node2 = vertex.node_set[2] - - node3 = (int(-1), float(0.0)) - if len(vertex.node_set) > 3: - node3 = vertex.node_set[3] - - node0_index = node0[0] - node0_weight = node0[1] - - node1_index = node1[0] - node1_weight = node1[1] - - node2_index = node2[0] - node2_weight = node2[1] - - node3_index = node3[0] - node3_weight = node3[1] - - if jms_version < 8202: - if not node1_index == -1: - node1_weight = 1.0 - node0_weight - - if node1_weight == 0: - node1_index = -1 - - if node1_weight == 1: - node0_index = node1[0] - node1_index = -1 - node1_weight = 0.0 - - if jms_version >= 8204: - file.write(struct.pack('= 8200: - if jms_version >= 8202 and jms_version <= 8204: - file.write(struct.pack('= 8199: - file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') + + for idx, vertex in enumerate(JMS.vertices): + if write_comments: + file.write('\n;VERTEX %s' % idx) + + node0 = (int(-1), float(0.0)) + if len(vertex.node_set) > 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + file.write('\n%s' % vertex.region) + file.write('\n%s' % node0_index) + file.write(DECIMAL_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2])) + file.write(DECIMAL_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2])) + file.write('\n%s' % node1_index) + file.write(DECIMAL_1 % node1_weight) + file.write(DECIMAL_2 % (vertex.uv_set[0][0], vertex.uv_set[0][1])) + if write_whitespace: + file.write('\n') + +def write_vertices_8198(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, vertex in enumerate(JMS.vertices): + if write_comments: + file.write('\n;VERTEX %s' % idx) + + node0 = (int(-1), float(0.0)) + if len(vertex.node_set) > 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + file.write('\n%s' % node0_index) + file.write(DECIMAL_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2])) + file.write(DECIMAL_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2])) + file.write('\n%s' % node1_index) + file.write(DECIMAL_1 % node1_weight) + file.write(DECIMAL_2 % (vertex.uv_set[0][0], vertex.uv_set[0][1])) + file.write('\n%s' % 0) + if write_whitespace: + file.write('\n') + +def write_vertices_8199(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, vertex in enumerate(JMS.vertices): + if write_comments: + file.write('\n;VERTEX %s' % idx) + + node0 = (int(-1), float(0.0)) + if len(vertex.node_set) > 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + file.write('\n%s' % node0_index) + file.write(DECIMAL_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2])) + file.write(DECIMAL_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2])) + file.write('\n%s' % node1_index) + file.write(DECIMAL_1 % node1_weight) + file.write(DECIMAL_2 % (vertex.uv_set[0][0], vertex.uv_set[0][1])) + file.write('\n%s' % 0) + if write_whitespace: + file.write('\n') + +def write_vertices_8201(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + file.write('\n%s' % node0_index) + file.write(DECIMAL_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2])) + file.write(DECIMAL_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2])) + file.write('\n%s' % node1_index) + file.write(DECIMAL_1 % node1_weight) + file.write(DECIMAL_2 % (vertex.uv_set[0][0], vertex.uv_set[0][1])) + file.write('\n%s' % 0) + if write_whitespace: + file.write('\n') + +def write_vertices_8202(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + uv_0 = vertex.uv_set[0] + tex_u_0 = uv_0[0] + tex_v_0 = uv_0[1] + + uv_1 = None + tex_u_1 = 0.0 + tex_v_1 = 0.0 + if len(vertex.uv_set) > 1: + uv_1 = vertex.uv_set[1] + tex_u_1 = uv_1[0] + tex_v_1 = uv_1[1] + + uv_2 = None + tex_u_2 = 0.0 + tex_v_2 = 0.0 + if len(vertex.uv_set) > 2: + uv_2 = vertex.uv_set[2] + tex_u_2 = uv_2[0] + tex_v_2 = uv_2[1] + + uv_3 = None + tex_u_3 = 0.0 + tex_v_3 = 0.0 + if len(vertex.uv_set) > 3: + uv_3 = vertex.uv_set[3] + tex_u_3 = uv_3[0] + tex_v_3 = uv_3[1] + + file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node0_index = node0[0] + + node1_index = node1[0] + node1_weight = node1[1] + + uv_0 = vertex.uv_set[0] + tex_u_0 = uv_0[0] + tex_v_0 = uv_0[1] + + uv_1 = None + tex_u_1 = 0.0 + tex_v_1 = 0.0 + if len(vertex.uv_set) > 1: + uv_1 = vertex.uv_set[1] + tex_u_1 = uv_1[0] + tex_v_1 = uv_1[1] + + uv_2 = None + tex_u_2 = 0.0 + tex_v_2 = 0.0 + if len(vertex.uv_set) > 2: + uv_2 = vertex.uv_set[2] + tex_u_2 = uv_2[0] + tex_v_2 = uv_2[1] + + uv_3 = None + tex_u_3 = 0.0 + tex_v_3 = 0.0 + if len(vertex.uv_set) > 3: + uv_3 = vertex.uv_set[3] + tex_u_3 = uv_3[0] + tex_v_3 = uv_3[1] + + file.write('\n%s' % node0_index) + file.write(DECIMAL_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2])) + file.write(DECIMAL_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2])) + file.write('\n%s' % node1_index) + file.write(DECIMAL_1 % node1_weight) + file.write(DECIMAL_2 % (tex_u_0, tex_v_0)) + file.write(DECIMAL_2 % (tex_u_1, tex_v_1)) + file.write(DECIMAL_2 % (tex_u_2, tex_v_2)) + file.write(DECIMAL_2 % (tex_u_3, tex_v_3)) + file.write('\n%s' % 0) + if write_whitespace: + file.write('\n') + +def write_vertices_8204(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node2 = (int(-1), float(0.0)) + if len(vertex.node_set) > 2: + node2 = vertex.node_set[2] + + node3 = (int(-1), float(0.0)) + if len(vertex.node_set) > 3: + node3 = vertex.node_set[3] + + node0_index = node0[0] + node0_weight = node0[1] + + node1_index = node1[0] + node1_weight = node1[1] + + node2_index = node2[0] + node2_weight = node2[1] + + node3_index = node3[0] + node3_weight = node3[1] + + uv_0 = vertex.uv_set[0] + tex_u_0 = uv_0[0] + tex_v_0 = uv_0[1] + + uv_1 = None + tex_u_1 = 0.0 + tex_v_1 = 0.0 + if len(vertex.uv_set) > 1: + uv_1 = vertex.uv_set[1] + tex_u_1 = uv_1[0] + tex_v_1 = uv_1[1] + + uv_2 = None + tex_u_2 = 0.0 + tex_v_2 = 0.0 + if len(vertex.uv_set) > 2: + uv_2 = vertex.uv_set[2] + tex_u_2 = uv_2[0] + tex_v_2 = uv_2[1] + + uv_3 = None + tex_u_3 = 0.0 + tex_v_3 = 0.0 + if len(vertex.uv_set) > 3: + uv_3 = vertex.uv_set[3] + tex_u_3 = uv_3[0] + tex_v_3 = uv_3[1] + + file.write(struct.pack(' 0: + node0 = vertex.node_set[0] + + node1 = (int(-1), float(0.0)) + if len(vertex.node_set) > 1: + node1 = vertex.node_set[1] + + node2 = (int(-1), float(0.0)) + if len(vertex.node_set) > 2: + node2 = vertex.node_set[2] + + node3 = (int(-1), float(0.0)) + if len(vertex.node_set) > 3: + node3 = vertex.node_set[3] + + node0_index = node0[0] + node0_weight = node0[1] + + node1_index = node1[0] + node1_weight = node1[1] + + node2_index = node2[0] + node2_weight = node2[1] + + node3_index = node3[0] + node3_weight = node3[1] + + uv_0 = vertex.uv_set[0] + tex_u_0 = uv_0[0] + tex_v_0 = uv_0[1] + + uv_1 = None + tex_u_1 = 0.0 + tex_v_1 = 0.0 + if len(vertex.uv_set) > 1: + uv_1 = vertex.uv_set[1] + tex_u_1 = uv_1[0] + tex_v_1 = uv_1[1] + + uv_2 = None + tex_u_2 = 0.0 + tex_v_2 = 0.0 + if len(vertex.uv_set) > 2: + uv_2 = vertex.uv_set[2] + tex_u_2 = uv_2[0] + tex_v_2 = uv_2[1] + + uv_3 = None + tex_u_3 = 0.0 + tex_v_3 = 0.0 + if len(vertex.uv_set) > 3: + uv_3 = vertex.uv_set[3] + tex_u_3 = uv_3[0] + tex_v_3 = uv_3[1] + + file.write('\n%s' % node0_index) + file.write(DECIMAL_1 % node0_weight) + file.write(DECIMAL_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2])) + file.write(DECIMAL_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2])) + file.write('\n%s' % node1_index) + file.write(DECIMAL_1 % node1_weight) + file.write('\n%s' % node2_index) + file.write(DECIMAL_1 % node2_weight) + file.write('\n%s' % node3_index) + file.write(DECIMAL_1 % node3_weight) + file.write(DECIMAL_2 % (tex_u_0, tex_v_0)) + file.write(DECIMAL_2 % (tex_u_1, tex_v_1)) + file.write(DECIMAL_2 % (tex_u_2, tex_v_2)) + file.write(DECIMAL_2 % (tex_u_3, tex_v_3)) + file.write('\n%s' % 0) + if write_whitespace: + file.write('\n') + +def write_vertices_8205(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t\t>') + file.write('\n;\t\t<...>') + file.write('\n;\t') + file.write('\n;\t\t>') + file.write('\n;\t\t<...>') + if write_whitespace: + file.write('\n') + + for idx, vertex in enumerate(JMS.vertices): + if write_comments: + file.write('\n;VERTEX %s' % idx) + + file.write(DECIMAL_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2])) + file.write(DECIMAL_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2])) + file.write('\n%s' % len(vertex.node_set)) + for node in vertex.node_set: + node_index, node_weight = node + file.write('\n%s' % (node_index)) + file.write(DECIMAL_1 % (node_weight)) + + file.write('\n%s' % len(vertex.uv_set)) + for uv in vertex.uv_set: + uv_0, uv_1 = uv + file.write(DECIMAL_2 % (uv_0, uv_1)) + + if write_whitespace: + file.write('\n') + +def write_vertices_8211(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t\t>') + file.write('\n;\t\t<...>') + file.write('\n;\t') + file.write('\n;\t\t>') + file.write('\n;\t\t<...>') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') + + for idx, vertex in enumerate(JMS.vertices): + if write_comments: + file.write('\n;VERTEX %s' % idx) + + file.write(DECIMAL_3 % (vertex.translation[0], vertex.translation[1], vertex.translation[2])) + file.write(DECIMAL_3 % (vertex.normal[0], vertex.normal[1], vertex.normal[2])) + file.write('\n%s' % len(vertex.node_set)) + for node in vertex.node_set: + node_index, node_weight = node + file.write('\n%s' % (node_index)) + file.write(DECIMAL_1 % (node_weight)) + + file.write('\n%s' % len(vertex.uv_set)) + for uv in vertex.uv_set: + uv_0, uv_1 = uv + file.write(DECIMAL_2 % (uv_0, uv_1)) + + file.write(DECIMAL_3 % vertex.color) + if write_whitespace: + file.write('\n') + +def write_triangles_8197(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') + for idx, triangle in enumerate(JMS.triangles): - if jms_version >= 8198: - file.write(struct.pack('= 8206: - file.write( - '\n;### SPHERES ###' + - '\n%s' % (len(JMS.spheres)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t\n' - ) - - #write sphere - for idx, sphere in enumerate(JMS.spheres): - file.write( - '\n;SPHERE %s' % (idx) + - '\n%s' % (sphere.name) + - '\n%s' % (sphere.parent_index) + - '\n%s' % (sphere.material_index) + - decimal_4 % (sphere.rotation) + - decimal_3 % (sphere.translation) + - decimal_1 % (sphere.radius) + - '\n' - ) - - #write boxes - file.write( - '\n;### BOXES ###' + - '\n%s' % (len(JMS.boxes)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, box in enumerate(JMS.boxes): - file.write( - '\n;BOXES %s' % (idx) + - '\n%s' % (box.name) + - '\n%s' % (box.parent_index) + - '\n%s' % (box.material_index) + - decimal_4 % (box.rotation) + - decimal_3 % (box.translation) + - decimal_1 % (box.width) + - decimal_1 % (box.length) + - decimal_1 % (box.height) + - '\n' - ) - - #write capsules - file.write( - '\n;### CAPSULES ###' + - '\n%s' % (len(JMS.capsules)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, capsule in enumerate(JMS.capsules): - file.write( - '\n;CAPSULES %s' % (idx) + - '\n%s' % (capsule.name) + - '\n%s' % (capsule.parent_index) + - '\n%s' % (capsule.material_index) + - decimal_4 % (capsule.rotation) + - decimal_3 % (capsule.translation) + - decimal_1 % (capsule.height) + - decimal_1 % (capsule.radius) + - '\n' - ) - - #write convex shapes - file.write( - '\n;### CONVEX SHAPES ###' + - '\n%s' % (len(JMS.convex_shapes)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t>' + - '\n;\t>' + - '\n;\t' + - '\n;\t<...vertices>\n' - ) - - for idx, convex_shape in enumerate(JMS.convex_shapes): - file.write( - '\n;CONVEX %s' % (idx) + - '\n%s' % (convex_shape.name) + - '\n%s' % (convex_shape.parent_index) + - '\n%s' % (convex_shape.material_index) + - decimal_4 % (convex_shape.rotation) + - decimal_3 % (convex_shape.translation) + - '\n%s' % (len(convex_shape.verts)) - ) - - for vertex in convex_shape.verts: - file.write(decimal_3 % (vertex.translation)) - - file.write('\n') - - #write rag dolls - file.write( - '\n;### RAGDOLLS ###' + - '\n%s' % (len(JMS.ragdolls)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - if jms_version == 8213: - file.write(';\t\n') - - for idx, ragdoll in enumerate(JMS.ragdolls): - file.write( - '\n;RAGDOLL %s' % (idx) + - '\n%s' % (ragdoll.name) + - '\n%s' % (ragdoll.attached_index) + - '\n%s' % (ragdoll.referenced_index) + - decimal_4 % (ragdoll.attached_rotation) + - decimal_3 % (ragdoll.attached_translation) + - decimal_4 % (ragdoll.referenced_rotation) + - decimal_3 % (ragdoll.referenced_translation) + - decimal_1 % (ragdoll.min_twist) + - decimal_1 % (ragdoll.max_twist) + - decimal_1 % (ragdoll.min_cone) + - decimal_1 % (ragdoll.max_cone) + - decimal_1 % (ragdoll.min_plane) + - decimal_1 % (ragdoll.max_plane) - ) - - if jms_version == 8213: - file.write(decimal_1 % (ragdoll.friction_limit)) - file.write('\n') - - #write hinges - file.write( - '\n;### HINGES ###' + - '\n%s' % (len(JMS.hinges)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, hinge in enumerate(JMS.hinges): - file.write( - '\n;HINGE %s' % (idx) + - '\n%s' % (hinge.name) + - '\n%s' % (hinge.body_a_index) + - '\n%s' % (hinge.body_b_index) + - decimal_4 % (hinge.body_a_rotation) + - decimal_3 % (hinge.body_a_translation) + - decimal_4 % (hinge.body_b_rotation) + - decimal_3 % (hinge.body_b_translation) + - '\n%s' % (hinge.is_limited) + - decimal_1 % (hinge.friction_limit) + - decimal_1 % (hinge.min_angle) + - decimal_1 % (hinge.max_angle) + - '\n' - ) - - if jms_version > 8209: - #write car wheel - file.write( - '\n;### CAR WHEEL ###' + - '\n%s' % (len(JMS.car_wheels)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, car_wheel in enumerate(JMS.car_wheels): - file.write( - '\n;CAR WHEEL %s' % (idx) + - '\n%s' % (car_wheel.name) + - '\n%s' % (car_wheel.chassis_index) + - '\n%s' % (car_wheel.wheel_index) + - decimal_4 % (car_wheel.chassis_rotation) + - decimal_3 % (car_wheel.chassis_translation) + - decimal_4 % (car_wheel.wheel_rotation) + - decimal_3 % (car_wheel.wheel_translation) + - decimal_4 % (car_wheel.suspension_rotation) + - decimal_3 % (car_wheel.suspension_translation) + - decimal_1 % (car_wheel.suspension_min_limit) + - decimal_1 % (car_wheel.suspension_max_limit) + - decimal_1 % (car_wheel.friction_limit) + - decimal_1 % (car_wheel.velocity) + - decimal_1 % (car_wheel.gain) + - '\n' - ) - - #write point to point - file.write( - '\n;### POINT TO POINT ###' + - '\n%s' % (len(JMS.point_to_points)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, point_to_point in enumerate(JMS.point_to_points): - file.write( - '\n;POINT_TO_POINT %s' % (idx) + - '\n%s' % (point_to_point.name) + - '\n%s' % (point_to_point.body_a_index) + - '\n%s' % (point_to_point.body_b_index) + - decimal_4 % (point_to_point.body_b_rotation) + - decimal_3 % (point_to_point.body_b_translation) + - decimal_4 % (point_to_point.body_a_rotation) + - decimal_3 % (point_to_point.body_a_translation) + - '\n%s' % (point_to_point.constraint_type) + - decimal_1 % (point_to_point.x_min_limit) + - decimal_1 % (point_to_point.x_max_limit) + - decimal_1 % (point_to_point.y_min_limit) + - decimal_1 % (point_to_point.y_max_limit) + - decimal_1 % (point_to_point.z_min_limit) + - decimal_1 % (point_to_point.z_max_limit) + - decimal_1 % (point_to_point.spring_length) + - '\n' - ) - - #write prismatic - file.write( - '\n;### PRISMATIC ###' + - '\n%s' % (len(JMS.prismatics)) + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t' + - '\n;\t\n' - ) - - for idx, prismatic in enumerate(JMS.prismatics): - file.write( - '\n;PRISMATIC %s' % (idx) + - '\n%s' % (prismatic.name) + - '\n%s' % (prismatic.body_a_index) + - '\n%s' % (prismatic.body_b_index) + - decimal_4 % (prismatic.body_a_rotation) + - decimal_3 % (prismatic.body_a_translation) + - decimal_4 % (prismatic.body_b_rotation) + - decimal_3 % (prismatic.body_b_translation) + - '\n%s' % (prismatic.is_limited) + - decimal_1 % (prismatic.friction_limit) + - decimal_1 % (prismatic.min_limit) + - decimal_1 % (prismatic.max_limit) + - '\n' - ) - - if jms_version >= 8209: - #write bounding sphere - file.write( - '\n;### BOUNDING SPHERE ###' + - '\n%s' % (len(JMS.bounding_spheres)) + - '\n;\t>' + - '\n;\t\n' - ) - - for idx, bounding_sphere in enumerate(JMS.bounding_spheres): - file.write( - '\n;BOUNDING SPHERE %s' % (idx) + - decimal_3 % (bounding_sphere.translation) + - decimal_1 % (bounding_sphere.radius) + - '\n' - ) - - if jms_version >= 8212: - #write skylight - file.write( - '\n;### SKYLIGHT ###' + - '\n%s' % (len(JMS.skylights)) + - '\n;\t>' + - '\n;\t>' + - '\n;\t\n' - ) - - for idx, light in enumerate(JMS.skylights): - file.write( - '\n;SKYLIGHT %s' % (idx) + - decimal_3 % light.direction + - decimal_3 % light.radiant_intensity + - decimal_1 % light.solid_angle + - '\n' - ) + else: + if write_comments: + file.write('\n;### TRIANGLES ###') + + file.write('\n%s' % (len(JMS.triangles))) + if write_comments: + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') + + for idx, triangle in enumerate(JMS.triangles): + if write_comments: + file.write('\n;TRIANGLE %s' % idx) + + file.write('\n%s' % triangle.region) + file.write('\n%s' % triangle.material_index) + file.write('\n%s\t%s\t%s' % (triangle.v0, triangle.v1, triangle.v2)) + if write_whitespace: + file.write('\n') + +def write_triangles_8201(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t>') + if write_whitespace: + file.write('\n') + + for idx, triangle in enumerate(JMS.triangles): + if write_comments: + file.write('\n;TRIANGLE %s' % idx) + + file.write('\n%s' % triangle.material_index) + file.write('\n%s\t%s\t%s' % (triangle.v0, triangle.v1, triangle.v2)) + if write_whitespace: + file.write('\n') + +def write_spheres_8206(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, sphere in enumerate(JMS.spheres): + if write_comments: + file.write('\n;SPHERE %s' % idx) + + file.write('\n%s' % sphere.name) + file.write('\n%s' % sphere.parent_index) + file.write(DECIMAL_4 % sphere.rotation) + file.write(DECIMAL_3 % sphere.translation) + file.write(DECIMAL_1 % sphere.radius) + if write_whitespace: + file.write('\n') + +def write_spheres_8207(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, sphere in enumerate(JMS.spheres): + if write_comments: + file.write('\n;SPHERE %s' % idx) + + file.write('\n%s' % sphere.name) + file.write('\n%s' % sphere.parent_index) + file.write('\n%s' % sphere.material_index) + file.write(DECIMAL_4 % sphere.rotation) + file.write(DECIMAL_3 % sphere.translation) + file.write(DECIMAL_1 % sphere.radius) + if write_whitespace: + file.write('\n') + +def write_boxes_8206(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, box in enumerate(JMS.boxes): + if write_comments: + file.write('\n;BOX %s' % idx) + + file.write('\n%s' % box.name) + file.write('\n%s' % box.parent_index) + file.write(DECIMAL_4 % box.rotation) + file.write(DECIMAL_3 % box.translation) + file.write(DECIMAL_1 % box.width) + file.write(DECIMAL_1 % box.length) + file.write(DECIMAL_1 % box.height) + if write_whitespace: + file.write('\n') + +def write_boxes_8207(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, box in enumerate(JMS.boxes): + if write_comments: + file.write('\n;BOX %s' % idx) + + file.write('\n%s' % box.name) + file.write('\n%s' % box.parent_index) + file.write('\n%s' % box.material_index) + file.write(DECIMAL_4 % box.rotation) + file.write(DECIMAL_3 % box.translation) + file.write(DECIMAL_1 % box.width) + file.write(DECIMAL_1 % box.length) + file.write(DECIMAL_1 % box.height) + if write_whitespace: + file.write('\n') + +def write_capsules_8206(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, capsule in enumerate(JMS.capsules): + if write_comments: + file.write('\n;CAPSULE %s' % idx) + + file.write('\n%s' % capsule.name) + file.write('\n%s' % capsule.parent_index) + file.write(DECIMAL_4 % capsule.rotation) + file.write(DECIMAL_3 % capsule.translation) + file.write(DECIMAL_1 % capsule.height) + file.write(DECIMAL_1 % capsule.radius) + if write_whitespace: + file.write('\n') + +def write_capsules_8207(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, capsule in enumerate(JMS.capsules): + if write_comments: + file.write('\n;CAPSULE %s' % idx) + + file.write('\n%s' % capsule.name) + file.write('\n%s' % capsule.parent_index) + file.write('\n%s' % capsule.material_index) + file.write(DECIMAL_4 % capsule.rotation) + file.write(DECIMAL_3 % capsule.translation) + file.write(DECIMAL_1 % capsule.height) + file.write(DECIMAL_1 % capsule.radius) + if write_whitespace: + file.write('\n') + +def write_convex_shapes_8206(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + file.write('\n;\t<...vertices>') + if write_whitespace: + file.write('\n') + + for idx, convex_shape in enumerate(JMS.convex_shapes): + if write_comments: + file.write('\n;CONVEX %s' % idx) + + file.write('\n%s' % convex_shape.name) + file.write('\n%s' % convex_shape.parent_index) + file.write(DECIMAL_4 % convex_shape.rotation) + file.write(DECIMAL_3 % convex_shape.translation) + file.write('\n%s' % (len(convex_shape.verts))) + for vertex in convex_shape.verts: + file.write(DECIMAL_3 % vertex.translation) + + if write_whitespace: + file.write('\n') + +def write_convex_shapes_8207(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t>') + file.write('\n;\t>') + file.write('\n;\t') + file.write('\n;\t<...vertices>') + if write_whitespace: + file.write('\n') + + for idx, convex_shape in enumerate(JMS.convex_shapes): + if write_comments: + file.write('\n;CONVEX %s' % idx) + + file.write('\n%s' % convex_shape.name) + file.write('\n%s' % convex_shape.parent_index) + file.write('\n%s' % convex_shape.material_index) + file.write(DECIMAL_4 % convex_shape.rotation) + file.write(DECIMAL_3 % convex_shape.translation) + file.write('\n%s' % (len(convex_shape.verts))) + for vertex in convex_shape.verts: + file.write(DECIMAL_3 % vertex.translation) + + if write_whitespace: + file.write('\n') + +def write_ragdolls_8206(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, ragdoll in enumerate(JMS.ragdolls): + if write_comments: + file.write('\n;RAGDOLL %s' % idx) + + file.write('\n%s' % ragdoll.name) + file.write('\n%s' % ragdoll.attached_index) + file.write('\n%s' % ragdoll.referenced_index) + file.write(DECIMAL_4 % ragdoll.attached_rotation) + file.write(DECIMAL_3 % ragdoll.attached_translation) + file.write(DECIMAL_4 % ragdoll.referenced_rotation) + file.write(DECIMAL_3 % ragdoll.referenced_translation) + file.write(DECIMAL_1 % ragdoll.min_twist) + file.write(DECIMAL_1 % ragdoll.max_twist) + file.write(DECIMAL_1 % ragdoll.min_cone) + file.write(DECIMAL_1 % ragdoll.max_cone) + file.write(DECIMAL_1 % ragdoll.min_plane) + file.write(DECIMAL_1 % ragdoll.max_plane) + if write_whitespace: + file.write('\n') + +def write_ragdolls_8213(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, ragdoll in enumerate(JMS.ragdolls): + if write_comments: + file.write('\n;RAGDOLL %s' % idx) + + file.write('\n%s' % ragdoll.name) + file.write('\n%s' % ragdoll.attached_index) + file.write('\n%s' % ragdoll.referenced_index) + file.write(DECIMAL_4 % ragdoll.attached_rotation) + file.write(DECIMAL_3 % ragdoll.attached_translation) + file.write(DECIMAL_4 % ragdoll.referenced_rotation) + file.write(DECIMAL_3 % ragdoll.referenced_translation) + file.write(DECIMAL_1 % ragdoll.min_twist) + file.write(DECIMAL_1 % ragdoll.max_twist) + file.write(DECIMAL_1 % ragdoll.min_cone) + file.write(DECIMAL_1 % ragdoll.max_cone) + file.write(DECIMAL_1 % ragdoll.min_plane) + file.write(DECIMAL_1 % ragdoll.max_plane) + file.write(DECIMAL_1 % ragdoll.friction_limit) + if write_whitespace: + file.write('\n') + +def write_hinges(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, hinge in enumerate(JMS.hinges): + if write_comments: + file.write('\n;HINGE %s' % idx) + + file.write('\n%s' % hinge.name) + file.write('\n%s' % hinge.body_a_index) + file.write('\n%s' % hinge.body_b_index) + file.write(DECIMAL_4 % hinge.body_a_rotation) + file.write(DECIMAL_3 % hinge.body_a_translation) + file.write(DECIMAL_4 % hinge.body_b_rotation) + file.write(DECIMAL_3 % hinge.body_b_translation) + file.write(DECIMAL_1 % hinge.min_twist) + file.write('\n%s' % hinge.is_limited) + file.write(DECIMAL_1 % hinge.friction_limit) + file.write(DECIMAL_1 % hinge.min_angle) + file.write(DECIMAL_1 % hinge.max_angle) + if write_whitespace: + file.write('\n') + +def write_bounding_spheres(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('>') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, bounding_sphere in enumerate(JMS.bounding_spheres): + if write_comments: + file.write('\n;BOUNDING SPHERE %s' % idx) + + file.write(DECIMAL_3 % bounding_sphere.translation) + file.write(DECIMAL_1 % bounding_sphere.radius) + if write_whitespace: + file.write('\n') + +def write_car_wheels(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, car_wheel in enumerate(JMS.car_wheels): + if write_comments: + file.write('\n;CAR WHEEL %s' % idx) + + file.write('\n%s' % car_wheel.name) + file.write('\n%s' % car_wheel.chassis_index) + file.write('\n%s' % car_wheel.wheel_index) + file.write(DECIMAL_4 % car_wheel.chassis_rotation) + file.write(DECIMAL_3 % car_wheel.chassis_translation) + file.write(DECIMAL_4 % car_wheel.wheel_rotation) + file.write(DECIMAL_3 % car_wheel.wheel_translation) + file.write(DECIMAL_4 % car_wheel.suspension_rotation) + file.write(DECIMAL_3 % car_wheel.suspension_translation) + file.write(DECIMAL_1 % car_wheel.suspension_min_limit) + file.write(DECIMAL_1 % car_wheel.suspension_max_limit) + file.write(DECIMAL_1 % car_wheel.friction_limit) + file.write(DECIMAL_1 % car_wheel.friction_limit) + file.write(DECIMAL_1 % car_wheel.velocity) + file.write(DECIMAL_1 % car_wheel.gain) + if write_whitespace: + file.write('\n') + +def write_point_to_points(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, point_to_point in enumerate(JMS.point_to_points): + if write_comments: + file.write('\n;POINT_TO_POINT %s' % idx) + + file.write('\n%s' % point_to_point.name) + file.write('\n%s' % point_to_point.body_a_index) + file.write('\n%s' % point_to_point.body_b_index) + file.write(DECIMAL_4 % point_to_point.body_a_rotation) + file.write(DECIMAL_3 % point_to_point.body_a_translation) + file.write(DECIMAL_4 % point_to_point.body_b_rotation) + file.write(DECIMAL_3 % point_to_point.body_b_translation) + file.write('\n%s' % point_to_point.constraint_type) + file.write(DECIMAL_1 % point_to_point.x_min_limit) + file.write(DECIMAL_1 % point_to_point.x_max_limit) + file.write(DECIMAL_1 % point_to_point.y_min_limit) + file.write(DECIMAL_1 % point_to_point.y_max_limit) + file.write(DECIMAL_1 % point_to_point.z_min_limit) + file.write(DECIMAL_1 % point_to_point.z_max_limit) + file.write(DECIMAL_1 % point_to_point.spring_length) + if write_whitespace: + file.write('\n') + +def write_prismatics(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, prismatic in enumerate(JMS.prismatics): + if write_comments: + file.write('\n;PRISMATIC %s' % idx) + + file.write('\n%s' % prismatic.name) + file.write('\n%s' % prismatic.body_a_index) + file.write('\n%s' % prismatic.body_b_index) + file.write(DECIMAL_4 % prismatic.body_a_rotation) + file.write(DECIMAL_3 % prismatic.body_a_translation) + file.write(DECIMAL_4 % prismatic.body_b_rotation) + file.write(DECIMAL_3 % prismatic.body_b_translation) + file.write('\n%s' % prismatic.is_limited) + file.write(DECIMAL_1 % prismatic.friction_limit) + file.write(DECIMAL_1 % prismatic.min_limit) + file.write(DECIMAL_1 % prismatic.max_limit) + if write_whitespace: + file.write('\n') + +def write_skylights(file, JMS, binary, write_comments=False, write_whitespace=False): + if binary: + file.write(struct.pack('>') + file.write('\n;\t>') + file.write('\n;\t') + if write_whitespace: + file.write('\n') + + for idx, skylight in enumerate(JMS.skylights): + if write_comments: + file.write('\n;SKYLIGHT %s' % idx) + + file.write(DECIMAL_3 % skylight.direction) + file.write(DECIMAL_3 % skylight.radiant_intensity) + file.write(DECIMAL_1 % skylight.solid_angle) + if write_whitespace: + file.write('\n') + +def update_decimal(): + global DECIMAL_POINT + global DECIMAL_1 + global DECIMAL_2 + global DECIMAL_3 + global DECIMAL_4 + + DECIMAL_POINT = "10" + DECIMAL_1 = '\n%0.{decimal_point}f'.format(decimal_point=DECIMAL_POINT) + DECIMAL_2 = '\n%0.{decimal_point}f\t%0.{decimal_point}f'.format(decimal_point=DECIMAL_POINT) + DECIMAL_3 = '\n%0.{decimal_point}f\t%0.{decimal_point}f\t%0.{decimal_point}f'.format(decimal_point=DECIMAL_POINT) + DECIMAL_4 = '\n%0.{decimal_point}f\t%0.{decimal_point}f\t%0.{decimal_point}f\t%0.{decimal_point}f'.format(decimal_point=DECIMAL_POINT) + +def build_asset(context, blend_scene, filepath, jms_version, game_title, generate_checksum, fix_rotations, use_maya_sorting, folder_structure, folder_type, model_type, is_jmi, permutation_ce, level_of_detail_ce, custom_scale, loop_normals, write_textures, report): + JMS = process_scene(context, jms_version, game_title, generate_checksum, fix_rotations, use_maya_sorting, model_type, blend_scene, custom_scale, loop_normals, write_textures) + + binary = False + + version_bounds = '8197-8200' + if game_title == "halo2": + version_bounds = '8197-8210' + elif game_title == "halo3": + version_bounds = '8197-8213' + + filename = global_functions.get_filename(game_title, permutation_ce, level_of_detail_ce, folder_structure, model_type, False, filepath) + root_directory = global_functions.get_directory(context, game_title, model_type, folder_structure, folder_type, is_jmi, filepath) + output_path = os.path.join(root_directory, filename) + if binary: + file = open(output_path + "B", 'wb') + file.write(struct.pack('<4s', bytes("IMBF", 'utf-8'))) + + else: + file = open(output_path, 'w', encoding='utf_8') + + if jms_version == 8197: + write_comments = False + write_whitespace = False + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_checksum(file, JMS, binary, write_comments, write_whitespace) + write_nodes_8197(file, JMS, binary, write_comments, write_whitespace) + write_materials_8197(file, JMS, binary, write_comments, write_whitespace) + write_markers_8197(file, JMS, binary, write_comments, write_whitespace) + write_regions_8197(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8197(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8197(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8198: + write_comments = False + write_whitespace = False + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_checksum(file, JMS, binary, write_comments, write_whitespace) + write_nodes_8197(file, JMS, binary, write_comments, write_whitespace) + write_materials_8197(file, JMS, binary, write_comments, write_whitespace) + write_markers_8198(file, JMS, binary, write_comments, write_whitespace) + write_regions_8197(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8198(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8198(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8199: + write_comments = False + write_whitespace = False + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_checksum(file, JMS, binary, write_comments, write_whitespace) + write_nodes_8197(file, JMS, binary, write_comments, write_whitespace) + write_materials_8197(file, JMS, binary, write_comments, write_whitespace) + write_markers_8198(file, JMS, binary, write_comments, write_whitespace) + write_regions_8197(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8199(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8198(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8200: + write_comments = False + write_whitespace = False + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_checksum(file, JMS, binary, write_comments, write_whitespace) + write_nodes_8197(file, JMS, binary, write_comments, write_whitespace) + write_materials_8197(file, JMS, binary, write_comments, write_whitespace) + write_markers_8200(file, JMS, binary, write_comments, write_whitespace) + write_regions_8197(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8199(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8198(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8201: + write_comments = True + write_whitespace = False + write_version(file, jms_version, version_bounds, binary, False, write_whitespace) + write_checksum(file, JMS, binary, False, write_whitespace) + write_nodes_8201(file, JMS, binary, write_comments, write_whitespace) + write_materials_8201(file, JMS, binary, write_comments, write_whitespace) + write_markers_8201(file, JMS, binary, write_comments, write_whitespace) + if write_comments: + file.write('\n;') + file.write('\n;###Instances###') + write_instance_xref_paths_8201(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8201(file, JMS, binary, write_comments, write_whitespace) + if write_comments: + file.write('\n;') + file.write('\n;###Skin data###') + write_regions_8201(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8201(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8201(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8202: + write_comments = True + write_whitespace = False + write_version(file, jms_version, version_bounds, binary, False, write_whitespace) + write_checksum(file, JMS, binary, False, write_whitespace) + write_nodes_8201(file, JMS, binary, write_comments, write_whitespace) + write_materials_8201(file, JMS, binary, write_comments, write_whitespace) + write_markers_8201(file, JMS, binary, write_comments, write_whitespace) + if write_comments: + file.write('\n;') + file.write('\n;###Instances###') + write_instance_xref_paths_8201(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8201(file, JMS, binary, write_comments, write_whitespace) + if write_comments: + file.write('\n;') + file.write('\n;###Skin data###') + write_regions_8201(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8202(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8201(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8203: + write_comments = True + write_whitespace = False + write_version(file, jms_version, version_bounds, binary, False, write_whitespace) + write_checksum(file, JMS, binary, False, write_whitespace) + write_nodes_8201(file, JMS, binary, write_comments, write_whitespace) + write_materials_8201(file, JMS, binary, write_comments, write_whitespace) + write_markers_8201(file, JMS, binary, write_comments, write_whitespace) + if write_comments: + file.write('\n;') + file.write('\n;###Instances###') + write_instance_xref_paths_8201(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8203(file, JMS, binary, write_comments, write_whitespace) + if write_comments: + file.write('\n;') + file.write('\n;###Skin data###') + write_regions_8201(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8202(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8201(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8204: + write_comments = True + write_whitespace = False + write_version(file, jms_version, version_bounds, binary, False, write_whitespace) + write_checksum(file, JMS, binary, False, write_whitespace) + write_nodes_8201(file, JMS, binary, write_comments, write_whitespace) + write_materials_8201(file, JMS, binary, write_comments, write_whitespace) + write_markers_8201(file, JMS, binary, write_comments, write_whitespace) + if write_comments: + file.write('\n;') + file.write('\n;###Instances###') + write_instance_xref_paths_8201(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8203(file, JMS, binary, write_comments, write_whitespace) + if write_comments: + file.write('\n;') + file.write('\n;###Skin data###') + write_regions_8201(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8204(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8201(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8205: + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8205(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8206: + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8205(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + write_spheres_8206(file, JMS, binary, write_comments, write_whitespace) + write_boxes_8206(file, JMS, binary, write_comments, write_whitespace) + write_capsules_8206(file, JMS, binary, write_comments, write_whitespace) + write_convex_shapes_8206(file, JMS, binary, write_comments, write_whitespace) + write_ragdolls_8206(file, JMS, binary, write_comments, write_whitespace) + write_hinges(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8207: + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8205(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + write_spheres_8207(file, JMS, binary, write_comments, write_whitespace) + write_boxes_8207(file, JMS, binary, write_comments, write_whitespace) + write_capsules_8207(file, JMS, binary, write_comments, write_whitespace) + write_convex_shapes_8207(file, JMS, binary, write_comments, write_whitespace) + write_ragdolls_8206(file, JMS, binary, write_comments, write_whitespace) + write_hinges(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8208: + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8208(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8205(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + write_spheres_8207(file, JMS, binary, write_comments, write_whitespace) + write_boxes_8207(file, JMS, binary, write_comments, write_whitespace) + write_capsules_8207(file, JMS, binary, write_comments, write_whitespace) + write_convex_shapes_8207(file, JMS, binary, write_comments, write_whitespace) + write_ragdolls_8206(file, JMS, binary, write_comments, write_whitespace) + write_hinges(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8209: + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8208(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8205(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + write_spheres_8207(file, JMS, binary, write_comments, write_whitespace) + write_boxes_8207(file, JMS, binary, write_comments, write_whitespace) + write_capsules_8207(file, JMS, binary, write_comments, write_whitespace) + write_convex_shapes_8207(file, JMS, binary, write_comments, write_whitespace) + write_ragdolls_8206(file, JMS, binary, write_comments, write_whitespace) + write_hinges(file, JMS, binary, write_comments, write_whitespace) + write_bounding_spheres(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8210: + update_decimal() + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8208(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8205(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + write_spheres_8207(file, JMS, binary, write_comments, write_whitespace) + write_boxes_8207(file, JMS, binary, write_comments, write_whitespace) + write_capsules_8207(file, JMS, binary, write_comments, write_whitespace) + write_convex_shapes_8207(file, JMS, binary, write_comments, write_whitespace) + write_ragdolls_8206(file, JMS, binary, write_comments, write_whitespace) + write_hinges(file, JMS, binary, write_comments, write_whitespace) + write_car_wheels(file, JMS, binary, write_comments, write_whitespace) + write_point_to_points(file, JMS, binary, write_comments, write_whitespace) + write_prismatics(file, JMS, binary, write_comments, write_whitespace) + write_bounding_spheres(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8211: + update_decimal() + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8208(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8211(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + write_spheres_8207(file, JMS, binary, write_comments, write_whitespace) + write_boxes_8207(file, JMS, binary, write_comments, write_whitespace) + write_capsules_8207(file, JMS, binary, write_comments, write_whitespace) + write_convex_shapes_8207(file, JMS, binary, write_comments, write_whitespace) + write_ragdolls_8206(file, JMS, binary, write_comments, write_whitespace) + write_hinges(file, JMS, binary, write_comments, write_whitespace) + write_car_wheels(file, JMS, binary, write_comments, write_whitespace) + write_point_to_points(file, JMS, binary, write_comments, write_whitespace) + write_prismatics(file, JMS, binary, write_comments, write_whitespace) + write_bounding_spheres(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8212: + update_decimal() + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8208(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8211(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + write_spheres_8207(file, JMS, binary, write_comments, write_whitespace) + write_boxes_8207(file, JMS, binary, write_comments, write_whitespace) + write_capsules_8207(file, JMS, binary, write_comments, write_whitespace) + write_convex_shapes_8207(file, JMS, binary, write_comments, write_whitespace) + write_ragdolls_8206(file, JMS, binary, write_comments, write_whitespace) + write_hinges(file, JMS, binary, write_comments, write_whitespace) + write_car_wheels(file, JMS, binary, write_comments, write_whitespace) + write_point_to_points(file, JMS, binary, write_comments, write_whitespace) + write_prismatics(file, JMS, binary, write_comments, write_whitespace) + write_bounding_spheres(file, JMS, binary, write_comments, write_whitespace) + write_skylights(file, JMS, binary, write_comments, write_whitespace) + elif jms_version == 8213: + update_decimal() + write_comments = True + write_whitespace = True + write_version(file, jms_version, version_bounds, binary, write_comments, write_whitespace) + write_nodes_8205(file, JMS, binary, write_comments, write_whitespace) + write_materials_8205(file, JMS, binary, write_comments, write_whitespace) + write_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_instance_xref_paths_8208(file, JMS, binary, write_comments, write_whitespace) + write_instance_markers_8205(file, JMS, binary, write_comments, write_whitespace) + write_vertices_8211(file, JMS, binary, write_comments, write_whitespace) + write_triangles_8205(file, JMS, binary, write_comments, write_whitespace) + write_spheres_8207(file, JMS, binary, write_comments, write_whitespace) + write_boxes_8207(file, JMS, binary, write_comments, write_whitespace) + write_capsules_8207(file, JMS, binary, write_comments, write_whitespace) + write_convex_shapes_8207(file, JMS, binary, write_comments, write_whitespace) + write_ragdolls_8213(file, JMS, binary, write_comments, write_whitespace) + write_hinges(file, JMS, binary, write_comments, write_whitespace) + write_car_wheels(file, JMS, binary, write_comments, write_whitespace) + write_point_to_points(file, JMS, binary, write_comments, write_whitespace) + write_prismatics(file, JMS, binary, write_comments, write_whitespace) + write_bounding_spheres(file, JMS, binary, write_comments, write_whitespace) + write_skylights(file, JMS, binary, write_comments, write_whitespace) + if not binary: + file.write('\n') report({'INFO'}, "Export completed successfully") file.close() diff --git a/io_scene_halo/file_qua/__init__.py b/io_scene_halo/file_qua/__init__.py index 0d62bd6df..4db166899 100644 --- a/io_scene_halo/file_qua/__init__.py +++ b/io_scene_halo/file_qua/__init__.py @@ -26,13 +26,20 @@ import bpy -from bpy.types import Operator -from bpy_extras.io_utils import ExportHelper from ..global_functions import global_functions from bpy.props import ( EnumProperty, - StringProperty + StringProperty, + BoolProperty ) +from bpy.types import ( + Operator, + FileHandler + ) +from bpy_extras.io_utils import ( + ImportHelper, + ExportHelper + ) class ExportQUA(Operator, ExportHelper): """Write a QUA file""" @@ -40,6 +47,15 @@ class ExportQUA(Operator, ExportHelper): bl_label = 'Export QUA' filename_ext = '.QUA' + game_title: EnumProperty( + name="Game Title:", + description="What game will the Ubercam file be used for", + items=[ ('halo3', "Halo 3", "Export a QUA intended for Halo 3"), + ('halor', "Halo Reach", "Export a QUA intended for Halo Reach"), + ('halo4', "Halo 4", "Export a QUA intended for Halo 4"), + ] + ) + qua_version: EnumProperty( name="Version:", description="What version to use for the Ubercam file", @@ -48,10 +64,16 @@ class ExportQUA(Operator, ExportHelper): ('2', "2", "Non-functional"), ('3', "3", "Non-functional"), ('4', "4", "Non-functional"), - ('5', "5", "Non-functional"), + ('5', "5", "Retail"), ] ) + strip_identifier: BoolProperty( + name ="Strip Identifier", + description = "Strip identifier from filename of animation paths", + default = True, + ) + filter_glob: StringProperty( default="*.qua", options={'HIDDEN'}, @@ -60,18 +82,103 @@ class ExportQUA(Operator, ExportHelper): def execute(self, context): from ..file_qua import export_qua - return global_functions.run_code("export_qua.write_file(context, self.filepath, self.report, self.qua_version)") + return global_functions.run_code("export_qua.write_file(context, self.filepath, self.game_title, int(self.qua_version), self.strip_identifier, self.report)") + + def draw(self, context): + scene = context.scene + scene_halo = scene.halo + + layout = self.layout + + box = layout.box() + box.label(text="Game Title:") + col = box.column(align=True) + row = col.row() + row.prop(self, "game_title", text='') + box = layout.box() + box.label(text="File Details:") + col = box.column(align=True) + if scene_halo.expert_mode: + row = col.row() + row.label(text='QUA Version:') + row.prop(self, "qua_version", text='') + + row = col.row() + row.label(text='Strip Identifier:') + row.prop(self, "strip_identifier", text='') + +class ImportQUA(Operator, ImportHelper): + """Import a QUA file""" + bl_idname = "import_scene.qua" + bl_label = "Import QUA" + filename_ext = '.QUA' + + game_title: EnumProperty( + name="Game Title:", + description="What game was the cinematic file made for", + default="auto", + items=[ ('auto', "Auto", "Attempt to guess the game this animation was intended for. Will default to Halo CE if this fails."), + ('halo1', "Halo 1", "Import an animation intended for Halo 1"), + ('halo2', "Halo 2", "Import an animation intended for Halo 2"), + ('halo3', "Halo 3", "Import an animation intended for Halo 3"), + ] + ) + + filter_glob: StringProperty( + default="*.qua", + options={'HIDDEN'}, + ) + + filepath: StringProperty( + subtype='FILE_PATH', + options={'SKIP_SAVE'} + ) + + def execute(self, context): + from ..file_qua import import_qua + + return global_functions.run_code("import_qua.load_file(context, self.filepath, self.report)") + + def invoke(self, context, event): + if self.filepath: + return self.execute(context) + context.window_manager.fileselect_add(self) + return {'RUNNING_MODAL'} + +class ImportQUA_FileHandler(FileHandler): + bl_idname = "QUA_FH_import" + bl_label = "File handler for QUA import" + bl_import_operator = "import_scene.qua" + bl_file_extensions = ".QUA" + + @classmethod + def poll_drop(cls, context): + return (context.area and context.area.type == 'VIEW_3D') def menu_func_export(self, context): self.layout.operator(ExportQUA.bl_idname, text='Halo Ubercam Animation (.qua)') +def menu_func_import(self, context): + self.layout.operator(ImportQUA.bl_idname, text="Halo Ubercam Animation (.qua)") + +classeshalo = ( + ImportQUA, + ImportQUA_FileHandler, + ExportQUA +) + def register(): - bpy.utils.register_class(ExportQUA) + for clshalo in classeshalo: + bpy.utils.register_class(clshalo) + bpy.types.TOPBAR_MT_file_export.append(menu_func_export) + bpy.types.TOPBAR_MT_file_import.append(menu_func_import) def unregister(): bpy.types.TOPBAR_MT_file_export.remove(menu_func_export) - bpy.utils.unregister_class(ExportQUA) + bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) + for clshalo in classeshalo: + bpy.utils.unregister_class(clshalo) if __name__ == '__main__': register() diff --git a/io_scene_halo/file_qua/build_asset.py b/io_scene_halo/file_qua/build_asset.py new file mode 100644 index 000000000..86e79b688 --- /dev/null +++ b/io_scene_halo/file_qua/build_asset.py @@ -0,0 +1,216 @@ +# ##### 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 .process_scene import process_scene + +def build_asset(context, filepath, game_title, qua_version, strip_identifier, report): + decimal_1 = '\n%s' + decimal_2 = '\n%s %s' + decimal_3 = '\n%s %s %s' + decimal_4 = '\n%s %s %s %s' + + QUA = process_scene(context, game_title, qua_version, strip_identifier, report) + + file = open(filepath, 'w', encoding="utf-8") + + file.write( + ';### VERSION ###' + + '\n%s\n' % (QUA.version) + ) + + file.write( + '\n;### SCENE ###' + + '\n; ' + + '\n%s\n' % (QUA.name) + ) + + file.write( + '\n;### SHOTS ###' + + '\n%s\n' % (len(QUA.shots)) + ) + + file.write( + '\n;### UNITS ###' + + '\n%s' % (len(QUA.units)) + + '\n; ' + + '\n; ' + + '\n; \n' + ) + + for idx, unit in enumerate(QUA.units): + file.write( + '\n; UNIT %s' % (idx) + + '\n%s' % (unit.name) + + '\n%s' % (unit.path) + ) + bit_string = "" + for bit in unit.bits: + bit_string += "%s " % int(bit) + + file.write('\n%s' % (bit_string)) + file.write('\n') + + file.write( + '\n;### SCENERY ###' + + '\n%s' % (len(QUA.scenery)) + + '\n; ' + + '\n; ' + + '\n; \n' + ) + + for idx, scenery in enumerate(QUA.scenery): + file.write( + '\n; SCENERY %s' % (idx) + + '\n%s' % (scenery.name) + + '\n%s' % (scenery.path) + ) + bit_string = "" + for bit in scenery.bits: + bit_string += "%s " % int(bit) + + file.write('\n%s' % (bit_string)) + file.write('\n') + + file.write( + '\n;### EFFECTS_SCENERY ###' + + '\n%s' % (len(QUA.effects_scenery)) + + '\n; ' + + '\n; ' + + '\n; \n' + ) + + for idx, effect_scenery in enumerate(QUA.effects_scenery): + file.write( + '\n; EFFECTS_SCENERY %s' % (idx) + + '\n%s' % (effect_scenery.name) + + '\n%s' % (effect_scenery.path) + ) + bit_string = "" + for bit in effect_scenery.bits: + bit_string += "%s " % int(bit) + + file.write('\n%s' % (bit_string)) + file.write('\n') + + for idx, shot in enumerate(QUA.shots): + file.write( + '\n; ### SHOT %s ###' % (idx + 1) + + '\n; ' + + '\n; ' + + '\n; ' + + '\n; ' + + '\n; ' + + '\n; ' + + '\n; ' + + '\n; ' + + '\n; ' + + '\n; ' + + '\n; ' + + '\n%s' % (len(shot.frames)) + ) + + for idx, frame in enumerate(shot.frames): + file.write( + '\n; FRAME %s' % (idx + 1) + + decimal_3 % (frame.position) + + decimal_3 % (frame.up) + + decimal_3 % (frame.forward) + + decimal_1 % (frame.fov) + + decimal_1 % (frame.aperture) + + decimal_1 % (frame.focal_length) + + '\n%s' % (frame.depth_of_field) + + decimal_1 % (frame.near_focal) + + decimal_1 % (frame.far_focal) + + decimal_1 % (frame.focal_depth) + + decimal_1 % (frame.blur_amount) + + '\n' + ) + + file.write( + '\n;*** SHOT %s AUDIO DATA ***' % idx + + '\n%s' % (len(shot.audio_data)) + + '\n;