diff --git a/blender_bindings/models/__init__.py b/blender_bindings/models/__init__.py index ffca3712..ab98f100 100644 --- a/blender_bindings/models/__init__.py +++ b/blender_bindings/models/__init__.py @@ -4,7 +4,7 @@ from SourceIO.blender_bindings.models.model_tags import MODEL_HANDLERS, choose_model_importer from SourceIO.library.shared.content_providers.content_manager import ContentManager from SourceIO.library.utils import Buffer -from . import mdl4, mdl6, mdl10, mdl36, mdl44, mdl49,md3_15 +from . import mdl4, mdl6, mdl10, mdl36, mdl44, mdl49, md3_15 from ..operators.import_settings_base import ModelOptions from ..shared.model_container import ModelContainer from ...library.shared.app_id import SteamAppId @@ -19,13 +19,12 @@ def import_model(model_path: Path, buffer: Buffer, options: ModelOptions, override_steam_id: Optional[SteamAppId] = None) -> Optional[ModelContainer]: ident, version = buffer.read_fmt("4sI") - print(ident, version) + logger.info(f"Detected magic: {ident!r}, version:{version}") cp = content_manager.get_content_provider_from_asset_path(model_path) handler = choose_model_importer(ident, version, (override_steam_id or ((cp.steam_id or None) if cp else None))) if handler is None: logger.error(f"No handler found for ident {ident} version: {version}") return None - print(handler) buffer.seek(0) container = handler(model_path, buffer, content_manager, options) return container diff --git a/library/models/mdl/v6/mdl_file.py b/library/models/mdl/v6/mdl_file.py index 0e9b953e..c9d7382f 100644 --- a/library/models/mdl/v6/mdl_file.py +++ b/library/models/mdl/v6/mdl_file.py @@ -35,8 +35,9 @@ def from_buffer(cls, buffer: Buffer): for sequence in sequences: sequence_animations = [] sequence: StudioSequence - for _ in range(header.bone_count): - sequence_animations.append(StudioAnimation.from_buffer(buffer, sequence.frame_count)) + with buffer.read_from_offset(sequence.anim_offset): + for _ in range(header.bone_count): + sequence_animations.append(StudioAnimation.from_buffer(buffer, sequence.frame_count)) animations.append(sequence_animations) # sequence = self.sequences[0] # for n, bone in enumerate(self.bones): diff --git a/library/models/mdl/v6/structs/animation.py b/library/models/mdl/v6/structs/animation.py index 25094102..836b22d5 100644 --- a/library/models/mdl/v6/structs/animation.py +++ b/library/models/mdl/v6/structs/animation.py @@ -23,12 +23,13 @@ class StudioAnimation: @classmethod def from_buffer(cls, buffer: Buffer, frame_count: int): pos_count, pos_offset, rot_count, rot_offset = buffer.read_fmt('4I') - buffer.seek(pos_offset) - raw_pos_data = np.frombuffer(buffer.read(pos_count * raw_pos_dtype.itemsize), raw_pos_dtype) - - buffer.seek(rot_offset) - raw_rot_data = np.frombuffer(buffer.read(rot_count * raw_rot_dtype.itemsize), raw_rot_dtype) + with buffer.save_current_offset(): + buffer.seek(pos_offset) + raw_pos_data = np.frombuffer(buffer.read(pos_count * raw_pos_dtype.itemsize), raw_pos_dtype) + buffer.seek(rot_offset) + raw_rot_data = np.frombuffer(buffer.read(rot_count * raw_rot_dtype.itemsize), raw_rot_dtype) + # buffer.skip(2) frames = np.zeros((frame_count, 2, 3,), np.float32) total_count = frames.shape[0] diff --git a/library/models/mdl/v6/structs/sequence.py b/library/models/mdl/v6/structs/sequence.py index 1dd3a5dd..46af703f 100644 --- a/library/models/mdl/v6/structs/sequence.py +++ b/library/models/mdl/v6/structs/sequence.py @@ -34,7 +34,7 @@ def from_buffer(cls, buffer: Buffer): pivot_count, pivot_offset, motion_type, motion_bone, unused_2, - ) = buffer.read_fmt('