From bc98c26793f11b6470116cd54be33d7c01072207 Mon Sep 17 00:00:00 2001 From: Colin Basnett Date: Fri, 25 Aug 2023 16:57:26 -0700 Subject: [PATCH] Initial commit for UE1 exec command export --- io_scene_psk_psa/psa/builder.py | 1 + io_scene_psk_psa/psa/export/operators.py | 12 ++++++++++-- io_scene_psk_psa/psa/export/properties.py | 6 ++++++ io_scene_psk_psa/psa/writer.py | 13 +++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/io_scene_psk_psa/psa/builder.py b/io_scene_psk_psa/psa/builder.py index c8b831e..b8fc65e 100644 --- a/io_scene_psk_psa/psa/builder.py +++ b/io_scene_psk_psa/psa/builder.py @@ -31,6 +31,7 @@ class PsaBuildOptions: self.sequence_name_prefix: str = '' self.sequence_name_suffix: str = '' self.root_motion: bool = False + self.unreal_engine_1_mode: bool = False def _get_pose_bone_location_and_rotation(pose_bone: PoseBone, armature_object: Object, options: PsaBuildOptions): diff --git a/io_scene_psk_psa/psa/export/operators.py b/io_scene_psk_psa/psa/export/operators.py index 2176834..8d54bcf 100644 --- a/io_scene_psk_psa/psa/export/operators.py +++ b/io_scene_psk_psa/psa/export/operators.py @@ -1,3 +1,4 @@ +import os.path import re from collections import Counter from typing import List, Iterable, Dict, Tuple @@ -10,7 +11,7 @@ from bpy_types import Operator from .properties import PSA_PG_export, PSA_PG_export_action_list_item, filter_sequences from ..builder import build_psa, PsaBuildSequence, PsaBuildOptions -from ..writer import write_psa +from ..writer import write_psa, write_psa_import_commands from ...helpers import populate_bone_group_list, get_nla_strips_in_frame_range @@ -313,8 +314,9 @@ class PSA_OT_export(Operator, ExportHelper): layout.separator() - # ROOT MOTION layout.prop(pg, 'root_motion', text='Root Motion') + layout.prop(pg, 'should_write_import_commands', text='Write Import Commands') + @classmethod def _check_context(cls, context): @@ -423,6 +425,12 @@ class PSA_OT_export(Operator, ExportHelper): write_psa(psa, self.filepath) + if pg.should_write_import_commands: + # Replace the extension in the file path to be ".uc" instead of ".psa". + # This is because the Unreal Engine 1 import command expects the file to have a ".uc" extension. + filepath = os.path.splitext(self.filepath)[0] + '.uc' + write_psa_import_commands(psa, filepath) + return {'FINISHED'} diff --git a/io_scene_psk_psa/psa/export/properties.py b/io_scene_psk_psa/psa/export/properties.py index 5a87548..34800af 100644 --- a/io_scene_psk_psa/psa/export/properties.py +++ b/io_scene_psk_psa/psa/export/properties.py @@ -184,6 +184,12 @@ class PSA_PG_export(PropertyGroup): name='Show Reversed', description='Show reversed sequences' ) + should_write_import_commands: BoolProperty( + default=True, + options=empty_set, + name='Write PSA Import Commands', + description='Write PSA import commands to a UnrealScript file in the same directory as the exported file' + ) def filter_sequences(pg: PSA_PG_export, sequences) -> List[int]: diff --git a/io_scene_psk_psa/psa/writer.py b/io_scene_psk_psa/psa/writer.py index 64fea60..713ce8a 100644 --- a/io_scene_psk_psa/psa/writer.py +++ b/io_scene_psk_psa/psa/writer.py @@ -1,3 +1,4 @@ +import os.path from ctypes import Structure, sizeof from typing import Type @@ -23,3 +24,15 @@ def write_psa(psa: Psa, path: str): write_section(fp, b'BONENAMES', Psa.Bone, psa.bones) write_section(fp, b'ANIMINFO', Psa.Sequence, list(psa.sequences.values())) write_section(fp, b'ANIMKEYS', Psa.Key, psa.keys) + + +def write_psa_import_commands(psa: Psa, path: str): + anim = os.path.splitext(os.path.basename(path))[0] + with open(path, 'w') as fp: + for sequence_name, sequence in psa.sequences.items(): + fp.write(f'#EXEC ANIM SEQUENCE ' + f'ANIM={anim} ' + f'SEQ={sequence_name} ' + f'STARTFRAME={sequence.frame_start_index} ' + f'NUMFRAMES={sequence.frame_count} ' + f'RATE={sequence.fps}\n')