Update spline_editor.js

This commit is contained in:
kijai 2024-04-25 17:58:04 +03:00
parent b99d27311f
commit ddc4753a03

View File

@ -160,6 +160,30 @@ function createSplineEditor(context, reset=false) {
const pointsStoreWidget = context.widgets.find(w => w.name === "points_store"); const pointsStoreWidget = context.widgets.find(w => w.name === "points_store");
const tensionWidget = context.widgets.find(w => w.name === "tension"); const tensionWidget = context.widgets.find(w => w.name === "tension");
const segmentedWidget = context.widgets.find(w => w.name === "segmented"); const segmentedWidget = context.widgets.find(w => w.name === "segmented");
var interpolation = interpolationWidget.value
var tension = tensionWidget.value
var points_to_sample = pointsWidget.value
interpolationWidget.callback = () => {
interpolation = interpolationWidget.value
vis.render();
}
tensionWidget.callback = () => {
tension = tensionWidget.value
vis.render();
}
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();
}
}
// Initialize or reset points array // Initialize or reset points array
var w = 512 var w = 512
@ -203,7 +227,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], pointsWidget.value); let coords = samplePoints(pathElements[0], points_to_sample);
let coordsString = JSON.stringify(coords); let coordsString = JSON.stringify(coords);
pointsStoreWidget.value = JSON.stringify(points); pointsStoreWidget.value = JSON.stringify(points);
if (coordWidget) { if (coordWidget) {
@ -222,9 +246,9 @@ function createSplineEditor(context, reset=false) {
.data(() => points) .data(() => points)
.left(d => d.x) .left(d => d.x)
.top(d => d.y) .top(d => d.y)
.interpolate(() => interpolationWidget.value) .interpolate(() => interpolation)
.tension(() => tensionWidget.value) .tension(() => tension)
.segmented(() => segmentedWidget.value) .segmented(() => false)
.strokeStyle(pv.Colors.category10().by(pv.index)) .strokeStyle(pv.Colors.category10().by(pv.index))
.lineWidth(3) .lineWidth(3)