More region widget fixes

This commit is contained in:
space-nuko
2023-05-23 17:29:33 -05:00
parent e3c73ce18a
commit a3d4e4bca7
8 changed files with 68 additions and 23 deletions

View File

@@ -7,10 +7,11 @@ export default class ComfyRegionToCoordsNode extends ComfyGraphNode {
{ name: "in", type: "COMFYBOX_REGION" },
],
outputs: [
{ name: "x", type: "number" },
{ name: "y", type: "number" },
// same order as conditioning nodes
{ name: "width", type: "number" },
{ name: "height", type: "number" },
{ name: "x", type: "number" },
{ name: "y", type: "number" },
],
}
@@ -19,16 +20,16 @@ export default class ComfyRegionToCoordsNode extends ComfyGraphNode {
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])
this.setOutputData(0, value[2])
this.setOutputData(1, value[3])
this.setOutputData(2, value[0])
this.setOutputData(3, value[1])
}
}
LiteGraph.registerNodeType({
class: ComfyRegionToCoordsNode,
title: "Comfy.RegionToCoords",
desc: "Converts a COMFYBOX_REGION to four outputs of [x, y, width, height]",
desc: "Converts a COMFYBOX_REGION to four outputs of [width, height, x, y]",
type: "utils/region_to_coords"
})

View File

@@ -41,7 +41,7 @@ export default class ComfyMultiRegionNode extends ComfyWidgetNode<BoundingBox[]>
{ name: "changed", type: BuiltInSlotType.EVENT },
// dynamic outputs, may be removed later
{ name: "region1", type: "COMFYBOX_REGION" },
{ name: "region_1", type: "COMFYBOX_REGION" },
]
}
@@ -145,7 +145,7 @@ export default class ComfyMultiRegionNode extends ComfyWidgetNode<BoundingBox[]>
}
for (let index = this.outputs.length - 1; index < this.properties.regionCount; index++) {
this.addOutput(`region${index + 1}`, "COMFYBOX_REGION")
this.addOutput(`region_${index + 1}`, "COMFYBOX_REGION")
}
this.regionsChanged.set(true);
@@ -165,10 +165,10 @@ export default class ComfyMultiRegionNode extends ComfyWidgetNode<BoundingBox[]>
value ||= this.getValue();
for (const bbox of value) {
bbox[0] = clamp(bbox[0], 0, 1 - bbox[2]);
bbox[1] = clamp(bbox[1], 0, 1 - bbox[3]);
bbox[2] = clamp(bbox[2], 0, 1 - bbox[1])
bbox[3] = clamp(bbox[3], 0, 1 - bbox[2])
bbox[0] = clamp(bbox[0], 0, 1);
bbox[1] = clamp(bbox[1], 0, 1);
bbox[2] = clamp(bbox[2], 0, 1)
bbox[3] = clamp(bbox[3], 0, 1)
}
const sizeChanged = this.properties.canvasWidth != this._prevWidth