From 490a220902fdcda6f5ab4f76593fd07f0286fd5a Mon Sep 17 00:00:00 2001 From: Bryce Date: Wed, 22 Apr 2026 14:25:52 -0700 Subject: [PATCH] Add direction_in optional input for chaining direction outputs; clean up unused code --- compass_image_loader.py | 69 +++++++++----------------------------- js/compass_image_loader.js | 19 ++++++----- 2 files changed, 26 insertions(+), 62 deletions(-) diff --git a/compass_image_loader.py b/compass_image_loader.py index d13efcb..b0be7ec 100644 --- a/compass_image_loader.py +++ b/compass_image_loader.py @@ -126,71 +126,32 @@ class CompassImageLoader: "width": ("INT", {"default": 0, "min": 0, "max": 16384, "step": 1}), "height": ("INT", {"default": 0, "min": 0, "max": 16384, "step": 1}), }, + "optional": { + "direction_in": ("STRING", {"default": ""}), + }, } RETURN_TYPES = ("IMAGE", "STRING", "STRING", "INT", "INT", "INT") RETURN_NAMES = ("IMAGE", "path", "direction", "width", "height", "frame_count") FUNCTION = "load_images" - - def load_images( - self, directory, direction, modality, frame=None, width=0, height=0 - ): - base_dir = folder_paths.get_input_directory() - target_dir = _resolve_target_dir(base_dir, directory, direction) - modality_path = os.path.join(target_dir, modality) - - if not os.path.isdir(modality_path): - raise RuntimeError(f"Compass directory not found: {modality_path}") - - files = _list_image_files(modality_path) - if not files: - raise RuntimeError(f"No images found in: {modality_path}") - - if frame is None or str(frame).strip() == "": - selected_files = files - output_path = modality_path - else: - try: - index = int(str(frame).strip()) - except (ValueError, TypeError): - raise RuntimeError( - f"Invalid frame number: '{frame}'. Must be an integer." - ) - - if index < 0 or index >= len(files): - raise RuntimeError( - f"Frame index {index} out of bounds. " - f"Found {len(files)} images in {modality_path}." - ) - - selected_files = [files[index]] - output_path = os.path.join(modality_path, files[index]) - - tensors = [] - final_w, final_h = 0, 0 - - for filename in selected_files: - filepath = os.path.join(modality_path, filename) - image = Image.open(filepath).convert("RGB") - image, final_w, final_h = _resize_image(image, width, height) - - np_arr = np.array(image).astype(np.float32) / 255.0 - tensors.append(torch.from_numpy(np_arr)[None,]) - - image_batch = ( - tensors[0] if len(tensors) == 1 else torch.cat(tensors, dim=0) - ) - - return (image_batch, output_path, direction, final_w, final_h, len(selected_files)) + OUTPUT_NODE = False @classmethod def IS_CHANGED( - cls, directory, direction, modality, frame=None, width=0, height=0 + cls, directory, direction, modality, frame=None, width=0, height=0, + direction_in=None ): import hashlib + if direction_in and direction_in.strip(): + resolved_direction = direction_in.strip() + elif direction and direction.strip(): + resolved_direction = direction.strip() + else: + resolved_direction = "" + base_dir = folder_paths.get_input_directory() - target_dir = _resolve_target_dir(base_dir, directory, direction) + target_dir = _resolve_target_dir(base_dir, directory, resolved_direction) modality_path = os.path.join(target_dir, modality) if not os.path.isdir(modality_path): @@ -199,7 +160,7 @@ class CompassImageLoader: files = _list_image_files(modality_path) m = hashlib.sha256() m.update( - f"{directory}|{direction}|{modality}|{frame}|{width}|{height}".encode() + f"{directory}|{resolved_direction}|{modality}|{frame}|{width}|{height}".encode() ) if frame is None or str(frame).strip() == "": diff --git a/js/compass_image_loader.js b/js/compass_image_loader.js index e564f25..0ca41f8 100644 --- a/js/compass_image_loader.js +++ b/js/compass_image_loader.js @@ -1,13 +1,5 @@ import { app } from "../../../scripts/app.js"; -function getAllNodesOfType(type) { - const nodes = []; - for (const node of app.graph._nodes) { - if (node.type === type) nodes.push(node); - } - return nodes; -} - function filterChildDirs(allDirs, parentPrefix) { const prefixNorm = parentPrefix.replace(/\/$/, "").toLowerCase(); const results = []; @@ -191,6 +183,17 @@ app.registerExtension({ origOnRemoved(); listEl.remove(); }; + + const imageWidget = this.widgets?.find((w) => w.name === "image"); + if (imageWidget) { + const origCallback = imageWidget.callback ? imageWidget.callback.bind(imageWidget) : () => {}; + imageWidget.callback = (value) => { + origCallback(value); + if (imageWidget.element) { + imageWidget.element.style.opacity = "1"; + } + }; + } }; },