From 557edbae16975b718672c70a50f1d35e59fc4c01 Mon Sep 17 00:00:00 2001 From: kijai <40791699+kijai@users.noreply.github.com> Date: Tue, 9 Dec 2025 23:49:26 +0200 Subject: [PATCH] SplineEditor: Return only first spline length when using multiple splines --- nodes/curve_nodes.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/nodes/curve_nodes.py b/nodes/curve_nodes.py index 053d8c6..ceea047 100644 --- a/nodes/curve_nodes.py +++ b/nodes/curve_nodes.py @@ -253,7 +253,7 @@ output types: # Handle nested list structure if present all_normalized = [] all_normalized_y_values = [] - + # Check if we have a nested list structure if isinstance(coordinates, list) and len(coordinates) > 0 and isinstance(coordinates[0], list): # Process each list of coordinates in the nested structure @@ -261,12 +261,14 @@ output types: else: # If not nested, treat as a single list of coordinates coordinate_sets = [coordinates] - + + first_spline = coordinate_sets[0] if coordinate_sets else [] + # Process each set of coordinates for coord_set in coordinate_sets: normalized = [] normalized_y_values = [] - + for coord in coord_set: coord['x'] = int(round(coord['x'])) coord['y'] = int(round(coord['y'])) @@ -274,10 +276,10 @@ output types: norm_y = (1.0 - (coord['y'] / mask_height) - 0.0) * (max_value - min_value) + min_value normalized_y_values.append(norm_y) normalized.append({'x':norm_x, 'y':norm_y}) - + all_normalized.extend(normalized) all_normalized_y_values.extend(normalized_y_values) - + # Use the combined normalized values for output if float_output_type == 'list': out_floats = all_normalized_y_values * repeat_output @@ -289,18 +291,21 @@ output types: out_floats = pd.Series(all_normalized_y_values * repeat_output), elif float_output_type == 'tensor': out_floats = torch.tensor(all_normalized_y_values * repeat_output, dtype=torch.float32) - + # Create a color map for grayscale intensities color_map = lambda y: torch.full((mask_height, mask_width, 3), y, dtype=torch.float32) - # Create image tensors for each normalized y value - mask_tensors = [color_map(y) for y in all_normalized_y_values] + # Create a color map for grayscale intensities (from first spline only) + color_map = lambda y: torch.full((mask_height, mask_width, 3), y, dtype=torch.float32) + mask_tensors = [color_map(y) for y in normalized_y_values] masks_out = torch.stack(mask_tensors) masks_out = masks_out.repeat(repeat_output, 1, 1, 1) masks_out = masks_out.mean(dim=-1) - + + single_spline_count = len(first_spline) + if bg_image is None: - return (masks_out, json.dumps(coordinates if len(coordinates) > 1 else coordinates[0]), out_floats, len(out_floats), json.dumps(all_normalized)) + return (masks_out, json.dumps(coordinates if len(coordinates) > 1 else coordinates[0]), out_floats, single_spline_count, json.dumps(all_normalized)) else: transform = transforms.ToPILImage() image = transform(bg_image[0].permute(2, 0, 1)) @@ -310,12 +315,12 @@ output types: # Encode the image bytes to a Base64 string img_bytes = buffered.getvalue() img_base64 = base64.b64encode(img_bytes).decode('utf-8') - + return { "ui": {"bg_image": [img_base64]}, - "result": (masks_out, json.dumps(coordinates if len(coordinates) > 1 else coordinates[0]), out_floats, len(out_floats), json.dumps(all_normalized)) + "result": (masks_out, json.dumps(coordinates if len(coordinates) > 1 else coordinates[0]), out_floats, single_spline_count, json.dumps(all_normalized)) } - + class CreateShapeMaskOnPath: