mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 22:37:32 +00:00
fix in delay
This commit is contained in:
@@ -7239,7 +7239,6 @@ DelayEvent.prototype.onAction = function(action, param)
|
||||
DelayEvent.prototype.onExecute = function()
|
||||
{
|
||||
var dt = this.graph.elapsed_time * 1000; //in ms
|
||||
console.log(this._pending);
|
||||
|
||||
for(var i = 0; i < this._pending.length; ++i)
|
||||
{
|
||||
@@ -7332,6 +7331,7 @@ var LiteGraph = global.LiteGraph;
|
||||
function WidgetToggle()
|
||||
{
|
||||
this.addInput( "", "boolean" );
|
||||
this.addInput( "e", LiteGraph.ACTION );
|
||||
this.addOutput( "v", "boolean" );
|
||||
this.addOutput( "e", LiteGraph.EVENT );
|
||||
this.properties = { font: "", value: false };
|
||||
@@ -7363,6 +7363,12 @@ var LiteGraph = global.LiteGraph;
|
||||
ctx.textAlign = "left";
|
||||
}
|
||||
|
||||
WidgetToggle.prototype.onAction = function(action)
|
||||
{
|
||||
this.properties.value = !this.properties.value;
|
||||
this.trigger( "e", this.properties.value );
|
||||
}
|
||||
|
||||
WidgetToggle.prototype.onExecute = function()
|
||||
{
|
||||
var v = this.getInputData(0);
|
||||
|
||||
321
build/litegraph.min.js
vendored
321
build/litegraph.min.js
vendored
@@ -1,29 +1,29 @@
|
||||
(function(u){function g(){l.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear()}function e(a){this._ctor(a)}function h(a,b,d){d=d||{};this.background_image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
|
||||
a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.min_zoom=0.1;this.zoom_modify_alpha=!0;this.title_text_font="bold 14px Arial";this.inner_text_font="normal 12px Arial";this.node_title_color=l.NODE_TITLE_COLOR;this.default_link_color="#AAC";this.default_connection_color={input_off:"#AAB",input_on:"#7F7",output_off:"#AAB",output_on:"#7F7"};this.highquality_render=!0;this.editor_alpha=1;this.pause_rendering=!1;this.render_only_selected=this.clear_background=this.render_shadows=
|
||||
!0;this.live_mode=!1;this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=!1;this.dragging_rectangle=null;this.always_render_background=!1;this.render_canvas_border=!0;this.render_connections_shadows=!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.connections_width=3;b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();this.autoresize=d.autoresize}function n(a,
|
||||
b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function p(a,b,d,c,f,m){return d<a&&d+f>a&&c<b&&c+m>b?!0:!1}function q(a,b){var d=a[0]+a[2],c=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||d<b[0]||c<b[1]?!1:!0}function r(a,b){function d(a){var b=parseInt(f.style.top);f.style.top=(b+0.1*a.deltaY).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var c=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),
|
||||
!0;this.live_mode=!1;this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=!1;this.dragging_rectangle=null;this.always_render_background=!1;this.render_canvas_border=!0;this.render_connections_shadows=!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.connections_width=3;b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();this.autoresize=d.autoresize}function m(a,
|
||||
b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function p(a,b,d,c,f,n){return d<a&&d+f>a&&c<b&&c+n>b?!0:!1}function q(a,b){var d=a[0]+a[2],c=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||d<b[0]||c<b[1]?!1:!0}function r(a,b){function d(a){var b=parseInt(f.style.top);f.style.top=(b+0.1*a.deltaY).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var c=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 f=document.createElement("div");f.className="litegraph litecontextmenu litemenubar-panel";f.style.minWidth=100;f.style.minHeight=100;f.style.pointerEvents="none";setTimeout(function(){f.style.pointerEvents=
|
||||
"auto"},100);f.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);f.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);f.addEventListener("mousedown",function(a){if(2==a.button)return c.close(),a.preventDefault(),!0},!0);f.addEventListener("wheel",d,!0);f.addEventListener("mousewheel",d,!0);this.root=f;if(b.title){var m=document.createElement("div");m.className="litemenu-title";m.innerHTML=b.title;f.appendChild(m)}var m=0,k;for(k in a){var t=
|
||||
a.constructor==Array?a[k]:k;null!=t&&t.constructor!==String&&(t=void 0===t.content?String(t):t.content);this.addItem(t,a[k],b);m++}f.addEventListener("mouseleave",function(a){c.lock||c.close(a)});k=document;b.event&&(k=b.event.target.ownerDocument);k||(k=document);k.body.appendChild(f);m=b.left||0;k=b.top||0;if(b.event){m=b.event.pageX-10;k=b.event.pageY-10;b.title&&(k-=20);b.parentMenu&&(m=b.parentMenu.root.getBoundingClientRect(),m=m.left+m.width);var t=document.body.getBoundingClientRect(),e=f.getBoundingClientRect();
|
||||
m>t.width-e.width-10&&(m=t.width-e.width-10);k>t.height-e.height-10&&(k=t.height-e.height-10)}f.style.left=m+"px";f.style.top=k+"px"}var l=u.LiteGraph={NODE_TITLE_HEIGHT:16,NODE_SLOT_HEIGHT:15,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,CANVAS_GRID_SIZE:10,NODE_TITLE_COLOR:"#222",NODE_DEFAULT_COLOR:"#999",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#AEF",NODE_DEFAULT_SHAPE:"box",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],node_images_path:"",VALID_SHAPES:["box",
|
||||
"auto"},100);f.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);f.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);f.addEventListener("mousedown",function(a){if(2==a.button)return c.close(),a.preventDefault(),!0},!0);f.addEventListener("wheel",d,!0);f.addEventListener("mousewheel",d,!0);this.root=f;if(b.title){var n=document.createElement("div");n.className="litemenu-title";n.innerHTML=b.title;f.appendChild(n)}var n=0,k;for(k in a){var t=
|
||||
a.constructor==Array?a[k]:k;null!=t&&t.constructor!==String&&(t=void 0===t.content?String(t):t.content);this.addItem(t,a[k],b);n++}f.addEventListener("mouseleave",function(a){c.lock||c.close(a)});k=document;b.event&&(k=b.event.target.ownerDocument);k||(k=document);k.body.appendChild(f);n=b.left||0;k=b.top||0;if(b.event){n=b.event.pageX-10;k=b.event.pageY-10;b.title&&(k-=20);b.parentMenu&&(n=b.parentMenu.root.getBoundingClientRect(),n=n.left+n.width);var t=document.body.getBoundingClientRect(),e=f.getBoundingClientRect();
|
||||
n>t.width-e.width-10&&(n=t.width-e.width-10);k>t.height-e.height-10&&(k=t.height-e.height-10)}f.style.left=n+"px";f.style.top=k+"px"}var l=u.LiteGraph={NODE_TITLE_HEIGHT:16,NODE_SLOT_HEIGHT:15,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,CANVAS_GRID_SIZE:10,NODE_TITLE_COLOR:"#222",NODE_DEFAULT_COLOR:"#999",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#AEF",NODE_DEFAULT_SHAPE:"box",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],node_images_path:"",VALID_SHAPES:["box",
|
||||
"round"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,proxy:null,debug:!1,throw_errors:!0,allow_scripts:!0,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;l.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,c=a.lastIndexOf("/");b.category=a.substr(0,c);b.title||
|
||||
(b.title=d);if(b.prototype)for(var f in e.prototype)b.prototype[f]||(b.prototype[f]=e.prototype[f]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "box":this._shape=l.BOX_SHAPE;break;case "round":this._shape=l.ROUND_SHAPE;break;case "circle":this._shape=l.CIRCLE_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+
|
||||
a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(f in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[f].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,c){for(var f=Array(b.length),m="",k=l.getParameterNames(b),t=0;t<k.length;++t)m+="this.addInput('"+k[t]+"',"+(d&&d[t]?"'"+d[t]+"'":"0")+");\n";d=Function(m+("this.addOutput('out',"+(c?"'"+c+"'":0)+");\n"));d.title=a.split("/").pop();d.desc="Generated from "+
|
||||
a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(f in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[f].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,c){for(var f=Array(b.length),n="",k=l.getParameterNames(b),t=0;t<k.length;++t)n+="this.addInput('"+k[t]+"',"+(d&&d[t]?"'"+d[t]+"'":"0")+");\n";d=Function(n+("this.addOutput('out',"+(c?"'"+c+"'":0)+");\n"));d.title=a.split("/").pop();d.desc="Generated from "+
|
||||
b.name;d.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,d)},addNodeMethod:function(a,b){e.prototype[a]=b;for(var d in this.registered_node_types){var c=this.registered_node_types[d];c.prototype[a]&&(c.prototype["_"+a]=c.prototype[a]);c.prototype[a]=b}},createNode:function(a,b,d){var c=this.registered_node_types[a];if(!c)return l.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;
|
||||
b=b||c.title||a;c=new c(b);c.type=a;!c.title&&b&&(c.title=b);c.properties||(c.properties={});c.properties_info||(c.properties_info=[]);c.flags||(c.flags={});c.size||(c.size=c.computeSize());c.pos||(c.pos=l.DEFAULT_POSITION.concat());c.mode||(c.mode=l.ALWAYS);if(d)for(var f in d)c[f]=d[f];return c},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a){var b=[],d;for(d in this.registered_node_types)""==a?null==this.registered_node_types[d].category&&b.push(this.registered_node_types[d]):
|
||||
this.registered_node_types[d].category==a&&b.push(this.registered_node_types[d]);return b},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 d=[];for(b in a)d.push(b);return d},reloadNodes:function(a){var b=document.getElementsByTagName("script"),d=[],c;for(c in b)d.push(b[c]);b=document.getElementsByTagName("head")[0];a=document.location.href+
|
||||
a;for(c in d){var f=d[c].src;if(f&&f.substr(0,a.length)==a)try{l.debug&&console.log("Reloading: "+f);var m=document.createElement("script");m.type="text/javascript";m.src=f;b.appendChild(m);b.removeChild(d[c])}catch(k){if(l.throw_errors)throw k;l.debug&&console.log("Error while reloading "+f)}}l.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var d=JSON.parse(JSON.stringify(a));if(!b)return d;for(var c in d)b[c]=d[c];return b},isValidConnection:function(a,b){if(!a||
|
||||
!b||a==b||a==l.EVENT&&b==l.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 d=a.split(","),c=b.split(","),f=0;f<d.length;++f)for(var m=0;m<c.length;++m)if(d[f]==c[m])return!0;return!1}};l.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()};
|
||||
a;for(c in d){var f=d[c].src;if(f&&f.substr(0,a.length)==a)try{l.debug&&console.log("Reloading: "+f);var n=document.createElement("script");n.type="text/javascript";n.src=f;b.appendChild(n);b.removeChild(d[c])}catch(k){if(l.throw_errors)throw k;l.debug&&console.log("Error while reloading "+f)}}l.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var d=JSON.parse(JSON.stringify(a));if(!b)return d;for(var c in d)b[c]=d[c];return b},isValidConnection:function(a,b){if(!a||
|
||||
!b||a==b||a==l.EVENT&&b==l.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 d=a.split(","),c=b.split(","),f=0;f<d.length;++f)for(var n=0;n<c.length;++n)if(d[f]==c[n])return!0;return!1}};l.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=l.LGraph=g;g.supported_types=["number","string","boolean"];g.prototype.getSupportedTypes=function(){return this.supported_types||g.supported_types};g.STATUS_STOPPED=1;g.STATUS_RUNNING=2;g.prototype.clear=function(){this.stop();this.status=g.STATUS_STOPPED;this.last_node_id=0;this._nodes=[];this._nodes_by_id={};this._nodes_executable=this._nodes_in_order=null;this.last_link_id=0;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.global_inputs={};this.global_outputs={};this.debug=!0;this.change();this.sendActionToCanvas("clear")};g.prototype.attachCanvas=function(a){if(a.constructor!=h)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)};g.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))}};g.prototype.start=function(a){if(this.status!=g.STATUS_RUNNING){this.status=g.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=l.getTime();var b=this;this.execution_timer_id=setInterval(function(){b.runStep(1,!this.catch_errors)},a||1)}};g.prototype.stop=function(){if(this.status!=g.STATUS_STOPPED){this.status=g.STATUS_STOPPED;
|
||||
if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&clearInterval(this.execution_timer_id);this.execution_timer_id=null;this.sendEventToAllNodes("onStop")}};g.prototype.runStep=function(a,b){a=a||1;var d=l.getTime();this.globaltime=0.001*(d-this.starttime);var c=this._nodes_executable?this._nodes_executable:this._nodes;if(c){if(b){for(var f=0;f<a;f++){for(var m=0,k=c.length;m<k;++m){var t=c[m];if(t.mode==l.ALWAYS&&t.onExecute)t.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=
|
||||
0;f<a;f++){m=0;for(k=c.length;m<k;++m)if(t=c[m],t.mode==l.ALWAYS&&t.onExecute)t.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(e){this.errors_in_execution=!0;if(l.throw_errors)throw e;l.debug&&console.log("Error during execution: "+e);this.stop()}c=l.getTime();d=c-d;0==d&&(d=1);this.execution_time=0.001*d;this.globaltime+=0.001*d;this.iteration+=1;this.elapsed_time=0.001*(c-
|
||||
this.last_update_time);this.last_update_time=c}};g.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])};g.prototype.computeExecutionOrder=function(a,b){for(var d=[],c=[],f={},m={},k={},t=0,e=this._nodes.length;t<e;++t){var h=this._nodes[t];if(!a||h.onExecute){f[h.id]=h;var g=0;if(h.inputs)for(var n=
|
||||
0,p=h.inputs.length;n<p;n++)h.inputs[n]&&null!=h.inputs[n].link&&(g+=1);0==g?(c.push(h),b&&(h._level=1)):(b&&(h._level=0),k[h.id]=g)}}for(;0!=c.length;)if(h=c.shift(),d.push(h),delete f[h.id],h.outputs)for(t=0;t<h.outputs.length;t++)if(e=h.outputs[t],null!=e&&null!=e.links&&0!=e.links.length)for(n=0;n<e.links.length;n++)(g=this.links[e.links[n]])&&!m[g.id]&&(p=this.getNodeById(g.target_id),null==p?m[g.id]=!0:(b&&(!p._level||p._level<=h._level)&&(p._level=h._level+1),m[g.id]=!0,k[p.id]-=1,0==k[p.id]&&
|
||||
c.push(p)));for(t in f)d.push(f[t]);d.length!=this._nodes.length&&l.debug&&console.warn("something went wrong, nodes missing");e=d.length;for(t=0;t<e;++t)d[t].order=t;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,c=b.constructor.priority||b.priority||0;return d==c?a.order-b.order:d-c});for(t=0;t<e;++t)d[t].order=t;return d};g.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),d=[],c=0;c<b.length;++c){var f=b[c],m=f._level||1;d[m]||(d[m]=[]);d[m].push(f)}b=
|
||||
a;for(c=0;c<d.length;++c)if(m=d[c]){for(var k=100,h=a,e=0;e<m.length;++e)f=m[e],f.pos[0]=b,f.pos[1]=h,f.size[0]>k&&(k=f.size[0]),h+=f.size[1]+a;b+=k+a}this.setDirtyCanvas(!0,!0)};g.prototype.getTime=function(){return this.globaltime};g.prototype.getFixedTime=function(){return this.fixedtime};g.prototype.getElapsedTime=function(){return this.elapsed_time};g.prototype.sendEventToAllNodes=function(a,b,d){d=d||l.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,m=c.length;f<
|
||||
m;++f){var k=c[f];if(k[a]&&k.mode==d)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[a](b)}};g.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d<this.list_of_graphcanvas.length;++d){var c=this.list_of_graphcanvas[d];c[a]&&c[a].apply(c,b)}};g.prototype.add=function(a,b){if(a){-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>=
|
||||
if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&clearInterval(this.execution_timer_id);this.execution_timer_id=null;this.sendEventToAllNodes("onStop")}};g.prototype.runStep=function(a,b){a=a||1;var d=l.getTime();this.globaltime=0.001*(d-this.starttime);var c=this._nodes_executable?this._nodes_executable:this._nodes;if(c){if(b){for(var f=0;f<a;f++){for(var n=0,k=c.length;n<k;++n){var t=c[n];if(t.mode==l.ALWAYS&&t.onExecute)t.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=
|
||||
0;f<a;f++){n=0;for(k=c.length;n<k;++n)if(t=c[n],t.mode==l.ALWAYS&&t.onExecute)t.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(e){this.errors_in_execution=!0;if(l.throw_errors)throw e;l.debug&&console.log("Error during execution: "+e);this.stop()}c=l.getTime();d=c-d;0==d&&(d=1);this.execution_time=0.001*d;this.globaltime+=0.001*d;this.iteration+=1;this.elapsed_time=0.001*(c-
|
||||
this.last_update_time);this.last_update_time=c}};g.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])};g.prototype.computeExecutionOrder=function(a,b){for(var d=[],c=[],f={},n={},k={},t=0,e=this._nodes.length;t<e;++t){var h=this._nodes[t];if(!a||h.onExecute){f[h.id]=h;var g=0;if(h.inputs)for(var m=
|
||||
0,p=h.inputs.length;m<p;m++)h.inputs[m]&&null!=h.inputs[m].link&&(g+=1);0==g?(c.push(h),b&&(h._level=1)):(b&&(h._level=0),k[h.id]=g)}}for(;0!=c.length;)if(h=c.shift(),d.push(h),delete f[h.id],h.outputs)for(t=0;t<h.outputs.length;t++)if(e=h.outputs[t],null!=e&&null!=e.links&&0!=e.links.length)for(m=0;m<e.links.length;m++)(g=this.links[e.links[m]])&&!n[g.id]&&(p=this.getNodeById(g.target_id),null==p?n[g.id]=!0:(b&&(!p._level||p._level<=h._level)&&(p._level=h._level+1),n[g.id]=!0,k[p.id]-=1,0==k[p.id]&&
|
||||
c.push(p)));for(t in f)d.push(f[t]);d.length!=this._nodes.length&&l.debug&&console.warn("something went wrong, nodes missing");e=d.length;for(t=0;t<e;++t)d[t].order=t;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,c=b.constructor.priority||b.priority||0;return d==c?a.order-b.order:d-c});for(t=0;t<e;++t)d[t].order=t;return d};g.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),d=[],c=0;c<b.length;++c){var f=b[c],n=f._level||1;d[n]||(d[n]=[]);d[n].push(f)}b=
|
||||
a;for(c=0;c<d.length;++c)if(n=d[c]){for(var k=100,e=a,h=0;h<n.length;++h)f=n[h],f.pos[0]=b,f.pos[1]=e,f.size[0]>k&&(k=f.size[0]),e+=f.size[1]+a;b+=k+a}this.setDirtyCanvas(!0,!0)};g.prototype.getTime=function(){return this.globaltime};g.prototype.getFixedTime=function(){return this.fixedtime};g.prototype.getElapsedTime=function(){return this.elapsed_time};g.prototype.sendEventToAllNodes=function(a,b,d){d=d||l.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,n=c.length;f<
|
||||
n;++f){var k=c[f];if(k[a]&&k.mode==d)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[a](b)}};g.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d<this.list_of_graphcanvas.length;++d){var c=this.list_of_graphcanvas[d];c[a]&&c[a].apply(c,b)}};g.prototype.add=function(a,b){if(a){-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>=
|
||||
l.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;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}};g.prototype.remove=function(a){if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){if(a.inputs)for(var b=
|
||||
0;b<a.inputs.length;b++){var d=a.inputs[b];null!=d.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)d=a.outputs[b],null!=d.links&&d.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)d=this.list_of_graphcanvas[b],d.selected_nodes[a.id]&&delete d.selected_nodes[a.id],d.node_dragged==a&&(d.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()}};g.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};g.prototype.findNodesByClass=function(a){for(var b=[],d=0,c=this._nodes.length;d<c;++d)this._nodes[d].constructor===a&&b.push(this._nodes[d]);return b};g.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],d=0,c=this._nodes.length;d<c;++d)this._nodes[d].type.toLowerCase()==a&&b.push(this._nodes[d]);
|
||||
@@ -35,7 +35,7 @@ if(this.global_outputs[b])return console.error("there is already one output with
|
||||
b)};g.prototype.removeGlobalOutput=function(a){if(!this.global_outputs[a])return!1;delete this.global_outputs[a];if(this.onGlobalOutputRemoved)this.onGlobalOutputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();return!0};g.prototype.triggerInput=function(a,b){for(var d=this.findNodesByTitle(a),c=0;c<d.length;++c)d[c].onTrigger(b)};g.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),c=0;c<d.length;++c)d[c].setTrigger(b)};g.prototype.connectionChange=function(a){this.updateExecutionOrder();
|
||||
if(this.onConnectionChange)this.onConnectionChange(a);this.sendActionToCanvas("onConnectionChange")};g.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};g.prototype.change=function(){l.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};g.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",
|
||||
[a,b])};g.prototype.serialize=function(){for(var a=[],b=0,d=this._nodes.length;b<d;++b)a.push(this._nodes[b].serialize());d=[];for(b in this.links){var c=this.links[b];d.push([c.id,c.origin_id,c.origin_slot,c.target_id,c.target_slot,c.type])}return{iteration:this.iteration,frame:this.frame,last_node_id:this.last_node_id,last_link_id:this.last_link_id,links:d,config:this.config,nodes:a}};g.prototype.configure=function(a,b){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=
|
||||
{},f=0;f<a.links.length;++f){var m=a.links[f];c[m[0]]={id:m[0],origin_id:m[1],origin_slot:m[2],target_id:m[3],target_slot:m[4],type:m[5]}}a.links=c}for(f in a)this[f]=a[f];c=!1;this._nodes=[];f=0;for(m=d.length;f<m;++f){var k=d[f],h=l.createNode(k.type,k.title);h?(h.id=k.id,this.add(h,!0)):(l.debug&&console.log("Node not found: "+k.type),c=!0)}f=0;for(m=d.length;f<m;++f)k=d[f],(h=this.getNodeById(k.id))&&h.configure(k);this.updateExecutionOrder();this.setDirtyCanvas(!0,!0);return c};g.prototype.load=
|
||||
{},f=0;f<a.links.length;++f){var n=a.links[f];c[n[0]]={id:n[0],origin_id:n[1],origin_slot:n[2],target_id:n[3],target_slot:n[4],type:n[5]}}a.links=c}for(f in a)this[f]=a[f];c=!1;this._nodes=[];f=0;for(n=d.length;f<n;++f){var k=d[f],e=l.createNode(k.type,k.title);e?(e.id=k.id,this.add(e,!0)):(l.debug&&console.log("Node not found: "+k.type),c=!0)}f=0;for(n=d.length;f<n;++f)k=d[f],(e=this.getNodeById(k.id))&&e.configure(k);this.updateExecutionOrder();this.setDirtyCanvas(!0,!0);return c};g.prototype.load=
|
||||
function(a){var b=this,d=new XMLHttpRequest;d.open("GET",a,!0);d.send(null);d.onload=function(a){200!==d.status?console.error("Error loading graph:",d.status,d.response):(a=JSON.parse(d.response),b.configure(a))};d.onerror=function(a){console.error("Error loading graph:",a)}};g.prototype.onNodeTrace=function(a,b,d){};u.LGraphNode=l.LGraphNode=e;e.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[l.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.data=null;this.flags={}};e.prototype.configure=function(a){for(var b in a)if("console"!=b)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=
|
||||
a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=l.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(var c=0;c<this.inputs.length;++c){d=this.inputs[c];var f=this.graph.links[d.link];this.onConnectionsChange(l.INPUT,c,!0,f,d)}if(this.outputs)for(c=0;c<this.outputs.length;++c)if(d=this.outputs[c],d.links)for(b=0;b<d.links.length;++b)f=this.graph.links[d.links[b]],this.onConnectionsChange(l.OUTPUT,
|
||||
@@ -47,20 +47,20 @@ else if(c.onExecute)c.onExecute();return d.data}};e.prototype.getInputDataByName
|
||||
(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};e.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return(a=this.graph.links[this.inputs[b].link])?a.data:null;return this.properties[a]};e.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};e.prototype.getOutputInfo=function(a){return this.outputs?
|
||||
a<this.outputs.length?this.outputs[a]:null:null};e.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};e.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};e.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=[],d=0;d<a.links.length;d++){var c=this.graph.links[a.links[d]];c&&(c=this.graph.getNodeById(c.target_id))&&b.push(c)}return b};e.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var d=0;d<this.outputs.length;++d){var c=this.outputs[d];!c||c.type!==l.EVENT||a&&c.name!=a||this.triggerSlot(d,b)}}};e.prototype.triggerSlot=function(a,b){if(this.outputs){var d=this.outputs[a];
|
||||
if(d&&(d=d.links)&&d.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var c=0;c<d.length;++c){var f=this.graph.links[d[c]];if(f){var m=this.graph.getNodeById(f.target_id);if(m)if(f._last_time=l.getTime(),f=m.inputs[f.target_slot],m.onAction)m.onAction(f.name,b);else if(m.mode===l.ON_TRIGGER&&m.onExecute)m.onExecute(b)}}}}};e.prototype.addProperty=function(a,b,d,c){d={name:a,type:d,default_value:b};if(c)for(var f in c)d[f]=c[f];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);
|
||||
if(d&&(d=d.links)&&d.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var c=0;c<d.length;++c){var f=this.graph.links[d[c]];if(f){var n=this.graph.getNodeById(f.target_id);if(n)if(f._last_time=l.getTime(),f=n.inputs[f.target_slot],n.onAction)n.onAction(f.name,b);else if(n.mode===l.ON_TRIGGER&&n.onExecute)n.onExecute(b)}}}}};e.prototype.addProperty=function(a,b,d,c){d={name:a,type:d,default_value:b};if(c)for(var f in c)d[f]=c[f];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);
|
||||
this.properties||(this.properties={});this.properties[a]=b;return d};e.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var c in d)a[c]=d[c];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();return a};e.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],c={name:d[0],type:d[1],link:null};if(a[2])for(var f in d[2])c[f]=d[2][f];this.outputs||(this.outputs=[]);this.outputs.push(c);
|
||||
if(this.onOutputAdded)this.onOutputAdded(c)}this.size=this.computeSize()};e.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a)};e.prototype.addInput=function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var c in d)a[c]=d[c];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);return a};e.prototype.addInputs=function(a){for(var b=
|
||||
0;b<a.length;++b){var d=a[b],c={name:d[0],type:d[1],link:null};if(a[2])for(var f in d[2])c[f]=d[2][f];this.inputs||(this.inputs=[]);this.inputs.push(c);if(this.onInputAdded)this.onInputAdded(c)}this.size=this.computeSize()};e.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a)};e.prototype.addConnection=function(a,b,d,c){a={name:a,type:b,pos:d,direction:c,links:null};this.connections.push(a);return a};
|
||||
e.prototype.computeSize=function(a,b){function d(a){return a?m*a.length*0.6:0}var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),f=b||new Float32Array([0,0]),c=Math.max(c,1);f[1]=14*c+6;var m=14,c=d(this.title),k=0,h=0;if(this.inputs)for(var e=0,g=this.inputs.length;e<g;++e){var n=this.inputs[e],n=n.label||n.name||"",n=d(n);k<n&&(k=n)}if(this.outputs)for(e=0,g=this.outputs.length;e<g;++e)n=this.outputs[e],n=n.label||n.name||"",n=d(n),h<n&&(h=n);f[0]=Math.max(k+h+10,
|
||||
e.prototype.computeSize=function(a,b){function d(a){return a?n*a.length*0.6:0}var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),f=b||new Float32Array([0,0]),c=Math.max(c,1);f[1]=14*c+6;var n=14,c=d(this.title),k=0,e=0;if(this.inputs)for(var h=0,g=this.inputs.length;h<g;++h){var m=this.inputs[h],m=m.label||m.name||"",m=d(m);k<m&&(k=m)}if(this.outputs)for(h=0,g=this.outputs.length;h<g;++h)m=this.outputs[h],m=m.label||m.name||"",m=d(m),e<m&&(e=m);f[0]=Math.max(k+e+10,
|
||||
c);f[0]=Math.max(f[0],l.NODE_WIDTH);return f};e.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-l.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+l.NODE_TITLE_HEIGHT;return a};e.prototype.isPointInsideNode=function(a,b,d){d=d||0;var c=this.graph&&this.graph.isLive()?0:20;if(this.flags.collapsed){if(p(a,b,this.pos[0]-d,this.pos[1]-l.NODE_TITLE_HEIGHT-d,l.NODE_COLLAPSED_WIDTH+2*d,l.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-d<a&&this.pos[0]+
|
||||
this.size[0]+4+d>a&&this.pos[1]-c-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};e.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var d=0,c=this.inputs.length;d<c;++d){var f=this.inputs[d],m=this.getConnectionPos(!0,d);if(p(a,b,m[0]-10,m[1]-5,20,10))return{input:f,slot:d,link_pos:m,locked:f.locked}}if(this.outputs)for(d=0,c=this.outputs.length;d<c;++d)if(f=this.outputs[d],m=this.getConnectionPos(!1,d),p(a,b,m[0]-10,m[1]-5,20,10))return{output:f,slot:d,link_pos:m,locked:f.locked};
|
||||
this.size[0]+4+d>a&&this.pos[1]-c-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};e.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var d=0,c=this.inputs.length;d<c;++d){var f=this.inputs[d],n=this.getConnectionPos(!0,d);if(p(a,b,n[0]-10,n[1]-5,20,10))return{input:f,slot:d,link_pos:n,locked:f.locked}}if(this.outputs)for(d=0,c=this.outputs.length;d<c;++d)if(f=this.outputs[d],n=this.getConnectionPos(!1,d),p(a,b,n[0]-10,n[1]-5,20,10))return{output:f,slot:d,link_pos:n,locked:f.locked};
|
||||
return null};e.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return b;return-1};e.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};e.prototype.connect=function(a,b,d){d=d||0;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||
|
||||
a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Node not found";if(b==this)return!1;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return l.debug&&console.log("Connect: Error, no slot of name "+d),!1}else{if(d===l.EVENT)return!1;if(!b.inputs||d>=b.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[d].link&&b.disconnectInput(d);
|
||||
this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return!1;var f=b.inputs[d];if(l.isValidConnection(c.type,f.type)){var m={id:this.graph.last_link_id++,type:f.type,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:d};this.graph.links[m.id]=m;null==c.links&&(c.links=[]);c.links.push(m.id);b.inputs[d].link=m.id;if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!0,m,c);if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,
|
||||
d,!0,m,f)}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";
|
||||
for(var c=0,f=d.links.length;c<f;c++){var m=d.links[c],k=this.graph.links[m];if(k.target_id==b.id){d.links.splice(c,1);var h=b.inputs[k.target_slot];h.link=null;delete this.graph.links[m];if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,k.target_slot,!1,k,h);if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,k,d);break}}}else{c=0;for(f=d.links.length;c<f;c++)if(m=d.links[c],k=this.graph.links[m]){if(b=this.graph.getNodeById(k.target_id))if(h=b.inputs[k.target_slot],h.link=null,
|
||||
b.onConnectionsChange)b.onConnectionsChange(l.INPUT,k.target_slot,!1,k,h);delete this.graph.links[m];if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,k,d)}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),
|
||||
!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var m=f.outputs[c.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var k=0,h=m.links.length;k<h;k++)if(m.links[k]==d){m.links.splice(k,1);break}delete this.graph.links[d];if(this.onConnectionsChange)this.onConnectionsChange(l.INPUT,a,!1,c,b);if(f.onConnectionsChange)f.onConnectionsChange(l.OUTPUT,k,!1,c,m)}this.setDirtyCanvas(!1,
|
||||
this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return!1;var f=b.inputs[d];if(l.isValidConnection(c.type,f.type)){var n={id:this.graph.last_link_id++,type:f.type,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:d};this.graph.links[n.id]=n;null==c.links&&(c.links=[]);c.links.push(n.id);b.inputs[d].link=n.id;if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!0,n,c);if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,
|
||||
d,!0,n,f)}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";
|
||||
for(var c=0,f=d.links.length;c<f;c++){var n=d.links[c],k=this.graph.links[n];if(k.target_id==b.id){d.links.splice(c,1);var e=b.inputs[k.target_slot];e.link=null;delete this.graph.links[n];if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,k.target_slot,!1,k,e);if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,k,d);break}}}else{c=0;for(f=d.links.length;c<f;c++)if(n=d.links[c],k=this.graph.links[n]){if(b=this.graph.getNodeById(k.target_id))if(e=b.inputs[k.target_slot],e.link=null,
|
||||
b.onConnectionsChange)b.onConnectionsChange(l.INPUT,k.target_slot,!1,k,e);delete this.graph.links[n];if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,k,d)}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),
|
||||
!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var n=f.outputs[c.origin_slot];if(!n||!n.links||0==n.links.length)return!1;for(var k=0,e=n.links.length;k<e;k++)if(n.links[k]==d){n.links.splice(k,1);break}delete this.graph.links[d];if(this.onConnectionsChange)this.onConnectionsChange(l.INPUT,a,!1,c,b);if(f.onConnectionsChange)f.onConnectionsChange(l.OUTPUT,k,!1,c,n)}this.setDirtyCanvas(!1,
|
||||
!0);this.graph.connectionChange(this);return!0};e.prototype.getConnectionPos=function(a,b){return this.flags.collapsed?a?[this.pos[0],this.pos[1]-0.5*l.NODE_TITLE_HEIGHT]:[this.pos[0]+l.NODE_COLLAPSED_WIDTH,this.pos[1]-0.5*l.NODE_TITLE_HEIGHT]:a&&-1==b?[this.pos[0]+10,this.pos[1]+10]:a&&this.inputs.length>b&&this.inputs[b].pos?[this.pos[0]+this.inputs[b].pos[0],this.pos[1]+this.inputs[b].pos[1]]:!a&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]:
|
||||
a?[this.pos[0],this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]};e.prototype.alignToGrid=function(){this.pos[0]=l.CANVAS_GRID_SIZE*Math.round(this.pos[0]/l.CANVAS_GRID_SIZE);this.pos[1]=l.CANVAS_GRID_SIZE*Math.round(this.pos[1]/l.CANVAS_GRID_SIZE)};e.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>e.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};e.prototype.setDirtyCanvas=function(a,
|
||||
b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};e.prototype.loadImage=function(a){var b=new Image;b.src=l.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};e.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;d<b.length;++d){var c=b[d];if(a||c.node_capturing_input==this)c.node_capturing_input=a?this:null}};e.prototype.collapse=function(){this.flags.collapsed=
|
||||
@@ -76,13 +76,13 @@ this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothin
|
||||
this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};h.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()};h.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};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};h.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))};h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();h.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=!1;l.closeAllContextMenus(b);
|
||||
if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var f=!1;if(d&&this.allow_interaction&&!c){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode){if(d.outputs)for(var m=0,k=d.outputs.length;m<k;++m){var e=d.outputs[m],g=d.getConnectionPos(!1,m);if(p(a.canvasX,a.canvasY,g[0]-10,g[1]-
|
||||
5,20,10)){this.connecting_node=d;this.connecting_output=e;this.connecting_pos=d.getConnectionPos(!1,m);this.connecting_slot=m;c=!0;break}}if(d.inputs)for(m=0,k=d.inputs.length;m<k;++m)e=d.inputs[m],g=d.getConnectionPos(!0,m),p(a.canvasX,a.canvasY,g[0]-10,g[1]-5,20,10)&&null!==e.link&&(d.disconnectInput(m),c=this.dirty_bgcanvas=!0);!c&&p(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)&&(this.resizing_node=d,this.canvas.style.cursor="se-resize",c=!0)}!c&&p(a.canvasX,a.canvasY,d.pos[0],
|
||||
d.pos[1]-l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT)&&(d.collapse(),c=!0);if(!c){m=!1;if(300>l.getTime()-this.last_mouseclick&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a);this.processNodeDblClicked(d);m=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]])?m=!0:this.live_mode&&(m=f=!0);m||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else f=!0;!c&&f&&this.allow_dragcanvas&&
|
||||
if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var f=!1;if(d&&this.allow_interaction&&!c){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode){if(d.outputs)for(var n=0,k=d.outputs.length;n<k;++n){var e=d.outputs[n],g=d.getConnectionPos(!1,n);if(p(a.canvasX,a.canvasY,g[0]-10,g[1]-
|
||||
5,20,10)){this.connecting_node=d;this.connecting_output=e;this.connecting_pos=d.getConnectionPos(!1,n);this.connecting_slot=n;c=!0;break}}if(d.inputs)for(n=0,k=d.inputs.length;n<k;++n)e=d.inputs[n],g=d.getConnectionPos(!0,n),p(a.canvasX,a.canvasY,g[0]-10,g[1]-5,20,10)&&null!==e.link&&(d.disconnectInput(n),c=this.dirty_bgcanvas=!0);!c&&p(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)&&(this.resizing_node=d,this.canvas.style.cursor="se-resize",c=!0)}!c&&p(a.canvasX,a.canvasY,d.pos[0],
|
||||
d.pos[1]-l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT)&&(d.collapse(),c=!0);if(!c){n=!1;if(300>l.getTime()-this.last_mouseclick&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a);this.processNodeDblClicked(d);n=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]])?n=!0:this.live_mode&&(n=f=!0);n||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else f=!0;!c&&f&&this.allow_dragcanvas&&
|
||||
(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(d,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=l.getTime();this.canvas_mouse=[a.canvasX,a.canvasY];this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}};h.prototype.processMouseMove=function(a){this.autoresize&&
|
||||
this.resize();if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse=[a.canvasX,a.canvasY];if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.dragging_canvas)this.offset[0]+=d[0]/this.scale,this.offset[1]+=d[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=
|
||||
!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=0,f=this.graph._nodes.length;c<f;++c)if(this.graph._nodes[c].mouseOver&&b!=this.graph._nodes[c]){this.graph._nodes[c].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(b){if(!b.mouseOver&&(b.mouseOver=!0,this.node_over=b,this.dirty_canvas=!0,b.onMouseEnter))b.onMouseEnter(a);
|
||||
if(b.onMouseMove)b.onMouseMove(a);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(b,a.canvasX,a.canvasY))){var m=this.isOverNodeInput(b,a.canvasX,a.canvasY,f);-1!=m&&b.inputs[m]?l.isValidConnection(this.connecting_output.type,b.inputs[m].type)&&(this._highlight_input=f):this._highlight_input=null}p(a.canvasX,a.canvasY,b.pos[0]+b.size[0]-5,b.pos[1]+b.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor=null}else this.canvas.style.cursor=null;if(this.node_capturing_input&&
|
||||
if(b.onMouseMove)b.onMouseMove(a);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(b,a.canvasX,a.canvasY))){var n=this.isOverNodeInput(b,a.canvasX,a.canvasY,f);-1!=n&&b.inputs[n]?l.isValidConnection(this.connecting_output.type,b.inputs[n].type)&&(this._highlight_input=f):this._highlight_input=null}p(a.canvasX,a.canvasY,b.pos[0]+b.size[0]-5,b.pos[1]+b.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor=null}else this.canvas.style.cursor=null;if(this.node_capturing_input&&
|
||||
this.node_capturing_input!=b&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(c in this.selected_nodes)b=this.selected_nodes[c],b.pos[0]+=d[0]/this.scale,b.pos[1]+=d[1]/this.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]+=d[0]/this.scale,this.resizing_node.size[1]+=d[1]/this.scale,d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?
|
||||
this.resizing_node.outputs.length:0),this.resizing_node.size[1]<d*l.NODE_SLOT_HEIGHT+4&&(this.resizing_node.size[1]=d*l.NODE_SLOT_HEIGHT+4),this.resizing_node.size[0]<l.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=l.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};h.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;h.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=l.getTime();a.click_time=b-this.last_mouseclick;if(1==a.which)if(this.dragging_rectangle){if(this.graph){var d=this.graph._nodes,c=new Float32Array(4);this.deselectAllNodes();0>this.dragging_rectangle[2]&&(this.dragging_rectangle[0]+=this.dragging_rectangle[2]);0>this.dragging_rectangle[3]&&(this.dragging_rectangle[1]+=this.dragging_rectangle[3]);
|
||||
@@ -91,19 +91,19 @@ this.connecting_node.connect(this.connecting_slot,b,l.EVENT):(d=this.isOverNodeI
|
||||
-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.resizing_node=null;else if(this.node_dragged)this.dirty_bgcanvas=this.dirty_canvas=!0,this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]),this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]),this.graph.config.align_to_grid&&this.node_dragged.alignToGrid(),this.node_dragged=null;else{b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!b&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=
|
||||
!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]]);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();
|
||||
a.preventDefault();return!1}};h.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.scale;0<b?d*=1.1:0>b&&(d*=1/1.1);this.setZoom(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};h.prototype.isOverNodeBox=function(a,b,d){var c=l.NODE_TITLE_HEIGHT;return p(b,d,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,c){if(a.inputs)for(var f=
|
||||
0,m=a.inputs.length;f<m;++f){var k=a.getConnectionPos(!0,f);if(p(b,d,k[0]-10,k[1]-5,20,10))return c&&(c[0]=k[0],c[1]=k[1]),f}return-1};h.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){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();
|
||||
0,n=a.inputs.length;f<n;++f){var k=a.getConnectionPos(!0,f);if(p(b,d,k[0]-10,k[1]-5,20,10))return c&&(c[0]=k[0],c[1]=k[1]),f}return-1};h.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){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();
|
||||
if(46==a.keyCode||8==a.keyCode)this.deleteSelectedNodes(),b=!0;if(this.selected_nodes)for(var d in this.selected_nodes)if(this.selected_nodes[d].onKeyDown)this.selected_nodes[d].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in this.selected_nodes)if(this.selected_nodes[d].onKeyUp)this.selected_nodes[d].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),!1}}};h.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,
|
||||
d=[],c;for(c in this.selected_nodes){var f=this.selected_nodes[c];f._relative_id=b;d.push(f);b+=1}for(c=0;c<d.length;++c)if(f=d[c],a.nodes.push(f.clone().serialize()),f.inputs&&f.inputs.length)for(b=0;b<f.inputs.length;++b){var m=f.inputs[b];if(m&&null!=m.link&&(m=this.graph.links[m.link])){var k=this.graph.getNodeById(m.origin_id);k&&this.selected_nodes[k.id]&&a.links.push([k._relative_id,b,f._relative_id,m.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};h.prototype.pasteFromClipboard=
|
||||
d=[],c;for(c in this.selected_nodes){var f=this.selected_nodes[c];f._relative_id=b;d.push(f);b+=1}for(c=0;c<d.length;++c)if(f=d[c],a.nodes.push(f.clone().serialize()),f.inputs&&f.inputs.length)for(b=0;b<f.inputs.length;++b){var n=f.inputs[b];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var k=this.graph.getNodeById(n.origin_id);k&&this.selected_nodes[k.id]&&a.links.push([k._relative_id,b,f._relative_id,n.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};h.prototype.pasteFromClipboard=
|
||||
function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],d=0;d<a.nodes.length;++d){var c=a.nodes[d],f=l.createNode(c.type);f&&(f.configure(c),f.pos[0]+=5,f.pos[1]+=5,this.graph.add(f),b.push(f))}for(d=0;d<a.links.length;++d)c=a.links[d],b[c[0]].connect(c[1],b[c[2]],c[3]);this.selectNodes(b)}};h.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],d=this.graph.getNodeOnPos(b[0],b[1]);if(d){if((d.onDropFile||
|
||||
d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var f=a.dataTransfer.files[0],m=f.name;h.getFileExtension(m);if(d.onDropFile)d.onDropFile(f);if(d.onDropData){var k=new FileReader;k.onload=function(a){d.onDropData(a.target.result,m,f)};var e=f.type.split("/")[0];"text"==e||""==e?k.readAsText(f):"image"==e?k.readAsDataURL(f):k.readAsArrayBuffer(f)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));
|
||||
d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var f=a.dataTransfer.files[0],n=f.name;h.getFileExtension(n);if(d.onDropFile)d.onDropFile(f);if(d.onDropData){var k=new FileReader;k.onload=function(a){d.onDropData(a.target.result,n,f)};var e=f.type.split("/")[0];"text"==e||""==e?k.readAsText(f):"image"==e?k.readAsDataURL(f):k.readAsArrayBuffer(f)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));
|
||||
b||this.checkDropItem(a)};h.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],d=h.getFileExtension(b.name).toLowerCase();if(d=l.node_types_by_file_extension[d])if(d=l.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};h.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};h.prototype.processNodeSelected=
|
||||
function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};h.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};h.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};h.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var c=a[d];if(!c.selected){if(!c.selected&&c.onSelected)c.onSelected();c.selected=
|
||||
!0;this.selected_nodes[c.id]=c;if(c.inputs)for(d=0;d<c.inputs.length;++d)this.highlighted_links[c.inputs[d].link]=!0;if(c.outputs)for(d=0;d<c.outputs.length;++d){var f=c.outputs[d];if(f.links)for(var m=0;m<f.links.length;++m)this.highlighted_links[f.links[m]]=!0}}}this.setDirty(!0)};h.prototype.deselectNode=function(a){if(a.selected){if(a.onDeselected)a.onDeselected();a.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<
|
||||
!0;this.selected_nodes[c.id]=c;if(c.inputs)for(d=0;d<c.inputs.length;++d)this.highlighted_links[c.inputs[d].link]=!0;if(c.outputs)for(d=0;d<c.outputs.length;++d){var f=c.outputs[d];if(f.links)for(var e=0;e<f.links.length;++e)this.highlighted_links[f.links[e]]=!0}}}this.setDirty(!0)};h.prototype.deselectNode=function(a){if(a.selected){if(a.onDeselected)a.onDeselected();a.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 d=a.outputs[b];if(d.links)for(var c=0;c<d.links.length;++c)delete this.highlighted_links[d.links[c]]}}};h.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,d=a.length;b<d;++b){var c=a[b];if(c.selected){if(c.onDeselected)c.onDeselected();c.selected=!1}}this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)}};h.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)};h.prototype.centerOnNode=function(a){this.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.scale;this.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.scale;this.setDirty(!0,!0)};h.prototype.adjustMouseEvent=function(a){var b=this.canvas.getBoundingClientRect();a.localX=a.pageX-b.left;a.localY=a.pageY-b.top;a.canvasX=a.localX/this.scale-this.offset[0];a.canvasY=a.localY/this.scale-this.offset[1]};h.prototype.setZoom=function(a,
|
||||
b){b||(b=[0.5*this.canvas.width,0.5*this.canvas.height]);var d=this.convertOffsetToCanvas(b);this.scale=a;this.scale>this.max_zoom?this.scale=this.max_zoom:this.scale<this.min_zoom&&(this.scale=this.min_zoom);var c=this.convertOffsetToCanvas(b),d=[c[0]-d[0],c[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=function(a,b){b=b||[];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};h.prototype.convertCanvasToOffset=
|
||||
function(a,b){b=b||[];b[0]=(a[0]+this.offset[0])*this.scale;b[1]=(a[1]+this.offset[1])*this.scale;return b};h.prototype.convertEventToCanvas=function(a){var b=this.canvas.getBoundingClientRect();return this.convertOffsetToCanvas([a.pageX-b.left,a.pageY-b.top])};h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};h.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 s=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var c=0,f=a.length;c<f;++c){var m=a[c];(!this.live_mode||m.onDrawBackground||m.onDrawForeground)&&q(this.visible_area,m.getBounding(s))&&d.push(m)}return d};h.prototype.draw=function(a,b){if(this.canvas){var d=l.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;if(this.graph){var c=[-this.offset[0],-this.offset[1]],
|
||||
1),this.graph._nodes.unshift(a))};var s=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var c=0,f=a.length;c<f;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&q(this.visible_area,e.getBounding(s))&&d.push(e)}return d};h.prototype.draw=function(a,b){if(this.canvas){var d=l.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;if(this.graph){var c=[-this.offset[0],-this.offset[1]],
|
||||
f=[c[0]+this.canvas.width/this.scale,c[1]+this.canvas.height/this.scale];this.visible_area=new Float32Array([c[0],c[1],f[0]-c[0],f[1]-c[1]])}(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));
|
||||
var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();a.scale(this.scale,this.scale);a.translate(this.offset[0],
|
||||
this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}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 l.EVENT:b="#F85";break;default:b="#AFA"}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b);
|
||||
@@ -112,32 +112,32 @@ a.restore()}this.dirty_area&&a.restore();a.finish2D&&a.finish2D();this.dirty_can
|
||||
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);this._graph_stack&&this._graph_stack.length&&(b.strokeStyle=this._graph_stack[this._graph_stack.length-1].bgcolor,b.lineWidth=10,b.strokeRect(1,1,a.width-2,a.height-2),b.lineWidth=1);b.restore();b.setTransform(1,0,0,1,0,0);if(this.graph){b.save();
|
||||
b.scale(this.scale,this.scale);b.translate(this.offset[0],this.offset[1]);if(this.background_image&&0.5<this.scale){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.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)}}var c=
|
||||
null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,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}if(this.onBackgroundRender)this.onBackgroundRender(a,b);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 c=new Float32Array(2);h.prototype.drawNode=function(a,b){var d=a.color||l.NODE_DEFAULT_COLOR,h=!0;if(a.flags.skip_title_render||a.graph.isLive())h=!1;a.mouseOver&&(h=!0);a.selected||(this.render_shadows?
|
||||
(b.shadowColor="rgba(0,0,0,0.5)",b.shadowOffsetX=2,b.shadowOffsetY=2,b.shadowBlur=3):b.shadowColor="transparent");if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b)}else{var f=this.editor_alpha;b.globalAlpha=f;var m=a._shape||l.BOX_SHAPE;c.set(a.size);a.flags.collapsed&&(c[0]=l.NODE_COLLAPSED_WIDTH,c[1]=0);a.flags.clip_area&&(b.save(),m==l.BOX_SHAPE?(b.beginPath(),b.rect(0,0,c[0],c[1])):m==l.ROUND_SHAPE?b.roundRect(0,0,c[0],c[1],10):m==
|
||||
l.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI)),b.clip());this.drawNodeShape(a,b,c,d,a.bgcolor,!h,a.selected);b.shadowColor="transparent";b.textAlign="left";b.font=this.inner_text_font;h=0.6<this.scale;m=this.connecting_output;if(!a.flags.collapsed){if(a.inputs)for(var k=0;k<a.inputs.length;k++){var e=a.inputs[k];b.globalAlpha=f;this.connecting_node&&l.isValidConnection(e.type&&m.type)&&(b.globalAlpha=0.4*f);b.fillStyle=null!=e.link?this.default_connection_color.input_on:
|
||||
this.default_connection_color.input_off;var g=a.getConnectionPos(!0,k);g[0]-=a.pos[0];g[1]-=a.pos[1];b.beginPath();e.type===l.EVENT?b.rect(g[0]-6+0.5,g[1]-5+0.5,14,10):b.arc(g[0],g[1],4,0,2*Math.PI);b.fill();h&&(e=null!=e.label?e.label:e.name)&&(b.fillStyle=d,b.fillText(e,g[0]+10,g[1]+5))}this.connecting_node&&(b.globalAlpha=0.4*f);b.lineWidth=1;b.textAlign="right";b.strokeStyle="black";if(a.outputs)for(k=0;k<a.outputs.length;k++)if(e=a.outputs[k],g=a.getConnectionPos(!1,k),g[0]-=a.pos[0],g[1]-=a.pos[1],
|
||||
b.fillStyle=e.links&&e.links.length?this.default_connection_color.output_on:this.default_connection_color.output_off,b.beginPath(),e.type===l.EVENT?b.rect(g[0]-6+0.5,g[1]-5+0.5,14,10):b.arc(g[0],g[1],4,0,2*Math.PI),b.fill(),b.stroke(),h&&(e=null!=e.label?e.label:e.name))b.fillStyle=d,b.fillText(e,g[0]-10,g[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.onDrawForeground)a.onDrawForeground(b)}a.flags.clip_area&&b.restore();b.globalAlpha=1}};h.prototype.drawNodeShape=function(a,b,d,c,f,e,k){b.strokeStyle=
|
||||
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 c=new Float32Array(2);h.prototype.drawNode=function(a,b){var d=a.color||l.NODE_DEFAULT_COLOR,e=!0;if(a.flags.skip_title_render||a.graph.isLive())e=!1;a.mouseOver&&(e=!0);a.selected||(this.render_shadows?
|
||||
(b.shadowColor="rgba(0,0,0,0.5)",b.shadowOffsetX=2,b.shadowOffsetY=2,b.shadowBlur=3):b.shadowColor="transparent");if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b)}else{var f=this.editor_alpha;b.globalAlpha=f;var n=a._shape||l.BOX_SHAPE;c.set(a.size);a.flags.collapsed&&(c[0]=l.NODE_COLLAPSED_WIDTH,c[1]=0);a.flags.clip_area&&(b.save(),n==l.BOX_SHAPE?(b.beginPath(),b.rect(0,0,c[0],c[1])):n==l.ROUND_SHAPE?b.roundRect(0,0,c[0],c[1],10):n==
|
||||
l.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI)),b.clip());this.drawNodeShape(a,b,c,d,a.bgcolor,!e,a.selected);b.shadowColor="transparent";b.textAlign="left";b.font=this.inner_text_font;e=0.6<this.scale;n=this.connecting_output;if(!a.flags.collapsed){if(a.inputs)for(var k=0;k<a.inputs.length;k++){var h=a.inputs[k];b.globalAlpha=f;this.connecting_node&&l.isValidConnection(h.type&&n.type)&&(b.globalAlpha=0.4*f);b.fillStyle=null!=h.link?this.default_connection_color.input_on:
|
||||
this.default_connection_color.input_off;var g=a.getConnectionPos(!0,k);g[0]-=a.pos[0];g[1]-=a.pos[1];b.beginPath();h.type===l.EVENT?b.rect(g[0]-6+0.5,g[1]-5+0.5,14,10):b.arc(g[0],g[1],4,0,2*Math.PI);b.fill();e&&(h=null!=h.label?h.label:h.name)&&(b.fillStyle=d,b.fillText(h,g[0]+10,g[1]+5))}this.connecting_node&&(b.globalAlpha=0.4*f);b.lineWidth=1;b.textAlign="right";b.strokeStyle="black";if(a.outputs)for(k=0;k<a.outputs.length;k++)if(h=a.outputs[k],g=a.getConnectionPos(!1,k),g[0]-=a.pos[0],g[1]-=a.pos[1],
|
||||
b.fillStyle=h.links&&h.links.length?this.default_connection_color.output_on:this.default_connection_color.output_off,b.beginPath(),h.type===l.EVENT?b.rect(g[0]-6+0.5,g[1]-5+0.5,14,10):b.arc(g[0],g[1],4,0,2*Math.PI),b.fill(),b.stroke(),e&&(h=null!=h.label?h.label:h.name))b.fillStyle=d,b.fillText(h,g[0]-10,g[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.onDrawForeground)a.onDrawForeground(b)}a.flags.clip_area&&b.restore();b.globalAlpha=1}};h.prototype.drawNodeShape=function(a,b,d,c,f,e,k){b.strokeStyle=
|
||||
c||l.NODE_DEFAULT_COLOR;b.fillStyle=f||l.NODE_DEFAULT_BGCOLOR;f=l.NODE_TITLE_HEIGHT;var h=a._shape||l.BOX_SHAPE;h==l.BOX_SHAPE?(b.beginPath(),b.rect(0,e?0:-f,d[0]+1,e?d[1]:d[1]+f),b.fill(),b.shadowColor="transparent",k&&(b.strokeStyle="#CCC",b.strokeRect(-0.5,e?-0.5:-f+-0.5,d[0]+2,e?d[1]+2:d[1]+f+2-1),b.strokeStyle=c)):h==l.ROUND_SHAPE?(b.roundRect(0,e?0:-f,d[0],e?d[1]:d[1]+f,10),b.fill()):h==l.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI),b.fill());b.shadowColor="transparent";
|
||||
a.bgImage&&a.bgImage.width&&b.drawImage(a.bgImage,0.5*(d[0]-a.bgImage.width),0.5*(d[1]-a.bgImage.height));a.bgImageUrl&&!a.bgImage&&(a.bgImage=a.loadImage(a.bgImageUrl));if(a.onDrawBackground)a.onDrawBackground(b);e||(b.fillStyle=c||l.NODE_DEFAULT_COLOR,c=b.globalAlpha,b.globalAlpha=0.5*c,h==l.BOX_SHAPE?(b.beginPath(),b.rect(0,-f,d[0]+1,f),b.fill()):h==l.ROUND_SHAPE&&(b.roundRect(0,-f,d[0],f,10,0),b.fill()),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),h==l.ROUND_SHAPE||h==l.CIRCLE_SHAPE?
|
||||
b.arc(0.5*f,-0.5*f,0.5*(f-6),0,2*Math.PI):b.rect(3,-f+3,f-6,f-6),b.fill(),b.globalAlpha=c,b.font=this.title_text_font,(a=a.getTitle())&&0.5<this.scale&&(b.fillStyle=this.node_title_color,b.fillText(a,16,13-f)))};h.prototype.drawNodeCollapsed=function(a,b,c,e){b.strokeStyle=c||l.NODE_DEFAULT_COLOR;b.fillStyle=e||l.NODE_DEFAULT_BGCOLOR;c=l.NODE_COLLAPSED_RADIUS;e=a._shape||l.BOX_SHAPE;e==l.CIRCLE_SHAPE?(b.beginPath(),b.arc(0.5*a.size[0],0.5*a.size[1],c,0,2*Math.PI),b.fill(),b.shadowColor="rgba(0,0,0,0)",
|
||||
b.stroke(),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*a.size[0],0.5*a.size[1],0.5*c,0,2*Math.PI)):e==l.ROUND_SHAPE?(b.beginPath(),b.roundRect(0.5*a.size[0]-c,0.5*a.size[1]-c,2*c,2*c,5),b.fill(),b.shadowColor="rgba(0,0,0,0)",b.stroke(),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.roundRect(0.5*a.size[0]-0.5*c,0.5*a.size[1]-0.5*c,c,c,2)):(b.beginPath(),b.rect(0,0,a.size[0],2*c),b.fill(),b.shadowColor="rgba(0,0,0,0)",b.stroke(),b.fillStyle=a.boxcolor||
|
||||
l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.rect(0.5*c,0.5*c,c,c));b.fill()};h.prototype.drawConnections=function(a){var b=l.getTime();a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=0,e=this.graph._nodes.length;c<e;++c){var f=this.graph._nodes[c];if(f.inputs&&f.inputs.length)for(var h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var g=this.graph.getNodeById(k.origin_id);if(null!=g){var n=
|
||||
k.origin_slot,p=null,p=-1==n?[g.pos[0]+10,g.pos[1]+10]:g.getConnectionPos(!1,n);this.renderLink(a,p,f.getConnectionPos(!0,h),k);k&&k._last_time&&1E3>b-k._last_time&&(g=2-0.002*(b-k._last_time),n="rgba(255,255,255, "+g.toFixed(2)+")",this.renderLink(a,p,f.getConnectionPos(!0,h),k,!0,g,n))}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,f,m,k){if(this.highquality_render){var g=n(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);!k&&e&&(k=h.link_type_colors[e.type]);
|
||||
k||(k=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(k="#FFF");a.beginPath();this.render_curved_connections?(a.moveTo(b[0],b[1]),a.bezierCurveTo(b[0]+0.25*g,b[1],c[0]-0.25*g,c[1],c[0],c[1])):(a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]));this.render_connections_border&&0.6<this.scale&&!f&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();
|
||||
this.render_connection_arrows&&0.6<=this.scale&&this.render_connection_arrows&&0.6<this.scale&&(e=this.computeConnectionPoint(b,c,0.5),f=this.computeConnectionPoint(b,c,0.51),k=0,k=this.render_curved_connections?-Math.atan2(f[0]-e[0],f[1]-e[1]):c[1]>b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(m)for(m=0;5>m;++m)e=(0.001*l.getTime()+0.2*m)%1,e=this.computeConnectionPoint(b,c,e),a.beginPath(),a.arc(e[0],
|
||||
e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};h.prototype.computeConnectionPoint=function(a,b,c){var e=n(a,b),f=[a[0]+0.25*e,a[1]],e=[b[0]-0.25*e,b[1]],h=(1-c)*(1-c)*(1-c),k=3*(1-c)*(1-c)*c,g=3*(1-c)*c*c;c*=c*c;return[h*a[0]+k*f[0]+g*e[0]+c*b[0],h*a[1]+k*f[1]+g*e[1]+c*b[1]]};h.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=
|
||||
l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.rect(0.5*c,0.5*c,c,c));b.fill()};h.prototype.drawConnections=function(a){var b=l.getTime();a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=0,e=this.graph._nodes.length;c<e;++c){var f=this.graph._nodes[c];if(f.inputs&&f.inputs.length)for(var h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var g=this.graph.getNodeById(k.origin_id);if(null!=g){var m=
|
||||
k.origin_slot,p=null,p=-1==m?[g.pos[0]+10,g.pos[1]+10]:g.getConnectionPos(!1,m);this.renderLink(a,p,f.getConnectionPos(!0,h),k);k&&k._last_time&&1E3>b-k._last_time&&(g=2-0.002*(b-k._last_time),m="rgba(255,255,255, "+g.toFixed(2)+")",this.renderLink(a,p,f.getConnectionPos(!0,h),k,!0,g,m))}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,f,g,k){if(this.highquality_render){var t=m(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);!k&&e&&(k=h.link_type_colors[e.type]);
|
||||
k||(k=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(k="#FFF");a.beginPath();this.render_curved_connections?(a.moveTo(b[0],b[1]),a.bezierCurveTo(b[0]+0.25*t,b[1],c[0]-0.25*t,c[1],c[0],c[1])):(a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]));this.render_connections_border&&0.6<this.scale&&!f&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();
|
||||
this.render_connection_arrows&&0.6<=this.scale&&this.render_connection_arrows&&0.6<this.scale&&(e=this.computeConnectionPoint(b,c,0.5),f=this.computeConnectionPoint(b,c,0.51),k=0,k=this.render_curved_connections?-Math.atan2(f[0]-e[0],f[1]-e[1]):c[1]>b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(g)for(g=0;5>g;++g)e=(0.001*l.getTime()+0.2*g)%1,e=this.computeConnectionPoint(b,c,e),a.beginPath(),a.arc(e[0],
|
||||
e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};h.prototype.computeConnectionPoint=function(a,b,c){var e=m(a,b),f=[a[0]+0.25*e,a[1]],e=[b[0]-0.25*e,b[1]],h=(1-c)*(1-c)*(1-c),k=3*(1-c)*(1-c)*c,g=3*(1-c)*c*c;c*=c*c;return[h*a[0]+k*f[0]+g*e[0]+c*b[0],h*a[1]+k*f[1]+g*e[1]+c*b[1]]};h.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=
|
||||
a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var e=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,
|
||||
this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.onNodeSelectionChange=function(a){};h.prototype.touchHandler=function(a){var b=a.changedTouches[0],c="";switch(a.type){case "touchstart":c="mousedown";break;case "touchmove":c="mousemove";break;case "touchend":c="mouseup";break;default:return}var e=this.getCanvasWindow(),f=e.document.createEvent("MouseEvent");f.initMouseEvent(c,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(f);a.preventDefault()};h.onMenuAdd=
|
||||
function(a,b,c,e){function f(a,b){var c=e.getFirstEvent(),d=l.createNode(a.value);d&&(d.pos=g.convertEventToCanvas(c),g.graph.add(d))}var g=h.active_canvas,k=g.getCanvasWindow();a=l.getNodeTypesCategories();b=[];for(var n in a)a[n]&&b.push({value:a[n],content:a[n],has_submenu:!0});var p=new l.ContextMenu(b,{event:c,callback:function(a,b,c){a=l.getNodeTypesInCategory(a.value);b=[];for(var d in a)b.push({content:a[d].title,value:a[d].type});new l.ContextMenu(b,{event:c,callback:f,parentMenu:p},k);return!1},
|
||||
parentMenu:e},k);return!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,c,e,f){function g(a,b,c){f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value&&(f.addInput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0)))}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var n=[];if(b)for(var p in b){var q=b[p];if(q){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};
|
||||
q[1]==l.ACTION&&(r.className="event");n.push(r)}else n.push(null)}this.onMenuNodeInputs&&(n=this.onMenuNodeInputs(n));if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.showMenuNodeOptionalOutputs=function(a,b,c,e,f){function g(a,b,c){if(f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)f.addOutput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0);else{a=[];for(var d in c)a.push({content:d,
|
||||
value:c[d]});new l.ContextMenu(a,{event:b,callback:g,parentMenu:e,node:f});return!1}}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_outputs;f.onGetOutputs&&(b=f.onGetOutputs());var n=[];if(b)for(var p in b){var q=b[p];if(!q)n.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||-1==f.findOutputSlot(q[0])){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==l.EVENT&&(r.className="event");n.push(r)}}this.onMenuNodeOutputs&&(n=this.onMenuNodeOutputs(n));
|
||||
if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.onShowMenuNodeProperties=function(a,b,c,e,f){function g(a,b,c,d){f&&(b=this.getBoundingClientRect(),k.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))}if(f&&f.properties){var k=h.active_canvas;b=k.getCanvasWindow();var n=[],p;for(p in f.properties)a=void 0!==f.properties[p]?f.properties[p]:" ",a=h.decodeHTML(a),n.push({content:"<span class='property_name'>"+p+"</span><span class='property_value'>"+
|
||||
a+"</span>",value:p});if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,c,e,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};h.onShowTitleEditor=function(a,b,c,e,f){function g(){f.title=n.value;k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var k=document.createElement("div");k.className="graphdialog";k.innerHTML=
|
||||
"<span class='name'>Title</span><input autofocus type='text' class='value'/><button>OK</button>";var n=k.querySelector("input");n&&(n.value=f.title,n.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));a=h.active_canvas.canvas;b=a.getBoundingClientRect();e=c=-20;b&&(c-=b.left,e-=b.top);event?(k.style.left=event.pageX+c+"px",k.style.top=event.pageY+e+"px"):(k.style.left=0.5*a.width+c+"px",k.style.top=0.5*a.height+e+"px");k.querySelector("button").addEventListener("click",
|
||||
function(a,b,c,e){function f(a,b){var c=e.getFirstEvent(),d=l.createNode(a.value);d&&(d.pos=g.convertEventToCanvas(c),g.graph.add(d))}var g=h.active_canvas,k=g.getCanvasWindow();a=l.getNodeTypesCategories();b=[];for(var m in a)a[m]&&b.push({value:a[m],content:a[m],has_submenu:!0});var p=new l.ContextMenu(b,{event:c,callback:function(a,b,c){a=l.getNodeTypesInCategory(a.value);b=[];for(var d in a)b.push({content:a[d].title,value:a[d].type});new l.ContextMenu(b,{event:c,callback:f,parentMenu:p},k);return!1},
|
||||
parentMenu:e},k);return!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,c,e,f){function g(a,b,c){f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value&&(f.addInput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0)))}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var m=[];if(b)for(var p in b){var q=b[p];if(q){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};
|
||||
q[1]==l.ACTION&&(r.className="event");m.push(r)}else m.push(null)}this.onMenuNodeInputs&&(m=this.onMenuNodeInputs(m));if(m.length)return new l.ContextMenu(m,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.showMenuNodeOptionalOutputs=function(a,b,c,e,f){function g(a,b,c){if(f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)f.addOutput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0);else{a=[];for(var d in c)a.push({content:d,
|
||||
value:c[d]});new l.ContextMenu(a,{event:b,callback:g,parentMenu:e,node:f});return!1}}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_outputs;f.onGetOutputs&&(b=f.onGetOutputs());var m=[];if(b)for(var p in b){var q=b[p];if(!q)m.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||-1==f.findOutputSlot(q[0])){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==l.EVENT&&(r.className="event");m.push(r)}}this.onMenuNodeOutputs&&(m=this.onMenuNodeOutputs(m));
|
||||
if(m.length)return new l.ContextMenu(m,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.onShowMenuNodeProperties=function(a,b,c,e,f){function g(a,b,c,d){f&&(b=this.getBoundingClientRect(),k.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))}if(f&&f.properties){var k=h.active_canvas;b=k.getCanvasWindow();var m=[],p;for(p in f.properties)a=void 0!==f.properties[p]?f.properties[p]:" ",a=h.decodeHTML(a),m.push({content:"<span class='property_name'>"+p+"</span><span class='property_value'>"+
|
||||
a+"</span>",value:p});if(m.length)return new l.ContextMenu(m,{event:c,callback:g,parentMenu:e,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,c,e,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};h.onShowTitleEditor=function(a,b,c,e,f){function g(){f.title=m.value;k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var k=document.createElement("div");k.className="graphdialog";k.innerHTML=
|
||||
"<span class='name'>Title</span><input autofocus type='text' class='value'/><button>OK</button>";var m=k.querySelector("input");m&&(m.value=f.title,m.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));a=h.active_canvas.canvas;b=a.getBoundingClientRect();e=c=-20;b&&(c-=b.left,e-=b.top);event?(k.style.left=event.pageX+c+"px",k.style.top=event.pageY+e+"px"):(k.style.left=0.5*a.width+c+"px",k.style.top=0.5*a.height+e+"px");k.querySelector("button").addEventListener("click",
|
||||
g);a.parentNode.appendChild(k)};h.prototype.showEditPropertyValue=function(a,b,c){function e(){f(q.value)}function f(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var h="string";null!==a.properties[b]&&(h=typeof a.properties[b]);var k=null;a.getPropertyInfo&&(k=a.getPropertyInfo(b));if(a.properties_info)for(var g=0;g<a.properties_info.length;++g)if(a.properties_info[g].name==
|
||||
b){k=a.properties_info[g];break}void 0!==k&&null!==k&&k.type&&(h=k.type);var n="";if("string"==h||"number"==h)n="<input autofocus type='text' class='value'/>";else if("enum"==h&&k.values){n="<select autofocus type='text' class='value'>";for(g in k.values)var l=k.values.constructor===Array?k.values[g]:g,n=n+("<option value='"+l+"' "+(l==a.properties[b]?"selected":"")+">"+k.values[g]+"</option>");n+="</select>"}else"boolean"==h&&(n="<input autofocus type='checkbox' class='value' "+(a.properties[b]?
|
||||
"checked":"")+"/>");var p=this.createDialog("<span class='name'>"+b+"</span>"+n+"<button>OK</button>",c);if("enum"==h&&k.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==h)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.value=void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});
|
||||
b){k=a.properties_info[g];break}void 0!==k&&null!==k&&k.type&&(h=k.type);var m="";if("string"==h||"number"==h)m="<input autofocus type='text' class='value'/>";else if("enum"==h&&k.values){m="<select autofocus type='text' class='value'>";for(g in k.values)var l=k.values.constructor===Array?k.values[g]:g,m=m+("<option value='"+l+"' "+(l==a.properties[b]?"selected":"")+">"+k.values[g]+"</option>");m+="</select>"}else"boolean"==h&&(m="<input autofocus type='checkbox' class='value' "+(a.properties[b]?
|
||||
"checked":"")+"/>");var p=this.createDialog("<span class='name'>"+b+"</span>"+m+"<button>OK</button>",c);if("enum"==h&&k.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==h)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.value=void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});
|
||||
p.querySelector("button").addEventListener("click",e)}};h.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var e=this.canvas.getBoundingClientRect(),f=-20,h=-20;e&&(f-=e.left,h-=e.top);b.position?(f+=b.position[0],h+=b.position[1]):b.event?(f+=b.event.pageX,h+=b.event.pageY):(f+=0.5*this.canvas.width,h+=0.5*this.canvas.height);c.style.left=f+"px";c.style.top=h+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&
|
||||
this.parentNode.removeChild(this)};return c};h.onMenuNodeCollapse=function(a,b,c,e,f){f.flags.collapsed=!f.flags.collapsed;f.setDirtyCanvas(!0,!0)};h.onMenuNodePin=function(a,b,c,e,f){f.pin()};h.onMenuNodeMode=function(a,b,c,e,f){new l.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(f)switch(a){case "On Event":f.mode=l.ON_EVENT;break;case "On Trigger":f.mode=l.ON_TRIGGER;break;case "Never":f.mode=l.NEVER;break;default:f.mode=l.ALWAYS}},parentMenu:e,node:f});
|
||||
return!1};h.onMenuNodeColors=function(a,b,c,e,f){if(!f)throw"no node for color";b=[];for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:"<span style='display: block; color:"+a.color+"; background-color:"+a.bgcolor+"'>"+g+"</span>"},b.push(a);new l.ContextMenu(b,{event:c,callback:function(a){f&&(a=h.node_colors[a.value])&&(f.color=a.color,f.bgcolor=a.bgcolor,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeShapes=function(a,b,c,e,f){if(!f)throw"no node passed";new l.ContextMenu(l.VALID_SHAPES,
|
||||
@@ -148,7 +148,7 @@ callback:h.onResizeNode},{content:"Collapse",callback:h.onMenuNodeCollapse},{con
|
||||
(c=a.onGetInputs())&&c.length&&(b[0].disabled=!1);a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.processContextMenu=function(a,b){var c=this,e=h.active_canvas.getCanvasWindow(),f=null,g={event:b,callback:function(b,f,e){if(b)if("Remove Slot"==b.content){var k=b.slot;k.input?a.removeInput(k.slot):k.output&&a.removeOutput(k.slot)}else if("Rename Slot"==b.content){var k=b.slot,h=c.createDialog("<span class='name'>Name</span><input type='text'/><button>OK</button>",
|
||||
f),g=h.querySelector("input");h.querySelector("button").addEventListener("click",function(b){if(g.value){if(b=k.input?a.getInputInfo(k.slot):a.getOutputInfo(k.slot))b.label=g.value;c.setDirty(!0)}h.close()})}},node:a},k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(f=[],f.push(k.locked?"Cannot remove":{content:"Remove Slot",slot:k}),f.push({content:"Rename Slot",slot:k}),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==l.ACTION&&(g.title="Action"),
|
||||
k.output&&k.output.type==l.EVENT&&(g.title="Event")):f=a?this.getNodeMenuOptions(a):this.getCanvasMenuOptions();f&&new l.ContextMenu(f,g,e)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,f,h){void 0===f&&(f=5);void 0===h&&(h=f);this.beginPath();this.moveTo(a+f,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+e-h);this.quadraticCurveTo(a+c,b+e,a+c-h,b+e);this.lineTo(a+h,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a,
|
||||
b+f);this.quadraticCurveTo(a,b,a+f,b)});l.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};l.distance=n;l.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};l.isInsideRectangle=p;l.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};l.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||
|
||||
b+f);this.quadraticCurveTo(a,b,a+f,b)});l.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};l.distance=m;l.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};l.isInsideRectangle=p;l.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};l.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};l.overlapBounding=q;l.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,f,h=0;6>h;h+=2)e="0123456789ABCDEF".indexOf(a.charAt(h)),f="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[c]=16*e+f,c++;return b};l.num2hex=function(a){for(var b="#",c,e,f=0;3>f;f++)c=a[f]/16,e=a[f]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};r.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&
|
||||
f.call(this,a)}function f(a){var b=this.value,f=!0;h.current_submenu&&h.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,h,c.node);!0===e&&(f=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,h,c.node),!0===e&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
|
||||
title:b.submenu.title,autoopen:c.autoopen});f=!1}f&&!h.lock&&h.close()}var h=this;c=c||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var g=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(g=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);
|
||||
@@ -159,67 +159,68 @@ b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__loo
|
||||
window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
(function(u){function g(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function e(){this.size=[120,60];this.subgraph=new LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onGlobalInputAdded=this.onSubgraphNewGlobalInput.bind(this);this.subgraph.onGlobalInputRenamed=this.onSubgraphRenamedGlobalInput.bind(this);this.subgraph.onGlobalInputTypeChanged=this.onSubgraphTypeChangeGlobalInput.bind(this);this.subgraph.onGlobalOutputAdded=this.onSubgraphNewGlobalOutput.bind(this);
|
||||
this.subgraph.onGlobalOutputRenamed=this.onSubgraphRenamedGlobalOutput.bind(this);this.subgraph.onGlobalOutputTypeChanged=this.onSubgraphTypeChangeGlobalOutput.bind(this);this.bgcolor="#663"}function h(){var a="input_"+(1E3*Math.random()).toFixed();this.addOutput(a,null);this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var e=b.getOutputInfo(0);e.name!=c&&(e.name=c,b.graph&&b.graph.renameGlobalInput(a,c),
|
||||
a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.outputs[0].type},set:function(c){b.outputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.outputs[0].type)},enumerable:!0})}function n(){var a="output_"+(1E3*Math.random()).toFixed();this.addInput(a,null);this._value=null;this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var e=b.getInputInfo(0);e.name!=c&&(e.name=
|
||||
a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.outputs[0].type},set:function(c){b.outputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.outputs[0].type)},enumerable:!0})}function m(){var a="output_"+(1E3*Math.random()).toFixed();this.addInput(a,null);this._value=null;this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var e=b.getInputInfo(0);e.name!=c&&(e.name=
|
||||
c,b.graph&&b.graph.renameGlobalOutput(a,c),a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.inputs[0].type},set:function(c){b.inputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.inputs[0].type)},enumerable:!0})}function p(){this.addOutput("value","number");this.addProperty("value",1);this.editable={property:"value",type:"number"}}function q(){this.size=[60,20];this.addInput("value",0,{label:""});this.addOutput("value",0,{label:""});this.addProperty("value",
|
||||
"")}function r(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,20]}function l(){this.mode=c.ON_EVENT;this.size=[60,20];this.addProperty("msg","");this.addInput("log",c.EVENT);this.addInput("msg",0)}function s(){this.size=[60,20];this.addProperty("onExecute","");this.addInput("in","");this.addInput("in2","");this.addOutput("out","");this.addOutput("out2","");this._func=null}var c=u.LiteGraph;g.title="Time";g.desc="Time";g.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);
|
||||
this.setOutputData(1,this.graph.globaltime)};c.registerNodeType("basic/time",g);e.title="Subgraph";e.desc="Graph inside a node";e.prototype.onSubgraphNewGlobalInput=function(a,b){this.addInput(a,b)};e.prototype.onSubgraphRenamedGlobalInput=function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).name=b)};e.prototype.onSubgraphTypeChangeGlobalInput=function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).type=b)};e.prototype.onSubgraphNewGlobalOutput=function(a,b){this.addOutput(a,
|
||||
b)};e.prototype.onSubgraphRenamedGlobalOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).name=b)};e.prototype.onSubgraphTypeChangeGlobalOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).type=b)};e.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};e.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);
|
||||
this.subgraph.setGlobalInputData(b.name,c)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)c=this.subgraph.getGlobalOutputData(this.outputs[a].name),this.setOutputData(a,c)};e.prototype.configure=function(a){LGraphNode.prototype.configure.call(this,a)};e.prototype.serialize=function(){var a=LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};e.prototype.clone=function(){var a=c.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;
|
||||
delete b.outputs;a.configure(b);return a};c.registerNodeType("graph/subgraph",e);h.title="Input";h.desc="Input of the graph";h.prototype.onAdded=function(){this.graph.addGlobalInput(this.properties.name,this.properties.type)};h.prototype.onExecute=function(){var a=this.graph.global_inputs[this.properties.name];a&&this.setOutputData(0,a.value)};c.registerNodeType("graph/input",h);n.title="Output";n.desc="Output of the graph";n.prototype.onAdded=function(){this.graph.addGlobalOutput(this.properties.name,
|
||||
this.properties.type)};n.prototype.getValue=function(){return this._value};n.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setGlobalOutputData(this.properties.name,this._value)};c.registerNodeType("graph/output",n);p.title="Const";p.desc="Constant value";p.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a;this.setDirtyCanvas(!0)};p.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};p.prototype.onDrawBackground=
|
||||
delete b.outputs;a.configure(b);return a};c.registerNodeType("graph/subgraph",e);h.title="Input";h.desc="Input of the graph";h.prototype.onAdded=function(){this.graph.addGlobalInput(this.properties.name,this.properties.type)};h.prototype.onExecute=function(){var a=this.graph.global_inputs[this.properties.name];a&&this.setOutputData(0,a.value)};c.registerNodeType("graph/input",h);m.title="Output";m.desc="Output of the graph";m.prototype.onAdded=function(){this.graph.addGlobalOutput(this.properties.name,
|
||||
this.properties.type)};m.prototype.getValue=function(){return this._value};m.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setGlobalOutputData(this.properties.name,this._value)};c.registerNodeType("graph/output",m);p.title="Const";p.desc="Constant value";p.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a;this.setDirtyCanvas(!0)};p.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};p.prototype.onDrawBackground=
|
||||
function(a){this.outputs[0].label=this.properties.value.toFixed(3)};p.prototype.onWidget=function(a,b){"value"==b.name&&this.setValue(b.value)};c.registerNodeType("basic/const",p);q.title="Watch";q.desc="Show value of input";q.prototype.onExecute=function(){this.properties.value=this.getInputData(0);this.setOutputData(0,this.properties.value)};q.prototype.onDrawBackground=function(a){this.inputs[0]&&null!=this.properties.value&&(this.inputs[0].label=this.properties.value.constructor===Number?this.properties.value.toFixed(3):
|
||||
String(this.properties.value))};c.registerNodeType("basic/watch",q);r.title="Pass";r.desc="Allows to connect different types";r.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};c.registerNodeType("basic/pass",r);l.title="Console";l.desc="Show value inside the console";l.prototype.onAction=function(a,b){"log"==a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};l.prototype.onExecute=function(){var a=this.getInputData(1);null!==a&&(this.properties.msg=
|
||||
a);console.log(a)};l.prototype.onGetInputs=function(){return[["log",c.ACTION],["warn",c.ACTION],["error",c.ACTION]]};c.registerNodeType("basic/console",l);s.title="Script";s.desc="executes a code";s.widgets_info={onExecute:{type:"code"}};s.prototype.onPropertyChanged=function(a,b){if("onExecute"==a&&c.allow_scripts){this._func=null;try{this._func=new Function(b)}catch(d){console.error("Error parsing script"),console.error(d)}}};s.prototype.onExecute=function(){if(this._func)try{this._func.call(this)}catch(a){console.error("Error in script"),
|
||||
console.error(a)}};c.registerNodeType("basic/script",s)})(this);
|
||||
(function(u){function g(){this.size=[60,20];this.addInput("event",n.ACTION)}function e(){this.size=[60,20];this.addInput("event",n.ACTION);this.addOutput("event",n.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function h(){this.size=[60,20];this.addProperty("time",1E3);this.addInput("event",n.ACTION);this.addOutput("on_time",n.EVENT);this._pending=[]}var n=u.LiteGraph;g.title="Log Event";g.desc="Log event in console";g.prototype.onAction=function(e,h){console.log(e,h)};
|
||||
n.registerNodeType("events/log",g);e.title="Filter Event";e.desc="Blocks events that do not match the filter";e.prototype.onAction=function(e,h){if(null!=h&&(!this.properties.equal_to||this.properties.equal_to==h)){if(this.properties.has_property){var g=h[this.properties.has_property];if(null==g||this.properties.property_equal_to&&this.properties.property_equal_to!=g)return}this.triggerSlot(0,h)}};n.registerNodeType("events/filter",e);h.title="Delay";h.desc="Delays one event";h.prototype.onAction=
|
||||
function(e,h){this._pending.push([this.properties.time,h])};h.prototype.onExecute=function(){var e=1E3*this.graph.elapsed_time;console.log(this._pending);for(var h=0;h<this._pending.length;++h){var g=this._pending[h];g[0]-=e;0<g[0]||(this._pending.splice(h,1),--h,this.trigger(null,g[1]))}};h.prototype.onGetInputs=function(){return[["event",n.ACTION]]};n.registerNodeType("events/delay",h)})(this);
|
||||
(function(u){function g(){this.addOutput("clicked",s.EVENT);this.addProperty("text","");this.addProperty("font_size",40);this.addProperty("message","");this.size=[64,84]}function e(){this.addInput("","boolean");this.addOutput("v","boolean");this.addOutput("e",s.EVENT);this.properties={font:"",value:!1};this.size=[124,64]}function h(){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 n(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,wcolor:"#7AF",size:50}}function p(){this.size=[160,26];this.addOutput("","number");this.properties={wcolor:"#7AF",min:0,max:1,value:0.5}}function q(){this.size=[160,26];this.addInput("","number");this.properties={min:0,max:1,value:0,wcolor:"#AAF"}}function r(){this.addInputs("",0);this.properties={value:"...",font:"Arial",fontsize:18,color:"#AAA",align:"left",glowSize:0,decimals:1}}function l(){this.size=
|
||||
[200,100];this.properties={borderColor:"#ffffff",bgcolorTop:"#f0f0f0",bgcolorBottom:"#e0e0e0",shadowSize:2,borderRadius:3}}var s=u.LiteGraph;g.title="Button";g.desc="Triggers an event";g.font="Arial";g.prototype.onDrawForeground=function(c){if(!this.flags.collapsed&&(c.fillStyle="black",c.fillRect(1,1,this.size[0]-3,this.size[1]-3),c.fillStyle="#AAF",c.fillRect(0,0,this.size[0]-3,this.size[1]-3),c.fillStyle=this.clicked?"white":this.mouseOver?"#668":"#334",c.fillRect(1,1,this.size[0]-4,this.size[1]-
|
||||
4),this.properties.text||0===this.properties.text)){var a=this.properties.font_size||30;c.textAlign="center";c.fillStyle=this.clicked?"black":"white";c.font=a+"px "+g.font;c.fillText(this.properties.text,0.5*this.size[0],0.5*this.size[1]+0.3*a);c.textAlign="left"}};g.prototype.onMouseDown=function(c,a){if(1<a[0]&&1<a[1]&&a[0]<this.size[0]-2&&a[1]<this.size[1]-2)return this.clicked=!0,this.trigger("clicked",this.properties.message),!0};g.prototype.onMouseUp=function(c){this.clicked=!1};s.registerNodeType("widget/button",
|
||||
g);e.title="Toggle";e.desc="Toggles between true or false";e.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var a=0.5*this.size[1],b=0.8*this.size[1];c.fillStyle="#AAA";c.fillRect(10,b-a,a,a);c.fillStyle=this.properties.value?"#AEF":"#000";c.fillRect(10+0.25*a,b-a+0.25*a,0.5*a,0.5*a);c.textAlign="left";c.font=this.properties.font||(0.8*a).toFixed(0)+"px Arial";c.fillStyle="#AAA";c.fillText(this.title,a+20,0.85*b);c.textAlign="left"}};e.prototype.onExecute=function(){var c=this.getInputData(0);
|
||||
null!=c&&(this.properties.value=c);this.setOutputData(0,this.properties.value)};e.prototype.onMouseDown=function(c,a){if(1<a[0]&&1<a[1]&&a[0]<this.size[0]-2&&a[1]<this.size[1]-2)return this.properties.value=!this.properties.value,this.trigger("e",this.properties.value),!0};s.registerNodeType("widget/toggle",e);h.title="Number";h.desc="Widget to select number value";h.pixels_threshold=10;h.markers_color="#666";h.prototype.onDrawForeground=function(c){var a=0.5*this.size[0],b=this.size[1];30<b?(c.fillStyle=
|
||||
h.markers_color,c.beginPath(),c.moveTo(a,0.1*b),c.lineTo(a+0.1*b,0.2*b),c.lineTo(a+-0.1*b,0.2*b),c.fill(),c.beginPath(),c.moveTo(a,0.9*b),c.lineTo(a+0.1*b,0.8*b),c.lineTo(a+-0.1*b,0.8*b),c.fill(),c.font=(0.7*b).toFixed(1)+"px Arial"):c.font=(0.8*b).toFixed(1)+"px Arial";c.textAlign="center";c.font=(0.7*b).toFixed(1)+"px Arial";c.fillStyle="#EEE";c.fillText(this.properties.value.toFixed(this._precision),a,0.75*b)};h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};h.prototype.onPropertyChanged=
|
||||
function(c,a){var b=(this.properties.step+"").split(".");this._precision=1<b.length?b[1].length:0};h.prototype.onMouseDown=function(c,a){if(!(0>a[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};h.prototype.onMouseMove=function(c){if(this.mouse_captured){var a=this.old_y-c.canvasY;c.shiftKey&&(a*=10);if(c.metaKey||c.altKey)a*=0.1;this.old_y=c.canvasY;c=this._remainder+a/h.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+(c|0)*this.properties.step,
|
||||
this.properties.min,this.properties.max);this.properties.value=c;this.setDirtyCanvas(!0)}};h.prototype.onMouseUp=function(c,a){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(a[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};s.registerNodeType("widget/number",h);n.title="Knob";n.desc="Circular controller";n.widgets=[{name:"increase",text:"+",
|
||||
type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}];n.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};n.prototype.onDrawImageKnob=function(c){if(this.imgfg&&this.imgfg.width){var a=0.5*this.imgbg.width,b=this.size[0]/this.imgfg.width;c.save();c.translate(0,20);c.scale(b,b);c.drawImage(this.imgbg,0,0);c.translate(a,a);
|
||||
c.rotate(2*this.value*Math.PI*6/8+10*Math.PI/8);c.translate(-a,-a);c.drawImage(this.imgfg,0,0);c.restore();this.title&&(c.font="bold 16px Criticized,Tahoma",c.fillStyle="rgba(100,100,100,0.8)",c.textAlign="center",c.fillText(this.title.toUpperCase(),0.5*this.size[0],18),c.textAlign="left")}};n.prototype.onDrawVectorKnob=function(c){if(this.imgfg&&this.imgfg.width){c.lineWidth=1;c.strokeStyle=this.mouseOver?"#FFF":"#AAA";c.fillStyle="#000";c.beginPath();c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.5*
|
||||
this.properties.size,0,2*Math.PI,!0);c.stroke();0<this.value&&(c.strokeStyle=this.properties.wcolor,c.lineWidth=0.2*this.properties.size,c.beginPath(),c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.35*this.properties.size,-0.5*Math.PI+2*Math.PI*this.value,-0.5*Math.PI,!0),c.stroke(),c.lineWidth=1);c.font=0.2*this.properties.size+"px Arial";c.fillStyle="#AAA";c.textAlign="center";var a=this.properties.value;"number"==typeof a&&(a=a.toFixed(2));c.fillText(a,0.5*this.size[0],0.65*this.size[1]);c.textAlign=
|
||||
"left"}};n.prototype.onDrawForeground=function(c){this.onDrawImageKnob(c)};n.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};n.prototype.onMouseDown=function(c){if(this.imgfg&&this.imgfg.width){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]||s.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;
|
||||
this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0}};n.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a-0.01*(c[1]-this.oldmouse[1]);1<a?a=1:0>a&&(a=0);this.value=a;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};n.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};
|
||||
n.prototype.onMouseLeave=function(c){};n.prototype.onWidget=function(c,a){if("increase"==a.name)this.onPropertyChanged("size",this.properties.size+10);else if("decrease"==a.name)this.onPropertyChanged("size",this.properties.size-10)};n.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else if("size"==c)a=parseInt(a),this.properties[c]=a,this.size=[a+4,a+24],this.setDirtyCanvas(!0,!0);else if("min"==c||"max"==c||"value"==c)this.properties[c]=parseFloat(a);else return!1;
|
||||
return!0};s.registerNodeType("widget/knob",n);p.title="H.Slider";p.desc="Linear slider controller";p.prototype.onAdded=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};p.prototype.onDrawVectorial=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.strokeStyle=this.mouseOver?"#FFF":"#AAA",c.fillStyle="#000",c.beginPath(),c.rect(2,0,this.size[0]-4,20),c.stroke(),c.fillStyle=this.properties.wcolor,c.beginPath(),c.rect(2+(this.size[0]-4-20)*this.value,0,20,20),c.fill())};
|
||||
p.prototype.onDrawImage=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.fillStyle="#000",c.fillRect(2,9,this.size[0]-4,2),c.strokeStyle="#333",c.beginPath(),c.moveTo(2,9),c.lineTo(this.size[0]-4,9),c.stroke(),c.strokeStyle="#AAA",c.beginPath(),c.moveTo(2,11),c.lineTo(this.size[0]-4,11),c.stroke(),c.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};p.prototype.onDrawForeground=function(c){this.onDrawImage(c)};p.prototype.onExecute=function(){this.properties.value=
|
||||
this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};p.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};p.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a+(c[0]-this.oldmouse[0])/this.size[0];
|
||||
1<a?a=1:0>a&&(a=0);this.value=a;this.oldmouse=c;this.setDirtyCanvas(!0)}};p.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};p.prototype.onMouseLeave=function(c){};p.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else return!1;return!0};s.registerNodeType("widget/hslider",p);q.title="Progress";q.desc="Shows data in linear progress";q.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};q.prototype.onDrawForeground=
|
||||
function(c){c.lineWidth=1;c.fillStyle=this.properties.wcolor;var a=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),a=Math.min(1,a),a=Math.max(0,a);c.fillRect(2,2,(this.size[0]-4)*a,this.size[1]-4)};s.registerNodeType("widget/progress",q);r.title="Text";r.desc="Shows the input value";r.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];r.prototype.onDrawForeground=
|
||||
function(c){c.fillStyle=this.properties.color;var a=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var b=this.properties.fontsize;c.textAlign=this.properties.align;c.font=b.toString()+"px "+this.properties.font;this.str="number"==typeof a?a.toFixed(this.properties.decimals):a;if("string"==typeof this.str){var a=this.str.split("\\n"),d;for(d in a)c.fillText(a[d],
|
||||
"left"==this.properties.align?15:this.size[0]-15,-0.15*b+b*(parseInt(d)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};r.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var a=0,b;for(b in c){var d=this.last_ctx.measureText(c[b]).width;a<d&&(a=d)}this.size[0]=a+20;this.size[1]=4+c.length*
|
||||
this.properties.fontsize;this.setDirtyCanvas(!0)}};r.prototype.onWidget=function(c,a){"resize"==a.name?this.resize():"led_text"==a.name?(this.properties.font="Digital",this.properties.glowSize=4,this.setDirtyCanvas(!0)):"normal_text"==a.name&&(this.properties.font="Arial",this.setDirtyCanvas(!0))};r.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;this.str="number"==typeof a?a.toFixed(3):a;return!0};s.registerNodeType("widget/text",r);l.title="Panel";l.desc="Non interactive panel";l.widgets=
|
||||
[{name:"update",text:"Update",type:"button"}];l.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))};l.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())};l.prototype.onWidget=function(c,a){"update"==a.name&&(this.lineargradient=null,this.setDirtyCanvas(!0))};s.registerNodeType("widget/panel",l)})(this);
|
||||
(function(u){function g(){this.size=[60,20];this.addInput("event",m.ACTION)}function e(){this.size=[60,20];this.addInput("event",m.ACTION);this.addOutput("event",m.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function h(){this.size=[60,20];this.addProperty("time",1E3);this.addInput("event",m.ACTION);this.addOutput("on_time",m.EVENT);this._pending=[]}var m=u.LiteGraph;g.title="Log Event";g.desc="Log event in console";g.prototype.onAction=function(e,h){console.log(e,h)};
|
||||
m.registerNodeType("events/log",g);e.title="Filter Event";e.desc="Blocks events that do not match the filter";e.prototype.onAction=function(e,h){if(null!=h&&(!this.properties.equal_to||this.properties.equal_to==h)){if(this.properties.has_property){var g=h[this.properties.has_property];if(null==g||this.properties.property_equal_to&&this.properties.property_equal_to!=g)return}this.triggerSlot(0,h)}};m.registerNodeType("events/filter",e);h.title="Delay";h.desc="Delays one event";h.prototype.onAction=
|
||||
function(e,h){this._pending.push([this.properties.time,h])};h.prototype.onExecute=function(){for(var e=1E3*this.graph.elapsed_time,h=0;h<this._pending.length;++h){var g=this._pending[h];g[0]-=e;0<g[0]||(this._pending.splice(h,1),--h,this.trigger(null,g[1]))}};h.prototype.onGetInputs=function(){return[["event",m.ACTION]]};m.registerNodeType("events/delay",h)})(this);
|
||||
(function(u){function g(){this.addOutput("clicked",s.EVENT);this.addProperty("text","");this.addProperty("font_size",40);this.addProperty("message","");this.size=[64,84]}function e(){this.addInput("","boolean");this.addInput("e",s.ACTION);this.addOutput("v","boolean");this.addOutput("e",s.EVENT);this.properties={font:"",value:!1};this.size=[124,64]}function h(){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 m(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,wcolor:"#7AF",size:50}}function p(){this.size=[160,26];this.addOutput("","number");this.properties={wcolor:"#7AF",min:0,max:1,value:0.5}}function q(){this.size=[160,26];this.addInput("","number");this.properties={min:0,max:1,value:0,wcolor:"#AAF"}}function r(){this.addInputs("",0);this.properties={value:"...",font:"Arial",fontsize:18,color:"#AAA",align:"left",glowSize:0,decimals:1}}
|
||||
function l(){this.size=[200,100];this.properties={borderColor:"#ffffff",bgcolorTop:"#f0f0f0",bgcolorBottom:"#e0e0e0",shadowSize:2,borderRadius:3}}var s=u.LiteGraph;g.title="Button";g.desc="Triggers an event";g.font="Arial";g.prototype.onDrawForeground=function(c){if(!this.flags.collapsed&&(c.fillStyle="black",c.fillRect(1,1,this.size[0]-3,this.size[1]-3),c.fillStyle="#AAF",c.fillRect(0,0,this.size[0]-3,this.size[1]-3),c.fillStyle=this.clicked?"white":this.mouseOver?"#668":"#334",c.fillRect(1,1,this.size[0]-
|
||||
4,this.size[1]-4),this.properties.text||0===this.properties.text)){var a=this.properties.font_size||30;c.textAlign="center";c.fillStyle=this.clicked?"black":"white";c.font=a+"px "+g.font;c.fillText(this.properties.text,0.5*this.size[0],0.5*this.size[1]+0.3*a);c.textAlign="left"}};g.prototype.onMouseDown=function(c,a){if(1<a[0]&&1<a[1]&&a[0]<this.size[0]-2&&a[1]<this.size[1]-2)return this.clicked=!0,this.trigger("clicked",this.properties.message),!0};g.prototype.onMouseUp=function(c){this.clicked=
|
||||
!1};s.registerNodeType("widget/button",g);e.title="Toggle";e.desc="Toggles between true or false";e.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var a=0.5*this.size[1],b=0.8*this.size[1];c.fillStyle="#AAA";c.fillRect(10,b-a,a,a);c.fillStyle=this.properties.value?"#AEF":"#000";c.fillRect(10+0.25*a,b-a+0.25*a,0.5*a,0.5*a);c.textAlign="left";c.font=this.properties.font||(0.8*a).toFixed(0)+"px Arial";c.fillStyle="#AAA";c.fillText(this.title,a+20,0.85*b);c.textAlign="left"}};e.prototype.onAction=
|
||||
function(c){this.properties.value=!this.properties.value;this.trigger("e",this.properties.value)};e.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c);this.setOutputData(0,this.properties.value)};e.prototype.onMouseDown=function(c,a){if(1<a[0]&&1<a[1]&&a[0]<this.size[0]-2&&a[1]<this.size[1]-2)return this.properties.value=!this.properties.value,this.trigger("e",this.properties.value),!0};s.registerNodeType("widget/toggle",e);h.title="Number";h.desc="Widget to select number value";
|
||||
h.pixels_threshold=10;h.markers_color="#666";h.prototype.onDrawForeground=function(c){var a=0.5*this.size[0],b=this.size[1];30<b?(c.fillStyle=h.markers_color,c.beginPath(),c.moveTo(a,0.1*b),c.lineTo(a+0.1*b,0.2*b),c.lineTo(a+-0.1*b,0.2*b),c.fill(),c.beginPath(),c.moveTo(a,0.9*b),c.lineTo(a+0.1*b,0.8*b),c.lineTo(a+-0.1*b,0.8*b),c.fill(),c.font=(0.7*b).toFixed(1)+"px Arial"):c.font=(0.8*b).toFixed(1)+"px Arial";c.textAlign="center";c.font=(0.7*b).toFixed(1)+"px Arial";c.fillStyle="#EEE";c.fillText(this.properties.value.toFixed(this._precision),
|
||||
a,0.75*b)};h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};h.prototype.onPropertyChanged=function(c,a){var b=(this.properties.step+"").split(".");this._precision=1<b.length?b[1].length:0};h.prototype.onMouseDown=function(c,a){if(!(0>a[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};h.prototype.onMouseMove=function(c){if(this.mouse_captured){var a=this.old_y-c.canvasY;c.shiftKey&&(a*=10);if(c.metaKey||c.altKey)a*=0.1;this.old_y=c.canvasY;
|
||||
c=this._remainder+a/h.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+(c|0)*this.properties.step,this.properties.min,this.properties.max);this.properties.value=c;this.setDirtyCanvas(!0)}};h.prototype.onMouseUp=function(c,a){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(a[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};
|
||||
s.registerNodeType("widget/number",h);m.title="Knob";m.desc="Circular controller";m.widgets=[{name:"increase",text:"+",type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}];m.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};m.prototype.onDrawImageKnob=function(c){if(this.imgfg&&this.imgfg.width){var a=0.5*this.imgbg.width,
|
||||
b=this.size[0]/this.imgfg.width;c.save();c.translate(0,20);c.scale(b,b);c.drawImage(this.imgbg,0,0);c.translate(a,a);c.rotate(2*this.value*Math.PI*6/8+10*Math.PI/8);c.translate(-a,-a);c.drawImage(this.imgfg,0,0);c.restore();this.title&&(c.font="bold 16px Criticized,Tahoma",c.fillStyle="rgba(100,100,100,0.8)",c.textAlign="center",c.fillText(this.title.toUpperCase(),0.5*this.size[0],18),c.textAlign="left")}};m.prototype.onDrawVectorKnob=function(c){if(this.imgfg&&this.imgfg.width){c.lineWidth=1;c.strokeStyle=
|
||||
this.mouseOver?"#FFF":"#AAA";c.fillStyle="#000";c.beginPath();c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.5*this.properties.size,0,2*Math.PI,!0);c.stroke();0<this.value&&(c.strokeStyle=this.properties.wcolor,c.lineWidth=0.2*this.properties.size,c.beginPath(),c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.35*this.properties.size,-0.5*Math.PI+2*Math.PI*this.value,-0.5*Math.PI,!0),c.stroke(),c.lineWidth=1);c.font=0.2*this.properties.size+"px Arial";c.fillStyle="#AAA";c.textAlign="center";var a=this.properties.value;
|
||||
"number"==typeof a&&(a=a.toFixed(2));c.fillText(a,0.5*this.size[0],0.65*this.size[1]);c.textAlign="left"}};m.prototype.onDrawForeground=function(c){this.onDrawImageKnob(c)};m.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};m.prototype.onMouseDown=function(c){if(this.imgfg&&this.imgfg.width){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]||s.distance([c.canvasX,
|
||||
c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0}};m.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a-0.01*(c[1]-this.oldmouse[1]);1<a?a=1:0>a&&(a=0);this.value=a;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};
|
||||
m.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};m.prototype.onMouseLeave=function(c){};m.prototype.onWidget=function(c,a){if("increase"==a.name)this.onPropertyChanged("size",this.properties.size+10);else if("decrease"==a.name)this.onPropertyChanged("size",this.properties.size-10)};m.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else if("size"==c)a=parseInt(a),this.properties[c]=a,this.size=[a+4,a+24],this.setDirtyCanvas(!0,
|
||||
!0);else if("min"==c||"max"==c||"value"==c)this.properties[c]=parseFloat(a);else return!1;return!0};s.registerNodeType("widget/knob",m);p.title="H.Slider";p.desc="Linear slider controller";p.prototype.onAdded=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};p.prototype.onDrawVectorial=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.strokeStyle=this.mouseOver?"#FFF":"#AAA",c.fillStyle="#000",c.beginPath(),c.rect(2,0,this.size[0]-4,20),c.stroke(),c.fillStyle=this.properties.wcolor,
|
||||
c.beginPath(),c.rect(2+(this.size[0]-4-20)*this.value,0,20,20),c.fill())};p.prototype.onDrawImage=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.fillStyle="#000",c.fillRect(2,9,this.size[0]-4,2),c.strokeStyle="#333",c.beginPath(),c.moveTo(2,9),c.lineTo(this.size[0]-4,9),c.stroke(),c.strokeStyle="#AAA",c.beginPath(),c.moveTo(2,11),c.lineTo(this.size[0]-4,11),c.stroke(),c.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};p.prototype.onDrawForeground=
|
||||
function(c){this.onDrawImage(c)};p.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};p.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};p.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-
|
||||
this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a+(c[0]-this.oldmouse[0])/this.size[0];1<a?a=1:0>a&&(a=0);this.value=a;this.oldmouse=c;this.setDirtyCanvas(!0)}};p.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};p.prototype.onMouseLeave=function(c){};p.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else return!1;return!0};s.registerNodeType("widget/hslider",p);q.title="Progress";q.desc="Shows data in linear progress";q.prototype.onExecute=
|
||||
function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};q.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.wcolor;var a=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),a=Math.min(1,a),a=Math.max(0,a);c.fillRect(2,2,(this.size[0]-4)*a,this.size[1]-4)};s.registerNodeType("widget/progress",q);r.title="Text";r.desc="Shows the input value";r.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",
|
||||
text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];r.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var a=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var b=this.properties.fontsize;c.textAlign=this.properties.align;c.font=b.toString()+"px "+this.properties.font;this.str="number"==typeof a?a.toFixed(this.properties.decimals):
|
||||
a;if("string"==typeof this.str){var a=this.str.split("\\n"),d;for(d in a)c.fillText(a[d],"left"==this.properties.align?15:this.size[0]-15,-0.15*b+b*(parseInt(d)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};r.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var a=0,b;for(b in c){var d=this.last_ctx.measureText(c[b]).width;
|
||||
a<d&&(a=d)}this.size[0]=a+20;this.size[1]=4+c.length*this.properties.fontsize;this.setDirtyCanvas(!0)}};r.prototype.onWidget=function(c,a){"resize"==a.name?this.resize():"led_text"==a.name?(this.properties.font="Digital",this.properties.glowSize=4,this.setDirtyCanvas(!0)):"normal_text"==a.name&&(this.properties.font="Arial",this.setDirtyCanvas(!0))};r.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;this.str="number"==typeof a?a.toFixed(3):a;return!0};s.registerNodeType("widget/text",
|
||||
r);l.title="Panel";l.desc="Non interactive panel";l.widgets=[{name:"update",text:"Update",type:"button"}];l.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))};l.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())};l.prototype.onWidget=function(c,a){"update"==a.name&&(this.lineargradient=null,this.setDirtyCanvas(!0))};s.registerNodeType("widget/panel",
|
||||
l)})(this);
|
||||
(function(u){function g(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",e.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 e=u.LiteGraph;g.title="Gamepad";g.desc="gets the input of the gamepad";g.zero=new Float32Array(2);g.buttons="a b x y lb rb lt rt back start ls rs home".split(" ");
|
||||
g.prototype.onExecute=function(){var e=this.getGamepad(),n=this.properties.threshold||0;e&&(this._left_axis[0]=Math.abs(e.xbox.axes.lx)>n?e.xbox.axes.lx:0,this._left_axis[1]=Math.abs(e.xbox.axes.ly)>n?e.xbox.axes.ly:0,this._right_axis[0]=Math.abs(e.xbox.axes.rx)>n?e.xbox.axes.rx:0,this._right_axis[1]=Math.abs(e.xbox.axes.ry)>n?e.xbox.axes.ry:0,this._triggers[0]=Math.abs(e.xbox.axes.ltrigger)>n?e.xbox.axes.ltrigger:0,this._triggers[1]=Math.abs(e.xbox.axes.rtrigger)>n?e.xbox.axes.rtrigger:0);if(this.outputs)for(n=
|
||||
0;n<this.outputs.length;n++){var p=this.outputs[n];if(p.links&&p.links.length){var q=null;if(e)switch(p.name){case "left_axis":q=this._left_axis;break;case "right_axis":q=this._right_axis;break;case "left_x_axis":q=this._left_axis[0];break;case "left_y_axis":q=this._left_axis[1];break;case "right_x_axis":q=this._right_axis[0];break;case "right_y_axis":q=this._right_axis[1];break;case "trigger_left":q=this._triggers[0];break;case "trigger_right":q=this._triggers[1];break;case "a_button":q=e.xbox.buttons.a?
|
||||
g.prototype.onExecute=function(){var e=this.getGamepad(),m=this.properties.threshold||0;e&&(this._left_axis[0]=Math.abs(e.xbox.axes.lx)>m?e.xbox.axes.lx:0,this._left_axis[1]=Math.abs(e.xbox.axes.ly)>m?e.xbox.axes.ly:0,this._right_axis[0]=Math.abs(e.xbox.axes.rx)>m?e.xbox.axes.rx:0,this._right_axis[1]=Math.abs(e.xbox.axes.ry)>m?e.xbox.axes.ry:0,this._triggers[0]=Math.abs(e.xbox.axes.ltrigger)>m?e.xbox.axes.ltrigger:0,this._triggers[1]=Math.abs(e.xbox.axes.rtrigger)>m?e.xbox.axes.rtrigger:0);if(this.outputs)for(m=
|
||||
0;m<this.outputs.length;m++){var p=this.outputs[m];if(p.links&&p.links.length){var q=null;if(e)switch(p.name){case "left_axis":q=this._left_axis;break;case "right_axis":q=this._right_axis;break;case "left_x_axis":q=this._left_axis[0];break;case "left_y_axis":q=this._left_axis[1];break;case "right_x_axis":q=this._right_axis[0];break;case "right_y_axis":q=this._right_axis[1];break;case "trigger_left":q=this._triggers[0];break;case "trigger_right":q=this._triggers[1];break;case "a_button":q=e.xbox.buttons.a?
|
||||
1:0;break;case "b_button":q=e.xbox.buttons.b?1:0;break;case "x_button":q=e.xbox.buttons.x?1:0;break;case "y_button":q=e.xbox.buttons.y?1:0;break;case "lb_button":q=e.xbox.buttons.lb?1:0;break;case "rb_button":q=e.xbox.buttons.rb?1:0;break;case "ls_button":q=e.xbox.buttons.ls?1:0;break;case "rs_button":q=e.xbox.buttons.rs?1:0;break;case "start_button":q=e.xbox.buttons.start?1:0;break;case "back_button":q=e.xbox.buttons.back?1:0;break;case "button_pressed":for(p=0;p<this._current_buttons.length;++p)this._current_buttons[p]&&
|
||||
!this._previous_buttons[p]&&this.triggerSlot(n,g.buttons[p])}else switch(p.name){case "button_pressed":break;case "left_axis":case "right_axis":q=g.zero;break;default:q=0}this.setOutputData(n,q)}}};g.prototype.getGamepad=function(){var e=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!e)return null;var g=e.call(navigator),e=null;this._previous_buttons.set(this._current_buttons);for(e=this.properties.gamepad_index;4>e;e++)if(g[e]){e=g[e];g=this.xbox_mapping;g||(g=this.xbox_mapping=
|
||||
!this._previous_buttons[p]&&this.triggerSlot(m,g.buttons[p])}else switch(p.name){case "button_pressed":break;case "left_axis":case "right_axis":q=g.zero;break;default:q=0}this.setOutputData(m,q)}}};g.prototype.getGamepad=function(){var e=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!e)return null;var g=e.call(navigator),e=null;this._previous_buttons.set(this._current_buttons);for(e=this.properties.gamepad_index;4>e;e++)if(g[e]){e=g[e];g=this.xbox_mapping;g||(g=this.xbox_mapping=
|
||||
{axes:[],buttons:{},hat:""});g.axes.lx=e.axes[0];g.axes.ly=e.axes[1];g.axes.rx=e.axes[2];g.axes.ry=e.axes[3];g.axes.ltrigger=e.buttons[6].value;g.axes.rtrigger=e.buttons[7].value;for(var p=0;p<e.buttons.length;p++)switch(this._current_buttons[p]=e.buttons[p].pressed,p){case 0:g.buttons.a=e.buttons[p].pressed;break;case 1:g.buttons.b=e.buttons[p].pressed;break;case 2:g.buttons.x=e.buttons[p].pressed;break;case 3:g.buttons.y=e.buttons[p].pressed;break;case 4:g.buttons.lb=e.buttons[p].pressed;break;
|
||||
case 5:g.buttons.rb=e.buttons[p].pressed;break;case 6:g.buttons.lt=e.buttons[p].pressed;break;case 7:g.buttons.rt=e.buttons[p].pressed;break;case 8:g.buttons.back=e.buttons[p].pressed;break;case 9:g.buttons.start=e.buttons[p].pressed;break;case 10:g.buttons.ls=e.buttons[p].pressed;break;case 11:g.buttons.rs=e.buttons[p].pressed;break;case 12:e.buttons[p].pressed&&(g.hat+="up");break;case 13:e.buttons[p].pressed&&(g.hat+="down");break;case 14:e.buttons[p].pressed&&(g.hat+="left");break;case 15:e.buttons[p].pressed&&
|
||||
(g.hat+="right");break;case 16:g.buttons.home=e.buttons[p].pressed}e.xbox=g;return e}};g.prototype.onDrawBackground=function(e){var g=this._left_axis,p=this._right_axis;e.strokeStyle="#88A";e.strokeRect(0.5*(g[0]+1)*this.size[0]-4,0.5*(g[1]+1)*this.size[1]-4,8,8);e.strokeStyle="#8A8";e.strokeRect(0.5*(p[0]+1)*this.size[0]-4,0.5*(p[1]+1)*this.size[1]-4,8,8);g=this.size[1]/this._current_buttons.length;e.fillStyle="#AEB";for(p=0;p<this._current_buttons.length;++p)this._current_buttons[p]&&e.fillRect(0,
|
||||
g*p,6,g)};g.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","number"],["back","number"],["button_pressed",e.EVENT]]};e.registerNodeType("input/gamepad",
|
||||
g)})(this);
|
||||
(function(u){function g(){this.addInput("in","*");this.size=[60,20]}function e(){this.addInput("in");this.addOutput("out");this.size=[60,20]}function h(){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)}function n(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[60,20]}function p(){this.addInput("in",
|
||||
(function(u){function g(){this.addInput("in","*");this.size=[60,20]}function e(){this.addInput("in");this.addOutput("out");this.size=[60,20]}function h(){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)}function m(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[60,20]}function p(){this.addInput("in",
|
||||
"number");this.addOutput("out","number");this.size=[60,20];this.addProperty("min",0);this.addProperty("max",1)}function q(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function r(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function l(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function s(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,
|
||||
20]}function c(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20];this.properties={A:0,B:1}}function a(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[60,20];this.addProperty("factor",1)}function b(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function d(){this.addInput("in","number");this.addOutput("out","number");
|
||||
this.addProperty("factor",0.1);this.size=[60,20];this._value=null}function x(){this.addInput("A","number");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","string",{values:x.values})}function f(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function m(){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:m.values});this.size=[60,40]}function k(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function t(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function D(){this.addInput("vec2",
|
||||
this.addProperty("factor",0.1);this.size=[60,20];this._value=null}function x(){this.addInput("A","number");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","string",{values:x.values})}function f(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function n(){this.addInput("A","number");this.addInput("B",
|
||||
"number");this.addOutput("out","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","string",{values:n.values});this.size=[60,40]}function k(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function t(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function D(){this.addInput("vec2",
|
||||
"vec2");this.addOutput("x","number");this.addOutput("y","number")}function w(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function y(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function A(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)}
|
||||
function C(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function B(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var v=u.LiteGraph;g.title="Converter";g.desc="type A to type B";g.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=
|
||||
0;b<this.outputs.length;b++){var c=this.outputs[b];if(c.links&&c.links.length){var d=null;switch(c.name){case "number":d=a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":d=1;switch(c.name){case "vec2":d=2;break;case "vec3":d=3;break;case "vec4":d=4}d=new Float32Array(d);if(a.length)for(c=0;c<a.length&&c<d.length;c++)d[c]=a[c];else d[0]=parseFloat(a)}this.setOutputData(b,d)}}};g.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4",
|
||||
"vec4"]]};v.registerNodeType("math/converter",g);e.title="Bypass";e.desc="removes the type";e.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,a)};v.registerNodeType("math/bypass",e);h.title="Range";h.desc="Convert a number from one range to another";h.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}c=this.properties["in"];if(void 0===c||null===c||c.constructor!==
|
||||
Number)c=0;a=this.properties.in_min;b=this.properties.out_min;this._last_v=(c-a)/(this.properties.in_max-a)*(this.properties.out_max-b)+b;this.setOutputData(0,this._last_v)};h.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};h.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};v.registerNodeType("math/range",h);n.title="Rand";n.desc="Random number";n.prototype.onExecute=function(){if(this.inputs)for(var a=
|
||||
0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;b=this.properties.max;this._last_v=Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};n.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};n.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};v.registerNodeType("math/rand",n);p.title="Clamp";p.desc="Clamp number between min and max";
|
||||
Number)c=0;a=this.properties.in_min;b=this.properties.out_min;this._last_v=(c-a)/(this.properties.in_max-a)*(this.properties.out_max-b)+b;this.setOutputData(0,this._last_v)};h.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};h.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};v.registerNodeType("math/range",h);m.title="Rand";m.desc="Random number";m.prototype.onExecute=function(){if(this.inputs)for(var a=
|
||||
0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;b=this.properties.max;this._last_v=Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};m.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};m.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};v.registerNodeType("math/rand",m);p.title="Clamp";p.desc="Clamp number between min and max";
|
||||
p.filter="shader";p.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))};p.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};v.registerNodeType("math/clamp",p);q.title="Lerp";q.desc="Linear Interpolation";q.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);
|
||||
null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};q.prototype.onGetInputs=function(){return[["f","number"]]};v.registerNodeType("math/lerp",q);r.title="Abs";r.desc="Absolute";r.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};v.registerNodeType("math/abs",r);l.title="Floor";l.desc="Floor number to remove fractional part";l.prototype.onExecute=function(){var a=this.getInputData(0);
|
||||
null!=a&&this.setOutputData(0,Math.floor(a))};v.registerNodeType("math/floor",l);s.title="Frac";s.desc="Returns fractional part";s.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};v.registerNodeType("math/frac",s);c.title="Smoothstep";c.desc="Smoothstep";c.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))}};v.registerNodeType("math/smoothstep",
|
||||
@@ -228,8 +229,8 @@ function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);var c=this._value
|
||||
(1-b)+a*b;this.setOutputData(0,this._value)};v.registerNodeType("math/tendTo",d);x.values="+-*/%^".split("");x.title="Operation";x.desc="Easy math operators";x["@OP"]={type:"enum",title:"operation",values:x.values};x.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};x.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=b:b=this.properties.B;var c=0;switch(this.properties.OP){case "+":c=
|
||||
a+b;break;case "-":c=a-b;break;case "x":case "X":case "*":c=a*b;break;case "/":c=a/b;break;case "%":c=a%b;break;case "^":c=Math.pow(a,b);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,c)};x.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="black",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.5*this.size[1]+v.NODE_TITLE_HEIGHT),a.textAlign="left")};v.registerNodeType("math/operation",x);
|
||||
f.title="Compare";f.desc="compares between two values";f.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,d=this.outputs.length;c<d;++c){var e=this.outputs[c];if(e.links&&e.links.length){switch(e.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(c,value)}}};f.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};v.registerNodeType("math/compare",f);m.values="> < == != <= >=".split(" ");m["@OP"]={type:"enum",title:"operation",values:m.values};m.title="Condition";m.desc="evaluates condition between A and B";m.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;
|
||||
var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a<b;break;case "==":c=a==b;break;case "!=":c=a!=b;break;case "<=":c=a<=b;break;case ">=":c=a>=b}this.setOutputData(0,c)};v.registerNodeType("math/condition",m);k.title="Accumulate";k.desc="Increments a value every time";k.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=
|
||||
a>=b}this.setOutputData(c,value)}}};f.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};v.registerNodeType("math/compare",f);n.values="> < == != <= >=".split(" ");n["@OP"]={type:"enum",title:"operation",values:n.values};n.title="Condition";n.desc="evaluates condition between A and B";n.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;
|
||||
var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a<b;break;case "==":c=a==b;break;case "!=":c=a!=b;break;case "<=":c=a<=b;break;case ">=":c=a>=b}this.setOutputData(0,c)};v.registerNodeType("math/condition",n);k.title="Accumulate";k.desc="Increments a value every time";k.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=
|
||||
null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};v.registerNodeType("math/accumulate",k);t.title="Trigonometry";t.desc="Sin Cos Tan";t.filter="shader";t.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,c=this.findInputSlot("amplitude");-1!=c&&(b=this.getInputData(c));var d=this.properties.offset,c=this.findInputSlot("offset");-1!=c&&(d=this.getInputData(c));for(var c=
|
||||
0,e=this.outputs.length;c<e;++c){switch(this.outputs[c].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(c,b*value+d)}};t.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};t.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],
|
||||
["asin","number"],["acos","number"],["atan","number"]]};v.registerNodeType("math/trigonometry",t);if(void 0!=typeof math){var z=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};z.title="Formula";z.desc="Compute safe formula";z.prototype.onExecute=function(){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;a=math.eval(this.properties.formula,
|
||||
@@ -242,18 +243,18 @@ e)};v.registerNodeType("math3d/xyzw-to-vec4",B);u.glMatrix&&(u=function(){this.a
|
||||
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))},v.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))}},v.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 c=this.properties.factor;null!=this.getInputData(2)&&(c=this.getInputData(2));a=quat.slerp(this._value,a,b,c);this.setOutputData(0,a)}}},v.registerNodeType("math3d/quat-slerp",u))})(this);
|
||||
(function(u){function g(){this.addInput("sel","boolean");this.addOutput("value","number");this.properties={A:0,B:1};this.size=[60,20]}u=u.LiteGraph;g.title="Selector";g.desc="outputs A if selector is true, B if selector is false";g.prototype.onExecute=function(){var e=this.getInputData(0);if(void 0!==e){for(var g=1;g<this.inputs.length;g++){var n=this.inputs[g],p=this.getInputData(g);void 0!==p&&(this.properties[n.name]=p)}g=this.properties.A;n=this.properties.B;this.setOutputData(0,e?g:n)}};g.prototype.onGetInputs=
|
||||
(function(u){function g(){this.addInput("sel","boolean");this.addOutput("value","number");this.properties={A:0,B:1};this.size=[60,20]}u=u.LiteGraph;g.title="Selector";g.desc="outputs A if selector is true, B if selector is false";g.prototype.onExecute=function(){var e=this.getInputData(0);if(void 0!==e){for(var g=1;g<this.inputs.length;g++){var m=this.inputs[g],p=this.getInputData(g);void 0!==p&&(this.properties[m.name]=p)}g=this.properties.A;m=this.properties.B;this.setOutputData(0,e?g:m)}};g.prototype.onGetInputs=
|
||||
function(){return[["A",0],["B",0]]};u.registerNodeType("logic/selector",g)})(this);
|
||||
(function(u){function g(){this.addInput("A","Number");this.addInput("B","Number");this.addInput("C","Number");this.addInput("D","Number");this.values=[[],[],[],[]];this.properties={scale:2}}function e(){this.addOutput("frame","image");this.properties={url:""}}function h(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function n(){this.addInput("","image");this.size=[200,200]}function p(){this.addInputs([["img1",
|
||||
(function(u){function g(){this.addInput("A","Number");this.addInput("B","Number");this.addInput("C","Number");this.addInput("D","Number");this.values=[[],[],[],[]];this.properties={scale:2}}function e(){this.addOutput("frame","image");this.properties={url:""}}function h(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function m(){this.addInput("","image");this.size=[200,200]}function p(){this.addInputs([["img1",
|
||||
"image"],["img2","image"],["fade","number"]]);this.addOutput("","image");this.properties={fade:0.5,width:512,height:512}}function q(){this.addInput("","image");this.addOutput("","image");this.properties={width:256,height:256,x:0,y:0,scale:1};this.size=[50,20]}function r(){this.addInput("t","number");this.addOutputs([["frame","image"],["t","number"],["d","number"]]);this.properties={url:"",use_proxy:!0}}function l(){this.addOutput("Webcam","image");this.properties={}}var s=u.LiteGraph;g.title="Plot";
|
||||
g.desc="Plots data over time";g.colors=["#FFF","#F99","#9F9","#99F"];g.prototype.onExecute=function(c){if(!this.flags.collapsed){c=this.size;for(var a=0;4>a;++a){var b=this.getInputData(a);if(null!=b){var d=this.values[a];d.push(b);d.length>c[0]&&d.shift()}}}};g.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var a=this.size,b=0.5*a[1]/this.properties.scale,d=g.colors,e=0.5*a[1];c.fillStyle="#000";c.fillRect(0,0,a[0],a[1]);c.strokeStyle="#555";c.beginPath();c.moveTo(0,e);c.lineTo(a[0],
|
||||
e);c.stroke();for(var f=0;4>f;++f){var h=this.values[f];c.strokeStyle=d[f];c.beginPath();var k=h[0]*b*-1+e;c.moveTo(0,Math.clamp(k,0,a[1]));for(var l=1;l<h.length&&l<a[0];++l)k=h[l]*b*-1+e,c.lineTo(l,Math.clamp(k,0,a[1]));c.stroke()}}};s.registerNodeType("graphics/plot",g);e.title="Image";e.desc="Image loader";e.widgets=[{name:"load",text:"Load",type:"button"}];e.supported_extensions=["jpg","jpeg","png","gif"];e.prototype.onAdded=function(){""!=this.properties.url&&null==this.img&&this.loadImage(this.properties.url)};
|
||||
e.prototype.onDrawBackground=function(c){this.img&&5<this.size[0]&&5<this.size[1]&&c.drawImage(this.img,0,0,this.size[0],this.size[1])};e.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)};e.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;"url"==c&&""!=a&&this.loadImage(a);return!0};e.prototype.loadImage=function(c,a){if(""==c)this.img=null;
|
||||
else{this.img=document.createElement("img");"http"==c.substr(0,4)&&s.proxy&&(c=s.proxy+c.substr(c.indexOf(":")+3));this.img.src=c;this.boxcolor="#F95";var b=this;this.img.onload=function(){a&&a(this);b.trace("Image loaded, size: "+b.img.width+"x"+b.img.height);this.dirty=!0;b.boxcolor="#9F9";b.setDirtyCanvas(!0)}}};e.prototype.onWidget=function(c,a){"load"==a.name&&this.loadImage(this.properties.url)};e.prototype.onDropFile=function(c){var a=this;this._url&&URL.revokeObjectURL(this._url);this._url=
|
||||
URL.createObjectURL(c);this.properties.url=this._url;this.loadImage(this._url,function(b){a.size[1]=b.height/b.width*a.size[0]})};s.registerNodeType("graphics/image",e);h.title="Palette";h.desc="Generates a color";h.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 a=this.getInputData(0);null==a&&(a=0.5);1<a?a=1:0>a&&(a=0);if(0!=c.length){var b=[0,0,0];if(0==a)b=c[0];else if(1==a)b=c[c.length-1];else{var d=(c.length-1)*a,a=c[Math.floor(d)],c=c[Math.floor(d)+1],d=d-Math.floor(d);b[0]=a[0]*(1-d)+c[0]*d;b[1]=a[1]*(1-d)+c[1]*d;b[2]=a[2]*(1-d)+c[2]*d}for(var e in b)b[e]/=255;this.boxcolor=colorToString(b);this.setOutputData(0,b)}};s.registerNodeType("color/palette",h);n.title="Frame";n.desc="Frame viewerew";n.widgets=[{name:"resize",text:"Resize box",type:"button"},
|
||||
{name:"view",text:"View Image",type:"button"}];n.prototype.onDrawBackground=function(c){this.frame&&c.drawImage(this.frame,0,0,this.size[0],this.size[1])};n.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};n.prototype.onWidget=function(c,a){if("resize"==a.name&&this.frame){var b=this.frame.width,d=this.frame.height;b||null==this.frame.videoWidth||(b=this.frame.videoWidth,d=this.frame.videoHeight);b&&d&&(this.size=[b,d]);this.setDirtyCanvas(!0,!0)}else"view"==
|
||||
a.name&&this.show()};n.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};s.registerNodeType("graphics/frame",n);p.title="Image fade";p.desc="Fades between images";p.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];p.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};p.prototype.createCanvas=function(){this.canvas=
|
||||
var a=this.getInputData(0);null==a&&(a=0.5);1<a?a=1:0>a&&(a=0);if(0!=c.length){var b=[0,0,0];if(0==a)b=c[0];else if(1==a)b=c[c.length-1];else{var d=(c.length-1)*a,a=c[Math.floor(d)],c=c[Math.floor(d)+1],d=d-Math.floor(d);b[0]=a[0]*(1-d)+c[0]*d;b[1]=a[1]*(1-d)+c[1]*d;b[2]=a[2]*(1-d)+c[2]*d}for(var e in b)b[e]/=255;this.boxcolor=colorToString(b);this.setOutputData(0,b)}};s.registerNodeType("color/palette",h);m.title="Frame";m.desc="Frame viewerew";m.widgets=[{name:"resize",text:"Resize box",type:"button"},
|
||||
{name:"view",text:"View Image",type:"button"}];m.prototype.onDrawBackground=function(c){this.frame&&c.drawImage(this.frame,0,0,this.size[0],this.size[1])};m.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};m.prototype.onWidget=function(c,a){if("resize"==a.name&&this.frame){var b=this.frame.width,d=this.frame.height;b||null==this.frame.videoWidth||(b=this.frame.videoWidth,d=this.frame.videoHeight);b&&d&&(this.size=[b,d]);this.setDirtyCanvas(!0,!0)}else"view"==
|
||||
a.name&&this.show()};m.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};s.registerNodeType("graphics/frame",m);p.title="Image fade";p.desc="Fades between images";p.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];p.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};p.prototype.createCanvas=function(){this.canvas=
|
||||
document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};p.prototype.onExecute=function(){var c=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;var a=this.getInputData(0);null!=a&&c.drawImage(a,0,0,this.canvas.width,this.canvas.height);a=this.getInputData(2);null==a?a=this.properties.fade:this.properties.fade=a;c.globalAlpha=a;a=this.getInputData(1);null!=a&&c.drawImage(a,0,0,this.canvas.width,this.canvas.height);c.globalAlpha=
|
||||
1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};s.registerNodeType("graphics/imagefade",p);q.title="Crop";q.desc="Crop Image";q.prototype.onAdded=function(){this.createCanvas()};q.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};q.prototype.onExecute=function(){var c=this.getInputData(0);c&&(c.width?(this.canvas.getContext("2d").drawImage(c,-this.properties.x,-this.properties.y,
|
||||
c.width*this.properties.scale,c.height*this.properties.scale),this.setOutputData(0,this.canvas)):this.setOutputData(0,null))};q.prototype.onDrawBackground=function(c){this.flags.collapsed||this.canvas&&c.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,this.size[0],this.size[1])};q.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;"scale"==c?(this.properties[c]=parseFloat(a),0==this.properties[c]&&(this.trace("Error in scale"),this.properties[c]=1)):this.properties[c]=
|
||||
@@ -274,8 +275,8 @@ gl.LINEAR);this.setOutputData(0,a);for(var b=1;b<this.outputs.length;b++){var c=
|
||||
else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=e.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())}};e.generateLowResTexturePreview=function(a){if(!a)return null;var b=e.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};e.prototype.getResources=function(a){a[this.properties.name]=GL.Texture;return a};e.prototype.onGetInputs=function(){return[["in","Texture"]]};e.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};g.registerNodeType("texture/texture",
|
||||
e);var h=function(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[e.image_preview_size,e.image_preview_size]};h.title="Preview";h.desc="Show a texture in the graph canvas";h.allow_preview=!1;h.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||h.allow_preview)){var b=this.getInputData(0);if(b){var c=null,c=!b.handle&&a.webgl?b:e.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(c,
|
||||
0,0,this.size[0],this.size[1]);a.restore()}}};g.registerNodeType("texture/preview",h);var n=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={name:""}};n.title="Save";n.desc="Save a texture in the repository";n.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(e.storeTexture?e.storeTexture(this.properties.name,a):e.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};g.registerNodeType("texture/save",
|
||||
n);var p=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="<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",
|
||||
0,0,this.size[0],this.size[1]);a.restore()}}};g.registerNodeType("texture/preview",h);var m=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={name:""}};m.title="Save";m.desc="Save a texture in the repository";m.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(e.storeTexture?e.storeTexture(this.properties.name,a):e.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};g.registerNodeType("texture/save",
|
||||
m);var p=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="<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:e.DEFAULT}};p.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo",values:e.MODE_VALUES}};p.title="Operation";p.desc="Texture shader operation";p.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};p.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||
|
||||
!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())};p.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===e.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,d=512;a?(c=a.width,d=a.height):b&&(c=b.width,d=b.height);var f=e.getTextureType(this.properties.precision,a);this._tex=a||this._tex?e.getTargetTexture(a||
|
||||
this._tex,this._tex,this.properties.precision):new GL.Texture(c,d,{type:f,format:gl.RGBA,filter:gl.LINEAR});f="";this.properties.uvcode&&(f="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(f=this.properties.uvcode));var k="";this.properties.pixelcode&&(k="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(k=this.properties.pixelcode));var g=this._shader;if(!g||this._shader_code!=f+"|"+k){try{this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,
|
||||
@@ -295,18 +296,18 @@ gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Me
|
||||
g.registerNodeType("texture/warp",l);var s=function(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1};this.size[0]=130};s.title="to Viewport";s.desc="Texture to viewport";s.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA,gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);
|
||||
var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);if(this.properties.antialiasing){s._shader||(s._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,s.aa_pixel_shader));gl.getViewport();var c=Mesh.getScreenQuad();a.bind(0);s._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(c)}else 1!=b?(s._gamma_shader||(s._gamma_shader=
|
||||
new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.gamma_pixel_shader)),a.toViewport(s._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport()}};s.prototype.onGetInputs=function(){return[["gamma","number"]]};s.aa_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 uViewportSize;\n\t\t\tuniform vec2 inverseVP;\n\t\t\tuniform float u_igamma;\n\t\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\t\n\t\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t\t{\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\t\n\t\t\t\tvec2 dir;\n\t\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\t\n\t\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\t\n\t\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\t\n\t\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\t\n\t\t\t\t//return vec4(rgbA,1.0);\n\t\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\t\telse\n\t\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\t\tif(u_igamma != 1.0)\n\t\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\t\treturn color;\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t\t}\n\t\t\t";
|
||||
s.gamma_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_igamma;\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t\t gl_FragColor = color;\n\t\t\t}\n\t\t\t";g.registerNodeType("texture/toviewport",s);n=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,
|
||||
precision:e.DEFAULT}};n.title="Copy";n.desc="Copy Texture";n.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:e.MODE_VALUES}};n.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,c=a.height;0!=this.properties.size&&(c=b=this.properties.size);var d=this._temp_texture,f=a.type;this.properties.precision===e.LOW?f=gl.UNSIGNED_BYTE:this.properties.precision===e.HIGH&&
|
||||
s.gamma_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_igamma;\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t\t gl_FragColor = color;\n\t\t\t}\n\t\t\t";g.registerNodeType("texture/toviewport",s);m=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,
|
||||
precision:e.DEFAULT}};m.title="Copy";m.desc="Copy Texture";m.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:e.MODE_VALUES}};m.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,c=a.height;0!=this.properties.size&&(c=b=this.properties.size);var d=this._temp_texture,f=a.type;this.properties.precision===e.LOW?f=gl.UNSIGNED_BYTE:this.properties.precision===e.HIGH&&
|
||||
(f=gl.HIGH_PRECISION_FORMAT);d&&d.width==b&&d.height==c&&d.type==f||(d=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(c)&&(d=gl.LINEAR_MIPMAP_LINEAR),this._temp_texture=new GL.Texture(b,c,{type:f,format:gl.RGBA,minFilter:d,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}};g.registerNodeType("texture/copy",
|
||||
n);var c=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:e.DEFAULT}};c.title="Downsample";c.desc="Downsample Texture";c.widgets_info={iterations:{type:"number",step:1,precision:0,min:1},precision:{widget:"combo",values:e.MODE_VALUES}};c.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D){var b=c._shader;b||(c._shader=
|
||||
m);var c=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:e.DEFAULT}};c.title="Downsample";c.desc="Downsample Texture";c.widgets_info={iterations:{type:"number",step:1,precision:0,min:1},precision:{widget:"combo",values:e.MODE_VALUES}};c.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D){var b=c._shader;b||(c._shader=
|
||||
b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,c.pixel_shader));var d=a.width|0,f=a.height|0,k=a.type;this.properties.precision===e.LOW?k=gl.UNSIGNED_BYTE:this.properties.precision===e.HIGH&&(k=gl.HIGH_PRECISION_FORMAT);var g=this.properties.iterations||1,h=a,l=null,m=[],a={type:k,format:a.format},k=vec2.create(),n={u_offset:k};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var p=0;p<g;++p){k[0]=1/d;k[1]=1/f;d=d>>1||0;f=f>>1||0;l=GL.Texture.getTemporary(d,f,a);m.push(l);h.setParameter(GL.TEXTURE_MAG_FILTER,
|
||||
GL.NEAREST);h.copyTo(l,b,n);if(1==d&&1==f)break;h=l}this._texture=m.pop();for(p=0;p<m.length;++p)GL.Texture.releaseTemporary(m[p]);this.properties.generate_mipmaps&&(this._texture.bind(0),gl.generateMipmap(this._texture.texture_type),this._texture.unbind(0));this.setOutputData(0,this._texture)}};c.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";
|
||||
g.registerNodeType("texture/downsample",c);var a=function(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg","vec4");this.addOutput("lum","number");this.properties={mipmap_offset:0,low_precision:!1};this._uniforms={u_texture:0,u_mipmap_offset:this.properties.mipmap_offset};this._luminance=new Float32Array(4)};a.title="Average";a.desc="Compute a partial average (32 random samples) of a texture and stores it as a 1x1 pixel texture";a.prototype.onExecute=function(){var b=
|
||||
this.getInputData(0);if(b&&(this.isOutputConnected(0)||this.isOutputConnected(1)||this.isOutputConnected(2))){if(!a._shader){a._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,a.pixel_shader);for(var c=new Float32Array(32),d=0;32>d;++d)c[d]=Math.random();a._shader.uniforms({u_samples_a:c.subarray(0,16),u_samples_b:c.subarray(16,32)})}d=this._temp_texture;c=gl.UNSIGNED_BYTE;b.type!=c&&(c=gl.FLOAT);d&&d.type==c||(this._temp_texture=new GL.Texture(1,1,{type:c,format:gl.RGBA,filter:gl.NEAREST}));
|
||||
var e=a._shader,f=this._uniforms;f.u_mipmap_offset=this.properties.mipmap_offset;this._temp_texture.drawTo(function(){b.toViewport(e,f)});this.setOutputData(0,this._temp_texture);if(this.isOutputConnected(1)||this.isOutputConnected(2))if(d=this._temp_texture.getPixels()){var k=this._luminance,c=this._temp_texture.type;k.set(d);c==gl.UNSIGNED_BYTE?vec4.scale(k,k,1/255):c!=GL.HALF_FLOAT&&c!=GL.HALF_FLOAT_OES||vec4.scale(k,k,1/65025);this.setOutputData(1,k);this.setOutputData(2,(k[0]+k[1]+k[2])/3)}}};
|
||||
a.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t";
|
||||
g.registerNodeType("texture/average",a);n=function(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}};n.title="Image to Texture";n.desc="Uploads an image to the GPU";n.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,c=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var d=this._temp_texture;d&&d.width==b&&d.height==c||(this._temp_texture=new GL.Texture(b,c,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(e){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+
|
||||
e);return}this.setOutputData(0,this._temp_texture)}}};g.registerNodeType("texture/imageToTexture",n);var b=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={intensity:1,precision:e.DEFAULT,texture:null};b._shader||(b._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader))};b.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:e.MODE_VALUES}};b.title="LUT";b.desc=
|
||||
g.registerNodeType("texture/average",a);m=function(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}};m.title="Image to Texture";m.desc="Uploads an image to the GPU";m.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,c=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var d=this._temp_texture;d&&d.width==b&&d.height==c||(this._temp_texture=new GL.Texture(b,c,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(e){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+
|
||||
e);return}this.setOutputData(0,this._temp_texture)}}};g.registerNodeType("texture/imageToTexture",m);var b=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={intensity:1,precision:e.DEFAULT,texture:null};b._shader||(b._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader))};b.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:e.MODE_VALUES}};b.title="LUT";b.desc=
|
||||
"Apply LUT to Texture";b.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===e.PASS_THROUGH)this.setOutputData(0,a);else if(a){var c=this.getInputData(1);c||(c=e.getTexture(this.properties.texture));if(c){c.bind(0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D,
|
||||
null);var d=this.properties.intensity;this.isInputConnected(2)&&(this.properties.intensity=d=this.getInputData(2));this._tex=e.getTargetTexture(a,this._tex,this.properties.precision);this._tex.drawTo(function(){c.bind(1);a.toViewport(b._shader,{u_texture:0,u_textureB:1,u_amount:d})});this.setOutputData(0,this._tex)}else this.setOutputData(0,a)}}};b.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_amount;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t\t mediump vec2 quad1;\n\t\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t\t mediump vec2 quad2;\n\t\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t\t highp vec2 texPos1;\n\t\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t highp vec2 texPos2;\n\t\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t\t}\n\t\t\t";
|
||||
g.registerNodeType("texture/LUT",b);var d=function(){this.addInput("Texture","Texture");this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");this.properties={};d._shader||(d._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader))};d.title="Texture to Channels";d.desc="Split texture channels";d.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b=0,c=0;4>c;c++)this.isOutputConnected(c)?
|
||||
@@ -317,9 +318,9 @@ a[1].bind(1);a[2].bind(2);a[3].bind(3);c.uniforms({u_textureR:0,u_textureG:1,u_t
|
||||
g.registerNodeType("texture/channelsTexture",x);var f=function(){this.addInput("A","color");this.addInput("B","color");this.addOutput("Texture","Texture");this.properties={angle:0,scale:1,A:[0,0,0],B:[1,1,1],texture_size:32};f._shader||(f._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}};f.title="Gradient";f.desc="Generates a gradient";f["@A"]={type:"color"};f["@B"]={type:"color"};f["@texture_size"]={type:"enum",
|
||||
values:[32,64,128,256,512]};f.prototype.onExecute=function(){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var a=GL.Mesh.getScreenQuad(),b=f._shader,c=this.getInputData(0);c||(c=this.properties.A);var d=this.getInputData(1);d||(d=this.properties.B);for(var e=2;e<this.inputs.length;e++){var k=this.inputs[e],g=this.getInputData(e);void 0!==g&&(this.properties[k.name]=g)}var h=this._uniforms;this._uniforms.u_angle=this.properties.angle*DEG2RAD;this._uniforms.u_scale=this.properties.scale;vec3.copy(h.u_colorA,
|
||||
c);vec3.copy(h.u_colorB,d);c=parseInt(this.properties.texture_size);this._tex&&this._tex.width==c||(this._tex=new GL.Texture(c,c,{format:gl.RGB,filter:gl.LINEAR}));this._tex.drawTo(function(){b.uniforms(h).draw(a)});this.setOutputData(0,this._tex)};f.prototype.onGetInputs=function(){return[["angle","number"],["scale","number"]]};f.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";
|
||||
g.registerNodeType("texture/gradient",f);var m=function(){this.addInput("A","Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={precision:e.DEFAULT};m._shader||(m._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,m.pixel_shader))};m.title="Mix";m.desc="Generates a texture mixing two textures";m.widgets_info={precision:{widget:"combo",values:e.MODE_VALUES}};m.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===
|
||||
e.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1),c=this.getInputData(2);if(a&&b&&c){this._tex=e.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),f=m._shader;this._tex.drawTo(function(){a.bind(0);b.bind(1);c.bind(2);f.uniforms({u_textureA:0,u_textureB:1,u_textureMix:2}).draw(d)});this.setOutputData(0,this._tex)}}};m.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\tuniform sampler2D u_textureMix;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), texture2D(u_textureMix, v_coord) );\n\t\t\t}\n\t\t\t";
|
||||
g.registerNodeType("texture/mix",m);var k=function(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:e.DEFAULT};k._shader||(k._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k.pixel_shader))};k.title="Edges";k.desc="Detects edges";k.widgets_info={precision:{widget:"combo",values:e.MODE_VALUES}};k.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===e.PASS_THROUGH)this.setOutputData(0,
|
||||
g.registerNodeType("texture/gradient",f);var n=function(){this.addInput("A","Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={precision:e.DEFAULT};n._shader||(n._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n.pixel_shader))};n.title="Mix";n.desc="Generates a texture mixing two textures";n.widgets_info={precision:{widget:"combo",values:e.MODE_VALUES}};n.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===
|
||||
e.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1),c=this.getInputData(2);if(a&&b&&c){this._tex=e.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),f=n._shader;this._tex.drawTo(function(){a.bind(0);b.bind(1);c.bind(2);f.uniforms({u_textureA:0,u_textureB:1,u_textureMix:2}).draw(d)});this.setOutputData(0,this._tex)}}};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_textureA;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform sampler2D u_textureMix;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), texture2D(u_textureMix, v_coord) );\n\t\t\t}\n\t\t\t";
|
||||
g.registerNodeType("texture/mix",n);var k=function(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:e.DEFAULT};k._shader||(k._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k.pixel_shader))};k.title="Edges";k.desc="Detects edges";k.widgets_info={precision:{widget:"combo",values:e.MODE_VALUES}};k.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===e.PASS_THROUGH)this.setOutputData(0,
|
||||
a);else if(a){this._tex=e.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),c=k._shader,d=this.properties.invert,f=this.properties.factor,g=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);c.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:f,u_threshold:g,u_invert:d?1:0}).draw(b)});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_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";
|
||||
g.registerNodeType("texture/edges",k);var t=function(){this.addInput("Texture","Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}};t.title="Depth Range";t.desc="Generates a texture with a depth range";t.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);
|
||||
if(a){var b=gl.UNSIGNED_BYTE;this.properties.high_precision&&(b=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&&this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGBA,filter:gl.LINEAR}));var c=this._uniforms,b=this.properties.distance;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.distance=b);var d=this.properties.range;this.isInputConnected(2)&&
|
||||
@@ -340,10 +341,10 @@ w.final_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuni
|
||||
g.registerNodeType("texture/glow",w);var y=function(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}};y.title="Kuwahara Filter";y.desc="Filters a texture giving an artistic oil canvas painting";y.max_radius=10;y._shaders=[];y.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,
|
||||
a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));b=this.properties.radius;b=Math.min(Math.floor(b),y.max_radius);if(0==b)this.setOutputData(0,a);else{var c=this.properties.intensity,d=g.camera_aspect;d||void 0===window.gl||(d=gl.canvas.height/gl.canvas.width);d||(d=1);d=this.properties.preserve_aspect?d:1;y._shaders[b]||(y._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,y.pixel_shader,{RADIUS:b.toFixed(0)}));var e=y._shaders[b],f=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){e.uniforms({u_texture:0,
|
||||
u_intensity:c,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(f)});this.setOutputData(0,this._temp_texture)}}};y.pixel_shader="\n\tprecision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_intensity;\n\tuniform vec2 u_resolution;\n\tuniform vec2 u_iResolution;\n\t#ifndef RADIUS\n\t\t#define RADIUS 7\n\t#endif\n\tvoid main() {\n\t\n\t\tconst int radius = RADIUS;\n\t\tvec2 fragCoord = v_coord;\n\t\tvec2 src_size = u_iResolution;\n\t\tvec2 uv = v_coord;\n\t\tfloat n = float((radius + 1) * (radius + 1));\n\t\tint i;\n\t\tint j;\n\t\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\t\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\t\tvec3 c;\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm0 += c;\n\t\t\t\ts0 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm1 += c;\n\t\t\t\ts1 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm2 += c;\n\t\t\t\ts2 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm3 += c;\n\t\t\t\ts3 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfloat min_sigma2 = 1e+2;\n\t\tm0 /= n;\n\t\ts0 = abs(s0 / n - m0 * m0);\n\t\t\n\t\tfloat sigma2 = s0.r + s0.g + s0.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m0, 1.0);\n\t\t}\n\t\t\n\t\tm1 /= n;\n\t\ts1 = abs(s1 / n - m1 * m1);\n\t\t\n\t\tsigma2 = s1.r + s1.g + s1.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m1, 1.0);\n\t\t}\n\t\t\n\t\tm2 /= n;\n\t\ts2 = abs(s2 / n - m2 * m2);\n\t\t\n\t\tsigma2 = s2.r + s2.g + s2.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m2, 1.0);\n\t\t}\n\t\t\n\t\tm3 /= n;\n\t\ts3 = abs(s3 / n - m3 * m3);\n\t\t\n\t\tsigma2 = s3.r + s3.g + s3.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m3, 1.0);\n\t\t}\n\t}\n\t";
|
||||
g.registerNodeType("texture/kuwahara",y);n=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:""}};n.title="Webcam";n.desc="Webcam texture";n.prototype.openStream=function(){function a(c){console.log("Webcam rejected",c);b._webcam_stream=!1;b.box_color="red"}navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL;if(navigator.getUserMedia){this._waiting_confirmation=
|
||||
!0;var b=this;navigator.getUserMedia({video:!0},this.streamReady.bind(this),a)}};n.prototype.streamReady=function(a){this._webcam_stream=a;var b=this._video;b||(b=document.createElement("video"),b.autoplay=!0,b.src=window.URL.createObjectURL(a),this._video=b,b.onloadedmetadata=function(a){console.log(a)})};n.prototype.onRemoved=function(){if(this._webcam_stream){var a=this._webcam_stream.getVideoTracks();a.length&&a[0].stop();this._video=this._webcam_stream=null}};n.prototype.onDrawBackground=function(a){this.flags.collapsed||
|
||||
20>=this.size[1]||!this._video||(a.save(),a.webgl?this._temp_texture&&a.drawImage(this._temp_texture,0,0,this.size[0],this.size[1]):(a.translate(0,this.size[1]),a.scale(1,-1),a.drawImage(this._video,0,0,this.size[0],this.size[1])),a.restore())};n.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,c=this._temp_texture;c&&c.width==a&&c.height==b||(this._temp_texture=
|
||||
new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._temp_texture.uploadImage(this._video);this.properties.texture_name&&(e.getTexturesContainer()[this.properties.texture_name]=this._temp_texture);this.setOutputData(0,this._temp_texture)}};g.registerNodeType("texture/webcam",n);var A=function(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:e.LOW};this._uniforms={u_texture:0,u_factor:1}};A.title="Lens FX";
|
||||
g.registerNodeType("texture/kuwahara",y);m=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:""}};m.title="Webcam";m.desc="Webcam texture";m.prototype.openStream=function(){function a(c){console.log("Webcam rejected",c);b._webcam_stream=!1;b.box_color="red"}navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL;if(navigator.getUserMedia){this._waiting_confirmation=
|
||||
!0;var b=this;navigator.getUserMedia({video:!0},this.streamReady.bind(this),a)}};m.prototype.streamReady=function(a){this._webcam_stream=a;var b=this._video;b||(b=document.createElement("video"),b.autoplay=!0,b.src=window.URL.createObjectURL(a),this._video=b,b.onloadedmetadata=function(a){console.log(a)})};m.prototype.onRemoved=function(){if(this._webcam_stream){var a=this._webcam_stream.getVideoTracks();a.length&&a[0].stop();this._video=this._webcam_stream=null}};m.prototype.onDrawBackground=function(a){this.flags.collapsed||
|
||||
20>=this.size[1]||!this._video||(a.save(),a.webgl?this._temp_texture&&a.drawImage(this._temp_texture,0,0,this.size[0],this.size[1]):(a.translate(0,this.size[1]),a.scale(1,-1),a.drawImage(this._video,0,0,this.size[0],this.size[1])),a.restore())};m.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,c=this._temp_texture;c&&c.width==a&&c.height==b||(this._temp_texture=
|
||||
new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._temp_texture.uploadImage(this._video);this.properties.texture_name&&(e.getTexturesContainer()[this.properties.texture_name]=this._temp_texture);this.setOutputData(0,this._temp_texture)}};g.registerNodeType("texture/webcam",m);var A=function(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:e.LOW};this._uniforms={u_texture:0,u_factor:1}};A.title="Lens FX";
|
||||
A.desc="distortion and chromatic aberration";A.widgets_info={precision:{widget:"combo",values:e.MODE_VALUES}};A.prototype.onGetInputs=function(){return[["enabled","boolean"]]};A.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0))if(this.properties.precision===e.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,a);else{var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._temp_texture=new GL.Texture(a.width,
|
||||
a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var c=A._shader;c||(c=A._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,A.pixel_shader));var d=this.getInputData(1);null==d&&(d=this.properties.factor);var f=this._uniforms;f.u_factor=d;gl.disable(gl.DEPTH_TEST);b.drawTo(function(){a.bind(0);c.uniforms(f).draw(GL.Mesh.getScreenQuad())});this.setOutputData(0,b)}};A.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_factor;\n\t\t\tvec2 barrelDistortion(vec2 coord, float amt) {\n\t\t\t\tvec2 cc = coord - 0.5;\n\t\t\t\tfloat dist = dot(cc, cc);\n\t\t\t\treturn coord + cc * dist * amt;\n\t\t\t}\n\t\t\t\n\t\t\tfloat sat( float t )\n\t\t\t{\n\t\t\t\treturn clamp( t, 0.0, 1.0 );\n\t\t\t}\n\t\t\t\n\t\t\tfloat linterp( float t ) {\n\t\t\t\treturn sat( 1.0 - abs( 2.0*t - 1.0 ) );\n\t\t\t}\n\t\t\t\n\t\t\tfloat remap( float t, float a, float b ) {\n\t\t\t\treturn sat( (t - a) / (b - a) );\n\t\t\t}\n\t\t\t\n\t\t\tvec4 spectrum_offset( float t ) {\n\t\t\t\tvec4 ret;\n\t\t\t\tfloat lo = step(t,0.5);\n\t\t\t\tfloat hi = 1.0-lo;\n\t\t\t\tfloat w = linterp( remap( t, 1.0/6.0, 5.0/6.0 ) );\n\t\t\t\tret = vec4(lo,1.0,hi, 1.) * vec4(1.0-w, w, 1.0-w, 1.);\n\t\t\t\n\t\t\t\treturn pow( ret, vec4(1.0/2.2) );\n\t\t\t}\n\t\t\t\n\t\t\tconst float max_distort = 2.2;\n\t\t\tconst int num_iter = 12;\n\t\t\tconst float reci_num_iter_f = 1.0 / float(num_iter);\n\t\t\t\n\t\t\tvoid main()\n\t\t\t{\t\n\t\t\t\tvec2 uv=v_coord;\n\t\t\t\tvec4 sumcol = vec4(0.0);\n\t\t\t\tvec4 sumw = vec4(0.0);\t\n\t\t\t\tfor ( int i=0; i<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}";
|
||||
g.registerNodeType("texture/lensfx",A);var C=function(){this.addInput("in","Texture");this.addInput("exp","number");this.addOutput("out","Texture");this.properties={exposition:1,precision:e.LOW};this._uniforms={u_texture:0,u_exposition:exp}};C.title="Exposition";C.desc="Controls texture exposition";C.widgets_info={exposition:{widget:"slider",min:0,max:3},precision:{widget:"combo",values:e.MODE_VALUES}};C.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=
|
||||
@@ -356,34 +357,34 @@ g.registerNodeType("texture/tonemapping",B);var v=function(){this.addOutput("out
|
||||
precision:0,step:1},octaves:{type:"Number",precision:0,step:1,min:1,max:50}};v.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 c=e.getTextureType(this.properties.precision),d=this._temp_texture;d&&d.width==a&&d.height==b&&d.type==c||(d=this._temp_texture=new GL.Texture(a,b,{type:c,format:gl.RGB,filter:gl.LINEAR}));c=a+b+c+this.properties.persistence+this.properties.octaves+
|
||||
this.properties.scale+this.properties.seed+this.properties.offset[0]+this.properties.offset[1]+this.properties.amplitude;if(c!=this._key){this._key=c;var f=this._uniforms;f.u_persistence=this.properties.persistence;f.u_octaves=this.properties.octaves;f.u_offset[0]=this.properties.offset[0];f.u_offset[1]=this.properties.offset[1];f.u_scale=this.properties.scale;f.u_amplitude=this.properties.amplitude;f.u_viewport[0]=a;f.u_viewport[1]=b;f.u_seed=128*this.properties.seed;var k=v._shader;k||(k=v._shader=
|
||||
new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,v.pixel_shader));gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);d.drawTo(function(){k.uniforms(f).draw(GL.Mesh.getScreenQuad())})}this.setOutputData(0,d)}};v.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}";
|
||||
g.registerNodeType("texture/perlin",v);n=function(){this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,precision:e.DEFAULT};this._temp_texture=this._func=null};n.title="Canvas2D";n.desc="Executes Canvas2D code inside a texture or the viewport";n.widgets_info={precision:{widget:"combo",values:e.MODE_VALUES},code:{type:"code"},width:{type:"Number",precision:0,step:1},height:{type:"Number",precision:0,step:1}};n.prototype.onPropertyChanged=function(a,b){if("code"==a&&g.allow_scripts){this._func=
|
||||
null;try{this._func=new Function("canvas","ctx","time","script",b),this.boxcolor="#00FF00"}catch(c){this.boxcolor="#FF0000",console.error("Error parsing script"),console.error(c)}}};n.prototype.onExecute=function(){var a=this._func;if(a&&this.isOutputConnected(0))if(u.enableWebGLCanvas){var b=this.properties.width||gl.canvas.width,c=this.properties.height||gl.canvas.height,d=this._temp_texture;d&&d.width==b&&d.height==c||(d=this._temp_texture=new GL.Texture(b,c,{format:gl.RGBA,filter:gl.LINEAR}));
|
||||
var e=this,f=this.graph.getTime();d.drawTo(function(){gl.start2D();try{a.draw?a.draw.call(e,gl.canvas,gl,f,a):a.call(e,gl.canvas,gl,f,a),e.boxcolor="#00FF00"}catch(b){e.boxcolor="#FF0000",console.error("Error executing script"),console.error(b)}gl.finish2D()});this.setOutputData(0,d)}else console.warn("cannot use LGraphTextureCanvas2D if Canvas2DtoWebGL is not included")};g.registerNodeType("texture/canvas2D",n);var z=function(){this.addInput("in","Texture");this.addOutput("out","Texture");this.properties=
|
||||
g.registerNodeType("texture/perlin",v);m=function(){this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,precision:e.DEFAULT};this._temp_texture=this._func=null};m.title="Canvas2D";m.desc="Executes Canvas2D code inside a texture or the viewport";m.widgets_info={precision:{widget:"combo",values:e.MODE_VALUES},code:{type:"code"},width:{type:"Number",precision:0,step:1},height:{type:"Number",precision:0,step:1}};m.prototype.onPropertyChanged=function(a,b){if("code"==a&&g.allow_scripts){this._func=
|
||||
null;try{this._func=new Function("canvas","ctx","time","script",b),this.boxcolor="#00FF00"}catch(c){this.boxcolor="#FF0000",console.error("Error parsing script"),console.error(c)}}};m.prototype.onExecute=function(){var a=this._func;if(a&&this.isOutputConnected(0))if(u.enableWebGLCanvas){var b=this.properties.width||gl.canvas.width,c=this.properties.height||gl.canvas.height,d=this._temp_texture;d&&d.width==b&&d.height==c||(d=this._temp_texture=new GL.Texture(b,c,{format:gl.RGBA,filter:gl.LINEAR}));
|
||||
var e=this,f=this.graph.getTime();d.drawTo(function(){gl.start2D();try{a.draw?a.draw.call(e,gl.canvas,gl,f,a):a.call(e,gl.canvas,gl,f,a),e.boxcolor="#00FF00"}catch(b){e.boxcolor="#FF0000",console.error("Error executing script"),console.error(b)}gl.finish2D()});this.setOutputData(0,d)}else console.warn("cannot use LGraphTextureCanvas2D if Canvas2DtoWebGL is not included")};g.registerNodeType("texture/canvas2D",m);var z=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:e.DEFAULT}};z.title="Matte";z.desc="Extracts background";z.widgets_info={key_color:{widget:"color"},precision:{widget:"combo",values:e.MODE_VALUES}};z.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===e.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=e.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,c=Mesh.getScreenQuad(),d=z._shader;d||(d=z._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,z.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);d.uniforms(b).draw(c)});this.setOutputData(0,this._tex)}}};z.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}";
|
||||
g.registerNodeType("texture/matte",z);n=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[e.image_preview_size,e.image_preview_size]};n.title="Cubemap";n.prototype.onDropFile=function(a,b,c){a?(this._drop_texture="string"==typeof a?GL.Texture.fromURL(a):GL.Texture.fromDDSInMemory(a),this.properties.name=b):(this._drop_texture=null,this.properties.name="")};n.prototype.onExecute=function(){if(this._drop_texture)this.setOutputData(0,this._drop_texture);else if(this.properties.name){var a=
|
||||
e.getTexture(this.properties.name);a&&(this._last_tex=a,this.setOutputData(0,a))}};n.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||a.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};g.registerNodeType("texture/cubemap",n)}})(this);
|
||||
g.registerNodeType("texture/matte",z);m=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[e.image_preview_size,e.image_preview_size]};m.title="Cubemap";m.prototype.onDropFile=function(a,b,c){a?(this._drop_texture="string"==typeof a?GL.Texture.fromURL(a):GL.Texture.fromDDSInMemory(a),this.properties.name=b):(this._drop_texture=null,this.properties.name="")};m.prototype.onExecute=function(){if(this._drop_texture)this.setOutputData(0,this._drop_texture);else if(this.properties.name){var a=
|
||||
e.getTexture(this.properties.name);a&&(this._last_tex=a,this.setOutputData(0,a))}};m.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||a.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};g.registerNodeType("texture/cubemap",m)}})(this);
|
||||
(function(u){var g=u.LiteGraph;if("undefined"!=typeof GL){var e=function(){this.addInput("Texture","Texture");this.addInput("Aberration","number");this.addInput("Distortion","number");this.addInput("Blur","number");this.addOutput("Texture","Texture");this.properties={aberration:1,distortion:1,blur:1,precision:LGraphTexture.DEFAULT};e._shader||(e._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,e.pixel_shader),e._texture=new GL.Texture(3,1,{format:gl.RGB,wrap:gl.CLAMP_TO_EDGE,magFilter:gl.LINEAR,
|
||||
minFilter:gl.LINEAR,pixel_data:[255,0,0,0,255,0,0,0,255]}))};e.title="Lens";e.desc="Camera Lens distortion";e.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};e.prototype.onExecute=function(){var g=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,g);else if(g){this._tex=LGraphTexture.getTargetTexture(g,this._tex,this.properties.precision);var h=this.properties.aberration;this.isInputConnected(1)&&(h=this.getInputData(1),
|
||||
this.properties.aberration=h);var l=this.properties.distortion;this.isInputConnected(2)&&(l=this.getInputData(2),this.properties.distortion=l);var n=this.properties.blur;this.isInputConnected(3)&&(n=this.getInputData(3),this.properties.blur=n);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var c=Mesh.getScreenQuad(),a=e._shader;this._tex.drawTo(function(){g.bind(0);a.uniforms({u_texture:0,u_aberration:h,u_distortion:l,u_blur:n}).draw(c)});this.setOutputData(0,this._tex)}};e.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t";
|
||||
this.properties.aberration=h);var l=this.properties.distortion;this.isInputConnected(2)&&(l=this.getInputData(2),this.properties.distortion=l);var m=this.properties.blur;this.isInputConnected(3)&&(m=this.getInputData(3),this.properties.blur=m);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var c=Mesh.getScreenQuad(),a=e._shader;this._tex.drawTo(function(){g.bind(0);a.uniforms({u_texture:0,u_aberration:h,u_distortion:l,u_blur:m}).draw(c)});this.setOutputData(0,this._tex)}};e.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t";
|
||||
g.registerNodeType("fx/lens",e);u.LGraphFXLens=e;var h=function(){this.addInput("Texture","Texture");this.addInput("Blurred","Texture");this.addInput("Mask","Texture");this.addInput("Threshold","number");this.addOutput("Texture","Texture");this.properties={shape:"",size:10,alpha:1,threshold:1,high_precision:!1}};h.title="Bokeh";h.desc="applies an Bokeh effect";h.widgets_info={shape:{widget:"texture"}};h.prototype.onExecute=function(){var e=this.getInputData(0),g=this.getInputData(1),l=this.getInputData(2);
|
||||
if(e&&l&&this.properties.shape){g||(g=e);var n=LGraphTexture.getTexture(this.properties.shape);if(n){var c=this.properties.threshold;this.isInputConnected(3)&&(c=this.getInputData(3),this.properties.threshold=c);var a=gl.UNSIGNED_BYTE;this.properties.high_precision&&(a=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==a&&this._temp_texture.width==e.width&&this._temp_texture.height==e.height||(this._temp_texture=new GL.Texture(e.width,e.height,{type:a,format:gl.RGBA,
|
||||
filter:gl.LINEAR}));var b=h._first_shader;b||(b=h._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h._first_pixel_shader));var d=h._second_shader;d||(d=h._second_shader=new GL.Shader(h._second_vertex_shader,h._second_pixel_shader));var p=this._points_mesh;p&&p._width==e.width&&p._height==e.height&&2==p._spacing||(p=this.createPointsMesh(e.width,e.height,2));var f=Mesh.getScreenQuad(),m=this.properties.size,k=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){e.bind(0);
|
||||
g.bind(1);l.bind(2);b.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[e.width,e.height]}).draw(f)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);e.bind(0);n.bind(3);d.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:k,u_threshold:c,u_pointSize:m,u_itexsize:[1/e.width,1/e.height]}).draw(p,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,e)};h.prototype.createPointsMesh=function(e,g,h){for(var n=Math.round(e/h),c=Math.round(g/
|
||||
h),a=new Float32Array(n*c*2),b=-1,d=2/e*h,p=2/g*h,f=0;f<c;++f){for(var m=-1,k=0;k<n;++k){var t=f*n*2+2*k;a[t]=m;a[t+1]=b;m+=d}b+=p}this._points_mesh=GL.Mesh.load({vertices2D:a});this._points_mesh._width=e;this._points_mesh._height=g;this._points_mesh._spacing=h;return this._points_mesh};h._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";
|
||||
if(e&&l&&this.properties.shape){g||(g=e);var m=LGraphTexture.getTexture(this.properties.shape);if(m){var c=this.properties.threshold;this.isInputConnected(3)&&(c=this.getInputData(3),this.properties.threshold=c);var a=gl.UNSIGNED_BYTE;this.properties.high_precision&&(a=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==a&&this._temp_texture.width==e.width&&this._temp_texture.height==e.height||(this._temp_texture=new GL.Texture(e.width,e.height,{type:a,format:gl.RGBA,
|
||||
filter:gl.LINEAR}));var b=h._first_shader;b||(b=h._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h._first_pixel_shader));var d=h._second_shader;d||(d=h._second_shader=new GL.Shader(h._second_vertex_shader,h._second_pixel_shader));var p=this._points_mesh;p&&p._width==e.width&&p._height==e.height&&2==p._spacing||(p=this.createPointsMesh(e.width,e.height,2));var f=Mesh.getScreenQuad(),n=this.properties.size,k=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){e.bind(0);
|
||||
g.bind(1);l.bind(2);b.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[e.width,e.height]}).draw(f)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);e.bind(0);m.bind(3);d.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:k,u_threshold:c,u_pointSize:n,u_itexsize:[1/e.width,1/e.height]}).draw(p,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,e)};h.prototype.createPointsMesh=function(e,g,h){for(var m=Math.round(e/h),c=Math.round(g/
|
||||
h),a=new Float32Array(m*c*2),b=-1,d=2/e*h,p=2/g*h,f=0;f<c;++f){for(var n=-1,k=0;k<m;++k){var t=f*m*2+2*k;a[t]=n;a[t+1]=b;n+=d}b+=p}this._points_mesh=GL.Mesh.load({vertices2D:a});this._points_mesh._width=e;this._points_mesh._height=g;this._points_mesh._spacing=h;return this._points_mesh};h._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";
|
||||
h._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";
|
||||
h._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";g.registerNodeType("fx/bokeh",h);u.LGraphFXBokeh=h;var n=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}};n.title="FX";n.desc="applies an FX from a list";n.widgets_info={fx:{widget:"combo",values:["halftone","pixelate","lowpalette","noise","gamma"]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};n.shaders={};n.prototype.onExecute=function(){if(this.isOutputConnected(0)){var e=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){this._tex=
|
||||
LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);var g=this.properties.value1;this.isInputConnected(1)&&(g=this.getInputData(1),this.properties.value1=g);var h=this.properties.value2;this.isInputConnected(2)&&(h=this.getInputData(2),this.properties.value2=h);var p=this.properties.fx,c=n.shaders[p];if(!c){var a=n["pixel_shader_"+p];if(!a)return;c=n.shaders[p]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a)}gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad();
|
||||
camera_planes=u.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var d=null;"noise"==p&&(d=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){e.bind(0);"noise"==p&&d.bind(1);c.uniforms({u_texture:0,u_noise:1,u_size:[e.width,e.height],u_rand:[Math.random(),Math.random()],u_value1:g,u_value2:h,u_camera_planes:camera_planes}).draw(b)});this.setOutputData(0,this._tex)}}};n.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";
|
||||
n.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";n.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";
|
||||
n.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";
|
||||
n.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";g.registerNodeType("fx/generic",n);u.LGraphFXGeneric=n;var p=function(){this.addInput("Tex.","Texture");this.addInput("intensity","number");this.addOutput("Texture",
|
||||
h._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";g.registerNodeType("fx/bokeh",h);u.LGraphFXBokeh=h;var m=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}};m.title="FX";m.desc="applies an FX from a list";m.widgets_info={fx:{widget:"combo",values:["halftone","pixelate","lowpalette","noise","gamma"]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};m.shaders={};m.prototype.onExecute=function(){if(this.isOutputConnected(0)){var e=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){this._tex=
|
||||
LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);var g=this.properties.value1;this.isInputConnected(1)&&(g=this.getInputData(1),this.properties.value1=g);var h=this.properties.value2;this.isInputConnected(2)&&(h=this.getInputData(2),this.properties.value2=h);var p=this.properties.fx,c=m.shaders[p];if(!c){var a=m["pixel_shader_"+p];if(!a)return;c=m.shaders[p]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a)}gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad();
|
||||
camera_planes=u.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var d=null;"noise"==p&&(d=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){e.bind(0);"noise"==p&&d.bind(1);c.uniforms({u_texture:0,u_noise:1,u_size:[e.width,e.height],u_rand:[Math.random(),Math.random()],u_value1:g,u_value2:h,u_camera_planes:camera_planes}).draw(b)});this.setOutputData(0,this._tex)}}};m.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";
|
||||
m.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";m.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";
|
||||
m.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";
|
||||
m.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";g.registerNodeType("fx/generic",m);u.LGraphFXGeneric=m;var p=function(){this.addInput("Tex.","Texture");this.addInput("intensity","number");this.addOutput("Texture",
|
||||
"Texture");this.properties={intensity:1,invert:!1,precision:LGraphTexture.DEFAULT};p._shader||(p._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,p.pixel_shader))};p.title="Vigneting";p.desc="Vigneting";p.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};p.prototype.onExecute=function(){var e=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){this._tex=LGraphTexture.getTargetTexture(e,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 h=Mesh.getScreenQuad(),n=p._shader,c=this.properties.invert;this._tex.drawTo(function(){e.bind(0);n.uniforms({u_texture:0,u_intensity:g,u_isize:[1/e.width,1/e.height],u_invert:c?1:0}).draw(h)});this.setOutputData(0,this._tex)}};p.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";
|
||||
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 h=Mesh.getScreenQuad(),m=p._shader,c=this.properties.invert;this._tex.drawTo(function(){e.bind(0);m.uniforms({u_texture:0,u_intensity:g,u_isize:[1/e.width,1/e.height],u_invert:c?1:0}).draw(h)});this.setOutputData(0,this._tex)}};p.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";
|
||||
g.registerNodeType("fx/vigneting",p);u.LGraphFXVigneting=p}})(this);
|
||||
(function(u){function g(c){this.cmd=this.channel=0;c?this.setup(c):this.data=[0,0,0]}function e(c,a){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",a?a("Not supported"):console.error("MIDI NOT SUPPORTED, enable by chrome://flags"))}function h(){this.addOutput("on_midi",s.EVENT);this.addOutput("out","midi");this.properties={port:0};this._current_midi_event=
|
||||
this._last_midi_event=null;var c=this;new e(function(a){c._midi=a;if(c._waiting)c.onStart();c._waiting=!1})}function n(){this.addInput("send",s.EVENT);this.properties={port:0};var c=this;new e(function(a){c._midi=a})}function p(){this.addInput("on_midi",s.EVENT);this._str="";this.size=[200,40]}function q(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};this.addInput("in",s.EVENT);this.addOutput("on_midi",s.EVENT)}function r(){this.properties={channel:0,cmd:"CC",value1:1,value2:1};this.addInput("send",
|
||||
this._last_midi_event=null;var c=this;new e(function(a){c._midi=a;if(c._waiting)c.onStart();c._waiting=!1})}function m(){this.addInput("send",s.EVENT);this.properties={port:0};var c=this;new e(function(a){c._midi=a})}function p(){this.addInput("on_midi",s.EVENT);this._str="";this.size=[200,40]}function q(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};this.addInput("in",s.EVENT);this.addOutput("on_midi",s.EVENT)}function r(){this.properties={channel:0,cmd:"CC",value1:1,value2:1};this.addInput("send",
|
||||
s.EVENT);this.addInput("assign",s.EVENT);this.addOutput("on_midi",s.EVENT)}function l(){this.properties={cc:1,value:0};this.addOutput("value","number")}var s=u.LiteGraph;g.prototype.setup=function(c){this.data=c;this.status=c=c[0];var a=c&240;this.cmd=240<=c?c:a;this.cmd==g.NOTEON&&0==this.velocity&&(this.cmd=g.NOTEOFF);this.cmd_str=g.commands[this.cmd]||"";if(a>=g.NOTEON||a<=g.NOTEOFF)this.channel=c&15};Object.defineProperty(g.prototype,"velocity",{get:function(){return this.cmd==g.NOTEON?this.data[2]:
|
||||
-1},set:function(c){this.data[2]=c},enumerable:!0});g.notes="A A# B C C# D D# E F F# G G#".split(" ");g.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};g.computePitch=function(c){return 440*Math.pow(2,(c-69)/12)};g.prototype.getCC=function(){return this.data[1]};g.prototype.getCCValue=function(){return this.data[2]};g.prototype.getPitchBend=function(){return this.data[1]+(this.data[2]<<7)-8192};g.computePitchBend=function(c,a){return c+(a<<7)-8192};g.prototype.setCommandFromString=
|
||||
function(c){this.cmd=g.computeCommandFromString(c)};g.computeCommandFromString=function(c){if(!c)return 0;if(c&&c.constructor===Number)return c;c=c.toUpperCase();switch(c){case "NOTE ON":case "NOTEON":return g.NOTEON;case "NOTE OFF":case "NOTEOFF":return g.NOTEON;case "KEY PRESSURE":case "KEYPRESSURE":return g.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return g.CONTROLLERCHANGE;case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return g.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return g.CHANNELPRESSURE;
|
||||
@@ -394,48 +395,48 @@ case g.PROGRAMCHANGE:c+="PC "+this.data[1];break;case g.PITCHBEND:c+="PITCHBEND
|
||||
function(c){console.error("Failed to get MIDI access - "+c)};e.prototype.openInputPort=function(c,a){var b=this.input_ports.get("input-"+c);if(!b)return!1;e.input=this;var d=this;b.onmidimessage=function(b){var c=new g(b.data);d.updateState(c);a&&a(b.data,c);if(e.on_message)e.on_message(b.data,c)};console.log("port open: ",b);return!0};e.parseMsg=function(c){};e.prototype.updateState=function(c){switch(c.cmd){case g.NOTEON:this.state.note[c.value1|0]=c.value2;break;case g.NOTEOFF:this.state.note[c.value1|
|
||||
0]=0;break;case g.CONTROLLERCHANGE:this.state.cc[c.getCC()]=c.getCCValue()}};e.prototype.sendMIDI=function(c,a){if(a){var b=this.output_ports.get("output-"+c);b&&(e.output=this,a.constructor===g?b.send(a.data):b.send(a))}};h.MIDIInterface=e;h.title="MIDI Input";h.desc="Reads MIDI from a input port";h.prototype.getPropertyInfo=function(c){if(this._midi&&"port"==c){c={};for(var a=0;a<this._midi.input_ports.size;++a){var b=this._midi.input_ports.get("input-"+a);c[a]=a+".- "+b.name+" version:"+b.version}return{type:"enum",
|
||||
values:c}}};h.prototype.onStart=function(){this._midi?this._midi.openInputPort(this.properties.port,this.onMIDIEvent.bind(this)):this._waiting=!0};h.prototype.onMIDIEvent=function(c,a){this._last_midi_event=a;this.trigger("on_midi",a);a.cmd==g.NOTEON?this.trigger("on_noteon",a):a.cmd==g.NOTEOFF?this.trigger("on_noteoff",a):a.cmd==g.CONTROLLERCHANGE?this.trigger("on_cc",a):a.cmd==g.PROGRAMCHANGE?this.trigger("on_pc",a):a.cmd==g.PITCHBEND&&this.trigger("on_pitchbend",a)};h.prototype.onExecute=function(){if(this.outputs)for(var c=
|
||||
this._last_midi_event,a=0;a<this.outputs.length;++a){var b=null;switch(this.outputs[a].name){case "midi":b=this._midi;break;case "last_midi":b=c;break;default:continue}this.setOutputData(a,b)}};h.prototype.onGetOutputs=function(){return[["last_midi","midi"],["on_midi",s.EVENT],["on_noteon",s.EVENT],["on_noteoff",s.EVENT],["on_cc",s.EVENT],["on_pc",s.EVENT],["on_pitchbend",s.EVENT]]};s.registerNodeType("midi/input",h);n.MIDIInterface=e;n.title="MIDI Output";n.desc="Sends MIDI to output channel";n.prototype.getPropertyInfo=
|
||||
function(c){if(this._midi&&"port"==c){c={};for(var a=0;a<this._midi.output_ports.size;++a){var b=this._midi.output_ports.get(a);c[a]=a+".- "+b.name+" version:"+b.version}return{type:"enum",values:c}}};n.prototype.onAction=function(c,a){console.log(a);this._midi&&("send"==c&&this._midi.sendMIDI(this.port,a),this.trigger("midi",a))};n.prototype.onGetInputs=function(){return[["send",s.ACTION]]};n.prototype.onGetOutputs=function(){return[["on_midi",s.EVENT]]};s.registerNodeType("midi/output",n);p.title=
|
||||
this._last_midi_event,a=0;a<this.outputs.length;++a){var b=null;switch(this.outputs[a].name){case "midi":b=this._midi;break;case "last_midi":b=c;break;default:continue}this.setOutputData(a,b)}};h.prototype.onGetOutputs=function(){return[["last_midi","midi"],["on_midi",s.EVENT],["on_noteon",s.EVENT],["on_noteoff",s.EVENT],["on_cc",s.EVENT],["on_pc",s.EVENT],["on_pitchbend",s.EVENT]]};s.registerNodeType("midi/input",h);m.MIDIInterface=e;m.title="MIDI Output";m.desc="Sends MIDI to output channel";m.prototype.getPropertyInfo=
|
||||
function(c){if(this._midi&&"port"==c){c={};for(var a=0;a<this._midi.output_ports.size;++a){var b=this._midi.output_ports.get(a);c[a]=a+".- "+b.name+" version:"+b.version}return{type:"enum",values:c}}};m.prototype.onAction=function(c,a){console.log(a);this._midi&&("send"==c&&this._midi.sendMIDI(this.port,a),this.trigger("midi",a))};m.prototype.onGetInputs=function(){return[["send",s.ACTION]]};m.prototype.onGetOutputs=function(){return[["on_midi",s.EVENT]]};s.registerNodeType("midi/output",m);p.title=
|
||||
"MIDI Show";p.desc="Shows MIDI in the graph";p.prototype.onAction=function(c,a){a&&(this._str=a.constructor===g?a.toString():"???")};p.prototype.onDrawForeground=function(c){this._str&&(c.font="30px Arial",c.fillText(this._str,10,0.8*this.size[1]))};p.prototype.onGetInputs=function(){return[["in",s.ACTION]]};p.prototype.onGetOutputs=function(){return[["on_midi",s.EVENT]]};s.registerNodeType("midi/show",p);q.title="MIDI Filter";q.desc="Filters MIDI messages";q.prototype.onAction=function(c,a){!a||
|
||||
a.constructor!==g||-1!=this.properties.channel&&a.channel!=this.properties.channel||-1!=this.properties.cmd&&a.cmd!=this.properties.cmd||-1!=this.properties.min_value&&a.data[1]<this.properties.min_value||-1!=this.properties.max_value&&a.data[1]>this.properties.max_value||this.trigger("on_midi",a)};s.registerNodeType("midi/filter",q);r.title="MIDIEvent";r.desc="Create a MIDI Event";r.prototype.onAction=function(c,a){"assign"==c?(this.properties.channel=a.channel,this.properties.cmd=a.cmd,this.properties.value1=
|
||||
a.data[1],this.properties.value2=a.data[2]):(a=new g,a.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?a.setCommandFromString(this.properties.cmd):a.cmd=this.properties.cmd,a.data[0]=a.cmd|a.channel,a.data[1]=Number(this.properties.value1),a.data[2]=Number(this.properties.value2),this.trigger("on_midi",a))};r.prototype.onExecute=function(){var c=this.properties;if(this.outputs)for(var a=0;a<this.outputs.length;++a){var b=null;switch(this.outputs[a].name){case "midi":b=
|
||||
new g;b.setup([c.cmd,c.value1,c.value2]);b.channel=c.channel;break;case "command":b=c.cmd;break;case "cc":b=c.value1;break;case "cc_value":b=c.value2;break;case "note":b=c.cmd==g.NOTEON||c.cmd==g.NOTEOFF?c.value1:null;break;case "velocity":b=c.cmd==g.NOTEON?c.value2:null;break;case "pitch":b=c.cmd==g.NOTEON?g.computePitch(c.value1):null;break;case "pitchbend":b=c.cmd==g.PITCHBEND?g.computePitchBend(c.value1,c.value2):null;break;default:continue}null!==b&&this.setOutputData(a,b)}};r.prototype.onPropertyChanged=
|
||||
function(c,a){"cmd"==c&&(this.properties.cmd=g.computeCommandFromString(a))};r.prototype.onGetOutputs=function(){return[["midi","midi"],["on_midi",s.EVENT],["command","number"],["note","number"],["velocity","number"],["cc","number"],["cc_value","number"],["pitch","number"],["pitchbend","number"]]};s.registerNodeType("midi/event",r);l.title="MIDICC";l.desc="gets a Controller Change";l.prototype.onExecute=function(){e.input&&(this.properties.value=e.input.state.cc[this.properties.cc]);this.setOutputData(0,
|
||||
this.properties.value)};s.registerNodeType("midi/cc",l)})(this);
|
||||
(function(u){function g(){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=m.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function e(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,
|
||||
smoothingTimeConstant:0.5};this.audionode=m.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 h(){this.properties={gain:1};
|
||||
this.audionode=m.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function n(){this.properties={impulse_src:"",normalize:!0};this.audionode=m.getAudioContext().createConvolver();this.addInput("in","audio");this.addOutput("out","audio")}function p(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=m.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out",
|
||||
"audio")}function q(){this.properties={};this.audionode=m.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function r(){this.properties={gain1:0.5,gain2:0.5};this.audionode=m.getAudioContext().createGain();this.audionode1=m.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=m.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 l(){this.properties={delayTime:0.5};this.audionode=m.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function s(){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=m.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function c(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=m.getAudioContext().createOscillator();this.addOutput("out","audio")}function a(){this.properties={continuous:!0,
|
||||
mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function b(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function d(){if(!d.default_code){var a=d.default_function.toString(),b=a.indexOf("{")+1,c=a.lastIndexOf("}");d.default_code=a.substr(b,c-b)}this.properties={code:d.default_code};a=m.getAudioContext();a.createScriptProcessor?this.audionode=a.createScriptProcessor(4096,1,1):
|
||||
(console.warn("ScriptProcessorNode deprecated"),this.audionode=a.createGain());this.processCode();d._bypass_function||(d._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function x(){this.audionode=m.getAudioContext().destination;this.addInput("in","audio")}var f=u.LiteGraph,m={};u.LGAudio=m;m.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};m.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};m.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};m.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 e=a.graph.getNodeById(d.origin_id),f=null,f=e.getAudioNodeInOutputSlot?e.getAudioNodeInOutputSlot(d.origin_slot):e.audionode,d=null,d=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(c):a.audionode;b?m.connect(f,d):m.disconnect(f,d)}}if(a.outputs)for(c=0;c<a.outputs.length;++c)for(var e=a.outputs[c],g=0;g<e.links.length;++g)if(d=a.graph.links[e.links[g]]){var f=a.getAudioNodeInOutputSlot?a.getAudioNodeInOutputSlot(c):a.audionode,
|
||||
h=a.graph.getNodeById(d.target_id),d=h.getAudioNodeInInputSlot?h.getAudioNodeInInputSlot(d.target_slot):h.audionode;b?m.connect(f,d):m.disconnect(f,d)}};m.onConnectionsChange=function(a,b,c,d){if(a==f.OUTPUT&&(a=null,d&&(a=this.graph.getNodeById(d.target_id)),a)){var e=null,e=this.getAudioNodeInOutputSlot?this.getAudioNodeInOutputSlot(b):this.audionode;b=null;b=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(d.target_slot):a.audionode;c?m.connect(e,b):m.disconnect(e,b)}};m.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=m.onConnectionsChange};m.cached_audios={};m.loadSound=function(a,b,c){function d(a){console.log("Audio loading sample error:",a);c&&c(a)}if(m.cached_audios[a]&&-1==a.indexOf("blob:"))b&&b(m.cached_audios[a]);else{m.onProcessAudioURL&&
|
||||
(a=m.onProcessAudioURL(a));var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";var f=m.getAudioContext();e.onload=function(){console.log("AudioSource loaded");f.decodeAudioData(e.response,function(c){console.log("AudioSource decoded");m.cached_audios[a]=c;b&&b(c)},d)};e.send();return e}};g["@src"]={widget:"resource"};g.supported_extensions=["wav","ogg","mp3"];g.prototype.onAdded=function(a){if(a.status===LGraph.STATUS_RUNNING)this.onStart()};g.prototype.onStart=function(){this._audiobuffer&&
|
||||
(function(u){function g(){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=n.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function e(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,
|
||||
smoothingTimeConstant:0.5};this.audionode=n.getAudioContext().createAnalyser();this.audionode.graphnode=this;this.audionode.fftSize=this.properties.fftSize;this.audionode.minDecibels=this.properties.minDecibels;this.audionode.maxDecibels=this.properties.maxDecibels;this.audionode.smoothingTimeConstant=this.properties.smoothingTimeConstant;this.addInput("in","audio");this.addOutput("freqs","array");this.addOutput("samples","array");this._time_bin=this._freq_bin=null}function h(){this.properties={gain:1};
|
||||
this.audionode=n.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function m(){this.properties={impulse_src:"",normalize:!0};this.audionode=n.getAudioContext().createConvolver();this.addInput("in","audio");this.addOutput("out","audio")}function p(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=n.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out",
|
||||
"audio")}function q(){this.properties={};this.audionode=n.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function r(){this.properties={gain1:0.5,gain2:0.5};this.audionode=n.getAudioContext().createGain();this.audionode1=n.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=n.getAudioContext().createGain();this.audionode2.gain.value=this.properties.gain2;this.audionode1.connect(this.audionode);
|
||||
this.audionode2.connect(this.audionode);this.addInput("in1","audio");this.addInput("in1 gain","number");this.addInput("in2","audio");this.addInput("in2 gain","number");this.addOutput("out","audio")}function l(){this.properties={delayTime:0.5};this.audionode=n.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function s(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type",
|
||||
"lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});this.audionode=n.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function c(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=n.getAudioContext().createOscillator();this.addOutput("out","audio")}function a(){this.properties={continuous:!0,
|
||||
mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function b(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function d(){if(!d.default_code){var a=d.default_function.toString(),b=a.indexOf("{")+1,c=a.lastIndexOf("}");d.default_code=a.substr(b,c-b)}this.properties={code:d.default_code};a=n.getAudioContext();a.createScriptProcessor?this.audionode=a.createScriptProcessor(4096,1,1):
|
||||
(console.warn("ScriptProcessorNode deprecated"),this.audionode=a.createGain());this.processCode();d._bypass_function||(d._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function x(){this.audionode=n.getAudioContext().destination;this.addInput("in","audio")}var f=u.LiteGraph,n={};u.LGAudio=n;n.getAudioContext=function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"),
|
||||
null;this._audio_context=new AudioContext;this._audio_context.onmessage=function(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};n.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};n.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};n.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 e=a.graph.getNodeById(d.origin_id),f=null,f=e.getAudioNodeInOutputSlot?e.getAudioNodeInOutputSlot(d.origin_slot):e.audionode,d=null,d=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(c):a.audionode;b?n.connect(f,d):n.disconnect(f,d)}}if(a.outputs)for(c=0;c<a.outputs.length;++c)for(var e=a.outputs[c],g=0;g<e.links.length;++g)if(d=a.graph.links[e.links[g]]){var f=a.getAudioNodeInOutputSlot?a.getAudioNodeInOutputSlot(c):a.audionode,
|
||||
h=a.graph.getNodeById(d.target_id),d=h.getAudioNodeInInputSlot?h.getAudioNodeInInputSlot(d.target_slot):h.audionode;b?n.connect(f,d):n.disconnect(f,d)}};n.onConnectionsChange=function(a,b,c,d){if(a==f.OUTPUT&&(a=null,d&&(a=this.graph.getNodeById(d.target_id)),a)){var e=null,e=this.getAudioNodeInOutputSlot?this.getAudioNodeInOutputSlot(b):this.audionode;b=null;b=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(d.target_slot):a.audionode;c?n.connect(e,b):n.disconnect(e,b)}};n.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=n.onConnectionsChange};n.cached_audios={};n.loadSound=function(a,b,c){function d(a){console.log("Audio loading sample error:",a);c&&c(a)}if(n.cached_audios[a]&&-1==a.indexOf("blob:"))b&&b(n.cached_audios[a]);else{n.onProcessAudioURL&&
|
||||
(a=n.onProcessAudioURL(a));var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";var f=n.getAudioContext();e.onload=function(){console.log("AudioSource loaded");f.decodeAudioData(e.response,function(c){console.log("AudioSource decoded");n.cached_audios[a]=c;b&&b(c)},d)};e.send();return e}};g["@src"]={widget:"resource"};g.supported_extensions=["wav","ogg","mp3"];g.prototype.onAdded=function(a){if(a.status===LGraph.STATUS_RUNNING)this.onStart()};g.prototype.onStart=function(){this._audiobuffer&&
|
||||
this.properties.autoplay&&this.playBuffer(this._audiobuffer)};g.prototype.onStop=function(){this.stopAllSounds()};g.prototype.onPause=function(){this.pauseAllSounds()};g.prototype.onUnpause=function(){this.unpauseAllSounds()};g.prototype.onRemoved=function(){this.stopAllSounds();this._dropped_url&&URL.revokeObjectURL(this._url)};g.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};g.prototype.pauseAllSounds=function(){m.getAudioContext().suspend()};g.prototype.unpauseAllSounds=function(){m.getAudioContext().resume()};g.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};g.prototype.pauseAllSounds=function(){n.getAudioContext().suspend()};g.prototype.unpauseAllSounds=function(){n.getAudioContext().resume()};g.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)};g.prototype.onAction=function(a){this._audiobuffer&&("Play"==a?this.playBuffer(this._audiobuffer):"Stop"==a&&this.stopAllSounds())};g.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};g.prototype.playBuffer=
|
||||
function(a){var b=this,c=m.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};g.prototype.loadSound=function(a){function b(a){this.boxcolor=f.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=m.loadSound(a,b),this._loading_audio=!0,this.boxcolor="#AA4")};g.prototype.onConnectionsChange=m.onConnectionsChange;g.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",f.ACTION],["Stop",f.ACTION]]};g.prototype.onGetOutputs=function(){return[["buffer",
|
||||
function(a){var b=this,c=n.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};g.prototype.loadSound=function(a){function b(a){this.boxcolor=f.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=n.loadSound(a,b),this._loading_audio=!0,this.boxcolor="#AA4")};g.prototype.onConnectionsChange=n.onConnectionsChange;g.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",f.ACTION],["Stop",f.ACTION]]};g.prototype.onGetOutputs=function(){return[["buffer",
|
||||
"audiobuffer"],["ended",f.EVENT]]};g.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};g.title="Source";g.desc="Plays audio";f.registerNodeType("audio/source",g);e.prototype.onPropertyChanged=function(a,b){this.audionode[a]=b};e.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)}}};e.prototype.onGetInputs=
|
||||
function(){return[["minDecibels","number"],["maxDecibels","number"],["smoothingTimeConstant","number"]]};e.prototype.onGetOutputs=function(){return[["freqs","array"],["samples","array"]]};e.title="Analyser";e.desc="Audio Analyser";f.registerNodeType("audio/analyser",e);h.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)}};m.createAudioNodeWrapper(h);h.title=
|
||||
"Gain";h.desc="Audio gain";f.registerNodeType("audio/gain",h);m.createAudioNodeWrapper(n);n.prototype.onRemove=function(){this._dropped_url&&URL.revokeObjectURL(this._dropped_url)};n.prototype.onPropertyChanged=function(a,b){"impulse_src"==a?this.loadImpulse(b):"normalize"==a&&(this.audionode.normalize=b)};n.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)};
|
||||
n.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=m.loadSound(a,b),this._loading_impulse=!0)};n.title="Convolver";n.desc="Convolves the signal (used for reverb)";f.registerNodeType("audio/convolver",n);m.createAudioNodeWrapper(p);p.prototype.onExecute=function(){if(this.inputs&&
|
||||
function(){return[["minDecibels","number"],["maxDecibels","number"],["smoothingTimeConstant","number"]]};e.prototype.onGetOutputs=function(){return[["freqs","array"],["samples","array"]]};e.title="Analyser";e.desc="Audio Analyser";f.registerNodeType("audio/analyser",e);h.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)}};n.createAudioNodeWrapper(h);h.title=
|
||||
"Gain";h.desc="Audio gain";f.registerNodeType("audio/gain",h);n.createAudioNodeWrapper(m);m.prototype.onRemove=function(){this._dropped_url&&URL.revokeObjectURL(this._dropped_url)};m.prototype.onPropertyChanged=function(a,b){"impulse_src"==a?this.loadImpulse(b):"normalize"==a&&(this.audionode.normalize=b)};m.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)};
|
||||
m.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=n.loadSound(a,b),this._loading_impulse=!0)};m.title="Convolver";m.desc="Convolves the signal (used for reverb)";f.registerNodeType("audio/convolver",m);n.createAudioNodeWrapper(p);p.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)}}};p.prototype.onGetInputs=function(){return[["threshold","number"],["knee","number"],["ratio","number"],["reduction","number"],["attack","number"],["release","number"]]};p.title="DynamicsCompressor";p.desc="Dynamics Compressor";f.registerNodeType("audio/dynamicsCompressor",p);q.prototype.onExecute=function(){if(this.inputs&&this.inputs.length){var a=
|
||||
this.getInputData(1);void 0!==a&&(this.audionode.curve=a)}};q.prototype.setWaveShape=function(a){this.audionode.curve=a};m.createAudioNodeWrapper(q);r.prototype.getAudioNodeInInputSlot=function(a){if(0==a)return this.audionode1;if(2==a)return this.audionode2};r.prototype.onPropertyChanged=function(a,b){"gain1"==a?this.audionode1.gain.value=b:"gain2"==a&&(this.audionode2.gain.value=b)};r.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)))}};m.createAudioNodeWrapper(r);r.title="Mixer";r.desc="Audio mixer";f.registerNodeType("audio/mixer",r);m.createAudioNodeWrapper(l);l.prototype.onExecute=function(){var a=this.getInputData(1);void 0!==a&&(this.audionode.delayTime.value=a)};l.title="Delay";l.desc="Audio delay";f.registerNodeType("audio/delay",l);s.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)}}};s.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["Q","number"]]};m.createAudioNodeWrapper(s);s.title="BiquadFilter";s.desc="Audio filter";f.registerNodeType("audio/biquadfilter",s);c.prototype.onStart=function(){this.audionode.started||(this.audionode.started=!0,this.audionode.start())};c.prototype.onStop=
|
||||
this.getInputData(1);void 0!==a&&(this.audionode.curve=a)}};q.prototype.setWaveShape=function(a){this.audionode.curve=a};n.createAudioNodeWrapper(q);r.prototype.getAudioNodeInInputSlot=function(a){if(0==a)return this.audionode1;if(2==a)return this.audionode2};r.prototype.onPropertyChanged=function(a,b){"gain1"==a?this.audionode1.gain.value=b:"gain2"==a&&(this.audionode2.gain.value=b)};r.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)))}};n.createAudioNodeWrapper(r);r.title="Mixer";r.desc="Audio mixer";f.registerNodeType("audio/mixer",r);n.createAudioNodeWrapper(l);l.prototype.onExecute=function(){var a=this.getInputData(1);void 0!==a&&(this.audionode.delayTime.value=a)};l.title="Delay";l.desc="Audio delay";f.registerNodeType("audio/delay",l);s.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)}}};s.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["Q","number"]]};n.createAudioNodeWrapper(s);s.title="BiquadFilter";s.desc="Audio filter";f.registerNodeType("audio/biquadfilter",s);c.prototype.onStart=function(){this.audionode.started||(this.audionode.started=!0,this.audionode.start())};c.prototype.onStop=
|
||||
function(){this.audionode.started&&(this.audionode.started=!1,this.audionode.stop())};c.prototype.onPause=function(){this.onStop()};c.prototype.onUnpause=function(){this.onStart()};c.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)}}};c.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["type","string"]]};
|
||||
m.createAudioNodeWrapper(c);c.title="Oscillator";c.desc="Oscillator";f.registerNodeType("audio/oscillator",c);a.prototype.onExecute=function(){this._last_buffer=this.getInputData(0);var a=this.getInputData(1);void 0!==a&&(this.properties.mark=a);this.setDirtyCanvas(!0,!1)};a.prototype.onDrawForeground=function(a){if(this._last_buffer){var b=this._last_buffer,c=b.length/this.size[0],d=this.size[1];a.fillStyle="black";a.fillRect(0,0,this.size[0],this.size[1]);a.strokeStyle="white";a.beginPath();var e=
|
||||
0;if(this.properties.continuous){a.moveTo(e,d);for(var f=0;f<b.length;f+=c)a.lineTo(e,d-b[f|0]/255*d),e++}else for(f=0;f<b.length;f+=c)a.moveTo(e+0.5,d),a.lineTo(e+0.5,d-b[f|0]/255*d),e++;a.stroke();0<=this.properties.mark&&(b=m.getAudioContext().sampleRate/b.length,e=this.properties.mark/b*2/c,e>=this.size[0]&&(e=this.size[0]-1),a.strokeStyle="red",a.beginPath(),a.moveTo(e,d),a.lineTo(e,0),a.stroke())}};a.title="Visualization";a.desc="Audio Visualization";f.registerNodeType("audio/visualization",
|
||||
a);b.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var a=this.properties.band,b=this.getInputData(1);void 0!==b&&(a=b);b=m.getAudioContext().sampleRate/this._freqs.length;b=a/b*2;b>=this._freqs.length?b=this._freqs[this._freqs.length-1]:(a=b|0,b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.properties.amplitude)}};b.prototype.onGetInputs=function(){return[["band","number"]]};b.title="Signal";b.desc="extract the signal of some frequency";f.registerNodeType("audio/signal",
|
||||
n.createAudioNodeWrapper(c);c.title="Oscillator";c.desc="Oscillator";f.registerNodeType("audio/oscillator",c);a.prototype.onExecute=function(){this._last_buffer=this.getInputData(0);var a=this.getInputData(1);void 0!==a&&(this.properties.mark=a);this.setDirtyCanvas(!0,!1)};a.prototype.onDrawForeground=function(a){if(this._last_buffer){var b=this._last_buffer,c=b.length/this.size[0],d=this.size[1];a.fillStyle="black";a.fillRect(0,0,this.size[0],this.size[1]);a.strokeStyle="white";a.beginPath();var e=
|
||||
0;if(this.properties.continuous){a.moveTo(e,d);for(var f=0;f<b.length;f+=c)a.lineTo(e,d-b[f|0]/255*d),e++}else for(f=0;f<b.length;f+=c)a.moveTo(e+0.5,d),a.lineTo(e+0.5,d-b[f|0]/255*d),e++;a.stroke();0<=this.properties.mark&&(b=n.getAudioContext().sampleRate/b.length,e=this.properties.mark/b*2/c,e>=this.size[0]&&(e=this.size[0]-1),a.strokeStyle="red",a.beginPath(),a.moveTo(e,d),a.lineTo(e,0),a.stroke())}};a.title="Visualization";a.desc="Audio Visualization";f.registerNodeType("audio/visualization",
|
||||
a);b.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var a=this.properties.band,b=this.getInputData(1);void 0!==b&&(a=b);b=n.getAudioContext().sampleRate/this._freqs.length;b=a/b*2;b>=this._freqs.length?b=this._freqs[this._freqs.length-1]:(a=b|0,b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.properties.amplitude)}};b.prototype.onGetInputs=function(){return[["band","number"]]};b.title="Signal";b.desc="extract the signal of some frequency";f.registerNodeType("audio/signal",
|
||||
b);d.prototype.onAdded=function(a){a.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};d["@code"]={widget:"code"};d.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};d.prototype.onStop=function(){this.audionode.onaudioprocess=d._bypass_function};d.prototype.onPause=function(){this.audionode.onaudioprocess=d._bypass_function};d.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};d.prototype.onExecute=function(){};d.prototype.onRemoved=
|
||||
function(){this.audionode.onaudioprocess=d._bypass_function};d.prototype.processCode=function(){try{this._script=new new Function("properties",this.properties.code)(this.properties),this._old_code=this.properties.code,this._callback=this._script.onaudioprocess}catch(a){console.error("Error in onaudioprocess code",a),this._callback=d._bypass_function,this.audionode.onaudioprocess=this._callback}};d.prototype.onPropertyChanged=function(a,b){"code"==a&&(this.properties.code=b,this.processCode(),this.graph&&
|
||||
this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};d.default_function=function(){this.onaudioprocess=function(a){var b=a.inputBuffer;a=a.outputBuffer;for(var c=0;c<a.numberOfChannels;c++)for(var d=b.getChannelData(c),e=a.getChannelData(c),f=0;f<b.length;f++)e[f]=d[f]}};m.createAudioNodeWrapper(d);d.title="Script";d.desc="apply script to signal";f.registerNodeType("audio/script",d);x.title="Destination";x.desc="Audio output";f.registerNodeType("audio/destination",
|
||||
this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};d.default_function=function(){this.onaudioprocess=function(a){var b=a.inputBuffer;a=a.outputBuffer;for(var c=0;c<a.numberOfChannels;c++)for(var d=b.getChannelData(c),e=a.getChannelData(c),f=0;f<b.length;f++)e[f]=d[f]}};n.createAudioNodeWrapper(d);d.title="Script";d.desc="apply script to signal";f.registerNodeType("audio/script",d);x.title="Destination";x.desc="Audio output";f.registerNodeType("audio/destination",
|
||||
x)})(this);
|
||||
(function(u){function g(){this.size=[60,20];this.addInput("send",h.ACTION);this.addOutput("received",h.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph"};this._ws=null;this._last_data=[]}function e(){this.size=[60,20];this.addInput("send",h.ACTION);this.addOutput("received",h.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"tamats.com:55000",room:"lgraph",save_bandwidth:!0};this._server=null;this.createSocket();this._last_input_data=[];
|
||||
this._last_output_data=[]}var h=u.LiteGraph;g.title="WebSocket";g.desc="Send data through a websocket";g.prototype.onPropertyChanged=function(e,g){"url"==e&&this.createSocket()};g.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.createSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var e=this.properties.room,g=1;g<this.inputs.length;++g){var h=this.getInputData(g);if(null!=h){var r;try{r=JSON.stringify({type:0,room:e,channel:g,data:h})}catch(l){continue}this._ws.send(r)}}for(g=
|
||||
|
||||
@@ -122,7 +122,6 @@ DelayEvent.prototype.onAction = function(action, param)
|
||||
DelayEvent.prototype.onExecute = function()
|
||||
{
|
||||
var dt = this.graph.elapsed_time * 1000; //in ms
|
||||
console.log(this._pending);
|
||||
|
||||
for(var i = 0; i < this._pending.length; ++i)
|
||||
{
|
||||
|
||||
@@ -64,6 +64,7 @@ var LiteGraph = global.LiteGraph;
|
||||
function WidgetToggle()
|
||||
{
|
||||
this.addInput( "", "boolean" );
|
||||
this.addInput( "e", LiteGraph.ACTION );
|
||||
this.addOutput( "v", "boolean" );
|
||||
this.addOutput( "e", LiteGraph.EVENT );
|
||||
this.properties = { font: "", value: false };
|
||||
@@ -95,6 +96,12 @@ var LiteGraph = global.LiteGraph;
|
||||
ctx.textAlign = "left";
|
||||
}
|
||||
|
||||
WidgetToggle.prototype.onAction = function(action)
|
||||
{
|
||||
this.properties.value = !this.properties.value;
|
||||
this.trigger( "e", this.properties.value );
|
||||
}
|
||||
|
||||
WidgetToggle.prototype.onExecute = function()
|
||||
{
|
||||
var v = this.getInputData(0);
|
||||
|
||||
Reference in New Issue
Block a user