wall texture
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -0,0 +1,120 @@
#!/usr/bin/env python3
"""Export face-id / heightmap / upscaled refs from thick-stone-wall alone.
Run from repo root:
python3 client/scripts/export-thick-wall-refs.py
Requires: Pillow
"""
from __future__ import annotations
from pathlib import Path
from PIL import Image, ImageDraw
ROOT = Path(__file__).resolve().parents[1]
ALONE = ROOT / "assets/blocks/_examples/stone-wall/thick-stone-wall.png"
OUT = ROOT / "assets/blocks/_examples/stone-wall"
# Source greys → semantic face roles (see docs/STONE_WALL_SHAPES.md)
FACE_RGB = {
(175, 175, 175): (255, 255, 255), # N bevel
(149, 149, 149): (220, 60, 60), # W face
(108, 108, 108): (60, 100, 220), # E face
(84, 84, 84): (60, 180, 80), # S face
(128, 128, 128): (220, 180, 60), # top plateau
(64, 64, 64): (20, 20, 20), # outline
}
HEIGHT = {
(64, 64, 64): 40,
(84, 84, 84): 80,
(108, 108, 108): 140,
(149, 149, 149): 160,
(128, 128, 128): 200,
(175, 175, 175): 220,
}
def main() -> None:
OUT.mkdir(parents=True, exist_ok=True)
alone = Image.open(ALONE).convert("RGBA")
w, h = alone.size
face = Image.new("RGBA", (w, h), (0, 0, 0, 0))
height = Image.new("L", (w, h), 0)
for y in range(h):
for x in range(w):
r, g, b, a = alone.getpixel((x, y))
if a == 0:
continue
key = (r, g, b)
if key not in FACE_RGB:
raise SystemExit(f"Unknown grey {key} at ({x},{y})")
fr, fg, fb = FACE_RGB[key]
face.putpixel((x, y), (fr, fg, fb, 255))
height.putpixel((x, y), HEIGHT[key])
face.save(OUT / "ref-thick-face-id-16.png")
face.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-face-id-256.png")
height.save(OUT / "ref-thick-height-16.png")
height.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-height-256.png")
alone.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-alone-256.png")
leg = Image.new("RGBA", (280, 200), (30, 30, 30, 255))
d = ImageDraw.Draw(leg)
items = [
((255, 255, 255), "North bevel 0xAF"),
((220, 60, 60), "West face 0x95"),
((60, 100, 220), "East face 0x6C"),
((60, 180, 80), "South face 0x54"),
((220, 180, 60), "Top plateau 0x80"),
((20, 20, 20), "Outline 0x40"),
]
for i, (c, label) in enumerate(items):
yy = 16 + i * 28
d.rectangle([16, yy, 40, yy + 20], fill=(*c, 255))
d.text((52, yy + 2), label, fill=(230, 230, 230, 255))
leg.save(OUT / "ref-thick-face-legend.png")
# Labeled contact sheet of all 16 thick *shape* states (bit order).
wall_dir = OUT
names = [
("alone", "thick-stone-wall.png"),
("n", "thick-stone-wall-n.png"),
("e", "thick-stone-wall-e.png"),
("ne", "thick-stone-wall-ne.png"),
("s", "thick-stone-wall-s.png"),
("ns", "thick-stone-wall-ns.png"),
("es", "thick-stone-wall-es.png"),
("nes", "thick-stone-wall-nes.png"),
("w", "thick-stone-wall-w.png"),
("wn", "thick-stone-wall-wn.png"),
("we", "thick-stone-wall-we.png"),
("wne", "thick-stone-wall-wne.png"),
("sw", "thick-stone-wall-sw.png"),
("swn", "thick-stone-wall-swn.png"),
("esw", "thick-stone-wall-esw.png"),
("nesw", "thick-stone-wall-nesw.png"),
]
scale, pad, label_h, cols = 8, 28, 14, 4
cell = 16 * scale
rows = 4
sheet_w = cols * cell + (cols + 1) * pad
sheet_h = rows * (cell + label_h) + (rows + 1) * pad
sheet = Image.new("RGBA", (sheet_w, sheet_h), (24, 24, 28, 255))
draw = ImageDraw.Draw(sheet)
for i, (label, fname) in enumerate(names):
r, c = divmod(i, cols)
x = pad + c * (cell + pad)
y = pad + r * (cell + label_h + pad)
im = Image.open(wall_dir / fname).convert("RGBA").resize((cell, cell), Image.NEAREST)
sheet.paste(im, (x, y), im)
draw.text((x, y + cell + 2), label, fill=(220, 220, 220, 255))
sheet.save(OUT / "ref-thick-all-variants.png")
print(f"Wrote refs to {OUT}")
if __name__ == "__main__":
main()
@@ -0,0 +1,120 @@#!/usr/bin/env python3"""Export face-id / heightmap / upscaled refs from thick-stone-wall alone.Run from repo root: python3 client/scripts/export-thick-wall-refs.pyRequires: Pillow"""from __future__ import annotationsfrom pathlib import Pathfrom PIL import Image, ImageDrawROOT = Path(__file__).resolve().parents[1]ALONE = ROOT / "assets/blocks/_examples/stone-wall/thick-stone-wall.png"OUT = ROOT / "assets/blocks/_examples/stone-wall"# Source greys → semantic face roles (see docs/STONE_WALL_SHAPES.md)FACE_RGB = { (175, 175, 175): (255, 255, 255), # N bevel (149, 149, 149): (220, 60, 60), # W face (108, 108, 108): (60, 100, 220), # E face (84, 84, 84): (60, 180, 80), # S face (128, 128, 128): (220, 180, 60), # top plateau (64, 64, 64): (20, 20, 20), # outline}HEIGHT = { (64, 64, 64): 40, (84, 84, 84): 80, (108, 108, 108): 140, (149, 149, 149): 160, (128, 128, 128): 200, (175, 175, 175): 220,}def main() -> None: OUT.mkdir(parents=True, exist_ok=True) alone = Image.open(ALONE).convert("RGBA") w, h = alone.size face = Image.new("RGBA", (w, h), (0, 0, 0, 0)) height = Image.new("L", (w, h), 0) for y in range(h): for x in range(w): r, g, b, a = alone.getpixel((x, y)) if a == 0: continue key = (r, g, b) if key not in FACE_RGB: raise SystemExit(f"Unknown grey {key} at ({x},{y})") fr, fg, fb = FACE_RGB[key] face.putpixel((x, y), (fr, fg, fb, 255)) height.putpixel((x, y), HEIGHT[key]) face.save(OUT / "ref-thick-face-id-16.png") face.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-face-id-256.png") height.save(OUT / "ref-thick-height-16.png") height.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-height-256.png") alone.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-alone-256.png") leg = Image.new("RGBA", (280, 200), (30, 30, 30, 255)) d = ImageDraw.Draw(leg) items = [ ((255, 255, 255), "North bevel 0xAF"), ((220, 60, 60), "West face 0x95"), ((60, 100, 220), "East face 0x6C"), ((60, 180, 80), "South face 0x54"), ((220, 180, 60), "Top plateau 0x80"), ((20, 20, 20), "Outline 0x40"), ] for i, (c, label) in enumerate(items): yy = 16 + i * 28 d.rectangle([16, yy, 40, yy + 20], fill=(*c, 255)) d.text((52, yy + 2), label, fill=(230, 230, 230, 255)) leg.save(OUT / "ref-thick-face-legend.png") # Labeled contact sheet of all 16 thick *shape* states (bit order). wall_dir = OUT names = [ ("alone", "thick-stone-wall.png"), ("n", "thick-stone-wall-n.png"), ("e", "thick-stone-wall-e.png"), ("ne", "thick-stone-wall-ne.png"), ("s", "thick-stone-wall-s.png"), ("ns", "thick-stone-wall-ns.png"), ("es", "thick-stone-wall-es.png"), ("nes", "thick-stone-wall-nes.png"), ("w", "thick-stone-wall-w.png"), ("wn", "thick-stone-wall-wn.png"), ("we", "thick-stone-wall-we.png"), ("wne", "thick-stone-wall-wne.png"), ("sw", "thick-stone-wall-sw.png"), ("swn", "thick-stone-wall-swn.png"), ("esw", "thick-stone-wall-esw.png"), ("nesw", "thick-stone-wall-nesw.png"), ] scale, pad, label_h, cols = 8, 28, 14, 4 cell = 16 * scale rows = 4 sheet_w = cols * cell + (cols + 1) * pad sheet_h = rows * (cell + label_h) + (rows + 1) * pad sheet = Image.new("RGBA", (sheet_w, sheet_h), (24, 24, 28, 255)) draw = ImageDraw.Draw(sheet) for i, (label, fname) in enumerate(names): r, c = divmod(i, cols) x = pad + c * (cell + pad) y = pad + r * (cell + label_h + pad) im = Image.open(wall_dir / fname).convert("RGBA").resize((cell, cell), Image.NEAREST) sheet.paste(im, (x, y), im) draw.text((x, y + cell + 2), label, fill=(220, 220, 220, 255)) sheet.save(OUT / "ref-thick-all-variants.png") print(f"Wrote refs to {OUT}")if __name__ == "__main__": main()@@ -9,24 +9,26 @@
*
* node client/scripts/generate-stone-wall-sprites.mjs
*/
import {
mkdirSync,
writeFileSync,
readdirSync,
unlinkSync,
readFileSync,
existsSync,
cpSync,
rmSync
} from "node:fs";
import
{
mkdirSync,
writeFileSync,
readdirSync,
unlinkSync,
readFileSync,
existsSync,
cpSync,
rmSync
} from "node:fs";
import { deflateSync, inflateSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import {
NeighborBit,
cardinalConnectionSuffix,
composeNamedNeighborConnectState
} from "../../shared/world/neighborConnect.js";
import
{
NeighborBit,
cardinalConnectionSuffix,
composeNamedNeighborConnectState
} from "../../shared/world/neighborConnect.js";
const SIZE = 16;
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
@@ -9,24 +9,26 @@ * * * node client/scripts/generate-stone-wall-sprites.mjs * node client/scripts/generate-stone-wall-sprites.mjs */ */import {import mkdirSync, { writeFileSync, mkdirSync, readdirSync, writeFileSync, unlinkSync, readdirSync, readFileSync, unlinkSync, existsSync, readFileSync, cpSync, existsSync, rmSync cpSync,} from "node:fs"; rmSync } from "node:fs";import { deflateSync, inflateSync } from "node:zlib";import { deflateSync, inflateSync } from "node:zlib";import { fileURLToPath } from "node:url";import { fileURLToPath } from "node:url";import { dirname, join } from "node:path";import { dirname, join } from "node:path";import {import NeighborBit, { cardinalConnectionSuffix, NeighborBit, composeNamedNeighborConnectState cardinalConnectionSuffix,} from "../../shared/world/neighborConnect.js"; composeNamedNeighborConnectState } from "../../shared/world/neighborConnect.js";const SIZE = 16;const SIZE = 16;const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");@@ -0,0 +1,297 @@
/**
* Bake grey cobblestone texture onto thick/thin stone-wall shape masks.
*
* Shape source of truth (greyscale face-IDs):
* client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png
*
* Textured output (gameplay sprites):
* client/assets/blocks/thick-stone-wall/
* client/assets/blocks/thin-stone-wall/
*
* Face greys (see docs/STONE_WALL_SHAPES.md) pick a cobble base luminance;
* a stable hash adds mortar/highlight speckles inside each face.
*
* node client/scripts/texture-stone-wall-sprites.mjs
*/
import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from "node:fs";
import { deflateSync, inflateSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
const SIZE = 16;
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
const EXAMPLES = join(ROOT, "_examples/stone-wall");
const OUT = {
"thick-stone-wall": join(ROOT, "thick-stone-wall"),
"thin-stone-wall": join(ROOT, "thin-stone-wall")
};
/** Gray cobble palette (cool stone; no magenta). */
const TOP = [168, 168, 172, 255];
const TOP_HI = [198, 198, 202, 255];
const TOP_LO = [140, 140, 144, 255];
const FACE = [112, 112, 116, 255];
const FACE_HI = [132, 132, 136, 255];
const FACE_LO = [88, 88, 92, 255];
const EDGE = [70, 70, 74, 255];
const MORTAR = [78, 78, 82, 255];
/**
* Face-id grey → cobble base (directional light from NW).
* Thick and thin use slightly different vocabularies (thin frustum).
*/
const THICK_ROLE_BASE = new Map([
[0xaf, TOP_HI], // north bevel
[0x95, FACE_HI], // west face
[0x80, TOP], // top plateau
[0x6c, FACE], // east face
[0x54, FACE_LO], // south face
[0x40, EDGE] // outline / crease
]);
const THIN_ROLE_BASE = new Map([
[0xb6, FACE_HI], // west face (bright)
[0x95, TOP_HI], // north rim / ridge top
[0x80, FACE], // east face
[0x73, FACE_LO], // south / front body
[0x40, EDGE]
]);
function roleBaseFor (prefix)
{
return prefix === "thin-stone-wall" ? THIN_ROLE_BASE : THICK_ROLE_BASE;
}
/** Fallback: map arbitrary grey luminance into the cobble range. */
function baseFromLuminance (g)
{
if (g <= 0x48)
{ return EDGE; }
if (g <= 0x60)
{ return FACE_LO; }
if (g <= 0x78)
{ return FACE; }
if (g <= 0x90)
{ return FACE_HI; }
if (g <= 0xa8)
{ return TOP; }
return TOP_HI;
}
function crcTable ()
{
const table = new Uint32Array(256);
for (let n = 0; n < 256; n++)
{
let c = n;
for (let k = 0; k < 8; k++)
{ c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); }
table[n] = c >>> 0;
}
return table;
}
const CRC_TABLE = crcTable();
function crc32 (buf)
{
let c = 0xffffffff;
for (let i = 0; i < buf.length; i++)
{ c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); }
return (c ^ 0xffffffff) >>> 0;
}
function chunk (type, data)
{
const len = Buffer.alloc(4);
len.writeUInt32BE(data.length);
const typeBuf = Buffer.from(type, "ascii");
const crcBuf = Buffer.alloc(4);
crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])));
return Buffer.concat([len, typeBuf, data, crcBuf]);
}
function encodePng (rgba)
{
const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE);
for (let y = 0; y < SIZE; y++)
{
const row = y * (SIZE * 4 + 1);
raw[row] = 0;
for (let x = 0; x < SIZE; x++)
{
const i = (y * SIZE + x) * 4;
const o = row + 1 + x * 4;
raw[o] = rgba[i];
raw[o + 1] = rgba[i + 1];
raw[o + 2] = rgba[i + 2];
raw[o + 3] = rgba[i + 3];
}
}
const ihdr = Buffer.alloc(13);
ihdr.writeUInt32BE(SIZE, 0);
ihdr.writeUInt32BE(SIZE, 4);
ihdr[8] = 8;
ihdr[9] = 6;
return Buffer.concat([
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
chunk("IHDR", ihdr),
chunk("IDAT", deflateSync(raw, { level: 9 })),
chunk("IEND", Buffer.alloc(0))
]);
}
function decodePngRgba (path)
{
const buf = readFileSync(path);
let off = 8;
let w = 0;
let h = 0;
const idat = [];
while (off < buf.length)
{
const len = buf.readUInt32BE(off);
const type = buf.slice(off + 4, off + 8).toString("ascii");
const data = buf.slice(off + 8, off + 8 + len);
if (type === "IHDR")
{
w = data.readUInt32BE(0);
h = data.readUInt32BE(4);
}
else if (type === "IDAT")
{ idat.push(data); }
else if (type === "IEND")
{ break; }
off += 12 + len;
}
const inflated = inflateSync(Buffer.concat(idat));
const rgba = new Uint8Array(w * h * 4);
const bpp = 4;
let src = 0;
for (let y = 0; y < h; y++)
{
const filter = inflated[src++];
const row = inflated.subarray(src, src + w * bpp);
src += w * bpp;
const prev = y > 0 ? rgba.subarray((y - 1) * w * bpp, y * w * bpp) : null;
const out = rgba.subarray(y * w * bpp, (y + 1) * w * bpp);
for (let i = 0; i < row.length; i++)
{
let v = row[i];
if (filter === 1)
{ v = (v + (i >= bpp ? out[i - bpp] : 0)) & 255; }
else if (filter === 2)
{ v = (v + (prev ? prev[i] : 0)) & 255; }
else if (filter === 3)
{
const a = i >= bpp ? out[i - bpp] : 0;
const b = prev ? prev[i] : 0;
v = (v + Math.floor((a + b) / 2)) & 255;
}
else if (filter === 4)
{
const a = i >= bpp ? out[i - bpp] : 0;
const b = prev ? prev[i] : 0;
const c = prev && i >= bpp ? prev[i - bpp] : 0;
const p = a + b - c;
const pa = Math.abs(p - a);
const pb = Math.abs(p - b);
const pc = Math.abs(p - c);
v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255;
}
out[i] = v;
}
}
if (w !== SIZE || h !== SIZE)
{ throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
return rgba;
}
function hash2 (x, y)
{
let n = (x * 374761393 + y * 668265263) | 0;
n = (n ^ (n >>> 13)) * 1274126177;
return (n ^ (n >>> 16)) >>> 0;
}
function cobbleShade (base, x, y, isOutline)
{
if (isOutline)
{
// Keep creases mostly solid so silhouettes stay crisp.
const h = hash2(x, y);
return (h & 15) === 0 ? MORTAR : EDGE;
}
const h = hash2(x, y);
const speck = h & 7;
if (speck === 0)
{ return MORTAR; }
if (speck === 1 || speck === 2)
{
return base === TOP || base === TOP_HI || base === TOP_LO
? TOP_HI
: FACE_HI;
}
if (speck === 3)
{
return base === TOP || base === TOP_HI || base === TOP_LO
? TOP_LO
: FACE_LO;
}
return base;
}
function textureMask (rgba, roleBase)
{
const out = new Uint8Array(SIZE * SIZE * 4);
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
const i = (y * SIZE + x) * 4;
const a = rgba[i + 3];
if (a === 0)
{ continue; }
const g = rgba[i];
const base = roleBase.get(g) ?? baseFromLuminance(g);
const color = cobbleShade(base, x, y, g === 0x40);
out[i] = color[0];
out[i + 1] = color[1];
out[i + 2] = color[2];
out[i + 3] = 255;
}
}
return out;
}
function shapeFiles (prefix)
{
if (!existsSync(EXAMPLES))
{ throw new Error(`Missing examples folder: ${EXAMPLES}`); }
return readdirSync(EXAMPLES)
.filter((name) => name.startsWith(prefix) && name.endsWith(".png"))
.sort();
}
let wrote = 0;
for (const [prefix, outDir] of Object.entries(OUT))
{
mkdirSync(outDir, { recursive: true });
const files = shapeFiles(prefix);
if (files.length !== 16)
{
throw new Error(
`Expected 16 ${prefix} masks in ${EXAMPLES}, found ${files.length}`
);
}
const roleBase = roleBaseFor(prefix);
for (const name of files)
{
const shaped = decodePngRgba(join(EXAMPLES, name));
const textured = textureMask(shaped, roleBase);
writeFileSync(join(outDir, name), encodePng(textured));
wrote++;
}
console.log(`Textured ${files.length} → ${outDir}`);
}
console.log(`Done (${wrote} sprites). Shapes left greyscale in ${EXAMPLES}`);
@@ -0,0 +1,297 @@/** * Bake grey cobblestone texture onto thick/thin stone-wall shape masks. * * Shape source of truth (greyscale face-IDs): * client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png * * Textured output (gameplay sprites): * client/assets/blocks/thick-stone-wall/ * client/assets/blocks/thin-stone-wall/ * * Face greys (see docs/STONE_WALL_SHAPES.md) pick a cobble base luminance; * a stable hash adds mortar/highlight speckles inside each face. * * node client/scripts/texture-stone-wall-sprites.mjs */import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from "node:fs";import { deflateSync, inflateSync } from "node:zlib";import { fileURLToPath } from "node:url";import { dirname, join } from "node:path";const SIZE = 16;const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");const EXAMPLES = join(ROOT, "_examples/stone-wall");const OUT = { "thick-stone-wall": join(ROOT, "thick-stone-wall"), "thin-stone-wall": join(ROOT, "thin-stone-wall")};/** Gray cobble palette (cool stone; no magenta). */const TOP = [168, 168, 172, 255];const TOP_HI = [198, 198, 202, 255];const TOP_LO = [140, 140, 144, 255];const FACE = [112, 112, 116, 255];const FACE_HI = [132, 132, 136, 255];const FACE_LO = [88, 88, 92, 255];const EDGE = [70, 70, 74, 255];const MORTAR = [78, 78, 82, 255];/** * Face-id grey → cobble base (directional light from NW). * Thick and thin use slightly different vocabularies (thin frustum). */const THICK_ROLE_BASE = new Map([ [0xaf, TOP_HI], // north bevel [0x95, FACE_HI], // west face [0x80, TOP], // top plateau [0x6c, FACE], // east face [0x54, FACE_LO], // south face [0x40, EDGE] // outline / crease]);const THIN_ROLE_BASE = new Map([ [0xb6, FACE_HI], // west face (bright) [0x95, TOP_HI], // north rim / ridge top [0x80, FACE], // east face [0x73, FACE_LO], // south / front body [0x40, EDGE]]);function roleBaseFor (prefix){ return prefix === "thin-stone-wall" ? THIN_ROLE_BASE : THICK_ROLE_BASE;}/** Fallback: map arbitrary grey luminance into the cobble range. */function baseFromLuminance (g){ if (g <= 0x48) { return EDGE; } if (g <= 0x60) { return FACE_LO; } if (g <= 0x78) { return FACE; } if (g <= 0x90) { return FACE_HI; } if (g <= 0xa8) { return TOP; } return TOP_HI;}function crcTable (){ const table = new Uint32Array(256); for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) { c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); } table[n] = c >>> 0; } return table;}const CRC_TABLE = crcTable();function crc32 (buf){ let c = 0xffffffff; for (let i = 0; i < buf.length; i++) { c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); } return (c ^ 0xffffffff) >>> 0;}function chunk (type, data){ const len = Buffer.alloc(4); len.writeUInt32BE(data.length); const typeBuf = Buffer.from(type, "ascii"); const crcBuf = Buffer.alloc(4); crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data]))); return Buffer.concat([len, typeBuf, data, crcBuf]);}function encodePng (rgba){ const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE); for (let y = 0; y < SIZE; y++) { const row = y * (SIZE * 4 + 1); raw[row] = 0; for (let x = 0; x < SIZE; x++) { const i = (y * SIZE + x) * 4; const o = row + 1 + x * 4; raw[o] = rgba[i]; raw[o + 1] = rgba[i + 1]; raw[o + 2] = rgba[i + 2]; raw[o + 3] = rgba[i + 3]; } } const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(SIZE, 0); ihdr.writeUInt32BE(SIZE, 4); ihdr[8] = 8; ihdr[9] = 6; return Buffer.concat([ Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", ihdr), chunk("IDAT", deflateSync(raw, { level: 9 })), chunk("IEND", Buffer.alloc(0)) ]);}function decodePngRgba (path){ const buf = readFileSync(path); let off = 8; let w = 0; let h = 0; const idat = []; while (off < buf.length) { const len = buf.readUInt32BE(off); const type = buf.slice(off + 4, off + 8).toString("ascii"); const data = buf.slice(off + 8, off + 8 + len); if (type === "IHDR") { w = data.readUInt32BE(0); h = data.readUInt32BE(4); } else if (type === "IDAT") { idat.push(data); } else if (type === "IEND") { break; } off += 12 + len; } const inflated = inflateSync(Buffer.concat(idat)); const rgba = new Uint8Array(w * h * 4); const bpp = 4; let src = 0; for (let y = 0; y < h; y++) { const filter = inflated[src++]; const row = inflated.subarray(src, src + w * bpp); src += w * bpp; const prev = y > 0 ? rgba.subarray((y - 1) * w * bpp, y * w * bpp) : null; const out = rgba.subarray(y * w * bpp, (y + 1) * w * bpp); for (let i = 0; i < row.length; i++) { let v = row[i]; if (filter === 1) { v = (v + (i >= bpp ? out[i - bpp] : 0)) & 255; } else if (filter === 2) { v = (v + (prev ? prev[i] : 0)) & 255; } else if (filter === 3) { const a = i >= bpp ? out[i - bpp] : 0; const b = prev ? prev[i] : 0; v = (v + Math.floor((a + b) / 2)) & 255; } else if (filter === 4) { const a = i >= bpp ? out[i - bpp] : 0; const b = prev ? prev[i] : 0; const c = prev && i >= bpp ? prev[i - bpp] : 0; const p = a + b - c; const pa = Math.abs(p - a); const pb = Math.abs(p - b); const pc = Math.abs(p - c); v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255; } out[i] = v; } } if (w !== SIZE || h !== SIZE) { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); } return rgba;}function hash2 (x, y){ let n = (x * 374761393 + y * 668265263) | 0; n = (n ^ (n >>> 13)) * 1274126177; return (n ^ (n >>> 16)) >>> 0;}function cobbleShade (base, x, y, isOutline){ if (isOutline) { // Keep creases mostly solid so silhouettes stay crisp. const h = hash2(x, y); return (h & 15) === 0 ? MORTAR : EDGE; } const h = hash2(x, y); const speck = h & 7; if (speck === 0) { return MORTAR; } if (speck === 1 || speck === 2) { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_HI : FACE_HI; } if (speck === 3) { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_LO : FACE_LO; } return base;}function textureMask (rgba, roleBase){ const out = new Uint8Array(SIZE * SIZE * 4); for (let y = 0; y < SIZE; y++) { for (let x = 0; x < SIZE; x++) { const i = (y * SIZE + x) * 4; const a = rgba[i + 3]; if (a === 0) { continue; } const g = rgba[i]; const base = roleBase.get(g) ?? baseFromLuminance(g); const color = cobbleShade(base, x, y, g === 0x40); out[i] = color[0]; out[i + 1] = color[1]; out[i + 2] = color[2]; out[i + 3] = 255; } } return out;}function shapeFiles (prefix){ if (!existsSync(EXAMPLES)) { throw new Error(`Missing examples folder: ${EXAMPLES}`); } return readdirSync(EXAMPLES) .filter((name) => name.startsWith(prefix) && name.endsWith(".png")) .sort();}let wrote = 0;for (const [prefix, outDir] of Object.entries(OUT)){ mkdirSync(outDir, { recursive: true }); const files = shapeFiles(prefix); if (files.length !== 16) { throw new Error( `Expected 16 ${prefix} masks in ${EXAMPLES}, found ${files.length}` ); } const roleBase = roleBaseFor(prefix); for (const name of files) { const shaped = decodePngRgba(join(EXAMPLES, name)); const textured = textureMask(shaped, roleBase); writeFileSync(join(outDir, name), encodePng(textured)); wrote++; } console.log(`Textured ${files.length} → ${outDir}`);}console.log(`Done (${wrote} sprites). Shapes left greyscale in ${EXAMPLES}`);@@ -1,6 +1,6 @@
# Stone wall shape system
How **thick** stone-wall sprites encode a 3D block as flat greyscale, how **connections** open faces into neighbours, and how to clone the structure for new materials / textures.
How **thick** stone-wall sprites encode a 3D block as flat greyscale face-IDs, how **connections** open faces into neighbours, and how cobble texture is baked onto those masks for gameplay.
Thin walls use the same face vocabulary on a narrower frustum; this document centres on **thick**, which is the clearest reference.
@@ -10,9 +10,10 @@ Thin walls use the same face vocabulary on a narrower frustum; this document cen
| Path | What it is |
|------|------------|
| `client/assets/blocks/thick-stone-wall/thick-stone-wall.png` | **Source of truth** — alone 1×1 |
| `client/assets/blocks/thick-stone-wall/thick-stone-wall-*.png` | 15 connected variants |
| `client/assets/blocks/_examples/stone-wall/ref-thick-alone-256.png` | Nearest-neighbour ×16 alone |
| `client/assets/blocks/thick-stone-wall/thick-stone-wall.png` | **Gameplay** alone 1×1 (textured) |
| `client/assets/blocks/_examples/stone-wall/thick-stone-wall.png` | **Shape mask** alone 1×1 (face-id greys) |
| `client/assets/blocks/thick-stone-wall/thick-stone-wall-*.png` | 15 connected gameplay variants |
| `client/assets/blocks/_examples/stone-wall/ref-thick-alone-256.png` | Nearest-neighbour ×16 alone (shape) |
| `…/ref-thick-face-id-16.png` / `…-256.png` | False-colour face roles |
| `…/ref-thick-height-16.png` / `…-256.png` | Relative heightmap from roles |
| `…/ref-thick-face-legend.png` | Colour key for face-id |
@@ -207,7 +208,7 @@ Each keeps the two **outer** free faces and opens the two **inner** sides into t
**`w`** — west open: N/T/S run to `x=0`; free east column remains.
> **Authoring note:** on the current `thick-stone-wall-w.png`, the free east column is painted with **`0x95` (west grey)** rather than `0x6C`. Structurally it is still “east free face”. When texturing or rebuilding, prefer **remapping to `0x6C`** so E/W lighting stays consistent with alone. Horizontal flips of `e` must reassign face greys — do not keep mirrored luminance.
> **Note:** free east on `thick-stone-wall-w` uses `0x6C` (corrected). When flipping `e`↔`w` art, always reassign face greys — do not keep mirrored luminance.
---
@@ -287,31 +288,55 @@ Suggested pipeline for a new wall set:
## 10. Thin walls
`thin-stone-wall` uses the **same face roles** on a **narrow frustum** (alone body inset; N/S runs stay narrow; E/W opens the frustum to the edge). Clone thin silhouettes, recolour by the thick role table. Prefer thick as the teaching reference when learning the system.
`thin-stone-wall` uses the **same idea** on a **narrow frustum**, but a slightly different grey vocabulary:
| Grey | Hex | Thin role |
|------|-----|-----------|
| 64 | `0x40` | Outline |
| 182 | `0xB6` | West face |
| 149 | `0x95` | North rim / ridge top |
| 128 | `0x80` | East face (**not** top plateau — differs from thick) |
| 115 | `0x73` | South / front body |
Clone thin silhouettes; recolour via this table (or `texture-stone-wall-sprites.mjs`).
---
## 11. Baking cobble texture
Gameplay sprites in `thick-stone-wall/` and `thin-stone-wall/` are **textured**. Greyscale face-id masks stay in `_examples/stone-wall/`.
```bash
node client/scripts/texture-stone-wall-sprites.mjs
```
Reads example masks → writes cobble-shaded PNGs using the old cool-grey stone palette (TOP / FACE / EDGE / MORTAR speckles), keyed by face role. Re-run after editing shapes in `_examples`.
---
## 11. Code touchpoints
## 12. Code touchpoints
| Concern | Location |
|---------|----------|
| Cardinal suffix / mask (`& 15`) | `shared/world/neighborConnect.js` |
| Block defs | `shared/definitions/tiles.js` |
| Sprites | `client/assets/blocks/thick-stone-wall/`, `thin-stone-wall/` |
| Shape examples + refs | `client/assets/blocks/_examples/stone-wall/` |
| Example-driven generator | `client/scripts/generate-stone-wall-sprites.mjs` |
| Textured sprites (gameplay) | `client/assets/blocks/thick-stone-wall/`, `thin-stone-wall/` |
| Greyscale shape masks + refs | `client/assets/blocks/_examples/stone-wall/` |
| Shape generator from connecting examples | `client/scripts/generate-stone-wall-sprites.mjs` |
| Cobble texture bake | `client/scripts/texture-stone-wall-sprites.mjs` |
| Ref export | `client/scripts/export-thick-wall-refs.py` |
Editor recomputes neighbour suffixes on paint and on chunk load so a 2×2 stays on corner suffixes, not `nesw`.
---
## 12. Regenerate reference maps
## 13. Regenerate reference maps
Whenever `thick-stone-wall.png` (alone) changes:
Whenever the thick alone **shape** mask changes:
```bash
python3 client/scripts/export-thick-wall-refs.py
node client/scripts/texture-stone-wall-sprites.mjs
```
Then update the grey table in §2 if the vocabulary shifted.
Then update the grey table in §2 / §10 if the vocabulary shifted.
@@ -1,6 +1,6 @@# Stone wall shape system# Stone wall shape systemHow **thick** stone-wall sprites encode a 3D block as flat greyscale, how **connections** open faces into neighbours, and how to clone the structure for new materials / textures.How **thick** stone-wall sprites encode a 3D block as flat greyscale face-IDs, how **connections** open faces into neighbours, and how cobble texture is baked onto those masks for gameplay.Thin walls use the same face vocabulary on a narrower frustum; this document centres on **thick**, which is the clearest reference.Thin walls use the same face vocabulary on a narrower frustum; this document centres on **thick**, which is the clearest reference.@@ -10,9 +10,10 @@ Thin walls use the same face vocabulary on a narrower frustum; this document cen| Path | What it is || Path | What it is ||------|------------||------|------------|| `client/assets/blocks/thick-stone-wall/thick-stone-wall.png` | **Source of truth** — alone 1×1 || `client/assets/blocks/thick-stone-wall/thick-stone-wall.png` | **Gameplay** alone 1×1 (textured) || `client/assets/blocks/thick-stone-wall/thick-stone-wall-*.png` | 15 connected variants || `client/assets/blocks/_examples/stone-wall/thick-stone-wall.png` | **Shape mask** alone 1×1 (face-id greys) || `client/assets/blocks/_examples/stone-wall/ref-thick-alone-256.png` | Nearest-neighbour ×16 alone || `client/assets/blocks/thick-stone-wall/thick-stone-wall-*.png` | 15 connected gameplay variants || `client/assets/blocks/_examples/stone-wall/ref-thick-alone-256.png` | Nearest-neighbour ×16 alone (shape) || `…/ref-thick-face-id-16.png` / `…-256.png` | False-colour face roles || `…/ref-thick-face-id-16.png` / `…-256.png` | False-colour face roles || `…/ref-thick-height-16.png` / `…-256.png` | Relative heightmap from roles || `…/ref-thick-height-16.png` / `…-256.png` | Relative heightmap from roles || `…/ref-thick-face-legend.png` | Colour key for face-id || `…/ref-thick-face-legend.png` | Colour key for face-id |@@ -207,7 +208,7 @@ Each keeps the two **outer** free faces and opens the two **inner** sides into t**`w`** — west open: N/T/S run to `x=0`; free east column remains.**`w`** — west open: N/T/S run to `x=0`; free east column remains.> **Authoring note:** on the current `thick-stone-wall-w.png`, the free east column is painted with **`0x95` (west grey)** rather than `0x6C`. Structurally it is still “east free face”. When texturing or rebuilding, prefer **remapping to `0x6C`** so E/W lighting stays consistent with alone. Horizontal flips of `e` must reassign face greys — do not keep mirrored luminance.> **Note:** free east on `thick-stone-wall-w` uses `0x6C` (corrected). When flipping `e`↔`w` art, always reassign face greys — do not keep mirrored luminance.------@@ -287,31 +288,55 @@ Suggested pipeline for a new wall set:## 10. Thin walls## 10. Thin walls`thin-stone-wall` uses the **same face roles** on a **narrow frustum** (alone body inset; N/S runs stay narrow; E/W opens the frustum to the edge). Clone thin silhouettes, recolour by the thick role table. Prefer thick as the teaching reference when learning the system.`thin-stone-wall` uses the **same idea** on a **narrow frustum**, but a slightly different grey vocabulary:| Grey | Hex | Thin role ||------|-----|-----------|| 64 | `0x40` | Outline || 182 | `0xB6` | West face || 149 | `0x95` | North rim / ridge top || 128 | `0x80` | East face (**not** top plateau — differs from thick) || 115 | `0x73` | South / front body |Clone thin silhouettes; recolour via this table (or `texture-stone-wall-sprites.mjs`).---## 11. Baking cobble textureGameplay sprites in `thick-stone-wall/` and `thin-stone-wall/` are **textured**. Greyscale face-id masks stay in `_examples/stone-wall/`.```bashnode client/scripts/texture-stone-wall-sprites.mjs```Reads example masks → writes cobble-shaded PNGs using the old cool-grey stone palette (TOP / FACE / EDGE / MORTAR speckles), keyed by face role. Re-run after editing shapes in `_examples`.------## 11. Code touchpoints## 12. Code touchpoints| Concern | Location || Concern | Location ||---------|----------||---------|----------|| Cardinal suffix / mask (`& 15`) | `shared/world/neighborConnect.js` || Cardinal suffix / mask (`& 15`) | `shared/world/neighborConnect.js` || Block defs | `shared/definitions/tiles.js` || Block defs | `shared/definitions/tiles.js` || Sprites | `client/assets/blocks/thick-stone-wall/`, `thin-stone-wall/` || Textured sprites (gameplay) | `client/assets/blocks/thick-stone-wall/`, `thin-stone-wall/` || Shape examples + refs | `client/assets/blocks/_examples/stone-wall/` || Greyscale shape masks + refs | `client/assets/blocks/_examples/stone-wall/` || Example-driven generator | `client/scripts/generate-stone-wall-sprites.mjs` || Shape generator from connecting examples | `client/scripts/generate-stone-wall-sprites.mjs` || Cobble texture bake | `client/scripts/texture-stone-wall-sprites.mjs` || Ref export | `client/scripts/export-thick-wall-refs.py` || Ref export | `client/scripts/export-thick-wall-refs.py` |Editor recomputes neighbour suffixes on paint and on chunk load so a 2×2 stays on corner suffixes, not `nesw`.Editor recomputes neighbour suffixes on paint and on chunk load so a 2×2 stays on corner suffixes, not `nesw`.------## 12. Regenerate reference maps## 13. Regenerate reference mapsWhenever `thick-stone-wall.png` (alone) changes:Whenever the thick alone **shape** mask changes:```bash```bashpython3 client/scripts/export-thick-wall-refs.pypython3 client/scripts/export-thick-wall-refs.pynode client/scripts/texture-stone-wall-sprites.mjs``````Then update the grey table in §2 if the vocabulary shifted.Then update the grey table in §2 / §10 if the vocabulary shifted.@@ -1,20 +1,20 @@
import test from "node:test";
import assert from "node:assert/strict";
import
{
NeighborBit,
computeNeighborConnectMask,
neighborConnectStateName,
parseNeighborConnectMask,
composeNeighborConnectState,
neighborConnectBlocksMatch,
parseMaterialNeighborConnectState,
worldTileToChunkLocal,
neighborConnectRefreshTiles,
cardinalConnectionSuffix,
composeNamedNeighborConnectState,
parseNamedNeighborConnectMask
} from "../../shared/world/neighborConnect.js";
{
NeighborBit,
computeNeighborConnectMask,
neighborConnectStateName,
parseNeighborConnectMask,
composeNeighborConnectState,
neighborConnectBlocksMatch,
parseMaterialNeighborConnectState,
worldTileToChunkLocal,
neighborConnectRefreshTiles,
cardinalConnectionSuffix,
composeNamedNeighborConnectState,
parseNamedNeighborConnectMask
} from "../../shared/world/neighborConnect.js";
import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";
import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";
import { BlockType, BLOCK_DEFINITIONS } from "../../shared/definitions/tiles.js";
@@ -1,20 +1,20 @@import test from "node:test";import test from "node:test";import assert from "node:assert/strict";import assert from "node:assert/strict";importimport {{ NeighborBit, NeighborBit, computeNeighborConnectMask, computeNeighborConnectMask, neighborConnectStateName, neighborConnectStateName, parseNeighborConnectMask, parseNeighborConnectMask, composeNeighborConnectState, composeNeighborConnectState, neighborConnectBlocksMatch, neighborConnectBlocksMatch, parseMaterialNeighborConnectState, parseMaterialNeighborConnectState, worldTileToChunkLocal, worldTileToChunkLocal, neighborConnectRefreshTiles, neighborConnectRefreshTiles, cardinalConnectionSuffix, cardinalConnectionSuffix, composeNamedNeighborConnectState, composeNamedNeighborConnectState, parseNamedNeighborConnectMask parseNamedNeighborConnectMask } from "../../shared/world/neighborConnect.js";} from "../../shared/world/neighborConnect.js";import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";import { BlockType, BLOCK_DEFINITIONS } from "../../shared/definitions/tiles.js";import { BlockType, BLOCK_DEFINITIONS } from "../../shared/definitions/tiles.js";@@ -2,19 +2,20 @@ import test from "node:test";
import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import { join } from "node:path";
import {
SeasonId,
GrowthSeasonId,
seasonIdAt,
growthSeasonIdAt,
regrowDurationMultiplier,
scaleRegrowDurationMs,
resolveSeasonalVisualState,
preferredSeasonalDefaultState,
typeHasSeasonalStates,
seasonalCycleStates,
seasonIdFromVisualState
} from "../../shared/world/season.js";
import
{
SeasonId,
GrowthSeasonId,
seasonIdAt,
growthSeasonIdAt,
regrowDurationMultiplier,
scaleRegrowDurationMs,
resolveSeasonalVisualState,
preferredSeasonalDefaultState,
typeHasSeasonalStates,
seasonalCycleStates,
seasonIdFromVisualState
} from "../../shared/world/season.js";
import { shopRestockDayKey } from "../../shared/shop/pricing.js";
import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
@@ -2,19 +2,20 @@ import test from "node:test";import assert from "node:assert/strict";import assert from "node:assert/strict";import { fileURLToPath } from "node:url";import { fileURLToPath } from "node:url";import { join } from "node:path";import { join } from "node:path";import {import SeasonId, { GrowthSeasonId, SeasonId, seasonIdAt, GrowthSeasonId, growthSeasonIdAt, seasonIdAt, regrowDurationMultiplier, growthSeasonIdAt, scaleRegrowDurationMs, regrowDurationMultiplier, resolveSeasonalVisualState, scaleRegrowDurationMs, preferredSeasonalDefaultState, resolveSeasonalVisualState, typeHasSeasonalStates, preferredSeasonalDefaultState, seasonalCycleStates, typeHasSeasonalStates, seasonIdFromVisualState seasonalCycleStates,} from "../../shared/world/season.js"; seasonIdFromVisualState } from "../../shared/world/season.js";import { shopRestockDayKey } from "../../shared/shop/pricing.js";import { shopRestockDayKey } from "../../shared/shop/pricing.js";import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";