Align original Half-Life office walls and ceiling with explicit room UVs
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""Extract original Half-Life office wall/ceiling textures without touching Steam files."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import pathlib
|
||||
import struct
|
||||
from PIL import Image
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('wad', type=pathlib.Path, help='Original valve/halflife.wad')
|
||||
args = parser.parse_args()
|
||||
project = pathlib.Path(__file__).resolve().parents[1]
|
||||
out = project / 'assets/textures/office'
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
wad = args.wad.read_bytes()
|
||||
assert wad[:4] == b'WAD3'
|
||||
count, directory = struct.unpack_from('<ii', wad, 4)
|
||||
wanted = {'FIFTIES_WALL14U': 'wall.png', 'FIFTIES_CEIL5': 'ceiling.png'}
|
||||
manifest = {'wad_sha256': hashlib.sha256(wad).hexdigest(), 'textures': {}}
|
||||
for i in range(count):
|
||||
offset, size, _, typ, compression, _, _, raw = struct.unpack_from('<iiiBBBB16s', wad, directory + 32*i)
|
||||
name = raw.split(b'\0')[0].decode().upper()
|
||||
if name not in wanted:
|
||||
continue
|
||||
assert not compression and typ == 0x43, name
|
||||
_, w, h, pixels, _, _, last = struct.unpack_from('<16s6I', wad, offset)
|
||||
palette = offset + last + (w//8)*(h//8)
|
||||
assert struct.unpack_from('<H', wad, palette)[0] == 256
|
||||
im = Image.frombytes('P', (w, h), wad[offset+pixels:offset+pixels+w*h])
|
||||
im.putpalette(wad[palette+2:palette+2+768])
|
||||
im.convert('RGB').save(out / wanted[name])
|
||||
manifest['textures'][name] = {'file': wanted[name], 'size': [w, h],
|
||||
'lump_sha256': hashlib.sha256(wad[offset:offset+size]).hexdigest()}
|
||||
assert set(manifest['textures']) == set(wanted)
|
||||
(out / 'source_manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
||||
print(out)
|
||||
Reference in New Issue
Block a user