Spline editor cleanup

This commit is contained in:
kijai 2024-04-25 23:28:16 +03:00
parent 0920c127be
commit 6e0784801a
2 changed files with 16 additions and 25 deletions

View File

@ -4755,7 +4755,7 @@ class SplineEditor:
"coordinates": ("STRING", {"multiline": False}),
"mask_width": ("INT", {"default": 512, "min": 8, "max": MAX_RESOLUTION, "step": 8}),
"mask_height": ("INT", {"default": 512, "min": 8, "max": MAX_RESOLUTION, "step": 8}),
"points_to_sample": ("INT", {"default": 4, "min": 2, "max": 1000, "step": 1}),
"points_to_sample": ("INT", {"default": 16, "min": 2, "max": 1000, "step": 1}),
"interpolation": (
[
'cardinal',

View File

@ -150,10 +150,21 @@ app.registerExtension({
function createSplineEditor(context, reset=false) {
console.log("creatingSplineEditor")
function updatePath() {
points_to_sample = pointsWidget.value
let coords = samplePoints(pathElements[0], points_to_sample);
let coordsString = JSON.stringify(coords);
pointsStoreWidget.value = JSON.stringify(points);
if (coordWidget) {
coordWidget.value = coordsString;
}
vis.render();
}
if (reset && context.splineEditor.element) {
context.splineEditor.element.innerHTML = ''; // Clear the container
}
}
const coordWidget = context.widgets.find(w => w.name === "coordinates");
const interpolationWidget = context.widgets.find(w => w.name === "interpolation");
const pointsWidget = context.widgets.find(w => w.name === "points_to_sample");
@ -166,31 +177,16 @@ function createSplineEditor(context, reset=false) {
var points_to_sample = pointsWidget.value
interpolationWidget.callback = () => {
interpolation = interpolationWidget.value
vis.render();
}
tensionWidget.callback = () => {
tension = tensionWidget.value
points_to_sample = pointsWidget.value
let coords = samplePoints(pathElements[0], points_to_sample);
let coordsString = JSON.stringify(coords);
pointsStoreWidget.value = JSON.stringify(points);
if (coordWidget) {
coordWidget.value = coordsString;
vis.render();
updatePath();
}
}
pointsWidget.callback = () => {
points_to_sample = pointsWidget.value
let coords = samplePoints(pathElements[0], points_to_sample);
let coordsString = JSON.stringify(coords);
pointsStoreWidget.value = JSON.stringify(points);
if (coordWidget) {
coordWidget.value = coordsString;
vis.render();
updatePath();
}
}
// Initialize or reset points array
var w = 512
@ -234,12 +230,7 @@ function createSplineEditor(context, reset=false) {
})
.event("mouseup", function() {
if (this.pathElements !== null) {
let coords = samplePoints(pathElements[0], points_to_sample);
let coordsString = JSON.stringify(coords);
pointsStoreWidget.value = JSON.stringify(points);
if (coordWidget) {
coordWidget.value = coordsString;
}
updatePath();
}
});