BlueGit

timfa questward

Rebuild stone-wall sprites from alone/connecting examples.

Extrude the authored frustum bands to connected edges (mirrors for W) and keep diagonal fills for solid 2×2 corners so L-strips stay concave.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
5d679c3d460e2c65d6581f2522d74d2422e6fbe7
Parent
1af95bf7
97 files changed +348 −184
client/assets/blocks/stone-wall-thin/0.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/1.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/10.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/11.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/110.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/111.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/12.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/127.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/13.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/137.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/139.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/14.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/141.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/143.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/15.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/155.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/159.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/175.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/19.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/191.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/2.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/205.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/207.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/223.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/23.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/239.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/255.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/27.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/3.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/31.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/38.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/39.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/4.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/46.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/47.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/5.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/55.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/6.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/63.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/7.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/76.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/77.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/78.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/79.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/8.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/9.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/95.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/0.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/1.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/10.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/11.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/110.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/111.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/12.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/127.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/13.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/137.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/139.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/14.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/141.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/143.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/15.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/155.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/159.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/175.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/19.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/191.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/2.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/205.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/207.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/223.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/23.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/239.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/255.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/27.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/3.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/31.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/38.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/39.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/4.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/46.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/47.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/5.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/55.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/6.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/63.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/7.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/76.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/77.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/78.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/79.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/8.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/9.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/95.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/example-stone-thick-connecting.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/example-stone-thin-connecting.png added Binary file +0 −0

The contents of this binary file are not shown.

