|
|
|
|
@@ -6,21 +6,21 @@ var h=document.createElement("div");h.className="litegraph litecontextmenu litem
|
|
|
|
|
this.root=h;if(b.title){var k=document.createElement("div");k.className="litemenu-title";k.innerHTML=b.title;h.appendChild(k)}var k=0,d;for(d in a){var n=a.constructor==Array?a[d]:d;null!=n&&n.constructor!==String&&(n=void 0===n.content?String(n):n.content);this.addItem(n,a[d],b);k++}h.addEventListener("mouseleave",function(a){c.lock||c.close(a)});d=document;b.event&&(d=b.event.target.ownerDocument);d||(d=document);d.body.appendChild(h);k=b.left||0;d=b.top||0;if(b.event){k=b.event.pageX-10;d=b.event.pageY-
|
|
|
|
|
10;b.title&&(d-=20);b.parentMenu&&(k=b.parentMenu.root.getBoundingClientRect(),k=k.left+k.width);var n=document.body.getBoundingClientRect(),e=h.getBoundingClientRect();k>n.width-e.width-10&&(k=n.width-e.width-10);d>n.height-e.height-10&&(d=n.height-e.height-10)}h.style.left=k+"px";h.style.top=d+"px"}var d=q.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;d.debug&&console.log("Node registered: "+a);a.split("/");var c=b.constructor.name,h=a.lastIndexOf("/");b.category=a.substr(0,h);b.title||(b.title=c);if(b.prototype)for(var k in f.prototype)b.prototype[k]||(b.prototype[k]=f.prototype[k]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "box":this._shape=d.BOX_SHAPE;break;case "round":this._shape=d.ROUND_SHAPE;break;case "circle":this._shape=d.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[c]=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(k in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[k].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,c,h){for(var k=Array(b.length),r="",n=d.getParameterNames(b),e=0;e<n.length;++e)r+="this.addInput('"+
|
|
|
|
|
n[e]+"',"+(c&&c[e]?"'"+c[e]+"'":"0")+");\n";c=Function(r+("this.addOutput('out',"+(h?"'"+h+"'":0)+");\n"));c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<k.length;++a)k[a]=this.getInputData(a);a=b.apply(this,k);this.setOutputData(0,a)};this.registerNodeType(a,c)},addNodeMethod:function(a,b){f.prototype[a]=b;for(var c in this.registered_node_types){var h=this.registered_node_types[c];h.prototype[a]&&(h.prototype["_"+a]=h.prototype[a]);h.prototype[a]=
|
|
|
|
|
b.type=a;d.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,h=a.lastIndexOf("/");b.category=a.substr(0,h);b.title||(b.title=c);if(b.prototype)for(var k in f.prototype)b.prototype[k]||(b.prototype[k]=f.prototype[k]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "box":this._shape=d.BOX_SHAPE;break;case "round":this._shape=d.ROUND_SHAPE;break;case "circle":this._shape=d.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[c]=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(k in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[k].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,c,h){for(var k=Array(b.length),s="",n=d.getParameterNames(b),e=0;e<n.length;++e)s+="this.addInput('"+n[e]+"',"+
|
|
|
|
|
(c&&c[e]?"'"+c[e]+"'":"0")+");\n";c=Function(s+("this.addOutput('out',"+(h?"'"+h+"'":0)+");\n"));c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<k.length;++a)k[a]=this.getInputData(a);a=b.apply(this,k);this.setOutputData(0,a)};this.registerNodeType(a,c)},addNodeMethod:function(a,b){f.prototype[a]=b;for(var c in this.registered_node_types){var h=this.registered_node_types[c];h.prototype[a]&&(h.prototype["_"+a]=h.prototype[a]);h.prototype[a]=
|
|
|
|
|
b}},createNode:function(a,b,c){var h=this.registered_node_types[a];if(!h)return d.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||h.title||a;h=new h(b);h.type=a;h.title||(h.title=b);h.properties||(h.properties={});h.properties_info||(h.properties_info=[]);h.flags||(h.flags={});h.size||(h.size=h.computeSize());h.pos||(h.pos=d.DEFAULT_POSITION.concat());h.mode||(h.mode=d.ALWAYS);if(c)for(var k in c)h[k]=c[k];return h},getNodeType:function(a){return this.registered_node_types[a]},
|
|
|
|
|
getNodeTypesInCategory:function(a){var b=[],c;for(c in this.registered_node_types)""==a?null==this.registered_node_types[c].category&&b.push(this.registered_node_types[c]):this.registered_node_types[c].category==a&&b.push(this.registered_node_types[c]);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 c=[];for(b in a)c.push(b);
|
|
|
|
|
return c},reloadNodes:function(a){var b=document.getElementsByTagName("script"),c=[],h;for(h in b)c.push(b[h]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(h in c){var k=c[h].src;if(k&&k.substr(0,a.length)==a)try{d.debug&&console.log("Reloading: "+k);var r=document.createElement("script");r.type="text/javascript";r.src=k;b.appendChild(r);b.removeChild(c[h])}catch(n){if(d.throw_errors)throw n;d.debug&&console.log("Error while reloading "+k)}}d.debug&&console.log("Nodes reloaded")},
|
|
|
|
|
cloneObject:function(a,b){if(null==a)return null;var c=JSON.parse(JSON.stringify(a));if(!b)return c;for(var h in c)b[h]=c[h];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==d.EVENT&&b==d.ACTION)return!0;a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;for(var c=a.split(","),h=b.split(","),k=0;k<c.length;++k)for(var r=0;r<h.length;++r)if(c[k]==h[k])return!0;return!1}};d.getTime="undefined"!=typeof performance?performance.now.bind(performance):
|
|
|
|
|
return c},reloadNodes:function(a){var b=document.getElementsByTagName("script"),c=[],h;for(h in b)c.push(b[h]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(h in c){var k=c[h].src;if(k&&k.substr(0,a.length)==a)try{d.debug&&console.log("Reloading: "+k);var s=document.createElement("script");s.type="text/javascript";s.src=k;b.appendChild(s);b.removeChild(c[h])}catch(n){if(d.throw_errors)throw n;d.debug&&console.log("Error while reloading "+k)}}d.debug&&console.log("Nodes reloaded")},
|
|
|
|
|
cloneObject:function(a,b){if(null==a)return null;var c=JSON.parse(JSON.stringify(a));if(!b)return c;for(var h in c)b[h]=c[h];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==d.EVENT&&b==d.ACTION)return!0;a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;for(var c=a.split(","),h=b.split(","),k=0;k<c.length;++k)for(var s=0;s<h.length;++s)if(c[k]==h[k])return!0;return!1}};d.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()};q.LGraph=d.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=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!=e)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.starttime=d.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 c=d.getTime();this.globaltime=0.001*(c-this.starttime);var h=this._nodes_executable?this._nodes_executable:this._nodes;if(h){if(b){for(var k=
|
|
|
|
|
0;k<a;k++){for(var r=0,n=h.length;r<n;++r){var e=h[r];if(e.mode==d.ALWAYS&&e.onExecute)e.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(k=0;k<a;k++){r=0;for(n=h.length;r<n;++r)if(e=h[r],e.mode==d.ALWAYS&&e.onExecute)e.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(l){this.errors_in_execution=
|
|
|
|
|
0;k<a;k++){for(var s=0,n=h.length;s<n;++s){var e=h[s];if(e.mode==d.ALWAYS&&e.onExecute)e.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(k=0;k<a;k++){s=0;for(n=h.length;s<n;++s)if(e=h[s],e.mode==d.ALWAYS&&e.onExecute)e.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(l){this.errors_in_execution=
|
|
|
|
|
!0;if(d.throw_errors)throw l;d.debug&&console.log("Error during execution: "+l);this.stop()}c=d.getTime()-c;0==c&&(c=1);this.elapsed_time=0.001*c;this.globaltime+=0.001*c;this.iteration+=1}};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 c=
|
|
|
|
|
[],h=[],k={},e={},n={},l=0,g=this._nodes.length;l<g;++l){var f=this._nodes[l];if(!a||f.onExecute){k[f.id]=f;var w=0;if(f.inputs)for(var y=0,s=f.inputs.length;y<s;y++)f.inputs[y]&&null!=f.inputs[y].link&&(w+=1);0==w?(h.push(f),b&&(f._level=1)):(b&&(f._level=0),n[f.id]=w)}}for(;0!=h.length;)if(f=h.shift(),c.push(f),delete k[f.id],f.outputs)for(l=0;l<f.outputs.length;l++)if(g=f.outputs[l],null!=g&&null!=g.links&&0!=g.links.length)for(y=0;y<g.links.length;y++)(w=this.links[g.links[y]])&&!e[w.id]&&(s=
|
|
|
|
|
this.getNodeById(w.target_id),null==s?e[w.id]=!0:(b&&(!s._level||s._level<=f._level)&&(s._level=f._level+1),e[w.id]=!0,n[s.id]-=1,0==n[s.id]&&h.push(s)));for(l in k)c.push(k[l]);c.length!=this._nodes.length&&d.debug&&console.warn("something went wrong, nodes missing");for(l=0;l<c.length;++l)c[l].order=l;return c};g.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),c=[],h=0;h<b.length;++h){var k=b[h],d=k._level||1;c[d]||(c[d]=[]);c[d].push(k)}b=a;for(h=0;h<c.length;++h)if(d=
|
|
|
|
|
[],h=[],k={},e={},n={},l=0,g=this._nodes.length;l<g;++l){var f=this._nodes[l];if(!a||f.onExecute){k[f.id]=f;var r=0;if(f.inputs)for(var x=0,B=f.inputs.length;x<B;x++)f.inputs[x]&&null!=f.inputs[x].link&&(r+=1);0==r?(h.push(f),b&&(f._level=1)):(b&&(f._level=0),n[f.id]=r)}}for(;0!=h.length;)if(f=h.shift(),c.push(f),delete k[f.id],f.outputs)for(l=0;l<f.outputs.length;l++)if(g=f.outputs[l],null!=g&&null!=g.links&&0!=g.links.length)for(x=0;x<g.links.length;x++)(r=this.links[g.links[x]])&&!e[r.id]&&(B=
|
|
|
|
|
this.getNodeById(r.target_id),null==B?e[r.id]=!0:(b&&(!B._level||B._level<=f._level)&&(B._level=f._level+1),e[r.id]=!0,n[B.id]-=1,0==n[B.id]&&h.push(B)));for(l in k)c.push(k[l]);c.length!=this._nodes.length&&d.debug&&console.warn("something went wrong, nodes missing");for(l=0;l<c.length;++l)c[l].order=l;return c};g.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),c=[],h=0;h<b.length;++h){var k=b[h],d=k._level||1;c[d]||(c[d]=[]);c[d].push(k)}b=a;for(h=0;h<c.length;++h)if(d=
|
|
|
|
|
c[h]){for(var n=100,e=a,l=0;l<d.length;++l)k=d[l],k.pos[0]=b,k.pos[1]=e,k.size[0]>n&&(n=k.size[0]),e+=k.size[1]+a;b+=n+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,c){c=c||d.ALWAYS;var h=this._nodes_in_order?this._nodes_in_order:this._nodes;if(h)for(var k=0,e=h.length;k<e;++k){var n=h[k];if(n[a]&&
|
|
|
|
|
n.mode==c)if(void 0===b)n[a]();else if(b&&b.constructor===Array)n[a].apply(n,b);else n[a](b)}};g.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var h=this.list_of_graphcanvas[c];h[a]&&h[a].apply(h,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>=d.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 c=a.inputs[b];null!=c.link&&
|
|
|
|
|
@@ -31,7 +31,7 @@ b){var c=this.global_inputs[a];c&&(c.value=b)};g.prototype.getGlobalInputData=fu
|
|
|
|
|
function(a,b){if(!this.global_inputs[a])return!1;if(this.global_inputs[a].type.toLowerCase()!=b.toLowerCase()&&(this.global_inputs[a].type=b,this.onGlobalInputTypeChanged))this.onGlobalInputTypeChanged(a,b)};g.prototype.removeGlobalInput=function(a){if(!this.global_inputs[a])return!1;delete this.global_inputs[a];if(this.onGlobalInputRemoved)this.onGlobalInputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();return!0};g.prototype.addGlobalOutput=function(a,b,c){this.global_outputs[a]={name:a,
|
|
|
|
|
type:b,value:c};if(this.onGlobalOutputAdded)this.onGlobalOutputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};g.prototype.setGlobalOutputData=function(a,b){var c=this.global_outputs[a];c&&(c.value=b)};g.prototype.getGlobalOutputData=function(a){return(a=this.global_outputs[a])?a.value:null};g.prototype.renameGlobalOutput=function(a,b){if(!this.global_outputs[a])return!1;if(this.global_outputs[b])return console.error("there is already one output with that name"),!1;this.global_outputs[b]=
|
|
|
|
|
this.global_outputs[a];delete this.global_outputs[a];if(this.onGlobalOutputRenamed)this.onGlobalOutputRenamed(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};g.prototype.changeGlobalOutputType=function(a,b){if(!this.global_outputs[a])return!1;if(this.global_outputs[a].type.toLowerCase()!=b.toLowerCase()&&(this.global_outputs[a].type=b,this.onGlobalOutputTypeChanged))this.onGlobalOutputTypeChanged(a,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.setInputData=function(a,b){for(var c=this.findNodesByName(a),h=0,d=c.length;h<d;++h)c[h].setValue(b)};g.prototype.getOutputData=function(a){return this.findNodesByName(a).length?m[0].getValue():null};g.prototype.triggerInput=function(a,b){for(var c=this.findNodesByName(a),h=0;h<c.length;++h)c[h].onTrigger(b)};g.prototype.setCallback=function(a,b){for(var c=this.findNodesByName(a),
|
|
|
|
|
if(this.onGlobalOutputRemoved)this.onGlobalOutputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();return!0};g.prototype.setInputData=function(a,b){for(var c=this.findNodesByTitle(a),h=0,d=c.length;h<d;++h)c[h].setValue(b)};g.prototype.getOutputData=function(a){return this.findNodesByTitle(a).length?m[0].getValue():null};g.prototype.triggerInput=function(a,b){for(var c=this.findNodesByTitle(a),h=0;h<c.length;++h)c[h].onTrigger(b)};g.prototype.setCallback=function(a,b){for(var c=this.findNodesByTitle(a),
|
|
|
|
|
h=0;h<c.length;++h)c[h].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(){d.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,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var h=this.links[b];c.push([h.id,h.origin_id,h.origin_slot,h.target_id,h.target_slot,h.type])}return{iteration:this.iteration,frame:this.frame,last_node_id:this.last_node_id,last_link_id:this.last_link_id,links:c,config:this.config,nodes:a}};g.prototype.configure=function(a,b){b||
|
|
|
|
|
this.clear();var c=a.nodes;if(a.links&&a.links.constructor===Array){for(var h={},k=0;k<a.links.length;++k){var e=a.links[k];h[e[0]]={id:e[0],origin_id:e[1],origin_slot:e[2],target_id:e[3],target_slot:e[4],type:e[5]}}a.links=h}for(k in a)this[k]=a[k];h=!1;this._nodes=[];k=0;for(e=c.length;k<e;++k){var n=c[k],l=d.createNode(n.type,n.title);l?(l.id=n.id,this.add(l,!0)):(d.debug&&console.log("Node not found: "+n.type),h=!0)}k=0;for(e=c.length;k<e;++k)n=c[k],(l=this.getNodeById(n.id))&&l.configure(n);
|
|
|
|
|
@@ -49,7 +49,7 @@ this.graph.links[c[h]];if(k){var e=this.graph.getNodeById(k.target_id);if(e)if(k
|
|
|
|
|
b,c){a={name:a,type:b,links:null};if(c)for(var h in c)a[h]=c[h];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();return a};f.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],h={name:c[0],type:c[1],link:null};if(a[2])for(var d in c[2])h[d]=c[2][d];this.outputs||(this.outputs=[]);this.outputs.push(h);if(this.onOutputAdded)this.onOutputAdded(h)}this.size=this.computeSize()};f.prototype.removeOutput=function(a){this.disconnectOutput(a);
|
|
|
|
|
this.outputs.splice(a,1);this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a)};f.prototype.addInput=function(a,b,c){a={name:a,type:b||0,link:null};if(c)for(var h in c)a[h]=c[h];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);return a};f.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],h={name:c[0],type:c[1],link:null};if(a[2])for(var d in c[2])h[d]=c[2][d];this.inputs||(this.inputs=
|
|
|
|
|
[]);this.inputs.push(h);if(this.onInputAdded)this.onInputAdded(h)}this.size=this.computeSize()};f.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a)};f.prototype.addConnection=function(a,b,c,h){a={name:a,type:b,pos:c,direction:h,links:null};this.connections.push(a);return a};f.prototype.computeSize=function(a,b){function c(a){return a?e*a.length*0.6:0}var h=Math.max(this.inputs?this.inputs.length:
|
|
|
|
|
1,this.outputs?this.outputs.length:1),k=b||new Float32Array([0,0]),h=Math.max(h,1);k[1]=14*h+6;var e=14,h=c(this.title),n=0,l=0;if(this.inputs)for(var f=0,g=this.inputs.length;f<g;++f){var w=this.inputs[f],w=w.label||w.name||"",w=c(w);n<w&&(n=w)}if(this.outputs)for(f=0,g=this.outputs.length;f<g;++f)w=this.outputs[f],w=w.label||w.name||"",w=c(w),l<w&&(l=w);k[0]=Math.max(n+l+10,h);k[0]=Math.max(k[0],d.NODE_WIDTH);return k};f.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-
|
|
|
|
|
1,this.outputs?this.outputs.length:1),k=b||new Float32Array([0,0]),h=Math.max(h,1);k[1]=14*h+6;var e=14,h=c(this.title),n=0,l=0;if(this.inputs)for(var f=0,g=this.inputs.length;f<g;++f){var r=this.inputs[f],r=r.label||r.name||"",r=c(r);n<r&&(n=r)}if(this.outputs)for(f=0,g=this.outputs.length;f<g;++f)r=this.outputs[f],r=r.label||r.name||"",r=c(r),l<r&&(l=r);k[0]=Math.max(n+l+10,h);k[0]=Math.max(k[0],d.NODE_WIDTH);return k};f.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-
|
|
|
|
|
4;a[1]=this.pos[1]-d.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+d.NODE_TITLE_HEIGHT;return a};f.prototype.isPointInsideNode=function(a,b,c){c=c||0;var h=this.graph&&this.graph.isLive()?0:20;if(this.flags.collapsed){if(p(a,b,this.pos[0]-c,this.pos[1]-d.NODE_TITLE_HEIGHT-c,d.NODE_COLLAPSED_WIDTH+2*c,d.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-h-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};f.prototype.getSlotInPosition=
|
|
|
|
|
function(a,b){if(this.inputs)for(var c=0,h=this.inputs.length;c<h;++c){var d=this.inputs[c],e=this.getConnectionPos(!0,c);if(p(a,b,e[0]-10,e[1]-5,20,10))return{input:d,slot:c,link_pos:e,locked:d.locked}}if(this.outputs)for(c=0,h=this.outputs.length;c<h;++c)if(d=this.outputs[c],e=this.getConnectionPos(!1,c),p(a,b,e[0]-10,e[1]-5,20,10))return{output:d,slot:c,link_pos:e,locked:d.locked};return null};f.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(a==
|
|
|
|
|
this.inputs[b].name)return b;return-1};f.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<c;++b)if(a==this.outputs[b].name)return b;return-1};f.prototype.connect=function(a,b,c){c=c||0;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return d.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return d.debug&&console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===
|
|
|
|
|
@@ -100,8 +100,8 @@ e.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.select
|
|
|
|
|
d.selected=!1}}this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)}};e.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)};e.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)};e.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]};e.prototype.setZoom=function(a,b){b||(b=[0.5*this.canvas.width,0.5*this.canvas.height]);var c=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 d=this.convertOffsetToCanvas(b),c=[d[0]-c[0],d[1]-c[1]];this.offset[0]+=
|
|
|
|
|
c[0];this.offset[1]+=c[1];this.dirty_bgcanvas=this.dirty_canvas=!0};e.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};e.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};e.prototype.convertEventToCanvas=function(a){var b=this.canvas.getBoundingClientRect();return this.convertOffsetToCanvas([a.pageX-b.left,a.pageY-b.top])};
|
|
|
|
|
e.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};e.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);e.prototype.computeVisibleNodes=function(a,b){var c=b||[];c.length=0;a=a||this.graph._nodes;for(var d=0,k=a.length;d<k;++d){var e=a[d];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&u(this.visible_area,
|
|
|
|
|
e.getBounding(s))&&c.push(e)}return c};e.prototype.draw=function(a,b){if(this.canvas){var c=d.getTime();this.render_time=0.001*(c-this.last_draw_time);this.last_draw_time=c;if(this.graph){var h=[-this.offset[0],-this.offset[1]],k=[h[0]+this.canvas.width/this.scale,h[1]+this.canvas.height/this.scale];this.visible_area=new Float32Array([h[0],h[1],k[0]-h[0],k[1]-h[1]])}(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&
|
|
|
|
|
e.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};e.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 r=new Float32Array(4);e.prototype.computeVisibleNodes=function(a,b){var c=b||[];c.length=0;a=a||this.graph._nodes;for(var d=0,k=a.length;d<k;++d){var e=a[d];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&u(this.visible_area,
|
|
|
|
|
e.getBounding(r))&&c.push(e)}return c};e.prototype.draw=function(a,b){if(this.canvas){var c=d.getTime();this.render_time=0.001*(c-this.last_draw_time);this.last_draw_time=c;if(this.graph){var h=[-this.offset[0],-this.offset[1]],k=[h[0]+this.canvas.width/this.scale,h[1]+this.canvas.height/this.scale];this.visible_area=new Float32Array([h[0],h[1],k[0]-h[0],k[1]-h[1]])}(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&
|
|
|
|
|
this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};e.prototype.drawFrontCanvas=function(){this.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),c=0;c<b.length;++c){var h=b[c];a.save();a.translate(h.pos[0],h.pos[1]);this.drawNode(h,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 d.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);a.beginPath();this.connecting_output.type===d.EVENT?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),
|
|
|
|
|
@@ -126,16 +126,16 @@ this.connections_width;a.fillStyle=a.strokeStyle=n;a.stroke();this.render_connec
|
|
|
|
|
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)};e.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 d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(d),
|
|
|
|
|
b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};e.prototype.onNodeSelectionChange=function(a){};e.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 d=this.getCanvasWindow(),e=d.document.createEvent("MouseEvent");e.initMouseEvent(c,!0,!0,d,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,
|
|
|
|
|
!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};e.onMenuAdd=function(a,b,c,h){function k(a,b){var c=h.getFirstEvent(),n=d.createNode(a.value);n&&(n.pos=l.convertEventToCanvas(c),l.graph.add(n))}var l=e.active_canvas,n=l.getCanvasWindow();a=d.getNodeTypesCategories();b=[];for(var f in a)a[f]&&b.push({value:a[f],content:a[f],has_submenu:!0});var g=new d.ContextMenu(b,{event:c,callback:function(a,b,c){a=d.getNodeTypesInCategory(a.value);b=[];for(var h in a)b.push({content:a[h].title,value:a[h].type});
|
|
|
|
|
new d.ContextMenu(b,{event:c,callback:k,parentMenu:g},n);return!1},parentMenu:h},n);return!1};e.onMenuCollapseAll=function(){};e.onMenuNodeEdit=function(){};e.showMenuNodeOptionalInputs=function(a,b,c,h,k){function l(a,b,c){k&&(a.callback&&a.callback.call(n,k,a,b,c),a.value&&(k.addInput(a.value[0],a.value[1],a.value[2]),k.setDirtyCanvas(!0,!0)))}if(k){var n=this;a=e.active_canvas.getCanvasWindow();b=k.optional_inputs;k.onGetInputs&&(b=k.onGetInputs());var f=[];if(b)for(var g in b){var s=b[g];if(s){var w=
|
|
|
|
|
s[0];s[2]&&s[2].label&&(w=s[2].label);w={content:w,value:s};s[1]==d.ACTION&&(w.className="event");f.push(w)}else f.push(null)}this.onMenuNodeInputs&&(f=this.onMenuNodeInputs(f));if(f.length)return new d.ContextMenu(f,{event:c,callback:l,parentMenu:h,node:k},a),!1}};e.showMenuNodeOptionalOutputs=function(a,b,c,h,k){function l(a,b,c){if(k&&(a.callback&&a.callback.call(n,k,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)k.addOutput(a.value[0],a.value[1],a.value[2]),
|
|
|
|
|
k.setDirtyCanvas(!0,!0);else{a=[];for(var e in c)a.push({content:e,value:c[e]});new d.ContextMenu(a,{event:b,callback:l,parentMenu:h,node:k});return!1}}if(k){var n=this;a=e.active_canvas.getCanvasWindow();b=k.optional_outputs;k.onGetOutputs&&(b=k.onGetOutputs());var f=[];if(b)for(var g in b){var s=b[g];if(!s)f.push(null);else if(!k.flags||!k.flags.skip_repeated_outputs||-1==k.findOutputSlot(s[0])){var w=s[0];s[2]&&s[2].label&&(w=s[2].label);w={content:w,value:s};s[1]==d.EVENT&&(w.className="event");
|
|
|
|
|
f.push(w)}}this.onMenuNodeOutputs&&(f=this.onMenuNodeOutputs(f));if(f.length)return new d.ContextMenu(f,{event:c,callback:l,parentMenu:h,node:k},a),!1}};e.onShowMenuNodeProperties=function(a,b,c,h,k){function l(a,b,c,d){k&&(b=this.getBoundingClientRect(),n.showEditPropertyValue(k,a.value,{position:[b.left,b.top]}))}if(k&&k.properties){var n=e.active_canvas;b=n.getCanvasWindow();var f=[],g;for(g in k.properties)a=void 0!==k.properties[g]?k.properties[g]:" ",a=e.decodeHTML(a),f.push({content:"<span class='property_name'>"+
|
|
|
|
|
new d.ContextMenu(b,{event:c,callback:k,parentMenu:g},n);return!1},parentMenu:h},n);return!1};e.onMenuCollapseAll=function(){};e.onMenuNodeEdit=function(){};e.showMenuNodeOptionalInputs=function(a,b,c,h,k){function l(a,b,c){k&&(a.callback&&a.callback.call(n,k,a,b,c),a.value&&(k.addInput(a.value[0],a.value[1],a.value[2]),k.setDirtyCanvas(!0,!0)))}if(k){var n=this;a=e.active_canvas.getCanvasWindow();b=k.optional_inputs;k.onGetInputs&&(b=k.onGetInputs());var f=[];if(b)for(var g in b){var r=b[g];if(r){var p=
|
|
|
|
|
r[0];r[2]&&r[2].label&&(p=r[2].label);p={content:p,value:r};r[1]==d.ACTION&&(p.className="event");f.push(p)}else f.push(null)}this.onMenuNodeInputs&&(f=this.onMenuNodeInputs(f));if(f.length)return new d.ContextMenu(f,{event:c,callback:l,parentMenu:h,node:k},a),!1}};e.showMenuNodeOptionalOutputs=function(a,b,c,h,k){function l(a,b,c){if(k&&(a.callback&&a.callback.call(n,k,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)k.addOutput(a.value[0],a.value[1],a.value[2]),
|
|
|
|
|
k.setDirtyCanvas(!0,!0);else{a=[];for(var e in c)a.push({content:e,value:c[e]});new d.ContextMenu(a,{event:b,callback:l,parentMenu:h,node:k});return!1}}if(k){var n=this;a=e.active_canvas.getCanvasWindow();b=k.optional_outputs;k.onGetOutputs&&(b=k.onGetOutputs());var f=[];if(b)for(var g in b){var r=b[g];if(!r)f.push(null);else if(!k.flags||!k.flags.skip_repeated_outputs||-1==k.findOutputSlot(r[0])){var p=r[0];r[2]&&r[2].label&&(p=r[2].label);p={content:p,value:r};r[1]==d.EVENT&&(p.className="event");
|
|
|
|
|
f.push(p)}}this.onMenuNodeOutputs&&(f=this.onMenuNodeOutputs(f));if(f.length)return new d.ContextMenu(f,{event:c,callback:l,parentMenu:h,node:k},a),!1}};e.onShowMenuNodeProperties=function(a,b,c,h,k){function l(a,b,c,d){k&&(b=this.getBoundingClientRect(),n.showEditPropertyValue(k,a.value,{position:[b.left,b.top]}))}if(k&&k.properties){var n=e.active_canvas;b=n.getCanvasWindow();var f=[],g;for(g in k.properties)a=void 0!==k.properties[g]?k.properties[g]:" ",a=e.decodeHTML(a),f.push({content:"<span class='property_name'>"+
|
|
|
|
|
g+"</span><span class='property_value'>"+a+"</span>",value:g});if(f.length)return new d.ContextMenu(f,{event:c,callback:l,parentMenu:h,allow_html:!0,node:k},b),!1}};e.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};e.onResizeNode=function(a,b,c,d,e){e&&(e.size=e.computeSize(),e.setDirtyCanvas(!0,!0))};e.onShowTitleEditor=function(a,b,c,d,k){function l(){k.title=f.value;n.parentNode.removeChild(n);k.setDirtyCanvas(!0,!0)}var n=document.createElement("div");
|
|
|
|
|
n.className="graphdialog";n.innerHTML="<span class='name'>Title</span><input autofocus type='text' class='value'/><button>OK</button>";var f=n.querySelector("input");f&&(f.value=k.title,f.addEventListener("keydown",function(a){13==a.keyCode&&(l(),a.preventDefault(),a.stopPropagation())}));a=e.active_canvas.canvas;b=a.getBoundingClientRect();d=c=-20;b&&(c-=b.left,d-=b.top);event?(n.style.left=event.pageX+c+"px",n.style.top=event.pageY+d+"px"):(n.style.left=0.5*a.width+c+"px",n.style.top=0.5*a.height+
|
|
|
|
|
d+"px");n.querySelector("button").addEventListener("click",l);a.parentNode.appendChild(n)};e.prototype.showEditPropertyValue=function(a,b,c){function d(){e(y.value)}function e(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c);w.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var l="string";null!==a.properties[b]&&(l=typeof a.properties[b]);var n=null;a.getPropertyInfo&&(n=a.getPropertyInfo(b));if(a.properties_info)for(var f=
|
|
|
|
|
0;f<a.properties_info.length;++f)if(a.properties_info[f].name==b){n=a.properties_info[f];break}void 0!==n&&null!==n&&n.type&&(l=n.type);var g="";if("string"==l||"number"==l)g="<input autofocus type='text' class='value'/>";else if("enum"==l&&n.values){g="<select autofocus type='text' class='value'>";for(f in n.values)var s=n.values.constructor===Array?n.values[f]:f,g=g+("<option value='"+s+"' "+(s==a.properties[b]?"selected":"")+">"+n.values[f]+"</option>");g+="</select>"}else"boolean"==l&&(g="<input autofocus type='checkbox' class='value' "+
|
|
|
|
|
(a.properties[b]?"checked":"")+"/>");var w=this.createDialog("<span class='name'>"+b+"</span>"+g+"<button>OK</button>",c);if("enum"==l&&n.values){var y=w.querySelector("select");y.addEventListener("change",function(a){e(a.target.value)})}else if("boolean"==l)(y=w.querySelector("input"))&&y.addEventListener("click",function(a){e(!!y.checked)});else if(y=w.querySelector("input"))y.value=void 0!==a.properties[b]?a.properties[b]:"",y.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),
|
|
|
|
|
a.stopPropagation())});w.querySelector("button").addEventListener("click",d)}};e.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var d=this.canvas.getBoundingClientRect(),e=-20,l=-20;d&&(e-=d.left,l-=d.top);b.position?(e+=b.position[0],l+=b.position[1]):b.event?(e+=b.event.pageX,l+=b.event.pageY):(e+=0.5*this.canvas.width,l+=0.5*this.canvas.height);c.style.left=e+"px";c.style.top=l+"px";this.canvas.parentNode.appendChild(c);
|
|
|
|
|
d+"px");n.querySelector("button").addEventListener("click",l);a.parentNode.appendChild(n)};e.prototype.showEditPropertyValue=function(a,b,c){function d(){e(x.value)}function e(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 l="string";null!==a.properties[b]&&(l=typeof a.properties[b]);var n=null;a.getPropertyInfo&&(n=a.getPropertyInfo(b));if(a.properties_info)for(var f=
|
|
|
|
|
0;f<a.properties_info.length;++f)if(a.properties_info[f].name==b){n=a.properties_info[f];break}void 0!==n&&null!==n&&n.type&&(l=n.type);var g="";if("string"==l||"number"==l)g="<input autofocus type='text' class='value'/>";else if("enum"==l&&n.values){g="<select autofocus type='text' class='value'>";for(f in n.values)var r=n.values.constructor===Array?n.values[f]:f,g=g+("<option value='"+r+"' "+(r==a.properties[b]?"selected":"")+">"+n.values[f]+"</option>");g+="</select>"}else"boolean"==l&&(g="<input autofocus type='checkbox' class='value' "+
|
|
|
|
|
(a.properties[b]?"checked":"")+"/>");var p=this.createDialog("<span class='name'>"+b+"</span>"+g+"<button>OK</button>",c);if("enum"==l&&n.values){var x=p.querySelector("select");x.addEventListener("change",function(a){e(a.target.value)})}else if("boolean"==l)(x=p.querySelector("input"))&&x.addEventListener("click",function(a){e(!!x.checked)});else if(x=p.querySelector("input"))x.value=void 0!==a.properties[b]?a.properties[b]:"",x.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),
|
|
|
|
|
a.stopPropagation())});p.querySelector("button").addEventListener("click",d)}};e.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var d=this.canvas.getBoundingClientRect(),e=-20,l=-20;d&&(e-=d.left,l-=d.top);b.position?(e+=b.position[0],l+=b.position[1]):b.event?(e+=b.event.pageX,l+=b.event.pageY):(e+=0.5*this.canvas.width,l+=0.5*this.canvas.height);c.style.left=e+"px";c.style.top=l+"px";this.canvas.parentNode.appendChild(c);
|
|
|
|
|
c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};e.onMenuNodeCollapse=function(a,b,c,d,e){e.flags.collapsed=!e.flags.collapsed;e.setDirtyCanvas(!0,!0)};e.onMenuNodePin=function(a,b,c,d,e){e.pin()};e.onMenuNodeMode=function(a,b,c,e,l){new d.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(l)switch(a){case "On Event":l.mode=d.ON_EVENT;break;case "On Trigger":l.mode=d.ON_TRIGGER;break;case "Never":l.mode=d.NEVER;break;default:l.mode=
|
|
|
|
|
d.ALWAYS}},parentMenu:e,node:l});return!1};e.onMenuNodeColors=function(a,b,c,l,k){if(!k)throw"no node for color";b=[];for(var f in e.node_colors)a=e.node_colors[f],a={value:f,content:"<span style='display: block; color:"+a.color+"; background-color:"+a.bgcolor+"'>"+f+"</span>"},b.push(a);new d.ContextMenu(b,{event:c,callback:function(a){k&&(a=e.node_colors[a.value])&&(k.color=a.color,k.bgcolor=a.bgcolor,k.setDirtyCanvas(!0))},parentMenu:l,node:k});return!1};e.onMenuNodeShapes=function(a,b,c,e,l){if(!l)throw"no node passed";
|
|
|
|
|
new d.ContextMenu(d.VALID_SHAPES,{event:c,callback:function(a){l&&(l.shape=a,l.setDirtyCanvas(!0))},parentMenu:e,node:l});return!1};e.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";!1!=e.removable&&(e.graph.remove(e),e.setDirtyCanvas(!0,!0))};e.onMenuNodeClone=function(a,b,c,d,e){!1!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.add(a),e.setDirtyCanvas(!0,!0))};e.node_colors={red:{color:"#FAA",bgcolor:"#944"},green:{color:"#AFA",bgcolor:"#494"},blue:{color:"#AAF",
|
|
|
|
|
@@ -158,7 +158,7 @@ window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequest
|
|
|
|
|
this.subgraph.onGlobalOutputRenamed=this.onSubgraphRenamedGlobalOutput.bind(this);this.subgraph.onGlobalOutputTypeChanged=this.onSubgraphTypeChangeGlobalOutput.bind(this);this.bgcolor="#663"}function e(){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 d=b.getOutputInfo(0);d.name!=c&&(d.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 t(){var a="output_"+(1E3*Math.random()).toFixed();this.addInput(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 d=b.getInputInfo(0);d.name!=c&&(d.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 u(){this.size=[60,20];this.addInput("value",0,{label:""});this.addOutput("value",0,{label:""});this.addProperty("value",
|
|
|
|
|
"")}function v(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,20]}function d(){this.mode=l.ON_EVENT;this.size=[60,20];this.addProperty("msg","");this.addInput("log",l.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 l=q.LiteGraph;g.title="Time";g.desc="Time";g.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);
|
|
|
|
|
"")}function v(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,20]}function d(){this.mode=l.ON_EVENT;this.size=[60,20];this.addProperty("msg","");this.addInput("log",l.EVENT);this.addInput("msg",0)}function r(){this.size=[60,20];this.addProperty("onExecute","");this.addInput("in","");this.addInput("in2","");this.addOutput("out","");this.addOutput("out2","");this._func=null}var l=q.LiteGraph;g.title="Time";g.desc="Time";g.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);
|
|
|
|
|
this.setOutputData(1,this.graph.globaltime)};l.registerNodeType("basic/time",g);f.title="Subgraph";f.desc="Graph inside a node";f.prototype.onSubgraphNewGlobalInput=function(a,b){this.addInput(a,b)};f.prototype.onSubgraphRenamedGlobalInput=function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).name=b)};f.prototype.onSubgraphTypeChangeGlobalInput=function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).type=b)};f.prototype.onSubgraphNewGlobalOutput=function(a,b){this.addOutput(a,
|
|
|
|
|
b)};f.prototype.onSubgraphRenamedGlobalOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).name=b)};f.prototype.onSubgraphTypeChangeGlobalOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).type=b)};f.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};f.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)};f.prototype.configure=function(a){LGraphNode.prototype.configure.call(this,a)};f.prototype.serialize=function(){var a=LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};f.prototype.clone=function(){var a=l.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;
|
|
|
|
|
@@ -166,8 +166,8 @@ delete b.outputs;a.configure(b);return a};l.registerNodeType("graph/subgraph",f)
|
|
|
|
|
this.properties.type)};t.prototype.onExecute=function(){this.graph.setGlobalOutputData(this.properties.name,this.getInputData(0))};l.registerNodeType("graph/output",t);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)};l.registerNodeType("basic/const",p);u.title="Watch";u.desc="Show value of input";u.prototype.onExecute=function(){this.properties.value=this.getInputData(0);this.setOutputData(0,this.properties.value)};u.prototype.onDrawBackground=function(a){this.inputs[0]&&null!=this.properties.value&&(this.properties.value.constructor===Number?this.inputs[0].label=this.properties.value.toFixed(3):((a=this.properties.value)&&a.length&&(a=
|
|
|
|
|
Array.prototype.slice.call(a).join(",")),this.inputs[0].label=a))};l.registerNodeType("basic/watch",u);v.title="Pass";v.desc="Allows to connect different types";v.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};l.registerNodeType("basic/pass",v);d.title="Console";d.desc="Show value inside the console";d.prototype.onAction=function(a,b){"log"==a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};d.prototype.onExecute=function(){var a=this.getInputData(1);
|
|
|
|
|
null!==a&&(this.properties.msg=a);console.log(a)};d.prototype.onGetInputs=function(){return[["log",l.ACTION],["warn",l.ACTION],["error",l.ACTION]]};l.registerNodeType("basic/console",d);s.title="Script";s.desc="executes a code";s.widgets_info={onExecute:{type:"code"}};s.prototype.onPropertyChanged=function(a,b){if("onExecute"==a&&l.allow_scripts){this._func=null;try{this._func=new Function(b)}catch(c){console.error("Error parsing script"),console.error(c)}}};s.prototype.onExecute=function(){if(this._func)try{this._func.call(this)}catch(a){console.error("Error in script"),
|
|
|
|
|
console.error(a)}};l.registerNodeType("basic/script",s)})(this);
|
|
|
|
|
null!==a&&(this.properties.msg=a);console.log(a)};d.prototype.onGetInputs=function(){return[["log",l.ACTION],["warn",l.ACTION],["error",l.ACTION]]};l.registerNodeType("basic/console",d);r.title="Script";r.desc="executes a code";r.widgets_info={onExecute:{type:"code"}};r.prototype.onPropertyChanged=function(a,b){if("onExecute"==a&&l.allow_scripts){this._func=null;try{this._func=new Function(b)}catch(c){console.error("Error parsing script"),console.error(c)}}};r.prototype.onExecute=function(){if(this._func)try{this._func.call(this)}catch(a){console.error("Error in script"),
|
|
|
|
|
console.error(a)}};l.registerNodeType("basic/script",r)})(this);
|
|
|
|
|
(function(q){function g(){this.size=[60,20];this.addInput("event",t.ACTION)}function f(){this.size=[60,20];this.addInput("event",t.ACTION);this.addOutput("event",t.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function e(){this.size=[60,20];this.addProperty("time",1E3);this.addInput("event",t.ACTION);this.addOutput("on_time",t.EVENT);this._pending=[]}var t=q.LiteGraph;g.title="Log Event";g.desc="Log event in console";g.prototype.onAction=function(e,f){console.log(e,f)};
|
|
|
|
|
t.registerNodeType("events/log",g);f.title="Filter Event";f.desc="Blocks events that do not match the filter";f.prototype.onAction=function(e,f){if(null!=f&&(!this.properties.equal_to||this.properties.equal_to==f)){if(this.properties.has_property){var g=f[this.properties.has_property];if(null==g||this.properties.property_equal_to&&this.properties.property_equal_to!=g)return}this.triggerSlot(0,f)}};t.registerNodeType("events/filter",f);e.title="Delay";e.desc="Delays one event";e.prototype.onAction=
|
|
|
|
|
function(e,f){this._pending.push([this.properties.time,f])};e.prototype.onExecute=function(){for(var e=1E3*this.graph.elapsed_time,f=0;f<this._pending.length;++f){var g=this._pending[f];g[0]-=e;0<g[0]||(this._pending.splice(f,1),--f,this.trigger(null,g[1]))}};e.prototype.onGetInputs=function(){return[["event",t.ACTION]]};t.registerNodeType("events/delay",e)})(this);
|
|
|
|
|
@@ -202,37 +202,37 @@ case 5:f.buttons.rb=e.buttons[g].pressed;break;case 6:f.buttons.lt=e.buttons[g].
|
|
|
|
|
f*g,6,f)};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",f.EVENT]]};f.registerNodeType("input/gamepad",
|
|
|
|
|
g)})(this);
|
|
|
|
|
(function(q){function g(){this.addInput("in","*");this.size=[60,20]}function f(){this.addInput("in");this.addOutput("out");this.size=[60,20]}function e(){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 t(){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 u(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function v(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function d(){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,
|
|
|
|
|
"number");this.addOutput("out","number");this.size=[60,20];this.addProperty("min",0);this.addProperty("max",1)}function u(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function v(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function d(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}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];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 c(){this.addInput("A","number");this.addInput("B","number");
|
|
|
|
|
this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","string",{values:c.values})}function h(){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 k(){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:k.values});
|
|
|
|
|
this.size=[60,40]}function r(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function n(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function A(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function z(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2",
|
|
|
|
|
"vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function B(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function w(){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 y(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w",
|
|
|
|
|
"number")}function D(){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 x=q.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"]]};x.registerNodeType("math/converter",g);f.title="Bypass";f.desc="removes the type";f.prototype.onExecute=function(){var a=this.getInputData(0);
|
|
|
|
|
this.setOutputData(0,a)};x.registerNodeType("math/bypass",f);e.title="Range";e.desc="Convert a number from one range to another";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);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)};e.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};e.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};x.registerNodeType("math/range",e);t.title="Rand";t.desc="Random number";t.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)};t.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};t.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};x.registerNodeType("math/rand",t);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};x.registerNodeType("math/clamp",p);u.title="Lerp";u.desc="Linear Interpolation";u.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};
|
|
|
|
|
u.prototype.onGetInputs=function(){return[["f","number"]]};x.registerNodeType("math/lerp",u);v.title="Abs";v.desc="Absolute";v.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};x.registerNodeType("math/abs",v);d.title="Floor";d.desc="Floor number to remove fractional part";d.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};x.registerNodeType("math/floor",d);s.title="Frac";s.desc="Returns fractional part";
|
|
|
|
|
s.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};x.registerNodeType("math/frac",s);l.title="Smoothstep";l.desc="Smoothstep";l.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))}};x.registerNodeType("math/smoothstep",l);a.title="Scale";a.desc="v * factor";a.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,
|
|
|
|
|
a*this.properties.factor)};x.registerNodeType("math/scale",a);b.title="Average";b.desc="Average Filter";b.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};b.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);var c=this._values;this._values=new Float32Array(this.properties.samples);
|
|
|
|
|
c.length<=this._values.length?this._values.set(c):this._values.set(c.subarray(0,this._values.length))};x.registerNodeType("math/average",b);c.values="+-*/%^".split("");c.title="Operation";c.desc="Easy math operators";c["@OP"]={type:"enum",title:"operation",values:c.values};c.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};c.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.A=a:a=this.properties.A;
|
|
|
|
|
this.size=[60,40]}function s(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function n(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function z(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function y(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2",
|
|
|
|
|
"vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function C(){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 x(){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 w=q.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"]]};w.registerNodeType("math/converter",g);f.title="Bypass";f.desc="removes the type";f.prototype.onExecute=function(){var a=this.getInputData(0);
|
|
|
|
|
this.setOutputData(0,a)};w.registerNodeType("math/bypass",f);e.title="Range";e.desc="Convert a number from one range to another";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);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)};e.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};e.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};w.registerNodeType("math/range",e);t.title="Rand";t.desc="Random number";t.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)};t.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};t.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};w.registerNodeType("math/rand",t);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};w.registerNodeType("math/clamp",p);u.title="Lerp";u.desc="Linear Interpolation";u.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};
|
|
|
|
|
u.prototype.onGetInputs=function(){return[["f","number"]]};w.registerNodeType("math/lerp",u);v.title="Abs";v.desc="Absolute";v.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};w.registerNodeType("math/abs",v);d.title="Floor";d.desc="Floor number to remove fractional part";d.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};w.registerNodeType("math/floor",d);r.title="Frac";r.desc="Returns fractional part";
|
|
|
|
|
r.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};w.registerNodeType("math/frac",r);l.title="Smoothstep";l.desc="Smoothstep";l.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))}};w.registerNodeType("math/smoothstep",l);a.title="Scale";a.desc="v * factor";a.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,
|
|
|
|
|
a*this.properties.factor)};w.registerNodeType("math/scale",a);b.title="Average";b.desc="Average Filter";b.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};b.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);var c=this._values;this._values=new Float32Array(this.properties.samples);
|
|
|
|
|
c.length<=this._values.length?this._values.set(c):this._values.set(c.subarray(0,this._values.length))};w.registerNodeType("math/average",b);c.values="+-*/%^".split("");c.title="Operation";c.desc="Easy math operators";c["@OP"]={type:"enum",title:"operation",values:c.values};c.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};c.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)};c.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]+x.NODE_TITLE_HEIGHT),a.textAlign="left")};x.registerNodeType("math/operation",c);h.title="Compare";h.desc="compares between two values";h.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)}}};h.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};x.registerNodeType("math/compare",h);k.values="> < == != <= >=".split(" ");k["@OP"]={type:"enum",title:"operation",values:k.values};k.title="Condition";k.desc="evaluates condition between A and B";k.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)};x.registerNodeType("math/condition",k);r.title="Accumulate";r.desc="Increments a value every time";r.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)};x.registerNodeType("math/accumulate",r);n.title="Trigonometry";n.desc="Sin Cos Tan";n.filter="shader";n.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,
|
|
|
|
|
this.size[1]+w.NODE_TITLE_HEIGHT),a.textAlign="left")};w.registerNodeType("math/operation",c);h.title="Compare";h.desc="compares between two values";h.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)}}};h.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};w.registerNodeType("math/compare",h);k.values="> < == != <= >=".split(" ");k["@OP"]={type:"enum",title:"operation",values:k.values};k.title="Condition";k.desc="evaluates condition between A and B";k.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)};w.registerNodeType("math/condition",k);s.title="Accumulate";s.desc="Increments a value every time";s.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)};w.registerNodeType("math/accumulate",s);n.title="Trigonometry";n.desc="Sin Cos Tan";n.filter="shader";n.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)}};n.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};n.prototype.onGetOutputs=
|
|
|
|
|
function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};x.registerNodeType("math/trigonometry",n);if(void 0!=typeof math){var C=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};C.title="Formula";C.desc="Compute safe formula";C.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,{x:a,y:b,T:this.graph.globaltime});this.setOutputData(0,a)};C.prototype.onDrawBackground=function(){this.outputs[0].label=this.properties.formula};C.prototype.onGetOutputs=function(){return[["A-B","number"],["A*B","number"],["A/B","number"]]};x.registerNodeType("math/formula",C)}A.title="Vec2->XY";A.desc="vector 2 to components";A.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,
|
|
|
|
|
a[0]),this.setOutputData(1,a[1]))};x.registerNodeType("math3d/vec2-to-xyz",A);z.title="XY->Vec2";z.desc="components to vector2";z.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};x.registerNodeType("math3d/xy-to-vec2",z);B.title="Vec3->XYZ";B.desc="vector 3 to components";B.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,
|
|
|
|
|
a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};x.registerNodeType("math3d/vec3-to-xyz",B);w.title="XYZ->Vec3";w.desc="components to vector3";w.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};x.registerNodeType("math3d/xyz-to-vec3",w);y.title="Vec4->XYZW";y.desc="vector 4 to components";
|
|
|
|
|
y.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};x.registerNodeType("math3d/vec4-to-xyzw",y);D.title="XYZW->Vec4";D.desc="components to vector4";D.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);
|
|
|
|
|
null==d&&(d=this.properties.w);var e=this._data;e[0]=a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};x.registerNodeType("math3d/xyzw-to-vec4",D);q.glMatrix&&(q=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},q.title="Quaternion",q.desc="quaternion",q.prototype.onExecute=function(){this._value[0]=this.properties.x;this._value[1]=this.properties.y;this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},
|
|
|
|
|
x.registerNodeType("math3d/quaternion",q),q=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},q.title="Rotation",q.desc="quaternion rotation",q.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.angle);var b=this.getInputData(1);null==b&&(b=this.properties.axis);a=quat.setAxisAngle(this._value,b,0.0174532925*a);this.setOutputData(0,a)},
|
|
|
|
|
x.registerNodeType("math3d/rotation",q),q=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},q.title="Rot. Vec3",q.desc="rotate a point",q.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))},x.registerNodeType("math3d/rotate_vec3",q),q=function(){this.addInputs([["A","quat"],
|
|
|
|
|
["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},q.title="Mult. Quat",q.desc="rotate quaternion",q.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))}},x.registerNodeType("math3d/mult-quat",q),q=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},q.title=
|
|
|
|
|
"Quat Slerp",q.desc="quaternion spherical interpolation",q.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)}}},x.registerNodeType("math3d/quat-slerp",q))})(this);
|
|
|
|
|
function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};w.registerNodeType("math/trigonometry",n);if(void 0!=typeof math){var D=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};D.title="Formula";D.desc="Compute safe formula";D.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,{x:a,y:b,T:this.graph.globaltime});this.setOutputData(0,a)};D.prototype.onDrawBackground=function(){this.outputs[0].label=this.properties.formula};D.prototype.onGetOutputs=function(){return[["A-B","number"],["A*B","number"],["A/B","number"]]};w.registerNodeType("math/formula",D)}z.title="Vec2->XY";z.desc="vector 2 to components";z.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,
|
|
|
|
|
a[0]),this.setOutputData(1,a[1]))};w.registerNodeType("math3d/vec2-to-xyz",z);y.title="XY->Vec2";y.desc="components to vector2";y.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};w.registerNodeType("math3d/xy-to-vec2",y);C.title="Vec3->XYZ";C.desc="vector 3 to components";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,
|
|
|
|
|
a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};w.registerNodeType("math3d/vec3-to-xyz",C);A.title="XYZ->Vec3";A.desc="components to vector3";A.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};w.registerNodeType("math3d/xyz-to-vec3",A);x.title="Vec4->XYZW";x.desc="vector 4 to components";
|
|
|
|
|
x.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};w.registerNodeType("math3d/vec4-to-xyzw",x);B.title="XYZW->Vec4";B.desc="components to vector4";B.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);
|
|
|
|
|
null==d&&(d=this.properties.w);var e=this._data;e[0]=a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};w.registerNodeType("math3d/xyzw-to-vec4",B);q.glMatrix&&(q=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},q.title="Quaternion",q.desc="quaternion",q.prototype.onExecute=function(){this._value[0]=this.properties.x;this._value[1]=this.properties.y;this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},
|
|
|
|
|
w.registerNodeType("math3d/quaternion",q),q=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},q.title="Rotation",q.desc="quaternion rotation",q.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.angle);var b=this.getInputData(1);null==b&&(b=this.properties.axis);a=quat.setAxisAngle(this._value,b,0.0174532925*a);this.setOutputData(0,a)},
|
|
|
|
|
w.registerNodeType("math3d/rotation",q),q=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},q.title="Rot. Vec3",q.desc="rotate a point",q.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))},w.registerNodeType("math3d/rotate_vec3",q),q=function(){this.addInputs([["A","quat"],
|
|
|
|
|
["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},q.title="Mult. Quat",q.desc="rotate quaternion",q.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))}},w.registerNodeType("math3d/mult-quat",q),q=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},q.title=
|
|
|
|
|
"Quat Slerp",q.desc="quaternion spherical interpolation",q.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)}}},w.registerNodeType("math3d/quat-slerp",q))})(this);
|
|
|
|
|
(function(q){function g(){this.addInput("sel","boolean");this.addOutput("value","number");this.properties={A:0,B:1};this.size=[60,20]}q=q.LiteGraph;g.title="Selector";g.desc="outputs A if selector is true, B if selector is false";g.prototype.onExecute=function(){var f=this.getInputData(0);if(void 0!==f){for(var e=1;e<this.inputs.length;e++){var g=this.inputs[e],p=this.getInputData(e);void 0!==p&&(this.properties[g.name]=p)}e=this.properties.A;g=this.properties.B;this.setOutputData(0,f?e:g)}};g.prototype.onGetInputs=
|
|
|
|
|
function(){return[["A",0],["B",0]]};q.registerNodeType("logic/selector",g)})(this);
|
|
|
|
|
(function(q){function g(){this.inputs=[];this.addOutput("frame","image");this.properties={url:""}}function f(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function e(){this.addInput("","image");this.size=[200,200]}function t(){this.addInputs([["img1","image"],["img2","image"],["fade","number"]]);this.addOutput("","image");this.properties={fade:0.5,width:512,height:512}}function p(){this.addInput("",
|
|
|
|
|
@@ -287,10 +287,10 @@ d.gamma_pixel_shader)),a.toViewport(d._gamma_shader,{u_texture:0,u_igamma:1/b}))
|
|
|
|
|
d.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",d);q=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,
|
|
|
|
|
precision:f.DEFAULT}};q.title="Copy";q.desc="Copy Texture";q.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:f.MODE_VALUES}};q.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,e=a.type;this.properties.precision===f.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===f.HIGH&&
|
|
|
|
|
(e=gl.HIGH_PRECISION_FORMAT);d&&d.width==b&&d.height==c&&d.type==e||(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:e,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",
|
|
|
|
|
q);var s=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:f.DEFAULT}};s.title="Downsample";s.desc="Downsample Texture";s.widgets_info={iterations:{type:"number",step:1,precision:0,min:1},precision:{widget:"combo",values:f.MODE_VALUES}};s.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=s._shader;b||(s._shader=
|
|
|
|
|
b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,s.pixel_shader));var c=a.width|0,d=a.height|0,e=a.type;this.properties.precision===f.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===f.HIGH&&(e=gl.HIGH_PRECISION_FORMAT);var n=this.properties.iterations||1,l=a,h=null,g=[],a={type:e,format:a.format},e=vec2.create(),k={u_offset:e};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var u=0;u<n;++u){e[0]=1/c;e[1]=1/d;c=c>>1||0;d=d>>1||0;h=GL.Texture.getTemporary(c,d,a);g.push(h);l.setParameter(GL.TEXTURE_MAG_FILTER,
|
|
|
|
|
GL.NEAREST);l.copyTo(h,b,k);if(1==c&&1==d)break;l=h}this._texture=g.pop();for(u=0;u<g.length;++u)GL.Texture.releaseTemporary(g[u]);this.properties.generate_mipmaps&&(this._texture.bind(0),gl.generateMipmap(this._texture.texture_type),this._texture.unbind(0));this.setOutputData(0,this._texture)}};s.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",s);var l=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={mipmap_offset:0,low_precision:!1};this._uniforms={u_texture:0,u_mipmap_offset:this.properties.mipmap_offset}};l.title="Average";l.desc="Compute a partial average (32 random samples) of a texture and stores it as a 1x1 pixel texture";l.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){if(!l._shader){l._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,
|
|
|
|
|
q);var r=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:f.DEFAULT}};r.title="Downsample";r.desc="Downsample Texture";r.widgets_info={iterations:{type:"number",step:1,precision:0,min:1},precision:{widget:"combo",values:f.MODE_VALUES}};r.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=r._shader;b||(r._shader=
|
|
|
|
|
b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,r.pixel_shader));var c=a.width|0,d=a.height|0,e=a.type;this.properties.precision===f.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===f.HIGH&&(e=gl.HIGH_PRECISION_FORMAT);var n=this.properties.iterations||1,l=a,h=null,g=[],a={type:e,format:a.format},e=vec2.create(),k={u_offset:e};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var p=0;p<n;++p){e[0]=1/c;e[1]=1/d;c=c>>1||0;d=d>>1||0;h=GL.Texture.getTemporary(c,d,a);g.push(h);l.setParameter(GL.TEXTURE_MAG_FILTER,
|
|
|
|
|
GL.NEAREST);l.copyTo(h,b,k);if(1==c&&1==d)break;l=h}this._texture=g.pop();for(p=0;p<g.length;++p)GL.Texture.releaseTemporary(g[p]);this.properties.generate_mipmaps&&(this._texture.bind(0),gl.generateMipmap(this._texture.texture_type),this._texture.unbind(0));this.setOutputData(0,this._texture)}};r.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",r);var l=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={mipmap_offset:0,low_precision:!1};this._uniforms={u_texture:0,u_mipmap_offset:this.properties.mipmap_offset}};l.title="Average";l.desc="Compute a partial average (32 random samples) of a texture and stores it as a 1x1 pixel texture";l.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){if(!l._shader){l._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,
|
|
|
|
|
l.pixel_shader);for(var b=new Float32Array(32),c=0;32>c;++c)b[c]=Math.random();l._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}b=this._temp_texture;c=this.properties.low_precision?gl.UNSIGNED_BYTE:a.type;b&&b.type==c||(this._temp_texture=new GL.Texture(1,1,{type:c,format:gl.RGBA,filter:gl.NEAREST}));var d=l._shader,e=this._uniforms;e.u_mipmap_offset=this.properties.mipmap_offset;this._temp_texture.drawTo(function(){a.toViewport(d,e)});this.setOutputData(0,this._temp_texture)}};
|
|
|
|
|
l.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",l);q=function(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}};q.title="Image to Texture";q.desc="Uploads an image to the GPU";q.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");
|
|
|
|
|
@@ -307,48 +307,51 @@ values:[32,64,128,256,512]};h.prototype.onExecute=function(){gl.disable(gl.BLEND
|
|
|
|
|
c);vec3.copy(l.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(l).draw(a)});this.setOutputData(0,this._tex)};h.prototype.onGetInputs=function(){return[["angle","number"],["scale","number"]]};h.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform float u_angle;\n\t\t\tuniform float u_scale;\n\t\t\tuniform vec3 u_colorA;\n\t\t\tuniform vec3 u_colorB;\n\t\t\t\n\t\t\tvec2 rotate(vec2 v, float angle)\n\t\t\t{\n\t\t\t\tvec2 result;\n\t\t\t\tfloat _cos = cos(angle);\n\t\t\t\tfloat _sin = sin(angle);\n\t\t\t\tresult.x = v.x * _cos - v.y * _sin;\n\t\t\t\tresult.y = v.x * _sin + v.y * _cos;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tvoid main() {\n\t\t\t\tfloat f = (rotate(u_scale * (v_coord - vec2(0.5)), u_angle) + vec2(0.5)).x;\n\t\t\t\tvec3 color = mix(u_colorA,u_colorB,clamp(f,0.0,1.0));\n\t\t\t gl_FragColor = vec4(color,1.0);\n\t\t\t}\n\t\t\t";
|
|
|
|
|
g.registerNodeType("texture/gradient",h);var k=function(){this.addInput("A","Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={precision:f.DEFAULT};k._shader||(k._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k.pixel_shader))};k.title="Mix";k.desc="Generates a texture mixing two textures";k.widgets_info={precision:{widget:"combo",values:f.MODE_VALUES}};k.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===
|
|
|
|
|
f.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1),c=this.getInputData(2);if(a&&b&&c){this._tex=f.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),e=k._shader;this._tex.drawTo(function(){a.bind(0);b.bind(1);c.bind(2);e.uniforms({u_textureA:0,u_textureB:1,u_textureMix:2}).draw(d)});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_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",k);var r=function(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,factor:1,precision:f.DEFAULT};r._shader||(r._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,r.pixel_shader))};r.title="Edges";r.desc="Detects edges";r.widgets_info={precision:{widget:"combo",values:f.MODE_VALUES}};r.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===f.PASS_THROUGH)this.setOutputData(0,
|
|
|
|
|
a);else if(a){this._tex=f.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),c=r._shader,d=this.properties.invert,e=this.properties.factor;this._tex.drawTo(function(){a.bind(0);c.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:e,u_invert:d?1:0}).draw(b)});this.setOutputData(0,this._tex)}}};r.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_isize;\n\t\t\tuniform int u_invert;\n\t\t\tuniform float u_factor;\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 gl_FragColor = vec4( diff.xyz, center.a );\n\t\t\t}\n\t\t\t";
|
|
|
|
|
g.registerNodeType("texture/edges",r);var n=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}};n.title="Depth Range";n.desc="Generates a texture with a depth range";n.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);
|
|
|
|
|
g.registerNodeType("texture/mix",k);var s=function(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,factor:1,precision:f.DEFAULT};s._shader||(s._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.pixel_shader))};s.title="Edges";s.desc="Detects edges";s.widgets_info={precision:{widget:"combo",values:f.MODE_VALUES}};s.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===f.PASS_THROUGH)this.setOutputData(0,
|
|
|
|
|
a);else if(a){this._tex=f.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),c=s._shader,d=this.properties.invert,e=this.properties.factor;this._tex.drawTo(function(){a.bind(0);c.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:e,u_invert:d?1:0}).draw(b)});this.setOutputData(0,this._tex)}}};s.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_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\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 gl_FragColor = vec4( diff.xyz, center.a );\n\t\t\t}\n\t\t\t";
|
|
|
|
|
g.registerNodeType("texture/edges",s);var n=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}};n.title="Depth Range";n.desc="Generates a texture with a depth range";n.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)&&
|
|
|
|
|
(d=this.getInputData(2),this.properties.range=d);c.u_distance=b;c.u_range=d;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad();n._shader||(n._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n.pixel_shader),n._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n.pixel_shader,{ONLY_DEPTH:""}));var f=this.properties.only_depth?n._shader_onlydepth:n._shader,b=null,b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:
|
|
|
|
|
[0.1,1E3];c.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);f.uniforms(c).draw(e)});this.setOutputData(0,this._temp_texture)}}};n.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_distance;\n\t\t\tuniform float u_range;\n\t\t\t\n\t\t\tfloat LinearDepth()\n\t\t\t{\n\t\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat depth = LinearDepth();\n\t\t\t\t#ifdef ONLY_DEPTH\n\t\t\t\t gl_FragColor = vec4(depth);\n\t\t\t\t#else\n\t\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\t\tfloat dof = 1.0;\n\t\t\t\t\tif(diff <= u_range)\n\t\t\t\t\t\tdof = diff / u_range;\n\t\t\t\t gl_FragColor = vec4(dof);\n\t\t\t\t#endif\n\t\t\t}\n\t\t\t";
|
|
|
|
|
g.registerNodeType("texture/depth_range",n);var A=function(){this.addInput("Texture","Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1]}};A.title="Blur";A.desc="Blur a texture";A.max_iterations=20;A.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}),this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));b=this.properties.iterations;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.iterations=b);b=Math.min(Math.floor(b),A.max_iterations);if(0==b)this.setOutputData(0,a);else{var c=this.properties.intensity;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.intensity=
|
|
|
|
|
c);var d=g.camera_aspect;d||void 0===window.gl||(d=gl.canvas.height/gl.canvas.width);d||(d=1);for(var d=this.properties.preserve_aspect?d:1,e=this.properties.scale||[1,1],f=0;f<b;++f)a.applyBlur(d*e[0]*f,e[1]*f,c,this._temp_texture,this._final_texture),a=this._final_texture;this.setOutputData(0,this._final_texture)}}};A.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_offset;\n\t\t\tuniform float u_intensity;\n\t\t\tvoid main() {\n\t\t\t vec4 sum = vec4(0.0);\n\t\t\t vec4 center = texture2D(u_texture, v_coord);\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -4.0) * 0.05/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -3.0) * 0.09/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -2.0) * 0.12/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -1.0) * 0.15/0.98;\n\t\t\t sum += center * 0.16/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 4.0) * 0.05/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 3.0) * 0.09/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 2.0) * 0.12/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 1.0) * 0.15/0.98;\n\t\t\t gl_FragColor = u_intensity * sum;\n\t\t\t /*gl_FragColor.a = center.a*/;\n\t\t\t}\n\t\t\t";
|
|
|
|
|
g.registerNodeType("texture/blur",A);var z=function(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}};z.title="Kuwahara Filter";z.desc="Filters a texture giving an artistic oil canvas painting";z.max_radius=10;z._shaders=[];z.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),z.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;z._shaders[b]||(z._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,z.pixel_shader,{RADIUS:b.toFixed(0)}));var e=z._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)}}};z.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",z);q=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:""}};q.title="Webcam";q.desc="Webcam texture";q.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.1,1E3];c.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);f.uniforms(c).draw(e)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}};n.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_distance;\n\t\t\tuniform float u_range;\n\t\t\t\n\t\t\tfloat LinearDepth()\n\t\t\t{\n\t\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat depth = LinearDepth();\n\t\t\t\t#ifdef ONLY_DEPTH\n\t\t\t\t gl_FragColor = vec4(depth);\n\t\t\t\t#else\n\t\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\t\tfloat dof = 1.0;\n\t\t\t\t\tif(diff <= u_range)\n\t\t\t\t\t\tdof = diff / u_range;\n\t\t\t\t gl_FragColor = vec4(dof);\n\t\t\t\t#endif\n\t\t\t}\n\t\t\t";
|
|
|
|
|
g.registerNodeType("texture/depth_range",n);var z=function(){this.addInput("Texture","Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1]}};z.title="Blur";z.desc="Blur a texture";z.max_iterations=20;z.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}),this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));b=this.properties.iterations;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.iterations=b);b=Math.min(Math.floor(b),z.max_iterations);if(0==b)this.setOutputData(0,a);else{var c=this.properties.intensity;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.intensity=
|
|
|
|
|
c);var d=g.camera_aspect;d||void 0===window.gl||(d=gl.canvas.height/gl.canvas.width);d||(d=1);for(var d=this.properties.preserve_aspect?d:1,e=this.properties.scale||[1,1],f=0;f<b;++f)a.applyBlur(d*e[0]*f,e[1]*f,c,this._temp_texture,this._final_texture),a=this._final_texture;this.setOutputData(0,this._final_texture)}}};z.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_offset;\n\t\t\tuniform float u_intensity;\n\t\t\tvoid main() {\n\t\t\t vec4 sum = vec4(0.0);\n\t\t\t vec4 center = texture2D(u_texture, v_coord);\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -4.0) * 0.05/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -3.0) * 0.09/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -2.0) * 0.12/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -1.0) * 0.15/0.98;\n\t\t\t sum += center * 0.16/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 4.0) * 0.05/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 3.0) * 0.09/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 2.0) * 0.12/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 1.0) * 0.15/0.98;\n\t\t\t gl_FragColor = u_intensity * sum;\n\t\t\t /*gl_FragColor.a = center.a*/;\n\t\t\t}\n\t\t\t";
|
|
|
|
|
g.registerNodeType("texture/blur",z);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);q=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:""}};q.title="Webcam";q.desc="Webcam texture";q.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)}};q.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)})};q.prototype.onRemoved=function(){this._webcam_stream&&(this._webcam_stream.stop(),this._video=this._webcam_stream=null)};q.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())};q.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&&(f.getTexturesContainer()[this.properties.texture_name]=this._temp_texture);this.setOutputData(0,this._temp_texture)}};g.registerNodeType("texture/webcam",q);var B=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:f.DEFAULT};B._shader||(B._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,
|
|
|
|
|
B.pixel_shader))};B.title="Matte";B.desc="Extracts background";B.widgets_info={key_color:{widget:"color"},precision:{widget:"combo",values:f.MODE_VALUES}};B.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===f.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=f.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=B._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)}}};B.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",B);q=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[f.image_preview_size,f.image_preview_size]};q.title="Cubemap";q.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="")};q.prototype.onExecute=function(){if(this._drop_texture)this.setOutputData(0,this._drop_texture);else if(this.properties.name){var a=
|
|
|
|
|
b,{format:gl.RGB,filter:gl.LINEAR}));this._temp_texture.uploadImage(this._video);this.properties.texture_name&&(f.getTexturesContainer()[this.properties.texture_name]=this._temp_texture);this.setOutputData(0,this._temp_texture)}};g.registerNodeType("texture/webcam",q);var C=function(){this.addInput("in","Texture");this.addInput("exp","number");this.addOutput("out","Texture");this.properties={exposition:1,precision:f.LOW}};C.title="Exposition";C.desc="Controls texture exposition";C.widgets_info={exposition:{widget:"slider",
|
|
|
|
|
min:0,max:3},precision:{widget:"combo",values:f.MODE_VALUES}};C.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var c=C._shader;c||(c=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,C.pixel_shader));var d=this.properties.exposition,e=this.getInputData(1);null!=e&&(d=this.properties.exposition=
|
|
|
|
|
e);b.drawTo(function(){gl.disable(gl.DEPTH_TEST);a.bind(0);var b=GL.Mesh.getScreenQuad();c.uniforms({u_texture:0,u_exposition:d}).draw(b)});this.setOutputData(0,b)}};C.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_exposition;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord );\n\t\t\t\tgl_FragColor = vec4( color.xyz * u_exposition, color.a );\n\t\t\t}";g.registerNodeType("texture/exposition",
|
|
|
|
|
C);var A=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:f.DEFAULT};A._shader||(A._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,A.pixel_shader))};A.title="Matte";A.desc="Extracts background";A.widgets_info={key_color:{widget:"color"},precision:{widget:"combo",values:f.MODE_VALUES}};A.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===
|
|
|
|
|
f.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=f.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=A._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)}}};A.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",A);q=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[f.image_preview_size,f.image_preview_size]};q.title="Cubemap";q.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="")};q.prototype.onExecute=function(){if(this._drop_texture)this.setOutputData(0,this._drop_texture);else if(this.properties.name){var a=
|
|
|
|
|
f.getTexture(this.properties.name);a&&(this._last_tex=a,this.setOutputData(0,a))}};q.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",q)}})(this);
|
|
|
|
|
(function(q){var g=q.LiteGraph;if("undefined"!=typeof GL){var f=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};f._shader||(f._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader),f._texture=new GL.Texture(3,1,{format:gl.RGB,wrap:gl.CLAMP_TO_EDGE,magFilter:gl.LINEAR,
|
|
|
|
|
(function(q){var g=q.LiteGraph;if("undefined"!=typeof GL){var f=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};f._shader||(f._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,f.pixel_shader),f._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]}))};f.title="Lens";f.desc="Camera Lens distortion";f.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};f.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.aberration;this.isInputConnected(1)&&(g=this.getInputData(1),
|
|
|
|
|
this.properties.aberration=g);var d=this.properties.distortion;this.isInputConnected(2)&&(d=this.getInputData(2),this.properties.distortion=d);var p=this.properties.blur;this.isInputConnected(3)&&(p=this.getInputData(3),this.properties.blur=p);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var l=Mesh.getScreenQuad(),a=f._shader;this._tex.drawTo(function(){e.bind(0);a.uniforms({u_texture:0,u_aberration:g,u_distortion:d,u_blur:p}).draw(l)});this.setOutputData(0,this._tex)}};f.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform 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",f);window.LGraphFXLens=f;var e=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}};e.title="Bokeh";e.desc="applies an Bokeh effect";e.widgets_info={shape:{widget:"texture"}};e.prototype.onExecute=function(){var f=this.getInputData(0),g=this.getInputData(1),d=this.getInputData(2);
|
|
|
|
|
g.registerNodeType("fx/lens",f);q.LGraphFXLens=f;var e=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}};e.title="Bokeh";e.desc="applies an Bokeh effect";e.widgets_info={shape:{widget:"texture"}};e.prototype.onExecute=function(){var f=this.getInputData(0),g=this.getInputData(1),d=this.getInputData(2);
|
|
|
|
|
if(f&&d&&this.properties.shape){g||(g=f);var p=LGraphTexture.getTexture(this.properties.shape);if(p){var l=this.properties.threshold;this.isInputConnected(3)&&(l=this.getInputData(3),this.properties.threshold=l);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==f.width&&this._temp_texture.height==f.height||(this._temp_texture=new GL.Texture(f.width,f.height,{type:a,format:gl.RGBA,
|
|
|
|
|
filter:gl.LINEAR}));var b=e._first_shader;b||(b=e._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,e._first_pixel_shader));var c=e._second_shader;c||(c=e._second_shader=new GL.Shader(e._second_vertex_shader,e._second_pixel_shader));var h=this._points_mesh;h&&h._width==f.width&&h._height==f.height&&2==h._spacing||(h=this.createPointsMesh(f.width,f.height,2));var k=Mesh.getScreenQuad(),t=this.properties.size,n=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){f.bind(0);
|
|
|
|
|
g.bind(1);d.bind(2);b.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[f.width,f.height]}).draw(k)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);f.bind(0);p.bind(3);c.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:n,u_threshold:l,u_pointSize:t,u_itexsize:[1/f.width,1/f.height]}).draw(h,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,f)};e.prototype.createPointsMesh=function(e,f,d){for(var g=Math.round(e/d),l=Math.round(f/
|
|
|
|
|
d),a=new Float32Array(g*l*2),b=-1,c=2/e*d,h=2/f*d,k=0;k<l;++k){for(var p=-1,n=0;n<g;++n){var A=k*g*2+2*n;a[A]=p;a[A+1]=b;p+=c}b+=h}this._points_mesh=GL.Mesh.load({vertices2D:a});this._points_mesh._width=e;this._points_mesh._height=f;this._points_mesh._spacing=d;return this._points_mesh};e._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";
|
|
|
|
|
d),a=new Float32Array(g*l*2),b=-1,c=2/e*d,h=2/f*d,k=0;k<l;++k){for(var p=-1,n=0;n<g;++n){var z=k*g*2+2*n;a[z]=p;a[z+1]=b;p+=c}b+=h}this._points_mesh=GL.Mesh.load({vertices2D:a});this._points_mesh._width=e;this._points_mesh._height=f;this._points_mesh._spacing=d;return this._points_mesh};e._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";
|
|
|
|
|
e._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";
|
|
|
|
|
e._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",e);window.LGraphFXBokeh=e;var t=function(){this.addInput("Texture","Texture");this.addInput("value1","number");this.addInput("value2","number");this.addOutput("Texture",
|
|
|
|
|
e._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",e);q.LGraphFXBokeh=e;var t=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}};t.title="FX";t.desc="applies an FX from a list";t.widgets_info={fx:{widget:"combo",values:["halftone","pixelate","lowpalette","noise","gamma"]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};t.shaders={};t.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 f=this.properties.value1;this.isInputConnected(1)&&(f=this.getInputData(1),this.properties.value1=f);var d=this.properties.value2;this.isInputConnected(2)&&(d=this.getInputData(2),this.properties.value2=d);var g=this.properties.fx,l=t.shaders[g];if(!l){var a=t["pixel_shader_"+g];if(!a)return;l=t.shaders[g]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a)}gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad();
|
|
|
|
|
camera_planes=window.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var c=null;"noise"==g&&(c=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){e.bind(0);"noise"==g&&c.bind(1);l.uniforms({u_texture:0,u_noise:1,u_size:[e.width,e.height],u_rand:[Math.random(),Math.random()],u_value1:f,u_value2:d,u_camera_planes:camera_planes}).draw(b)});this.setOutputData(0,this._tex)}}};t.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";
|
|
|
|
|
camera_planes=q.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var c=null;"noise"==g&&(c=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){e.bind(0);"noise"==g&&c.bind(1);l.uniforms({u_texture:0,u_noise:1,u_size:[e.width,e.height],u_rand:[Math.random(),Math.random()],u_value1:f,u_value2:d,u_camera_planes:camera_planes}).draw(b)});this.setOutputData(0,this._tex)}}};t.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";
|
|
|
|
|
t.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";t.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";
|
|
|
|
|
t.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";
|
|
|
|
|
t.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",t);window.LGraphFXGeneric=t;var p=function(){this.addInput("Tex.","Texture");this.addInput("intensity","number");this.addOutput("Texture",
|
|
|
|
|
t.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",t);q.LGraphFXGeneric=t;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 f=this.properties.intensity;this.isInputConnected(1)&&(f=this.getInputData(1),this.properties.intensity=f);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),g=p._shader,l=this.properties.invert;this._tex.drawTo(function(){e.bind(0);g.uniforms({u_texture:0,u_intensity:f,u_isize:[1/e.width,1/e.height],u_invert:l?1:0}).draw(d)});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);q.LGraphFXVigneting=p}})(this);
|
|
|
|
|
(function(q){function g(d){this.cmd=this.channel=0;d?this.setup(d):this.data=[0,0,0]}function f(d,a){navigator.requestMIDIAccess?(this.on_ready=d,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 e(){this.addOutput("on_midi",s.EVENT);this.addOutput("out","midi");this.properties={port:0};this._current_midi_event=
|
|
|
|
|
this._last_midi_event=null;var d=this;new f(function(a){d._midi=a;if(d._waiting)d.onStart();d._waiting=!1})}function t(){this.addInput("send",s.EVENT);this.properties={port:0};var d=this;new f(function(a){d._midi=a})}function p(){this.addInput("on_midi",s.EVENT);this._str="";this.size=[200,40]}function u(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};this.addInput("in",s.EVENT);this.addOutput("on_midi",s.EVENT)}function v(){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 d(){this.properties={cc:1,value:0};this.addOutput("value","number")}var s=q.LiteGraph;g.prototype.setup=function(d){this.data=d;this.status=d=d[0];var a=d&240;this.cmd=240<=d?d: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=d&15};Object.defineProperty(g.prototype,"velocity",{get:function(){return this.cmd==g.NOTEON?this.data[2]:
|
|
|
|
|
(function(q){function g(d){this.cmd=this.channel=0;d?this.setup(d):this.data=[0,0,0]}function f(d,a){navigator.requestMIDIAccess?(this.on_ready=d,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 e(){this.addOutput("on_midi",r.EVENT);this.addOutput("out","midi");this.properties={port:0};this._current_midi_event=
|
|
|
|
|
this._last_midi_event=null;var d=this;new f(function(a){d._midi=a;if(d._waiting)d.onStart();d._waiting=!1})}function t(){this.addInput("send",r.EVENT);this.properties={port:0};var d=this;new f(function(a){d._midi=a})}function p(){this.addInput("on_midi",r.EVENT);this._str="";this.size=[200,40]}function u(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};this.addInput("in",r.EVENT);this.addOutput("on_midi",r.EVENT)}function v(){this.properties={channel:0,cmd:"CC",value1:1,value2:1};this.addInput("send",
|
|
|
|
|
r.EVENT);this.addInput("assign",r.EVENT);this.addOutput("on_midi",r.EVENT)}function d(){this.properties={cc:1,value:0};this.addOutput("value","number")}var r=q.LiteGraph;g.prototype.setup=function(d){this.data=d;this.status=d=d[0];var a=d&240;this.cmd=240<=d?d: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=d&15};Object.defineProperty(g.prototype,"velocity",{get:function(){return this.cmd==g.NOTEON?this.data[2]:
|
|
|
|
|
-1},set:function(d){this.data[2]=d},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(d){return 440*Math.pow(2,(d-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(d,a){return d+(a<<7)-8192};g.prototype.setCommandFromString=
|
|
|
|
|
function(d){this.cmd=g.computeCommandFromString(d)};g.computeCommandFromString=function(d){if(!d)return 0;if(d&&d.constructor===Number)return d;d=d.toUpperCase();switch(d){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;
|
|
|
|
|
case "PITCH BEND":case "PITCHBEND":return g.PITCHBEND;case "TIME TICK":case "TIMETICK":return g.TIMETICK;default:return Number(d)}};g.toNoteString=function(d){var a;a=(d-21)%12;0>a&&(a=12+a);return g.notes[a]+Math.floor((d-24)/12+1)};g.prototype.toString=function(){var d=""+this.channel+". ";switch(this.cmd){case g.NOTEON:d+="NOTEON "+g.toNoteString(this.data[1]);break;case g.NOTEOFF:d+="NOTEOFF "+g.toNoteString(this.data[1]);break;case g.CONTROLLERCHANGE:d+="CC "+this.data[1]+" "+this.data[2];break;
|
|
|
|
|
@@ -358,48 +361,48 @@ case g.PROGRAMCHANGE:d+="PC "+this.data[1];break;case g.PITCHBEND:d+="PITCHBEND
|
|
|
|
|
function(d){console.error("Failed to get MIDI access - "+d)};f.prototype.openInputPort=function(d,a){var b=this.input_ports.get("input-"+d);if(!b)return!1;f.input=this;var c=this;b.onmidimessage=function(b){var d=new g(b.data);c.updateState(d);a&&a(b.data,d);if(f.on_message)f.on_message(b.data,d)};console.log("port open: ",b);return!0};f.parseMsg=function(d){};f.prototype.updateState=function(d){switch(d.cmd){case g.NOTEON:this.state.note[d.value1|0]=d.value2;break;case g.NOTEOFF:this.state.note[d.value1|
|
|
|
|
|
0]=0;break;case g.CONTROLLERCHANGE:this.state.cc[d.getCC()]=d.getCCValue()}};f.prototype.sendMIDI=function(d,a){if(a){var b=this.output_ports.get("output-"+d);b&&(f.output=this,a.constructor===g?b.send(a.data):b.send(a))}};e.MIDIInterface=f;e.title="MIDI Input";e.desc="Reads MIDI from a input port";e.prototype.getPropertyInfo=function(d){if(this._midi&&"port"==d){d={};for(var a=0;a<this._midi.input_ports.size;++a){var b=this._midi.input_ports.get("input-"+a);d[a]=a+".- "+b.name+" version:"+b.version}return{type:"enum",
|
|
|
|
|
values:d}}};e.prototype.onStart=function(){this._midi?this._midi.openInputPort(this.properties.port,this.onMIDIEvent.bind(this)):this._waiting=!0};e.prototype.onMIDIEvent=function(d,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)};e.prototype.onExecute=function(){if(this.outputs)for(var d=
|
|
|
|
|
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=d;break;default:continue}this.setOutputData(a,b)}};e.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",e);t.MIDIInterface=f;t.title="MIDI Output";t.desc="Sends MIDI to output channel";t.prototype.getPropertyInfo=
|
|
|
|
|
function(d){if(this._midi&&"port"==d){d={};for(var a=0;a<this._midi.output_ports.size;++a){var b=this._midi.output_ports.get(a);d[a]=a+".- "+b.name+" version:"+b.version}return{type:"enum",values:d}}};t.prototype.onAction=function(d,a){console.log(a);this._midi&&("send"==d&&this._midi.sendMIDI(this.port,a),this.trigger("midi",a))};t.prototype.onGetInputs=function(){return[["send",s.ACTION]]};t.prototype.onGetOutputs=function(){return[["on_midi",s.EVENT]]};s.registerNodeType("midi/output",t);p.title=
|
|
|
|
|
"MIDI Show";p.desc="Shows MIDI in the graph";p.prototype.onAction=function(d,a){a&&(this._str=a.constructor===g?a.toString():"???")};p.prototype.onDrawForeground=function(d){this._str&&(d.font="30px Arial",d.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);u.title="MIDI Filter";u.desc="Filters MIDI messages";u.prototype.onAction=function(d,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",u);v.title="MIDIEvent";v.desc="Create a MIDI Event";v.prototype.onAction=function(d,a){"assign"==d?(this.properties.channel=a.channel,this.properties.cmd=a.cmd,this.properties.value1=
|
|
|
|
|
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=d;break;default:continue}this.setOutputData(a,b)}};e.prototype.onGetOutputs=function(){return[["last_midi","midi"],["on_midi",r.EVENT],["on_noteon",r.EVENT],["on_noteoff",r.EVENT],["on_cc",r.EVENT],["on_pc",r.EVENT],["on_pitchbend",r.EVENT]]};r.registerNodeType("midi/input",e);t.MIDIInterface=f;t.title="MIDI Output";t.desc="Sends MIDI to output channel";t.prototype.getPropertyInfo=
|
|
|
|
|
function(d){if(this._midi&&"port"==d){d={};for(var a=0;a<this._midi.output_ports.size;++a){var b=this._midi.output_ports.get(a);d[a]=a+".- "+b.name+" version:"+b.version}return{type:"enum",values:d}}};t.prototype.onAction=function(d,a){console.log(a);this._midi&&("send"==d&&this._midi.sendMIDI(this.port,a),this.trigger("midi",a))};t.prototype.onGetInputs=function(){return[["send",r.ACTION]]};t.prototype.onGetOutputs=function(){return[["on_midi",r.EVENT]]};r.registerNodeType("midi/output",t);p.title=
|
|
|
|
|
"MIDI Show";p.desc="Shows MIDI in the graph";p.prototype.onAction=function(d,a){a&&(this._str=a.constructor===g?a.toString():"???")};p.prototype.onDrawForeground=function(d){this._str&&(d.font="30px Arial",d.fillText(this._str,10,0.8*this.size[1]))};p.prototype.onGetInputs=function(){return[["in",r.ACTION]]};p.prototype.onGetOutputs=function(){return[["on_midi",r.EVENT]]};r.registerNodeType("midi/show",p);u.title="MIDI Filter";u.desc="Filters MIDI messages";u.prototype.onAction=function(d,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)};r.registerNodeType("midi/filter",u);v.title="MIDIEvent";v.desc="Create a MIDI Event";v.prototype.onAction=function(d,a){"assign"==d?(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))};v.prototype.onExecute=function(){var d=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([d.cmd,d.value1,d.value2]);b.channel=d.channel;break;case "command":b=d.cmd;break;case "cc":b=d.value1;break;case "cc_value":b=d.value2;break;case "note":b=d.cmd==g.NOTEON||d.cmd==g.NOTEOFF?d.value1:null;break;case "velocity":b=d.cmd==g.NOTEON?d.value2:null;break;case "pitch":b=d.cmd==g.NOTEON?g.computePitch(d.value1):null;break;case "pitchbend":b=d.cmd==g.PITCHBEND?g.computePitchBend(d.value1,d.value2):null;break;default:continue}null!==b&&this.setOutputData(a,b)}};v.prototype.onPropertyChanged=
|
|
|
|
|
function(d,a){"cmd"==d&&(this.properties.cmd=g.computeCommandFromString(a))};v.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",v);d.title="MIDICC";d.desc="gets a Controller Change";d.prototype.onExecute=function(){f.input&&(this.properties.value=f.input.state.cc[this.properties.cc]);this.setOutputData(0,
|
|
|
|
|
this.properties.value)};s.registerNodeType("midi/cc",d)})(this);
|
|
|
|
|
(function(q){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=r.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function f(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,
|
|
|
|
|
smoothingTimeConstant:0.5};this.audionode=r.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 e(){this.properties={gain:1};
|
|
|
|
|
this.audionode=r.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function t(){this.properties={impulse_src:"",normalize:!0};this.audionode=r.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=r.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out",
|
|
|
|
|
"audio")}function u(){this.properties={};this.audionode=r.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function v(){this.properties={gain1:0.5,gain2:0.5};this.audionode=r.getAudioContext().createGain();this.audionode1=r.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=r.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 d(){this.properties={delayTime:0.5};this.audionode=r.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=r.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function l(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=r.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 c(){if(!c.default_code){var a=c.default_function.toString(),b=a.indexOf("{")+1,d=a.lastIndexOf("}");c.default_code=a.substr(b,d-b)}this.properties={code:c.default_code};a=r.getAudioContext();a.createScriptProcessor?this.audionode=a.createScriptProcessor(4096,1,1):
|
|
|
|
|
(console.warn("ScriptProcessorNode deprecated"),this.audionode=a.createGain());this.processCode();c._bypass_function||(c._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function h(){this.audionode=r.getAudioContext().destination;this.addInput("in","audio")}var k=q.LiteGraph,r={};q.LGAudio=r;r.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};r.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};r.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};r.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?r.connect(f,d):r.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?r.connect(f,d):r.disconnect(f,d)}};r.onConnectionsChange=function(a,b,c,d){if(a==k.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?r.connect(e,b):r.disconnect(e,b)}};r.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=r.onConnectionsChange};r.cached_audios={};r.loadSound=function(a,b,c){function d(a){console.log("Audio loading sample error:",a);c&&c(a)}if(r.cached_audios[a]&&-1==a.indexOf("blob:"))b&&b(r.cached_audios[a]);else{r.onProcessAudioURL&&
|
|
|
|
|
(a=r.onProcessAudioURL(a));var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";var f=r.getAudioContext();e.onload=function(){console.log("AudioSource loaded");f.decodeAudioData(e.response,function(c){console.log("AudioSource decoded");r.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(d,a){"cmd"==d&&(this.properties.cmd=g.computeCommandFromString(a))};v.prototype.onGetOutputs=function(){return[["midi","midi"],["on_midi",r.EVENT],["command","number"],["note","number"],["velocity","number"],["cc","number"],["cc_value","number"],["pitch","number"],["pitchbend","number"]]};r.registerNodeType("midi/event",v);d.title="MIDICC";d.desc="gets a Controller Change";d.prototype.onExecute=function(){f.input&&(this.properties.value=f.input.state.cc[this.properties.cc]);this.setOutputData(0,
|
|
|
|
|
this.properties.value)};r.registerNodeType("midi/cc",d)})(this);
|
|
|
|
|
(function(q){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=s.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function f(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,
|
|
|
|
|
smoothingTimeConstant:0.5};this.audionode=s.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 e(){this.properties={gain:1};
|
|
|
|
|
this.audionode=s.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function t(){this.properties={impulse_src:"",normalize:!0};this.audionode=s.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=s.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out",
|
|
|
|
|
"audio")}function u(){this.properties={};this.audionode=s.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function v(){this.properties={gain1:0.5,gain2:0.5};this.audionode=s.getAudioContext().createGain();this.audionode1=s.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=s.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 d(){this.properties={delayTime:0.5};this.audionode=s.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function r(){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=s.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function l(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=s.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 c(){if(!c.default_code){var a=c.default_function.toString(),b=a.indexOf("{")+1,d=a.lastIndexOf("}");c.default_code=a.substr(b,d-b)}this.properties={code:c.default_code};a=s.getAudioContext();a.createScriptProcessor?this.audionode=a.createScriptProcessor(4096,1,1):
|
|
|
|
|
(console.warn("ScriptProcessorNode deprecated"),this.audionode=a.createGain());this.processCode();c._bypass_function||(c._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function h(){this.audionode=s.getAudioContext().destination;this.addInput("in","audio")}var k=q.LiteGraph,s={};q.LGAudio=s;s.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};s.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};s.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};s.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?s.connect(f,d):s.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?s.connect(f,d):s.disconnect(f,d)}};s.onConnectionsChange=function(a,b,c,d){if(a==k.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?s.connect(e,b):s.disconnect(e,b)}};s.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=s.onConnectionsChange};s.cached_audios={};s.loadSound=function(a,b,c){function d(a){console.log("Audio loading sample error:",a);c&&c(a)}if(s.cached_audios[a]&&-1==a.indexOf("blob:"))b&&b(s.cached_audios[a]);else{s.onProcessAudioURL&&
|
|
|
|
|
(a=s.onProcessAudioURL(a));var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";var f=s.getAudioContext();e.onload=function(){console.log("AudioSource loaded");f.decodeAudioData(e.response,function(c){console.log("AudioSource decoded");s.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(){r.getAudioContext().suspend()};g.prototype.unpauseAllSounds=function(){r.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(){s.getAudioContext().suspend()};g.prototype.unpauseAllSounds=function(){s.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=r.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=k.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=r.loadSound(a,b),this._loading_audio=!0,this.boxcolor="#AA4")};g.prototype.onConnectionsChange=r.onConnectionsChange;g.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",k.ACTION],["Stop",k.ACTION]]};g.prototype.onGetOutputs=function(){return[["buffer",
|
|
|
|
|
function(a){var b=this,c=s.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=k.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=s.loadSound(a,b),this._loading_audio=!0,this.boxcolor="#AA4")};g.prototype.onConnectionsChange=s.onConnectionsChange;g.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",k.ACTION],["Stop",k.ACTION]]};g.prototype.onGetOutputs=function(){return[["buffer",
|
|
|
|
|
"audiobuffer"],["ended",k.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";k.registerNodeType("audio/source",g);f.prototype.onPropertyChanged=function(a,b){this.audionode[a]=b};f.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)}}};f.prototype.onGetInputs=
|
|
|
|
|
function(){return[["minDecibels","number"],["maxDecibels","number"],["smoothingTimeConstant","number"]]};f.prototype.onGetOutputs=function(){return[["freqs","array"],["samples","array"]]};f.title="Analyser";f.desc="Audio Analyser";k.registerNodeType("audio/analyser",f);e.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)}};r.createAudioNodeWrapper(e);e.title=
|
|
|
|
|
"Gain";e.desc="Audio gain";k.registerNodeType("audio/gain",e);r.createAudioNodeWrapper(t);t.prototype.onRemove=function(){this._dropped_url&&URL.revokeObjectURL(this._dropped_url)};t.prototype.onPropertyChanged=function(a,b){"impulse_src"==a?this.loadImpulse(b):"normalize"==a&&(this.audionode.normalize=b)};t.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)};
|
|
|
|
|
t.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=r.loadSound(a,b),this._loading_impulse=!0)};t.title="Convolver";t.desc="Convolves the signal (used for reverb)";k.registerNodeType("audio/convolver",t);r.createAudioNodeWrapper(p);p.prototype.onExecute=function(){if(this.inputs&&
|
|
|
|
|
function(){return[["minDecibels","number"],["maxDecibels","number"],["smoothingTimeConstant","number"]]};f.prototype.onGetOutputs=function(){return[["freqs","array"],["samples","array"]]};f.title="Analyser";f.desc="Audio Analyser";k.registerNodeType("audio/analyser",f);e.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)}};s.createAudioNodeWrapper(e);e.title=
|
|
|
|
|
"Gain";e.desc="Audio gain";k.registerNodeType("audio/gain",e);s.createAudioNodeWrapper(t);t.prototype.onRemove=function(){this._dropped_url&&URL.revokeObjectURL(this._dropped_url)};t.prototype.onPropertyChanged=function(a,b){"impulse_src"==a?this.loadImpulse(b):"normalize"==a&&(this.audionode.normalize=b)};t.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)};
|
|
|
|
|
t.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=s.loadSound(a,b),this._loading_impulse=!0)};t.title="Convolver";t.desc="Convolves the signal (used for reverb)";k.registerNodeType("audio/convolver",t);s.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";k.registerNodeType("audio/dynamicsCompressor",p);u.prototype.onExecute=function(){if(this.inputs&&this.inputs.length){var a=
|
|
|
|
|
this.getInputData(1);void 0!==a&&(this.audionode.curve=a)}};u.prototype.setWaveShape=function(a){this.audionode.curve=a};r.createAudioNodeWrapper(u);v.prototype.getAudioNodeInInputSlot=function(a){if(0==a)return this.audionode1;if(2==a)return this.audionode2};v.prototype.onPropertyChanged=function(a,b){"gain1"==a?this.audionode1.gain.value=b:"gain2"==a&&(this.audionode2.gain.value=b)};v.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)))}};r.createAudioNodeWrapper(v);v.title="Mixer";v.desc="Audio mixer";k.registerNodeType("audio/mixer",v);r.createAudioNodeWrapper(d);d.prototype.onExecute=function(){var a=this.getInputData(1);void 0!==a&&(this.audionode.delayTime.value=a)};d.title="Delay";d.desc="Audio delay";k.registerNodeType("audio/delay",d);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"]]};r.createAudioNodeWrapper(s);s.title="BiquadFilter";s.desc="Audio filter";k.registerNodeType("audio/biquadfilter",s);l.prototype.onStart=function(){this.audionode.started||(this.audionode.started=!0,this.audionode.start())};l.prototype.onStop=
|
|
|
|
|
this.getInputData(1);void 0!==a&&(this.audionode.curve=a)}};u.prototype.setWaveShape=function(a){this.audionode.curve=a};s.createAudioNodeWrapper(u);v.prototype.getAudioNodeInInputSlot=function(a){if(0==a)return this.audionode1;if(2==a)return this.audionode2};v.prototype.onPropertyChanged=function(a,b){"gain1"==a?this.audionode1.gain.value=b:"gain2"==a&&(this.audionode2.gain.value=b)};v.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)))}};s.createAudioNodeWrapper(v);v.title="Mixer";v.desc="Audio mixer";k.registerNodeType("audio/mixer",v);s.createAudioNodeWrapper(d);d.prototype.onExecute=function(){var a=this.getInputData(1);void 0!==a&&(this.audionode.delayTime.value=a)};d.title="Delay";d.desc="Audio delay";k.registerNodeType("audio/delay",d);r.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)}}};r.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["Q","number"]]};s.createAudioNodeWrapper(r);r.title="BiquadFilter";r.desc="Audio filter";k.registerNodeType("audio/biquadfilter",r);l.prototype.onStart=function(){this.audionode.started||(this.audionode.started=!0,this.audionode.start())};l.prototype.onStop=
|
|
|
|
|
function(){this.audionode.started&&(this.audionode.started=!1,this.audionode.stop())};l.prototype.onPause=function(){this.onStop()};l.prototype.onUnpause=function(){this.onStart()};l.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)}}};l.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["type","string"]]};
|
|
|
|
|
r.createAudioNodeWrapper(l);l.title="Oscillator";l.desc="Oscillator";k.registerNodeType("audio/oscillator",l);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=r.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";k.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=r.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";k.registerNodeType("audio/signal",
|
|
|
|
|
s.createAudioNodeWrapper(l);l.title="Oscillator";l.desc="Oscillator";k.registerNodeType("audio/oscillator",l);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=s.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";k.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=s.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";k.registerNodeType("audio/signal",
|
|
|
|
|
b);c.prototype.onAdded=function(a){a.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};c["@code"]={widget:"code"};c.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};c.prototype.onStop=function(){this.audionode.onaudioprocess=c._bypass_function};c.prototype.onPause=function(){this.audionode.onaudioprocess=c._bypass_function};c.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};c.prototype.onExecute=function(){};c.prototype.onRemoved=
|
|
|
|
|
function(){this.audionode.onaudioprocess=c._bypass_function};c.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=c._bypass_function,this.audionode.onaudioprocess=this._callback}};c.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))};c.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]}};r.createAudioNodeWrapper(c);c.title="Script";c.desc="apply script to signal";k.registerNodeType("audio/script",c);h.title="Destination";h.desc="Audio output";k.registerNodeType("audio/destination",
|
|
|
|
|
this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};c.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]}};s.createAudioNodeWrapper(c);c.title="Script";c.desc="apply script to signal";k.registerNodeType("audio/script",c);h.title="Destination";h.desc="Audio output";k.registerNodeType("audio/destination",
|
|
|
|
|
h)})(this);
|
|
|
|
|
(function(q){function g(){this.size=[60,20];this.addInput("send",e.ACTION);this.addOutput("received",e.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph"};this._ws=null;this._last_data=[]}function f(){this.size=[60,20];this.addInput("send",e.ACTION);this.addOutput("received",e.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 e=q.LiteGraph;g.title="WebSocket";g.desc="Send data through a websocket";g.prototype.onPropertyChanged=function(e,f){"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,f=1;f<this.inputs.length;++f){var g=this.getInputData(f);if(null!=g){var q;try{q=JSON.stringify({type:0,room:e,channel:f,data:g})}catch(d){continue}this._ws.send(q)}}for(f=
|
|
|
|
|
|