diff --git a/build/litegraph.js b/build/litegraph.js index 2c31e2795..aa1ee51ed 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -7239,7 +7239,6 @@ DelayEvent.prototype.onAction = function(action, param) DelayEvent.prototype.onExecute = function() { var dt = this.graph.elapsed_time * 1000; //in ms - console.log(this._pending); for(var i = 0; i < this._pending.length; ++i) { @@ -7332,6 +7331,7 @@ var LiteGraph = global.LiteGraph; function WidgetToggle() { this.addInput( "", "boolean" ); + this.addInput( "e", LiteGraph.ACTION ); this.addOutput( "v", "boolean" ); this.addOutput( "e", LiteGraph.EVENT ); this.properties = { font: "", value: false }; @@ -7363,6 +7363,12 @@ var LiteGraph = global.LiteGraph; ctx.textAlign = "left"; } + WidgetToggle.prototype.onAction = function(action) + { + this.properties.value = !this.properties.value; + this.trigger( "e", this.properties.value ); + } + WidgetToggle.prototype.onExecute = function() { var v = this.getInputData(0); diff --git a/build/litegraph.min.js b/build/litegraph.min.js index f5c04d616..1eeb91a9b 100755 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -1,29 +1,29 @@ (function(u){function g(){l.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear()}function e(a){this._ctor(a)}function h(a,b,d){d=d||{};this.background_image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.min_zoom=0.1;this.zoom_modify_alpha=!0;this.title_text_font="bold 14px Arial";this.inner_text_font="normal 12px Arial";this.node_title_color=l.NODE_TITLE_COLOR;this.default_link_color="#AAC";this.default_connection_color={input_off:"#AAB",input_on:"#7F7",output_off:"#AAB",output_on:"#7F7"};this.highquality_render=!0;this.editor_alpha=1;this.pause_rendering=!1;this.render_only_selected=this.clear_background=this.render_shadows= -!0;this.live_mode=!1;this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=!1;this.dragging_rectangle=null;this.always_render_background=!1;this.render_canvas_border=!0;this.render_connections_shadows=!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.connections_width=3;b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();this.autoresize=d.autoresize}function n(a, -b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function p(a,b,d,c,f,m){return da&&cb?!0:!1}function q(a,b){var d=a[0]+a[2],c=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||da&&cb?!0:!1}function q(a,b){var d=a[0]+a[2],c=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||dt.width-e.width-10&&(m=t.width-e.width-10);k>t.height-e.height-10&&(k=t.height-e.height-10)}f.style.left=m+"px";f.style.top=k+"px"}var l=u.LiteGraph={NODE_TITLE_HEIGHT:16,NODE_SLOT_HEIGHT:15,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,CANVAS_GRID_SIZE:10,NODE_TITLE_COLOR:"#222",NODE_DEFAULT_COLOR:"#999",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#AEF",NODE_DEFAULT_SHAPE:"box",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],node_images_path:"",VALID_SHAPES:["box", +"auto"},100);f.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);f.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);f.addEventListener("mousedown",function(a){if(2==a.button)return c.close(),a.preventDefault(),!0},!0);f.addEventListener("wheel",d,!0);f.addEventListener("mousewheel",d,!0);this.root=f;if(b.title){var n=document.createElement("div");n.className="litemenu-title";n.innerHTML=b.title;f.appendChild(n)}var n=0,k;for(k in a){var t= +a.constructor==Array?a[k]:k;null!=t&&t.constructor!==String&&(t=void 0===t.content?String(t):t.content);this.addItem(t,a[k],b);n++}f.addEventListener("mouseleave",function(a){c.lock||c.close(a)});k=document;b.event&&(k=b.event.target.ownerDocument);k||(k=document);k.body.appendChild(f);n=b.left||0;k=b.top||0;if(b.event){n=b.event.pageX-10;k=b.event.pageY-10;b.title&&(k-=20);b.parentMenu&&(n=b.parentMenu.root.getBoundingClientRect(),n=n.left+n.width);var t=document.body.getBoundingClientRect(),e=f.getBoundingClientRect(); +n>t.width-e.width-10&&(n=t.width-e.width-10);k>t.height-e.height-10&&(k=t.height-e.height-10)}f.style.left=n+"px";f.style.top=k+"px"}var l=u.LiteGraph={NODE_TITLE_HEIGHT:16,NODE_SLOT_HEIGHT:15,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,CANVAS_GRID_SIZE:10,NODE_TITLE_COLOR:"#222",NODE_DEFAULT_COLOR:"#999",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#AEF",NODE_DEFAULT_SHAPE:"box",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],node_images_path:"",VALID_SHAPES:["box", "round"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,proxy:null,debug:!1,throw_errors:!0,allow_scripts:!0,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;l.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,c=a.lastIndexOf("/");b.category=a.substr(0,c);b.title|| (b.title=d);if(b.prototype)for(var f in e.prototype)b.prototype[f]||(b.prototype[f]=e.prototype[f]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "box":this._shape=l.BOX_SHAPE;break;case "round":this._shape=l.ROUND_SHAPE;break;case "circle":this._shape=l.CIRCLE_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+ -a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(f in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[f].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,c){for(var f=Array(b.length),m="",k=l.getParameterNames(b),t=0;tk&&(k=f.size[0]),h+=f.size[1]+a;b+=k+a}this.setDirtyCanvas(!0,!0)};g.prototype.getTime=function(){return this.globaltime};g.prototype.getFixedTime=function(){return this.fixedtime};g.prototype.getElapsedTime=function(){return this.elapsed_time};g.prototype.sendEventToAllNodes=function(a,b,d){d=d||l.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,m=c.length;f< -m;++f){var k=c[f];if(k[a]&&k.mode==d)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[a](b)}};g.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d= +if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&clearInterval(this.execution_timer_id);this.execution_timer_id=null;this.sendEventToAllNodes("onStop")}};g.prototype.runStep=function(a,b){a=a||1;var d=l.getTime();this.globaltime=0.001*(d-this.starttime);var c=this._nodes_executable?this._nodes_executable:this._nodes;if(c){if(b){for(var f=0;fk&&(k=f.size[0]),e+=f.size[1]+a;b+=k+a}this.setDirtyCanvas(!0,!0)};g.prototype.getTime=function(){return this.globaltime};g.prototype.getFixedTime=function(){return this.fixedtime};g.prototype.getElapsedTime=function(){return this.elapsed_time};g.prototype.sendEventToAllNodes=function(a,b,d){d=d||l.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,n=c.length;f< +n;++f){var k=c[f];if(k[a]&&k.mode==d)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[a](b)}};g.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d= l.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id!a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.data=null;this.flags={}};e.prototype.configure=function(a){for(var b in a)if("console"!=b)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!= a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=l.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(var c=0;c=this.outputs.length?null:this.outputs[a]._data};e.prototype.getOutputInfo=function(a){return this.outputs? a=this.outputs.length)return null;a=this.outputs[a]; if(!a.links||0==a.links.length)return null;for(var b=[],d=0;da&&this.pos[1]-c-db)return!0;return!1};e.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var d=0,c=this.inputs.length;da&&this.pos[1]-c-db)return!0;return!1};e.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var d=0,c=this.inputs.length;d=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Node not found";if(b==this)return!1;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return l.debug&&console.log("Connect: Error, no slot of name "+d),!1}else{if(d===l.EVENT)return!1;if(!b.inputs||d>=b.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[d].link&&b.disconnectInput(d); -this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return!1;var f=b.inputs[d];if(l.isValidConnection(c.type,f.type)){var m={id:this.graph.last_link_id++,type:f.type,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:d};this.graph.links[m.id]=m;null==c.links&&(c.links=[]);c.links.push(m.id);b.inputs[d].link=m.id;if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!0,m,c);if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT, -d,!0,m,f)}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found"; -for(var c=0,f=d.links.length;c=this.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"), -!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var m=f.outputs[c.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var k=0,h=m.links.length;k=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found"; +for(var c=0,f=d.links.length;c=this.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"), +!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var n=f.outputs[c.origin_slot];if(!n||!n.links||0==n.links.length)return!1;for(var k=0,e=n.links.length;kb&&this.inputs[b].pos?[this.pos[0]+this.inputs[b].pos[0],this.pos[1]+this.inputs[b].pos[1]]:!a&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]: a?[this.pos[0],this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]};e.prototype.alignToGrid=function(){this.pos[0]=l.CANVAS_GRID_SIZE*Math.round(this.pos[0]/l.CANVAS_GRID_SIZE);this.pos[1]=l.CANVAS_GRID_SIZE*Math.round(this.pos[1]/l.CANVAS_GRID_SIZE)};e.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>e.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};e.prototype.setDirtyCanvas=function(a, b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};e.prototype.loadImage=function(a){var b=new Image;b.src=l.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};e.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;dl.getTime()-this.last_mouseclick&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a);this.processNodeDblClicked(d);m=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]])?m=!0:this.live_mode&&(m=f=!0);m||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else f=!0;!c&&f&&this.allow_dragcanvas&& +if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var f=!1;if(d&&this.allow_interaction&&!c){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode){if(d.outputs)for(var n=0,k=d.outputs.length;nl.getTime()-this.last_mouseclick&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a);this.processNodeDblClicked(d);n=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]])?n=!0:this.live_mode&&(n=f=!0);n||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else f=!0;!c&&f&&this.allow_dragcanvas&& (this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(d,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=l.getTime();this.canvas_mouse=[a.canvasX,a.canvasY];this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}};h.prototype.processMouseMove=function(a){this.autoresize&& this.resize();if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse=[a.canvasX,a.canvasY];if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.dragging_canvas)this.offset[0]+=d[0]/this.scale,this.offset[1]+=d[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas= !0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=0,f=this.graph._nodes.length;cthis.dragging_rectangle[2]&&(this.dragging_rectangle[0]+=this.dragging_rectangle[2]);0>this.dragging_rectangle[3]&&(this.dragging_rectangle[1]+=this.dragging_rectangle[3]); @@ -91,19 +91,19 @@ this.connecting_node.connect(this.connecting_slot,b,l.EVENT):(d=this.isOverNodeI -1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.resizing_node=null;else if(this.node_dragged)this.dirty_bgcanvas=this.dirty_canvas=!0,this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]),this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]),this.graph.config.align_to_grid&&this.node_dragged.alignToGrid(),this.node_dragged=null;else{b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!b&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas= !0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]]);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation(); a.preventDefault();return!1}};h.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.scale;0b&&(d*=1/1.1);this.setZoom(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};h.prototype.isOverNodeBox=function(a,b,d){var c=l.NODE_TITLE_HEIGHT;return p(b,d,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,c){if(a.inputs)for(var f= -0,m=a.inputs.length;fthis.max_zoom?this.scale=this.max_zoom:this.scaled-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}};h.prototype.drawFrontCanvas=function(){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();a.scale(this.scale,this.scale);a.translate(this.offset[0], this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;db-k._last_time&&(g=2-0.002*(b-k._last_time),n="rgba(255,255,255, "+g.toFixed(2)+")",this.renderLink(a,p,f.getConnectionPos(!0,h),k,!0,g,n))}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,f,m,k){if(this.highquality_render){var g=n(b,c);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(m)for(m=0;5>m;++m)e=(0.001*l.getTime()+0.2*m)%1,e=this.computeConnectionPoint(b,c,e),a.beginPath(),a.arc(e[0], -e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};h.prototype.computeConnectionPoint=function(a,b,c){var e=n(a,b),f=[a[0]+0.25*e,a[1]],e=[b[0]-0.25*e,b[1]],h=(1-c)*(1-c)*(1-c),k=3*(1-c)*(1-c)*c,g=3*(1-c)*c*c;c*=c*c;return[h*a[0]+k*f[0]+g*e[0]+c*b[0],h*a[1]+k*f[1]+g*e[1]+c*b[1]]};h.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width= +l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.rect(0.5*c,0.5*c,c,c));b.fill()};h.prototype.drawConnections=function(a){var b=l.getTime();a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=0,e=this.graph._nodes.length;cb-k._last_time&&(g=2-0.002*(b-k._last_time),m="rgba(255,255,255, "+g.toFixed(2)+")",this.renderLink(a,p,f.getConnectionPos(!0,h),k,!0,g,m))}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,f,g,k){if(this.highquality_render){var t=m(b,c);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(g)for(g=0;5>g;++g)e=(0.001*l.getTime()+0.2*g)%1,e=this.computeConnectionPoint(b,c,e),a.beginPath(),a.arc(e[0], +e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};h.prototype.computeConnectionPoint=function(a,b,c){var e=m(a,b),f=[a[0]+0.25*e,a[1]],e=[b[0]-0.25*e,b[1]],h=(1-c)*(1-c)*(1-c),k=3*(1-c)*(1-c)*c,g=3*(1-c)*c*c;c*=c*c;return[h*a[0]+k*f[0]+g*e[0]+c*b[0],h*a[1]+k*f[1]+g*e[1]+c*b[1]]};h.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.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)};h.prototype.switchLiveMode=function(a){if(a){var b=this,c=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*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1"+p+""+ -a+"",value:p});if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,c,e,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};h.onShowTitleEditor=function(a,b,c,e,f){function g(){f.title=n.value;k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var k=document.createElement("div");k.className="graphdialog";k.innerHTML= -"Title";var n=k.querySelector("input");n&&(n.value=f.title,n.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));a=h.active_canvas.canvas;b=a.getBoundingClientRect();e=c=-20;b&&(c-=b.left,e-=b.top);event?(k.style.left=event.pageX+c+"px",k.style.top=event.pageY+e+"px"):(k.style.left=0.5*a.width+c+"px",k.style.top=0.5*a.height+e+"px");k.querySelector("button").addEventListener("click", +function(a,b,c,e){function f(a,b){var c=e.getFirstEvent(),d=l.createNode(a.value);d&&(d.pos=g.convertEventToCanvas(c),g.graph.add(d))}var g=h.active_canvas,k=g.getCanvasWindow();a=l.getNodeTypesCategories();b=[];for(var m in a)a[m]&&b.push({value:a[m],content:a[m],has_submenu:!0});var p=new l.ContextMenu(b,{event:c,callback:function(a,b,c){a=l.getNodeTypesInCategory(a.value);b=[];for(var d in a)b.push({content:a[d].title,value:a[d].type});new l.ContextMenu(b,{event:c,callback:f,parentMenu:p},k);return!1}, +parentMenu:e},k);return!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,c,e,f){function g(a,b,c){f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value&&(f.addInput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0)))}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var m=[];if(b)for(var p in b){var q=b[p];if(q){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q}; +q[1]==l.ACTION&&(r.className="event");m.push(r)}else m.push(null)}this.onMenuNodeInputs&&(m=this.onMenuNodeInputs(m));if(m.length)return new l.ContextMenu(m,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.showMenuNodeOptionalOutputs=function(a,b,c,e,f){function g(a,b,c){if(f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)f.addOutput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0);else{a=[];for(var d in c)a.push({content:d, +value:c[d]});new l.ContextMenu(a,{event:b,callback:g,parentMenu:e,node:f});return!1}}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_outputs;f.onGetOutputs&&(b=f.onGetOutputs());var m=[];if(b)for(var p in b){var q=b[p];if(!q)m.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||-1==f.findOutputSlot(q[0])){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==l.EVENT&&(r.className="event");m.push(r)}}this.onMenuNodeOutputs&&(m=this.onMenuNodeOutputs(m)); +if(m.length)return new l.ContextMenu(m,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.onShowMenuNodeProperties=function(a,b,c,e,f){function g(a,b,c,d){f&&(b=this.getBoundingClientRect(),k.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))}if(f&&f.properties){var k=h.active_canvas;b=k.getCanvasWindow();var m=[],p;for(p in f.properties)a=void 0!==f.properties[p]?f.properties[p]:" ",a=h.decodeHTML(a),m.push({content:""+p+""+ +a+"",value:p});if(m.length)return new l.ContextMenu(m,{event:c,callback:g,parentMenu:e,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,c,e,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};h.onShowTitleEditor=function(a,b,c,e,f){function g(){f.title=m.value;k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var k=document.createElement("div");k.className="graphdialog";k.innerHTML= +"Title";var m=k.querySelector("input");m&&(m.value=f.title,m.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));a=h.active_canvas.canvas;b=a.getBoundingClientRect();e=c=-20;b&&(c-=b.left,e-=b.top);event?(k.style.left=event.pageX+c+"px",k.style.top=event.pageY+e+"px"):(k.style.left=0.5*a.width+c+"px",k.style.top=0.5*a.height+e+"px");k.querySelector("button").addEventListener("click", g);a.parentNode.appendChild(k)};h.prototype.showEditPropertyValue=function(a,b,c){function e(){f(q.value)}function f(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var h="string";null!==a.properties[b]&&(h=typeof a.properties[b]);var k=null;a.getPropertyInfo&&(k=a.getPropertyInfo(b));if(a.properties_info)for(var g=0;g";else if("enum"==h&&k.values){n=""}else"boolean"==h&&(n="");var p=this.createDialog(""+b+""+n+"",c);if("enum"==h&&k.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==h)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.value=void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())}); +b){k=a.properties_info[g];break}void 0!==k&&null!==k&&k.type&&(h=k.type);var m="";if("string"==h||"number"==h)m="";else if("enum"==h&&k.values){m=""}else"boolean"==h&&(m="");var p=this.createDialog(""+b+""+m+"",c);if("enum"==h&&k.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==h)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.value=void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())}); p.querySelector("button").addEventListener("click",e)}};h.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var e=this.canvas.getBoundingClientRect(),f=-20,h=-20;e&&(f-=e.left,h-=e.top);b.position?(f+=b.position[0],h+=b.position[1]):b.event?(f+=b.event.pageX,h+=b.event.pageY):(f+=0.5*this.canvas.width,h+=0.5*this.canvas.height);c.style.left=f+"px";c.style.top=h+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&& this.parentNode.removeChild(this)};return c};h.onMenuNodeCollapse=function(a,b,c,e,f){f.flags.collapsed=!f.flags.collapsed;f.setDirtyCanvas(!0,!0)};h.onMenuNodePin=function(a,b,c,e,f){f.pin()};h.onMenuNodeMode=function(a,b,c,e,f){new l.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(f)switch(a){case "On Event":f.mode=l.ON_EVENT;break;case "On Trigger":f.mode=l.ON_TRIGGER;break;case "Never":f.mode=l.NEVER;break;default:f.mode=l.ALWAYS}},parentMenu:e,node:f}); return!1};h.onMenuNodeColors=function(a,b,c,e,f){if(!f)throw"no node for color";b=[];for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:""+g+""},b.push(a);new l.ContextMenu(b,{event:c,callback:function(a){f&&(a=h.node_colors[a.value])&&(f.color=a.color,f.bgcolor=a.bgcolor,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeShapes=function(a,b,c,e,f){if(!f)throw"no node passed";new l.ContextMenu(l.VALID_SHAPES, @@ -148,7 +148,7 @@ callback:h.onResizeNode},{content:"Collapse",callback:h.onMenuNodeCollapse},{con (c=a.onGetInputs())&&c.length&&(b[0].disabled=!1);a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.processContextMenu=function(a,b){var c=this,e=h.active_canvas.getCanvasWindow(),f=null,g={event:b,callback:function(b,f,e){if(b)if("Remove Slot"==b.content){var k=b.slot;k.input?a.removeInput(k.slot):k.output&&a.removeOutput(k.slot)}else if("Rename Slot"==b.content){var k=b.slot,h=c.createDialog("Name", f),g=h.querySelector("input");h.querySelector("button").addEventListener("click",function(b){if(g.value){if(b=k.input?a.getInputInfo(k.slot):a.getOutputInfo(k.slot))b.label=g.value;c.setDirty(!0)}h.close()})}},node:a},k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(f=[],f.push(k.locked?"Cannot remove":{content:"Remove Slot",slot:k}),f.push({content:"Rename Slot",slot:k}),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==l.ACTION&&(g.title="Action"), k.output&&k.output.type==l.EVENT&&(g.title="Event")):f=a?this.getNodeMenuOptions(a):this.getCanvasMenuOptions();f&&new l.ContextMenu(f,g,e)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,f,h){void 0===f&&(f=5);void 0===h&&(h=f);this.beginPath();this.moveTo(a+f,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+e-h);this.quadraticCurveTo(a+c,b+e,a+c-h,b+e);this.lineTo(a+h,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a, -b+f);this.quadraticCurveTo(a,b,a+f,b)});l.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};l.distance=n;l.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")+")"};l.isInsideRectangle=p;l.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};l.isInsideBounding=function(a,b){return a[0]a[2]&&(a[2]=b);ca[3]&&(a[3]=c)};l.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};l.overlapBounding=q;l.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,f,h=0;6>h;h+=2)e="0123456789ABCDEF".indexOf(a.charAt(h)),f="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[c]=16*e+f,c++;return b};l.num2hex=function(a){for(var b="#",c,e,f=0;3>f;f++)c=a[f]/16,e=a[f]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};r.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&& f.call(this,a)}function f(a){var b=this.value,f=!0;h.current_submenu&&h.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,h,c.node);!0===e&&(f=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,h,c.node),!0===e&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks, title:b.submenu.title,autoopen:c.autoopen});f=!1}f&&!h.lock&&h.close()}var h=this;c=c||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var g=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(g=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k); @@ -159,67 +159,68 @@ b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__loo window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph); (function(u){function g(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function e(){this.size=[120,60];this.subgraph=new LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onGlobalInputAdded=this.onSubgraphNewGlobalInput.bind(this);this.subgraph.onGlobalInputRenamed=this.onSubgraphRenamedGlobalInput.bind(this);this.subgraph.onGlobalInputTypeChanged=this.onSubgraphTypeChangeGlobalInput.bind(this);this.subgraph.onGlobalOutputAdded=this.onSubgraphNewGlobalOutput.bind(this); this.subgraph.onGlobalOutputRenamed=this.onSubgraphRenamedGlobalOutput.bind(this);this.subgraph.onGlobalOutputTypeChanged=this.onSubgraphTypeChangeGlobalOutput.bind(this);this.bgcolor="#663"}function h(){var a="input_"+(1E3*Math.random()).toFixed();this.addOutput(a,null);this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var e=b.getOutputInfo(0);e.name!=c&&(e.name=c,b.graph&&b.graph.renameGlobalInput(a,c), -a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.outputs[0].type},set:function(c){b.outputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.outputs[0].type)},enumerable:!0})}function n(){var a="output_"+(1E3*Math.random()).toFixed();this.addInput(a,null);this._value=null;this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var e=b.getInputInfo(0);e.name!=c&&(e.name= +a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.outputs[0].type},set:function(c){b.outputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.outputs[0].type)},enumerable:!0})}function m(){var a="output_"+(1E3*Math.random()).toFixed();this.addInput(a,null);this._value=null;this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var e=b.getInputInfo(0);e.name!=c&&(e.name= c,b.graph&&b.graph.renameGlobalOutput(a,c),a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.inputs[0].type},set:function(c){b.inputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.inputs[0].type)},enumerable:!0})}function p(){this.addOutput("value","number");this.addProperty("value",1);this.editable={property:"value",type:"number"}}function q(){this.size=[60,20];this.addInput("value",0,{label:""});this.addOutput("value",0,{label:""});this.addProperty("value", "")}function r(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,20]}function l(){this.mode=c.ON_EVENT;this.size=[60,20];this.addProperty("msg","");this.addInput("log",c.EVENT);this.addInput("msg",0)}function s(){this.size=[60,20];this.addProperty("onExecute","");this.addInput("in","");this.addInput("in2","");this.addOutput("out","");this.addOutput("out2","");this._func=null}var c=u.LiteGraph;g.title="Time";g.desc="Time";g.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime); this.setOutputData(1,this.graph.globaltime)};c.registerNodeType("basic/time",g);e.title="Subgraph";e.desc="Graph inside a node";e.prototype.onSubgraphNewGlobalInput=function(a,b){this.addInput(a,b)};e.prototype.onSubgraphRenamedGlobalInput=function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).name=b)};e.prototype.onSubgraphTypeChangeGlobalInput=function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).type=b)};e.prototype.onSubgraphNewGlobalOutput=function(a,b){this.addOutput(a, b)};e.prototype.onSubgraphRenamedGlobalOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).name=b)};e.prototype.onSubgraphTypeChangeGlobalOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).type=b)};e.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};e.prototype.onExecute=function(){if(this.inputs)for(var a=0;aa[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};h.prototype.onMouseMove=function(c){if(this.mouse_captured){var a=this.old_y-c.canvasY;c.shiftKey&&(a*=10);if(c.metaKey||c.altKey)a*=0.1;this.old_y=c.canvasY;c=this._remainder+a/h.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+(c|0)*this.properties.step, -this.properties.min,this.properties.max);this.properties.value=c;this.setDirtyCanvas(!0)}};h.prototype.onMouseUp=function(c,a){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(a[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};s.registerNodeType("widget/number",h);n.title="Knob";n.desc="Circular controller";n.widgets=[{name:"increase",text:"+", -type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}];n.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};n.prototype.onDrawImageKnob=function(c){if(this.imgfg&&this.imgfg.width){var a=0.5*this.imgbg.width,b=this.size[0]/this.imgfg.width;c.save();c.translate(0,20);c.scale(b,b);c.drawImage(this.imgbg,0,0);c.translate(a,a); -c.rotate(2*this.value*Math.PI*6/8+10*Math.PI/8);c.translate(-a,-a);c.drawImage(this.imgfg,0,0);c.restore();this.title&&(c.font="bold 16px Criticized,Tahoma",c.fillStyle="rgba(100,100,100,0.8)",c.textAlign="center",c.fillText(this.title.toUpperCase(),0.5*this.size[0],18),c.textAlign="left")}};n.prototype.onDrawVectorKnob=function(c){if(this.imgfg&&this.imgfg.width){c.lineWidth=1;c.strokeStyle=this.mouseOver?"#FFF":"#AAA";c.fillStyle="#000";c.beginPath();c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.5* -this.properties.size,0,2*Math.PI,!0);c.stroke();0c.canvasY-this.pos[1]||s.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1; -this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0}};n.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a-0.01*(c[1]-this.oldmouse[1]);1a&&(a=0);this.value=a;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};n.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))}; -n.prototype.onMouseLeave=function(c){};n.prototype.onWidget=function(c,a){if("increase"==a.name)this.onPropertyChanged("size",this.properties.size+10);else if("decrease"==a.name)this.onPropertyChanged("size",this.properties.size-10)};n.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else if("size"==c)a=parseInt(a),this.properties[c]=a,this.size=[a+4,a+24],this.setDirtyCanvas(!0,!0);else if("min"==c||"max"==c||"value"==c)this.properties[c]=parseFloat(a);else return!1; -return!0};s.registerNodeType("widget/knob",n);p.title="H.Slider";p.desc="Linear slider controller";p.prototype.onAdded=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};p.prototype.onDrawVectorial=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.strokeStyle=this.mouseOver?"#FFF":"#AAA",c.fillStyle="#000",c.beginPath(),c.rect(2,0,this.size[0]-4,20),c.stroke(),c.fillStyle=this.properties.wcolor,c.beginPath(),c.rect(2+(this.size[0]-4-20)*this.value,0,20,20),c.fill())}; -p.prototype.onDrawImage=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.fillStyle="#000",c.fillRect(2,9,this.size[0]-4,2),c.strokeStyle="#333",c.beginPath(),c.moveTo(2,9),c.lineTo(this.size[0]-4,9),c.stroke(),c.strokeStyle="#AAA",c.beginPath(),c.moveTo(2,11),c.lineTo(this.size[0]-4,11),c.stroke(),c.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};p.prototype.onDrawForeground=function(c){this.onDrawImage(c)};p.prototype.onExecute=function(){this.properties.value= -this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};p.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};p.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a+(c[0]-this.oldmouse[0])/this.size[0]; -1a&&(a=0);this.value=a;this.oldmouse=c;this.setDirtyCanvas(!0)}};p.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};p.prototype.onMouseLeave=function(c){};p.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else return!1;return!0};s.registerNodeType("widget/hslider",p);q.title="Progress";q.desc="Shows data in linear progress";q.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};q.prototype.onDrawForeground= -function(c){c.lineWidth=1;c.fillStyle=this.properties.wcolor;var a=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),a=Math.min(1,a),a=Math.max(0,a);c.fillRect(2,2,(this.size[0]-4)*a,this.size[1]-4)};s.registerNodeType("widget/progress",q);r.title="Text";r.desc="Shows the input value";r.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];r.prototype.onDrawForeground= -function(c){c.fillStyle=this.properties.color;var a=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var b=this.properties.fontsize;c.textAlign=this.properties.align;c.font=b.toString()+"px "+this.properties.font;this.str="number"==typeof a?a.toFixed(this.properties.decimals):a;if("string"==typeof this.str){var a=this.str.split("\\n"),d;for(d in a)c.fillText(a[d], -"left"==this.properties.align?15:this.size[0]-15,-0.15*b+b*(parseInt(d)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};r.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var a=0,b;for(b in c){var d=this.last_ctx.measureText(c[b]).width;aa[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};h.prototype.onMouseMove=function(c){if(this.mouse_captured){var a=this.old_y-c.canvasY;c.shiftKey&&(a*=10);if(c.metaKey||c.altKey)a*=0.1;this.old_y=c.canvasY; +c=this._remainder+a/h.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+(c|0)*this.properties.step,this.properties.min,this.properties.max);this.properties.value=c;this.setDirtyCanvas(!0)}};h.prototype.onMouseUp=function(c,a){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(a[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))}; +s.registerNodeType("widget/number",h);m.title="Knob";m.desc="Circular controller";m.widgets=[{name:"increase",text:"+",type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}];m.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};m.prototype.onDrawImageKnob=function(c){if(this.imgfg&&this.imgfg.width){var a=0.5*this.imgbg.width, +b=this.size[0]/this.imgfg.width;c.save();c.translate(0,20);c.scale(b,b);c.drawImage(this.imgbg,0,0);c.translate(a,a);c.rotate(2*this.value*Math.PI*6/8+10*Math.PI/8);c.translate(-a,-a);c.drawImage(this.imgfg,0,0);c.restore();this.title&&(c.font="bold 16px Criticized,Tahoma",c.fillStyle="rgba(100,100,100,0.8)",c.textAlign="center",c.fillText(this.title.toUpperCase(),0.5*this.size[0],18),c.textAlign="left")}};m.prototype.onDrawVectorKnob=function(c){if(this.imgfg&&this.imgfg.width){c.lineWidth=1;c.strokeStyle= +this.mouseOver?"#FFF":"#AAA";c.fillStyle="#000";c.beginPath();c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.5*this.properties.size,0,2*Math.PI,!0);c.stroke();0c.canvasY-this.pos[1]||s.distance([c.canvasX, +c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0}};m.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a-0.01*(c[1]-this.oldmouse[1]);1a&&(a=0);this.value=a;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}}; +m.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};m.prototype.onMouseLeave=function(c){};m.prototype.onWidget=function(c,a){if("increase"==a.name)this.onPropertyChanged("size",this.properties.size+10);else if("decrease"==a.name)this.onPropertyChanged("size",this.properties.size-10)};m.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else if("size"==c)a=parseInt(a),this.properties[c]=a,this.size=[a+4,a+24],this.setDirtyCanvas(!0, +!0);else if("min"==c||"max"==c||"value"==c)this.properties[c]=parseFloat(a);else return!1;return!0};s.registerNodeType("widget/knob",m);p.title="H.Slider";p.desc="Linear slider controller";p.prototype.onAdded=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};p.prototype.onDrawVectorial=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.strokeStyle=this.mouseOver?"#FFF":"#AAA",c.fillStyle="#000",c.beginPath(),c.rect(2,0,this.size[0]-4,20),c.stroke(),c.fillStyle=this.properties.wcolor, +c.beginPath(),c.rect(2+(this.size[0]-4-20)*this.value,0,20,20),c.fill())};p.prototype.onDrawImage=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.fillStyle="#000",c.fillRect(2,9,this.size[0]-4,2),c.strokeStyle="#333",c.beginPath(),c.moveTo(2,9),c.lineTo(this.size[0]-4,9),c.stroke(),c.strokeStyle="#AAA",c.beginPath(),c.moveTo(2,11),c.lineTo(this.size[0]-4,11),c.stroke(),c.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};p.prototype.onDrawForeground= +function(c){this.onDrawImage(c)};p.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};p.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};p.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX- +this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a+(c[0]-this.oldmouse[0])/this.size[0];1a&&(a=0);this.value=a;this.oldmouse=c;this.setDirtyCanvas(!0)}};p.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};p.prototype.onMouseLeave=function(c){};p.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else return!1;return!0};s.registerNodeType("widget/hslider",p);q.title="Progress";q.desc="Shows data in linear progress";q.prototype.onExecute= +function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};q.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.wcolor;var a=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),a=Math.min(1,a),a=Math.max(0,a);c.fillRect(2,2,(this.size[0]-4)*a,this.size[1]-4)};s.registerNodeType("widget/progress",q);r.title="Text";r.desc="Shows the input value";r.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text", +text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];r.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var a=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var b=this.properties.fontsize;c.textAlign=this.properties.align;c.font=b.toString()+"px "+this.properties.font;this.str="number"==typeof a?a.toFixed(this.properties.decimals): +a;if("string"==typeof this.str){var a=this.str.split("\\n"),d;for(d in a)c.fillText(a[d],"left"==this.properties.align?15:this.size[0]-15,-0.15*b+b*(parseInt(d)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};r.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var a=0,b;for(b in c){var d=this.last_ctx.measureText(c[b]).width; +an?e.xbox.axes.lx:0,this._left_axis[1]=Math.abs(e.xbox.axes.ly)>n?e.xbox.axes.ly:0,this._right_axis[0]=Math.abs(e.xbox.axes.rx)>n?e.xbox.axes.rx:0,this._right_axis[1]=Math.abs(e.xbox.axes.ry)>n?e.xbox.axes.ry:0,this._triggers[0]=Math.abs(e.xbox.axes.ltrigger)>n?e.xbox.axes.ltrigger:0,this._triggers[1]=Math.abs(e.xbox.axes.rtrigger)>n?e.xbox.axes.rtrigger:0);if(this.outputs)for(n= -0;nm?e.xbox.axes.lx:0,this._left_axis[1]=Math.abs(e.xbox.axes.ly)>m?e.xbox.axes.ly:0,this._right_axis[0]=Math.abs(e.xbox.axes.rx)>m?e.xbox.axes.rx:0,this._right_axis[1]=Math.abs(e.xbox.axes.ry)>m?e.xbox.axes.ry:0,this._triggers[0]=Math.abs(e.xbox.axes.ltrigger)>m?e.xbox.axes.ltrigger:0,this._triggers[1]=Math.abs(e.xbox.axes.rtrigger)>m?e.xbox.axes.rtrigger:0);if(this.outputs)for(m= +0;me;e++)if(g[e]){e=g[e];g=this.xbox_mapping;g||(g=this.xbox_mapping= +!this._previous_buttons[p]&&this.triggerSlot(m,g.buttons[p])}else switch(p.name){case "button_pressed":break;case "left_axis":case "right_axis":q=g.zero;break;default:q=0}this.setOutputData(m,q)}}};g.prototype.getGamepad=function(){var e=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!e)return null;var g=e.call(navigator),e=null;this._previous_buttons.set(this._current_buttons);for(e=this.properties.gamepad_index;4>e;e++)if(g[e]){e=g[e];g=this.xbox_mapping;g||(g=this.xbox_mapping= {axes:[],buttons:{},hat:""});g.axes.lx=e.axes[0];g.axes.ly=e.axes[1];g.axes.rx=e.axes[2];g.axes.ry=e.axes[3];g.axes.ltrigger=e.buttons[6].value;g.axes.rtrigger=e.buttons[7].value;for(var p=0;p","string",{values:m.values});this.size=[60,40]}function k(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function t(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function D(){this.addInput("vec2", +this.addProperty("factor",0.1);this.size=[60,20];this._value=null}function x(){this.addInput("A","number");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","string",{values:x.values})}function f(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function n(){this.addInput("A","number");this.addInput("B", +"number");this.addOutput("out","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","string",{values:n.values});this.size=[60,40]}function k(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function t(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function D(){this.addInput("vec2", "vec2");this.addOutput("x","number");this.addOutput("y","number")}function w(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function y(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function A(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)} function C(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function B(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var v=u.LiteGraph;g.title="Converter";g.desc="type A to type B";g.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b= 0;bb&&(b=1);this.properties.samples=Math.round(b);var c=this._value (1-b)+a*b;this.setOutputData(0,this._value)};v.registerNodeType("math/tendTo",d);x.values="+-*/%^".split("");x.title="Operation";x.desc="Easy math operators";x["@OP"]={type:"enum",title:"operation",values:x.values};x.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};x.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=b:b=this.properties.B;var c=0;switch(this.properties.OP){case "+":c= a+b;break;case "-":c=a-b;break;case "x":case "X":case "*":c=a*b;break;case "/":c=a/b;break;case "%":c=a%b;break;case "^":c=Math.pow(a,b);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,c)};x.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="black",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.5*this.size[1]+v.NODE_TITLE_HEIGHT),a.textAlign="left")};v.registerNodeType("math/operation",x); f.title="Compare";f.desc="compares between two values";f.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,d=this.outputs.length;cB":value=a>b;break;case "A=B":value= -a>=b}this.setOutputData(c,value)}}};f.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};v.registerNodeType("math/compare",f);m.values="> < == != <= >=".split(" ");m["@OP"]={type:"enum",title:"operation",values:m.values};m.title="Condition";m.desc="evaluates condition between A and B";m.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a; -var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a=":c=a>=b}this.setOutputData(0,c)};v.registerNodeType("math/condition",m);k.title="Accumulate";k.desc="Increments a value every time";k.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value= +a>=b}this.setOutputData(c,value)}}};f.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};v.registerNodeType("math/compare",f);n.values="> < == != <= >=".split(" ");n["@OP"]={type:"enum",title:"operation",values:n.values};n.title="Condition";n.desc="evaluates condition between A and B";n.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a; +var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a=":c=a>=b}this.setOutputData(0,c)};v.registerNodeType("math/condition",n);k.title="Accumulate";k.desc="Increments a value every time";k.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value= null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};v.registerNodeType("math/accumulate",k);t.title="Trigonometry";t.desc="Sin Cos Tan";t.filter="shader";t.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,c=this.findInputSlot("amplitude");-1!=c&&(b=this.getInputData(c));var d=this.properties.offset,c=this.findInputSlot("offset");-1!=c&&(d=this.getInputData(c));for(var c= 0,e=this.outputs.length;ca;++a){var b=this.getInputData(a);if(null!=b){var d=this.values[a];d.push(b);d.length>c[0]&&d.shift()}}}};g.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var a=this.size,b=0.5*a[1]/this.properties.scale,d=g.colors,e=0.5*a[1];c.fillStyle="#000";c.fillRect(0,0,a[0],a[1]);c.strokeStyle="#555";c.beginPath();c.moveTo(0,e);c.lineTo(a[0], e);c.stroke();for(var f=0;4>f;++f){var h=this.values[f];c.strokeStyle=d[f];c.beginPath();var k=h[0]*b*-1+e;c.moveTo(0,Math.clamp(k,0,a[1]));for(var l=1;la&&(a=0);if(0!=c.length){var b=[0,0,0];if(0==a)b=c[0];else if(1==a)b=c[c.length-1];else{var d=(c.length-1)*a,a=c[Math.floor(d)],c=c[Math.floor(d)+1],d=d-Math.floor(d);b[0]=a[0]*(1-d)+c[0]*d;b[1]=a[1]*(1-d)+c[1]*d;b[2]=a[2]*(1-d)+c[2]*d}for(var e in b)b[e]/=255;this.boxcolor=colorToString(b);this.setOutputData(0,b)}};s.registerNodeType("color/palette",h);n.title="Frame";n.desc="Frame viewerew";n.widgets=[{name:"resize",text:"Resize box",type:"button"}, -{name:"view",text:"View Image",type:"button"}];n.prototype.onDrawBackground=function(c){this.frame&&c.drawImage(this.frame,0,0,this.size[0],this.size[1])};n.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};n.prototype.onWidget=function(c,a){if("resize"==a.name&&this.frame){var b=this.frame.width,d=this.frame.height;b||null==this.frame.videoWidth||(b=this.frame.videoWidth,d=this.frame.videoHeight);b&&d&&(this.size=[b,d]);this.setDirtyCanvas(!0,!0)}else"view"== -a.name&&this.show()};n.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};s.registerNodeType("graphics/frame",n);p.title="Image fade";p.desc="Fades between images";p.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];p.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};p.prototype.createCanvas=function(){this.canvas= +var a=this.getInputData(0);null==a&&(a=0.5);1a&&(a=0);if(0!=c.length){var b=[0,0,0];if(0==a)b=c[0];else if(1==a)b=c[c.length-1];else{var d=(c.length-1)*a,a=c[Math.floor(d)],c=c[Math.floor(d)+1],d=d-Math.floor(d);b[0]=a[0]*(1-d)+c[0]*d;b[1]=a[1]*(1-d)+c[1]*d;b[2]=a[2]*(1-d)+c[2]*d}for(var e in b)b[e]/=255;this.boxcolor=colorToString(b);this.setOutputData(0,b)}};s.registerNodeType("color/palette",h);m.title="Frame";m.desc="Frame viewerew";m.widgets=[{name:"resize",text:"Resize box",type:"button"}, +{name:"view",text:"View Image",type:"button"}];m.prototype.onDrawBackground=function(c){this.frame&&c.drawImage(this.frame,0,0,this.size[0],this.size[1])};m.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};m.prototype.onWidget=function(c,a){if("resize"==a.name&&this.frame){var b=this.frame.width,d=this.frame.height;b||null==this.frame.videoWidth||(b=this.frame.videoWidth,d=this.frame.videoHeight);b&&d&&(this.size=[b,d]);this.setDirtyCanvas(!0,!0)}else"view"== +a.name&&this.show()};m.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};s.registerNodeType("graphics/frame",m);p.title="Image fade";p.desc="Fades between images";p.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];p.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};p.prototype.createCanvas=function(){this.canvas= document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};p.prototype.onExecute=function(){var c=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;var a=this.getInputData(0);null!=a&&c.drawImage(a,0,0,this.canvas.width,this.canvas.height);a=this.getInputData(2);null==a?a=this.properties.fade:this.properties.fade=a;c.globalAlpha=a;a=this.getInputData(1);null!=a&&c.drawImage(a,0,0,this.canvas.width,this.canvas.height);c.globalAlpha= 1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};s.registerNodeType("graphics/imagefade",p);q.title="Crop";q.desc="Crop Image";q.prototype.onAdded=function(){this.createCanvas()};q.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};q.prototype.onExecute=function(){var c=this.getInputData(0);c&&(c.width?(this.canvas.getContext("2d").drawImage(c,-this.properties.x,-this.properties.y, c.width*this.properties.scale,c.height*this.properties.scale),this.setOutputData(0,this.canvas)):this.setOutputData(0,null))};q.prototype.onDrawBackground=function(c){this.flags.collapsed||this.canvas&&c.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,this.size[0],this.size[1])};q.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;"scale"==c?(this.properties[c]=parseFloat(a),0==this.properties[c]&&(this.trace("Error in scale"),this.properties[c]=1)):this.properties[c]= @@ -274,8 +275,8 @@ gl.LINEAR);this.setOutputData(0,a);for(var b=1;bb||a.height>b)c=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=c=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(c);a=this._preview_canvas;a||(this._preview_canvas=a=createCanvas(b,b));c&&c.toCanvas(a);return a};e.prototype.getResources=function(a){a[this.properties.name]=GL.Texture;return a};e.prototype.onGetInputs=function(){return[["in","Texture"]]};e.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};g.registerNodeType("texture/texture", e);var h=function(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[e.image_preview_size,e.image_preview_size]};h.title="Preview";h.desc="Show a texture in the graph canvas";h.allow_preview=!1;h.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||h.allow_preview)){var b=this.getInputData(0);if(b){var c=null,c=!b.handle&&a.webgl?b:e.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(c, -0,0,this.size[0],this.size[1]);a.restore()}}};g.registerNodeType("texture/preview",h);var n=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={name:""}};n.title="Save";n.desc="Save a texture in the repository";n.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(e.storeTexture?e.storeTexture(this.properties.name,a):e.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};g.registerNodeType("texture/save", -n);var p=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="

pixelcode must be vec3

\t\t\t

uvcode must be vec2, is optional

\t\t\t

uv: tex. coords

color: texture

colorB: textureB

time: scene time

value: input value

";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value", +0,0,this.size[0],this.size[1]);a.restore()}}};g.registerNodeType("texture/preview",h);var m=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={name:""}};m.title="Save";m.desc="Save a texture in the repository";m.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(e.storeTexture?e.storeTexture(this.properties.name,a):e.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};g.registerNodeType("texture/save", +m);var p=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="

