A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date. Images, audio, models and binaries go through Git LFS (.gitattributes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
256 lines
11 KiB
Python
256 lines
11 KiB
Python
"""Procedural farmstead textures for GRASS CUTTER: painted boards, nailed deck planks, timber, worn trim stripes, gingham
|
|
and bib-denim crew cloth, plus the wooden UI skins (9-sliced in GrassCutter.uss). Seamless where they tile.
|
|
Run: python ArtSource/Textures/proc_farm.py"""
|
|
import os
|
|
|
|
import numpy as np
|
|
from PIL import Image, ImageDraw, ImageFilter
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
TEX = os.path.join(HERE, "..", "..", "Assets", "Art", "Textures")
|
|
UI = os.path.join(HERE, "..", "..", "Assets", "Art", "UI")
|
|
rng = np.random.default_rng(11)
|
|
|
|
|
|
def fbm(n, cells, octaves=4, sx=1.0, sy=1.0):
|
|
"""Tiling value noise, 0..1. sx / sy stretch it (wood grain)."""
|
|
out = np.zeros((n, n), np.float32)
|
|
amp, tot = 1.0, 0.0
|
|
for o in range(octaves):
|
|
cx, cy = max(1, int(cells * sx * 2 ** o)), max(1, int(cells * sy * 2 ** o))
|
|
g = rng.random((cy, cx), dtype=np.float32)
|
|
yy, xx = np.mgrid[0:n, 0:n].astype(np.float32)
|
|
u, v = xx / n * cx, yy / n * cy
|
|
x0, y0 = u.astype(int) % cx, v.astype(int) % cy
|
|
x1, y1 = (x0 + 1) % cx, (y0 + 1) % cy
|
|
fx, fy = u - np.floor(u), v - np.floor(v)
|
|
fx, fy = fx * fx * (3 - 2 * fx), fy * fy * (3 - 2 * fy)
|
|
out += amp * ((g[y0, x0] * (1 - fx) + g[y0, x1] * fx) * (1 - fy) + (g[y1, x0] * (1 - fx) + g[y1, x1] * fx) * fy)
|
|
tot += amp
|
|
amp *= 0.5
|
|
return out / tot
|
|
|
|
|
|
def lerp3(a, b, t):
|
|
return np.array(a, np.float32) * (1 - t[..., None]) + np.array(b, np.float32) * t[..., None]
|
|
|
|
|
|
def planks(n, count, horizontal, base_a, base_b, gap=(30, 20, 12), gap_w=5, knots=6, paint=None, chip=0.62):
|
|
"""Boards side by side. Grain runs along the boards; every board gets its own tone and offset."""
|
|
grain = fbm(n, 2, 5, sx=1, sy=7) # streaks along x before the optional transpose below
|
|
tone = np.zeros((n, n), np.float32)
|
|
w = n / count
|
|
for i in range(count):
|
|
y0, y1 = int(i * w), int((i + 1) * w)
|
|
tone[y0:y1, :] = rng.uniform(0, 1)
|
|
grain[y0:y1, :] = np.roll(grain[y0:y1, :], rng.integers(n), axis=1)
|
|
t = np.clip(tone * 0.45 + (grain - 0.5) * 1.8 + 0.3, 0, 1)
|
|
img = lerp3(base_a, base_b, t)
|
|
# knots
|
|
yy, xx = np.mgrid[0:n, 0:n].astype(np.float32)
|
|
for _ in range(knots):
|
|
cx, cy = rng.uniform(0, n), (rng.integers(count) + 0.5) * w
|
|
dx = (xx - cx + n / 2) % n - n / 2
|
|
dy = (yy - cy + n / 2) % n - n / 2
|
|
d = np.sqrt((dx / 2.2) ** 2 + dy ** 2)
|
|
k = np.exp(-(d / rng.uniform(5, 10)) ** 2)
|
|
img *= (1 - 0.55 * k)[..., None]
|
|
if paint is not None:
|
|
# chipped paint: wood shows through along board edges and in worn patches
|
|
wear = fbm(n, 6, 5)
|
|
edge = np.zeros((n, n), np.float32)
|
|
for i in range(count + 1):
|
|
y = i * w
|
|
edge += np.exp(-(((yy - y + n / 2) % n - n / 2) / (w * 0.09)) ** 2)
|
|
m = np.clip((wear + edge * 0.28 - chip) * 9, 0, 1)
|
|
p = lerp3(paint, np.array(paint, np.float32) * 0.82, np.clip(grain * 1.4 - 0.2, 0, 1))
|
|
img = p * (1 - m[..., None]) + img * m[..., None]
|
|
# dark gaps
|
|
for i in range(count + 1):
|
|
y = i * w
|
|
d = np.abs((yy - y + n / 2) % n - n / 2)
|
|
g = np.clip(1 - d / gap_w, 0, 1)
|
|
img = img * (1 - g[..., None]) + np.array(gap, np.float32) * g[..., None]
|
|
s = np.clip(1 - (d - gap_w) / (gap_w * 1.6), 0, 1) * (d >= gap_w)
|
|
img *= (1 - 0.25 * s)[..., None]
|
|
if not horizontal:
|
|
img = np.transpose(img, (1, 0, 2))
|
|
return img
|
|
|
|
|
|
def save(img, name, folder=TEX):
|
|
Image.fromarray(np.clip(img, 0, 255).astype(np.uint8)).save(os.path.join(folder, name))
|
|
print(name)
|
|
|
|
|
|
def nails(img, pts, r=7):
|
|
"""Iron nail heads with a little rust stain."""
|
|
n = img.shape[0]
|
|
yy, xx = np.mgrid[0:n, 0:n].astype(np.float32)
|
|
for (x, y) in pts:
|
|
dx, dy = (xx - x + n / 2) % n - n / 2, (yy - y + n / 2) % n - n / 2
|
|
d = np.sqrt(dx * dx + dy * dy)
|
|
stain = np.exp(-(d / (r * 3.2)) ** 2) * 0.28
|
|
img = img * (1 - stain[..., None]) + np.array([96, 56, 28], np.float32) * stain[..., None]
|
|
m = np.clip(r - d, 0, 1)
|
|
shade = np.clip(0.75 + (-dx - dy) / (r * 3.2), 0.4, 1.2)
|
|
head = np.array([72, 68, 62], np.float32) * shade[..., None]
|
|
img = img * (1 - m[..., None]) + head * m[..., None]
|
|
return img
|
|
|
|
|
|
def deck():
|
|
n = 1024
|
|
count = 6
|
|
img = planks(n, count, True, (120, 78, 44), (186, 134, 80), knots=9)
|
|
w = n / count
|
|
pts = []
|
|
for i in range(count):
|
|
y = (i + 0.5) * w
|
|
for x in (n * 0.02, n * 0.98, n * 0.5):
|
|
for dy in (-w * 0.26, w * 0.26):
|
|
pts.append((x + (i % 2) * n * 0.02, y + dy))
|
|
save(nails(img, pts), "T_Deck.png")
|
|
|
|
|
|
def barn_boards():
|
|
n = 1024
|
|
save(planks(n, 7, False, (120, 92, 62), (150, 118, 80), knots=4, paint=(239, 227, 194)), "T_HullPanel.png")
|
|
save(planks(n, 7, False, (92, 62, 40), (122, 84, 54), knots=5, paint=(176, 64, 44)), "T_BarnRed.png")
|
|
|
|
|
|
def timber():
|
|
n = 1024
|
|
save(planks(n, 4, False, (92, 60, 34), (152, 104, 60), gap=(40, 26, 14), gap_w=3, knots=10), "T_Timber.png")
|
|
|
|
|
|
def trim():
|
|
"""The old hazard stripes: worn barn-red and cream diagonal boards."""
|
|
n = 1024
|
|
yy, xx = np.mgrid[0:n, 0:n].astype(np.float32)
|
|
s = ((xx + yy) / n * 4) % 1 < 0.5
|
|
wear = fbm(n, 8, 5)
|
|
a, b = np.array((176, 64, 44), np.float32), np.array((239, 227, 194), np.float32)
|
|
img = a * s[..., None] + b * (~s)[..., None]
|
|
wood = lerp3((96, 66, 40), (140, 100, 62), fbm(n, 2, 4, 1, 6))
|
|
m = np.clip((wear - 0.6) * 8, 0, 1)[..., None]
|
|
img = img * (1 - m) + wood * m
|
|
save(img, "T_Hazard.png")
|
|
|
|
|
|
def gingham():
|
|
"""The old orange awning: red and cream gingham."""
|
|
n = 1024
|
|
yy, xx = np.mgrid[0:n, 0:n].astype(np.float32)
|
|
k = 8
|
|
a = ((xx / n * k) % 1 < 0.5).astype(np.float32)
|
|
b = ((yy / n * k) % 1 < 0.5).astype(np.float32)
|
|
t = (a + b) / 2
|
|
img = lerp3((240, 228, 198), (168, 58, 40), t)
|
|
weave = (np.sin(xx * 1.6) * np.sin(yy * 1.6)) * 7
|
|
save(img + weave[..., None], "T_Fabric.png")
|
|
|
|
|
|
def dirt():
|
|
"""Packed earth of the garage yard: dry patches, tyre-worn streaks, a scatter of pebbles and straw."""
|
|
n = 1024
|
|
big, fine = fbm(n, 5, 5), fbm(n, 40, 3)
|
|
img = lerp3((96, 70, 44), (150, 116, 76), np.clip(big * 0.7 + fine * 0.5 - 0.1, 0, 1))
|
|
pil = Image.fromarray(img.astype(np.uint8))
|
|
d = ImageDraw.Draw(pil)
|
|
for _ in range(420):
|
|
x, y, r = rng.uniform(0, n), rng.uniform(0, n), rng.uniform(1.5, 4.5)
|
|
c = int(rng.uniform(70, 170))
|
|
d.ellipse((x - r, y - r * 0.7, x + r, y + r * 0.7), fill=(c, int(c * 0.86), int(c * 0.68)))
|
|
for _ in range(160):
|
|
x, y, a = rng.uniform(0, n), rng.uniform(0, n), rng.uniform(0, 6.28)
|
|
L = rng.uniform(10, 26)
|
|
d.line((x, y, x + np.cos(a) * L, y + np.sin(a) * L), fill=(214, 182, 104), width=2)
|
|
pil.filter(ImageFilter.GaussianBlur(0.6)).save(os.path.join(TEX, "T_Dirt.png"))
|
|
print("T_Dirt.png")
|
|
|
|
|
|
def main():
|
|
dirt()
|
|
deck()
|
|
barn_boards()
|
|
timber()
|
|
trim()
|
|
gingham()
|
|
ui()
|
|
|
|
|
|
# ───────────────────────── UI skins ─────────────────────────
|
|
|
|
INK = (42, 33, 20)
|
|
|
|
|
|
def rounded_mask(w, h, r, ss=3):
|
|
m = Image.new("L", (w * ss, h * ss), 0)
|
|
ImageDraw.Draw(m).rounded_rectangle((0, 0, w * ss - 1, h * ss - 1), r * ss, fill=255)
|
|
return m.resize((w, h), Image.LANCZOS)
|
|
|
|
|
|
def board(w, h, boards, a, b, paint=None, r=26, border=7, nail=True, bevel=True, horizontal=True, name=None):
|
|
"""A wooden sign: boards, dark ink rim, lit top edge, nails in the corners. Saved with alpha for 9-slicing."""
|
|
n = max(w, h)
|
|
img = planks(n, boards * n // h if horizontal else boards * n // w, True, a, b, gap=(46, 30, 18), gap_w=2.2, knots=3, paint=paint, chip=0.78)
|
|
if not horizontal:
|
|
img = np.transpose(img, (1, 0, 2))
|
|
img = img[:h, :w].copy()
|
|
yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
|
|
if bevel:
|
|
img *= (1 + 0.16 * np.exp(-yy / 9.0) - 0.26 * np.exp(-(h - 1 - yy) / 11.0))[..., None]
|
|
if nail:
|
|
d = r * 0.82 + 5
|
|
for (x, y) in ((d, d), (w - d, d), (d, h - d), (w - d, h - d)):
|
|
dist = np.sqrt((xx - x) ** 2 + (yy - y) ** 2)
|
|
m = np.clip(5.5 - dist, 0, 1)[..., None]
|
|
img = img * (1 - m) + np.array((60, 54, 46), np.float32) * m
|
|
hl = np.clip(2.2 - np.sqrt((xx - x + 1.6) ** 2 + (yy - y + 1.6) ** 2), 0, 1)[..., None] * 0.7
|
|
img = img * (1 - hl) + np.array((176, 170, 158), np.float32) * hl
|
|
out = Image.fromarray(np.clip(img, 0, 255).astype(np.uint8)).convert("RGBA")
|
|
rim = Image.new("RGBA", (w, h), INK + (255,))
|
|
inner = rounded_mask(w - border * 2, h - border * 2, max(2, r - border))
|
|
rim.paste(out.crop((border, border, w - border, h - border)), (border, border), inner)
|
|
rim.putalpha(rounded_mask(w, h, r))
|
|
rim.save(os.path.join(UI, name))
|
|
print(name)
|
|
|
|
|
|
def paper(w, h, name):
|
|
"""Cream almanac paper with a stitched burlap edge."""
|
|
base = lerp3((232, 216, 176), (246, 236, 208), fbm(max(w, h), 8, 5)[:h, :w])
|
|
out = Image.fromarray(base.astype(np.uint8)).convert("RGBA")
|
|
d = ImageDraw.Draw(out)
|
|
m = 15
|
|
for x in range(m + 12, w - m - 12, 26):
|
|
d.line((x, m, x + 13, m), fill=(150, 110, 66, 255), width=3)
|
|
d.line((x, h - m, x + 13, h - m), fill=(150, 110, 66, 255), width=3)
|
|
for y in range(m + 12, h - m - 12, 26):
|
|
d.line((m, y, m, y + 13), fill=(150, 110, 66, 255), width=3)
|
|
d.line((w - m, y, w - m, y + 13), fill=(150, 110, 66, 255), width=3)
|
|
rim = Image.new("RGBA", (w, h), INK + (255,))
|
|
rim.paste(out.crop((6, 6, w - 6, h - 6)), (6, 6), rounded_mask(w - 12, h - 12, 14))
|
|
rim.putalpha(rounded_mask(w, h, 20))
|
|
rim.save(os.path.join(UI, name))
|
|
print(name)
|
|
|
|
|
|
def ui():
|
|
timber_a, timber_b = (112, 74, 42), (160, 112, 66)
|
|
dark_a, dark_b = (58, 40, 25), (84, 58, 36)
|
|
board(512, 200, 2, timber_a, timber_b, name="ui_btn_wood.png", r=24)
|
|
board(512, 200, 2, timber_a, timber_b, paint=(176, 64, 44), name="ui_btn_red.png", r=24)
|
|
board(512, 200, 2, timber_a, timber_b, paint=(92, 150, 52), name="ui_btn_green.png", r=24)
|
|
board(512, 200, 2, timber_a, timber_b, paint=(230, 184, 60), name="ui_btn_gold.png", r=24)
|
|
board(512, 200, 2, timber_a, timber_b, paint=(236, 224, 192), name="ui_btn_cream.png", r=24)
|
|
board(512, 320, 4, dark_a, dark_b, name="ui_panel_dark.png", r=20, nail=True)
|
|
board(256, 256, 3, timber_a, timber_b, paint=(226, 212, 174), name="ui_slot.png", r=22, nail=False)
|
|
board(256, 256, 3, timber_a, timber_b, paint=(230, 184, 60), name="ui_slot_on.png", r=22, nail=False)
|
|
paper(768, 512, "ui_panel_paper.png")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|