From 28c0eec6c20b3c347c6ff294c7bdb6b0b620d550 Mon Sep 17 00:00:00 2001 From: tamat Date: Wed, 8 Apr 2020 17:14:32 +0200 Subject: [PATCH] fix --- build/litegraph.js | 196 ++------ build/litegraph.min.js | 1054 ++++++++++++++++++++-------------------- src/litegraph.js | 12 +- src/nodes/base.js | 47 +- src/nodes/math.js | 137 ------ 5 files changed, 627 insertions(+), 819 deletions(-) diff --git a/build/litegraph.js b/build/litegraph.js index f5861d749..743dbef0f 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -4585,14 +4585,12 @@ LGraphNode.prototype.executeAction = function(action) return; } - /* - if(this.graph) - this.graph.canvas = null; //remove old graph link to the canvas - this.graph = graph; - if(this.graph) - this.graph.canvas = this; - */ graph.attachCanvas(this); + + //remove the graph stack in case a subgraph was open + if (this._graph_stack) + this._graph_stack = null; + this.setDirty(true, true); }; @@ -11177,7 +11175,7 @@ if (typeof exports != "undefined") { }; Subgraph.prototype.serialize = function() { - var data = LGraphNode.prototype.serialize.call(this); + var data = LiteGraph.LGraphNode.prototype.serialize.call(this); data.subgraph = this.subgraph.serialize(); return data; }; @@ -11650,6 +11648,51 @@ if (typeof exports != "undefined") { LiteGraph.registerNodeType("basic/data", ConstantData); + //to store json objects + function ConstantArray() { + this.addInput("", ""); + this.addOutput("", "array"); + this.addProperty("value", ""); + this.widget = this.addWidget("text","array","","value"); + this.widgets_up = true; + this.size = [140, 30]; + this._value = null; + } + + ConstantArray.title = "Const Array"; + ConstantArray.desc = "Constant Array"; + + ConstantArray.prototype.onPropertyChanged = function(name, value) { + this.widget.value = value; + if (value == null || value == "") { + return; + } + + try { + this._value = JSON.parse(value); + this.boxcolor = "#AEA"; + } catch (err) { + this.boxcolor = "red"; + } + }; + + ConstantArray.prototype.onExecute = function() { + var v = this.getInputData(0); + if(v && v.length) + { + if(!this._value) + this._value = new Array(); + this._value.length = v.length; + for(var i = 0; i < v.length; ++i) + this._value[i] = v[i]; + } + this.setOutputData(0, this._value); + }; + + ConstantArray.prototype.setValue = ConstantNumber.prototype.setValue; + + LiteGraph.registerNodeType("basic/array", ConstantArray); + function ArrayElement() { this.addInput("array", "array,table,string"); this.addInput("index", "number"); @@ -14845,143 +14888,6 @@ if (typeof exports != "undefined") { LiteGraph.registerNodeType("math3d/xyzw-to-vec4", Math3DXYZWToVec4); - //if glMatrix is installed... - if (global.glMatrix) { - function Math3DQuaternion() { - this.addOutput("quat", "quat"); - this.properties = { x: 0, y: 0, z: 0, w: 1 }; - this._value = quat.create(); - } - - Math3DQuaternion.title = "Quaternion"; - Math3DQuaternion.desc = "quaternion"; - - Math3DQuaternion.prototype.onExecute = function() { - this._value[0] = this.properties.x; - this._value[1] = this.properties.y; - this._value[2] = this.properties.z; - this._value[3] = this.properties.w; - this.setOutputData(0, this._value); - }; - - LiteGraph.registerNodeType("math3d/quaternion", Math3DQuaternion); - - function Math3DRotation() { - this.addInputs([["degrees", "number"], ["axis", "vec3"]]); - this.addOutput("quat", "quat"); - this.properties = { angle: 90.0, axis: vec3.fromValues(0, 1, 0) }; - - this._value = quat.create(); - } - - Math3DRotation.title = "Rotation"; - Math3DRotation.desc = "quaternion rotation"; - - Math3DRotation.prototype.onExecute = function() { - var angle = this.getInputData(0); - if (angle == null) { - angle = this.properties.angle; - } - var axis = this.getInputData(1); - if (axis == null) { - axis = this.properties.axis; - } - - var R = quat.setAxisAngle(this._value, axis, angle * 0.0174532925); - this.setOutputData(0, R); - }; - - LiteGraph.registerNodeType("math3d/rotation", Math3DRotation); - - //Math3D rotate vec3 - function Math3DRotateVec3() { - this.addInputs([["vec3", "vec3"], ["quat", "quat"]]); - this.addOutput("result", "vec3"); - this.properties = { vec: [0, 0, 1] }; - } - - Math3DRotateVec3.title = "Rot. Vec3"; - Math3DRotateVec3.desc = "rotate a point"; - - Math3DRotateVec3.prototype.onExecute = function() { - var vec = this.getInputData(0); - if (vec == null) { - vec = this.properties.vec; - } - var quat = this.getInputData(1); - if (quat == null) { - this.setOutputData(vec); - } else { - this.setOutputData( - 0, - vec3.transformQuat(vec3.create(), vec, quat) - ); - } - }; - - LiteGraph.registerNodeType("math3d/rotate_vec3", Math3DRotateVec3); - - function Math3DMultQuat() { - this.addInputs([["A", "quat"], ["B", "quat"]]); - this.addOutput("A*B", "quat"); - - this._value = quat.create(); - } - - Math3DMultQuat.title = "Mult. Quat"; - Math3DMultQuat.desc = "rotate quaternion"; - - Math3DMultQuat.prototype.onExecute = function() { - var A = this.getInputData(0); - if (A == null) { - return; - } - var B = this.getInputData(1); - if (B == null) { - return; - } - - var R = quat.multiply(this._value, A, B); - this.setOutputData(0, R); - }; - - LiteGraph.registerNodeType("math3d/mult-quat", Math3DMultQuat); - - function Math3DQuatSlerp() { - this.addInputs([ - ["A", "quat"], - ["B", "quat"], - ["factor", "number"] - ]); - this.addOutput("slerp", "quat"); - this.addProperty("factor", 0.5); - - this._value = quat.create(); - } - - Math3DQuatSlerp.title = "Quat Slerp"; - Math3DQuatSlerp.desc = "quaternion spherical interpolation"; - - Math3DQuatSlerp.prototype.onExecute = function() { - var A = this.getInputData(0); - if (A == null) { - return; - } - var B = this.getInputData(1); - if (B == null) { - return; - } - var factor = this.properties.factor; - if (this.getInputData(2) != null) { - factor = this.getInputData(2); - } - - var R = quat.slerp(this._value, A, B, factor); - this.setOutputData(0, R); - }; - - LiteGraph.registerNodeType("math3d/quat-slerp", Math3DQuatSlerp); - } //glMatrix })(this); (function(global) { diff --git a/build/litegraph.min.js b/build/litegraph.min.js index e597b5473..d26101b08 100755 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -1,36 +1,36 @@ -(function(y){function c(a){g.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function l(a,b,d,h,f,g){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=h;this.target_id=f;this.target_slot=g;this._data=null;this._pos=new Float32Array(2)}function p(a){this._ctor(a)}function k(a){this._ctor(a)}function w(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=0.1;this.onredraw=null;this.enabled=!0;this.last_mouse= +(function(C){function c(a){g.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function m(a,b,d,h,f,s){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=h;this.target_id=f;this.target_slot=s;this._data=null;this._pos=new Float32Array(2)}function p(a){this._ctor(a)}function k(a){this._ctor(a)}function v(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=0.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 e(a,b,d){d=d||{};this.background_image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; -a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new w;this.zoom_modify_alpha=!0;this.title_text_font=""+g.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+g.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=g.NODE_TITLE_COLOR;this.default_link_color=g.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= +a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new v;this.zoom_modify_alpha=!0;this.title_text_font=""+g.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+g.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=g.NODE_TITLE_COLOR;this.default_link_color=g.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.allow_reconnect_links=!1;this.filter=this.dragging_rectangle=null;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=g.SPLINE_LINK;this.canvas_mouse=[0,0];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=[];b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();this.autoresize=d.autoresize}function C(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,g){return da&&hb?!0:!1}function u(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||da&&hb?!0:!1}function y(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||dc.width-e.width-10&&(f=c.width-e.width-10);q>c.height-e.height-10&&(q=c.height-e.height-10)}g.style.left=f+"px";g.style.top=q+"px";b.scale&&(g.style.transform="scale("+b.scale+")")}function B(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var g=y.LiteGraph={VERSION:0.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, +b.event=null);var s=document.createElement("div");s.className="litegraph litecontextmenu litemenubar-panel";b.className&&(s.className+=" "+b.className);s.style.minWidth=100;s.style.minHeight=100;s.style.pointerEvents="none";setTimeout(function(){s.style.pointerEvents="auto"},100);s.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);s.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);s.addEventListener("mousedown",function(a){if(2== +a.button)return h.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);s.addEventListener("wheel",d,!0);s.addEventListener("mousewheel",d,!0);this.root=s;b.title&&(f=document.createElement("div"),f.className="litemenu-title",f.innerHTML=b.title,s.appendChild(f));var f=0,g;for(g in a){var c=a.constructor==Array?a[g]:g;null!=c&&c.constructor!==String&&(c=void 0===c.content?String(c):c.content);this.addItem(c,a[g],b);f++}s.addEventListener("mouseleave",function(a){h.lock||(s.closing_timer&& +clearTimeout(s.closing_timer),s.closing_timer=setTimeout(h.close.bind(h,a),500))});s.addEventListener("mouseenter",function(a){s.closing_timer&&clearTimeout(s.closing_timer)});g=document;b.event&&(g=b.event.target.ownerDocument);g||(g=document);g.fullscreenElement?g.fullscreenElement.appendChild(s):g.body.appendChild(s);f=b.left||0;g=b.top||0;if(b.event){f=b.event.clientX-10;g=b.event.clientY-10;b.title&&(g-=20);b.parentMenu&&(f=b.parentMenu.root.getBoundingClientRect(),f=f.left+f.width);var c=document.body.getBoundingClientRect(), +e=s.getBoundingClientRect();f>c.width-e.width-10&&(f=c.width-e.width-10);g>c.height-e.height-10&&(g=c.height-e.height-10)}s.style.left=f+"px";s.style.top=g+"px";b.scale&&(s.style.transform="scale("+b.scale+")")}function A(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var g=C.LiteGraph={VERSION:0.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_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",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:{},searchbox_extras:{}, registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;g.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 p.prototype)b.prototype[f]||(b.prototype[f]=p.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=g.BOX_SHAPE;break;case "round":this._shape=g.ROUND_SHAPE;break;case "circle":this._shape=g.CIRCLE_SHAPE;break;case "card":this._shape=g.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 E= -b.supported_extensions[f];E&&E.constructor===String&&(this.node_types_by_file_extension[E.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(g.onNodeTypeRegistered)g.onNodeTypeRegistered(a,b);if(h&&g.onNodeTypeReplaced)g.onNodeTypeReplaced(a,b,h)},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]}, -wrapFunctionAsNode:function(a,b,d,h,f){for(var E=Array(b.length),q="",c=g.getParameterNames(b),e=0;eq&&(q=f.size[0]),c+=f.size[1]+a+g.NODE_TITLE_HEIGHT;b+=q+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||g.ALWAYS;var h=this._nodes_in_order?this._nodes_in_order:this._nodes;if(h)for(var f=0,E=h.length;fr&&(r=f.size[0]),c+=f.size[1]+a+g.NODE_TITLE_HEIGHT;b+=r+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||g.ALWAYS;var h=this._nodes_in_order?this._nodes_in_order:this._nodes;if(h)for(var f=0,s=h.length;f=g.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={}};p.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]=g.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?null:this.outputs[a]._data};p.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;d=this.outputs.length)return g.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 g.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===g.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&& -b.disconnectInput(d);var h=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,h.type,h))return null;var f=b.inputs[d],c=null;if(g.isValidConnection(h.type,f.type)){c=new l(++this.graph.last_link_id,f.type,this.id,a,b.id,d);this.graph.links[c.id]=c;null==h.links&&(h.links=[]);h.links.push(c.id);b.inputs[d].link=c.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!0,c,h);if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,d,!0,c,f);this.graph&& -this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(g.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this,c);return c};p.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return g.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 g.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var h=this.graph.links[d];if(h){var f=this.graph.getNodeById(h.origin_id);if(!f)return!1;var c=f.outputs[h.origin_slot];if(!c||!c.links||0==c.links.length)return!1;for(var q=0,e=c.links.length;q< -e;q++)if(c.links[q]==d){c.links.splice(q,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.INPUT,a,!1,h,b);if(f.onConnectionsChange)f.onConnectionsChange(g.OUTPUT,q,!1,h,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.OUTPUT,f,q),this.graph.onNodeConnectionChange(g.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};p.prototype.getConnectionPos=function(a, +b.disconnectInput(d);var h=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,h.type,h))return null;var f=b.inputs[d],s=null;if(g.isValidConnection(h.type,f.type)){s=new m(++this.graph.last_link_id,f.type,this.id,a,b.id,d);this.graph.links[s.id]=s;null==h.links&&(h.links=[]);h.links.push(s.id);b.inputs[d].link=s.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!0,s,h);if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,d,!0,s,f);this.graph&& +this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(g.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this,s);return s};p.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return g.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 g.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var h=this.graph.links[d];if(h){var f=this.graph.getNodeById(h.origin_id);if(!f)return!1;var s=f.outputs[h.origin_slot];if(!s||!s.links||0==s.links.length)return!1;for(var r=0,c=s.links.length;r< +c;r++)if(s.links[r]==d){s.links.splice(r,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.INPUT,a,!1,h,b);if(f.onConnectionsChange)f.onConnectionsChange(g.OUTPUT,r,!1,h,s);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.OUTPUT,f,r),this.graph.onNodeConnectionChange(g.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};p.prototype.getConnectionPos=function(a, b,d){d=d||new Float32Array(2);var h=0;a&&this.inputs&&(h=this.inputs.length);!a&&this.outputs&&(h=this.outputs.length);var f=0.5*g.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||g.NODE_COLLAPSED_WIDTH,this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-g.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=a?this.pos[0]:this.pos[0]+b,d[1]=this.pos[1]-0.5*g.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*g.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*g.NODE_TITLE_HEIGHT,d;if(a&& h>b&&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+0.5),d[1]=a?this.pos[1]-g.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+0.7)*g.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d}; p.prototype.alignToGrid=function(){this.pos[0]=g.CANVAS_GRID_SIZE*Math.round(this.pos[0]/g.CANVAS_GRID_SIZE);this.pos[1]=g.CANVAS_GRID_SIZE*Math.round(this.pos[1]/g.CANVAS_GRID_SIZE)};p.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>p.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};p.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};p.prototype.loadImage=function(a){var b=new Image; b.src=g.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};p.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})};k.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color; this.font=a.font};k.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}};k.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;dthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var h=this.convertCanvasToOffset(b),d=[h[0]-d[0],h[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(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=g.LGraphCanvas=e;e.link_type_colors={"-1":g.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};e.gradients={};e.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.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()};e.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this.setDirty(!0,!0)))};e.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null"; +h;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};v.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};v.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};v.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};v.prototype.mouseDrag=function(a,b){this.offset[0]+= +a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};v.prototype.changeScale=function(a,b){athis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var h=this.convertCanvasToOffset(b),d=[h[0]-d[0],h[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}}; +v.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};v.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};C.LGraphCanvas=g.LGraphCanvas=e;e.link_type_colors={"-1":g.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};e.gradients={};e.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.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()};e.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)))};e.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.setDirty(!0,!0)};e.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]))}};e.prototype.getCurrentGraph= function(){return this.graph};e.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()}};e.prototype._doNothing=function(a){a.preventDefault(); @@ -108,42 +108,42 @@ this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};e.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()};e.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas"; if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};e.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};e.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};e.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))};e.prototype.stopRendering=function(){this.is_rendering=!1};e.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();e.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup", -this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),h=!1,f=300>g.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();g.closeAllContextMenus(b);if(!this.onMouse||!0!=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,h=!0);var c= -!1;if(d&&this.allow_interaction&&!h&&!this.read_only){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!h&&!1!==d.resizable&&z(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor="se-resize",h=!0;else{if(d.outputs)for(var q=0,m=d.outputs.length;qc[0]+4||a.canvasYc[1]+4)){this.showLinkMenu(d, -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>C([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());f&&!this.read_only&&this.allow_searchbox&&this.showSearchBox(a); -c=!0}!h&&c&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(d,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=g.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); +this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),h=!1,f=300>g.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();g.closeAllContextMenus(b);if(!this.onMouse||!0!=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,h=!0);var s= +!1;if(d&&this.allow_interaction&&!h&&!this.read_only){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!h&&!1!==d.resizable&&z(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor="se-resize",h=!0;else{if(d.outputs)for(var r=0,c=d.outputs.length;rs[0]+4||a.canvasYs[1]+4)){this.showLinkMenu(d, +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>E([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());f&&!this.read_only&&this.allow_searchbox&&this.showSearchBox(a); +s=!0}!h&&s&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(d,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=g.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}}};e.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){e.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_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);for(var h=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,f=this.graph._nodes.length;bq[0]+4||a.canvasYq[1]+4)){f=c;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, +!0}if(h){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 s=this.isOverNodeInput(h,a.canvasX,a.canvasY,f);-1!=s&&h.inputs[s]?g.isValidConnection(this.connecting_output.type,h.inputs[s].type)&&(this._highlight_input=f):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;br[0]+4||a.canvasYr[1]+4)){f=s;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&&(this.resizing_node.size[0]=a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length: 0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*g.NODE_SLOT_HEIGHT+(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(g.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]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]=c;this.dragging_rectangle[2]=h;this.dragging_rectangle[3]=f;f=[];for(c=0;cthis.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]=s;this.dragging_rectangle[2]=h;this.dragging_rectangle[3]=f;f=[];for(s=0;sa.click_time&&z(a.canvasX,a.canvasY,h.pos[0],h.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.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.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(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}};e.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY: --60*a.detail;this.adjustMouseEvent(a);var d=this.ds.scale;0b&&(d*=1/1.1);this.ds.changeScale(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};e.prototype.isOverNodeBox=function(a,b,d){var h=g.NODE_TITLE_HEIGHT;return z(b,d,a.pos[0]+2,a.pos[1]+2-h,h-4,h-4)?!0:!1};e.prototype.isOverNodeInput=function(a,b,d,h){if(a.inputs)for(var f=0,g=a.inputs.length;fb&&(d*=1/1.1);this.ds.changeScale(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};e.prototype.isOverNodeBox=function(a,b,d){var h=g.NODE_TITLE_HEIGHT;return z(b,d,a.pos[0]+2,a.pos[1]+2-h,h-4,h-4)?!0:!1};e.prototype.isOverNodeInput=function(a,b,d,h){if(a.inputs)for(var f=0,g=a.inputs.length;fd-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}};e.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(), a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;dthis.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=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,this)){var q=a._shape||g.BOX_SHAPE;s.set(a.size);var e=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var m=a.getTitle?a.getTitle():a.title;null!=m&&(a._collapsed_width=Math.min(a.size[0],b.measureText(m).width+ -2*g.NODE_TITLE_HEIGHT),s[0]=a._collapsed_width,s[1]=0)}a.clip_area&&(b.save(),b.beginPath(),q==g.BOX_SHAPE?b.rect(0,0,s[0],s[1]):q==g.ROUND_SHAPE?b.roundRect(0,0,s[0],s[1],10):q==g.CIRCLE_SHAPE&&b.arc(0.5*s[0],0.5*s[1],0.5*s[0],0,2*Math.PI),b.clip());a.has_errors&&(h="red");this.drawNodeShape(a,b,s,d,h,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=e?"center":"left";b.font=this.inner_text_font;h=!f;q=this.connecting_output; -b.lineWidth=1;var m=0,r=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;dthis.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var s= +this.editor_alpha;b.globalAlpha=s;this.render_shadows&&!f?(b.shadowColor=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,this)){var r=a._shape||g.BOX_SHAPE;t.set(a.size);var c=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var e=a.getTitle?a.getTitle():a.title;null!=e&&(a._collapsed_width=Math.min(a.size[0],b.measureText(e).width+ +2*g.NODE_TITLE_HEIGHT),t[0]=a._collapsed_width,t[1]=0)}a.clip_area&&(b.save(),b.beginPath(),r==g.BOX_SHAPE?b.rect(0,0,t[0],t[1]):r==g.ROUND_SHAPE?b.roundRect(0,0,t[0],t[1],10):r==g.CIRCLE_SHAPE&&b.arc(0.5*t[0],0.5*t[1],0.5*t[0],0,2*Math.PI),b.clip());a.has_errors&&(h="red");this.drawNodeShape(a,b,t,d,h,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=c?"center":"left";b.font=this.inner_text_font;h=!f;r=this.connecting_output; +b.lineWidth=1;var e=0,n=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;dthis.ds.scale,n=a._shape||a.constructor.shape||g.ROUND_SHAPE,r=a.constructor.title_mode,k=!0;r==g.TRANSPARENT_TITLE?k=!1:r==g.AUTOHIDE_TITLE&& -q&&(k=!0);A[0]=0;A[1]=k?-f:0;A[2]=d[0]+1;A[3]=k?d[1]+f:d[1];q=b.globalAlpha;b.beginPath();n==g.BOX_SHAPE||m?b.fillRect(A[0],A[1],A[2],A[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE?b.roundRect(A[0],A[1],A[2],A[3],this.round_radius,n==g.CARD_SHAPE?0:this.round_radius):n==g.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,A[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b, -this,this.canvas);if(k||r==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,f,d,this.ds.scale,h);else if(r!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){k=a.constructor.title_color||h;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var t=e.gradients[k];t||(t=e.gradients[k]=b.createLinearGradient(0,0,400,0),t.addColorStop(0,k),t.addColorStop(1,"#000"));b.fillStyle=t}else b.fillStyle=k;b.beginPath();n==g.BOX_SHAPE||m?b.rect(0, --f,d[0]+1,f):n!=g.ROUND_SHAPE&&n!=g.CARD_SHAPE||b.roundRect(0,-f,d[0]+1,f,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else n==g.ROUND_SHAPE||n==g.CIRCLE_SHAPE||n==g.CARD_SHAPE?(m&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*f,-0.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||g.NODE_DEFAULT_BOXCOLOR,m?b.fillRect(0.5*f-5,-0.5*f-5,10,10):(b.beginPath(),b.arc(0.5*f,-0.5*f,5,0,2*Math.PI), -b.fill())):(m&&(b.fillStyle="black",b.fillRect(0.5*(f-10)-1,-0.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(f-10),-0.5*(f+10),10,10));b.globalAlpha=q;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,c);!m&&(b.font=this.title_text_font,m=String(a.getTitle()))&&(b.fillStyle=c?"white":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,g.NODE_TITLE_TEXT_Y- -f),b.textAlign="left"):(b.textAlign="left",b.fillText(m,f,g.NODE_TITLE_TEXT_Y-f)));if(a.onDrawTitle)a.onDrawTitle(b)}if(c){if(a.onBounding)a.onBounding(A);r==g.TRANSPARENT_TITLE&&(A[1]-=f,A[3]+=f);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();n==g.BOX_SHAPE?b.rect(-6+A[0],-6+A[1],12+A[2],12+A[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+A[0],-6+A[1],12+A[2],12+A[3],2*this.round_radius):n==g.CARD_SHAPE?b.roundRect(-6+A[0],-6+A[1],12+A[2],12+A[3],2*this.round_radius,2):n== -g.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=h;b.globalAlpha=1}};var r=new Float32Array(4),n=new Float32Array(4),x=new Float32Array(2),v=new Float32Array(2);e.prototype.drawConnections=function(a){var b=g.getTime(),d=this.visible_area;r[0]=d[0]-20;r[1]=d[1]-20;r[2]=d[2]+40;r[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,h=0,f=d.length;h< -f;++h){var c=d[h];if(c.inputs&&c.inputs.length)for(var q=0;qn[2]&&(n[0]+=n[2],n[2]=Math.abs(n[2]));0>n[3]&&(n[1]+=n[3],n[3]=Math.abs(n[3]));if(u(n,r)){var p=m.outputs[k],k=c.inputs[q];if(p&& -k&&(m=p.dir||(m.horizontal?g.DOWN:g.RIGHT),k=k.dir||(c.horizontal?g.UP:g.LEFT),this.renderLink(a,s,t,e,!1,0,null,m,k),e&&e._last_time&&1E3>b-e._last_time)){var p=2-0.002*(b-e._last_time),K=a.globalAlpha;a.globalAlpha=K*p;this.renderLink(a,s,t,e,!0,p,"white",m,k);a.globalAlpha=K}}}}}}a.globalAlpha=1};e.prototype.renderLink=function(a,b,d,h,f,c,q,m,n,r){h&&this.visible_links.push(h);!q&&h&&(q=h.color||e.link_type_colors[h.type]);q||(q=this.default_link_color);null!=h&&this.highlighted_links[h.id]&& -(q="#FFF");m=m||g.RIGHT;n=n||g.LEFT;var k=C(b,d);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(t[0],t[1]),a.rotate(s),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(r[0],r[1]),a.rotate(v), -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=q,t=0;5>t;++t)c=(0.001*g.getTime()+0.2*t)%1,f=this.computeConnectionPoint(b,d,c,m,n),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};e.prototype.computeConnectionPoint=function(a,b,d,h,f){h=h||g.RIGHT;f=f||g.LEFT;var c=C(a,b),q=[a[0],a[1]],e=[b[0],b[1]];switch(h){case g.LEFT:q[0]+=-0.25*c;break;case g.RIGHT:q[0]+=0.25*c;break;case g.UP:q[1]+= --0.25*c;break;case g.DOWN:q[1]+=0.25*c}switch(f){case g.LEFT:e[0]+=-0.25*c;break;case g.RIGHT:e[0]+=0.25*c;break;case g.UP:e[1]+=-0.25*c;break;case g.DOWN:e[1]+=0.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*q[0]+c*e[0]+d*b[0],h*a[1]+f*q[1]+c*e[1]+d*b[1]]};e.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;dt.last_y&&q -t.options.max&&(t.value=t.options.max);else if("mousedown"==d.type){var s=t.options.values;s&&s.constructor===Function&&(s=t.options.values(t,a));var k=s.constructor===Array?s:Object.keys(s),c=40>c?-1:c>e-40?1:0;if("number"==t.type)t.value+=0.1*c*(t.options.step||1),null!=t.options.min&&t.valuet.options.max&&(t.value=t.options.max);else if(c)n=-1,n=s.constructor===Object?k.indexOf(String(t.value))+c:k.indexOf(t.value)+c,n>=k.length&& -(n=k.length-1),0>n&&(n=0),t.value=s.constructor===Array?s[n]:n;else{var v=s!=k?Object.values(s):s;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:p.bind(t)},n);var p=function(a,b,d){s!=k&&(a=v.indexOf(a));this.value=a;f(this,a);m.dirty_canvas=!0;return!1}}}else"mouseup"==d.type&&"number"==t.type&&(c=40>c?-1:c>e-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",t.value,function(a){this.value=Number(a);f(this,this.value)}.bind(t),d));h!=t.value&&setTimeout(function(){f(this, -this.value)}.bind(t),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(t.value=!t.value,setTimeout(function(){f(t,t.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",t.value,function(a){this.value=a;f(this,a)}.bind(t),d);break;default:t.mouse&&t.mouse(ctx,d,[c,q],a)}return t}}return null};e.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var h=0;hthis.ds.scale,l=a._shape||a.constructor.shape||g.ROUND_SHAPE,n=a.constructor.title_mode,k=!0;n==g.TRANSPARENT_TITLE?k=!1:n==g.AUTOHIDE_TITLE&& +r&&(k=!0);B[0]=0;B[1]=k?-f:0;B[2]=d[0]+1;B[3]=k?d[1]+f:d[1];r=b.globalAlpha;b.beginPath();l==g.BOX_SHAPE||c?b.fillRect(B[0],B[1],B[2],B[3]):l==g.ROUND_SHAPE||l==g.CARD_SHAPE?b.roundRect(B[0],B[1],B[2],B[3],this.round_radius,l==g.CARD_SHAPE?0:this.round_radius):l==g.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,B[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b, +this,this.canvas);if(k||n==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,f,d,this.ds.scale,h);else if(n!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){k=a.constructor.title_color||h;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var u=e.gradients[k];u||(u=e.gradients[k]=b.createLinearGradient(0,0,400,0),u.addColorStop(0,k),u.addColorStop(1,"#000"));b.fillStyle=u}else b.fillStyle=k;b.beginPath();l==g.BOX_SHAPE||c?b.rect(0, +-f,d[0]+1,f):l!=g.ROUND_SHAPE&&l!=g.CARD_SHAPE||b.roundRect(0,-f,d[0]+1,f,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else l==g.ROUND_SHAPE||l==g.CIRCLE_SHAPE||l==g.CARD_SHAPE?(c&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*f,-0.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||g.NODE_DEFAULT_BOXCOLOR,c?b.fillRect(0.5*f-5,-0.5*f-5,10,10):(b.beginPath(),b.arc(0.5*f,-0.5*f,5,0,2*Math.PI), +b.fill())):(c&&(b.fillStyle="black",b.fillRect(0.5*(f-10)-1,-0.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(f-10),-0.5*(f+10),10,10));b.globalAlpha=r;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,s);!c&&(b.font=this.title_text_font,c=String(a.getTitle()))&&(b.fillStyle=s?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(c),b.fillText(c.substr(0,20),f,g.NODE_TITLE_TEXT_Y- +f),b.textAlign="left"):(b.textAlign="left",b.fillText(c,f,g.NODE_TITLE_TEXT_Y-f)));if(a.onDrawTitle)a.onDrawTitle(b)}if(s){if(a.onBounding)a.onBounding(B);n==g.TRANSPARENT_TITLE&&(B[1]-=f,B[3]+=f);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();l==g.BOX_SHAPE?b.rect(-6+B[0],-6+B[1],12+B[2],12+B[3]):l==g.ROUND_SHAPE||l==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],2*this.round_radius):l==g.CARD_SHAPE?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],2*this.round_radius,2):l== +g.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=h;b.globalAlpha=1}};var l=new Float32Array(4),q=new Float32Array(4),w=new Float32Array(2),x=new Float32Array(2);e.prototype.drawConnections=function(a){var b=g.getTime(),d=this.visible_area;l[0]=d[0]-20;l[1]=d[1]-20;l[2]=d[2]+40;l[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,h=0,f=d.length;h< +f;++h){var s=d[h];if(s.inputs&&s.inputs.length)for(var r=0;rq[2]&&(q[0]+=q[2],q[2]=Math.abs(q[2]));0>q[3]&&(q[1]+=q[3],q[3]=Math.abs(q[3]));if(y(q,l)){var t=e.outputs[n],n=s.inputs[r];if(t&& +n&&(e=t.dir||(e.horizontal?g.DOWN:g.RIGHT),n=n.dir||(s.horizontal?g.UP:g.LEFT),this.renderLink(a,k,u,c,!1,0,null,e,n),c&&c._last_time&&1E3>b-c._last_time)){var t=2-0.002*(b-c._last_time),p=a.globalAlpha;a.globalAlpha=p*t;this.renderLink(a,k,u,c,!0,t,"white",e,n);a.globalAlpha=p}}}}}}a.globalAlpha=1};e.prototype.renderLink=function(a,b,d,h,f,s,c,l,n,k){h&&this.visible_links.push(h);!c&&h&&(c=h.color||e.link_type_colors[h.type]);c||(c=this.default_link_color);null!=h&&this.highlighted_links[h.id]&& +(c="#FFF");l=l||g.RIGHT;n=n||g.LEFT;var q=E(b,d);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(u[0],u[1]),a.rotate(t),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(k[0],k[1]),a.rotate(x), +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(s)for(a.fillStyle=c,u=0;5>u;++u)s=(0.001*g.getTime()+0.2*u)%1,f=this.computeConnectionPoint(b,d,s,l,n),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};e.prototype.computeConnectionPoint=function(a,b,d,h,f){h=h||g.RIGHT;f=f||g.LEFT;var s=E(a,b),c=[a[0],a[1]],l=[b[0],b[1]];switch(h){case g.LEFT:c[0]+=-0.25*s;break;case g.RIGHT:c[0]+=0.25*s;break;case g.UP:c[1]+= +-0.25*s;break;case g.DOWN:c[1]+=0.25*s}switch(f){case g.LEFT:l[0]+=-0.25*s;break;case g.RIGHT:l[0]+=0.25*s;break;case g.UP:l[1]+=-0.25*s;break;case g.DOWN:l[1]+=0.25*s}h=(1-d)*(1-d)*(1-d);f=3*(1-d)*(1-d)*d;s=3*(1-d)*d*d;d*=d*d;return[h*a[0]+f*c[0]+s*l[0]+d*b[0],h*a[1]+f*c[1]+s*l[1]+d*b[1]]};e.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;du.last_y&&r +u.options.max&&(u.value=u.options.max);else if("mousedown"==d.type){var q=u.options.values;q&&q.constructor===Function&&(q=u.options.values(u,a));var x=q.constructor===Array?q:Object.keys(q),c=40>c?-1:c>l-40?1:0;if("number"==u.type)u.value+=0.1*c*(u.options.step||1),null!=u.options.min&&u.valueu.options.max&&(u.value=u.options.max);else if(c)n=-1,n=q.constructor===Object?x.indexOf(String(u.value))+c:x.indexOf(u.value)+c,n>=x.length&& +(n=x.length-1),0>n&&(n=0),u.value=q.constructor===Array?q[n]:n;else{var t=q!=x?Object.values(q):q;new g.ContextMenu(t,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:p.bind(u)},n);var p=function(a,b,d){q!=x&&(a=t.indexOf(a));this.value=a;f(this,a);e.dirty_canvas=!0;return!1}}}else"mouseup"==d.type&&"number"==u.type&&(c=40>c?-1:c>l-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",u.value,function(a){this.value=Number(a);f(this,this.value)}.bind(u),d));h!=u.value&&setTimeout(function(){f(this, +this.value)}.bind(u),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(u.value=!u.value,setTimeout(function(){f(u,u.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",u.value,function(a){this.value=a;f(this,a)}.bind(u),d);break;default:u.mouse&&u.mouse(ctx,d,[c,r],a)}return u}}return null};e.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var h=0;hd&&0.01>b.editor_alpha&&(clearInterval(h),1>d&&(b.live_mode=!0));1"+n+""+ -a+"",value:n});if(m.length)return new g.ContextMenu(m,{event:d,callback:c,parentMenu:h,allow_html:!0,node:f},b),!1}};e.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};e.onResizeNode=function(a,b,d,h,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};e.prototype.showLinkMenu=function(a,b){var d=this;console.log(a);var h=new g.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g, -c){switch(b){case "Add Node":e.onMenuAdd(null,null,c,h,function(b){console.log("node autoconnect");var h=d.graph.getNodeById(a.origin_id),f=d.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&h.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==f.inputs[0].type&&(h.connect(a.origin_slot,b,0),b.connect(0,f,a.target_slot),b.pos[0]-=0.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};e.onShowPropertyEditor=function(a,b,d,h,f){function g(){var b= -n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));f[c]=b;m.parentNode&&m.parentNode.removeChild(m);f.setDirtyCanvas(!0,!0)}var c=a.property||"title";b=f[c];var m=document.createElement("div");m.className="graphdialog";m.innerHTML="";m.querySelector(".name").innerText=c;var n=m.querySelector("input");n&&(n.value=b,n.addEventListener("blur",function(a){this.focus()}),n.addEventListener("keydown", -function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));b=e.active_canvas.canvas;d=b.getBoundingClientRect();var r=h=-20;d&&(h-=d.left,r-=d.top);event?(m.style.left=event.clientX+h+"px",m.style.top=event.clientY+r+"px"):(m.style.left=0.5*b.width+h+"px",m.style.top=0.5*b.height+r+"px");m.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(m)};e.prototype.prompt=function(a,b,d,h){var f=this;a=a||"";var g=!1,c=document.createElement("div");c.className="graphdialog rounded"; -c.innerHTML=" ";c.close=function(){f.prompt_box=null;c.parentNode&&c.parentNode.removeChild(c)};1"+n+""+ +a+"",value:n});if(l.length)return new g.ContextMenu(l,{event:d,callback:c,parentMenu:h,allow_html:!0,node:f},b),!1}};e.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};e.onResizeNode=function(a,b,d,h,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};e.prototype.showLinkMenu=function(a,b){var d=this;console.log(a);var h=new g.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g, +c){switch(b){case "Add Node":e.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]-=0.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};e.onShowPropertyEditor=function(a,b,d,h,f){function g(){var b= +n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));f[c]=b;l.parentNode&&l.parentNode.removeChild(l);f.setDirtyCanvas(!0,!0)}var c=a.property||"title";b=f[c];var l=document.createElement("div");l.className="graphdialog";l.innerHTML="";l.querySelector(".name").innerText=c;var n=l.querySelector("input");n&&(n.value=b,n.addEventListener("blur",function(a){this.focus()}),n.addEventListener("keydown", +function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));b=e.active_canvas.canvas;d=b.getBoundingClientRect();var q=h=-20;d&&(h-=d.left,q-=d.top);event?(l.style.left=event.clientX+h+"px",l.style.top=event.clientY+q+"px"):(l.style.left=0.5*b.width+h+"px",l.style.top=0.5*b.height+q+"px");l.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(l)};e.prototype.prompt=function(a,b,d,h){var f=this;a=a||"";var g=!1,c=document.createElement("div");c.className="graphdialog rounded"; +c.innerHTML=" ";c.close=function(){f.prompt_box=null;c.parentNode&&c.parentNode.removeChild(c)};1e.search_limit)break}}m=null;if(Array.prototype.filter)m=Object.keys(g.registered_node_types).filter(r);else for(L in m=[],g.registered_node_types)r(L)&&m.push(L);for(L=0;Le.search_limit);L++);var r=function(a){var b=g.registered_node_types[a];return q&&b.filter!=q?!1:-1!==a.toLowerCase().indexOf(d)}}}var f=this,c=e.active_canvas,q=c.canvas,m=q.ownerDocument||document,n=document.createElement("div"); -n.className="litegraph litesearchbox graphdialog rounded";n.innerHTML="Search
";n.close=function(){f.search_box=null;m.body.focus();m.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);n.parentNode&&n.parentNode.removeChild(n)};var r=null;1q.height-200&&(s.style.maxHeight=q.height-a.layerY-20+"px");p.focus();return n};e.prototype.showEditPropertyValue=function(a,b,d){function h(){f(t.value)}function f(h){"number"==typeof a.properties[b]&& -(h=Number(h));if("array"==g||"object"==g)h=JSON.parse(h);a.properties[b]=h;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,h);if(d.onclose)d.onclose();r.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var c=a.getPropertyInfo(b),g=c.type,m="";if("string"==g||"number"==g||"array"==g||"object"==g)m="";else if("enum"==g&&c.values){var m=""}else if("boolean"==g)m="";else{console.warn("unknown type: "+g);return}var r=this.createDialog(""+b+""+m+"",d);if("enum"==g&&c.values){var t=r.querySelector("select");t.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"== -g)(t=r.querySelector("input"))&&t.addEventListener("click",function(a){f(!!t.checked)});else if(t=r.querySelector("input"))t.addEventListener("blur",function(a){this.focus()}),n=void 0!==a.properties[b]?a.properties[b]:"",n=JSON.stringify(n),t.value=n,t.addEventListener("keydown",function(a){13==a.keyCode&&(h(),a.preventDefault(),a.stopPropagation())});r.querySelector("button").addEventListener("click",h);return r}};e.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div"); +[],d.data.outputs)b.addOutput(d.data.outputs[h][0],d.data.outputs[h][1]);d.data.title&&(b.title=d.data.title);d.data.json&&b.configure(d.data.json)}}n.close()}function d(a){var b=t;t&&t.classList.remove("selected");t?(t=a?t.nextSibling:t.previousSibling)||(t=b):t=a?k.childNodes[0]:k.childNodes[k.childNodes.length];t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function h(){function a(d,f){var h=document.createElement("div");u||(u=d);h.innerText=d;h.dataset.type= +escape(d);h.className="litegraph lite-search-item";f&&(h.className+=" "+f);h.addEventListener("click",function(a){b(unescape(this.dataset.type))});k.appendChild(h)}x=null;var d=p.value;u=null;k.innerHTML="";if(d)if(f.onSearchBox){var h=f.onSearchBox(k,d,c);if(h)for(var L=0;Le.search_limit)break}}r=null;if(Array.prototype.filter)r=Object.keys(g.registered_node_types).filter(q);else for(L in r=[],g.registered_node_types)q(L)&&r.push(L);for(L=0;Le.search_limit);L++);var q=function(a){var b=g.registered_node_types[a];return l&&b.filter!=l?!1:-1!==a.toLowerCase().indexOf(d)}}}var f=this,c=e.active_canvas,r=c.canvas,l=r.ownerDocument||document,n=document.createElement("div"); +n.className="litegraph litesearchbox graphdialog rounded";n.innerHTML="Search
";n.close=function(){f.search_box=null;l.body.focus();l.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);n.parentNode&&n.parentNode.removeChild(n)};var q=null;1r.height-200&&(k.style.maxHeight=r.height-a.layerY-20+"px");p.focus();return n};e.prototype.showEditPropertyValue=function(a,b,d){function h(){f(u.value)}function f(f){"number"==typeof a.properties[b]&& +(f=Number(f));if("array"==g||"object"==g)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();q.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var c=a.getPropertyInfo(b),g=c.type,l="";if("string"==g||"number"==g||"array"==g||"object"==g)l="";else if("enum"==g&&c.values){var l=""}else if("boolean"==g)l="";else{console.warn("unknown type: "+g);return}var q=this.createDialog(""+b+""+l+"",d);if("enum"==g&&c.values){var u=q.querySelector("select");u.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"== +g)(u=q.querySelector("input"))&&u.addEventListener("click",function(a){f(!!u.checked)});else if(u=q.querySelector("input"))u.addEventListener("blur",function(a){this.focus()}),e=void 0!==a.properties[b]?a.properties[b]:"",e=JSON.stringify(e),u.value=e,u.addEventListener("keydown",function(a){13==a.keyCode&&(h(),a.preventDefault(),a.stopPropagation())});q.querySelector("button").addEventListener("click",h);return q}};e.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div"); d.className="graphdialog";d.innerHTML=a;var h=this.canvas.getBoundingClientRect(),f=-20,c=-20;h&&(f-=h.left,c-=h.top);b.position?(f+=b.position[0],c+=b.position[1]):b.event?(f+=b.event.clientX,c+=b.event.clientY):(f+=0.5*this.canvas.width,c+=0.5*this.canvas.height);d.style.left=f+"px";d.style.top=c+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};e.onMenuNodeCollapse=function(a,b,d,h,f){f.collapse()};e.onMenuNodePin=function(a, b,d,h,f){f.pin()};e.onMenuNodeMode=function(a,b,d,h,f){new g.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(f)switch(a){case "On Event":f.mode=g.ON_EVENT;break;case "On Trigger":f.mode=g.ON_TRIGGER;break;case "Never":f.mode=g.NEVER;break;default:f.mode=g.ALWAYS}},parentMenu:h,node:f});return!1};e.onMenuNodeColors=function(a,b,d,h,f){if(!f)throw"no node for color";b=[];b.push({value:null,content:"No color"}); for(var c in e.node_colors)a=e.node_colors[c],a={value:c,content:""+c+""},b.push(a);new g.ContextMenu(b,{event:d,callback:function(a){f&&((a=a.value?e.node_colors[a.value]:null)?f.constructor===g.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};e.onMenuNodeShapes= @@ -223,493 +223,489 @@ brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#23 null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:e.onMenuAdd},{content:"Add Group",callback:e.onGroupAdd}],this._graph_stack&&0Name",h),m=g.querySelector("input");m&&c&&(m.value=c.label||"");g.querySelector("button").addEventListener("click",function(a){m.value&& -(c&&(c.label=m.value),d.setDirty(!0));g.close()})}},extra:a};a&&(c.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),e.active_node=a);if(m){f=[];m&&m.output&&m.output.links&&m.output.links.length&&f.push({content:"Disconnect Links",slot:m});var n=m.input||m.output;f.push(n.locked?"Cannot remove":{content:"Remove Slot",slot:m});f.push(n.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m});c.title=(m.input?m.input.type:m.output.type)||"*";m.input&&m.input.type==g.ACTION&& -(c.title="Action");m.output&&m.output.type==g.EVENT&&(c.title="Event")}else a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(),(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));f&&new g.ContextMenu(f,c,h)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,h,f,c){void 0===f&&(f=5);void 0===c&&(c=f);this.moveTo(a+f,b);this.lineTo(a+ -d-f,b);this.quadraticCurveTo(a+d,b,a+d,b+f);this.lineTo(a+d,b+h-c);this.quadraticCurveTo(a+d,b+h,a+d-c,b+h);this.lineTo(a+c,b+h);this.quadraticCurveTo(a,b+h,a,b+h-c);this.lineTo(a,b+f);this.quadraticCurveTo(a,b,a+f,b)});g.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};g.distance=C;g.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")+")"};g.isInsideRectangle= -z;g.growBounding=function(a,b,d){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};g.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};g.overlapBounding=u;g.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,h,f,c=0;6>c;c+=2)h="0123456789ABCDEF".indexOf(a.charAt(c)),f="0123456789ABCDEF".indexOf(a.charAt(c+1)),b[d]=16*h+f,d++;return b};g.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};D.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,h=!0;c.current_submenu&&c.current_submenu.close(a);if(d.callback){var f=d.callback.call(this,b,d,a,c,d.node);!0===f&&(h=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(f=b.callback.call(this,b,d,a,c,d.extra),!0===f&&(h=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options"; -new c.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:c,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});h=!1}h&&!c.lock&&c.close()}var c=this;d=d||{};var g=document.createElement("div");g.className="litemenu-entry submenu";var m=!1;if(null===b)g.classList.add("separator");else{g.innerHTML=b&&b.title?b.title:a;if(g.value=b)b.disabled&&(m=!0,g.classList.add("disabled")),(b.submenu||b.has_submenu)&& -g.classList.add("has_submenu");"function"==typeof b?(g.dataset.value=a,g.onclick_callback=b):g.dataset.value=b;b.className&&(g.className+=" "+b.className)}this.root.appendChild(g);m||g.addEventListener("click",f);d.autoopen&&g.addEventListener("mouseenter",h);return g};D.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&&!D.isCursorOverElement(a, +a);return b};e.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:e.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:e.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:e.onShowPropertyEditor},null,{content:"Remove",callback:e.onMenuNodeRemove}]};e.prototype.processContextMenu=function(a,b){var d=this,h=e.active_canvas.getCanvasWindow(),f=null,c={event:b,callback:function(b,f,h){if(b)if("Remove Slot"==b.content)b=b.slot,b.input? +a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var c=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),g=d.createDialog("Name",f),s=g.querySelector("input");s&&c&&(s.value=c.label||"");g.querySelector("button").addEventListener("click",function(a){s.value&& +(c&&(c.label=s.value),d.setDirty(!0));g.close()})}},extra:a};a&&(c.title=a.type);var l=null;a&&(l=a.getSlotInPosition(b.canvasX,b.canvasY),e.active_node=a);if(l){f=[];l&&l.output&&l.output.links&&l.output.links.length&&f.push({content:"Disconnect Links",slot:l});var n=l.input||l.output;f.push(n.locked?"Cannot remove":{content:"Remove Slot",slot:l});f.push(n.nameLocked?"Cannot rename":{content:"Rename Slot",slot:l});c.title=(l.input?l.input.type:l.output.type)||"*";l.input&&l.input.type==g.ACTION&& +(c.title="Action");l.output&&l.output.type==g.EVENT&&(c.title="Event")}else 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 g.ContextMenu(f,c,h)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,h,f,c){void 0===f&&(f=5);void 0===c&&(c=f);this.moveTo(a+f,b);this.lineTo(a+ +d-f,b);this.quadraticCurveTo(a+d,b,a+d,b+f);this.lineTo(a+d,b+h-c);this.quadraticCurveTo(a+d,b+h,a+d-c,b+h);this.lineTo(a+c,b+h);this.quadraticCurveTo(a,b+h,a,b+h-c);this.lineTo(a,b+f);this.quadraticCurveTo(a,b,a+f,b)});g.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};g.distance=E;g.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")+")"};g.isInsideRectangle= +z;g.growBounding=function(a,b,d){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};g.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};g.overlapBounding=y;g.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,h,f,c=0;6>c;c+=2)h="0123456789ABCDEF".indexOf(a.charAt(c)),f="0123456789ABCDEF".indexOf(a.charAt(c+1)),b[d]=16*h+f,d++;return b};g.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};D.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;c.current_submenu&&c.current_submenu.close(a);if(d.callback){var h=d.callback.call(this,b,d,a,c,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,c,d.extra),!0===h&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options"; +new c.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:c,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});f=!1}f&&!c.lock&&c.close()}var c=this;d=d||{};var g=document.createElement("div");g.className="litemenu-entry submenu";var l=!1;if(null===b)g.classList.add("separator");else{g.innerHTML=b&&b.title?b.title:a;if(g.value=b)b.disabled&&(l=!0,g.classList.add("disabled")),(b.submenu||b.has_submenu)&& +g.classList.add("has_submenu");"function"==typeof b?(g.dataset.value=a,g.onclick_callback=b):g.dataset.value=b;b.className&&(g.className+=" "+b.className)}this.root.appendChild(g);l||g.addEventListener("click",f);d.autoopen&&g.addEventListener("mouseenter",h);return g};D.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&&!D.isCursorOverElement(a, this.parentMenu.root)&&D.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};D.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};D.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};D.prototype.getFirstEvent= function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};D.isCursorOverElement=function(a,b){var d=a.clientX,h=a.clientY,f=b.getBoundingClientRect();return f?h>f.top&&hf.left&&dMath.abs(d))return h[1];d=(a-h[0])/d;return h[1]*(1-d)+f[1]*d}}return 0}};B.prototype.draw=function(a,b,d,h,f,c){if(d=this.points){this.size=b;var g=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,g,b),a.fillStyle="#222",a.fillRect(0.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=f;c&&(a.globalAlpha=0.5);a.beginPath();for(h=0;ha[1])){var h=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,c=a[0]-this.margin,g=a[1]-this.margin;this.selected=this.getCloserPoint([c,g],30/b.ds.scale);-1==this.selected&&(h=[c/h,1-g/f],d.push(h),d.sort(function(a,b){return a[0]- -b[0]}),this.selected=d.indexOf(h),this.must_update=!0);if(-1!=this.selected)return!0}};B.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),c=(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);var g=d[h];if(g){var m=0==h||h==d.length-1;!m&&(-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):(g[0]=m?0==h?0:1:Math.clamp(f,0,1),g[1]=1-Math.clamp(c,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(g),this.must_update=!0)}}}};B.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};B.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,c=d.length,g=[0,0],m=1E6,n=-1,e=0;em||r>b||(n=e,m=r)}return n};g.CurveEditor= -B;g.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:dMath.abs(d))return h[1];d=(a-h[0])/d;return h[1]*(1-d)+f[1]*d}}return 0}};A.prototype.draw=function(a,b,d,h,f,c){if(d=this.points){this.size=b;var g=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,g,b),a.fillStyle="#222",a.fillRect(0.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=f;c&&(a.globalAlpha=0.5);a.beginPath();for(h=0;ha[1])){var h=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,c=a[0]-this.margin,g=a[1]-this.margin;this.selected=this.getCloserPoint([c,g],30/b.ds.scale);-1==this.selected&&(h=[c/h,1-g/f],d.push(h),d.sort(function(a,b){return a[0]- +b[0]}),this.selected=d.indexOf(h),this.must_update=!0);if(-1!=this.selected)return!0}};A.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),c=(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);var g=d[h];if(g){var l=0==h||h==d.length-1;!l&&(-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):(g[0]=l?0==h?0:1:Math.clamp(f,0,1),g[1]=1-Math.clamp(c,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(g),this.must_update=!0)}}}};A.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};A.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,c=d.length,g=[0,0],l=1E6,n=-1,e=0;el||q>b||(n=e,l=q)}return n};g.CurveEditor= +A;g.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:dthis.size[0]-d.NODE_TITLE_HEIGHT&&0>b[1]){var g=this;setTimeout(function(){c.openSubgraph(g.subgraph)},10)}};l.prototype.onAction=function(a,b){this.subgraph.onAction(a,b)};l.prototype.onExecute=function(){if(this.enabled=this.getInputOrProperty("enabled")){if(this.inputs)for(var a=0;a=g?this.trigger(null,e):this._pending.push([g,e])};e.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;em[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};p.prototype.onMouseMove=function(c){if(this.mouse_captured){var m=this.old_y-c.canvasY;c.shiftKey&&(m*=10);if(c.metaKey||c.altKey)m*=0.1;this.old_y=c.canvasY;c=this._remainder+m/p.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)}};p.prototype.onMouseUp=function(c,m){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(m[1]>0.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))};B.registerNodeType("widget/number",p);k.title= -"Combo";k.desc="Widget to select from a list";k.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};k.prototype.onPropertyChanged=function(c,m){"values"==c?(this._values=m.split(";"),this.widget.options.values=this._values):"value"==c&&(this.widget.value=m)};B.registerNodeType("widget/combo",k);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 m=0.5*this.size[0],e=0.5*this.size[1],k=0.5*Math.min(this.size[0],this.size[1])-5;c.globalAlpha=1;c.save();c.translate(m,e);c.rotate(0.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(0.01,this.value));c.closePath();c.fill();c.lineWidth=1;c.globalAlpha=1;c.restore(); -c.fillStyle="black";c.beginPath();c.arc(m,e,0.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+0.75*Math.PI;c.arc(m+Math.cos(r)*k*0.65,e+Math.sin(r)*k*0.65,0.05*k,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";c.font=Math.floor(0.5*k)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision),m,e+0.15*k)}};w.prototype.onExecute=function(){this.setOutputData(0, -this.properties.value);this.boxcolor=B.colorToString([this.value,this.value,this.value])};w.prototype.onMouseDown=function(c){this.center=[0.5*this.size[0],0.5*this.size[1]+20];this.radius=0.5*this.size[0];if(20>c.canvasY-this.pos[1]||B.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=e-0.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,e){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(e),!0};B.registerNodeType("widget/knob", -w);e.title="Inner Slider";e.prototype.onPropertyChanged=function(c,e){"value"==c&&(this.slider.value=e)};e.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};B.registerNodeType("widget/internal_slider",e);C.title="H.Slider";C.desc="Linear slider controller";C.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()};C.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=B.colorToString([this.value,this.value,this.value])};C.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};C.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value,e=e+(c[0]-this.oldmouse[0])/this.size[0];1e&&(e=0);this.value=e;this.oldmouse=c;this.setDirtyCanvas(!0)}};C.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};C.prototype.onMouseLeave=function(c){};B.registerNodeType("widget/hslider",C);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)};B.registerNodeType("widget/progress",z);u.title="Text";u.desc="Shows the input value";u.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text", -text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];u.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 k=this.properties.fontsize;c.textAlign=this.properties.align;c.font=k.toString()+"px "+this.properties.font;this.str="number"==typeof e?e.toFixed(this.properties.decimals): -e;if("string"==typeof this.str){var e=this.str.split("\\n"),p;for(p in e)c.fillText(e[p],"left"==this.properties.align?15:this.size[0]-15,-0.15*k+k*(parseInt(p)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};u.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};u.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var e=0,k;for(k in c){var p=this.last_ctx.measureText(c[k]).width; -ethis.size[0]-h.NODE_TITLE_HEIGHT&&0>b[1]){var c=this;setTimeout(function(){d.openSubgraph(c.subgraph)},10)}};m.prototype.onAction=function(a,b){this.subgraph.onAction(a,b)};m.prototype.onExecute=function(){if(this.enabled= +this.getInputOrProperty("enabled")){if(this.inputs)for(var a=0;a=g?this.trigger(null,e):this._pending.push([g,e])};e.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;en[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};p.prototype.onMouseMove=function(c){if(this.mouse_captured){var n=this.old_y-c.canvasY;c.shiftKey&&(n*=10);if(c.metaKey||c.altKey)n*=0.1;this.old_y=c.canvasY;c=this._remainder+n/p.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)}};p.prototype.onMouseUp=function(c,n){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(n[1]>0.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))};A.registerNodeType("widget/number",p);k.title= +"Combo";k.desc="Widget to select from a list";k.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};k.prototype.onPropertyChanged=function(c,n){"values"==c?(this._values=n.split(";"),this.widget.options.values=this._values):"value"==c&&(this.widget.value=n)};A.registerNodeType("widget/combo",k);v.title="Knob";v.desc="Circular controller";v.size=[80,100];v.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 n=0.5*this.size[0],e=0.5*this.size[1],k=0.5*Math.min(this.size[0],this.size[1])-5;c.globalAlpha=1;c.save();c.translate(n,e);c.rotate(0.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(0.01,this.value));c.closePath();c.fill();c.lineWidth=1;c.globalAlpha=1;c.restore(); +c.fillStyle="black";c.beginPath();c.arc(n,e,0.75*k,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":this.properties.color;c.beginPath();var l=this.value*Math.PI*1.5+0.75*Math.PI;c.arc(n+Math.cos(l)*k*0.65,e+Math.sin(l)*k*0.65,0.05*k,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";c.font=Math.floor(0.5*k)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision),n,e+0.15*k)}};v.prototype.onExecute=function(){this.setOutputData(0, +this.properties.value);this.boxcolor=A.colorToString([this.value,this.value,this.value])};v.prototype.onMouseDown=function(c){this.center=[0.5*this.size[0],0.5*this.size[1]+20];this.radius=0.5*this.size[0];if(20>c.canvasY-this.pos[1]||A.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};v.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX- +this.pos[0],c.canvasY-this.pos[1]];var e=this.value,e=e-0.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)}};v.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};v.prototype.onPropertyChanged=function(c,e){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(e),!0};A.registerNodeType("widget/knob", +v);e.title="Inner Slider";e.prototype.onPropertyChanged=function(c,e){"value"==c&&(this.slider.value=e)};e.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};A.registerNodeType("widget/internal_slider",e);E.title="H.Slider";E.desc="Linear slider controller";E.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()};E.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=A.colorToString([this.value,this.value,this.value])};E.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};E.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value,e=e+(c[0]-this.oldmouse[0])/this.size[0];1e&&(e=0);this.value=e;this.oldmouse=c;this.setDirtyCanvas(!0)}};E.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};E.prototype.onMouseLeave=function(c){};A.registerNodeType("widget/hslider",E);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)};A.registerNodeType("widget/progress",z);y.title="Text";y.desc="Shows the input value";y.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text", +text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];y.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 k=this.properties.fontsize;c.textAlign=this.properties.align;c.font=k.toString()+"px "+this.properties.font;this.str="number"==typeof e?e.toFixed(this.properties.decimals): +e;if("string"==typeof this.str){var e=this.str.split("\\n"),p;for(p in e)c.fillText(e[p],"left"==this.properties.align?15:this.size[0]-15,-0.15*k+k*(parseInt(p)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};y.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};y.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var e=0,k;for(k in c){var p=this.last_ctx.measureText(c[k]).width; +ek?p.xbox.axes.lx:0,this._left_axis[1]=Math.abs(p.xbox.axes.ly)>k?p.xbox.axes.ly:0,this._right_axis[0]=Math.abs(p.xbox.axes.rx)>k?p.xbox.axes.rx:0,this._right_axis[1]=Math.abs(p.xbox.axes.ry)>k?p.xbox.axes.ry:0,this._triggers[0]=Math.abs(p.xbox.axes.ltrigger)>k?p.xbox.axes.ltrigger: -0,this._triggers[1]=Math.abs(p.xbox.axes.rtrigger)>k?p.xbox.axes.rtrigger:0);if(this.outputs)for(k=0;kk?p.xbox.axes.rtrigger:0);if(this.outputs)for(k=0;kp;p++)if(k[p]){p=k[p];k=this.xbox_mapping;k||(k=this.xbox_mapping={axes:[], -buttons:{},hat:"",hatmap:c.CENTER});k.axes.lx=p.axes[0];k.axes.ly=p.axes[1];k.axes.rx=p.axes[2];k.axes.ry=p.axes[3];k.axes.ltrigger=p.buttons[6].value;k.axes.rtrigger=p.buttons[7].value;k.hat="";k.hatmap=c.CENTER;for(var l=0;ll)k.buttons[c.mapping_array[l]]=p.buttons[l].pressed,p.buttons[l].was_pressed&&this.trigger(c.mapping_array[l]+"_button_event");else switch(l){case 12:p.buttons[l].pressed&&(k.hat+="up",k.hatmap|=c.UP); -break;case 13:p.buttons[l].pressed&&(k.hat+="down",k.hatmap|=c.DOWN);break;case 14:p.buttons[l].pressed&&(k.hat+="left",k.hatmap|=c.LEFT);break;case 15:p.buttons[l].pressed&&(k.hat+="right",k.hatmap|=c.RIGHT);break;case 16:k.buttons.home=p.buttons[l].pressed}p.xbox=k;return p}};c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var k=this._left_axis,l=this._right_axis;c.strokeStyle="#88A";c.strokeRect(0.5*(k[0]+1)*this.size[0]-4,0.5*(k[1]+1)*this.size[1]-4,8,8);c.strokeStyle="#8A8"; -c.strokeRect(0.5*(l[0]+1)*this.size[0]-4,0.5*(l[1]+1)*this.size[1]-4,8,8);k=this.size[1]/this._current_buttons.length;c.fillStyle="#AEB";for(l=0;lm)k.buttons[c.mapping_array[m]]=p.buttons[m].pressed,p.buttons[m].was_pressed&&this.trigger(c.mapping_array[m]+"_button_event");else switch(m){case 12:p.buttons[m].pressed&&(k.hat+="up",k.hatmap|=c.UP); +break;case 13:p.buttons[m].pressed&&(k.hat+="down",k.hatmap|=c.DOWN);break;case 14:p.buttons[m].pressed&&(k.hat+="left",k.hatmap|=c.LEFT);break;case 15:p.buttons[m].pressed&&(k.hat+="right",k.hatmap|=c.RIGHT);break;case 16:k.buttons.home=p.buttons[m].pressed}p.xbox=k;return p}};c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var k=this._left_axis,m=this._right_axis;c.strokeStyle="#88A";c.strokeRect(0.5*(k[0]+1)*this.size[0]-4,0.5*(k[1]+1)*this.size[1]-4,8,8);c.strokeStyle="#8A8"; +c.strokeRect(0.5*(m[0]+1)*this.size[0]-4,0.5*(m[1]+1)*this.size[1]-4,8,8);k=this.size[1]/this._current_buttons.length;c.fillStyle="#AEB";for(m=0;m","enum",{values:a.values});this.size=[80,60]}function b(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function d(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl= -"nodes/imgs/icon-sin.png"}function h(){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",F.allow_scripts,function(a){F.allow_scripts=a});this._func=null}function f(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function E(){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 I(){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 J(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number"); -this.addOutput("z","number");this.addOutput("w","number")}function H(){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 F=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=e.data[c];c=e.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return d*(1-a)+c*a};e.prototype.onExecute=function(){var a=this.getInputData(0)||0,a=e.getValue(a,this.properties.smooth), -b=this.properties.min;this._last_v=a*(this.properties.max-b)+b;this.setOutputData(0,this._last_v)};e.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};F.registerNodeType("math/noise",e);C.title="Spikes";C.desc="spike every random time";C.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)};F.registerNodeType("math/spikes",C);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};F.registerNodeType("math/clamp",z);u.title="Lerp";u.desc="Linear Interpolation";u.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)};u.prototype.onGetInputs=function(){return[["f","number"]]};F.registerNodeType("math/lerp",u);D.title="Abs";D.desc="Absolute";D.prototype.onExecute= -function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};F.registerNodeType("math/abs",D);B.title="Floor";B.desc="Floor number to remove fractional part";B.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};F.registerNodeType("math/floor",B);g.title="Frac";g.desc="Returns fractional part";g.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};F.registerNodeType("math/frac",g);m.title= -"Smoothstep";m.desc="Smoothstep";m.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))}};F.registerNodeType("math/smoothstep",m);s.title="Scale";s.desc="v * factor";s.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};F.registerNodeType("math/scale",s);A.title="Gate";A.desc="if v is true, then outputs A, otherwise B"; -A.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};F.registerNodeType("math/gate",A);r.title="Average";r.desc="Average Filter";r.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);var d=this._values;this._values=new Float32Array(this.properties.samples);d.length<=this._values.length?this._values.set(d):this._values.set(d.subarray(0,this._values.length))};F.registerNodeType("math/average",r);n.title="TendTo";n.desc="moves the output value always closer to the input";n.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)};F.registerNodeType("math/tendTo", -n);x.values="+ - * / % ^ max min".split(" ");x.title="Operation";x.desc="Easy math operators";x["@OP"]={type:"enum",title:"operation",values:x.values};x.size=[100,60];x.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};x.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};x.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a? -this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=b:b=this.properties.B;var d=0;switch(this.properties.OP){case "+":d=a+b;break;case "-":d=a-b;break;case "x":case "X":case "*":d=a*b;break;case "/":d=a/b;break;case "%":d=a%b;break;case "^":d=Math.pow(a,b);break;case "max":d=Math.max(a,b);break;case "min":d=Math.min(a,b);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,d)};x.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font= -"40px Arial",a.fillStyle="#666",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.5*(this.size[1]+F.NODE_TITLE_HEIGHT)),a.textAlign="left")};F.registerNodeType("math/operation",x);F.registerSearchboxExtra("math/operation","MAX",{properties:{OP:"max"},title:"MAX()"});F.registerSearchboxExtra("math/operation","MIN",{properties:{OP:"min"},title:"MIN()"});v.title="Compare";v.desc="compares between two values";v.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1); -void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var d=0,c=this.outputs.length;dB":f=a>b;break;case "A=B":f=a>=b}this.setOutputData(d,f)}}};v.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B", -"boolean"],["A<=B","boolean"]]};F.registerNodeType("math/compare",v);F.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});F.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});F.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});F.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"}); +["out_min","number"],["out_max","number"]]};F.registerNodeType("math/range",k);v.title="Rand";v.desc="Random number";v.prototype.onExecute=function(){if(this.inputs)for(var a=0;aa&&(a+=1024);var c=Math.floor(a);a-=c;d=e.data[c];c=e.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return d*(1-a)+c*a};e.prototype.onExecute=function(){var a=this.getInputData(0)||0,a=e.getValue(a,this.properties.smooth), +b=this.properties.min;this._last_v=a*(this.properties.max-b)+b;this.setOutputData(0,this._last_v)};e.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};F.registerNodeType("math/noise",e);E.title="Spikes";E.desc="spike every random time";E.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)};F.registerNodeType("math/spikes",E);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};F.registerNodeType("math/clamp",z);y.title="Lerp";y.desc="Linear Interpolation";y.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)};y.prototype.onGetInputs=function(){return[["f","number"]]};F.registerNodeType("math/lerp",y);D.title="Abs";D.desc="Absolute";D.prototype.onExecute= +function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};F.registerNodeType("math/abs",D);A.title="Floor";A.desc="Floor number to remove fractional part";A.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};F.registerNodeType("math/floor",A);g.title="Frac";g.desc="Returns fractional part";g.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};F.registerNodeType("math/frac",g);n.title= +"Smoothstep";n.desc="Smoothstep";n.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))}};F.registerNodeType("math/smoothstep",n);t.title="Scale";t.desc="v * factor";t.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};F.registerNodeType("math/scale",t);B.title="Gate";B.desc="if v is true, then outputs A, otherwise B"; +B.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};F.registerNodeType("math/gate",B);l.title="Average";l.desc="Average Filter";l.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);var d=this._values;this._values=new Float32Array(this.properties.samples);d.length<=this._values.length?this._values.set(d):this._values.set(d.subarray(0,this._values.length))};F.registerNodeType("math/average",l);q.title="TendTo";q.desc="moves the output value always closer to the input";q.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)};F.registerNodeType("math/tendTo", +q);w.values="+ - * / % ^ max min".split(" ");w.title="Operation";w.desc="Easy math operators";w["@OP"]={type:"enum",title:"operation",values:w.values};w.size=[100,60];w.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};w.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};w.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a? +this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=b:b=this.properties.B;var d=0;switch(this.properties.OP){case "+":d=a+b;break;case "-":d=a-b;break;case "x":case "X":case "*":d=a*b;break;case "/":d=a/b;break;case "%":d=a%b;break;case "^":d=Math.pow(a,b);break;case "max":d=Math.max(a,b);break;case "min":d=Math.min(a,b);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,d)};w.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font= +"40px Arial",a.fillStyle="#666",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.5*(this.size[1]+F.NODE_TITLE_HEIGHT)),a.textAlign="left")};F.registerNodeType("math/operation",w);F.registerSearchboxExtra("math/operation","MAX",{properties:{OP:"max"},title:"MAX()"});F.registerSearchboxExtra("math/operation","MIN",{properties:{OP:"min"},title:"MIN()"});x.title="Compare";x.desc="compares between two values";x.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1); +void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var d=0,c=this.outputs.length;dB":f=a>b;break;case "A=B":f=a>=b}this.setOutputData(d,f)}}};x.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B", +"boolean"],["A<=B","boolean"]]};F.registerNodeType("math/compare",x);F.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});F.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});F.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});F.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"}); F.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)};F.registerNodeType("math/condition",a);b.title="Accumulate";b.desc="Increments a value every time";b.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)};F.registerNodeType("math/accumulate",b);d.title="Trigonometry";d.desc="Sin Cos Tan";d.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));for(var d=0,h=this.outputs.length;d< h;++d){var f;switch(this.outputs[d].name){case "sin":f=Math.sin(a);break;case "cos":f=Math.cos(a);break;case "tan":f=Math.tan(a);break;case "asin":f=Math.asin(a);break;case "acos":f=Math.acos(a);break;case "atan":f=Math.atan(a)}this.setOutputData(d,b*f+c)}};d.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};d.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]}; -F.registerNodeType("math/trigonometry",d);F.registerSearchboxExtra("math/trigonometry","SIN()",{outputs:[["sin","number"]],title:"SIN()"});F.registerSearchboxExtra("math/trigonometry","COS()",{outputs:[["cos","number"]],title:"COS()"});F.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});h.title="Formula";h.desc="Compute formula";h.size=[160,100];r.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};h.prototype.onExecute= +F.registerNodeType("math/trigonometry",d);F.registerSearchboxExtra("math/trigonometry","SIN()",{outputs:[["sin","number"]],title:"SIN()"});F.registerSearchboxExtra("math/trigonometry","COS()",{outputs:[["cos","number"]],title:"COS()"});F.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});h.title="Formula";h.desc="Compute formula";h.size=[160,100];l.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};h.prototype.onExecute= function(){if(F.allow_scripts){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;var d;try{this._func&&this._func_code==this.properties.formula||(this._func=new Function("x","y","TIME","return "+this.properties.formula),this._func_code=this.properties.formula),d=this._func(a,b,this.graph.globaltime),this.boxcolor=null}catch(c){this.boxcolor="red"}this.setOutputData(0,d)}};h.prototype.getTitle=function(){return this._func_code|| -"Formula"};h.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};F.registerNodeType("math/formula",h);f.title="Vec2->XY";f.desc="vector 2 to components";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};F.registerNodeType("math3d/vec2-to-xy",f);E.title="XY->Vec2";E.desc="components to vector2";E.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)};F.registerNodeType("math3d/xy-to-vec2",E);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]))};F.registerNodeType("math3d/vec3-to-xyz",q);I.title="XYZ->Vec3";I.desc="components to vector3";I.prototype.onExecute= +"Formula"};h.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};F.registerNodeType("math/formula",h);f.title="Vec2->XY";f.desc="vector 2 to components";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};F.registerNodeType("math3d/vec2-to-xy",f);s.title="XY->Vec2";s.desc="components to vector2";s.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)};F.registerNodeType("math3d/xy-to-vec2",s);r.title="Vec3->XYZ";r.desc="vector 3 to components";r.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]))};F.registerNodeType("math3d/vec3-to-xyz",r);I.title="XYZ->Vec3";I.desc="components to vector3";I.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)};F.registerNodeType("math3d/xyz-to-vec3",I);J.title="Vec4->XYZW";J.desc="vector 4 to components";J.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]))};F.registerNodeType("math3d/vec4-to-xyzw",J);H.title="XYZW->Vec4";H.desc="components to vector4";H.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)};F.registerNodeType("math3d/xyzw-to-vec4",H);y.glMatrix&&(y=function(){this.addOutput("quat", -"quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},y.title="Quaternion",y.desc="quaternion",y.prototype.onExecute=function(){this._value[0]=this.properties.x;this._value[1]=this.properties.y;this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},F.registerNodeType("math3d/quaternion",y),y=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()},y.title="Rotation",y.desc="quaternion rotation",y.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.angle);var b=this.getInputData(1);null==b&&(b=this.properties.axis);a=quat.setAxisAngle(this._value,b,0.0174532925*a);this.setOutputData(0,a)},F.registerNodeType("math3d/rotation",y),y=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},y.title="Rot. Vec3",y.desc= -"rotate a point",y.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.vec);var b=this.getInputData(1);null==b?this.setOutputData(a):this.setOutputData(0,vec3.transformQuat(vec3.create(),a,b))},F.registerNodeType("math3d/rotate_vec3",y),y=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},y.title="Mult. Quat",y.desc="rotate quaternion",y.prototype.onExecute=function(){var a=this.getInputData(0);if(null!= -a){var b=this.getInputData(1);null!=b&&(a=quat.multiply(this._value,a,b),this.setOutputData(0,a))}},F.registerNodeType("math3d/mult-quat",y),y=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},y.title="Quat Slerp",y.desc="quaternion spherical interpolation",y.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);if(null!=b){var d=this.properties.factor; -null!=this.getInputData(2)&&(d=this.getInputData(2));a=quat.slerp(this._value,a,b,d);this.setOutputData(0,a)}}},F.registerNodeType("math3d/quat-slerp",y))})(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 l(){this.addInput("A","number,vec3");this.addInput("B","number,vec3");this.addOutput("=","vec3");this.addProperty("OP","+","enum",{values:l.values});this._result=vec3.create()}function p(){this.addInput("in","vec3");this.addInput("f","number");this.addOutput("out", -"vec3");this.properties={f:1};this._data=new Float32Array(3)}function k(){this.addInput("in","vec3");this.addOutput("out","number")}function w(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function e(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:0.5};this._data=new Float32Array(3)}function C(){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,k=c.temp_quat,p=c.temp_mat4,g=c.temp_vec3,m=this.getInputData(0),s=this.getInputData(1),l=this.getInputData(2);if(this._must_update||m||s||l)m=m||this.properties.T,s=s||this.properties.R,l=l||this.properties.S,mat4.identity(e),mat4.translate(e,e, -m),this.properties.R_in_degrees?(g.set(s),vec3.scale(g,g,DEG2RAD),quat.fromEuler(k,g)):quat.fromEuler(k,s),mat4.fromQuat(p,k),mat4.multiply(e,e,p),mat4.scale(e,e,l);this.setOutputData(0,e)};z.registerNodeType("math3d/mat4",c);l.values="+ - * / % ^ max min".split(" ");l.title="Operation";l.desc="Easy math 3D operators";l["@OP"]={type:"enum",title:"operation",values:l.values};l.size=[100,60];l.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+ -"(A,B)":"A "+this.properties.OP+" B"};l.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 k=this._result;switch(this.properties.OP){case "+":k=vec3.add(k,c,e);break;case "-":k=vec3.sub(k,c,e);break;case "x":case "X":case "*":k=vec3.mul(k,c,e);break;case "/":k=vec3.div(k,c,e);break;case "%":k[0]=c[0]%e[0];k[1]=c[1]%e[1];k[2]=c[2]%e[2];break;case "^":k[0]=Math.pow(c[0],e[0]); -k[1]=Math.pow(c[1],e[1]);k[2]=Math.pow(c[2],e[2]);break;case "max":k[0]=Math.max(c[0],e[0]);k[1]=Math.max(c[1],e[1]);k[2]=Math.max(c[2],e[2]);break;case "min":k[0]=Math.min(c[0],e[0]);k[1]=Math.min(c[1],e[1]);k[2]=Math.min(c[2],e[2]);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,k)}};l.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.font="40px Arial",c.fillStyle="#666",c.textAlign="center",c.fillText(this.properties.OP,0.5*this.size[0],0.5* -(this.size[1]+z.NODE_TITLE_HEIGHT)),c.textAlign="left")};z.registerNodeType("math3d/operation",l);p.title="vec3_scale";p.desc="scales the components of a vec3";p.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null==e&&(e=this.properties.f);var k=this._data;k[0]=c[0]*e;k[1]=c[1]*e;k[2]=c[2]*e;this.setOutputData(0,k)}};z.registerNodeType("math3d/vec3-scale",p);k.title="vec3_length";k.desc="returns the module of a vector";k.prototype.onExecute=function(){var c= -this.getInputData(0);null!=c&&(c=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),this.setOutputData(0,c))};z.registerNodeType("math3d/vec3-length",k);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]),k=this._data;k[0]=c[0]/e;k[1]=c[1]/e;k[2]=c[2]/e;this.setOutputData(0,k)}};z.registerNodeType("math3d/vec3-normalize",w);e.title="vec3_lerp";e.desc="returns the interpolated vector"; -e.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var k=this.getInputOrProperty("f"),g=this._data;g[0]=c[0]*(1-k)+e[0]*k;g[1]=c[1]*(1-k)+e[1]*k;g[2]=c[2]*(1-k)+e[2]*k;this.setOutputData(0,g)}}};z.registerNodeType("math3d/vec3-lerp",e);C.title="vec3_dot";C.desc="returns the dot product";C.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",C);y.glMatrix?(y=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1,normalize:!1};this._value=quat.create()},y.title="Quaternion",y.desc="quaternion",y.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)},y.prototype.onGetInputs=function(){return[["x","number"],["y","number"],["z","number"],["w","number"]]},z.registerNodeType("math3d/quaternion",y),y=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()},y.title="Rotation",y.desc="quaternion rotation",y.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,0.0174532925*c);this.setOutputData(0,c)},z.registerNodeType("math3d/rotation",y),y=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},y.title="Rot. Vec3",y.desc="rotate a point",y.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",y),y=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},y.title="Mult. Quat",y.desc="rotate quaternion",y.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",y),y=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp", -"quat");this.addProperty("factor",0.5);this._value=quat.create()},y.title="Quat Slerp",y.desc="quaternion spherical interpolation",y.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var k=this.properties.factor;null!=this.getInputData(2)&&(k=this.getInputData(2));c=quat.slerp(this._value,c,e,k);this.setOutputData(0,c)}}},z.registerNodeType("math3d/quat-slerp",y),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()},y.title="Remap Range",y.desc="remap a 3D range",y.prototype.onExecute=function(){var c=this.getInputData(0);c&&this._value.set(c);for(var c=this.properties.range_min,e=this.properties.range_max,k=this.properties.target_min,g=this.properties.target_max,m=0;3>m;++m){var s=e[m]-c[m];this._clamped[m]=Math.clamp(this._value[m],c[m],e[m]); -0==s?this._value[m]=0.5*(k[m]+g[m]):(s=(this._value[m]-c[m])/s,this.properties.clamp&&(s=Math.clamp(s,0,1)),this._value[m]=k[m]+s*(g[m]-k[m]))}this.setOutputData(0,this._value);this.setOutputData(1,this._clamped)},z.registerNodeType("math3d/remap_range",y)):console.warn("No glmatrix found, some Math3D nodes may not work")})(this); -(function(y){function c(c,k){return c==k}function l(){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",c,["*"],"String");y.wrapFunctionAsNode("string/compare",c,["string","string"],"boolean");y.wrapFunctionAsNode("string/concatenate",function(c,k){return void 0===c?k:void 0===k?c:c+k},["string","string"],"string");y.wrapFunctionAsNode("string/contains", -function(c,k){return void 0===c||void 0===k?!1:-1!=c.indexOf(k)},["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,k){null==k&&(k=this.properties.separator);if(null==c)return[];if(c.constructor===String)return c.split(k||" ");if(c.constructor===Array){for(var l=[],e=0;ee;++e){var g=this.getInputData(e);if(null!=g){var r=this.values[e];r.push(g);r.length>c[0]&&r.shift()}}}};c.prototype.onDrawBackground=function(e){if(!this.flags.collapsed){var g=this.size,k=0.5*g[1]/ -this.properties.scale,r=c.colors,n=0.5*g[1];e.fillStyle="#000";e.fillRect(0,0,g[0],g[1]);e.strokeStyle="#555";e.beginPath();e.moveTo(0,n);e.lineTo(g[0],n);e.stroke();if(this.inputs)for(var l=0;4>l;++l){var v=this.values[l];if(this.inputs[l]&&this.inputs[l].link){e.strokeStyle=r[l];e.beginPath();var a=v[0]*k*-1+n;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 r= -(c.length-1)*e,e=c[Math.floor(r)],c=c[Math.floor(r)+1],r=r-Math.floor(r);g[0]=e[0]*(1-r)+c[0]*r;g[1]=e[1]*(1-r)+c[1]*r;g[2]=e[2]*(1-r)+c[2]*r}for(var n in g)g[n]/=255;this.boxcolor=colorToString(g);this.setOutputData(0,g)}};g.registerNodeType("color/palette",p);k.title="Frame";k.desc="Frame viewerew";k.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"view",text:"View Image",type:"button"}];k.prototype.onDrawBackground=function(c){this.frame&&!this.flags.collapsed&&c.drawImage(this.frame, -0,0,this.size[0],this.size[1])};k.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};k.prototype.onWidget=function(c,e){if("resize"==e.name&&this.frame){var g=this.frame.width,r=this.frame.height;g||null==this.frame.videoWidth||(g=this.frame.videoWidth,r=this.frame.videoHeight);g&&r&&(this.size=[g,r]);this.setDirtyCanvas(!0,!0)}else"view"==e.name&&this.show()};k.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};g.registerNodeType("graphics/frame", -k);w.title="Image fade";w.desc="Fades between images";w.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];w.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};w.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};w.prototype.onExecute= -function(){var c=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;var e=this.getInputData(0);null!=e&&c.drawImage(e,0,0,this.canvas.width,this.canvas.height);e=this.getInputData(2);null==e?e=this.properties.fade:this.properties.fade=e;c.globalAlpha=e;e=this.getInputData(1);null!=e&&c.drawImage(e,0,0,this.canvas.width,this.canvas.height);c.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};g.registerNodeType("graphics/imagefade",w);e.title="Crop";e.desc="Crop Image"; +a[3]))};F.registerNodeType("math3d/vec4-to-xyzw",J);H.title="XYZW->Vec4";H.desc="components to vector4";H.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 h=this._data;h[0]=a;h[1]=b;h[2]=d;h[3]=c;this.setOutputData(0,h)};F.registerNodeType("math3d/xyzw-to-vec4",H)})(this); +(function(C){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 m(){this.addInput("A","number,vec3");this.addInput("B","number,vec3");this.addOutput("=","vec3");this.addProperty("OP","+","enum",{values:m.values});this._result=vec3.create()}function p(){this.addInput("in","vec3");this.addInput("f","number");this.addOutput("out", +"vec3");this.properties={f:1};this._data=new Float32Array(3)}function k(){this.addInput("in","vec3");this.addOutput("out","number")}function v(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function e(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:0.5};this._data=new Float32Array(3)}function E(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out","number")} +var z=C.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,k=c.temp_quat,p=c.temp_mat4,g=c.temp_vec3,n=this.getInputData(0),t=this.getInputData(1),m=this.getInputData(2);if(this._must_update||n||t||m)n=n||this.properties.T,t=t||this.properties.R,m=m||this.properties.S,mat4.identity(e),mat4.translate(e,e, +n),this.properties.R_in_degrees?(g.set(t),vec3.scale(g,g,DEG2RAD),quat.fromEuler(k,g)):quat.fromEuler(k,t),mat4.fromQuat(p,k),mat4.multiply(e,e,p),mat4.scale(e,e,m);this.setOutputData(0,e)};z.registerNodeType("math3d/mat4",c);m.values="+ - * / % ^ max min".split(" ");m.title="Operation";m.desc="Easy math 3D operators";m["@OP"]={type:"enum",title:"operation",values:m.values};m.size=[100,60];m.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+ +"(A,B)":"A "+this.properties.OP+" B"};m.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 k=this._result;switch(this.properties.OP){case "+":k=vec3.add(k,c,e);break;case "-":k=vec3.sub(k,c,e);break;case "x":case "X":case "*":k=vec3.mul(k,c,e);break;case "/":k=vec3.div(k,c,e);break;case "%":k[0]=c[0]%e[0];k[1]=c[1]%e[1];k[2]=c[2]%e[2];break;case "^":k[0]=Math.pow(c[0],e[0]); +k[1]=Math.pow(c[1],e[1]);k[2]=Math.pow(c[2],e[2]);break;case "max":k[0]=Math.max(c[0],e[0]);k[1]=Math.max(c[1],e[1]);k[2]=Math.max(c[2],e[2]);break;case "min":k[0]=Math.min(c[0],e[0]);k[1]=Math.min(c[1],e[1]);k[2]=Math.min(c[2],e[2]);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,k)}};m.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.font="40px Arial",c.fillStyle="#666",c.textAlign="center",c.fillText(this.properties.OP,0.5*this.size[0],0.5* +(this.size[1]+z.NODE_TITLE_HEIGHT)),c.textAlign="left")};z.registerNodeType("math3d/operation",m);p.title="vec3_scale";p.desc="scales the components of a vec3";p.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null==e&&(e=this.properties.f);var k=this._data;k[0]=c[0]*e;k[1]=c[1]*e;k[2]=c[2]*e;this.setOutputData(0,k)}};z.registerNodeType("math3d/vec3-scale",p);k.title="vec3_length";k.desc="returns the module of a vector";k.prototype.onExecute=function(){var c= +this.getInputData(0);null!=c&&(c=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),this.setOutputData(0,c))};z.registerNodeType("math3d/vec3-length",k);v.title="vec3_normalize";v.desc="returns the vector normalized";v.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]),k=this._data;k[0]=c[0]/e;k[1]=c[1]/e;k[2]=c[2]/e;this.setOutputData(0,k)}};z.registerNodeType("math3d/vec3-normalize",v);e.title="vec3_lerp";e.desc="returns the interpolated vector"; +e.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var k=this.getInputOrProperty("f"),g=this._data;g[0]=c[0]*(1-k)+e[0]*k;g[1]=c[1]*(1-k)+e[1]*k;g[2]=c[2]*(1-k)+e[2]*k;this.setOutputData(0,g)}}};z.registerNodeType("math3d/vec3-lerp",e);E.title="vec3_dot";E.desc="returns the dot product";E.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",E);C.glMatrix?(C=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1,normalize:!1};this._value=quat.create()},C.title="Quaternion",C.desc="quaternion",C.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)},C.prototype.onGetInputs=function(){return[["x","number"],["y","number"],["z","number"],["w","number"]]},z.registerNodeType("math3d/quaternion",C),C=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()},C.title="Rotation",C.desc="quaternion rotation",C.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,0.0174532925*c);this.setOutputData(0,c)},z.registerNodeType("math3d/rotation",C),C=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},C.title="Rot. Vec3",C.desc="rotate a point",C.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",C),C=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},C.title="Mult. Quat",C.desc="rotate quaternion",C.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",C),C=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp", +"quat");this.addProperty("factor",0.5);this._value=quat.create()},C.title="Quat Slerp",C.desc="quaternion spherical interpolation",C.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var k=this.properties.factor;null!=this.getInputData(2)&&(k=this.getInputData(2));c=quat.slerp(this._value,c,e,k);this.setOutputData(0,c)}}},z.registerNodeType("math3d/quat-slerp",C),C=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()},C.title="Remap Range",C.desc="remap a 3D range",C.prototype.onExecute=function(){var c=this.getInputData(0);c&&this._value.set(c);for(var c=this.properties.range_min,e=this.properties.range_max,k=this.properties.target_min,g=this.properties.target_max,n=0;3>n;++n){var p=e[n]-c[n];this._clamped[n]=Math.clamp(this._value[n],c[n],e[n]); +0==p?this._value[n]=0.5*(k[n]+g[n]):(p=(this._value[n]-c[n])/p,this.properties.clamp&&(p=Math.clamp(p,0,1)),this._value[n]=k[n]+p*(g[n]-k[n]))}this.setOutputData(0,this._value);this.setOutputData(1,this._clamped)},z.registerNodeType("math3d/remap_range",C)):console.warn("No glmatrix found, some Math3D nodes may not work")})(this); +(function(C){function c(c,k){return c==k}function m(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}C=C.LiteGraph;C.wrapFunctionAsNode("string/toString",c,["*"],"String");C.wrapFunctionAsNode("string/compare",c,["string","string"],"boolean");C.wrapFunctionAsNode("string/concatenate",function(c,k){return void 0===c?k:void 0===k?c:c+k},["string","string"],"string");C.wrapFunctionAsNode("string/contains", +function(c,k){return void 0===c||void 0===k?!1:-1!=c.indexOf(k)},["string","string"],"boolean");C.wrapFunctionAsNode("string/toUpperCase",function(c){return null!=c&&c.constructor===String?c.toUpperCase():c},["string"],"string");C.wrapFunctionAsNode("string/split",function(c,k){null==k&&(k=this.properties.separator);if(null==c)return[];if(c.constructor===String)return c.split(k||" ");if(c.constructor===Array){for(var m=[],e=0;ee;++e){var g=this.getInputData(e);if(null!=g){var l=this.values[e];l.push(g);l.length>c[0]&&l.shift()}}}};c.prototype.onDrawBackground=function(e){if(!this.flags.collapsed){var g=this.size,k=0.5*g[1]/ +this.properties.scale,l=c.colors,q=0.5*g[1];e.fillStyle="#000";e.fillRect(0,0,g[0],g[1]);e.strokeStyle="#555";e.beginPath();e.moveTo(0,q);e.lineTo(g[0],q);e.stroke();if(this.inputs)for(var m=0;4>m;++m){var x=this.values[m];if(this.inputs[m]&&this.inputs[m].link){e.strokeStyle=l[m];e.beginPath();var a=x[0]*k*-1+q;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 l= +(c.length-1)*e,e=c[Math.floor(l)],c=c[Math.floor(l)+1],l=l-Math.floor(l);g[0]=e[0]*(1-l)+c[0]*l;g[1]=e[1]*(1-l)+c[1]*l;g[2]=e[2]*(1-l)+c[2]*l}for(var k in g)g[k]/=255;this.boxcolor=colorToString(g);this.setOutputData(0,g)}};g.registerNodeType("color/palette",p);k.title="Frame";k.desc="Frame viewerew";k.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"view",text:"View Image",type:"button"}];k.prototype.onDrawBackground=function(c){this.frame&&!this.flags.collapsed&&c.drawImage(this.frame, +0,0,this.size[0],this.size[1])};k.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};k.prototype.onWidget=function(c,e){if("resize"==e.name&&this.frame){var g=this.frame.width,l=this.frame.height;g||null==this.frame.videoWidth||(g=this.frame.videoWidth,l=this.frame.videoHeight);g&&l&&(this.size=[g,l]);this.setDirtyCanvas(!0,!0)}else"view"==e.name&&this.show()};k.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};g.registerNodeType("graphics/frame", +k);v.title="Image fade";v.desc="Fades between images";v.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];v.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};v.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};v.prototype.onExecute= +function(){var c=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;var e=this.getInputData(0);null!=e&&c.drawImage(e,0,0,this.canvas.width,this.canvas.height);e=this.getInputData(2);null==e?e=this.properties.fade:this.properties.fade=e;c.globalAlpha=e;e=this.getInputData(1);null!=e&&c.drawImage(e,0,0,this.canvas.width,this.canvas.height);c.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};g.registerNodeType("graphics/imagefade",v);e.title="Crop";e.desc="Crop Image"; e.prototype.onAdded=function(){this.createCanvas()};e.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};e.prototype.onExecute=function(){var c=this.getInputData(0);c&&(c.width?(this.canvas.getContext("2d").drawImage(c,-this.properties.x,-this.properties.y,c.width*this.properties.scale,c.height*this.properties.scale),this.setOutputData(0,this.canvas)):this.setOutputData(0,null))};e.prototype.onDrawBackground= -function(c){this.flags.collapsed||this.canvas&&c.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,this.size[0],this.size[1])};e.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"scale"==c?(this.properties[c]=parseFloat(e),0==this.properties[c]&&(console.error("Error in scale"),this.properties[c]=1)):this.properties[c]=parseInt(e);this.createCanvas();return!0};g.registerNodeType("graphics/cropImage",e);C.title="Canvas";C.desc="Canvas to render stuff";C.prototype.onExecute= -function(){var c=this.canvas,e=this.properties.width|0,g=this.properties.height|0;c.width!=e&&(c.width=e);c.height!=g&&(c.height=g);this.properties.autoclear&&this.ctx.clearRect(0,0,c.width,c.height);this.setOutputData(0,c)};C.prototype.onAction=function(c,e){"clear"==c&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)};g.registerNodeType("graphics/canvas",C);z.title="DrawImage";z.desc="Draws image into a canvas";z.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var e= -this.getInputOrProperty("img");if(e){var g=this.getInputOrProperty("x"),r=this.getInputOrProperty("y");c.getContext("2d").drawImage(e,g,r)}}};g.registerNodeType("graphics/drawImage",z);u.title="DrawRectangle";u.desc="Draws rectangle in canvas";u.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var e=this.getInputOrProperty("x"),g=this.getInputOrProperty("y"),r=this.getInputOrProperty("w"),n=this.getInputOrProperty("h");c.getContext("2d").fillRect(e,g,r,n)}};g.registerNodeType("graphics/drawRectangle", -u);D.title="Video";D.desc="Video playback";D.widgets=[{name:"play",text:"PLAY",type:"minibutton"},{name:"stop",text:"STOP",type:"minibutton"},{name:"demo",text:"Demo video",type:"button"},{name:"mute",text:"Mute video",type:"button"}];D.prototype.onExecute=function(){if(this.properties.url&&(this.properties.url!=this._video_url&&this.loadVideo(this.properties.url),this._video&&0!=this._video.width)){var c=this.getInputData(0);c&&0<=c&&1>=c&&(this._video.currentTime=c*this._video.duration,this._video.pause()); +function(c){this.flags.collapsed||this.canvas&&c.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,this.size[0],this.size[1])};e.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"scale"==c?(this.properties[c]=parseFloat(e),0==this.properties[c]&&(console.error("Error in scale"),this.properties[c]=1)):this.properties[c]=parseInt(e);this.createCanvas();return!0};g.registerNodeType("graphics/cropImage",e);E.title="Canvas";E.desc="Canvas to render stuff";E.prototype.onExecute= +function(){var c=this.canvas,e=this.properties.width|0,g=this.properties.height|0;c.width!=e&&(c.width=e);c.height!=g&&(c.height=g);this.properties.autoclear&&this.ctx.clearRect(0,0,c.width,c.height);this.setOutputData(0,c)};E.prototype.onAction=function(c,e){"clear"==c&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)};g.registerNodeType("graphics/canvas",E);z.title="DrawImage";z.desc="Draws image into a canvas";z.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var e= +this.getInputOrProperty("img");if(e){var g=this.getInputOrProperty("x"),l=this.getInputOrProperty("y");c.getContext("2d").drawImage(e,g,l)}}};g.registerNodeType("graphics/drawImage",z);y.title="DrawRectangle";y.desc="Draws rectangle in canvas";y.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var e=this.getInputOrProperty("x"),g=this.getInputOrProperty("y"),l=this.getInputOrProperty("w"),k=this.getInputOrProperty("h");c.getContext("2d").fillRect(e,g,l,k)}};g.registerNodeType("graphics/drawRectangle", +y);D.title="Video";D.desc="Video playback";D.widgets=[{name:"play",text:"PLAY",type:"minibutton"},{name:"stop",text:"STOP",type:"minibutton"},{name:"demo",text:"Demo video",type:"button"},{name:"mute",text:"Mute video",type:"button"}];D.prototype.onExecute=function(){if(this.properties.url&&(this.properties.url!=this._video_url&&this.loadVideo(this.properties.url),this._video&&0!=this._video.width)){var c=this.getInputData(0);c&&0<=c&&1>=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)}};D.prototype.onStart=function(){this.play()};D.prototype.onStop=function(){this.stop()};D.prototype.loadVideo=function(c){this._video_url=c;var e=c.substr(0,10).indexOf(":"),k="";-1!=e&&(k=c.substr(0,e));e="";k&&(e=c.substr(0,c.indexOf("/",k.length+3)),e=e.substr(k.length+3));this.properties.use_proxy&&k&&g.proxy&&e!=location.host&& -(c=g.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...")}); +(c=g.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 l=this;this._video.addEventListener("loadedmetadata",function(c){console.log("Duration: "+this.duration+" seconds");console.log("Size: "+this.videoWidth+","+this.videoHeight);l.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()})};D.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"url"==c&&""!=e&&this.loadVideo(e);return!0};D.prototype.play=function(){this._video&&this._video.videoWidth&&this._video.play()};D.prototype.playPause=function(){this._video&&(this._video.paused?this.play():this.pause())};D.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};D.prototype.pause=function(){this._video&&(console.log("Video paused"), -this._video.pause())};D.prototype.onWidget=function(c,e){};g.registerNodeType("graphics/video",D);B.title="Webcam";B.desc="Webcam image";B.is_webcam_open=!1;B.prototype.openStream=function(){function c(g){console.log("Webcam rejected",g);e._webcam_stream=!1;B.is_webcam_open=!1;e.boxcolor="red";e.trigger("stream_error")}if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this))["catch"](c); -var e=this}};B.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())};B.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",g.EVENT],["stream_closed",g.EVENT],["stream_error",g.EVENT]]};g.registerNodeType("graphics/webcam",B)})(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 l(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[c.image_preview_size,c.image_preview_size]}function p(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",generate_mipmaps:!1}}function k(){this.addInput("Texture", +this._video.pause())};D.prototype.onWidget=function(c,e){};g.registerNodeType("graphics/video",D);A.title="Webcam";A.desc="Webcam image";A.is_webcam_open=!1;A.prototype.openStream=function(){function c(g){console.log("Webcam rejected",g);e._webcam_stream=!1;A.is_webcam_open=!1;e.boxcolor="red";e.trigger("stream_error")}if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this))["catch"](c); +var e=this}};A.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())};A.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",g.EVENT],["stream_closed",g.EVENT],["stream_error",g.EVENT]]};g.registerNodeType("graphics/webcam",A)})(this); +(function(C){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 m(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[c.image_preview_size,c.image_preview_size]}function p(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",generate_mipmaps:!1}}function k(){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:vec2.create(),time:0}}function e(){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 C(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:0.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}function 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 u(){this.addInput("Texture", -"Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function D(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function B(){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("Texture","Texture");this.addOutput("min_t","Texture");this.addOutput("max_t","Texture");this.addOutput("min","vec4");this.addOutput("max","vec4");this.properties={mode:"max",use_previous_frame:!0};this._uniforms={u_texture:0};this._max=new Float32Array(4);this._min=new Float32Array(4);this._textures_chain=[]}function m(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:0.5};this._uniforms= -{u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function s(){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 A(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}}function r(){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};r._shader||(r._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,r.pixel_shader))}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 x(){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 v(){this.addOutput("Texture","Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:c.DEFAULT}}function a(){this.addInput("A","color");this.addInput("B","color"); +this.has_error=!1}function v(){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=v.pixel_shader;this._uniforms={u_value:1,u_color:vec4.create(),in_texture:0,texSize:vec2.create(),time:0}}function e(){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 E(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:0.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}function 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 y(){this.addInput("Texture", +"Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function D(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function A(){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("Texture","Texture");this.addOutput("min_t","Texture");this.addOutput("max_t","Texture");this.addOutput("min","vec4");this.addOutput("max","vec4");this.properties={mode:"max",use_previous_frame:!0};this._uniforms={u_texture:0};this._max=new Float32Array(4);this._min=new Float32Array(4);this._textures_chain=[]}function n(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:0.5};this._uniforms= +{u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function t(){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 B(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}}function l(){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};l._shader||(l._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,l.pixel_shader))}function q(){this.addInput("Texture","Texture");this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");q._shader||(q._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,q.pixel_shader))}function w(){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 x(){this.addOutput("Texture","Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:c.DEFAULT}}function a(){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};a._shader||(a._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}}function b(){this.addInput("A","Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={factor:0.5,size_from_biggest:!0,invert:!1,precision:c.DEFAULT};this._uniforms={u_textureA:0, u_textureB:1,u_textureMix:2,u_mix:vec4.create()}}function d(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:c.DEFAULT};d._shader||(d._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader))}function h(){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 f(){this.addInput("Texture","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,invert:!1};this._uniforms={u_texture:0,u_near:0.1,u_far:1E4}}function E(){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.addInput("in","Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:0.99,iterations:16,threshold:0,scale:1,dirt_factor:0.5,precision:c.DEFAULT};this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function I(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1, -radius:5}}function J(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79,phi:0.017}}function H(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function F(){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 t(){this.addInput("in", +this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}}function f(){this.addInput("Texture","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,invert:!1};this._uniforms={u_texture:0,u_near:0.1,u_far:1E4}}function s(){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 r(){this.addInput("in","Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:0.99,iterations:16,threshold:0,scale:1,dirt_factor:0.5,precision:c.DEFAULT};this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function I(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1, +radius:5}}function J(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79,phi:0.017}}function H(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function F(){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 u(){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 O(){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 K(){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 N(){this.addOutput("out", "Texture");this.properties={width:512,height:512,seed:0,persistence:0.1,octaves:8,scale:1,offset:[0,0],amplitude:1,precision:c.DEFAULT};this._key=0;this._texture=null;this._uniforms={u_persistence:0.1,u_seed:0,u_offset:vec2.create(),u_scale:1,u_viewport:vec2.create()}}function M(){this.addInput("v");this.addOutput("out","Texture");this.properties={code:M.default_code,width:512,height:512,clear:!0,precision:c.DEFAULT,use_html_canvas:!1};this._temp_texture=this._func=null;this.compileCode()}function P(){this.addInput("in", -"Texture");this.addOutput("out","Texture");this.properties={key_color:vec3.fromValues(0,1,0),threshold:0.8,slope:0.2,precision:c.DEFAULT}}function Q(){this.addInput("in","texture");this.addInput("yaw","number");this.addOutput("out","texture");this.properties={yaw:0}}var G=y.LiteGraph;y.LGraphTexture=null;"undefined"!=typeof GL&&(LGraphCanvas.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= +"Texture");this.addOutput("out","Texture");this.properties={key_color:vec3.fromValues(0,1,0),threshold:0.8,slope:0.2,precision:c.DEFAULT}}function Q(){this.addInput("in","texture");this.addInput("yaw","number");this.addOutput("out","texture");this.properties={yaw:0}}var G=C.LiteGraph;C.LGraphTexture=null;"undefined"!=typeof GL&&(LGraphCanvas.link_type_colors.Texture="#987",C.LGraphTexture=c,c.title="Texture",c.desc="Texture",c.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}},c.loadTextureCallback= null,c.image_preview_size=256,c.PASS_THROUGH=1,c.COPY=2,c.LOW=3,c.HIGH=4,c.REUSE=5,c.DEFAULT=2,c.MODE_VALUES={"pass through":c.PASS_THROUGH,copy:c.COPY,low:c.LOW,high:c.HIGH,reuse:c.REUSE,"default":c.DEFAULT},c.getTexturesContainer=function(){return gl.textures},c.loadTexture=function(a,b){b=b||{};var d=a;"http://"==d.substr(0,7)&&G.proxy&&(d=G.proxy+d.substr(7));return c.getTexturesContainer()[a]=GL.Texture.fromURL(d,b)},c.getTexture=function(a){var b=this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found"; -b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a):b},c.getTargetTexture=function(a,b,d){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var f=null;switch(d){case c.LOW:f=gl.UNSIGNED_BYTE;break;case c.HIGH:f=gl.HIGH_PRECISION_FORMAT;break;case c.REUSE:return a;default:f=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==f||(b=new GL.Texture(a.width,a.height,{type:f,format:gl.RGBA,filter:gl.LINEAR}));return b},c.getTextureType=function(a,b){var d=b?b.type: +b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a):b},c.getTargetTexture=function(a,b,d){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var h=null;switch(d){case c.LOW:h=gl.UNSIGNED_BYTE;break;case c.HIGH:h=gl.HIGH_PRECISION_FORMAT;break;case c.REUSE:return a;default:h=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==h||(b=new GL.Texture(a.width,a.height,{type:h,format:gl.RGBA,filter:gl.LINEAR}));return b},c.getTextureType=function(a,b){var d=b?b.type: gl.UNSIGNED_BYTE;switch(a){case c.HIGH:d=gl.HIGH_PRECISION_FORMAT;break;case c.LOW:d=gl.UNSIGNED_BYTE}return d},c.getWhiteTexture=function(){return this._white_texture?this._white_texture:this._white_texture=GL.Texture.fromMemory(1,1,[255,255,255,255],{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576),b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512, 512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.prototype.onDropFile=function(a,b,d){if(a){var c=null;"string"==typeof a?c=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?c=GL.Texture.fromDDSInMemory(a):(a=new Blob([d]),a=URL.createObjectURL(a),c=GL.Texture.fromURL(a));this._drop_texture=c;this.properties.name=b}else this._drop_texture=null,this.properties.name=""},c.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture= null;b.properties.name=""}}]},c.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=c.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,a);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= +if(d){var h=null;"width"==d.name?h=a.width:"height"==d.name?h=a.height:"aspect"==d.name&&(h=a.width/a.height);this.setOutputData(b,h)}}}else this.setOutputData(0,null),this.setOutputData(1,"")},c.prototype.onResourceRenamed=function(a,b){this.properties.name==a&&(this.properties.name=b)},c.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||20>=this.size[1]))if(this._drop_texture&&a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas= this._last_tex;else{var b=c.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}},c.generateLowResTexturePreview=function(a){if(!a)return null;var b=c.image_preview_size,d=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)d=this._preview_temp_tex,this._preview_temp_tex|| (this._preview_temp_tex=d=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(d);a=this._preview_canvas;a||(this._preview_canvas=a=createCanvas(b,b));d&&d.toCanvas(a);return a},c.prototype.getResources=function(a){this.properties.name&&(a[this.properties.name]=GL.Texture);return a},c.prototype.onGetInputs=function(){return[["in","Texture"]]},c.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]},c.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g, -function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},G.registerNodeType("texture/texture",c),l.title="Preview",l.desc="Show a texture in the graph canvas",l.allow_preview=!1,l.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||l.allow_preview)){var b=this.getInputData(0);if(b){var d=null,d=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(d,0,0,this.size[0],this.size[1]);a.restore()}}}, -G.registerNodeType("texture/preview",l),p.title="Save",p.desc="Save a texture in the repository",p.prototype.getPreviewTexture=function(){return this._texture},p.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]= +function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},G.registerNodeType("texture/texture",c),m.title="Preview",m.desc="Show a texture in the graph canvas",m.allow_preview=!1,m.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||m.allow_preview)){var b=this.getInputData(0);if(b){var d=null,d=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(d,0,0,this.size[0],this.size[1]);a.restore()}}}, +G.registerNodeType("texture/preview",m),p.title="Save",p.desc="Save a texture in the repository",p.prototype.getPreviewTexture=function(){return this._texture},p.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))},G.registerNodeType("texture/save",p),k.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},k.title="Operation",k.desc="Texture shader operation",k.presets={},k.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},k.prototype.onPropertyChanged= -function(){this.has_error=!1},k.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())},k.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 n=c.replaceCode(k.pixel_shader,{UV_CODE:h,PIXEL_CODE:e});try{g=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n),this.boxcolor="#00FF00"}catch(r){GL.Shader.dumpErrorToConsole(r,Shader.SCREEN_VERTEX_SHADER,n);this.boxcolor="#FF0000";this.has_error=!0;return}this._shader=g;this._shader_code=h+"|"+e}if(this._shader){var q=this.getInputData(2);null!=q?this.properties.value= -q:q=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:q,texSize:[d,f],time:v}).draw(c)});this.setOutputData(0,this._tex)}}}},k.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", +function(){this.has_error=!1},k.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())},k.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,h=512; +a?(d=a.width,h=a.height):b&&(d=b.width,h=b.height);b||(b=GL.Texture.getWhiteTexture());var f=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,h,{type:f,format:gl.RGBA,filter:gl.LINEAR});f="";this.properties.uvcode&&(f="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(f=this.properties.uvcode));var 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==f+"|"+e)){var l=c.replaceCode(k.pixel_shader,{UV_CODE:f,PIXEL_CODE:e});try{g=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,l),this.boxcolor="#00FF00"}catch(q){GL.Shader.dumpErrorToConsole(q,Shader.SCREEN_VERTEX_SHADER,l);this.boxcolor="#FF0000";this.has_error=!0;return}this._shader=g;this._shader_code=f+"|"+e}if(this._shader){var r=this.getInputData(2);null!=r?this.properties.value= +r:r=parseFloat(this.properties.value);var s=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:r,texSize:[d,h],time:s}).draw(c)});this.setOutputData(0,this._tex)}}}},k.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", k.registerPreset=function(a,b){k.presets[a]=b},k.registerPreset("",""),k.registerPreset("bypass","color"),k.registerPreset("add","color + colorB * value"),k.registerPreset("substract","(color - colorB) * value"),k.registerPreset("mate","mix( color, colorB, color4B.a * value)"),k.registerPreset("invert","vec3(1.0) - color"),k.registerPreset("multiply","color * colorB * value"),k.registerPreset("divide","(color / colorB) / value"),k.registerPreset("difference","abs(color - colorB) * value"),k.registerPreset("max", "max(color, colorB) * value"),k.registerPreset("min","min(color, colorB) * value"),k.registerPreset("displace","texture2D(u_texture, uv + (colorB.xy - vec2(0.5)) * value).xyz"),k.registerPreset("grayscale","vec3(color.x + color.y + color.z) * value / 3.0"),k.registerPreset("saturation","mix( vec3(color.x + color.y + color.z) / 3.0, color, value )"),k.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)"), -k.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(k.presets),callback:function(d){var c=k.presets[d];c&&(b.setProperty("pixelcode",c),b.title=d,a.refresh())}})},G.registerNodeType("texture/operation",k),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){var d=this.getShader();if(d){var c=d.uniformInfo;if(this.inputs)for(var f= -{},h=0;h 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",G.registerNodeType("texture/toviewport",z),u.title="Copy",u.desc="Copy Texture",u.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo", -values:c.MODE_VALUES}},u.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)}},G.registerNodeType("texture/copy",u),D.title="Downsample",D.desc="Downsample Texture",D.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:c.MODE_VALUES}}, -D.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=D._shader;b||(D._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,D.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,n= -null,r=[],a={type:h,format:a.format},h=vec2.create(),k={u_offset:h};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var q=0;q>1||0;f=f>>1||0;n=GL.Texture.getTemporary(d,f,a);r.push(n);g.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);g.copyTo(n,b,k);if(1==d&&1==f)break;g=n}this._texture=r.pop();for(q=0;qthis.properties.iterations)this.setOutputData(0,a);else{var b=D._shader;b||(D._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,D.pixel_shader));var d=a.width|0,h=a.height|0,f=a.type;this.properties.precision===c.LOW?f=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(f=gl.HIGH_PRECISION_FORMAT);var e=this.properties.iterations||1,g=a,l= +null,k=[],a={type:f,format:a.format},f=vec2.create(),q={u_offset:f};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var r=0;r>1||0;h=h>>1||0;l=GL.Texture.getTemporary(d,h,a);k.push(l);g.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);g.copyTo(l,b,q);if(1==d&&1==h)break;g=l}this._texture=k.pop();for(r=0;r>=2,c++,1!=d););a.copyTo(this._textures_chain[0]);for(var c=1;c<=this._textures_chain.length;++c)a=this._textures_chain[c];var f=g._shader,h=this._uniforms;h.u_mipmap_offset=this.properties.mipmap_offset;gl.disable(gl.DEPTH_TEST); -gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.toViewport(f,h)})}},g.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tuniform mat4 u_samples_a;\n\t\tuniform mat4 u_samples_b;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_mipmap_offset;\n\t\tvarying vec2 v_coord;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t//random average\n\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t{\n\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t}\n\t\t gl_FragColor = color * 0.03125;\n\t\t}\n\t\t", -m.title="Smooth",m.desc="Smooth texture over time",m.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){m._shader||(m._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,m.pixel_shader));var b=this._temp_texture;b&&b.type==a.type&&b.width==a.width&&b.height==a.height||(b={type:a.type,format:gl.RGBA,filter:gl.NEAREST},this._temp_texture=new GL.Texture(a.width,a.height,b),this._temp_texture2=new GL.Texture(a.width,a.height,b),a.copyTo(this._temp_texture2));var b= -this._temp_texture,d=this._temp_texture2,c=m._shader,f=this._uniforms;f.u_factor=1-this.getInputOrProperty("factor");gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);b.drawTo(function(){d.bind(1);a.toViewport(c,f)});this.setOutputData(0,b);this._temp_texture=d;this._temp_texture2=b}},m.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tuniform float u_factor;\n\t\tvarying vec2 v_coord;\n\t\t\n\t\tvoid main() {\n\t\t\tgl_FragColor = mix( texture2D( u_texture, v_coord ), texture2D( u_textureB, v_coord ), u_factor );\n\t\t}\n\t\t", -G.registerNodeType("texture/temporal_smooth",m),s.title="Lineal Avg Smooth",s.desc="Smooth texture linearly over time",s["@samples"]={type:"number",min:1,max:64,step:1,precision:1},s.prototype.getPreviewTexture=function(){return this._temp_texture2},s.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){s._shader||(s._shader_copy=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,s.pixel_shader_copy),s._shader_avg=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,s.pixel_shader_avg)); -var b=Math.clamp(this.properties.samples,0,64),d=this.frame,c=this.properties.frames_interval;if(0==c||0==d%c){d=this._temp_texture;d&&d.type==a.type&&d.width==b||(d={type:a.type,format:gl.RGBA,filter:gl.NEAREST},this._temp_texture=new GL.Texture(b,1,d),this._temp_texture2=new GL.Texture(b,1,d),this._temp_texture_out=new GL.Texture(1,1,d));var f=this._temp_texture,h=this._temp_texture2,e=s._shader_copy,g=s._shader_avg,n=this._uniforms;n.u_samples=b;n.u_isamples=1/b;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST); -f.drawTo(function(){h.bind(1);a.toViewport(e,n)});this._temp_texture_out.drawTo(function(){f.toViewport(g,n)});this.setOutputData(0,this._temp_texture_out);this._temp_texture=h;this._temp_texture2=f}else this.setOutputData(0,this._temp_texture_out);this.setOutputData(1,this._temp_texture2);this.frame++}},s.pixel_shader_copy="precision highp float;\n\t\tprecision highp float;\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tuniform float u_isamples;\n\t\tvarying vec2 v_coord;\n\t\t\n\t\tvoid main() {\n\t\t\tif( v_coord.x <= u_isamples )\n\t\t\t\tgl_FragColor = texture2D( u_texture, vec2(0.5) );\n\t\t\telse\n\t\t\t\tgl_FragColor = texture2D( u_textureB, v_coord - vec2(u_isamples,0.0) );\n\t\t}\n\t\t", -s.pixel_shader_avg="precision highp float;\n\t\tprecision highp float;\n\t\tuniform sampler2D u_texture;\n\t\tuniform int u_samples;\n\t\tuniform float u_isamples;\n\t\tvarying vec2 v_coord;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 color = vec4(0.0);\n\t\t\tfor(int i = 0; i < 64; ++i)\n\t\t\t{\n\t\t\t\tcolor += texture2D( u_texture, vec2( float(i)*u_isamples,0.0) );\n\t\t\t\tif(i == (u_samples - 1))\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tgl_FragColor = color * u_isamples;\n\t\t}\n\t\t",G.registerNodeType("texture/linear_avg_smooth", -s),A.title="Image to Texture",A.desc="Uploads an image to the GPU",A.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,d=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var c=this._temp_texture;c&&c.width==b&&c.height==d||(this._temp_texture=new GL.Texture(b,d,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(f){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+f); -return}this.setOutputData(0,this._temp_texture)}}},G.registerNodeType("texture/imageToTexture",A),r.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:c.MODE_VALUES}},r.title="LUT",r.desc="Apply LUT to Texture",r.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===c.PASS_THROUGH||!1===this.properties.enabled)this.setOutputData(0,a);else if(a){var b=this.getInputData(1);b||(b=c.getTexture(this.properties.texture)); -if(b){b.bind(0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D,null);var d=this.properties.intensity;this.isInputConnected(2)&&(this.properties.intensity=d=this.getInputData(2));this._tex=c.getTargetTexture(a,this._tex,this.properties.precision);this._tex.drawTo(function(){b.bind(1);a.toViewport(r._shader,{u_texture:0,u_textureB:1, -u_amount:d})});this.setOutputData(0,this._tex)}else this.setOutputData(0,a)}}},r.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 sampler2D u_textureB;\n\t\tuniform float u_amount;\n\t\t\n\t\tvoid main() {\n\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t mediump vec2 quad1;\n\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t mediump vec2 quad2;\n\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t highp vec2 texPos1;\n\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t highp vec2 texPos2;\n\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t}\n\t\t", -G.registerNodeType("texture/LUT",r),n.title="Texture to Channels",n.desc="Split texture channels",n.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b=gl.RGB,d=0,c=0;4>c;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);for(var f=Mesh.getScreenQuad(),h=n._shader,e=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],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", -G.registerNodeType("texture/textureChannels",n),x.title="Channels to Texture",x.desc="Split texture channels",x.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},x.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();x._shader||(x._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,x.pixel_shader));var g=x._shader, -a=Math.max(b.width,d.width,f.width,h.width),n=Math.max(b.height,d.height,f.height,h.height),r=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._texture&&this._texture.width==a&&this._texture.height==n&&this._texture.type==r||(this._texture=new GL.Texture(a,n,{type:r,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 q=this._uniforms;this._texture.drawTo(function(){b.bind(0); -d.bind(1);f.bind(2);h.bind(3);g.uniforms(q).draw(e)});this.setOutputData(0,this._texture)},x.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", -G.registerNodeType("texture/channelsTexture",x),v.title="Color",v.desc="Generates a 1x1 texture with a constant color",v.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},v.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])},v.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?d: -a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad(),g=null,n=this._uniforms;f?(g=b._shader_tex,g||(g=b._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader,{MIX_TEX:""}))):(g=b._shader_factor,g||(g=b._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader)),h=null==h?this.properties.factor:h,n.u_mix.set([h,h,h,h]));var r=this.properties.invert;this._tex.drawTo(function(){a.bind(r?1:0);d.bind(r?0:1);f&&f.bind(2); -g.uniforms(n).draw(e)});this.setOutputData(0,this._tex)}}},b.prototype.onGetInputs=function(){return[["factor","number"]]},b.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", -G.registerNodeType("texture/mix",b),d.title="Edges",d.desc="Detects edges",d.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},d.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(),f=d._shader,h=this.properties.invert,e=this.properties.factor, -g=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);f.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:e,u_threshold:g,u_invert:h?1:0}).draw(b)});this.setOutputData(0,this._tex)}}},d.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", +G.registerNodeType("texture/downsample",D),A.title="Average",A.desc="Compute a partial average (32 random samples) of a texture and stores it as a 1x1 pixel texture.\n If high_quality is true, then it generates the mipmaps first and reads from the lower one.",A.prototype.onExecute=function(){this.properties.use_previous_frame||this.updateAverage();var a=this._luminance;this.setOutputData(0,this._temp_texture);this.setOutputData(1,a);this.setOutputData(2,(a[0]+a[1]+a[2])/3)},A.prototype.onPreRenderExecute= +function(){this.updateAverage()},A.prototype.updateAverage=function(){var a=this.getInputData(0);if(a&&(this.isOutputConnected(0)||this.isOutputConnected(1)||this.isOutputConnected(2))){if(!A._shader){A._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,A.pixel_shader);for(var b=new Float32Array(16),d=0;d>=2,c++,1!=d););a.copyTo(this._textures_chain[0]);for(var c=1;c<=this._textures_chain.length;++c)a=this._textures_chain[c];var h=g._shader,f=this._uniforms;f.u_mipmap_offset=this.properties.mipmap_offset;gl.disable(gl.DEPTH_TEST); +gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.toViewport(h,f)})}},g.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tuniform mat4 u_samples_a;\n\t\tuniform mat4 u_samples_b;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_mipmap_offset;\n\t\tvarying vec2 v_coord;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t//random average\n\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t{\n\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t}\n\t\t gl_FragColor = color * 0.03125;\n\t\t}\n\t\t", +n.title="Smooth",n.desc="Smooth texture over time",n.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){n._shader||(n._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,n.pixel_shader));var b=this._temp_texture;b&&b.type==a.type&&b.width==a.width&&b.height==a.height||(b={type:a.type,format:gl.RGBA,filter:gl.NEAREST},this._temp_texture=new GL.Texture(a.width,a.height,b),this._temp_texture2=new GL.Texture(a.width,a.height,b),a.copyTo(this._temp_texture2));var b= +this._temp_texture,d=this._temp_texture2,c=n._shader,h=this._uniforms;h.u_factor=1-this.getInputOrProperty("factor");gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);b.drawTo(function(){d.bind(1);a.toViewport(c,h)});this.setOutputData(0,b);this._temp_texture=d;this._temp_texture2=b}},n.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tuniform float u_factor;\n\t\tvarying vec2 v_coord;\n\t\t\n\t\tvoid main() {\n\t\t\tgl_FragColor = mix( texture2D( u_texture, v_coord ), texture2D( u_textureB, v_coord ), u_factor );\n\t\t}\n\t\t", +G.registerNodeType("texture/temporal_smooth",n),t.title="Lineal Avg Smooth",t.desc="Smooth texture linearly over time",t["@samples"]={type:"number",min:1,max:64,step:1,precision:1},t.prototype.getPreviewTexture=function(){return this._temp_texture2},t.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){t._shader||(t._shader_copy=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,t.pixel_shader_copy),t._shader_avg=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,t.pixel_shader_avg)); +var b=Math.clamp(this.properties.samples,0,64),d=this.frame,c=this.properties.frames_interval;if(0==c||0==d%c){d=this._temp_texture;d&&d.type==a.type&&d.width==b||(d={type:a.type,format:gl.RGBA,filter:gl.NEAREST},this._temp_texture=new GL.Texture(b,1,d),this._temp_texture2=new GL.Texture(b,1,d),this._temp_texture_out=new GL.Texture(1,1,d));var h=this._temp_texture,f=this._temp_texture2,e=t._shader_copy,g=t._shader_avg,l=this._uniforms;l.u_samples=b;l.u_isamples=1/b;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST); +h.drawTo(function(){f.bind(1);a.toViewport(e,l)});this._temp_texture_out.drawTo(function(){h.toViewport(g,l)});this.setOutputData(0,this._temp_texture_out);this._temp_texture=f;this._temp_texture2=h}else this.setOutputData(0,this._temp_texture_out);this.setOutputData(1,this._temp_texture2);this.frame++}},t.pixel_shader_copy="precision highp float;\n\t\tprecision highp float;\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tuniform float u_isamples;\n\t\tvarying vec2 v_coord;\n\t\t\n\t\tvoid main() {\n\t\t\tif( v_coord.x <= u_isamples )\n\t\t\t\tgl_FragColor = texture2D( u_texture, vec2(0.5) );\n\t\t\telse\n\t\t\t\tgl_FragColor = texture2D( u_textureB, v_coord - vec2(u_isamples,0.0) );\n\t\t}\n\t\t", +t.pixel_shader_avg="precision highp float;\n\t\tprecision highp float;\n\t\tuniform sampler2D u_texture;\n\t\tuniform int u_samples;\n\t\tuniform float u_isamples;\n\t\tvarying vec2 v_coord;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 color = vec4(0.0);\n\t\t\tfor(int i = 0; i < 64; ++i)\n\t\t\t{\n\t\t\t\tcolor += texture2D( u_texture, vec2( float(i)*u_isamples,0.0) );\n\t\t\t\tif(i == (u_samples - 1))\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tgl_FragColor = color * u_isamples;\n\t\t}\n\t\t",G.registerNodeType("texture/linear_avg_smooth", +t),B.title="Image to Texture",B.desc="Uploads an image to the GPU",B.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,d=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var c=this._temp_texture;c&&c.width==b&&c.height==d||(this._temp_texture=new GL.Texture(b,d,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(h){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+h); +return}this.setOutputData(0,this._temp_texture)}}},G.registerNodeType("texture/imageToTexture",B),l.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:c.MODE_VALUES}},l.title="LUT",l.desc="Apply LUT to Texture",l.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===c.PASS_THROUGH||!1===this.properties.enabled)this.setOutputData(0,a);else if(a){var b=this.getInputData(1);b||(b=c.getTexture(this.properties.texture)); +if(b){b.bind(0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D,null);var d=this.properties.intensity;this.isInputConnected(2)&&(this.properties.intensity=d=this.getInputData(2));this._tex=c.getTargetTexture(a,this._tex,this.properties.precision);this._tex.drawTo(function(){b.bind(1);a.toViewport(l._shader,{u_texture:0,u_textureB:1, +u_amount:d})});this.setOutputData(0,this._tex)}else this.setOutputData(0,a)}}},l.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 sampler2D u_textureB;\n\t\tuniform float u_amount;\n\t\t\n\t\tvoid main() {\n\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t mediump vec2 quad1;\n\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t mediump vec2 quad2;\n\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t highp vec2 texPos1;\n\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t highp vec2 texPos2;\n\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t}\n\t\t", +G.registerNodeType("texture/LUT",l),q.title="Texture to Channels",q.desc="Split texture channels",q.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b=gl.RGB,d=0,c=0;4>c;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);for(var h=Mesh.getScreenQuad(),f=q._shader,e=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],c=0;4>c;c++)this._channels[c]&&(this._channels[c].drawTo(function(){a.bind(0);f.uniforms({u_texture:0,u_mask:e[c]}).draw(h)}),this.setOutputData(c,this._channels[c]))}}},q.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", +G.registerNodeType("texture/textureChannels",q),w.title="Channels to Texture",w.desc="Split texture channels",w.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},w.prototype.onExecute=function(){var a=c.getWhiteTexture(),b=this.getInputData(0)||a,d=this.getInputData(1)||a,h=this.getInputData(2)||a,f=this.getInputData(3)||a;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad();w._shader||(w._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,w.pixel_shader));var g=w._shader, +a=Math.max(b.width,d.width,h.width,f.width),l=Math.max(b.height,d.height,h.height,f.height),k=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==k||(this._texture=new GL.Texture(a,l,{type:k,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 q=this._uniforms;this._texture.drawTo(function(){b.bind(0); +d.bind(1);h.bind(2);f.bind(3);g.uniforms(q).draw(e)});this.setOutputData(0,this._texture)},w.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", +G.registerNodeType("texture/channelsTexture",w),x.title="Color",x.desc="Generates a 1x1 texture with a constant color",x.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},x.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])},x.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?d: +a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad(),g=null,l=this._uniforms;h?(g=b._shader_tex,g||(g=b._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader,{MIX_TEX:""}))):(g=b._shader_factor,g||(g=b._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader)),f=null==f?this.properties.factor:f,l.u_mix.set([f,f,f,f]));var k=this.properties.invert;this._tex.drawTo(function(){a.bind(k?1:0);d.bind(k?0:1);h&&h.bind(2); +g.uniforms(l).draw(e)});this.setOutputData(0,this._tex)}}},b.prototype.onGetInputs=function(){return[["factor","number"]]},b.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", +G.registerNodeType("texture/mix",b),d.title="Edges",d.desc="Detects edges",d.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},d.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(),h=d._shader,f=this.properties.invert,e=this.properties.factor, +g=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);h.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)}}},d.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", G.registerNodeType("texture/edges",d),h.title="Depth Range",h.desc="Generates a texture with a depth range",h.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 f=Mesh.getScreenQuad();h._shader||(h._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h.pixel_shader),h._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h.pixel_shader, {ONLY_DEPTH:""}));var e=this.properties.only_depth?h._shader_onlydepth:h._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:[0.1,1E3];d.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);e.uniforms(d).draw(f)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},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_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", G.registerNodeType("texture/depth_range",h),f.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},f.title="Linear Depth",f.desc="Creates a color texture with linear depth",f.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_near=a.near_far_planes[0];d.u_far=a.near_far_planes[1];d.u_invert=this.properties.invert?1:0;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad();f._shader||(f._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,f.pixel_shader));var e=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:[0.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 float u_near;\n\t\tuniform float u_far;\n\t\tuniform int u_invert;\n\t\t\n\t\tvoid main() {\n\t\t\tfloat zNear = u_near;\n\t\t\tfloat zFar = u_far;\n\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\tdepth = depth * 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", -G.registerNodeType("texture/linear_depth",f),E.title="Blur",E.desc="Blur a texture",E.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},E.max_iterations=20,E.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),E.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=G.camera_aspect;f||void 0===window.gl||(f=gl.canvas.height/gl.canvas.width);f||(f=1);var f=this.properties.preserve_aspect?f:1,h=this.properties.scale||[1,1];a.applyBlur(f*h[0],h[1],c,b);for(a=1;a>=1;1<(d|0)&&(d>>=1);if(2>b)break;r=g[p]=GL.Texture.getTemporary(b,d,f);m[0]=1/k.width;m[1]=1/k.height;k.blit(r,n.uniforms(e));k=r}this.isOutputConnected(2)&&(b=this._average_texture,b&&b.type==a.type&&b.format==a.format||(b=this._average_texture=new GL.Texture(1,1,{type:a.type,format:a.format,filter:gl.LINEAR})),m[0]=1/k.width,m[1]=1/k.height,e.u_intensity=l,e.u_delta=1,k.blit(b,n.uniforms(e)),this.setOutputData(2,b));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);e.u_intensity= -this.getInputOrProperty("persistence");e.u_delta=0.5;for(p-=2;0<=p;p--)r=g[p],g[p]=null,m[0]=1/k.width,m[1]=1/k.height,k.blit(r,n.uniforms(e)),GL.Texture.releaseTemporary(k),k=r;gl.disable(gl.BLEND);this.isOutputConnected(1)&&(g=this._glow_texture,g&&g.width==a.width&&g.height==a.height&&g.type==h&&g.format==a.format||(g=this._glow_texture=new GL.Texture(a.width,a.height,{type:h,format:a.format,filter:gl.LINEAR})),k.blit(g),this.setOutputData(1,g));if(this.isOutputConnected(0)){g=this._final_texture; -g&&g.width==a.width&&g.height==a.height&&g.type==h&&g.format==a.format||(g=this._final_texture=new GL.Texture(a.width,a.height,{type:h,format:a.format,filter:gl.LINEAR}));var t=this.getInputData(1),s=this.getInputOrProperty("dirt_factor");e.u_intensity=l;n=t?q._dirt_final_shader:q._final_shader;n||(n=t?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));g.drawTo(function(){a.bind(0); -k.bind(1);t&&(n.setUniform("u_dirt_factor",s),n.setUniform("u_dirt_texture",t.bind(2)));n.toViewport(e)});this.setOutputData(0,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}", -G.registerNodeType("texture/glow",q),I.title="Kuwahara Filter",I.desc="Filters a texture giving an artistic oil canvas painting",I.max_radius=10,I._shaders=[],I.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),I.max_radius);if(0== -b)this.setOutputData(0,a);else{var d=this.properties.intensity,c=G.camera_aspect;c||void 0===window.gl||(c=gl.canvas.height/gl.canvas.width);c||(c=1);c=this.properties.preserve_aspect?c:1;I._shaders[b]||(I._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,I.pixel_shader,{RADIUS:b.toFixed(0)}));var f=I._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)}); +G.registerNodeType("texture/linear_depth",f),s.title="Blur",s.desc="Blur a texture",s.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},s.max_iterations=20,s.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),s.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 h=G.camera_aspect;h||void 0===window.gl||(h=gl.canvas.height/gl.canvas.width);h||(h=1);var h=this.properties.preserve_aspect?h:1,f=this.properties.scale||[1,1];a.applyBlur(h*f[0],f[1],c,b);for(a=1;a>=1;1<(d|0)&&(d>>=1);if(2>b)break;k=g[n]=GL.Texture.getTemporary(b,d,h);x[0]=1/q.width;x[1]=1/q.height;q.blit(k,l.uniforms(e));q=k}this.isOutputConnected(2)&&(b=this._average_texture,b&&b.type==a.type&&b.format==a.format||(b=this._average_texture=new GL.Texture(1,1,{type:a.type,format:a.format,filter:gl.LINEAR})),x[0]=1/q.width,x[1]=1/q.height,e.u_intensity=m,e.u_delta=1,q.blit(b,l.uniforms(e)),this.setOutputData(2,b));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);e.u_intensity= +this.getInputOrProperty("persistence");e.u_delta=0.5;for(n-=2;0<=n;n--)k=g[n],g[n]=null,x[0]=1/q.width,x[1]=1/q.height,q.blit(k,l.uniforms(e)),GL.Texture.releaseTemporary(q),q=k;gl.disable(gl.BLEND);this.isOutputConnected(1)&&(g=this._glow_texture,g&&g.width==a.width&&g.height==a.height&&g.type==f&&g.format==a.format||(g=this._glow_texture=new GL.Texture(a.width,a.height,{type:f,format:a.format,filter:gl.LINEAR})),q.blit(g),this.setOutputData(1,g));if(this.isOutputConnected(0)){g=this._final_texture; +g&&g.width==a.width&&g.height==a.height&&g.type==f&&g.format==a.format||(g=this._final_texture=new GL.Texture(a.width,a.height,{type:f,format:a.format,filter:gl.LINEAR}));var p=this.getInputData(1),w=this.getInputOrProperty("dirt_factor");e.u_intensity=m;l=p?r._dirt_final_shader:r._final_shader;l||(l=p?r._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,r.final_pixel_shader,{USE_DIRT:""}):r._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,r.final_pixel_shader));g.drawTo(function(){a.bind(0); +q.bind(1);p&&(l.setUniform("u_dirt_factor",w),l.setUniform("u_dirt_texture",p.bind(2)));l.toViewport(e)});this.setOutputData(0,g)}GL.Texture.releaseTemporary(q)}},r.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}",r.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}", +r.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}", +G.registerNodeType("texture/glow",r),I.title="Kuwahara Filter",I.desc="Filters a texture giving an artistic oil canvas painting",I.max_radius=10,I._shaders=[],I.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),I.max_radius);if(0== +b)this.setOutputData(0,a);else{var d=this.properties.intensity,c=G.camera_aspect;c||void 0===window.gl||(c=gl.canvas.height/gl.canvas.width);c||(c=1);c=this.properties.preserve_aspect?c:1;I._shaders[b]||(I._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,I.pixel_shader,{RADIUS:b.toFixed(0)}));var h=I._shaders[b],f=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){h.uniforms({u_texture:0,u_intensity:d,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(f)}); this.setOutputData(0,this._temp_texture)}}},I.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", G.registerNodeType("texture/kuwahara",I),J.title="XDoG Filter",J.desc="Filters a texture giving an artistic ink style",J.max_radius=10,J._shaders=[],J.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}));J._xdog_shader||(J._xdog_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,J.xdog_pixel_shader)); -var d=J._xdog_shader,c=GL.Mesh.getScreenQuad(),f=this.properties.sigma,h=this.properties.k,e=this.properties.p,g=this.properties.epsilon,n=this.properties.phi;a.bind(0);this._temp_texture.drawTo(function(){d.uniforms({src:0,sigma:f,k:h,p:e,epsilon:g,phi:n,cvsWidth:a.width,cvsHeight:a.height}).draw(c)});this.setOutputData(0,this._temp_texture)}},J.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}", +var d=J._xdog_shader,c=GL.Mesh.getScreenQuad(),h=this.properties.sigma,f=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:h,k:f,p:e,epsilon:g,phi:l,cvsWidth:a.width,cvsHeight:a.height}).draw(c)});this.setOutputData(0,this._temp_texture)}},J.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}", G.registerNodeType("texture/xDoG",J),H.title="Webcam",H.desc="Webcam texture",H.is_webcam_open=!1,H.prototype.openStream=function(){function a(d){H.is_webcam_open=!1;console.log("Webcam rejected",d);b._webcam_stream=!1;b.boxcolor="red";b.trigger("stream_error")}if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this))["catch"](a);var b=this}},H.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())},H.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(d))return c[1];d=(a-c[0])/d;return c[1]*(1-d)+f[1]*d}}return 0}},t.prototype.updateCurve=function(){for(var a=this._values,b=a.length/4,d=this.properties.split_channels,c=0;cMath.abs(d))return c[1];d=(a-c[0])/d;return c[1]*(1-d)+h[1]*d}}return 0}},u.prototype.updateCurve=function(){for(var a=this._values,b=a.length/4,d=this.properties.split_channels,c=0;c=f;){e=0.5*(g+f)|0;c=a[e];if(c==d)break;if(f==g-1)return f;ca&&(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=l.generatePoints(d,a,c,this.points, -this.normals,this.properties.regular,f);this.version++};l.generatePoints=function(a,d,c,f,e,g,n){var r=3*d;f&&f.length==r||(f=new Float32Array(r));var k=new Float32Array(3),v=new Float32Array([0,1,0]);if(g)if(c==l.RECTANGLE){r=Math.floor(Math.sqrt(d));for(d=0;d=f;){e=0.5*(g+f)|0;c=a[e];if(c==d)break;if(f==g-1)return f;ca&&(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=m.generatePoints(d,a,c,this.points, +this.normals,this.properties.regular,f);this.version++};m.generatePoints=function(a,d,c,f,e,g,l){var k=3*d;f&&f.length==k||(f=new Float32Array(k));var q=new Float32Array(3),x=new Float32Array([0,1,0]);if(g)if(c==m.RECTANGLE){k=Math.floor(Math.sqrt(d));for(d=0;dg||xn&&nr))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)}};A.registerNodeType("geometry/connectPoints",u);"undefined"!=typeof GL&&(D.title="to geometry",D.desc="converts a mesh to geometry",D.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)}},A.registerNodeType("geometry/toGeometry",D),B.title="Geo to Mesh",B.prototype.updateMesh=function(a){this.mesh||(this.mesh=new GL.Mesh); +g=this.vertices;g&&this.vertices.length==a.vertices.length?g.set(a.vertices):g=this.vertices=new Float32Array(a.vertices);for(f=0;fe||wg&&gl))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)}};B.registerNodeType("geometry/connectPoints",y);"undefined"!=typeof GL&&(D.title="to geometry",D.desc="converts a mesh to geometry",D.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)}},B.registerNodeType("geometry/toGeometry",D),A.title="Geo to Mesh",A.prototype.updateMesh=function(a){this.mesh||(this.mesh=new GL.Mesh); for(var d in a)if("_"!=d[0]){var c=a[d],f=GL.Mesh.common_buffers[d];if(f||"indices"==d){var f=f?f.spacing:3,e=this.mesh.vertexBuffers[d];e&&e.data.length==c.length?(e.data.set(c),e.upload(GL.DYNAMIC_DRAW)):e=new GL.Buffer("indices"==d?GL.ELEMENT_ARRAY_BUFFER:GL.ARRAY_BUFFER,c,f,GL.DYNAMIC_DRAW);this.mesh.addBuffer(d,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(d=0;d=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 k,v=Math.floor((e-24)/12+1);k=(e-21)%12;0>k&&(k=12+k);return c.notes[k]+(g?"":v)};c.NoteStringToPitch=function(e){e=e.toUpperCase();var g=e[0],k=4;"#"==e[1]?(g+="#",2k&&(k=12+k);return c.notes[k]+(g?"":x)};c.NoteStringToPitch=function(e){e=e.toUpperCase();var g=e[0],k=4;"#"==e[1]?(g+="#",2this.properties.max_value)return;this.trigger("on_midi",g)}};s.registerNodeType("midi/filter",e);C.title="MIDIEvent";C.desc="Create a MIDI Event";C.color="#243";C.prototype.onAction= +g.channel,this.properties.cmd=g.cmd,this.properties.min_value=this.properties.max_value=g.data[1];else if(-1!=this.properties.channel&&g.channel!=this.properties.channel||-1!=this.properties.cmd&&g.cmd!=this.properties.cmd||-1!=this.properties.min_value&&g.data[1]this.properties.max_value)return;this.trigger("on_midi",g)}};t.registerNodeType("midi/filter",e);E.title="MIDIEvent";E.desc="Create a MIDI Event";E.color="#243";E.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))};C.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}}};B.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))};B.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&& -this.processScale(c)};s.registerNodeType("midi/quantize",B);g.title="MIDI Play";g.desc="Plays a MIDI note";g.color="#243";g.prototype.onAction=function(e,g){if(g&&g.constructor===c){if(this.instrument&&g.data[0]==c.NOTEON){var k=g.note;if(!k||"undefined"==k||k.constructor!==String)return;this.instrument.play(k,g.octave,this.properties.duration,this.properties.volume)}this.trigger("note",g)}};g.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&(this.properties.volume=c);c=this.getInputData(2); -null!=c&&(this.properties.duration=c)};s.registerNodeType("midi/play",g);m.title="MIDI Keys";m.desc="Keyboard to play notes";m.color="#243";m.keys=[{x:0,w:1,h:1,t:0},{x:0.75,w:0.5,h:0.6,t:1},{x:1,w:1,h:1,t:0},{x:1.75,w:0.5,h:0.6,t:1},{x:2,w:1,h:1,t:0},{x:2.75,w:0.5,h:0.6,t:1},{x:3,w:1,h:1,t:0},{x:4,w:1,h:1,t:0},{x:4.75,w:0.5,h:0.6,t:1},{x:5,w:1,h:1,t:0},{x:5.75,w:0.5,h:0.6,t:1},{x:6,w:1,h:1,t:0}];m.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var e=12*this.properties.num_octaves; -this.keys.length=e;var g=this.size[0]/(7*this.properties.num_octaves),k=this.size[1];c.globalAlpha=1;for(var a=0;2>a;a++)for(var b=0;bd+h||c[1]>b))return a}}return-1};m.prototype.onAction=function(e,g){if("reset"==e)for(var k=0;kg[1])){var k=this.getKeyIndex(g);this.keys[k]=!0;this._last_key= -k;var k=12*(this.properties.start_octave-1)+29+k,v=new c;v.setup([c.NOTEON,k,100]);this.trigger("note",v);return!0}};m.prototype.onMouseMove=function(e,g){if(!(0>g[1]||-1==this._last_key)){this.setDirtyCanvas(!0);var k=this.getKeyIndex(g);if(this._last_key==k)return!0;this.keys[this._last_key]=!1;var v=12*(this.properties.start_octave-1)+29+this._last_key,a=new c;a.setup([c.NOTEOFF,v,100]);this.trigger("note",a);this.keys[k]=!0;v=12*(this.properties.start_octave-1)+29+k;a=new c;a.setup([c.NOTEON, -v,100]);this.trigger("note",a);this._last_key=k;return!0}};m.prototype.onMouseUp=function(e,g){if(!(0>g[1])){var k=this.getKeyIndex(g);this.keys[k]=!1;this._last_key=-1;var k=12*(this.properties.start_octave-1)+29+k,v=new c;v.setup([c.NOTEOFF,k,100]);this.trigger("note",v);return!0}};s.registerNodeType("midi/keys",m)})(this); -(function(y){function c(){this.properties={src:"",gain:0.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=x.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function l(){this.properties={gain:0.5};this._audionodes=[];this._media_stream= -null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=x.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function p(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:0.5};this.audionode=x.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 k(){this.properties={gain:1};this.audionode=x.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function w(){this.properties={impulse_src:"",normalize:!0};this.audionode=x.getAudioContext().createConvolver(); -this.addInput("in","audio");this.addOutput("out","audio")}function e(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=x.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function C(){this.properties={};this.audionode=x.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function z(){this.properties={gain1:0.5,gain2:0.5}; -this.audionode=x.getAudioContext().createGain();this.audionode1=x.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=x.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 u(){this.properties= -{A:0.1,D:0.1,S:0.1,R:0.1};this.audionode=x.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","bool");this.addOutput("out","audio");this.gate=!1}function D(){this.properties={delayTime:0.5};this.audionode=x.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function B(){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=x.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function g(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=x.getAudioContext().createOscillator();this.addOutput("out","audio")}function m(){this.properties= -{continuous:!0,mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function s(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function A(){if(!A.default_code){var c=A.default_function.toString(),a=c.indexOf("{")+1,b=c.lastIndexOf("}");A.default_code=c.substr(a,b-a)}this.properties={code:A.default_code};c=x.getAudioContext();c.createScriptProcessor?this.audionode=c.createScriptProcessor(4096, -1,1):(console.warn("ScriptProcessorNode deprecated"),this.audionode=c.createGain());this.processCode();A._bypass_function||(A._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function r(){this.audionode=x.getAudioContext().destination;this.addInput("in","audio")}var n=y.LiteGraph,x={};y.LGAudio=x;x.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};x.connect=function(c,a){try{c.connect(a)}catch(b){console.warn("LGraphAudio:",b)}};x.disconnect=function(c,a){try{c.disconnect(a)}catch(b){console.warn("LGraphAudio:",b)}};x.changeAllAudiosConnections=function(c,a){if(c.inputs)for(var b= -0;bc;++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}}};A.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))};A.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&& +this.processScale(c)};t.registerNodeType("midi/quantize",A);g.title="MIDI Play";g.desc="Plays a MIDI note";g.color="#243";g.prototype.onAction=function(e,g){if(g&&g.constructor===c){if(this.instrument&&g.data[0]==c.NOTEON){var k=g.note;if(!k||"undefined"==k||k.constructor!==String)return;this.instrument.play(k,g.octave,this.properties.duration,this.properties.volume)}this.trigger("note",g)}};g.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&(this.properties.volume=c);c=this.getInputData(2); +null!=c&&(this.properties.duration=c)};t.registerNodeType("midi/play",g);n.title="MIDI Keys";n.desc="Keyboard to play notes";n.color="#243";n.keys=[{x:0,w:1,h:1,t:0},{x:0.75,w:0.5,h:0.6,t:1},{x:1,w:1,h:1,t:0},{x:1.75,w:0.5,h:0.6,t:1},{x:2,w:1,h:1,t:0},{x:2.75,w:0.5,h:0.6,t:1},{x:3,w:1,h:1,t:0},{x:4,w:1,h:1,t:0},{x:4.75,w:0.5,h:0.6,t:1},{x:5,w:1,h:1,t:0},{x:5.75,w:0.5,h:0.6,t:1},{x:6,w:1,h:1,t:0}];n.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var e=12*this.properties.num_octaves; +this.keys.length=e;var g=this.size[0]/(7*this.properties.num_octaves),k=this.size[1];c.globalAlpha=1;for(var a=0;2>a;a++)for(var b=0;bd+h||c[1]>b))return a}}return-1};n.prototype.onAction=function(e,g){if("reset"==e)for(var k=0;kg[1])){var k=this.getKeyIndex(g);this.keys[k]=!0;this._last_key= +k;var k=12*(this.properties.start_octave-1)+29+k,x=new c;x.setup([c.NOTEON,k,100]);this.trigger("note",x);return!0}};n.prototype.onMouseMove=function(e,g){if(!(0>g[1]||-1==this._last_key)){this.setDirtyCanvas(!0);var k=this.getKeyIndex(g);if(this._last_key==k)return!0;this.keys[this._last_key]=!1;var x=12*(this.properties.start_octave-1)+29+this._last_key,a=new c;a.setup([c.NOTEOFF,x,100]);this.trigger("note",a);this.keys[k]=!0;x=12*(this.properties.start_octave-1)+29+k;a=new c;a.setup([c.NOTEON, +x,100]);this.trigger("note",a);this._last_key=k;return!0}};n.prototype.onMouseUp=function(e,g){if(!(0>g[1])){var k=this.getKeyIndex(g);this.keys[k]=!1;this._last_key=-1;var k=12*(this.properties.start_octave-1)+29+k,x=new c;x.setup([c.NOTEOFF,k,100]);this.trigger("note",x);return!0}};t.registerNodeType("midi/keys",n)})(this); +(function(C){function c(){this.properties={src:"",gain:0.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=w.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function m(){this.properties={gain:0.5};this._audionodes=[];this._media_stream= +null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=w.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function p(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:0.5};this.audionode=w.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 k(){this.properties={gain:1};this.audionode=w.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function v(){this.properties={impulse_src:"",normalize:!0};this.audionode=w.getAudioContext().createConvolver(); +this.addInput("in","audio");this.addOutput("out","audio")}function e(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=w.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function E(){this.properties={};this.audionode=w.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function z(){this.properties={gain1:0.5,gain2:0.5}; +this.audionode=w.getAudioContext().createGain();this.audionode1=w.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=w.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 y(){this.properties= +{A:0.1,D:0.1,S:0.1,R:0.1};this.audionode=w.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","bool");this.addOutput("out","audio");this.gate=!1}function D(){this.properties={delayTime:0.5};this.audionode=w.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function A(){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=w.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function g(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=w.getAudioContext().createOscillator();this.addOutput("out","audio")}function n(){this.properties= +{continuous:!0,mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function t(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function B(){if(!B.default_code){var c=B.default_function.toString(),a=c.indexOf("{")+1,b=c.lastIndexOf("}");B.default_code=c.substr(a,b-a)}this.properties={code:B.default_code};c=w.getAudioContext();c.createScriptProcessor?this.audionode=c.createScriptProcessor(4096, +1,1):(console.warn("ScriptProcessorNode deprecated"),this.audionode=c.createGain());this.processCode();B._bypass_function||(B._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function l(){this.audionode=w.getAudioContext().destination;this.addInput("in","audio")}var q=C.LiteGraph,w={};C.LGAudio=w;w.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};w.connect=function(c,a){try{c.connect(a)}catch(b){console.warn("LGraphAudio:",b)}};w.disconnect=function(c,a){try{c.disconnect(a)}catch(b){console.warn("LGraphAudio:",b)}};w.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())}};m.title="Visualization";m.desc="Audio Visualization";n.registerNodeType("audio/visualization",m);s.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var c=this.properties.band,a=this.getInputData(1); -void 0!==a&&(c=a);a=x.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)}};s.prototype.onGetInputs=function(){return[["band","number"]]};s.title="Signal";s.desc="extract the signal of some frequency";n.registerNodeType("audio/signal",s);A.prototype.onAdded=function(c){c.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess= -this._callback)};A["@code"]={widget:"code",type:"code"};A.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};A.prototype.onStop=function(){this.audionode.onaudioprocess=A._bypass_function};A.prototype.onPause=function(){this.audionode.onaudioprocess=A._bypass_function};A.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};A.prototype.onExecute=function(){};A.prototype.onRemoved=function(){this.audionode.onaudioprocess=A._bypass_function};A.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(c){console.error("Error in onaudioprocess code",c),this._callback=A._bypass_function,this.audionode.onaudioprocess=this._callback}};A.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))}; -A.default_function=function(){this.onaudioprocess=function(c){var a=c.inputBuffer;c=c.outputBuffer;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())}};n.title="Visualization";n.desc="Audio Visualization";q.registerNodeType("audio/visualization",n);t.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var c=this.properties.band,a=this.getInputData(1); +void 0!==a&&(c=a);a=w.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)}};t.prototype.onGetInputs=function(){return[["band","number"]]};t.title="Signal";t.desc="extract the signal of some frequency";q.registerNodeType("audio/signal",t);B.prototype.onAdded=function(c){c.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess= +this._callback)};B["@code"]={widget:"code",type:"code"};B.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};B.prototype.onStop=function(){this.audionode.onaudioprocess=B._bypass_function};B.prototype.onPause=function(){this.audionode.onaudioprocess=B._bypass_function};B.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};B.prototype.onExecute=function(){};B.prototype.onRemoved=function(){this.audionode.onaudioprocess=B._bypass_function};B.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(c){console.error("Error in onaudioprocess code",c),this._callback=B._bypass_function,this.audionode.onaudioprocess=this._callback}};B.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))}; +B.default_function=function(){this.onaudioprocess=function(c){var a=c.inputBuffer;c=c.outputBuffer;for(var b=0;b