pixelcode must be vec3

\t\t\t

uvcode must be vec2, is optional

\t\t\t

uv: tex. coords

color: texture

colorB: textureB

time: scene time

value: input value

";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value", precision:e.DEFAULT}};p.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo",values:e.MODE_VALUES}};p.title="Operation";p.desc="Texture shader operation";p.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};p.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())};p.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===e.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,d=512;a?(c=a.width,d=a.height):b&&(c=b.width,d=b.height);var f=e.getTextureType(this.properties.precision,a);this._tex=a||this._tex?e.getTargetTexture(a|| this._tex,this._tex,this.properties.precision):new GL.Texture(c,d,{type:f,format:gl.RGBA,filter:gl.LINEAR});f="";this.properties.uvcode&&(f="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(f=this.properties.uvcode));var k="";this.properties.pixelcode&&(k="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(k=this.properties.pixelcode));var g=this._shader;if(!g||this._shader_code!=f+"|"+k){try{this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER, @@ -295,18 +296,18 @@ gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Me g.registerNodeType("texture/warp",l);var s=function(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1};this.size[0]=130};s.title="to Viewport";s.desc="Texture to viewport";s.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){s._shader||(s._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,s.aa_pixel_shader));gl.getViewport();var c=Mesh.getScreenQuad();a.bind(0);s._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?(s._gamma_shader||(s._gamma_shader= new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.gamma_pixel_shader)),a.toViewport(s._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport()}};s.prototype.onGetInputs=function(){return[["gamma","number"]]};s.aa_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 uViewportSize;\n\t\t\tuniform vec2 inverseVP;\n\t\t\tuniform float u_igamma;\n\t\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\t\n\t\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t\t{\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\t\n\t\t\t\tvec2 dir;\n\t\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\t\n\t\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\t\n\t\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\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\t\n\t\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\t\n\t\t\t\t//return vec4(rgbA,1.0);\n\t\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\t\telse\n\t\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\t\tif(u_igamma != 1.0)\n\t\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\t\treturn color;\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t\t}\n\t\t\t"; -s.gamma_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_igamma;\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t\t gl_FragColor = color;\n\t\t\t}\n\t\t\t";g.registerNodeType("texture/toviewport",s);n=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1, -precision:e.DEFAULT}};n.title="Copy";n.desc="Copy Texture";n.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:e.MODE_VALUES}};n.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,c=a.height;0!=this.properties.size&&(c=b=this.properties.size);var d=this._temp_texture,f=a.type;this.properties.precision===e.LOW?f=gl.UNSIGNED_BYTE:this.properties.precision===e.HIGH&& +s.gamma_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_igamma;\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t\t gl_FragColor = color;\n\t\t\t}\n\t\t\t";g.registerNodeType("texture/toviewport",s);m=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1, +precision:e.DEFAULT}};m.title="Copy";m.desc="Copy Texture";m.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:e.MODE_VALUES}};m.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,c=a.height;0!=this.properties.size&&(c=b=this.properties.size);var d=this._temp_texture,f=a.type;this.properties.precision===e.LOW?f=gl.UNSIGNED_BYTE:this.properties.precision===e.HIGH&& (f=gl.HIGH_PRECISION_FORMAT);d&&d.width==b&&d.height==c&&d.type==f||(d=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(c)&&(d=gl.LINEAR_MIPMAP_LINEAR),this._temp_texture=new GL.Texture(b,c,{type:f,format:gl.RGBA,minFilter:d,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)}};g.registerNodeType("texture/copy", -n);var c=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:e.DEFAULT}};c.title="Downsample";c.desc="Downsample Texture";c.widgets_info={iterations:{type:"number",step:1,precision:0,min:1},precision:{widget:"combo",values:e.MODE_VALUES}};c.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D){var b=c._shader;b||(c._shader= +m);var c=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:e.DEFAULT}};c.title="Downsample";c.desc="Downsample Texture";c.widgets_info={iterations:{type:"number",step:1,precision:0,min:1},precision:{widget:"combo",values:e.MODE_VALUES}};c.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D){var b=c._shader;b||(c._shader= b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,c.pixel_shader));var d=a.width|0,f=a.height|0,k=a.type;this.properties.precision===e.LOW?k=gl.UNSIGNED_BYTE:this.properties.precision===e.HIGH&&(k=gl.HIGH_PRECISION_FORMAT);var g=this.properties.iterations||1,h=a,l=null,m=[],a={type:k,format:a.format},k=vec2.create(),n={u_offset:k};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var p=0;p>1||0;f=f>>1||0;l=GL.Texture.getTemporary(d,f,a);m.push(l);h.setParameter(GL.TEXTURE_MAG_FILTER, GL.NEAREST);h.copyTo(l,b,n);if(1==d&&1==f)break;h=l}this._texture=m.pop();for(p=0;pd;++d)c[d]=Math.random();a._shader.uniforms({u_samples_a:c.subarray(0,16),u_samples_b:c.subarray(16,32)})}d=this._temp_texture;c=gl.UNSIGNED_BYTE;b.type!=c&&(c=gl.FLOAT);d&&d.type==c||(this._temp_texture=new GL.Texture(1,1,{type:c,format:gl.RGBA,filter:gl.NEAREST})); var e=a._shader,f=this._uniforms;f.u_mipmap_offset=this.properties.mipmap_offset;this._temp_texture.drawTo(function(){b.toViewport(e,f)});this.setOutputData(0,this._temp_texture);if(this.isOutputConnected(1)||this.isOutputConnected(2))if(d=this._temp_texture.getPixels()){var k=this._luminance,c=this._temp_texture.type;k.set(d);c==gl.UNSIGNED_BYTE?vec4.scale(k,k,1/255):c!=GL.HALF_FLOAT&&c!=GL.HALF_FLOAT_OES||vec4.scale(k,k,1/65025);this.setOutputData(1,k);this.setOutputData(2,(k[0]+k[1]+k[2])/3)}}}; a.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t"; -g.registerNodeType("texture/average",a);n=function(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}};n.title="Image to Texture";n.desc="Uploads an image to the GPU";n.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,c=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var d=this._temp_texture;d&&d.width==b&&d.height==c||(this._temp_texture=new GL.Texture(b,c,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(e){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+ -e);return}this.setOutputData(0,this._temp_texture)}}};g.registerNodeType("texture/imageToTexture",n);var b=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={intensity:1,precision:e.DEFAULT,texture:null};b._shader||(b._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader))};b.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:e.MODE_VALUES}};b.title="LUT";b.desc= +g.registerNodeType("texture/average",a);m=function(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}};m.title="Image to Texture";m.desc="Uploads an image to the GPU";m.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,c=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var d=this._temp_texture;d&&d.width==b&&d.height==c||(this._temp_texture=new GL.Texture(b,c,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(e){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+ +e);return}this.setOutputData(0,this._temp_texture)}}};g.registerNodeType("texture/imageToTexture",m);var b=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={intensity:1,precision:e.DEFAULT,texture:null};b._shader||(b._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader))};b.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:e.MODE_VALUES}};b.title="LUT";b.desc= "Apply LUT to Texture";b.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===e.PASS_THROUGH)this.setOutputData(0,a);else if(a){var c=this.getInputData(1);c||(c=e.getTexture(this.properties.texture));if(c){c.bind(0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D, null);var d=this.properties.intensity;this.isInputConnected(2)&&(this.properties.intensity=d=this.getInputData(2));this._tex=e.getTargetTexture(a,this._tex,this.properties.precision);this._tex.drawTo(function(){c.bind(1);a.toViewport(b._shader,{u_texture:0,u_textureB:1,u_amount:d})});this.setOutputData(0,this._tex)}else this.setOutputData(0,a)}}};b.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_amount;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t\t mediump vec2 quad1;\n\t\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t\t mediump vec2 quad2;\n\t\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t\t highp vec2 texPos1;\n\t\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t highp vec2 texPos2;\n\t\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t\t}\n\t\t\t"; g.registerNodeType("texture/LUT",b);var d=function(){this.addInput("Texture","Texture");this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");this.properties={};d._shader||(d._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader))};d.title="Texture to Channels";d.desc="Split texture channels";d.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b=0,c=0;4>c;c++)this.isOutputConnected(c)? @@ -317,9 +318,9 @@ a[1].bind(1);a[2].bind(2);a[3].bind(3);c.uniforms({u_textureR:0,u_textureG:1,u_t g.registerNodeType("texture/channelsTexture",x);var f=function(){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};f._shader||(f._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}};f.title="Gradient";f.desc="Generates a gradient";f["@A"]={type:"color"};f["@B"]={type:"color"};f["@texture_size"]={type:"enum", values:[32,64,128,256,512]};f.prototype.onExecute=function(){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var a=GL.Mesh.getScreenQuad(),b=f._shader,c=this.getInputData(0);c||(c=this.properties.A);var d=this.getInputData(1);d||(d=this.properties.B);for(var e=2;e 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\t}\n\t\t\t"; g.registerNodeType("texture/edges",k);var t=function(){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}};t.title="Depth Range";t.desc="Generates a texture with a depth range";t.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,filter:gl.LINEAR}));var c=this._uniforms,b=this.properties.distance;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.distance=b);var d=this.properties.range;this.isInputConnected(2)&& @@ -340,10 +341,10 @@ w.final_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuni g.registerNodeType("texture/glow",w);var y=function(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}};y.title="Kuwahara Filter";y.desc="Filters a texture giving an artistic oil canvas painting";y.max_radius=10;y._shaders=[];y.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width, a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));b=this.properties.radius;b=Math.min(Math.floor(b),y.max_radius);if(0==b)this.setOutputData(0,a);else{var c=this.properties.intensity,d=g.camera_aspect;d||void 0===window.gl||(d=gl.canvas.height/gl.canvas.width);d||(d=1);d=this.properties.preserve_aspect?d:1;y._shaders[b]||(y._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,y.pixel_shader,{RADIUS:b.toFixed(0)}));var e=y._shaders[b],f=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){e.uniforms({u_texture:0, u_intensity:c,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(f)});this.setOutputData(0,this._temp_texture)}}};y.pixel_shader="\n\tprecision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_intensity;\n\tuniform vec2 u_resolution;\n\tuniform vec2 u_iResolution;\n\t#ifndef RADIUS\n\t\t#define RADIUS 7\n\t#endif\n\tvoid main() {\n\t\n\t\tconst int radius = RADIUS;\n\t\tvec2 fragCoord = v_coord;\n\t\tvec2 src_size = u_iResolution;\n\t\tvec2 uv = v_coord;\n\t\tfloat n = float((radius + 1) * (radius + 1));\n\t\tint i;\n\t\tint j;\n\t\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\t\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\t\tvec3 c;\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm0 += c;\n\t\t\t\ts0 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm1 += c;\n\t\t\t\ts1 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm2 += c;\n\t\t\t\ts2 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm3 += c;\n\t\t\t\ts3 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfloat min_sigma2 = 1e+2;\n\t\tm0 /= n;\n\t\ts0 = abs(s0 / n - m0 * m0);\n\t\t\n\t\tfloat sigma2 = s0.r + s0.g + s0.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m0, 1.0);\n\t\t}\n\t\t\n\t\tm1 /= n;\n\t\ts1 = abs(s1 / n - m1 * m1);\n\t\t\n\t\tsigma2 = s1.r + s1.g + s1.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m1, 1.0);\n\t\t}\n\t\t\n\t\tm2 /= n;\n\t\ts2 = abs(s2 / n - m2 * m2);\n\t\t\n\t\tsigma2 = s2.r + s2.g + s2.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m2, 1.0);\n\t\t}\n\t\t\n\t\tm3 /= n;\n\t\ts3 = abs(s3 / n - m3 * m3);\n\t\t\n\t\tsigma2 = s3.r + s3.g + s3.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m3, 1.0);\n\t\t}\n\t}\n\t"; -g.registerNodeType("texture/kuwahara",y);n=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:""}};n.title="Webcam";n.desc="Webcam texture";n.prototype.openStream=function(){function a(c){console.log("Webcam rejected",c);b._webcam_stream=!1;b.box_color="red"}navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL;if(navigator.getUserMedia){this._waiting_confirmation= -!0;var b=this;navigator.getUserMedia({video:!0},this.streamReady.bind(this),a)}};n.prototype.streamReady=function(a){this._webcam_stream=a;var b=this._video;b||(b=document.createElement("video"),b.autoplay=!0,b.src=window.URL.createObjectURL(a),this._video=b,b.onloadedmetadata=function(a){console.log(a)})};n.prototype.onRemoved=function(){if(this._webcam_stream){var a=this._webcam_stream.getVideoTracks();a.length&&a[0].stop();this._video=this._webcam_stream=null}};n.prototype.onDrawBackground=function(a){this.flags.collapsed|| -20>=this.size[1]||!this._video||(a.save(),a.webgl?this._temp_texture&&a.drawImage(this._temp_texture,0,0,this.size[0],this.size[1]):(a.translate(0,this.size[1]),a.scale(1,-1),a.drawImage(this._video,0,0,this.size[0],this.size[1])),a.restore())};n.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,c=this._temp_texture;c&&c.width==a&&c.height==b||(this._temp_texture= -new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._temp_texture.uploadImage(this._video);this.properties.texture_name&&(e.getTexturesContainer()[this.properties.texture_name]=this._temp_texture);this.setOutputData(0,this._temp_texture)}};g.registerNodeType("texture/webcam",n);var A=function(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:e.LOW};this._uniforms={u_texture:0,u_factor:1}};A.title="Lens FX"; +g.registerNodeType("texture/kuwahara",y);m=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:""}};m.title="Webcam";m.desc="Webcam texture";m.prototype.openStream=function(){function a(c){console.log("Webcam rejected",c);b._webcam_stream=!1;b.box_color="red"}navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL;if(navigator.getUserMedia){this._waiting_confirmation= +!0;var b=this;navigator.getUserMedia({video:!0},this.streamReady.bind(this),a)}};m.prototype.streamReady=function(a){this._webcam_stream=a;var b=this._video;b||(b=document.createElement("video"),b.autoplay=!0,b.src=window.URL.createObjectURL(a),this._video=b,b.onloadedmetadata=function(a){console.log(a)})};m.prototype.onRemoved=function(){if(this._webcam_stream){var a=this._webcam_stream.getVideoTracks();a.length&&a[0].stop();this._video=this._webcam_stream=null}};m.prototype.onDrawBackground=function(a){this.flags.collapsed|| +20>=this.size[1]||!this._video||(a.save(),a.webgl?this._temp_texture&&a.drawImage(this._temp_texture,0,0,this.size[0],this.size[1]):(a.translate(0,this.size[1]),a.scale(1,-1),a.drawImage(this._video,0,0,this.size[0],this.size[1])),a.restore())};m.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,c=this._temp_texture;c&&c.width==a&&c.height==b||(this._temp_texture= +new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._temp_texture.uploadImage(this._video);this.properties.texture_name&&(e.getTexturesContainer()[this.properties.texture_name]=this._temp_texture);this.setOutputData(0,this._temp_texture)}};g.registerNodeType("texture/webcam",m);var A=function(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:e.LOW};this._uniforms={u_texture:0,u_factor:1}};A.title="Lens FX"; A.desc="distortion and chromatic aberration";A.widgets_info={precision:{widget:"combo",values:e.MODE_VALUES}};A.prototype.onGetInputs=function(){return[["enabled","boolean"]]};A.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0))if(this.properties.precision===e.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,a);else{var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._temp_texture=new GL.Texture(a.width, a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var c=A._shader;c||(c=A._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,A.pixel_shader));var d=this.getInputData(1);null==d&&(d=this.properties.factor);var f=this._uniforms;f.u_factor=d;gl.disable(gl.DEPTH_TEST);b.drawTo(function(){a.bind(0);c.uniforms(f).draw(GL.Mesh.getScreenQuad())});this.setOutputData(0,b)}};A.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_factor;\n\t\t\tvec2 barrelDistortion(vec2 coord, float amt) {\n\t\t\t\tvec2 cc = coord - 0.5;\n\t\t\t\tfloat dist = dot(cc, cc);\n\t\t\t\treturn coord + cc * dist * amt;\n\t\t\t}\n\t\t\t\n\t\t\tfloat sat( float t )\n\t\t\t{\n\t\t\t\treturn clamp( t, 0.0, 1.0 );\n\t\t\t}\n\t\t\t\n\t\t\tfloat linterp( float t ) {\n\t\t\t\treturn sat( 1.0 - abs( 2.0*t - 1.0 ) );\n\t\t\t}\n\t\t\t\n\t\t\tfloat remap( float t, float a, float b ) {\n\t\t\t\treturn sat( (t - a) / (b - a) );\n\t\t\t}\n\t\t\t\n\t\t\tvec4 spectrum_offset( float t ) {\n\t\t\t\tvec4 ret;\n\t\t\t\tfloat lo = step(t,0.5);\n\t\t\t\tfloat hi = 1.0-lo;\n\t\t\t\tfloat w = linterp( remap( t, 1.0/6.0, 5.0/6.0 ) );\n\t\t\t\tret = vec4(lo,1.0,hi, 1.) * vec4(1.0-w, w, 1.0-w, 1.);\n\t\t\t\n\t\t\t\treturn pow( ret, vec4(1.0/2.2) );\n\t\t\t}\n\t\t\t\n\t\t\tconst float max_distort = 2.2;\n\t\t\tconst int num_iter = 12;\n\t\t\tconst float reci_num_iter_f = 1.0 / float(num_iter);\n\t\t\t\n\t\t\tvoid main()\n\t\t\t{\t\n\t\t\t\tvec2 uv=v_coord;\n\t\t\t\tvec4 sumcol = vec4(0.0);\n\t\t\t\tvec4 sumw = vec4(0.0);\t\n\t\t\t\tfor ( int i=0; i=this.size[1]||a.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};g.registerNodeType("texture/cubemap",n)}})(this); +g.registerNodeType("texture/matte",z);m=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[e.image_preview_size,e.image_preview_size]};m.title="Cubemap";m.prototype.onDropFile=function(a,b,c){a?(this._drop_texture="string"==typeof a?GL.Texture.fromURL(a):GL.Texture.fromDDSInMemory(a),this.properties.name=b):(this._drop_texture=null,this.properties.name="")};m.prototype.onExecute=function(){if(this._drop_texture)this.setOutputData(0,this._drop_texture);else if(this.properties.name){var a= +e.getTexture(this.properties.name);a&&(this._last_tex=a,this.setOutputData(0,a))}};m.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||a.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};g.registerNodeType("texture/cubemap",m)}})(this); (function(u){var g=u.LiteGraph;if("undefined"!=typeof GL){var e=function(){this.addInput("Texture","Texture");this.addInput("Aberration","number");this.addInput("Distortion","number");this.addInput("Blur","number");this.addOutput("Texture","Texture");this.properties={aberration:1,distortion:1,blur:1,precision:LGraphTexture.DEFAULT};e._shader||(e._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,e.pixel_shader),e._texture=new GL.Texture(3,1,{format:gl.RGB,wrap:gl.CLAMP_TO_EDGE,magFilter:gl.LINEAR, minFilter:gl.LINEAR,pixel_data:[255,0,0,0,255,0,0,0,255]}))};e.title="Lens";e.desc="Camera Lens distortion";e.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};e.prototype.onExecute=function(){var g=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,g);else if(g){this._tex=LGraphTexture.getTargetTexture(g,this._tex,this.properties.precision);var h=this.properties.aberration;this.isInputConnected(1)&&(h=this.getInputData(1), -this.properties.aberration=h);var l=this.properties.distortion;this.isInputConnected(2)&&(l=this.getInputData(2),this.properties.distortion=l);var n=this.properties.blur;this.isInputConnected(3)&&(n=this.getInputData(3),this.properties.blur=n);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var c=Mesh.getScreenQuad(),a=e._shader;this._tex.drawTo(function(){g.bind(0);a.uniforms({u_texture:0,u_aberration:h,u_distortion:l,u_blur:n}).draw(c)});this.setOutputData(0,this._tex)}};e.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t"; +this.properties.aberration=h);var l=this.properties.distortion;this.isInputConnected(2)&&(l=this.getInputData(2),this.properties.distortion=l);var m=this.properties.blur;this.isInputConnected(3)&&(m=this.getInputData(3),this.properties.blur=m);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var c=Mesh.getScreenQuad(),a=e._shader;this._tex.drawTo(function(){g.bind(0);a.uniforms({u_texture:0,u_aberration:h,u_distortion:l,u_blur:m}).draw(c)});this.setOutputData(0,this._tex)}};e.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t"; g.registerNodeType("fx/lens",e);u.LGraphFXLens=e;var h=function(){this.addInput("Texture","Texture");this.addInput("Blurred","Texture");this.addInput("Mask","Texture");this.addInput("Threshold","number");this.addOutput("Texture","Texture");this.properties={shape:"",size:10,alpha:1,threshold:1,high_precision:!1}};h.title="Bokeh";h.desc="applies an Bokeh effect";h.widgets_info={shape:{widget:"texture"}};h.prototype.onExecute=function(){var e=this.getInputData(0),g=this.getInputData(1),l=this.getInputData(2); -if(e&&l&&this.properties.shape){g||(g=e);var n=LGraphTexture.getTexture(this.properties.shape);if(n){var c=this.properties.threshold;this.isInputConnected(3)&&(c=this.getInputData(3),this.properties.threshold=c);var a=gl.UNSIGNED_BYTE;this.properties.high_precision&&(a=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==a&&this._temp_texture.width==e.width&&this._temp_texture.height==e.height||(this._temp_texture=new GL.Texture(e.width,e.height,{type:a,format:gl.RGBA, -filter:gl.LINEAR}));var b=h._first_shader;b||(b=h._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h._first_pixel_shader));var d=h._second_shader;d||(d=h._second_shader=new GL.Shader(h._second_vertex_shader,h._second_pixel_shader));var p=this._points_mesh;p&&p._width==e.width&&p._height==e.height&&2==p._spacing||(p=this.createPointsMesh(e.width,e.height,2));var f=Mesh.getScreenQuad(),m=this.properties.size,k=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){e.bind(0); -g.bind(1);l.bind(2);b.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[e.width,e.height]}).draw(f)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);e.bind(0);n.bind(3);d.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:k,u_threshold:c,u_pointSize:m,u_itexsize:[1/e.width,1/e.height]}).draw(p,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,e)};h.prototype.createPointsMesh=function(e,g,h){for(var n=Math.round(e/h),c=Math.round(g/ -h),a=new Float32Array(n*c*2),b=-1,d=2/e*h,p=2/g*h,f=0;f=g.NOTEON||a<=g.NOTEOFF)this.channel=c&15};Object.defineProperty(g.prototype,"velocity",{get:function(){return this.cmd==g.NOTEON?this.data[2]: -1},set:function(c){this.data[2]=c},enumerable:!0});g.notes="A A# B C C# D D# E F F# G G#".split(" ");g.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};g.computePitch=function(c){return 440*Math.pow(2,(c-69)/12)};g.prototype.getCC=function(){return this.data[1]};g.prototype.getCCValue=function(){return this.data[2]};g.prototype.getPitchBend=function(){return this.data[1]+(this.data[2]<<7)-8192};g.computePitchBend=function(c,a){return c+(a<<7)-8192};g.prototype.setCommandFromString= function(c){this.cmd=g.computeCommandFromString(c)};g.computeCommandFromString=function(c){if(!c)return 0;if(c&&c.constructor===Number)return c;c=c.toUpperCase();switch(c){case "NOTE ON":case "NOTEON":return g.NOTEON;case "NOTE OFF":case "NOTEOFF":return g.NOTEON;case "KEY PRESSURE":case "KEYPRESSURE":return g.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return g.CONTROLLERCHANGE;case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return g.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return g.CHANNELPRESSURE; @@ -394,48 +395,48 @@ case g.PROGRAMCHANGE:c+="PC "+this.data[1];break;case g.PITCHBEND:c+="PITCHBEND function(c){console.error("Failed to get MIDI access - "+c)};e.prototype.openInputPort=function(c,a){var b=this.input_ports.get("input-"+c);if(!b)return!1;e.input=this;var d=this;b.onmidimessage=function(b){var c=new g(b.data);d.updateState(c);a&&a(b.data,c);if(e.on_message)e.on_message(b.data,c)};console.log("port open: ",b);return!0};e.parseMsg=function(c){};e.prototype.updateState=function(c){switch(c.cmd){case g.NOTEON:this.state.note[c.value1|0]=c.value2;break;case g.NOTEOFF:this.state.note[c.value1| 0]=0;break;case g.CONTROLLERCHANGE:this.state.cc[c.getCC()]=c.getCCValue()}};e.prototype.sendMIDI=function(c,a){if(a){var b=this.output_ports.get("output-"+c);b&&(e.output=this,a.constructor===g?b.send(a.data):b.send(a))}};h.MIDIInterface=e;h.title="MIDI Input";h.desc="Reads MIDI from a input port";h.prototype.getPropertyInfo=function(c){if(this._midi&&"port"==c){c={};for(var a=0;athis.properties.max_value||this.trigger("on_midi",a)};s.registerNodeType("midi/filter",q);r.title="MIDIEvent";r.desc="Create a MIDI Event";r.prototype.onAction=function(c,a){"assign"==c?(this.properties.channel=a.channel,this.properties.cmd=a.cmd,this.properties.value1= a.data[1],this.properties.value2=a.data[2]):(a=new g,a.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?a.setCommandFromString(this.properties.cmd):a.cmd=this.properties.cmd,a.data[0]=a.cmd|a.channel,a.data[1]=Number(this.properties.value1),a.data[2]=Number(this.properties.value2),this.trigger("on_midi",a))};r.prototype.onExecute=function(){var c=this.properties;if(this.outputs)for(var a=0;a=this.size[0]&&(e=this.size[0]-1),a.strokeStyle="red",a.beginPath(),a.moveTo(e,d),a.lineTo(e,0),a.stroke())}};a.title="Visualization";a.desc="Audio Visualization";f.registerNodeType("audio/visualization", -a);b.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var a=this.properties.band,b=this.getInputData(1);void 0!==b&&(a=b);b=m.getAudioContext().sampleRate/this._freqs.length;b=a/b*2;b>=this._freqs.length?b=this._freqs[this._freqs.length-1]:(a=b|0,b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.properties.amplitude)}};b.prototype.onGetInputs=function(){return[["band","number"]]};b.title="Signal";b.desc="extract the signal of some frequency";f.registerNodeType("audio/signal", +n.createAudioNodeWrapper(c);c.title="Oscillator";c.desc="Oscillator";f.registerNodeType("audio/oscillator",c);a.prototype.onExecute=function(){this._last_buffer=this.getInputData(0);var a=this.getInputData(1);void 0!==a&&(this.properties.mark=a);this.setDirtyCanvas(!0,!1)};a.prototype.onDrawForeground=function(a){if(this._last_buffer){var b=this._last_buffer,c=b.length/this.size[0],d=this.size[1];a.fillStyle="black";a.fillRect(0,0,this.size[0],this.size[1]);a.strokeStyle="white";a.beginPath();var e= +0;if(this.properties.continuous){a.moveTo(e,d);for(var f=0;f=this.size[0]&&(e=this.size[0]-1),a.strokeStyle="red",a.beginPath(),a.moveTo(e,d),a.lineTo(e,0),a.stroke())}};a.title="Visualization";a.desc="Audio Visualization";f.registerNodeType("audio/visualization", +a);b.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var a=this.properties.band,b=this.getInputData(1);void 0!==b&&(a=b);b=n.getAudioContext().sampleRate/this._freqs.length;b=a/b*2;b>=this._freqs.length?b=this._freqs[this._freqs.length-1]:(a=b|0,b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.properties.amplitude)}};b.prototype.onGetInputs=function(){return[["band","number"]]};b.title="Signal";b.desc="extract the signal of some frequency";f.registerNodeType("audio/signal", b);d.prototype.onAdded=function(a){a.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};d["@code"]={widget:"code"};d.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};d.prototype.onStop=function(){this.audionode.onaudioprocess=d._bypass_function};d.prototype.onPause=function(){this.audionode.onaudioprocess=d._bypass_function};d.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};d.prototype.onExecute=function(){};d.prototype.onRemoved= function(){this.audionode.onaudioprocess=d._bypass_function};d.prototype.processCode=function(){try{this._script=new new Function("properties",this.properties.code)(this.properties),this._old_code=this.properties.code,this._callback=this._script.onaudioprocess}catch(a){console.error("Error in onaudioprocess code",a),this._callback=d._bypass_function,this.audionode.onaudioprocess=this._callback}};d.prototype.onPropertyChanged=function(a,b){"code"==a&&(this.properties.code=b,this.processCode(),this.graph&& -this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};d.default_function=function(){this.onaudioprocess=function(a){var b=a.inputBuffer;a=a.outputBuffer;for(var c=0;c