@nodetool-ai/image-nodes 0.8.1
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/README.md +94 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/game.d.ts +68 -0
- package/dist/nodes/game.d.ts.map +1 -0
- package/dist/nodes/game.js +551 -0
- package/dist/nodes/game.js.map +1 -0
- package/dist/nodes/gpu-device.d.ts +59 -0
- package/dist/nodes/gpu-device.d.ts.map +1 -0
- package/dist/nodes/gpu-device.js +144 -0
- package/dist/nodes/gpu-device.js.map +1 -0
- package/dist/nodes/image-io.d.ts +122 -0
- package/dist/nodes/image-io.d.ts.map +1 -0
- package/dist/nodes/image-io.js +381 -0
- package/dist/nodes/image-io.js.map +1 -0
- package/dist/nodes/image.d.ts +649 -0
- package/dist/nodes/image.d.ts.map +1 -0
- package/dist/nodes/image.js +2827 -0
- package/dist/nodes/image.js.map +1 -0
- package/dist/nodes/lib-grid.d.ts +19 -0
- package/dist/nodes/lib-grid.d.ts.map +1 -0
- package/dist/nodes/lib-grid.js +134 -0
- package/dist/nodes/lib-grid.js.map +1 -0
- package/dist/nodes/lib-image-channel.d.ts +38 -0
- package/dist/nodes/lib-image-channel.d.ts.map +1 -0
- package/dist/nodes/lib-image-channel.js +55 -0
- package/dist/nodes/lib-image-channel.js.map +1 -0
- package/dist/nodes/lib-image-color-grading.d.ts +3 -0
- package/dist/nodes/lib-image-color-grading.d.ts.map +1 -0
- package/dist/nodes/lib-image-color-grading.js +1080 -0
- package/dist/nodes/lib-image-color-grading.js.map +1 -0
- package/dist/nodes/lib-image-color.d.ts +96 -0
- package/dist/nodes/lib-image-color.d.ts.map +1 -0
- package/dist/nodes/lib-image-color.js +150 -0
- package/dist/nodes/lib-image-color.js.map +1 -0
- package/dist/nodes/lib-image-draw.d.ts +4 -0
- package/dist/nodes/lib-image-draw.d.ts.map +1 -0
- package/dist/nodes/lib-image-draw.js +464 -0
- package/dist/nodes/lib-image-draw.js.map +1 -0
- package/dist/nodes/lib-image-effects.d.ts +72 -0
- package/dist/nodes/lib-image-effects.d.ts.map +1 -0
- package/dist/nodes/lib-image-effects.js +123 -0
- package/dist/nodes/lib-image-effects.js.map +1 -0
- package/dist/nodes/lib-image-enhance.d.ts +3 -0
- package/dist/nodes/lib-image-enhance.d.ts.map +1 -0
- package/dist/nodes/lib-image-enhance.js +442 -0
- package/dist/nodes/lib-image-enhance.js.map +1 -0
- package/dist/nodes/lib-image-filter-extras.d.ts +72 -0
- package/dist/nodes/lib-image-filter-extras.d.ts.map +1 -0
- package/dist/nodes/lib-image-filter-extras.js +110 -0
- package/dist/nodes/lib-image-filter-extras.js.map +1 -0
- package/dist/nodes/lib-image-filter.d.ts +3 -0
- package/dist/nodes/lib-image-filter.d.ts.map +1 -0
- package/dist/nodes/lib-image-filter.js +588 -0
- package/dist/nodes/lib-image-filter.js.map +1 -0
- package/dist/nodes/lib-image-generators.d.ts +71 -0
- package/dist/nodes/lib-image-generators.d.ts.map +1 -0
- package/dist/nodes/lib-image-generators.js +158 -0
- package/dist/nodes/lib-image-generators.js.map +1 -0
- package/dist/nodes/lib-image-keyer.d.ts +34 -0
- package/dist/nodes/lib-image-keyer.d.ts.map +1 -0
- package/dist/nodes/lib-image-keyer.js +61 -0
- package/dist/nodes/lib-image-keyer.js.map +1 -0
- package/dist/nodes/lib-image-mask.d.ts +47 -0
- package/dist/nodes/lib-image-mask.d.ts.map +1 -0
- package/dist/nodes/lib-image-mask.js +59 -0
- package/dist/nodes/lib-image-mask.js.map +1 -0
- package/dist/nodes/lib-image-utils.d.ts +16 -0
- package/dist/nodes/lib-image-utils.d.ts.map +1 -0
- package/dist/nodes/lib-image-utils.js +61 -0
- package/dist/nodes/lib-image-utils.js.map +1 -0
- package/dist/nodes/lib-image-warp.d.ts +112 -0
- package/dist/nodes/lib-image-warp.d.ts.map +1 -0
- package/dist/nodes/lib-image-warp.js +236 -0
- package/dist/nodes/lib-image-warp.js.map +1 -0
- package/dist/nodes/lib-shader-utils.d.ts +105 -0
- package/dist/nodes/lib-shader-utils.d.ts.map +1 -0
- package/dist/nodes/lib-shader-utils.js +452 -0
- package/dist/nodes/lib-shader-utils.js.map +1 -0
- package/dist/nodes/sketch.d.ts +62 -0
- package/dist/nodes/sketch.d.ts.map +1 -0
- package/dist/nodes/sketch.js +325 -0
- package/dist/nodes/sketch.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Game asset slot nodes. Each takes a generated image, measures it, and stamps
|
|
9
|
+
* the ref with a `SlotFill` under `metadata.nodetool_slot` so native game staging
|
|
10
|
+
* reads frame regions off the sheet without looking at pixels. Nothing here
|
|
11
|
+
* calls a model; generation is upstream.
|
|
12
|
+
*/
|
|
13
|
+
import { BaseNode, isObjectLike, isString, prop } from "@nodetool-ai/node-sdk";
|
|
14
|
+
import { SLOT_METADATA_KEY, imageFill, readSlotProp, slotCheckerProps, spritesheetFill, tilesetFill } from "@nodetool-ai/protocol";
|
|
15
|
+
import { loadMediaRefBytes } from "@nodetool-ai/runtime/media-ref-bytes";
|
|
16
|
+
import { loadSharp, SHARP_UNAVAILABLE_MESSAGE } from "./image-io.js";
|
|
17
|
+
/** Animations that play once by default. Everything else loops. */
|
|
18
|
+
const ONE_SHOT_ANIMATIONS = ["jump", "hurt", "die", "attack"];
|
|
19
|
+
const EMPTY_IMAGE = {
|
|
20
|
+
type: "image",
|
|
21
|
+
uri: "",
|
|
22
|
+
asset_id: null,
|
|
23
|
+
data: null,
|
|
24
|
+
metadata: null
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Read the input through the context-aware loader (inline bytes, `asset://`
|
|
28
|
+
* through the asset store, a storage key) and hand back PNG bytes, re-encoding
|
|
29
|
+
* a JPEG or WebP generation so the exported `.png` path holds a PNG.
|
|
30
|
+
*/
|
|
31
|
+
async function measureImage(nodeName, image, context) {
|
|
32
|
+
const sharp = await loadSharp();
|
|
33
|
+
if (!sharp) {
|
|
34
|
+
throw new Error(`${nodeName}: ${SHARP_UNAVAILABLE_MESSAGE}`);
|
|
35
|
+
}
|
|
36
|
+
const bytes = isObjectLike(image)
|
|
37
|
+
? await loadMediaRefBytes(image, context)
|
|
38
|
+
: null;
|
|
39
|
+
if (!bytes || bytes.length === 0) {
|
|
40
|
+
throw new Error(`${nodeName}: image input is required.`);
|
|
41
|
+
}
|
|
42
|
+
const meta = await sharp(bytes, { failOn: "none" }).metadata();
|
|
43
|
+
const width = meta.width ?? 0;
|
|
44
|
+
const height = meta.height ?? 0;
|
|
45
|
+
if (width <= 0 || height <= 0) {
|
|
46
|
+
throw new Error(`${nodeName}: input image has invalid dimensions.`);
|
|
47
|
+
}
|
|
48
|
+
const buf = meta.format === "png"
|
|
49
|
+
? Buffer.from(bytes)
|
|
50
|
+
: await sharp(bytes, { failOn: "none" }).png().toBuffer();
|
|
51
|
+
return { buf, width, height };
|
|
52
|
+
}
|
|
53
|
+
function positiveInt(nodeName, name, value) {
|
|
54
|
+
const n = Number(value);
|
|
55
|
+
if (!Number.isInteger(n) || n <= 0) {
|
|
56
|
+
throw new Error(`${nodeName}: ${name} must be a positive integer, got ${String(value)}.`);
|
|
57
|
+
}
|
|
58
|
+
return n;
|
|
59
|
+
}
|
|
60
|
+
/** Columns and rows of a sheet whose size is an exact multiple of the cell. */
|
|
61
|
+
function deriveGrid(nodeName, img, cellWidth, cellHeight) {
|
|
62
|
+
if (img.width % cellWidth !== 0 || img.height % cellHeight !== 0) {
|
|
63
|
+
throw new Error(`${nodeName}: image ${img.width}x${img.height} is not a multiple of cell ${cellWidth}x${cellHeight}.`);
|
|
64
|
+
}
|
|
65
|
+
return { columns: img.width / cellWidth, rows: img.height / cellHeight };
|
|
66
|
+
}
|
|
67
|
+
function slotIdOf(nodeName, value) {
|
|
68
|
+
if (!isString(value) || value.length === 0) {
|
|
69
|
+
throw new Error(`${nodeName}: slot_id is required.`);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
/** The `game_slot` prop description every checker repeats. */
|
|
74
|
+
const SLOT_PROP_DESCRIPTION = "The manifest slot to fill, straight from LoadGameTemplate or SlotPrompt. " +
|
|
75
|
+
"When connected it supplies slot_id and the numbers below, so the fields " +
|
|
76
|
+
"beside it are ignored.";
|
|
77
|
+
/**
|
|
78
|
+
* The checker props a connected `game_slot` dictates, or an empty bag.
|
|
79
|
+
*
|
|
80
|
+
* A connected slot wins over every hand-typed field it covers: a graph rewired
|
|
81
|
+
* from one slot to another would otherwise stamp a fill from the numbers left
|
|
82
|
+
* behind by the first, and `checkSlotFill` would accept it because the fill and
|
|
83
|
+
* the slot it names agree with each other and with nothing else.
|
|
84
|
+
*/
|
|
85
|
+
function slotOverrides(nodeName, value, kind) {
|
|
86
|
+
let spec;
|
|
87
|
+
try {
|
|
88
|
+
spec = readSlotProp(value, kind);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new Error(`${nodeName}: ${error instanceof Error ? error.message : String(error)}`);
|
|
92
|
+
}
|
|
93
|
+
return spec ? slotCheckerProps(spec) : {};
|
|
94
|
+
}
|
|
95
|
+
/** A dict prop that may arrive as a JSON object string. */
|
|
96
|
+
function parseDict(nodeName, name, value) {
|
|
97
|
+
if (value == null || value === "") {
|
|
98
|
+
return {};
|
|
99
|
+
}
|
|
100
|
+
let parsed = value;
|
|
101
|
+
if (isString(value)) {
|
|
102
|
+
try {
|
|
103
|
+
parsed = JSON.parse(value);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new Error(`${nodeName}: ${name} is not valid JSON.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (!isObjectLike(parsed) || Array.isArray(parsed)) {
|
|
110
|
+
throw new Error(`${nodeName}: ${name} must be a JSON object.`);
|
|
111
|
+
}
|
|
112
|
+
return parsed;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Store the stamped sheet as its own asset when the context can, so the fill
|
|
116
|
+
* outlives the run: native game staging reads it back off the asset row.
|
|
117
|
+
* Without `createAsset` (a hermetic run, a graph with no store) the ref is
|
|
118
|
+
* returned inline and the caller keeps it.
|
|
119
|
+
*/
|
|
120
|
+
async function persistStamped(context, nodeName, slotId, ref) {
|
|
121
|
+
if (!context?.hasModelInterface?.("createAsset"))
|
|
122
|
+
return ref;
|
|
123
|
+
const created = (await context.createAsset({
|
|
124
|
+
name: `${slotId.replace(/\./g, "_")}.png`,
|
|
125
|
+
contentType: "image/png",
|
|
126
|
+
content: ref.data,
|
|
127
|
+
metadata: ref.metadata
|
|
128
|
+
}));
|
|
129
|
+
const id = created ? created["id"] : null;
|
|
130
|
+
if (!isString(id) || id === "")
|
|
131
|
+
throw new Error(`${nodeName}: the asset was created without an id.`);
|
|
132
|
+
return { ...ref, uri: `asset://${id}.png`, asset_id: id };
|
|
133
|
+
}
|
|
134
|
+
function stampFill(image, img, fill) {
|
|
135
|
+
const source = isObjectLike(image) ? image : {};
|
|
136
|
+
const previous = isObjectLike(source.metadata)
|
|
137
|
+
? source.metadata
|
|
138
|
+
: {};
|
|
139
|
+
return {
|
|
140
|
+
...source,
|
|
141
|
+
type: "image",
|
|
142
|
+
data: new Uint8Array(img.buf),
|
|
143
|
+
metadata: { ...previous, [SLOT_METADATA_KEY]: fill }
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function formatZodIssues(nodeName, error) {
|
|
147
|
+
const lines = error.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`);
|
|
148
|
+
return new Error(`${nodeName}: fill failed validation. ${lines.join("; ")}`);
|
|
149
|
+
}
|
|
150
|
+
export class SpriteSheetNode extends BaseNode {
|
|
151
|
+
static nodeType = "nodetool.game.SpriteSheet";
|
|
152
|
+
static title = "Sprite Sheet";
|
|
153
|
+
static description = "Describe a generated sprite sheet for a game slot: derive the grid from the cell size, assign each animation a row-major frame range, and stamp the image with the slot fill.\n game, sprite, spritesheet, animation, slot\n\n Use cases:\n - Fill a spritesheet slot of a game template from a generated sheet\n - Record frame regions and loop flags without slicing the image\n - Reject sheets whose size does not match the cell or hold too few frames";
|
|
154
|
+
static metadataOutputTypes = {
|
|
155
|
+
output: "image",
|
|
156
|
+
fill: "dict"
|
|
157
|
+
};
|
|
158
|
+
static inlineFields = ["cell_width", "cell_height", "fps"];
|
|
159
|
+
static inputFields = ["image", "slot"];
|
|
160
|
+
async process(context) {
|
|
161
|
+
const name = SpriteSheetNode.title;
|
|
162
|
+
const fromSlot = slotOverrides(name, this.slot, "spritesheet");
|
|
163
|
+
const img = await measureImage(name, this.image, context);
|
|
164
|
+
const cellWidth = positiveInt(name, "cell_width", fromSlot.cell_width ?? this.cell_width);
|
|
165
|
+
const cellHeight = positiveInt(name, "cell_height", fromSlot.cell_height ?? this.cell_height);
|
|
166
|
+
const fps = positiveInt(name, "fps", fromSlot.fps ?? this.fps);
|
|
167
|
+
const slotId = slotIdOf(name, fromSlot.slot_id ?? this.slot_id);
|
|
168
|
+
const { columns, rows } = deriveGrid(name, img, cellWidth, cellHeight);
|
|
169
|
+
const requested = parseDict(name, "animations", fromSlot.animations ?? this.animations);
|
|
170
|
+
const entries = Object.entries(requested);
|
|
171
|
+
if (entries.length === 0) {
|
|
172
|
+
throw new Error(`${name}: animations must name at least one animation.`);
|
|
173
|
+
}
|
|
174
|
+
const overrides = new Map();
|
|
175
|
+
for (const [animation, value] of Object.entries(parseDict(name, "loop", this.loop))) {
|
|
176
|
+
if (value !== true && value !== false) {
|
|
177
|
+
throw new Error(`${name}: loop.${animation} must be true or false.`);
|
|
178
|
+
}
|
|
179
|
+
overrides.set(animation, value);
|
|
180
|
+
}
|
|
181
|
+
const capacity = columns * rows;
|
|
182
|
+
const animations = {};
|
|
183
|
+
let cursor = 0;
|
|
184
|
+
for (const [animation, count] of entries) {
|
|
185
|
+
const frames = positiveInt(name, `animations.${animation}`, count);
|
|
186
|
+
const loop = overrides.get(animation) ??
|
|
187
|
+
!ONE_SHOT_ANIMATIONS.includes(animation);
|
|
188
|
+
animations[animation] = {
|
|
189
|
+
from: cursor,
|
|
190
|
+
to: cursor + frames - 1,
|
|
191
|
+
fps,
|
|
192
|
+
loop
|
|
193
|
+
};
|
|
194
|
+
cursor += frames;
|
|
195
|
+
}
|
|
196
|
+
if (cursor > capacity) {
|
|
197
|
+
throw new Error(`${name}: animations need ${cursor} frames, sheet holds ${capacity} (${columns}x${rows}).`);
|
|
198
|
+
}
|
|
199
|
+
const parsed = spritesheetFill.safeParse({
|
|
200
|
+
kind: "spritesheet",
|
|
201
|
+
slot_id: slotId,
|
|
202
|
+
cell: [cellWidth, cellHeight],
|
|
203
|
+
columns,
|
|
204
|
+
rows,
|
|
205
|
+
animations
|
|
206
|
+
});
|
|
207
|
+
if (!parsed.success) {
|
|
208
|
+
throw formatZodIssues(name, parsed.error);
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
output: await persistStamped(context, name, parsed.data.slot_id, stampFill(this.image, img, parsed.data)),
|
|
212
|
+
fill: parsed.data
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
__decorate([
|
|
217
|
+
prop({
|
|
218
|
+
type: "image",
|
|
219
|
+
default: EMPTY_IMAGE,
|
|
220
|
+
title: "Image",
|
|
221
|
+
description: "The generated sprite sheet."
|
|
222
|
+
})
|
|
223
|
+
], SpriteSheetNode.prototype, "image", void 0);
|
|
224
|
+
__decorate([
|
|
225
|
+
prop({
|
|
226
|
+
type: "game_slot",
|
|
227
|
+
default: null,
|
|
228
|
+
title: "Slot",
|
|
229
|
+
description: SLOT_PROP_DESCRIPTION
|
|
230
|
+
})
|
|
231
|
+
], SpriteSheetNode.prototype, "slot", void 0);
|
|
232
|
+
__decorate([
|
|
233
|
+
prop({
|
|
234
|
+
type: "int",
|
|
235
|
+
default: 32,
|
|
236
|
+
title: "Cell Width",
|
|
237
|
+
description: "Pixel width of one frame.",
|
|
238
|
+
min: 1
|
|
239
|
+
})
|
|
240
|
+
], SpriteSheetNode.prototype, "cell_width", void 0);
|
|
241
|
+
__decorate([
|
|
242
|
+
prop({
|
|
243
|
+
type: "int",
|
|
244
|
+
default: 32,
|
|
245
|
+
title: "Cell Height",
|
|
246
|
+
description: "Pixel height of one frame.",
|
|
247
|
+
min: 1
|
|
248
|
+
})
|
|
249
|
+
], SpriteSheetNode.prototype, "cell_height", void 0);
|
|
250
|
+
__decorate([
|
|
251
|
+
prop({
|
|
252
|
+
type: "dict",
|
|
253
|
+
default: {},
|
|
254
|
+
title: "Animations",
|
|
255
|
+
description: "Animation name to frame count, in sheet order. A dict or a JSON object string, e.g. {\"idle\": 4, \"run\": 8}."
|
|
256
|
+
})
|
|
257
|
+
], SpriteSheetNode.prototype, "animations", void 0);
|
|
258
|
+
__decorate([
|
|
259
|
+
prop({
|
|
260
|
+
type: "int",
|
|
261
|
+
default: 8,
|
|
262
|
+
title: "FPS",
|
|
263
|
+
description: "Frames per second for every animation.",
|
|
264
|
+
min: 1
|
|
265
|
+
})
|
|
266
|
+
], SpriteSheetNode.prototype, "fps", void 0);
|
|
267
|
+
__decorate([
|
|
268
|
+
prop({
|
|
269
|
+
type: "str",
|
|
270
|
+
default: "",
|
|
271
|
+
title: "Slot ID",
|
|
272
|
+
description: "The manifest slot this sheet fills, e.g. player."
|
|
273
|
+
})
|
|
274
|
+
], SpriteSheetNode.prototype, "slot_id", void 0);
|
|
275
|
+
__decorate([
|
|
276
|
+
prop({
|
|
277
|
+
type: "dict",
|
|
278
|
+
default: {},
|
|
279
|
+
title: "Loop",
|
|
280
|
+
description: "Per-animation loop overrides, name to boolean. By default every animation loops except jump, hurt, die and attack."
|
|
281
|
+
})
|
|
282
|
+
], SpriteSheetNode.prototype, "loop", void 0);
|
|
283
|
+
export class TilesetNode extends BaseNode {
|
|
284
|
+
static nodeType = "nodetool.game.Tileset";
|
|
285
|
+
static title = "Tileset";
|
|
286
|
+
static description = "Describe a generated tileset for a game slot: derive the grid from the cell size and stamp the image with the slot fill.\n game, tileset, tiles, tilemap, slot\n\n Use cases:\n - Fill a tileset slot of a game template from a generated sheet\n - Record the cell size and tile count without slicing the image\n - Reject sheets whose size does not match the cell or hold too few tiles";
|
|
287
|
+
static metadataOutputTypes = {
|
|
288
|
+
output: "image",
|
|
289
|
+
fill: "dict"
|
|
290
|
+
};
|
|
291
|
+
static inlineFields = ["cell_width", "cell_height", "count"];
|
|
292
|
+
static inputFields = ["image", "slot"];
|
|
293
|
+
async process(context) {
|
|
294
|
+
const name = TilesetNode.title;
|
|
295
|
+
const fromSlot = slotOverrides(name, this.slot, "tileset");
|
|
296
|
+
const img = await measureImage(name, this.image, context);
|
|
297
|
+
const cellWidth = positiveInt(name, "cell_width", fromSlot.cell_width ?? this.cell_width);
|
|
298
|
+
const cellHeight = positiveInt(name, "cell_height", fromSlot.cell_height ?? this.cell_height);
|
|
299
|
+
const count = positiveInt(name, "count", fromSlot.count ?? this.count);
|
|
300
|
+
const slotId = slotIdOf(name, fromSlot.slot_id ?? this.slot_id);
|
|
301
|
+
const { columns, rows } = deriveGrid(name, img, cellWidth, cellHeight);
|
|
302
|
+
if (count > columns * rows) {
|
|
303
|
+
throw new Error(`${name}: ${count} tiles do not fit ${columns}x${rows}.`);
|
|
304
|
+
}
|
|
305
|
+
const parsed = tilesetFill.safeParse({
|
|
306
|
+
kind: "tileset",
|
|
307
|
+
slot_id: slotId,
|
|
308
|
+
cell: [cellWidth, cellHeight],
|
|
309
|
+
columns,
|
|
310
|
+
rows,
|
|
311
|
+
count
|
|
312
|
+
});
|
|
313
|
+
if (!parsed.success) {
|
|
314
|
+
throw formatZodIssues(name, parsed.error);
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
output: await persistStamped(context, name, parsed.data.slot_id, stampFill(this.image, img, parsed.data)),
|
|
318
|
+
fill: parsed.data
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
__decorate([
|
|
323
|
+
prop({
|
|
324
|
+
type: "image",
|
|
325
|
+
default: EMPTY_IMAGE,
|
|
326
|
+
title: "Image",
|
|
327
|
+
description: "The generated tileset sheet."
|
|
328
|
+
})
|
|
329
|
+
], TilesetNode.prototype, "image", void 0);
|
|
330
|
+
__decorate([
|
|
331
|
+
prop({
|
|
332
|
+
type: "game_slot",
|
|
333
|
+
default: null,
|
|
334
|
+
title: "Slot",
|
|
335
|
+
description: SLOT_PROP_DESCRIPTION
|
|
336
|
+
})
|
|
337
|
+
], TilesetNode.prototype, "slot", void 0);
|
|
338
|
+
__decorate([
|
|
339
|
+
prop({
|
|
340
|
+
type: "int",
|
|
341
|
+
default: 16,
|
|
342
|
+
title: "Cell Width",
|
|
343
|
+
description: "Pixel width of one tile.",
|
|
344
|
+
min: 1
|
|
345
|
+
})
|
|
346
|
+
], TilesetNode.prototype, "cell_width", void 0);
|
|
347
|
+
__decorate([
|
|
348
|
+
prop({
|
|
349
|
+
type: "int",
|
|
350
|
+
default: 16,
|
|
351
|
+
title: "Cell Height",
|
|
352
|
+
description: "Pixel height of one tile.",
|
|
353
|
+
min: 1
|
|
354
|
+
})
|
|
355
|
+
], TilesetNode.prototype, "cell_height", void 0);
|
|
356
|
+
__decorate([
|
|
357
|
+
prop({
|
|
358
|
+
type: "int",
|
|
359
|
+
default: 1,
|
|
360
|
+
title: "Count",
|
|
361
|
+
description: "Number of distinct tiles on the sheet, row-major from the top left.",
|
|
362
|
+
min: 1
|
|
363
|
+
})
|
|
364
|
+
], TilesetNode.prototype, "count", void 0);
|
|
365
|
+
__decorate([
|
|
366
|
+
prop({
|
|
367
|
+
type: "str",
|
|
368
|
+
default: "",
|
|
369
|
+
title: "Slot ID",
|
|
370
|
+
description: "The manifest slot this tileset fills, e.g. tiles.ground."
|
|
371
|
+
})
|
|
372
|
+
], TilesetNode.prototype, "slot_id", void 0);
|
|
373
|
+
/**
|
|
374
|
+
* Mean absolute per-channel (RGB) difference between two pixel lines of an
|
|
375
|
+
* RGBA buffer, given the byte offset of pixel i on each line.
|
|
376
|
+
*/
|
|
377
|
+
function meanEdgeDifference(rgba, length, offsetA, offsetB) {
|
|
378
|
+
let total = 0;
|
|
379
|
+
for (let i = 0; i < length; i++) {
|
|
380
|
+
const a = offsetA(i);
|
|
381
|
+
const b = offsetB(i);
|
|
382
|
+
for (let c = 0; c < 3; c++) {
|
|
383
|
+
total += Math.abs(rgba[a + c] - rgba[b + c]);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return total / (length * 3);
|
|
387
|
+
}
|
|
388
|
+
function repairEdgeBand(rgba, width, height, axis) {
|
|
389
|
+
const extent = axis === "x" ? width : height;
|
|
390
|
+
const length = axis === "x" ? height : width;
|
|
391
|
+
const band = Math.min(Math.floor(extent / 2), Math.max(1, Math.ceil(extent * 0.1)));
|
|
392
|
+
for (let depth = 0; depth < band; depth++) {
|
|
393
|
+
const t = depth / band;
|
|
394
|
+
const weight = (1 - t * t * (3 - 2 * t)) / 2;
|
|
395
|
+
for (let i = 0; i < length; i++) {
|
|
396
|
+
const a = (axis === "x" ? i * width + depth : depth * width + i) * 4;
|
|
397
|
+
const b = (axis === "x" ? i * width + width - 1 - depth : (height - 1 - depth) * width + i) * 4;
|
|
398
|
+
// Blend premultiplied colors so invisible RGB cannot tint opaque pixels.
|
|
399
|
+
const alphaA = rgba[a + 3];
|
|
400
|
+
const alphaB = rgba[b + 3];
|
|
401
|
+
const blendedA = alphaA * (1 - weight) + alphaB * weight;
|
|
402
|
+
const blendedB = alphaB * (1 - weight) + alphaA * weight;
|
|
403
|
+
for (let c = 0; c < 3; c++) {
|
|
404
|
+
const colorA = rgba[a + c] * alphaA;
|
|
405
|
+
const colorB = rgba[b + c] * alphaB;
|
|
406
|
+
rgba[a + c] = blendedA === 0 ? 0 : Math.round((colorA * (1 - weight) + colorB * weight) / blendedA);
|
|
407
|
+
rgba[b + c] = blendedB === 0 ? 0 : Math.round((colorB * (1 - weight) + colorA * weight) / blendedB);
|
|
408
|
+
}
|
|
409
|
+
rgba[a + 3] = Math.round(blendedA);
|
|
410
|
+
rgba[b + 3] = Math.round(blendedB);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
export class SeamlessImageNode extends BaseNode {
|
|
415
|
+
static nodeType = "nodetool.game.SeamlessImage";
|
|
416
|
+
static title = "Seamless Image";
|
|
417
|
+
static description = "Describe a generated image for a game slot: measure it, compare its opposite edges to decide whether it tiles, and stamp the image with the slot fill.\n game, image, seamless, tileable, background, slot\n\n Use cases:\n - Fill an image slot of a game template from a generated background\n - Prove a background tiles horizontally before use in a scrolling scene\n - Reject images that a template expects to tile but do not";
|
|
418
|
+
static metadataOutputTypes = {
|
|
419
|
+
output: "image",
|
|
420
|
+
fill: "dict"
|
|
421
|
+
};
|
|
422
|
+
static inlineFields = ["check_x", "check_y", "repair", "threshold"];
|
|
423
|
+
static inputFields = ["image", "slot"];
|
|
424
|
+
async process(context) {
|
|
425
|
+
const name = SeamlessImageNode.title;
|
|
426
|
+
const fromSlot = slotOverrides(name, this.slot, "image");
|
|
427
|
+
const img = await measureImage(name, this.image, context);
|
|
428
|
+
const slotId = slotIdOf(name, fromSlot.slot_id ?? this.slot_id);
|
|
429
|
+
const threshold = Number(this.threshold ?? 12);
|
|
430
|
+
if (!Number.isFinite(threshold) || threshold < 0) {
|
|
431
|
+
throw new Error(`${name}: threshold must be a non-negative number.`);
|
|
432
|
+
}
|
|
433
|
+
const checkX = Boolean(fromSlot.check_x ?? this.check_x);
|
|
434
|
+
const checkY = Boolean(fromSlot.check_y ?? this.check_y);
|
|
435
|
+
let seamlessX = false;
|
|
436
|
+
let seamlessY = false;
|
|
437
|
+
if (checkX || checkY) {
|
|
438
|
+
const sharp = await loadSharp();
|
|
439
|
+
if (!sharp) {
|
|
440
|
+
throw new Error(`${name}: ${SHARP_UNAVAILABLE_MESSAGE}`);
|
|
441
|
+
}
|
|
442
|
+
const rgba = await sharp(img.buf, { failOn: "none" })
|
|
443
|
+
.toColourspace("srgb")
|
|
444
|
+
.ensureAlpha()
|
|
445
|
+
.raw()
|
|
446
|
+
.toBuffer();
|
|
447
|
+
const { width, height } = img;
|
|
448
|
+
const stride = width * 4;
|
|
449
|
+
if (this.repair) {
|
|
450
|
+
if (checkX)
|
|
451
|
+
repairEdgeBand(rgba, width, height, "x");
|
|
452
|
+
if (checkY)
|
|
453
|
+
repairEdgeBand(rgba, width, height, "y");
|
|
454
|
+
img.buf = await sharp(rgba, { raw: { width, height, channels: 4 } })
|
|
455
|
+
.png().toBuffer();
|
|
456
|
+
}
|
|
457
|
+
if (checkX) {
|
|
458
|
+
const diff = meanEdgeDifference(rgba, height, (y) => y * stride, (y) => y * stride + (width - 1) * 4);
|
|
459
|
+
seamlessX = diff <= threshold;
|
|
460
|
+
}
|
|
461
|
+
if (checkY) {
|
|
462
|
+
const diff = meanEdgeDifference(rgba, width, (x) => x * 4, (x) => (height - 1) * stride + x * 4);
|
|
463
|
+
seamlessY = diff <= threshold;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
const parsed = imageFill.safeParse({
|
|
467
|
+
kind: "image",
|
|
468
|
+
slot_id: slotId,
|
|
469
|
+
size: [img.width, img.height],
|
|
470
|
+
seamless_x: seamlessX,
|
|
471
|
+
seamless_y: seamlessY
|
|
472
|
+
});
|
|
473
|
+
if (!parsed.success) {
|
|
474
|
+
throw formatZodIssues(name, parsed.error);
|
|
475
|
+
}
|
|
476
|
+
const stampedImage = stampFill(this.image, img, parsed.data);
|
|
477
|
+
if (this.repair && (checkX || checkY)) {
|
|
478
|
+
// The repaired bytes must not retain the original asset's identity.
|
|
479
|
+
stampedImage.uri = "";
|
|
480
|
+
stampedImage.asset_id = null;
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
output: await persistStamped(context, name, parsed.data.slot_id, stampedImage),
|
|
484
|
+
fill: parsed.data
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
__decorate([
|
|
489
|
+
prop({
|
|
490
|
+
type: "image",
|
|
491
|
+
default: EMPTY_IMAGE,
|
|
492
|
+
title: "Image",
|
|
493
|
+
description: "The generated image."
|
|
494
|
+
})
|
|
495
|
+
], SeamlessImageNode.prototype, "image", void 0);
|
|
496
|
+
__decorate([
|
|
497
|
+
prop({
|
|
498
|
+
type: "game_slot",
|
|
499
|
+
default: null,
|
|
500
|
+
title: "Slot",
|
|
501
|
+
description: SLOT_PROP_DESCRIPTION
|
|
502
|
+
})
|
|
503
|
+
], SeamlessImageNode.prototype, "slot", void 0);
|
|
504
|
+
__decorate([
|
|
505
|
+
prop({
|
|
506
|
+
type: "str",
|
|
507
|
+
default: "",
|
|
508
|
+
title: "Slot ID",
|
|
509
|
+
description: "The manifest slot this image fills, e.g. bg.far."
|
|
510
|
+
})
|
|
511
|
+
], SeamlessImageNode.prototype, "slot_id", void 0);
|
|
512
|
+
__decorate([
|
|
513
|
+
prop({
|
|
514
|
+
type: "bool",
|
|
515
|
+
default: true,
|
|
516
|
+
title: "Check X",
|
|
517
|
+
description: "Compare the left and right columns. When off, seamless_x is reported false."
|
|
518
|
+
})
|
|
519
|
+
], SeamlessImageNode.prototype, "check_x", void 0);
|
|
520
|
+
__decorate([
|
|
521
|
+
prop({
|
|
522
|
+
type: "bool",
|
|
523
|
+
default: false,
|
|
524
|
+
title: "Check Y",
|
|
525
|
+
description: "Compare the top and bottom rows. When off, seamless_y is reported false."
|
|
526
|
+
})
|
|
527
|
+
], SeamlessImageNode.prototype, "check_y", void 0);
|
|
528
|
+
__decorate([
|
|
529
|
+
prop({
|
|
530
|
+
type: "float",
|
|
531
|
+
default: 12,
|
|
532
|
+
title: "Threshold",
|
|
533
|
+
description: "Largest mean absolute per-channel difference (0-255) between opposite edges that still counts as seamless.",
|
|
534
|
+
min: 0,
|
|
535
|
+
max: 255
|
|
536
|
+
})
|
|
537
|
+
], SeamlessImageNode.prototype, "threshold", void 0);
|
|
538
|
+
__decorate([
|
|
539
|
+
prop({
|
|
540
|
+
type: "bool",
|
|
541
|
+
default: false,
|
|
542
|
+
title: "Repair seams",
|
|
543
|
+
description: "Blend the outer 10% on each checked axis before measuring. Preserves dimensions and the center, but softens detail near the edges."
|
|
544
|
+
})
|
|
545
|
+
], SeamlessImageNode.prototype, "repair", void 0);
|
|
546
|
+
export const GAME_NODES = [
|
|
547
|
+
SpriteSheetNode,
|
|
548
|
+
TilesetNode,
|
|
549
|
+
SeamlessImageNode
|
|
550
|
+
];
|
|
551
|
+
//# sourceMappingURL=game.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"game.js","sourceRoot":"","sources":["../../src/nodes/game.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;GAKG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE/E,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,WAAW,EAOZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAGrE,mEAAmE;AACnE,MAAM,mBAAmB,GAAG,CAAC,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
|
4
|
+
* Owns the single cached `GPUContext` (Dawn on Node, `navigator.gpu` in the
|
|
5
|
+
* browser/worker) so every shader op and every read-back uses the same device,
|
|
6
|
+
* and hosts the run-scoped texture registry behind the in-flight GPU-texture
|
|
7
|
+
* `ImageRef` (see {@link gpuTextureImageRef}). Sits below both `lib-shader-utils`
|
|
8
|
+
* (which runs shaders) and `image-io` (which decodes/encodes), so the
|
|
9
|
+
* texture-readback seam is reachable from either without a circular import.
|
|
10
|
+
*
|
|
11
|
+
* GPU-texture refs exist only in the browser, for one run, and are never
|
|
12
|
+
* serialized: `releaseRunTextures(jobId)` frees them when the runner ends a job,
|
|
13
|
+
* and any boundary (transport / CPU / server) resolves them to bytes first.
|
|
14
|
+
*/
|
|
15
|
+
import { createLabeledTexture, type LabeledTexture, type GPUContext } from "@nodetool-ai/gpu/pool";
|
|
16
|
+
import { type ImageRef } from "@nodetool-ai/protocol";
|
|
17
|
+
export { createLabeledTexture };
|
|
18
|
+
export type { LabeledTexture };
|
|
19
|
+
/** GPU-texture refs are browser-only; Node/Dawn always reads back to RGBA. */
|
|
20
|
+
export declare const GPU_TEXTURES_ENABLED: boolean;
|
|
21
|
+
/** The single cached GPU context (Dawn on Node, `navigator.gpu` in browser). */
|
|
22
|
+
export declare function getGpuContext(): Promise<GPUContext>;
|
|
23
|
+
/** Premultiply straight-alpha RGBA in place. Mutates and returns `pixels`. */
|
|
24
|
+
export declare function premultiplyInPlace(pixels: Uint8Array): Uint8Array;
|
|
25
|
+
/** Un-premultiply RGBA in place. Mutates and returns `pixels`. */
|
|
26
|
+
export declare function unpremultiplyInPlace(pixels: Uint8Array): Uint8Array;
|
|
27
|
+
/** Read a premultiplied `rgba8unorm` texture back to straight-alpha RGBA bytes. */
|
|
28
|
+
export declare function readbackTexture(device: GPUDevice, texture: GPUTexture, width: number, height: number): Promise<Uint8Array>;
|
|
29
|
+
/** Read a `LabeledTexture` back to straight-alpha RGBA bytes. */
|
|
30
|
+
export declare function readbackStraightAlpha(device: GPUDevice, texture: LabeledTexture): Promise<Uint8Array>;
|
|
31
|
+
/**
|
|
32
|
+
* Track `texture` under the run `runId` (a job id) so it's destroyed when the
|
|
33
|
+
* runner ends the run via {@link releaseRunTextures}. Chained shader nodes hand
|
|
34
|
+
* textures to one another within a run; freeing them per-node would break the
|
|
35
|
+
* hand-off, so cleanup is deferred to the run boundary.
|
|
36
|
+
*/
|
|
37
|
+
export declare function trackRunTexture(runId: string, texture: LabeledTexture): void;
|
|
38
|
+
/** Destroy and forget every texture tracked for `runId`. Safe to call twice. */
|
|
39
|
+
export declare function releaseRunTextures(runId: string): void;
|
|
40
|
+
/** Number of live tracked textures (debug/telemetry). */
|
|
41
|
+
export declare function trackedRunTextureCount(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Build the in-flight GPU-texture `ImageRef` (browser, single run). `texture`
|
|
44
|
+
* is the `LabeledTexture` the producing shader wrote — held opaque in the ref's
|
|
45
|
+
* `texture` field so a consuming node can sample it directly. It must already
|
|
46
|
+
* be tracked via {@link trackRunTexture}.
|
|
47
|
+
*/
|
|
48
|
+
export declare function gpuTextureImageRef(texture: LabeledTexture, width: number, height: number): ImageRef;
|
|
49
|
+
/** Read a GPU-texture `ImageRef`'s pixels back to straight-alpha RGBA. */
|
|
50
|
+
export declare function readbackTextureRef(ref: {
|
|
51
|
+
texture: unknown;
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
rgba: Uint8Array;
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
}>;
|
|
59
|
+
//# sourceMappingURL=gpu-device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-device.d.ts","sourceRoot":"","sources":["../../src/nodes/gpu-device.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,UAAU,EAChB,MAAM,uBAAuB,C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