@rig-c/parts 2.26.1 → 2.27.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 +2 -2
- package/cli.ts +92 -11
- package/docs/AUTHORING.md +55 -5
- package/docs/PAINTING.md +5 -3
- package/docs/STABILITY.md +68 -1
- package/package.json +1 -1
- package/src/assemble.ts +5 -5
- package/src/boundarycolour.ts +3 -3
- package/src/build.ts +28 -27
- package/src/coincideio.ts +3 -2
- package/src/comfy/client.ts +59 -26
- package/src/comfy/index.ts +1 -0
- package/src/comfy/painting.ts +13 -11
- package/src/comfy/plate.ts +132 -0
- package/src/comfy/seethrough.ts +11 -12
- package/src/config.ts +4 -4
- package/src/errors.ts +5 -0
- package/src/paintingedges.ts +4 -2
- package/src/parts.ts +3 -3
- package/src/plate.ts +521 -0
- package/src/rig.ts +9 -9
- package/src/runstamp.ts +186 -0
- package/src/scene.ts +4 -2
- package/src/supportdomains.ts +4 -4
package/src/build.ts
CHANGED
|
@@ -95,7 +95,7 @@ import {
|
|
|
95
95
|
} from './autoreplay.ts';
|
|
96
96
|
import { besideIdleLine, checkSummaryLine, inputFileRecord, type InputFileRecord, CLOTH_LINE, type ClothLine, clothWarnText, figureOpeningLines, frameRuns, MOTION_SEAM_LINE, type MotionSeamLine, type MotionSeamPlant, motionSeamRequiredLine, motionSeamWarnText, motionJointContactLines, FOLD_LINE, type FoldsLine, LEVEL_LINE, type LevelLine, LIMB_LINE, type LimbLine, STRESS_LINE, SWEEP_LINE, type SweepLine, buildGateLines, causeLines, environmentLine, IDLE_FPS, IDLE_MAX_PX, maxRgbDiff, REQUIREMENTS_DIR, type CheckReport, type PackLine, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, GATE_PROFILE, JUDGEMENT_LINES, type JudgementLine, packedBuildArgs, packedBuildLabel, type PackMode, readCheckEnvironment, readWindBand, type PackShape, type PageEdges, readFrameSet, rigcFailed, rigcIdentity, rigcRanClause, REPORTED_LINES, type ReportedLine, type RigcRunner, runCheck, SEAM_DIR, SEAM_MEAN_BAR, seamPairText, seamRigPxText, SOURCE_LINE, SEAM_PX_BAR, SEAM_PX_LEVEL, SEAM_PX_LEVEL_HIGH, SPINEBOY_YARDSTICK, STILL_DIR, WIND_BAND_LINE, windBandLines } from './check.ts';
|
|
97
97
|
import { type Cut, type Extend, type Limb, loadConfigAndAnimations, loadConfigWithBytes, loadEarlyConfig, type Patch, type PlanEntry } from './config.ts';
|
|
98
|
-
import { coreCompileGuideLine, failLine, PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
98
|
+
import { coreCompileGuideLine, failLine, foldName, PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
99
99
|
import { editedConfigImages, editedRunImages, missingReceipts, readEditorReceipts } from './editreceipt.ts';
|
|
100
100
|
import { untracedPartSources } from './partsource.ts';
|
|
101
101
|
import type { MeshQualityReport, MotionSchedule } from '@rig-c/core/mesh';
|
|
@@ -866,7 +866,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
866
866
|
];
|
|
867
867
|
const assetIndices = new Map<string, number>();
|
|
868
868
|
emittedAssets.forEach((file, index) => {
|
|
869
|
-
const previous = assetIndices.get(file
|
|
869
|
+
const previous = assetIndices.get(foldName(file));
|
|
870
870
|
if (previous !== undefined) {
|
|
871
871
|
altProblems.push({
|
|
872
872
|
code: 'DEPTH_SHEET_UNAMBIGUOUS',
|
|
@@ -874,10 +874,10 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
874
874
|
detail: `output assets[${previous}] ("${emittedAssets[previous]}") and [${index}] ("${file}") require the same filename; choose distinct base, alternate and sheet names`,
|
|
875
875
|
});
|
|
876
876
|
} else {
|
|
877
|
-
assetIndices.set(file
|
|
877
|
+
assetIndices.set(foldName(file), index);
|
|
878
878
|
}
|
|
879
879
|
});
|
|
880
|
-
const outputFiles = new
|
|
880
|
+
const outputFiles = new Map([
|
|
881
881
|
outs.partsJson, outs.recomposite, outs.errorMap,
|
|
882
882
|
join(dirname(outs.partsJson), PAINTING_ALLOCATION_FILE),
|
|
883
883
|
join(dirname(outs.partsJson), SOURCE_COVER_FILE),
|
|
@@ -887,13 +887,13 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
887
887
|
join(dirname(outs.partsJson), STAGE_MAP_FILE),
|
|
888
888
|
join(dirname(outs.partsJson), EDGE_RESIDUAL_FILE),
|
|
889
889
|
...emittedAssets.map(file => join(outs.partsDir, file)),
|
|
890
|
-
].map(file => resolve(file)));
|
|
890
|
+
].map((file): [string, string] => [foldName(resolve(file)), `"${basename(file)}"`]));
|
|
891
891
|
for (const { file, report } of allocationReports) {
|
|
892
|
-
const
|
|
893
|
-
if (outputFiles.has(
|
|
892
|
+
const k = foldName(resolve(dirname(outs.partsJson), `painting_allocation.${encodeURIComponent(foldName(report.set))}.json`));
|
|
893
|
+
if (outputFiles.has(k) || outputFiles.has(foldName(resolve(dirname(outs.partsJson), file)))) altProblems.push({ code: 'PAINTING_ALLOCATION_UNAMBIGUOUS',
|
|
894
894
|
object: `alternate set "${report.set}" report "${file}"`,
|
|
895
|
-
detail:
|
|
896
|
-
outputFiles.
|
|
895
|
+
detail: `${outputFiles.get(k) ?? outputFiles.get(foldName(resolve(dirname(outs.partsJson), file)))} and alternate set "${report.set}" report "${file}" share an output path with another artifact; choose distinct output paths and set names` });
|
|
896
|
+
else outputFiles.set(k, `alternate set "${report.set}" report "${file}"`);
|
|
897
897
|
}
|
|
898
898
|
// Issue #944: under pinholes.required, every pinhole of the base set's flat parts stack is refused by name, with the
|
|
899
899
|
// alternate sets' refusals, before anything is written.
|
|
@@ -939,21 +939,24 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
939
939
|
if (result.edgeResiduals === undefined) rmSync(residualPath, { force: true });
|
|
940
940
|
else writeFileSync(residualPath, JSON.stringify(result.edgeResiduals, null, 2) + '\n');
|
|
941
941
|
const allocation = result.paintingEdges?.allocation;
|
|
942
|
-
|
|
943
|
-
else writeFileSync(allocationPath, JSON.stringify({ spec: 'rig-parts-painting-allocation/1',
|
|
944
|
-
code: PAINTING_EDGE_COVERAGE_TRANSFER,
|
|
945
|
-
stage: 'paintingEdges after piece guarding and restoration', grid: result.parts.rig_size,
|
|
946
|
-
...allocation, written_reports: allocationReports.map(report => report.file) }, null, 2) + '\n');
|
|
947
|
-
const currentAllocationFiles = new Set(allocationReports.map(report => report.file));
|
|
942
|
+
const currentAllocationFiles = new Set(allocation === undefined ? [] : allocationReports.map(report => foldName(report.file)));
|
|
948
943
|
for (const file of previousAllocationFiles) {
|
|
949
|
-
if (!currentAllocationFiles.has(file) && !outputFiles.has(resolve(dirname(outs.partsJson), file))) {
|
|
944
|
+
if (!currentAllocationFiles.has(foldName(file)) && !outputFiles.has(foldName(resolve(dirname(outs.partsJson), file)))) {
|
|
950
945
|
rmSync(join(dirname(outs.partsJson), file), { force: true });
|
|
951
946
|
}
|
|
952
947
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
948
|
+
if (allocation === undefined) {
|
|
949
|
+
rmSync(allocationPath, { force: true });
|
|
950
|
+
} else {
|
|
951
|
+
writeFileSync(allocationPath, JSON.stringify({ spec: 'rig-parts-painting-allocation/1',
|
|
952
|
+
code: PAINTING_EDGE_COVERAGE_TRANSFER,
|
|
953
|
+
stage: 'paintingEdges after piece guarding and restoration', grid: result.parts.rig_size,
|
|
954
|
+
...allocation, written_reports: allocationReports.map(report => report.file) }, null, 2) + '\n');
|
|
955
|
+
for (const { file, report } of allocationReports) {
|
|
956
|
+
writeFileSync(join(dirname(outs.partsJson), file), JSON.stringify(report, null, 2) + '\n');
|
|
957
|
+
const count = report.coverageTransfers.reduce((n, row) => n + row.pixels.count, 0);
|
|
958
|
+
log(`${PAINTING_EDGE_COVERAGE_TRANSFER}: set "${report.set}" ${count} native rig px; membership in ${file}`);
|
|
959
|
+
}
|
|
957
960
|
}
|
|
958
961
|
for (const { record, image, depthImage } of result.images) {
|
|
959
962
|
writePng(join(outs.partsDir, `${record.name}.png`), image);
|
|
@@ -988,13 +991,11 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
988
991
|
if (result.paintingEdges !== undefined) {
|
|
989
992
|
const e = result.paintingEdges;
|
|
990
993
|
log(`painting edges: ${e.resolved} edge px resolved from the painting (${e.unseparated} against the two reference colours where the window's far sides overlap), ${e.changed} part px changed; left as they were: ${e.skipped.cover} under a part the two-layer model does not carry, ${e.skipped.contrast} where the painting draws no edge (contrast below ${EDGE_CONTRAST}), ${e.skipped.locked} kept, feathered, a patch or a turn's moving pair, ${e.skipped.noBehind} with no behind pixel in the window; ${e.skipped.pieces} part px not written so a part's art keeps its pieces`);
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
for (const fault of a.lineage) log(` painting receiver refused: "${fault.receiver}", ${fault.reason}; one declared raw-plan ancestor is required`);
|
|
997
|
-
}
|
|
994
|
+
const a = e.allocation;
|
|
995
|
+
log(`painting owner: ${a.supplier}; ${a.fallbackHeld} clean-fallback part px held by piece preservation`);
|
|
996
|
+
log(`${PAINTING_EDGE_COVERAGE_TRANSFER}: ${a.coverageTransfers.reduce((n, row) => n + row.pixels.count, 0)} native rig px; membership in ${PAINTING_ALLOCATION_FILE}`);
|
|
997
|
+
for (const [reason, px] of Object.entries(a.refused)) log(` painting owner refused: ${reason}, ${px} edge px`);
|
|
998
|
+
for (const fault of a.lineage) log(` painting receiver refused: "${fault.receiver}", ${fault.reason}; one declared raw-plan ancestor is required`);
|
|
998
999
|
// Issue #996: under a declared busy ground, what the two ground rules left.
|
|
999
1000
|
if (fields.ground === 'busy') log(` busy ground (assemble.ground): ${e.skipped.mix} behind-side px left that are not a mix of the two reference colours, ${e.skipped.support} part px not raised outside the part's own support`);
|
|
1000
1001
|
}
|
package/src/coincideio.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** Pre-rig pair domains and actual textured setup observations (#998). */
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
3
|
+
import { basename, join } from 'node:path';
|
|
4
4
|
import { sourceSupportFigure as supportFigure } from './assemble.ts';
|
|
5
5
|
import { officialRenderer, sourceSizeProblem, type CheckInputs } from './check.ts';
|
|
6
6
|
import { supportReport, unownedSupport, SUPPORT_GRID_CODE, type SupportPart, type SupportReport } from './coincide.ts';
|
|
7
7
|
import { refuseIfAny } from './errors.ts';
|
|
8
|
+
import { partImageReference } from './parts.ts';
|
|
8
9
|
import { readPng } from './raster/png.ts';
|
|
9
10
|
import { assertBinary, type Mask } from './raster/types.ts';
|
|
10
11
|
import { readSupportDomains } from './supportdomains.ts';
|
|
@@ -21,7 +22,7 @@ export function observeSupport(build: string, input: CheckInputs, supportSource?
|
|
|
21
22
|
for (const part of ordered) if (!slots.has(part.name)) refuseIfAny([{ code: 'CHECK_PART_SLOT_PRESENT', object: `part "${part.name}"`, detail: 'support report requires the named setup slot; no draw order is guessed' }]);
|
|
22
23
|
ordered.sort((a, b) => slots.get(a.name)! - slots.get(b.name)!);
|
|
23
24
|
const art = ordered.map<SupportPart>(part => {
|
|
24
|
-
const image = readPng(join(input.partsDir,
|
|
25
|
+
const image = readPng(join(input.partsDir, basename(partImageReference(part).path)));
|
|
25
26
|
if (image.width !== part.w || image.height !== part.h) refuseIfAny([{ code: SUPPORT_GRID_CODE, object: `part "${part.name}"`, detail: `PNG is ${image.width}x${image.height}; parts.json requires ${part.w}x${part.h}` }]);
|
|
26
27
|
const mask: Mask = { width, height, data: new Uint8Array(width * height) };
|
|
27
28
|
for (let y = 0; y < image.height; y++) for (let x = 0; x < image.width; x++) {
|
package/src/comfy/client.ts
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* into an output file.
|
|
15
15
|
*
|
|
16
16
|
* Every failure is a `PartsError` whose problem names the call, the value found
|
|
17
|
-
* and the value required: a box that does not answer, a
|
|
18
|
-
*
|
|
17
|
+
* and the value required: a box that does not answer, a job still pending in the
|
|
18
|
+
* queue past the wait, a `/prompt` the box rejected (with its own
|
|
19
19
|
* `node_errors`), a job that does not reach `/history` within the timeout, a
|
|
20
20
|
* job that ended in error, a history entry with no outputs.
|
|
21
21
|
*/
|
|
@@ -44,11 +44,6 @@ export interface ClientTiming {
|
|
|
44
44
|
request: number;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export interface QueueState {
|
|
48
|
-
running: number;
|
|
49
|
-
pending: number;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
47
|
export interface OutputImage {
|
|
53
48
|
filename: string;
|
|
54
49
|
subfolder: string;
|
|
@@ -118,34 +113,72 @@ export class ComfyClient {
|
|
|
118
113
|
return out;
|
|
119
114
|
}
|
|
120
115
|
|
|
121
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Where a queued prompt stands: `running` when the box is running it,
|
|
118
|
+
* `pending` with its 1-based place among the pending jobs (and how many are
|
|
119
|
+
* ahead of it, running included), or `absent` when the queue no longer lists
|
|
120
|
+
* it (finished, or never queued).
|
|
121
|
+
*/
|
|
122
|
+
async queuePlace(id: string): Promise<{ state: 'running' } | { state: 'pending'; place: number; pending: number; ahead: number } | { state: 'absent' }> {
|
|
122
123
|
const q = asObject(await this.json('GET', '/queue'));
|
|
123
124
|
if (q === null || !Array.isArray(q.queue_running) || !Array.isArray(q.queue_pending)) {
|
|
124
125
|
refuse('COMFY_REQUEST_OK', `GET ${this.host}/queue`, 'answered without queue_running and queue_pending arrays');
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
+
const idOf = (e: unknown): unknown => (Array.isArray(e) ? e[1] : undefined);
|
|
128
|
+
const running = q.queue_running as unknown[];
|
|
129
|
+
if (running.some((e) => idOf(e) === id)) return { state: 'running' };
|
|
130
|
+
// ComfyUI orders pending jobs by their queue number (the entry's first element), not by list position.
|
|
131
|
+
const pending = [...(q.queue_pending as unknown[])].sort((a, b) => Number(Array.isArray(a) ? a[0] : 0) - Number(Array.isArray(b) ? b[0] : 0));
|
|
132
|
+
const at = pending.findIndex((e) => idOf(e) === id);
|
|
133
|
+
if (at < 0) return { state: 'absent' };
|
|
134
|
+
return { state: 'pending', place: at + 1, pending: pending.length, ahead: running.length + at };
|
|
127
135
|
}
|
|
128
136
|
|
|
129
|
-
/**
|
|
130
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Wait for a prompt queued behind other jobs (it was appended, never put in
|
|
139
|
+
* front, and nothing here reorders or cancels anyone's job): at most `wait`
|
|
140
|
+
* seconds while it is still pending, then at most `timeout` seconds once the
|
|
141
|
+
* box is running it. A wait past either bound is refused naming the job's
|
|
142
|
+
* place in the queue; the job is left on the box.
|
|
143
|
+
*/
|
|
144
|
+
async waitBehind(id: string, wait: number, timeout: number, say: (line: string) => void): Promise<{ entry: HistoryEntry; vramLow: Record<string, number>; elapsed: number }> {
|
|
131
145
|
const t0 = Date.now();
|
|
132
|
-
let
|
|
133
|
-
let
|
|
134
|
-
while
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
);
|
|
146
|
+
let started: number | null = null;
|
|
147
|
+
let lastPlace = -1;
|
|
148
|
+
// The minimum free VRAM while this job runs: sampled on every running poll,
|
|
149
|
+
// then merged with what `waitHistory` reads, so it is not a post-run reading.
|
|
150
|
+
const vramLow: Record<string, number> = {};
|
|
151
|
+
for (;;) {
|
|
152
|
+
const place = await this.queuePlace(id);
|
|
153
|
+
if (place.state === 'absent') {
|
|
154
|
+
const done = await this.waitHistory(id, Math.max(this.timing.request, this.timing.poll * 2));
|
|
155
|
+
for (const [k, v] of Object.entries(done.vramLow)) if (!(k in vramLow) || v < vramLow[k]) vramLow[k] = v;
|
|
156
|
+
return { entry: done.entry, vramLow, elapsed: (Date.now() - t0) / 1000 };
|
|
157
|
+
}
|
|
158
|
+
const now = Date.now();
|
|
159
|
+
if (place.state === 'running') {
|
|
160
|
+
for (const [k, v] of Object.entries(await this.vramFree())) if (!(k in vramLow) || v < vramLow[k]) vramLow[k] = v;
|
|
161
|
+
if (started === null) {
|
|
162
|
+
started = now;
|
|
163
|
+
say(` prompt ${id} is running`);
|
|
164
|
+
}
|
|
165
|
+
if ((now - started) / 1000 >= timeout) {
|
|
166
|
+
refuse('COMFY_HISTORY_WITHIN', `prompt ${id}`, `was still running ${((now - started) / 1000).toFixed(1)} s after it started; it is required within --timeout ${timeout} s (the job was left on the box, not cancelled)`);
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
if (place.place !== lastPlace) say(` prompt ${id} queued behind ${place.ahead} job(s) (pending place ${place.place} of ${place.pending})`);
|
|
170
|
+
lastPlace = place.place;
|
|
171
|
+
const waited = (now - t0) / 1000;
|
|
172
|
+
if (waited >= wait) {
|
|
173
|
+
refuse(
|
|
174
|
+
'COMFY_QUEUE_BEHIND',
|
|
175
|
+
`prompt ${id}`,
|
|
176
|
+
`was still pending after ${waited.toFixed(1)} s, at place ${place.place} of ${place.pending} pending with ${place.ahead} job(s) ahead of it; it is required to start within --wait ${wait} s — the job was left in its place on the box, not moved and not cancelled, and no one else's job was touched`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
142
179
|
}
|
|
143
|
-
|
|
144
|
-
reported = true;
|
|
145
|
-
await sleep(Math.min(this.timing.poll, Math.max(0, wait - waited)));
|
|
146
|
-
last = await this.queue();
|
|
180
|
+
await sleep(this.timing.poll);
|
|
147
181
|
}
|
|
148
|
-
return (Date.now() - t0) / 1000;
|
|
149
182
|
}
|
|
150
183
|
|
|
151
184
|
/** `GET /object_info`: every node class the box has, with its inputs. */
|
package/src/comfy/index.ts
CHANGED
|
@@ -16,4 +16,5 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export { ComfyClient, type ClientTiming, resolveHost } from './client.ts';
|
|
18
18
|
export { runPainting, type PaintRun, type Painted } from './painting.ts';
|
|
19
|
+
export { runBackground, type BackgroundRun } from './plate.ts';
|
|
19
20
|
export { runSeeThrough, type SeeThroughResult, type SeeThroughRun } from './seethrough.ts';
|
package/src/comfy/painting.ts
CHANGED
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
* or upscale model the box does not list is refused by name, not discovered
|
|
14
14
|
* as a failed job.
|
|
15
15
|
*
|
|
16
|
-
* Every seed
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
16
|
+
* Every seed is appended to the queue behind any other job — never in front,
|
|
17
|
+
* nothing reordered and nothing cancelled; a wait past `--wait` while pending
|
|
18
|
+
* is refused naming the job's place (`COMFY_QUEUE_BEHIND`) — and each painting
|
|
19
|
+
* is written only after its job is in `/history`, not in error, and the image
|
|
20
|
+
* it saved decodes at twice the latent size (4x-AnimeSharp then 0.5). A seed
|
|
21
|
+
* whose file already exists in `--out` is refused before the first job, so no
|
|
22
|
+
* painting is overwritten.
|
|
21
23
|
*
|
|
22
24
|
* The meta file holds the positive and negative prompts verbatim, what was
|
|
23
25
|
* dropped as `DUP_WORDS`, where the pose words came from, the checkpoint, the
|
|
@@ -75,23 +77,19 @@ export async function runPainting(client: ComfyClient, run: PaintRun, say: (line
|
|
|
75
77
|
refuseIfAny(checkGraph(probe, await client.objectInfo(), client.host, new Set(['30.image'])));
|
|
76
78
|
say(' box: every node, input and model of the painting graph is on its /object_info');
|
|
77
79
|
|
|
78
|
-
mkdirSync(run.out, { recursive: true });
|
|
79
80
|
let skeletonRef: string | null = null;
|
|
80
81
|
if (control !== null && drawn !== null && skeletonName !== null) {
|
|
81
82
|
const local = join(run.out, `control_${drawn.label}.png`);
|
|
82
|
-
writeFileSync(local, drawn.png);
|
|
83
83
|
skeletonRef = await client.uploadImage(drawn.png, skeletonName);
|
|
84
84
|
say(` control: ${drawn.from} at ${w}x${h} -> ${local}, uploaded as input/${skeletonRef}; ${control.model} strength ${control.strength} end ${control.end_percent}`);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
const done: Painted[] = [];
|
|
88
88
|
for (const seed of seeds) {
|
|
89
|
-
const waited = await client.waitQueueEmpty(run.wait, say);
|
|
90
|
-
if (waited > 0.05) say(` queue empty after ${waited.toFixed(1)} s`);
|
|
91
89
|
const graph = paintingGraph(g, seed, prompts, `spine_parts_${run.config.key}_${seed}`, skeletonRef);
|
|
92
90
|
const id = await client.submit(graph, 'rig-parts');
|
|
93
|
-
say(` seed ${seed}:
|
|
94
|
-
const { entry, elapsed } = await client.
|
|
91
|
+
say(` seed ${seed}: appended prompt ${id} to the queue (behind any other job; nothing reordered or cancelled)`);
|
|
92
|
+
const { entry, elapsed } = await client.waitBehind(id, run.wait, run.timeout, say);
|
|
95
93
|
const image = historyImages(entry).find((im) => im.type === 'output');
|
|
96
94
|
if (image === undefined) {
|
|
97
95
|
refuse('COMFY_HISTORY_OUTPUTS', `prompt ${id}`, `lists outputs from node(s) ${Object.keys(entry.outputs).join(', ')} and no image of type "output"; SaveImage (node 9) is required to have saved one`);
|
|
@@ -101,6 +99,10 @@ export async function runPainting(client: ComfyClient, run: PaintRun, say: (line
|
|
|
101
99
|
if (img.width !== 2 * w || img.height !== 2 * h) {
|
|
102
100
|
refuse('COMFY_PAINTING_SIZE', `output/${image.filename}`, `is ${img.width}x${img.height}; ${2 * w}x${2 * h} is required (latent ${w}x${h}, 4x-AnimeSharp then 0.5)`);
|
|
103
101
|
}
|
|
102
|
+
if (done.length === 0) {
|
|
103
|
+
mkdirSync(run.out, { recursive: true });
|
|
104
|
+
if (control !== null && drawn !== null) writeFileSync(join(run.out, `control_${drawn.label}.png`), drawn.png);
|
|
105
|
+
}
|
|
104
106
|
const file = join(run.out, `painting_${seed}.png`);
|
|
105
107
|
writeFileSync(file, bytes);
|
|
106
108
|
const meta = {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `comfy plate --mode background`: the figure-removed background plate of a
|
|
3
|
+
* painting, inpainted on a ComfyUI box over a source mask (issue #1183).
|
|
4
|
+
*
|
|
5
|
+
* The route, in order, each step refusing by name:
|
|
6
|
+
*
|
|
7
|
+
* 1. the source mask is read (`src/plate.ts`); with none, the run is refused
|
|
8
|
+
* before anything is written and before the host is reached;
|
|
9
|
+
* 2. the declared checkpoint sha256 and, for `core`, the painting's grid are
|
|
10
|
+
* checked;
|
|
11
|
+
* 3. the box answers `/system_stats` and names its GPU;
|
|
12
|
+
* 4. every node, input and model of the chosen graph is on the box's
|
|
13
|
+
* `/object_info` (`checkGraph`) — a box without the inpaint pack is refused
|
|
14
|
+
* here for `lama`, before anything is uploaded;
|
|
15
|
+
* 5. the painting and the grown mask are uploaded and the graph is appended
|
|
16
|
+
* to the queue: behind every other job, never in front, nothing reordered
|
|
17
|
+
* and nothing cancelled; a wait past `--wait` while pending is refused
|
|
18
|
+
* naming the job's place (`COMFY_QUEUE_BEHIND`);
|
|
19
|
+
* 6. the box's image is read back, required at the painting's size, pasted
|
|
20
|
+
* into the painting inside the mask only, and written with its receipt
|
|
21
|
+
* through `publishPlate` (staged, read back, then moved).
|
|
22
|
+
*/
|
|
23
|
+
import { refuseIfAny } from '../errors.ts';
|
|
24
|
+
import { checkGraph, type Graph } from '../graphs.ts';
|
|
25
|
+
import {
|
|
26
|
+
assertPlateOutFree,
|
|
27
|
+
CORE_DEFAULTS,
|
|
28
|
+
type CoreParams,
|
|
29
|
+
coreGridProblem,
|
|
30
|
+
corePlateGraph,
|
|
31
|
+
declaredChecksum,
|
|
32
|
+
type FigureMask,
|
|
33
|
+
growMask,
|
|
34
|
+
type LamaParams,
|
|
35
|
+
LAMA_MODEL,
|
|
36
|
+
lamaPlateGraph,
|
|
37
|
+
maskImage,
|
|
38
|
+
parseMaskFrom,
|
|
39
|
+
pasteInside,
|
|
40
|
+
PLATE_GRAPH_IDS,
|
|
41
|
+
type PlateGraph,
|
|
42
|
+
type PlateReceipt,
|
|
43
|
+
publishPlate,
|
|
44
|
+
readPlatePainting,
|
|
45
|
+
readSourceMask,
|
|
46
|
+
} from '../plate.ts';
|
|
47
|
+
import { OPAQUE_ALPHA_ABOVE } from '../layers.ts';
|
|
48
|
+
import { decodePngBytes, encodePngBytes } from '../raster/png.ts';
|
|
49
|
+
import { ComfyClient, historyImages, refuse } from './client.ts';
|
|
50
|
+
|
|
51
|
+
export interface BackgroundRun {
|
|
52
|
+
painting: string;
|
|
53
|
+
maskFrom: string | undefined;
|
|
54
|
+
out: string;
|
|
55
|
+
graph: PlateGraph;
|
|
56
|
+
/** The model file the graph loads: the LaMa model for `lama`, the checkpoint for `core`. */
|
|
57
|
+
model: string | undefined;
|
|
58
|
+
checkpointSha256: string | undefined;
|
|
59
|
+
seed: number;
|
|
60
|
+
growPx: number;
|
|
61
|
+
steps: number;
|
|
62
|
+
prompt: string | undefined;
|
|
63
|
+
negative: string | undefined;
|
|
64
|
+
wait: number;
|
|
65
|
+
timeout: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The GPU the box runs on, as `/system_stats` names its torch device. */
|
|
69
|
+
export function gpuName(stats: Record<string, unknown>, host: string): string {
|
|
70
|
+
const devices = Array.isArray(stats.devices) ? stats.devices : [];
|
|
71
|
+
const names = devices.map((d) => (typeof d === 'object' && d !== null ? (d as Record<string, unknown>).name : undefined)).filter((n): n is string => typeof n === 'string' && n !== '');
|
|
72
|
+
if (names.length !== 1) {
|
|
73
|
+
refuse('COMFY_GPU_NAMED', `GET ${host}/system_stats`, `names ${names.length} device(s); exactly one is required, because the receipt records the GPU (the same seed gives other pixels on another GPU)`);
|
|
74
|
+
}
|
|
75
|
+
return names[0];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `connect` is called only after every local check has passed, so a refused run never resolves a host or reaches a box. */
|
|
79
|
+
export async function runBackground(connect: () => ComfyClient, run: BackgroundRun, say: (line: string) => void): Promise<PlateReceipt> {
|
|
80
|
+
// Local first: no source mask, a bad checksum or an off-grid painting is refused before the box is reached.
|
|
81
|
+
const from = parseMaskFrom(run.maskFrom);
|
|
82
|
+
const painting = readPlatePainting(run.painting);
|
|
83
|
+
const { width: W, height: H } = painting.raster;
|
|
84
|
+
const source: FigureMask = readSourceMask(from.source, from.dir, W, H, painting.raster);
|
|
85
|
+
const checkpoint = declaredChecksum(run.checkpointSha256);
|
|
86
|
+
if (run.graph === 'core') {
|
|
87
|
+
if (run.model === undefined) refuse('PLATE_MODEL_GIVEN', '--model', 'is absent; the core graph needs the checkpoint the box loads, by its name on the box — there is no default checkpoint');
|
|
88
|
+
const grid = coreGridProblem(W, H, run.painting);
|
|
89
|
+
if (grid !== null) refuseIfAny([grid]);
|
|
90
|
+
}
|
|
91
|
+
assertPlateOutFree(run.out);
|
|
92
|
+
const mask = growMask(source, run.growPx);
|
|
93
|
+
const model = run.model ?? LAMA_MODEL;
|
|
94
|
+
const lama: LamaParams = { seed: run.seed, grow_px: run.growPx };
|
|
95
|
+
const core: CoreParams = { seed: run.seed, grow_px: run.growPx, steps: run.steps, cfg: CORE_DEFAULTS.cfg, sampler: CORE_DEFAULTS.sampler, scheduler: CORE_DEFAULTS.scheduler, denoise: CORE_DEFAULTS.denoise, prompt: run.prompt ?? CORE_DEFAULTS.prompt, negative: run.negative ?? CORE_DEFAULTS.negative };
|
|
96
|
+
const prefix = `rig_parts_plate_${crypto.randomUUID().slice(0, 8)}`;
|
|
97
|
+
const build = (p: string, m: string): Graph => (run.graph === 'lama' ? lamaPlateGraph(p, m, model, lama, prefix) : corePlateGraph(p, m, model, core, prefix));
|
|
98
|
+
|
|
99
|
+
const client = connect();
|
|
100
|
+
const gpu = gpuName(await client.systemStats(), client.host);
|
|
101
|
+
const info = await client.objectInfo();
|
|
102
|
+
refuseIfAny(checkGraph(build(`${prefix}_painting.png`, `${prefix}_mask.png`), info, client.host, new Set(['1.image', '2.image'])));
|
|
103
|
+
say(` box: every node, input and model of the ${run.graph} graph is on its /object_info; GPU ${gpu}`);
|
|
104
|
+
|
|
105
|
+
const paintingRef = await client.uploadImage(painting.bytes, `${prefix}_painting.png`);
|
|
106
|
+
const maskRef = await client.uploadImage(encodePngBytes(maskImage(mask)), `${prefix}_mask.png`);
|
|
107
|
+
say(` uploaded ${run.painting} (${W}x${H}) and its mask (${mask.inside.reduce((a, b) => a + b, 0)} px, grown ${run.growPx} px)`);
|
|
108
|
+
const id = await client.submit(build(paintingRef, maskRef), 'rig-parts');
|
|
109
|
+
say(` appended prompt ${id} to the queue (behind any other job; nothing reordered or cancelled)`);
|
|
110
|
+
const { entry, elapsed } = await client.waitBehind(id, run.wait, run.timeout, say);
|
|
111
|
+
say(` GPU job finished ${elapsed.toFixed(1)} s after it was queued`);
|
|
112
|
+
const images = historyImages(entry);
|
|
113
|
+
if (images.length !== 1) refuse('COMFY_HISTORY_OUTPUTS', `prompt ${id}`, `lists ${images.length} image(s); the graph's one SaveImage is required to have saved exactly one`);
|
|
114
|
+
const got = decodePngBytes(await client.view(images[0].filename, images[0].subfolder, images[0].type), images[0].filename);
|
|
115
|
+
if (got.width !== W || got.height !== H) refuse('COMFY_PLATE_SIZE', `prompt ${id} ${images[0].filename}`, `is ${got.width}x${got.height}; the painting's ${W}x${H} is required — the plate is pasted into the painting pixel for pixel, never resized`);
|
|
116
|
+
|
|
117
|
+
return publishPlate({
|
|
118
|
+
out: run.out,
|
|
119
|
+
stageTag: prefix,
|
|
120
|
+
mode: 'background',
|
|
121
|
+
paintingPath: run.painting,
|
|
122
|
+
paintingBytes: painting.bytes,
|
|
123
|
+
source: from.source,
|
|
124
|
+
sourceDir: from.dir,
|
|
125
|
+
mask,
|
|
126
|
+
plate: pasteInside(painting.raster, got, mask),
|
|
127
|
+
model: { name: model, checkpoint_sha256: checkpoint, checkpoint_sha256_from: 'declared' },
|
|
128
|
+
params: run.graph === 'lama' ? { ...lama, mask_alpha_above: OPAQUE_ALPHA_ABOVE } : { ...core, mask_alpha_above: OPAQUE_ALPHA_ABOVE },
|
|
129
|
+
graph: PLATE_GRAPH_IDS[run.graph],
|
|
130
|
+
gpu,
|
|
131
|
+
});
|
|
132
|
+
}
|
package/src/comfy/seethrough.ts
CHANGED
|
@@ -10,18 +10,19 @@
|
|
|
10
10
|
* 2. every node and input of `workflows/seethrough.json` is on the box's
|
|
11
11
|
* `/object_info` (`checkGraph`) — the wrapper not installed is refused
|
|
12
12
|
* here, before anything is uploaded;
|
|
13
|
-
* 3. the
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* 3. the image is uploaded to the box's input directory and the graph is
|
|
14
|
+
* appended to the queue: behind every other job, never in front, nothing
|
|
15
|
+
* reordered and nothing cancelled; a wait past `--wait` while pending is
|
|
16
|
+
* refused naming the job's place (`COMFY_QUEUE_BEHIND`);
|
|
17
|
+
* 4. `/history/<id>` holds the job within `--timeout` once running, not in
|
|
18
|
+
* error, with outputs;
|
|
19
|
+
* 5. the manifest is found the way the wrapper leaves it: SavePSD writes the
|
|
19
20
|
* layer PNGs and the manifest into the output directory but reports only
|
|
20
21
|
* the previews to `/history`, and records the manifest's file name in
|
|
21
22
|
* `output/seethrough_psd_info.log`. That log is overwritten by every run, so
|
|
22
23
|
* the manifest it names must carry THIS run's prefix — a prefix with a
|
|
23
24
|
* random suffix per run — or it is refused as another run's;
|
|
24
|
-
*
|
|
25
|
+
* 6. everything is written into a staging directory beside `--out`, read back
|
|
25
26
|
* through `readWrapperLayers`, and only then moved to `--out`. Emit only
|
|
26
27
|
* after green: a directory the layer reader would refuse is never left at
|
|
27
28
|
* the path the next stage reads.
|
|
@@ -91,16 +92,14 @@ export async function runSeeThrough(client: ComfyClient, run: SeeThroughRun, say
|
|
|
91
92
|
refuseIfAny(checkGraph(fillSeeThrough(template, params), info, client.host, new Set(['1.image'])));
|
|
92
93
|
say(` box: every node and input of workflows/seethrough.json is on its /object_info`);
|
|
93
94
|
|
|
94
|
-
const waited = await client.waitQueueEmpty(run.wait, say);
|
|
95
|
-
say(` queue empty${waited > 0.05 ? ` after ${waited.toFixed(1)} s` : ''}`);
|
|
96
95
|
const ref = await client.uploadImage(bytes, uploadName);
|
|
97
96
|
say(` uploaded ${run.image} (${img.width}x${img.height}) as input/${ref}`);
|
|
98
97
|
const graph = fillSeeThrough(template, { ...params, image: ref });
|
|
99
98
|
const vramBefore = await client.vramFree();
|
|
100
99
|
const id = await client.submit(graph, 'rig-parts');
|
|
101
|
-
say(`
|
|
102
|
-
const { entry, vramLow, elapsed } = await client.
|
|
103
|
-
say(` GPU job finished
|
|
100
|
+
say(` appended prompt ${id} (prefix ${prefix}) to the queue (behind any other job; nothing reordered or cancelled)`);
|
|
101
|
+
const { entry, vramLow, elapsed } = await client.waitBehind(id, run.wait, run.timeout, say);
|
|
102
|
+
say(` GPU job finished ${elapsed.toFixed(1)} s after it was queued`);
|
|
104
103
|
const previews = historyImages(entry);
|
|
105
104
|
if (previews.length === 0) {
|
|
106
105
|
refuse('COMFY_HISTORY_OUTPUTS', `prompt ${id}`, `lists outputs from node(s) ${Object.keys(entry.outputs).join(', ')} and no image; the graph's two preview SaveImage nodes are required to have saved`);
|
package/src/config.ts
CHANGED
|
@@ -100,7 +100,7 @@ import { REQUIREMENTS_SPEC, type RequirementsFile } from './requirements.ts';
|
|
|
100
100
|
import { setupPaintingFilePath } from './setuppainting.ts';
|
|
101
101
|
import { CLOTH_TARGETS, type ClothRecipes, RECIPE_STRENGTH, RIGC_DEFAULT_DAMPING, springStable } from './cloth.ts';
|
|
102
102
|
import { GRID, MAX_SIDE } from './contour.ts';
|
|
103
|
-
import { type Problem, refuseIfAny } from './errors.ts';
|
|
103
|
+
import { foldName, type Problem, refuseIfAny } from './errors.ts';
|
|
104
104
|
import { edgeLength } from './length.ts';
|
|
105
105
|
import { setFocusProblems } from './setfocus.ts';
|
|
106
106
|
import { type EditorReceipts, SHA256_PATTERN, SHA256_RULE } from './editreceipt.ts';
|
|
@@ -2824,15 +2824,15 @@ function checkAlternates(
|
|
|
2824
2824
|
...baseSlots,
|
|
2825
2825
|
...explicitIslandSlotNames(baseSlots, meshes),
|
|
2826
2826
|
]);
|
|
2827
|
-
const seenNames = new Map<string, number>();
|
|
2827
|
+
const seenNames = new Map<string, { index: number; name: string }>();
|
|
2828
2828
|
(v as Json[]).forEach((entry, i) => {
|
|
2829
2829
|
const at = `${p}[${i}]`;
|
|
2830
2830
|
const e = c.object(at, entry, ['name'], ['source', 'full', 'head', 'parts', 'hides', 'head_box', 'cuts', 'skeleton', 'anchor', 'drawn', 'tips', 'front', 'layers', 'focus', 'base_anchor']);
|
|
2831
2831
|
if (e === null) return;
|
|
2832
2832
|
if ('name' in e && c.string(`${at}.name`, e.name)) {
|
|
2833
2833
|
if (!partNameOk(e.name)) c.fail('CONFIG_PART_NAME', `${at}.name`, `names the set ${show(e.name)}; a set name is a file prefix, so it may not be empty, start with "." or hold a slash`);
|
|
2834
|
-
if (seenNames.has(e.name)) c.fail('CONFIG_PART_UNIQUE', `${at}.name`, `names the set "${e.name}" again (first at alternates[${seenNames.get(e.name)}])`);
|
|
2835
|
-
else seenNames.set(e.name, i);
|
|
2834
|
+
if (seenNames.has(foldName(e.name))) c.fail('CONFIG_PART_UNIQUE', `${at}.name`, `names the set "${e.name}" again (first at alternates[${seenNames.get(foldName(e.name))!.index}] ("${seenNames.get(foldName(e.name))!.name}"))`);
|
|
2835
|
+
else seenNames.set(foldName(e.name), { index: i, name: e.name });
|
|
2836
2836
|
}
|
|
2837
2837
|
for (const k of ['source', 'full', 'head', 'skeleton'] as const) {
|
|
2838
2838
|
if (k in e) c.string(`${at}.${k}`, e[k]);
|
package/src/errors.ts
CHANGED
|
@@ -65,3 +65,8 @@ export class PartsError extends Error {
|
|
|
65
65
|
export function refuseIfAny(problems: readonly Problem[]): void {
|
|
66
66
|
if (problems.length > 0) throw new PartsError(problems);
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
/** Fold a file, part or set name for host-independent collision checks (NFC + ASCII lower case). */
|
|
70
|
+
export function foldName(name: string): string {
|
|
71
|
+
return name.normalize('NFC').toLowerCase();
|
|
72
|
+
}
|
package/src/paintingedges.ts
CHANGED
|
@@ -732,8 +732,10 @@ function applyPaintingEdges(
|
|
|
732
732
|
});
|
|
733
733
|
if (held.length > 0) {
|
|
734
734
|
if (!held.includes(event.target) && event.target === event.behind && held.every(i => i === event.front)) {
|
|
735
|
-
//
|
|
736
|
-
|
|
735
|
+
// Keep the original FRONT colour at the least coverage that preserves
|
|
736
|
+
// the guarded art bridge. BEHIND already carries its accepted own P.
|
|
737
|
+
const front = parts[event.front].data;
|
|
738
|
+
planned[event.front].set(event.p, [front[offset], front[offset + 1], front[offset + 2], OPAQUE_ALPHA_ABOVE + 1]);
|
|
737
739
|
event.status = 'retained-front';
|
|
738
740
|
} else {
|
|
739
741
|
for (const i of event.affected) planned[i].delete(event.p);
|
package/src/parts.ts
CHANGED
|
@@ -94,7 +94,7 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
94
94
|
import { createHash } from 'node:crypto';
|
|
95
95
|
import { dirname, join } from 'node:path';
|
|
96
96
|
import { decodePngBytes } from './raster/png.ts';
|
|
97
|
-
import { type Problem, refuseIfAny } from './errors.ts';
|
|
97
|
+
import { foldName, type Problem, refuseIfAny } from './errors.ts';
|
|
98
98
|
import { KEYPOINT_NAMES, type PosePoints } from './skeleton.ts';
|
|
99
99
|
import { readLayerTag } from './tags.ts';
|
|
100
100
|
import { edgeLength } from './length.ts';
|
|
@@ -796,8 +796,8 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
796
796
|
}
|
|
797
797
|
if (!isPartName(r.name)) {
|
|
798
798
|
fail('PARTS_FIELD_TYPE', `${label} field "name"`, `is ${show(r.name)}; a file-name-safe part name is required`);
|
|
799
|
-
} else if (seen.has(r.name
|
|
800
|
-
else seen.set(r.name
|
|
799
|
+
} else if (seen.has(foldName(r.name))) fail('PARTS_NAME_UNIQUE', label, `appears at parts[${seen.get(foldName(r.name))!.index}] ("${seen.get(foldName(r.name))!.name}") and parts[${i}] ("${r.name}")`);
|
|
800
|
+
else seen.set(foldName(r.name), { index: i, name: r.name });
|
|
801
801
|
const from = typeof r.from === 'string' ? readFrom(r.from) : null;
|
|
802
802
|
if (from === null) fail('PARTS_FROM_KNOWN', `${label} field "from"`, `is ${show(r.from)}; "<full|head>:<v3 tag>", "<full|head>:author:<label>" for a layer the author made, or "painting:<the part's own name>" for a patch, is required`);
|
|
803
803
|
else if (from.run === 'painting' && from.patch !== r.name) {
|