Add direction_in optional input for chaining direction outputs; clean up unused code
This commit is contained in:
@@ -126,71 +126,32 @@ class CompassImageLoader:
|
|||||||
"width": ("INT", {"default": 0, "min": 0, "max": 16384, "step": 1}),
|
"width": ("INT", {"default": 0, "min": 0, "max": 16384, "step": 1}),
|
||||||
"height": ("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_TYPES = ("IMAGE", "STRING", "STRING", "INT", "INT", "INT")
|
||||||
RETURN_NAMES = ("IMAGE", "path", "direction", "width", "height", "frame_count")
|
RETURN_NAMES = ("IMAGE", "path", "direction", "width", "height", "frame_count")
|
||||||
FUNCTION = "load_images"
|
FUNCTION = "load_images"
|
||||||
|
OUTPUT_NODE = False
|
||||||
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))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def IS_CHANGED(
|
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
|
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()
|
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)
|
modality_path = os.path.join(target_dir, modality)
|
||||||
|
|
||||||
if not os.path.isdir(modality_path):
|
if not os.path.isdir(modality_path):
|
||||||
@@ -199,7 +160,7 @@ class CompassImageLoader:
|
|||||||
files = _list_image_files(modality_path)
|
files = _list_image_files(modality_path)
|
||||||
m = hashlib.sha256()
|
m = hashlib.sha256()
|
||||||
m.update(
|
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() == "":
|
if frame is None or str(frame).strip() == "":
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
import { app } from "../../../scripts/app.js";
|
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) {
|
function filterChildDirs(allDirs, parentPrefix) {
|
||||||
const prefixNorm = parentPrefix.replace(/\/$/, "").toLowerCase();
|
const prefixNorm = parentPrefix.replace(/\/$/, "").toLowerCase();
|
||||||
const results = [];
|
const results = [];
|
||||||
@@ -191,6 +183,17 @@ app.registerExtension({
|
|||||||
origOnRemoved();
|
origOnRemoved();
|
||||||
listEl.remove();
|
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";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user