31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
"""Convert local Half-Life space sky faces to a Godot panorama (Pillow + ffmpeg)."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
import tempfile
|
|
from PIL import Image
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('source', type=pathlib.Path, help='Half-Life valve/gfx/env directory')
|
|
args = parser.parse_args()
|
|
out = pathlib.Path(__file__).resolve().parents[1] / 'assets/textures/sky'
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
faces = ['rt', 'lf', 'up', 'dn', 'ft', 'bk']
|
|
images = [Image.open(args.source / f'space{s}.tga').convert('RGB') for s in faces]
|
|
w, h = images[0].size
|
|
assert w == h and all(im.size == (w, h) for im in images)
|
|
strip = Image.new('RGB', (6*w, h))
|
|
for i, im in enumerate(images):
|
|
strip.paste(im, (i*w, 0))
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
src = pathlib.Path(tmp) / 'cube.png'
|
|
strip.save(src)
|
|
subprocess.run(['ffmpeg', '-y', '-loglevel', 'error', '-i', str(src),
|
|
'-vf', 'v360=input=c6x1:output=e:in_forder=rludfb:w=2048:h=1024',
|
|
'-frames:v', '1', str(out / 'space_panorama.png')], check=True)
|
|
manifest = {f'space{s}.tga': hashlib.sha256((args.source / f'space{s}.tga').read_bytes()).hexdigest() for s in faces}
|
|
(out / 'source_manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
|
print(out / 'space_panorama.png')
|