Files
io_scene_psk_psa/io_scene_psk_psa/psa/writer.py
Colin Basnett 00d9e3996c Fixed an issue where ACTIVE_ACTION sequence source was not working
Also added a scene-level transform source.
2025-05-18 00:46:50 -07:00

26 lines
864 B
Python

from ctypes import Structure, sizeof
from typing import Optional, Type, Collection
from .data import Psa
from ..shared.data import PsxBone, Section
def write_section(fp, name: bytes, data_type: Optional[Type[Structure]] = None, data: Optional[Collection] = None):
section = Section()
section.name = name
if data_type is not None and data is not None:
section.data_size = sizeof(data_type)
section.data_count = len(data)
fp.write(section)
if data is not None:
for datum in data:
fp.write(datum)
def write_psa(psa: Psa, path: str):
with open(path, 'wb') as fp:
write_section(fp, b'ANIMHEAD')
write_section(fp, b'BONENAMES', PsxBone, psa.bones)
write_section(fp, b'ANIMINFO', Psa.Sequence, list(psa.sequences.values()))
write_section(fp, b'ANIMKEYS', Psa.Key, psa.keys)