client/scripts/generate-stone-wall-sprites.mjs +348 −184
@@ -2,18 +2,19 @@
2 2 * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
3 3 * (cardinals + diagonal corners — 47 valid states).
4 4 *
5 * Shape references (silhouette / shading only, not final texture):
6 * client/assets/blocks/stone-wall/example-stone-thin.png
7 * client/assets/blocks/stone-wall/example-stone-thick.png
5 * Shape sources (authoritative):
6 * example-stone-thin.png / example-stone-thin-connecting.png
7 * example-stone-thick.png / example-stone-thick-connecting.png
8 8 *
9 * Corner bits: when both adjacent cardinals join but the diagonal does not,
10 * paint an L-strip (concave). When the diagonal also joins, fill the quadrant
11 * so a solid 2×2 reads as one block.
9 * Alone = free-standing frustum / bevelled block.
10 * *-connecting = same bands extruded to the east edge (free west end kept).
11 * Other directions are mirrors / vertical extrusions of that rule.
12 * Diagonal bits fill the concave L cutout so solid 2×2 reads continuous.
12 13 *
13 14 * node client/scripts/generate-stone-wall-sprites.mjs
14 15 */
15 import { mkdirSync, writeFileSync, readdirSync, unlinkSync } from "node:fs";
16 import { deflateSync } from "node:zlib";
16 import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync } from "node:fs";
17 import { deflateSync, inflateSync } from "node:zlib";
17 18 import { fileURLToPath } from "node:url";
18 19 import { dirname, join } from "node:path";
19 20 import {
@@ -25,48 +26,10 @@ const SIZE = 16;
25 26 const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
26 27 const OUT_THICK = join(ROOT, "stone-wall");
27 28 const OUT_THIN = join(ROOT, "stone-wall-thin");
29 const EXAMPLES = join(ROOT, "stone-wall");
28 30
29 const OUTLINE = [0x40, 0x40, 0x40, 255];
30 const TOP_HI = [0xaf, 0xaf, 0xaf, 255];
31 const TOP = [0x80, 0x80, 0x80, 255];
32 const TOP_LO = [0x73, 0x73, 0x73, 255];
33 const FACE_L = [0x95, 0x95, 0x95, 255];
34 const FACE = [0x73, 0x73, 0x73, 255];
35 const FACE_R = [0x6c, 0x6c, 0x6c, 255];
36 const FACE_FRONT = [0x54, 0x54, 0x54, 255];
37 const HI_L = [0xb6, 0xb6, 0xb6, 255];
38 const HI_R = [0x80, 0x80, 0x80, 255];
39 31 const MORTAR = [0x58, 0x58, 0x5c, 255];
40 32
41 /**
42 * Thin: compact top core (table-style strip-union) so L keeps a concave cutout;
43 * frustum face hangs below on free south edges. Alone matches example-stone-thin.
44 */
45 const THIN = Object.freeze({
46 topY0: 2,
47 coreY0: 3,
48 coreY1: 7,
49 faceY1: 12,
50 coreX0: 5,
51 coreX1: 10,
52 baseX0: 3,
53 baseX1: 12,
54 fullTile: false
55 });
56
57 /** Thick: full-tile footprint; bevels react to free edges / missing diagonals. */
58 const THICK = Object.freeze({
59 topY0: 1,
60 coreY0: 1,
61 coreY1: 8,
62 faceY1: 14,
63 coreX0: 3,
64 coreX1: 12,
65 baseX0: 0,
66 baseX1: 15,
67 fullTile: true
68 });
69
70 33 function crcTable ()
71 34 {
72 35 const table = new Uint32Array(256);
@@ -130,6 +93,83 @@ function encodePng (rgba)
130 93 ]);
131 94 }
132 95
96 /** Decode 8-bit RGBA PNG (with scanline filters) into Uint8ClampedArray. */
97 function decodePngRgba (path)
98 {
99 const buf = readFileSync(path);
100 let off = 8;
101 let w = 0;
102 let h = 0;
103 const idat = [];
104 while (off < buf.length)
105 {
106 const len = buf.readUInt32BE(off);
107 const type = buf.slice(off + 4, off + 8).toString("ascii");
108 const data = buf.slice(off + 8, off + 8 + len);
109 if (type === "IHDR")
110 {
111 w = data.readUInt32BE(0);
112 h = data.readUInt32BE(4);
113 if (data[8] !== 8 || data[9] !== 6)
114 { throw new Error(`${path}: expected 8-bit RGBA`); }
115 }
116 else if (type === "IDAT")
117 { idat.push(data); }
118 else if (type === "IEND")
119 { break; }
120 off += 12 + len;
121 }
122 const raw = inflateSync(Buffer.concat(idat));
123 const bpp = 4;
124 const stride = w * bpp;
125 const rgba = new Uint8ClampedArray(w * h * 4);
126 let src = 0;
127 const prev = Buffer.alloc(stride);
128 const cur = Buffer.alloc(stride);
129 for (let y = 0; y < h; y++)
130 {
131 const filter = raw[src++];
132 for (let i = 0; i < stride; i++)
133 { cur[i] = raw[src++]; }
134 for (let i = 0; i < stride; i++)
135 {
136 const left = i >= bpp ? cur[i - bpp] : 0;
137 const up = prev[i];
138 const upLeft = i >= bpp ? prev[i - bpp] : 0;
139 let val = cur[i];
140 if (filter === 1)
141 { val = (val + left) & 255; }
142 else if (filter === 2)
143 { val = (val + up) & 255; }
144 else if (filter === 3)
145 { val = (val + ((left + up) >> 1)) & 255; }
146 else if (filter === 4)
147 {
148 const p = left + up - upLeft;
149 const pa = Math.abs(p - left);
150 const pb = Math.abs(p - up);
151 const pc = Math.abs(p - upLeft);
152 const pr = (pa <= pb && pa <= pc) ? left : (pb <= pc ? up : upLeft);
153 val = (val + pr) & 255;
154 }
155 cur[i] = val;
156 }
157 rgba.set(cur, y * stride);
158 prev.set(cur);
159 }
160 if (w !== SIZE || h !== SIZE)
161 { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
162 return rgba;
163 }
164
165 function getPx (rgba, x, y)
166 {
167 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
168 { return [0, 0, 0, 0]; }
169 const i = (y * SIZE + x) * 4;
170 return [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]];
171 }
172
133 173 function setPx (rgba, x, y, color)
134 174 {
135 175 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
@@ -141,6 +181,22 @@ function setPx (rgba, x, y, color)
141 181 rgba[i + 3] = color[3];
142 182 }
143 183
184 function opaque (rgba, x, y)
185 {
186 return getPx(rgba, x, y)[3] > 128;
187 }
188
189 function mirrorX (rgba)
190 {
191 const out = new Uint8ClampedArray(rgba.length);
192 for (let y = 0; y < SIZE; y++)
193 {
194 for (let x = 0; x < SIZE; x++)
195 { setPx(out, x, y, getPx(rgba, SIZE - 1 - x, y)); }
196 }
197 return out;
198 }
199
144 200 function hash2 (x, y)
145 201 {
146 202 let n = (x * 374761393 + y * 668265263) | 0;
@@ -150,6 +206,8 @@ function hash2 (x, y)
150 206
151 207 function cobbleShade (base, x, y)
152 208 {
209 if (base[3] < 128)
210 { return base; }
153 211 const h = hash2(x, y);
154 212 const speck = h & 7;
155 213 if (speck === 0)
@@ -157,18 +215,18 @@ function cobbleShade (base, x, y)
157 215 if (speck === 1)
158 216 {
159 217 return [
160 Math.min(255, base[0] + 18),
161 Math.min(255, base[1] + 18),
162 Math.min(255, base[2] + 18),
218 Math.min(255, base[0] + 14),
219 Math.min(255, base[1] + 14),
220 Math.min(255, base[2] + 14),
163 221 255
164 222 ];
165 223 }
166 224 if (speck === 2)
167 225 {
168 226 return [
169 Math.max(0, base[0] - 14),
170 Math.max(0, base[1] - 14),
171 Math.max(0, base[2] - 14),
227 Math.max(0, base[0] - 12),
228 Math.max(0, base[1] - 12),
229 Math.max(0, base[2] - 12),
172 230 255
173 231 ];
174 232 }
@@ -189,186 +247,268 @@ function decodeMask (mask)
189 247 };
190 248 }
191 249
192 function frustumX0X1 (y, profile)
250 function aloneRowRange (alone, y)
193 251 {
194 if (y <= 2)
195 { return { x0: 6, x1: 9 }; }
196 if (y <= 4)
197 { return { x0: 5, x1: 10 }; }
198 if (y <= 6)
199 { return { x0: 4, x1: 11 }; }
200 return { x0: profile.baseX0, x1: profile.baseX1 };
252 let x0 = -1;
253 let x1 = -1;
254 for (let x = 0; x < SIZE; x++)
255 {
256 if (!opaque(alone, x, y))
257 { continue; }
258 if (x0 < 0)
259 { x0 = x; }
260 x1 = x;
261 }
262 return x0 < 0 ? null : { x0, x1 };
201 263 }
202 264
203 /** Top-plane strip-union + diagonal fills (no front skirt). */
204 function inTopPlane (x, y, c, profile)
265 function aloneColRange (alone, x)
205 266 {
206 const { coreX0, coreX1, coreY0, coreY1 } = profile;
207 const inCoreX = x >= coreX0 && x <= coreX1;
208 const inCoreY = y >= coreY0 && y <= coreY1;
209 const wantH = c.e || c.w;
210 const wantV = c.n || c.s;
267 let y0 = -1;
268 let y1 = -1;
269 for (let y = 0; y < SIZE; y++)
270 {
271 if (!opaque(alone, x, y))
272 { continue; }
273 if (y0 < 0)
274 { y0 = y; }
275 y1 = y;
276 }
277 return y0 < 0 ? null : { y0, y1 };
278 }
211 279
212 if (inCoreX && inCoreY)
213 { return true; }
280 function aloneBounds (alone)
281 {
282 let minX = SIZE;
283 let maxX = -1;
284 let minY = SIZE;
285 let maxY = -1;
286 for (let y = 0; y < SIZE; y++)
287 {
288 for (let x = 0; x < SIZE; x++)
289 {
290 if (!opaque(alone, x, y))
291 { continue; }
292 minX = Math.min(minX, x);
293 maxX = Math.max(maxX, x);
294 minY = Math.min(minY, y);
295 maxY = Math.max(maxY, y);
296 }
297 }
298 return { minX, maxX, minY, maxY };
299 }
300
301 /**
302 * Strip-union of alone rows (E/W extrusion) and alone columns (N/S extrusion),
303 * plus diagonal fills for solid 2×2 corners.
304 */
305 function thinOccupied (x, y, c, alone)
306 {
307 if (!c.n && !c.e && !c.s && !c.w)
308 { return opaque(alone, x, y); }
214 309
215 if (wantH && inCoreY)
310 const row = aloneRowRange(alone, y);
311 if (row && (c.e || c.w || opaque(alone, x, y)))
216 312 {
217 const x0 = c.w ? 0 : coreX0;
218 const x1 = c.e ? SIZE - 1 : coreX1;
313 const x0 = c.w ? 0 : row.x0;
314 const x1 = c.e ? SIZE - 1 : row.x1;
219 315 if (x >= x0 && x <= x1)
220 316 { return true; }
221 317 }
222 318
223 if (wantV && inCoreX)
319 const col = aloneColRange(alone, x);
320 if (col && (c.n || c.s || opaque(alone, x, y)))
224 321 {
225 const y0 = c.n ? 0 : coreY0;
226 const y1 = c.s ? SIZE - 1 : coreY1;
322 const y0 = c.n ? 0 : col.y0;
323 const y1 = c.s ? SIZE - 1 : col.y1;
227 324 if (y >= y0 && y <= y1)
228 325 { return true; }
229 326 }
230 327
231 // Close concave L/T cutouts when the diagonal neighbour is present.
232 if (c.se && c.s && c.e && x > coreX1 && y > coreY1)
328 if (opaque(alone, x, y))
329 { return true; }
330
331 const b = aloneBounds(alone);
332 // Diagonal fills close the concave cutout of an L/T.
333 if (c.se && c.s && c.e && x > b.maxX && y > b.maxY)
233 334 { return true; }
234 if (c.sw && c.s && c.w && x < coreX0 && y > coreY1)
335 if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
235 336 { return true; }
236 if (c.ne && c.n && c.e && x > coreX1 && y < coreY0)
337 if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
237 338 { return true; }
238 if (c.nw && c.n && c.w && x < coreX0 && y < coreY0)
339 if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
340 { return true; }
341
342 // Also fill the "inside" corner within the extruded AABB when diagonal joins
343 // (region east of alone footprint ∩ south of alone footprint, etc.).
344 if (c.se && c.s && c.e && x > b.maxX && y >= b.minY && y <= SIZE - 1 && x <= SIZE - 1)
345 {
346 // Only below the horizontal band's natural bottom is the true cutout;
347 // pixels with y in alone rows are already filled by E extrusion.
348 if (y > b.maxY)
349 { return true; }
350 }
351 if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
352 { return true; }
353 if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
354 { return true; }
355 if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
239 356 { return true; }
240 357
241 358 return false;
242 359 }
243 360
244 function inWall (x, y, c, profile)
361 /**
362 * Colour for a thin pixel: prefer alone, else east/west connecting template,
363 * else sample the nearest alone edge colour along the extrusion axis.
364 */
365 function thinColor (x, y, c, alone, east, west)
245 366 {
246 if (profile.fullTile)
247 { return true; }
248
249 const alone = !c.n && !c.e && !c.s && !c.w;
250 if (alone)
367 if (opaque(alone, x, y))
368 { return getPx(alone, x, y); }
369
370 if (c.e && !c.w && opaque(east, x, y))
371 { return getPx(east, x, y); }
372 if (c.w && !c.e && opaque(west, x, y))
373 { return getPx(west, x, y); }
374 if (c.e && c.w)
251 375 {
252 if (y < profile.topY0 || y > profile.faceY1)
253 { return false; }
254 const { x0, x1 } = frustumX0X1(y, profile);
255 return x >= x0 && x <= x1;
376 // Full E–W run: take interior colour from the east template at this y.
377 const row = aloneRowRange(alone, y);
378 if (row)
379 {
380 const sampleX = Math.min(SIZE - 1, row.x1);
381 const col = getPx(east, sampleX, y);
382 if (col[3] > 128)
383 { return col; }
384 return getPx(alone, sampleX, y);
385 }
256 386 }
257 387
258 if (inTopPlane(x, y, c, profile))
259 { return true; }
260
261 // Front-face skirt under top-plane pixels that do not continue south.
262 if (y > profile.coreY1 && y <= profile.faceY1)
388 // N/S extrusion: continue the colour of the alone column end.
389 const col = aloneColRange(alone, x);
390 if (col)
263 391 {
264 if (!inTopPlane(x, profile.coreY1, c, profile))
265 { return false; }
266 // Vertical run into a southern neighbour: no skirt in the core column.
267 if (c.s && x >= profile.coreX0 && x <= profile.coreX1)
268 { return false; }
269 // Diagonal-filled SE mass continues as solid top — skirt only at very bottom
270 // of columns that are the south perimeter (no further south neighbour top).
271 if (c.s && ((c.se && c.e && x > profile.coreX1) || (c.sw && c.w && x < profile.coreX0)))
272 { return false; }
273 const { x0, x1 } = frustumX0X1(y, profile);
274 const skirtX0 = c.w ? 0 : x0;
275 const skirtX1 = c.e ? SIZE - 1 : x1;
276 if (x < skirtX0 || x > skirtX1)
277 { return false; }
278 return inTopPlane(x, profile.coreY1, c, profile);
392 if (c.n && y < col.y0)
393 { return getPx(alone, x, col.y0); }
394 if (c.s && y > col.y1)
395 { return getPx(alone, x, col.y1); }
279 396 }
280 397
281 return false;
398 // Diagonal fill / extended cutout: pick nearest alone interior.
399 const b = aloneBounds(alone);
400 const sx = Math.min(b.maxX, Math.max(b.minX, x));
401 const sy = Math.min(b.maxY, Math.max(b.minY, y));
402 return getPx(alone, sx, sy);
282 403 }
283 404
284 function shadeAt (x, y, c, profile, occ)
405 /**
406 * Thick walls always fill the tile. Shading: start from alone; for each
407 * connected side, replace that edge's bevel with the extruded connecting look.
408 */
409 function thickColor (x, y, c, alone, east, west)
285 410 {
286 const n = occ(x, y - 1);
287 const e = occ(x + 1, y);
288 const s = occ(x, y + 1);
289 const w = occ(x - 1, y);
290
291 const openCount = (!n ? 1 : 0) + (!s ? 1 : 0) + (!e ? 1 : 0) + (!w ? 1 : 0);
292 if (openCount > 0)
411 // Build by compositing directional templates.
412 // Base = alone.
413 let color = getPx(alone, x, y);
414
415 const fromEast = opaque(east, x, y) ? getPx(east, x, y) : null;
416 const fromWest = opaque(west, x, y) ? getPx(west, x, y) : null;
417
418 // East connection: use east template where it differs from alone on the right half,
419 // or more simply — if only E: use east template entirely.
420 if (c.e && !c.w && !c.n && !c.s)
421 { return fromEast ?? color; }
422 if (c.w && !c.e && !c.n && !c.s)
423 { return fromWest ?? color; }
424
425 // General case: for each axis, prefer the connecting template's pixel when
426 // that side is connected and we're on the extruded side of the tile.
427 if (c.e && x >= 8 && fromEast)
428 { color = fromEast; }
429 if (c.w && x <= 7 && fromWest)
430 { color = fromWest; }
431
432 // North/south: extend the top/bottom band colours toward the edge.
433 if (c.n && y <= 2)
293 434 {
294 const edgeHeavy = (!n && y <= (profile.fullTile ? 0 : profile.topY0))
295 || (!s && y >= (profile.fullTile ? SIZE - 1 : profile.faceY1))
296 || (!w && x <= (profile.fullTile ? 0 : profile.baseX0))
297 || (!e && x >= (profile.fullTile ? SIZE - 1 : profile.baseX1));
298 if (edgeHeavy || openCount >= 2)
299 { return OUTLINE; }
435 // Sample the y=1 band from the appropriate horizontal template.
436 const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
437 color = getPx(src, x, 1);
438 }
439 if (c.s && y >= 13)
440 {
441 const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
442 color = getPx(src, x, 14);
300 443 }
301 444
302 if (profile.fullTile)
445 // Both E+W: full horizontal extrusion like two connecting halves.
446 if (c.e && c.w)
303 447 {
304 const freeN = !c.n;
305 const freeS = !c.s;
306 const freeW = !c.w;
307 const freeE = !c.e;
308 const openNe = c.n && c.e && !c.ne;
309 const openSe = c.s && c.e && !c.se;
310 const openSw = c.s && c.w && !c.sw;
311 const openNw = c.n && c.w && !c.nw;
312
313 if (y === 0 || x === 0 || x === SIZE - 1 || y === SIZE - 1)
314 { return OUTLINE; }
315 if ((freeW && x <= 2) || (openNw && x <= 2 && y <= 2) || (openSw && x <= 2 && y >= SIZE - 3))
316 { return FACE_L; }
317 if ((freeE && x >= SIZE - 3) || (openNe && x >= SIZE - 3 && y <= 2) || (openSe && x >= SIZE - 3 && y >= SIZE - 3))
318 { return FACE_R; }
319 if (freeN && y === 1)
320 { return TOP_HI; }
321 if (y <= 8 && x >= 3 && x <= 12)
322 { return TOP; }
323 if (freeS || y >= 10)
324 { return FACE_FRONT; }
325 return TOP_LO;
448 const left = getPx(west, Math.min(x, 7), y);
449 const right = getPx(east, Math.max(x, 8), y);
450 color = x <= 7 ? left : right;
326 451 }
327 452
328 if (y <= profile.coreY1)
453 // Open L corner (cardinals without diagonal): keep alone's outer-corner bevel
454 // in that quadrant. Filled diagonal: use connecting interior instead.
455 if (c.e && c.s && !c.se && x >= 12 && y >= 12)
456 { color = getPx(alone, x, y); }
457 if (c.e && c.s && c.se && x >= 12 && y >= 12)
458 { color = getPx(east, Math.min(15, x), Math.min(14, y)); }
459
460 if (c.w && c.s && !c.sw && x <= 3 && y >= 12)
461 { color = getPx(alone, x, y); }
462 if (c.w && c.s && c.sw && x <= 3 && y >= 12)
463 { color = getPx(west, Math.max(0, x), Math.min(14, y)); }
464
465 if (c.e && c.n && !c.ne && x >= 12 && y <= 3)
466 { color = getPx(alone, x, y); }
467 if (c.e && c.n && c.ne && x >= 12 && y <= 3)
468 { color = getPx(east, Math.min(15, x), Math.max(1, y)); }
469
470 if (c.w && c.n && !c.nw && x <= 3 && y <= 3)
471 { color = getPx(alone, x, y); }
472 if (c.w && c.n && c.nw && x <= 3 && y <= 3)
473 { color = getPx(west, Math.max(0, x), Math.max(1, y)); }
474
475 // Interior of solid block (all 4 + diagonals): flat top mid colour.
476 if (c.n && c.e && c.s && c.w && c.ne && c.se && c.sw && c.nw)
329 477 {
330 if (!n)
331 { return OUTLINE; }
332 if (!w)
333 { return HI_L; }
334 if (!e)
335 { return HI_R; }
336 return TOP;
478 if (x > 0 && x < SIZE - 1 && y > 0 && y < SIZE - 1)
479 { color = getPx(east, 8, 5); }
337 480 }
338 481
339 if (!s)
340 { return OUTLINE; }
341 if (!w)
342 { return HI_L; }
343 if (!e)
344 { return HI_R; }
345 return FACE;
482 return color;
346 483 }
347 484
348 function paintWall (mask, profile)
485 function paintThin (mask, alone, east, west)
349 486 {
350 const rgba = new Uint8Array(SIZE * SIZE * 4);
487 const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
351 488 const c = decodeMask(mask);
352 const occ = (x, y) =>
489 for (let y = 0; y < SIZE; y++)
353 490 {
354 if (x < 0)
355 { return c.w; }
356 if (x >= SIZE)
357 { return c.e; }
358 if (y < 0)
359 { return c.n; }
360 if (y >= SIZE)
361 { return c.s; }
362 return inWall(x, y, c, profile);
363 };
491 for (let x = 0; x < SIZE; x++)
492 {
493 if (!thinOccupied(x, y, c, alone))
494 { continue; }
495 const col = thinColor(x, y, c, alone, east, west);
496 setPx(rgba, x, y, cobbleShade(col, x, y));
497 }
498 }
499 return rgba;
500 }
364 501
502 function paintThick (mask, alone, east, west)
503 {
504 const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
505 const c = decodeMask(mask);
365 506 for (let y = 0; y < SIZE; y++)
366 507 {
367 508 for (let x = 0; x < SIZE; x++)
368 509 {
369 if (!occ(x, y))
370 { continue; }
371 setPx(rgba, x, y, cobbleShade(shadeAt(x, y, c, profile, occ), x, y));
510 const col = thickColor(x, y, c, alone, east, west);
511 setPx(rgba, x, y, cobbleShade(col, x, y));
372 512 }
373 513 }
374 514 return rgba;
@@ -385,16 +525,40 @@ function clearGenerated (dir)
385 525 }
386 526 }
387 527
388 function writeSet (dir, profile, label)
528 function writeSet (dir, paint, label)
389 529 {
390 530 clearGenerated(dir);
391 531 const masks = listValidNeighborConnectCornerMasks();
392 532 for (const mask of masks)
393 533 {
394 writeFileSync(join(dir, `${mask}.png`), encodePng(paintWall(mask, profile)));
534 writeFileSync(join(dir, `${mask}.png`), encodePng(paint(mask)));
395 535 }
396 536 console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
397 537 }
398 538
399 writeSet(OUT_THICK, THICK, "thick");
400 writeSet(OUT_THIN, THIN, "thin");
539 const thinAlone = decodePngRgba(join(EXAMPLES, "example-stone-thin.png"));
540 const thinEast = decodePngRgba(join(EXAMPLES, "example-stone-thin-connecting.png"));
541 const thinWest = mirrorX(thinEast);
542 const thickAlone = decodePngRgba(join(EXAMPLES, "example-stone-thick.png"));
543 const thickEast = decodePngRgba(join(EXAMPLES, "example-stone-thick-connecting.png"));
544 const thickWest = mirrorX(thickEast);
545
546 // Sanity: alone / east templates must decode to expected coverage.
547 const thinAloneCount = [...thinAlone].filter((_, i) => i % 4 === 3 && thinAlone[i] > 128).length;
548 const thinEastCount = [...thinEast].filter((_, i) => i % 4 === 3 && thinEast[i] > 128).length;
549 if (thinAloneCount < 80 || thinEastCount < 120)
550 {
551 throw new Error(`Example decode looks wrong (alone=${thinAloneCount}, east=${thinEastCount})`);
552 }
553
554 writeSet(OUT_THICK, (mask) => paintThick(mask, thickAlone, thickEast, thickWest), "thick");
555 writeSet(OUT_THIN, (mask) => paintThin(mask, thinAlone, thinEast, thinWest), "thin");
556
557 // Keep mask 0 / east-only (2) pixel-identical to examples (minus cobble speck on 0).
558 writeFileSync(join(OUT_THIN, "0.png"), encodePng(thinAlone));
559 writeFileSync(join(OUT_THICK, "0.png"), encodePng(thickAlone));
560 writeFileSync(join(OUT_THIN, "2.png"), encodePng(thinEast));
561 writeFileSync(join(OUT_THICK, "2.png"), encodePng(thickEast));
562 writeFileSync(join(OUT_THIN, "8.png"), encodePng(thinWest));
563 writeFileSync(join(OUT_THICK, "8.png"), encodePng(thickWest));
564 console.log("Pinned 0 / E / W templates to example pixels");
@@ -2,18 +2,19 @@
2 * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
2 * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
3 * (cardinals + diagonal corners — 47 valid states).
3 * (cardinals + diagonal corners — 47 valid states).
4 *
4 *
5 * Shape references (silhouette / shading only, not final texture):
5 * Shape sources (authoritative):
6 * client/assets/blocks/stone-wall/example-stone-thin.png
6 * example-stone-thin.png / example-stone-thin-connecting.png
7 * client/assets/blocks/stone-wall/example-stone-thick.png
7 * example-stone-thick.png / example-stone-thick-connecting.png
8 *
8 *
9 * Corner bits: when both adjacent cardinals join but the diagonal does not,
9 * Alone = free-standing frustum / bevelled block.
10 * paint an L-strip (concave). When the diagonal also joins, fill the quadrant
10 * *-connecting = same bands extruded to the east edge (free west end kept).
11 * so a solid 2×2 reads as one block.
11 * Other directions are mirrors / vertical extrusions of that rule.
12 * Diagonal bits fill the concave L cutout so solid 2×2 reads continuous.
12 *
13 *
13 * node client/scripts/generate-stone-wall-sprites.mjs
14 * node client/scripts/generate-stone-wall-sprites.mjs
14 */
15 */
15import { mkdirSync, writeFileSync, readdirSync, unlinkSync } from "node:fs";
16import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync } from "node:fs";
16import { deflateSync } from "node:zlib";
17import { deflateSync, inflateSync } from "node:zlib";
17import { fileURLToPath } from "node:url";
18import { fileURLToPath } from "node:url";
18import { dirname, join } from "node:path";
19import { dirname, join } from "node:path";
19import {
20import {
@@ -25,48 +26,10 @@ const SIZE = 16;
25const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
26const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
26const OUT_THICK = join(ROOT, "stone-wall");
27const OUT_THICK = join(ROOT, "stone-wall");
27const OUT_THIN = join(ROOT, "stone-wall-thin");
28const OUT_THIN = join(ROOT, "stone-wall-thin");
29const EXAMPLES = join(ROOT, "stone-wall");
28
30
29const OUTLINE = [0x40, 0x40, 0x40, 255];
30const TOP_HI = [0xaf, 0xaf, 0xaf, 255];
31const TOP = [0x80, 0x80, 0x80, 255];
32const TOP_LO = [0x73, 0x73, 0x73, 255];
33const FACE_L = [0x95, 0x95, 0x95, 255];
34const FACE = [0x73, 0x73, 0x73, 255];
35const FACE_R = [0x6c, 0x6c, 0x6c, 255];
36const FACE_FRONT = [0x54, 0x54, 0x54, 255];
37const HI_L = [0xb6, 0xb6, 0xb6, 255];
38const HI_R = [0x80, 0x80, 0x80, 255];
39const MORTAR = [0x58, 0x58, 0x5c, 255];
31const MORTAR = [0x58, 0x58, 0x5c, 255];
40
32
41/**
42 * Thin: compact top core (table-style strip-union) so L keeps a concave cutout;
43 * frustum face hangs below on free south edges. Alone matches example-stone-thin.
44 */
45const THIN = Object.freeze({
46 topY0: 2,
47 coreY0: 3,
48 coreY1: 7,
49 faceY1: 12,
50 coreX0: 5,
51 coreX1: 10,
52 baseX0: 3,
53 baseX1: 12,
54 fullTile: false
55});
56
57/** Thick: full-tile footprint; bevels react to free edges / missing diagonals. */
58const THICK = Object.freeze({
59 topY0: 1,
60 coreY0: 1,
61 coreY1: 8,
62 faceY1: 14,
63 coreX0: 3,
64 coreX1: 12,
65 baseX0: 0,
66 baseX1: 15,
67 fullTile: true
68});
69
70function crcTable ()
33function crcTable ()
71{
34{
72 const table = new Uint32Array(256);
35 const table = new Uint32Array(256);
@@ -130,6 +93,83 @@ function encodePng (rgba)
130 ]);
93 ]);
131}
94}
132
95
96/** Decode 8-bit RGBA PNG (with scanline filters) into Uint8ClampedArray. */
97function decodePngRgba (path)
98{
99 const buf = readFileSync(path);
100 let off = 8;
101 let w = 0;
102 let h = 0;
103 const idat = [];
104 while (off < buf.length)
105 {
106 const len = buf.readUInt32BE(off);
107 const type = buf.slice(off + 4, off + 8).toString("ascii");
108 const data = buf.slice(off + 8, off + 8 + len);
109 if (type === "IHDR")
110 {
111 w = data.readUInt32BE(0);
112 h = data.readUInt32BE(4);
113 if (data[8] !== 8 || data[9] !== 6)
114 { throw new Error(`${path}: expected 8-bit RGBA`); }
115 }
116 else if (type === "IDAT")
117 { idat.push(data); }
118 else if (type === "IEND")
119 { break; }
120 off += 12 + len;
121 }
122 const raw = inflateSync(Buffer.concat(idat));
123 const bpp = 4;
124 const stride = w * bpp;
125 const rgba = new Uint8ClampedArray(w * h * 4);
126 let src = 0;
127 const prev = Buffer.alloc(stride);
128 const cur = Buffer.alloc(stride);
129 for (let y = 0; y < h; y++)
130 {
131 const filter = raw[src++];
132 for (let i = 0; i < stride; i++)
133 { cur[i] = raw[src++]; }
134 for (let i = 0; i < stride; i++)
135 {
136 const left = i >= bpp ? cur[i - bpp] : 0;
137 const up = prev[i];
138 const upLeft = i >= bpp ? prev[i - bpp] : 0;
139 let val = cur[i];
140 if (filter === 1)
141 { val = (val + left) & 255; }
142 else if (filter === 2)
143 { val = (val + up) & 255; }
144 else if (filter === 3)
145 { val = (val + ((left + up) >> 1)) & 255; }
146 else if (filter === 4)
147 {
148 const p = left + up - upLeft;
149 const pa = Math.abs(p - left);
150 const pb = Math.abs(p - up);
151 const pc = Math.abs(p - upLeft);
152 const pr = (pa <= pb && pa <= pc) ? left : (pb <= pc ? up : upLeft);
153 val = (val + pr) & 255;
154 }
155 cur[i] = val;
156 }
157 rgba.set(cur, y * stride);
158 prev.set(cur);
159 }
160 if (w !== SIZE || h !== SIZE)
161 { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
162 return rgba;
163}
164
165function getPx (rgba, x, y)
166{
167 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
168 { return [0, 0, 0, 0]; }
169 const i = (y * SIZE + x) * 4;
170 return [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]];
171}
172
133function setPx (rgba, x, y, color)
173function setPx (rgba, x, y, color)
134{
174{
135 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
175 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
@@ -141,6 +181,22 @@ function setPx (rgba, x, y, color)
141 rgba[i + 3] = color[3];
181 rgba[i + 3] = color[3];
142}
182}
143
183
184function opaque (rgba, x, y)
185{
186 return getPx(rgba, x, y)[3] > 128;
187}
188
189function mirrorX (rgba)
190{
191 const out = new Uint8ClampedArray(rgba.length);
192 for (let y = 0; y < SIZE; y++)
193 {
194 for (let x = 0; x < SIZE; x++)
195 { setPx(out, x, y, getPx(rgba, SIZE - 1 - x, y)); }
196 }
197 return out;
198}
199
144function hash2 (x, y)
200function hash2 (x, y)
145{
201{
146 let n = (x * 374761393 + y * 668265263) | 0;
202 let n = (x * 374761393 + y * 668265263) | 0;
@@ -150,6 +206,8 @@ function hash2 (x, y)
150
206
151function cobbleShade (base, x, y)
207function cobbleShade (base, x, y)
152{
208{
209 if (base[3] < 128)
210 { return base; }
153 const h = hash2(x, y);
211 const h = hash2(x, y);
154 const speck = h & 7;
212 const speck = h & 7;
155 if (speck === 0)
213 if (speck === 0)
@@ -157,18 +215,18 @@ function cobbleShade (base, x, y)
157 if (speck === 1)
215 if (speck === 1)
158 {
216 {
159 return [
217 return [
160 Math.min(255, base[0] + 18),
218 Math.min(255, base[0] + 14),
161 Math.min(255, base[1] + 18),
219 Math.min(255, base[1] + 14),
162 Math.min(255, base[2] + 18),
220 Math.min(255, base[2] + 14),
163 255
221 255
164 ];
222 ];
165 }
223 }
166 if (speck === 2)
224 if (speck === 2)
167 {
225 {
168 return [
226 return [
169 Math.max(0, base[0] - 14),
227 Math.max(0, base[0] - 12),
170 Math.max(0, base[1] - 14),
228 Math.max(0, base[1] - 12),
171 Math.max(0, base[2] - 14),
229 Math.max(0, base[2] - 12),
172 255
230 255
173 ];
231 ];
174 }
232 }
@@ -189,186 +247,268 @@ function decodeMask (mask)
189 };
247 };
190}
248}
191
249
192function frustumX0X1 (y, profile)
250function aloneRowRange (alone, y)
193{
251{
194 if (y <= 2)
252 let x0 = -1;
195 { return { x0: 6, x1: 9 }; }
253 let x1 = -1;
196 if (y <= 4)
254 for (let x = 0; x < SIZE; x++)
197 { return { x0: 5, x1: 10 }; }
255 {
198 if (y <= 6)
256 if (!opaque(alone, x, y))
199 { return { x0: 4, x1: 11 }; }
257 { continue; }
200 return { x0: profile.baseX0, x1: profile.baseX1 };
258 if (x0 < 0)
259 { x0 = x; }
260 x1 = x;
261 }
262 return x0 < 0 ? null : { x0, x1 };
201}
263}
202
264
203/** Top-plane strip-union + diagonal fills (no front skirt). */
265function aloneColRange (alone, x)
204function inTopPlane (x, y, c, profile)
205{
266{
206 const { coreX0, coreX1, coreY0, coreY1 } = profile;
267 let y0 = -1;
207 const inCoreX = x >= coreX0 && x <= coreX1;
268 let y1 = -1;
208 const inCoreY = y >= coreY0 && y <= coreY1;
269 for (let y = 0; y < SIZE; y++)
209 const wantH = c.e || c.w;
270 {
210 const wantV = c.n || c.s;
271 if (!opaque(alone, x, y))
272 { continue; }
273 if (y0 < 0)
274 { y0 = y; }
275 y1 = y;
276 }
277 return y0 < 0 ? null : { y0, y1 };
278}
211
279
212 if (inCoreX && inCoreY)
280function aloneBounds (alone)
213 { return true; }
281{
282 let minX = SIZE;
283 let maxX = -1;
284 let minY = SIZE;
285 let maxY = -1;
286 for (let y = 0; y < SIZE; y++)
287 {
288 for (let x = 0; x < SIZE; x++)
289 {
290 if (!opaque(alone, x, y))
291 { continue; }
292 minX = Math.min(minX, x);
293 maxX = Math.max(maxX, x);
294 minY = Math.min(minY, y);
295 maxY = Math.max(maxY, y);
296 }
297 }
298 return { minX, maxX, minY, maxY };
299}
300
301/**
302 * Strip-union of alone rows (E/W extrusion) and alone columns (N/S extrusion),
303 * plus diagonal fills for solid 2×2 corners.
304 */
305function thinOccupied (x, y, c, alone)
306{
307 if (!c.n && !c.e && !c.s && !c.w)
308 { return opaque(alone, x, y); }
214
309
215 if (wantH && inCoreY)
310 const row = aloneRowRange(alone, y);
311 if (row && (c.e || c.w || opaque(alone, x, y)))
216 {
312 {
217 const x0 = c.w ? 0 : coreX0;
313 const x0 = c.w ? 0 : row.x0;
218 const x1 = c.e ? SIZE - 1 : coreX1;
314 const x1 = c.e ? SIZE - 1 : row.x1;
219 if (x >= x0 && x <= x1)
315 if (x >= x0 && x <= x1)
220 { return true; }
316 { return true; }
221 }
317 }
222
318
223 if (wantV && inCoreX)
319 const col = aloneColRange(alone, x);
320 if (col && (c.n || c.s || opaque(alone, x, y)))
224 {
321 {
225 const y0 = c.n ? 0 : coreY0;
322 const y0 = c.n ? 0 : col.y0;
226 const y1 = c.s ? SIZE - 1 : coreY1;
323 const y1 = c.s ? SIZE - 1 : col.y1;
227 if (y >= y0 && y <= y1)
324 if (y >= y0 && y <= y1)
228 { return true; }
325 { return true; }
229 }
326 }
230
327
231 // Close concave L/T cutouts when the diagonal neighbour is present.
328 if (opaque(alone, x, y))
232 if (c.se && c.s && c.e && x > coreX1 && y > coreY1)
329 { return true; }
330
331 const b = aloneBounds(alone);
332 // Diagonal fills close the concave cutout of an L/T.
333 if (c.se && c.s && c.e && x > b.maxX && y > b.maxY)
233 { return true; }
334 { return true; }
234 if (c.sw && c.s && c.w && x < coreX0 && y > coreY1)
335 if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
235 { return true; }
336 { return true; }
236 if (c.ne && c.n && c.e && x > coreX1 && y < coreY0)
337 if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
237 { return true; }
338 { return true; }
238 if (c.nw && c.n && c.w && x < coreX0 && y < coreY0)
339 if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
340 { return true; }
341
342 // Also fill the "inside" corner within the extruded AABB when diagonal joins
343 // (region east of alone footprint ∩ south of alone footprint, etc.).
344 if (c.se && c.s && c.e && x > b.maxX && y >= b.minY && y <= SIZE - 1 && x <= SIZE - 1)
345 {
346 // Only below the horizontal band's natural bottom is the true cutout;
347 // pixels with y in alone rows are already filled by E extrusion.
348 if (y > b.maxY)
349 { return true; }
350 }
351 if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
352 { return true; }
353 if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
354 { return true; }
355 if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
239 { return true; }
356 { return true; }
240
357
241 return false;
358 return false;
242}
359}
243
360
244function inWall (x, y, c, profile)
361/**
362 * Colour for a thin pixel: prefer alone, else east/west connecting template,
363 * else sample the nearest alone edge colour along the extrusion axis.
364 */
365function thinColor (x, y, c, alone, east, west)
245{
366{
246 if (profile.fullTile)
367 if (opaque(alone, x, y))
247 { return true; }
368 { return getPx(alone, x, y); }
248
369
249 const alone = !c.n && !c.e && !c.s && !c.w;
370 if (c.e && !c.w && opaque(east, x, y))
250 if (alone)
371 { return getPx(east, x, y); }
372 if (c.w && !c.e && opaque(west, x, y))
373 { return getPx(west, x, y); }
374 if (c.e && c.w)
251 {
375 {
252 if (y < profile.topY0 || y > profile.faceY1)
376 // Full E–W run: take interior colour from the east template at this y.
253 { return false; }
377 const row = aloneRowRange(alone, y);
254 const { x0, x1 } = frustumX0X1(y, profile);
378 if (row)
255 return x >= x0 && x <= x1;
379 {
380 const sampleX = Math.min(SIZE - 1, row.x1);
381 const col = getPx(east, sampleX, y);
382 if (col[3] > 128)
383 { return col; }
384 return getPx(alone, sampleX, y);
385 }
256 }
386 }
257
387
258 if (inTopPlane(x, y, c, profile))
388 // N/S extrusion: continue the colour of the alone column end.
259 { return true; }
389 const col = aloneColRange(alone, x);
260
390 if (col)
261 // Front-face skirt under top-plane pixels that do not continue south.
262 if (y > profile.coreY1 && y <= profile.faceY1)
263 {
391 {
264 if (!inTopPlane(x, profile.coreY1, c, profile))
392 if (c.n && y < col.y0)
265 { return false; }
393 { return getPx(alone, x, col.y0); }
266 // Vertical run into a southern neighbour: no skirt in the core column.
394 if (c.s && y > col.y1)
267 if (c.s && x >= profile.coreX0 && x <= profile.coreX1)
395 { return getPx(alone, x, col.y1); }
268 { return false; }
269 // Diagonal-filled SE mass continues as solid top — skirt only at very bottom
270 // of columns that are the south perimeter (no further south neighbour top).
271 if (c.s && ((c.se && c.e && x > profile.coreX1) || (c.sw && c.w && x < profile.coreX0)))
272 { return false; }
273 const { x0, x1 } = frustumX0X1(y, profile);
274 const skirtX0 = c.w ? 0 : x0;
275 const skirtX1 = c.e ? SIZE - 1 : x1;
276 if (x < skirtX0 || x > skirtX1)
277 { return false; }
278 return inTopPlane(x, profile.coreY1, c, profile);
279 }
396 }
280
397
281 return false;
398 // Diagonal fill / extended cutout: pick nearest alone interior.
399 const b = aloneBounds(alone);
400 const sx = Math.min(b.maxX, Math.max(b.minX, x));
401 const sy = Math.min(b.maxY, Math.max(b.minY, y));
402 return getPx(alone, sx, sy);
282}
403}
283
404
284function shadeAt (x, y, c, profile, occ)
405/**
406 * Thick walls always fill the tile. Shading: start from alone; for each
407 * connected side, replace that edge's bevel with the extruded connecting look.
408 */
409function thickColor (x, y, c, alone, east, west)
285{
410{
286 const n = occ(x, y - 1);
411 // Build by compositing directional templates.
287 const e = occ(x + 1, y);
412 // Base = alone.
288 const s = occ(x, y + 1);
413 let color = getPx(alone, x, y);
289 const w = occ(x - 1, y);
414
290
415 const fromEast = opaque(east, x, y) ? getPx(east, x, y) : null;
291 const openCount = (!n ? 1 : 0) + (!s ? 1 : 0) + (!e ? 1 : 0) + (!w ? 1 : 0);
416 const fromWest = opaque(west, x, y) ? getPx(west, x, y) : null;
292 if (openCount > 0)
417
418 // East connection: use east template where it differs from alone on the right half,
419 // or more simply — if only E: use east template entirely.
420 if (c.e && !c.w && !c.n && !c.s)
421 { return fromEast ?? color; }
422 if (c.w && !c.e && !c.n && !c.s)
423 { return fromWest ?? color; }
424
425 // General case: for each axis, prefer the connecting template's pixel when
426 // that side is connected and we're on the extruded side of the tile.
427 if (c.e && x >= 8 && fromEast)
428 { color = fromEast; }
429 if (c.w && x <= 7 && fromWest)
430 { color = fromWest; }
431
432 // North/south: extend the top/bottom band colours toward the edge.
433 if (c.n && y <= 2)
293 {
434 {
294 const edgeHeavy = (!n && y <= (profile.fullTile ? 0 : profile.topY0))
435 // Sample the y=1 band from the appropriate horizontal template.
295 || (!s && y >= (profile.fullTile ? SIZE - 1 : profile.faceY1))
436 const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
296 || (!w && x <= (profile.fullTile ? 0 : profile.baseX0))
437 color = getPx(src, x, 1);
297 || (!e && x >= (profile.fullTile ? SIZE - 1 : profile.baseX1));
438 }
298 if (edgeHeavy || openCount >= 2)
439 if (c.s && y >= 13)
299 { return OUTLINE; }
440 {
441 const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
442 color = getPx(src, x, 14);
300 }
443 }
301
444
302 if (profile.fullTile)
445 // Both E+W: full horizontal extrusion like two connecting halves.
446 if (c.e && c.w)
303 {
447 {
304 const freeN = !c.n;
448 const left = getPx(west, Math.min(x, 7), y);
305 const freeS = !c.s;
449 const right = getPx(east, Math.max(x, 8), y);
306 const freeW = !c.w;
450 color = x <= 7 ? left : right;
307 const freeE = !c.e;
308 const openNe = c.n && c.e && !c.ne;
309 const openSe = c.s && c.e && !c.se;
310 const openSw = c.s && c.w && !c.sw;
311 const openNw = c.n && c.w && !c.nw;
312
313 if (y === 0 || x === 0 || x === SIZE - 1 || y === SIZE - 1)
314 { return OUTLINE; }
315 if ((freeW && x <= 2) || (openNw && x <= 2 && y <= 2) || (openSw && x <= 2 && y >= SIZE - 3))
316 { return FACE_L; }
317 if ((freeE && x >= SIZE - 3) || (openNe && x >= SIZE - 3 && y <= 2) || (openSe && x >= SIZE - 3 && y >= SIZE - 3))
318 { return FACE_R; }
319 if (freeN && y === 1)
320 { return TOP_HI; }
321 if (y <= 8 && x >= 3 && x <= 12)
322 { return TOP; }
323 if (freeS || y >= 10)
324 { return FACE_FRONT; }
325 return TOP_LO;
326 }
451 }
327
452
328 if (y <= profile.coreY1)
453 // Open L corner (cardinals without diagonal): keep alone's outer-corner bevel
454 // in that quadrant. Filled diagonal: use connecting interior instead.
455 if (c.e && c.s && !c.se && x >= 12 && y >= 12)
456 { color = getPx(alone, x, y); }
457 if (c.e && c.s && c.se && x >= 12 && y >= 12)
458 { color = getPx(east, Math.min(15, x), Math.min(14, y)); }
459
460 if (c.w && c.s && !c.sw && x <= 3 && y >= 12)
461 { color = getPx(alone, x, y); }
462 if (c.w && c.s && c.sw && x <= 3 && y >= 12)
463 { color = getPx(west, Math.max(0, x), Math.min(14, y)); }
464
465 if (c.e && c.n && !c.ne && x >= 12 && y <= 3)
466 { color = getPx(alone, x, y); }
467 if (c.e && c.n && c.ne && x >= 12 && y <= 3)
468 { color = getPx(east, Math.min(15, x), Math.max(1, y)); }
469
470 if (c.w && c.n && !c.nw && x <= 3 && y <= 3)
471 { color = getPx(alone, x, y); }
472 if (c.w && c.n && c.nw && x <= 3 && y <= 3)
473 { color = getPx(west, Math.max(0, x), Math.max(1, y)); }
474
475 // Interior of solid block (all 4 + diagonals): flat top mid colour.
476 if (c.n && c.e && c.s && c.w && c.ne && c.se && c.sw && c.nw)
329 {
477 {
330 if (!n)
478 if (x > 0 && x < SIZE - 1 && y > 0 && y < SIZE - 1)
331 { return OUTLINE; }
479 { color = getPx(east, 8, 5); }
332 if (!w)
333 { return HI_L; }
334 if (!e)
335 { return HI_R; }
336 return TOP;
337 }
480 }
338
481
339 if (!s)
482 return color;
340 { return OUTLINE; }
341 if (!w)
342 { return HI_L; }
343 if (!e)
344 { return HI_R; }
345 return FACE;
346}
483}
347
484
348function paintWall (mask, profile)
485function paintThin (mask, alone, east, west)
349{
486{
350 const rgba = new Uint8Array(SIZE * SIZE * 4);
487 const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
351 const c = decodeMask(mask);
488 const c = decodeMask(mask);
352 const occ = (x, y) =>
489 for (let y = 0; y < SIZE; y++)
353 {
490 {
354 if (x < 0)
491 for (let x = 0; x < SIZE; x++)
355 { return c.w; }
492 {
356 if (x >= SIZE)
493 if (!thinOccupied(x, y, c, alone))
357 { return c.e; }
494 { continue; }
358 if (y < 0)
495 const col = thinColor(x, y, c, alone, east, west);
359 { return c.n; }
496 setPx(rgba, x, y, cobbleShade(col, x, y));
360 if (y >= SIZE)
497 }
361 { return c.s; }
498 }
362 return inWall(x, y, c, profile);
499 return rgba;
363 };
500}
364
501
502function paintThick (mask, alone, east, west)
503{
504 const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
505 const c = decodeMask(mask);
365 for (let y = 0; y < SIZE; y++)
506 for (let y = 0; y < SIZE; y++)
366 {
507 {
367 for (let x = 0; x < SIZE; x++)
508 for (let x = 0; x < SIZE; x++)
368 {
509 {
369 if (!occ(x, y))
510 const col = thickColor(x, y, c, alone, east, west);
370 { continue; }
511 setPx(rgba, x, y, cobbleShade(col, x, y));
371 setPx(rgba, x, y, cobbleShade(shadeAt(x, y, c, profile, occ), x, y));
372 }
512 }
373 }
513 }
374 return rgba;
514 return rgba;
@@ -385,16 +525,40 @@ function clearGenerated (dir)
385 }
525 }
386}
526}
387
527
388function writeSet (dir, profile, label)
528function writeSet (dir, paint, label)
389{
529{
390 clearGenerated(dir);
530 clearGenerated(dir);
391 const masks = listValidNeighborConnectCornerMasks();
531 const masks = listValidNeighborConnectCornerMasks();
392 for (const mask of masks)
532 for (const mask of masks)
393 {
533 {
394 writeFileSync(join(dir, `${mask}.png`), encodePng(paintWall(mask, profile)));
534 writeFileSync(join(dir, `${mask}.png`), encodePng(paint(mask)));
395 }
535 }
396 console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
536 console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
397}
537}
398
538
399writeSet(OUT_THICK, THICK, "thick");
539const thinAlone = decodePngRgba(join(EXAMPLES, "example-stone-thin.png"));
400writeSet(OUT_THIN, THIN, "thin");
540const thinEast = decodePngRgba(join(EXAMPLES, "example-stone-thin-connecting.png"));
541const thinWest = mirrorX(thinEast);
542const thickAlone = decodePngRgba(join(EXAMPLES, "example-stone-thick.png"));
543const thickEast = decodePngRgba(join(EXAMPLES, "example-stone-thick-connecting.png"));
544const thickWest = mirrorX(thickEast);
545
546// Sanity: alone / east templates must decode to expected coverage.
547const thinAloneCount = [...thinAlone].filter((_, i) => i % 4 === 3 && thinAlone[i] > 128).length;
548const thinEastCount = [...thinEast].filter((_, i) => i % 4 === 3 && thinEast[i] > 128).length;
549if (thinAloneCount < 80 || thinEastCount < 120)
550{
551 throw new Error(`Example decode looks wrong (alone=${thinAloneCount}, east=${thinEastCount})`);
552}
553
554writeSet(OUT_THICK, (mask) => paintThick(mask, thickAlone, thickEast, thickWest), "thick");
555writeSet(OUT_THIN, (mask) => paintThin(mask, thinAlone, thinEast, thinWest), "thin");
556
557// Keep mask 0 / east-only (2) pixel-identical to examples (minus cobble speck on 0).
558writeFileSync(join(OUT_THIN, "0.png"), encodePng(thinAlone));
559writeFileSync(join(OUT_THICK, "0.png"), encodePng(thickAlone));
560writeFileSync(join(OUT_THIN, "2.png"), encodePng(thinEast));
561writeFileSync(join(OUT_THICK, "2.png"), encodePng(thickEast));
562writeFileSync(join(OUT_THIN, "8.png"), encodePng(thinWest));
563writeFileSync(join(OUT_THICK, "8.png"), encodePng(thickWest));
564console.log("Pinned 0 / E / W templates to example pixels");