56 lines
2.8 KiB
Python
56 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Prepare local scene/audio assets without modifying the original installation."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from omt import Database, export_scene, extract
|
|
from ase import export_ase
|
|
from png import read_png
|
|
|
|
|
|
def find_archive(original: Path, name: str) -> Path:
|
|
matches = [p for p in (original / 'omt').iterdir()
|
|
if p.name.casefold() == (name if name.casefold().endswith('.omt') else name + '.omt').casefold()]
|
|
if len(matches) != 1:
|
|
raise ValueError(f'Expected exactly one archive for {name}, found {len(matches)}')
|
|
return matches[0]
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--original', type=Path, default=Path('../Original'))
|
|
parser.add_argument('--output', type=Path, default=Path('artifacts/extracted'))
|
|
parser.add_argument('--scenes', nargs='+', default=['level1b', 'VR01'])
|
|
parser.add_argument('--audio', nargs='*', default=['sounds', 'musicjimmyshouse', 'musicneighborhood'])
|
|
parser.add_argument('--animations', nargs='*', default=['jimstop', 'jimrun', 'jimjump'])
|
|
args = parser.parse_args()
|
|
if args.output.resolve().is_relative_to(args.original.resolve()):
|
|
parser.error('Output must be outside the original installation')
|
|
for name in args.scenes:
|
|
source = find_archive(args.original, name)
|
|
scene = export_scene(Database(source), args.output / source.stem)
|
|
print(f"{source.name}: {len(scene['indices'])//3} triangles, {len(scene['textures'])} textures")
|
|
for name in args.audio:
|
|
source = find_archive(args.original, name)
|
|
report = extract(Database(source), args.output / source.stem)
|
|
count = sum(1 for e in report['entries'] if 'audio' in e)
|
|
print(f'{source.name}: {count} audio resources')
|
|
if args.animations:
|
|
texture_source = next(p for p in (args.original/'png').iterdir() if p.name.casefold()=='jimycarl.png')
|
|
texture = read_png(texture_source)
|
|
target = args.output/'animations'
|
|
target.mkdir(parents=True,exist_ok=True)
|
|
(target/'jimycarl.rgba').write_bytes(texture.pop('rgba'))
|
|
base = next(p for p in (args.original/'ASE').iterdir() if p.name.casefold()=='jimstop.ase')
|
|
for name in args.animations:
|
|
matches = [p for p in (args.original/'ASE').iterdir() if p.stem.casefold()==name.casefold() and p.suffix.casefold()=='.ase']
|
|
if len(matches)!=1: raise ValueError(f'Expected one ASE for {name}')
|
|
manifest = export_ase(matches[0],target/name,base)
|
|
manifest['texture'] = {'path':'../jimycarl.rgba', **texture}
|
|
(target/name/'animation.json').write_text(json.dumps(manifest,indent=2)+'\n',encoding='utf-8')
|
|
print(f"{matches[0].name}: {len(manifest['frames'])} animation samples")
|
|
|
|
|
|
if __name__ == '__main__': main()
|