mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-21 20:00:17 +08:00
add batchCount ouptut
have all widget related stuff in the extension instead of widgets.js
This commit is contained in:
parent
612f99bda6
commit
aa29284a76
@ -4,28 +4,44 @@ import { app } from "/scripts/app.js";
|
|||||||
class BatchInfo {
|
class BatchInfo {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.addOutput("iteration", "INT");
|
this.addOutput("iteration", "INT");
|
||||||
|
this.addOutput("batchCount", "INT");
|
||||||
|
|
||||||
let widget = (ComfyWidgets["INT:batch_index"](this, "iteration", ["INT",{}], app) || {}).widget;
|
const batchIteration = (ComfyWidgets["INT"](this, "iteration", ["INT",{}], app) || {}).widget;
|
||||||
|
batchIteration.disabled = true;
|
||||||
|
|
||||||
|
const batchCount = (ComfyWidgets["INT"](this, "batchCount", ["INT",{}], app) || {}).widget;
|
||||||
|
batchCount.disabled = true;
|
||||||
|
|
||||||
|
batchIteration.onInitBatch = (batchSize) => {
|
||||||
|
batchIteration.value = 0;
|
||||||
|
batchCount.value = batchSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
batchIteration.afterQueued = () => {
|
||||||
|
batchIteration.value += 1;
|
||||||
|
};
|
||||||
|
|
||||||
this.serialize_widgets = true;
|
this.serialize_widgets = true;
|
||||||
this.isVirtualNode = true;
|
this.isVirtualNode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyToGraph() {
|
applyToGraph() {
|
||||||
if (!this.outputs[0].links?.length) return;
|
for (const idx in this.outputs) {
|
||||||
|
// For each output link copy our value over the original widget value
|
||||||
// For each output link copy our value over the original widget value
|
if (this.outputs[idx].links?.length) {
|
||||||
for (const l of this.outputs[0].links) {
|
for (const l of this.outputs[idx].links) {
|
||||||
const linkInfo = app.graph.links[l];
|
const linkInfo = app.graph.links[l];
|
||||||
const node = this.graph.getNodeById(linkInfo.target_id);
|
const node = this.graph.getNodeById(linkInfo.target_id);
|
||||||
const input = node.inputs[linkInfo.target_slot];
|
const input = node.inputs[linkInfo.target_slot];
|
||||||
const widgetName = input.widget.name;
|
const widgetName = input.widget.name;
|
||||||
if (widgetName) {
|
if (widgetName) {
|
||||||
const widget = node.widgets.find((w) => w.name === widgetName);
|
const widget = node.widgets.find((w) => w.name === widgetName);
|
||||||
if (widget) {
|
if (widget) {
|
||||||
widget.value = this.widgets[0].value;
|
widget.value = this.widgets[idx].value;
|
||||||
if (widget.callback) {
|
if (widget.callback) {
|
||||||
widget.callback(widget.value, app.canvas, node, app.canvas.graph_mouse, {});
|
widget.callback(widget.value, app.canvas, node, app.canvas.graph_mouse, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -997,7 +997,7 @@ class ComfyApp {
|
|||||||
// Allow widgets to run callbacks on firts iteration of a batch
|
// Allow widgets to run callbacks on firts iteration of a batch
|
||||||
// e.g. random seed after every gen
|
// e.g. random seed after every gen
|
||||||
if (widget.onInitBatch) {
|
if (widget.onInitBatch) {
|
||||||
widget.onInitBatch();
|
widget.onInitBatch(batchCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,24 +43,6 @@ function seedWidget(node, inputName, inputData) {
|
|||||||
return { widget: seed, randomize };
|
return { widget: seed, randomize };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function batchIndexWidget(node, inputName, inputData) {
|
|
||||||
|
|
||||||
const { val, config } = getNumberDefaults(inputData, 1);
|
|
||||||
Object.assign(config, { precision: 0 });
|
|
||||||
const batchIndex = node.addWidget("number", inputName, val, () => {}, config)
|
|
||||||
batchIndex.disabled = true;
|
|
||||||
|
|
||||||
batchIndex.onInitBatch = () => {
|
|
||||||
batchIndex.value = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
batchIndex.afterQueued = () => {
|
|
||||||
batchIndex.value += 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
return batchIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MultilineSymbol = Symbol();
|
const MultilineSymbol = Symbol();
|
||||||
const MultilineResizeSymbol = Symbol();
|
const MultilineResizeSymbol = Symbol();
|
||||||
|
|
||||||
@ -215,7 +197,6 @@ function addMultilineWidget(node, name, opts, app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ComfyWidgets = {
|
export const ComfyWidgets = {
|
||||||
"INT:batch_index": batchIndexWidget,
|
|
||||||
"INT:seed": seedWidget,
|
"INT:seed": seedWidget,
|
||||||
"INT:noise_seed": seedWidget,
|
"INT:noise_seed": seedWidget,
|
||||||
FLOAT(node, inputName, inputData) {
|
FLOAT(node, inputName, inputData) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user