mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2026-06-04 23:04:27 +08:00
Add normalized_str output to spline editor
thanks @joviex !
This commit is contained in:
parent
218e95c8c9
commit
668496d85f
@ -149,8 +149,8 @@ class SplineEditor:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_TYPES = ("MASK", "STRING", "FLOAT", "INT")
|
RETURN_TYPES = ("MASK", "STRING", "FLOAT", "INT", "STRING",)
|
||||||
RETURN_NAMES = ("mask", "coord_str", "float", "count")
|
RETURN_NAMES = ("mask", "coord_str", "float", "count", "normalized_str",)
|
||||||
FUNCTION = "splinedata"
|
FUNCTION = "splinedata"
|
||||||
CATEGORY = "KJNodes/weights"
|
CATEGORY = "KJNodes/weights"
|
||||||
DESCRIPTION = """
|
DESCRIPTION = """
|
||||||
@ -195,14 +195,15 @@ output types:
|
|||||||
points_to_sample, sampling_method, points_store, tension, repeat_output, min_value=0.0, max_value=1.0):
|
points_to_sample, sampling_method, points_store, tension, repeat_output, min_value=0.0, max_value=1.0):
|
||||||
|
|
||||||
coordinates = json.loads(coordinates)
|
coordinates = json.loads(coordinates)
|
||||||
|
normalized = []
|
||||||
|
normalized_y_values = []
|
||||||
for coord in coordinates:
|
for coord in coordinates:
|
||||||
coord['x'] = int(round(coord['x']))
|
coord['x'] = int(round(coord['x']))
|
||||||
coord['y'] = int(round(coord['y']))
|
coord['y'] = int(round(coord['y']))
|
||||||
|
norm_x = (1.0 - (coord['x'] / mask_height) - 0.0) * (max_value - min_value) + min_value
|
||||||
normalized_y_values = [
|
norm_y = (1.0 - (coord['y'] / mask_height) - 0.0) * (max_value - min_value) + min_value
|
||||||
(1.0 - (point['y'] / mask_height) - 0.0) * (max_value - min_value) + min_value
|
normalized_y_values.append(norm_y)
|
||||||
for point in coordinates
|
normalized.append({'x':norm_x, 'y':norm_y})
|
||||||
]
|
|
||||||
if float_output_type == 'list':
|
if float_output_type == 'list':
|
||||||
out_floats = normalized_y_values * repeat_output
|
out_floats = normalized_y_values * repeat_output
|
||||||
elif float_output_type == 'pandas series':
|
elif float_output_type == 'pandas series':
|
||||||
@ -221,7 +222,7 @@ output types:
|
|||||||
masks_out = torch.stack(mask_tensors)
|
masks_out = torch.stack(mask_tensors)
|
||||||
masks_out = masks_out.repeat(repeat_output, 1, 1, 1)
|
masks_out = masks_out.repeat(repeat_output, 1, 1, 1)
|
||||||
masks_out = masks_out.mean(dim=-1)
|
masks_out = masks_out.mean(dim=-1)
|
||||||
return (masks_out, str(coordinates), out_floats, len(out_floats))
|
return (masks_out, json.dumps(coordinates), out_floats, len(out_floats) , json.dumps(normalized))
|
||||||
|
|
||||||
class CreateShapeMaskOnPath:
|
class CreateShapeMaskOnPath:
|
||||||
|
|
||||||
|
|||||||
@ -187,7 +187,7 @@ app.registerExtension({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setSize([550, 920]);
|
this.setSize([550, 950]);
|
||||||
this.resizable = false;
|
this.resizable = false;
|
||||||
this.splineEditor.parentEl = document.createElement("div");
|
this.splineEditor.parentEl = document.createElement("div");
|
||||||
this.splineEditor.parentEl.className = "spline-editor";
|
this.splineEditor.parentEl.className = "spline-editor";
|
||||||
@ -392,7 +392,6 @@ function createSplineEditor(context, reset=false) {
|
|||||||
widthWidget.callback = () => {
|
widthWidget.callback = () => {
|
||||||
w = widthWidget.value;
|
w = widthWidget.value;
|
||||||
if (w > 256) {
|
if (w > 256) {
|
||||||
|
|
||||||
context.setSize([w + 45, context.size[1]]);
|
context.setSize([w + 45, context.size[1]]);
|
||||||
}
|
}
|
||||||
vis.width(w);
|
vis.width(w);
|
||||||
@ -401,7 +400,7 @@ function createSplineEditor(context, reset=false) {
|
|||||||
heightWidget.callback = () => {
|
heightWidget.callback = () => {
|
||||||
h = heightWidget.value
|
h = heightWidget.value
|
||||||
vis.height(h)
|
vis.height(h)
|
||||||
context.setSize([context.size[0], h + 410]);
|
context.setSize([context.size[0], h + 430]);
|
||||||
updatePath();
|
updatePath();
|
||||||
}
|
}
|
||||||
pointsStoreWidget.callback = () => {
|
pointsStoreWidget.callback = () => {
|
||||||
@ -610,6 +609,11 @@ function createSplineEditor(context, reset=false) {
|
|||||||
svgElement.style['position'] = "relative"
|
svgElement.style['position'] = "relative"
|
||||||
context.splineEditor.element.appendChild(svgElement);
|
context.splineEditor.element.appendChild(svgElement);
|
||||||
var pathElements = svgElement.getElementsByTagName('path'); // Get all path elements
|
var pathElements = svgElement.getElementsByTagName('path'); // Get all path elements
|
||||||
|
|
||||||
|
if (w > 256) {
|
||||||
|
context.setSize([w + 45, context.size[1]]);
|
||||||
|
}
|
||||||
|
context.setSize([context.size[0], h + 430]);
|
||||||
updatePath();
|
updatePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user