@holtjs/craft 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +63 -2
- package/dist/atlas-Pc12eQsg.js +112 -0
- package/dist/atlas.d.ts +75 -0
- package/dist/atlas.js +1 -0
- package/dist/index.d.ts +154 -0
- package/dist/index.js +14 -0
- package/dist/inspect-NzY8Ac1j.js +466 -0
- package/dist/inspect.d.ts +36 -0
- package/dist/inspect.js +1 -0
- package/dist/pixel-D3jgByB5.js +728 -0
- package/dist/pixel.d.ts +79 -0
- package/dist/pixel.js +1 -0
- package/dist/rig3d-C3i7UL88.js +7257 -0
- package/dist/rig3d-DhTgbTbX.d.ts +605 -0
- package/dist/rig3d.d.ts +2 -0
- package/dist/rig3d.js +2 -0
- package/dist/tilemap-BFH4_JLe.js +266 -0
- package/dist/tilemap.d.ts +61 -0
- package/dist/tilemap.js +1 -0
- package/llms.txt +16 -0
- package/package.json +71 -4
- package/skills/craft/SKILL.md +93 -0
- package/skills/craft/references/subpaths.md +32 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { i as derivePixelRamp, o as mixRgb, s as parseHexRgb, t as PixelCanvas, u as __exportAll } from "./pixel-D3jgByB5.js";
|
|
2
|
+
// src/tilemap.ts
|
|
3
|
+
var tilemap_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
BLOB47_CANONICAL_MASKS: () => BLOB47_CANONICAL_MASKS,
|
|
5
|
+
bakeNormalMapRgba: () => bakeNormalMapRgba,
|
|
6
|
+
bakePixelBlob47Sheet: () => bakePixelBlob47Sheet,
|
|
7
|
+
bakePixelDualGridSheet: () => bakePixelDualGridSheet,
|
|
8
|
+
computeBlob47Index: () => computeBlob47Index,
|
|
9
|
+
computeDualGridMask: () => computeDualGridMask
|
|
10
|
+
});
|
|
11
|
+
function hash2D(ix, iy, seed) {
|
|
12
|
+
let h = ix * 374761393 + iy * 668265263 + seed * 0x55fdc781 | 0;
|
|
13
|
+
h = Math.imul(h ^ h >>> 13, 0x4bf19f61);
|
|
14
|
+
return ((h ^ h >>> 16) >>> 0) / 4294967296;
|
|
15
|
+
}
|
|
16
|
+
/** Oskar Stålberg 4-corner Dual-Grid mask (`bit0=TL, bit1=TR, bit2=BL, bit3=BR` -> `0..15`). */
|
|
17
|
+
function computeDualGridMask(tl, tr, bl, br) {
|
|
18
|
+
return (tl ? 1 : 0) | (tr ? 2 : 0) | (bl ? 4 : 0) | (br ? 8 : 0);
|
|
19
|
+
}
|
|
20
|
+
/** Canonical 47-tile Blob bitmasks (`N=1, NE=2, E=4, SE=8, S=16, SW=32, W=64, NW=128` with diagonal gating). */
|
|
21
|
+
const BLOB47_CANONICAL_MASKS = (() => {
|
|
22
|
+
const set = /* @__PURE__ */ new Set();
|
|
23
|
+
for (let m = 0; m < 256; m++) {
|
|
24
|
+
const n = (m & 1) !== 0, e = (m & 4) !== 0, s = (m & 16) !== 0, w = (m & 64) !== 0;
|
|
25
|
+
let gm = (n ? 1 : 0) | (e ? 4 : 0) | (s ? 16 : 0) | (w ? 64 : 0);
|
|
26
|
+
if (n && e && m & 2) gm |= 2;
|
|
27
|
+
if (s && e && m & 8) gm |= 8;
|
|
28
|
+
if (s && w && m & 32) gm |= 32;
|
|
29
|
+
if (n && w && m & 128) gm |= 128;
|
|
30
|
+
set.add(gm);
|
|
31
|
+
}
|
|
32
|
+
return Array.from(set).sort((a, b) => a - b);
|
|
33
|
+
})();
|
|
34
|
+
const BLOB47_LOOKUP = (() => {
|
|
35
|
+
const map = /* @__PURE__ */ new Map();
|
|
36
|
+
BLOB47_CANONICAL_MASKS.forEach((m, idx) => map.set(m, idx));
|
|
37
|
+
return map;
|
|
38
|
+
})();
|
|
39
|
+
function computeBlob47Index(n, ne, e, se, s, sw, w, nw) {
|
|
40
|
+
let gm = (n ? 1 : 0) | (e ? 4 : 0) | (s ? 16 : 0) | (w ? 64 : 0);
|
|
41
|
+
if (n && e && ne) gm |= 2;
|
|
42
|
+
if (s && e && se) gm |= 8;
|
|
43
|
+
if (s && w && sw) gm |= 32;
|
|
44
|
+
if (n && w && nw) gm |= 128;
|
|
45
|
+
return BLOB47_LOOKUP.get(gm) ?? 0;
|
|
46
|
+
}
|
|
47
|
+
/** Bake a tangent-space 3x3 Sobel normal map (`RGBA`) from pixel luminance + alpha silhouette height. */
|
|
48
|
+
function bakeNormalMapRgba(rgba, width, height, opts) {
|
|
49
|
+
const strength = opts?.strength ?? 2.4;
|
|
50
|
+
const alphaWeight = opts?.alphaWeight ?? .65;
|
|
51
|
+
const out = new Uint8ClampedArray(width * height * 4);
|
|
52
|
+
const hMap = new Float32Array(width * height);
|
|
53
|
+
for (let i = 0, p = 0; i < hMap.length; i++, p += 4) {
|
|
54
|
+
const a = rgba[p + 3] / 255;
|
|
55
|
+
const lum = (rgba[p] * .299 + rgba[p + 1] * .587 + rgba[p + 2] * .114) / 255;
|
|
56
|
+
hMap[i] = a * (alphaWeight + (1 - alphaWeight) * lum);
|
|
57
|
+
}
|
|
58
|
+
const sampleH = (x, y) => {
|
|
59
|
+
const cx = Math.max(0, Math.min(width - 1, x));
|
|
60
|
+
const cy = Math.max(0, Math.min(height - 1, y));
|
|
61
|
+
return hMap[cy * width + cx];
|
|
62
|
+
};
|
|
63
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
64
|
+
const o = (y * width + x) * 4;
|
|
65
|
+
if (rgba[o + 3] === 0) {
|
|
66
|
+
out[o] = 128;
|
|
67
|
+
out[o + 1] = 128;
|
|
68
|
+
out[o + 2] = 255;
|
|
69
|
+
out[o + 3] = 0;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const tl = sampleH(x - 1, y - 1), t = sampleH(x, y - 1), tr = sampleH(x + 1, y - 1);
|
|
73
|
+
const l = sampleH(x - 1, y), r = sampleH(x + 1, y);
|
|
74
|
+
const bl = sampleH(x - 1, y + 1), b = sampleH(x, y + 1), br = sampleH(x + 1, y + 1);
|
|
75
|
+
const dx = tr + 2 * r + br - (tl + 2 * l + bl);
|
|
76
|
+
const dy = bl + 2 * b + br - (tl + 2 * t + tr);
|
|
77
|
+
let nx = -dx * strength;
|
|
78
|
+
let ny = -dy * strength;
|
|
79
|
+
let nz = 1;
|
|
80
|
+
const len = Math.hypot(nx, ny, nz) || 1;
|
|
81
|
+
nx /= len;
|
|
82
|
+
ny /= len;
|
|
83
|
+
nz /= len;
|
|
84
|
+
out[o] = Math.round((nx * .5 + .5) * 255);
|
|
85
|
+
out[o + 1] = Math.round((ny * .5 + .5) * 255);
|
|
86
|
+
out[o + 2] = Math.round((nz * .5 + .5) * 255);
|
|
87
|
+
out[o + 3] = rgba[o + 3];
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
function sampleStyleTexel(style, px, py, ramp, seed) {
|
|
92
|
+
const n = hash2D(px, py, seed);
|
|
93
|
+
if (style === "cobble") {
|
|
94
|
+
const row = Math.floor(py / 6);
|
|
95
|
+
const shift = (row & 1) * 4;
|
|
96
|
+
const lx = (px + shift) % 8;
|
|
97
|
+
const ly = py % 6;
|
|
98
|
+
if (ly === 0 || lx === 0) return ramp[3];
|
|
99
|
+
if (ly === 1 && lx < 6) return ramp[0];
|
|
100
|
+
if (ly === 5 || lx === 7) return ramp[2];
|
|
101
|
+
const stoneTone = hash2D(Math.floor((px + shift) / 8), row, seed + 17);
|
|
102
|
+
return stoneTone > .65 ? mixRgb(ramp[1], ramp[0], .25) : stoneTone < .28 ? mixRgb(ramp[1], ramp[2], .28) : ramp[1];
|
|
103
|
+
}
|
|
104
|
+
if (style === "stone_brick") {
|
|
105
|
+
const lx = (px + (Math.floor(py / 8) & 1) * 8) % 16;
|
|
106
|
+
const ly = py % 8;
|
|
107
|
+
if (ly === 0 || lx === 0) return ramp[3];
|
|
108
|
+
if (ly === 1) return ramp[0];
|
|
109
|
+
if (ly === 7) return ramp[2];
|
|
110
|
+
return n > .82 ? ramp[2] : ramp[1];
|
|
111
|
+
}
|
|
112
|
+
if (style === "grass") {
|
|
113
|
+
const tuft = hash2D(px >> 1, py >> 2, seed + 31);
|
|
114
|
+
if (tuft > .76 && (py & 3) < 2) return ramp[0];
|
|
115
|
+
if (tuft < .2 && (py & 3) >= 2) return ramp[2];
|
|
116
|
+
return n > .62 ? mixRgb(ramp[1], ramp[0], .18) : ramp[1];
|
|
117
|
+
}
|
|
118
|
+
if (style === "water") {
|
|
119
|
+
if (Math.sin(px * .45 + (py >> 2) * 1.7) > .82 && py % 5 === 1) return ramp[0];
|
|
120
|
+
return n > .55 ? ramp[1] : mixRgb(ramp[1], ramp[2], .22);
|
|
121
|
+
}
|
|
122
|
+
if (n > .9) return ramp[0];
|
|
123
|
+
if (n < .12) return ramp[2];
|
|
124
|
+
return ramp[1];
|
|
125
|
+
}
|
|
126
|
+
function evalDualGridInside(mask, u, v) {
|
|
127
|
+
const tl = mask & 1 ? 1 : 0;
|
|
128
|
+
const tr = mask & 2 ? 1 : 0;
|
|
129
|
+
const bl = mask & 4 ? 1 : 0;
|
|
130
|
+
const br = mask & 8 ? 1 : 0;
|
|
131
|
+
const top = tl * (1 - u) + tr * u;
|
|
132
|
+
const bot = bl * (1 - u) + br * u;
|
|
133
|
+
return top * (1 - v) + bot * v;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Bake a 16-tile (`4x4` grid) Oskar Stålberg Dual-Grid pixel-art tileset with rich surface micro-texture,
|
|
137
|
+
* 1px sunlit/shaded transition bevels, and optional 3x3 Sobel normal map for `@holtjs/stage`.
|
|
138
|
+
*/
|
|
139
|
+
function bakePixelDualGridSheet(spec) {
|
|
140
|
+
const ts = Math.max(8, Math.floor(spec.tileSize ?? 32));
|
|
141
|
+
const cols = 4, rows = 4;
|
|
142
|
+
const width = ts * cols, height = ts * rows;
|
|
143
|
+
const canvas = new PixelCanvas(width, height);
|
|
144
|
+
const ramp = derivePixelRamp(spec.baseColor);
|
|
145
|
+
const bgRgb = spec.backgroundColor ? parseHexRgb(spec.backgroundColor) : null;
|
|
146
|
+
const style = spec.style ?? "grass";
|
|
147
|
+
const seed = spec.seed ?? 1337;
|
|
148
|
+
const frames = [];
|
|
149
|
+
for (let mask = 0; mask < 16; mask++) {
|
|
150
|
+
const ox = mask % cols * ts;
|
|
151
|
+
const oy = Math.floor(mask / cols) * ts;
|
|
152
|
+
frames.push({
|
|
153
|
+
index: mask,
|
|
154
|
+
mask,
|
|
155
|
+
x: ox,
|
|
156
|
+
y: oy,
|
|
157
|
+
w: ts,
|
|
158
|
+
h: ts
|
|
159
|
+
});
|
|
160
|
+
for (let ly = 0; ly < ts; ly++) {
|
|
161
|
+
const v = (ly + .5) / ts;
|
|
162
|
+
for (let lx = 0; lx < ts; lx++) {
|
|
163
|
+
const u = (lx + .5) / ts;
|
|
164
|
+
const jitter = (hash2D(lx, ly, seed + mask * 7) - .5) * .06;
|
|
165
|
+
if (evalDualGridInside(mask, u, v) + jitter >= .5) {
|
|
166
|
+
const fUp = evalDualGridInside(mask, u, Math.max(0, v - 1.2 / ts));
|
|
167
|
+
const fDn = evalDualGridInside(mask, u, Math.min(1, v + 1.2 / ts));
|
|
168
|
+
const fLf = evalDualGridInside(mask, Math.max(0, u - 1.2 / ts), v);
|
|
169
|
+
const fRt = evalDualGridInside(mask, Math.min(1, u + 1.2 / ts), v);
|
|
170
|
+
if (fDn < .5 || fRt < .5) canvas.setPixel(ox + lx, oy + ly, ramp[3], 255);
|
|
171
|
+
else if (fUp < .5 || fLf < .5) canvas.setPixel(ox + lx, oy + ly, ramp[0], 255);
|
|
172
|
+
else canvas.setPixel(ox + lx, oy + ly, sampleStyleTexel(style, lx, ly, ramp, seed), 255);
|
|
173
|
+
} else if (bgRgb) canvas.setPixel(ox + lx, oy + ly, bgRgb, 255);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const normalRgba = spec.bakeNormals !== false ? bakeNormalMapRgba(canvas.rgba, width, height, { strength: spec.normalStrength ?? 2.6 }) : void 0;
|
|
178
|
+
return {
|
|
179
|
+
id: spec.id,
|
|
180
|
+
width,
|
|
181
|
+
height,
|
|
182
|
+
tileSize: ts,
|
|
183
|
+
columns: cols,
|
|
184
|
+
rows,
|
|
185
|
+
tileCount: 16,
|
|
186
|
+
rgba: canvas.rgba,
|
|
187
|
+
...normalRgba ? { normalRgba } : {},
|
|
188
|
+
frames
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Bake a 47-tile (`8x6` grid) Blob autotile spritesheet for stone graveyard walls, wrought-iron fences,
|
|
193
|
+
* or wooden palisades with top cap highlights, front-face masonry, and paired normal map.
|
|
194
|
+
*/
|
|
195
|
+
function bakePixelBlob47Sheet(spec) {
|
|
196
|
+
const ts = Math.max(12, Math.floor(spec.tileSize ?? 32));
|
|
197
|
+
const cols = 8, rows = 6;
|
|
198
|
+
const width = ts * cols, height = ts * rows;
|
|
199
|
+
const canvas = new PixelCanvas(width, height);
|
|
200
|
+
const capRamp = derivePixelRamp(spec.capColor);
|
|
201
|
+
const faceRamp = derivePixelRamp(spec.faceColor ?? rgbShiftDarker(spec.capColor));
|
|
202
|
+
const style = spec.style ?? "stone_wall";
|
|
203
|
+
const seed = spec.seed ?? 2026;
|
|
204
|
+
const frames = [];
|
|
205
|
+
const half = ts * .5;
|
|
206
|
+
const barHalf = style === "iron_fence" ? Math.max(2, Math.round(ts * .12)) : Math.max(4, Math.round(ts * .24));
|
|
207
|
+
for (let idx = 0; idx < BLOB47_CANONICAL_MASKS.length; idx++) {
|
|
208
|
+
const mask = BLOB47_CANONICAL_MASKS[idx];
|
|
209
|
+
const ox = idx % cols * ts;
|
|
210
|
+
const oy = Math.floor(idx / cols) * ts;
|
|
211
|
+
frames.push({
|
|
212
|
+
index: idx,
|
|
213
|
+
mask,
|
|
214
|
+
x: ox,
|
|
215
|
+
y: oy,
|
|
216
|
+
w: ts,
|
|
217
|
+
h: ts
|
|
218
|
+
});
|
|
219
|
+
const n = (mask & 1) !== 0, e = (mask & 4) !== 0, s = (mask & 16) !== 0, w = (mask & 64) !== 0;
|
|
220
|
+
const tile = new PixelCanvas(ts, ts);
|
|
221
|
+
tile.fillRect(half - barHalf, half - barHalf, barHalf * 2, barHalf * 2, capRamp[1]);
|
|
222
|
+
if (n) tile.fillRect(half - barHalf, 0, barHalf * 2, half, capRamp[1]);
|
|
223
|
+
if (s) tile.fillRect(half - barHalf, half, barHalf * 2, half, capRamp[1]);
|
|
224
|
+
if (w) tile.fillRect(0, half - barHalf, half, barHalf * 2, capRamp[1]);
|
|
225
|
+
if (e) tile.fillRect(half, half - barHalf, half, barHalf * 2, capRamp[1]);
|
|
226
|
+
const skirtH = Math.max(3, Math.round(ts * .22));
|
|
227
|
+
for (let y = 0; y < ts - 1; y++) for (let x = 0; x < ts; x++) {
|
|
228
|
+
const a = tile.getPixel(x, y)[3];
|
|
229
|
+
const aBelow = tile.getPixel(x, y + 1)[3];
|
|
230
|
+
if (a > 0 && y > 0 && tile.getPixel(x, y - 1)[3] === 0) tile.setPixel(x, y, capRamp[0]);
|
|
231
|
+
else if (a > 0 && aBelow === 0) for (let sy = 1; sy <= skirtH && y + sy < ts; sy++) {
|
|
232
|
+
const brick = (x + sy * 3) % 6 === 0 ? faceRamp[2] : faceRamp[1];
|
|
233
|
+
tile.setPixel(x, y + sy, sy === skirtH ? faceRamp[3] : brick);
|
|
234
|
+
}
|
|
235
|
+
else if (a > 0 && hash2D(x, y, seed + idx) > .82) tile.setPixel(x, y, capRamp[2]);
|
|
236
|
+
}
|
|
237
|
+
if (style === "iron_fence") {
|
|
238
|
+
for (let sx = 3; sx < ts - 2; sx += 6) if (w && sx < half - barHalf || e && sx > half + barHalf) tile.drawLine(sx, half - barHalf - 4, sx, half + barHalf + 2, capRamp[0]);
|
|
239
|
+
}
|
|
240
|
+
tile.addSelectiveOutline(capRamp[3]);
|
|
241
|
+
canvas.blit(tile, ox, oy);
|
|
242
|
+
}
|
|
243
|
+
const normalRgba = spec.bakeNormals !== false ? bakeNormalMapRgba(canvas.rgba, width, height, { strength: 2.8 }) : void 0;
|
|
244
|
+
return {
|
|
245
|
+
id: spec.id,
|
|
246
|
+
width,
|
|
247
|
+
height,
|
|
248
|
+
tileSize: ts,
|
|
249
|
+
columns: cols,
|
|
250
|
+
rows,
|
|
251
|
+
tileCount: BLOB47_CANONICAL_MASKS.length,
|
|
252
|
+
rgba: canvas.rgba,
|
|
253
|
+
...normalRgba ? { normalRgba } : {},
|
|
254
|
+
frames
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function rgbShiftDarker(hex) {
|
|
258
|
+
const c = mixRgb(parseHexRgb(hex), [
|
|
259
|
+
28,
|
|
260
|
+
22,
|
|
261
|
+
36
|
|
262
|
+
], .32);
|
|
263
|
+
const h = (n) => c[n].toString(16).padStart(2, "0");
|
|
264
|
+
return `#${h(0)}${h(1)}${h(2)}`;
|
|
265
|
+
}
|
|
266
|
+
export { computeBlob47Index as a, bakePixelDualGridSheet as i, bakeNormalMapRgba as n, computeDualGridMask as o, bakePixelBlob47Sheet as r, tilemap_exports as s, BLOB47_CANONICAL_MASKS as t };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type TerrainTextureStyle = 'cobble' | 'grass' | 'dirt' | 'water' | 'stone_brick' | 'sand';
|
|
2
|
+
export interface PixelDualGridSpec {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly tileSize?: number;
|
|
5
|
+
readonly baseColor: string;
|
|
6
|
+
readonly style?: TerrainTextureStyle;
|
|
7
|
+
readonly seed?: number;
|
|
8
|
+
/** Optional under-terrain fill color (transparent when omitted so layers stack cleanly). */
|
|
9
|
+
readonly backgroundColor?: string | null;
|
|
10
|
+
/** Generate a paired 3x3 Sobel normal map (`normalRgba`) alongside `rgba`. Default `true`. */
|
|
11
|
+
readonly bakeNormals?: boolean;
|
|
12
|
+
readonly normalStrength?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface BakedPixelTileset {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly width: number;
|
|
17
|
+
readonly height: number;
|
|
18
|
+
readonly tileSize: number;
|
|
19
|
+
readonly columns: number;
|
|
20
|
+
readonly rows: number;
|
|
21
|
+
readonly tileCount: number;
|
|
22
|
+
readonly rgba: Uint8ClampedArray;
|
|
23
|
+
readonly normalRgba?: Uint8ClampedArray;
|
|
24
|
+
readonly frames: ReadonlyArray<{
|
|
25
|
+
readonly index: number;
|
|
26
|
+
readonly mask: number;
|
|
27
|
+
readonly x: number;
|
|
28
|
+
readonly y: number;
|
|
29
|
+
readonly w: number;
|
|
30
|
+
readonly h: number;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export interface PixelBlob47Spec {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly tileSize?: number;
|
|
36
|
+
readonly capColor: string;
|
|
37
|
+
readonly faceColor?: string;
|
|
38
|
+
readonly style?: 'stone_wall' | 'iron_fence' | 'wood_fence';
|
|
39
|
+
readonly seed?: number;
|
|
40
|
+
readonly bakeNormals?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Oskar Stålberg 4-corner Dual-Grid mask (`bit0=TL, bit1=TR, bit2=BL, bit3=BR` -> `0..15`). */
|
|
43
|
+
export declare function computeDualGridMask(tl: boolean, tr: boolean, bl: boolean, br: boolean): number;
|
|
44
|
+
/** Canonical 47-tile Blob bitmasks (`N=1, NE=2, E=4, SE=8, S=16, SW=32, W=64, NW=128` with diagonal gating). */
|
|
45
|
+
export declare const BLOB47_CANONICAL_MASKS: readonly number[];
|
|
46
|
+
export declare function computeBlob47Index(n: boolean, ne: boolean, e: boolean, se: boolean, s: boolean, sw: boolean, w: boolean, nw: boolean): number;
|
|
47
|
+
/** Bake a tangent-space 3x3 Sobel normal map (`RGBA`) from pixel luminance + alpha silhouette height. */
|
|
48
|
+
export declare function bakeNormalMapRgba(rgba: Uint8Array | Uint8ClampedArray, width: number, height: number, opts?: {
|
|
49
|
+
strength?: number;
|
|
50
|
+
alphaWeight?: number;
|
|
51
|
+
}): Uint8ClampedArray;
|
|
52
|
+
/**
|
|
53
|
+
* Bake a 16-tile (`4x4` grid) Oskar Stålberg Dual-Grid pixel-art tileset with rich surface micro-texture,
|
|
54
|
+
* 1px sunlit/shaded transition bevels, and optional 3x3 Sobel normal map for `@holtjs/stage`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function bakePixelDualGridSheet(spec: PixelDualGridSpec): BakedPixelTileset;
|
|
57
|
+
/**
|
|
58
|
+
* Bake a 47-tile (`8x6` grid) Blob autotile spritesheet for stone graveyard walls, wrought-iron fences,
|
|
59
|
+
* or wooden palisades with top cap highlights, front-face masonry, and paired normal map.
|
|
60
|
+
*/
|
|
61
|
+
export declare function bakePixelBlob47Sheet(spec: PixelBlob47Spec): BakedPixelTileset;
|
package/dist/tilemap.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as BLOB47_CANONICAL_MASKS, n as bakeNormalMapRgba, r as bakePixelBlob47Sheet, i as bakePixelDualGridSheet, a as computeBlob47Index, o as computeDualGridMask } from "./tilemap-BFH4_JLe.js";
|
package/llms.txt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Holt Craft (`@holtjs/craft`)
|
|
2
|
+
|
|
3
|
+
> Zero-dependency procedural pixel-art, analytical 3D->2D character/prop/socket baker, Dual-Grid/Blob tileset & normal-map generator, atlas packer, and 4x AI visual contact-sheet inspector in pure zero-DOM TypeScript.
|
|
4
|
+
|
|
5
|
+
## Subpaths
|
|
6
|
+
- `@holtjs/craft`: Full barrel (`Craft` namespace + all subpaths).
|
|
7
|
+
- `@holtjs/craft/pixel`: `PixelCanvas`, `derivePixelRamp`, `derivePaletteVariants`, `compilePixelGrid`, pure-TS `encodePngRgba`.
|
|
8
|
+
- `@holtjs/craft/rig3d`: Analytical 3D->2D character/humanoid/monster/prop baker (`bakeDirectionalCharacterSheet`, `renderDecorPropSheet`, `projectAllSockets2D`, `GRAVEYARD_PRESETS`).
|
|
9
|
+
- `@holtjs/craft/tilemap`: Textured 16-tile Dual-Grid (`bakePixelDualGridSheet`), 47-tile Blob (`bakePixelBlob47Sheet`), 3x3 Sobel `bakeNormalMapRgba`.
|
|
10
|
+
- `@holtjs/craft/atlas`: Shelf sprite & normal-map atlas packer (`packSpriteAtlas`, `registerAtlasOnStage`).
|
|
11
|
+
- `@holtjs/craft/inspect`: 4x nearest-neighbor visual QA contact sheet (`renderContactSheet`).
|
|
12
|
+
|
|
13
|
+
## Links
|
|
14
|
+
- [README](https://github.com/botiverse-play/craft/blob/main/README.md)
|
|
15
|
+
- [Craft Agent Skill](https://github.com/botiverse-play/craft/blob/main/skills/craft/SKILL.md)
|
|
16
|
+
- [Subpath API Reference](https://github.com/botiverse-play/craft/blob/main/skills/craft/references/subpaths.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holtjs/craft",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zero-dependency procedural pixel-art, analytical 3D-to-2D sprite/socket baker, Dual-Grid/Blob tileset & normal-map generator, atlas packer, and 4x AI visual contact-sheet inspector for @holtjs/stage.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Botiverse, Inc.",
|
|
7
|
+
"homepage": "https://holt.js.org",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/botiverse-play/craft/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/botiverse-play/craft.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"holt",
|
|
17
|
+
"craft",
|
|
18
|
+
"pixel-art",
|
|
19
|
+
"procedural-generation",
|
|
20
|
+
"spritesheet",
|
|
21
|
+
"3d-to-2d",
|
|
22
|
+
"raycasting",
|
|
23
|
+
"skeletal-animation",
|
|
24
|
+
"autotile",
|
|
25
|
+
"dual-grid",
|
|
26
|
+
"normal-map",
|
|
27
|
+
"texture-atlas",
|
|
28
|
+
"ai-agents",
|
|
29
|
+
"game-dev",
|
|
30
|
+
"typescript",
|
|
31
|
+
"zero-dependency"
|
|
32
|
+
],
|
|
33
|
+
"type": "module",
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22.0.0"
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"default": "./dist/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./pixel": {
|
|
44
|
+
"types": "./dist/pixel.d.ts",
|
|
45
|
+
"default": "./dist/pixel.js"
|
|
46
|
+
},
|
|
47
|
+
"./rig3d": {
|
|
48
|
+
"types": "./dist/rig3d.d.ts",
|
|
49
|
+
"default": "./dist/rig3d.js"
|
|
50
|
+
},
|
|
51
|
+
"./tilemap": {
|
|
52
|
+
"types": "./dist/tilemap.d.ts",
|
|
53
|
+
"default": "./dist/tilemap.js"
|
|
54
|
+
},
|
|
55
|
+
"./atlas": {
|
|
56
|
+
"types": "./dist/atlas.d.ts",
|
|
57
|
+
"default": "./dist/atlas.js"
|
|
58
|
+
},
|
|
59
|
+
"./inspect": {
|
|
60
|
+
"types": "./dist/inspect.d.ts",
|
|
61
|
+
"default": "./dist/inspect.js"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"files": [
|
|
65
|
+
"dist",
|
|
66
|
+
"skills/craft",
|
|
67
|
+
"llms.txt",
|
|
68
|
+
"CHANGELOG.md",
|
|
69
|
+
"LICENSE",
|
|
70
|
+
"NOTICE",
|
|
71
|
+
"README.md"
|
|
72
|
+
]
|
|
73
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: craft
|
|
3
|
+
description: Procedurally bake crisp Graveyard Keeper / RPG pixel-art characters, monsters, 26-degree oblique props, 9-socket equipment anchors, textured 16-tile Dual-Grid & 47-tile Blob autotiles, tangent-space normal maps, packed sprite atlases, and 4x AI visual inspection contact sheets in pure zero-DOM TypeScript with @holtjs/craft.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Procedural Pixel Characters, Props, Autotiles & 4× Contact Sheets with `@holtjs/craft`
|
|
7
|
+
|
|
8
|
+
Use `@holtjs/craft` whenever an AI coding agent or developer needs **crisp, consistent, frame-coherent pixel-art assets** (multi-direction animated characters, zombies/creatures, stone/wood world props, Dual-Grid/Blob terrain sheets, normal maps, and packed atlases) with **zero runtime dependencies, zero Blender/Three.js, and zero browser/DOM required**.
|
|
9
|
+
|
|
10
|
+
For the complete exported symbol list across all 6 subpaths, see [references/subpaths.md](references/subpaths.md).
|
|
11
|
+
|
|
12
|
+
## 1. Install & Subpath Overview
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @holtjs/craft
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
| Subpath | Responsibility | Zero DOM / Zero Native Deps? |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| `@holtjs/craft` | Full barrel (`Craft` namespace + all subpaths) | Yes |
|
|
21
|
+
| `@holtjs/craft/pixel` | `PixelCanvas`, `derivePixelRamp`, `derivePaletteVariants`, `compilePixelGrid`, pure-TS `encodePngRgba` | Yes |
|
|
22
|
+
| `@holtjs/craft/rig3d` | Analytical 3D→2D character/humanoid/monster/prop raycaster (~0.4ms/frame), 9 projected sockets, `GRAVEYARD_PRESETS` | Yes |
|
|
23
|
+
| `@holtjs/craft/tilemap` | Textured 16-tile Dual-Grid (`bakePixelDualGridSheet`), 47-tile Blob (`bakePixelBlob47Sheet`), 3×3 Sobel `bakeNormalMapRgba` | Yes |
|
|
24
|
+
| `@holtjs/craft/atlas` | Shelf `packSpriteAtlas` (RGBA + synchronized normal-map atlas) & one-line `registerAtlasOnStage` | Yes |
|
|
25
|
+
| `@holtjs/craft/inspect` | `renderContactSheet` — 4× nearest-neighbor checkerboard + `3×5` bitmap labels + socket/baseline visual QA PNG | Yes |
|
|
26
|
+
|
|
27
|
+
## 2. Bake Multi-Direction Pixel Characters & Props (`@holtjs/craft/rig3d`)
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import {
|
|
31
|
+
GRAVEYARD_PRESETS,
|
|
32
|
+
bakeDirectionalCharacterSheet,
|
|
33
|
+
renderDecorPropSheet,
|
|
34
|
+
} from '@holtjs/craft/rig3d';
|
|
35
|
+
|
|
36
|
+
// 1. Bake 4-direction (S/E/N/W) walk + axe-chop spritesheet + normal map + 9-socket table
|
|
37
|
+
const keeper = bakeDirectionalCharacterSheet(GRAVEYARD_PRESETS.keeperBody, {
|
|
38
|
+
dirs: 4,
|
|
39
|
+
rows: [
|
|
40
|
+
{ clip: 'walk', name: 'walk' },
|
|
41
|
+
{ clip: GRAVEYARD_PRESETS.clips.chop, name: 'chop' },
|
|
42
|
+
],
|
|
43
|
+
cosmetics: [
|
|
44
|
+
GRAVEYARD_PRESETS.cosmetics.ironAxe,
|
|
45
|
+
GRAVEYARD_PRESETS.cosmetics.blazingTorch,
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 2. Bake 26-degree oblique pixel-art world props (1-dir or 4-dir)
|
|
50
|
+
const tombstone = renderDecorPropSheet(GRAVEYARD_PRESETS.props.tombstone);
|
|
51
|
+
const furnace = renderDecorPropSheet(GRAVEYARD_PRESETS.props.stoneFurnace);
|
|
52
|
+
const arrowTower = renderDecorPropSheet(GRAVEYARD_PRESETS.props.arrowTower);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 3. Bake Textured Dual-Grid & Blob47 Tilesets + Normal Maps (`@holtjs/craft/tilemap`)
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { bakePixelDualGridSheet, bakePixelBlob47Sheet } from '@holtjs/craft/tilemap';
|
|
59
|
+
|
|
60
|
+
const cobble = bakePixelDualGridSheet({
|
|
61
|
+
id: 'graveyard_cobble',
|
|
62
|
+
tileSize: 32,
|
|
63
|
+
baseColor: '#64748b',
|
|
64
|
+
style: 'cobble', // 'cobble' | 'stone_brick' | 'grass' | 'dirt' | 'water' | 'sand'
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const fence = bakePixelBlob47Sheet({
|
|
68
|
+
id: 'wrought_iron_fence',
|
|
69
|
+
tileSize: 32,
|
|
70
|
+
capColor: '#475569',
|
|
71
|
+
style: 'iron_fence', // 'stone_wall' | 'iron_fence' | 'wood_fence'
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 4. Pack into `@holtjs/stage` & Visually Inspect at 4× (`@holtjs/craft/atlas` + `/inspect`)
|
|
76
|
+
|
|
77
|
+
**Golden Rule for AI Agents**: Always render a 3× or 4× `renderContactSheet()` PNG and inspect it visually before shipping new custom bodies, props, or tiles!
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import fs from 'node:fs';
|
|
81
|
+
import { packSpriteAtlas, registerAtlasOnStage } from '@holtjs/craft/atlas';
|
|
82
|
+
import { renderContactSheet } from '@holtjs/craft/inspect';
|
|
83
|
+
|
|
84
|
+
const sheet = renderContactSheet(
|
|
85
|
+
[
|
|
86
|
+
{ label: 'KEEPER 4-DIR', sprite: keeper, cellW: 32, cellH: 32 },
|
|
87
|
+
{ label: 'TOMBSTONE', sprite: tombstone, cellW: 32, baseY: 36 },
|
|
88
|
+
{ label: 'COBBLE DG', sprite: cobble, cellW: 32, cellH: 32 },
|
|
89
|
+
],
|
|
90
|
+
{ scale: 4, columns: 3, title: 'ASSET QA' },
|
|
91
|
+
);
|
|
92
|
+
fs.writeFileSync('asset-qa.png', sheet.png); // pure zero-dep PNG encoder!
|
|
93
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# `@holtjs/craft` Subpath API Reference
|
|
2
|
+
|
|
3
|
+
All symbols verified against `src/*.ts` (`@holtjs/craft@0.1.0`, 6 subpaths, 0 runtime dependencies, 0 DOM globals).
|
|
4
|
+
|
|
5
|
+
## `@holtjs/craft` (Barrel)
|
|
6
|
+
- Default & named `Craft` namespace + all exports from `./pixel`, `./rig3d`, `./tilemap`, `./atlas`, and `./inspect`.
|
|
7
|
+
|
|
8
|
+
## `@holtjs/craft/pixel`
|
|
9
|
+
- Color & Ramps: `parseHexRgb(hex)`, `rgbToHex(rgb)`, `mixRgb(a, b, t)`, `derivePixelRamp(hexOrRgb)` (`[light, base, shade, outline]`), `derivePaletteVariants(baseHex, count?)`
|
|
10
|
+
- `PixelCanvas`: `.clear()`, `.setPixel()`, `.getPixel()`, `.fillRect()`, `.strokeRect()`, `.fillEllipse()`, `.drawLine()`, `.blit()`, `.flipX()`, `.applyOrderedDither()`, `.addSelectiveOutline()`, `.addContactShadow()`, `.clone()`, `.toPng()`
|
|
11
|
+
- Declarative Grid & PNG: `compilePixelGrid(spec, opts?)`, `encodePngRgba(width, height, rgba)` (pure-TS RFC-2083 PNG encoder)
|
|
12
|
+
- Types: `Rgb`, `Rgba`, `Ramp4`, `PixelSpriteLike`, `AsciiPixelGridSpec`, `CompilePixelGridOptions`
|
|
13
|
+
|
|
14
|
+
## `@holtjs/craft/rig3d`
|
|
15
|
+
- Multi-Direction Character Baker & Presets: `bakeDirectionalCharacterSheet(bodyOrCustom, opts?)`, `GRAVEYARD_PRESETS` (`keeperBody`, `zombieBody`, `cosmetics.{ironAxe,blazingTorch}`, `clips.{chop,shamble}`, `props.{tombstone,woodenChest,stoneFurnace,arrowTower,ancientPine}`)
|
|
16
|
+
- 3D Skeleton, Kinematics & 9-Socket Projection: `RIG_BODIES`, `RIG_BONE_NAMES`, `RIG_SOCKET_NAMES`, `BUILTIN_ANIM_FRAMES`, `createRigState`, `updateRigMatrices`, `reachArm`, `getBodySockets`, `projectWorldPoint2D`, `projectSocket2D`, `projectAllSockets2D`, `evaluateBuiltinPose`, `evaluateRigClip`, `rigClipFrameCount`, `compileCustomBodySpec`
|
|
17
|
+
- Analytical 3D->2D Rasterizers: `renderRigPose`, `renderRigClipStrip`, `renderBodyAnimStrip`, `renderCosmeticSprite`, `compositeSpriteRgba`, `renderDecorPropSprite`, `renderDecorPropSheet`, `renderBodyRestPreview`
|
|
18
|
+
- Strict Validators: `validateRigCosmetic`, `validateRigClip`, `validateRigCustomBody`, `validateRigDecorProp`, `validateRigPrimitiveList`, `validateRigPixelSprite`
|
|
19
|
+
|
|
20
|
+
## `@holtjs/craft/tilemap`
|
|
21
|
+
- Autotile Masks: `computeDualGridMask(tl, tr, bl, br)`, `computeBlob47Index(...)`, `BLOB47_CANONICAL_MASKS`
|
|
22
|
+
- Pixel Tileset & Normal-Map Bakers: `bakePixelDualGridSheet(spec)`, `bakePixelBlob47Sheet(spec)`, `bakeNormalMapRgba(rgba, width, height, opts?)`
|
|
23
|
+
- Types: `TerrainTextureStyle`, `PixelDualGridSpec`, `PixelBlob47Spec`, `BakedPixelTileset`
|
|
24
|
+
|
|
25
|
+
## `@holtjs/craft/atlas`
|
|
26
|
+
- `packSpriteAtlas(items, opts?)` -> `PackedSpriteAtlas` (`.width`, `.height`, `.rgba`, `.normalRgba`, `.frames`, `.toPng()`, `.toNormalPng()`)
|
|
27
|
+
- Stage Integration: `writeRgbaToCanvas(sprite, createCanvas)`, `registerAtlasOnStage(scene, textureKey, atlas, createCanvas)`
|
|
28
|
+
- Types: `AtlasInputItem`, `PackedFrameRect`, `PackAtlasOptions`, `PackedSpriteAtlas`, `StageSceneTextureHost`, `MinimalCanvas2D`
|
|
29
|
+
|
|
30
|
+
## `@holtjs/craft/inspect`
|
|
31
|
+
- `renderContactSheet(items, opts?)` -> `ContactSheetResult` (`{ width, height, scale, rgba, png }`)
|
|
32
|
+
- Types: `InspectMarker`, `ContactSheetItem`, `ContactSheetOptions`, `ContactSheetResult`
|