Sliders and region breakout node

This commit is contained in:
space-nuko
2023-05-23 13:34:56 -05:00
parent 9a40f84e79
commit 631029edf7
7 changed files with 717 additions and 591 deletions

View File

@@ -0,0 +1,34 @@
import { LiteGraph, type SlotLayout } from "@litegraph-ts/core";
import ComfyGraphNode from "./ComfyGraphNode";
export default class ComfyRegionToCoordsNode extends ComfyGraphNode {
static slotLayout: SlotLayout = {
inputs: [
{ name: "in", type: "COMFYBOX_REGION" },
],
outputs: [
{ name: "x", type: "number" },
{ name: "y", type: "number" },
{ name: "width", type: "number" },
{ name: "height", type: "number" },
],
}
override onExecute() {
const value = this.getInputData(0);
if (!Array.isArray(value))
return;
this.setOutputData(0, value[0])
this.setOutputData(1, value[1])
this.setOutputData(2, value[2])
this.setOutputData(3, value[3])
}
}
LiteGraph.registerNodeType({
class: ComfyRegionToCoordsNode,
title: "Comfy.RegionToCoords",
desc: "Converts a COMFYBOX_REGION to four outputs of [x, y, width, height]",
type: "utils/region_to_coords"
})

View File

@@ -1,5 +1,3 @@
import "$lib/nodes/ComfyGraphNode";
export { default as ComfyReroute } from "./ComfyReroute"
export { default as ComfyPickFirstNode } from "./ComfyPickFirstNode"
export { default as ComfyValueControl } from "./ComfyValueControl"
@@ -8,3 +6,4 @@ export { default as ComfyTriggerNewEventNode } from "./ComfyTriggerNewEventNode"
export { default as ComfyConfigureQueuePromptButton } from "./ComfyConfigureQueuePromptButton"
export { default as ComfyPickImageNode } from "./ComfyPickImageNode"
export { default as ComfyNoChangeEvent } from "./ComfyNoChangeEvent"
export { default as ComfyRegionToCoordsNode } from "./ComfyRegionToCoordsNode"

View File

@@ -43,10 +43,7 @@ export default class ComfyMultiRegionNode extends ComfyWidgetNode<BoundingBox[]>
{ name: "changed", type: BuiltInSlotType.EVENT },
// dynamic outputs, may be removed later
{ name: "x1", type: "number" },
{ name: "y1", type: "number" },
{ name: "w1", type: "number" },
{ name: "h1", type: "number" },
{ name: "region1", type: "COMFYBOX_REGION" },
]
}
@@ -77,24 +74,24 @@ export default class ComfyMultiRegionNode extends ComfyWidgetNode<BoundingBox[]>
let height = this.getInputData(2) || 0
if (width != this.properties.canvasWidth || height != this.properties.canvasHeight) {
console.warn("SIZCHANGE", width, height, this.properties.canvasWidth, this.properties.canvasHeight)
this.properties.canvasWidth = width;
this.properties.canvasHeight = height;
this.sizeChanged.set(true);
this.updateSize();
}
const value = this.getValue();
for (let index = 0; index < this.properties.regionCount * 2; index += 2) {
for (let index = 0; index < this.properties.regionCount; index++) {
const bbox = value[index]
if (bbox != null) {
const xOutput = this.outputs[index + 1]
if (xOutput != null) {
this.setOutputData(index + 1, bbox[0] * this.properties.canvasWidth)
this.setOutputData(index + 2, bbox[1] * this.properties.canvasHeight)
this.setOutputData(index + 3, bbox[2] * this.properties.canvasWidth)
this.setOutputData(index + 4, bbox[3] * this.properties.canvasHeight)
const output = this.outputs[index + 1] // + changed slot
if (output != null) {
let data = this.getOutputData(index) || [0, 0, 0, 0]
data[0] = bbox[0] * this.properties.canvasWidth
data[1] = bbox[1] * this.properties.canvasHeight
data[2] = bbox[2] * this.properties.canvasWidth
data[3] = bbox[3] * this.properties.canvasHeight
this.setOutputData(index, data)
}
}
}
@@ -110,10 +107,7 @@ export default class ComfyMultiRegionNode extends ComfyWidgetNode<BoundingBox[]>
}
for (let index = 0; index < this.properties.regionCount; index++) {
this.addOutput(`x${index + 1}`, "number")
this.addOutput(`y${index + 1}`, "number")
this.addOutput(`w${index + 1}`, "number")
this.addOutput(`h${index + 1}`, "number")
this.addOutput(`region${index + 1}`, "COMFYBOX_REGION")
}
this.regionsChanged.set(true);