From f41539532fa747d03e622bf808823f17252584e9 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:24:04 +1000 Subject: [PATCH] feat(ui): use node manager for addRegions --- .../nodes/util/graph/generation/addRegions.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/addRegions.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/addRegions.ts index c20fcd56d6..7d47ac3331 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/addRegions.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/addRegions.ts @@ -1,7 +1,6 @@ import { getStore } from 'app/store/nanostores/store'; import { deepClone } from 'common/util/deepClone'; import openBase64ImageInTab from 'common/util/openBase64ImageInTab'; -import { RG_LAYER_NAME } from 'features/controlLayers/konva/naming'; import { KonvaNodeManager } from 'features/controlLayers/konva/nodeManager'; import { renderRegions } from 'features/controlLayers/konva/renderers/regions'; import { blobToDataURL } from 'features/controlLayers/konva/util'; @@ -261,22 +260,23 @@ export const getRGMaskBlobs = async ( ): Promise> => { const container = document.createElement('div'); const stage = new Konva.Stage({ container, ...documentSize }); - renderRegions(new KonvaNodeManager(stage), regions, 1, 'brush', null); - const konvaLayers = stage.find(`.${RG_LAYER_NAME}`); + const manager = new KonvaNodeManager(stage); + renderRegions(manager, regions, 1, 'brush', null); + const adapters = manager.getAll(); const blobs: Record = {}; // First remove all layers - for (const layer of konvaLayers) { - layer.remove(); + for (const adapter of adapters) { + adapter.konvaLayer.remove(); } // Next render each layer to a blob - for (const layer of konvaLayers) { - const rg = regions.find((l) => l.id === layer.id()); - if (!rg) { + for (const adapter of adapters) { + const region = regions.find((l) => l.id === adapter.id); + if (!region) { continue; } - stage.add(layer); + stage.add(adapter.konvaLayer); const blob = await new Promise((resolve) => { stage.toBlob({ callback: (blob) => { @@ -292,12 +292,12 @@ export const getRGMaskBlobs = async ( openBase64ImageInTab([ { base64, - caption: `${rg.id}: ${rg.positivePrompt} / ${rg.negativePrompt}`, + caption: `${region.id}: ${region.positivePrompt} / ${region.negativePrompt}`, }, ]); } - layer.remove(); - blobs[layer.id()] = blob; + adapter.konvaLayer.remove(); + blobs[adapter.id] = blob; } return blobs;