"""v3 env textures: raw_*.png -> Assets/Art/Textures (power-of-two), seamless ones made tileable. Also builds procedural T_CuttingMat and T_PalletWood (desaturated T_Wood).""" import os, sys import numpy as np from PIL import Image, ImageDraw, ImageEnhance sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from finalize import seamless, DST, HERE SEAMLESS = {"T_Asphalt": (True, True), "T_Grass": (True, True), "T_Corrugated": (False, True)} WIDE = ["T_Billboard_1", "T_Billboard_2", "T_Billboard_3"] TALL = ["T_Banner_1", "T_Banner_2", "T_Banner_3"] def fit(im, w, h): """centre-crop to aspect w:h then resize.""" W, H = im.size if W / H > w / h: nw = int(H * w / h); x0 = (W - nw) // 2; im = im.crop((x0, 0, x0 + nw, H)) else: nh = int(W * h / w); y0 = (H - nh) // 2; im = im.crop((0, y0, W, y0 + nh)) return im.resize((w, h), Image.LANCZOS) def pad(im, l, t, r, b, col): W, H = im.size out = Image.new("RGB", (W + l + r, H + t + b), col) out.paste(im, (l, t)) return out def crop_f(im, x0, y0, x1, y1): W, H = im.size return im.crop((int(x0 * W), int(y0 * H), int(x1 * W), int(y1 * H))) def corner(im, fx=0.5, fy=0.5): W, H = im.size return im.getpixel((int(fx * (W - 1)), int(fy * (H - 1)))) def ad_billboard(n, im): """raw 3:2 -> 2:1 without cutting the big text: per-image crop / pad (+ mild squash).""" if n == "T_Billboard_1": im = crop_f(im, 0, 0, 1, 0.88) # lose some bubbles at the bottom, squash the rest elif n == "T_Billboard_2": c = corner(im, 0.02, 0.5) W, H = im.size im = pad(im, (2 * H - W) // 2, 0, (2 * H - W) // 2, 0, c) # plain yellow sides elif n == "T_Billboard_3": im = crop_f(im, 0, 0.03, 1, 0.97) W, H = im.size c = corner(im, 0.5, 0.02) im = pad(im, (2 * H - W) // 2, 0, (2 * H - W) // 2, 0, c) return im.resize((1024, 512), Image.LANCZOS) def ad_banner(n, im): """raw 2:3 -> 1:2: grow height with the background colour, squash width a little.""" W, H = im.size if n == "T_Banner_1": im = crop_f(im, 0.035, 0.025, 0.965, 0.975) # drop the old thin border W, H = im.size c = corner(im, 0.5, 0.01) im = pad(im, 0, 140, 0, 140, c) W, H = im.size d = ImageDraw.Draw(im) bw = int(W * 0.022) d.rounded_rectangle((bw, bw, W - bw - 1, H - bw - 1), radius=bw * 2, outline=(255, 255, 255), width=bw) elif n == "T_Banner_2": c = corner(im, 0.03, 0.03) im = pad(im, 0, 200, 0, 60, c) elif n == "T_Banner_3": top = crop_f(im, 0, 0, 1, 0.085) mid = crop_f(im, 0, 0.085, 1, 0.915) bot = crop_f(im, 0, 0.915, 1, 1) a = np.array(mid)[3:-3] mid = Image.fromarray(np.pad(a, ((150, 150), (0, 0), (0, 0)), mode="edge")) out = Image.new("RGB", (W, top.size[1] + mid.size[1] + bot.size[1])) out.paste(top, (0, 0)); out.paste(mid, (0, top.size[1])); out.paste(bot, (0, top.size[1] + mid.size[1])) im = out return im.resize((512, 1024), Image.LANCZOS) def save(im, n): im.save(os.path.join(DST, n + ".png")); print("ok", n, im.size) def main(): for n, (dx, dy) in SEAMLESS.items(): p = os.path.join(HERE, f"raw_{n}.png") if os.path.exists(p): im = fit(Image.open(p).convert("RGB"), 1024, 1024) save(Image.fromarray(seamless(np.array(im), do_x=dx, do_y=dy)), n) for n in WIDE: p = os.path.join(HERE, f"raw_{n}.png") if os.path.exists(p): save(ad_billboard(n, Image.open(p).convert("RGB")), n) for n in TALL: p = os.path.join(HERE, f"raw_{n}.png") if os.path.exists(p): save(ad_banner(n, Image.open(p).convert("RGB")), n) # cutting mat: green with a fine grid, bolder every 4th line, ruler ticks on two edges S = 1024 im = Image.new("RGB", (S, S), (52, 150, 112)) d = ImageDraw.Draw(im) step = S // 32 for i in range(33): c, w = ((120, 205, 170), 2) if i % 4 else ((190, 240, 215), 4) d.line([(i * step, 0), (i * step, S)], fill=c, width=w) d.line([(0, i * step), (S, i * step)], fill=c, width=w) for k in range(0, S, step // 2): L = 22 if k % step == 0 else 12 d.line([(k, 0), (k, L)], fill=(240, 250, 245), width=2) d.line([(0, k), (L, k)], fill=(240, 250, 245), width=2) d.line([(0, S // 2), (S, 0)], fill=(150, 220, 190), width=3) save(im, "T_CuttingMat") # pallet wood: less saturated / slightly cooler version of T_Wood so pallets read as raw timber w = Image.open(os.path.join(DST, "T_Wood.png")).convert("RGB") w = ImageEnhance.Color(w).enhance(0.55) a = np.array(w).astype(np.float32) a = a * np.array([0.98, 0.95, 0.92]) + np.array([6, 6, 8]) save(Image.fromarray(np.clip(a, 0, 255).astype(np.uint8)), "T_PalletWood") if __name__ == "__main__": main()