mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-08 09:00:05 +00:00
589 lines
309 KiB
JavaScript
Executable File
589 lines
309 KiB
JavaScript
Executable File
(function(u){function d(a){c.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function k(a,b,e,t,l,c){this.id=a;this.type=b;this.origin_id=e;this.origin_slot=t;this.target_id=l;this.target_slot=c;this._data=null;this._pos=new Float32Array(2)}function q(a){this._ctor(a)}function g(a){this._ctor(a)}function r(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 m(a,b,e){e=e||{};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 r;this.zoom_modify_alpha=!0;this.title_text_font=""+c.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+c.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=c.NODE_TITLE_COLOR;this.default_link_color=c.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.render_only_selected=
|
|
this.clear_background=!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_title_colored=!0;this.links_render_mode=c.SPLINE_LINK;this.canvas_mouse=[0,0];this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;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();e.skip_render||this.startRendering();this.autoresize=
|
|
e.autoresize}function w(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function B(a,b,e,t,l,c){return e<a&&e+l>a&&t<b&&t+c>b?!0:!1}function z(a,b){var e=a[0]+a[2],t=a[1]+a[3],l=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>l||e<b[0]||t<b[1]?!1:!0}function y(a,b){function e(a){var e=parseInt(l.style.top);l.style.top=(e+a.deltaY*b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var t=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),
|
|
b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&b.event.constructor!==MouseEvent&&b.event.constructor!==CustomEvent&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var l=document.createElement("div");l.className="litegraph litecontextmenu litemenubar-panel";b.className&&(l.className+=" "+b.className);l.style.minWidth=100;l.style.minHeight=100;l.style.pointerEvents=
|
|
"none";setTimeout(function(){l.style.pointerEvents="auto"},100);l.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);l.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);l.addEventListener("mousedown",function(a){if(2==a.button)return t.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);l.addEventListener("wheel",e,!0);l.addEventListener("mousewheel",e,!0);this.root=l;if(b.title){var c=document.createElement("div");
|
|
c.className="litemenu-title";c.innerHTML=b.title;l.appendChild(c)}var c=0,f;for(f in a){var h=a.constructor==Array?a[f]:f;null!=h&&h.constructor!==String&&(h=void 0===h.content?String(h):h.content);this.addItem(h,a[f],b);c++}l.addEventListener("mouseleave",function(a){t.lock||(l.closing_timer&&clearTimeout(l.closing_timer),l.closing_timer=setTimeout(t.close.bind(t,a),500))});l.addEventListener("mouseenter",function(a){l.closing_timer&&clearTimeout(l.closing_timer)});f=document;b.event&&(f=b.event.target.ownerDocument);
|
|
f||(f=document);f.body.appendChild(l);c=b.left||0;f=b.top||0;if(b.event){c=b.event.clientX-10;f=b.event.clientY-10;b.title&&(f-=20);b.parentMenu&&(c=b.parentMenu.root.getBoundingClientRect(),c=c.left+c.width);var h=document.body.getBoundingClientRect(),d=l.getBoundingClientRect();c>h.width-d.width-10&&(c=h.width-d.width-10);f>h.height-d.height-10&&(f=h.height-d.height-10)}l.style.left=c+"px";l.style.top=f+"px";b.scale&&(l.style.transform="scale("+b.scale+")")}var c=u.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,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;c.debug&&console.log("Node registered: "+a);a.split("/");var e=b.name,t=a.lastIndexOf("/");b.category=a.substr(0,t);b.title||(b.title=e);if(b.prototype)for(var l in q.prototype)b.prototype[l]||(b.prototype[l]=q.prototype[l]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=
|
|
c.BOX_SHAPE;break;case "round":this._shape=c.ROUND_SHAPE;break;case "circle":this._shape=c.CIRCLE_SHAPE;break;case "card":this._shape=c.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[e]=b);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(l in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[l].toLowerCase()]=
|
|
b},wrapFunctionAsNode:function(a,b,e,t,l){for(var f=Array(b.length),h="",d=c.getParameterNames(b),m=0;m<d.length;++m)h+="this.addInput('"+d[m]+"',"+(e&&e[m]?"'"+e[m]+"'":"0")+");\n";h+="this.addOutput('out',"+(t?"'"+t+"'":0)+");\n";l&&(h+="this.properties = "+JSON.stringify(l)+";\n");e=Function(h);e.title=a.split("/").pop();e.desc="Generated from "+b.name;e.prototype.onExecute=function(){for(var a=0;a<f.length;++a)f[a]=this.getInputData(a);a=b.apply(this,f);this.setOutputData(0,a)};this.registerNodeType(a,
|
|
e)},addNodeMethod:function(a,b){q.prototype[a]=b;for(var e in this.registered_node_types){var t=this.registered_node_types[e];t.prototype[a]&&(t.prototype["_"+a]=t.prototype[a]);t.prototype[a]=b}},createNode:function(a,b,e){var t=this.registered_node_types[a];if(!t)return c.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||t.title||a;var l=null;if(c.catch_exceptions)try{l=new t(b)}catch(f){return console.error(f),null}else l=new t(b);l.type=a;!l.title&&b&&(l.title=b);l.properties||
|
|
(l.properties={});l.properties_info||(l.properties_info=[]);l.flags||(l.flags={});l.size||(l.size=l.computeSize());l.pos||(l.pos=c.DEFAULT_POSITION.concat());l.mode||(l.mode=c.ALWAYS);if(e)for(var h in e)l[h]=e[h];return l},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var e=[],t;for(t in this.registered_node_types){var l=this.registered_node_types[t];b&&l.filter&&l.filter!=b||(""==a?null==l.category&&e.push(l):l.category==a&&e.push(l))}return e},
|
|
getNodeTypesCategories:function(){var a={"":1},b;for(b in this.registered_node_types)this.registered_node_types[b].category&&!this.registered_node_types[b].skip_list&&(a[this.registered_node_types[b].category]=1);var e=[];for(b in a)e.push(b);return e},reloadNodes:function(a){var b=document.getElementsByTagName("script"),e=[],t;for(t in b)e.push(b[t]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(t in e){var l=e[t].src;if(l&&l.substr(0,a.length)==a)try{c.debug&&console.log("Reloading: "+
|
|
l);var f=document.createElement("script");f.type="text/javascript";f.src=l;b.appendChild(f);b.removeChild(e[t])}catch(h){if(c.throw_errors)throw h;c.debug&&console.log("Error while reloading "+l)}}c.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var e=JSON.parse(JSON.stringify(a));if(!b)return e;for(var t in e)b[t]=e[t];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==c.EVENT&&b==c.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();
|
|
if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;for(var e=a.split(","),t=b.split(","),l=0;l<e.length;++l)for(var f=0;f<t.length;++f)if(e[l]==t[f])return!0;return!1},registerSearchboxExtra:function(a,b,e){this.searchbox_extras[b]={type:a,desc:b,data:e}}};c.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):"undefined"!=typeof process?function(){var a=process.hrtime();return 0.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};
|
|
u.LGraph=c.LGraph=d;d.supported_types=["number","string","boolean"];d.prototype.getSupportedTypes=function(){return this.supported_types||d.supported_types};d.STATUS_STOPPED=1;d.STATUS_RUNNING=2;d.prototype.clear=function(){this.stop();this.status=d.STATUS_STOPPED;this.last_link_id=this.last_node_id=1;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=
|
|
null;this._groups=[];this.links={};this.iteration=0;this.config={};this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=this.fixedtime_lapse=0.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};d.prototype.attachCanvas=function(a){if(a.constructor!=m)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=
|
|
[]);this.list_of_graphcanvas.push(a)};d.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))}};d.prototype.start=function(a){if(this.status!=d.STATUS_RUNNING){this.status=d.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=c.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var e=
|
|
function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(e),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;e()}else this.execution_timer_id=setInterval(function(){b.runStep(1,!this.catch_errors)},a)}};d.prototype.stop=function(){if(this.status!=d.STATUS_STOPPED){this.status=d.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id),this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};
|
|
d.prototype.runStep=function(a,b){a=a||1;var e=c.getTime();this.globaltime=0.001*(e-this.starttime);var t=this._nodes_executable?this._nodes_executable:this._nodes;if(t){if(b){for(var l=0;l<a;l++){for(var f=0,h=t.length;f<h;++f){var d=t[f];if(d.mode==c.ALWAYS&&d.onExecute)d.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(l=0;l<a;l++){f=0;for(h=t.length;f<h;++f)if(d=t[f],d.mode==c.ALWAYS&&d.onExecute)d.onExecute();
|
|
this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(m){this.errors_in_execution=!0;if(c.throw_errors)throw m;c.debug&&console.log("Error during execution: "+m);this.stop()}t=c.getTime();e=t-e;0==e&&(e=1);this.execution_time=0.001*e;this.globaltime+=0.001*e;this.iteration+=1;this.elapsed_time=0.001*(t-this.last_update_time);this.last_update_time=t}};d.prototype.updateExecutionOrder=function(){this._nodes_in_order=
|
|
this.computeExecutionOrder(!1);this._nodes_executable=[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};d.prototype.computeExecutionOrder=function(a,b){for(var e=[],t=[],l={},f={},h={},d=0,m=this._nodes.length;d<m;++d){var n=this._nodes[d];if(!a||n.onExecute){l[n.id]=n;var p=0;if(n.inputs)for(var C=0,D=n.inputs.length;C<D;C++)n.inputs[C]&&null!=n.inputs[C].link&&(p+=1);0==p?(t.push(n),b&&(n._level=1)):(b&&(n._level=
|
|
0),h[n.id]=p)}}for(;0!=t.length;)if(n=t.shift(),e.push(n),delete l[n.id],n.outputs)for(d=0;d<n.outputs.length;d++)if(m=n.outputs[d],null!=m&&null!=m.links&&0!=m.links.length)for(C=0;C<m.links.length;C++)(p=this.links[m.links[C]])&&!f[p.id]&&(D=this.getNodeById(p.target_id),null==D?f[p.id]=!0:(b&&(!D._level||D._level<=n._level)&&(D._level=n._level+1),f[p.id]=!0,h[D.id]-=1,0==h[D.id]&&t.push(D)));for(d in l)e.push(l[d]);e.length!=this._nodes.length&&c.debug&&console.warn("something went wrong, nodes missing");
|
|
m=e.length;for(d=0;d<m;++d)e[d].order=d;e=e.sort(function(a,b){var e=a.constructor.priority||a.priority||0,p=b.constructor.priority||b.priority||0;return e==p?a.order-b.order:e-p});for(d=0;d<m;++d)e[d].order=d;return e};d.prototype.getAncestors=function(a){for(var b=[],e=[a],t={};e.length;){var l=e.shift();if(l.inputs){t[l.id]||l==a||(t[l.id]=!0,b.push(l));for(var c=0;c<l.inputs.length;++c){var f=l.getInputNode(c);f&&-1==b.indexOf(f)&&e.push(f)}}}b.sort(function(a,b){return a.order-b.order});return b};
|
|
d.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),e=[],t=0;t<b.length;++t){var l=b[t],c=l._level||1;e[c]||(e[c]=[]);e[c].push(l)}b=a;for(t=0;t<e.length;++t)if(c=e[t]){for(var f=100,h=a,d=0;d<c.length;++d)l=c[d],l.pos[0]=b,l.pos[1]=h,l.size[0]>f&&(f=l.size[0]),h+=l.size[1]+a;b+=f+a}this.setDirtyCanvas(!0,!0)};d.prototype.getTime=function(){return this.globaltime};d.prototype.getFixedTime=function(){return this.fixedtime};d.prototype.getElapsedTime=function(){return this.elapsed_time};
|
|
d.prototype.sendEventToAllNodes=function(a,b,e){e=e||c.ALWAYS;var t=this._nodes_in_order?this._nodes_in_order:this._nodes;if(t)for(var l=0,f=t.length;l<f;++l){var h=t[l];if(h[a]&&h.mode==e)if(void 0===b)h[a]();else if(b&&b.constructor===Array)h[a].apply(h,b);else h[a](b)}};d.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var e=0;e<this.list_of_graphcanvas.length;++e){var c=this.list_of_graphcanvas[e];c[a]&&c[a].apply(c,b)}};d.prototype.add=function(a,b){if(a)if(a.constructor===
|
|
g)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=c.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=
|
|
a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};d.prototype.remove=function(a){if(a.constructor===c.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){if(a.inputs)for(b=0;b<a.inputs.length;b++){var e=a.inputs[b];
|
|
null!=e.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)e=a.outputs[b],null!=e.links&&e.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)e=this.list_of_graphcanvas[b],e.selected_nodes[a.id]&&delete e.selected_nodes[a.id],e.node_dragged==a&&(e.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);
|
|
this.setDirtyCanvas(!0,!0);this.change();this.updateExecutionOrder()}};d.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};d.prototype.findNodesByClass=function(a){for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].constructor===a&&b.push(this._nodes[e]);return b};d.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].type.toLowerCase()==a&&b.push(this._nodes[e]);return b};d.prototype.findNodesByTitle=
|
|
function(a){for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].title==a&&b.push(this._nodes[e]);return b};d.prototype.getNodeOnPos=function(a,b,e,c){e=e||this._nodes;for(var l=e.length-1;0<=l;l--){var f=e[l];if(f.isPointInside(a,b,c))return f}return null};d.prototype.getGroupOnPos=function(a,b){for(var e=this._groups.length-1;0<=e;e--){var c=this._groups[e];if(c.isPointInside(a,b,2,!0))return c}return null};d.prototype.addInput=function(a,b,e){if(!this.inputs[a]){this.inputs[a]={name:a,
|
|
type:b,value:e};this._version++;if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};d.prototype.setInputData=function(a,b){var e=this.inputs[a];e&&(e.value=b)};d.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};d.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),!1;this.inputs[b]=this.inputs[a];delete this.inputs[a];
|
|
this._version++;if(this.onInputRenamed)this.onInputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};d.prototype.changeInputType=function(a,b){if(!this.inputs[a])return!1;if(!this.inputs[a].type||this.inputs[a].type.toLowerCase()!=b.toLowerCase())if(this.inputs[a].type=b,this._version++,this.onInputTypeChanged)this.onInputTypeChanged(a,b)};d.prototype.removeInput=function(a){if(!this.inputs[a])return!1;delete this.inputs[a];this._version++;if(this.onInputRemoved)this.onInputRemoved(a);
|
|
if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};d.prototype.addOutput=function(a,b,e){this.outputs[a]={name:a,type:b,value:e};this._version++;if(this.onOutputAdded)this.onOutputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};d.prototype.setOutputData=function(a,b){var e=this.outputs[a];e&&(e.value=b)};d.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};d.prototype.renameOutput=function(a,b){if(!this.outputs[a])return!1;if(this.outputs[b])return console.error("there is already one output with that name"),
|
|
!1;this.outputs[b]=this.outputs[a];delete this.outputs[a];this._version++;if(this.onOutputRenamed)this.onOutputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};d.prototype.changeOutputType=function(a,b){if(!this.outputs[a])return!1;if(!this.outputs[a].type||this.outputs[a].type.toLowerCase()!=b.toLowerCase())if(this.outputs[a].type=b,this._version++,this.onOutputTypeChanged)this.onOutputTypeChanged(a,b)};d.prototype.removeOutput=function(a){if(!this.outputs[a])return!1;delete this.outputs[a];
|
|
this._version++;if(this.onOutputRemoved)this.onOutputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};d.prototype.triggerInput=function(a,b){for(var e=this.findNodesByTitle(a),c=0;c<e.length;++c)e[c].onTrigger(b)};d.prototype.setCallback=function(a,b){for(var e=this.findNodesByTitle(a),c=0;c<e.length;++c)e[c].setTrigger(b)};d.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};
|
|
d.prototype.isLive=function(){if(!this.list_of_graphcanvas)return!1;for(var a=0;a<this.list_of_graphcanvas.length;++a)if(this.list_of_graphcanvas[a].live_mode)return!0;return!1};d.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};d.prototype.change=function(){c.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};d.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",
|
|
[a,b])};d.prototype.removeLink=function(a){if(a=this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};d.prototype.serialize=function(){for(var a=[],b=0,e=this._nodes.length;b<e;++b)a.push(this._nodes[b].serialize());e=[];for(b in this.links){var t=this.links[b];e.push([t.id,t.origin_id,t.origin_slot,t.target_id,t.target_slot,t.type])}t=[];for(b=0;b<this._groups.length;++b)t.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,last_link_id:this.last_link_id,
|
|
nodes:a,links:e,groups:t,config:this.config,version:c.VERSION}};d.prototype.configure=function(a,b){if(a){b||this.clear();var e=a.nodes;if(a.links&&a.links.constructor===Array){for(var t=[],l=0;l<a.links.length;++l){var f=a.links[l],h=new k;h.configure(f);t[h.id]=h}a.links=t}for(l in a)this[l]=a[l];t=!1;this._nodes=[];if(e){l=0;for(f=e.length;l<f;++l){var h=e[l],d=c.createNode(h.type,h.title);d||(c.debug&&console.log("Node not found or has errors: "+h.type),d=new q,d.last_serialization=h,t=d.has_errors=
|
|
!0);d.id=h.id;this.add(d,!0)}l=0;for(f=e.length;l<f;++l)h=e[l],(d=this.getNodeById(h.id))&&d.configure(h)}this._groups.length=0;if(a.groups)for(l=0;l<a.groups.length;++l)e=new c.LGraphGroup,e.configure(a.groups[l]),this.add(e);this.updateExecutionOrder();this._version++;this.setDirtyCanvas(!0,!0);return t}};d.prototype.load=function(a){var b=this,e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),
|
|
b.configure(a))};e.onerror=function(a){console.error("Error loading graph:",a)}};d.prototype.onNodeTrace=function(a,b,e){};k.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};k.prototype.serialize=function(){return[this.id,this.type,this.origin_id,
|
|
this.origin_slot,this.target_id,this.target_slot]};c.LLink=k;u.LGraphNode=c.LGraphNode=q;q.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[c.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags=
|
|
{}};q.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("properties"==b)for(var e in a.properties){if(this.properties[e]=a.properties[e],this.onPropertyChanged)this.onPropertyChanged(e,a.properties[e])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=c.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(e=0;e<this.inputs.length;++e){b=
|
|
this.inputs[e];var t=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(c.INPUT,e,!0,t,b)}if(this.outputs)for(e=0;e<this.outputs.length;++e){var l=this.outputs[e];if(l.links)for(b=0;b<l.links.length;++b)t=this.graph?this.graph.links[l.links[b]]:null,this.onConnectionsChange(c.OUTPUT,e,!0,t,l)}}if(this.onConfigure)this.onConfigure(a)};q.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:c.cloneObject(this.flags),mode:this.mode};if(this.constructor===
|
|
q&&this.last_serialization)return this.last_serialization;this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&(a.title=this.title);this.properties&&(a.properties=c.cloneObject(this.properties));a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=
|
|
this.shape);this.onSerialize&&this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");return a};q.prototype.clone=function(){var a=c.createNode(this.type);if(!a)return null;var b=c.cloneObject(this.serialize());if(b.inputs)for(var e=0;e<b.inputs.length;++e)b.inputs[e].link=null;if(b.outputs)for(e=0;e<b.outputs.length;++e)b.outputs[e].links&&(b.outputs[e].links.length=0);delete b.id;a.configure(b);return a};q.prototype.toString=
|
|
function(){return JSON.stringify(this.serialize())};q.prototype.getTitle=function(){return this.title||this.constructor.title};q.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var e=this.outputs[a];if(e&&(e._data=b,this.outputs[a].links))for(e=0;e<this.outputs[a].links.length;e++)this.graph.links[this.outputs[a].links[e]].data=b}};q.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var e=this.outputs[a];if(e&&(e.type=
|
|
b,this.outputs[a].links))for(e=0;e<this.outputs[a].links.length;e++)this.graph.links[this.outputs[a].links[e]].type=b}};q.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var e=this.graph.links[this.inputs[a].link];if(!e)return null;if(!b)return e.data;var c=this.graph.getNodeById(e.origin_id);if(!c)return e.data;if(c.updateOutputData)c.updateOutputData(e.origin_slot);else if(c.onExecute)c.onExecute();return e.data}};q.prototype.getInputDataType=
|
|
function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};q.prototype.getInputDataByName=function(a,b){var e=this.findInputSlot(a);return-1==e?null:this.getInputData(e,b)};q.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};q.prototype.getInputInfo=function(a){return this.inputs?
|
|
a<this.inputs.length?this.inputs[a]:null:null};q.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};q.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,e=this.inputs.length;b<e;++b){var c=this.inputs[b];if(a==c.name&&null!=c.link&&(c=this.graph.links[c.link]))return c.data}return this.properties[a]};
|
|
q.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};q.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};q.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};q.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;
|
|
return!1};q.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],e=0;e<a.links.length;e++){var c=this.graph.links[a.links[e]];c&&(c=this.graph.getNodeById(c.target_id))&&b.push(c)}return b};q.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=c.getTime());for(var e=0;e<this.outputs.length;++e){var t=this.outputs[e];
|
|
!t||t.type!==c.EVENT||a&&t.name!=a||this.triggerSlot(e,b)}}};q.prototype.triggerSlot=function(a,b,e){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=c.getTime());for(var t=0;t<a.length;++t){var l=a[t];if(null==e||e==l){var f=this.graph.links[a[t]];if(f&&(f._last_time=c.getTime(),l=this.graph.getNodeById(f.target_id)))if(f=l.inputs[f.target_slot],l.onAction)l.onAction(f.name,b);else if(l.mode===c.ON_TRIGGER&&l.onExecute)l.onExecute(b)}}}};q.prototype.clearTriggeredSlot=
|
|
function(a,b){if(this.outputs){var e=this.outputs[a];if(e&&(e=e.links)&&e.length)for(var c=0;c<e.length;++c){var l=e[c];if(null==b||b==l)if(l=this.graph.links[e[c]])l._last_time=0}}};q.prototype.addProperty=function(a,b,e,c){e={name:a,type:e,default_value:b};if(c)for(var l in c)e[l]=c[l];this.properties_info||(this.properties_info=[]);this.properties_info.push(e);this.properties||(this.properties={});this.properties[a]=b;return e};q.prototype.addOutput=function(a,b,e){a={name:a,type:b,links:null};
|
|
if(e)for(var c in e)a[c]=e[c];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();this.setDirtyCanvas(!0,!0);return a};q.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var e=a[b],c={name:e[0],type:e[1],link:null};if(a[2])for(var l in e[2])c[l]=e[2][l];this.outputs||(this.outputs=[]);this.outputs.push(c);if(this.onOutputAdded)this.onOutputAdded(c)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};q.prototype.removeOutput=
|
|
function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var e=this.outputs[b].links,c=0;c<e.length;++c){var l=this.graph.links[e[c]];l&&(l.origin_slot-=1)}this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};q.prototype.addInput=function(a,b,e){a={name:a,type:b||0,link:null};if(e)for(var c in e)a[c]=e[c];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=
|
|
this.computeSize();if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};q.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var e=a[b],c={name:e[0],type:e[1],link:null};if(a[2])for(var l in e[2])c[l]=e[2][l];this.inputs||(this.inputs=[]);this.inputs.push(c);if(this.onInputAdded)this.onInputAdded(c)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};q.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);for(var b=a;b<this.inputs.length;++b)if(this.inputs[b]){var e=
|
|
this.graph.links[this.inputs[b].link];e&&(e.target_slot-=1)}this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a);this.setDirtyCanvas(!0,!0)};q.prototype.addConnection=function(a,b,e,c){a={name:a,type:b,pos:e,direction:c,links:null};this.connections.push(a);return a};q.prototype.computeSize=function(a,b){function e(a){return a?f*a.length*0.6:0}if(this.constructor.size)return this.constructor.size.concat();var t=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:
|
|
1),l=b||new Float32Array([0,0]),t=Math.max(t,1),f=c.NODE_TEXT_SIZE;l[1]=(this.constructor.slot_start_y||0)+t*c.NODE_SLOT_HEIGHT;this.widgets&&this.widgets.length&&(l[1]+=this.widgets.length*(c.NODE_WIDGET_HEIGHT+4)+8);var t=e(this.title),h=0,d=0;if(this.inputs)for(var m=0,n=this.inputs.length;m<n;++m){var p=this.inputs[m],p=p.label||p.name||"",p=e(p);h<p&&(h=p)}if(this.outputs)for(m=0,n=this.outputs.length;m<n;++m)p=this.outputs[m],p=p.label||p.name||"",p=e(p),d<p&&(d=p);l[0]=Math.max(h+d+10,t);l[0]=
|
|
Math.max(l[0],c.NODE_WIDTH);this.widgets&&this.widgets.length&&(l[0]=Math.max(l[0],1.5*c.NODE_WIDTH));if(this.onResize)this.onResize(l);this.constructor.min_height&&l[1]<this.constructor.min_height&&(l[1]=this.constructor.min_height);l[1]+=6;return l};q.prototype.addWidget=function(a,b,e,c,l){this.widgets||(this.widgets=[]);b={type:a.toLowerCase(),name:b,value:e,callback:c,options:l||{}};void 0!==b.options.y&&(b.y=b.options.y);c||console.warn("LiteGraph addWidget('button',...) without a callback");
|
|
if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);return b};q.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};q.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-c.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+c.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};q.prototype.isPointInside=
|
|
function(a,b,e,t){e=e||0;var l=this.graph&&this.graph.isLive()?0:20;t&&(l=0);if(this.flags&&this.flags.collapsed){if(B(a,b,this.pos[0]-e,this.pos[1]-c.NODE_TITLE_HEIGHT-e,(this._collapsed_width||c.NODE_COLLAPSED_WIDTH)+2*e,c.NODE_TITLE_HEIGHT+2*e))return!0}else if(this.pos[0]-4-e<a&&this.pos[0]+this.size[0]+4+e>a&&this.pos[1]-l-e<b&&this.pos[1]+this.size[1]+e>b)return!0;return!1};q.prototype.getSlotInPosition=function(a,b){var e=new Float32Array(2);if(this.inputs)for(var c=0,l=this.inputs.length;c<
|
|
l;++c){var f=this.inputs[c];this.getConnectionPos(!0,c,e);if(B(a,b,e[0]-10,e[1]-5,20,10))return{input:f,slot:c,link_pos:e,locked:f.locked}}if(this.outputs)for(c=0,l=this.outputs.length;c<l;++c)if(f=this.outputs[c],this.getConnectionPos(!1,c,e),B(a,b,e[0]-10,e[1]-5,20,10))return{output:f,slot:c,link_pos:e,locked:f.locked};return null};q.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,e=this.inputs.length;b<e;++b)if(a==this.inputs[b].name)return b;return-1};q.prototype.findOutputSlot=
|
|
function(a){if(!this.outputs)return-1;for(var b=0,e=this.outputs.length;b<e;++b)if(a==this.outputs[b].name)return b;return-1};q.prototype.connect=function(a,b,e){e=e||0;if(!this.graph)return console.log("Connect: Error, node doesnt belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return c.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return c.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(e.constructor===String){if(e=b.findInputSlot(e),-1==e)return c.debug&&console.log("Connect: Error, no slot of name "+e),null}else{if(e===c.EVENT)return null;if(!b.inputs||e>=b.inputs.length)return c.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[e].link&&b.disconnectInput(e);var t=this.outputs[a];
|
|
if(b.onConnectInput&&!1===b.onConnectInput(e,t.type,t))return null;var l=b.inputs[e],f=null;if(c.isValidConnection(t.type,l.type)){f=new k(this.graph.last_link_id++,l.type,this.id,a,b.id,e);this.graph.links[f.id]=f;null==t.links&&(t.links=[]);t.links.push(f.id);b.inputs[e].link=f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(c.OUTPUT,a,!0,f,t);if(b.onConnectionsChange)b.onConnectionsChange(c.INPUT,e,!0,f,l);this.graph&&this.graph.onNodeConnectionChange&&
|
|
(this.graph.onNodeConnectionChange(c.INPUT,b,e,this,a),this.graph.onNodeConnectionChange(c.OUTPUT,this,a,b,e))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this,f);return f};q.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return c.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return c.debug&&console.log("Connect: Error, slot number not found"),!1;var e=this.outputs[a];if(!e||
|
|
!e.links||0==e.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var f=0,l=e.links.length;f<l;f++){var h=e.links[f],d=this.graph.links[h];if(d.target_id==b.id){e.links.splice(f,1);var m=b.inputs[d.target_slot];m.link=null;delete this.graph.links[h];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(c.INPUT,d.target_slot,!1,d,m);if(this.onConnectionsChange)this.onConnectionsChange(c.OUTPUT,a,!1,d,e);
|
|
if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(c.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(c.OUTPUT,this,a),this.graph.onNodeConnectionChange(c.INPUT,b,d.target_slot));break}}}else{f=0;for(l=e.links.length;f<l;f++)if(h=e.links[f],d=this.graph.links[h]){b=this.graph.getNodeById(d.target_id);this.graph&&this.graph._version++;if(b){m=b.inputs[d.target_slot];m.link=null;if(b.onConnectionsChange)b.onConnectionsChange(c.INPUT,
|
|
d.target_slot,!1,d,m);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(c.INPUT,b,d.target_slot)}delete this.graph.links[h];if(this.onConnectionsChange)this.onConnectionsChange(c.OUTPUT,a,!1,d,e);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(c.OUTPUT,this,a),this.graph.onNodeConnectionChange(c.INPUT,b,d.target_slot))}e.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};q.prototype.disconnectInput=function(a){if(a.constructor===
|
|
String){if(a=this.findInputSlot(a),-1==a)return c.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return c.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var e=this.inputs[a].link;this.inputs[a].link=null;var f=this.graph.links[e];if(f){var l=this.graph.getNodeById(f.origin_id);if(!l)return!1;var h=l.outputs[f.origin_slot];if(!h||!h.links||0==h.links.length)return!1;for(var d=0,m=h.links.length;d<
|
|
m;d++)if(h.links[d]==e){h.links.splice(d,1);break}delete this.graph.links[e];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(c.INPUT,a,!1,f,b);if(l.onConnectionsChange)l.onConnectionsChange(c.OUTPUT,d,!1,f,h);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(c.OUTPUT,l,d),this.graph.onNodeConnectionChange(c.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};q.prototype.getConnectionPos=function(a,
|
|
b,e){e=e||new Float32Array(2);var f=0;a&&this.inputs&&(f=this.inputs.length);!a&&this.outputs&&(f=this.outputs.length);var l=0.5*c.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||c.NODE_COLLAPSED_WIDTH,this.horizontal?(e[0]=this.pos[0]+0.5*b,e[1]=a?this.pos[1]-c.NODE_TITLE_HEIGHT:this.pos[1]):(e[0]=a?this.pos[0]:this.pos[0]+b,e[1]=this.pos[1]-0.5*c.NODE_TITLE_HEIGHT),e;if(a&&-1==b)return e[0]=this.pos[0]+0.5*c.NODE_TITLE_HEIGHT,e[1]=this.pos[1]+0.5*c.NODE_TITLE_HEIGHT,e;if(a&&
|
|
f>b&&this.inputs[b].pos)return e[0]=this.pos[0]+this.inputs[b].pos[0],e[1]=this.pos[1]+this.inputs[b].pos[1],e;if(!a&&f>b&&this.outputs[b].pos)return e[0]=this.pos[0]+this.outputs[b].pos[0],e[1]=this.pos[1]+this.outputs[b].pos[1],e;if(this.horizontal)return e[0]=this.pos[0]+this.size[0]/f*(b+0.5),e[1]=a?this.pos[1]-c.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],e;e[0]=a?this.pos[0]+l:this.pos[0]+this.size[0]+1-l;e[1]=this.pos[1]+(b+0.7)*c.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return e};
|
|
q.prototype.alignToGrid=function(){this.pos[0]=c.CANVAS_GRID_SIZE*Math.round(this.pos[0]/c.CANVAS_GRID_SIZE);this.pos[1]=c.CANVAS_GRID_SIZE*Math.round(this.pos[1]/c.CANVAS_GRID_SIZE)};q.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>q.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};q.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};q.prototype.loadImage=function(a){var b=new Image;
|
|
b.src=c.node_images_path+a;b.ready=!1;var e=this;b.onload=function(){this.ready=!0;e.setDirtyCanvas(!0)};return b};q.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,e=0;e<b.length;++e){var c=b[e];if(a||c.node_capturing_input==this)c.node_capturing_input=a?this:null}};q.prototype.collapse=function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?!1:!0,this.setDirtyCanvas(!0,
|
|
!0)};q.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};q.prototype.localToScreen=function(a,b,e){return[(a+this.pos[0])*e.scale+e.offset[0],(b+this.pos[1])*e.scale+e.offset[1]]};u.LGraphGroup=c.LGraphGroup=g;g.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=m.node_colors.pale_blue?m.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=
|
|
this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.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})};g.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;
|
|
this.font=a.font};g.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}};g.prototype.move=function(a,b,e){this._pos[0]+=a;this._pos[1]+=b;if(!e)for(e=0;e<this._nodes.length;++e){var c=this._nodes[e];c.pos[0]+=a;c.pos[1]+=b}};g.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),e=0;e<a.length;++e){var c=
|
|
a[e];c.getBounding(b);z(this._bounding,b)&&this._nodes.push(c)}};g.prototype.isPointInside=q.prototype.isPointInside;g.prototype.setDirtyCanvas=q.prototype.setDirtyCanvas;c.DragAndScale=r;r.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",
|
|
this._binded_mouse_callback,!1)};r.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],e=a+this.element.width/this.scale,c=b+this.element.height/this.scale;this.visible_area[0]=a;this.visible_area[1]=b;this.visible_area[2]=e-a;this.visible_area[3]=c-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};r.prototype.onMouse=function(a){if(this.enabled){var b=this.element,e=b.getBoundingClientRect(),c=a.clientX-e.left,
|
|
e=a.clientY-e.top;a.canvasx=c;a.canvasy=e;a.dragging=this.dragging;var l=!1;this.onmouse&&(l=this.onmouse(a));if("mousedown"==a.type)this.dragging=!0,b.removeEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback);else if("mousemove"==a.type)l||(b=c-this.last_mouse[0],l=e-this.last_mouse[1],this.dragging&&this.mouseDrag(b,l));else if("mouseup"==a.type)this.dragging=
|
|
!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback);else if("mousewheel"==a.type||"wheel"==a.type||"DOMMouseScroll"==a.type)a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta);this.last_mouse[0]=
|
|
c;this.last_mouse[1]=e;a.preventDefault();a.stopPropagation();return!1}};r.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};r.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};r.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};r.prototype.mouseDrag=function(a,b){this.offset[0]+=
|
|
a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};r.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var e=this.element.getBoundingClientRect();if(e){b=b||[0.5*e.width,0.5*e.height];e=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var c=this.convertCanvasToOffset(b),e=[c[0]-e[0],c[1]-e[1]];this.offset[0]+=e[0];this.offset[1]+=e[1];if(this.onredraw)this.onredraw(this)}}};
|
|
r.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};r.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};u.LGraphCanvas=c.LGraphCanvas=m;m.link_type_colors={"-1":c.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};m.gradients={};m.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()};m.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)))};m.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)};m.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]))}};m.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 <canvas> element, you passed a "+
|
|
a.localName;throw"This browser doesnt 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()}};m.prototype._doNothing=function(a){a.preventDefault();return!1};m.prototype._doReturnTrue=function(a){a.preventDefault();return!0};m.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");
|
|
else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",
|
|
this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",
|
|
this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};m.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",
|
|
this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);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")};m.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()};m.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};m.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};m.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};m.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))};m.prototype.stopRendering=function(){this.is_rendering=!1};m.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();m.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 e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),
|
|
f=!1,l=300>c.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();c.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,f=!0);var h=!1;if(e&&this.allow_interaction&&!f){this.live_mode||e.flags.pinned||this.bringToFront(e);if(!this.connecting_node&&
|
|
!e.flags.collapsed&&!this.live_mode)if(!f&&!1!==e.resizable&&B(a.canvasX,a.canvasY,e.pos[0]+e.size[0]-5,e.pos[1]+e.size[1]-5,10,10))this.resizing_node=e,this.canvas.style.cursor="se-resize",f=!0;else{if(e.outputs)for(var d=0,n=e.outputs.length;d<n;++d){var s=e.outputs[d],g=e.getConnectionPos(!1,d);if(B(a.canvasX,a.canvasY,g[0]-15,g[1]-10,30,20)){this.connecting_node=e;this.connecting_output=s;this.connecting_pos=e.getConnectionPos(!1,d);this.connecting_slot=d;a.shiftKey&&e.disconnectOutput(d);if(l){if(e.onOutputDblClick)e.onOutputDblClick(d,
|
|
a)}else if(e.onOutputClick)e.onOutputClick(d,a);f=!0;break}}if(e.inputs)for(d=0,n=e.inputs.length;d<n;++d)if(s=e.inputs[d],g=e.getConnectionPos(!0,d),B(a.canvasX,a.canvasY,g[0]-15,g[1]-10,30,20)){if(l){if(e.onInputDblClick)e.onInputDblClick(d,a)}else if(e.onInputClick)e.onInputClick(d,a);if(null!==s.link){f=this.graph.links[s.link];e.disconnectInput(d);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[f.origin_id],this.connecting_slot=f.origin_slot,this.connecting_output=
|
|
this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);f=this.dirty_bgcanvas=!0}}}if(!f){d=!1;if(n=this.processNodeWidgets(e,this.canvas_mouse,a))d=!0,this.node_widget=[e,n];if(l&&this.selected_nodes[e.id]){if(e.onDblClick)e.onDblClick(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],this);this.processNodeDblClicked(e);d=!0}e.onMouseDown&&e.onMouseDown(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],this)?d=!0:this.live_mode&&(d=h=
|
|
!0);d||(this.allow_dragnodes&&(this.node_dragged=e),this.selected_nodes[e.id]||this.processNodeSelected(e,a));this.dirty_canvas=!0}}else{for(d=0;d<this.visible_links.length;++d)if(e=this.visible_links[d],(h=e._pos)&&!(a.canvasX<h[0]-4||a.canvasX>h[0]+4||a.canvasY<h[1]-4||a.canvasY>h[1]+4)){this.showLinkMenu(e,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&(a.ctrlKey&&(this.dragging_rectangle=null),10>w([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());l&&this.showSearchBox(a);h=!0}!f&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(e,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=c.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}}};m.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){m.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],e=[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.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(e[0]/
|
|
this.ds.scale,e[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]+=e[0]/this.ds.scale,this.ds.offset[1]+=e[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,l=this.graph._nodes.length;b<l;++b)if(this.graph._nodes[b].mouseOver&&f!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=
|
|
!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(f){if(!f.mouseOver&&(f.mouseOver=!0,this.node_over=f,this.dirty_canvas=!0,f.onMouseEnter))f.onMouseEnter(a);if(f.onMouseMove)f.onMouseMove(a,[a.canvasX-f.pos[0],a.canvasY-f.pos[1]],this);if(this.connecting_node&&(l=this._highlight_input||[0,0],!this.isOverNodeBox(f,a.canvasX,a.canvasY))){var d=this.isOverNodeInput(f,a.canvasX,a.canvasY,l);-1!=d&&f.inputs[d]?c.isValidConnection(this.connecting_output.type,
|
|
f.inputs[d].type)&&(this._highlight_input=l):this._highlight_input=null}this.canvas&&(B(a.canvasX,a.canvasY,f.pos[0]+f.size[0]-5,f.pos[1]+f.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else this.canvas&&(this.canvas.style.cursor="");if(this.node_capturing_input&&this.node_capturing_input!=f&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)f=this.selected_nodes[b],
|
|
f.pos[0]+=e[0]/this.ds.scale,f.pos[1]+=e[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],e=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*c.NODE_SLOT_HEIGHT+(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(c.NODE_WIDGET_HEIGHT+
|
|
4)+4,this.resizing_node.size[1]<e&&(this.resizing_node.size[1]=e),this.resizing_node.size[0]<c.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=c.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};m.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;m.active_canvas=this;b.removeEventListener("mousemove",this._mousemove_callback,!0);this.canvas.addEventListener("mousemove",this._mousemove_callback,
|
|
!0);b.removeEventListener("mouseup",this._mouseup_callback,!0);this.adjustMouseEvent(a);b=c.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;if(1==a.which){this.node_widget=null;if(this.selected_group){var b=this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),e=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,e,a.ctrlKey);this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]);this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]);
|
|
this.selected_group._nodes.length&&(this.dirty_canvas=!0);this.selected_group=null}this.selected_group_resizing=!1;if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;e=new Float32Array(4);this.deselectAllNodes();var f=Math.abs(this.dragging_rectangle[2]),l=Math.abs(this.dragging_rectangle[3]),d=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-l:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-f:this.dragging_rectangle[0];
|
|
this.dragging_rectangle[1]=d;this.dragging_rectangle[2]=f;this.dragging_rectangle[3]=l;l=[];for(d=0;d<b.length;++d)f=b[d],f.getBounding(e),z(this.dragging_rectangle,e)&&l.push(f);l.length&&this.selectNodes(l)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==c.EVENT&&this.isOverNodeBox(f,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,
|
|
f,c.EVENT):(b=this.isOverNodeInput(f,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,f,b):(b=f.getInputInfo(0),this.connecting_output.type==c.EVENT?this.connecting_node.connect(this.connecting_slot,f,c.EVENT):b&&!b.link&&c.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,f,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=-1}else if(this.resizing_node)this.dirty_bgcanvas=
|
|
this.dirty_canvas=!0,this.resizing_node=null;else if(this.node_dragged)(f=this.node_dragged)&&300>a.click_time&&B(a.canvasX,a.canvasY,f.pos[0],f.pos[1]-c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT)&&f.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(),this.node_dragged=null;else{f=this.graph.getNodeOnPos(a.canvasX,
|
|
a.canvasY,this.visible_nodes);!f&&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}};m.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var e=this.ds.scale;0<b?e*=1.1:0>b&&(e*=1/1.1);this.ds.changeScale(e,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};m.prototype.isOverNodeBox=function(a,b,e){var f=c.NODE_TITLE_HEIGHT;return B(b,
|
|
e,a.pos[0]+2,a.pos[1]+2-f,f-4,f-4)?!0:!1};m.prototype.isOverNodeInput=function(a,b,e,c){if(a.inputs)for(var f=0,d=a.inputs.length;f<d;++f){var h=a.getConnectionPos(!0,f),m=!1;if(m=a.horizontal?B(b,e,h[0]-5,h[1]-10,10,20):B(b,e,h[0]-10,h[1]-5,40,10))return c&&(c[0]=h[0],c[1]=h[1]),f}return-1};m.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),
|
|
"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var e in this.selected_nodes)if(this.selected_nodes[e].onKeyDown)this.selected_nodes[e].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(e in this.selected_nodes)if(this.selected_nodes[e].onKeyUp)this.selected_nodes[e].onKeyUp(a);
|
|
this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};m.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,e=[],c;for(c in this.selected_nodes){var f=this.selected_nodes[c];f._relative_id=b;e.push(f);b+=1}for(c=0;c<e.length;++c)if(f=e[c],a.nodes.push(f.clone().serialize()),f.inputs&&f.inputs.length)for(b=0;b<f.inputs.length;++b){var d=f.inputs[b];if(d&&null!=d.link&&(d=this.graph.links[d.link])){var h=this.graph.getNodeById(d.origin_id);h&&this.selected_nodes[h.id]&&
|
|
a.links.push([h._relative_id,b,f._relative_id,d.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};m.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],e=0;e<a.nodes.length;++e){var f=a.nodes[e],l=c.createNode(f.type);l&&(l.configure(f),l.pos[0]+=5,l.pos[1]+=5,this.graph.add(l),b.push(l))}for(e=0;e<a.links.length;++e)f=a.links[e],b[f[0]].connect(f[1],b[f[2]],f[3]);this.selectNodes(b)}};
|
|
m.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],e=this.graph.getNodeOnPos(b[0],b[1]);if(e){if((e.onDropFile||e.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var f=a.dataTransfer.files[0],d=f.name;m.getFileExtension(d);if(e.onDropFile)e.onDropFile(f);if(e.onDropData){var h=new FileReader;h.onload=function(a){e.onDropData(a.target.result,d,f)};var n=f.type.split("/")[0];"text"==n||""==n?h.readAsText(f):"image"==
|
|
n?h.readAsDataURL(f):h.readAsArrayBuffer(f)}}return e.onDropItem&&e.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};m.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],e=m.getFileExtension(b.name).toLowerCase();if(e=c.node_types_by_file_extension[e])if(e=c.createNode(e.type),e.pos=[a.canvasX,a.canvasY],this.graph.add(e),e.onDropFile)e.onDropFile(b)}};m.prototype.processNodeDblClicked=
|
|
function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};m.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};m.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};m.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};m.prototype.selectNodes=function(a,
|
|
b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var e=0;e<a.length;++e){var c=a[e];if(!c.is_selected){if(!c.is_selected&&c.onSelected)c.onSelected();c.is_selected=!0;this.selected_nodes[c.id]=c;if(c.inputs)for(var f=0;f<c.inputs.length;++f)this.highlighted_links[c.inputs[f].link]=!0;if(c.outputs)for(f=0;f<c.outputs.length;++f){var d=c.outputs[f];if(d.links)for(var h=0;h<d.links.length;++h)this.highlighted_links[d.links[h]]=!0}}}this.setDirty(!0)};m.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();
|
|
a.is_selected=!1;if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var e=a.outputs[b];if(e.links)for(var c=0;c<e.links.length;++c)delete this.highlighted_links[e.links[c]]}}};m.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,e=a.length;b<e;++b){var c=a[b];if(c.is_selected){if(c.onDeselected)c.onDeselected();c.is_selected=!1}}this.selected_nodes={};this.highlighted_links={};
|
|
this.setDirty(!0)}};m.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)};m.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};m.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();
|
|
a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};m.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.convertOffsetToCanvas=function(a,
|
|
b){return this.ds.convertOffsetToCanvas(a,b)};m.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};m.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};m.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};m.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);
|
|
-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var x=new Float32Array(4);m.prototype.computeVisibleNodes=function(a,b){var e=b||[];e.length=0;a=a||this.graph._nodes;for(var c=0,f=a.length;c<f;++c){var d=a[c];(!this.live_mode||d.onDrawBackground||d.onDrawForeground)&&z(this.visible_area,d.getBounding(x))&&e.push(d)}return e};m.prototype.draw=function(a,b){if(this.canvas){var e=c.getTime();this.render_time=0.001*(e-this.last_draw_time);this.last_draw_time=e;this.graph&&this.ds.computeVisibleArea();
|
|
(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>e-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}};m.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),e=0;e<b.length;++e){var f=b[e];a.save();a.translate(f.pos[0],f.pos[1]);this.drawNode(f,
|
|
a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case c.EVENT:b=c.EVENT_LINK_COLOR;break;default:b=c.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?c.DOWN:c.RIGHT),c.CENTER);
|
|
a.beginPath();this.connecting_output.type===c.EVENT||this.connecting_output.shape===c.BOX_SHAPE?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],
|
|
this.dragging_rectangle[3]));if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};m.prototype.renderInfo=function(a,b,e){b=b||0;e=e||0;a.save();a.translate(b,e);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+
|
|
"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};m.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();
|
|
var e=this.graph._subgraph_node;b.strokeStyle=e.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=e.bgcolor;for(var c="",f=1;f<this._graph_stack.length;++f)c+=this._graph_stack[f]._subgraph_node.getTitle()+" >> ";b.fillText(c+e.getTitle(),0.5*a.width,40);b.restore()}e=!1;this.onRenderBackground&&(e=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();
|
|
this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!e){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var d=this;this._bg_img.onload=function(){d.draw(!0,!0)}}e=null;null==this._pattern&&0<this._bg_img.width?
|
|
(e=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=e):e=this._pattern;e&&(b.fillStyle=e,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),
|
|
this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var n=new Float32Array(2);m.prototype.drawNode=function(a,b){this.current_node=a;var e=a.color||a.constructor.color||
|
|
c.NODE_DEFAULT_COLOR,f=a.bgcolor||a.constructor.bgcolor||c.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var l=this.editor_alpha;b.globalAlpha=l;this.render_shadows?(b.shadowColor=c.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.onDrawCollaped||!0!=a.onDrawCollapsed(b,
|
|
this)){var d=a._shape||c.BOX_SHAPE;n.set(a.size);var h=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*c.NODE_TITLE_HEIGHT),n[0]=a._collapsed_width,n[1]=0)}a.clip_area&&(b.save(),b.beginPath(),d==c.BOX_SHAPE?b.rect(0,0,n[0],n[1]):d==c.ROUND_SHAPE?b.roundRect(0,0,n[0],n[1],10):d==c.CIRCLE_SHAPE&&b.arc(0.5*n[0],0.5*n[1],0.5*n[0],0,2*Math.PI),b.clip());a.has_errors&&(f="red");
|
|
this.drawNodeShape(a,b,n,e,f,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=h?"center":"left";b.font=this.inner_text_font;f=0.6<this.ds.scale;d=this.connecting_output;b.lineWidth=1;var m=0,s=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(e=0;e<a.inputs.length;e++){var g=a.inputs[e];b.globalAlpha=l;this.connecting_node&&c.isValidConnection(g.type&&d.type)&&(b.globalAlpha=0.4*l);b.fillStyle=null!=g.link?g.color_on||
|
|
this.default_connection_color.input_on:g.color_off||this.default_connection_color.input_off;var p=a.getConnectionPos(!0,e,s);p[0]-=a.pos[0];p[1]-=a.pos[1];m<p[1]+0.5*c.NODE_SLOT_HEIGHT&&(m=p[1]+0.5*c.NODE_SLOT_HEIGHT);b.beginPath();g.type===c.EVENT||g.shape===c.BOX_SHAPE?h?b.rect(p[0]-5+0.5,p[1]-8+0.5,10,14):b.rect(p[0]-6+0.5,p[1]-5+0.5,14,10):g.shape===c.ARROW_SHAPE?(b.moveTo(p[0]+8,p[1]+0.5),b.lineTo(p[0]-4,p[1]+6+0.5),b.lineTo(p[0]-4,p[1]-6+0.5),b.closePath()):b.arc(p[0],p[1],4,0,2*Math.PI);b.fill();
|
|
if(f){var C=null!=g.label?g.label:g.name;C&&(b.fillStyle=c.NODE_TEXT_COLOR,h||g.dir==c.UP?b.fillText(C,p[0],p[1]-10):b.fillText(C,p[0]+10,p[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*l);b.textAlign=h?"center":"right";b.strokeStyle="black";if(a.outputs)for(e=0;e<a.outputs.length;e++)if(g=a.outputs[e],p=a.getConnectionPos(!1,e,s),p[0]-=a.pos[0],p[1]-=a.pos[1],m<p[1]+0.5*c.NODE_SLOT_HEIGHT&&(m=p[1]+0.5*c.NODE_SLOT_HEIGHT),b.fillStyle=g.links&&g.links.length?g.color_on||this.default_connection_color.output_on:
|
|
g.color_off||this.default_connection_color.output_off,b.beginPath(),g.type===c.EVENT||g.shape===c.BOX_SHAPE?h?b.rect(p[0]-5+0.5,p[1]-8+0.5,10,14):b.rect(p[0]-6+0.5,p[1]-5+0.5,14,10):g.shape===c.ARROW_SHAPE?(b.moveTo(p[0]+8,p[1]+0.5),b.lineTo(p[0]-4,p[1]+6+0.5),b.lineTo(p[0]-4,p[1]-6+0.5),b.closePath()):b.arc(p[0],p[1],4,0,2*Math.PI),b.fill(),b.stroke(),f&&(C=null!=g.label?g.label:g.name))b.fillStyle=c.NODE_TEXT_COLOR,h||g.dir==c.DOWN?b.fillText(C,p[0],p[1]-8):b.fillText(C,p[0]-10,p[1]+5);b.textAlign=
|
|
"left";b.globalAlpha=1;if(a.widgets){if(h||a.widgets_up)m=2;this.drawNodeWidgets(a,m,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){l=f=null;if(a.inputs)for(e=0;e<a.inputs.length;e++)if(g=a.inputs[e],null!=g.link){f=g;break}if(a.outputs)for(e=0;e<a.outputs.length;e++)g=a.outputs[e],g.links&&g.links.length&&(l=g);f&&(e=0,f=-0.5*c.NODE_TITLE_HEIGHT,h&&(e=0.5*a._collapsed_width,f=-c.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),g.type===
|
|
c.EVENT||g.shape===c.BOX_SHAPE?b.rect(e-7+0.5,f-4,14,8):g.shape===c.ARROW_SHAPE?(b.moveTo(e+8,f),b.lineTo(e+-4,f-4),b.lineTo(e+-4,f+4),b.closePath()):b.arc(e,f,4,0,2*Math.PI),b.fill());l&&(e=a._collapsed_width,f=-0.5*c.NODE_TITLE_HEIGHT,h&&(e=0.5*a._collapsed_width,f=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),g.type===c.EVENT||g.shape===c.BOX_SHAPE?b.rect(e-7+0.5,f-4,14,8):g.shape===c.ARROW_SHAPE?(b.moveTo(e+6,f),b.lineTo(e-6,f-4),b.lineTo(e-6,f+4),b.closePath()):b.arc(e,f,4,0,2*Math.PI),
|
|
b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};var f=new Float32Array(4);m.prototype.drawNodeShape=function(a,b,e,d,l,h,n){b.strokeStyle=d;b.fillStyle=l;l=c.NODE_TITLE_HEIGHT;var g=0.5>this.ds.scale,s=a._shape||a.constructor.shape||c.ROUND_SHAPE,k=a.constructor.title_mode,p=!0;k==c.TRANSPARENT_TITLE?p=!1:k==c.AUTOHIDE_TITLE&&n&&(p=!0);f[0]=0;f[1]=p?-l:0;f[2]=e[0]+1;f[3]=p?e[1]+l:e[1];n=b.globalAlpha;b.beginPath();s==c.BOX_SHAPE||g?b.fillRect(f[0],f[1],f[2],f[3]):s==c.ROUND_SHAPE||s==c.CARD_SHAPE?
|
|
b.roundRect(f[0],f[1],f[2],f[3],this.round_radius,s==c.CARD_SHAPE?0:this.round_radius):s==c.CIRCLE_SHAPE&&b.arc(0.5*e[0],0.5*e[1],0.5*e[0],0,2*Math.PI);b.fill();b.shadowColor="transparent";b.fillStyle="rgba(0,0,0,0.2)";b.fillRect(0,-1,f[2],2);b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(p||k==c.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,l,e,this.ds.scale,d);else if(k!=c.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){p=
|
|
a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=c.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var C=m.gradients[p];C||(C=m.gradients[p]=b.createLinearGradient(0,0,400,0),C.addColorStop(0,p),C.addColorStop(1,"#000"));b.fillStyle=C}else b.fillStyle=p;b.beginPath();s==c.BOX_SHAPE||g?b.rect(0,-l,e[0]+1,l):s!=c.ROUND_SHAPE&&s!=c.CARD_SHAPE||b.roundRect(0,-l,e[0]+1,l,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,
|
|
l,e,this.ds.scale);else s==c.ROUND_SHAPE||s==c.CIRCLE_SHAPE||s==c.CARD_SHAPE?(g&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*l,-0.5*l,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||c.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*l,-0.5*l,5,0,2*Math.PI),b.fill()):(g&&(b.fillStyle="black",b.fillRect(0.5*(l-10)-1,-0.5*(l+10)-1,12,12)),b.fillStyle=a.boxcolor||c.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(l-10),-0.5*(l+10),10,10));b.globalAlpha=n;if(a.onDrawTitleText)a.onDrawTitleText(b,l,e,this.ds.scale,
|
|
this.title_text_font,h);!g&&(b.font=this.title_text_font,g=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",n=b.measureText(g),b.fillText(g,l+0.5*n.width,c.NODE_TITLE_TEXT_Y-l),b.textAlign="left"):(b.textAlign="left",b.fillText(g,l,c.NODE_TITLE_TEXT_Y-l)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(f);k==c.TRANSPARENT_TITLE&&(f[1]-=l,f[3]+=l);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();s==
|
|
c.BOX_SHAPE?b.rect(-6+f[0],-6+f[1],12+f[2],12+f[3]):s==c.ROUND_SHAPE||s==c.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+f[0],-6+f[1],12+f[2],12+f[3],2*this.round_radius):s==c.CARD_SHAPE?b.roundRect(-6+f[0],-6+f[1],12+f[2],12+f[3],2*this.round_radius,2):s==c.CIRCLE_SHAPE&&b.arc(0.5*e[0],0.5*e[1],0.5*e[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=d;b.globalAlpha=1}};var A=new Float32Array(4),h=new Float32Array(4),s=new Float32Array(2),v=new Float32Array(2);m.prototype.drawConnections=
|
|
function(a){var b=c.getTime(),e=this.visible_area;A[0]=e[0]-20;A[1]=e[1]-20;A[2]=e[2]+40;A[3]=e[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var e=this.graph._nodes,f=0,l=e.length;f<l;++f){var d=e[f];if(d.inputs&&d.inputs.length)for(var m=0;m<d.inputs.length;++m){var n=d.inputs[m];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var g=this.graph.getNodeById(n.origin_id);if(null!=g){var k=n.origin_slot,p=null,p=-1==k?[g.pos[0]+
|
|
10,g.pos[1]+10]:g.getConnectionPos(!1,k,s),C=d.getConnectionPos(!0,m,v);h[0]=p[0];h[1]=p[1];h[2]=C[0]-p[0];h[3]=C[1]-p[1];0>h[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(z(h,A)){var D=g.outputs[k],k=d.inputs[m];if(D&&k&&(g=D.dir||(g.horizontal?c.DOWN:c.RIGHT),k=k.dir||(d.horizontal?c.UP:c.LEFT),this.renderLink(a,p,C,n,!1,0,null,g,k),n&&n._last_time&&1E3>b-n._last_time)){var D=2-0.002*(b-n._last_time),E=a.globalAlpha;a.globalAlpha=E*D;this.renderLink(a,p,C,n,!0,
|
|
D,"white",g,k);a.globalAlpha=E}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,e,f,l,d,h,n,g,s){f&&this.visible_links.push(f);!h&&f&&(h=f.color||m.link_type_colors[f.type]);h||(h=this.default_link_color);null!=f&&this.highlighted_links[f.id]&&(h="#FFF");n=n||c.RIGHT;g=g||c.LEFT;var p=w(b,e);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";s=s||1;1<s&&(a.lineWidth=0.5);a.beginPath();for(var C=0;C<s;C+=1){var D=5*(C-0.5*(s-1));if(this.links_render_mode==
|
|
c.SPLINE_LINK){a.moveTo(b[0],b[1]+D);var E=0,k=0,q=0,A=0;switch(n){case c.LEFT:E=-0.25*p;break;case c.RIGHT:E=0.25*p;break;case c.UP:k=-0.25*p;break;case c.DOWN:k=0.25*p}switch(g){case c.LEFT:q=-0.25*p;break;case c.RIGHT:q=0.25*p;break;case c.UP:A=-0.25*p;break;case c.DOWN:A=0.25*p}a.bezierCurveTo(b[0]+E,b[1]+k+D,e[0]+q,e[1]+A+D,e[0],e[1]+D)}else if(this.links_render_mode==c.LINEAR_LINK){a.moveTo(b[0],b[1]+D);A=q=k=E=0;switch(n){case c.LEFT:E=-1;break;case c.RIGHT:E=1;break;case c.UP:k=-1;break;case c.DOWN:k=
|
|
1}switch(g){case c.LEFT:q=-1;break;case c.RIGHT:q=1;break;case c.UP:A=-1;break;case c.DOWN:A=1}a.lineTo(b[0]+15*E,b[1]+15*k+D);a.lineTo(e[0]+15*q,e[1]+15*A+D);a.lineTo(e[0],e[1]+D)}else if(this.links_render_mode==c.STRAIGHT_LINK)a.moveTo(b[0],b[1]),D=b[0],E=b[1],k=e[0],q=e[1],n==c.RIGHT?D+=10:E+=10,g==c.LEFT?k-=10:q-=10,a.lineTo(D,E),a.lineTo(0.5*(D+k),E),a.lineTo(0.5*(D+k),q),a.lineTo(k,q),a.lineTo(e[0],e[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!l&&(a.strokeStyle="rgba(0,0,0,0.5)",
|
|
a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=h;a.stroke();l=this.computeConnectionPoint(b,e,0.5,n,g);f&&f._pos&&(f._pos[0]=l[0],f._pos[1]=l[1]);0.6<=this.ds.scale&&this.highquality_render&&g!=c.CENTER&&(this.render_connection_arrows&&(C=this.computeConnectionPoint(b,e,0.25,n,g),f=this.computeConnectionPoint(b,e,0.26,n,g),s=this.computeConnectionPoint(b,e,0.75,n,g),p=this.computeConnectionPoint(b,e,0.76,n,g),E=D=0,this.render_curved_connections?(D=-Math.atan2(f[0]-C[0],
|
|
f[1]-C[1]),E=-Math.atan2(p[0]-s[0],p[1]-s[1])):E=D=e[1]>b[1]?0:Math.PI,a.save(),a.translate(C[0],C[1]),a.rotate(D),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(s[0],s[1]),a.rotate(E),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(l[0],l[1],5,0,2*Math.PI),a.fill());if(d)for(a.fillStyle=h,C=0;5>C;++C)d=(0.001*c.getTime()+0.2*C)%1,l=this.computeConnectionPoint(b,e,d,n,g),a.beginPath(),a.arc(l[0],
|
|
l[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,e,f,l){f=f||c.RIGHT;l=l||c.LEFT;var d=w(a,b),h=[a[0],a[1]],n=[b[0],b[1]];switch(f){case c.LEFT:h[0]+=-0.25*d;break;case c.RIGHT:h[0]+=0.25*d;break;case c.UP:h[1]+=-0.25*d;break;case c.DOWN:h[1]+=0.25*d}switch(l){case c.LEFT:n[0]+=-0.25*d;break;case c.RIGHT:n[0]+=0.25*d;break;case c.UP:n[1]+=-0.25*d;break;case c.DOWN:n[1]+=0.25*d}f=(1-e)*(1-e)*(1-e);l=3*(1-e)*(1-e)*e;d=3*(1-e)*e*e;e*=e*e;return[f*a[0]+l*h[0]+d*n[0]+e*b[0],
|
|
f*a[1]+l*h[1]+d*n[1]+e*b[1]]};m.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,e=0;e<b.length;++e){var f=b[e];a.fillStyle="black";a.fillRect(f.pos[0]-c.NODE_TITLE_HEIGHT,f.pos[1]-c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT);0==f.order&&a.strokeRect(f.pos[0]-c.NODE_TITLE_HEIGHT+0.5,f.pos[1]-c.NODE_TITLE_HEIGHT+0.5,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT);
|
|
a.fillStyle="#FFF";a.fillText(f.order,f.pos[0]+-0.5*c.NODE_TITLE_HEIGHT,f.pos[1]-6)}a.globalAlpha=1};m.prototype.drawNodeWidgets=function(a,b,e,f){if(!a.widgets||!a.widgets.length)return 0;var l=a.size[0],d=a.widgets;b+=2;var h=c.NODE_WIDGET_HEIGHT,n=0.5<this.ds.scale;e.save();e.globalAlpha=this.editor_alpha;for(var m=0;m<d.length;++m){var g=d[m],p=b;g.y&&(p=g.y);g.last_y=p;e.strokeStyle="#666";e.fillStyle="#222";e.textAlign="left";switch(g.type){case "button":g.clicked&&(e.fillStyle="#AAA",g.clicked=
|
|
!1,this.dirty_canvas=!0);e.fillRect(15,p,l-30,h);e.strokeRect(15,p,l-30,h);n&&(e.textAlign="center",e.fillStyle="#AAA",e.fillText(g.name,0.5*l,p+0.7*h));break;case "toggle":e.textAlign="left";e.strokeStyle="#666";e.fillStyle="#222";e.beginPath();e.roundRect(15,b,l-30,h,0.5*h);e.fill();e.stroke();e.fillStyle=g.value?"#89A":"#333";e.beginPath();e.arc(l-30,p+0.5*h,0.36*h,0,2*Math.PI);e.fill();n&&(e.fillStyle="#999",null!=g.name&&e.fillText(g.name,30,p+0.7*h),e.fillStyle=g.value?"#DDD":"#888",e.textAlign=
|
|
"right",e.fillText(g.value?g.options.on||"true":g.options.off||"false",l-40,p+0.7*h));break;case "slider":e.fillStyle="#222";e.fillRect(15,p,l-30,h);var C=g.options.max-g.options.min,D=(g.value-g.options.min)/C;e.fillStyle=f==g?"#89A":"#678";e.fillRect(15,p,D*(l-30),h);e.strokeRect(15,p,l-30,h);g.marker&&(C=(g.marker-g.options.min)/C,e.fillStyle="#AA9",e.fillRect(15+C*(l-30),p,2,h));n&&(e.textAlign="center",e.fillStyle="#DDD",e.fillText(g.name+" "+Number(g.value).toFixed(3),0.5*l,p+0.7*h));break;
|
|
case "number":case "combo":e.textAlign="left";e.strokeStyle="#666";e.fillStyle="#222";e.beginPath();e.roundRect(15,b,l-30,h,0.5*h);e.fill();e.stroke();n&&(e.fillStyle="#AAA",e.beginPath(),e.moveTo(31,b+5),e.lineTo(21,b+0.5*h),e.lineTo(31,b+h-5),e.moveTo(l-15-16,b+5),e.lineTo(l-15-6,b+0.5*h),e.lineTo(l-15-16,b+h-5),e.fill(),e.fillStyle="#999",e.fillText(g.name,35,p+0.7*h),e.fillStyle="#DDD",e.textAlign="right","number"==g.type?e.fillText(Number(g.value).toFixed(void 0!==g.options.precision?g.options.precision:
|
|
3),l-30-20,p+0.7*h):e.fillText(g.value,l-30-20,p+0.7*h));break;case "string":case "text":e.textAlign="left";e.strokeStyle="#666";e.fillStyle="#222";e.beginPath();e.roundRect(15,b,l-30,h,0.5*h);e.fill();e.stroke();n&&(e.fillStyle="#999",null!=g.name&&e.fillText(g.name,30,p+0.7*h),e.fillStyle="#DDD",e.textAlign="right",e.fillText(g.value,l-30,p+0.7*h));break;default:g.draw&&g.draw(e,a,g,p,h)}b+=h+4}e.restore()};m.prototype.processNodeWidgets=function(a,b,e,f){if(!a.widgets||!a.widgets.length)return null;
|
|
for(var l=b[0]-a.pos[0],h=b[1]-a.pos[1],d=a.size[0],n=this,g=this.getCanvasWindow(),m=0;m<a.widgets.length;++m){var p=a.widgets[m];if(p==f||6<l&&l<d-12&&h>p.last_y&&h<p.last_y+c.NODE_WIDGET_HEIGHT){switch(p.type){case "button":p.callback&&setTimeout(function(){p.callback(p,n,a,b)},20);this.dirty_canvas=p.clicked=!0;break;case "slider":e=Math.clamp((l-10)/(d-20),0,1);p.value=p.options.min+(p.options.max-p.options.min)*e;p.callback&&setTimeout(function(){p.callback(p.value,n,a,b)},20);this.dirty_canvas=
|
|
!0;break;case "number":case "combo":if("mousemove"==e.type&&"number"==p.type)p.value+=0.1*e.deltaX*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if("mousedown"==e.type)if((f=p.options.values)&&f.constructor===Function&&(f=p.options.values(p,a)),l=40>l?-1:l>d-40?1:0,"number"==p.type)p.value+=0.1*l*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),
|
|
null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if(l)e=f.indexOf(p.value)+l,e>=f.length&&(e=0),0>e&&(e=f.length-1),p.value=f[e];else{new c.ContextMenu(f,{scale:Math.max(1,this.ds.scale),event:e,className:"dark",callback:C.bind(p)},g);var C=function(a,b,e){this.value=a;n.dirty_canvas=!0;return!1}}p.callback&&setTimeout(function(){this.callback(this.value,n,a,b)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==e.type&&(p.value=!p.value,p.callback&&setTimeout(function(){p.callback(p.value,
|
|
n,a,b)},20));break;case "string":case "text":"mousedown"==e.type&&this.prompt("Value",p.value,function(b){this.value=b;p.callback&&p.callback(b,n,a)}.bind(p),e);break;default:p.mouse&&p.mouse(ctx,e,[l,h],a)}return p}}return null};m.prototype.drawGroups=function(a,b){if(this.graph){var e=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var f=0;f<e.length;++f){var l=e[f];if(z(this.visible_area,l._bounding)){b.fillStyle=l.color||"#335";b.strokeStyle=l.color||"#335";var h=l._pos,d=
|
|
l._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(h[0]+0.5,h[1]+0.5,d[0],d[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(h[0]+d[0],h[1]+d[1]);b.lineTo(h[0]+d[0]-10,h[1]+d[1]);b.lineTo(h[0]+d[0],h[1]+d[1]-10);b.fill();d=l.font_size||c.DEFAULT_GROUP_FONT_SIZE;b.font=d+"px Arial";b.fillText(l.title,h[0]+4,h[1]+d)}}b.restore()}};m.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,
|
|
!0)};m.prototype.resize=function(a,b){if(!a&&!b){var e=this.canvas.parentNode;a=e.offsetWidth;b=e.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};m.prototype.switchLiveMode=function(a){if(a){var b=this,e=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var c=setInterval(function(){b.editor_alpha*=e;b.dirty_canvas=!0;
|
|
b.dirty_bgcanvas=!0;1>e&&0.01>b.editor_alpha&&(clearInterval(c),1>e&&(b.live_mode=!0));1<e&&0.99<b.editor_alpha&&(clearInterval(c),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.onNodeSelectionChange=function(a){};m.prototype.touchHandler=function(a){var b=a.changedTouches[0],e="";switch(a.type){case "touchstart":e="mousedown";break;case "touchmove":e="mousemove";break;case "touchend":e="mouseup";break;default:return}var c=this.getCanvasWindow(),
|
|
f=c.document.createEvent("MouseEvent");f.initMouseEvent(e,!0,!0,c,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(f);a.preventDefault()};m.onGroupAdd=function(a,b,e){a=m.active_canvas;a.getCanvasWindow();b=new c.LGraphGroup;b.pos=a.convertEventToCanvasOffset(e);a.graph.add(b)};m.onMenuAdd=function(a,b,e,f){function l(a,b){var e=f.getFirstEvent(),l=c.createNode(a.value);l&&(l.pos=d.convertEventToCanvasOffset(e),d.graph.add(l))}var d=m.active_canvas,h=d.getCanvasWindow();
|
|
a=c.getNodeTypesCategories();b=[];for(var n in a)a[n]&&b.push({value:a[n],content:a[n],has_submenu:!0});var g=new c.ContextMenu(b,{event:e,callback:function(a,b,e){a=c.getNodeTypesInCategory(a.value,d.filter);b=[];for(var f in a)a[f].skip_list||b.push({content:a[f].title,value:a[f].type});new c.ContextMenu(b,{event:e,callback:l,parentMenu:g},h);return!1},parentMenu:f},h);return!1};m.onMenuCollapseAll=function(){};m.onMenuNodeEdit=function(){};m.showMenuNodeOptionalInputs=function(a,b,e,f,l){function d(a,
|
|
b,e){l&&(a.callback&&a.callback.call(h,l,a,b,e),a.value&&(l.addInput(a.value[0],a.value[1],a.value[2]),l.setDirtyCanvas(!0,!0)))}if(l){var h=this;a=m.active_canvas.getCanvasWindow();b=l.optional_inputs;l.onGetInputs&&(b=l.onGetInputs());var n=[];if(b)for(var g in b){var s=b[g];if(s){var p=s[0];s[2]&&s[2].label&&(p=s[2].label);p={content:p,value:s};s[1]==c.ACTION&&(p.className="event");n.push(p)}else n.push(null)}this.onMenuNodeInputs&&(n=this.onMenuNodeInputs(n));if(n.length)return new c.ContextMenu(n,
|
|
{event:e,callback:d,parentMenu:f,node:l},a),!1}};m.showMenuNodeOptionalOutputs=function(a,b,e,f,l){function d(a,b,e){if(l&&(a.callback&&a.callback.call(h,l,a,b,e),a.value))if(e=a.value[1],!e||e.constructor!==Object&&e.constructor!==Array)l.addOutput(a.value[0],a.value[1],a.value[2]),l.setDirtyCanvas(!0,!0);else{a=[];for(var p in e)a.push({content:p,value:e[p]});new c.ContextMenu(a,{event:b,callback:d,parentMenu:f,node:l});return!1}}if(l){var h=this;a=m.active_canvas.getCanvasWindow();b=l.optional_outputs;
|
|
l.onGetOutputs&&(b=l.onGetOutputs());var n=[];if(b)for(var g in b){var s=b[g];if(!s)n.push(null);else if(!l.flags||!l.flags.skip_repeated_outputs||-1==l.findOutputSlot(s[0])){var p=s[0];s[2]&&s[2].label&&(p=s[2].label);p={content:p,value:s};s[1]==c.EVENT&&(p.className="event");n.push(p)}}this.onMenuNodeOutputs&&(n=this.onMenuNodeOutputs(n));if(n.length)return new c.ContextMenu(n,{event:e,callback:d,parentMenu:f,node:l},a),!1}};m.onShowMenuNodeProperties=function(a,b,e,f,l){function d(a,b,e,c){l&&
|
|
(b=this.getBoundingClientRect(),h.showEditPropertyValue(l,a.value,{position:[b.left,b.top]}))}if(l&&l.properties){var h=m.active_canvas;b=h.getCanvasWindow();var n=[],g;for(g in l.properties)a=void 0!==l.properties[g]?l.properties[g]:" ",a=m.decodeHTML(a),n.push({content:"<span class='property_name'>"+g+"</span><span class='property_value'>"+a+"</span>",value:g});if(n.length)return new c.ContextMenu(n,{event:e,callback:d,parentMenu:f,allow_html:!0,node:l},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");
|
|
b.innerText=a;return b.innerHTML};m.onResizeNode=function(a,b,e,c,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};m.prototype.showLinkMenu=function(a,b){var e=this;new c.ContextMenu(["Delete"],{event:b,callback:function(b){switch(b){case "Delete":e.graph.removeLink(a.id)}}});return!1};m.onShowPropertyEditor=function(a,b,e,c,f){function d(){var b=g.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));f[h]=b;n.parentNode&&n.parentNode.removeChild(n);f.setDirtyCanvas(!0,!0)}var h=
|
|
a.property||"title";b=f[h];var n=document.createElement("div");n.className="graphdialog";n.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";n.querySelector(".name").innerText=h;var g=n.querySelector("input");g&&(g.value=b,g.addEventListener("blur",function(a){this.focus()}),g.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())}));b=m.active_canvas.canvas;e=b.getBoundingClientRect();var s=c=-20;e&&(c-=
|
|
e.left,s-=e.top);event?(n.style.left=event.clientX+c+"px",n.style.top=event.clientY+s+"px"):(n.style.left=0.5*b.width+c+"px",n.style.top=0.5*b.height+s+"px");n.querySelector("button").addEventListener("click",d);b.parentNode.appendChild(n)};m.prototype.prompt=function(a,b,e,c){var f=this;a=a||"";var d=!1,h=document.createElement("div");h.className="graphdialog rounded";h.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";h.close=
|
|
function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseleave",function(a){d||h.close()});f.prompt_box&&f.prompt_box.close();f.prompt_box=h;h.querySelector(".name").innerText=a;h.querySelector(".value").value=b;var n=h.querySelector("input");n.addEventListener("keydown",function(a){d=!0;if(27==a.keyCode)h.close();else if(13==a.keyCode)e&&e(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});
|
|
h.querySelector("button").addEventListener("click",function(a){e&&e(n.value);f.setDirty(!0);h.close()});a=m.active_canvas.canvas;b=a.getBoundingClientRect();var g=-20,s=-20;b&&(g-=b.left,s-=b.top);c?(h.style.left=c.clientX+g+"px",h.style.top=c.clientY+s+"px"):(h.style.left=0.5*a.width+g+"px",h.style.top=0.5*a.height+s+"px");a.parentNode.appendChild(h);setTimeout(function(){n.focus()},10);return h};m.search_limit=-1;m.prototype.showSearchBox=function(a){function b(b){if(b)if(h.onSearchBoxSelection)h.onSearchBoxSelection(b,
|
|
a,D);else{var e=c.searchbox_extras[b];e&&(b=e.type);if(b=c.createNode(b))b.pos=D.convertEventToCanvasOffset(a),D.graph.add(b);if(e&&e.data){if(e.data.properties)for(var f in e.data.properties)b.addProperty(e.data.properties[f][0],e.data.properties[f][0]);if(e.data.inputs)for(f in b.inputs=[],e.data.inputs)b.addOutput(e.data.inputs[f][0],e.data.inputs[f][1]);if(e.data.outputs)for(f in b.outputs=[],e.data.outputs)b.addOutput(e.data.outputs[f][0],e.data.outputs[f][1]);e.data.title&&(b.title=e.data.title);
|
|
e.data.json&&b.configure(e.data.json)}}d.close()}function e(a){var b=p;p&&p.classList.remove("selected");p?(p=a?p.nextSibling:p.previousSibling)||(p=b):p=a?g.childNodes[0]:g.childNodes[g.childNodes.length];p&&(p.classList.add("selected"),p.scrollIntoView())}function f(){function a(e,c){var f=document.createElement("div");s||(s=e);f.innerText=e;f.dataset.type=escape(e);f.className="litegraph lite-search-item";c&&(f.className+=" "+c);f.addEventListener("click",function(a){b(unescape(this.dataset.type))});
|
|
g.appendChild(f)}k=null;var e=C.value;s=null;g.innerHTML="";if(e)if(h.onSearchBox){var p=h.onSearchBox(help,e,D);if(p)for(var d=0;d<p.length;++d)a(p[d])}else{p=0;e=e.toLowerCase();for(d in c.searchbox_extras){var n=c.searchbox_extras[d];if(-1!==n.desc.toLowerCase().indexOf(e)&&(a(n.desc,"searchbox_extra"),-1!==m.search_limit&&p++>m.search_limit))break}if(Array.prototype.filter)for(n=Object.keys(c.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(e)}),d=0;d<n.length&&!(a(n[d]),
|
|
-1!==m.search_limit&&p++>m.search_limit);d++);else for(d in c.registered_node_types)if(-1!=d.indexOf(e)&&(a(d),-1!==m.search_limit&&p++>m.search_limit))break}}var h=this,d=document.createElement("div");d.className="litegraph litesearchbox graphdialog rounded";d.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";d.close=function(){h.search_box=null;document.body.focus();setTimeout(function(){h.canvas.focus()},20);d.parentNode&&
|
|
d.parentNode.removeChild(d)};var n=null;1<this.ds.scale&&(d.style.transform="scale("+this.ds.scale+")");d.addEventListener("mouseenter",function(a){n&&(clearTimeout(n),n=null)});d.addEventListener("mouseleave",function(a){n=setTimeout(function(){d.close()},500)});h.search_box&&h.search_box.close();h.search_box=d;var g=d.querySelector(".helper"),s=null,k=null,p=null,C=d.querySelector("input");C&&(C.addEventListener("blur",function(a){this.focus()}),C.addEventListener("keydown",function(a){if(38==a.keyCode)e(!1);
|
|
else if(40==a.keyCode)e(!0);else if(27==a.keyCode)d.close();else if(13==a.keyCode)p?b(p.innerHTML):s?b(s):d.close();else{k&&clearInterval(k);k=setTimeout(f,10);return}a.preventDefault();a.stopPropagation()}));var D=m.active_canvas,E=D.canvas,q=E.getBoundingClientRect(),A=-20,v=-20;q&&(A-=q.left,v-=q.top);a?(d.style.left=a.clientX+A+"px",d.style.top=a.clientY+v+"px"):(d.style.left=0.5*E.width+A+"px",d.style.top=0.5*E.height+v+"px");E.parentNode.appendChild(d);C.focus();return d};m.prototype.showEditPropertyValue=
|
|
function(a,b,e){function f(){c(C.value)}function c(e){"number"==typeof a.properties[b]&&(e=Number(e));"array"==d&&(e=e.split(",").map(Number));a.properties[b]=e;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,e);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){e=e||{};var d="string";null!==a.properties[b]&&(d=typeof a.properties[b]);"object"==d&&a.properties[b].length&&(d="array");var h=null;a.getPropertyInfo&&(h=a.getPropertyInfo(b));if(a.properties_info)for(var n=
|
|
0;n<a.properties_info.length;++n)if(a.properties_info[n].name==b){h=a.properties_info[n];break}void 0!==h&&null!==h&&h.type&&(d=h.type);var g="";if("string"==d||"number"==d||"array"==d)g="<input autofocus type='text' class='value'/>";else if("enum"==d&&h.values){g="<select autofocus type='text' class='value'>";for(n in h.values)var m=h.values.constructor===Array?h.values[n]:n,g=g+("<option value='"+m+"' "+(m==a.properties[b]?"selected":"")+">"+h.values[n]+"</option>");g+="</select>"}else if("boolean"==
|
|
d)g="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+d);return}var p=this.createDialog("<span class='name'>"+b+"</span>"+g+"<button>OK</button>",e);if("enum"==d&&h.values){var C=p.querySelector("select");C.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==d)(C=p.querySelector("input"))&&C.addEventListener("click",function(a){c(!!C.checked)});else if(C=p.querySelector("input"))C.addEventListener("blur",
|
|
function(a){this.focus()}),C.value=void 0!==a.properties[b]?a.properties[b]:"",C.addEventListener("keydown",function(a){13==a.keyCode&&(f(),a.preventDefault(),a.stopPropagation())});p.querySelector("button").addEventListener("click",f)}};m.prototype.createDialog=function(a,b){b=b||{};var e=document.createElement("div");e.className="graphdialog";e.innerHTML=a;var f=this.canvas.getBoundingClientRect(),c=-20,d=-20;f&&(c-=f.left,d-=f.top);b.position?(c+=b.position[0],d+=b.position[1]):b.event?(c+=b.event.clientX,
|
|
d+=b.event.clientY):(c+=0.5*this.canvas.width,d+=0.5*this.canvas.height);e.style.left=c+"px";e.style.top=d+"px";this.canvas.parentNode.appendChild(e);e.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return e};m.onMenuNodeCollapse=function(a,b,e,c,f){f.collapse()};m.onMenuNodePin=function(a,b,e,c,f){f.pin()};m.onMenuNodeMode=function(a,b,e,f,d){new c.ContextMenu(["Always","On Event","On Trigger","Never"],{event:e,callback:function(a){if(d)switch(a){case "On Event":d.mode=c.ON_EVENT;
|
|
break;case "On Trigger":d.mode=c.ON_TRIGGER;break;case "Never":d.mode=c.NEVER;break;default:d.mode=c.ALWAYS}},parentMenu:f,node:d});return!1};m.onMenuNodeColors=function(a,b,e,f,d){if(!d)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var h in m.node_colors)a=m.node_colors[h],a={value:h,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+
|
|
"'>"+h+"</span>"},b.push(a);new c.ContextMenu(b,{event:e,callback:function(a){d&&((a=a.value?m.node_colors[a.value]:null)?d.constructor===c.LGraphGroup?d.color=a.groupcolor:(d.color=a.color,d.bgcolor=a.bgcolor):(delete d.color,delete d.bgcolor),d.setDirtyCanvas(!0,!0))},parentMenu:f,node:d});return!1};m.onMenuNodeShapes=function(a,b,e,f,d){if(!d)throw"no node passed";new c.ContextMenu(c.VALID_SHAPES,{event:e,callback:function(a){d&&(d.shape=a,d.setDirtyCanvas(!0))},parentMenu:f,node:d});return!1};
|
|
m.onMenuNodeRemove=function(a,b,e,f,c){if(!c)throw"no node passed";!1!==c.removable&&(c.graph.remove(c),c.setDirtyCanvas(!0,!0))};m.onMenuNodeClone=function(a,b,e,f,c){!1!=c.clonable&&(a=c.clone())&&(a.pos=[c.pos[0]+5,c.pos[1]+5],c.graph.add(a),c.setDirtyCanvas(!0,!0))};m.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},
|
|
pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};m.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:m.onMenuAdd},{content:"Add Group",callback:m.onGroupAdd}],this._graph_stack&&
|
|
0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};m.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:m.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:m.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,
|
|
callback:m.onShowMenuNodeProperties},null,{content:"Title",callback:m.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:m.onMenuNodeMode},{content:"Resize",callback:m.onResizeNode},{content:"Collapse",callback:m.onMenuNodeCollapse},{content:"Pin",callback:m.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:m.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:m.onMenuNodeShapes},null];if(a.onGetInputs){var e=a.onGetInputs();e&&e.length&&(b[0].disabled=!1)}a.onGetOutputs&&
|
|
(e=a.onGetOutputs())&&e.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(e=a.getExtraMenuOptions(this))&&(e.push(null),b=e.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:m.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:m.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};m.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:m.onShowPropertyEditor},{content:"Color",has_submenu:!0,
|
|
callback:m.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:m.onShowPropertyEditor},null,{content:"Remove",callback:m.onMenuNodeRemove}]};m.prototype.processContextMenu=function(a,b){var e=this,f=m.active_canvas.getCanvasWindow(),d=null,h={event:b,callback:function(b,c,f){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 p=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),d=e.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",c),h=d.querySelector("input");h&&p&&(h.value=p.label||"");d.querySelector("button").addEventListener("click",function(a){h.value&&(p&&(p.label=h.value),e.setDirty(!0));d.close()})}},extra:a},n=null;a&&(n=a.getSlotInPosition(b.canvasX,b.canvasY),m.active_node=a);n?(d=[],n&&
|
|
n.output&&n.output.links&&n.output.links.length&&d.push({content:"Disconnect Links",slot:n}),d.push(n.locked?"Cannot remove":{content:"Remove Slot",slot:n}),d.push(n.nameLocked?"Cannot rename":{content:"Rename Slot",slot:n}),h.title=(n.input?n.input.type:n.output.type)||"*",n.input&&n.input.type==c.ACTION&&(h.title="Action"),n.output&&n.output.type==c.EVENT&&(h.title="Event")):a?d=this.getNodeMenuOptions(a):(d=this.getCanvasMenuOptions(),(n=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&d.push(null,
|
|
{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:n,options:this.getGroupMenuOptions(n)}}));d&&new c.ContextMenu(d,h,f)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,e,c,f,d){void 0===f&&(f=5);void 0===d&&(d=f);this.moveTo(a+f,b);this.lineTo(a+e-f,b);this.quadraticCurveTo(a+e,b,a+e,b+f);this.lineTo(a+e,b+c-d);this.quadraticCurveTo(a+e,b+c,a+e-d,b+c);this.lineTo(a+d,b+c);this.quadraticCurveTo(a,b+c,a,b+c-d);this.lineTo(a,b+f);this.quadraticCurveTo(a,
|
|
b,a+f,b)});c.compareObjects=function(a,b){for(var e in a)if(a[e]!=b[e])return!1;return!0};c.distance=w;c.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")+")"};c.isInsideRectangle=B;c.growBounding=function(a,b,e){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);e<a[1]?a[1]=e:e>a[3]&&(a[3]=e)};c.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?
|
|
!1:!0};c.overlapBounding=z;c.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),e=0,c,f,d=0;6>d;d+=2)c="0123456789ABCDEF".indexOf(a.charAt(d)),f="0123456789ABCDEF".indexOf(a.charAt(d+1)),b[e]=16*c+f,e++;return b};c.num2hex=function(a){for(var b="#",e,c,f=0;3>f;f++)e=a[f]/16,c=a[f]%16,b+="0123456789ABCDEF".charAt(e)+"0123456789ABCDEF".charAt(c);return b};y.prototype.addItem=function(a,b,e){function c(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=
|
|
this.value,c=!0;d.current_submenu&&d.current_submenu.close(a);if(e.callback){var h=e.callback.call(this,b,e,a,d,e.node);!0===h&&(c=!1)}if(b&&(b.callback&&!e.ignore_item_callbacks&&!0!==b.disabled&&(h=b.callback.call(this,b,e,a,d,e.extra),!0===h&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new d.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:d,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,
|
|
autoopen:e.autoopen});c=!1}c&&!d.lock&&d.close()}var d=this;e=e||{};var h=document.createElement("div");h.className="litemenu-entry submenu";var n=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(n=!0,h.classList.add("disabled")),(b.submenu||b.has_submenu)&&h.classList.add("has_submenu");"function"==typeof b?(h.dataset.value=a,h.onclick_callback=b):h.dataset.value=b;b.className&&(h.className+=" "+b.className)}this.root.appendChild(h);n||h.addEventListener("click",
|
|
f);e.autoopen&&h.addEventListener("mouseenter",c);return h};y.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&&!y.isCursorOverElement(a,this.parentMenu.root)&&y.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};y.trigger=
|
|
function(a,b,e,c){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,e);f.srcElement=c;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};y.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};y.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};y.isCursorOverElement=function(a,b){var e=a.clientX,c=a.clientY,f=b.getBoundingClientRect();
|
|
return f?c>f.top&&c<f.top+f.height&&e>f.left&&e<f.left+f.width?!0:!1:!1};c.ContextMenu=y;c.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],e=0;e<a.length;e++)b.push(a[e]);for(e in b)b[e].close?b[e].close():b[e].parentNode&&b[e].parentNode.removeChild(b[e])}};c.extendClass=function(a,b){for(var e in b)a.hasOwnProperty(e)||(a[e]=b[e]);if(b.prototype)for(e in b.prototype)b.prototype.hasOwnProperty(e)&&!a.prototype.hasOwnProperty(e)&&
|
|
(b.prototype.__lookupGetter__(e)?a.prototype.__defineGetter__(e,b.prototype.__lookupGetter__(e)):a.prototype[e]=b.prototype[e],b.prototype.__lookupSetter__(e)&&a.prototype.__defineSetter__(e,b.prototype.__lookupSetter__(e)))};c.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/mg,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,e){return b>a?b:e<a?e:a};"undefined"==
|
|
typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
|
(function(u){function d(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function k(){this.size=[140,80];this.properties={enabled:!0};this.addInput("enabled","boolean");this.subgraph=new LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);this.subgraph.onInputRemoved=
|
|
this.onSubgraphRemovedInput.bind(this);this.subgraph.onOutputAdded=this.onSubgraphNewOutput.bind(this);this.subgraph.onOutputRenamed=this.onSubgraphRenamedOutput.bind(this);this.subgraph.onOutputTypeChanged=this.onSubgraphTypeChangeOutput.bind(this);this.subgraph.onOutputRemoved=this.onSubgraphRemovedOutput.bind(this)}function q(){this.addOutput("","");this.name_in_graph="";this.properties={};var f=this;Object.defineProperty(this.properties,"name",{get:function(){return f.name_in_graph},set:function(c){""!=
|
|
c&&c!=f.name_in_graph&&"enabled"!=c&&(f.name_in_graph?f.graph.renameInput(f.name_in_graph,c):f.graph.addInput(c,f.properties.type),f.name_widget.value=c,f.name_in_graph=c)},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return f.outputs[0].type},set:function(c){f.outputs[0].type=c;f.name_in_graph&&f.graph.changeInputType(f.name_in_graph,f.outputs[0].type);f.type_widget.value=c},enumerable:!0});this.name_widget=this.addWidget("text","Name",this.properties.name,function(c){c&&
|
|
(f.properties.name=c)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(c){f.properties.type=c||""});this.widgets_up=!0;this.size=[180,60]}function g(){this.addInput("","");this.name_in_graph="";this.properties={};var c=this;Object.defineProperty(this.properties,"name",{get:function(){return c.name_in_graph},set:function(d){""!=d&&d!=c.name_in_graph&&(c.name_in_graph?c.graph.renameOutput(c.name_in_graph,d):c.graph.addOutput(d,c.properties.type),c.name_widget.value=d,c.name_in_graph=
|
|
d)},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return c.inputs[0].type},set:function(d){c.inputs[0].type=d;c.name_in_graph&&c.graph.changeOutputType(c.name_in_graph,c.inputs[0].type);c.type_widget.value=d||""},enumerable:!0});this.name_widget=this.addWidget("text","Name",this.properties.name,function(d){d&&(c.properties.name=d)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(d){c.properties.type=d||""});this.widgets_up=!0;this.size=[180,
|
|
60]}function r(){this.addOutput("value","number");this.addProperty("value",1)}function m(){this.addOutput("","string");this.addProperty("value","");this.widget=this.addWidget("text","value","",this.setValue.bind(this));this.widgets_up=!0;this.size=[100,30]}function w(){this.addOutput("","");this.addProperty("value","");this.widget=this.addWidget("text","json","",this.setValue.bind(this));this.widgets_up=!0;this.size=[140,30];this._value=null}function B(){this.addInput("obj","");this.addOutput("",
|
|
"");this.addProperty("value","");this.widget=this.addWidget("text","prop.","",this.setValue.bind(this));this.widgets_up=!0;this.size=[140,30];this._value=null}function z(){this.size=[60,20];this.addInput("value",0,{label:""});this.value=0}function y(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,20]}function c(){this.mode=n.ON_EVENT;this.size=[60,20];this.addProperty("msg","");this.addInput("log",n.EVENT);this.addInput("msg",0)}function x(){this.size=[60,20];this.addProperty("onExecute",
|
|
"return A;");this.addInput("A","");this.addInput("B","");this.addOutput("out","");this._func=null;this.data={}}var n=u.LiteGraph;d.title="Time";d.desc="Time";d.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};n.registerNodeType("basic/time",d);k.title="Subgraph";k.desc="Graph inside a node";k.title_color="#334";k.prototype.onDrawTitle=function(c){if(!this.flags.collapsed){c.fillStyle="#555";var d=n.NODE_TITLE_HEIGHT,h=this.size[0]-
|
|
d;c.fillRect(h,-d,d,d);c.fillStyle="#333";c.beginPath();c.moveTo(h+0.2*d,0.6*-d);c.lineTo(h+0.8*d,0.6*-d);c.lineTo(h+0.5*d,0.3*-d);c.fill()}};k.prototype.onDblClick=function(c,d,h){var n=this;setTimeout(function(){h.openSubgraph(n.subgraph)},10)};k.prototype.onMouseDown=function(c,d,h){if(!this.flags.collapsed&&d[0]>this.size[0]-n.NODE_TITLE_HEIGHT&&0>d[1]){var g=this;setTimeout(function(){h.openSubgraph(g.subgraph)},10)}};k.prototype.onExecute=function(){if(this.getInputOrProperty("enabled")){if(this.inputs)for(var c=
|
|
0;c<this.inputs.length;c++){var d=this.inputs[c],h=this.getInputData(c);this.subgraph.setInputData(d.name,h)}this.subgraph.runStep();if(this.outputs)for(c=0;c<this.outputs.length;c++)h=this.subgraph.getOutputData(this.outputs[c].name),this.setOutputData(c,h)}};k.prototype.onSubgraphNewInput=function(c,d){-1==this.findInputSlot(c)&&this.addInput(c,d)};k.prototype.onSubgraphRenamedInput=function(c,d){var h=this.findInputSlot(c);-1!=h&&(this.getInputInfo(h).name=d)};k.prototype.onSubgraphTypeChangeInput=
|
|
function(c,d){var h=this.findInputSlot(c);-1!=h&&(this.getInputInfo(h).type=d)};k.prototype.onSubgraphRemovedInput=function(c){c=this.findInputSlot(c);-1!=c&&this.removeInput(c)};k.prototype.onSubgraphNewOutput=function(c,d){-1==this.findOutputSlot(c)&&this.addOutput(c,d)};k.prototype.onSubgraphRenamedOutput=function(c,d){var h=this.findOutputSlot(c);-1!=h&&(this.getOutputInfo(h).name=d)};k.prototype.onSubgraphTypeChangeOutput=function(c,d){var h=this.findOutputSlot(c);-1!=h&&(this.getOutputInfo(h).type=
|
|
d)};k.prototype.onSubgraphRemovedOutput=function(c){c=this.findInputSlot(c);-1!=c&&this.removeOutput(c)};k.prototype.getExtraMenuOptions=function(c){var d=this;return[{content:"Open",callback:function(){c.openSubgraph(d.subgraph)}}]};k.prototype.onResize=function(c){c[1]+=20};k.prototype.serialize=function(){var c=LGraphNode.prototype.serialize.call(this);c.subgraph=this.subgraph.serialize();return c};k.prototype.clone=function(){var c=n.createNode(this.type),d=this.serialize();delete d.id;delete d.inputs;
|
|
delete d.outputs;c.configure(d);return c};n.registerNodeType("graph/subgraph",k);q.title="Input";q.desc="Input of the graph";q.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};q.prototype.onExecute=function(){var c=this.graph.inputs[this.properties.name];c&&this.setOutputData(0,c.value)};q.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeInput(this.name_in_graph)};n.registerNodeType("graph/input",q);g.title="Output";g.desc="Output of the graph";
|
|
g.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setOutputData(this.properties.name,this._value)};g.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeOutput(this.name_in_graph)};g.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};n.registerNodeType("graph/output",g);r.title="Const Number";r.desc="Constant number";r.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};r.prototype.getTitle=
|
|
function(){return this.flags.collapsed?this.properties.value:this.title};r.prototype.setValue=function(c){this.properties.value=c};r.prototype.onDrawBackground=function(c){this.outputs[0].label=this.properties.value.toFixed(3)};n.registerNodeType("basic/const",r);m.title="Const String";m.desc="Constant string";m.prototype.setValue=function(c){this.properties.value=c};m.prototype.onPropertyChanged=function(c,d){this.widget.value=d};m.prototype.getTitle=r.prototype.getTitle;m.prototype.onExecute=function(){this.setOutputData(0,
|
|
this.properties.value)};n.registerNodeType("basic/string",m);w.title="Const Data";w.desc="Constant Data";w.prototype.setValue=function(c){this.properties.value=c;this.onPropertyChanged("value",c)};w.prototype.onPropertyChanged=function(c,d){this.widget.value=d;if(null!=d&&""!=d)try{this._value=JSON.parse(d),this.boxcolor="#AEA"}catch(h){this.boxcolor="red"}};w.prototype.onExecute=function(){this.setOutputData(0,this._value)};n.registerNodeType("basic/data",w);B.title="Object property";B.desc="Outputs the property of an object";
|
|
B.prototype.setValue=function(c){this.properties.value=c;this.widget.value=c};B.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};B.prototype.onPropertyChanged=function(c,d){this.widget.value=d};B.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&this.setOutputData(0,c[this.properties.value])};n.registerNodeType("basic/object_property",B);z.title="Watch";z.desc="Show value of input";z.prototype.onExecute=function(){this.inputs[0]&&(this.value=
|
|
this.getInputData(0))};z.prototype.getTitle=function(){return this.flags.collapsed?this.inputs[0].label:this.title};z.toString=function(c){if(null==c)return"null";if(c.constructor===Number)return c.toFixed(3);if(c.constructor===Array){for(var d="[",h=0;h<c.length;++h)d+=z.toString(c[h])+(h+1!=c.length?",":"");return d+"]"}return String(c)};z.prototype.onDrawBackground=function(c){this.inputs[0].label=z.toString(this.value)};n.registerNodeType("basic/watch",z);y.title="Cast";y.desc="Allows to connect different types";
|
|
y.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};n.registerNodeType("basic/cast",y);c.title="Console";c.desc="Show value inside the console";c.prototype.onAction=function(c,d){"log"==c?console.log(d):"warn"==c?console.warn(d):"error"==c&&console.error(d)};c.prototype.onExecute=function(){var c=this.getInputData(1);null!==c&&(this.properties.msg=c);console.log(c)};c.prototype.onGetInputs=function(){return[["log",n.ACTION],["warn",n.ACTION],["error",n.ACTION]]};n.registerNodeType("basic/console",
|
|
c);x.prototype.onConfigure=function(c){c.properties.onExecute&&this.compileCode(c.properties.onExecute)};x.title="Script";x.desc="executes a code (max 100 characters)";x.widgets_info={onExecute:{type:"code"}};x.prototype.onPropertyChanged=function(c,d){"onExecute"==c&&n.allow_scripts&&this.compileCode(d)};x.prototype.compileCode=function(c){this._func=null;if(100<c.length)console.warn("Script too long, max 100 chars");else{for(var d=c.toLowerCase(),h="script body document eval nodescript function".split(" "),
|
|
n=0;n<h.length;++n)if(-1!=d.indexOf(h[n])){console.warn("invalid script");return}try{this._func=new Function("A","B","C","DATA","node",c)}catch(g){console.error("Error parsing script"),console.error(g)}}};x.prototype.onExecute=function(){if(this._func)try{var c=this.getInputData(0),d=this.getInputData(1),h=this.getInputData(2);this.setOutputData(0,this._func(c,d,h,this.data,this))}catch(n){console.error("Error in script"),console.error(n)}};x.prototype.onGetOutputs=function(){return[["C",""]]};n.registerNodeType("basic/script",
|
|
x)})(this);
|
|
(function(u){function d(){this.size=[60,20];this.addInput("event",w.ACTION)}function k(){this.addInput("",w.ACTION);this.addInput("",w.ACTION);this.addInput("",w.ACTION);this.addInput("",w.ACTION);this.addInput("",w.ACTION);this.addInput("",w.ACTION);this.addOutput("",w.EVENT);this.addOutput("",w.EVENT);this.addOutput("",w.EVENT);this.addOutput("",w.EVENT);this.addOutput("",w.EVENT);this.addOutput("",w.EVENT);this.size=[120,30];this.flags={horizontal:!0,render_box:!1}}function q(){this.size=[60,20];
|
|
this.addInput("event",w.ACTION);this.addOutput("event",w.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function g(){this.addInput("inc",w.ACTION);this.addInput("dec",w.ACTION);this.addInput("reset",w.ACTION);this.addOutput("change",w.EVENT);this.addOutput("num","number");this.num=0}function r(){this.size=[60,20];this.addProperty("time_in_ms",1E3);this.addInput("event",w.ACTION);this.addOutput("on_time",w.EVENT);this._pending=[]}function m(){this.addProperty("interval",
|
|
1E3);this.addProperty("event","tick");this.addOutput("on_tick",w.EVENT);this.time=0;this.last_interval=1E3;this.triggered=!1}var w=u.LiteGraph;d.title="Log Event";d.desc="Log event in console";d.prototype.onAction=function(d,g){console.log(d,g)};w.registerNodeType("events/log",d);k.title="Sequencer";k.desc="Trigger events when an event arrives";k.prototype.getTitle=function(){return""};k.prototype.onAction=function(d,g){if(this.outputs)for(var m=0;m<this.outputs.length;++m)this.triggerSlot(m,g)};
|
|
w.registerNodeType("events/sequencer",k);q.title="Filter Event";q.desc="Blocks events that do not match the filter";q.prototype.onAction=function(d,g){if(null!=g&&(!this.properties.equal_to||this.properties.equal_to==g)){if(this.properties.has_property){var m=g[this.properties.has_property];if(null==m||this.properties.property_equal_to&&this.properties.property_equal_to!=m)return}this.triggerSlot(0,g)}};w.registerNodeType("events/filter",q);g.title="Counter";g.desc="Counts events";g.prototype.onAction=
|
|
function(d,g){var m=this.num;"inc"==d?this.num+=1:"dec"==d?this.num-=1:"reset"==d&&(this.num=0);this.num!=m&&this.trigger("change",this.num)};g.prototype.onDrawBackground=function(d){this.flags.collapsed||(d.fillStyle="#AAA",d.font="20px Arial",d.textAlign="center",d.fillText(this.num,0.5*this.size[0],0.5*this.size[1]))};g.prototype.onExecute=function(){this.setOutputData(1,this.num)};w.registerNodeType("events/counter",g);r.title="Delay";r.desc="Delays one event";r.prototype.onAction=function(d,
|
|
g){var m=this.properties.time_in_ms;0>=m?this.trigger(null,g):this._pending.push([m,g])};r.prototype.onExecute=function(){var d=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var g=0;g<this._pending.length;++g){var m=this._pending[g];m[0]-=d;0<m[0]||(this._pending.splice(g,1),--g,this.trigger(null,m[1]))}};r.prototype.onGetInputs=function(){return[["event",w.ACTION],["time_in_ms","number"]]};w.registerNodeType("events/delay",r);m.title=
|
|
"Timer";m.desc="Sends an event every N milliseconds";m.prototype.onStart=function(){this.time=0};m.prototype.getTitle=function(){return"Timer: "+this.last_interval.toString()+"ms"};m.on_color="#AAA";m.off_color="#222";m.prototype.onDrawBackground=function(){this.boxcolor=this.triggered?m.on_color:m.off_color;this.triggered=!1};m.prototype.onExecute=function(){var d=0==this.time;this.time+=1E3*this.graph.elapsed_time;this.last_interval=Math.max(1,this.getInputOrProperty("interval")|0);!d&&(this.time<
|
|
this.last_interval||isNaN(this.last_interval))?this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!1):(this.triggered=!0,this.time%=this.last_interval,this.trigger("on_tick",this.properties.event),this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!0))};m.prototype.onGetInputs=function(){return[["interval","number"]]};m.prototype.onGetOutputs=function(){return[["tick","boolean"]]};w.registerNodeType("events/timer",m)})(this);
|
|
(function(u){function d(){this.addOutput("",y.EVENT);this.addProperty("text","click me");this.addProperty("font_size",30);this.addProperty("message","");this.size=[164,84]}function k(){this.addInput("","boolean");this.addInput("e",y.ACTION);this.addOutput("v","boolean");this.addOutput("e",y.EVENT);this.properties={font:"",value:!1};this.size=[160,44]}function q(){this.addOutput("","number");this.size=[74,54];this.properties={min:-1E3,max:1E3,value:1,step:1};this.old_y=-1;this._precision=this._remainder=
|
|
0;this.mouse_captured=!1}function g(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,color:"#7AF",precision:2};this.value=-1}function r(){this.addOutput("","number");this.properties={value:0.5,min:0,max:1,text:"V"};var c=this;this.size=[80,60];this.slider=this.addWidget("slider","V",this.properties.value,function(d){c.properties.value=d},this.properties)}function m(){this.size=[160,26];this.addOutput("","number");this.properties={color:"#7AF",min:0,max:1,value:0.5};
|
|
this.value=-1}function w(){this.size=[160,26];this.addInput("","number");this.properties={min:0,max:1,value:0,color:"#AAF"}}function B(){this.addInputs("",0);this.properties={value:"...",font:"Arial",fontsize:18,color:"#AAA",align:"left",glowSize:0,decimals:1}}function z(){this.size=[200,100];this.properties={borderColor:"#ffffff",bgcolorTop:"#f0f0f0",bgcolorBottom:"#e0e0e0",shadowSize:2,borderRadius:3}}var y=u.LiteGraph;d.title="Button";d.desc="Triggers an event";d.font="Arial";d.prototype.onDrawForeground=
|
|
function(c){if(!this.flags.collapsed&&(c.fillStyle="black",c.fillRect(11,11,this.size[0]-20,this.size[1]-20),c.fillStyle="#AAF",c.fillRect(9,9,this.size[0]-20,this.size[1]-20),c.fillStyle=this.clicked?"white":this.mouseOver?"#668":"#334",c.fillRect(10,10,this.size[0]-20,this.size[1]-20),this.properties.text||0===this.properties.text)){var g=this.properties.font_size||30;c.textAlign="center";c.fillStyle=this.clicked?"black":"white";c.font=g+"px "+d.font;c.fillText(this.properties.text,0.5*this.size[0],
|
|
0.5*this.size[1]+0.3*g);c.textAlign="left"}};d.prototype.onMouseDown=function(c,d){if(1<d[0]&&1<d[1]&&d[0]<this.size[0]-2&&d[1]<this.size[1]-2)return this.clicked=!0,this.trigger("clicked",this.properties.message),!0};d.prototype.onMouseUp=function(c){this.clicked=!1};y.registerNodeType("widget/button",d);k.title="Toggle";k.desc="Toggles between true or false";k.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var d=0.5*this.size[1],n=0.8*this.size[1];c.font=this.properties.font||
|
|
(0.8*d).toFixed(0)+"px Arial";var f=c.measureText(this.title).width,f=0.5*(this.size[0]-(f+d));c.fillStyle="#AAA";c.fillRect(f,n-d,d,d);c.fillStyle=this.properties.value?"#AEF":"#000";c.fillRect(f+0.25*d,n-d+0.25*d,0.5*d,0.5*d);c.textAlign="left";c.fillStyle="#AAA";c.fillText(this.title,1.2*d+f,0.85*n);c.textAlign="left"}};k.prototype.onAction=function(c){this.properties.value=!this.properties.value;this.trigger("e",this.properties.value)};k.prototype.onExecute=function(){var c=this.getInputData(0);
|
|
null!=c&&(this.properties.value=c);this.setOutputData(0,this.properties.value)};k.prototype.onMouseDown=function(c,d){if(1<d[0]&&1<d[1]&&d[0]<this.size[0]-2&&d[1]<this.size[1]-2)return this.properties.value=!this.properties.value,this.graph._version++,this.trigger("e",this.properties.value),!0};y.registerNodeType("widget/toggle",k);q.title="Number";q.desc="Widget to select number value";q.pixels_threshold=10;q.markers_color="#666";q.prototype.onDrawForeground=function(c){var d=0.5*this.size[0],n=
|
|
this.size[1];30<n?(c.fillStyle=q.markers_color,c.beginPath(),c.moveTo(d,0.1*n),c.lineTo(d+0.1*n,0.2*n),c.lineTo(d+-0.1*n,0.2*n),c.fill(),c.beginPath(),c.moveTo(d,0.9*n),c.lineTo(d+0.1*n,0.8*n),c.lineTo(d+-0.1*n,0.8*n),c.fill(),c.font=(0.7*n).toFixed(1)+"px Arial"):c.font=(0.8*n).toFixed(1)+"px Arial";c.textAlign="center";c.font=(0.7*n).toFixed(1)+"px Arial";c.fillStyle="#EEE";c.fillText(this.properties.value.toFixed(this._precision),d,0.75*n)};q.prototype.onExecute=function(){this.setOutputData(0,
|
|
this.properties.value)};q.prototype.onPropertyChanged=function(c,d){var n=(this.properties.step+"").split(".");this._precision=1<n.length?n[1].length:0};q.prototype.onMouseDown=function(c,d){if(!(0>d[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};q.prototype.onMouseMove=function(c){if(this.mouse_captured){var d=this.old_y-c.canvasY;c.shiftKey&&(d*=10);if(c.metaKey||c.altKey)d*=0.1;this.old_y=c.canvasY;c=this._remainder+d/q.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)}};q.prototype.onMouseUp=function(c,d){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(d[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))};y.registerNodeType("widget/number",q);g.title=
|
|
"Knob";g.desc="Circular controller";g.size=[80,100];g.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 d=0.5*this.size[0],n=0.5*this.size[1],f=0.5*Math.min(this.size[0],this.size[1])-5;c.globalAlpha=1;c.save();c.translate(d,n);c.rotate(0.75*Math.PI);c.fillStyle="rgba(0,0,0,0.5)";c.beginPath();c.moveTo(0,0);c.arc(0,0,f,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,f-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(d,n,0.75*f,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":this.properties.color;c.beginPath();var g=this.value*Math.PI*1.5+0.75*Math.PI;c.arc(d+Math.cos(g)*f*0.65,n+Math.sin(g)*f*0.65,0.05*f,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";
|
|
c.font=Math.floor(0.5*f)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision),d,n+0.15*f)}};g.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=y.colorToString([this.value,this.value,this.value])};g.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]||y.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};g.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var d=this.value,d=d-0.01*(c[1]-this.oldmouse[1]);1<d?d=1:0>d&&(d=0);this.value=d;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};g.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=
|
|
null,this.captureInput(!1))};g.prototype.onPropertyChanged=function(c,d){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(d),!0};y.registerNodeType("widget/knob",g);r.title="Internal Slider";r.prototype.onPropertyChanged=function(c,d){"value"==c&&(this.slider.value=d)};r.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};y.registerNodeType("widget/internal_slider",r);m.title="H.Slider";m.desc="Linear slider controller";m.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()};m.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=
|
|
y.colorToString([this.value,this.value,this.value])};m.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};m.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var d=this.value,d=d+(c[0]-this.oldmouse[0])/this.size[0];1<d?d=1:0>d&&(d=0);this.value=d;this.oldmouse=c;this.setDirtyCanvas(!0)}};m.prototype.onMouseUp=function(c){this.oldmouse=null;
|
|
this.captureInput(!1)};m.prototype.onMouseLeave=function(c){};y.registerNodeType("widget/hslider",m);w.title="Progress";w.desc="Shows data in linear progress";w.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};w.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.color;var d=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),d=Math.min(1,d),d=Math.max(0,d);c.fillRect(2,2,(this.size[0]-4)*
|
|
d,this.size[1]-4)};y.registerNodeType("widget/progress",w);B.title="Text";B.desc="Shows the input value";B.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];B.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var d=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 n=this.properties.fontsize;c.textAlign=this.properties.align;c.font=n.toString()+"px "+this.properties.font;this.str="number"==typeof d?d.toFixed(this.properties.decimals):d;if("string"==typeof this.str){var d=this.str.split("\\n"),f;for(f in d)c.fillText(d[f],"left"==this.properties.align?15:this.size[0]-15,-0.15*n+n*(parseInt(f)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};B.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&
|
|
(this.properties.value=c)};B.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 d=0,n;for(n in c){var f=this.last_ctx.measureText(c[n]).width;d<f&&(d=f)}this.size[0]=d+20;this.size[1]=4+c.length*this.properties.fontsize;this.setDirtyCanvas(!0)}};B.prototype.onPropertyChanged=function(c,d){this.properties[c]=d;this.str="number"==typeof d?d.toFixed(3):d;return!0};y.registerNodeType("widget/text",B);z.title=
|
|
"Panel";z.desc="Non interactive panel";z.widgets=[{name:"update",text:"Update",type:"button"}];z.prototype.createGradient=function(c){""==this.properties.bgcolorTop||""==this.properties.bgcolorBottom?this.lineargradient=0:(this.lineargradient=c.createLinearGradient(0,0,0,this.size[1]),this.lineargradient.addColorStop(0,this.properties.bgcolorTop),this.lineargradient.addColorStop(1,this.properties.bgcolorBottom))};z.prototype.onDrawForeground=function(c){null==this.lineargradient&&this.createGradient(c);
|
|
this.lineargradient&&(c.lineWidth=1,c.strokeStyle=this.properties.borderColor,c.fillStyle=this.lineargradient,this.properties.shadowSize?(c.shadowColor="#000",c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.shadowSize):c.shadowColor="transparent",c.roundRect(0,0,this.size[0]-1,this.size[1]-1,this.properties.shadowSize),c.fill(),c.shadowColor="transparent",c.stroke())};y.registerNodeType("widget/panel",z)})(this);
|
|
(function(u){function d(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",k.EVENT);this.properties={gamepad_index:0,threshold:0.1};this._left_axis=new Float32Array(2);this._right_axis=new Float32Array(2);this._triggers=new Float32Array(2);this._previous_buttons=new Uint8Array(17);this._current_buttons=new Uint8Array(17)}var k=u.LiteGraph;d.title="Gamepad";d.desc="gets the input of the gamepad";d.CENTER=0;d.LEFT=1;d.RIGHT=2;d.UP=4;d.DOWN=
|
|
8;d.zero=new Float32Array(2);d.buttons="a b x y lb rb lt rt back start ls rs home".split(" ");d.prototype.onExecute=function(){var k=this.getGamepad(),g=this.properties.threshold||0;k&&(this._left_axis[0]=Math.abs(k.xbox.axes.lx)>g?k.xbox.axes.lx:0,this._left_axis[1]=Math.abs(k.xbox.axes.ly)>g?k.xbox.axes.ly:0,this._right_axis[0]=Math.abs(k.xbox.axes.rx)>g?k.xbox.axes.rx:0,this._right_axis[1]=Math.abs(k.xbox.axes.ry)>g?k.xbox.axes.ry:0,this._triggers[0]=Math.abs(k.xbox.axes.ltrigger)>g?k.xbox.axes.ltrigger:
|
|
0,this._triggers[1]=Math.abs(k.xbox.axes.rtrigger)>g?k.xbox.axes.rtrigger:0);if(this.outputs)for(g=0;g<this.outputs.length;g++){var r=this.outputs[g];if(r.links&&r.links.length){var m=null;if(k)switch(r.name){case "left_axis":m=this._left_axis;break;case "right_axis":m=this._right_axis;break;case "left_x_axis":m=this._left_axis[0];break;case "left_y_axis":m=this._left_axis[1];break;case "right_x_axis":m=this._right_axis[0];break;case "right_y_axis":m=this._right_axis[1];break;case "trigger_left":m=
|
|
this._triggers[0];break;case "trigger_right":m=this._triggers[1];break;case "a_button":m=k.xbox.buttons.a?1:0;break;case "b_button":m=k.xbox.buttons.b?1:0;break;case "x_button":m=k.xbox.buttons.x?1:0;break;case "y_button":m=k.xbox.buttons.y?1:0;break;case "lb_button":m=k.xbox.buttons.lb?1:0;break;case "rb_button":m=k.xbox.buttons.rb?1:0;break;case "ls_button":m=k.xbox.buttons.ls?1:0;break;case "rs_button":m=k.xbox.buttons.rs?1:0;break;case "hat_left":m=k.xbox.hatmap&d.LEFT;break;case "hat_right":m=
|
|
k.xbox.hatmap&d.RIGHT;break;case "hat_up":m=k.xbox.hatmap&d.UP;break;case "hat_down":m=k.xbox.hatmap&d.DOWN;break;case "hat":m=k.xbox.hatmap;break;case "start_button":m=k.xbox.buttons.start?1:0;break;case "back_button":m=k.xbox.buttons.back?1:0;break;case "button_pressed":for(r=0;r<this._current_buttons.length;++r)this._current_buttons[r]&&!this._previous_buttons[r]&&this.triggerSlot(g,d.buttons[r])}else switch(r.name){case "button_pressed":break;case "left_axis":case "right_axis":m=d.zero;break;
|
|
default:m=0}this.setOutputData(g,m)}}};d.prototype.getGamepad=function(){var k=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!k)return null;var g=k.call(navigator),k=null;this._previous_buttons.set(this._current_buttons);for(k=this.properties.gamepad_index;4>k;k++)if(g[k]){k=g[k];g=this.xbox_mapping;g||(g=this.xbox_mapping={axes:[],buttons:{},hat:"",hatmap:d.CENTER});g.axes.lx=k.axes[0];g.axes.ly=k.axes[1];g.axes.rx=k.axes[2];g.axes.ry=k.axes[3];g.axes.ltrigger=k.buttons[6].value;
|
|
g.axes.rtrigger=k.buttons[7].value;g.hat="";g.hatmap=d.CENTER;for(var r=0;r<k.buttons.length;r++)switch(this._current_buttons[r]=k.buttons[r].pressed,r){case 0:g.buttons.a=k.buttons[r].pressed;break;case 1:g.buttons.b=k.buttons[r].pressed;break;case 2:g.buttons.x=k.buttons[r].pressed;break;case 3:g.buttons.y=k.buttons[r].pressed;break;case 4:g.buttons.lb=k.buttons[r].pressed;break;case 5:g.buttons.rb=k.buttons[r].pressed;break;case 6:g.buttons.lt=k.buttons[r].pressed;break;case 7:g.buttons.rt=k.buttons[r].pressed;
|
|
break;case 8:g.buttons.back=k.buttons[r].pressed;break;case 9:g.buttons.start=k.buttons[r].pressed;break;case 10:g.buttons.ls=k.buttons[r].pressed;break;case 11:g.buttons.rs=k.buttons[r].pressed;break;case 12:k.buttons[r].pressed&&(g.hat+="up",g.hatmap|=d.UP);break;case 13:k.buttons[r].pressed&&(g.hat+="down",g.hatmap|=d.DOWN);break;case 14:k.buttons[r].pressed&&(g.hat+="left",g.hatmap|=d.LEFT);break;case 15:k.buttons[r].pressed&&(g.hat+="right",g.hatmap|=d.RIGHT);break;case 16:g.buttons.home=k.buttons[r].pressed}k.xbox=
|
|
g;return k}};d.prototype.onDrawBackground=function(d){if(!this.flags.collapsed){var g=this._left_axis,k=this._right_axis;d.strokeStyle="#88A";d.strokeRect(0.5*(g[0]+1)*this.size[0]-4,0.5*(g[1]+1)*this.size[1]-4,8,8);d.strokeStyle="#8A8";d.strokeRect(0.5*(k[0]+1)*this.size[0]-4,0.5*(k[1]+1)*this.size[1]-4,8,8);g=this.size[1]/this._current_buttons.length;d.fillStyle="#AEB";for(k=0;k<this._current_buttons.length;++k)this._current_buttons[k]&&d.fillRect(0,g*k,6,g)}};d.prototype.onGetOutputs=function(){return[["left_axis",
|
|
"vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button","number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start_button","number"],["back_button","number"],["hat_left","number"],["hat_right","number"],["hat_up","number"],["hat_down","number"],
|
|
["hat","number"],["button_pressed",k.EVENT]]};k.registerNodeType("input/gamepad",d)})(this);
|
|
(function(u){function d(){this.addInput("in","*");this.size=[60,20]}function k(){this.addInput("in");this.addOutput("out");this.size=[60,20]}function q(){this.addInput("in");this.addOutput("out")}function g(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",1);this.size=[80,20]}function r(){this.addOutput("value","number");this.addProperty("min",
|
|
0);this.addProperty("max",1);this.size=[60,20]}function m(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("min",0);this.addProperty("max",1);this.addProperty("smooth",!0);this.size=[90,20]}function w(){this.addOutput("out","number");this.addProperty("min_time",1);this.addProperty("max_time",2);this.addProperty("duration",0.2);this.size=[90,20];this._blink_time=this._remaining_time=0}function B(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,
|
|
20];this.addProperty("min",0);this.addProperty("max",1)}function z(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function y(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function c(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function x(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function n(){this.addInput("in","number");this.addOutput("out",
|
|
"number");this.size=[80,30];this.properties={A:0,B:1}}function f(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function A(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function h(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",0.1);this.size=[80,30];this._value=
|
|
null}function s(){this.addInput("A","number");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","enum",{values:s.values})}function v(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function a(){this.addInput("A","number");this.addInput("B","number");this.addOutput("out","boolean");this.addProperty("A",
|
|
1);this.addProperty("B",1);this.addProperty("OP",">","string",{values: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 e(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function t(){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,e){e.properties.formula=a});this.addWidget("toggle","allow",p.allow_scripts,function(a){p.allow_scripts=a});this._func=null}function l(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function G(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function J(){this.addInput("vec3",
|
|
"vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function F(){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 H(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function I(){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 p=u.LiteGraph;d.title="Converter";d.desc="type A to type B";d.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var e=this.outputs[b];if(e.links&&e.links.length){var c=null;switch(e.name){case "number":c=a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":c=1;switch(e.name){case "vec2":c=2;break;case "vec3":c=3;
|
|
break;case "vec4":c=4}c=new Float32Array(c);if(a.length)for(e=0;e<a.length&&e<c.length;e++)c[e]=a[e];else c[0]=parseFloat(a)}this.setOutputData(b,c)}}};d.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};p.registerNodeType("math/converter",d);k.title="Bypass";k.desc="removes the type";k.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,a)};p.registerNodeType("math/bypass",k);q.title="to Number";q.desc="Cast to number";
|
|
q.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,Number(a))};p.registerNodeType("math/to_number",q);g.title="Range";g.desc="Convert a number from one range to another";g.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};g.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],e=this.getInputData(a);void 0!==e&&(this.properties[b.name]=e)}e=this.properties["in"];if(void 0===
|
|
e||null===e||e.constructor!==Number)e=0;a=this.properties.in_min;b=this.properties.out_min;this._last_v=(e-a)/(this.properties.in_max-a)*(this.properties.out_max-b)+b;this.setOutputData(0,this._last_v)};g.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};g.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};p.registerNodeType("math/range",g);r.title="Rand";r.desc="Random number";
|
|
r.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],e=this.getInputData(a);void 0!==e&&(this.properties[b.name]=e)}a=this.properties.min;b=this.properties.max;this._last_v=Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};r.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};r.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};p.registerNodeType("math/rand",r);m.title="Noise";
|
|
m.desc="Random number with temporal continuity";m.data=null;m.getValue=function(a,b){if(!m.data){m.data=new Float32Array(1024);for(var e=0;e<m.data.length;++e)m.data[e]=Math.random()}a%=1024;0>a&&(a+=1024);var c=Math.floor(a);a-=c;e=m.data[c];c=m.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return e*(1-a)+c*a};m.prototype.onExecute=function(){var a=this.getInputData(0)||0,a=m.getValue(a,this.properties.smooth),b=this.properties.min;this._last_v=a*(this.properties.max-b)+b;this.setOutputData(0,
|
|
this._last_v)};m.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};p.registerNodeType("math/noise",m);w.title="Spikes";w.desc="spike every random time";w.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0<this._blink_time&&(a=1/(Math.pow(this._blink_time/this.properties.duration*8-4,4)+1));0>this._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)};p.registerNodeType("math/spikes",w);B.title="Clamp";B.desc="Clamp number between min and max";B.filter="shader";B.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))};B.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+
|
|
","+this.properties.max+")");return a};p.registerNodeType("math/clamp",B);z.title="Lerp";z.desc="Linear Interpolation";z.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);null==b&&(b=0);var e=this.properties.f,c=this.getInputData(2);void 0!==c&&(e=c);this.setOutputData(0,a*(1-e)+b*e)};z.prototype.onGetInputs=function(){return[["f","number"]]};p.registerNodeType("math/lerp",z);y.title="Abs";y.desc="Absolute";y.prototype.onExecute=function(){var a=this.getInputData(0);
|
|
null!=a&&this.setOutputData(0,Math.abs(a))};p.registerNodeType("math/abs",y);c.title="Floor";c.desc="Floor number to remove fractional part";c.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};p.registerNodeType("math/floor",c);x.title="Frac";x.desc="Returns fractional part";x.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};p.registerNodeType("math/frac",x);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))}};p.registerNodeType("math/smoothstep",n);f.title="Scale";f.desc="v * factor";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};p.registerNodeType("math/scale",f);A.title="Average";A.desc="Average Filter";A.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 e=a=0;e<b;++e)a+=this._values[e];this.setOutputData(0,a/b)};A.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);var e=this._values;this._values=new Float32Array(this.properties.samples);e.length<=this._values.length?this._values.set(e):this._values.set(e.subarray(0,this._values.length))};p.registerNodeType("math/average",A);h.title=
|
|
"TendTo";h.desc="moves the output value always closer to the input";h.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)};p.registerNodeType("math/tendTo",h);s.values="+-*/%^".split("");s.title="Operation";s.desc="Easy math operators";s["@OP"]={type:"enum",title:"operation",values:s.values};s.size=[100,60];s.prototype.getTitle=function(){return"A "+this.properties.OP+
|
|
" B"};s.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};s.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 e=0;switch(this.properties.OP){case "+":e=a+b;break;case "-":e=a-b;break;case "x":case "X":case "*":e=a*b;break;case "/":e=a/b;break;case "%":e=a%b;break;case "^":e=Math.pow(a,b);break;default:console.warn("Unknown operation: "+
|
|
this.properties.OP)}this.setOutputData(0,e)};s.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]+p.NODE_TITLE_HEIGHT)),a.textAlign="left")};p.registerNodeType("math/operation",s);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 e=0,c=this.outputs.length;e<c;++e){var d=this.outputs[e];if(d.links&&d.links.length){switch(d.name){case "A==B":value=a==b;break;case "A!=B":value=a!=b;break;case "A>B":value=a>b;break;case "A<B":value=a<b;break;case "A<=B":value=a<=b;break;case "A>=B":value=a>=b}this.setOutputData(e,value)}}};v.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};
|
|
p.registerNodeType("math/compare",v);p.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});p.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});p.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});p.registerSearchboxExtra("math/compare","<",{outputs:[["A<B","boolean"]],title:"A<B"});p.registerSearchboxExtra("math/compare",">=",{outputs:[["A>=B","boolean"]],title:"A>=B"});p.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.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 e=!0;switch(this.properties.OP){case ">":e=a>b;break;case "<":e=a<b;break;case "==":e=a==b;break;case "!=":e=
|
|
a!=b;break;case "<=":e=a<=b;break;case ">=":e=a>=b}this.setOutputData(0,e)};p.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)};p.registerNodeType("math/accumulate",b);e.title="Trigonometry";
|
|
e.desc="Sin Cos Tan";e.filter="shader";e.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,e=this.findInputSlot("amplitude");-1!=e&&(b=this.getInputData(e));var c=this.properties.offset,e=this.findInputSlot("offset");-1!=e&&(c=this.getInputData(e));for(var e=0,d=this.outputs.length;e<d;++e){switch(this.outputs[e].name){case "sin":value=Math.sin(a);break;case "cos":value=Math.cos(a);break;case "tan":value=Math.tan(a);break;case "asin":value=Math.asin(a);
|
|
break;case "acos":value=Math.acos(a);break;case "atan":value=Math.atan(a)}this.setOutputData(e,b*value+c)}};e.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};e.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};p.registerNodeType("math/trigonometry",e);p.registerSearchboxExtra("math/trigonometry","SIN()",{outputs:[["sin","number"]],title:"SIN()"});p.registerSearchboxExtra("math/trigonometry",
|
|
"COS()",{outputs:[["cos","number"]],title:"COS()"});p.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});t.title="Formula";t.desc="Compute formula";t.size=[160,100];A.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};t.prototype.onExecute=function(){if(p.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 e;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),e=this._func(a,b,this.graph.globaltime),this.boxcolor=null}catch(c){this.boxcolor="red"}this.setOutputData(0,e)}};t.prototype.getTitle=function(){return this._func_code||"Formula"};t.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};p.registerNodeType("math/formula",
|
|
t);l.title="Vec2->XY";l.desc="vector 2 to components";l.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};p.registerNodeType("math3d/vec2-to-xyz",l);G.title="XY->Vec2";G.desc="components to vector2";G.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 e=this._data;e[0]=a;e[1]=b;this.setOutputData(0,e)};p.registerNodeType("math3d/xy-to-vec2",
|
|
G);J.title="Vec3->XYZ";J.desc="vector 3 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]))};p.registerNodeType("math3d/vec3-to-xyz",J);F.title="XYZ->Vec3";F.desc="components to vector3";F.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 e=this.getInputData(2);null==e&&(e=this.properties.z);
|
|
var c=this._data;c[0]=a;c[1]=b;c[2]=e;this.setOutputData(0,c)};p.registerNodeType("math3d/xyz-to-vec3",F);H.title="Vec4->XYZW";H.desc="vector 4 to components";H.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]))};p.registerNodeType("math3d/vec4-to-xyzw",H);I.title="XYZW->Vec4";I.desc="components to vector4";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 e=this.getInputData(2);null==e&&(e=this.properties.z);var c=this.getInputData(3);null==c&&(c=this.properties.w);var d=this._data;d[0]=a;d[1]=b;d[2]=e;d[3]=c;this.setOutputData(0,d)};p.registerNodeType("math3d/xyzw-to-vec4",I);u.glMatrix&&(u=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},u.title="Quaternion",u.desc="quaternion",u.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)},p.registerNodeType("math3d/quaternion",u),u=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()},u.title="Rotation",u.desc="quaternion rotation",u.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)},p.registerNodeType("math3d/rotation",u),u=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},u.title="Rot. Vec3",u.desc="rotate a point",u.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))},p.registerNodeType("math3d/rotate_vec3",u),u=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},u.title="Mult. Quat",u.desc="rotate quaternion",u.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))}},p.registerNodeType("math3d/mult-quat",u),u=function(){this.addInputs([["A","quat"],["B",
|
|
"quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},u.title="Quat Slerp",u.desc="quaternion spherical interpolation",u.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);if(null!=b){var e=this.properties.factor;null!=this.getInputData(2)&&(e=this.getInputData(2));a=quat.slerp(this._value,a,b,e);this.setOutputData(0,a)}}},p.registerNodeType("math3d/quat-slerp",u))})(this);
|
|
(function(u){function d(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function k(){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 g(){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 r(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function m(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}function w(){this.addInput("in","vec3");this.addInput("f","number");this.addOutput("out","vec3");this.properties=
|
|
{f:1};this._data=new Float32Array(3)}function B(){this.addInput("in","vec3");this.addOutput("out","number")}function z(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function y(){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 x=u.LiteGraph;d.title=
|
|
"Vec2->XY";d.desc="vector 2 to components";d.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.setOutputData(0,c[0]),this.setOutputData(1,c[1]))};x.registerNodeType("math3d/vec2-to-xyz",d);k.title="XY->Vec2";k.desc="components to vector2";k.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.x);var d=this.getInputData(1);null==d&&(d=this.properties.y);var g=this._data;g[0]=c;g[1]=d;this.setOutputData(0,g)};x.registerNodeType("math3d/xy-to-vec2",
|
|
k);q.title="Vec3->XYZ";q.desc="vector 3 to components";q.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.setOutputData(0,c[0]),this.setOutputData(1,c[1]),this.setOutputData(2,c[2]))};x.registerNodeType("math3d/vec3-to-xyz",q);g.title="XYZ->Vec3";g.desc="components to vector3";g.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.x);var d=this.getInputData(1);null==d&&(d=this.properties.y);var g=this.getInputData(2);null==g&&(g=this.properties.z);
|
|
var h=this._data;h[0]=c;h[1]=d;h[2]=g;this.setOutputData(0,h)};x.registerNodeType("math3d/xyz-to-vec3",g);r.title="Vec4->XYZW";r.desc="vector 4 to components";r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.setOutputData(0,c[0]),this.setOutputData(1,c[1]),this.setOutputData(2,c[2]),this.setOutputData(3,c[3]))};x.registerNodeType("math3d/vec4-to-xyzw",r);m.title="XYZW->Vec4";m.desc="components to vector4";m.prototype.onExecute=function(){var c=this.getInputData(0);null==
|
|
c&&(c=this.properties.x);var d=this.getInputData(1);null==d&&(d=this.properties.y);var g=this.getInputData(2);null==g&&(g=this.properties.z);var h=this.getInputData(3);null==h&&(h=this.properties.w);var m=this._data;m[0]=c;m[1]=d;m[2]=g;m[3]=h;this.setOutputData(0,m)};x.registerNodeType("math3d/xyzw-to-vec4",m);w.title="vec3_scale";w.desc="scales the components of a vec3";w.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);null==d&&(d=this.properties.f);
|
|
var g=this._data;g[0]=c[0]*d;g[1]=c[1]*d;g[2]=c[2]*d;this.setOutputData(0,g)}};x.registerNodeType("math3d/vec3-scale",w);B.title="vec3_length";B.desc="returns the module of a vector";B.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))};x.registerNodeType("math3d/vec3-length",B);z.title="vec3_normalize";z.desc="returns the vector normalized";z.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=
|
|
Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),g=this._data;g[0]=c[0]/d;g[1]=c[1]/d;g[2]=c[2]/d;this.setOutputData(0,g)}};x.registerNodeType("math3d/vec3-normalize",z);y.title="vec3_lerp";y.desc="returns the interpolated vector";y.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);if(null!=d){var g=this.getInputOrProperty("f"),h=this._data;h[0]=c[0]*(1-g)+d[0]*g;h[1]=c[1]*(1-g)+d[1]*g;h[2]=c[2]*(1-g)+d[2]*g;this.setOutputData(0,h)}}};x.registerNodeType("math3d/vec3-lerp",
|
|
y);c.title="vec3_dot";c.desc="returns the dot product";c.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);null!=d&&this.setOutputData(0,c[0]*d[0]+c[1]*d[1]+c[2]*d[2])}};x.registerNodeType("math3d/vec3-dot",c);u.glMatrix&&(u=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},u.title="Quaternion",u.desc="quaternion",u.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)},x.registerNodeType("math3d/quaternion",u),u=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()},u.title="Rotation",u.desc="quaternion rotation",u.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.angle);var d=this.getInputData(1);null==d&&
|
|
(d=this.properties.axis);c=quat.setAxisAngle(this._value,d,0.0174532925*c);this.setOutputData(0,c)},x.registerNodeType("math3d/rotation",u),u=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},u.title="Rot. Vec3",u.desc="rotate a point",u.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.vec);var d=this.getInputData(1);null==d?this.setOutputData(c):this.setOutputData(0,vec3.transformQuat(vec3.create(),
|
|
c,d))},x.registerNodeType("math3d/rotate_vec3",u),u=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},u.title="Mult. Quat",u.desc="rotate quaternion",u.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);null!=d&&(c=quat.multiply(this._value,c,d),this.setOutputData(0,c))}},x.registerNodeType("math3d/mult-quat",u),u=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp",
|
|
"quat");this.addProperty("factor",0.5);this._value=quat.create()},u.title="Quat Slerp",u.desc="quaternion spherical interpolation",u.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);if(null!=d){var g=this.properties.factor;null!=this.getInputData(2)&&(g=this.getInputData(2));c=quat.slerp(this._value,c,d,g);this.setOutputData(0,c)}}},x.registerNodeType("math3d/quat-slerp",u))})(this);
|
|
(function(u){function d(d,g){return d==g}function k(d){return null!=d&&d.constructor===String?d.toUpperCase():d}u=u.LiteGraph;u.wrapFunctionAsNode("string/toString",d,["*"],"String");u.wrapFunctionAsNode("string/compare",d,["String","String"],"Boolean");u.wrapFunctionAsNode("string/concatenate",function(d,g){return void 0===d?g:void 0===g?d:d+g},["String","String"],"String");u.wrapFunctionAsNode("string/contains",function(d,g){return void 0===d||void 0===g?!1:-1!=d.indexOf(g)},["String","String"],
|
|
"Boolean");u.wrapFunctionAsNode("string/toUpperCase",k,["String"],"String");u.wrapFunctionAsNode("string/split",k,["String","String"],"Array");u.wrapFunctionAsNode("string/toFixed",function(d){return null!=d&&d.constructor===Number?d.toFixed(this.properties.precision):d},["Number"],"String",{precision:0})})(this);
|
|
(function(u){function d(){this.addInput("sel","number");this.addInput("A");this.addInput("B");this.addInput("C");this.addInput("D");this.addOutput("out");this.selected=0}function k(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}var q=u.LiteGraph;d.title="Selector";d.desc="selects an output";d.prototype.onDrawBackground=function(d){if(!this.flags.collapsed){d.fillStyle="#AFB";
|
|
var k=(this.selected+1)*q.NODE_SLOT_HEIGHT+6;d.beginPath();d.moveTo(50,k);d.lineTo(50,k+q.NODE_SLOT_HEIGHT);d.lineTo(34,k+0.5*q.NODE_SLOT_HEIGHT);d.fill()}};d.prototype.onExecute=function(){var d=this.getInputData(0);null==d&&(d=0);this.selected=d=Math.round(d)%(this.inputs.length-1);d=this.getInputData(d+1);void 0!==d&&this.setOutputData(0,d)};d.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};q.registerNodeType("logic/selector",d);k.title="Sequence";k.desc="select one element from a sequence from a string";
|
|
k.prototype.onPropertyChanged=function(d,k){"sequence"==d&&(this.values=k.split(","))};k.prototype.onExecute=function(){var d=this.getInputData(1);d&&d!=this.current_sequence&&(this.values=d.split(","),this.current_sequence=d);d=this.getInputData(0);null==d&&(d=0);this.index=d=Math.round(d)%this.values.length;this.setOutputData(0,this.values[d])};q.registerNodeType("logic/sequence",k)})(this);
|
|
(function(u){function d(){this.addInput("A","Number");this.addInput("B","Number");this.addInput("C","Number");this.addInput("D","Number");this.values=[[],[],[],[]];this.properties={scale:2}}function k(){this.addOutput("frame","image");this.properties={url:""}}function q(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function g(){this.addInput("","image,canvas");this.size=[200,200]}function r(){this.addInputs([["img1",
|
|
"image"],["img2","image"],["fade","number"]]);this.addOutput("","image");this.properties={fade:0.5,width:512,height:512}}function m(){this.addInput("","image");this.addOutput("","image");this.properties={width:256,height:256,x:0,y:0,scale:1};this.size=[50,20]}function w(){this.addInput("clear",x.ACTION);this.addOutput("","canvas");this.properties={width:512,height:512,autoclear:!0};this.canvas=document.createElement("canvas");this.ctx=this.canvas.getContext("2d")}function B(){this.addInput("canvas",
|
|
"canvas");this.addInput("img","image,canvas");this.addInput("x","number");this.addInput("y","number");this.properties={x:0,y:0,opacity:1}}function z(){this.addInput("canvas","canvas");this.addInput("x","number");this.addInput("y","number");this.addInput("w","number");this.addInput("h","number");this.properties={x:0,y:0,w:10,h:10,color:"white",opacity:1}}function y(){this.addInput("t","number");this.addOutputs([["frame","image"],["t","number"],["d","number"]]);this.properties={url:"",use_proxy:!0}}
|
|
function c(){this.addOutput("Webcam","image");this.properties={facingMode:"user"};this.boxcolor="black";this.frame=0}var x=u.LiteGraph;d.title="Plot";d.desc="Plots data over time";d.colors=["#FFF","#F99","#9F9","#99F"];d.prototype.onExecute=function(c){if(!this.flags.collapsed){c=this.size;for(var d=0;4>d;++d){var g=this.getInputData(d);if(null!=g){var h=this.values[d];h.push(g);h.length>c[0]&&h.shift()}}}};d.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var f=this.size,g=0.5*f[1]/
|
|
this.properties.scale,h=d.colors,m=0.5*f[1];c.fillStyle="#000";c.fillRect(0,0,f[0],f[1]);c.strokeStyle="#555";c.beginPath();c.moveTo(0,m);c.lineTo(f[0],m);c.stroke();if(this.inputs)for(var k=0;4>k;++k){var a=this.values[k];if(this.inputs[k]&&this.inputs[k].link){c.strokeStyle=h[k];c.beginPath();var b=a[0]*g*-1+m;c.moveTo(0,Math.clamp(b,0,f[1]));for(var e=1;e<a.length&&e<f[0];++e)b=a[e]*g*-1+m,c.lineTo(e,Math.clamp(b,0,f[1]));c.stroke()}}}};x.registerNodeType("graphics/plot",d);k.title="Image";k.desc=
|
|
"Image loader";k.widgets=[{name:"load",text:"Load",type:"button"}];k.supported_extensions=["jpg","jpeg","png","gif"];k.prototype.onAdded=function(){""!=this.properties.url&&null==this.img&&this.loadImage(this.properties.url)};k.prototype.onDrawBackground=function(c){this.flags.collapsed||this.img&&5<this.size[0]&&5<this.size[1]&&c.drawImage(this.img,0,0,this.size[0],this.size[1])};k.prototype.onExecute=function(){this.img||(this.boxcolor="#000");this.img&&this.img.width?this.setOutputData(0,this.img):
|
|
this.setOutputData(0,null);this.img&&this.img.dirty&&(this.img.dirty=!1)};k.prototype.onPropertyChanged=function(c,d){this.properties[c]=d;"url"==c&&""!=d&&this.loadImage(d);return!0};k.prototype.loadImage=function(c,d){if(""==c)this.img=null;else{this.img=document.createElement("img");"http"==c.substr(0,4)&&x.proxy&&(c=x.proxy+c.substr(c.indexOf(":")+3));this.img.src=c;this.boxcolor="#F95";var g=this;this.img.onload=function(){d&&d(this);g.trace("Image loaded, size: "+g.img.width+"x"+g.img.height);
|
|
this.dirty=!0;g.boxcolor="#9F9";g.setDirtyCanvas(!0)}}};k.prototype.onWidget=function(c,d){"load"==d.name&&this.loadImage(this.properties.url)};k.prototype.onDropFile=function(c){var d=this;this._url&&URL.revokeObjectURL(this._url);this._url=URL.createObjectURL(c);this.properties.url=this._url;this.loadImage(this._url,function(c){d.size[1]=c.height/c.width*d.size[0]})};x.registerNodeType("graphics/image",k);q.title="Palette";q.desc="Generates a color";q.prototype.onExecute=function(){var c=[];null!=
|
|
this.properties.colorA&&c.push(hex2num(this.properties.colorA));null!=this.properties.colorB&&c.push(hex2num(this.properties.colorB));null!=this.properties.colorC&&c.push(hex2num(this.properties.colorC));null!=this.properties.colorD&&c.push(hex2num(this.properties.colorD));var d=this.getInputData(0);null==d&&(d=0.5);1<d?d=1:0>d&&(d=0);if(0!=c.length){var g=[0,0,0];if(0==d)g=c[0];else if(1==d)g=c[c.length-1];else{var h=(c.length-1)*d,d=c[Math.floor(h)],c=c[Math.floor(h)+1],h=h-Math.floor(h);g[0]=d[0]*
|
|
(1-h)+c[0]*h;g[1]=d[1]*(1-h)+c[1]*h;g[2]=d[2]*(1-h)+c[2]*h}for(var m in g)g[m]/=255;this.boxcolor=colorToString(g);this.setOutputData(0,g)}};x.registerNodeType("color/palette",q);g.title="Frame";g.desc="Frame viewerew";g.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"view",text:"View Image",type:"button"}];g.prototype.onDrawBackground=function(c){this.frame&&!this.flags.collapsed&&c.drawImage(this.frame,0,0,this.size[0],this.size[1])};g.prototype.onExecute=function(){this.frame=this.getInputData(0);
|
|
this.setDirtyCanvas(!0)};g.prototype.onWidget=function(c,d){if("resize"==d.name&&this.frame){var g=this.frame.width,h=this.frame.height;g||null==this.frame.videoWidth||(g=this.frame.videoWidth,h=this.frame.videoHeight);g&&h&&(this.size=[g,h]);this.setDirtyCanvas(!0,!0)}else"view"==d.name&&this.show()};g.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};x.registerNodeType("graphics/frame",g);r.title="Image fade";r.desc="Fades between images";r.widgets=[{name:"resizeA",text:"Resize to A",
|
|
type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];r.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};r.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};r.prototype.onExecute=function(){var c=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;
|
|
var d=this.getInputData(0);null!=d&&c.drawImage(d,0,0,this.canvas.width,this.canvas.height);d=this.getInputData(2);null==d?d=this.properties.fade:this.properties.fade=d;c.globalAlpha=d;d=this.getInputData(1);null!=d&&c.drawImage(d,0,0,this.canvas.width,this.canvas.height);c.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};x.registerNodeType("graphics/imagefade",r);m.title="Crop";m.desc="Crop Image";m.prototype.onAdded=function(){this.createCanvas()};m.prototype.createCanvas=
|
|
function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};m.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))};m.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])};m.prototype.onPropertyChanged=function(c,d){this.properties[c]=d;"scale"==c?(this.properties[c]=parseFloat(d),0==this.properties[c]&&(this.trace("Error in scale"),this.properties[c]=1)):this.properties[c]=parseInt(d);this.createCanvas();return!0};x.registerNodeType("graphics/cropImage",m);w.title="Canvas";w.desc="Canvas to render stuff";w.prototype.onExecute=function(){var c=this.canvas,d=this.properties.width|0,g=this.properties.height|
|
|
0;c.width!=d&&(c.width=d);c.height!=g&&(c.height=g);this.properties.autoclear&&this.ctx.clearRect(0,0,c.width,c.height);this.setOutputData(0,c)};w.prototype.onAction=function(c,d){"clear"==c&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)};x.registerNodeType("graphics/canvas",w);B.title="DrawImage";B.desc="Draws image into a canvas";B.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var d=this.getInputOrProperty("img");if(d){var g=this.getInputOrProperty("x"),h=this.getInputOrProperty("y");
|
|
c.getContext("2d").drawImage(d,g,h)}}};x.registerNodeType("graphics/drawImage",B);z.title="DrawRectangle";z.desc="Draws rectangle in canvas";z.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var d=this.getInputOrProperty("x"),g=this.getInputOrProperty("y"),h=this.getInputOrProperty("w"),m=this.getInputOrProperty("h");c.getContext("2d").fillRect(d,g,h,m)}};x.registerNodeType("graphics/drawRectangle",z);y.title="Video";y.desc="Video playback";y.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"}];y.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)}};y.prototype.onStart=function(){this.play()};y.prototype.onStop=function(){this.stop()};y.prototype.loadVideo=function(c){this._video_url=c;this.properties.use_proxy&&"http"==c.substr(0,4)&&x.proxy&&(c=x.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 d=this;this._video.addEventListener("loadedmetadata",
|
|
function(c){d.trace("Duration: "+this.duration+" seconds");d.trace("Size: "+this.videoWidth+","+this.videoHeight);d.setDirtyCanvas(!0);this.width=this.videoWidth;this.height=this.videoHeight});this._video.addEventListener("progress",function(c){});this._video.addEventListener("error",function(c){console.log("Error loading video: "+this.src);d.trace("Error loading video: "+this.src);if(this.error)switch(this.error.code){case this.error.MEDIA_ERR_ABORTED:d.trace("You stopped the video.");break;case this.error.MEDIA_ERR_NETWORK:d.trace("Network error - please try again later.");
|
|
break;case this.error.MEDIA_ERR_DECODE:d.trace("Video is broken..");break;case this.error.MEDIA_ERR_SRC_NOT_SUPPORTED:d.trace("Sorry, your browser can't play this video.")}});this._video.addEventListener("ended",function(c){d.trace("Ended.");this.play()})};y.prototype.onPropertyChanged=function(c,d){this.properties[c]=d;"url"==c&&""!=d&&this.loadVideo(d);return!0};y.prototype.play=function(){this._video&&this._video.play()};y.prototype.playPause=function(){this._video&&(this._video.paused?this.play():
|
|
this.pause())};y.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};y.prototype.pause=function(){this._video&&(this.trace("Video paused"),this._video.pause())};y.prototype.onWidget=function(c,d){};x.registerNodeType("graphics/video",y);c.title="Webcam";c.desc="Webcam image";c.is_webcam_open=!1;c.prototype.openStream=function(){function d(g){console.log("Webcam rejected",g);f._webcam_stream=!1;c.is_webcam_open=!1;f.boxcolor="red";f.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"](d);var f=this}};c.prototype.closeStream=function(){if(this._webcam_stream){var d=this._webcam_stream.getTracks();if(d.length)for(var f=0;f<d.length;++f)d[f].stop();c.is_webcam_open=!1;this._video=this._webcam_stream=null;this.boxcolor="black";this.trigger("stream_closed")}};c.prototype.onPropertyChanged=function(c,d){"facingMode"==c&&(this.properties.facingMode=
|
|
d,this.closeStream(),this.openStream())};c.prototype.onRemoved=function(){this.closeStream()};c.prototype.streamReady=function(d){this._webcam_stream=d;this.boxcolor="green";var f=this._video;f||(f=document.createElement("video"),f.autoplay=!0,f.srcObject=d,this._video=f,f.onloadedmetadata=function(d){console.log(d);c.is_webcam_open=!0});this.trigger("stream_ready",f)};c.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){this._video.frame=
|
|
++this.frame;this._video.width=this._video.videoWidth;this._video.height=this._video.videoHeight;this.setOutputData(0,this._video);for(var c=1;c<this.outputs.length;++c)if(this.outputs[c])switch(this.outputs[c].name){case "width":this.setOutputData(c,this._video.videoWidth);break;case "height":this.setOutputData(c,this._video.videoHeight)}}};c.prototype.getExtraMenuOptions=function(c){var d=this;return[{content:d.properties.show?"Hide Frame":"Show Frame",callback:function(){d.properties.show=!d.properties.show}}]};
|
|
c.prototype.onDrawBackground=function(c){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};c.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",x.EVENT],["stream_closed",x.EVENT],["stream_error",x.EVENT]]};x.registerNodeType("graphics/webcam",c)})(this);
|
|
(function(u){var d=u.LiteGraph;u.LGraphTexture=null;if("undefined"!=typeof GL){LGraphCanvas.link_type_colors.Texture="#987";var k=function(){this.addOutput("Texture","Texture");this.properties={name:"",filter:!0};this.size=[k.image_preview_size,k.image_preview_size]};u.LGraphTexture=k;k.title="Texture";k.desc="Texture";k.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}};k.loadTextureCallback=null;k.image_preview_size=256;k.PASS_THROUGH=1;k.COPY=2;k.LOW=3;k.HIGH=4;k.REUSE=5;k.DEFAULT=
|
|
2;k.MODE_VALUES={"pass through":k.PASS_THROUGH,copy:k.COPY,low:k.LOW,high:k.HIGH,reuse:k.REUSE,"default":k.DEFAULT};k.getTexturesContainer=function(){return gl.textures};k.loadTexture=function(a,b){b=b||{};var c=a;"http://"==c.substr(0,7)&&d.proxy&&(c=d.proxy+c.substr(7));return k.getTexturesContainer()[a]=GL.Texture.fromURL(c,b)};k.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};k.getTargetTexture=function(a,b,c){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var e=null;switch(c){case k.LOW:e=gl.UNSIGNED_BYTE;break;case k.HIGH:e=gl.HIGH_PRECISION_FORMAT;break;case k.REUSE:return a;default:e=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==e||(b=new GL.Texture(a.width,a.height,{type:e,format:gl.RGBA,filter:gl.LINEAR}));return b};k.getTextureType=function(a,b){var c=b?b.type:gl.UNSIGNED_BYTE;switch(a){case k.HIGH:c=gl.HIGH_PRECISION_FORMAT;
|
|
break;case k.LOW:c=gl.UNSIGNED_BYTE}return c};k.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})};k.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})};
|
|
k.prototype.onDropFile=function(a,b,c){if(a){var e=null;"string"==typeof a?e=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?e=GL.Texture.fromDDSInMemory(a):(a=new Blob([c]),a=URL.createObjectURL(a),e=GL.Texture.fromURL(a));this._drop_texture=e;this.properties.name=b}else this._drop_texture=null,this.properties.name=""};k.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]};k.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=k.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,a);for(var b=1;b<this.outputs.length;b++){var c=this.outputs[b];if(c){var e=null;"width"==c.name?e=a.width:"height"==c.name?e=a.height:"aspect"==c.name&&
|
|
(e=a.width/a.height);this.setOutputData(b,e)}}}};k.prototype.onResourceRenamed=function(a,b){this.properties.name==a&&(this.properties.name=b)};k.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=k.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())}};k.generateLowResTexturePreview=function(a){if(!a)return null;var b=k.image_preview_size,c=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)c=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=c=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(c);a=this._preview_canvas;
|
|
a||(this._preview_canvas=a=createCanvas(b,b));c&&c.toCanvas(a);return a};k.prototype.getResources=function(a){a[this.properties.name]=GL.Texture;return a};k.prototype.onGetInputs=function(){return[["in","Texture"]]};k.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};d.registerNodeType("texture/texture",k);var q=function(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[k.image_preview_size,k.image_preview_size]};q.title=
|
|
"Preview";q.desc="Show a texture in the graph canvas";q.allow_preview=!1;q.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||q.allow_preview)){var b=this.getInputData(0);if(b){var c=null,c=!b.handle&&a.webgl?b:k.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(c,0,0,this.size[0],this.size[1]);a.restore()}}};d.registerNodeType("texture/preview",q);var g=function(){this.addInput("Texture","Texture");this.addOutput("",
|
|
"Texture");this.properties={name:""}};g.title="Save";g.desc="Save a texture in the repository";g.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(k.storeTexture?k.storeTexture(this.properties.name,a):k.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};d.registerNodeType("texture/save",g);var r=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");
|
|
this.help="<p>pixelcode must be vec3</p>\t\t\t<p>uvcode must be vec2, is optional</p>\t\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p>";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value",precision:k.DEFAULT}};r.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo",
|
|
values:k.MODE_VALUES}};r.title="Operation";r.desc="Texture shader operation";r.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};r.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())};r.prototype.onExecute=function(){var a=
|
|
this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,e=512;a?(c=a.width,e=a.height):b&&(c=b.width,e=b.height);var d=k.getTextureType(this.properties.precision,a);this._tex=a||this._tex?k.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(c,e,{type:d,format:gl.RGBA,filter:gl.LINEAR});d="";this.properties.uvcode&&
|
|
(d="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(d=this.properties.uvcode));var h="";this.properties.pixelcode&&(h="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(h=this.properties.pixelcode));var f=this._shader;if(!f||this._shader_code!=d+"|"+h){try{this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,r.pixel_shader,{UV_CODE:d,PIXEL_CODE:h}),this.boxcolor="#00FF00"}catch(g){console.log("Error compiling shader: ",g);this.boxcolor="#FF0000";
|
|
return}this.boxcolor="#FF0000";this._shader_code=d+"|"+h;f=this._shader}if(f){this.boxcolor="green";var l=this.getInputData(2);null!=l?this.properties.value=l:l=parseFloat(this.properties.value);var m=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 d=Mesh.getScreenQuad();f.uniforms({u_texture:0,u_textureB:1,value:l,texSize:[c,e],time:m}).draw(d)});this.setOutputData(0,this._tex)}else this.boxcolor=
|
|
"red"}}};r.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tUV_CODE;\n\t\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\tPIXEL_CODE;\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/operation",r);var m=function(){this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,precision:k.DEFAULT};this.properties.code="\nvoid main() {\n vec2 uv = v_coord;\n vec3 color = vec3(0.0);\n//your code here\n\ngl_FragColor = vec4(color, 1.0);\n}\n";this._uniforms={in_texture:0,texSize:vec2.create(),time:0}};m.title="Shader";m.desc="Texture shader";m.widgets_info={code:{type:"code"},precision:{widget:"combo",values:k.MODE_VALUES}};m.prototype.onPropertyChanged=
|
|
function(a,b){if("code"==a){var c=this.getShader();if(c){var e=c.uniformInfo;if(this.inputs)for(var d={},h=0;h<this.inputs.length;++h){var f=this.getInputInfo(h);f&&(e[f.name]&&!d[f.name]?d[f.name]=!0:(this.removeInput(h),h--))}for(h in e)if(f=c.uniformInfo[h],null!==f.loc&&"time"!=h){e="number";if(this._shader.samplers[h])e="texture";else switch(f.size){case 1:e="number";break;case 2:e="vec2";break;case 3:e="vec3";break;case 4:e="vec4";break;case 9:e="mat3";break;case 16:e="mat4";break;default:continue}f=
|
|
this.findInputSlot(h);-1==f?this.addInput(h,e):(d=this.getInputInfo(f),d)?d.type!=e&&(this.removeInput(f,e),this.addInput(h,e)):this.addInput(h,e)}}}};m.prototype.getShader=function(){if(this._shader&&this._shader_code==this.properties.code)return this._shader;this._shader_code=this.properties.code;if(this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,m.pixel_shader+this.properties.code))this.boxcolor="green";else return this.boxcolor="red",null;return this._shader};m.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=
|
|
this.getShader();if(a){for(var b=0,c=null,e=0;e<this.inputs.length;++e){var d=this.getInputInfo(e),h=this.getInputData(e);null!=h&&(h.constructor===GL.Texture&&(h.bind(b),c||(c=h),h=b,b++),a.setUniform(d.name,h))}var f=this._uniforms,b=k.getTextureType(this.properties.precision,c),e=this.properties.width|0,d=this.properties.height|0;0==e&&(e=c?c.width:gl.canvas.width);0==d&&(d=c?c.height:gl.canvas.height);f.texSize[0]=e;f.texSize[1]=d;f.time=this.graph.getTime();this._tex&&this._tex.type==b&&this._tex.width==
|
|
e&&this._tex.height==d||(this._tex=new GL.Texture(e,d,{type:b,format:gl.RGBA,filter:gl.LINEAR}));this._tex.drawTo(function(){a.uniforms(f).draw(GL.Mesh.getScreenQuad())});this.setOutputData(0,this._tex)}}};m.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform float time;\n\t";d.registerNodeType("texture/shader",m);var w=function(){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:k.DEFAULT}};w.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};w.title="Scale/Offset";w.desc="Applies an scaling and offseting";w.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0)&&a)if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,a);else{var b=a.width,c=a.height,e=this.precision===k.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT;this.precision===k.DEFAULT&&(e=a.type);
|
|
this._tex&&this._tex.width==b&&this._tex.height==c&&this._tex.type==e||(this._tex=new GL.Texture(b,c,{type:e,format:gl.RGBA,filter:gl.LINEAR}));var d=this._shader;d||(d=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,w.pixel_shader));var h=this.getInputData(1);h?(this.properties.scale[0]=h[0],this.properties.scale[1]=h[1]):h=this.properties.scale;var f=this.getInputData(2);f?(this.properties.offset[0]=f[0],this.properties.offset[1]=f[1]):f=this.properties.offset;this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);
|
|
gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a.bind(0);var b=Mesh.getScreenQuad();d.uniforms({u_texture:0,u_scale:h,u_offset:f}).draw(b)});this.setOutputData(0,this._tex)}};w.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 u_scale;\n\t\t\tuniform vec2 u_offset;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tuv = uv / u_scale - u_offset;\n\t\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/scaleOffset",w);var B=function(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:0.01,precision:k.DEFAULT}};B.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};B.title="Warp";B.desc="Texture warp operation";B.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,
|
|
a);else{var b=this.getInputData(1),c=512,e=512;a?(c=a.width,e=a.height):b&&(c=b.width,e=b.height);this._tex=a||this._tex?k.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(c,e,{type:this.precision===k.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT,format:gl.RGBA,filter:gl.LINEAR});var d=this._shader;d||(d=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,B.pixel_shader));var h=this.getInputData(2);null!=h?this.properties.factor=h:h=parseFloat(this.properties.factor);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();d.uniforms({u_texture:0,u_textureB:1,u_factor:h}).draw(c)});this.setOutputData(0,this._tex)}};B.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform float u_factor;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tuv += ( texture2D(u_textureB, uv).rg - vec2(0.5)) * u_factor;\n\t\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/warp",B);var z=function(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1};this.size[0]=130};z.title="to Viewport";z.desc="Texture to viewport";z.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA,gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);
|
|
var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);if(this.properties.antialiasing){z._shader||(z._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,z.aa_pixel_shader));gl.getViewport();var c=Mesh.getScreenQuad();a.bind(0);z._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(c)}else 1!=b?(z._gamma_shader||(z._gamma_shader=
|
|
new GL.Shader(Shader.SCREEN_VERTEX_SHADER,z.gamma_pixel_shader)),a.toViewport(z._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport()}};z.prototype.onGetInputs=function(){return[["gamma","number"]]};z.aa_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 uViewportSize;\n\t\t\tuniform vec2 inverseVP;\n\t\t\tuniform float u_igamma;\n\t\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\t\n\t\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t\t{\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\t\n\t\t\t\tvec2 dir;\n\t\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\t\n\t\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\t\n\t\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\t\n\t\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\t\n\t\t\t\t//return vec4(rgbA,1.0);\n\t\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\t\telse\n\t\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\t\tif(u_igamma != 1.0)\n\t\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\t\treturn color;\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t\t}\n\t\t\t";
|
|
z.gamma_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_igamma;\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t\t gl_FragColor = color;\n\t\t\t}\n\t\t\t";d.registerNodeType("texture/toviewport",z);g=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,
|
|
precision:k.DEFAULT}};g.title="Copy";g.desc="Copy Texture";g.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:k.MODE_VALUES}};g.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,c=a.height;0!=this.properties.size&&(c=b=this.properties.size);var e=this._temp_texture,d=a.type;this.properties.precision===k.LOW?d=gl.UNSIGNED_BYTE:this.properties.precision===k.HIGH&&
|
|
(d=gl.HIGH_PRECISION_FORMAT);e&&e.width==b&&e.height==c&&e.type==d||(e=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(c)&&(e=gl.LINEAR_MIPMAP_LINEAR),this._temp_texture=new GL.Texture(b,c,{type:d,format:gl.RGBA,minFilter:e,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}};d.registerNodeType("texture/copy",
|
|
g);var y=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:k.DEFAULT}};y.title="Downsample";y.desc="Downsample Texture";y.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:k.MODE_VALUES}};y.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=y._shader;b||(y._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,y.pixel_shader));var c=a.width|0,e=a.height|0,d=a.type;this.properties.precision===k.LOW?d=gl.UNSIGNED_BYTE:this.properties.precision===k.HIGH&&(d=gl.HIGH_PRECISION_FORMAT);var h=this.properties.iterations||1,f=a,g=null,l=[],a={type:d,format:a.format},d=vec2.create(),m={u_offset:d};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var s=0;s<h;++s){d[0]=1/c;d[1]=1/e;c=c>>1||0;e=e>>1||0;g=GL.Texture.getTemporary(c,
|
|
e,a);l.push(g);f.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);f.copyTo(g,b,m);if(1==c&&1==e)break;f=g}this._texture=l.pop();for(s=0;s<l.length;++s)GL.Texture.releaseTemporary(l[s]);this.properties.generate_mipmaps&&(this._texture.bind(0),gl.generateMipmap(this._texture.texture_type),this._texture.unbind(0));this.setOutputData(0,this._texture)}};y.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( u_offset.x, 0.0 ) );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( 0.0, u_offset.y ) );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( u_offset.x, u_offset.y ) );\n\t\t\t gl_FragColor = color * 0.25;\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/downsample",y);var c=function(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg","vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,mipmap_offset:0,low_precision:!1};this._uniforms={u_texture:0,u_mipmap_offset:this.properties.mipmap_offset};this._luminance=new Float32Array(4)};c.title="Average";c.desc="Compute a partial average (32 random samples) of a texture and stores it as a 1x1 pixel texture";c.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)};c.prototype.onPreRenderExecute=function(){this.updateAverage()};c.prototype.updateAverage=function(){var a=this.getInputData(0);if(a&&(this.isOutputConnected(0)||this.isOutputConnected(1)||this.isOutputConnected(2))){if(!c._shader){c._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,c.pixel_shader);for(var b=
|
|
new Float32Array(32),e=0;32>e;++e)b[e]=Math.random();c._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}e=this._temp_texture;b=gl.UNSIGNED_BYTE;a.type!=b&&(b=gl.FLOAT);e&&e.type==b||(this._temp_texture=new GL.Texture(1,1,{type:b,format:gl.RGBA,filter:gl.NEAREST}));var d=c._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(d,h)});if(this.isOutputConnected(1)||
|
|
this.isOutputConnected(2))if(e=this._temp_texture.getPixels()){var f=this._luminance,b=this._temp_texture.type;f.set(e);b==gl.UNSIGNED_BYTE&&vec4.scale(f,f,1/255)}}};c.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/average",c);var x=function(){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}};x.title="Smooth";x.desc="Smooth texture over time";x.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){x._shader||(x._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,x.pixel_shader));var b=this._temp_texture;
|
|
b&&b.type==a.type&&b.width==a.width&&b.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.NEAREST}),this._temp_texture2=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.NEAREST}),a.copyTo(this._temp_texture2));var b=this._temp_texture,c=this._temp_texture2,e=x._shader,d=this._uniforms;d.u_factor=1-this.getInputOrProperty("factor");gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);b.drawTo(function(){c.bind(1);a.toViewport(e,
|
|
d)});this.setOutputData(0,b);this._temp_texture=c;this._temp_texture2=b}};x.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_factor;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = mix( texture2D( u_texture, v_coord ), texture2D( u_textureB, v_coord ), u_factor );\n\t\t\t}\n\t\t\t";d.registerNodeType("texture/temporal_smooth",x);g=function(){this.addInput("Image",
|
|
"image");this.addOutput("","Texture");this.properties={}};g.title="Image to Texture";g.desc="Uploads an image to the GPU";g.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,c=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var e=this._temp_texture;e&&e.width==b&&e.height==c||(this._temp_texture=new GL.Texture(b,c,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(d){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+
|
|
d);return}this.setOutputData(0,this._temp_texture)}}};d.registerNodeType("texture/imageToTexture",g);var n=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={intensity:1,precision:k.DEFAULT,texture:null};n._shader||(n._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n.pixel_shader))};n.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:k.MODE_VALUES}};n.title="LUT";n.desc=
|
|
"Apply LUT to Texture";n.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,a);else if(a){var b=this.getInputData(1);b||(b=k.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 c=this.properties.intensity;this.isInputConnected(2)&&(this.properties.intensity=c=this.getInputData(2));this._tex=k.getTargetTexture(a,this._tex,this.properties.precision);this._tex.drawTo(function(){b.bind(1);a.toViewport(n._shader,{u_texture:0,u_textureB:1,u_amount:c})});this.setOutputData(0,this._tex)}else this.setOutputData(0,a)}}};n.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_amount;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t\t mediump vec2 quad1;\n\t\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t\t mediump vec2 quad2;\n\t\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t\t highp vec2 texPos1;\n\t\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t highp vec2 texPos2;\n\t\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/LUT",n);var f=function(){this.addInput("Texture","Texture");this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");this.properties={use_luminance:!0};f._shader||(f._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader))};f.title="Texture to Channels";f.desc="Split texture channels";f.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b=
|
|
this.properties.use_luminance?gl.LUMINANCE:gl.RGBA,c=0,e=0;4>e;e++)this.isOutputConnected(e)?(this._channels[e]&&this._channels[e].width==a.width&&this._channels[e].height==a.height&&this._channels[e].type==a.type&&this._channels[e].format==b||(this._channels[e]=new GL.Texture(a.width,a.height,{type:a.type,format:b,filter:gl.LINEAR})),c++):this._channels[e]=null;if(c){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);for(var d=Mesh.getScreenQuad(),h=f._shader,g=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,
|
|
1]],e=0;4>e;e++)this._channels[e]&&(this._channels[e].drawTo(function(){a.bind(0);h.uniforms({u_texture:0,u_mask:g[e]}).draw(d)}),this.setOutputData(e,this._channels[e]))}}};f.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec4 u_mask;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t\t}\n\t\t\t";d.registerNodeType("texture/textureChannels",
|
|
f);var A=function(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={precision:k.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}};A.title="Channels to Texture";A.desc="Split texture channels";A.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};A.prototype.onExecute=function(){var a=
|
|
k.getWhiteTexture(),b=this.getInputData(0)||a,e=this.getInputData(1)||a,c=this.getInputData(2)||a,d=this.getInputData(3)||a;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad();A._shader||(A._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,A.pixel_shader));var f=A._shader,a=Math.max(b.width,e.width,c.width,d.width),g=Math.max(b.height,e.height,c.height,d.height),l=this.properties.precision==k.HIGH?k.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._texture&&this._texture.width==a&&
|
|
this._texture.height==g&&this._texture.type==l||(this._texture=new GL.Texture(a,g,{type:l,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 m=this._uniforms;this._texture.drawTo(function(){b.bind(0);e.bind(1);c.bind(2);d.bind(3);f.uniforms(m).draw(h)});this.setOutputData(0,this._texture)};A.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_textureR;\n\t\t\tuniform sampler2D u_textureG;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform sampler2D u_textureA;\n\t\t\tuniform vec4 u_color;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = u_color * vec4( \t\t\t\t\t\ttexture2D(u_textureR, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureG, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureB, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureA, v_coord).r);\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/channelsTexture",A);g=function(){this.addOutput("Texture","Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:k.DEFAULT}};g.title="Color";g.desc="Generates a 1x1 texture with a constant color";g.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};g.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])};g.prototype.onExecute=function(){var a=this.properties.precision==k.HIGH?k.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;b<this.inputs.length;b++){var e=this.inputs[b],c=this.getInputData(b);if(void 0!==c)switch(e.name){case "RGB":case "RGBA":a.set(c);
|
|
break;case "R":a[0]=c;break;case "G":a[1]=c;break;case "B":a[2]=c;break;case "A":a[3]=c}}0.001<vec4.sqrDist(this._tex_color,a)&&(this._tex_color.set(a),this._tex.fill(a));this.setOutputData(0,this._tex)};g.prototype.onGetInputs=function(){return[["RGB","vec3"],["RGBA","vec4"],["R","number"],["G","number"],["B","number"],["A","number"]]};d.registerNodeType("texture/color",g);var h=function(){this.addInput("A","color");this.addInput("B","color");this.addOutput("Texture","Texture");this.properties={angle:0,
|
|
scale:1,A:[0,0,0],B:[1,1,1],texture_size:32};h._shader||(h._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}};h.title="Gradient";h.desc="Generates a gradient";h["@A"]={type:"color"};h["@B"]={type:"color"};h["@texture_size"]={type:"enum",values:[32,64,128,256,512]};h.prototype.onExecute=function(){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var a=GL.Mesh.getScreenQuad(),b=h._shader,e=this.getInputData(0);e||
|
|
(e=this.properties.A);var c=this.getInputData(1);c||(c=this.properties.B);for(var d=2;d<this.inputs.length;d++){var f=this.inputs[d],g=this.getInputData(d);void 0!==g&&(this.properties[f.name]=g)}var l=this._uniforms;this._uniforms.u_angle=this.properties.angle*DEG2RAD;this._uniforms.u_scale=this.properties.scale;vec3.copy(l.u_colorA,e);vec3.copy(l.u_colorB,c);e=parseInt(this.properties.texture_size);this._tex&&this._tex.width==e||(this._tex=new GL.Texture(e,e,{format:gl.RGB,filter:gl.LINEAR}));this._tex.drawTo(function(){b.uniforms(l).draw(a)});
|
|
this.setOutputData(0,this._tex)};h.prototype.onGetInputs=function(){return[["angle","number"],["scale","number"]]};h.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform float u_angle;\n\t\t\tuniform float u_scale;\n\t\t\tuniform vec3 u_colorA;\n\t\t\tuniform vec3 u_colorB;\n\t\t\t\n\t\t\tvec2 rotate(vec2 v, float angle)\n\t\t\t{\n\t\t\t\tvec2 result;\n\t\t\t\tfloat _cos = cos(angle);\n\t\t\t\tfloat _sin = sin(angle);\n\t\t\t\tresult.x = v.x * _cos - v.y * _sin;\n\t\t\t\tresult.y = v.x * _sin + v.y * _cos;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tvoid main() {\n\t\t\t\tfloat f = (rotate(u_scale * (v_coord - vec2(0.5)), u_angle) + vec2(0.5)).x;\n\t\t\t\tvec3 color = mix(u_colorA,u_colorB,clamp(f,0.0,1.0));\n\t\t\t gl_FragColor = vec4(color,1.0);\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/gradient",h);var s=function(){this.addInput("A","Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={factor:0.5,precision:k.DEFAULT};this._uniforms={u_textureA:0,u_textureB:1,u_textureMix:2,u_mix:vec4.create()}};s.title="Mix";s.desc="Generates a texture mixing two textures";s.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};s.prototype.onExecute=function(){var a=this.getInputData(0);
|
|
if(this.isOutputConnected(0))if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(a&&b){var e=this.getInputData(2),c=this.getInputData(3);this._tex=k.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),h=null,f=this._uniforms;e?(h=s._shader_tex,h||(h=s._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.pixel_shader,{MIX_TEX:""}))):(h=s._shader_factor,h||(h=s._shader_factor=
|
|
new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.pixel_shader)),c=null==c?this.properties.factor:c,f.u_mix.set([c,c,c,c]));this._tex.drawTo(function(){a.bind(0);b.bind(1);e&&e.bind(2);h.uniforms(f).draw(d)});this.setOutputData(0,this._tex)}}};s.prototype.onGetInputs=function(){return[["factor","number"]]};s.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_textureA;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\t#ifdef MIX_TEX\n\t\t\t\tuniform sampler2D u_textureMix;\n\t\t\t#else\n\t\t\t\tuniform vec4 u_mix;\n\t\t\t#endif\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\t#ifdef MIX_TEX\n\t\t\t\t vec4 f = texture2D(u_textureMix, v_coord);\n\t\t\t\t#else\n\t\t\t\t vec4 f = u_mix;\n\t\t\t\t#endif\n\t\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), f );\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/mix",s);var v=function(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:k.DEFAULT};v._shader||(v._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,v.pixel_shader))};v.title="Edges";v.desc="Detects edges";v.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};v.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,
|
|
a);else if(a){this._tex=k.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),e=v._shader,c=this.properties.invert,d=this.properties.factor,h=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);e.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:d,u_threshold:h,u_invert:c?1:0}).draw(b)});this.setOutputData(0,this._tex)}}};v.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_isize;\n\t\t\tuniform int u_invert;\n\t\t\tuniform float u_factor;\n\t\t\tuniform float u_threshold;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 center = texture2D(u_texture, v_coord);\n\t\t\t\tvec4 up = texture2D(u_texture, v_coord + u_isize * vec2(0.0,1.0) );\n\t\t\t\tvec4 down = texture2D(u_texture, v_coord + u_isize * vec2(0.0,-1.0) );\n\t\t\t\tvec4 left = texture2D(u_texture, v_coord + u_isize * vec2(1.0,0.0) );\n\t\t\t\tvec4 right = texture2D(u_texture, v_coord + u_isize * vec2(-1.0,0.0) );\n\t\t\t\tvec4 diff = abs(center - up) + abs(center - down) + abs(center - left) + abs(center - right);\n\t\t\t\tdiff *= u_factor;\n\t\t\t\tif(u_invert == 1)\n\t\t\t\t\tdiff.xyz = vec3(1.0) - diff.xyz;\n\t\t\t\tif( u_threshold == 0.0 )\n\t\t\t\t\tgl_FragColor = vec4( diff.xyz, center.a );\n\t\t\t\telse\n\t\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\t}\n\t\t\t";
|
|
d.registerNodeType("texture/edges",v);var a=function(){this.addInput("Texture","Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}};a.title="Depth Range";a.desc="Generates a texture with a depth range";a.prototype.onExecute=function(){if(this.isOutputConnected(0)){var b=this.getInputData(0);
|
|
if(b){var e=gl.UNSIGNED_BYTE;this.properties.high_precision&&(e=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==e&&this._temp_texture.width==b.width&&this._temp_texture.height==b.height||(this._temp_texture=new GL.Texture(b.width,b.height,{type:e,format:gl.RGBA,filter:gl.LINEAR}));var c=this._uniforms,e=this.properties.distance;this.isInputConnected(1)&&(e=this.getInputData(1),this.properties.distance=e);var d=this.properties.range;this.isInputConnected(2)&&
|
|
(d=this.getInputData(2),this.properties.range=d);c.u_distance=e;c.u_range=d;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad();a._shader||(a._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a.pixel_shader),a._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a.pixel_shader,{ONLY_DEPTH:""}));var f=this.properties.only_depth?a._shader_onlydepth:a._shader,e=null,e=b.near_far_planes?b.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:
|
|
[0.1,1E3];c.u_camera_planes=e;this._temp_texture.drawTo(function(){b.bind(0);f.uniforms(c).draw(h)});this._temp_texture.near_far_planes=e;this.setOutputData(0,this._temp_texture)}}};a.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_distance;\n\t\t\tuniform float u_range;\n\t\t\t\n\t\t\tfloat LinearDepth()\n\t\t\t{\n\t\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat depth = LinearDepth();\n\t\t\t\t#ifdef ONLY_DEPTH\n\t\t\t\t gl_FragColor = vec4(depth);\n\t\t\t\t#else\n\t\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\t\tfloat dof = 1.0;\n\t\t\t\t\tif(diff <= u_range)\n\t\t\t\t\t\tdof = diff / u_range;\n\t\t\t\t gl_FragColor = vec4(dof);\n\t\t\t\t#endif\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("texture/depth_range",a);var b=function(){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:k.DEFAULT}};b.title="Blur";b.desc="Blur a texture";b.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};b.max_iterations=20;b.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var e=
|
|
this._final_texture;e&&e.width==a.width&&e.height==a.height&&e.type==a.type||(e=this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var c=this.properties.iterations;this.isInputConnected(1)&&(c=this.getInputData(1),this.properties.iterations=c);c=Math.min(Math.floor(c),b.max_iterations);if(0==c)this.setOutputData(0,a);else{var h=this.properties.intensity;this.isInputConnected(2)&&(h=this.getInputData(2),this.properties.intensity=h);var f=d.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,g=this.properties.scale||[1,1];a.applyBlur(f*g[0],g[1],h,e);for(a=1;a<c;++a)e.applyBlur(f*g[0]*(a+1),g[1]*(a+1),h);this.setOutputData(0,e)}}};d.registerNodeType("texture/blur",b);var e=function(){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:k.DEFAULT};this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}};e.title="Glow";e.desc="Filters a texture giving it a glow effect";e.weights=new Float32Array([0.5,0.4,0.3,0.2]);e.widgets_info={iterations:{type:"number",min:0,max:16,step:1,precision:0},threshold:{type:"number",min:0,max:10,step:0.01,precision:2},precision:{widget:"combo",values:k.MODE_VALUES}};e.prototype.onGetInputs=function(){return[["enabled",
|
|
"boolean"],["threshold","number"],["intensity","number"],["persistence","number"],["iterations","number"],["dirt_factor","number"]]};e.prototype.onGetOutputs=function(){return[["average","Texture"]]};e.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isAnyOutputConnected())if(this.properties.precision===k.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,a);else{var b=a.width,c=a.height,d={format:a.format,type:a.type,minFilter:GL.LINEAR,magFilter:GL.LINEAR,
|
|
wrap:gl.CLAMP_TO_EDGE},h=k.getTextureType(this.properties.precision,a),f=this._uniforms,g=this._textures,l=e._cut_shader;l||(l=e._cut_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,e.cut_pixel_shader));gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);f.u_threshold=this.getInputOrProperty("threshold");var m=g[0]=GL.Texture.getTemporary(b,c,d);a.blit(m,l.uniforms(f));var s=m,n=this.getInputOrProperty("iterations"),n=Math.clamp(n,1,16)|0,v=f.u_texel_size,t=this.getInputOrProperty("intensity");f.u_intensity=
|
|
1;f.u_delta=this.properties.scale;l=e._shader;l||(l=e._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,e.scale_pixel_shader));for(var q=1;q<n;q++){b>>=1;1<(c|0)&&(c>>=1);if(2>b)break;m=g[q]=GL.Texture.getTemporary(b,c,d);v[0]=1/s.width;v[1]=1/s.height;s.blit(m,l.uniforms(f));s=m}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})),v[0]=1/s.width,v[1]=1/s.height,f.u_intensity=
|
|
t,f.u_delta=1,s.blit(b,l.uniforms(f)),this.setOutputData(2,b));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);f.u_intensity=this.getInputOrProperty("persistence");f.u_delta=0.5;for(q-=2;0<=q;q--)m=g[q],g[q]=null,v[0]=1/s.width,v[1]=1/s.height,s.blit(m,l.uniforms(f)),GL.Texture.releaseTemporary(s),s=m;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})),s.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 r=this.getInputData(1),w=this.getInputOrProperty("dirt_factor");f.u_intensity=t;l=r?e._dirt_final_shader:e._final_shader;l||(l=r?e._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,e.final_pixel_shader,
|
|
{USE_DIRT:""}):e._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,e.final_pixel_shader));g.drawTo(function(){a.bind(0);s.bind(1);r&&(l.setUniform("u_dirt_factor",w),l.setUniform("u_dirt_texture",r.bind(2)));l.toViewport(f)});this.setOutputData(0,g)}GL.Texture.releaseTemporary(s)}};e.cut_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_threshold;\n\t\tvoid main() {\n\t\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t\t}";
|
|
e.scale_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_texel_size;\n\t\tuniform float u_delta;\n\t\tuniform float u_intensity;\n\t\t\n\t\tvec4 sampleBox(vec2 uv) {\n\t\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\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\t\treturn s * 0.25;\n\t\t}\n\t\tvoid main() {\n\t\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t\t}";
|
|
e.final_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_glow_texture;\n\t\t#ifdef USE_DIRT\n\t\t\tuniform sampler2D u_dirt_texture;\n\t\t#endif\n\t\tuniform vec2 u_texel_size;\n\t\tuniform float u_delta;\n\t\tuniform float u_intensity;\n\t\tuniform float u_dirt_factor;\n\t\t\n\t\tvec4 sampleBox(vec2 uv) {\n\t\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\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\t\treturn s * 0.25;\n\t\t}\n\t\tvoid main() {\n\t\t\tvec4 glow = sampleBox( v_coord );\n\t\t\t#ifdef USE_DIRT\n\t\t\t\tglow = mix( glow, glow * texture2D( u_dirt_texture, v_coord ), u_dirt_factor );\n\t\t\t#endif\n\t\t\tgl_FragColor = texture2D( u_texture, v_coord ) + u_intensity * glow;\n\t\t}";
|
|
d.registerNodeType("texture/glow",e);var t=function(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}};t.title="Kuwahara Filter";t.desc="Filters a texture giving an artistic oil canvas painting";t.max_radius=10;t._shaders=[];t.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),t.max_radius);if(0==b)this.setOutputData(0,a);else{var e=this.properties.intensity,c=d.camera_aspect;c||void 0===window.gl||(c=gl.canvas.height/gl.canvas.width);c||(c=1);c=this.properties.preserve_aspect?c:1;t._shaders[b]||(t._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,t.pixel_shader,{RADIUS:b.toFixed(0)}));var h=t._shaders[b],f=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){h.uniforms({u_texture:0,
|
|
u_intensity:e,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(f)});this.setOutputData(0,this._temp_texture)}}};t.pixel_shader="\n\tprecision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_intensity;\n\tuniform vec2 u_resolution;\n\tuniform vec2 u_iResolution;\n\t#ifndef RADIUS\n\t\t#define RADIUS 7\n\t#endif\n\tvoid main() {\n\t\n\t\tconst int radius = RADIUS;\n\t\tvec2 fragCoord = v_coord;\n\t\tvec2 src_size = u_iResolution;\n\t\tvec2 uv = v_coord;\n\t\tfloat n = float((radius + 1) * (radius + 1));\n\t\tint i;\n\t\tint j;\n\t\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\t\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\t\tvec3 c;\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm0 += c;\n\t\t\t\ts0 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm1 += c;\n\t\t\t\ts1 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm2 += c;\n\t\t\t\ts2 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm3 += c;\n\t\t\t\ts3 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfloat min_sigma2 = 1e+2;\n\t\tm0 /= n;\n\t\ts0 = abs(s0 / n - m0 * m0);\n\t\t\n\t\tfloat sigma2 = s0.r + s0.g + s0.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m0, 1.0);\n\t\t}\n\t\t\n\t\tm1 /= n;\n\t\ts1 = abs(s1 / n - m1 * m1);\n\t\t\n\t\tsigma2 = s1.r + s1.g + s1.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m1, 1.0);\n\t\t}\n\t\t\n\t\tm2 /= n;\n\t\ts2 = abs(s2 / n - m2 * m2);\n\t\t\n\t\tsigma2 = s2.r + s2.g + s2.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m2, 1.0);\n\t\t}\n\t\t\n\t\tm3 /= n;\n\t\ts3 = abs(s3 / n - m3 * m3);\n\t\t\n\t\tsigma2 = s3.r + s3.g + s3.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m3, 1.0);\n\t\t}\n\t}\n\t";
|
|
d.registerNodeType("texture/kuwahara",t);var l=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0};l.title="Webcam";l.desc="Webcam texture";l.is_webcam_open=!1;l.prototype.openStream=function(){function a(e){l.is_webcam_open=!1;console.log("Webcam rejected",e);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}};l.prototype.closeStream=function(){if(this._webcam_stream){var a=this._webcam_stream.getTracks();if(a.length)for(var b=0;b<a.length;++b)a[b].stop();l.is_webcam_open=!1;this._video=this._webcam_stream=null;this.boxcolor="black";this.trigger("stream_closed")}};l.prototype.streamReady=function(a){this._webcam_stream=a;this.boxcolor="green";var b=this._video;b||(b=document.createElement("video"),
|
|
b.autoplay=!0,b.srcObject=a,this._video=b,b.onloadedmetadata=function(a){l.is_webcam_open=!0;console.log(a)});this.trigger("stream_ready",b)};l.prototype.onPropertyChanged=function(a,b){"facingMode"==a&&(this.properties.facingMode=b,this.closeStream(),this.openStream())};l.prototype.onRemoved=function(){if(this._webcam_stream){var a=this._webcam_stream.getTracks();if(a.length)for(var b=0;b<a.length;++b)a[b].stop();this._video=this._webcam_stream=null}};l.prototype.onDrawBackground=function(a){this.flags.collapsed||
|
|
20>=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())};l.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,e=this._video_texture;e&&e.width==a&&e.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&&(k.getTexturesContainer()[this.properties.texture_name]=this._video_texture);this.setOutputData(0,this._video_texture);for(a=1;a<this.outputs.length;++a)if(this.outputs[a])switch(this.outputs[a].name){case "width":this.setOutputData(a,this._video.videoWidth);break;case "height":this.setOutputData(a,this._video.videoHeight)}}};l.prototype.onGetOutputs=function(){return[["width",
|
|
"number"],["height","number"],["stream_ready",d.EVENT],["stream_closed",d.EVENT],["stream_error",d.EVENT]]};d.registerNodeType("texture/webcam",l);var G=function(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:k.LOW};this._uniforms={u_texture:0,u_factor:1}};G.title="Lens FX";G.desc="distortion and chromatic aberration";G.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};G.prototype.onGetInputs=
|
|
function(){return[["enabled","boolean"]]};G.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0))if(this.properties.precision===k.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,a);else{var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var e=G._shader;e||(e=G._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,
|
|
G.pixel_shader));var c=this.getInputData(1);null==c&&(c=this.properties.factor);var d=this._uniforms;d.u_factor=c;gl.disable(gl.DEPTH_TEST);b.drawTo(function(){a.bind(0);e.uniforms(d).draw(GL.Mesh.getScreenQuad())});this.setOutputData(0,b)}};G.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_factor;\n\t\t\tvec2 barrelDistortion(vec2 coord, float amt) {\n\t\t\t\tvec2 cc = coord - 0.5;\n\t\t\t\tfloat dist = dot(cc, cc);\n\t\t\t\treturn coord + cc * dist * amt;\n\t\t\t}\n\t\t\t\n\t\t\tfloat sat( float t )\n\t\t\t{\n\t\t\t\treturn clamp( t, 0.0, 1.0 );\n\t\t\t}\n\t\t\t\n\t\t\tfloat linterp( float t ) {\n\t\t\t\treturn sat( 1.0 - abs( 2.0*t - 1.0 ) );\n\t\t\t}\n\t\t\t\n\t\t\tfloat remap( float t, float a, float b ) {\n\t\t\t\treturn sat( (t - a) / (b - a) );\n\t\t\t}\n\t\t\t\n\t\t\tvec4 spectrum_offset( float t ) {\n\t\t\t\tvec4 ret;\n\t\t\t\tfloat lo = step(t,0.5);\n\t\t\t\tfloat hi = 1.0-lo;\n\t\t\t\tfloat w = linterp( remap( t, 1.0/6.0, 5.0/6.0 ) );\n\t\t\t\tret = vec4(lo,1.0,hi, 1.) * vec4(1.0-w, w, 1.0-w, 1.);\n\t\t\t\n\t\t\t\treturn pow( ret, vec4(1.0/2.2) );\n\t\t\t}\n\t\t\t\n\t\t\tconst float max_distort = 2.2;\n\t\t\tconst int num_iter = 12;\n\t\t\tconst float reci_num_iter_f = 1.0 / float(num_iter);\n\t\t\t\n\t\t\tvoid main()\n\t\t\t{\t\n\t\t\t\tvec2 uv=v_coord;\n\t\t\t\tvec4 sumcol = vec4(0.0);\n\t\t\t\tvec4 sumw = vec4(0.0);\t\n\t\t\t\tfor ( int i=0; i<num_iter;++i )\n\t\t\t\t{\n\t\t\t\t\tfloat t = float(i) * reci_num_iter_f;\n\t\t\t\t\tvec4 w = spectrum_offset( t );\n\t\t\t\t\tsumw += w;\n\t\t\t\t\tsumcol += w * texture2D( u_texture, barrelDistortion(uv, .6 * max_distort*t * u_factor ) );\n\t\t\t\t}\n\t\t\t\tgl_FragColor = sumcol / sumw;\n\t\t\t}";
|
|
d.registerNodeType("texture/lensfx",G);var J=function(){this.addInput("in","Texture");this.addInput("exp","number");this.addOutput("out","Texture");this.properties={exposition:1,precision:k.LOW};this._uniforms={u_texture:0,u_exposition:1}};J.title="Exposition";J.desc="Controls texture exposition";J.widgets_info={exposition:{widget:"slider",min:0,max:3},precision:{widget:"combo",values:k.MODE_VALUES}};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||(b=this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var e=J._shader;e||(e=J._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,J.pixel_shader));var c=this.getInputData(1);null!=c&&(this.properties.exposition=c);var d=this._uniforms;b.drawTo(function(){gl.disable(gl.DEPTH_TEST);a.bind(0);e.uniforms(d).draw(GL.Mesh.getScreenQuad())});this.setOutputData(0,b)}};J.pixel_shader=
|
|
"precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_exposition;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord );\n\t\t\t\tgl_FragColor = vec4( color.xyz * u_exposition, color.a );\n\t\t\t}";d.registerNodeType("texture/exposition",J);var F=function(){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:k.LOW};this._uniforms={u_texture:0,u_lumwhite2:1,u_igamma:1,u_scale:1,u_average_lum:1}};F.title="Tone Mapping";F.desc="Applies Tone Mapping to convert from high to low";F.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};F.prototype.onGetInputs=function(){return[["enabled","boolean"]]};F.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0))if(this.properties.precision===k.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,
|
|
a);else{var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var e=this.getInputData(1);null==e&&(e=this.properties.average_lum);var c=this._uniforms,d=null;e.constructor===Number?(this.properties.average_lum=e,c.u_average_lum=this.properties.average_lum,d=F._shader,d||(d=F._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,F.pixel_shader))):e.constructor===GL.Texture&&
|
|
(c.u_average_texture=e.bind(1),d=F._shader_texture,d||(d=F._shader_texture=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,F.pixel_shader,{AVG_TEXTURE:""})));c.u_lumwhite2=this.properties.lum_white*this.properties.lum_white;c.u_scale=this.properties.scale;c.u_igamma=1/this.properties.gamma;gl.disable(gl.DEPTH_TEST);b.drawTo(function(){a.bind(0);d.uniforms(c).draw(GL.Mesh.getScreenQuad())});this.setOutputData(0,this._temp_texture)}};F.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_scale;\n\t\t\t#ifdef AVG_TEXTURE\n\t\t\t\tuniform sampler2D u_average_texture;\n\t\t\t#else\n\t\t\t\tuniform float u_average_lum;\n\t\t\t#endif\n\t\t\tuniform float u_lumwhite2;\n\t\t\tuniform float u_igamma;\n\t\t\tvec3 RGB2xyY (vec3 rgb)\n\t\t\t{\n\t\t\t\t const mat3 RGB2XYZ = mat3(0.4124, 0.3576, 0.1805,\n\t\t\t\t\t\t\t\t\t\t 0.2126, 0.7152, 0.0722,\n\t\t\t\t\t\t\t\t\t\t 0.0193, 0.1192, 0.9505);\n\t\t\t\tvec3 XYZ = RGB2XYZ * rgb;\n\t\t\t\t\n\t\t\t\tfloat f = (XYZ.x + XYZ.y + XYZ.z);\n\t\t\t\treturn vec3(XYZ.x / f,\n\t\t\t\t\t\t\tXYZ.y / f,\n\t\t\t\t\t\t\tXYZ.y);\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord );\n\t\t\t\tvec3 rgb = color.xyz;\n\t\t\t\tfloat average_lum = 0.0;\n\t\t\t\t#ifdef AVG_TEXTURE\n\t\t\t\t\tvec3 pixel = texture2D(u_average_texture,vec2(0.5)).xyz;\n\t\t\t\t\taverage_lum = (pixel.x + pixel.y + pixel.z) / 3.0;\n\t\t\t\t#else\n\t\t\t\t\taverage_lum = u_average_lum;\n\t\t\t\t#endif\n\t\t\t\t//Ld - this part of the code is the same for both versions\n\t\t\t\tfloat lum = dot(rgb, vec3(0.2126, 0.7152, 0.0722));\n\t\t\t\tfloat L = (u_scale / average_lum) * lum;\n\t\t\t\tfloat Ld = (L * (1.0 + L / u_lumwhite2)) / (1.0 + L);\n\t\t\t\t//first\n\t\t\t\t//vec3 xyY = RGB2xyY(rgb);\n\t\t\t\t//xyY.z *= Ld;\n\t\t\t\t//rgb = xyYtoRGB(xyY);\n\t\t\t\t//second\n\t\t\t\trgb = (rgb / lum) * Ld;\n\t\t\t\trgb = pow( rgb, vec3( u_igamma ) );\n\t\t\t\tgl_FragColor = vec4( rgb, color.a );\n\t\t\t}";
|
|
d.registerNodeType("texture/tonemapping",F);var H=function(){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:k.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()}};H.title="Perlin";H.desc="Generates a perlin noise texture";H.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES},width:{type:"Number",precision:0,
|
|
step:1},height:{type:"Number",precision:0,step:1},octaves:{type:"Number",precision:0,step:1,min:1,max:50}};H.prototype.onGetInputs=function(){return[["seed","Number"],["persistence","Number"],["octaves","Number"],["scale","Number"],["amplitude","Number"],["offset","vec2"]]};H.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.properties.width|0,b=this.properties.height|0;0==a&&(a=gl.viewport_data[2]);0==b&&(b=gl.viewport_data[3]);var e=k.getTextureType(this.properties.precision),
|
|
c=this._texture;c&&c.width==a&&c.height==b&&c.type==e||(c=this._texture=new GL.Texture(a,b,{type:e,format:gl.RGB,filter:gl.LINEAR}));var d=this.getInputOrProperty("persistence"),h=this.getInputOrProperty("octaves"),f=this.getInputOrProperty("offset"),g=this.getInputOrProperty("scale"),l=this.getInputOrProperty("amplitude"),m=this.getInputOrProperty("seed"),e=""+a+b+e+d+h+g+m+f[0]+f[1]+l;if(e!=this._key){this._key=e;var s=this._uniforms;s.u_persistence=d;s.u_octaves=h;s.u_offset.set(f);s.u_scale=g;
|
|
s.u_amplitude=l;s.u_seed=128*m;s.u_viewport[0]=a;s.u_viewport[1]=b;var n=H._shader;n||(n=H._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,H.pixel_shader));gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);c.drawTo(function(){n.uniforms(s).draw(GL.Mesh.getScreenQuad())})}this.setOutputData(0,c)}};H.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 u_offset;\n\t\t\tuniform float u_scale;\n\t\t\tuniform float u_persistence;\n\t\t\tuniform int u_octaves;\n\t\t\tuniform float u_amplitude;\n\t\t\tuniform vec2 u_viewport;\n\t\t\tuniform float u_seed;\n\t\t\t#define M_PI 3.14159265358979323846\n\t\t\t\n\t\t\tfloat rand(vec2 c){\treturn fract(sin(dot(c.xy ,vec2( 12.9898 + u_seed,78.233 + u_seed))) * 43758.5453); }\n\t\t\t\n\t\t\tfloat noise(vec2 p, float freq ){\n\t\t\t\tfloat unit = u_viewport.x/freq;\n\t\t\t\tvec2 ij = floor(p/unit);\n\t\t\t\tvec2 xy = mod(p,unit)/unit;\n\t\t\t\t//xy = 3.*xy*xy-2.*xy*xy*xy;\n\t\t\t\txy = .5*(1.-cos(M_PI*xy));\n\t\t\t\tfloat a = rand((ij+vec2(0.,0.)));\n\t\t\t\tfloat b = rand((ij+vec2(1.,0.)));\n\t\t\t\tfloat c = rand((ij+vec2(0.,1.)));\n\t\t\t\tfloat d = rand((ij+vec2(1.,1.)));\n\t\t\t\tfloat x1 = mix(a, b, xy.x);\n\t\t\t\tfloat x2 = mix(c, d, xy.x);\n\t\t\t\treturn mix(x1, x2, xy.y);\n\t\t\t}\n\t\t\t\n\t\t\tfloat pNoise(vec2 p, int res){\n\t\t\t\tfloat persistance = u_persistence;\n\t\t\t\tfloat n = 0.;\n\t\t\t\tfloat normK = 0.;\n\t\t\t\tfloat f = 4.;\n\t\t\t\tfloat amp = 1.0;\n\t\t\t\tint iCount = 0;\n\t\t\t\tfor (int i = 0; i<50; i++){\n\t\t\t\t\tn+=amp*noise(p, f);\n\t\t\t\t\tf*=2.;\n\t\t\t\t\tnormK+=amp;\n\t\t\t\t\tamp*=persistance;\n\t\t\t\t\tif (iCount >= res)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tiCount++;\n\t\t\t\t}\n\t\t\t\tfloat nf = n/normK;\n\t\t\t\treturn nf*nf*nf*nf;\n\t\t\t}\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord * u_scale * u_viewport + u_offset * u_scale;\n\t\t\t\tvec4 color = vec4( pNoise( uv, u_octaves ) * u_amplitude );\n\t\t\t\tgl_FragColor = color;\n\t\t\t}";
|
|
d.registerNodeType("texture/perlin",H);g=function(){this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,precision:k.DEFAULT};this._temp_texture=this._func=null};g.title="Canvas2D";g.desc="Executes Canvas2D code inside a texture or the viewport";g.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES},code:{type:"code"},width:{type:"Number",precision:0,step:1},height:{type:"Number",precision:0,step:1}};g.prototype.onPropertyChanged=function(a,b){if("code"==a&&d.allow_scripts){this._func=
|
|
null;try{this._func=new Function("canvas","ctx","time","script",b),this.boxcolor="#00FF00"}catch(e){this.boxcolor="#FF0000",console.error("Error parsing script"),console.error(e)}}};g.prototype.onExecute=function(){var a=this._func;if(a&&this.isOutputConnected(0))if(u.enableWebGLCanvas){var b=this.properties.width||gl.canvas.width,e=this.properties.height||gl.canvas.height,c=this._temp_texture;c&&c.width==b&&c.height==e||(c=this._temp_texture=new GL.Texture(b,e,{format:gl.RGBA,filter:gl.LINEAR}));
|
|
var d=this,h=this.graph.getTime();c.drawTo(function(){gl.start2D();try{a.draw?a.draw.call(d,gl.canvas,gl,h,a):a.call(d,gl.canvas,gl,h,a),d.boxcolor="#00FF00"}catch(b){d.boxcolor="#FF0000",console.error("Error executing script"),console.error(b)}gl.finish2D()});this.setOutputData(0,c)}else console.warn("cannot use LGraphTextureCanvas2D if Canvas2DtoWebGL is not included")};d.registerNodeType("texture/canvas2D",g);var I=function(){this.addInput("in","Texture");this.addOutput("out","Texture");this.properties=
|
|
{key_color:vec3.fromValues(0,1,0),threshold:0.8,slope:0.2,precision:k.DEFAULT}};I.title="Matte";I.desc="Extracts background";I.widgets_info={key_color:{widget:"color"},precision:{widget:"combo",values:k.MODE_VALUES}};I.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=k.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);
|
|
this._uniforms||(this._uniforms={u_texture:0,u_key_color:this.properties.key_color,u_threshold:1,u_slope:1});var b=this._uniforms,e=Mesh.getScreenQuad(),c=I._shader;c||(c=I._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,I.pixel_shader));b.u_key_color=this.properties.key_color;b.u_threshold=this.properties.threshold;b.u_slope=this.properties.slope;this._tex.drawTo(function(){a.bind(0);c.uniforms(b).draw(e)});this.setOutputData(0,this._tex)}}};I.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec3 u_key_color;\n\t\t\tuniform float u_threshold;\n\t\t\tuniform float u_slope;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec3 color = texture2D( u_texture, v_coord ).xyz;\n\t\t\t\tfloat diff = length( normalize(color) - normalize(u_key_color) );\n\t\t\t\tfloat edge = u_threshold * (1.0 - u_slope);\n\t\t\t\tfloat alpha = smoothstep( edge, u_threshold, diff);\n\t\t\t\tgl_FragColor = vec4( color, alpha );\n\t\t\t}";
|
|
d.registerNodeType("texture/matte",I);g=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[k.image_preview_size,k.image_preview_size]};g.title="Cubemap";g.prototype.onDropFile=function(a,b,e){a?(this._drop_texture="string"==typeof a?GL.Texture.fromURL(a):GL.Texture.fromDDSInMemory(a),this.properties.name=b):(this._drop_texture=null,this.properties.name="")};g.prototype.onExecute=function(){if(this._drop_texture)this.setOutputData(0,this._drop_texture);else if(this.properties.name){var a=
|
|
k.getTexture(this.properties.name);a&&(this._last_tex=a,this.setOutputData(0,a))}};g.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||a.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};d.registerNodeType("texture/cubemap",g)}})(this);
|
|
(function(u){var d=u.LiteGraph;if("undefined"!=typeof GL){var k=function(){this.addInput("Texture","Texture");this.addInput("Aberration","number");this.addInput("Distortion","number");this.addInput("Blur","number");this.addOutput("Texture","Texture");this.properties={aberration:1,distortion:1,blur:1,precision:LGraphTexture.DEFAULT};k._shader||(k._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,k.pixel_shader),k._texture=new GL.Texture(3,1,{format:gl.RGB,wrap:gl.CLAMP_TO_EDGE,magFilter:gl.LINEAR,
|
|
minFilter:gl.LINEAR,pixel_data:[255,0,0,0,255,0,0,0,255]}))};k.title="Lens";k.desc="Camera Lens distortion";k.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};k.prototype.onExecute=function(){var d=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,d);else if(d){this._tex=LGraphTexture.getTargetTexture(d,this._tex,this.properties.precision);var g=this.properties.aberration;this.isInputConnected(1)&&(g=this.getInputData(1),
|
|
this.properties.aberration=g);var q=this.properties.distortion;this.isInputConnected(2)&&(q=this.getInputData(2),this.properties.distortion=q);var r=this.properties.blur;this.isInputConnected(3)&&(r=this.getInputData(3),this.properties.blur=r);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var u=Mesh.getScreenQuad(),c=k._shader;this._tex.drawTo(function(){d.bind(0);c.uniforms({u_texture:0,u_aberration:g,u_distortion:q,u_blur:r}).draw(u)});this.setOutputData(0,this._tex)}};k.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("fx/lens",k);u.LGraphFXLens=k;var q=function(){this.addInput("Texture","Texture");this.addInput("Blurred","Texture");this.addInput("Mask","Texture");this.addInput("Threshold","number");this.addOutput("Texture","Texture");this.properties={shape:"",size:10,alpha:1,threshold:1,high_precision:!1}};q.title="Bokeh";q.desc="applies an Bokeh effect";q.widgets_info={shape:{widget:"texture"}};q.prototype.onExecute=function(){var d=this.getInputData(0),g=this.getInputData(1),k=this.getInputData(2);
|
|
if(d&&k&&this.properties.shape){g||(g=d);var r=LGraphTexture.getTexture(this.properties.shape);if(r){var u=this.properties.threshold;this.isInputConnected(3)&&(u=this.getInputData(3),this.properties.threshold=u);var c=gl.UNSIGNED_BYTE;this.properties.high_precision&&(c=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==c&&this._temp_texture.width==d.width&&this._temp_texture.height==d.height||(this._temp_texture=new GL.Texture(d.width,d.height,{type:c,format:gl.RGBA,
|
|
filter:gl.LINEAR}));var x=q._first_shader;x||(x=q._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,q._first_pixel_shader));var n=q._second_shader;n||(n=q._second_shader=new GL.Shader(q._second_vertex_shader,q._second_pixel_shader));var f=this._points_mesh;f&&f._width==d.width&&f._height==d.height&&2==f._spacing||(f=this.createPointsMesh(d.width,d.height,2));var A=Mesh.getScreenQuad(),h=this.properties.size,s=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){d.bind(0);
|
|
g.bind(1);k.bind(2);x.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[d.width,d.height]}).draw(A)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);d.bind(0);r.bind(3);n.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:s,u_threshold:u,u_pointSize:h,u_itexsize:[1/d.width,1/d.height]}).draw(f,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,d)};q.prototype.createPointsMesh=function(d,g,k){for(var q=Math.round(d/k),r=Math.round(g/
|
|
k),c=new Float32Array(q*r*2),u=-1,n=2/d*k,f=2/g*k,A=0;A<r;++A){for(var h=-1,s=0;s<q;++s){var v=A*q*2+2*s;c[v]=h;c[v+1]=u;h+=n}u+=f}this._points_mesh=GL.Mesh.load({vertices2D:c});this._points_mesh._width=d;this._points_mesh._height=g;this._points_mesh._spacing=k;return this._points_mesh};q._first_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_texture_blur;\n\t\t\tuniform sampler2D u_mask;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tvec4 blurred_color = texture2D(u_texture_blur, v_coord);\n\t\t\t\tfloat mask = texture2D(u_mask, v_coord).x;\n\t\t\t gl_FragColor = mix(color, blurred_color, mask);\n\t\t\t}\n\t\t\t";
|
|
q._second_vertex_shader="precision highp float;\n\t\t\tattribute vec2 a_vertex2D;\n\t\t\tvarying vec4 v_color;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_mask;\n\t\t\tuniform vec2 u_itexsize;\n\t\t\tuniform float u_pointSize;\n\t\t\tuniform float u_threshold;\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = a_vertex2D * 0.5 + 0.5;\n\t\t\t\tv_color = texture2D( u_texture, coord );\n\t\t\t\tv_color += texture2D( u_texture, coord + vec2(u_itexsize.x, 0.0) );\n\t\t\t\tv_color += texture2D( u_texture, coord + vec2(0.0, u_itexsize.y));\n\t\t\t\tv_color += texture2D( u_texture, coord + u_itexsize);\n\t\t\t\tv_color *= 0.25;\n\t\t\t\tfloat mask = texture2D(u_mask, coord).x;\n\t\t\t\tfloat luminance = length(v_color) * mask;\n\t\t\t\t/*luminance /= (u_pointSize*u_pointSize)*0.01 */;\n\t\t\t\tluminance -= u_threshold;\n\t\t\t\tif(luminance < 0.0)\n\t\t\t\t{\n\t\t\t\t\tgl_Position.x = -100.0;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tgl_PointSize = u_pointSize;\n\t\t\t\tgl_Position = vec4(a_vertex2D,0.0,1.0);\n\t\t\t}\n\t\t\t";
|
|
q._second_pixel_shader="precision highp float;\n\t\t\tvarying vec4 v_color;\n\t\t\tuniform sampler2D u_shape;\n\t\t\tuniform float u_alpha;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_shape, gl_PointCoord );\n\t\t\t\tcolor *= v_color * u_alpha;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n";d.registerNodeType("fx/bokeh",q);u.LGraphFXBokeh=q;var g=function(){this.addInput("Texture","Texture");this.addInput("value1","number");this.addInput("value2","number");this.addOutput("Texture",
|
|
"Texture");this.properties={fx:"halftone",value1:1,value2:1,precision:LGraphTexture.DEFAULT}};g.title="FX";g.desc="applies an FX from a list";g.widgets_info={fx:{widget:"combo",values:["halftone","pixelate","lowpalette","noise","gamma"]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};g.shaders={};g.prototype.onExecute=function(){if(this.isOutputConnected(0)){var d=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,d);else if(d){this._tex=
|
|
LGraphTexture.getTargetTexture(d,this._tex,this.properties.precision);var k=this.properties.value1;this.isInputConnected(1)&&(k=this.getInputData(1),this.properties.value1=k);var q=this.properties.value2;this.isInputConnected(2)&&(q=this.getInputData(2),this.properties.value2=q);var r=this.properties.fx,y=g.shaders[r];if(!y){var c=g["pixel_shader_"+r];if(!c)return;y=g.shaders[r]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,c)}gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var x=Mesh.getScreenQuad();
|
|
camera_planes=u.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var n=null;"noise"==r&&(n=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){d.bind(0);"noise"==r&&n.bind(1);y.uniforms({u_texture:0,u_noise:1,u_size:[d.width,d.height],u_rand:[Math.random(),Math.random()],u_value1:k,u_value2:q,u_camera_planes:camera_planes}).draw(x)});this.setOutputData(0,this._tex)}}};g.pixel_shader_halftone="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\t\n\t\t\tfloat pattern() {\n\t\t\t\tfloat s = sin(u_value1 * 3.1415), c = cos(u_value1 * 3.1415);\n\t\t\t\tvec2 tex = v_coord * u_size.xy;\n\t\t\t\tvec2 point = vec2(\n\t\t\t\t c * tex.x - s * tex.y ,\n\t\t\t\t s * tex.x + c * tex.y \n\t\t\t\t) * u_value2;\n\t\t\t\treturn (sin(point.x) * sin(point.y)) * 4.0;\n\t\t\t}\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tfloat average = (color.r + color.g + color.b) / 3.0;\n\t\t\t\tgl_FragColor = vec4(vec3(average * 10.0 - 5.0 + pattern()), color.a);\n\t\t\t}\n";
|
|
g.pixel_shader_pixelate="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = vec2( floor(v_coord.x * u_value1) / u_value1, floor(v_coord.y * u_value2) / u_value2 );\n\t\t\t\tvec4 color = texture2D(u_texture, coord);\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n";g.pixel_shader_lowpalette="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tgl_FragColor = floor(color * u_value1) / u_value1;\n\t\t\t}\n";
|
|
g.pixel_shader_noise="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_noise;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\tuniform vec2 u_rand;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tvec3 noise = texture2D(u_noise, v_coord * vec2(u_size.x / 512.0, u_size.y / 512.0) + u_rand).xyz - vec3(0.5);\n\t\t\t\tgl_FragColor = vec4( color.xyz + noise * u_value1, color.a );\n\t\t\t}\n";
|
|
g.pixel_shader_gamma="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_value1;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tfloat gamma = 1.0 / u_value1;\n\t\t\t\tgl_FragColor = vec4( pow( color.xyz, vec3(gamma) ), color.a );\n\t\t\t}\n";d.registerNodeType("fx/generic",g);u.LGraphFXGeneric=g;var r=function(){this.addInput("Tex.","Texture");this.addInput("intensity","number");this.addOutput("Texture",
|
|
"Texture");this.properties={intensity:1,invert:!1,precision:LGraphTexture.DEFAULT};r._shader||(r._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,r.pixel_shader))};r.title="Vigneting";r.desc="Vigneting";r.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};r.prototype.onExecute=function(){var d=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,d);else if(d){this._tex=LGraphTexture.getTargetTexture(d,this._tex,this.properties.precision);
|
|
var g=this.properties.intensity;this.isInputConnected(1)&&(g=this.getInputData(1),this.properties.intensity=g);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var k=Mesh.getScreenQuad(),q=r._shader,u=this.properties.invert;this._tex.drawTo(function(){d.bind(0);q.uniforms({u_texture:0,u_intensity:g,u_isize:[1/d.width,1/d.height],u_invert:u?1:0}).draw(k)});this.setOutputData(0,this._tex)}};r.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_intensity;\n\t\t\tuniform int u_invert;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat luminance = 1.0 - length( v_coord - vec2(0.5) ) * 1.414;\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tif(u_invert == 1)\n\t\t\t\t\tluminance = 1.0 - luminance;\n\t\t\t\tluminance = mix(1.0, luminance, u_intensity);\n\t\t\t gl_FragColor = vec4( luminance * color.xyz, color.a);\n\t\t\t}\n\t\t\t";
|
|
d.registerNodeType("fx/vigneting",r);u.LGraphFXVigneting=r}})(this);
|
|
(function(u){function d(c){this.cmd=this.channel=0;this.data=new Uint32Array(3);c&&this.setup(c)}function k(c,d){navigator.requestMIDIAccess?(this.on_ready=c,this.state={note:[],cc:[]},navigator.requestMIDIAccess().then(this.onMIDISuccess.bind(this),this.onMIDIFailure.bind(this))):(this.error="not suppoorted",d?d("Not supported"):console.error("MIDI NOT SUPPORTED, enable by chrome://flags"))}function q(){this.addOutput("on_midi",f.EVENT);this.addOutput("out","midi");this.properties={port:0};this._current_midi_event=
|
|
this._last_midi_event=null;this.boxcolor="#AAA";this._last_time=0;var c=this;new k(function(d){c._midi=d;if(c._waiting)c.onStart();c._waiting=!1})}function g(){this.addInput("send",f.EVENT);this.properties={port:0};var c=this;new k(function(d){c._midi=d})}function r(){this.addInput("on_midi",f.EVENT);this._str="";this.size=[200,40]}function m(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};var c=this;this._learning=!1;this.addWidget("button","Learn","",function(){c._learning=!0;c.boxcolor=
|
|
"#FA3"});this.addInput("in",f.EVENT);this.addOutput("on_midi",f.EVENT);this.boxcolor="#AAA"}function w(){this.properties={channel:0,cmd:144,value1:1,value2:1};this.addInput("send",f.EVENT);this.addInput("assign",f.EVENT);this.addOutput("on_midi",f.EVENT);this.midi_event=new d;this.gate=!1}function B(){this.properties={cc:1,value:0};this.addOutput("value","number")}function z(){this.addInput("generate",f.ACTION);this.addInput("scale","string");this.addInput("octave","number");this.addOutput("note",
|
|
f.EVENT);this.properties={notes:"A,A#,B,C,C#,D,D#,E,F,F#,G,G#",octave:2,duration:0.5,mode:"sequence"};this.notes_pitches=z.processScale(this.properties.notes);this.sequence_index=0}function y(){this.properties={amount:0};this.addInput("in",f.ACTION);this.addInput("amount","number");this.addOutput("out",f.EVENT);this.midi_event=new d}function c(){this.properties={scale:"A,A#,B,C,C#,D,D#,E,F,F#,G,G#"};this.addInput("note",f.ACTION);this.addInput("scale","string");this.addOutput("out",f.EVENT);this.valid_notes=
|
|
Array(12);this.offset_notes=Array(12);this.processScale(this.properties.scale)}function x(){this.properties={volume:0.5,duration:1};this.addInput("note",f.ACTION);this.addInput("volume","number");this.addInput("duration","number");this.addOutput("note",f.EVENT);"undefined"==typeof AudioSynth?(console.error("Audiosynth.js not included, LGMidiPlay requires that library"),this.boxcolor="red"):this.instrument=(this.synth=new AudioSynth).createInstrument("piano")}function n(){this.properties={num_octaves:2,
|
|
start_octave:2};this.addInput("note",f.ACTION);this.addInput("reset",f.ACTION);this.addOutput("note",f.EVENT);this.size=[400,100];this.keys=[];this._last_key=-1}var f=u.LiteGraph;f.MIDIEvent=d;d.prototype.fromJSON=function(c){this.setup(c.data)};d.prototype.setup=function(c){var f=c;c.constructor===Object&&(f=c.data);this.data.set(f);this.status=c=f[0];f=c&240;this.cmd=240<=c?c:f;this.cmd==d.NOTEON&&0==this.velocity&&(this.cmd=d.NOTEOFF);this.cmd_str=d.commands[this.cmd]||"";if(f>=d.NOTEON||f<=d.NOTEOFF)this.channel=
|
|
c&15};Object.defineProperty(d.prototype,"velocity",{get:function(){return this.cmd==d.NOTEON?this.data[2]:-1},set:function(c){this.data[2]=c},enumerable:!0});d.notes="A A# B C C# D D# E F F# G G#".split(" ");d.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(d.prototype,"note",{get:function(){return this.cmd!=d.NOTEON?-1:d.toNoteString(this.data[1],!0)},set:function(c){throw"notes cannot be assigned this way, must modify the data[1]";},enumerable:!0});
|
|
Object.defineProperty(d.prototype,"octave",{get:function(){return this.cmd!=d.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});d.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};d.computePitch=function(c){return 440*Math.pow(2,(c-69)/12)};d.prototype.getCC=function(){return this.data[1]};d.prototype.getCCValue=function(){return this.data[2]};d.prototype.getPitchBend=function(){return this.data[1]+
|
|
(this.data[2]<<7)-8192};d.computePitchBend=function(c,d){return c+(d<<7)-8192};d.prototype.setCommandFromString=function(c){this.cmd=d.computeCommandFromString(c)};d.computeCommandFromString=function(c){if(!c)return 0;if(c&&c.constructor===Number)return c;c=c.toUpperCase();switch(c){case "NOTE ON":case "NOTEON":return d.NOTEON;case "NOTE OFF":case "NOTEOFF":return d.NOTEON;case "KEY PRESSURE":case "KEYPRESSURE":return d.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return d.CONTROLLERCHANGE;
|
|
case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return d.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return d.CHANNELPRESSURE;case "PITCH BEND":case "PITCHBEND":return d.PITCHBEND;case "TIME TICK":case "TIMETICK":return d.TIMETICK;default:return Number(c)}};d.toNoteString=function(c,f){c=Math.round(c);var g,a=Math.floor((c-24)/12+1);g=(c-21)%12;0>g&&(g=12+g);return d.notes[g]+(f?"":a)};d.NoteStringToPitch=function(c){c=c.toUpperCase();var f=c[0],g=4;"#"==c[1]?(f+="#",2<c.length&&
|
|
(g=Number(c[2]))):1<c.length&&(g=Number(c[1]));c=d.note_to_index[f];return null==c?null:12*(g-1)+c+21};d.prototype.toString=function(){var c=""+this.channel+". ";switch(this.cmd){case d.NOTEON:c+="NOTEON "+d.toNoteString(this.data[1]);break;case d.NOTEOFF:c+="NOTEOFF "+d.toNoteString(this.data[1]);break;case d.CONTROLLERCHANGE:c+="CC "+this.data[1]+" "+this.data[2];break;case d.PROGRAMCHANGE:c+="PC "+this.data[1];break;case d.PITCHBEND:c+="PITCHBEND "+this.getPitchBend();break;case d.KEYPRESSURE:c+=
|
|
"KEYPRESS "+this.data[1]}return c};d.prototype.toHexString=function(){for(var c="",d=0;d<this.data.length;d++)c+=this.data[d].toString(16)+" "};d.prototype.toJSON=function(){return{data:[this.data[0],this.data[1],this.data[2]],object_class:"MIDIEvent"}};d.NOTEOFF=128;d.NOTEON=144;d.KEYPRESSURE=160;d.CONTROLLERCHANGE=176;d.PROGRAMCHANGE=192;d.CHANNELPRESSURE=208;d.PITCHBEND=224;d.TIMETICK=248;d.commands={128:"note off",144:"note on",160:"key pressure",176:"controller change",192:"program change",208:"channel pressure",
|
|
224:"pitch bend",240:"system",242:"Song pos",243:"Song select",246:"Tune request",248:"time tick",250:"Start Song",251:"Continue Song",252:"Stop Song",254:"Sensing",255:"Reset"};d.commands_short={128:"NOTEOFF",144:"NOTEOFF",160:"KEYP",176:"CC",192:"PC",208:"CP",224:"PB",240:"SYS",242:"POS",243:"SELECT",246:"TUNEREQ",248:"TT",250:"START",251:"CONTINUE",252:"STOP",254:"SENS",255:"RESET"};d.commands_reversed={};for(var A in d.commands)d.commands_reversed[d.commands[A]]=A;k.input=null;k.MIDIEvent=d;k.prototype.onMIDISuccess=
|
|
function(c){console.log("MIDI ready!");console.log(c);this.midi=c;this.updatePorts();if(this.on_ready)this.on_ready(this)};k.prototype.updatePorts=function(){var c=this.midi;this.input_ports=c.inputs;for(var d=0,f=this.input_ports.values(),a=f.next();a&&!1===a.done;)a=a.value,console.log("Input port [type:'"+a.type+"'] id:'"+a.id+"' manufacturer:'"+a.manufacturer+"' name:'"+a.name+"' version:'"+a.version+"'"),d++,a=f.next();this.num_input_ports=d;d=0;this.output_ports=c.outputs;f=this.output_ports.values();
|
|
for(a=f.next();a&&!1===a.done;)a=a.value,console.log("Output port [type:'"+a.type+"'] id:'"+a.id+"' manufacturer:'"+a.manufacturer+"' name:'"+a.name+"' version:'"+a.version+"'"),d++,a=f.next();this.num_output_ports=d};k.prototype.onMIDIFailure=function(c){console.error("Failed to get MIDI access - "+c)};k.prototype.openInputPort=function(c,f){var g=this.input_ports.get("input-"+c);if(!g)return!1;k.input=this;var a=this;g.onmidimessage=function(b){var c=new d(b.data);a.updateState(c);f&&f(b.data,c);
|
|
if(k.on_message)k.on_message(b.data,c)};console.log("port open: ",g);return!0};k.parseMsg=function(c){};k.prototype.updateState=function(c){switch(c.cmd){case d.NOTEON:this.state.note[c.value1|0]=c.value2;break;case d.NOTEOFF:this.state.note[c.value1|0]=0;break;case d.CONTROLLERCHANGE:this.state.cc[c.getCC()]=c.getCCValue()}};k.prototype.sendMIDI=function(c,f){if(f){var g=this.output_ports.get("output-"+c);g&&(k.output=this,f.constructor===d?g.send(f.data):g.send(f))}};q.MIDIInterface=k;q.title="MIDI Input";
|
|
q.desc="Reads MIDI from a input port";q.color="#243";q.prototype.getPropertyInfo=function(c){if(this._midi&&"port"==c){c={};for(var d=0;d<this._midi.input_ports.size;++d){var f=this._midi.input_ports.get("input-"+d);c[d]=d+".- "+f.name+" version:"+f.version}return{type:"enum",values:c}}};q.prototype.onStart=function(){this._midi?this._midi.openInputPort(this.properties.port,this.onMIDIEvent.bind(this)):this._waiting=!0};q.prototype.onMIDIEvent=function(c,g){this._last_midi_event=g;this.boxcolor="#AFA";
|
|
this._last_time=f.getTime();this.trigger("on_midi",g);g.cmd==d.NOTEON?this.trigger("on_noteon",g):g.cmd==d.NOTEOFF?this.trigger("on_noteoff",g):g.cmd==d.CONTROLLERCHANGE?this.trigger("on_cc",g):g.cmd==d.PROGRAMCHANGE?this.trigger("on_pc",g):g.cmd==d.PITCHBEND&&this.trigger("on_pitchbend",g)};q.prototype.onDrawBackground=function(c){this.boxcolor="#AAA";if(!this.flags.collapsed&&this._last_midi_event){c.fillStyle="white";var d=f.getTime(),d=1-Math.max(0,0.001*(d-this._last_time));if(0<d){var g=c.globalAlpha;
|
|
c.globalAlpha*=d;c.font="12px Tahoma";c.fillText(this._last_midi_event.toString(),2,0.5*this.size[1]+3);c.globalAlpha=g}}};q.prototype.onExecute=function(){if(this.outputs)for(var c=this._last_midi_event,d=0;d<this.outputs.length;++d){var f=null;switch(this.outputs[d].name){case "midi":f=this._midi;break;case "last_midi":f=c;break;default:continue}this.setOutputData(d,f)}};q.prototype.onGetOutputs=function(){return[["last_midi","midi"],["on_midi",f.EVENT],["on_noteon",f.EVENT],["on_noteoff",f.EVENT],
|
|
["on_cc",f.EVENT],["on_pc",f.EVENT],["on_pitchbend",f.EVENT]]};f.registerNodeType("midi/input",q);g.MIDIInterface=k;g.title="MIDI Output";g.desc="Sends MIDI to output channel";g.color="#243";g.prototype.getPropertyInfo=function(c){if(this._midi&&"port"==c){c={};for(var d=0;d<this._midi.output_ports.size;++d){var f=this._midi.output_ports.get(d);c[d]=d+".- "+f.name+" version:"+f.version}return{type:"enum",values:c}}};g.prototype.onAction=function(c,d){this._midi&&("send"==c&&this._midi.sendMIDI(this.port,
|
|
d),this.trigger("midi",d))};g.prototype.onGetInputs=function(){return[["send",f.ACTION]]};g.prototype.onGetOutputs=function(){return[["on_midi",f.EVENT]]};f.registerNodeType("midi/output",g);r.title="MIDI Show";r.desc="Shows MIDI in the graph";r.color="#243";r.prototype.getTitle=function(){return this.flags.collapsed?this._str:this.title};r.prototype.onAction=function(c,f){f&&(this._str=f.constructor===d?f.toString():"???")};r.prototype.onDrawForeground=function(c){this._str&&!this.flags.collapsed&&
|
|
(c.font="30px Arial",c.fillText(this._str,10,0.8*this.size[1]))};r.prototype.onGetInputs=function(){return[["in",f.ACTION]]};r.prototype.onGetOutputs=function(){return[["on_midi",f.EVENT]]};f.registerNodeType("midi/show",r);m.title="MIDI Filter";m.desc="Filters MIDI messages";m.color="#243";m["@cmd"]={type:"enum",title:"Command",values:d.commands_reversed};m.prototype.getTitle=function(){var c=null,c=-1==this.properties.cmd?"Nothing":d.commands_short[this.properties.cmd]||"Unknown";-1!=this.properties.min_value&&
|
|
-1!=this.properties.max_value&&(c+=" "+(this.properties.min_value==this.properties.max_value?this.properties.max_value:this.properties.min_value+".."+this.properties.max_value));return"Filter: "+c};m.prototype.onPropertyChanged=function(c,f){if("cmd"==c){var g=Number(f);isNaN(g)&&(g=d.commands[f]||0);this.properties.cmd=g}};m.prototype.onAction=function(c,f){if(f&&f.constructor===d){if(this._learning)this._learning=!1,this.boxcolor="#AAA",this.properties.channel=f.channel,this.properties.cmd=f.cmd,
|
|
this.properties.min_value=this.properties.max_value=f.data[1];else if(-1!=this.properties.channel&&f.channel!=this.properties.channel||-1!=this.properties.cmd&&f.cmd!=this.properties.cmd||-1!=this.properties.min_value&&f.data[1]<this.properties.min_value||-1!=this.properties.max_value&&f.data[1]>this.properties.max_value)return;this.trigger("on_midi",f)}};f.registerNodeType("midi/filter",m);w.title="MIDIEvent";w.desc="Create a MIDI Event";w.color="#243";w.prototype.onAction=function(c,f){"assign"==
|
|
c?(this.properties.channel=f.channel,this.properties.cmd=f.cmd,this.properties.value1=f.data[1],this.properties.value2=f.data[2],f.cmd==d.NOTEON?this.gate=!0:f.cmd==d.NOTEOFF&&(this.gate=!1)):(f=this.midi_event,f.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?f.setCommandFromString(this.properties.cmd):f.cmd=this.properties.cmd,f.data[0]=f.cmd|f.channel,f.data[1]=Number(this.properties.value1),f.data[2]=Number(this.properties.value2),this.trigger("on_midi",
|
|
f))};w.prototype.onExecute=function(){var c=this.properties;if(this.inputs)for(var f=0;f<this.inputs.length;++f){var g=this.inputs[f];if(-1!=g.link)switch(g.name){case "note":g=this.getInputData(f),null!=g&&(g.constructor===String&&(g=d.NoteStringToPitch(g)),this.properties.value1=(g|0)%255)}}if(this.outputs)for(f=0;f<this.outputs.length;++f){switch(this.outputs[f].name){case "midi":g=new d;g.setup([c.cmd,c.value1,c.value2]);g.channel=c.channel;break;case "command":g=c.cmd;break;case "cc":g=c.value1;
|
|
break;case "cc_value":g=c.value2;break;case "note":g=c.cmd==d.NOTEON||c.cmd==d.NOTEOFF?c.value1:null;break;case "velocity":g=c.cmd==d.NOTEON?c.value2:null;break;case "pitch":g=c.cmd==d.NOTEON?d.computePitch(c.value1):null;break;case "pitchbend":g=c.cmd==d.PITCHBEND?d.computePitchBend(c.value1,c.value2):null;break;case "gate":g=this.gate;break;default:continue}null!==g&&this.setOutputData(f,g)}};w.prototype.onPropertyChanged=function(c,f){"cmd"==c&&(this.properties.cmd=d.computeCommandFromString(f))};
|
|
w.prototype.onGetInputs=function(){return[["note","number"]]};w.prototype.onGetOutputs=function(){return[["midi","midi"],["on_midi",f.EVENT],["command","number"],["note","number"],["velocity","number"],["cc","number"],["cc_value","number"],["pitch","number"],["gate","bool"],["pitchbend","number"]]};f.registerNodeType("midi/event",w);B.title="MIDICC";B.desc="gets a Controller Change";B.color="#243";B.prototype.onExecute=function(){k.input&&(this.properties.value=k.input.state.cc[this.properties.cc]);
|
|
this.setOutputData(0,this.properties.value)};f.registerNodeType("midi/cc",B);z.title="MIDI Generator";z.desc="Generates a random MIDI note";z.color="#243";z.processScale=function(c){c=c.split(",");for(var g=0;g<c.length;++g){var k=c[g];c[g]=2==k.length&&"#"!=k[1]||2<k.length?-f.MIDIEvent.NoteStringToPitch(k):d.note_to_index[k]||0}return c};z.prototype.onPropertyChanged=function(c,d){"notes"==c&&(this.notes_pitches=z.processScale(d))};z.prototype.onExecute=function(){var c=this.getInputData(2);null!=
|
|
c&&(this.properties.octave=c);if(c=this.getInputData(1))this.notes_pitches=z.processScale(c)};z.prototype.onAction=function(c,f){var g=0,a=this.notes_pitches.length,b=0;"sequence"==this.properties.mode?b=this.sequence_index=(this.sequence_index+1)%a:"random"==this.properties.mode&&(b=Math.floor(Math.random()*a));a=this.notes_pitches[b];g=0<=a?a+12*(this.properties.octave-1)+33:-a;f=new d;f.setup([d.NOTEON,g,10]);a=this.properties.duration||1;this.trigger("note",f);setTimeout(function(){var a=new d;
|
|
a.setup([d.NOTEOFF,g,0]);this.trigger("note",a)}.bind(this),1E3*a)};f.registerNodeType("midi/generator",z);y.title="MIDI Transpose";y.desc="Transpose a MIDI note";y.color="#243";y.prototype.onAction=function(c,f){f&&f.constructor===d&&(f.data[0]==d.NOTEON||f.data[0]==d.NOTEOFF?(this.midi_event=new d,this.midi_event.setup(f.data),this.midi_event.data[1]=Math.round(this.midi_event.data[1]+this.properties.amount),this.trigger("out",this.midi_event)):this.trigger("out",f))};y.prototype.onExecute=function(){var c=
|
|
this.getInputData(1);null!=c&&(this.properties.amount=c)};f.registerNodeType("midi/transpose",y);c.title="MIDI Quantize Pitch";c.desc="Transpose a MIDI note tp fit an scale";c.color="#243";c.prototype.onPropertyChanged=function(c,d){"scale"==c&&this.processScale(d)};c.prototype.processScale=function(c){this._current_scale=c;this.notes_pitches=z.processScale(c);for(c=0;12>c;++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 d=
|
|
1;12>d;++d){if(this.valid_notes[(c-d)%12]){this.offset_notes[c]=-d;break}if(this.valid_notes[(c+d)%12]){this.offset_notes[c]=d;break}}};c.prototype.onAction=function(c,f){f&&f.constructor===d&&(f.data[0]==d.NOTEON||f.data[0]==d.NOTEOFF?(this.midi_event=new d,this.midi_event.setup(f.data),this.midi_event.data[1]+=this.offset_notes[d.note_to_index[f.note]],this.trigger("out",this.midi_event)):this.trigger("out",f))};c.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&&
|
|
this.processScale(c)};f.registerNodeType("midi/quantize",c);x.title="MIDI Play";x.desc="Plays a MIDI note";x.color="#243";x.prototype.onAction=function(c,f){if(f&&f.constructor===d){if(this.instrument&&f.data[0]==d.NOTEON){var g=f.note;if(!g||"undefined"==g||g.constructor!==String)return;this.instrument.play(g,f.octave,this.properties.duration,this.properties.volume)}this.trigger("note",f)}};x.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&(this.properties.volume=c);c=this.getInputData(2);
|
|
null!=c&&(this.properties.duration=c)};f.registerNodeType("midi/play",x);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 d=12*this.properties.num_octaves;
|
|
this.keys.length=d;var f=this.size[0]/(7*this.properties.num_octaves),a=this.size[1];c.globalAlpha=1;for(var b=0;2>b;b++)for(var e=0;e<d;++e){var g=n.keys[e%12];if(g.t==b){var l=7*Math.floor(e/12)*f+g.x*f;c.fillStyle=0==b?this.keys[e]?"#CCC":"white":this.keys[e]?"#333":"black";c.fillRect(l+1,0,f*g.w-2,a*g.h)}}}};n.prototype.getKeyIndex=function(c){for(var d=this.size[0]/(7*this.properties.num_octaves),f=this.size[1],a=1;0<=a;a--)for(var b=0;b<this.keys.length;++b){var e=n.keys[b%12];if(e.t==a){var g=
|
|
7*Math.floor(b/12)*d+e.x*d,l=d*e.w,e=f*e.h;if(!(c[0]<g||c[0]>g+l||c[1]>e))return b}}return-1};n.prototype.onAction=function(c,f){if("reset"==c)for(var g=0;g<this.keys.length;++g)this.keys[g]=!1;else f&&f.constructor===d&&(g=f.data[1]-(12*(this.properties.start_octave-1)+29),0<=g&&g<this.keys.length&&(f.data[0]==d.NOTEON?this.keys[g]=!0:f.data[0]==d.NOTEOFF&&(this.keys[g]=!1)),this.trigger("note",f))};n.prototype.onMouseDown=function(c,f){if(!(0>f[1])){var g=this.getKeyIndex(f);this.keys[g]=!0;this._last_key=
|
|
g;var g=12*(this.properties.start_octave-1)+29+g,a=new d;a.setup([d.NOTEON,g,100]);this.trigger("note",a);return!0}};n.prototype.onMouseMove=function(c,f){if(!(0>f[1]||-1==this._last_key)){this.setDirtyCanvas(!0);var g=this.getKeyIndex(f);if(this._last_key==g)return!0;this.keys[this._last_key]=!1;var a=12*(this.properties.start_octave-1)+29+this._last_key,b=new d;b.setup([d.NOTEOFF,a,100]);this.trigger("note",b);this.keys[g]=!0;a=12*(this.properties.start_octave-1)+29+g;b=new d;b.setup([d.NOTEON,
|
|
a,100]);this.trigger("note",b);this._last_key=g;return!0}};n.prototype.onMouseUp=function(c,f){if(!(0>f[1])){var g=this.getKeyIndex(f);this.keys[g]=!1;this._last_key=-1;var g=12*(this.properties.start_octave-1)+29+g,a=new d;a.setup([d.NOTEOFF,g,100]);this.trigger("note",a);return!0}};f.registerNodeType("midi/keys",n)})(this);
|
|
(function(u){function d(){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=v.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function k(){this.properties={gain:0.5};this._audionodes=[];this._media_stream=
|
|
null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=v.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function q(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:0.5};this.audionode=v.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 g(){this.properties={gain:1};this.audionode=v.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function r(){this.properties={impulse_src:"",normalize:!0};this.audionode=v.getAudioContext().createConvolver();
|
|
this.addInput("in","audio");this.addOutput("out","audio")}function m(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=v.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function w(){this.properties={};this.audionode=v.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function B(){this.properties={gain1:0.5,gain2:0.5};
|
|
this.audionode=v.getAudioContext().createGain();this.audionode1=v.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=v.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 z(){this.properties=
|
|
{A:0.1,D:0.1,S:0.1,R:0.1};this.audionode=v.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","bool");this.addOutput("out","audio");this.gate=!1}function y(){this.properties={delayTime:0.5};this.audionode=v.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function c(){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=v.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function x(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=v.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 f(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function A(){if(!A.default_code){var a=A.default_function.toString(),b=a.indexOf("{")+1,c=a.lastIndexOf("}");A.default_code=a.substr(b,c-b)}this.properties={code:A.default_code};a=v.getAudioContext();a.createScriptProcessor?this.audionode=a.createScriptProcessor(4096,
|
|
1,1):(console.warn("ScriptProcessorNode deprecated"),this.audionode=a.createGain());this.processCode();A._bypass_function||(A._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function h(){this.audionode=v.getAudioContext().destination;this.addInput("in","audio")}var s=u.LiteGraph,v={};u.LGAudio=v;v.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(a){console.log("msg",a)};this._audio_context.onended=function(a){console.log("ended",a)};this._audio_context.oncomplete=function(a){console.log("complete",a)}}return this._audio_context};v.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};v.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};v.changeAllAudiosConnections=function(a,b){if(a.inputs)for(var c=
|
|
0;c<a.inputs.length;++c){var d=a.graph.links[a.inputs[c].link];if(d){var f=a.graph.getNodeById(d.origin_id),g=null,g=f.getAudioNodeInOutputSlot?f.getAudioNodeInOutputSlot(d.origin_slot):f.audionode,d=null,d=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(c):a.audionode;b?v.connect(g,d):v.disconnect(g,d)}}if(a.outputs)for(c=0;c<a.outputs.length;++c)for(var f=a.outputs[c],h=0;h<f.links.length;++h)if(d=a.graph.links[f.links[h]]){var g=a.getAudioNodeInOutputSlot?a.getAudioNodeInOutputSlot(c):a.audionode,
|
|
k=a.graph.getNodeById(d.target_id),d=k.getAudioNodeInInputSlot?k.getAudioNodeInInputSlot(d.target_slot):k.audionode;b?v.connect(g,d):v.disconnect(g,d)}};v.onConnectionsChange=function(a,b,c,d){if(a==s.OUTPUT&&(a=null,d&&(a=this.graph.getNodeById(d.target_id)),a)){var f=null,f=this.getAudioNodeInOutputSlot?this.getAudioNodeInOutputSlot(b):this.audionode;b=null;b=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(d.target_slot):a.audionode;c?v.connect(f,b):v.disconnect(f,b)}};v.createAudioNodeWrapper=
|
|
function(a){var b=a.prototype.onPropertyChanged;a.prototype.onPropertyChanged=function(a,c){b&&b.call(this,a,c);this.audionode&&void 0!==this.audionode[a]&&(void 0!==this.audionode[a].value?this.audionode[a].value=c:this.audionode[a]=c)};a.prototype.onConnectionsChange=v.onConnectionsChange};v.cached_audios={};v.loadSound=function(a,b,c){function d(a){console.log("Audio loading sample error:",a);c&&c(a)}if(v.cached_audios[a]&&-1==a.indexOf("blob:"))b&&b(v.cached_audios[a]);else{v.onProcessAudioURL&&
|
|
(a=v.onProcessAudioURL(a));var f=new XMLHttpRequest;f.open("GET",a,!0);f.responseType="arraybuffer";var g=v.getAudioContext();f.onload=function(){console.log("AudioSource loaded");g.decodeAudioData(f.response,function(c){console.log("AudioSource decoded");v.cached_audios[a]=c;b&&b(c)},d)};f.send();return f}};d["@src"]={widget:"resource"};d.supported_extensions=["wav","ogg","mp3"];d.prototype.onAdded=function(a){if(a.status===LGraph.STATUS_RUNNING)this.onStart()};d.prototype.onStart=function(){this._audiobuffer&&
|
|
this.properties.autoplay&&this.playBuffer(this._audiobuffer)};d.prototype.onStop=function(){this.stopAllSounds()};d.prototype.onPause=function(){this.pauseAllSounds()};d.prototype.onUnpause=function(){this.unpauseAllSounds()};d.prototype.onRemoved=function(){this.stopAllSounds();this._dropped_url&&URL.revokeObjectURL(this._url)};d.prototype.stopAllSounds=function(){for(var a=0;a<this._audionodes.length;++a)this._audionodes[a].started&&(this._audionodes[a].started=!1,this._audionodes[a].stop());this._audionodes.length=
|
|
0};d.prototype.pauseAllSounds=function(){v.getAudioContext().suspend()};d.prototype.unpauseAllSounds=function(){v.getAudioContext().resume()};d.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;++a){var b=this.inputs[a];if(null!=b.link){var c=this.getInputData(a);if(void 0!==c)if("gain"==b.name)this.audionode.gain.value=c;else if("playbackRate"==b.name)for(this.properties.playbackRate=c,b=0;b<this._audionodes.length;++b)this._audionodes[b].playbackRate.value=c}}if(this.outputs)for(a=
|
|
0;a<this.outputs.length;++a)"buffer"==this.outputs[a].name&&this._audiobuffer&&this.setOutputData(a,this._audiobuffer)};d.prototype.onAction=function(a){this._audiobuffer&&("Play"==a?this.playBuffer(this._audiobuffer):"Stop"==a&&this.stopAllSounds())};d.prototype.onPropertyChanged=function(a,b){if("src"==a)this.loadSound(b);else if("gain"==a)this.audionode.gain.value=b;else if("playbackRate"==a)for(var c=0;c<this._audionodes.length;++c)this._audionodes[c].playbackRate.value=b};d.prototype.playBuffer=
|
|
function(a){var b=this,c=v.getAudioContext().createBufferSource();this._last_sourcenode=c;c.graphnode=this;c.buffer=a;c.loop=this.properties.loop;c.playbackRate.value=this.properties.playbackRate;this._audionodes.push(c);c.connect(this.audionode);this._audionodes.push(c);c.onended=function(){b.trigger("ended");var a=b._audionodes.indexOf(c);-1!=a&&b._audionodes.splice(a,1)};c.started||(c.started=!0,c.start());return c};d.prototype.loadSound=function(a){function b(a){this.boxcolor=s.NODE_DEFAULT_BOXCOLOR;
|
|
c._audiobuffer=a;c._loading_audio=!1;if(c.graph&&c.graph.status===LGraph.STATUS_RUNNING)c.onStart()}var c=this;this._request&&(this._request.abort(),this._request=null);this._audiobuffer=null;this._loading_audio=!1;a&&(this._request=v.loadSound(a,b),this._loading_audio=!0,this.boxcolor="#AA4")};d.prototype.onConnectionsChange=v.onConnectionsChange;d.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",s.ACTION],["Stop",s.ACTION]]};d.prototype.onGetOutputs=function(){return[["buffer",
|
|
"audiobuffer"],["ended",s.EVENT]]};d.prototype.onDropFile=function(a){this._dropped_url&&URL.revokeObjectURL(this._dropped_url);a=URL.createObjectURL(a);this.properties.src=a;this.loadSound(a);this._dropped_url=a};d.title="Source";d.desc="Plays audio";s.registerNodeType("audio/source",d);k.prototype.onAdded=function(a){if(a.status===LGraph.STATUS_RUNNING)this.onStart()};k.prototype.onStart=function(){null!=this._media_stream||this._waiting_confirmation||this.openStream()};k.prototype.onStop=function(){this.audionode.gain.value=
|
|
0};k.prototype.onPause=function(){this.audionode.gain.value=0};k.prototype.onUnpause=function(){this.audionode.gain.value=this.properties.gain};k.prototype.onRemoved=function(){this.audionode.gain.value=0;this.audiosource_node&&(this.audiosource_node.disconnect(this.audionode),this.audiosource_node=null);if(this._media_stream){var a=this._media_stream.getTracks();a.length&&a[0].stop()}};k.prototype.openStream=function(){function a(a){console.log("Media rejected",a);b._media_stream=!1;b.boxcolor="red"}
|
|
if(navigator.mediaDevices){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then(this.streamReady.bind(this))["catch"](a);var b=this}else console.log("getUserMedia() is not supported in your browser, use chrome and enable WebRTC from about://flags")};k.prototype.streamReady=function(a){this._media_stream=a;this.audiosource_node&&this.audiosource_node.disconnect(this.audionode);this.audiosource_node=v.getAudioContext().createMediaStreamSource(a);this.audiosource_node.graphnode=
|
|
this;this.audiosource_node.connect(this.audionode);this.boxcolor="white"};k.prototype.onExecute=function(){null!=this._media_stream||this._waiting_confirmation||this.openStream();if(this.inputs)for(var a=0;a<this.inputs.length;++a){var b=this.inputs[a];if(null!=b.link){var c=this.getInputData(a);void 0!==c&&"gain"==b.name&&(this.audionode.gain.value=this.properties.gain=c)}}};k.prototype.onAction=function(a){"Play"==a?this.audionode.gain.value=this.properties.gain:"Stop"==a&&(this.audionode.gain.value=
|
|
0)};k.prototype.onPropertyChanged=function(a,b){"gain"==a&&(this.audionode.gain.value=b)};k.prototype.onConnectionsChange=v.onConnectionsChange;k.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",s.ACTION],["Stop",s.ACTION]]};k.title="MediaSource";k.desc="Plays microphone";s.registerNodeType("audio/media_source",k);q.prototype.onPropertyChanged=function(a,b){this.audionode[a]=b};q.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.audionode.frequencyBinCount;
|
|
this._freq_bin&&this._freq_bin.length==a||(this._freq_bin=new Uint8Array(a));this.audionode.getByteFrequencyData(this._freq_bin);this.setOutputData(0,this._freq_bin)}this.isOutputConnected(1)&&(a=this.audionode.frequencyBinCount,this._time_bin&&this._time_bin.length==a||(this._time_bin=new Uint8Array(a)),this.audionode.getByteTimeDomainData(this._time_bin),this.setOutputData(1,this._time_bin));for(a=1;a<this.inputs.length;++a){var b=this.inputs[a];if(null!=b.link){var c=this.getInputData(a);void 0!==
|
|
c&&(this.audionode[b.name].value=c)}}};q.prototype.onGetInputs=function(){return[["minDecibels","number"],["maxDecibels","number"],["smoothingTimeConstant","number"]]};q.prototype.onGetOutputs=function(){return[["freqs","array"],["samples","array"]]};q.title="Analyser";q.desc="Audio Analyser";s.registerNodeType("audio/analyser",q);g.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=
|
|
c)}};v.createAudioNodeWrapper(g);g.title="Gain";g.desc="Audio gain";s.registerNodeType("audio/gain",g);v.createAudioNodeWrapper(r);r.prototype.onRemove=function(){this._dropped_url&&URL.revokeObjectURL(this._dropped_url)};r.prototype.onPropertyChanged=function(a,b){"impulse_src"==a?this.loadImpulse(b):"normalize"==a&&(this.audionode.normalize=b)};r.prototype.onDropFile=function(a){this._dropped_url&&URL.revokeObjectURL(this._dropped_url);this._dropped_url=URL.createObjectURL(a);this.properties.impulse_src=
|
|
this._dropped_url;this.loadImpulse(this._dropped_url)};r.prototype.loadImpulse=function(a){function b(a){c._impulse_buffer=a;c.audionode.buffer=a;console.log("Impulse signal set");c._loading_impulse=!1}var c=this;this._request&&(this._request.abort(),this._request=null);this._impulse_buffer=null;this._loading_impulse=!1;a&&(this._request=v.loadSound(a,b),this._loading_impulse=!0)};r.title="Convolver";r.desc="Convolves the signal (used for reverb)";s.registerNodeType("audio/convolver",r);v.createAudioNodeWrapper(m);
|
|
m.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=this.inputs[a];if(null!=b.link){var c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}}};m.prototype.onGetInputs=function(){return[["threshold","number"],["knee","number"],["ratio","number"],["reduction","number"],["attack","number"],["release","number"]]};m.title="DynamicsCompressor";m.desc="Dynamics Compressor";s.registerNodeType("audio/dynamicsCompressor",m);w.prototype.onExecute=
|
|
function(){if(this.inputs&&this.inputs.length){var a=this.getInputData(1);void 0!==a&&(this.audionode.curve=a)}};w.prototype.setWaveShape=function(a){this.audionode.curve=a};v.createAudioNodeWrapper(w);B.prototype.getAudioNodeInInputSlot=function(a){if(0==a)return this.audionode1;if(2==a)return this.audionode2};B.prototype.onPropertyChanged=function(a,b){"gain1"==a?this.audionode1.gain.value=b:"gain2"==a&&(this.audionode2.gain.value=b)};B.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=
|
|
1;a<this.inputs.length;++a){var b=this.inputs[a];null!=b.link&&"audio"!=b.type&&(b=this.getInputData(a),void 0!==b&&(1==a?this.audionode1.gain.value=b:3==a&&(this.audionode2.gain.value=b)))}};v.createAudioNodeWrapper(B);B.title="Mixer";B.desc="Audio mixer";s.registerNodeType("audio/mixer",B);z.prototype.onExecute=function(){var a=v.getAudioContext().currentTime,b=this.audionode.gain,c=this.getInputData(1),d=this.getInputOrProperty("A"),f=this.getInputOrProperty("D"),g=this.getInputOrProperty("S"),
|
|
h=this.getInputOrProperty("R");!this.gate&&c?(b.cancelScheduledValues(0),b.setValueAtTime(0,a),b.linearRampToValueAtTime(1,a+d),b.linearRampToValueAtTime(g,a+d+f)):this.gate&&!c&&(b.cancelScheduledValues(0),b.setValueAtTime(b.value,a),b.linearRampToValueAtTime(0,a+h));this.gate=c};z.prototype.onGetInputs=function(){return[["A","number"],["D","number"],["S","number"],["R","number"]]};v.createAudioNodeWrapper(z);z.title="ADSR";z.desc="Audio envelope";s.registerNodeType("audio/adsr",z);v.createAudioNodeWrapper(y);
|
|
y.prototype.onExecute=function(){var a=this.getInputData(1);void 0!==a&&(this.audionode.delayTime.value=a)};y.title="Delay";y.desc="Audio delay";s.registerNodeType("audio/delay",y);c.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=this.inputs[a];if(null!=b.link){var c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}}};c.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["Q","number"]]};
|
|
v.createAudioNodeWrapper(c);c.title="BiquadFilter";c.desc="Audio filter";s.registerNodeType("audio/biquadfilter",c);x.prototype.onStart=function(){if(!this.audionode.started){this.audionode.started=!0;try{this.audionode.start()}catch(a){}}};x.prototype.onStop=function(){this.audionode.started&&(this.audionode.started=!1,this.audionode.stop())};x.prototype.onPause=function(){this.onStop()};x.prototype.onUnpause=function(){this.onStart()};x.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=
|
|
0;a<this.inputs.length;++a){var b=this.inputs[a];if(null!=b.link){var c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}}};x.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["type","string"]]};v.createAudioNodeWrapper(x);x.title="Oscillator";x.desc="Oscillator";s.registerNodeType("audio/oscillator",x);n.prototype.onExecute=function(){this._last_buffer=this.getInputData(0);var a=this.getInputData(1);void 0!==a&&(this.properties.mark=a);this.setDirtyCanvas(!0,
|
|
!1)};n.prototype.onDrawForeground=function(a){if(this._last_buffer){var b=this._last_buffer,c=b.length/this.size[0],d=this.size[1];a.fillStyle="black";a.fillRect(0,0,this.size[0],this.size[1]);a.strokeStyle="white";a.beginPath();var f=0;if(this.properties.continuous){a.moveTo(f,d);for(var g=0;g<b.length;g+=c)a.lineTo(f,d-b[g|0]/255*d),f++}else for(g=0;g<b.length;g+=c)a.moveTo(f+0.5,d),a.lineTo(f+0.5,d-b[g|0]/255*d),f++;a.stroke();0<=this.properties.mark&&(b=v.getAudioContext().sampleRate/b.length,
|
|
f=this.properties.mark/b*2/c,f>=this.size[0]&&(f=this.size[0]-1),a.strokeStyle="red",a.beginPath(),a.moveTo(f,d),a.lineTo(f,0),a.stroke())}};n.title="Visualization";n.desc="Audio Visualization";s.registerNodeType("audio/visualization",n);f.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var a=this.properties.band,b=this.getInputData(1);void 0!==b&&(a=b);b=v.getAudioContext().sampleRate/this._freqs.length;b=a/b*2;b>=this._freqs.length?b=this._freqs[this._freqs.length-1]:(a=b|0,
|
|
b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.properties.amplitude)}};f.prototype.onGetInputs=function(){return[["band","number"]]};f.title="Signal";f.desc="extract the signal of some frequency";s.registerNodeType("audio/signal",f);A.prototype.onAdded=function(a){a.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};A["@code"]={widget:"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(a){console.error("Error in onaudioprocess code",a),this._callback=A._bypass_function,this.audionode.onaudioprocess=this._callback}};A.prototype.onPropertyChanged=function(a,b){"code"==a&&(this.properties.code=b,this.processCode(),this.graph&&this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};A.default_function=function(){this.onaudioprocess=function(a){var b=a.inputBuffer;a=a.outputBuffer;for(var c=0;c<a.numberOfChannels;c++)for(var d=
|
|
b.getChannelData(c),f=a.getChannelData(c),g=0;g<b.length;g++)f[g]=d[g]}};v.createAudioNodeWrapper(A);A.title="Script";A.desc="apply script to signal";s.registerNodeType("audio/script",A);h.title="Destination";h.desc="Audio output";s.registerNodeType("audio/destination",h)})(this);
|
|
(function(u){function d(){this.size=[60,20];this.addInput("send",q.ACTION);this.addOutput("received",q.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph",only_send_changes:!0};this._ws=null;this._last_sent_data=[];this._last_received_data=[]}function k(){this.room_widget=this.addWidget("text","Room","lgraph",this.setRoom.bind(this));this.addWidget("button","Reconnect",null,this.connectSocket.bind(this));this.addInput("send",q.ACTION);this.addOutput("received",
|
|
q.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"tamats.com:55000",room:"lgraph",only_send_changes:!0};this._server=null;this.connectSocket();this._last_sent_data=[];this._last_received_data=[]}var q=u.LiteGraph;d.title="WebSocket";d.desc="Send data through a websocket";d.prototype.onPropertyChanged=function(d,k){"url"==d&&this.connectSocket()};d.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var d=
|
|
this.properties.room,k=this.properties.only_send_changes,m=1;m<this.inputs.length;++m){var q=this.getInputData(m);if(null!=q){var u;try{u=JSON.stringify({type:0,room:d,channel:m,data:q})}catch(z){continue}k&&this._last_sent_data[m]==u||(this._last_sent_data[m]=u,this._ws.send(u))}}for(m=1;m<this.outputs.length;++m)this.setOutputData(m,this._last_received_data[m]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};d.prototype.connectSocket=function(){var d=this,k=this.properties.url;"ws"!=k.substr(0,
|
|
2)&&(k="ws://"+k);this._ws=new WebSocket(k);this._ws.onopen=function(){console.log("ready");d.boxcolor="#6C6"};this._ws.onmessage=function(k){d.boxcolor="#AFA";var r=JSON.parse(k.data);if(!r.room||r.room==this.properties.room)if(1==k.data.type)if(r.data.object_class&&q[r.data.object_class]){k=null;try{k=new q[r.data.object_class](r.data),d.triggerSlot(0,k)}catch(u){}}else d.triggerSlot(0,r.data);else d._last_received_data[k.data.channel||0]=r.data};this._ws.onerror=function(k){console.log("couldnt connect to websocket");
|
|
d.boxcolor="#E88"};this._ws.onclose=function(k){console.log("connection closed");d.boxcolor="#000"}};d.prototype.send=function(d){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:d}))};d.prototype.onAction=function(d,k){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,room:this.properties.room,action:d,data:k})};d.prototype.onGetInputs=function(){return[["in",0]]};d.prototype.onGetOutputs=function(){return[["out",0]]};q.registerNodeType("network/websocket",
|
|
d);k.title="SillyClient";k.desc="Connects to SillyServer to broadcast messages";k.prototype.onPropertyChanged=function(d,k){"room"==d&&(this.room_widget.value=k);this.connectSocket()};k.prototype.setRoom=function(d){this.properties.room=d;this.room_widget.value=d;this.connectSocket()};k.prototype.onDrawForeground=function(){for(var d=1;d<this.inputs.length;++d){var k=this.inputs[d];k.label="in_"+d}for(d=1;d<this.outputs.length;++d)k=this.outputs[d],k.label="out_"+d};k.prototype.onExecute=function(){if(this._server&&
|
|
this._server.is_connected){for(var d=this.properties.only_send_changes,k=1;k<this.inputs.length;++k){var m=this.getInputData(k);null==m||d&&this._last_sent_data[k]==m||(this._server.sendMessage({type:0,channel:k,data:m}),this._last_sent_data[k]=m)}for(k=1;k<this.outputs.length;++k)this.setOutputData(k,this._last_received_data[k]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};k.prototype.connectSocket=function(){var d=this;if("undefined"==typeof SillyClient)this._error||console.error("SillyClient node cannot be used, you must include SillyServer.js"),
|
|
this._error=!0;else if(this._server=new SillyClient,this._server.on_ready=function(){console.log("ready");d.boxcolor="#6C6"},this._server.on_message=function(k,r){var u=null;try{u=JSON.parse(r)}catch(z){return}if(1==u.type)if(u.data.object_class&&q[u.data.object_class]){var y=null;try{y=new q[u.data.object_class](u.data),d.triggerSlot(0,y)}catch(c){return}}else d.triggerSlot(0,u.data);else d._last_received_data[u.channel||0]=u.data;d.boxcolor="#AFA"},this._server.on_error=function(k){console.log("couldnt connect to websocket");
|
|
d.boxcolor="#E88"},this._server.on_close=function(k){console.log("connection closed");d.boxcolor="#000"},this.properties.url&&this.properties.room){try{this._server.connect(this.properties.url,this.properties.room)}catch(k){console.error("SillyServer error: "+k);this._server=null;return}this._final_url=this.properties.url+"/"+this.properties.room}};k.prototype.send=function(d){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,data:d})};k.prototype.onAction=function(d,k){this._server&&
|
|
this._server.is_connected&&this._server.sendMessage({type:1,action:d,data:k})};k.prototype.onGetInputs=function(){return[["in",0]]};k.prototype.onGetOutputs=function(){return[["out",0]]};q.registerNodeType("network/sillyclient",k)})(this);
|