This commit is contained in:
Kijai 2024-05-06 17:37:51 +03:00
parent b1a061fe47
commit 6afc4c38e7

View File

@ -193,10 +193,11 @@ app.registerExtension({
chainCallback(this, "onGraphConfigured", function() { chainCallback(this, "onGraphConfigured", function() {
this.editor.createEditor(); this.editor.createEditor();
}); });
chainCallback(this, "onConnectInput", function() { chainCallback(this, "onConnectInput", function(targetSlot, type, output, originNode, originSlot) {
console.log("INPUT CONNECTED") console.log("INPUT CONNECTED")
console.log(this.editor) console.log(targetSlot, type, output, originNode, originSlot)
this.editor.syncEditors(this); console.log("ORIGINNODE: ",originNode)
this.editor.syncEditors(originNode);
}); });
@ -623,16 +624,18 @@ class SplineEditor {
updatePath(); updatePath();
this.vis = vis this.vis = vis
} }
syncEditors(context) { syncEditors(originNode, targetNode) {
console.log(context) console.log(originNode)
let linkedInputEditor = context.getInputLink(0) let linkedInputEditor = originNode
let linkedOutputEditor = context.getOutputNodes(4) let linkedOutputEditor = originNode.outputs[4]
console.log(originNode.graph.links.filter(item => item.type === "EDITORLINK"))
console.log("linkedInputEditor: ",linkedInputEditor) console.log("linkedInputEditor: ",linkedInputEditor)
console.log("linkedOutputEditor: ",linkedOutputEditor) console.log("linkedOutputEditor: ",linkedOutputEditor)
let extraLineLayer = null let extraLineLayer = null
if (linkedInputEditor != null) { if (linkedInputEditor != null) {
let linkedInputPointsWidget = linkedInputEditor.widgets.find(w => w.name === "points_store") let linkedInputPointsWidget = linkedInputEditor.widgets.find(w => w.name === "points_store")
let linkedInputEditorCoords = JSON.parse(linkedInputPointsWidget.value) let linkedInputEditorCoords = JSON.parse(linkedInputPointsWidget.value)
//console.log("linkedInputEditorCoords",linkedInputEditorCoords) //console.log("linkedInputEditorCoords",linkedInputEditorCoords)
if (extraLineLayer) { if (extraLineLayer) {
console.log("extraLineLayer exists",extraLineLayer) console.log("extraLineLayer exists",extraLineLayer)
@ -645,7 +648,7 @@ class SplineEditor {
.left(d => d.x) .left(d => d.x)
.top(d => d.y) .top(d => d.y)
.interpolate(() => linkedInputEditor.widgets.find(w => w.name === "interpolation").value) .interpolate(() => linkedInputEditor.widgets.find(w => w.name === "interpolation").value)
.tension(() => tension) .tension(() => linkedInputEditor.widgets.find(w => w.name === "tension").value)
.segmented(() => false) .segmented(() => false)
.strokeStyle(linkedInputEditor.properties.spline_color["color"]) .strokeStyle(linkedInputEditor.properties.spline_color["color"])
.lineWidth(3) .lineWidth(3)
@ -659,32 +662,32 @@ class SplineEditor {
} }
} }
if (linkedOutputEditor != null) { // if (linkedOutputEditor != null) {
let linkedOutputPointsWidget = linkedOutputEditor[0].widgets.find(w => w.name === "points_store") // let linkedOutputPointsWidget = linkedOutputEditor[0].widgets.find(w => w.name === "points_store")
let linkedOutputEditorCoords = JSON.parse(linkedOutputPointsWidget.value) // let linkedOutputEditorCoords = JSON.parse(linkedOutputPointsWidget.value)
//console.log(linkedInputEditorCoords) // //console.log(linkedInputEditorCoords)
if (extraLineLayer) { // if (extraLineLayer) {
// Update the data of the existing layer // // Update the data of the existing layer
extraLineLayer.data(linkedOutputEditorCoords); // extraLineLayer.data(linkedOutputEditorCoords);
} else { // } else {
// Create the points layer if it doesn't exist // // Create the points layer if it doesn't exist
extraLineLayer = this.vis.add(pv.Line) // extraLineLayer = this.vis.add(pv.Line)
.data(() => linkedOutputEditorCoords) // .data(() => linkedOutputEditorCoords)
.left(d => d.x) // .left(d => d.x)
.top(d => d.y) // .top(d => d.y)
.interpolate(() => linkedOutputEditor[0].widgets.find(w => w.name === "interpolation").value) // .interpolate(() => linkedOutputEditor[0].widgets.find(w => w.name === "interpolation").value)
.tension(() => tension) // .tension(() => linkedOutputEditor[0].widgets.find(w => w.name === "tension").value)
.segmented(() => false) // .segmented(() => false)
.strokeStyle(linkedOutputEditor[0].properties.spline_color["color"]) // .strokeStyle(linkedOutputEditor[0].properties.spline_color["color"])
.lineWidth(3) // .lineWidth(3)
} // }
} else { // } else {
// if (extraLineLayer) { // // if (extraLineLayer) {
// // Remove the points layer // // // Remove the points layer
// extraLineLayer.data([]); // // extraLineLayer.data([]);
// vis.render(); // // vis.render();
// } // // }
} // }
} }
} }
function samplePoints(svgPathElement, numSamples, samplingMethod, width) { function samplePoints(svgPathElement, numSamples, samplingMethod, width) {