feat: chainmail over the map on the Smith's Table
The smith goes back to the cartography table, like the cook. Its map is painted over with 4-in-1 mail by scripts/paint_smith_mail.py at 512 px: colour, rusted worn colour, a normal map from the rings' height and a metallic map so they shine. Both tables now share one Dress/LayCover path.
This commit is contained in:
parent
069e098cf0
commit
35476eb8ef
6 changed files with 160 additions and 58 deletions
118
scripts/paint_smith_mail.py
Normal file
118
scripts/paint_smith_mail.py
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
"""Paint a sheet of chainmail over the cartography table's map: colour, worn (rusted) colour,
|
||||
normal map and metallic map, at twice the vanilla resolution so the rings keep their shape.
|
||||
Usage: py -3.14 -I paint_mail.py <pylib> <carto dir> <out dir>"""
|
||||
import os, sys
|
||||
sys.path.insert(0, sys.argv[1])
|
||||
import numpy as np
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
src, out = sys.argv[2], sys.argv[3]
|
||||
os.makedirs(out, exist_ok=True)
|
||||
|
||||
SCALE = 2
|
||||
# The parchment's UV island (x 10-133, y 11-90 at 256 px) plus a margin, as in paint_cook_cloth.py.
|
||||
X0, Y0, X1, Y1 = 4 * SCALE, 4 * SCALE, 141 * SCALE, 95 * SCALE
|
||||
W, H = X1 - X0, Y1 - Y0
|
||||
|
||||
RING = 7.0 # ring radius to the middle of the wire, px at 512 (about 15 cm across in game)
|
||||
WIRE = 1.5 # half the wire's thickness
|
||||
SX, SY = RING * 2.3, RING * 1.3 # 4-in-1: each row offset by half, linking the rows above and below
|
||||
rng = np.random.default_rng(7)
|
||||
|
||||
# ---------------------------------------------------------------- the rings, as a height field
|
||||
ys, xs = np.mgrid[0:H, 0:W].astype(np.float32)
|
||||
height = np.zeros((H, W), np.float32)
|
||||
tone = np.ones((H, W), np.float32)
|
||||
rows = int(H / SY) + 3
|
||||
cols = int(W / SX) + 3
|
||||
for row in range(-1, rows):
|
||||
tilt = 0.45 if row % 2 else -0.45 # alternate rows lean opposite ways, like real mail
|
||||
lift = 0.25 if row % 2 else 0.0 # and one set lies over the other
|
||||
for col in range(-1, cols):
|
||||
cx = col * SX + (SX / 2 if row % 2 else 0)
|
||||
cy = row * SY
|
||||
x0, x1 = int(max(0, cx - RING - WIRE - 2)), int(min(W, cx + RING + WIRE + 3))
|
||||
y0, y1 = int(max(0, cy - RING - WIRE - 2)), int(min(H, cy + RING + WIRE + 3))
|
||||
if x0 >= x1 or y0 >= y1:
|
||||
continue
|
||||
dx = xs[y0:y1, x0:x1] - cx
|
||||
dy = ys[y0:y1, x0:x1] - cy
|
||||
# a tilted ring seen from above is an ellipse, squashed along its lean
|
||||
u = dx * np.cos(tilt) + dy * np.sin(tilt)
|
||||
v = (-dx * np.sin(tilt) + dy * np.cos(tilt)) / 0.78
|
||||
t = (np.sqrt(u * u + v * v) - RING) / WIRE
|
||||
h = np.where(np.abs(t) < 1, np.sqrt(np.clip(1 - t * t, 0, 1)) * 0.75 + lift, 0)
|
||||
win = h > height[y0:y1, x0:x1]
|
||||
height[y0:y1, x0:x1] = np.where(win, h, height[y0:y1, x0:x1])
|
||||
tone[y0:y1, x0:x1] = np.where(win, 0.92 + rng.random() * 0.16, tone[y0:y1, x0:x1])
|
||||
|
||||
ring = height > 0
|
||||
|
||||
# ---------------------------------------------------------------- lighting from the height field
|
||||
gx = np.zeros_like(height); gy = np.zeros_like(height)
|
||||
gx[:, 1:-1] = height[:, 2:] - height[:, :-2]
|
||||
gy[1:-1, :] = height[2:, :] - height[:-2, :]
|
||||
K = 1.6
|
||||
n = np.stack([-gx * K, gy * K, np.ones_like(height)], -1) # image y runs down, texture v up
|
||||
n /= np.linalg.norm(n, axis=-1, keepdims=True)
|
||||
light = np.array([-0.45, 0.55, 0.70]); light /= np.linalg.norm(light)
|
||||
diffuse = np.clip((n * light).sum(-1), 0, 1)
|
||||
half = light + np.array([0, 0, 1.0]); half /= np.linalg.norm(half)
|
||||
spec = np.clip((n * half).sum(-1), 0, 1) ** 24
|
||||
|
||||
|
||||
def broad_shade(img):
|
||||
"""The parchment's folds and rolled edges, without its ink: a heavy blur of its brightness."""
|
||||
lum = np.asarray(img.convert("L").filter(ImageFilter.GaussianBlur(5 * SCALE)), np.float32)[Y0:Y1, X0:X1]
|
||||
return np.clip(lum / lum.mean(), 0.7, 1.15)
|
||||
|
||||
|
||||
def upscale(name):
|
||||
img = Image.open(os.path.join(src, name + ".png")).convert("RGBA")
|
||||
return img.resize((img.width * SCALE, img.height * SCALE), Image.BICUBIC)
|
||||
|
||||
|
||||
def colour(name, rust):
|
||||
img = upscale(name)
|
||||
a = np.asarray(img, np.float32).copy()
|
||||
shade = broad_shade(img)
|
||||
steel = np.array([150, 156, 164], np.float32)
|
||||
# Through the holes, the table's own planks in the mail's shadow: tiled from the wood island.
|
||||
wood = a[130 * SCALE:240 * SCALE, 60 * SCALE:240 * SCALE, :3]
|
||||
reps = (H // wood.shape[0] + 1, W // wood.shape[1] + 1, 1)
|
||||
gap = np.tile(wood, reps)[:H, :W] * 0.5
|
||||
lit = steel * (0.30 + 0.75 * diffuse[..., None]) * tone[..., None] + 120 * spec[..., None]
|
||||
if rust:
|
||||
blotch = np.asarray(Image.fromarray((rng.random((H // 6 + 1, W // 6 + 1)) * 255).astype(np.uint8))
|
||||
.resize((W, H), Image.BICUBIC).filter(ImageFilter.GaussianBlur(3)), np.float32) / 255
|
||||
amount = np.clip((blotch - 0.35) * 2.2, 0, 0.85)[..., None]
|
||||
rusty = np.array([118, 62, 32], np.float32) * (0.45 + 0.6 * diffuse[..., None])
|
||||
lit = lit * (1 - amount) + rusty * amount
|
||||
lit *= 0.85
|
||||
rgb = np.where(ring[..., None], lit, gap) * shade[..., None]
|
||||
a[Y0:Y1, X0:X1, :3] = np.clip(rgb, 0, 255)
|
||||
return Image.fromarray(a.astype(np.uint8), "RGBA")
|
||||
|
||||
|
||||
def normal():
|
||||
a = np.asarray(upscale("Cartographer_n"), np.float32).copy()
|
||||
# DXT5nm, as Valheim packs it: X in alpha, Y in green (blue repeats it), red pinned to 255.
|
||||
a[Y0:Y1, X0:X1, 0] = 255
|
||||
a[Y0:Y1, X0:X1, 1] = (n[..., 1] * 0.5 + 0.5) * 255
|
||||
a[Y0:Y1, X0:X1, 2] = (n[..., 1] * 0.5 + 0.5) * 255
|
||||
a[Y0:Y1, X0:X1, 3] = (n[..., 0] * 0.5 + 0.5) * 255
|
||||
return Image.fromarray(np.clip(a, 0, 255).astype(np.uint8), "RGBA")
|
||||
|
||||
|
||||
def metallic():
|
||||
a = np.asarray(upscale("Cartographer_m"), np.float32).copy()
|
||||
a[Y0:Y1, X0:X1, 0] = np.where(ring, 210, 0) # red is metallic; the rest of the table stays 0
|
||||
return Image.fromarray(a.astype(np.uint8), "RGBA")
|
||||
|
||||
|
||||
colour("Cartographer_d", rust=False).save(os.path.join(out, "SmithMail_d.png"))
|
||||
colour("Cartographer_worn_d", rust=True).save(os.path.join(out, "SmithMail_worn_d.png"))
|
||||
normal().save(os.path.join(out, "SmithMail_n.png"))
|
||||
metallic().save(os.path.join(out, "SmithMail_m.png"))
|
||||
print("done")
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue