BlueGit

timfa questward

Files

questward / client / scripts / export-thick-wall-refs.py

export-thick-wall-refs.py

wall texture
timfa Tim Falken · pushed by timfa · 2 months ago
0896e8da History
export-thick-wall-refs.py 4.1 KiB Download Raw
1#!/usr/bin/env python3
2"""Export face-id / heightmap / upscaled refs from thick-stone-wall alone.
3
4Run from repo root:
5 python3 client/scripts/export-thick-wall-refs.py
6
7Requires: Pillow
8"""
9from __future__ import annotations
10
11from pathlib import Path
12
13from PIL import Image, ImageDraw
14
15ROOT = Path(__file__).resolve().parents[1]
16ALONE = ROOT / "assets/blocks/_examples/stone-wall/thick-stone-wall.png"
17OUT = ROOT / "assets/blocks/_examples/stone-wall"
18
19# Source greys → semantic face roles (see docs/STONE_WALL_SHAPES.md)
20FACE_RGB = {
21 (175, 175, 175): (255, 255, 255), # N bevel
22 (149, 149, 149): (220, 60, 60), # W face
23 (108, 108, 108): (60, 100, 220), # E face
24 (84, 84, 84): (60, 180, 80), # S face
25 (128, 128, 128): (220, 180, 60), # top plateau
26 (64, 64, 64): (20, 20, 20), # outline
27}
28
29HEIGHT = {
30 (64, 64, 64): 40,
31 (84, 84, 84): 80,
32 (108, 108, 108): 140,
33 (149, 149, 149): 160,
34 (128, 128, 128): 200,
35 (175, 175, 175): 220,
36}
37
38
39def main() -> None:
40 OUT.mkdir(parents=True, exist_ok=True)
41 alone = Image.open(ALONE).convert("RGBA")
42 w, h = alone.size
43 face = Image.new("RGBA", (w, h), (0, 0, 0, 0))
44 height = Image.new("L", (w, h), 0)
45
46 for y in range(h):
47 for x in range(w):
48 r, g, b, a = alone.getpixel((x, y))
49 if a == 0:
50 continue
51 key = (r, g, b)
52 if key not in FACE_RGB:
53 raise SystemExit(f"Unknown grey {key} at ({x},{y})")
54 fr, fg, fb = FACE_RGB[key]
55 face.putpixel((x, y), (fr, fg, fb, 255))
56 height.putpixel((x, y), HEIGHT[key])
57
58 face.save(OUT / "ref-thick-face-id-16.png")
59 face.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-face-id-256.png")
60 height.save(OUT / "ref-thick-height-16.png")
61 height.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-height-256.png")
62 alone.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-alone-256.png")
63
64 leg = Image.new("RGBA", (280, 200), (30, 30, 30, 255))
65 d = ImageDraw.Draw(leg)
66 items = [
67 ((255, 255, 255), "North bevel 0xAF"),
68 ((220, 60, 60), "West face 0x95"),
69 ((60, 100, 220), "East face 0x6C"),
70 ((60, 180, 80), "South face 0x54"),
71 ((220, 180, 60), "Top plateau 0x80"),
72 ((20, 20, 20), "Outline 0x40"),
73 ]
74 for i, (c, label) in enumerate(items):
75 yy = 16 + i * 28
76 d.rectangle([16, yy, 40, yy + 20], fill=(*c, 255))
77 d.text((52, yy + 2), label, fill=(230, 230, 230, 255))
78 leg.save(OUT / "ref-thick-face-legend.png")
79
80 # Labeled contact sheet of all 16 thick *shape* states (bit order).
81 wall_dir = OUT
82 names = [
83 ("alone", "thick-stone-wall.png"),
84 ("n", "thick-stone-wall-n.png"),
85 ("e", "thick-stone-wall-e.png"),
86 ("ne", "thick-stone-wall-ne.png"),
87 ("s", "thick-stone-wall-s.png"),
88 ("ns", "thick-stone-wall-ns.png"),
89 ("es", "thick-stone-wall-es.png"),
90 ("nes", "thick-stone-wall-nes.png"),
91 ("w", "thick-stone-wall-w.png"),
92 ("wn", "thick-stone-wall-wn.png"),
93 ("we", "thick-stone-wall-we.png"),
94 ("wne", "thick-stone-wall-wne.png"),
95 ("sw", "thick-stone-wall-sw.png"),
96 ("swn", "thick-stone-wall-swn.png"),
97 ("esw", "thick-stone-wall-esw.png"),
98 ("nesw", "thick-stone-wall-nesw.png"),
99 ]
100 scale, pad, label_h, cols = 8, 28, 14, 4
101 cell = 16 * scale
102 rows = 4
103 sheet_w = cols * cell + (cols + 1) * pad
104 sheet_h = rows * (cell + label_h) + (rows + 1) * pad
105 sheet = Image.new("RGBA", (sheet_w, sheet_h), (24, 24, 28, 255))
106 draw = ImageDraw.Draw(sheet)
107 for i, (label, fname) in enumerate(names):
108 r, c = divmod(i, cols)
109 x = pad + c * (cell + pad)
110 y = pad + r * (cell + label_h + pad)
111 im = Image.open(wall_dir / fname).convert("RGBA").resize((cell, cell), Image.NEAREST)
112 sheet.paste(im, (x, y), im)
113 draw.text((x, y + cell + 2), label, fill=(220, 220, 220, 255))
114 sheet.save(OUT / "ref-thick-all-variants.png")
115
116 print(f"Wrote refs to {OUT}")
117
118
119if __name__ == "__main__":
120 main()