@holtjs/craft 0.0.0-stage → 0.2.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 +24 -0
- package/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +91 -2
- package/dist/atlas-Pc12eQsg.js +112 -0
- package/dist/atlas.d.ts +75 -0
- package/dist/atlas.js +1 -0
- package/dist/hd3d-BozZnINB.js +1871 -0
- package/dist/hd3d.d.ts +112 -0
- package/dist/hd3d.js +1 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +17 -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/rig-render-DZBV9u2H.js +6163 -0
- package/dist/rig-render-DoPVKQAF.d.ts +537 -0
- package/dist/rig3d-CPw8F6V2.js +1096 -0
- package/dist/rig3d-DeeG_PJj.d.ts +70 -0
- package/dist/rig3d.d.ts +3 -0
- package/dist/rig3d.js +3 -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 +18 -0
- package/package.json +77 -4
- package/skills/craft/SKILL.md +98 -0
- package/skills/craft/references/subpaths.md +39 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { A as ProjectedSocket2D, C as RigDecorPropSpec, Dt as RigBodySpec, Et as RigBodyKey, Mt as RigClip, Nt as RigCosmeticSpec, X as RigPoseState, Z as RigSocketName, m as RigLookColors, x as RigCustomBodySpec } from "./rig-render-DoPVKQAF.js";
|
|
2
|
+
declare const BUILTIN_ANIM_FRAMES: Readonly<Record<string, {
|
|
3
|
+
readonly frames: number;
|
|
4
|
+
readonly dirs: number;
|
|
5
|
+
}>>;
|
|
6
|
+
/** Evaluate any built-in Deck animation at `(bodyOrKey, anim, frame, dir16)` to get exact 3D bone transforms & sockets. */
|
|
7
|
+
declare function evaluateBuiltinPose(bodyOrKey: RigBodyKey | RigBodySpec, anim: string, frame?: number, dir16?: number): RigPoseState;
|
|
8
|
+
interface DirectionalSheetRowSpec {
|
|
9
|
+
/** Clip name (`'idle'`, `'walk'`, `'run'`, etc.) or a custom declarative `RigClip`. */
|
|
10
|
+
readonly clip: string | RigClip;
|
|
11
|
+
/** Row identifier in output metadata (defaults to clip string or `clip.id`). */
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
}
|
|
14
|
+
interface BakeCharacterSheetOptions {
|
|
15
|
+
readonly cellSize?: number;
|
|
16
|
+
readonly ss?: number;
|
|
17
|
+
/** Directions to bake: `4` = `[S(0), E(4), N(8), W(12)]`, `8` = `0,2,4,6,8,10,12,14`. Default `4`. */
|
|
18
|
+
readonly dirs?: 4 | 8;
|
|
19
|
+
readonly rows?: readonly DirectionalSheetRowSpec[];
|
|
20
|
+
readonly colors?: RigLookColors;
|
|
21
|
+
readonly cosmetics?: readonly RigCosmeticSpec[];
|
|
22
|
+
readonly bakeNormals?: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface CharacterFrameMeta {
|
|
25
|
+
readonly key: string;
|
|
26
|
+
readonly clip: string;
|
|
27
|
+
readonly dirIndex: number;
|
|
28
|
+
readonly dir16: number;
|
|
29
|
+
readonly frame: number;
|
|
30
|
+
readonly x: number;
|
|
31
|
+
readonly y: number;
|
|
32
|
+
readonly w: number;
|
|
33
|
+
readonly h: number;
|
|
34
|
+
readonly sockets: Readonly<Record<RigSocketName, ProjectedSocket2D>>;
|
|
35
|
+
}
|
|
36
|
+
interface BakedCharacterSheet {
|
|
37
|
+
readonly width: number;
|
|
38
|
+
readonly height: number;
|
|
39
|
+
readonly cellSize: number;
|
|
40
|
+
readonly columns: number;
|
|
41
|
+
readonly rowCount: number;
|
|
42
|
+
readonly rgba: Uint8ClampedArray;
|
|
43
|
+
readonly normalRgba?: Uint8ClampedArray;
|
|
44
|
+
readonly frames: readonly CharacterFrameMeta[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Bake a complete multi-direction (`4-dir` S/E/N/W or `8-dir`) × multi-animation pixel-art character spritesheet
|
|
48
|
+
* with per-frame projected 2D socket coordinates (`handR`, `handL`, `headTop`, `back`, ...) and optional Sobel normal map.
|
|
49
|
+
*/
|
|
50
|
+
declare function bakeDirectionalCharacterSheet(bodyOrCustom: RigBodyKey | RigBodySpec | RigCustomBodySpec, opts?: BakeCharacterSheetOptions): BakedCharacterSheet;
|
|
51
|
+
declare const GRAVEYARD_PRESETS: {
|
|
52
|
+
readonly keeperBody: RigCustomBodySpec;
|
|
53
|
+
readonly zombieBody: RigCustomBodySpec;
|
|
54
|
+
readonly cosmetics: {
|
|
55
|
+
readonly ironAxe: RigCosmeticSpec;
|
|
56
|
+
readonly blazingTorch: RigCosmeticSpec;
|
|
57
|
+
};
|
|
58
|
+
readonly clips: {
|
|
59
|
+
readonly chop: RigClip;
|
|
60
|
+
readonly shamble: RigClip;
|
|
61
|
+
};
|
|
62
|
+
readonly props: {
|
|
63
|
+
readonly tombstone: RigDecorPropSpec;
|
|
64
|
+
readonly woodenChest: RigDecorPropSpec;
|
|
65
|
+
readonly stoneFurnace: RigDecorPropSpec;
|
|
66
|
+
readonly arrowTower: RigDecorPropSpec;
|
|
67
|
+
readonly ancientPine: RigDecorPropSpec;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export { GRAVEYARD_PRESETS as a, evaluateBuiltinPose as c, DirectionalSheetRowSpec as i, BakedCharacterSheet as n, bakeDirectionalCharacterSheet as o, CharacterFrameMeta as r, BUILTIN_ANIM_FRAMES as s, BakeCharacterSheetOptions as t };
|
package/dist/rig3d.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { $ as Vec3, A as ProjectedSocket2D, At as RIG_PRIMITIVE_SHAPES, B as RIG_EYE_MODES, Bt as rigClipFrameCount, C as RigDecorPropSpec, Ct as RigBodyAttachment, D as Mat4, Dt as RigBodySpec, E as validateRigDecorProp, Et as RigBodyKey, F as RIG_CELL_SIZE, Ft as RigPixelSpriteSpec, G as RigBoneName, H as RIG_MODEL_SCALE, Ht as validateRigCosmetic, I as RIG_COSMETIC_SLOTS, It as RigPrimitiveShape, J as RigEaseMode, K as RigBoneTransform, L as RIG_COS_E, Lt as RigPrimitiveSpec, M as RIG_BONE_NAMES, Mt as RigClip, N as RIG_CAMERA_ELEV_DEG, Nt as RigCosmeticSpec, O as MutVec3, Ot as RigBodyTailStyle, P as RIG_CAMERA_GROUND_Y, Pt as RigKeyframe, Q as SocketDefinition, R as RIG_DUO_VIEW, Rt as RigPropInstance, S as RigDecorGroup, St as RigBodyAttachBone, T as validateRigCustomBody, Tt as RigBodyEyeStyle, U as RIG_SIN_E, Ut as validateRigPixelSprite, V as RIG_LIMITS, Vt as validateRigClip, W as RIG_SOCKET_NAMES, Wt as validateRigPrimitiveList, X as RigPoseState, Y as RigEyeMode, Z as RigSocketName, _ as RIG_BODY_CATEGORIES, _t as RIG_BODIES, a as renderBodyAnimStrip, at as mat4TransformDir, b as RigCustomBodyDefaultColors, bt as RIG_BODY_KEYS, c as renderDecorPropSheet, ct as projectSocket2D, d as renderRigPose, dt as quatFromEuler, et as createRigState, f as Ramp4, ft as quatFromUnitVectors, g as parseHexRgb, gt as updateRigMatrices, h as derivePixelRamp, ht as reachArm, i as compositeSpriteRgba, it as mat4Mul, j as Quat, jt as RigBonePoseOverride, k as ProjectedPoint2D, kt as rigBodyKeyFromIndex, l as renderDecorPropSprite, lt as projectWorldPoint2D, m as RigLookColors, mt as quatMul, n as DEFAULT_RIG_COLORS, nt as mat4Compose, o as renderBodyRestPreview, ot as mat4TransformPoint, p as Rgb, pt as quatIdentity, q as RigCosmeticSlot, r as RenderedRigCell, rt as mat4Invert, s as renderCosmeticSprite, st as projectAllSockets2D, t as CompiledRigStrip, tt as getBodySockets, u as renderRigClipStrip, ut as quatFromAxisAngle, v as RIG_DECOR_GROUPS, vt as RIG_BODY_ATTACH_BONES, w as compileCustomBodySpec, wt as RigBodyCustomColors, x as RigCustomBodySpec, xt as RIG_BODY_TAIL_STYLES, y as RigBodyCategory, yt as RIG_BODY_EYE_STYLES, z as RIG_EASE_MODES, zt as evaluateRigClip } from "./rig-render-DoPVKQAF.js";
|
|
2
|
+
import { a as GRAVEYARD_PRESETS, c as evaluateBuiltinPose, i as DirectionalSheetRowSpec, n as BakedCharacterSheet, o as bakeDirectionalCharacterSheet, r as CharacterFrameMeta, s as BUILTIN_ANIM_FRAMES, t as BakeCharacterSheetOptions } from "./rig3d-DeeG_PJj.js";
|
|
3
|
+
export { BUILTIN_ANIM_FRAMES, BakeCharacterSheetOptions, BakedCharacterSheet, CharacterFrameMeta, CompiledRigStrip, DEFAULT_RIG_COLORS, DirectionalSheetRowSpec, GRAVEYARD_PRESETS, type Mat4, type MutVec3, type ProjectedPoint2D, type ProjectedSocket2D, type Quat, RIG_BODIES, RIG_BODY_ATTACH_BONES, RIG_BODY_CATEGORIES, RIG_BODY_EYE_STYLES, RIG_BODY_KEYS, RIG_BODY_TAIL_STYLES, RIG_BONE_NAMES, RIG_CAMERA_ELEV_DEG, RIG_CAMERA_GROUND_Y, RIG_CELL_SIZE, RIG_COSMETIC_SLOTS, RIG_COS_E, RIG_DECOR_GROUPS, RIG_DUO_VIEW, RIG_EASE_MODES, RIG_EYE_MODES, RIG_LIMITS, RIG_MODEL_SCALE, RIG_PRIMITIVE_SHAPES, RIG_SIN_E, RIG_SOCKET_NAMES, type Ramp4, RenderedRigCell, type Rgb, type RigBodyAttachBone, type RigBodyAttachment, type RigBodyCategory, type RigBodyCustomColors, type RigBodyEyeStyle, type RigBodyKey, type RigBodySpec, type RigBodyTailStyle, type RigBoneName, type RigBonePoseOverride, type RigBoneTransform, type RigClip, type RigCosmeticSlot, type RigCosmeticSpec, type RigCustomBodyDefaultColors, type RigCustomBodySpec, type RigDecorGroup, type RigDecorPropSpec, type RigEaseMode, type RigEyeMode, type RigKeyframe, type RigLookColors, type RigPixelSpriteSpec, type RigPoseState, type RigPrimitiveShape, type RigPrimitiveSpec, type RigPropInstance, type RigSocketName, type SocketDefinition, type Vec3, bakeDirectionalCharacterSheet, compileCustomBodySpec, compositeSpriteRgba, createRigState, derivePixelRamp, evaluateBuiltinPose, evaluateRigClip, getBodySockets, mat4Compose, mat4Invert, mat4Mul, mat4TransformDir, mat4TransformPoint, parseHexRgb, projectAllSockets2D, projectSocket2D, projectWorldPoint2D, quatFromAxisAngle, quatFromEuler, quatFromUnitVectors, quatIdentity, quatMul, reachArm, renderBodyAnimStrip, renderBodyRestPreview, renderCosmeticSprite, renderDecorPropSheet, renderDecorPropSprite, renderRigClipStrip, renderRigPose, rigBodyKeyFromIndex, rigClipFrameCount, updateRigMatrices, validateRigClip, validateRigCosmetic, validateRigCustomBody, validateRigDecorProp, validateRigPixelSprite, validateRigPrimitiveList };
|
package/dist/rig3d.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { $ as projectSocket2D, A as validateRigPixelSprite, B as RIG_EYE_MODES, C as validateRigCustomBody, D as rigClipFrameCount, E as evaluateRigClip, F as RIG_CELL_SIZE, G as createRigState, H as RIG_MODEL_SCALE, I as RIG_COSMETIC_SLOTS, J as mat4Invert, K as getBodySockets, L as RIG_COS_E, M as RIG_BONE_NAMES, N as RIG_CAMERA_ELEV_DEG, O as validateRigClip, P as RIG_CAMERA_GROUND_Y, Q as projectAllSockets2D, R as RIG_DUO_VIEW, S as compileCustomBodySpec, T as RIG_PRIMITIVE_SHAPES, U as RIG_SIN_E, V as RIG_LIMITS, W as RIG_SOCKET_NAMES, X as mat4TransformDir, Y as mat4Mul, Z as mat4TransformPoint, _ as parseHexRgb, a as renderCosmeticSprite, at as quatMul, b as RIG_BODY_CATEGORIES, c as renderRigClipStrip, ct as RIG_BODIES, dt as RIG_BODY_KEYS, et as projectWorldPoint2D, ft as RIG_BODY_TAIL_STYLES, i as renderBodyRestPreview, it as quatIdentity, j as validateRigPrimitiveList, k as validateRigCosmetic, l as renderRigPose, lt as RIG_BODY_ATTACH_BONES, n as compositeSpriteRgba, nt as quatFromEuler, o as renderDecorPropSheet, ot as reachArm, p as derivePixelRamp, pt as rigBodyKeyFromIndex, q as mat4Compose, r as renderBodyAnimStrip, rt as quatFromUnitVectors, s as renderDecorPropSprite, st as updateRigMatrices, t as DEFAULT_RIG_COLORS, tt as quatFromAxisAngle, ut as RIG_BODY_EYE_STYLES, v as BUILTIN_ANIM_FRAMES, w as validateRigDecorProp, x as RIG_DECOR_GROUPS, y as evaluateBuiltinPose, z as RIG_EASE_MODES } from "./rig-render-DZBV9u2H.js";
|
|
2
|
+
import { n as bakeDirectionalCharacterSheet, t as GRAVEYARD_PRESETS } from "./rig3d-CPw8F6V2.js";
|
|
3
|
+
export { BUILTIN_ANIM_FRAMES, DEFAULT_RIG_COLORS, GRAVEYARD_PRESETS, RIG_BODIES, RIG_BODY_ATTACH_BONES, RIG_BODY_CATEGORIES, RIG_BODY_EYE_STYLES, RIG_BODY_KEYS, RIG_BODY_TAIL_STYLES, RIG_BONE_NAMES, RIG_CAMERA_ELEV_DEG, RIG_CAMERA_GROUND_Y, RIG_CELL_SIZE, RIG_COSMETIC_SLOTS, RIG_COS_E, RIG_DECOR_GROUPS, RIG_DUO_VIEW, RIG_EASE_MODES, RIG_EYE_MODES, RIG_LIMITS, RIG_MODEL_SCALE, RIG_PRIMITIVE_SHAPES, RIG_SIN_E, RIG_SOCKET_NAMES, bakeDirectionalCharacterSheet, compileCustomBodySpec, compositeSpriteRgba, createRigState, derivePixelRamp, evaluateBuiltinPose, evaluateRigClip, getBodySockets, mat4Compose, mat4Invert, mat4Mul, mat4TransformDir, mat4TransformPoint, parseHexRgb, projectAllSockets2D, projectSocket2D, projectWorldPoint2D, quatFromAxisAngle, quatFromEuler, quatFromUnitVectors, quatIdentity, quatMul, reachArm, renderBodyAnimStrip, renderBodyRestPreview, renderCosmeticSprite, renderDecorPropSheet, renderDecorPropSprite, renderRigClipStrip, renderRigPose, rigBodyKeyFromIndex, rigClipFrameCount, updateRigMatrices, validateRigClip, validateRigCosmetic, validateRigCustomBody, validateRigDecorProp, validateRigPixelSprite, validateRigPrimitiveList };
|
|
@@ -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,18 @@
|
|
|
1
|
+
# Holt Craft (`@holtjs/craft`)
|
|
2
|
+
|
|
3
|
+
> Zero-dependency smooth 2:1 isometric HD 3D sprite baker (3x3 SSAA + dark ink outlines + true 3D normal maps), procedural pixel-art engine, analytical 3D->2D socket baker, Dual-Grid/Blob tileset generator, atlas packer, and AI visual contact-sheet inspector in pure zero-DOM TypeScript.
|
|
4
|
+
|
|
5
|
+
## Subpaths
|
|
6
|
+
- `@holtjs/craft`: Full barrel (`Craft` namespace + all 7 subpaths).
|
|
7
|
+
- `@holtjs/craft/hd3d`: Smooth 2:1 isometric (`45°/30°`) 3x3 SSAA pre-rendered 3D character, prop & painted Dual-Grid terrain baker (`renderHdCharacterCell`, `bakeHdCharacterSheet`, `renderHdPropSheet`, `bakeHdDualGridSheet`, `KRAFTEERS_PRESETS`).
|
|
8
|
+
- `@holtjs/craft/pixel`: `PixelCanvas`, `derivePixelRamp`, `derivePaletteVariants`, `compilePixelGrid`, pure-TS compressed `encodePngRgba`.
|
|
9
|
+
- `@holtjs/craft/rig3d`: Crisp pixel 3D->2D character/humanoid/monster/prop & 9-socket baker (`bakeDirectionalCharacterSheet`, `renderDecorPropSheet`, `projectAllSockets2D`, `GRAVEYARD_PRESETS`).
|
|
10
|
+
- `@holtjs/craft/tilemap`: Textured pixel 16-tile Dual-Grid (`bakePixelDualGridSheet`), 47-tile Blob (`bakePixelBlob47Sheet`), 3x3 Sobel `bakeNormalMapRgba`.
|
|
11
|
+
- `@holtjs/craft/atlas`: Shelf sprite & normal-map atlas packer (`packSpriteAtlas`, `registerAtlasOnStage`).
|
|
12
|
+
- `@holtjs/craft/inspect`: Native `1x` HD or `4x` pixel visual QA contact sheet (`renderContactSheet`).
|
|
13
|
+
|
|
14
|
+
## Links
|
|
15
|
+
- [Official Docs](https://holt.js.org/craft/)
|
|
16
|
+
- [README](https://github.com/botiverse-play/craft/blob/main/README.md)
|
|
17
|
+
- [Craft Agent Skill](https://github.com/botiverse-play/craft/blob/main/skills/craft/SKILL.md)
|
|
18
|
+
- [Subpath API Reference](https://github.com/botiverse-play/craft/blob/main/skills/craft/references/subpaths.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holtjs/craft",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Zero-dependency smooth 2:1 isometric HD 3D sprite baker (3x3 SSAA + dark ink outlines), procedural pixel-art, analytical 3D-to-2D socket baker, Dual-Grid/Blob tileset & normal-map generator, atlas packer, and 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
|
+
"isometric",
|
|
19
|
+
"pre-rendered-3d",
|
|
20
|
+
"pixel-art",
|
|
21
|
+
"procedural-generation",
|
|
22
|
+
"spritesheet",
|
|
23
|
+
"3d-to-2d",
|
|
24
|
+
"raycasting",
|
|
25
|
+
"skeletal-animation",
|
|
26
|
+
"autotile",
|
|
27
|
+
"dual-grid",
|
|
28
|
+
"normal-map",
|
|
29
|
+
"texture-atlas",
|
|
30
|
+
"ai-agents",
|
|
31
|
+
"game-dev",
|
|
32
|
+
"typescript",
|
|
33
|
+
"zero-dependency"
|
|
34
|
+
],
|
|
35
|
+
"type": "module",
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22.0.0"
|
|
39
|
+
},
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./hd3d": {
|
|
46
|
+
"types": "./dist/hd3d.d.ts",
|
|
47
|
+
"default": "./dist/hd3d.js"
|
|
48
|
+
},
|
|
49
|
+
"./pixel": {
|
|
50
|
+
"types": "./dist/pixel.d.ts",
|
|
51
|
+
"default": "./dist/pixel.js"
|
|
52
|
+
},
|
|
53
|
+
"./rig3d": {
|
|
54
|
+
"types": "./dist/rig3d.d.ts",
|
|
55
|
+
"default": "./dist/rig3d.js"
|
|
56
|
+
},
|
|
57
|
+
"./tilemap": {
|
|
58
|
+
"types": "./dist/tilemap.d.ts",
|
|
59
|
+
"default": "./dist/tilemap.js"
|
|
60
|
+
},
|
|
61
|
+
"./atlas": {
|
|
62
|
+
"types": "./dist/atlas.d.ts",
|
|
63
|
+
"default": "./dist/atlas.js"
|
|
64
|
+
},
|
|
65
|
+
"./inspect": {
|
|
66
|
+
"types": "./dist/inspect.d.ts",
|
|
67
|
+
"default": "./dist/inspect.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"files": [
|
|
71
|
+
"dist",
|
|
72
|
+
"skills/craft",
|
|
73
|
+
"llms.txt",
|
|
74
|
+
"CHANGELOG.md",
|
|
75
|
+
"LICENSE",
|
|
76
|
+
"NOTICE",
|
|
77
|
+
"README.md"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: craft
|
|
3
|
+
description: Procedurally bake smooth 2:1 isometric HD 3D sprites (Krafteers / Clash style with 3x3 SSAA, dark ink outlines & true 3D normal maps) OR crisp Graveyard Keeper pixel-art characters, 9-socket equipment anchors, Dual-Grid & 47-tile Blob autotiles, packed sprite atlases, and visual QA contact sheets in pure zero-DOM TypeScript with @holtjs/craft.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Smooth 2:1 Isometric HD 3D & Pixel Asset Baking with `@holtjs/craft`
|
|
7
|
+
|
|
8
|
+
Use `@holtjs/craft` whenever an AI coding agent or developer needs **frame-coherent game art** with **zero runtime dependencies, zero Blender/Three.js, and zero browser/DOM required**:
|
|
9
|
+
- **Smooth 2:1 Isometric HD 3D (`@holtjs/craft/hd3d`)**: Vibrant, saturated *Krafteers: Tomb Defenders* / *Clash*-style `96×96` characters, `4-dir` turrets/walls/obelisks, smooth painted `64×64` Dual-Grid terrain, anti-aliased dark ink outlines, and exact 3D camera-space normal maps.
|
|
10
|
+
- **Crisp Low-Res Pixel Art (`@holtjs/craft/rig3d` + `/tilemap` + `/pixel`)**: *Graveyard Keeper* / *Eastward*-style `32×32` characters, `26°` oblique props, 4-shade crescent lighting, colored 1px outlines, and textured Dual-Grid / Blob47 tiles.
|
|
11
|
+
|
|
12
|
+
For the complete exported symbol list across all 7 subpaths, see [references/subpaths.md](references/subpaths.md).
|
|
13
|
+
|
|
14
|
+
## 1. Install & Subpath Overview
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @holtjs/craft
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
| Subpath | Responsibility | Zero DOM / Zero Native Deps? |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `@holtjs/craft` | Full barrel (`Craft` namespace + all subpaths) | Yes |
|
|
23
|
+
| `@holtjs/craft/hd3d` | Smooth `45°/30°` 2:1 isometric 3×3 SSAA HD 3D characters, props, painted Dual-Grid terrain, true 3D normal maps & `KRAFTEERS_PRESETS` | Yes |
|
|
24
|
+
| `@holtjs/craft/pixel` | `PixelCanvas`, `derivePixelRamp`, `derivePaletteVariants`, `compilePixelGrid`, pure-TS compressed `encodePngRgba` | Yes |
|
|
25
|
+
| `@holtjs/craft/rig3d` | Crisp pixel 3D→2D character/humanoid/monster/prop raycaster (~0.4ms/frame), 9 projected sockets, `GRAVEYARD_PRESETS` | Yes |
|
|
26
|
+
| `@holtjs/craft/tilemap` | Textured pixel 16-tile Dual-Grid (`bakePixelDualGridSheet`), 47-tile Blob (`bakePixelBlob47Sheet`), 3×3 Sobel `bakeNormalMapRgba` | Yes |
|
|
27
|
+
| `@holtjs/craft/atlas` | Shelf `packSpriteAtlas` (RGBA + synchronized normal-map atlas) & one-line `registerAtlasOnStage` | Yes |
|
|
28
|
+
| `@holtjs/craft/inspect` | `renderContactSheet` — `1×` native HD or `4×` pixel checkerboard + `3×5` bitmap labels + socket/baseline visual QA PNG | Yes |
|
|
29
|
+
|
|
30
|
+
## 2. Bake Smooth 2:1 Isometric HD 3D Assets (`@holtjs/craft/hd3d`)
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import {
|
|
34
|
+
KRAFTEERS_PRESETS,
|
|
35
|
+
bakeHdCharacterSheet,
|
|
36
|
+
bakeHdDualGridSheet,
|
|
37
|
+
renderHdPropSheet,
|
|
38
|
+
} from '@holtjs/craft/hd3d';
|
|
39
|
+
|
|
40
|
+
// 1. 4-dir (45°/135°/225°/315°) smooth 96x96 Explorer + exact 3D camera-space normal map!
|
|
41
|
+
const explorer = bakeHdCharacterSheet(KRAFTEERS_PRESETS.explorerBody, {
|
|
42
|
+
cellSize: 96,
|
|
43
|
+
ss: 3,
|
|
44
|
+
dirs: 4,
|
|
45
|
+
rows: [{ clip: 'walk' }, { clip: KRAFTEERS_PRESETS.clips.swing, name: 'swing' }],
|
|
46
|
+
cosmetics: [
|
|
47
|
+
KRAFTEERS_PRESETS.cosmetics.goldenPickaxe,
|
|
48
|
+
KRAFTEERS_PRESETS.cosmetics.expeditionTorch,
|
|
49
|
+
],
|
|
50
|
+
bakeNormals: true,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// 2. Smooth 2:1 isometric 4-dir defense turret & painted 64x64 Dual-Grid turf
|
|
54
|
+
const ballista = renderHdPropSheet(KRAFTEERS_PRESETS.props.ballistaTurret, { resolutionScale: 2.25, ss: 3 });
|
|
55
|
+
const turf = bakeHdDualGridSheet({
|
|
56
|
+
id: 'lush_turf',
|
|
57
|
+
tileSize: 64,
|
|
58
|
+
baseColor: '#22c55e',
|
|
59
|
+
accentColor: '#86efac',
|
|
60
|
+
style: 'grass',
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 3. Bake Crisp Pixel Characters, Props & Autotiles (`@holtjs/craft/rig3d` + `/tilemap`)
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { GRAVEYARD_PRESETS, bakeDirectionalCharacterSheet, renderDecorPropSheet } from '@holtjs/craft/rig3d';
|
|
68
|
+
import { bakePixelDualGridSheet, bakePixelBlob47Sheet } from '@holtjs/craft/tilemap';
|
|
69
|
+
|
|
70
|
+
const keeper = bakeDirectionalCharacterSheet(GRAVEYARD_PRESETS.keeperBody, {
|
|
71
|
+
dirs: 4,
|
|
72
|
+
rows: [{ clip: 'walk' }, { clip: GRAVEYARD_PRESETS.clips.chop, name: 'chop' }],
|
|
73
|
+
cosmetics: [GRAVEYARD_PRESETS.cosmetics.ironAxe, GRAVEYARD_PRESETS.cosmetics.blazingTorch],
|
|
74
|
+
});
|
|
75
|
+
const tombstone = renderDecorPropSheet(GRAVEYARD_PRESETS.props.tombstone);
|
|
76
|
+
const cobble = bakePixelDualGridSheet({ id: 'cobble', tileSize: 32, baseColor: '#64748b', style: 'cobble' });
|
|
77
|
+
const fence = bakePixelBlob47Sheet({ id: 'fence', tileSize: 32, capColor: '#475569', style: 'iron_fence' });
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 4. Pack into `@holtjs/stage` & Visually Inspect (`@holtjs/craft/atlas` + `/inspect`)
|
|
81
|
+
|
|
82
|
+
**Golden Rule for AI Agents**: Always render a `renderContactSheet()` PNG (`scale: 1` for `/hd3d`, `scale: 3` or `4` for `/rig3d` pixel art) and inspect it visually before shipping new custom bodies, props, or tiles!
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import fs from 'node:fs';
|
|
86
|
+
import { packSpriteAtlas, registerAtlasOnStage } from '@holtjs/craft/atlas';
|
|
87
|
+
import { renderContactSheet } from '@holtjs/craft/inspect';
|
|
88
|
+
|
|
89
|
+
const sheet = renderContactSheet(
|
|
90
|
+
[
|
|
91
|
+
{ label: 'EXPLORER HD 4-DIR', sprite: explorer, cellW: 96, cellH: 96 },
|
|
92
|
+
{ label: 'BALLISTA 4-DIR', sprite: ballista, cellW: ballista.frameW },
|
|
93
|
+
{ label: 'DUAL-GRID TURF', sprite: turf, cellW: 64, cellH: 64 },
|
|
94
|
+
],
|
|
95
|
+
{ scale: 1, columns: 3, title: 'HD ASSET QA' },
|
|
96
|
+
);
|
|
97
|
+
fs.writeFileSync('asset-qa.png', sheet.png);
|
|
98
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# `@holtjs/craft` Subpath API Reference
|
|
2
|
+
|
|
3
|
+
All symbols verified against `src/*.ts` (`@holtjs/craft@0.2.0`, 7 subpaths, 0 runtime dependencies, 0 DOM globals).
|
|
4
|
+
|
|
5
|
+
## `@holtjs/craft` (Barrel)
|
|
6
|
+
- Default & named `Craft` namespace + all exports from `./hd3d`, `./pixel`, `./rig3d`, `./tilemap`, `./atlas`, and `./inspect`.
|
|
7
|
+
|
|
8
|
+
## `@holtjs/craft/hd3d` (Smooth 2:1 Isometric HD 3D Baker)
|
|
9
|
+
- Character Bakers: `renderHdCharacterCell(bodyOrCustom, animOrClip, frame?, yawRad?, opts?)` -> `HdRenderedCell` (`{ width, height, rgba, normalRgba }`), `bakeHdCharacterSheet(bodyOrCustom, opts?)` -> `HdBakedCharacterSheet`
|
|
10
|
+
- Prop Bakers: `renderHdPropSprite(spec, dir4?, opts?)` -> `HdRenderedCell`, `renderHdPropSheet(spec, opts?)`
|
|
11
|
+
- Smooth Painted Terrain Baker: `bakeHdDualGridSheet(spec)` -> `HdBakedTileset` (`64x64` default seamless 16-tile Dual-Grid + normal map)
|
|
12
|
+
- Presets: `KRAFTEERS_PRESETS` (`explorerBody`, `tombMummyBody`, `cosmetics.{goldenPickaxe,expeditionTorch}`, `clips.{swing,shamble}`, `props.{pharaohObelisk,ballistaTurret,fortressWall,stylizedTree}`)
|
|
13
|
+
- Types: `HdCameraOptions`, `HdBakeCharacterOptions`, `HdBakedCharacterSheet`, `HdRenderedCell`, `HdPropRenderOptions`, `HdDualGridSpec`, `HdBakedTileset`
|
|
14
|
+
|
|
15
|
+
## `@holtjs/craft/pixel`
|
|
16
|
+
- Color & Ramps: `parseHexRgb(hex)`, `rgbToHex(rgb)`, `mixRgb(a, b, t)`, `derivePixelRamp(hexOrRgb)` (`[light, base, shade, outline]`), `derivePaletteVariants(baseHex, count?)`
|
|
17
|
+
- `PixelCanvas`: `.clear()`, `.setPixel()`, `.getPixel()`, `.fillRect()`, `.strokeRect()`, `.fillEllipse()`, `.drawLine()`, `.blit()`, `.flipX()`, `.applyOrderedDither()`, `.addSelectiveOutline()`, `.addContactShadow()`, `.clone()`, `.toPng()`
|
|
18
|
+
- Declarative Grid & PNG: `compilePixelGrid(spec, opts?)`, `encodePngRgba(width, height, rgba)` (pure-TS Fixed-Huffman LZ77 RFC-2083 PNG encoder)
|
|
19
|
+
- Types: `Rgb`, `Rgba`, `Ramp4`, `PixelSpriteLike`, `AsciiPixelGridSpec`, `CompilePixelGridOptions`
|
|
20
|
+
|
|
21
|
+
## `@holtjs/craft/rig3d` (Crisp Pixel 3D→2D & Socket Baker)
|
|
22
|
+
- Multi-Direction Character Baker & Presets: `bakeDirectionalCharacterSheet(bodyOrCustom, opts?)`, `GRAVEYARD_PRESETS` (`keeperBody`, `zombieBody`, `cosmetics.{ironAxe,blazingTorch}`, `clips.{chop,shamble}`, `props.{tombstone,woodenChest,stoneFurnace,arrowTower,ancientPine}`)
|
|
23
|
+
- 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`
|
|
24
|
+
- Analytical 3D->2D Rasterizers: `renderRigPose`, `renderRigClipStrip`, `renderBodyAnimStrip`, `renderCosmeticSprite`, `compositeSpriteRgba`, `renderDecorPropSprite`, `renderDecorPropSheet`, `renderBodyRestPreview`
|
|
25
|
+
- Strict Validators: `validateRigCosmetic`, `validateRigClip`, `validateRigCustomBody`, `validateRigDecorProp`, `validateRigPrimitiveList`, `validateRigPixelSprite`
|
|
26
|
+
|
|
27
|
+
## `@holtjs/craft/tilemap`
|
|
28
|
+
- Autotile Masks: `computeDualGridMask(tl, tr, bl, br)`, `computeBlob47Index(...)`, `BLOB47_CANONICAL_MASKS`
|
|
29
|
+
- Pixel Tileset & Normal-Map Bakers: `bakePixelDualGridSheet(spec)`, `bakePixelBlob47Sheet(spec)`, `bakeNormalMapRgba(rgba, width, height, opts?)`
|
|
30
|
+
- Types: `TerrainTextureStyle`, `PixelDualGridSpec`, `PixelBlob47Spec`, `BakedPixelTileset`
|
|
31
|
+
|
|
32
|
+
## `@holtjs/craft/atlas`
|
|
33
|
+
- `packSpriteAtlas(items, opts?)` -> `PackedSpriteAtlas` (`.width`, `.height`, `.rgba`, `.normalRgba`, `.frames`, `.toPng()`, `.toNormalPng()`)
|
|
34
|
+
- Stage Integration: `writeRgbaToCanvas(sprite, createCanvas)`, `registerAtlasOnStage(scene, textureKey, atlas, createCanvas)`
|
|
35
|
+
- Types: `AtlasInputItem`, `PackedFrameRect`, `PackAtlasOptions`, `PackedSpriteAtlas`, `StageSceneTextureHost`, `MinimalCanvas2D`
|
|
36
|
+
|
|
37
|
+
## `@holtjs/craft/inspect`
|
|
38
|
+
- `renderContactSheet(items, opts?)` -> `ContactSheetResult` (`{ width, height, scale, rgba, png }`)
|
|
39
|
+
- Types: `InspectMarker`, `ContactSheetItem`, `ContactSheetOptions`, `ContactSheetResult`
|