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}), "coordinates": ("STRING", {"multiline": False}),
"mask_width": ("INT", {"default": 512, "min": 8, "max": MAX_RESOLUTION, "step": 8}), "mask_width": ("INT", {"default": 512, "min": 8, "max": MAX_RESOLUTION, "step": 8}),
"mask_height": ("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": ( "interpolation": (
[ [
'cardinal', 'cardinal',

View File

@ -151,6 +151,17 @@ app.registerExtension({
function createSplineEditor(context, reset=false) { function createSplineEditor(context, reset=false) {
console.log("creatingSplineEditor") 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) { if (reset && context.splineEditor.element) {
context.splineEditor.element.innerHTML = ''; // Clear the container context.splineEditor.element.innerHTML = ''; // Clear the container
} }
@ -166,30 +177,15 @@ function createSplineEditor(context, reset=false) {
var points_to_sample = pointsWidget.value var points_to_sample = pointsWidget.value
interpolationWidget.callback = () => { interpolationWidget.callback = () => {
interpolation = interpolationWidget.value interpolation = interpolationWidget.value
vis.render();
} }
tensionWidget.callback = () => { tensionWidget.callback = () => {
tension = tensionWidget.value tension = tensionWidget.value
points_to_sample = pointsWidget.value updatePath();
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();
}
} }
pointsWidget.callback = () => { pointsWidget.callback = () => {
points_to_sample = pointsWidget.value updatePath();
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();
}
} }
// Initialize or reset points array // Initialize or reset points array
@ -234,12 +230,7 @@ function createSplineEditor(context, reset=false) {
}) })
.event("mouseup", function() { .event("mouseup", function() {
if (this.pathElements !== null) { if (this.pathElements !== null) {
let coords = samplePoints(pathElements[0], points_to_sample); updatePath();
let coordsString = JSON.stringify(coords);
pointsStoreWidget.value = JSON.stringify(points);
if (coordWidget) {
coordWidget.value = coordsString;
}
} }
}); });