From a4107d5ec2eb4e540c13963552792ad536e8ab39 Mon Sep 17 00:00:00 2001 From: CrossPr0duct Date: Thu, 12 Jun 2025 13:20:32 -0400 Subject: [PATCH] Setting up the background inference. --- .../app/src/pages/PageDraw/PageDraw.tsx | 12 ++++++++ .../src/pages/PageDraw/stores/SceneState.ts | 29 +++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/frontend/apps/editor3d/app/src/pages/PageDraw/PageDraw.tsx b/frontend/apps/editor3d/app/src/pages/PageDraw/PageDraw.tsx index 3bd3f7f677..441175f43f 100644 --- a/frontend/apps/editor3d/app/src/pages/PageDraw/PageDraw.tsx +++ b/frontend/apps/editor3d/app/src/pages/PageDraw/PageDraw.tsx @@ -290,6 +290,18 @@ const PageDraw = () => { onMenuAction={(action) => { switch (action) { + case 'REMOVE_BACKGROUND': + // returns a success if we have selected images only + store.removeBackground(store.selectedNodeIds, (success: boolean, message: string) => { + if (success) { + console.log(message); + return { success: true, file: new File([], "temp.png") }; // Replace with actual file when ready + } else { + console.error(message); + return { success: false }; + } + }); + break; case 'BRING_TO_FRONT': store.bringToFront(store.selectedNodeIds); break; diff --git a/frontend/apps/editor3d/app/src/pages/PageDraw/stores/SceneState.ts b/frontend/apps/editor3d/app/src/pages/PageDraw/stores/SceneState.ts index a2e4cd4dcf..f810378a9b 100644 --- a/frontend/apps/editor3d/app/src/pages/PageDraw/stores/SceneState.ts +++ b/frontend/apps/editor3d/app/src/pages/PageDraw/stores/SceneState.ts @@ -110,7 +110,7 @@ interface SceneState { sendToBack: (nodeIds: string[]) => void; bringForward: (nodeIds: string[]) => void; sendBackward: (nodeIds: string[]) => void; - removeBackground: (nodeIds: string[],operation: (success: boolean) => void) => void; + removeBackground: (nodeIds: string[], operation: (success: boolean, message: string) => { success: boolean; file?: File }) => void; } const generateId = (): string => { @@ -1132,9 +1132,28 @@ export const useSceneStore = create((set, get) => ({ }); get().saveState(); }, - removeBackground: (nodeIds: string[], operation: (success: boolean) => void): void => { - // Implement the logic for removing the background here - const success = true; // Placeholder for actual implementation - operation(success); + removeBackground: (nodeIds: string[], operation: (success: boolean, message: string) => { success: boolean; file?: File }) => { + + const hasImageNodes = nodeIds.some(id => { + const node = get().nodes.find(n => n.id === id); + return node ? node.type === 'image': false; + }); + let callbackSuccess = false + if (hasImageNodes) { + console.log("Selected nodes include image types."); + // Logic to remove background from image nodes would go here + const { success, file } = operation(true, "Removing Background."); // Indicate success in removing background + callbackSuccess = success + if (callbackSuccess) { + // save the state of the image. + set(state => { + + }) + } + } else { + console.log("No selected nodes are of image type."); + operation(false,"Did not select a Images"); // Indicate failure to remove background + } + }, }));