mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-07 08:30:06 +00:00
fix in onNodeDeselected
This commit is contained in:
@@ -6080,13 +6080,6 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
}
|
||||
};
|
||||
|
||||
LGraphCanvas.prototype.processNodeDeselected = function(node) {
|
||||
this.deselectNode(node);
|
||||
if (this.onNodeDeselected) {
|
||||
this.onNodeDeselected(node);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* selects a given node (or adds it to the current selection)
|
||||
* @method selectNode
|
||||
@@ -6163,6 +6156,10 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
}
|
||||
node.is_selected = false;
|
||||
|
||||
if (this.onNodeDeselected) {
|
||||
this.onNodeDeselected(node);
|
||||
}
|
||||
|
||||
//remove highlighted
|
||||
if (node.inputs) {
|
||||
for (var i = 0; i < node.inputs.length; ++i) {
|
||||
@@ -6199,6 +6196,9 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
node.onDeselected();
|
||||
}
|
||||
node.is_selected = false;
|
||||
if (this.onNodeDeselected) {
|
||||
this.onNodeDeselected(node);
|
||||
}
|
||||
}
|
||||
this.selected_nodes = {};
|
||||
this.current_node = null;
|
||||
@@ -17167,7 +17167,8 @@ if (typeof exports != "undefined") {
|
||||
antialiasing: false,
|
||||
filter: true,
|
||||
disable_alpha: false,
|
||||
gamma: 1.0
|
||||
gamma: 1.0,
|
||||
viewport: [0,0,1,1]
|
||||
};
|
||||
this.size[0] = 130;
|
||||
}
|
||||
@@ -17175,6 +17176,7 @@ if (typeof exports != "undefined") {
|
||||
LGraphTextureToViewport.title = "to Viewport";
|
||||
LGraphTextureToViewport.desc = "Texture to viewport";
|
||||
|
||||
LGraphTextureToViewport._prev_viewport = new Float32Array(4);
|
||||
LGraphTextureToViewport.prototype.onExecute = function() {
|
||||
var tex = this.getInputData(0);
|
||||
if (!tex) {
|
||||
@@ -17203,6 +17205,12 @@ if (typeof exports != "undefined") {
|
||||
this.properties.filter ? gl.LINEAR : gl.NEAREST
|
||||
);
|
||||
|
||||
var old_viewport = LGraphTextureToViewport._prev_viewport;
|
||||
old_viewport.set( gl.viewport_data );
|
||||
var new_view = this.properties.viewport;
|
||||
gl.viewport( old_viewport[0] + old_viewport[2] * new_view[0], old_viewport[1] + old_viewport[3] * new_view[1], old_viewport[2] * new_view[2], old_viewport[3] * new_view[3] );
|
||||
var viewport = gl.getViewport(); //gl.getParameter(gl.VIEWPORT);
|
||||
|
||||
if (this.properties.antialiasing) {
|
||||
if (!LGraphTextureToViewport._shader) {
|
||||
LGraphTextureToViewport._shader = new GL.Shader(
|
||||
@@ -17211,7 +17219,6 @@ if (typeof exports != "undefined") {
|
||||
);
|
||||
}
|
||||
|
||||
var viewport = gl.getViewport(); //gl.getParameter(gl.VIEWPORT);
|
||||
var mesh = Mesh.getScreenQuad();
|
||||
tex.bind(0);
|
||||
LGraphTextureToViewport._shader
|
||||
@@ -17238,6 +17245,8 @@ if (typeof exports != "undefined") {
|
||||
tex.toViewport();
|
||||
}
|
||||
}
|
||||
|
||||
gl.viewport( old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3] );
|
||||
};
|
||||
|
||||
LGraphTextureToViewport.prototype.onGetInputs = function() {
|
||||
@@ -18639,7 +18648,7 @@ if (typeof exports != "undefined") {
|
||||
this.addInput("Mixer", "Texture");
|
||||
|
||||
this.addOutput("Texture", "Texture");
|
||||
this.properties = { factor: 0.5, precision: LGraphTexture.DEFAULT };
|
||||
this.properties = { factor: 0.5, size_from_biggest: true, invert: false, precision: LGraphTexture.DEFAULT };
|
||||
this._uniforms = {
|
||||
u_textureA: 0,
|
||||
u_textureB: 1,
|
||||
@@ -18677,7 +18686,7 @@ if (typeof exports != "undefined") {
|
||||
var factor = this.getInputData(3);
|
||||
|
||||
this._tex = LGraphTexture.getTargetTexture(
|
||||
texA,
|
||||
this.properties.size_from_biggest && texB.width > texA.width ? texB : texA,
|
||||
this._tex,
|
||||
this.properties.precision
|
||||
);
|
||||
@@ -18709,9 +18718,11 @@ if (typeof exports != "undefined") {
|
||||
uniforms.u_mix.set([f, f, f, f]);
|
||||
}
|
||||
|
||||
var invert = this.properties.invert;
|
||||
|
||||
this._tex.drawTo(function() {
|
||||
texA.bind(0);
|
||||
texB.bind(1);
|
||||
texA.bind( invert ? 1 : 0 );
|
||||
texB.bind( invert ? 0 : 1 );
|
||||
if (texMix) {
|
||||
texMix.bind(2);
|
||||
}
|
||||
|
||||
271
build/litegraph.min.js
vendored
271
build/litegraph.min.js
vendored
@@ -133,104 +133,103 @@ a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in
|
||||
0;b<c.inputs.length;++b){var h=c.inputs[b];if(h&&null!=h.link&&(h=this.graph.links[h.link])){var g=this.graph.getNodeById(h.origin_id);g&&this.selected_nodes[g.id]&&a.links.push([g._relative_id,h.origin_slot,c._relative_id,h.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};k.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],d=0;d<a.nodes.length;++d){var c=a.nodes[d],n=e.createNode(c.type);
|
||||
n&&(n.configure(c),n.pos[0]+=5,n.pos[1]+=5,this.graph.add(n),b.push(n))}for(d=0;d<a.links.length;++d)c=a.links[d],b[c[0]].connect(c[1],b[c[2]],c[3]);this.selectNodes(b)}};k.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],d=this.graph.getNodeOnPos(b[0],b[1]);if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var e=0;e<b.length;e++){var c=a.dataTransfer.files[0],h=c.name;k.getFileExtension(h);if(d.onDropFile)d.onDropFile(c);
|
||||
if(d.onDropData){var g=new FileReader;g.onload=function(a){d.onDropData(a.target.result,h,c)};var m=c.type.split("/")[0];"text"==m||""==m?g.readAsText(c):"image"==m?g.readAsDataURL(c):g.readAsArrayBuffer(c)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};k.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],d=k.getFileExtension(b.name).toLowerCase();
|
||||
if(d=e.node_types_by_file_extension[d])if(d=e.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};k.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};k.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};k.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};
|
||||
k.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};k.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var e=a[d];if(!e.is_selected){if(!e.is_selected&&e.onSelected)e.onSelected();e.is_selected=!0;this.selected_nodes[e.id]=e;if(e.inputs)for(var c=0;c<e.inputs.length;++c)this.highlighted_links[e.inputs[c].link]=!0;if(e.outputs)for(c=0;c<e.outputs.length;++c){var h=e.outputs[c];if(h.links)for(var g=
|
||||
0;g<h.links.length;++g)this.highlighted_links[h.links[g]]=!0}}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)};k.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var d=a.outputs[b];if(d.links)for(var e=0;e<d.links.length;++e)delete this.highlighted_links[d.links[e]]}}};
|
||||
k.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,d=a.length;b<d;++b){var e=a[b];if(e.is_selected){if(e.onDeselected)e.onDeselected();e.is_selected=!1}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};k.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.current_node=
|
||||
null;this.highlighted_links={};this.setDirty(!0)};k.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};k.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];
|
||||
a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};k.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};k.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,
|
||||
b)};k.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};k.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};k.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var x=new Float32Array(4);k.prototype.computeVisibleNodes=
|
||||
function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var e=0,c=a.length;e<c;++e){var h=a[e];(!this.live_mode||h.onDrawBackground||h.onDrawForeground)&&v(this.visible_area,h.getBounding(x))&&d.push(h)}return d};k.prototype.draw=function(a,b){if(this.canvas){var d=e.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea();(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-
|
||||
this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};k.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),
|
||||
a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&
|
||||
(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case e.EVENT:b=e.EVENT_LINK_COLOR;break;default:b=e.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?e.DOWN:e.RIGHT),e.CENTER);a.beginPath();this.connecting_output.type===e.EVENT||this.connecting_output.shape===e.BOX_SHAPE?
|
||||
a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,
|
||||
this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};k.prototype.renderInfo=function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+
|
||||
this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};k.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,
|
||||
0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();var d=this.graph._subgraph_node;b.strokeStyle=d.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=d.bgcolor||"#AAA";for(var e="",c=1;c<this._graph_stack.length;++c)e+=this._graph_stack[c]._subgraph_node.getTitle()+" >> ";b.fillText(e+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();
|
||||
b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!d){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var h=this;
|
||||
this._bg_img.onload=function(){h.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);
|
||||
if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";
|
||||
b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var g=new Float32Array(2);k.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||e.NODE_DEFAULT_COLOR,c=a.bgcolor||a.constructor.bgcolor||e.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var n=this.editor_alpha;b.globalAlpha=n;this.render_shadows?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,
|
||||
b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,this)){var h=a._shape||e.BOX_SHAPE;g.set(a.size);var m=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var k=a.getTitle?a.getTitle():a.title;null!=k&&(a._collapsed_width=Math.min(a.size[0],b.measureText(k).width+2*e.NODE_TITLE_HEIGHT),g[0]=a._collapsed_width,g[1]=0)}a.clip_area&&(b.save(),b.beginPath(),
|
||||
h==e.BOX_SHAPE?b.rect(0,0,g[0],g[1]):h==e.ROUND_SHAPE?b.roundRect(0,0,g[0],g[1],10):h==e.CIRCLE_SHAPE&&b.arc(0.5*g[0],0.5*g[1],0.5*g[0],0,2*Math.PI),b.clip());a.has_errors&&(c="red");this.drawNodeShape(a,b,g,d,c,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=m?"center":"left";b.font=this.inner_text_font;c=0.6<this.ds.scale;h=this.connecting_output;b.lineWidth=1;var k=0,q=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=
|
||||
0;d<a.inputs.length;d++){var p=a.inputs[d];b.globalAlpha=n;this.connecting_node&&!e.isValidConnection(p.type,h.type)&&(b.globalAlpha=0.4*n);b.fillStyle=null!=p.link?p.color_on||this.default_connection_color.input_on:p.color_off||this.default_connection_color.input_off;var f=a.getConnectionPos(!0,d,q);f[0]-=a.pos[0];f[1]-=a.pos[1];k<f[1]+0.5*e.NODE_SLOT_HEIGHT&&(k=f[1]+0.5*e.NODE_SLOT_HEIGHT);b.beginPath();p.type===e.EVENT||p.shape===e.BOX_SHAPE?m?b.rect(f[0]-5+0.5,f[1]-8+0.5,10,14):b.rect(f[0]-6+
|
||||
0.5,f[1]-5+0.5,14,10):p.shape===e.ARROW_SHAPE?(b.moveTo(f[0]+8,f[1]+0.5),b.lineTo(f[0]-4,f[1]+6+0.5),b.lineTo(f[0]-4,f[1]-6+0.5),b.closePath()):b.arc(f[0],f[1],4,0,2*Math.PI);b.fill();if(c){var l=null!=p.label?p.label:p.name;l&&(b.fillStyle=e.NODE_TEXT_COLOR,m||p.dir==e.UP?b.fillText(l,f[0],f[1]-10):b.fillText(l,f[0]+10,f[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*n);b.textAlign=m?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(p=a.outputs[d],f=a.getConnectionPos(!1,
|
||||
d,q),f[0]-=a.pos[0],f[1]-=a.pos[1],k<f[1]+0.5*e.NODE_SLOT_HEIGHT&&(k=f[1]+0.5*e.NODE_SLOT_HEIGHT),b.fillStyle=p.links&&p.links.length?p.color_on||this.default_connection_color.output_on:p.color_off||this.default_connection_color.output_off,b.beginPath(),p.type===e.EVENT||p.shape===e.BOX_SHAPE?m?b.rect(f[0]-5+0.5,f[1]-8+0.5,10,14):b.rect(f[0]-6+0.5,f[1]-5+0.5,14,10):p.shape===e.ARROW_SHAPE?(b.moveTo(f[0]+8,f[1]+0.5),b.lineTo(f[0]-4,f[1]+6+0.5),b.lineTo(f[0]-4,f[1]-6+0.5),b.closePath()):b.arc(f[0],
|
||||
f[1],4,0,2*Math.PI),b.fill(),b.stroke(),c&&(l=null!=p.label?p.label:p.name))b.fillStyle=e.NODE_TEXT_COLOR,m||p.dir==e.DOWN?b.fillText(l,f[0],f[1]-8):b.fillText(l,f[0]-10,f[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(m||a.widgets_up)k=2;this.drawNodeWidgets(a,k,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){n=c=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(p=a.inputs[d],null!=p.link){c=p;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)p=
|
||||
a.outputs[d],p.links&&p.links.length&&(n=p);c&&(d=0,c=-0.5*e.NODE_TITLE_HEIGHT,m&&(d=0.5*a._collapsed_width,c=-e.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),p.type===e.EVENT||p.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):p.shape===e.ARROW_SHAPE?(b.moveTo(d+8,c),b.lineTo(d+-4,c-4),b.lineTo(d+-4,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill());n&&(d=a._collapsed_width,c=-0.5*e.NODE_TITLE_HEIGHT,m&&(d=0.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),p.type===
|
||||
e.EVENT||p.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):p.shape===e.ARROW_SHAPE?(b.moveTo(d+6,c),b.lineTo(d-6,c-4),b.lineTo(d-6,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};k.prototype.drawLinkTooltip=function(a,b){var d=b._pos;a.fillStyle="black";a.beginPath();a.arc(d[0],d[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||!0!=this.onDrawLinkTooltip(a,b,this))){var e=b.data,c=null,c=e.constructor===Number?e.toFixed(2):e.constructor===
|
||||
String?'"'+e+'"':e.constructor===Boolean?String(e):e.toToolTip?e.toToolTip():"["+e.constructor.name+"]";null!=c&&(a.font="14px Courier New",e=a.measureText(c).width+20,a.shadowColor="black",a.shadowOffsetX=2,a.shadowOffsetY=2,a.shadowBlur=3,a.fillStyle="#454",a.beginPath(),a.roundRect(d[0]-0.5*e,d[1]-15-24,e,24,3,3),a.moveTo(d[0]-10,d[1]-15),a.lineTo(d[0]+10,d[1]-15),a.lineTo(d[0],d[1]-5),a.fill(),a.shadowColor="transparent",a.textAlign="center",a.fillStyle="#CEC",a.fillText(c,d[0],d[1]-15-24*0.3))}};
|
||||
var m=new Float32Array(4);k.prototype.drawNodeShape=function(a,b,d,c,n,h,g){b.strokeStyle=c;b.fillStyle=n;n=e.NODE_TITLE_HEIGHT;var p=0.5>this.ds.scale,q=a._shape||a.constructor.shape||e.ROUND_SHAPE,f=a.constructor.title_mode,l=!0;f==e.TRANSPARENT_TITLE?l=!1:f==e.AUTOHIDE_TITLE&&g&&(l=!0);m[0]=0;m[1]=l?-n:0;m[2]=d[0]+1;m[3]=l?d[1]+n:d[1];g=b.globalAlpha;b.beginPath();q==e.BOX_SHAPE||p?b.fillRect(m[0],m[1],m[2],m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE?b.roundRect(m[0],m[1],m[2],m[3],this.round_radius,
|
||||
q==e.CARD_SHAPE?0:this.round_radius):q==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,m[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(l||f==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,n,d,this.ds.scale,c);else if(f!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){l=a.constructor.title_color||
|
||||
c;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var u=k.gradients[l];u||(u=k.gradients[l]=b.createLinearGradient(0,0,400,0),u.addColorStop(0,l),u.addColorStop(1,"#000"));b.fillStyle=u}else b.fillStyle=l;b.beginPath();q==e.BOX_SHAPE||p?b.rect(0,-n,d[0]+1,n):q!=e.ROUND_SHAPE&&q!=e.CARD_SHAPE||b.roundRect(0,-n,d[0]+1,n,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,n,d,this.ds.scale);
|
||||
else q==e.ROUND_SHAPE||q==e.CIRCLE_SHAPE||q==e.CARD_SHAPE?(p&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*n,-0.5*n,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*n,-0.5*n,5,0,2*Math.PI),b.fill()):(p&&(b.fillStyle="black",b.fillRect(0.5*(n-10)-1,-0.5*(n+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(n-10),-0.5*(n+10),10,10));b.globalAlpha=g;if(a.onDrawTitleText)a.onDrawTitleText(b,n,d,this.ds.scale,this.title_text_font,
|
||||
h);!p&&(b.font=this.title_text_font,p=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",g=b.measureText(p),b.fillText(p,n+0.5*g.width,e.NODE_TITLE_TEXT_Y-n),b.textAlign="left"):(b.textAlign="left",b.fillText(p,n,e.NODE_TITLE_TEXT_Y-n)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(m);f==e.TRANSPARENT_TITLE&&(m[1]-=n,m[3]+=n);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();q==e.BOX_SHAPE?b.rect(-6+
|
||||
m[0],-6+m[1],12+m[2],12+m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+m[0],-6+m[1],12+m[2],12+m[3],2*this.round_radius):q==e.CARD_SHAPE?b.roundRect(-6+m[0],-6+m[1],12+m[2],12+m[3],2*this.round_radius,2):q==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=c;b.globalAlpha=1}};var C=new Float32Array(4),h=new Float32Array(4),q=new Float32Array(2),p=new Float32Array(2);k.prototype.drawConnections=function(a){var b=
|
||||
e.getTime(),d=this.visible_area;C[0]=d[0]-20;C[1]=d[1]-20;C[2]=d[2]+40;C[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,c=0,n=d.length;c<n;++c){var g=d[c];if(g.inputs&&g.inputs.length)for(var m=0;m<g.inputs.length;++m){var k=g.inputs[m];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var f=this.graph.getNodeById(k.origin_id);if(null!=f){var l=k.origin_slot,u=null,u=-1==l?[f.pos[0]+10,f.pos[1]+10]:
|
||||
f.getConnectionPos(!1,l,q),x=g.getConnectionPos(!0,m,p);h[0]=u[0];h[1]=u[1];h[2]=x[0]-u[0];h[3]=x[1]-u[1];0>h[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(v(h,C)){var A=f.outputs[l],l=g.inputs[m];if(A&&l&&(f=A.dir||(f.horizontal?e.DOWN:e.RIGHT),l=l.dir||(g.horizontal?e.UP:e.LEFT),this.renderLink(a,u,x,k,!1,0,null,f,l),k&&k._last_time&&1E3>b-k._last_time)){var A=2-0.002*(b-k._last_time),J=a.globalAlpha;a.globalAlpha=J*A;this.renderLink(a,u,x,k,!0,A,"white",f,l);
|
||||
a.globalAlpha=J}}}}}}a.globalAlpha=1};k.prototype.renderLink=function(a,b,d,c,n,h,g,m,p,q){c&&this.visible_links.push(c);!g&&c&&(g=c.color||k.link_type_colors[c.type]);g||(g=this.default_link_color);null!=c&&this.highlighted_links[c.id]&&(g="#FFF");m=m||e.RIGHT;p=p||e.LEFT;var f=y(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=0.5);a.beginPath();for(var l=0;l<q;l+=1){var A=5*(l-0.5*(q-1));if(this.links_render_mode==
|
||||
e.SPLINE_LINK){a.moveTo(b[0],b[1]+A);var u=0,x=0,v=0,r=0;switch(m){case e.LEFT:u=-0.25*f;break;case e.RIGHT:u=0.25*f;break;case e.UP:x=-0.25*f;break;case e.DOWN:x=0.25*f}switch(p){case e.LEFT:v=-0.25*f;break;case e.RIGHT:v=0.25*f;break;case e.UP:r=-0.25*f;break;case e.DOWN:r=0.25*f}a.bezierCurveTo(b[0]+u,b[1]+x+A,d[0]+v,d[1]+r+A,d[0],d[1]+A)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+A);r=v=x=u=0;switch(m){case e.LEFT:u=-1;break;case e.RIGHT:u=1;break;case e.UP:x=-1;break;case e.DOWN:x=
|
||||
1}switch(p){case e.LEFT:v=-1;break;case e.RIGHT:v=1;break;case e.UP:r=-1;break;case e.DOWN:r=1}a.lineTo(b[0]+15*u,b[1]+15*x+A);a.lineTo(d[0]+15*v,d[1]+15*r+A);a.lineTo(d[0],d[1]+A)}else if(this.links_render_mode==e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),A=b[0],u=b[1],x=d[0],v=d[1],m==e.RIGHT?A+=10:u+=10,p==e.LEFT?x-=10:v-=10,a.lineTo(A,u),a.lineTo(0.5*(A+x),u),a.lineTo(0.5*(A+x),v),a.lineTo(x,v),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!n&&(a.strokeStyle="rgba(0,0,0,0.5)",
|
||||
a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=g;a.stroke();n=this.computeConnectionPoint(b,d,0.5,m,p);c&&c._pos&&(c._pos[0]=n[0],c._pos[1]=n[1]);0.6<=this.ds.scale&&this.highquality_render&&p!=e.CENTER&&(this.render_connection_arrows&&(l=this.computeConnectionPoint(b,d,0.25,m,p),c=this.computeConnectionPoint(b,d,0.26,m,p),q=this.computeConnectionPoint(b,d,0.75,m,p),f=this.computeConnectionPoint(b,d,0.76,m,p),u=A=0,this.render_curved_connections?(A=-Math.atan2(c[0]-l[0],
|
||||
c[1]-l[1]),u=-Math.atan2(f[0]-q[0],f[1]-q[1])):u=A=d[1]>b[1]?0:Math.PI,a.save(),a.translate(l[0],l[1]),a.rotate(A),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(q[0],q[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(n[0],n[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=g,l=0;5>l;++l)h=(0.001*e.getTime()+0.2*l)%1,n=this.computeConnectionPoint(b,d,h,m,p),a.beginPath(),a.arc(n[0],
|
||||
n[1],5,0,2*Math.PI),a.fill()};k.prototype.computeConnectionPoint=function(a,b,d,c,n){c=c||e.RIGHT;n=n||e.LEFT;var h=y(a,b),g=[a[0],a[1]],m=[b[0],b[1]];switch(c){case e.LEFT:g[0]+=-0.25*h;break;case e.RIGHT:g[0]+=0.25*h;break;case e.UP:g[1]+=-0.25*h;break;case e.DOWN:g[1]+=0.25*h}switch(n){case e.LEFT:m[0]+=-0.25*h;break;case e.RIGHT:m[0]+=0.25*h;break;case e.UP:m[1]+=-0.25*h;break;case e.DOWN:m[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);n=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+n*g[0]+h*m[0]+d*b[0],
|
||||
c*a[1]+n*g[1]+h*m[1]+d*b[1]]};k.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;d<b.length;++d){var c=b[d];a.fillStyle="black";a.fillRect(c.pos[0]-e.NODE_TITLE_HEIGHT,c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);0==c.order&&a.strokeRect(c.pos[0]-e.NODE_TITLE_HEIGHT+0.5,c.pos[1]-e.NODE_TITLE_HEIGHT+0.5,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);
|
||||
a.fillStyle="#FFF";a.fillText(c.order,c.pos[0]+-0.5*e.NODE_TITLE_HEIGHT,c.pos[1]-6)}a.globalAlpha=1};k.prototype.drawNodeWidgets=function(a,b,d,c){if(!a.widgets||!a.widgets.length)return 0;var n=a.size[0],h=a.widgets;b+=2;var g=e.NODE_WIDGET_HEIGHT,m=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var k=e.WIDGET_OUTLINE_COLOR,p=e.WIDGET_BGCOLOR,q=e.WIDGET_TEXT_COLOR,f=e.WIDGET_SECONDARY_TEXT_COLOR,A=0;A<h.length;++A){var l=h[A],u=b;l.y&&(u=l.y);l.last_y=u;d.strokeStyle=k;d.fillStyle=
|
||||
"#222";d.textAlign="left";switch(l.type){case "button":l.clicked&&(d.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,u,n-30,g);d.strokeRect(15,u,n-30,g);m&&(d.textAlign="center",d.fillStyle=q,d.fillText(l.name,0.5*n,u+0.7*g));break;case "toggle":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();d.fillStyle=l.value?"#89A":"#333";d.beginPath();d.arc(n-30,u+0.5*g,0.36*g,0,2*Math.PI);d.fill();m&&(d.fillStyle=f,null!=l.name&&
|
||||
d.fillText(l.name,30,u+0.7*g),d.fillStyle=l.value?q:f,d.textAlign="right",d.fillText(l.value?l.options.on||"true":l.options.off||"false",n-40,u+0.7*g));break;case "slider":d.fillStyle=p;d.fillRect(15,u,n-30,g);var x=l.options.max-l.options.min,v=(l.value-l.options.min)/x;d.fillStyle=c==l?"#89A":"#678";d.fillRect(15,u,v*(n-30),g);d.strokeRect(15,u,n-30,g);l.marker&&(x=(l.marker-l.options.min)/x,d.fillStyle="#AA9",d.fillRect(15+x*(n-30),u,2,g));m&&(d.textAlign="center",d.fillStyle=q,d.fillText(l.name+
|
||||
" "+Number(l.value).toFixed(3),0.5*n,u+0.7*g));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();m&&(d.fillStyle=q,d.beginPath(),d.moveTo(31,b+5),d.lineTo(21,b+0.5*g),d.lineTo(31,b+g-5),d.fill(),d.beginPath(),d.moveTo(n-15-16,b+5),d.lineTo(n-15-6,b+0.5*g),d.lineTo(n-15-16,b+g-5),d.fill(),d.fillStyle=f,d.fillText(l.name,35,u+0.7*g),d.fillStyle=q,d.textAlign="right","number"==l.type?d.fillText(Number(l.value).toFixed(void 0!==
|
||||
l.options.precision?l.options.precision:3),n-30-20,u+0.7*g):d.fillText(l.value,n-30-20,u+0.7*g));break;case "string":case "text":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();m&&(d.fillStyle=f,null!=l.name&&d.fillText(l.name,30,u+0.7*g),d.fillStyle=q,d.textAlign="right",d.fillText(l.value,n-30,u+0.7*g));break;default:l.draw&&l.draw(d,a,l,u,g)}b+=g+4}d.restore();d.textAlign="left"};k.prototype.processNodeWidgets=function(a,b,d,c){function n(e,
|
||||
c){e.value=c;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,c);e.callback&&e.callback(e.value,k,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var g=b[0]-a.pos[0],h=b[1]-a.pos[1],m=a.size[0],k=this,p=this.getCanvasWindow(),q=0;q<a.widgets.length;++q){var f=a.widgets[q];if(f==c||6<g&&g<m-12&&h>f.last_y&&h<f.last_y+e.NODE_WIDGET_HEIGHT){switch(f.type){case "button":if("mousemove"===d.type)break;f.callback&&setTimeout(function(){f.callback(f,
|
||||
k,a,b)},20);this.dirty_canvas=f.clicked=!0;break;case "slider":p=Math.clamp((g-10)/(m-20),0,1);f.value=f.options.min+(f.options.max-f.options.min)*p;f.callback&&setTimeout(function(){n(f,f.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==d.type&&"number"==f.type)f.value+=0.1*d.deltaX*(f.options.step||1),null!=f.options.min&&f.value<f.options.min&&(f.value=f.options.min),null!=f.options.max&&f.value>f.options.max&&(f.value=f.options.max);else if("mousedown"==d.type)if((c=
|
||||
f.options.values)&&c.constructor===Function&&(c=f.options.values(f,a)),g=40>g?-1:g>m-40?1:0,"number"==f.type)f.value+=0.1*g*(f.options.step||1),null!=f.options.min&&f.value<f.options.min&&(f.value=f.options.min),null!=f.options.max&&f.value>f.options.max&&(f.value=f.options.max);else if(g)p=c.indexOf(f.value)+g,p>=c.length&&(p=0),0>p&&(p=c.length-1),f.value=c[p];else{new e.ContextMenu(c,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:l.bind(f)},p);var l=function(a,b,d){this.value=
|
||||
a;n(this,a);k.dirty_canvas=!0;return!1}}setTimeout(function(){n(this,this.value)}.bind(f),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(f.value=!f.value,f.callback&&setTimeout(function(){n(f,f.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",f.value,function(a){this.value=a;n(this,a)}.bind(f),d);break;default:f.mouse&&f.mouse(ctx,d,[g,h],a)}return f}}return null};k.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;
|
||||
b.save();b.globalAlpha=0.5*this.editor_alpha;for(var c=0;c<d.length;++c){var g=d[c];if(v(this.visible_area,g._bounding)){b.fillStyle=g.color||"#335";b.strokeStyle=g.color||"#335";var h=g._pos,m=g._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(h[0]+0.5,h[1]+0.5,m[0],m[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(h[0]+m[0],h[1]+m[1]);b.lineTo(h[0]+m[0]-10,h[1]+m[1]);b.lineTo(h[0]+m[0],h[1]+m[1]-10);b.fill();m=g.font_size||e.DEFAULT_GROUP_FONT_SIZE;
|
||||
b.font=m+"px Arial";b.fillText(g.title,h[0]+4,h[1]+m)}}b.restore()}};k.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};k.prototype.resize=function(a,b){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};k.prototype.switchLiveMode=
|
||||
function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var e=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1<d&&0.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.onNodeSelectionChange=function(a){};k.prototype.touchHandler=function(a){var b=a.changedTouches[0],
|
||||
d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var e=this.getCanvasWindow(),c=e.document.createEvent("MouseEvent");c.initMouseEvent(d,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(c);a.preventDefault()};k.onGroupAdd=function(a,b,d){a=k.active_canvas;a.getCanvasWindow();b=new e.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};k.onMenuAdd=function(a,
|
||||
b,d,c){function g(a,b){var d=c.getFirstEvent(),n=e.createNode(a.value);n&&(n.pos=h.convertEventToCanvasOffset(d),h.graph.add(n))}var h=k.active_canvas,m=h.getCanvasWindow();a=e.getNodeTypesCategories(h.filter);b=[];for(var f in a)a[f]&&b.push({value:a[f],content:a[f],has_submenu:!0});var p=new e.ContextMenu(b,{event:d,callback:function(a,b,d){a=e.getNodeTypesInCategory(a.value,h.filter);b=[];for(var c in a)a[c].skip_list||b.push({content:a[c].title,value:a[c].type});new e.ContextMenu(b,{event:d,callback:g,
|
||||
parentMenu:p},m);return!1},parentMenu:c},m);return!1};k.onMenuCollapseAll=function(){};k.onMenuNodeEdit=function(){};k.showMenuNodeOptionalInputs=function(a,b,d,c,g){function h(a,b,d){g&&(a.callback&&a.callback.call(m,g,a,b,d),a.value&&(g.addInput(a.value[0],a.value[1],a.value[2]),g.setDirtyCanvas(!0,!0)))}if(g){var m=this;a=k.active_canvas.getCanvasWindow();b=g.optional_inputs;g.onGetInputs&&(b=g.onGetInputs());var f=[];if(b)for(var p in b){var q=b[p];if(q){var l=q[0];q[2]&&q[2].label&&(l=q[2].label);
|
||||
l={content:l,value:q};q[1]==e.ACTION&&(l.className="event");f.push(l)}else f.push(null)}this.onMenuNodeInputs&&(f=this.onMenuNodeInputs(f));if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,node:g},a),!1}};k.showMenuNodeOptionalOutputs=function(a,b,d,c,g){function h(a,b,d){if(g&&(a.callback&&a.callback.call(m,g,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)g.addOutput(a.value[0],a.value[1],a.value[2]),g.setDirtyCanvas(!0,!0);else{a=[];for(var f in d)a.push({content:f,
|
||||
value:d[f]});new e.ContextMenu(a,{event:b,callback:h,parentMenu:c,node:g});return!1}}if(g){var m=this;a=k.active_canvas.getCanvasWindow();b=g.optional_outputs;g.onGetOutputs&&(b=g.onGetOutputs());var f=[];if(b)for(var p in b){var q=b[p];if(!q)f.push(null);else if(!g.flags||!g.flags.skip_repeated_outputs||-1==g.findOutputSlot(q[0])){var l=q[0];q[2]&&q[2].label&&(l=q[2].label);l={content:l,value:q};q[1]==e.EVENT&&(l.className="event");f.push(l)}}this.onMenuNodeOutputs&&(f=this.onMenuNodeOutputs(f));
|
||||
if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,node:g},a),!1}};k.onShowMenuNodeProperties=function(a,b,d,c,g){function h(a,b,d,e){g&&(b=this.getBoundingClientRect(),m.showEditPropertyValue(g,a.value,{position:[b.left,b.top]}))}if(g&&g.properties){var m=k.active_canvas;b=m.getCanvasWindow();var f=[],q;for(q in g.properties)a=void 0!==g.properties[q]?g.properties[q]:" ","object"==typeof a&&(a=JSON.stringify(a)),a=k.decodeHTML(a),f.push({content:"<span class='property_name'>"+
|
||||
q+"</span><span class='property_value'>"+a+"</span>",value:q});if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,allow_html:!0,node:g},b),!1}};k.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};k.onResizeNode=function(a,b,d,e,c){c&&(c.size=c.computeSize(),c.setDirtyCanvas(!0,!0))};k.prototype.showLinkMenu=function(a,b){var d=this;console.log(a.data);new e.ContextMenu(["Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,
|
||||
callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};k.onShowPropertyEditor=function(a,b,d,e,c){function g(){var b=f.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));c[h]=b;m.parentNode&&m.parentNode.removeChild(m);c.setDirtyCanvas(!0,!0)}var h=a.property||"title";b=c[h];var m=document.createElement("div");m.className="graphdialog";m.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";m.querySelector(".name").innerText=
|
||||
h;var f=m.querySelector("input");f&&(f.value=b,f.addEventListener("blur",function(a){this.focus()}),f.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));b=k.active_canvas.canvas;d=b.getBoundingClientRect();var q=e=-20;d&&(e-=d.left,q-=d.top);event?(m.style.left=event.clientX+e+"px",m.style.top=event.clientY+q+"px"):(m.style.left=0.5*b.width+e+"px",m.style.top=0.5*b.height+q+"px");m.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(m)};
|
||||
k.prototype.prompt=function(a,b,d,e){var c=this;a=a||"";var g=!1,h=document.createElement("div");h.className="graphdialog rounded";h.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";h.close=function(){c.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseleave",function(a){g||h.close()});c.prompt_box&&c.prompt_box.close();c.prompt_box=
|
||||
h;h.querySelector(".name").innerText=a;h.querySelector(".value").value=b;var m=h.querySelector("input");m.addEventListener("keydown",function(a){g=!0;if(27==a.keyCode)h.close();else if(13==a.keyCode)d&&d(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){d&&d(m.value);c.setDirty(!0);h.close()});a=k.active_canvas.canvas;b=a.getBoundingClientRect();var f=-20,q=-20;b&&(f-=b.left,q-=b.top);e?(h.style.left=e.clientX+
|
||||
f+"px",h.style.top=e.clientY+q+"px"):(h.style.left=0.5*a.width+f+"px",h.style.top=0.5*a.height+q+"px");a.parentNode.appendChild(h);setTimeout(function(){m.focus()},10);return h};k.search_limit=-1;k.prototype.showSearchBox=function(a){function b(b){if(b)if(g.onSearchBoxSelection)g.onSearchBoxSelection(b,a,A);else{var d=e.searchbox_extras[b.toLowerCase()];d&&(b=d.type);if(b=e.createNode(b))b.pos=A.convertEventToCanvasOffset(a),A.graph.add(b);if(d&&d.data){if(d.data.properties)for(var c in d.data.properties)b.addProperty(c,
|
||||
d.data.properties[c]);if(d.data.inputs)for(c in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[c][0],d.data.inputs[c][1]);if(d.data.outputs)for(c in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[c][0],d.data.outputs[c][1]);d.data.title&&(b.title=d.data.title);d.data.json&&b.configure(d.data.json)}}h.close()}function d(a){var b=l;l&&l.classList.remove("selected");l?(l=a?l.nextSibling:l.previousSibling)||(l=b):l=a?f.childNodes[0]:f.childNodes[f.childNodes.length];l&&(l.classList.add("selected"),
|
||||
l.scrollIntoView())}function c(){function a(d,e){var c=document.createElement("div");q||(q=d);c.innerText=d;c.dataset.type=escape(d);c.className="litegraph lite-search-item";e&&(c.className+=" "+e);c.addEventListener("click",function(a){b(unescape(this.dataset.type))});f.appendChild(c)}p=null;var d=u.value;q=null;f.innerHTML="";if(d)if(g.onSearchBox){var h=g.onSearchBox(f,d,A);if(h)for(var m=0;m<h.length;++m)a(h[m])}else{var h=0,d=d.toLowerCase(),l=A.filter||A.graph.filter;for(m in e.searchbox_extras){var t=
|
||||
e.searchbox_extras[m];if(-1!==t.desc.toLowerCase().indexOf(d)){var x=e.registered_node_types[t.type];if(!x||!x.filter||x.filter==l)if(a(t.desc,"searchbox_extra"),-1!==k.search_limit&&h++>k.search_limit)break}}t=null;if(Array.prototype.filter)t=Object.keys(e.registered_node_types).filter(v);else for(m in t=[],e.registered_node_types)v(m)&&t.push(m);for(m=0;m<t.length&&!(a(t[m]),-1!==k.search_limit&&h++>k.search_limit);m++);var v=function(a){var b=e.registered_node_types[a];return l&&b.filter!=l?!1:
|
||||
-1!==a.toLowerCase().indexOf(d)}}}var g=this,h=document.createElement("div");h.className="litegraph litesearchbox graphdialog rounded";h.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";h.close=function(){g.search_box=null;document.body.focus();setTimeout(function(){g.canvas.focus()},20);h.parentNode&&h.parentNode.removeChild(h)};var m=null;1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseenter",
|
||||
function(a){m&&(clearTimeout(m),m=null)});h.addEventListener("mouseleave",function(a){m=setTimeout(function(){h.close()},500)});g.search_box&&g.search_box.close();g.search_box=h;var f=h.querySelector(".helper"),q=null,p=null,l=null,u=h.querySelector("input");u&&(u.addEventListener("blur",function(a){this.focus()}),u.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)h.close();else if(13==a.keyCode)l?b(l.innerHTML):q?b(q):h.close();else{p&&
|
||||
clearInterval(p);p=setTimeout(c,10);return}a.preventDefault();a.stopPropagation()}));var A=k.active_canvas,x=A.canvas,v=x.ownerDocument||document;v.fullscreenElement?v.fullscreenElement.appendChild(h):v.body.appendChild(h);x=x.getBoundingClientRect();v=(a?a.clientY:x.top+0.5*x.height)-20;h.style.left=(a?a.clientX:x.left+0.5*x.width)-80+"px";h.style.top=v+"px";u.focus();return h};k.prototype.showEditPropertyValue=function(a,b,d){function e(){c(p.value)}function c(d){"number"==typeof a.properties[b]&&
|
||||
(d=Number(d));if("array"==g||"object"==g)d=JSON.parse(d);a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);k.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var g="string";null!==a.properties[b]&&(g=typeof a.properties[b]);var h=null;a.getPropertyInfo&&(h=a.getPropertyInfo(b));if(a.properties_info)for(var m=0;m<a.properties_info.length;++m)if(a.properties_info[m].name==b){h=a.properties_info[m];break}void 0!==h&&null!==h&&h.type&&
|
||||
(g=h.type);var f="";if("string"==g||"number"==g||"array"==g||"object"==g)f="<input autofocus type='text' class='value'/>";else if("enum"==g&&h.values){f="<select autofocus type='text' class='value'>";for(m in h.values)var q=h.values.constructor===Array?h.values[m]:m,f=f+("<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+h.values[m]+"</option>");f+="</select>"}else if("boolean"==g)f="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+
|
||||
g);return}var k=this.createDialog("<span class='name'>"+b+"</span>"+f+"<button>OK</button>",d);if("enum"==g&&h.values){var p=k.querySelector("select");p.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==g)(p=k.querySelector("input"))&&p.addEventListener("click",function(a){c(!!p.checked)});else if(p=k.querySelector("input"))p.addEventListener("blur",function(a){this.focus()}),q=void 0!==a.properties[b]?a.properties[b]:"",q=JSON.stringify(q),p.value=q,p.addEventListener("keydown",
|
||||
function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});k.querySelector("button").addEventListener("click",e)}};k.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),c=-20,g=-20;e&&(c-=e.left,g-=e.top);b.position?(c+=b.position[0],g+=b.position[1]):b.event?(c+=b.event.clientX,g+=b.event.clientY):(c+=0.5*this.canvas.width,g+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=
|
||||
g+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};k.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};k.onMenuNodePin=function(a,b,d,e,c){c.pin()};k.onMenuNodeMode=function(a,b,d,c,g){new e.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(g)switch(a){case "On Event":g.mode=e.ON_EVENT;break;case "On Trigger":g.mode=e.ON_TRIGGER;break;case "Never":g.mode=e.NEVER;break;default:g.mode=
|
||||
e.ALWAYS}},parentMenu:c,node:g});return!1};k.onMenuNodeColors=function(a,b,d,c,g){if(!g)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var h in k.node_colors)a=k.node_colors[h],a={value:h,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+h+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){g&&((a=a.value?k.node_colors[a.value]:
|
||||
null)?g.constructor===e.LGraphGroup?g.color=a.groupcolor:(g.color=a.color,g.bgcolor=a.bgcolor):(delete g.color,delete g.bgcolor),g.setDirtyCanvas(!0,!0))},parentMenu:c,node:g});return!1};k.onMenuNodeShapes=function(a,b,d,c,g){if(!g)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){g&&(g.shape=a,g.setDirtyCanvas(!0))},parentMenu:c,node:g});return!1};k.onMenuNodeRemove=function(a,b,d,e,c){if(!c)throw"no node passed";!1!==c.removable&&(c.graph.remove(c),c.setDirtyCanvas(!0,
|
||||
!0))};k.onMenuNodeClone=function(a,b,d,c,e){!1!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.add(a),e.setDirtyCanvas(!0,!0))};k.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},
|
||||
purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};k.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:k.onMenuAdd},{content:"Add Group",callback:k.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));
|
||||
if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};k.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:k.onShowMenuNodeProperties},null,{content:"Title",callback:k.onShowPropertyEditor},{content:"Mode",
|
||||
has_submenu:!0,callback:k.onMenuNodeMode},{content:"Resize",callback:k.onResizeNode},{content:"Collapse",callback:k.onMenuNodeCollapse},{content:"Pin",callback:k.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:k.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this))&&
|
||||
(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:k.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:k.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};k.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:k.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:k.onShowPropertyEditor},
|
||||
null,{content:"Remove",callback:k.onMenuNodeRemove}]};k.prototype.processContextMenu=function(a,b){var d=this,c=k.active_canvas.getCanvasWindow(),g=null,h={event:b,callback:function(b,e,c){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var g=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),
|
||||
h=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",e),m=h.querySelector("input");m&&g&&(m.value=g.label||"");h.querySelector("button").addEventListener("click",function(a){m.value&&(g&&(g.label=m.value),d.setDirty(!0));h.close()})}},extra:a};a&&(h.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),k.active_node=a);if(m){g=[];m&&m.output&&m.output.links&&m.output.links.length&&g.push({content:"Disconnect Links",slot:m});var f=m.input||
|
||||
m.output;g.push(f.locked?"Cannot remove":{content:"Remove Slot",slot:m});g.push(f.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m});h.title=(m.input?m.input.type:m.output.type)||"*";m.input&&m.input.type==e.ACTION&&(h.title="Action");m.output&&m.output.type==e.EVENT&&(h.title="Event")}else a?g=this.getNodeMenuOptions(a):(g=this.getCanvasMenuOptions(),(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&g.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));
|
||||
g&&new e.ContextMenu(g,h,c)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,e,c,g){void 0===c&&(c=5);void 0===g&&(g=c);this.moveTo(a+c,b);this.lineTo(a+d-c,b);this.quadraticCurveTo(a+d,b,a+d,b+c);this.lineTo(a+d,b+e-g);this.quadraticCurveTo(a+d,b+e,a+d-g,b+e);this.lineTo(a+g,b+e);this.quadraticCurveTo(a,b+e,a,b+e-g);this.lineTo(a,b+c);this.quadraticCurveTo(a,b,a+c,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=
|
||||
y;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=u;e.growBounding=function(a,b,d){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);d<a[1]?a[1]=d:d>a[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};e.overlapBounding=v;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();
|
||||
for(var b=Array(3),d=0,e,c,g=0;6>g;g+=2)e="0123456789ABCDEF".indexOf(a.charAt(g)),c="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[d]=16*e+c,d++;return b};e.num2hex=function(a){for(var b="#",d,e,c=0;3>c;c++)d=a[c]/16,e=a[c]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(e);return b};z.prototype.addItem=function(a,b,d){function e(a){var b=this.value;b&&b.has_submenu&&c.call(this,a)}function c(a){var b=this.value,e=!0;g.current_submenu&&g.current_submenu.close(a);if(d.callback){var h=d.callback.call(this,
|
||||
b,d,a,g,d.node);!0===h&&(e=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(h=b.callback.call(this,b,d,a,g,d.extra),!0===h&&(e=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});e=!1}e&&!g.lock&&g.close()}var g=this;d=d||{};var h=document.createElement("div");
|
||||
h.className="litemenu-entry submenu";var m=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(m=!0,h.classList.add("disabled")),(b.submenu||b.has_submenu)&&h.classList.add("has_submenu");"function"==typeof b?(h.dataset.value=a,h.onclick_callback=b):h.dataset.value=b;b.className&&(h.className+=" "+b.className)}this.root.appendChild(h);m||h.addEventListener("click",c);d.autoopen&&h.addEventListener("mouseenter",e);return h};z.prototype.close=
|
||||
function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};z.trigger=function(a,b,d,e){var c=document.createEvent("CustomEvent");c.initCustomEvent(b,
|
||||
!0,!0,d);c.srcElement=e;a.dispatchEvent?a.dispatchEvent(c):a.__events&&a.__events.dispatchEvent(c);return c};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,b){var d=a.clientX,e=a.clientY,c=b.getBoundingClientRect();return c?e>c.top&&e<c.top+c.height&&d>c.left&&d<c.left+c.width?!0:
|
||||
!1:!1};e.ContextMenu=z;e.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};e.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,
|
||||
b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=
|
||||
window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
if(d=e.node_types_by_file_extension[d])if(d=e.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};k.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};k.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};k.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],
|
||||
b)};k.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var e=a[d];if(!e.is_selected){if(!e.is_selected&&e.onSelected)e.onSelected();e.is_selected=!0;this.selected_nodes[e.id]=e;if(e.inputs)for(var c=0;c<e.inputs.length;++c)this.highlighted_links[e.inputs[c].link]=!0;if(e.outputs)for(c=0;c<e.outputs.length;++c){var h=e.outputs[c];if(h.links)for(var g=0;g<h.links.length;++g)this.highlighted_links[h.links[g]]=!0}}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);
|
||||
this.setDirty(!0)};k.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var d=a.outputs[b];if(d.links)for(var e=0;e<d.links.length;++e)delete this.highlighted_links[d.links[e]]}}};k.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,
|
||||
b=0,d=a.length;b<d;++b){var e=a[b];if(e.is_selected){if(e.onDeselected)e.onDeselected();e.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(e)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};k.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.current_node=null;this.highlighted_links=
|
||||
{};this.setDirty(!0)};k.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};k.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];
|
||||
this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};k.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};k.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};k.prototype.convertEventToCanvasOffset=function(a){var b=
|
||||
this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};k.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};k.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var x=new Float32Array(4);k.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;
|
||||
for(var e=0,c=a.length;e<c;++e){var h=a[e];(!this.live_mode||h.onDrawBackground||h.onDrawForeground)&&v(this.visible_area,h.getBounding(x))&&d.push(h)}return d};k.prototype.draw=function(a,b){if(this.canvas){var d=e.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea();(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||
|
||||
a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};k.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==
|
||||
this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=
|
||||
this.connections_width;b=null;switch(this.connecting_output.type){case e.EVENT:b=e.EVENT_LINK_COLOR;break;default:b=e.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?e.DOWN:e.RIGHT),e.CENTER);a.beginPath();this.connecting_output.type===e.EVENT||this.connecting_output.shape===e.BOX_SHAPE?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],
|
||||
this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,
|
||||
null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};k.prototype.renderInfo=function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),
|
||||
a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};k.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();
|
||||
var d=this.graph._subgraph_node;b.strokeStyle=d.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=d.bgcolor||"#AAA";for(var e="",c=1;c<this._graph_stack.length;++c)e+=this._graph_stack[c]._subgraph_node.getTitle()+" >> ";b.fillText(e+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();
|
||||
this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!d){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var h=this;this._bg_img.onload=function(){h.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?
|
||||
(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),
|
||||
this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var g=new Float32Array(2);k.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||
|
||||
e.NODE_DEFAULT_COLOR,c=a.bgcolor||a.constructor.bgcolor||e.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var n=this.editor_alpha;b.globalAlpha=n;this.render_shadows?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,
|
||||
this)){var h=a._shape||e.BOX_SHAPE;g.set(a.size);var m=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var k=a.getTitle?a.getTitle():a.title;null!=k&&(a._collapsed_width=Math.min(a.size[0],b.measureText(k).width+2*e.NODE_TITLE_HEIGHT),g[0]=a._collapsed_width,g[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==e.BOX_SHAPE?b.rect(0,0,g[0],g[1]):h==e.ROUND_SHAPE?b.roundRect(0,0,g[0],g[1],10):h==e.CIRCLE_SHAPE&&b.arc(0.5*g[0],0.5*g[1],0.5*g[0],0,2*Math.PI),b.clip());a.has_errors&&(c="red");
|
||||
this.drawNodeShape(a,b,g,d,c,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=m?"center":"left";b.font=this.inner_text_font;c=0.6<this.ds.scale;h=this.connecting_output;b.lineWidth=1;var k=0,q=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;d<a.inputs.length;d++){var p=a.inputs[d];b.globalAlpha=n;this.connecting_node&&!e.isValidConnection(p.type,h.type)&&(b.globalAlpha=0.4*n);b.fillStyle=null!=p.link?p.color_on||
|
||||
this.default_connection_color.input_on:p.color_off||this.default_connection_color.input_off;var f=a.getConnectionPos(!0,d,q);f[0]-=a.pos[0];f[1]-=a.pos[1];k<f[1]+0.5*e.NODE_SLOT_HEIGHT&&(k=f[1]+0.5*e.NODE_SLOT_HEIGHT);b.beginPath();p.type===e.EVENT||p.shape===e.BOX_SHAPE?m?b.rect(f[0]-5+0.5,f[1]-8+0.5,10,14):b.rect(f[0]-6+0.5,f[1]-5+0.5,14,10):p.shape===e.ARROW_SHAPE?(b.moveTo(f[0]+8,f[1]+0.5),b.lineTo(f[0]-4,f[1]+6+0.5),b.lineTo(f[0]-4,f[1]-6+0.5),b.closePath()):b.arc(f[0],f[1],4,0,2*Math.PI);b.fill();
|
||||
if(c){var l=null!=p.label?p.label:p.name;l&&(b.fillStyle=e.NODE_TEXT_COLOR,m||p.dir==e.UP?b.fillText(l,f[0],f[1]-10):b.fillText(l,f[0]+10,f[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*n);b.textAlign=m?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(p=a.outputs[d],f=a.getConnectionPos(!1,d,q),f[0]-=a.pos[0],f[1]-=a.pos[1],k<f[1]+0.5*e.NODE_SLOT_HEIGHT&&(k=f[1]+0.5*e.NODE_SLOT_HEIGHT),b.fillStyle=p.links&&p.links.length?p.color_on||this.default_connection_color.output_on:
|
||||
p.color_off||this.default_connection_color.output_off,b.beginPath(),p.type===e.EVENT||p.shape===e.BOX_SHAPE?m?b.rect(f[0]-5+0.5,f[1]-8+0.5,10,14):b.rect(f[0]-6+0.5,f[1]-5+0.5,14,10):p.shape===e.ARROW_SHAPE?(b.moveTo(f[0]+8,f[1]+0.5),b.lineTo(f[0]-4,f[1]+6+0.5),b.lineTo(f[0]-4,f[1]-6+0.5),b.closePath()):b.arc(f[0],f[1],4,0,2*Math.PI),b.fill(),b.stroke(),c&&(l=null!=p.label?p.label:p.name))b.fillStyle=e.NODE_TEXT_COLOR,m||p.dir==e.DOWN?b.fillText(l,f[0],f[1]-8):b.fillText(l,f[0]-10,f[1]+5);b.textAlign=
|
||||
"left";b.globalAlpha=1;if(a.widgets){if(m||a.widgets_up)k=2;this.drawNodeWidgets(a,k,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){n=c=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(p=a.inputs[d],null!=p.link){c=p;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)p=a.outputs[d],p.links&&p.links.length&&(n=p);c&&(d=0,c=-0.5*e.NODE_TITLE_HEIGHT,m&&(d=0.5*a._collapsed_width,c=-e.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),p.type===
|
||||
e.EVENT||p.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):p.shape===e.ARROW_SHAPE?(b.moveTo(d+8,c),b.lineTo(d+-4,c-4),b.lineTo(d+-4,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill());n&&(d=a._collapsed_width,c=-0.5*e.NODE_TITLE_HEIGHT,m&&(d=0.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),p.type===e.EVENT||p.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):p.shape===e.ARROW_SHAPE?(b.moveTo(d+6,c),b.lineTo(d-6,c-4),b.lineTo(d-6,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),
|
||||
b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};k.prototype.drawLinkTooltip=function(a,b){var d=b._pos;a.fillStyle="black";a.beginPath();a.arc(d[0],d[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||!0!=this.onDrawLinkTooltip(a,b,this))){var e=b.data,c=null,c=e.constructor===Number?e.toFixed(2):e.constructor===String?'"'+e+'"':e.constructor===Boolean?String(e):e.toToolTip?e.toToolTip():"["+e.constructor.name+"]";null!=c&&(a.font="14px Courier New",e=a.measureText(c).width+
|
||||
20,a.shadowColor="black",a.shadowOffsetX=2,a.shadowOffsetY=2,a.shadowBlur=3,a.fillStyle="#454",a.beginPath(),a.roundRect(d[0]-0.5*e,d[1]-15-24,e,24,3,3),a.moveTo(d[0]-10,d[1]-15),a.lineTo(d[0]+10,d[1]-15),a.lineTo(d[0],d[1]-5),a.fill(),a.shadowColor="transparent",a.textAlign="center",a.fillStyle="#CEC",a.fillText(c,d[0],d[1]-15-24*0.3))}};var m=new Float32Array(4);k.prototype.drawNodeShape=function(a,b,d,c,n,h,g){b.strokeStyle=c;b.fillStyle=n;n=e.NODE_TITLE_HEIGHT;var p=0.5>this.ds.scale,q=a._shape||
|
||||
a.constructor.shape||e.ROUND_SHAPE,f=a.constructor.title_mode,l=!0;f==e.TRANSPARENT_TITLE?l=!1:f==e.AUTOHIDE_TITLE&&g&&(l=!0);m[0]=0;m[1]=l?-n:0;m[2]=d[0]+1;m[3]=l?d[1]+n:d[1];g=b.globalAlpha;b.beginPath();q==e.BOX_SHAPE||p?b.fillRect(m[0],m[1],m[2],m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE?b.roundRect(m[0],m[1],m[2],m[3],this.round_radius,q==e.CARD_SHAPE?0:this.round_radius):q==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle=
|
||||
"rgba(0,0,0,0.2)",b.fillRect(0,-1,m[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(l||f==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,n,d,this.ds.scale,c);else if(f!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){l=a.constructor.title_color||c;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var u=k.gradients[l];u||(u=k.gradients[l]=b.createLinearGradient(0,0,400,0),u.addColorStop(0,
|
||||
l),u.addColorStop(1,"#000"));b.fillStyle=u}else b.fillStyle=l;b.beginPath();q==e.BOX_SHAPE||p?b.rect(0,-n,d[0]+1,n):q!=e.ROUND_SHAPE&&q!=e.CARD_SHAPE||b.roundRect(0,-n,d[0]+1,n,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,n,d,this.ds.scale);else q==e.ROUND_SHAPE||q==e.CIRCLE_SHAPE||q==e.CARD_SHAPE?(p&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*n,-0.5*n,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,
|
||||
b.beginPath(),b.arc(0.5*n,-0.5*n,5,0,2*Math.PI),b.fill()):(p&&(b.fillStyle="black",b.fillRect(0.5*(n-10)-1,-0.5*(n+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(n-10),-0.5*(n+10),10,10));b.globalAlpha=g;if(a.onDrawTitleText)a.onDrawTitleText(b,n,d,this.ds.scale,this.title_text_font,h);!p&&(b.font=this.title_text_font,p=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",g=b.measureText(p),
|
||||
b.fillText(p,n+0.5*g.width,e.NODE_TITLE_TEXT_Y-n),b.textAlign="left"):(b.textAlign="left",b.fillText(p,n,e.NODE_TITLE_TEXT_Y-n)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(m);f==e.TRANSPARENT_TITLE&&(m[1]-=n,m[3]+=n);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();q==e.BOX_SHAPE?b.rect(-6+m[0],-6+m[1],12+m[2],12+m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+m[0],-6+m[1],12+m[2],12+m[3],2*this.round_radius):q==e.CARD_SHAPE?b.roundRect(-6+m[0],-6+
|
||||
m[1],12+m[2],12+m[3],2*this.round_radius,2):q==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=c;b.globalAlpha=1}};var C=new Float32Array(4),h=new Float32Array(4),q=new Float32Array(2),p=new Float32Array(2);k.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;C[0]=d[0]-20;C[1]=d[1]-20;C[2]=d[2]+40;C[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;
|
||||
for(var d=this.graph._nodes,c=0,n=d.length;c<n;++c){var g=d[c];if(g.inputs&&g.inputs.length)for(var m=0;m<g.inputs.length;++m){var k=g.inputs[m];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var f=this.graph.getNodeById(k.origin_id);if(null!=f){var l=k.origin_slot,u=null,u=-1==l?[f.pos[0]+10,f.pos[1]+10]:f.getConnectionPos(!1,l,q),x=g.getConnectionPos(!0,m,p);h[0]=u[0];h[1]=u[1];h[2]=x[0]-u[0];h[3]=x[1]-u[1];0>h[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(v(h,
|
||||
C)){var A=f.outputs[l],l=g.inputs[m];if(A&&l&&(f=A.dir||(f.horizontal?e.DOWN:e.RIGHT),l=l.dir||(g.horizontal?e.UP:e.LEFT),this.renderLink(a,u,x,k,!1,0,null,f,l),k&&k._last_time&&1E3>b-k._last_time)){var A=2-0.002*(b-k._last_time),J=a.globalAlpha;a.globalAlpha=J*A;this.renderLink(a,u,x,k,!0,A,"white",f,l);a.globalAlpha=J}}}}}}a.globalAlpha=1};k.prototype.renderLink=function(a,b,d,c,n,h,g,m,p,q){c&&this.visible_links.push(c);!g&&c&&(g=c.color||k.link_type_colors[c.type]);g||(g=this.default_link_color);
|
||||
null!=c&&this.highlighted_links[c.id]&&(g="#FFF");m=m||e.RIGHT;p=p||e.LEFT;var f=y(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=0.5);a.beginPath();for(var l=0;l<q;l+=1){var A=5*(l-0.5*(q-1));if(this.links_render_mode==e.SPLINE_LINK){a.moveTo(b[0],b[1]+A);var u=0,x=0,v=0,r=0;switch(m){case e.LEFT:u=-0.25*f;break;case e.RIGHT:u=0.25*f;break;case e.UP:x=-0.25*f;break;case e.DOWN:x=0.25*f}switch(p){case e.LEFT:v=
|
||||
-0.25*f;break;case e.RIGHT:v=0.25*f;break;case e.UP:r=-0.25*f;break;case e.DOWN:r=0.25*f}a.bezierCurveTo(b[0]+u,b[1]+x+A,d[0]+v,d[1]+r+A,d[0],d[1]+A)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+A);r=v=x=u=0;switch(m){case e.LEFT:u=-1;break;case e.RIGHT:u=1;break;case e.UP:x=-1;break;case e.DOWN:x=1}switch(p){case e.LEFT:v=-1;break;case e.RIGHT:v=1;break;case e.UP:r=-1;break;case e.DOWN:r=1}a.lineTo(b[0]+15*u,b[1]+15*x+A);a.lineTo(d[0]+15*v,d[1]+15*r+A);a.lineTo(d[0],d[1]+A)}else if(this.links_render_mode==
|
||||
e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),A=b[0],u=b[1],x=d[0],v=d[1],m==e.RIGHT?A+=10:u+=10,p==e.LEFT?x-=10:v-=10,a.lineTo(A,u),a.lineTo(0.5*(A+x),u),a.lineTo(0.5*(A+x),v),a.lineTo(x,v),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!n&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=g;a.stroke();n=this.computeConnectionPoint(b,d,0.5,m,p);c&&c._pos&&(c._pos[0]=n[0],c._pos[1]=n[1]);0.6<=this.ds.scale&&this.highquality_render&&
|
||||
p!=e.CENTER&&(this.render_connection_arrows&&(l=this.computeConnectionPoint(b,d,0.25,m,p),c=this.computeConnectionPoint(b,d,0.26,m,p),q=this.computeConnectionPoint(b,d,0.75,m,p),f=this.computeConnectionPoint(b,d,0.76,m,p),u=A=0,this.render_curved_connections?(A=-Math.atan2(c[0]-l[0],c[1]-l[1]),u=-Math.atan2(f[0]-q[0],f[1]-q[1])):u=A=d[1]>b[1]?0:Math.PI,a.save(),a.translate(l[0],l[1]),a.rotate(A),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(q[0],
|
||||
q[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(n[0],n[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=g,l=0;5>l;++l)h=(0.001*e.getTime()+0.2*l)%1,n=this.computeConnectionPoint(b,d,h,m,p),a.beginPath(),a.arc(n[0],n[1],5,0,2*Math.PI),a.fill()};k.prototype.computeConnectionPoint=function(a,b,d,c,n){c=c||e.RIGHT;n=n||e.LEFT;var h=y(a,b),g=[a[0],a[1]],m=[b[0],b[1]];switch(c){case e.LEFT:g[0]+=-0.25*h;break;case e.RIGHT:g[0]+=0.25*
|
||||
h;break;case e.UP:g[1]+=-0.25*h;break;case e.DOWN:g[1]+=0.25*h}switch(n){case e.LEFT:m[0]+=-0.25*h;break;case e.RIGHT:m[0]+=0.25*h;break;case e.UP:m[1]+=-0.25*h;break;case e.DOWN:m[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);n=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+n*g[0]+h*m[0]+d*b[0],c*a[1]+n*g[1]+h*m[1]+d*b[1]]};k.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;d<
|
||||
b.length;++d){var c=b[d];a.fillStyle="black";a.fillRect(c.pos[0]-e.NODE_TITLE_HEIGHT,c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);0==c.order&&a.strokeRect(c.pos[0]-e.NODE_TITLE_HEIGHT+0.5,c.pos[1]-e.NODE_TITLE_HEIGHT+0.5,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(c.order,c.pos[0]+-0.5*e.NODE_TITLE_HEIGHT,c.pos[1]-6)}a.globalAlpha=1};k.prototype.drawNodeWidgets=function(a,b,d,c){if(!a.widgets||!a.widgets.length)return 0;var n=a.size[0],h=a.widgets;
|
||||
b+=2;var g=e.NODE_WIDGET_HEIGHT,m=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var k=e.WIDGET_OUTLINE_COLOR,p=e.WIDGET_BGCOLOR,q=e.WIDGET_TEXT_COLOR,f=e.WIDGET_SECONDARY_TEXT_COLOR,A=0;A<h.length;++A){var l=h[A],u=b;l.y&&(u=l.y);l.last_y=u;d.strokeStyle=k;d.fillStyle="#222";d.textAlign="left";switch(l.type){case "button":l.clicked&&(d.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,u,n-30,g);d.strokeRect(15,u,n-30,g);m&&(d.textAlign="center",d.fillStyle=q,d.fillText(l.name,
|
||||
0.5*n,u+0.7*g));break;case "toggle":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();d.fillStyle=l.value?"#89A":"#333";d.beginPath();d.arc(n-30,u+0.5*g,0.36*g,0,2*Math.PI);d.fill();m&&(d.fillStyle=f,null!=l.name&&d.fillText(l.name,30,u+0.7*g),d.fillStyle=l.value?q:f,d.textAlign="right",d.fillText(l.value?l.options.on||"true":l.options.off||"false",n-40,u+0.7*g));break;case "slider":d.fillStyle=p;d.fillRect(15,u,n-30,g);var x=l.options.max-
|
||||
l.options.min,v=(l.value-l.options.min)/x;d.fillStyle=c==l?"#89A":"#678";d.fillRect(15,u,v*(n-30),g);d.strokeRect(15,u,n-30,g);l.marker&&(x=(l.marker-l.options.min)/x,d.fillStyle="#AA9",d.fillRect(15+x*(n-30),u,2,g));m&&(d.textAlign="center",d.fillStyle=q,d.fillText(l.name+" "+Number(l.value).toFixed(3),0.5*n,u+0.7*g));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();m&&(d.fillStyle=q,d.beginPath(),
|
||||
d.moveTo(31,b+5),d.lineTo(21,b+0.5*g),d.lineTo(31,b+g-5),d.fill(),d.beginPath(),d.moveTo(n-15-16,b+5),d.lineTo(n-15-6,b+0.5*g),d.lineTo(n-15-16,b+g-5),d.fill(),d.fillStyle=f,d.fillText(l.name,35,u+0.7*g),d.fillStyle=q,d.textAlign="right","number"==l.type?d.fillText(Number(l.value).toFixed(void 0!==l.options.precision?l.options.precision:3),n-30-20,u+0.7*g):d.fillText(l.value,n-30-20,u+0.7*g));break;case "string":case "text":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,
|
||||
b,n-30,g,0.5*g);d.fill();d.stroke();m&&(d.fillStyle=f,null!=l.name&&d.fillText(l.name,30,u+0.7*g),d.fillStyle=q,d.textAlign="right",d.fillText(l.value,n-30,u+0.7*g));break;default:l.draw&&l.draw(d,a,l,u,g)}b+=g+4}d.restore();d.textAlign="left"};k.prototype.processNodeWidgets=function(a,b,d,c){function n(e,c){e.value=c;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,c);e.callback&&e.callback(e.value,k,a,b,d)}if(!a.widgets||!a.widgets.length)return null;
|
||||
for(var g=b[0]-a.pos[0],h=b[1]-a.pos[1],m=a.size[0],k=this,p=this.getCanvasWindow(),q=0;q<a.widgets.length;++q){var f=a.widgets[q];if(f==c||6<g&&g<m-12&&h>f.last_y&&h<f.last_y+e.NODE_WIDGET_HEIGHT){switch(f.type){case "button":if("mousemove"===d.type)break;f.callback&&setTimeout(function(){f.callback(f,k,a,b)},20);this.dirty_canvas=f.clicked=!0;break;case "slider":p=Math.clamp((g-10)/(m-20),0,1);f.value=f.options.min+(f.options.max-f.options.min)*p;f.callback&&setTimeout(function(){n(f,f.value)},
|
||||
20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==d.type&&"number"==f.type)f.value+=0.1*d.deltaX*(f.options.step||1),null!=f.options.min&&f.value<f.options.min&&(f.value=f.options.min),null!=f.options.max&&f.value>f.options.max&&(f.value=f.options.max);else if("mousedown"==d.type)if((c=f.options.values)&&c.constructor===Function&&(c=f.options.values(f,a)),g=40>g?-1:g>m-40?1:0,"number"==f.type)f.value+=0.1*g*(f.options.step||1),null!=f.options.min&&f.value<f.options.min&&(f.value=
|
||||
f.options.min),null!=f.options.max&&f.value>f.options.max&&(f.value=f.options.max);else if(g)p=c.indexOf(f.value)+g,p>=c.length&&(p=0),0>p&&(p=c.length-1),f.value=c[p];else{new e.ContextMenu(c,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:l.bind(f)},p);var l=function(a,b,d){this.value=a;n(this,a);k.dirty_canvas=!0;return!1}}setTimeout(function(){n(this,this.value)}.bind(f),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(f.value=!f.value,f.callback&&setTimeout(function(){n(f,
|
||||
f.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",f.value,function(a){this.value=a;n(this,a)}.bind(f),d);break;default:f.mouse&&f.mouse(ctx,d,[g,h],a)}return f}}return null};k.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var c=0;c<d.length;++c){var g=d[c];if(v(this.visible_area,g._bounding)){b.fillStyle=g.color||"#335";b.strokeStyle=g.color||"#335";var h=g._pos,m=g._size;b.globalAlpha=
|
||||
0.25*this.editor_alpha;b.beginPath();b.rect(h[0]+0.5,h[1]+0.5,m[0],m[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(h[0]+m[0],h[1]+m[1]);b.lineTo(h[0]+m[0]-10,h[1]+m[1]);b.lineTo(h[0]+m[0],h[1]+m[1]-10);b.fill();m=g.font_size||e.DEFAULT_GROUP_FONT_SIZE;b.font=m+"px Arial";b.fillText(g.title,h[0]+4,h[1]+m)}}b.restore()}};k.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};k.prototype.resize=
|
||||
function(a,b){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};k.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var e=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>
|
||||
d&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1<d&&0.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.onNodeSelectionChange=function(a){};k.prototype.touchHandler=function(a){var b=a.changedTouches[0],d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var e=this.getCanvasWindow(),c=e.document.createEvent("MouseEvent");
|
||||
c.initMouseEvent(d,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(c);a.preventDefault()};k.onGroupAdd=function(a,b,d){a=k.active_canvas;a.getCanvasWindow();b=new e.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};k.onMenuAdd=function(a,b,d,c){function g(a,b){var d=c.getFirstEvent(),n=e.createNode(a.value);n&&(n.pos=h.convertEventToCanvasOffset(d),h.graph.add(n))}var h=k.active_canvas,m=h.getCanvasWindow();a=e.getNodeTypesCategories(h.filter);
|
||||
b=[];for(var f in a)a[f]&&b.push({value:a[f],content:a[f],has_submenu:!0});var p=new e.ContextMenu(b,{event:d,callback:function(a,b,d){a=e.getNodeTypesInCategory(a.value,h.filter);b=[];for(var c in a)a[c].skip_list||b.push({content:a[c].title,value:a[c].type});new e.ContextMenu(b,{event:d,callback:g,parentMenu:p},m);return!1},parentMenu:c},m);return!1};k.onMenuCollapseAll=function(){};k.onMenuNodeEdit=function(){};k.showMenuNodeOptionalInputs=function(a,b,d,c,g){function h(a,b,d){g&&(a.callback&&
|
||||
a.callback.call(m,g,a,b,d),a.value&&(g.addInput(a.value[0],a.value[1],a.value[2]),g.setDirtyCanvas(!0,!0)))}if(g){var m=this;a=k.active_canvas.getCanvasWindow();b=g.optional_inputs;g.onGetInputs&&(b=g.onGetInputs());var f=[];if(b)for(var p in b){var q=b[p];if(q){var l=q[0];q[2]&&q[2].label&&(l=q[2].label);l={content:l,value:q};q[1]==e.ACTION&&(l.className="event");f.push(l)}else f.push(null)}this.onMenuNodeInputs&&(f=this.onMenuNodeInputs(f));if(f.length)return new e.ContextMenu(f,{event:d,callback:h,
|
||||
parentMenu:c,node:g},a),!1}};k.showMenuNodeOptionalOutputs=function(a,b,d,c,g){function h(a,b,d){if(g&&(a.callback&&a.callback.call(m,g,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)g.addOutput(a.value[0],a.value[1],a.value[2]),g.setDirtyCanvas(!0,!0);else{a=[];for(var f in d)a.push({content:f,value:d[f]});new e.ContextMenu(a,{event:b,callback:h,parentMenu:c,node:g});return!1}}if(g){var m=this;a=k.active_canvas.getCanvasWindow();b=g.optional_outputs;g.onGetOutputs&&
|
||||
(b=g.onGetOutputs());var f=[];if(b)for(var p in b){var q=b[p];if(!q)f.push(null);else if(!g.flags||!g.flags.skip_repeated_outputs||-1==g.findOutputSlot(q[0])){var l=q[0];q[2]&&q[2].label&&(l=q[2].label);l={content:l,value:q};q[1]==e.EVENT&&(l.className="event");f.push(l)}}this.onMenuNodeOutputs&&(f=this.onMenuNodeOutputs(f));if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,node:g},a),!1}};k.onShowMenuNodeProperties=function(a,b,d,c,g){function h(a,b,d,e){g&&(b=this.getBoundingClientRect(),
|
||||
m.showEditPropertyValue(g,a.value,{position:[b.left,b.top]}))}if(g&&g.properties){var m=k.active_canvas;b=m.getCanvasWindow();var f=[],q;for(q in g.properties)a=void 0!==g.properties[q]?g.properties[q]:" ","object"==typeof a&&(a=JSON.stringify(a)),a=k.decodeHTML(a),f.push({content:"<span class='property_name'>"+q+"</span><span class='property_value'>"+a+"</span>",value:q});if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,allow_html:!0,node:g},b),!1}};k.decodeHTML=function(a){var b=
|
||||
document.createElement("div");b.innerText=a;return b.innerHTML};k.onResizeNode=function(a,b,d,e,c){c&&(c.size=c.computeSize(),c.setDirtyCanvas(!0,!0))};k.prototype.showLinkMenu=function(a,b){var d=this;console.log(a.data);new e.ContextMenu(["Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};k.onShowPropertyEditor=function(a,b,d,e,c){function g(){var b=f.value;"Number"==a.type?b=Number(b):"Boolean"==
|
||||
a.type&&(b=Boolean(b));c[h]=b;m.parentNode&&m.parentNode.removeChild(m);c.setDirtyCanvas(!0,!0)}var h=a.property||"title";b=c[h];var m=document.createElement("div");m.className="graphdialog";m.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";m.querySelector(".name").innerText=h;var f=m.querySelector("input");f&&(f.value=b,f.addEventListener("blur",function(a){this.focus()}),f.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),
|
||||
a.stopPropagation())}));b=k.active_canvas.canvas;d=b.getBoundingClientRect();var q=e=-20;d&&(e-=d.left,q-=d.top);event?(m.style.left=event.clientX+e+"px",m.style.top=event.clientY+q+"px"):(m.style.left=0.5*b.width+e+"px",m.style.top=0.5*b.height+q+"px");m.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(m)};k.prototype.prompt=function(a,b,d,e){var c=this;a=a||"";var g=!1,h=document.createElement("div");h.className="graphdialog rounded";h.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
|
||||
h.close=function(){c.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseleave",function(a){g||h.close()});c.prompt_box&&c.prompt_box.close();c.prompt_box=h;h.querySelector(".name").innerText=a;h.querySelector(".value").value=b;var m=h.querySelector("input");m.addEventListener("keydown",function(a){g=!0;if(27==a.keyCode)h.close();else if(13==a.keyCode)d&&d(this.value),h.close();else return;a.preventDefault();
|
||||
a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){d&&d(m.value);c.setDirty(!0);h.close()});a=k.active_canvas.canvas;b=a.getBoundingClientRect();var f=-20,q=-20;b&&(f-=b.left,q-=b.top);e?(h.style.left=e.clientX+f+"px",h.style.top=e.clientY+q+"px"):(h.style.left=0.5*a.width+f+"px",h.style.top=0.5*a.height+q+"px");a.parentNode.appendChild(h);setTimeout(function(){m.focus()},10);return h};k.search_limit=-1;k.prototype.showSearchBox=function(a){function b(b){if(b)if(g.onSearchBoxSelection)g.onSearchBoxSelection(b,
|
||||
a,A);else{var d=e.searchbox_extras[b.toLowerCase()];d&&(b=d.type);if(b=e.createNode(b))b.pos=A.convertEventToCanvasOffset(a),A.graph.add(b);if(d&&d.data){if(d.data.properties)for(var c in d.data.properties)b.addProperty(c,d.data.properties[c]);if(d.data.inputs)for(c in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[c][0],d.data.inputs[c][1]);if(d.data.outputs)for(c in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[c][0],d.data.outputs[c][1]);d.data.title&&(b.title=d.data.title);d.data.json&&
|
||||
b.configure(d.data.json)}}h.close()}function d(a){var b=l;l&&l.classList.remove("selected");l?(l=a?l.nextSibling:l.previousSibling)||(l=b):l=a?f.childNodes[0]:f.childNodes[f.childNodes.length];l&&(l.classList.add("selected"),l.scrollIntoView())}function c(){function a(d,e){var c=document.createElement("div");q||(q=d);c.innerText=d;c.dataset.type=escape(d);c.className="litegraph lite-search-item";e&&(c.className+=" "+e);c.addEventListener("click",function(a){b(unescape(this.dataset.type))});f.appendChild(c)}
|
||||
p=null;var d=u.value;q=null;f.innerHTML="";if(d)if(g.onSearchBox){var h=g.onSearchBox(f,d,A);if(h)for(var m=0;m<h.length;++m)a(h[m])}else{var h=0,d=d.toLowerCase(),l=A.filter||A.graph.filter;for(m in e.searchbox_extras){var t=e.searchbox_extras[m];if(-1!==t.desc.toLowerCase().indexOf(d)){var x=e.registered_node_types[t.type];if(!x||!x.filter||x.filter==l)if(a(t.desc,"searchbox_extra"),-1!==k.search_limit&&h++>k.search_limit)break}}t=null;if(Array.prototype.filter)t=Object.keys(e.registered_node_types).filter(v);
|
||||
else for(m in t=[],e.registered_node_types)v(m)&&t.push(m);for(m=0;m<t.length&&!(a(t[m]),-1!==k.search_limit&&h++>k.search_limit);m++);var v=function(a){var b=e.registered_node_types[a];return l&&b.filter!=l?!1:-1!==a.toLowerCase().indexOf(d)}}}var g=this,h=document.createElement("div");h.className="litegraph litesearchbox graphdialog rounded";h.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";h.close=function(){g.search_box=
|
||||
null;document.body.focus();setTimeout(function(){g.canvas.focus()},20);h.parentNode&&h.parentNode.removeChild(h)};var m=null;1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseenter",function(a){m&&(clearTimeout(m),m=null)});h.addEventListener("mouseleave",function(a){m=setTimeout(function(){h.close()},500)});g.search_box&&g.search_box.close();g.search_box=h;var f=h.querySelector(".helper"),q=null,p=null,l=null,u=h.querySelector("input");u&&(u.addEventListener("blur",
|
||||
function(a){this.focus()}),u.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)h.close();else if(13==a.keyCode)l?b(l.innerHTML):q?b(q):h.close();else{p&&clearInterval(p);p=setTimeout(c,10);return}a.preventDefault();a.stopPropagation()}));var A=k.active_canvas,x=A.canvas,v=x.ownerDocument||document;v.fullscreenElement?v.fullscreenElement.appendChild(h):v.body.appendChild(h);x=x.getBoundingClientRect();v=(a?a.clientY:x.top+0.5*x.height)-
|
||||
20;h.style.left=(a?a.clientX:x.left+0.5*x.width)-80+"px";h.style.top=v+"px";u.focus();return h};k.prototype.showEditPropertyValue=function(a,b,d){function e(){c(p.value)}function c(d){"number"==typeof a.properties[b]&&(d=Number(d));if("array"==g||"object"==g)d=JSON.parse(d);a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);k.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var g="string";null!==a.properties[b]&&(g=typeof a.properties[b]);
|
||||
var h=null;a.getPropertyInfo&&(h=a.getPropertyInfo(b));if(a.properties_info)for(var m=0;m<a.properties_info.length;++m)if(a.properties_info[m].name==b){h=a.properties_info[m];break}void 0!==h&&null!==h&&h.type&&(g=h.type);var f="";if("string"==g||"number"==g||"array"==g||"object"==g)f="<input autofocus type='text' class='value'/>";else if("enum"==g&&h.values){f="<select autofocus type='text' class='value'>";for(m in h.values)var q=h.values.constructor===Array?h.values[m]:m,f=f+("<option value='"+
|
||||
q+"' "+(q==a.properties[b]?"selected":"")+">"+h.values[m]+"</option>");f+="</select>"}else if("boolean"==g)f="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+g);return}var k=this.createDialog("<span class='name'>"+b+"</span>"+f+"<button>OK</button>",d);if("enum"==g&&h.values){var p=k.querySelector("select");p.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==g)(p=k.querySelector("input"))&&p.addEventListener("click",
|
||||
function(a){c(!!p.checked)});else if(p=k.querySelector("input"))p.addEventListener("blur",function(a){this.focus()}),q=void 0!==a.properties[b]?a.properties[b]:"",q=JSON.stringify(q),p.value=q,p.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});k.querySelector("button").addEventListener("click",e)}};k.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),
|
||||
c=-20,g=-20;e&&(c-=e.left,g-=e.top);b.position?(c+=b.position[0],g+=b.position[1]):b.event?(c+=b.event.clientX,g+=b.event.clientY):(c+=0.5*this.canvas.width,g+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=g+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};k.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};k.onMenuNodePin=function(a,b,d,e,c){c.pin()};k.onMenuNodeMode=function(a,b,d,c,g){new e.ContextMenu(["Always",
|
||||
"On Event","On Trigger","Never"],{event:d,callback:function(a){if(g)switch(a){case "On Event":g.mode=e.ON_EVENT;break;case "On Trigger":g.mode=e.ON_TRIGGER;break;case "Never":g.mode=e.NEVER;break;default:g.mode=e.ALWAYS}},parentMenu:c,node:g});return!1};k.onMenuNodeColors=function(a,b,d,c,g){if(!g)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var h in k.node_colors)a=k.node_colors[h],a={value:h,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+
|
||||
a.color+"; background-color:"+a.bgcolor+"'>"+h+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){g&&((a=a.value?k.node_colors[a.value]:null)?g.constructor===e.LGraphGroup?g.color=a.groupcolor:(g.color=a.color,g.bgcolor=a.bgcolor):(delete g.color,delete g.bgcolor),g.setDirtyCanvas(!0,!0))},parentMenu:c,node:g});return!1};k.onMenuNodeShapes=function(a,b,d,c,g){if(!g)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){g&&(g.shape=a,g.setDirtyCanvas(!0))},
|
||||
parentMenu:c,node:g});return!1};k.onMenuNodeRemove=function(a,b,d,e,c){if(!c)throw"no node passed";!1!==c.removable&&(c.graph.remove(c),c.setDirtyCanvas(!0,!0))};k.onMenuNodeClone=function(a,b,d,e,c){!1!=c.clonable&&(a=c.clone())&&(a.pos=[c.pos[0]+5,c.pos[1]+5],c.graph.add(a),c.setDirtyCanvas(!0,!0))};k.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",
|
||||
bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};k.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:k.onMenuAdd},{content:"Add Group",
|
||||
callback:k.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};k.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalOutputs},
|
||||
null,{content:"Properties",has_submenu:!0,callback:k.onShowMenuNodeProperties},null,{content:"Title",callback:k.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:k.onMenuNodeMode},{content:"Resize",callback:k.onResizeNode},{content:"Collapse",callback:k.onMenuNodeCollapse},{content:"Pin",callback:k.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:k.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&
|
||||
(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this))&&(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:k.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:k.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};k.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:k.onShowPropertyEditor},
|
||||
{content:"Color",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:k.onShowPropertyEditor},null,{content:"Remove",callback:k.onMenuNodeRemove}]};k.prototype.processContextMenu=function(a,b){var d=this,c=k.active_canvas.getCanvasWindow(),g=null,h={event:b,callback:function(b,c,e){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):
|
||||
b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var g=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),h=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",c),m=h.querySelector("input");m&&g&&(m.value=g.label||"");h.querySelector("button").addEventListener("click",function(a){m.value&&(g&&(g.label=m.value),d.setDirty(!0));h.close()})}},extra:a};a&&(h.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),
|
||||
k.active_node=a);if(m){g=[];m&&m.output&&m.output.links&&m.output.links.length&&g.push({content:"Disconnect Links",slot:m});var f=m.input||m.output;g.push(f.locked?"Cannot remove":{content:"Remove Slot",slot:m});g.push(f.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m});h.title=(m.input?m.input.type:m.output.type)||"*";m.input&&m.input.type==e.ACTION&&(h.title="Action");m.output&&m.output.type==e.EVENT&&(h.title="Event")}else a?g=this.getNodeMenuOptions(a):(g=this.getCanvasMenuOptions(),
|
||||
(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&g.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));g&&new e.ContextMenu(g,h,c)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,e,g){void 0===e&&(e=5);void 0===g&&(g=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+c-g);this.quadraticCurveTo(a+d,b+c,a+d-g,b+c);this.lineTo(a+g,b+c);this.quadraticCurveTo(a,
|
||||
b+c,a,b+c-g);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=y;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=u;e.growBounding=function(a,b,d){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);d<a[1]?a[1]=d:d>a[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]<
|
||||
b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};e.overlapBounding=v;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,c,e,g=0;6>g;g+=2)c="0123456789ABCDEF".indexOf(a.charAt(g)),e="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[d]=16*c+e,d++;return b};e.num2hex=function(a){for(var b="#",d,c,e=0;3>e;e++)d=a[e]/16,c=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=
|
||||
this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,c=!0;g.current_submenu&&g.current_submenu.close(a);if(d.callback){var h=d.callback.call(this,b,d,a,g,d.node);!0===h&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(h=b.callback.call(this,b,d,a,g,d.extra),!0===h&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
|
||||
title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});c=!1}c&&!g.lock&&g.close()}var g=this;d=d||{};var h=document.createElement("div");h.className="litemenu-entry submenu";var m=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(m=!0,h.classList.add("disabled")),(b.submenu||b.has_submenu)&&h.classList.add("has_submenu");"function"==typeof b?(h.dataset.value=a,h.onclick_callback=b):h.dataset.value=b;b.className&&(h.className+=" "+
|
||||
b.className)}this.root.appendChild(h);m||h.addEventListener("click",e);d.autoopen&&h.addEventListener("mouseenter",c);return h};z.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&
|
||||
clearTimeout(this.root.closing_timer)};z.trigger=function(a,b,d,c){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,d);e.srcElement=c;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,
|
||||
b){var d=a.clientX,c=a.clientY,e=b.getBoundingClientRect();return e?c>e.top&&c<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:!1:!1};e.ContextMenu=z;e.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};e.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&
|
||||
!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>
|
||||
a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
(function(w){function c(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function s(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new p.LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onTrigger=this.onSubgraphTrigger.bind(this);this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);
|
||||
this.subgraph.onInputRemoved=this.onSubgraphRemovedInput.bind(this);this.subgraph.onOutputAdded=this.onSubgraphNewOutput.bind(this);this.subgraph.onOutputRenamed=this.onSubgraphRenamedOutput.bind(this);this.subgraph.onOutputTypeChanged=this.onSubgraphTypeChangeOutput.bind(this);this.subgraph.onOutputRemoved=this.onSubgraphRemovedOutput.bind(this)}function l(){this.addOutput("","number");this.name_in_graph="";this.properties={name:"",type:"number",value:0};var a=this;this.name_widget=this.addWidget("text",
|
||||
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function f(){this.addInput("","");this.name_in_graph="";this.properties={};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return a.name_in_graph},set:function(b){""!=
|
||||
@@ -240,7 +239,7 @@ this.properties.name,function(b){b&&(a.properties.name=b)});this.type_widget=thi
|
||||
"object");this._result={};var a=this;this.addWidget("button","clear","",function(){a._result={}});this.size=this.computeSize()}function e(){this.size=[60,30];this.addInput("in");this.addOutput("out");this.properties={varname:"myname",global:!1};this.value=null}function x(){this.size=[60,30];this.addInput("data",0);this.addInput("download",p.ACTION);this.properties={filename:"data.json"};this.value=null;var a=this;this.addWidget("button","Download","",function(b){a.value&&a.downloadAsFile()})}function g(){this.size=
|
||||
[60,30];this.addInput("value",0,{label:""});this.value=0}function m(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,30]}function C(){this.mode=p.ON_EVENT;this.size=[80,30];this.addProperty("msg","");this.addInput("log",p.EVENT);this.addInput("msg",0)}function h(){this.mode=p.ON_EVENT;this.addProperty("msg","");this.addInput("",p.EVENT);var a=this;this.widget=this.addWidget("text","Text","",function(b){a.properties.msg=b});this.widgets_up=!0;this.size=[200,30]}function q(){this.size=
|
||||
[60,30];this.addProperty("onExecute","return A;");this.addInput("A","");this.addInput("B","");this.addOutput("out","");this._func=null;this.data={}}var p=w.LiteGraph;c.title="Time";c.desc="Time";c.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};p.registerNodeType("basic/time",c);s.title="Subgraph";s.desc="Graph inside a node";s.title_color="#334";s.prototype.onGetInputs=function(){return[["enabled","boolean"]]};s.prototype.onDrawTitle=
|
||||
function(a){if(!this.flags.collapsed){a.fillStyle="#555";var b=p.NODE_TITLE_HEIGHT,d=this.size[0]-b;a.fillRect(d,-b,b,b);a.fillStyle="#333";a.beginPath();a.moveTo(d+0.2*b,0.6*-b);a.lineTo(d+0.8*b,0.6*-b);a.lineTo(d+0.5*b,0.3*-b);a.fill()}};s.prototype.onDblClick=function(a,b,d){var c=this;setTimeout(function(){d.openSubgraph(c.subgraph)},10)};s.prototype.onMouseDown=function(a,b,d){if(!this.flags.collapsed&&b[0]>this.size[0]-p.NODE_TITLE_HEIGHT&&0>b[1]){var c=this;setTimeout(function(){d.openSubgraph(c.subgraph)},
|
||||
function(a){if(!this.flags.collapsed){a.fillStyle="#555";var b=p.NODE_TITLE_HEIGHT,d=this.size[0]-b;a.fillRect(d,-b,b,b);a.fillStyle="#333";a.beginPath();a.moveTo(d+0.2*b,0.6*-b);a.lineTo(d+0.8*b,0.6*-b);a.lineTo(d+0.5*b,0.3*-b);a.fill()}};s.prototype.onDblClick=function(a,b,d){var e=this;setTimeout(function(){d.openSubgraph(e.subgraph)},10)};s.prototype.onMouseDown=function(a,b,d){if(!this.flags.collapsed&&b[0]>this.size[0]-p.NODE_TITLE_HEIGHT&&0>b[1]){var e=this;setTimeout(function(){d.openSubgraph(e.subgraph)},
|
||||
10)}};s.prototype.onAction=function(a,b){this.subgraph.onAction(a,b)};s.prototype.onExecute=function(){if(this.enabled=this.getInputOrProperty("enabled")){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],d=this.getInputData(a);this.subgraph.setInputData(b.name,d)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)d=this.subgraph.getOutputData(this.outputs[a].name),this.setOutputData(a,d)}};s.prototype.sendEventToAllNodes=function(a,b,d){this.enabled&&
|
||||
this.subgraph.sendEventToAllNodes(a,b,d)};s.prototype.onSubgraphTrigger=function(a,b){var d=this.findOutputSlot(a);-1!=d&&this.triggerSlot(d)};s.prototype.onSubgraphNewInput=function(a,b){-1==this.findInputSlot(a)&&this.addInput(a,b)};s.prototype.onSubgraphRenamedInput=function(a,b){var d=this.findInputSlot(a);-1!=d&&(this.getInputInfo(d).name=b)};s.prototype.onSubgraphTypeChangeInput=function(a,b){var d=this.findInputSlot(a);-1!=d&&(this.getInputInfo(d).type=b)};s.prototype.onSubgraphRemovedInput=
|
||||
function(a){a=this.findInputSlot(a);-1!=a&&this.removeInput(a)};s.prototype.onSubgraphNewOutput=function(a,b){-1==this.findOutputSlot(a)&&this.addOutput(a,b)};s.prototype.onSubgraphRenamedOutput=function(a,b){var d=this.findOutputSlot(a);-1!=d&&(this.getOutputInfo(d).name=b)};s.prototype.onSubgraphTypeChangeOutput=function(a,b){var d=this.findOutputSlot(a);-1!=d&&(this.getOutputInfo(d).type=b)};s.prototype.onSubgraphRemovedOutput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeOutput(a)};s.prototype.getExtraMenuOptions=
|
||||
@@ -252,14 +251,14 @@ this.graph.trigger(this.properties.name,b)};f.prototype.onRemoved=function(){thi
|
||||
this.title};r.prototype.setValue=function(a){this.properties.value=a};r.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};p.registerNodeType("basic/const",r);k.title="Const String";k.desc="Constant string";k.prototype.setValue=function(a){this.properties.value=a};k.prototype.onPropertyChanged=function(a,b){this.widget.value=b};k.prototype.getTitle=r.prototype.getTitle;k.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};p.registerNodeType("basic/string",
|
||||
k);y.title="Const Data";y.desc="Constant Data";y.prototype.setValue=function(a){this.properties.value=a;this.onPropertyChanged("value",a)};y.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value=JSON.parse(b),this.boxcolor="#AEA"}catch(d){this.boxcolor="red"}};y.prototype.onExecute=function(){this.setOutputData(0,this._value)};p.registerNodeType("basic/data",y);u.title="Object property";u.desc="Outputs the property of an object";u.prototype.setValue=function(a){this.properties.value=
|
||||
a;this.widget.value=a};u.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};u.prototype.onPropertyChanged=function(a,b){this.widget.value=b};u.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a[this.properties.value])};p.registerNodeType("basic/object_property",u);v.title="Object keys";v.desc="Outputs an array with the keys of an object";v.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,
|
||||
Object.keys(a))};p.registerNodeType("basic/object_keys",v);z.title="Merge Objects";z.desc="Creates an object copying properties from others";z.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),d=this._result;if(a)for(var c in a)d[c]=a[c];if(b)for(c in b)d[c]=b[c];this.setOutputData(0,d)};p.registerNodeType("basic/merge_objects",z);e.title="Variable";e.desc="store/read variable value";e.prototype.onExecute=function(){this.value=this.getInputData(0);this.graph&&(this.graph.vars[this.properties.varname]=
|
||||
Object.keys(a))};p.registerNodeType("basic/object_keys",v);z.title="Merge Objects";z.desc="Creates an object copying properties from others";z.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),d=this._result;if(a)for(var e in a)d[e]=a[e];if(b)for(e in b)d[e]=b[e];this.setOutputData(0,d)};p.registerNodeType("basic/merge_objects",z);e.title="Variable";e.desc="store/read variable value";e.prototype.onExecute=function(){this.value=this.getInputData(0);this.graph&&(this.graph.vars[this.properties.varname]=
|
||||
this.value);this.properties.global&&(w[this.properties.varname]=this.value);this.setOutputData(0,this.value)};e.prototype.getTitle=function(){return this.properties.varname};p.registerNodeType("basic/variable",e);x.title="Download";x.desc="Download some data";x.prototype.downloadAsFile=function(){if(null!=this.value){var a=null,a=this.value.constructor===String?this.value:JSON.stringify(this.value),a=new Blob([a]),b=URL.createObjectURL(a),a=document.createElement("a");a.setAttribute("href",b);a.setAttribute("download",
|
||||
this.properties.filename);a.style.display="none";document.body.appendChild(a);a.click();document.body.removeChild(a);setTimeout(function(){URL.revokeObjectURL(b)},6E4)}};x.prototype.onAction=function(a,b){var d=this;setTimeout(function(){d.downloadAsFile()},100)};x.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};x.prototype.getTitle=function(){return this.flags.collapsed?this.properties.filename:this.title};p.registerNodeType("basic/download",x);g.title="Watch";g.desc=
|
||||
"Show value of input";g.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};g.prototype.getTitle=function(){return this.flags.collapsed?this.inputs[0].label:this.title};g.toString=function(a){if(null==a)return"null";if(a.constructor===Number)return a.toFixed(3);if(a.constructor===Array){for(var b="[",d=0;d<a.length;++d)b+=g.toString(a[d])+(d+1!=a.length?",":"");return b+"]"}return String(a)};g.prototype.onDrawBackground=function(a){this.inputs[0].label=g.toString(this.value)};
|
||||
p.registerNodeType("basic/watch",g);m.title="Cast";m.desc="Allows to connect different types";m.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};p.registerNodeType("basic/cast",m);C.title="Console";C.desc="Show value inside the console";C.prototype.onAction=function(a,b){"log"==a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};C.prototype.onExecute=function(){var a=this.getInputData(1);null!==a&&(this.properties.msg=a);console.log(a)};C.prototype.onGetInputs=
|
||||
function(){return[["log",p.ACTION],["warn",p.ACTION],["error",p.ACTION]]};p.registerNodeType("basic/console",C);h.title="Alert";h.desc="Show an alert window";h.color="#510";h.prototype.onConfigure=function(a){this.widget.value=a.properties.msg};h.prototype.onAction=function(a,b){var d=this.properties.msg;setTimeout(function(){alert(d)},10)};p.registerNodeType("basic/alert",h);q.prototype.onConfigure=function(a){a.properties.onExecute&&p.allow_scripts?this.compileCode(a.properties.onExecute):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};
|
||||
q.title="Script";q.desc="executes a code (max 100 characters)";q.widgets_info={onExecute:{type:"code"}};q.prototype.onPropertyChanged=function(a,b){"onExecute"==a&&p.allow_scripts?this.compileCode(b):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};q.prototype.compileCode=function(a){this._func=null;if(256<a.length)console.warn("Script too long, max 256 chars");else{for(var b=a.toLowerCase(),d="script body document eval nodescript function".split(" "),c=0;c<d.length;++c)if(-1!=
|
||||
b.indexOf(d[c])){console.warn("invalid script");return}try{this._func=new Function("A","B","C","DATA","node",a)}catch(e){console.error("Error parsing script"),console.error(e)}}};q.prototype.onExecute=function(){if(this._func)try{var a=this.getInputData(0),b=this.getInputData(1),d=this.getInputData(2);this.setOutputData(0,this._func(a,b,d,this.data,this))}catch(c){console.error("Error in script"),console.error(c)}};q.prototype.onGetOutputs=function(){return[["C",""]]};p.registerNodeType("basic/script",
|
||||
q.title="Script";q.desc="executes a code (max 100 characters)";q.widgets_info={onExecute:{type:"code"}};q.prototype.onPropertyChanged=function(a,b){"onExecute"==a&&p.allow_scripts?this.compileCode(b):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};q.prototype.compileCode=function(a){this._func=null;if(256<a.length)console.warn("Script too long, max 256 chars");else{for(var b=a.toLowerCase(),d="script body document eval nodescript function".split(" "),e=0;e<d.length;++e)if(-1!=
|
||||
b.indexOf(d[e])){console.warn("invalid script");return}try{this._func=new Function("A","B","C","DATA","node",a)}catch(c){console.error("Error parsing script"),console.error(c)}}};q.prototype.onExecute=function(){if(this._func)try{var a=this.getInputData(0),b=this.getInputData(1),d=this.getInputData(2);this.setOutputData(0,this._func(a,b,d,this.data,this))}catch(e){console.error("Error in script"),console.error(e)}};q.prototype.onGetOutputs=function(){return[["C",""]]};p.registerNodeType("basic/script",
|
||||
q)})(this);
|
||||
(function(w){function c(){this.size=[60,30];this.addInput("event",v.ACTION)}function s(){this.size=[60,30];this.addInput("in","");this.addOutput("true",v.EVENT);this.addOutput("change",v.EVENT);this.was_true=!1}function l(){this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",
|
||||
v.EVENT);this.addOutput("",v.EVENT);this.size=[120,30];this.flags={horizontal:!0,render_box:!1}}function f(){this.size=[60,30];this.addInput("event",v.ACTION);this.addOutput("event",v.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function r(){this.addInput("inc",v.ACTION);this.addInput("dec",v.ACTION);this.addInput("reset",v.ACTION);this.addOutput("change",v.EVENT);this.addOutput("num","number");this.num=0}function k(){this.size=[60,30];this.addProperty("time_in_ms",1E3);
|
||||
@@ -397,34 +396,34 @@ x.registerNodeType("graphics/webcam",e)})(this);
|
||||
"Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="<p>pixelcode must be vec3, uvcode must be vec2, is optional</p>\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture <strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time <strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";this.properties={value:1,pixelcode:"color + colorB * value",uvcode:"",precision:c.DEFAULT};this.has_error=!1}
|
||||
function r(){this.addOutput("out","Texture");this.properties={code:"",u_value:1,u_color:[1,1,1,1],width:512,height:512,precision:c.DEFAULT};this.properties.code="//time: time in seconds\n//texSize: vec2 with res\nuniform float u_value;\nuniform vec4 u_color;\n\nvoid main() {\n vec2 uv = v_coord;\n vec3 color = vec3(0.0);\n\t//your code here\n\tcolor.xy=uv;\n\ngl_FragColor = vec4(color, 1.0);\n}\n";this._uniforms={u_value:1,u_color:vec4.create(),in_texture:0,texSize:vec2.create(),time:0}}function k(){this.addInput("in",
|
||||
"Texture");this.addInput("scale","vec2");this.addInput("offset","vec2");this.addOutput("out","Texture");this.properties={offset:vec2.fromValues(0,0),scale:vec2.fromValues(1,1),precision:c.DEFAULT}}function y(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:0.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}
|
||||
function u(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1};this.size[0]=130}function v(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function z(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function e(){this.addInput("Texture","Texture");this.addOutput("tex",
|
||||
"Texture");this.addOutput("avg","vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)}function x(){this.addInput("Texture","Texture");this.addOutput("min_t","Texture");this.addOutput("max_t","Texture");this.addOutput("min","vec4");this.addOutput("max","vec4");this.properties={mode:"max",use_previous_frame:!0};this._uniforms={u_texture:0};this._max=new Float32Array(4);this._min=
|
||||
new Float32Array(4);this._textures_chain=[]}function g(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:0.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function m(){this.addInput("in","Texture");this.addOutput("avg","Texture");this.addOutput("array","Texture");this.properties={samples:64,frames_interval:1};this._uniforms={u_texture:0,u_textureB:1,u_samples:this.properties.samples,u_isamples:1/this.properties.samples};
|
||||
this.frame=0}function C(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}}function h(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={enabled:!0,intensity:1,precision:c.DEFAULT,texture:null};h._shader||(h._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h.pixel_shader))}function q(){this.addInput("Texture","Texture");this.addOutput("R","Texture");this.addOutput("G",
|
||||
"Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");q._shader||(q._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,q.pixel_shader))}function p(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,R:1,G:1,B:1,A:1};this._color=vec4.create();this._uniforms={u_textureR:0,u_textureG:1,u_textureB:2,u_textureA:3,u_color:this._color}}function a(){this.addOutput("Texture",
|
||||
"Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:c.DEFAULT}}function b(){this.addInput("A","color");this.addInput("B","color");this.addOutput("Texture","Texture");this.properties={angle:0,scale:1,A:[0,0,0],B:[1,1,1],texture_size:32};b._shader||(b._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}}function d(){this.addInput("A","Texture");this.addInput("B","Texture");this.addInput("Mixer",
|
||||
"Texture");this.addOutput("Texture","Texture");this.properties={factor:0.5,precision:c.DEFAULT};this._uniforms={u_textureA:0,u_textureB:1,u_textureMix:2,u_mix:vec4.create()}}function t(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:c.DEFAULT};t._shader||(t._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,t.pixel_shader))}function n(){this.addInput("Texture","Texture");this.addInput("Distance","number");this.addInput("Range",
|
||||
"number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}}function K(){this.addInput("Texture","Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1],precision:c.DEFAULT}}function E(){this.addInput("in","Texture");this.addInput("dirt",
|
||||
"Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:0.99,iterations:16,threshold:0,scale:1,dirt_factor:0.5,precision:c.DEFAULT};this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function G(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}}function H(){this.addInput("Texture","Texture");this.addOutput("Filtered",
|
||||
"Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79,phi:0.017}}function F(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function I(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:c.LOW};this._uniforms={u_texture:0,u_factor:1}}function B(){this.addInput("in","Texture");this.addInput("exp","number");this.addOutput("out",
|
||||
"Texture");this.properties={exposition:1,precision:c.LOW};this._uniforms={u_texture:0,u_exposition:1}}function A(){this.addInput("in","Texture");this.addInput("avg","number,Texture");this.addOutput("out","Texture");this.properties={enabled:!0,scale:1,gamma:1,average_lum:1,lum_white:1,precision:c.LOW};this._uniforms={u_texture:0,u_lumwhite2:1,u_igamma:1,u_scale:1,u_average_lum:1}}function J(){this.addOutput("out","Texture");this.properties={width:512,height:512,seed:0,persistence:0.1,octaves:8,scale:1,
|
||||
offset:[0,0],amplitude:1,precision:c.DEFAULT};this._key=0;this._texture=null;this._uniforms={u_persistence:0.1,u_seed:0,u_offset:vec2.create(),u_scale:1,u_viewport:vec2.create()}}function L(){this.addInput("v");this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,clear:!0,precision:c.DEFAULT,use_html_canvas:!1};this._temp_texture=this._func=null}function M(){this.addInput("in","Texture");this.addOutput("out","Texture");this.properties={key_color:vec3.fromValues(0,1,0),threshold:0.8,
|
||||
slope:0.2,precision:c.DEFAULT}}function N(){this.addInput("in","texture");this.addInput("yaw","number");this.addOutput("out","texture");this.properties={yaw:0}}var D=w.LiteGraph;w.LGraphTexture=null;"undefined"!=typeof GL&&(LGraphCanvas.link_type_colors.Texture="#987",w.LGraphTexture=c,c.title="Texture",c.desc="Texture",c.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}},c.loadTextureCallback=null,c.image_preview_size=256,c.PASS_THROUGH=1,c.COPY=2,c.LOW=3,c.HIGH=4,c.REUSE=5,c.DEFAULT=
|
||||
2,c.MODE_VALUES={"pass through":c.PASS_THROUGH,copy:c.COPY,low:c.LOW,high:c.HIGH,reuse:c.REUSE,"default":c.DEFAULT},c.getTexturesContainer=function(){return gl.textures},c.loadTexture=function(a,b){b=b||{};var d=a;"http://"==d.substr(0,7)&&D.proxy&&(d=D.proxy+d.substr(7));return c.getTexturesContainer()[a]=GL.Texture.fromURL(d,b)},c.getTexture=function(a){var b=this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a):
|
||||
b},c.getTargetTexture=function(a,b,d){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var e=null;switch(d){case c.LOW:e=gl.UNSIGNED_BYTE;break;case c.HIGH:e=gl.HIGH_PRECISION_FORMAT;break;case c.REUSE:return a;default:e=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==e||(b=new GL.Texture(a.width,a.height,{type:e,format:gl.RGBA,filter:gl.LINEAR}));return b},c.getTextureType=function(a,b){var d=b?b.type:gl.UNSIGNED_BYTE;switch(a){case c.HIGH:d=gl.HIGH_PRECISION_FORMAT;
|
||||
break;case c.LOW:d=gl.UNSIGNED_BYTE}return d},c.getWhiteTexture=function(){return this._white_texture?this._white_texture:this._white_texture=GL.Texture.fromMemory(1,1,[255,255,255,255],{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576),b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},
|
||||
c.prototype.onDropFile=function(a,b,c){if(a){var d=null;"string"==typeof a?d=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?d=GL.Texture.fromDDSInMemory(a):(a=new Blob([c]),a=URL.createObjectURL(a),d=GL.Texture.fromURL(a));this._drop_texture=d;this.properties.name=b}else this._drop_texture=null,this.properties.name=""},c.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]},c.prototype.onExecute=
|
||||
function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=c.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,a);for(var b=1;b<this.outputs.length;b++){var d=this.outputs[b];if(d){var e=null;"width"==d.name?e=a.width:"height"==d.name?e=a.height:"aspect"==d.name&&
|
||||
(e=a.width/a.height);this.setOutputData(b,e)}}}},c.prototype.onResourceRenamed=function(a,b){this.properties.name==a&&(this.properties.name=b)},c.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||20>=this.size[1]))if(this._drop_texture&&a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=c.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=
|
||||
this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}},c.generateLowResTexturePreview=function(a){if(!a)return null;var b=c.image_preview_size,d=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)d=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=d=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(d);a=this._preview_canvas;
|
||||
a||(this._preview_canvas=a=createCanvas(b,b));d&&d.toCanvas(a);return a},c.prototype.getResources=function(a){this.properties.name&&(a[this.properties.name]=GL.Texture);return a},c.prototype.onGetInputs=function(){return[["in","Texture"]]},c.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]},c.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g,function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},D.registerNodeType("texture/texture",
|
||||
c),s.title="Preview",s.desc="Show a texture in the graph canvas",s.allow_preview=!1,s.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||s.allow_preview)){var b=this.getInputData(0);if(b){var d=null,d=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(d,0,0,this.size[0],this.size[1]);a.restore()}}},D.registerNodeType("texture/preview",s),l.title="Save",l.desc="Save a texture in the repository",
|
||||
l.prototype.getPreviewTexture=function(){return this._texture},l.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.generate_mipmaps&&(a.bind(0),a.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR),gl.generateMipmap(a.texture_type),a.unbind(0)),this.properties.name&&(c.storeTexture?c.storeTexture(this.properties.name,a):c.getTexturesContainer()[this.properties.name]=a),this._texture=a,this.setOutputData(0,a),this.setOutputData(1,this.properties.name))},D.registerNodeType("texture/save",
|
||||
l),f.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},f.title="Operation",f.desc="Texture shader operation",f.presets={},f.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},f.prototype.onPropertyChanged=function(){this.has_error=!1},f.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||
|
||||
!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())},f.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,e=512;a?(d=a.width,e=a.height):b&&(d=b.width,e=b.height);b||(b=GL.Texture.getWhiteTexture());var h=c.getTextureType(this.properties.precision,
|
||||
a);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,e,{type:h,format:gl.RGBA,filter:gl.LINEAR});h="";this.properties.uvcode&&(h="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(h=this.properties.uvcode));var g="";this.properties.pixelcode&&(g="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(g=this.properties.pixelcode));var k=this._shader;if(!(this.has_error||k&&this._shader_code==
|
||||
h+"|"+g)){var m=c.replaceCode(f.pixel_shader,{UV_CODE:h,PIXEL_CODE:g});try{k=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,m),this.boxcolor="#00FF00"}catch(q){GL.Shader.dumpErrorToConsole(q,Shader.SCREEN_VERTEX_SHADER,m);this.boxcolor="#FF0000";this.has_error=!0;return}this._shader=k;this._shader_code=h+"|"+g}if(this._shader){var p=this.getInputData(2);null!=p?this.properties.value=p:p=parseFloat(this.properties.value);var n=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);
|
||||
gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:p,texSize:[d,e],time:n}).draw(c)});this.setOutputData(0,this._tex)}}}},f.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t",
|
||||
function u(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1,viewport:[0,0,1,1]};this.size[0]=130}function v(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function z(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function e(){this.addInput("Texture","Texture");
|
||||
this.addOutput("tex","Texture");this.addOutput("avg","vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)}function x(){this.addInput("Texture","Texture");this.addOutput("min_t","Texture");this.addOutput("max_t","Texture");this.addOutput("min","vec4");this.addOutput("max","vec4");this.properties={mode:"max",use_previous_frame:!0};this._uniforms={u_texture:0};this._max=new Float32Array(4);
|
||||
this._min=new Float32Array(4);this._textures_chain=[]}function g(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:0.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function m(){this.addInput("in","Texture");this.addOutput("avg","Texture");this.addOutput("array","Texture");this.properties={samples:64,frames_interval:1};this._uniforms={u_texture:0,u_textureB:1,u_samples:this.properties.samples,u_isamples:1/
|
||||
this.properties.samples};this.frame=0}function C(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}}function h(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={enabled:!0,intensity:1,precision:c.DEFAULT,texture:null};h._shader||(h._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h.pixel_shader))}function q(){this.addInput("Texture","Texture");this.addOutput("R","Texture");
|
||||
this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");q._shader||(q._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,q.pixel_shader))}function p(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,R:1,G:1,B:1,A:1};this._color=vec4.create();this._uniforms={u_textureR:0,u_textureG:1,u_textureB:2,u_textureA:3,u_color:this._color}}
|
||||
function a(){this.addOutput("Texture","Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:c.DEFAULT}}function b(){this.addInput("A","color");this.addInput("B","color");this.addOutput("Texture","Texture");this.properties={angle:0,scale:1,A:[0,0,0],B:[1,1,1],texture_size:32};b._shader||(b._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}}function d(){this.addInput("A","Texture");
|
||||
this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={factor:0.5,size_from_biggest:!0,invert:!1,precision:c.DEFAULT};this._uniforms={u_textureA:0,u_textureB:1,u_textureMix:2,u_mix:vec4.create()}}function t(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:c.DEFAULT};t._shader||(t._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,t.pixel_shader))}function n(){this.addInput("Texture",
|
||||
"Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}}function K(){this.addInput("Texture","Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1],precision:c.DEFAULT}}
|
||||
function E(){this.addInput("in","Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:0.99,iterations:16,threshold:0,scale:1,dirt_factor:0.5,precision:c.DEFAULT};this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function G(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,
|
||||
radius:5}}function H(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79,phi:0.017}}function F(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function I(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:c.LOW};this._uniforms={u_texture:0,u_factor:1}}function B(){this.addInput("in",
|
||||
"Texture");this.addInput("exp","number");this.addOutput("out","Texture");this.properties={exposition:1,precision:c.LOW};this._uniforms={u_texture:0,u_exposition:1}}function A(){this.addInput("in","Texture");this.addInput("avg","number,Texture");this.addOutput("out","Texture");this.properties={enabled:!0,scale:1,gamma:1,average_lum:1,lum_white:1,precision:c.LOW};this._uniforms={u_texture:0,u_lumwhite2:1,u_igamma:1,u_scale:1,u_average_lum:1}}function J(){this.addOutput("out","Texture");this.properties=
|
||||
{width:512,height:512,seed:0,persistence:0.1,octaves:8,scale:1,offset:[0,0],amplitude:1,precision:c.DEFAULT};this._key=0;this._texture=null;this._uniforms={u_persistence:0.1,u_seed:0,u_offset:vec2.create(),u_scale:1,u_viewport:vec2.create()}}function L(){this.addInput("v");this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,clear:!0,precision:c.DEFAULT,use_html_canvas:!1};this._temp_texture=this._func=null}function M(){this.addInput("in","Texture");this.addOutput("out","Texture");
|
||||
this.properties={key_color:vec3.fromValues(0,1,0),threshold:0.8,slope:0.2,precision:c.DEFAULT}}function N(){this.addInput("in","texture");this.addInput("yaw","number");this.addOutput("out","texture");this.properties={yaw:0}}var D=w.LiteGraph;w.LGraphTexture=null;"undefined"!=typeof GL&&(LGraphCanvas.link_type_colors.Texture="#987",w.LGraphTexture=c,c.title="Texture",c.desc="Texture",c.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}},c.loadTextureCallback=null,c.image_preview_size=
|
||||
256,c.PASS_THROUGH=1,c.COPY=2,c.LOW=3,c.HIGH=4,c.REUSE=5,c.DEFAULT=2,c.MODE_VALUES={"pass through":c.PASS_THROUGH,copy:c.COPY,low:c.LOW,high:c.HIGH,reuse:c.REUSE,"default":c.DEFAULT},c.getTexturesContainer=function(){return gl.textures},c.loadTexture=function(a,b){b=b||{};var d=a;"http://"==d.substr(0,7)&&D.proxy&&(d=D.proxy+d.substr(7));return c.getTexturesContainer()[a]=GL.Texture.fromURL(d,b)},c.getTexture=function(a){var b=this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";
|
||||
b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a):b},c.getTargetTexture=function(a,b,d){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var e=null;switch(d){case c.LOW:e=gl.UNSIGNED_BYTE;break;case c.HIGH:e=gl.HIGH_PRECISION_FORMAT;break;case c.REUSE:return a;default:e=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==e||(b=new GL.Texture(a.width,a.height,{type:e,format:gl.RGBA,filter:gl.LINEAR}));return b},c.getTextureType=function(a,b){var d=b?b.type:
|
||||
gl.UNSIGNED_BYTE;switch(a){case c.HIGH:d=gl.HIGH_PRECISION_FORMAT;break;case c.LOW:d=gl.UNSIGNED_BYTE}return d},c.getWhiteTexture=function(){return this._white_texture?this._white_texture:this._white_texture=GL.Texture.fromMemory(1,1,[255,255,255,255],{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576),b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,
|
||||
512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.prototype.onDropFile=function(a,b,c){if(a){var d=null;"string"==typeof a?d=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?d=GL.Texture.fromDDSInMemory(a):(a=new Blob([c]),a=URL.createObjectURL(a),d=GL.Texture.fromURL(a));this._drop_texture=d;this.properties.name=b}else this._drop_texture=null,this.properties.name=""},c.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=
|
||||
null;b.properties.name=""}}]},c.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=c.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,a);for(var b=1;b<this.outputs.length;b++){var d=this.outputs[b];if(d){var e=null;"width"==d.name?
|
||||
e=a.width:"height"==d.name?e=a.height:"aspect"==d.name&&(e=a.width/a.height);this.setOutputData(b,e)}}}},c.prototype.onResourceRenamed=function(a,b){this.properties.name==a&&(this.properties.name=b)},c.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||20>=this.size[1]))if(this._drop_texture&&a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=c.generateLowResTexturePreview(this._last_tex);
|
||||
if(!b)return;this._last_preview_tex=this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}},c.generateLowResTexturePreview=function(a){if(!a)return null;var b=c.image_preview_size,d=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)d=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=d=new GL.Texture(b,b,{minFilter:gl.NEAREST})),
|
||||
a.copyTo(d);a=this._preview_canvas;a||(this._preview_canvas=a=createCanvas(b,b));d&&d.toCanvas(a);return a},c.prototype.getResources=function(a){this.properties.name&&(a[this.properties.name]=GL.Texture);return a},c.prototype.onGetInputs=function(){return[["in","Texture"]]},c.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]},c.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g,function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},
|
||||
D.registerNodeType("texture/texture",c),s.title="Preview",s.desc="Show a texture in the graph canvas",s.allow_preview=!1,s.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||s.allow_preview)){var b=this.getInputData(0);if(b){var d=null,d=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(d,0,0,this.size[0],this.size[1]);a.restore()}}},D.registerNodeType("texture/preview",s),l.title=
|
||||
"Save",l.desc="Save a texture in the repository",l.prototype.getPreviewTexture=function(){return this._texture},l.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.generate_mipmaps&&(a.bind(0),a.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR),gl.generateMipmap(a.texture_type),a.unbind(0)),this.properties.name&&(c.storeTexture?c.storeTexture(this.properties.name,a):c.getTexturesContainer()[this.properties.name]=a),this._texture=a,this.setOutputData(0,a),this.setOutputData(1,
|
||||
this.properties.name))},D.registerNodeType("texture/save",l),f.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},f.title="Operation",f.desc="Texture shader operation",f.presets={},f.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},f.prototype.onPropertyChanged=function(){this.has_error=!1},f.prototype.onDrawBackground=
|
||||
function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())},f.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,e=512;a?(d=a.width,e=a.height):b&&(d=b.width,e=b.height);b||(b=GL.Texture.getWhiteTexture());
|
||||
var h=c.getTextureType(this.properties.precision,a);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,e,{type:h,format:gl.RGBA,filter:gl.LINEAR});h="";this.properties.uvcode&&(h="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(h=this.properties.uvcode));var g="";this.properties.pixelcode&&(g="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(g=this.properties.pixelcode));var k=this._shader;
|
||||
if(!(this.has_error||k&&this._shader_code==h+"|"+g)){var m=c.replaceCode(f.pixel_shader,{UV_CODE:h,PIXEL_CODE:g});try{k=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,m),this.boxcolor="#00FF00"}catch(q){GL.Shader.dumpErrorToConsole(q,Shader.SCREEN_VERTEX_SHADER,m);this.boxcolor="#FF0000";this.has_error=!0;return}this._shader=k;this._shader_code=h+"|"+g}if(this._shader){var p=this.getInputData(2);null!=p?this.properties.value=p:p=parseFloat(this.properties.value);var n=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);
|
||||
gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:p,texSize:[d,e],time:n}).draw(c)});this.setOutputData(0,this._tex)}}}},f.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t",
|
||||
f.registerPreset=function(a,b){f.presets[a]=b},f.registerPreset("",""),f.registerPreset("bypass","color"),f.registerPreset("add","color + colorB * value"),f.registerPreset("substract","(color - colorB) * value"),f.registerPreset("mate","mix( color, colorB, color4B.a * value)"),f.registerPreset("invert","vec3(1.0) - color"),f.registerPreset("multiply","color * colorB * value"),f.registerPreset("divide","(color / colorB) / value"),f.registerPreset("difference","abs(color - colorB) * value"),f.registerPreset("max",
|
||||
"max(color, colorB) * value"),f.registerPreset("min","min(color, colorB) * value"),f.registerPreset("displace","texture2D(u_texture, uv + (colorB.xy - vec2(0.5)) * value).xyz"),f.registerPreset("grayscale","vec3(color.x + color.y + color.z) * value / 3.0"),f.registerPreset("saturation","mix( vec3(color.x + color.y + color.z) / 3.0, color, value )"),f.registerPreset("threshold","vec3(color.x > colorB.x * value ? 1.0 : 0.0,color.y > colorB.y * value ? 1.0 : 0.0,color.z > colorB.z * value ? 1.0 : 0.0)"),
|
||||
f.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(f.presets),callback:function(c){var d=f.presets[c];d&&(b.setProperty("pixelcode",d),b.title=c,a.refresh())}})},D.registerNodeType("texture/operation",f),r.title="Shader",r.desc="Texture shader",r.widgets_info={code:{type:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},r.prototype.onPropertyChanged=function(a,b){if("code"==a){var c=this.getShader();if(c){var d=c.uniformInfo;if(this.inputs)for(var e={},
|
||||
@@ -437,9 +436,9 @@ k.pixel_shader));var f=this.getInputData(1);f?(this.properties.scale[0]=f[0],thi
|
||||
D.registerNodeType("texture/scaleOffset",k),y.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},y.title="Warp",y.desc="Texture warp operation",y.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1),d=512,e=512;a?(d=a.width,e=a.height):b&&(d=b.width,e=b.height);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):
|
||||
new GL.Texture(d,e,{type:this.precision===c.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT,format:gl.RGBA,filter:gl.LINEAR});var h=this._shader;h||(h=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,y.pixel_shader));d=this.getInputData(2);null!=d?this.properties.factor=d:d=parseFloat(this.properties.factor);var f=this._uniforms;f.u_factor=d;f.u_scale.set(this.properties.scale);f.u_offset.set(this.properties.offset);this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);
|
||||
a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();h.uniforms(f).draw(c)});this.setOutputData(0,this._tex)}},y.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform float u_factor;\n\t\tuniform vec2 u_scale;\n\t\tuniform vec2 u_offset;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\tuv += ( texture2D(u_textureB, uv).rg - vec2(0.5)) * u_factor * u_scale + u_offset;\n\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t}\n\t\t",
|
||||
D.registerNodeType("texture/warp",y),u.title="to Viewport",u.desc="Texture to viewport",u.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA,gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?
|
||||
gl.LINEAR:gl.NEAREST);if(this.properties.antialiasing){u._shader||(u._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,u.aa_pixel_shader));gl.getViewport();var c=Mesh.getScreenQuad();a.bind(0);u._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(c)}else 1!=b?(u._gamma_shader||(u._gamma_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,u.gamma_pixel_shader)),a.toViewport(u._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport()}},
|
||||
u.prototype.onGetInputs=function(){return[["gamma","number"]]},u.aa_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 uViewportSize;\n\t\tuniform vec2 inverseVP;\n\t\tuniform float u_igamma;\n\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\n\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t{\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\n\t\t\tvec2 dir;\n\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\n\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\n\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\n\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\n\t\t\t//return vec4(rgbA,1.0);\n\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\telse\n\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\tif(u_igamma != 1.0)\n\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\treturn color;\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t}\n\t\t",
|
||||
D.registerNodeType("texture/warp",y),u.title="to Viewport",u.desc="Texture to viewport",u._prev_viewport=new Float32Array(4),u.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA,gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,
|
||||
this.properties.filter?gl.LINEAR:gl.NEAREST);var c=u._prev_viewport;c.set(gl.viewport_data);var d=this.properties.viewport;gl.viewport(c[0]+c[2]*d[0],c[1]+c[3]*d[1],c[2]*d[2],c[3]*d[3]);gl.getViewport();this.properties.antialiasing?(u._shader||(u._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,u.aa_pixel_shader)),d=Mesh.getScreenQuad(),a.bind(0),u._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(d)):1!=b?(u._gamma_shader||(u._gamma_shader=
|
||||
new GL.Shader(Shader.SCREEN_VERTEX_SHADER,u.gamma_pixel_shader)),a.toViewport(u._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport();gl.viewport(c[0],c[1],c[2],c[3])}},u.prototype.onGetInputs=function(){return[["gamma","number"]]},u.aa_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 uViewportSize;\n\t\tuniform vec2 inverseVP;\n\t\tuniform float u_igamma;\n\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\n\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t{\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\n\t\t\tvec2 dir;\n\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\n\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\n\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\n\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\n\t\t\t//return vec4(rgbA,1.0);\n\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\telse\n\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\tif(u_igamma != 1.0)\n\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\treturn color;\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t}\n\t\t",
|
||||
u.gamma_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_igamma;\n\t\tvoid main() {\n\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t gl_FragColor = color;\n\t\t}\n\t\t",D.registerNodeType("texture/toviewport",u),v.title="Copy",v.desc="Copy Texture",v.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",
|
||||
values:c.MODE_VALUES}},v.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,d=a.height;0!=this.properties.size&&(d=b=this.properties.size);var e=this._temp_texture,h=a.type;this.properties.precision===c.LOW?h=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(h=gl.HIGH_PRECISION_FORMAT);e&&e.width==b&&e.height==d&&e.type==h||(e=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(d)&&(e=gl.LINEAR_MIPMAP_LINEAR),
|
||||
this._temp_texture=new GL.Texture(b,d,{type:h,format:gl.RGBA,minFilter:e,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}},D.registerNodeType("texture/copy",v),z.title="Downsample",z.desc="Downsample Texture",z.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:c.MODE_VALUES}},
|
||||
@@ -473,9 +472,9 @@ function(){var a=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UN
|
||||
a)&&(this._tex_color.set(a),this._tex.fill(a));this.setOutputData(0,this._tex)},a.prototype.onGetInputs=function(){return[["RGB","vec3"],["RGBA","vec4"],["R","number"],["G","number"],["B","number"],["A","number"]]},D.registerNodeType("texture/color",a),b.title="Gradient",b.desc="Generates a gradient",b["@A"]={type:"color"},b["@B"]={type:"color"},b["@texture_size"]={type:"enum",values:[32,64,128,256,512]},b.prototype.onExecute=function(){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var a=GL.Mesh.getScreenQuad(),
|
||||
c=b._shader,d=this.getInputData(0);d||(d=this.properties.A);var e=this.getInputData(1);e||(e=this.properties.B);for(var h=2;h<this.inputs.length;h++){var f=this.inputs[h],g=this.getInputData(h);void 0!==g&&(this.properties[f.name]=g)}var k=this._uniforms;this._uniforms.u_angle=this.properties.angle*DEG2RAD;this._uniforms.u_scale=this.properties.scale;vec3.copy(k.u_colorA,d);vec3.copy(k.u_colorB,e);d=parseInt(this.properties.texture_size);this._tex&&this._tex.width==d||(this._tex=new GL.Texture(d,
|
||||
d,{format:gl.RGB,filter:gl.LINEAR}));this._tex.drawTo(function(){c.uniforms(k).draw(a)});this.setOutputData(0,this._tex)},b.prototype.onGetInputs=function(){return[["angle","number"],["scale","number"]]},b.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform float u_angle;\n\t\tuniform float u_scale;\n\t\tuniform vec3 u_colorA;\n\t\tuniform vec3 u_colorB;\n\t\t\n\t\tvec2 rotate(vec2 v, float angle)\n\t\t{\n\t\t\tvec2 result;\n\t\t\tfloat _cos = cos(angle);\n\t\t\tfloat _sin = sin(angle);\n\t\t\tresult.x = v.x * _cos - v.y * _sin;\n\t\t\tresult.y = v.x * _sin + v.y * _cos;\n\t\t\treturn result;\n\t\t}\n\t\tvoid main() {\n\t\t\tfloat f = (rotate(u_scale * (v_coord - vec2(0.5)), u_angle) + vec2(0.5)).x;\n\t\t\tvec3 color = mix(u_colorA,u_colorB,clamp(f,0.0,1.0));\n\t\t gl_FragColor = vec4(color,1.0);\n\t\t}\n\t\t",
|
||||
D.registerNodeType("texture/gradient",b),d.title="Mix",d.desc="Generates a texture mixing two textures",d.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},d.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(a&&b){var e=this.getInputData(2),h=this.getInputData(3);this._tex=c.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);
|
||||
gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad(),g=null,k=this._uniforms;e?(g=d._shader_tex,g||(g=d._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader,{MIX_TEX:""}))):(g=d._shader_factor,g||(g=d._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader)),h=null==h?this.properties.factor:h,k.u_mix.set([h,h,h,h]));this._tex.drawTo(function(){a.bind(0);b.bind(1);e&&e.bind(2);g.uniforms(k).draw(f)});this.setOutputData(0,this._tex)}}},d.prototype.onGetInputs=function(){return[["factor",
|
||||
"number"]]},d.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform sampler2D u_textureB;\n\t\t#ifdef MIX_TEX\n\t\t\tuniform sampler2D u_textureMix;\n\t\t#else\n\t\t\tuniform vec4 u_mix;\n\t\t#endif\n\t\t\n\t\tvoid main() {\n\t\t\t#ifdef MIX_TEX\n\t\t\t vec4 f = texture2D(u_textureMix, v_coord);\n\t\t\t#else\n\t\t\t vec4 f = u_mix;\n\t\t\t#endif\n\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), f );\n\t\t}\n\t\t",
|
||||
D.registerNodeType("texture/gradient",b),d.title="Mix",d.desc="Generates a texture mixing two textures",d.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},d.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(a&&b){var e=this.getInputData(2),h=this.getInputData(3);this._tex=c.getTargetTexture(this.properties.size_from_biggest&&b.width>a.width?b:
|
||||
a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad(),g=null,k=this._uniforms;e?(g=d._shader_tex,g||(g=d._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader,{MIX_TEX:""}))):(g=d._shader_factor,g||(g=d._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader)),h=null==h?this.properties.factor:h,k.u_mix.set([h,h,h,h]));var m=this.properties.invert;this._tex.drawTo(function(){a.bind(m?1:0);b.bind(m?0:1);e&&e.bind(2);
|
||||
g.uniforms(k).draw(f)});this.setOutputData(0,this._tex)}}},d.prototype.onGetInputs=function(){return[["factor","number"]]},d.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform sampler2D u_textureB;\n\t\t#ifdef MIX_TEX\n\t\t\tuniform sampler2D u_textureMix;\n\t\t#else\n\t\t\tuniform vec4 u_mix;\n\t\t#endif\n\t\t\n\t\tvoid main() {\n\t\t\t#ifdef MIX_TEX\n\t\t\t vec4 f = texture2D(u_textureMix, v_coord);\n\t\t\t#else\n\t\t\t vec4 f = u_mix;\n\t\t\t#endif\n\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), f );\n\t\t}\n\t\t",
|
||||
D.registerNodeType("texture/mix",d),t.title="Edges",t.desc="Detects edges",t.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},t.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=c.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),d=t._shader,e=this.properties.invert,h=this.properties.factor,
|
||||
f=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);d.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:h,u_threshold:f,u_invert:e?1:0}).draw(b)});this.setOutputData(0,this._tex)}}},t.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_isize;\n\t\tuniform int u_invert;\n\t\tuniform float u_factor;\n\t\tuniform float u_threshold;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 center = texture2D(u_texture, v_coord);\n\t\t\tvec4 up = texture2D(u_texture, v_coord + u_isize * vec2(0.0,1.0) );\n\t\t\tvec4 down = texture2D(u_texture, v_coord + u_isize * vec2(0.0,-1.0) );\n\t\t\tvec4 left = texture2D(u_texture, v_coord + u_isize * vec2(1.0,0.0) );\n\t\t\tvec4 right = texture2D(u_texture, v_coord + u_isize * vec2(-1.0,0.0) );\n\t\t\tvec4 diff = abs(center - up) + abs(center - down) + abs(center - left) + abs(center - right);\n\t\t\tdiff *= u_factor;\n\t\t\tif(u_invert == 1)\n\t\t\t\tdiff.xyz = vec3(1.0) - diff.xyz;\n\t\t\tif( u_threshold == 0.0 )\n\t\t\t\tgl_FragColor = vec4( diff.xyz, center.a );\n\t\t\telse\n\t\t\t\tgl_FragColor = vec4( diff.x > 0.5 ? 1.0 : 0.0, diff.y > 0.5 ? 1.0 : 0.0, diff.z > 0.5 ? 1.0 : 0.0, center.a );\n\t\t}\n\t\t",
|
||||
D.registerNodeType("texture/edges",t),n.title="Depth Range",n.desc="Generates a texture with a depth range",n.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a){var b=gl.UNSIGNED_BYTE;this.properties.high_precision&&(b=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&&this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGBA,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "litegraph.js",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"description": "A graph node editor similar to PD or UDK Blueprints, it works in a HTML5 Canvas and allow to exported graphs to be included in applications.",
|
||||
"main": "build/litegraph.js",
|
||||
"types": "src/litegraph.d.ts",
|
||||
|
||||
@@ -6078,13 +6078,6 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
}
|
||||
};
|
||||
|
||||
LGraphCanvas.prototype.processNodeDeselected = function(node) {
|
||||
this.deselectNode(node);
|
||||
if (this.onNodeDeselected) {
|
||||
this.onNodeDeselected(node);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* selects a given node (or adds it to the current selection)
|
||||
* @method selectNode
|
||||
@@ -6161,6 +6154,10 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
}
|
||||
node.is_selected = false;
|
||||
|
||||
if (this.onNodeDeselected) {
|
||||
this.onNodeDeselected(node);
|
||||
}
|
||||
|
||||
//remove highlighted
|
||||
if (node.inputs) {
|
||||
for (var i = 0; i < node.inputs.length; ++i) {
|
||||
@@ -6197,6 +6194,9 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
node.onDeselected();
|
||||
}
|
||||
node.is_selected = false;
|
||||
if (this.onNodeDeselected) {
|
||||
this.onNodeDeselected(node);
|
||||
}
|
||||
}
|
||||
this.selected_nodes = {};
|
||||
this.current_node = null;
|
||||
|
||||
@@ -1192,7 +1192,8 @@
|
||||
antialiasing: false,
|
||||
filter: true,
|
||||
disable_alpha: false,
|
||||
gamma: 1.0
|
||||
gamma: 1.0,
|
||||
viewport: [0,0,1,1]
|
||||
};
|
||||
this.size[0] = 130;
|
||||
}
|
||||
@@ -1200,6 +1201,7 @@
|
||||
LGraphTextureToViewport.title = "to Viewport";
|
||||
LGraphTextureToViewport.desc = "Texture to viewport";
|
||||
|
||||
LGraphTextureToViewport._prev_viewport = new Float32Array(4);
|
||||
LGraphTextureToViewport.prototype.onExecute = function() {
|
||||
var tex = this.getInputData(0);
|
||||
if (!tex) {
|
||||
@@ -1228,6 +1230,12 @@
|
||||
this.properties.filter ? gl.LINEAR : gl.NEAREST
|
||||
);
|
||||
|
||||
var old_viewport = LGraphTextureToViewport._prev_viewport;
|
||||
old_viewport.set( gl.viewport_data );
|
||||
var new_view = this.properties.viewport;
|
||||
gl.viewport( old_viewport[0] + old_viewport[2] * new_view[0], old_viewport[1] + old_viewport[3] * new_view[1], old_viewport[2] * new_view[2], old_viewport[3] * new_view[3] );
|
||||
var viewport = gl.getViewport(); //gl.getParameter(gl.VIEWPORT);
|
||||
|
||||
if (this.properties.antialiasing) {
|
||||
if (!LGraphTextureToViewport._shader) {
|
||||
LGraphTextureToViewport._shader = new GL.Shader(
|
||||
@@ -1236,7 +1244,6 @@
|
||||
);
|
||||
}
|
||||
|
||||
var viewport = gl.getViewport(); //gl.getParameter(gl.VIEWPORT);
|
||||
var mesh = Mesh.getScreenQuad();
|
||||
tex.bind(0);
|
||||
LGraphTextureToViewport._shader
|
||||
@@ -1263,6 +1270,8 @@
|
||||
tex.toViewport();
|
||||
}
|
||||
}
|
||||
|
||||
gl.viewport( old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3] );
|
||||
};
|
||||
|
||||
LGraphTextureToViewport.prototype.onGetInputs = function() {
|
||||
@@ -2664,7 +2673,7 @@
|
||||
this.addInput("Mixer", "Texture");
|
||||
|
||||
this.addOutput("Texture", "Texture");
|
||||
this.properties = { factor: 0.5, precision: LGraphTexture.DEFAULT };
|
||||
this.properties = { factor: 0.5, size_from_biggest: true, invert: false, precision: LGraphTexture.DEFAULT };
|
||||
this._uniforms = {
|
||||
u_textureA: 0,
|
||||
u_textureB: 1,
|
||||
@@ -2702,7 +2711,7 @@
|
||||
var factor = this.getInputData(3);
|
||||
|
||||
this._tex = LGraphTexture.getTargetTexture(
|
||||
texA,
|
||||
this.properties.size_from_biggest && texB.width > texA.width ? texB : texA,
|
||||
this._tex,
|
||||
this.properties.precision
|
||||
);
|
||||
@@ -2734,9 +2743,11 @@
|
||||
uniforms.u_mix.set([f, f, f, f]);
|
||||
}
|
||||
|
||||
var invert = this.properties.invert;
|
||||
|
||||
this._tex.drawTo(function() {
|
||||
texA.bind(0);
|
||||
texB.bind(1);
|
||||
texA.bind( invert ? 1 : 0 );
|
||||
texB.bind( invert ? 0 : 1 );
|
||||
if (texMix) {
|
||||
texMix.bind(2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user