Skip to content

Commit

Permalink
Clean up JMS builder and QUA support
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Garcia committed Jun 4, 2024
1 parent 3973ae6 commit 12d26cb
Show file tree
Hide file tree
Showing 12 changed files with 3,481 additions and 1,754 deletions.
3,694 changes: 2,376 additions & 1,318 deletions io_scene_halo/file_jms/build_asset.py

Large diffs are not rendered by default.

121 changes: 114 additions & 7 deletions io_scene_halo/file_qua/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,36 @@

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"""
bl_idname = 'export_scene.qua'
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",
Expand All @@ -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'},
Expand All @@ -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()
216 changes: 216 additions & 0 deletions io_scene_halo/file_qua/build_asset.py
Original file line number Diff line number Diff line change
@@ -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; <scene name (string)>' +
'\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; <export name (string)>' +
'\n; <export path (string)>' +
'\n; <shots visible (bit mask - sorta)>\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; <export name (string)>' +
'\n; <export path (string)>' +
'\n; <shots visible (bit mask - sorta)>\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; <export name (string)>' +
'\n; <export path (string)>' +
'\n; <shots visible (bit mask - sorta)>\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; <Ubercam position (vector)>' +
'\n; <Ubercam up (vector)>' +
'\n; <Ubercam forward (vector)>' +
'\n; <Horizontal field of view (float)>' +
'\n; <Horizontal film aperture (float, millimeters)>' +
'\n; <Focal Length (float)>' +
'\n; <Depth of Field (bool)>' +
'\n; <Near Focal Plane Distance (float)>' +
'\n; <Far Focal Plane Distance (float)>' +
'\n; <Focal Depth (float)>' +
'\n; <Blur Amount (float)>' +
'\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; <Audio filename (string)>' +
'\n; <Frame number (int)>' +
'\n; <Character (string)>\n'
)

for idx, audio in enumerate(shot.audio_data):
file.write(
'\n; AUDIO %s' % (idx) +
'\n%s' % (audio.filepath) +
'\n%s' % (audio.frame) +
'\n%s\n' % (audio.name)
)

file.write(
'\n;### EXTRA CAMERAS ###' +
'\n%s' % (len(QUA.extra_cameras)) +
'\n; <Camera name (string)>' +
'\n; <Camera type (string)>\n'
)

for idx, extra_camera in enumerate(QUA.extra_cameras):
file.write(
'\n;### CAMERA %s ###' % (idx) +
'\n%s' % (extra_camera.name) +
'\n%s\n' % (extra_camera.camera_type)
)

for idx, extra_shot in enumerate(extra_camera.extra_shots):
file.write(
'\n; ### SHOT %s ###' % (idx + 1) +
'\n; <Camera enabled (bool)>' +
'\n; <Camera position (vector)>' +
'\n; <Camera up (vector)>' +
'\n; <Camera forward (vector)>' +
'\n; <Horizontal field of view (float)>' +
'\n; <Focal Length (float)>' +
'\n; <Depth of Field (bool)>' +
'\n; <Near Focal Plane Distance (float)>' +
'\n; <Far Focal Plane Distance (float)>' +
'\n; <Focal Depth (float)>' +
'\n; <Blur Amount (float)>'
)

for idx, frame in enumerate(extra_shot.frames):
file.write(
'\n; FRAME %s' % (idx + 1) +
'\n%s' % (int(frame.camera_is_enabled)) +
decimal_3 % (frame.position) +
decimal_3 % (frame.up) +
decimal_3 % (frame.forward) +
decimal_1 % (frame.fov) +
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'
)

report({'INFO'}, "Export completed successfully")
file.close()
Loading

0 comments on commit 12d26cb

Please sign in to comment.