Add direction_in optional input for chaining direction outputs; clean up unused code

This commit is contained in:
2026-04-22 14:25:52 -07:00
parent cdc5979e3f
commit 490a220902
2 changed files with 26 additions and 62 deletions

View File

@@ -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() == "":