var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(y,c,k){y!=Array.prototype&&y!=Object.prototype&&(y[c]=k.value)};$jscomp.getGlobal=function(y){return"undefined"!=typeof window&&window===y?y:"undefined"!=typeof global&&null!=global?global:y};$jscomp.global=$jscomp.getGlobal(this); $jscomp.polyfill=function(y,c,k,t){if(c){k=$jscomp.global;y=y.split(".");for(t=0;tk&&(k=Math.max(0,r+k));if(null==t||t>r)t=r;t=Number(t);0>t&&(t=Math.max(0,r+t));for(k=Number(k||0);k=w}},"es6","es3");$jscomp.findInternal=function(y,c,k){y instanceof String&&(y=String(y));for(var t=y.length,r=0;rc?-k:k}},"es6","es3"); (function(y){function c(a){e.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function k(a,b,d,h,f,e){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=h;this.target_id=f;this.target_slot=e;this._data=null;this._pos=new Float32Array(2)}function t(a){this._ctor(a)}function r(a){this._ctor(a)}function w(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse= [0,0];this.element=null;this.visible_area=new Float32Array(4);a&&(this.element=a,b||this.bindEvents(a))}function g(a,b,d){this.options=d=d||{};this.background_image=g.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new w;this.zoom_modify_alpha=!0;this.title_text_font=""+e.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+e.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=e.NODE_TITLE_COLOR;this.default_link_color=e.LINK_COLOR;this.default_connection_color= {input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=!0;this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.align_to_grid=this.allow_reconnect_links=!1;this.filter=this.dragging_rectangle=null;this.set_canvas_dirty_on_mouse_event=!0; this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=e.SPLINE_LINK;this.mouse=[0,0];this.canvas_mouse=this.graph_mouse=[0,0];this.onAfterChange=this.onBeforeChange=this.onConnectingChange=this.onSelectionChange= this.onNodeMoved=this.onDrawLinkTooltip=this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.over_link_center=this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=this.ds.visible_area;this.visible_links=[];this.viewport=d.viewport||null;b&&b.attachCanvas(this);this.setCanvas(a,d.skip_events);this.clear();d.skip_render||this.startRendering();this.autoresize= d.autoresize}function B(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function z(a,b,d,h,f,e){return da&&hb?!0:!1}function F(a,b){var d=a[0]+a[2],h=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||dm.width-q.width-10&&(f= m.width-q.width-10),m.height&&a>m.height-q.height-10&&(a=m.height-q.height-10));e.style.left=f+"px";e.style.top=a+"px";b.scale&&(e.style.transform="scale("+b.scale+")")}function D(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var e=y.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999", NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3, DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{}, Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;e.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,h=a.lastIndexOf("/");b.category=a.substr(0,h);b.title||(b.title=d);if(b.prototype)for(var f in t.prototype)b.prototype[f]||(b.prototype[f]=t.prototype[f]);if(h=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype, "shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=e.BOX_SHAPE;break;case "round":this._shape=e.ROUND_SHAPE;break;case "circle":this._shape=e.CIRCLE_SHAPE;break;case "card":this._shape=e.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"), b.supported_extensions)for(f in b.supported_extensions){var u=b.supported_extensions[f];u&&u.constructor===String&&(this.node_types_by_file_extension[u.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(e.onNodeTypeRegistered)e.onNodeTypeRegistered(a,b);if(h&&e.onNodeTypeReplaced)e.onNodeTypeReplaced(a,b,h);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=0;fm&&(m=f.size[0]),q+=f.size[1]+a+e.NODE_TITLE_HEIGHT;b+=m+a}this.setDirtyCanvas(!0,!0)};c.prototype.getTime=function(){return this.globaltime}; c.prototype.getFixedTime=function(){return this.fixedtime};c.prototype.getElapsedTime=function(){return this.elapsed_time};c.prototype.sendEventToAllNodes=function(a,b,d){d=d||e.ALWAYS;var h=this._nodes_in_order?this._nodes_in_order:this._nodes;if(h)for(var f=0,u=h.length;f=e.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_ida.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.flags={}};t.prototype.configure=function(a){this.graph&&this.graph._version++; for(var b in a)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]=e.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d=this.inputs.length||null==this.inputs[a].link)){a=this.graph.links[this.inputs[a].link];if(!a)return null;if(!b)return a.data;b=this.graph.getNodeById(a.origin_id); if(!b)return a.data;if(b.updateOutputData)b.updateOutputData(a.origin_slot);else if(b.onExecute)b.onExecute();return a.data}};t.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};t.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a, b)};t.prototype.isInputConnected=function(a){return this.inputs?a=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])? this.graph.getNodeById(a.origin_id):null:null};t.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};t.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]-f-db)return!0;return!1};t.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var h=0,f=this.inputs.length;h=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;b&& b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===e.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}var h=!1;null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d),h=!0);var f=this.outputs[a];if(b.onConnectInput&& !1===b.onConnectInput(d,f.type,f,this,a))return null;var u=b.inputs[d],m=null;if(!e.isValidConnection(f.type,u.type))return this.setDirtyCanvas(!1,!0),h&&this.graph.connectionChange(this,m),null;h||this.graph.beforeChange();m=new k(++this.graph.last_link_id,u.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==f.links&&(f.links=[]);f.links.push(m.id);b.inputs[d].link=m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,m,f);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT, d,!0,m,u);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,m);return m};t.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return e.debug&& console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!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 h=0,f=d.links.length;h=this.inputs.length)return e.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;if(null!=d){this.inputs[a].link=null;var h=this.graph.links[d];if(h){var f=this.graph.getNodeById(h.origin_id); if(!f)return!1;var u=f.outputs[h.origin_slot];if(!u||!u.links||0==u.links.length)return!1;for(var m=0,q=u.links.length;mb&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&h>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/h*(b+.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]= a?this.pos[0]+f:this.pos[0]+this.size[0]+1-f;d[1]=this.pos[1]+(b+.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};t.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};t.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>t.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this, a)};t.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};t.prototype.loadImage=function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};t.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;da.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size}, enumerable:!0})};r.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};r.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};r.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d=this.viewport[0]&&h=this.viewport[1]&&dthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d= this.element.getBoundingClientRect();if(d&&(b=b||[.5*d.width,.5*d.height],d=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-d[0],a[1]-d[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};w.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};w.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};y.LGraphCanvas=e.LGraphCanvas=g;g.DEFAULT_BACKGROUND_IMAGE= "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";g.link_type_colors= {"-1":e.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};g.gradients={};g.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse= [0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};g.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};g.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};g.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==a)throw"graph cannot be the same"; this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};g.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]));this.ds.offset=[0,0];this.ds.scale=1}};g.prototype.getCurrentGraph= function(){return this.graph};g.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height); if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};g.prototype._doNothing=function(a){a.preventDefault(); return!1};g.prototype._doReturnTrue=function(a){a.preventDefault();return!0};g.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);this._touch_callback=this.touchHandler.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove", this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this._touch_callback,!0);a.addEventListener("touchmove",this._touch_callback,!0);a.addEventListener("touchend",this._touch_callback,!0);a.addEventListener("touchcancel",this._touch_callback,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown", this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};g.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback); this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this._touch_callback); this.canvas.removeEventListener("touchmove",this._touch_callback);this.canvas.removeEventListener("touchend",this._touch_callback);this.canvas.removeEventListener("touchcancel",this._touch_callback);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};g.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()}; g.prototype.enableWebGL=function(){this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};g.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};g.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};g.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow(); this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};g.prototype.stopRendering=function(){this.is_rendering=!1};g.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};g.prototype.processMouseDown=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();g.active_canvas=this;var d=this,h=a.localX,f=a.localY;this.ds.viewport=this.viewport; h=!this.viewport||this.viewport&&h>=this.viewport[0]&&h=this.viewport[1]&&fe.getTime()-this.last_mouseclick; this.mouse[0]=a.localX;this.mouse[1]=a.localY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.canvas.focus();e.closeAllContextMenus(b);if(!this.onMouse||1!=this.onMouse(a)){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,f=!0);var m=!1;if(u&&this.allow_interaction&&!f&&!this.read_only){this.live_mode|| u.flags.pinned||this.bringToFront(u);if(!this.connecting_node&&!u.flags.collapsed&&!this.live_mode)if(!f&&!1!==u.resizable&&z(a.canvasX,a.canvasY,u.pos[0]+u.size[0]-5,u.pos[1]+u.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=u,this.canvas.style.cursor="se-resize",f=!0;else{if(u.outputs)for(var q=0,c=u.outputs.length;qu.size[0]-e.NODE_TITLE_HEIGHT&&0>c[1]&&(d=this,setTimeout(function(){d.openSubgraph(u.subgraph)},10)),this.live_mode&&(q=m=!0));q||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=u),this.selected_nodes[u.id]||this.processNodeSelected(u,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(q=0;qc[0]+4||a.canvasYc[1]+4)){this.showLinkMenu(m,a);this.over_link_center=null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>B([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes()); h&&!this.read_only&&this.allow_searchbox&&this.showSearchBox(a);m=!0}!f&&m&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(u,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=e.getTime();this.last_mouse_dragging=!0;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}}}};g.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){g.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY];this.mouse[0]=b[0];this.mouse[1]=b[1];var d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(), !1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);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.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]: (this.selected_group.move(d[0]/this.ds.scale,d[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);var h=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var f=this.graph._nodes.length;b< f;++b)if(this.graph._nodes[b].mouseOver&&h!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(h){h.redraw_on_mouse&&(this.dirty_canvas=!0);if(!h.mouseOver&&(h.mouseOver=!0,this.node_over=h,this.dirty_canvas=!0,h.onMouseEnter))h.onMouseEnter(a);if(h.onMouseMove)h.onMouseMove(a,[a.canvasX-h.pos[0],a.canvasY-h.pos[1]],this);if(this.connecting_node&&(f=this._highlight_input|| [0,0],!this.isOverNodeBox(h,a.canvasX,a.canvasY))){var u=this.isOverNodeInput(h,a.canvasX,a.canvasY,f);-1!=u&&h.inputs[u]?e.isValidConnection(this.connecting_output.type,h.inputs[u].type)&&(this._highlight_input=f,this._highlight_input_slot=h.inputs[u]):this._highlight_input_slot=this._highlight_input=null}this.canvas&&(z(a.canvasX,a.canvasY,h.pos[0]+h.size[0]-5,h.pos[1]+h.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{f=null;for(b=0;bm[0]+4||a.canvasYm[1]+4)){f=u;break}}f!=this.over_link_center&&(this.over_link_center=f,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=h&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)h= this.selected_nodes[b],h.pos[0]+=d[0]/this.ds.scale,h.pos[1]+=d[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(d=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),d[0]=Math.max(b[0],d[0]),d[1]=Math.max(b[1],d[1]),this.resizing_node.setSize(d),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};g.prototype.processMouseUp=function(a){this.set_canvas_dirty_on_mouse_event&& (this.dirty_canvas=!0);if(this.graph){var b=this.getCanvasWindow().document;g.active_canvas=this;this.options.skip_events||(b.removeEventListener("mousemove",this._mousemove_callback,!0),this.canvas.addEventListener("mousemove",this._mousemove_callback,!0),b.removeEventListener("mouseup",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=e.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(console.log("foo"),this.block_click= !1);if(1==a.which)if(this.node_widget&&this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a),this.node_widget=null,this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas= !0),this.selected_group=null),this.selected_group_resizing=!1,this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var d=new Float32Array(4);this.deselectAllNodes();var h=Math.abs(this.dragging_rectangle[2]),f=Math.abs(this.dragging_rectangle[3]),u=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-f:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-h:this.dragging_rectangle[0];this.dragging_rectangle[1]=u;this.dragging_rectangle[2]= h;this.dragging_rectangle[3]=f;f=[];for(u=0;ua.click_time&&z(a.canvasX,a.canvasY,h.pos[0],h.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT)&&h.collapse();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.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged); this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{h=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!h&&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]],this);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}};g.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=a.localX,h=a.localY;if(!this.viewport||this.viewport&&d>=this.viewport[0]&&d=this.viewport[1]&&hb&&(d*=1/1.1),this.ds.changeScale(d,[a.localX,a.localY]),this.graph.change(),a.preventDefault(),!1}};g.prototype.isOverNodeBox=function(a,b,d){var h=e.NODE_TITLE_HEIGHT;return z(b,d,a.pos[0]+2,a.pos[1]+2-h,h-4,h-4)?!0:!1};g.prototype.isOverNodeInput=function(a,b,d,h){if(a.inputs)for(var f=0,e=a.inputs.length;f=this.viewport[0]&&b=this.viewport[1]&&dd-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};g.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0)); var d=this.viewport||this.dirty_area;d&&(a.save(),a.beginPath(),a.rect(d[0],d[1],d[2],d[3]),a.clip());this.clear_background&&(d?a.clearRect(d[0],d[1],d[2],d[3]):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,d?d[0]:0,d?d[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var h=0;h> ";b.fillText(h+d.getTitle(),.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&& .5this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var c=this.editor_alpha;b.globalAlpha=c;this.render_shadows&&!f?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed|| 1!=a.onDrawCollapsed(b,this)){var m=a._shape||e.BOX_SHAPE;E.set(a.size);var q=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var l=a.getTitle?a.getTitle():a.title;null!=l&&(a._collapsed_width=Math.min(a.size[0],b.measureText(l).width+2*e.NODE_TITLE_HEIGHT),E[0]=a._collapsed_width,E[1]=0)}a.clip_area&&(b.save(),b.beginPath(),m==e.BOX_SHAPE?b.rect(0,0,E[0],E[1]):m==e.ROUND_SHAPE?b.roundRect(0,0,E[0],E[1],[10]):m==e.CIRCLE_SHAPE&&b.arc(.5*E[0],.5*E[1],.5*E[0],0,2*Math.PI),b.clip());a.has_errors&& (h="red");this.drawNodeShape(a,b,E,d,h,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=q?"center":"left";b.font=this.inner_text_font;h=!f;m=this.connecting_output;b.lineWidth=1;l=0;var v=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;dthis.ds.scale,u=a._shape||a.constructor.shape||e.ROUND_SHAPE,l=a.constructor.title_mode,n=!0;l==e.TRANSPARENT_TITLE?n=!1:l==e.AUTOHIDE_TITLE&&m&&(n=!0);x[0]=0;x[1]=n?-f:0;x[2]=d[0]+1;x[3]=n?d[1]+f:d[1];m=b.globalAlpha;b.beginPath();u==e.BOX_SHAPE||q?b.fillRect(x[0],x[1],x[2],x[3]):u==e.ROUND_SHAPE||u==e.CARD_SHAPE?b.roundRect(x[0],x[1],x[2],x[3],u==e.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):u==e.CIRCLE_SHAPE&&b.arc(.5* d[0],.5*d[1],.5*d[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&n&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,x[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(n||l==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,f,d,this.ds.scale,h);else if(l!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){n=a.constructor.title_color||h;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR); if(this.use_gradients){var v=g.gradients[n];v||(v=g.gradients[n]=b.createLinearGradient(0,0,400,0),v.addColorStop(0,n),v.addColorStop(1,"#000"));b.fillStyle=v}else b.fillStyle=n;b.beginPath();u==e.BOX_SHAPE||q?b.rect(0,-f,d[0]+1,f):(u==e.ROUND_SHAPE||u==e.CARD_SHAPE)&&b.roundRect(0,-f,d[0]+1,f,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else u==e.ROUND_SHAPE||u==e.CIRCLE_SHAPE|| u==e.CARD_SHAPE?(q&&(b.fillStyle="black",b.beginPath(),b.arc(.5*f,-.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,q?b.fillRect(.5*f-5,-.5*f-5,10,10):(b.beginPath(),b.arc(.5*f,-.5*f,5,0,2*Math.PI),b.fill())):(q&&(b.fillStyle="black",b.fillRect(.5*(f-10)-1,-.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(f-10),-.5*(f+10),10,10));b.globalAlpha=m;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,c);!q&&(b.font= this.title_text_font,m=String(a.getTitle()))&&(b.fillStyle=c?e.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(m),b.fillText(m.substr(0,20),f,e.NODE_TITLE_TEXT_Y-f),b.textAlign="left"):(b.textAlign="left",b.fillText(m,f,e.NODE_TITLE_TEXT_Y-f)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(m=e.NODE_TITLE_HEIGHT,n=a.size[0]-m,v=e.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1], n+2,-m+2,m-4,m-4),b.fillStyle=v?"#888":"#555",u==e.BOX_SHAPE||q?b.fillRect(n+2,-m+2,m-4,m-4):(b.beginPath(),b.roundRect(n+2,-m+2,m-4,m-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(n+.2*m,.6*-m),b.lineTo(n+.8*m,.6*-m),b.lineTo(n+.5*m,.3*-m),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(c){if(a.onBounding)a.onBounding(x);l==e.TRANSPARENT_TITLE&&(x[1]-=f,x[3]+=f);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();u==e.BOX_SHAPE?b.rect(-6+x[0],-6+x[1],12+x[2],12+x[3]):u==e.ROUND_SHAPE||u==e.CARD_SHAPE&& a.flags.collapsed?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius]):u==e.CARD_SHAPE?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius,2,2*this.round_radius,2]):u==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0]+6,0,2*Math.PI);b.strokeStyle=e.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=h;b.globalAlpha=1}};var K=new Float32Array(4),l=new Float32Array(4),n=new Float32Array(2),v=new Float32Array(2);g.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area; K[0]=d[0]-20;K[1]=d[1]-20;K[2]=d[2]+40;K[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;d=this.graph._nodes;for(var h=0,f=d.length;hl[2]&&(l[0]+=l[2],l[2]=Math.abs(l[2]));0>l[3]&&(l[1]+=l[3],l[3]=Math.abs(l[3]));if(F(l,K)){var J=g.outputs[k];k=c.inputs[m];if(J&&k&&(g=J.dir||(g.horizontal?e.DOWN:e.RIGHT),k=k.dir||(c.horizontal?e.UP:e.LEFT),this.renderLink(a,G,r,q,!1,0,null,g,k),q&&q._last_time&&1E3>b-q._last_time)){J=2-.002*(b-q._last_time);var C=a.globalAlpha;a.globalAlpha=C*J;this.renderLink(a,G,r,q,!0,J,"white",g,k);a.globalAlpha=C}}}}}}a.globalAlpha=1};g.prototype.renderLink= function(a,b,d,h,f,c,m,q,l,n){h&&this.visible_links.push(h);!m&&h&&(m=h.color||g.link_type_colors[h.type]);m||(m=this.default_link_color);null!=h&&this.highlighted_links[h.id]&&(m="#FFF");q=q||e.RIGHT;l=l||e.LEFT;var u=B(b,d);this.render_connections_border&&.6b[1]? 0:Math.PI,a.save(),a.translate(v[0],v[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(h[0],h[1]),a.rotate(n),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill());if(c)for(a.fillStyle=m,v=0;5>v;++v)c=(.001*e.getTime()+.2*v)%1,f=this.computeConnectionPoint(b,d,c,q,l),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};g.prototype.computeConnectionPoint= function(a,b,d,h,f){h=h||e.RIGHT;f=f||e.LEFT;var c=B(a,b),m=[a[0],a[1]],q=[b[0],b[1]];switch(h){case e.LEFT:m[0]+=-.25*c;break;case e.RIGHT:m[0]+=.25*c;break;case e.UP:m[1]+=-.25*c;break;case e.DOWN:m[1]+=.25*c}switch(f){case e.LEFT:q[0]+=-.25*c;break;case e.RIGHT:q[0]+=.25*c;break;case e.UP:q[1]+=-.25*c;break;case e.DOWN:q[1]+=.25*c}h=(1-d)*(1-d)*(1-d);f=3*(1-d)*(1-d)*d;c=3*(1-d)*d*d;d*=d*d;return[h*a[0]+f*m[0]+c*q[0]+d*b[0],h*a[1]+f*m[1]+c*q[1]+d*b[1]]};g.prototype.drawExecutionOrder=function(a){a.shadowColor= "transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,d=0;dc||c>C-12||mg.last_y+k||void 0===g.last_y)){h=g.value;switch(g.type){case "button":"mousedown"===d.type&&(g.callback&&setTimeout(function(){g.callback(g,l,a,b,d)},20), this.dirty_canvas=g.clicked=!0);break;case "slider":n=Math.clamp((c-15)/(C-30),0,1);g.value=g.options.min+(g.options.max-g.options.min)*n;g.callback&&setTimeout(function(){f(g,g.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":h=g.value;if("mousemove"==d.type&&"number"==g.type)g.value+=.1*d.deltaX*(g.options.step||1),null!=g.options.min&&g.valueg.options.max&&(g.value=g.options.max);else if("mousedown"==d.type){var H= g.options.values;H&&H.constructor===Function&&(H=g.options.values(g,a));var G=null;"number"!=g.type&&(G=H.constructor===Array?H:Object.keys(H));c=40>c?-1:c>C-40?1:0;if("number"==g.type)g.value+=.1*c*(g.options.step||1),null!=g.options.min&&g.valueg.options.max&&(g.value=g.options.max);else if(c)n=-1,this.last_mouseclick=0,n=H.constructor===Object?G.indexOf(String(g.value))+c:G.indexOf(g.value)+c,n>=G.length&&(n=G.length-1),0>n&& (n=0),g.value=H.constructor===Array?H[n]:n;else{var r=H!=G?Object.values(H):H;new e.ContextMenu(r,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:function(a,b,d){H!=G&&(a=r.indexOf(a));this.value=a;f(this,a);l.dirty_canvas=!0;return!1}.bind(g)},n)}}else"mouseup"==d.type&&"number"==g.type&&(c=40>c?-1:c>C-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",g.value,function(a){this.value=Number(a);f(this,this.value)}.bind(g),d));h!=g.value&&setTimeout(function(){f(this,this.value)}.bind(g), 20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(g.value=!g.value,setTimeout(function(){f(g,g.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",g.value,function(a){this.value=a;f(this,a)}.bind(g),d,g.options?g.options.multiline:!1);break;default:g.mouse&&(this.dirty_canvas=g.mouse(d,[c,m],a))}if(h!=g.value){if(a.onWidgetChanged)a.onWidgetChanged(g.name,g.value,h,g);a.graph._version++}return g}}}return null};g.prototype.drawGroups=function(a,b){if(this.graph){a= this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var d=0;dd&&.01>b.editor_alpha&&(clearInterval(h),1>d&&(b.live_mode=!0));1"+(l.label?l.label:q)+""+a+"", value:q})}if(m.length)return new e.ContextMenu(m,{event:d,callback:function(a,b,d,h){f&&(b=this.getBoundingClientRect(),c.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))},parentMenu:h,allow_html:!0,node:f},b),!1}};g.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};g.onResizeNode=function(a,b,d,h,f){if(f){f.size=f.computeSize();if(f.onResize)f.onResize(f.size);f.setDirtyCanvas(!0,!0)}};g.prototype.showLinkMenu=function(a,b){var d=this;console.log(a); var h=new e.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,e,c){switch(b){case "Add Node":g.onMenuAdd(null,null,c,h,function(b){console.log("node autoconnect");var f=d.graph.getNodeById(a.origin_id),h=d.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&f.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==h.inputs[0].type&&(f.connect(a.origin_slot,b,0),b.connect(0,h,a.target_slot), b.pos[0]-=.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};g.onShowPropertyEditor=function(a,b,d,h,f){function e(){var b=l.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);f[c]=b;q.parentNode&&q.parentNode.removeChild(q);f.setDirtyCanvas(!0,!0)}var c=a.property||"title";b=f[c];var q=document.createElement("div");q.className="graphdialog";q.innerHTML="";q.querySelector(".name").innerText= c;var l=q.querySelector(".value");l&&(l.value=b,l.addEventListener("blur",function(a){this.focus()}),l.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)e(),a.preventDefault(),a.stopPropagation()}));b=g.active_canvas.canvas;d=b.getBoundingClientRect();var n=h=-20;d&&(h-=d.left,n-=d.top);event?(q.style.left=event.clientX+h+"px",q.style.top=event.clientY+n+"px"):(q.style.left=.5*b.width+h+"px",q.style.top=.5*b.height+n+"px");q.querySelector("button").addEventListener("click", e);b.parentNode.appendChild(q)};g.prototype.prompt=function(a,b,d,h,f){var e=this;a=a||"";var c=!1,q=document.createElement("div");q.className="graphdialog rounded";q.innerHTML=f?" ":" ";q.close=function(){e.prompt_box=null;q.parentNode&&q.parentNode.removeChild(q)};1g.search_limit)break}}n=null;if(Array.prototype.filter)n=Object.keys(e.registered_node_types).filter(h);else for(q in n=[],e.registered_node_types)h(q)&&n.push(q);for(q=0;qg.search_limit);q++);}}var f=this,c=g.active_canvas,m=c.canvas,q=m.ownerDocument||document,l=document.createElement("div");l.className="litegraph litesearchbox graphdialog rounded";l.innerHTML="Search
"; l.close=function(){f.search_box=null;q.body.focus();q.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);l.parentNode&&l.parentNode.removeChild(l)};var n=null;1m.height-200&&(v.style.maxHeight=m.height-a.layerY-20+"px");H.focus();return l};g.prototype.showEditPropertyValue=function(a,b,d){function h(){f(v.value)}function f(f){e&&e.values&&e.values.constructor===Object&&void 0!=e.values[f]&&(f=e.values[f]);"number"==typeof a.properties[b]&&(f=Number(f));if("array"==c||"object"==c)f=JSON.parse(f);a.properties[b]= f;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,f);if(d.onclose)d.onclose();g.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var e=a.getPropertyInfo(b),c=e.type,q="";if("string"==c||"number"==c||"array"==c||"object"==c)q="";else if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c)q="";else{console.warn("unknown type: "+c); return}else{q=""}var g=this.createDialog(""+(e.label?e.label:b)+""+q+"",d);if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c)(v=g.querySelector("input"))&&v.addEventListener("click",function(a){f(!!v.checked)});else{if(v=g.querySelector("input"))v.addEventListener("blur", function(a){this.focus()}),n=void 0!==a.properties[b]?a.properties[b]:"","string"!==c&&(n=JSON.stringify(n)),v.value=n,v.addEventListener("keydown",function(a){13==a.keyCode&&(h(),a.preventDefault(),a.stopPropagation())})}else{var v=g.querySelector("select");v.addEventListener("change",function(a){f(a.target.value)})}g.querySelector("button").addEventListener("click",h);return g}};g.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML= a;a=this.canvas.getBoundingClientRect();var h=-20,f=-20;a&&(h-=a.left,f-=a.top);b.position?(h+=b.position[0],f+=b.position[1]):b.event?(h+=b.event.clientX,f+=b.event.clientY):(h+=.5*this.canvas.width,f+=.5*this.canvas.height);d.style.left=h+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};g.prototype.createPanel=function(a,b){b=b||{};var d=b.window||window,h=document.createElement("div");h.className="litegraph dialog"; h.innerHTML="
";h.header=h.querySelector(".dialog-header");b.width&&(h.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(h.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){h.close()}),h.header.appendChild(b)); h.title_element=h.querySelector(".dialog-title");h.title_element.innerText=a;h.content=h.querySelector(".dialog-content");h.footer=h.querySelector(".dialog-footer");h.close=function(){this.parentNode&&this.parentNode.removeChild(this)};h.clear=function(){this.content.innerHTML=""};h.addHTML=function(a,b,d){var f=document.createElement("div");b&&(f.className=b);f.innerHTML=a;d?h.footer.appendChild(f):h.content.appendChild(f);return f};h.addButton=function(a,b,d){var f=document.createElement("button"); f.innerText=a;f.options=d;f.classList.add("btn");f.addEventListener("click",b);h.footer.appendChild(f);return f};h.addSeparator=function(){var a=document.createElement("div");a.className="separator";h.content.appendChild(a)};h.addWidget=function(a,b,c,q,l){function f(a,b){console.log("change",a,b);q.callback&&q.callback(a,b);l&&l(a,b)}q=q||{};var m=String(c);a=a.toLowerCase();"number"==a&&(m=c.toFixed(3));var n=document.createElement("div");n.className="property";n.innerHTML=""; n.querySelector(".property_name").innerText=q.label||b;var v=n.querySelector(".property_value");v.innerText=m;n.dataset.property=b;n.dataset.type=q.type||a;n.options=q;n.value=c;if("boolean"==a)n.classList.add("boolean"),c&&n.classList.add("bool-on"),n.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";f(a,this.value)});else if("string"==a||"number"==a)v.setAttribute("contenteditable", !0),v.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),v.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));f(b,a)});else if("enum"==a||"combo"==a)m=g.getPropertyPrintableValue(c,q.values),v.innerText=m,v.addEventListener("click",function(a){var b=this.parentNode.dataset.property,h=this;new e.ContextMenu(q.values||[],{event:a,className:"dark",callback:function(a, d,e){h.innerText=a;f(b,a);return!1}},d)});h.content.appendChild(n);return n};return h};g.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var d="",h;for(h in b)if(b[h]==a){d=h;break}return String(a)+" ("+d+")"}};g.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var d=this.getCanvasWindow();b=this.createPanel(a.title||"",{closable:!0,window:d});b.id="node-panel";b.node= a;b.classList.add("settings");var h=this;(function(){b.content.innerHTML="";b.addHTML(""+a.type+""+(a.constructor.desc||"")+"");b.addHTML("

Properties

");for(var d in a.properties){var e=a.properties[d],c=a.getPropertyInfo(d);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(d,b)||b.addWidget(c.widget||c.type,d,e,c,function(b,d){h.graph.beforeChange(a);a.setProperty(b,d);h.graph.afterChange();h.dirty_canvas= !0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};g.prototype.showSubgraphPropertiesDialog=function(a){function b(){h.clear();if(a.inputs)for(var d=0;d", "subgraph_property");c.dataset.name=e.name;c.dataset.slot=d;c.querySelector(".name").innerText=e.name;c.querySelector(".type").innerText=e.type;c.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var h=this.createPanel("Subgraph Inputs",{closable:!0,width:500});h.node=a;h.classList.add("subgraph_dialog"); h.addHTML(" + NameType","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(d){d=this.parentNode;var f=d.querySelector(".name").value,h=d.querySelector(".type").value;f&&-1==a.findInputSlot(f)&&(a.addInput(f,h),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(h);return h};g.prototype.showSubgraphPropertiesDialogRight= function(a){function b(){f.clear();if(a.outputs)for(var d=0;d","subgraph_property");e.dataset.name=h.name;e.dataset.slot=d;e.querySelector(".name").innerText=h.name;e.querySelector(".type").innerText=h.type;e.querySelector("button").addEventListener("click",function(d){a.removeOutput(Number(this.parentNode.dataset.slot)); b()})}}}function d(){var d=this.parentNode,f=d.querySelector(".name").value,h=d.querySelector(".type").value;f&&-1==a.findOutputSlot(f)&&(a.addOutput(f,h),d.querySelector(".name").value="",d.querySelector(".type").value="",b())}var h=this.canvas.parentNode.querySelector(".subgraph_dialog");h&&h.close();var f=this.createPanel("Subgraph Outputs",{closable:!0,width:500});f.node=a;f.classList.add("subgraph_dialog");h=f.addHTML(" + NameType", "subgraph_property extra",!0);h.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&d.apply(this)});h.querySelector("button").addEventListener("click",function(a){d.apply(this)});b();this.canvas.parentNode.appendChild(f);return f};g.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;bNo color"});for(var c in g.node_colors)a=g.node_colors[c],a={value:c,content:""+c+""},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){f&&((a=a.value?g.node_colors[a.value]:null)?f.constructor===e.LGraphGroup?f.color=a.groupcolor:(f.color=a.color,f.bgcolor=a.bgcolor): (delete f.color,delete f.bgcolor),f.setDirtyCanvas(!0,!0))},parentMenu:h,node:f});return!1};g.onMenuNodeShapes=function(a,b,d,h,f){if(!f)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){f&&(f.graph.beforeChange(f),f.shape=a,f.graph.afterChange(f),f.setDirtyCanvas(!0))},parentMenu:h,node:f});return!1};g.onMenuNodeRemove=function(a,b,d,h,f){if(!f)throw"no node passed";!1!==f.removable&&(a=f.graph,a.beforeChange(),a.remove(f),a.afterChange(),f.setDirtyCanvas(!0,!0))}; g.onMenuNodeToSubgraph=function(a,b,d,h,f){a=f.graph;if(b=g.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[f]),h=e.createNode("graph/subgraph"),h.pos=f.pos.concat(),a.add(h),h.buildFromNodes(d),b.deselectAllNodes(),f.setDirtyCanvas(!0,!0)};g.onMenuNodeClone=function(a,b,d,h,f){0!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.beforeChange(),f.graph.add(a),f.graph.afterChange(),f.setDirtyCanvas(!0,!0))};g.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"}, brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};g.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a= this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:g.onMenuAdd},{content:"Add Group",callback:g.onGroupAdd}],this._graph_stack&&0Name",f),l=c.querySelector("input");l&&e&&(l.value=e.label||"");c.querySelector("button").addEventListener("click",function(a){l.value&& (e&&(e.label=l.value),d.setDirty(!0));c.close()})}},extra:a};a&&(c.title=a.type);var l=null;a&&(l=a.getSlotInPosition(b.canvasX,b.canvasY),g.active_node=a);l?(f=[],a.getSlotMenuOptions?f=a.getSlotMenuOptions(l):(l&&l.output&&l.output.links&&l.output.links.length&&f.push({content:"Disconnect Links",slot:l}),b=l.input||l.output,f.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:l}),f.push(b.nameLocked?"Cannot rename":{content:"Rename Slot",slot:l})),c.title=(l.input?l.input.type:l.output.type)|| "*",l.input&&l.input.type==e.ACTION&&(c.title="Action"),l.output&&l.output.type==e.EVENT&&(c.title="Event")):a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(),(l=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:l,options:this.getGroupMenuOptions(l)}}));f&&new e.ContextMenu(f,c,h)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect= function(a,b,d,h,f,e){var c,l;if(0===f)this.rect(a,b,d,h);else{void 0===e&&(e=f);if(null!=f&&f.constructor===Array)if(1==f.length)var n=c=l=e=f[0];else if(2==f.length)n=e=f[0],c=l=f[1];else if(4==f.length)n=f[0],c=f[1],l=f[2],e=f[3];else return;else n=f||0,c=f||0,l=e||0,e=e||0;this.moveTo(a+n,b);this.lineTo(a+d-c,b);this.quadraticCurveTo(a+d,b,a+d,b+c);this.lineTo(a+d,b+h-e);this.quadraticCurveTo(a+d,b+h,a+d-e,b+h);this.lineTo(a+e,b+h);this.quadraticCurveTo(a,b+h,a,b+h-l);this.lineTo(a,b+l);this.quadraticCurveTo(a, b,a+n,b)}});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=B;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=z;e.growBounding=function(a,b,d){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]? !1:!0};e.overlapBounding=F;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,h,f,e=0;6>e;e+=2)h="0123456789ABCDEF".indexOf(a.charAt(e)),f="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[d]=16*h+f,d++;return b};e.num2hex=function(a){for(var b="#",d,h,f=0;3>f;f++)d=a[f]/16,h=a[f]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(h);return b};A.prototype.addItem=function(a,b,d){function h(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b= this.value,f=!0;e.current_submenu&&e.current_submenu.close(a);if(d.callback){var h=d.callback.call(this,b,d,a,e,d.node);!0===h&&(f=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(h=b.callback.call(this,b,d,a,e,d.extra),!0===h&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new e.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:e,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra, autoopen:d.autoopen});f=!1}f&&!e.lock&&e.close()}var e=this;d=d||{};var c=document.createElement("div");c.className="litemenu-entry submenu";var l=!1;if(null===b)c.classList.add("separator");else{c.innerHTML=b&&b.title?b.title:a;if(c.value=b)b.disabled&&(l=!0,c.classList.add("disabled")),(b.submenu||b.has_submenu)&&c.classList.add("has_submenu");"function"==typeof b?(c.dataset.value=a,c.onclick_callback=b):c.dataset.value=b;b.className&&(c.className+=" "+b.className)}this.root.appendChild(c);l||c.addEventListener("click", f);d.autoopen&&c.addEventListener("mouseenter",h);return c};A.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!A.isCursorOverElement(a,this.parentMenu.root)&&A.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};A.trigger= function(a,b,d,h){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,d);f.srcElement=h;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};A.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};A.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};A.isCursorOverElement=function(a,b){var d=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())? a>b.top&&ab.left&&dMath.abs(b))return h[1];a=(a-h[0])/b;return h[1]*(1-a)+f[1]*a}}return 0}};D.prototype.draw=function(a,b,d,h,f,e){if(d=this.points){this.size=b;var c=b[0]-2*this.margin; b=b[1]-2*this.margin;f=f||"#666";a.save();a.translate(this.margin,this.margin);h&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=f;e&&(a.globalAlpha=.5);a.beginPath();for(h=0;ha[1])){var h=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([e,a],30/b.ds.scale);-1==this.selected&&(b=[e/h,1-a/f],d.push(b),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};D.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var h=this.selected;if(!(0>h)){var f= (a[0]-this.margin)/(this.size[0]-2*this.margin),e=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=d[h]){var c=0==h||h==d.length-1;!c&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(h,1),this.selected=-1):(b[0]=c?0==h?0:1:Math.clamp(f,0,1),b[1]=1-Math.clamp(e,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0)}}}};D.prototype.onMouseUp=function(a, b){this.selected=-1;return!1};D.prototype.getCloserPoint=function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var h=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=d.length,c=[0,0],l=1E6,n=-1,g=0;gl||v>b||(n=g,l=v)}return n};e.CurveEditor=D;e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g, "").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>a?b:da&&(b[0]=c?this.trigger(null,e):this._pending.push([c,e])};B.prototype.onExecute=function(){var c=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1)); for(var e=0;eg[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};t.prototype.onMouseMove=function(c){if(this.mouse_captured){var e=this.old_y-c.canvasY;c.shiftKey&&(e*=10);if(c.metaKey||c.altKey)e*=.1;this.old_y=c.canvasY;c=this._remainder+e/t.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.graph._version++;this.setDirtyCanvas(!0)}};t.prototype.onMouseUp=function(c,g){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(g[1]>.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.graph._version++,this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};D.registerNodeType("widget/number",t);r.title="Combo";r.desc="Widget to select from a list"; r.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};r.prototype.onPropertyChanged=function(c,g){"values"==c?(this._values=g.split(";"),this.widget.options.values=this._values):"value"==c&&(this.widget.value=g)};D.registerNodeType("widget/combo",r);w.title="Knob";w.desc="Circular controller";w.size=[80,100];w.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min)); var e=.5*this.size[0],g=.5*this.size[1],k=.5*Math.min(this.size[0],this.size[1])-5;c.globalAlpha=1;c.save();c.translate(e,g);c.rotate(.75*Math.PI);c.fillStyle="rgba(0,0,0,0.5)";c.beginPath();c.moveTo(0,0);c.arc(0,0,k,0,1.5*Math.PI);c.fill();c.strokeStyle="black";c.fillStyle=this.properties.color;c.lineWidth=2;c.beginPath();c.moveTo(0,0);c.arc(0,0,k-4,0,1.5*Math.PI*Math.max(.01,this.value));c.closePath();c.fill();c.lineWidth=1;c.globalAlpha=1;c.restore();c.fillStyle="black";c.beginPath();c.arc(e,g, .75*k,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":this.properties.color;c.beginPath();var r=this.value*Math.PI*1.5+.75*Math.PI;c.arc(e+Math.cos(r)*k*.65,g+Math.sin(r)*k*.65,.05*k,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";c.font=Math.floor(.5*k)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision),e,g+.15*k)}};w.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=D.colorToString([this.value, this.value,this.value])};w.prototype.onMouseDown=function(c){this.center=[.5*this.size[0],.5*this.size[1]+20];this.radius=.5*this.size[0];if(20>c.canvasY-this.pos[1]||D.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};w.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value;e-=.01*(c[1]- this.oldmouse[1]);1e&&(e=0);this.value=e;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};w.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};w.prototype.onPropertyChanged=function(c,g){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(g),!0};D.registerNodeType("widget/knob",w);g.title="Inner Slider";g.prototype.onPropertyChanged=function(c, g){"value"==c&&(this.slider.value=g)};g.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};D.registerNodeType("widget/internal_slider",g);B.title="H.Slider";B.desc="Linear slider controller";B.prototype.onDrawForeground=function(c){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min));c.globalAlpha=1;c.lineWidth=1;c.fillStyle="#000";c.fillRect(2,2,this.size[0]-4,this.size[1]-4);c.fillStyle=this.properties.color; c.beginPath();c.rect(4,4,(this.size[0]-8)*this.value,this.size[1]-8);c.fill()};B.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=D.colorToString([this.value,this.value,this.value])};B.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};B.prototype.onMouseMove= function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value;e+=(c[0]-this.oldmouse[0])/this.size[0];1e&&(e=0);this.value=e;this.oldmouse=c;this.setDirtyCanvas(!0)}};B.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};B.prototype.onMouseLeave=function(c){};D.registerNodeType("widget/hslider",B);z.title="Progress";z.desc="Shows data in linear progress";z.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value= c)};z.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.color;var e=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);e=Math.min(1,e);e=Math.max(0,e);c.fillRect(2,2,(this.size[0]-4)*e,this.size[1]-4)};D.registerNodeType("widget/progress",z);F.title="Text";F.desc="Shows the input value";F.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}]; F.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var e=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 g=this.properties.fontsize;c.textAlign=this.properties.align;c.font=g.toString()+"px "+this.properties.font;this.str="number"==typeof e?e.toFixed(this.properties.decimals):e;if("string"==typeof this.str){e=this.str.split("\\n");for(var k= 0;kr?k.xbox.axes.lx:0,this._left_axis[1]=Math.abs(k.xbox.axes.ly)>r?k.xbox.axes.ly:0,this._right_axis[0]=Math.abs(k.xbox.axes.rx)>r?k.xbox.axes.rx:0,this._right_axis[1]=Math.abs(k.xbox.axes.ry)>r?k.xbox.axes.ry:0,this._triggers[0]=Math.abs(k.xbox.axes.ltrigger)>r?k.xbox.axes.ltrigger: 0,this._triggers[1]=Math.abs(k.xbox.axes.rtrigger)>r?k.xbox.axes.rtrigger:0);if(this.outputs)for(r=0;rr;r++)if(k[r]){k=k[r];r=this.xbox_mapping;r||(r=this.xbox_mapping={axes:[], buttons:{},hat:"",hatmap:c.CENTER});r.axes.lx=k.axes[0];r.axes.ly=k.axes[1];r.axes.rx=k.axes[2];r.axes.ry=k.axes[3];r.axes.ltrigger=k.buttons[6].value;r.axes.rtrigger=k.buttons[7].value;r.hat="";r.hatmap=c.CENTER;for(var w=0;ww)r.buttons[c.mapping_array[w]]=k.buttons[w].pressed,k.buttons[w].was_pressed&&this.trigger(c.mapping_array[w]+"_button_event");else switch(w){case 12:k.buttons[w].pressed&&(r.hat+="up",r.hatmap|=c.UP); break;case 13:k.buttons[w].pressed&&(r.hat+="down",r.hatmap|=c.DOWN);break;case 14:k.buttons[w].pressed&&(r.hat+="left",r.hatmap|=c.LEFT);break;case 15:k.buttons[w].pressed&&(r.hat+="right",r.hatmap|=c.RIGHT);break;case 16:r.buttons.home=k.buttons[w].pressed}k.xbox=r;return k}};c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var k=this._left_axis,w=this._right_axis;c.strokeStyle="#88A";c.strokeRect(.5*(k[0]+1)*this.size[0]-4,.5*(k[1]+1)*this.size[1]-4,8,8);c.strokeStyle="#8A8"; c.strokeRect(.5*(w[0]+1)*this.size[0]-4,.5*(w[1]+1)*this.size[1]-4,8,8);k=this.size[1]/this._current_buttons.length;c.fillStyle="#AEB";for(w=0;w","enum",{values:a.values});this.addWidget("combo", "Cond.",this.properties.OP,{property:"OP",values:a.values});this.size=[80,60]}function b(){this.addInput("in","");this.addInput("cond","boolean");this.addOutput("true","");this.addOutput("false","");this.size=[80,60]}function d(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function h(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl= "nodes/imgs/icon-sin.png"}function f(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,d){d.properties.formula=a});this.addWidget("toggle","allow",I.allow_scripts,function(a){I.allow_scripts=a});this._func=null}function u(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function m(){this.addInputs([["x", "number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function q(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function N(){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 O(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number"); this.addOutput("z","number");this.addOutput("w","number")}function M(){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 I=y.LiteGraph;c.title="Converter";c.desc="type A to type B";c.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;ba&&(a+=1024);var c=Math.floor(a);a-=c;d=g.data[c];c=g.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return d*(1-a)+c*a};g.prototype.onExecute=function(){var a= this.getInputData(0)||0,b=this.properties.octaves||1,d=0,c=1;a+=this.properties.seed||0;for(var f=this.properties.speed||1,h=0,e=0;ec);++e);a=this.properties.min;this._last_v=d/h*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};g.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};I.registerNodeType("math/noise",g);B.title="Spikes";B.desc="spike every random time"; B.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};I.registerNodeType("math/spikes",B);z.title="Clamp";z.desc= "Clamp number between min and max";z.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};z.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};I.registerNodeType("math/clamp",z);F.title="Lerp";F.desc="Linear Interpolation";F.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b= this.getInputData(1);null==b&&(b=0);var d=this.properties.f,c=this.getInputData(2);void 0!==c&&(d=c);this.setOutputData(0,a*(1-d)+b*d)};F.prototype.onGetInputs=function(){return[["f","number"]]};I.registerNodeType("math/lerp",F);A.title="Abs";A.desc="Absolute";A.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};I.registerNodeType("math/abs",A);D.title="Floor";D.desc="Floor number to remove fractional part";D.prototype.onExecute=function(){var a= this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};I.registerNodeType("math/floor",D);e.title="Frac";e.desc="Returns fractional part";e.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};I.registerNodeType("math/frac",e);G.title="Smoothstep";G.desc="Smoothstep";G.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}}; I.registerNodeType("math/smoothstep",G);E.title="Scale";E.desc="v * factor";E.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};I.registerNodeType("math/scale",E);x.title="Gate";x.desc="if v is true, then outputs A, otherwise B";x.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};I.registerNodeType("math/gate",x);K.title="Average";K.desc="Average Filter";K.prototype.onExecute=function(){var a= this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var d=a=0;db&&(b=1);this.properties.samples=Math.round(b);a=this._values;this._values=new Float32Array(this.properties.samples);a.length<=this._values.length?this._values.set(a):this._values.set(a.subarray(0,this._values.length))};I.registerNodeType("math/average", K);l.title="TendTo";l.desc="moves the output value always closer to the input";l.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};I.registerNodeType("math/tendTo",l);n.values="+ - * / % ^ max min".split(" ");n.title="Operation";n.desc="Easy math operators";n["@OP"]={type:"enum",title:"operation",values:n.values};n.size=[100,60];n.prototype.getTitle=function(){return"max"== this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};n.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};n.prototype.onPropertyChanged=function(a,b){if("OP"==a)switch(this.properties.OP){case "+":this._func=function(a,b){return a+b};break;case "-":this._func=function(a,b){return a-b};break;case "x":case "X":case "*":this._func=function(a,b){return a*b};break;case "/":this._func=function(a,b){return a/b}; break;case "%":this._func=function(a,b){return a%b};break;case "^":this._func=function(a,b){return Math.pow(a,b)};break;case "max":this._func=function(a,b){return Math.max(a,b)};break;case "min":this._func=function(a,b){return Math.min(a,b)};break;default:console.warn("Unknown operation: "+this.properties.OP),this._func=function(a){return a}}};n.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?a.constructor===Number&&(this.properties.A=a):a=this.properties.A; null!=b?this.properties.B=b:b=this.properties.B;if(a.constructor===Number)var d=this._func(a,b);else if(a.constructor===Array){d=this._result;d.length=a.length;for(var c=0;cB":h=a>b;break;case "A=B":h=a>=b}this.setOutputData(d,h)}}};v.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};I.registerNodeType("math/compare",v);I.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"}); I.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});I.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});I.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"});I.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});a.values="> < == != <= >= || &&".split(" ");a["@OP"]={type:"enum", title:"operation",values:a.values};a.title="Condition";a.desc="evaluates condition between A and B";a.prototype.getTitle=function(){return"A "+this.properties.OP+" B"};a.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 d=!0;switch(this.properties.OP){case ">":d=a>b;break;case "<":d=a=":d=a>=b;break;case "||":d=a||b;break;case "&&":d=a&&b}this.setOutputData(0,d);this.setOutputData(1,!d)};I.registerNodeType("math/condition",a);b.title="Branch";b.desc="If condition is true, outputs IN in true, otherwise in false";b.prototype.onExecute=function(){var a=this.getInputData(0);this.getInputData(1)?(this.setOutputData(0,a),this.setOutputData(1,null)):(this.setOutputData(0,null),this.setOutputData(1,a))};I.registerNodeType("math/branch",b);d.title="Accumulate";d.desc="Increments a value every time"; d.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)};I.registerNodeType("math/accumulate",d);h.title="Trigonometry";h.desc="Sin Cos Tan";h.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,d=this.findInputSlot("amplitude");-1!=d&&(b=this.getInputData(d)); var c=this.properties.offset;d=this.findInputSlot("offset");-1!=d&&(c=this.getInputData(d));d=0;for(var f=this.outputs.length;dXY";u.desc="vector 2 to components";u.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};I.registerNodeType("math3d/vec2-to-xy", u);m.title="XY->Vec2";m.desc="components to vector2";m.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this._data;d[0]=a;d[1]=b;this.setOutputData(0,d)};I.registerNodeType("math3d/xy-to-vec2",m);q.title="Vec3->XYZ";q.desc="vector 3 to components";q.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))}; I.registerNodeType("math3d/vec3-to-xyz",q);N.title="XYZ->Vec3";N.desc="components to vector3";N.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this._data;c[0]=a;c[1]=b;c[2]=d;this.setOutputData(0,c)};I.registerNodeType("math3d/xyz-to-vec3",N);O.title="Vec4->XYZW";O.desc="vector 4 to components";O.prototype.onExecute=function(){var a=this.getInputData(0); null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};I.registerNodeType("math3d/vec4-to-xyzw",O);M.title="XYZW->Vec4";M.desc="components to vector4";M.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this.getInputData(3);null==c&&(c=this.properties.w);var f=this._data;f[0]= a;f[1]=b;f[2]=d;f[3]=c;this.setOutputData(0,f)};I.registerNodeType("math3d/xyzw-to-vec4",M)})(this); (function(y){function c(){this.addInput("T","vec3");this.addInput("R","vec3");this.addInput("S","vec3");this.addOutput("mat4","mat4");this.properties={T:[0,0,0],R:[0,0,0],S:[1,1,1],R_in_degrees:!0};this._result=mat4.create();this._must_update=!0}function k(){this.addInput("A","number,vec3");this.addInput("B","number,vec3");this.addOutput("=","number,vec3");this.addProperty("OP","+","enum",{values:k.values});this._result=vec3.create()}function t(){this.addInput("in","vec3");this.addInput("f","number"); this.addOutput("out","vec3");this.properties={f:1};this._data=new Float32Array(3)}function r(){this.addInput("in","vec3");this.addOutput("out","number")}function w(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function g(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:.5};this._data=new Float32Array(3)}function B(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out", "number")}var z=y.LiteGraph;c.title="mat4";c.temp_quat=new Float32Array([0,0,0,1]);c.temp_mat4=new Float32Array(16);c.temp_vec3=new Float32Array(3);c.prototype.onPropertyChanged=function(c,e){this._must_update=!0};c.prototype.onExecute=function(){var e=this._result,l=c.temp_quat,g=c.temp_mat4,v=c.temp_vec3,a=this.getInputData(0),b=this.getInputData(1),d=this.getInputData(2);if(this._must_update||a||b||d)a=a||this.properties.T,b=b||this.properties.R,d=d||this.properties.S,mat4.identity(e),mat4.translate(e, e,a),this.properties.R_in_degrees?(v.set(b),vec3.scale(v,v,DEG2RAD),quat.fromEuler(l,v)):quat.fromEuler(l,b),mat4.fromQuat(g,l),mat4.multiply(e,e,g),mat4.scale(e,e,d);this.setOutputData(0,e)};z.registerNodeType("math3d/mat4",c);k.values="+ - * / % ^ max min dot cross".split(" ");z.registerSearchboxExtra("math3d/operation","CROSS()",{properties:{OP:"cross"},title:"CROSS()"});z.registerSearchboxExtra("math3d/operation","DOT()",{properties:{OP:"dot"},title:"DOT()"});k.title="Operation";k.desc="Easy math 3D operators"; k["@OP"]={type:"enum",title:"operation",values:k.values};k.size=[100,60];k.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};k.prototype.onExecute=function(){var c=this.getInputData(0),e=this.getInputData(1);if(null!=c&&null!=e){c.constructor===Number&&(c=[c,c,c]);e.constructor===Number&&(e=[e,e,e]);var g=this._result;switch(this.properties.OP){case "+":g=vec3.add(g,c,e);break;case "-":g=vec3.sub(g,c,e); break;case "x":case "X":case "*":g=vec3.mul(g,c,e);break;case "/":g=vec3.div(g,c,e);break;case "%":g[0]=c[0]%e[0];g[1]=c[1]%e[1];g[2]=c[2]%e[2];break;case "^":g[0]=Math.pow(c[0],e[0]);g[1]=Math.pow(c[1],e[1]);g[2]=Math.pow(c[2],e[2]);break;case "max":g[0]=Math.max(c[0],e[0]);g[1]=Math.max(c[1],e[1]);g[2]=Math.max(c[2],e[2]);break;case "min":g[0]=Math.min(c[0],e[0]),g[1]=Math.min(c[1],e[1]),g[2]=Math.min(c[2],e[2]);case "dot":g=vec3.dot(c,e);break;case "cross":vec3.cross(g,c,e);break;default:console.warn("Unknown operation: "+ this.properties.OP)}this.setOutputData(0,g)}};k.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.font="40px Arial",c.fillStyle="#666",c.textAlign="center",c.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+z.NODE_TITLE_HEIGHT)),c.textAlign="left")};z.registerNodeType("math3d/operation",k);t.title="vec3_scale";t.desc="scales the components of a vec3";t.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null==e&&(e=this.properties.f); var g=this._data;g[0]=c[0]*e;g[1]=c[1]*e;g[2]=c[2]*e;this.setOutputData(0,g)}};z.registerNodeType("math3d/vec3-scale",t);r.title="vec3_length";r.desc="returns the module of a vector";r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&this.setOutputData(0,Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]))};z.registerNodeType("math3d/vec3-length",r);w.title="vec3_normalize";w.desc="returns the vector normalized";w.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e= Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),g=this._data;g[0]=c[0]/e;g[1]=c[1]/e;g[2]=c[2]/e;this.setOutputData(0,g)}};z.registerNodeType("math3d/vec3-normalize",w);g.title="vec3_lerp";g.desc="returns the interpolated vector";g.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var g=this.getInputOrProperty("f"),v=this._data;v[0]=c[0]*(1-g)+e[0]*g;v[1]=c[1]*(1-g)+e[1]*g;v[2]=c[2]*(1-g)+e[2]*g;this.setOutputData(0,v)}}};z.registerNodeType("math3d/vec3-lerp", g);B.title="vec3_dot";B.desc="returns the dot product";B.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&this.setOutputData(0,c[0]*e[0]+c[1]*e[1]+c[2]*e[2])}};z.registerNodeType("math3d/vec3-dot",B);if(y.glMatrix){y=function(){this.addInput("vec3","vec3");this.addOutput("remap","vec3");this.addOutput("clamped","vec3");this.properties={clamp:!0,range_min:[-1,-1,0],range_max:[1,1,0],target_min:[-1,-1,0],target_max:[1,1,0]};this._value=vec3.create(); this._clamped=vec3.create()};var F=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",.5);this._value=quat.create()},A=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},D=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},e=function(){this.addInput(["quat","quat"]);this.addOutput("euler", "vec3");this._value=vec3.create()},G=function(){this.addInput("euler","vec3");this.addOutput("quat","quat");this.properties={euler:[0,0,0],use_yaw_pitch_roll:!1};this._degs=vec3.create();this._value=quat.create()},E=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},x=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1,normalize:!1};this._value=quat.create()}; x.title="Quaternion";x.desc="quaternion";x.prototype.onExecute=function(){this._value[0]=this.getInputOrProperty("x");this._value[1]=this.getInputOrProperty("y");this._value[2]=this.getInputOrProperty("z");this._value[3]=this.getInputOrProperty("w");this.properties.normalize&&quat.normalize(this._value,this._value);this.setOutputData(0,this._value)};x.prototype.onGetInputs=function(){return[["x","number"],["y","number"],["z","number"],["w","number"]]};z.registerNodeType("math3d/quaternion",x);E.title= "Rotation";E.desc="quaternion rotation";E.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.angle);var e=this.getInputData(1);null==e&&(e=this.properties.axis);c=quat.setAxisAngle(this._value,e,.0174532925*c);this.setOutputData(0,c)};z.registerNodeType("math3d/rotation",E);G.title="Euler->Quat";G.desc="Converts euler angles (in degrees) to quaternion";G.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.euler);vec3.scale(this._degs, c,DEG2RAD);this.properties.use_yaw_pitch_roll&&(this._degs=[this._degs[2],this._degs[0],this._degs[1]]);c=quat.fromEuler(this._value,this._degs);this.setOutputData(0,c)};z.registerNodeType("math3d/euler_to_quat",G);e.title="Euler->Quat";e.desc="Converts rotX,rotY,rotZ in degrees to quat";e.prototype.onExecute=function(){var c=this.getInputData(0);c&&(quat.toEuler(this._value,c),vec3.scale(this._value,this._value,DEG2RAD),this.setOutputData(0,this._value))};z.registerNodeType("math3d/quat_to_euler", e);D.title="Rot. Vec3";D.desc="rotate a point";D.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.vec);var e=this.getInputData(1);null==e?this.setOutputData(c):this.setOutputData(0,vec3.transformQuat(vec3.create(),c,e))};z.registerNodeType("math3d/rotate_vec3",D);A.title="Mult. Quat";A.desc="rotate quaternion";A.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&(c=quat.multiply(this._value,c,e),this.setOutputData(0, c))}};z.registerNodeType("math3d/mult-quat",A);F.title="Quat Slerp";F.desc="quaternion spherical interpolation";F.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var g=this.properties.factor;null!=this.getInputData(2)&&(g=this.getInputData(2));c=quat.slerp(this._value,c,e,g);this.setOutputData(0,c)}}};z.registerNodeType("math3d/quat-slerp",F);y.title="Remap Range";y.desc="remap a 3D range";y.prototype.onExecute=function(){var c=this.getInputData(0); c&&this._value.set(c);c=this.properties.range_min;for(var e=this.properties.range_max,g=this.properties.target_min,v=this.properties.target_max,a=0;3>a;++a){var b=e[a]-c[a];this._clamped[a]=Math.clamp(this._value[a],c[a],e[a]);0==b?this._value[a]=.5*(g[a]+v[a]):(b=(this._value[a]-c[a])/b,this.properties.clamp&&(b=Math.clamp(b,0,1)),this._value[a]=g[a]+b*(v[a]-g[a]))}this.setOutputData(0,this._value);this.setOutputData(1,this._clamped)};z.registerNodeType("math3d/remap_range",y)}else console.warn("No glmatrix found, some Math3D nodes may not work")})(this); (function(y){function c(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}y=y.LiteGraph;y.wrapFunctionAsNode("string/toString",function(c){if(c&&c.constructor===Object)try{return JSON.stringify(c)}catch(t){}return String(c)},[""],"String");y.wrapFunctionAsNode("string/compare",function(c,t){return c==t},["string","string"],"boolean");y.wrapFunctionAsNode("string/concatenate", function(c,t){return void 0===c?t:void 0===t?c:c+t},["string","string"],"string");y.wrapFunctionAsNode("string/contains",function(c,t){return void 0===c||void 0===t?!1:-1!=c.indexOf(t)},["string","string"],"boolean");y.wrapFunctionAsNode("string/toUpperCase",function(c){return null!=c&&c.constructor===String?c.toUpperCase():c},["string"],"string");y.wrapFunctionAsNode("string/split",function(c,t){null==t&&(t=this.properties.separator);if(null==c)return[];if(c.constructor===String)return c.split(t|| " ");if(c.constructor===Array){for(var k=[],w=0;we;++e){var g=this.getInputData(e);if(null!=g){var k=this.values[e];k.push(g);k.length>c[0]&&k.shift()}}}};c.prototype.onDrawBackground=function(e){if(!this.flags.collapsed){var g= this.size,k=.5*g[1]/this.properties.scale,r=c.colors,l=.5*g[1];e.fillStyle="#000";e.fillRect(0,0,g[0],g[1]);e.strokeStyle="#555";e.beginPath();e.moveTo(0,l);e.lineTo(g[0],l);e.stroke();if(this.inputs)for(var n=0;4>n;++n){var v=this.values[n];if(this.inputs[n]&&this.inputs[n].link){e.strokeStyle=r[n];e.beginPath();var a=v[0]*k*-1+l;e.moveTo(0,Math.clamp(a,0,g[1]));for(var b=1;be&&(e=0);if(0!=c.length){var g=[0,0,0];if(0==e)g=c[0];else if(1==e)g=c[c.length- 1];else{var k=(c.length-1)*e;e=c[Math.floor(k)];c=c[Math.floor(k)+1];k-=Math.floor(k);g[0]=e[0]*(1-k)+c[0]*k;g[1]=e[1]*(1-k)+c[1]*k;g[2]=e[2]*(1-k)+c[2]*k}for(e=0;e=c&&(this._video.currentTime=c*this._video.duration,this._video.pause()); this._video.dirty=!0;this.setOutputData(0,this._video);this.setOutputData(1,this._video.currentTime);this.setOutputData(2,this._video.duration);this.setDirtyCanvas(!0)}};A.prototype.onStart=function(){this.play()};A.prototype.onStop=function(){this.stop()};A.prototype.loadVideo=function(c){this._video_url=c;var g=c.substr(0,10).indexOf(":"),k="";-1!=g&&(k=c.substr(0,g));g="";k&&(g=c.substr(0,c.indexOf("/",k.length+3)),g=g.substr(k.length+3));this.properties.use_proxy&&k&&e.proxy&&g!=location.host&& (c=e.proxy+c.substr(c.indexOf(":")+3));this._video=document.createElement("video");this._video.src=c;this._video.type="type=video/mp4";this._video.muted=!0;this._video.autoplay=!0;var r=this;this._video.addEventListener("loadedmetadata",function(c){console.log("Duration: "+this.duration+" seconds");console.log("Size: "+this.videoWidth+","+this.videoHeight);r.setDirtyCanvas(!0);this.width=this.videoWidth;this.height=this.videoHeight});this._video.addEventListener("progress",function(c){console.log("video loading...")}); this._video.addEventListener("error",function(c){console.error("Error loading video: "+this.src);if(this.error)switch(this.error.code){case this.error.MEDIA_ERR_ABORTED:console.error("You stopped the video.");break;case this.error.MEDIA_ERR_NETWORK:console.error("Network error - please try again later.");break;case this.error.MEDIA_ERR_DECODE:console.error("Video is broken..");break;case this.error.MEDIA_ERR_SRC_NOT_SUPPORTED:console.error("Sorry, your browser can't play this video.")}});this._video.addEventListener("ended", function(c){console.log("Video Ended.");this.play()})};A.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"url"==c&&""!=e&&this.loadVideo(e);return!0};A.prototype.play=function(){this._video&&this._video.videoWidth&&this._video.play()};A.prototype.playPause=function(){this._video&&(this._video.paused?this.play():this.pause())};A.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};A.prototype.pause=function(){this._video&&(console.log("Video paused"), this._video.pause())};A.prototype.onWidget=function(c,e){};e.registerNodeType("graphics/video",A);D.title="Webcam";D.desc="Webcam image";D.is_webcam_open=!1;D.prototype.openStream=function(){if(navigator.mediaDevices.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:this.properties.filterFacingMode?{facingMode:this.properties.facingMode}:!0}).then(this.streamReady.bind(this)).catch(function(e){console.log("Webcam rejected",e);c._webcam_stream=!1;D.is_webcam_open= !1;c.boxcolor="red";c.trigger("stream_error")});var c=this}else console.log("getUserMedia() is not supported in your browser, use chrome and enable WebRTC from about://flags")};D.prototype.closeStream=function(){if(this._webcam_stream){var c=this._webcam_stream.getTracks();if(c.length)for(var e=0;e=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};D.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",e.EVENT],["stream_closed",e.EVENT],["stream_error",e.EVENT]]};e.registerNodeType("graphics/webcam",D)})(this); (function(y){function c(){this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",filter:!0};this.size=[c.image_preview_size,c.image_preview_size]}function k(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[c.image_preview_size,c.image_preview_size]}function t(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",generate_mipmaps:!1}}function r(){this.addInput("Texture", "Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="

pixelcode must be vec3, uvcode must be vec2, is optional

\t\t

uv: tex. coords

color: texture colorB: textureB

time: scene time value: input value

For multiline you must type: result = ...

";this.properties={value:1,pixelcode:"color + colorB * value",uvcode:"",precision:c.DEFAULT}; this.has_error=!1}function w(){this.addOutput("out","Texture");this.properties={code:"",u_value:1,u_color:[1,1,1,1],width:512,height:512,precision:c.DEFAULT};this.properties.code=w.pixel_shader;this._uniforms={u_value:1,u_color:vec4.create(),in_texture:0,texSize:vec4.create(),time:0}}function g(){this.addInput("in","Texture");this.addInput("scale","vec2");this.addInput("offset","vec2");this.addOutput("out","Texture");this.properties={offset:vec2.fromValues(0,0),scale:vec2.fromValues(1,1),precision:c.DEFAULT}} function B(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}function z(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1,viewport:[0,0,1,1]};this.size[0]=130}function F(){this.addInput("Texture", "Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function A(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function D(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:[512,512],generate_mipmaps:!1,precision:c.DEFAULT}}function e(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg", "vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)}function G(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function E(){this.addInput("in","Texture");this.addOutput("avg","Texture");this.addOutput("array","Texture");this.properties= {samples:64,frames_interval:1};this._uniforms={u_texture:0,u_textureB:1,u_samples:this.properties.samples,u_isamples:1/this.properties.samples};this.frame=0}function x(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}}function K(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={enabled:!0,intensity:1,precision:c.DEFAULT,texture:null};K._shader||(K._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER, K.pixel_shader))}function l(){this.addInput("Texture","Texture");this.addInput("Atlas","Texture");this.addOutput("","Texture");this.properties={enabled:!0,num_row_symbols:4,symbol_size:16,brightness:1,colorize:!1,filter:!1,invert:!1,precision:c.DEFAULT,generate_mipmaps:!1,texture:null};l._shader||(l._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,l.pixel_shader));this._uniforms={u_texture:0,u_textureB:1,u_row_simbols:4,u_simbol_size:16,u_res:vec2.create()}}function n(){this.addInput("Texture","Texture"); this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");n._shader||(n._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n.pixel_shader))}function v(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,R:1,G:1,B:1,A:1};this._color=vec4.create();this._uniforms={u_textureR:0,u_textureG:1,u_textureB:2, u_textureA:3,u_color:this._color}}function a(){this.addOutput("Texture","Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:c.DEFAULT}}function b(){this.addInput("A","color");this.addInput("B","color");this.addOutput("Texture","Texture");this.properties={angle:0,scale:1,A:[0,0,0],B:[1,1,1],texture_size:32};b._shader||(b._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}}function d(){this.addInput("A", "Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={factor:.5,size_from_biggest:!0,invert:!1,precision:c.DEFAULT};this._uniforms={u_textureA:0,u_textureB:1,u_textureMix:2,u_mix:vec4.create()}}function h(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:c.DEFAULT};h._shader||(h._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h.pixel_shader))}function f(){this.addInput("Texture", "Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}}function u(){this.addInput("Texture","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,invert:!1};this._uniforms={u_texture:0,u_camera_planes:null,u_ires:vec2.create()}}function m(){this.addInput("Texture", "Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1],precision:c.DEFAULT}}function q(){this.intensity=.5;this.persistence=.6;this.iterations=8;this.threshold=.8;this.scale=1;this.dirt_texture=null;this.dirt_factor=.5;this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function N(){this.addInput("in", "Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:.99,iterations:16,threshold:0,scale:1,dirt_factor:.5,precision:c.DEFAULT};this.fx=new q}function O(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}}function M(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79, phi:.017}}function I(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function J(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:c.LOW};this._uniforms={u_texture:0,u_factor:1}}function C(){this.addInput("in","");this.properties={precision:c.LOW,width:0,height:0,channels:1};this.addOutput("out","Texture")}function H(){this.addInput("in", "Texture");this.addOutput("out","Texture");this.properties={precision:c.LOW,split_channels:!1};this._values=new Uint8Array(1024);this._values.fill(255);this._curve_texture=null;this._uniforms={u_texture:0,u_curve:1,u_range:1};this._must_update=!0;this._points={RGB:[[0,0],[1,1]],R:[[0,0],[1,1]],G:[[0,0],[1,1]],B:[[0,0],[1,1]]};this.curve_editor=null;this.addWidget("toggle","Split Channels",!1,"split_channels");this.addWidget("combo","Channel","RGB",{values:["RGB","R","G","B"]});this.curve_offset=68; this.size=[240,160]}function P(){this.addInput("in","Texture");this.addInput("exp","number");this.addOutput("out","Texture");this.properties={exposition:1,precision:c.LOW};this._uniforms={u_texture:0,u_exposition:1}}function Q(){this.addInput("in","Texture");this.addInput("avg","number,Texture");this.addOutput("out","Texture");this.properties={enabled:!0,scale:1,gamma:1,average_lum:1,lum_white:1,precision:c.LOW};this._uniforms={u_texture:0,u_lumwhite2:1,u_igamma:1,u_scale:1,u_average_lum:1}}function S(){this.addOutput("out", "Texture");this.properties={width:512,height:512,seed:0,persistence:.1,octaves:8,scale:1,offset:[0,0],amplitude:1,precision:c.DEFAULT};this._key=0;this._texture=null;this._uniforms={u_persistence:.1,u_seed:0,u_offset:vec2.create(),u_scale:1,u_viewport:vec2.create()}}function R(){this.addInput("v");this.addOutput("out","Texture");this.properties={code:R.default_code,width:512,height:512,clear:!0,precision:c.DEFAULT,use_html_canvas:!1};this._temp_texture=this._func=null;this.compileCode()}function T(){this.addInput("in", "Texture");this.addOutput("out","Texture");this.properties={key_color:vec3.fromValues(0,1,0),threshold:.8,slope:.2,precision:c.DEFAULT}}function U(){this.addInput("in","texture");this.addInput("yaw","number");this.addOutput("out","texture");this.properties={yaw:0}}var L=y.LiteGraph,Z=y.LGraphCanvas;y.LGraphTexture=null;"undefined"!=typeof GL&&(Z.link_type_colors.Texture="#987",y.LGraphTexture=c,c.title="Texture",c.desc="Texture",c.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}}, c.loadTextureCallback=null,c.image_preview_size=256,c.UNDEFINED=0,c.PASS_THROUGH=1,c.COPY=2,c.LOW=3,c.HIGH=4,c.REUSE=5,c.DEFAULT=2,c.MODE_VALUES={undefined:c.UNDEFINED,"pass through":c.PASS_THROUGH,copy:c.COPY,low:c.LOW,high:c.HIGH,reuse:c.REUSE,default:c.DEFAULT},c.getTexturesContainer=function(){return gl.textures},c.loadTexture=function(a,b){b=b||{};var d=a;"http://"==d.substr(0,7)&&L.proxy&&(d=L.proxy+d.substr(7));return c.getTexturesContainer()[a]=GL.Texture.fromURL(d,b)},c.getTexture=function(a){var b= this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a):b},c.getTargetTexture=function(a,b,d){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";switch(d){case c.LOW:d=gl.UNSIGNED_BYTE;break;case c.HIGH:d=gl.HIGH_PRECISION_FORMAT;break;case c.REUSE:return a;default:d=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==d&&b.format==a.format||(b=new GL.Texture(a.width, a.height,{type:d,format:a.format,filter:gl.LINEAR}));return b},c.getTextureType=function(a,b){b=b?b.type:gl.UNSIGNED_BYTE;switch(a){case c.HIGH:b=gl.HIGH_PRECISION_FORMAT;break;case c.LOW:b=gl.UNSIGNED_BYTE}return b},c.getWhiteTexture=function(){return this._white_texture?this._white_texture:this._white_texture=GL.Texture.fromMemory(1,1,[255,255,255,255],{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576), b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.prototype.onDropFile=function(a,b,d){a?("string"==typeof a?a=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?a=GL.Texture.fromDDSInMemory(a):(a=new Blob([d]),a=URL.createObjectURL(a),a=GL.Texture.fromURL(a)),this._drop_texture=a,this.properties.name=b):(this._drop_texture=null,this.properties.name="")},c.prototype.getExtraMenuOptions= function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]},c.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=c.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0, a);this.setOutputData(1,a.fullpath||a.filename);for(var b=2;b=this.size[1]))if(this._drop_texture&& a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=c.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}},c.generateLowResTexturePreview=function(a){if(!a)return null; var b=c.image_preview_size,d=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)d=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=d=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(d);a=this._preview_canvas;a||(this._preview_canvas=a=createCanvas(b,b));d&&d.toCanvas(a);return a},c.prototype.getResources=function(a){this.properties.name&&(a[this.properties.name]=GL.Texture);return a},c.prototype.onGetInputs=function(){return[["in","Texture"]]},c.prototype.onGetOutputs= function(){return[["width","number"],["height","number"],["aspect","number"]]},c.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g,function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},L.registerNodeType("texture/texture",c),k.title="Preview",k.desc="Show a texture in the graph canvas",k.allow_preview=!1,k.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||k.allow_preview)){var b=this.getInputData(0);b&&(b=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b), a.save(),this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(b,0,0,this.size[0],this.size[1]),a.restore())}},L.registerNodeType("texture/preview",k),t.title="Save",t.desc="Save a texture in the repository",t.prototype.getPreviewTexture=function(){return this._texture},t.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.generate_mipmaps&&(a.bind(0),a.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR),gl.generateMipmap(a.texture_type), a.unbind(0)),this.properties.name&&(c.storeTexture?c.storeTexture(this.properties.name,a):c.getTexturesContainer()[this.properties.name]=a),this._texture=a,this.setOutputData(0,a),this.setOutputData(1,this.properties.name))},L.registerNodeType("texture/save",t),r.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},r.title="Operation",r.desc="Texture shader operation",r.presets={},r.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show? "Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},r.prototype.onPropertyChanged=function(){this.has_error=!1},r.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())},r.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0, a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,f=512;a?(d=a.width,f=a.height):b&&(d=b.width,f=b.height);b||(b=GL.Texture.getWhiteTexture());var h=c.getTextureType(this.properties.precision,a);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,f,{type:h,format:gl.RGBA,filter:gl.LINEAR});h="";this.properties.uvcode&&(h="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&& (h=this.properties.uvcode));var e="";this.properties.pixelcode&&(e="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(e=this.properties.pixelcode));var g=this._shader;if(!(this.has_error||g&&this._shader_code==h+"|"+e)){var l=c.replaceCode(r.pixel_shader,{UV_CODE:h,PIXEL_CODE:e});try{g=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,l),this.boxcolor="#00FF00"}catch(aa){GL.Shader.dumpErrorToConsole(aa,Shader.SCREEN_VERTEX_SHADER,l);this.boxcolor="#FF0000";this.has_error=!0; return}this._shader=g;this._shader_code=h+"|"+e}if(this._shader){var n=this.getInputData(2);null!=n?this.properties.value=n:n=parseFloat(this.properties.value);var v=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();g.uniforms({u_texture:0,u_textureB:1,value:n,texSize:[d,f,1/d,1/f],time:v}).draw(c)});this.setOutputData(0,this._tex)}}}},r.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec4 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", r.registerPreset=function(a,b){r.presets[a]=b},r.registerPreset("",""),r.registerPreset("bypass","color"),r.registerPreset("add","color + colorB * value"),r.registerPreset("substract","(color - colorB) * value"),r.registerPreset("mate","mix( color, colorB, color4B.a * value)"),r.registerPreset("invert","vec3(1.0) - color"),r.registerPreset("multiply","color * colorB * value"),r.registerPreset("divide","(color / colorB) / value"),r.registerPreset("difference","abs(color - colorB) * value"),r.registerPreset("max", "max(color, colorB) * value"),r.registerPreset("min","min(color, colorB) * value"),r.registerPreset("displace","texture2D(u_texture, uv + (colorB.xy - vec2(0.5)) * value).xyz"),r.registerPreset("grayscale","vec3(color.x + color.y + color.z) * value / 3.0"),r.registerPreset("saturation","mix( vec3(color.x + color.y + color.z) / 3.0, color, value )"),r.registerPreset("normalmap","\n\t\tfloat z0 = texture2D(u_texture, uv + vec2(-texSize.z, -texSize.w) ).x;\n\t\tfloat z1 = texture2D(u_texture, uv + vec2(0.0, -texSize.w) ).x;\n\t\tfloat z2 = texture2D(u_texture, uv + vec2(texSize.z, -texSize.w) ).x;\n\t\tfloat z3 = texture2D(u_texture, uv + vec2(-texSize.z, 0.0) ).x;\n\t\tfloat z4 = color.x;\n\t\tfloat z5 = texture2D(u_texture, uv + vec2(texSize.z, 0.0) ).x;\n\t\tfloat z6 = texture2D(u_texture, uv + vec2(-texSize.z, texSize.w) ).x;\n\t\tfloat z7 = texture2D(u_texture, uv + vec2(0.0, texSize.w) ).x;\n\t\tfloat z8 = texture2D(u_texture, uv + vec2(texSize.z, texSize.w) ).x;\n\t\tvec3 normal = vec3( z2 + 2.0*z4 + z7 - z0 - 2.0*z3 - z5, z5 + 2.0*z6 + z7 -z0 - 2.0*z1 - z2, 1.0 );\n\t\tnormal.xy *= value;\n\t\tresult.xyz = normalize(normal) * 0.5 + vec3(0.5);\n\t"), r.registerPreset("threshold","vec3(color.x > colorB.x * value ? 1.0 : 0.0,color.y > colorB.y * value ? 1.0 : 0.0,color.z > colorB.z * value ? 1.0 : 0.0)"),r.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(r.presets),callback:function(d){var c=r.presets[d];c&&(b.setProperty("pixelcode",c),b.title=d,a.refresh())}})},L.registerNodeType("texture/operation",r),w.title="Shader",w.desc="Texture shader",w.widgets_info={code:{type:"code",lang:"glsl"},precision:{widget:"combo", values:c.MODE_VALUES}},w.prototype.onPropertyChanged=function(a,b){if("code"==a&&(a=this.getShader())){b=a.uniformInfo;if(this.inputs)for(var d={},c=0;c=this.size[1])){var b=this.getInputData(0);b&&a.drawImage(a==gl?b:gl.canvas,10,30,this.size[0]-20,this.size[1]-40)}},z.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA, gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);var d=z._prev_viewport;d.set(gl.viewport_data);var c=this.properties.viewport;gl.viewport(d[0]+d[2]*c[0],d[1]+d[3]*c[1],d[2]*c[2],d[3]*c[3]);gl.getViewport();this.properties.antialiasing?(z._shader||(z._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER, z.aa_pixel_shader)),c=Mesh.getScreenQuad(),a.bind(0),z._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(c)):1!=b?(z._gamma_shader||(z._gamma_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,z.gamma_pixel_shader)),a.toViewport(z._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport();gl.viewport(d[0],d[1],d[2],d[3])}},z.prototype.onGetInputs=function(){return[["gamma","number"]]},z.aa_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 uViewportSize;\n\t\tuniform vec2 inverseVP;\n\t\tuniform float u_igamma;\n\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\n\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t{\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\n\t\t\tvec2 dir;\n\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\n\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\n\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\n\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\n\t\t\t//return vec4(rgbA,1.0);\n\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\telse\n\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\tif(u_igamma != 1.0)\n\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\treturn color;\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t}\n\t\t", z.gamma_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_igamma;\n\t\tvoid main() {\n\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t gl_FragColor = color;\n\t\t}\n\t\t",L.registerNodeType("texture/toviewport",z),F.title="Copy",F.desc="Copy Texture",F.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo", values:c.MODE_VALUES}},F.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,d=a.height;0!=this.properties.size&&(d=b=this.properties.size);var f=this._temp_texture,h=a.type;this.properties.precision===c.LOW?h=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(h=gl.HIGH_PRECISION_FORMAT);f&&f.width==b&&f.height==d&&f.type==h||(f=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(d)&&(f=gl.LINEAR_MIPMAP_LINEAR), this._temp_texture=new GL.Texture(b,d,{type:h,format:gl.RGBA,minFilter:f,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)}},L.registerNodeType("texture/copy",F),A.title="Downsample",A.desc="Downsample Texture",A.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:c.MODE_VALUES}}, A.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D)if(1>this.properties.iterations)this.setOutputData(0,a);else{var b=A._shader;b||(A._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,A.pixel_shader));var d=a.width|0,f=a.height|0,h=a.type;this.properties.precision===c.LOW?h=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(h=gl.HIGH_PRECISION_FORMAT);var e=this.properties.iterations||1,g=a,l= [];h={type:h,format:a.format};var n=vec2.create(),v={u_offset:n};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var k=0;k>1||0;f=f>>1||0;a=GL.Texture.getTemporary(d,f,h);l.push(a);g.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);g.copyTo(a,b,v);if(1==d&&1==f)break;g=a}this._texture=l.pop();for(k=0;kc;c++)this.isOutputConnected(c)?(this._channels[c]&&this._channels[c].width==a.width&&this._channels[c].height==a.height&&this._channels[c].type==a.type&&this._channels[c].format==b||(this._channels[c]=new GL.Texture(a.width,a.height,{type:a.type,format:b,filter:gl.LINEAR})), d++):this._channels[c]=null;if(d){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad(),h=n._shader,e=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(c=0;4>c;c++)this._channels[c]&&(this._channels[c].drawTo(function(){a.bind(0);h.uniforms({u_texture:0,u_mask:e[c]}).draw(f)}),this.setOutputData(c,this._channels[c]))}}},n.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec4 u_mask;\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t}\n\t\t", L.registerNodeType("texture/textureChannels",n),v.title="Channels to Texture",v.desc="Split texture channels",v.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},v.prototype.onExecute=function(){var a=c.getWhiteTexture(),b=this.getInputData(0)||a,d=this.getInputData(1)||a,f=this.getInputData(2)||a,h=this.getInputData(3)||a;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad();v._shader||(v._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,v.pixel_shader));var g=v._shader; a=Math.max(b.width,d.width,f.width,h.width);var l=Math.max(b.height,d.height,f.height,h.height),n=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._texture&&this._texture.width==a&&this._texture.height==l&&this._texture.type==n||(this._texture=new GL.Texture(a,l,{type:n,format:gl.RGBA,filter:gl.LINEAR}));a=this._color;a[0]=this.properties.R;a[1]=this.properties.G;a[2]=this.properties.B;a[3]=this.properties.A;var k=this._uniforms;this._texture.drawTo(function(){b.bind(0); d.bind(1);f.bind(2);h.bind(3);g.uniforms(k).draw(e)});this.setOutputData(0,this._texture)},v.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureR;\n\t\tuniform sampler2D u_textureG;\n\t\tuniform sampler2D u_textureB;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform vec4 u_color;\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = u_color * vec4( \t\t\t\t\ttexture2D(u_textureR, v_coord).r,\t\t\t\t\ttexture2D(u_textureG, v_coord).r,\t\t\t\t\ttexture2D(u_textureB, v_coord).r,\t\t\t\t\ttexture2D(u_textureA, v_coord).r);\n\t\t}\n\t\t", L.registerNodeType("texture/channelsTexture",v),a.title="Color",a.desc="Generates a 1x1 texture with a constant color",a.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},a.prototype.onDrawBackground=function(a){var b=this.properties.color;a.fillStyle="rgb("+Math.floor(255*Math.clamp(b[0],0,1))+","+Math.floor(255*Math.clamp(b[1],0,1))+","+Math.floor(255*Math.clamp(b[2],0,1))+")";this.flags.collapsed?this.boxcolor=a.fillStyle:a.fillRect(0,0,this.size[0],this.size[1])},a.prototype.onExecute= function(){var a=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._tex&&this._tex.type==a||(this._tex=new GL.Texture(1,1,{format:gl.RGBA,type:a,minFilter:gl.NEAREST}));a=this.properties.color;if(this.inputs)for(var b=0;ba.width?b: a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad(),g=null,l=this._uniforms;f?(g=d._shader_tex,g||(g=d._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader,{MIX_TEX:""}))):(g=d._shader_factor,g||(g=d._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader)),h=null==h?this.properties.factor:h,l.u_mix.set([h,h,h,h]));var n=this.properties.invert;this._tex.drawTo(function(){a.bind(n?1:0);b.bind(n?0:1);f&&f.bind(2); g.uniforms(l).draw(e)});this.setOutputData(0,this._tex)}}},d.prototype.onGetInputs=function(){return[["factor","number"]]},d.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform sampler2D u_textureB;\n\t\t#ifdef MIX_TEX\n\t\t\tuniform sampler2D u_textureMix;\n\t\t#else\n\t\t\tuniform vec4 u_mix;\n\t\t#endif\n\t\t\n\t\tvoid main() {\n\t\t\t#ifdef MIX_TEX\n\t\t\t vec4 f = texture2D(u_textureMix, v_coord);\n\t\t\t#else\n\t\t\t vec4 f = u_mix;\n\t\t\t#endif\n\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), f );\n\t\t}\n\t\t", L.registerNodeType("texture/mix",d),h.title="Edges",h.desc="Detects edges",h.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},h.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=c.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),d=h._shader,f=this.properties.invert,e=this.properties.factor, g=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);d.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:e,u_threshold:g,u_invert:f?1:0}).draw(b)});this.setOutputData(0,this._tex)}}},h.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_isize;\n\t\tuniform int u_invert;\n\t\tuniform float u_factor;\n\t\tuniform float u_threshold;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 center = texture2D(u_texture, v_coord);\n\t\t\tvec4 up = texture2D(u_texture, v_coord + u_isize * vec2(0.0,1.0) );\n\t\t\tvec4 down = texture2D(u_texture, v_coord + u_isize * vec2(0.0,-1.0) );\n\t\t\tvec4 left = texture2D(u_texture, v_coord + u_isize * vec2(1.0,0.0) );\n\t\t\tvec4 right = texture2D(u_texture, v_coord + u_isize * vec2(-1.0,0.0) );\n\t\t\tvec4 diff = abs(center - up) + abs(center - down) + abs(center - left) + abs(center - right);\n\t\t\tdiff *= u_factor;\n\t\t\tif(u_invert == 1)\n\t\t\t\tdiff.xyz = vec3(1.0) - diff.xyz;\n\t\t\tif( u_threshold == 0.0 )\n\t\t\t\tgl_FragColor = vec4( diff.xyz, center.a );\n\t\t\telse\n\t\t\t\tgl_FragColor = vec4( diff.x > 0.5 ? 1.0 : 0.0, diff.y > 0.5 ? 1.0 : 0.0, diff.z > 0.5 ? 1.0 : 0.0, center.a );\n\t\t}\n\t\t", L.registerNodeType("texture/edges",h),f.title="Depth Range",f.desc="Generates a texture with a depth range",f.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 d=this._uniforms;b=this.properties.distance;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.distance=b);var c=this.properties.range;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.range=c);d.u_distance=b;d.u_range=c;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad();f._shader||(f._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader),f._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader, {ONLY_DEPTH:""}));var e=this.properties.only_depth?f._shader_onlydepth:f._shader;b=null;b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:[.1,1E3];d.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);e.uniforms(d).draw(h)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},f.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform float u_distance;\n\t\tuniform float u_range;\n\t\t\n\t\tfloat LinearDepth()\n\t\t{\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t\tfloat depth = LinearDepth();\n\t\t\t#ifdef ONLY_DEPTH\n\t\t\t gl_FragColor = vec4(depth);\n\t\t\t#else\n\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\tfloat dof = 1.0;\n\t\t\t\tif(diff <= u_range)\n\t\t\t\t\tdof = diff / u_range;\n\t\t\t gl_FragColor = vec4(dof);\n\t\t\t#endif\n\t\t}\n\t\t", L.registerNodeType("texture/depth_range",f),u.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},u.title="Linear Depth",u.desc="Creates a color texture with linear depth",u.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a&&(a.format==gl.DEPTH_COMPONENT||a.format==gl.DEPTH_STENCIL)){var b=this.properties.precision==c.HIGH?gl.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;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.RGB,filter:gl.LINEAR}));var d=this._uniforms;d.u_invert=this.properties.invert?1:0;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad();u._shader||(u._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,u.pixel_shader));var h=u._shader;b=null;b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:[.1,1E3]; d.u_camera_planes=b;d.u_ires.set([0,0]);this._temp_texture.drawTo(function(){a.bind(0);h.uniforms(d).draw(f)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},u.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform int u_invert;\n\t\tuniform vec2 u_ires;\n\t\t\n\t\tvoid main() {\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord + u_ires*0.5).x * 2.0 - 1.0;\n\t\t\tfloat f = zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\tif( u_invert == 1 )\n\t\t\t\tf = 1.0 - f;\n\t\t\tgl_FragColor = vec4(vec3(f),1.0);\n\t\t}\n\t\t", L.registerNodeType("texture/linear_depth",u),m.title="Blur",m.desc="Blur a texture",m.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},m.max_iterations=20,m.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._final_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var d=this.properties.iterations;this.isInputConnected(1)&& (d=this.getInputData(1),this.properties.iterations=d);d=Math.min(Math.floor(d),m.max_iterations);if(0==d)this.setOutputData(0,a);else{var c=this.properties.intensity;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.intensity=c);var f=L.camera_aspect;f||void 0===window.gl||(f=gl.canvas.height/gl.canvas.width);f||(f=1);f=this.properties.preserve_aspect?f:1;var h=this.properties.scale||[1,1];a.applyBlur(f*h[0],h[1],c,b);for(a=1;a>=1;1<(h|0)&&(h>>=1);if(2>f)break;v=l[C]=GL.Texture.getTemporary(f,h,e);H[0]=1/k.width;H[1]=1/k.height;k.blit(v,n.uniforms(g));k=v}c&&(H[0]=1/k.width,H[1]=1/k.height,g.u_intensity=u,g.u_delta=1,k.blit(c,n.uniforms(g)));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);g.u_intensity=this.persistence; g.u_delta=.5;for(C-=2;0<=C;C--)v=l[C],l[C]=null,H[0]=1/k.width,H[1]=1/k.height,k.blit(v,n.uniforms(g)),GL.Texture.releaseTemporary(k),k=v;gl.disable(gl.BLEND);d&&k.blit(d);if(b){var r=this.dirt_texture,w=this.dirt_factor;g.u_intensity=u;n=r?q._dirt_final_shader:q._final_shader;n||(n=r?q._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,q.final_pixel_shader,{USE_DIRT:""}):q._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,q.final_pixel_shader));b.drawTo(function(){a.bind(0); k.bind(1);r&&(n.setUniform("u_dirt_factor",w),n.setUniform("u_dirt_texture",r.bind(2)));n.toViewport(g)})}GL.Texture.releaseTemporary(k)},q.cut_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_threshold;\n\tvoid main() {\n\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t}",q.scale_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t}", q.final_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform sampler2D u_glow_texture;\n\t#ifdef USE_DIRT\n\t\tuniform sampler2D u_dirt_texture;\n\t#endif\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\tuniform float u_dirt_factor;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_glow_texture, uv + o.xy ) + texture2D( u_glow_texture, uv + o.zy) + texture2D( u_glow_texture, uv + o.xw) + texture2D( u_glow_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tvec4 glow = sampleBox( v_coord );\n\t\t#ifdef USE_DIRT\n\t\t\tglow = mix( glow, glow * texture2D( u_dirt_texture, v_coord ), u_dirt_factor );\n\t\t#endif\n\t\tgl_FragColor = texture2D( u_texture, v_coord ) + u_intensity * glow;\n\t}", N.title="Glow",N.desc="Filters a texture giving it a glow effect",N.widgets_info={iterations:{type:"number",min:0,max:16,step:1,precision:0},threshold:{type:"number",min:0,max:10,step:.01,precision:2},precision:{widget:"combo",values:c.MODE_VALUES}},N.prototype.onGetInputs=function(){return[["enabled","boolean"],["threshold","number"],["intensity","number"],["persistence","number"],["iterations","number"],["dirt_factor","number"]]},N.prototype.onGetOutputs=function(){return[["average","Texture"]]}, N.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isAnyOutputConnected())if(this.properties.precision===c.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,a);else{var b=this.fx;b.threshold=this.getInputOrProperty("threshold");b.iterations=this.getInputOrProperty("iterations");b.intensity=this.getInputOrProperty("intensity");b.persistence=this.getInputOrProperty("persistence");b.dirt_texture=this.getInputData(1);b.dirt_factor=this.getInputOrProperty("dirt_factor"); b.scale=this.properties.scale;var d=c.getTextureType(this.properties.precision,a),f=null;this.isOutputConnected(2)&&(f=this._average_texture,f&&f.type==a.type&&f.format==a.format||(f=this._average_texture=new GL.Texture(1,1,{type:a.type,format:a.format,filter:gl.LINEAR})));var h=null;this.isOutputConnected(1)&&(h=this._glow_texture,h&&h.width==a.width&&h.height==a.height&&h.type==d&&h.format==a.format||(h=this._glow_texture=new GL.Texture(a.width,a.height,{type:d,format:a.format,filter:gl.LINEAR}))); var e=null;this.isOutputConnected(0)&&(e=this._final_texture,e&&e.width==a.width&&e.height==a.height&&e.type==d&&e.format==a.format||(e=this._final_texture=new GL.Texture(a.width,a.height,{type:d,format:a.format,filter:gl.LINEAR})));b.applyFX(a,e,h,f);this.isOutputConnected(0)&&this.setOutputData(0,e);this.isOutputConnected(1)&&this.setOutputData(1,f);this.isOutputConnected(2)&&this.setOutputData(2,h)}},L.registerNodeType("texture/glow",N),O.title="Kuwahara Filter",O.desc="Filters a texture giving an artistic oil canvas painting", O.max_radius=10,O._shaders=[],O.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),O.max_radius);if(0==b)this.setOutputData(0,a);else{var d=this.properties.intensity,c=L.camera_aspect;c||void 0===window.gl||(c=gl.canvas.height/gl.canvas.width); c||(c=1);c=this.properties.preserve_aspect?c:1;O._shaders[b]||(O._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,O.pixel_shader,{RADIUS:b.toFixed(0)}));var f=O._shaders[b],h=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){f.uniforms({u_texture:0,u_intensity:d,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(h)});this.setOutputData(0,this._temp_texture)}}},O.pixel_shader="\nprecision highp float;\nvarying vec2 v_coord;\nuniform sampler2D u_texture;\nuniform float u_intensity;\nuniform vec2 u_resolution;\nuniform vec2 u_iResolution;\n#ifndef RADIUS\n\t#define RADIUS 7\n#endif\nvoid main() {\n\n\tconst int radius = RADIUS;\n\tvec2 fragCoord = v_coord;\n\tvec2 src_size = u_iResolution;\n\tvec2 uv = v_coord;\n\tfloat n = float((radius + 1) * (radius + 1));\n\tint i;\n\tint j;\n\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\tvec3 c;\n\t\n\tfor (int j = -radius; j <= 0; ++j) {\n\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm0 += c;\n\t\t\ts0 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = -radius; j <= 0; ++j) {\n\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm1 += c;\n\t\t\ts1 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = 0; j <= radius; ++j) {\n\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm2 += c;\n\t\t\ts2 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = 0; j <= radius; ++j) {\n\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm3 += c;\n\t\t\ts3 += c * c;\n\t\t}\n\t}\n\t\n\tfloat min_sigma2 = 1e+2;\n\tm0 /= n;\n\ts0 = abs(s0 / n - m0 * m0);\n\t\n\tfloat sigma2 = s0.r + s0.g + s0.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m0, 1.0);\n\t}\n\t\n\tm1 /= n;\n\ts1 = abs(s1 / n - m1 * m1);\n\t\n\tsigma2 = s1.r + s1.g + s1.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m1, 1.0);\n\t}\n\t\n\tm2 /= n;\n\ts2 = abs(s2 / n - m2 * m2);\n\t\n\tsigma2 = s2.r + s2.g + s2.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m2, 1.0);\n\t}\n\t\n\tm3 /= n;\n\ts3 = abs(s3 / n - m3 * m3);\n\t\n\tsigma2 = s3.r + s3.g + s3.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m3, 1.0);\n\t}\n}\n", L.registerNodeType("texture/kuwahara",O),M.title="XDoG Filter",M.desc="Filters a texture giving an artistic ink style",M.max_radius=10,M._shaders=[],M.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}));M._xdog_shader||(M._xdog_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,M.xdog_pixel_shader)); var d=M._xdog_shader,c=GL.Mesh.getScreenQuad(),f=this.properties.sigma,h=this.properties.k,e=this.properties.p,g=this.properties.epsilon,l=this.properties.phi;a.bind(0);this._temp_texture.drawTo(function(){d.uniforms({src:0,sigma:f,k:h,p:e,epsilon:g,phi:l,cvsWidth:a.width,cvsHeight:a.height}).draw(c)});this.setOutputData(0,this._temp_texture)}},M.xdog_pixel_shader="\nprecision highp float;\nuniform sampler2D src;\n\nuniform float cvsHeight;\nuniform float cvsWidth;\n\nuniform float sigma;\nuniform float k;\nuniform float p;\nuniform float epsilon;\nuniform float phi;\nvarying vec2 v_coord;\n\nfloat cosh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat cosH = (tmp + 1.0 / tmp) / 2.0;\n\treturn cosH;\n}\n\nfloat tanh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n\treturn tanH;\n}\n\nfloat sinh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat sinH = (tmp - 1.0 / tmp) / 2.0;\n\treturn sinH;\n}\n\nvoid main(void){\n\tvec3 destColor = vec3(0.0);\n\tfloat tFrag = 1.0 / cvsHeight;\n\tfloat sFrag = 1.0 / cvsWidth;\n\tvec2 Frag = vec2(sFrag,tFrag);\n\tvec2 uv = gl_FragCoord.st;\n\tfloat twoSigmaESquared = 2.0 * sigma * sigma;\n\tfloat twoSigmaRSquared = twoSigmaESquared * k * k;\n\tint halfWidth = int(ceil( 1.0 * sigma * k ));\n\n\tconst int MAX_NUM_ITERATION = 99999;\n\tvec2 sum = vec2(0.0);\n\tvec2 norm = vec2(0.0);\n\n\tfor(int cnt=0;cnt (2*halfWidth+1)*(2*halfWidth+1)){break;}\n\t\tint i = int(cnt / (2*halfWidth+1)) - halfWidth;\n\t\tint j = cnt - halfWidth - int(cnt / (2*halfWidth+1)) * (2*halfWidth+1);\n\n\t\tfloat d = length(vec2(i,j));\n\t\tvec2 kernel = vec2( exp( -d * d / twoSigmaESquared ), \n\t\t\t\t\t\t\texp( -d * d / twoSigmaRSquared ));\n\n\t\tvec2 L = texture2D(src, (uv + vec2(i,j)) * Frag).xx;\n\n\t\tnorm += kernel;\n\t\tsum += kernel * L;\n\t}\n\n\tsum /= norm;\n\n\tfloat H = 100.0 * ((1.0 + p) * sum.x - p * sum.y);\n\tfloat edge = ( H > epsilon )? 1.0 : 1.0 + tanh( phi * (H - epsilon));\n\tdestColor = vec3(edge);\n\tgl_FragColor = vec4(destColor, 1.0);\n}", L.registerNodeType("texture/xDoG",M),I.title="Webcam",I.desc="Webcam texture",I.is_webcam_open=!1,I.prototype.openStream=function(){if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this)).catch(function(b){I.is_webcam_open=!1;console.log("Webcam rejected",b);a._webcam_stream=!1;a.boxcolor="red";a.trigger("stream_error")});var a=this}},I.prototype.closeStream=function(){if(this._webcam_stream){var a= this._webcam_stream.getTracks();if(a.length)for(var b=0;b=this.size[1]||!this._video||(a.save(),a.webgl?this._video_texture&&a.drawImage(this._video_texture,0,0,this.size[0],this.size[1]):a.drawImage(this._video, 0,0,this.size[0],this.size[1]),a.restore())},I.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,d=this._video_texture;d&&d.width==a&&d.height==b||(this._video_texture=new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._video_texture.uploadImage(this._video);this._video_texture.version=++this.version;this.properties.texture_name&&(c.getTexturesContainer()[this.properties.texture_name]= this._video_texture);this.setOutputData(0,this._video_texture);for(a=1;aMath.abs(b))return c[1];a=(a-c[0])/b;return c[1]*(1-a)+f[1]*a}}return 0}},H.prototype.updateCurve=function(){for(var a=this._values,b=a.length/4,d=this.properties.split_channels,c=0;cd+f.NODE_TITLE_HEIGHT&&a.drawImage(b,10,h,this.size[0]-20,this.size[1]-d-f.NODE_TITLE_HEIGHT);var h=this.size[1]-f.NODE_TITLE_HEIGHT+.5;c=f.isInsideRectangle(c[0],c[1],this.pos[0],this.pos[1]+h,this.size[0],f.NODE_TITLE_HEIGHT);a.fillStyle=c?"#555":"#222";a.beginPath();this._shape==f.BOX_SHAPE?a.rect(0,h,this.size[0]+1,f.NODE_TITLE_HEIGHT):a.roundRect(0,h,this.size[0]+1,f.NODE_TITLE_HEIGHT,0,8);a.fill();a.textAlign="center";a.font="24px Arial";a.fillStyle= c?"#DDD":"#999";a.fillText("+",.5*this.size[0],h+24)}};B.prototype.onMouseDown=function(a,b,d){b[1]>this.size[1]-f.NODE_TITLE_HEIGHT+.5&&d.showSubgraphPropertiesDialog(this)};B.prototype.onDrawSubgraphBackground=function(a){};B.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Print Code",callback:function(){var a=b._context.computeShaderCode();console.log(a.vs_code,a.fs_code)}}]};f.registerNodeType("texture/shaderGraph",B);z.title="Uniform";z.desc="Input data for the shader"; z.prototype.getTitle=function(){return this.properties.name&&this.flags.collapsed?this.properties.type+" "+this.properties.name:"Uniform"};z.prototype.onPropertyChanged=function(a,b){this.outputs[0].name=this.properties.type+" "+this.properties.name};z.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;if(!b){if(!a.onGetPropertyInfo)return;b=a.onGetPropertyInfo(this.property.name);if(!b)return;b=b.type}"number"==b?b="float":"texture"==b&&(b="sampler2D");-1!=u.GLSL_types.indexOf(b)&& (a.addUniform("u_"+this.properties.name,b),this.setOutputData(0,b))}};z.prototype.getOutputVarName=function(a){return"u_"+this.properties.name};k("input/uniform",z);F.title="Attribute";F.desc="Input data from mesh attribute";F.prototype.getTitle=function(){return"att. "+this.properties.name};F.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;b&&-1!=u.GLSL_types.indexOf(b)&&("number"==b&&(b="float"),"coord"!=this.properties.name&&a.addCode("varying"," varying "+ b+" v_"+this.properties.name+";"),this.setOutputData(0,b))}};F.prototype.getOutputVarName=function(a){return"v_"+this.properties.name};k("input/attribute",F);A.title="Sampler2D";A.desc="Reads a pixel from a texture";A.prototype.onGetCode=function(a){if(this.shader_destination){var b=r(this,0),d=t(this),c="vec4 "+d+" = vec4(0.0);\n";if(b){var f=r(this,1)||a.buffer_names.uvs;c+=d+" = texture2D("+b+","+f+");\n"}w(this,0)&&(c+="vec4 "+w(this,0)+" = "+d+";\n");w(this,1)&&(c+="vec3 "+w(this,1)+" = "+d+ ".xyz;\n");a.addCode("code",c,this.shader_destination);this.setOutputData(0,"vec4");this.setOutputData(1,"vec3")}};k("texture/sampler2D",A);D.title="const";D.prototype.getTitle=function(){return this.flags.collapsed?M(this.properties.value,this.properties.type,2):"Const"};D.prototype.onPropertyChanged=function(a,b){"type"==a&&(this.outputs[0].type!=b&&(this.disconnectOutput(0),this.outputs[0].type=b),this.widgets.length=1,this.updateWidgets());"value"==a&&(b.length?(this.widgets[1].value=b[1],2d;++d)b.push({name:r(this,d),type:this.getInputData(d)||"float"});var c=w(this,0);if(c){var f=b[0].type,h=this.properties.operation, e=[];for(d=0;2>d;++d){var g=b[d].name;null==g&&(g=null!=p.value?p.value:"(1.0)",b[d].type="float");b[d].type!=f&&("float"!=b[d].type||"*"!=h&&"/"!=h)&&(g=J(g,b[d].type,f));e.push(g)}a.addCode("code",f+" "+c+" = "+e[0]+h+e[1]+";",this.shader_destination);this.setOutputData(0,f)}}};k("math/operation",K);l.title="Func";l.prototype.onPropertyChanged=function(a,b){this.graph&&this.graph._version++;if("func"==a&&(a=N[b])){for(b=a.params.length;bd;++d)b.push({name:r(this,d),type:this.getInputData(d)||"float"});var c=w(this,0);if(c){var f=N[this.properties.func];if(f){var h=b[0].type,e=f.return_type;"T"==e&&(e=h);var g=[];for(d= 0;d=c;){e=.5*(g+c)|0;b=a[e];if(b==d)break;if(c==g-1)return c;ba&&(a=1);this.points&&this.points.length==3*a||(this.points=new Float32Array(3*a));this.properties.generate_normals?this.normals&&this.normals.length==this.points.length||(this.normals=new Float32Array(this.points.length)):this.normals=null;var d=this._last_radius||this.properties.radius,c=this.properties.mode,f=this.getInputData(0);this._old_obj_version=f?f._version:null;this.points=k.generatePoints(d,a,c,this.points,this.normals, this.properties.regular,f);this.version++};k.generatePoints=function(a,d,c,f,e,g,l){var b=3*d;f&&f.length==b||(f=new Float32Array(b));var h=new Float32Array(3),n=new Float32Array([0,1,0]);if(g)if(c==k.RECTANGLE){b=Math.floor(Math.sqrt(d));for(d=0;dg||zl&&ln))break}this.geometry.indices=this.indices=new Uint32Array(k)}this.indices&&this.indices.length?(this.geometry.indices=this.indices,this.setOutputData(0,this.geometry)):this.setOutputData(0,null)}};x.registerNodeType("geometry/connectPoints",F);"undefined"!=typeof GL&&(A.title="to geometry",A.desc="converts a mesh to geometry",A.prototype.onExecute=function(){var a=this.getInputData(0);if(a){if(a!=this.last_mesh){this.last_mesh=a;for(i in a.vertexBuffers)this.geometry[i]= a.vertexBuffers[i].data;a.indexBuffers.triangles&&(this.geometry.indices=a.indexBuffers.triangles.data);this.geometry._id=c();this.geometry._version=0}this.setOutputData(0,this.geometry);this.geometry&&this.setOutputData(1,this.geometry.vertices)}},x.registerNodeType("geometry/toGeometry",A),D.title="Geo to Mesh",D.prototype.updateMesh=function(a){this.mesh||(this.mesh=new GL.Mesh);for(var b in a)if("_"!=b[0]){var c=a[b],f=GL.Mesh.common_buffers[b];if(f||"indices"==b){f=f?f.spacing:3;var e=this.mesh.vertexBuffers[b]; e&&e.data.length==c.length?(e.data.set(c),e.upload(GL.DYNAMIC_DRAW)):e=new GL.Buffer("indices"==b?GL.ELEMENT_ARRAY_BUFFER:GL.ARRAY_BUFFER,c,f,GL.DYNAMIC_DRAW);this.mesh.addBuffer(b,e)}}if(this.mesh.vertexBuffers.normals&&this.mesh.vertexBuffers.normals.data.length!=this.mesh.vertexBuffers.vertices.data.length){c=new Float32Array([0,1,0]);f=new Float32Array(this.mesh.vertexBuffers.vertices.data.length);for(b=0;b=c.NOTEON||g<=c.NOTEOFF)this.channel=e&15};Object.defineProperty(c.prototype,"velocity",{get:function(){return this.cmd==c.NOTEON?this.data[2]:-1},set:function(c){this.data[2]=c},enumerable:!0});c.notes="A A# B C C# D D# E F F# G G#".split(" ");c.note_to_index={A:0,"A#":1,B:2,C:3,"C#":4,D:5,"D#":6,E:7,F:8,"F#":9,G:10,"G#":11};Object.defineProperty(c.prototype,"note",{get:function(){return this.cmd!= c.NOTEON?-1:c.toNoteString(this.data[1],!0)},set:function(c){throw"notes cannot be assigned this way, must modify the data[1]";},enumerable:!0});Object.defineProperty(c.prototype,"octave",{get:function(){return this.cmd!=c.NOTEON?-1:Math.floor((this.data[1]-24)/12+1)},set:function(c){throw"octave cannot be assigned this way, must modify the data[1]";},enumerable:!0});c.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};c.computePitch=function(c){return 440*Math.pow(2,(c-69)/ 12)};c.prototype.getCC=function(){return this.data[1]};c.prototype.getCCValue=function(){return this.data[2]};c.prototype.getPitchBend=function(){return this.data[1]+(this.data[2]<<7)-8192};c.computePitchBend=function(c,e){return c+(e<<7)-8192};c.prototype.setCommandFromString=function(e){this.cmd=c.computeCommandFromString(e)};c.computeCommandFromString=function(e){if(!e)return 0;if(e&&e.constructor===Number)return e;e=e.toUpperCase();switch(e){case "NOTE ON":case "NOTEON":return c.NOTEON;case "NOTE OFF":case "NOTEOFF":return c.NOTEON; case "KEY PRESSURE":case "KEYPRESSURE":return c.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return c.CONTROLLERCHANGE;case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return c.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return c.CHANNELPRESSURE;case "PITCH BEND":case "PITCHBEND":return c.PITCHBEND;case "TIME TICK":case "TIMETICK":return c.TIMETICK;default:return Number(e)}};c.toNoteString=function(e,g){e=Math.round(e);var l=Math.floor((e-24)/12+1);e= (e-21)%12;0>e&&(e=12+e);return c.notes[e]+(g?"":l)};c.NoteStringToPitch=function(e){e=e.toUpperCase();var g=e[0],l=4;"#"==e[1]?(g+="#",2this.properties.max_value)return;this.trigger("on_midi",g)}};x.registerNodeType("midi/filter",g);B.title="MIDIEvent";B.desc="Create a MIDI Event";B.color="#243";B.prototype.onAction=function(e,g){"assign"==e?(this.properties.channel=g.channel,this.properties.cmd=g.cmd,this.properties.value1=g.data[1],this.properties.value2=g.data[2],g.cmd== c.NOTEON?this.gate=!0:g.cmd==c.NOTEOFF&&(this.gate=!1)):(g=this.midi_event,g.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?g.setCommandFromString(this.properties.cmd):g.cmd=this.properties.cmd,g.data[0]=g.cmd|g.channel,g.data[1]=Number(this.properties.value1),g.data[2]=Number(this.properties.value2),this.trigger("on_midi",g))};B.prototype.onExecute=function(){var e=this.properties;if(this.inputs)for(var g=0;gc;++c)this.valid_notes[c]=-1!=this.notes_pitches.indexOf(c);for(c=0;12>c;++c)if(this.valid_notes[c])this.offset_notes[c]=0;else for(var e=1;12>e;++e){if(this.valid_notes[(c-e)%12]){this.offset_notes[c]=-e;break}if(this.valid_notes[(c+e)%12]){this.offset_notes[c]=e;break}}};D.prototype.onAction=function(e,g){g&&g.constructor===c&&(g.data[0]==c.NOTEON||g.data[0]==c.NOTEOFF?(this.midi_event=new c,this.midi_event.setup(g.data),this.midi_event.data[1]+=this.offset_notes[c.note_to_index[g.note]], this.trigger("out",this.midi_event)):this.trigger("out",g))};D.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&&this.processScale(c)};x.registerNodeType("midi/quantize",D);e.title="MIDI fromFile";e.desc="Plays a MIDI file";e.color="#243";e.prototype.onAction=function(c){"play"==c?this.play():"pause"==c&&(this._playing=!this._playing)};e.prototype.onPropertyChanged=function(c,e){"url"==c&&this.loadMIDIFile(e)};e.prototype.onExecute=function(){if(this._midi&& this._playing){this._current_time+=this.graph.elapsed_time;for(var e=100*this._current_time,g=0;gb;b++)for(var d=0;dh+f||c[1]>d))return b}}return-1};E.prototype.onAction=function(e,g){if("reset"==e)for(g=0;gg[1]))return e=this.getKeyIndex(g),this.keys[e]=!0,this._last_key=e,e=12*(this.properties.start_octave-1)+29+e,g=new c,g.setup([c.NOTEON,e,100]),this.trigger("note",g),!0};E.prototype.onMouseMove=function(e,g){if(!(0>g[1]||-1==this._last_key)){this.setDirtyCanvas(!0); e=this.getKeyIndex(g);if(this._last_key==e)return!0;this.keys[this._last_key]=!1;g=12*(this.properties.start_octave-1)+29+this._last_key;var k=new c;k.setup([c.NOTEOFF,g,100]);this.trigger("note",k);this.keys[e]=!0;g=12*(this.properties.start_octave-1)+29+e;k=new c;k.setup([c.NOTEON,g,100]);this.trigger("note",k);this._last_key=e;return!0}};E.prototype.onMouseUp=function(e,g){if(!(0>g[1]))return e=this.getKeyIndex(g),this.keys[e]=!1,this._last_key=-1,e=12*(this.properties.start_octave-1)+29+e,g=new c, g.setup([c.NOTEOFF,e,100]),this.trigger("note",g),!0};x.registerNodeType("midi/keys",E)})(this); (function(y){function c(){this.properties={src:"",gain:.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audiobuffer=null;this._audionodes=[];this._last_sourcenode=null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=n.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function k(){this.properties={gain:.5};this._audionodes=[];this._media_stream= null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=n.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function t(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:.5};this.audionode=n.getAudioContext().createAnalyser();this.audionode.graphnode=this;this.audionode.fftSize=this.properties.fftSize;this.audionode.minDecibels=this.properties.minDecibels;this.audionode.maxDecibels= this.properties.maxDecibels;this.audionode.smoothingTimeConstant=this.properties.smoothingTimeConstant;this.addInput("in","audio");this.addOutput("freqs","array");this.addOutput("samples","array");this._time_bin=this._freq_bin=null}function r(){this.properties={gain:1};this.audionode=n.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function w(){this.properties={impulse_src:"",normalize:!0};this.audionode=n.getAudioContext().createConvolver(); this.addInput("in","audio");this.addOutput("out","audio")}function g(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:.25};this.audionode=n.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function B(){this.properties={};this.audionode=n.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function z(){this.properties={gain1:.5,gain2:.5}; this.audionode=n.getAudioContext().createGain();this.audionode1=n.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=n.getAudioContext().createGain();this.audionode2.gain.value=this.properties.gain2;this.audionode1.connect(this.audionode);this.audionode2.connect(this.audionode);this.addInput("in1","audio");this.addInput("in1 gain","number");this.addInput("in2","audio");this.addInput("in2 gain","number");this.addOutput("out","audio")}function F(){this.properties= {A:.1,D:.1,S:.1,R:.1};this.audionode=n.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","bool");this.addOutput("out","audio");this.gate=!1}function A(){this.properties={delayTime:.5};this.audionode=n.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function D(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type", "lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});this.audionode=n.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function e(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=n.getAudioContext().createOscillator();this.addOutput("out","audio")}function G(){this.properties={continuous:!0, mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function E(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function x(){if(!x.default_code){var c=x.default_function.toString(),a=c.indexOf("{")+1,b=c.lastIndexOf("}");x.default_code=c.substr(a,b-a)}this.properties={code:x.default_code};c=n.getAudioContext();c.createScriptProcessor?this.audionode=c.createScriptProcessor(4096,1,1): (console.warn("ScriptProcessorNode deprecated"),this.audionode=c.createGain());this.processCode();x._bypass_function||(x._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function K(){this.audionode=n.getAudioContext().destination;this.addInput("in","audio")}var l=y.LiteGraph,n={};y.LGAudio=n;n.getAudioContext=function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"), null;this._audio_context=new AudioContext;this._audio_context.onmessage=function(c){console.log("msg",c)};this._audio_context.onended=function(c){console.log("ended",c)};this._audio_context.oncomplete=function(c){console.log("complete",c)}}return this._audio_context};n.connect=function(c,a){try{c.connect(a)}catch(b){console.warn("LGraphAudio:",b)}};n.disconnect=function(c,a){try{c.disconnect(a)}catch(b){console.warn("LGraphAudio:",b)}};n.changeAllAudiosConnections=function(c,a){if(c.inputs)for(var b= 0;b=this.size[0]&&(e=this.size[0]-1),c.strokeStyle= "red",c.beginPath(),c.moveTo(e,d),c.lineTo(e,0),c.stroke())}};G.title="Visualization";G.desc="Audio Visualization";l.registerNodeType("audio/visualization",G);E.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var c=this.properties.band,a=this.getInputData(1);void 0!==a&&(c=a);a=n.getAudioContext().sampleRate/this._freqs.length;a=c/a*2;a>=this._freqs.length?a=this._freqs[this._freqs.length-1]:(c=a|0,a-=c,a=this._freqs[c]*(1-a)+this._freqs[c+1]*a);this.setOutputData(0,a/255*this.properties.amplitude)}}; E.prototype.onGetInputs=function(){return[["band","number"]]};E.title="Signal";E.desc="extract the signal of some frequency";l.registerNodeType("audio/signal",E);x.prototype.onAdded=function(c){c.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};x["@code"]={widget:"code",type:"code"};x.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};x.prototype.onStop=function(){this.audionode.onaudioprocess=x._bypass_function};x.prototype.onPause=function(){this.audionode.onaudioprocess= x._bypass_function};x.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};x.prototype.onExecute=function(){};x.prototype.onRemoved=function(){this.audionode.onaudioprocess=x._bypass_function};x.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(v){console.error("Error in onaudioprocess code",v),this._callback=x._bypass_function, this.audionode.onaudioprocess=this._callback}};x.prototype.onPropertyChanged=function(c,a){"code"==c&&(this.properties.code=a,this.processCode(),this.graph&&this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};x.default_function=function(){this.onaudioprocess=function(c){var a=c.inputBuffer;c=c.outputBuffer;for(var b=0;b