From 14f99bcfee0d35093d8e59c1f43607fd2037f066 Mon Sep 17 00:00:00 2001 From: Palazzini Luca Date: Fri, 13 Sep 2024 20:20:12 +0200 Subject: [PATCH] Add toggle button to split global_conditioning from other conditionings --- visual_area_prompt.py | 9 +++++---- web/visual_area_prompt.js | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/visual_area_prompt.py b/visual_area_prompt.py index acd8049..c920651 100644 --- a/visual_area_prompt.py +++ b/visual_area_prompt.py @@ -10,6 +10,7 @@ class VisualAreaPrompt: "required": { "general_conditioning": ("CONDITIONING", { "tooltip": "Base conditioning. Will be concatenated to all other conditionings." }), "global_conditioning": ("CONDITIONING", { "tooltip": "Base conditioning. Will be applied to the whole image once." }), + "merge_global": ("BOOLEAN", { "default": False, "tooltip": "Turning this on will make it so that the global conditioning will be concatenated to all other conditionings before being applied. (will not affect combined_conditioning output)." }), }, "hidden": { "extra_pnginfo": "EXTRA_PNGINFO", @@ -24,7 +25,7 @@ class VisualAreaPrompt: OUTPUT_NODE = False CATEGORY = "RegionalPrompt" - def run_node(self, general_conditioning, global_conditioning, extra_pnginfo, unique_id, **kwargs): + def run_node(self, general_conditioning, global_conditioning, merge_global, extra_pnginfo, unique_id, **kwargs): # Get values for the conditioning areas from the extra_pnginfo conditioning_areas: list[list[float]] = [] for node in extra_pnginfo["workflow"]["nodes"]: @@ -42,7 +43,7 @@ class VisualAreaPrompt: for cond in conditionings[1:]: last_concat: Node = graph.node("ConditioningConcat", conditioning_to=last_concat.out(0), conditioning_from=cond) # Combine with global conditioning - combined_conditioning: Node = graph.node("ConditioningConcat", conditioning_to=last_concat.out(0), conditioning_from=global_conditioning) + last_concat: Node = graph.node("ConditioningConcat", conditioning_to=last_concat.out(0), conditioning_from=global_conditioning) # Concat general to all other area conditionings (to: general, from: cond) conditionings_general: list = [] for cond in conditionings: @@ -67,9 +68,9 @@ class VisualAreaPrompt: for cond in conditionings_area[2:]: last_combine: Node = graph.node("ConditioningCombine", conditioning_1=last_combine.out(0), conditioning_2=cond.out(0)) # Final combination with the previously combined conditioning - output: Node = graph.node("ConditioningCombine", conditioning_1=last_combine.out(0), conditioning_2=combined_conditioning.out(0)) + output: Node = graph.node("ConditioningCombine", conditioning_1=last_combine.out(0), conditioning_2=last_concat.out(0) if merge_global else global_conditioning) # Return result and expanded graph return { - "result": (output.out(0), combined_conditioning.out(0)), + "result": (output.out(0), last_concat.out(0)), "expand": graph.finalize() } diff --git a/web/visual_area_prompt.js b/web/visual_area_prompt.js index e25ef94..8dbae08 100644 --- a/web/visual_area_prompt.js +++ b/web/visual_area_prompt.js @@ -36,7 +36,7 @@ function generateHslColor(value, max, alpha) { } function computeCanvasSize(node, size) { - if (node.widgets[0].last_y == null) { + if (node.widgets[1].last_y == null) { return; } const yBase = WIDGET_BASE_HEIGHT * Math.max(node.inputs.length, node.outputs.length) + 5; @@ -152,8 +152,8 @@ function updateWidgetValues(node) { [..._AREA_DEFAULTS].forEach((value, i) => { const newValue = areaValues[i] || value; node.properties["area_values"][node.index][i] = newValue; - // Offset by two because there are two widgets that should not change (graph and id) - node.widgets[i + 2].value = newValue; + // Offset by three because there are three widgets that should not change (boolean, graph and id) + node.widgets[i + 3].value = newValue; }); } @@ -245,8 +245,8 @@ app.registerExtension({ // Set ID widget new max and value const countDynamicInputs = this.inputs.filter((input) => input.name.includes(_PREFIX)).length; const newMaxIdx = (countDynamicInputs - 1) >= 0 ? (countDynamicInputs - 1) : 0; - this.widgets[1].options.max = newMaxIdx; - this.widgets[1].value = newMaxIdx; + this.widgets[2].options.max = newMaxIdx; + this.widgets[2].value = newMaxIdx; this.index = newMaxIdx; updateWidgetValues(this); // Remove extra values