diff --git a/build/litegraph.js b/build/litegraph.js index 36caf5406..573a509e0 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -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); } diff --git a/build/litegraph.min.js b/build/litegraph.min.js index 4a49b6bc1..0b08278e2 100755 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -133,104 +133,103 @@ a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in 0;bd- -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.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.5this.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;ch[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.6b[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;df.last_y&&hf.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.valuef.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;cd&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1"+ -q+""+a+"",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="";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=" ";h.close=function(){c.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};1k.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;mk.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="Search
";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";else if("enum"==g&&h.values){f=""}else if("boolean"==g)f="";else{console.warn("unknown type: "+ -g);return}var k=this.createDialog(""+b+""+f+"",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:"No color"});for(var h in k.node_colors)a=k.node_colors[h],a={value:h,content:""+h+""},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&&0Name",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){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return 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&&ec.left&&da?b:dd-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.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.5this.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;ch[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.6b[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.5f.last_y&&hf.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.valuef.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&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1"+q+""+a+"",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="";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=" "; +h.close=function(){c.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};1k.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;mk.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="Search
";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";else if("enum"==g&&h.values){f=""}else if("boolean"==g)f="";else{console.warn("unknown type: "+g);return}var k=this.createDialog(""+b+""+f+"",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:"No color"});for(var h in k.node_colors)a=k.node_colors[h],a={value:h,content:""+h+""},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&&0Name",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){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]< +b[0][0]||a[1]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&&ce.left&&d +a?b:dthis.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;ab;++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.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.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;ha.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, diff --git a/package.json b/package.json index 65b588f85..5b6e38a06 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/litegraph.js b/src/litegraph.js index 689339279..0fda270dc 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -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; diff --git a/src/nodes/gltextures.js b/src/nodes/gltextures.js index 0b37520a9..76b7fc61b 100755 --- a/src/nodes/gltextures.js +++ b/src/nodes/gltextures.js @@ -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); }