mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 22:37:32 +00:00
fix in searchbox
This commit is contained in:
@@ -9171,7 +9171,21 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
var graphcanvas = LGraphCanvas.active_canvas;
|
||||
var canvas = graphcanvas.canvas;
|
||||
|
||||
var root_document = canvas.ownerDocument || document;
|
||||
if( root_document.fullscreenElement )
|
||||
root_document.fullscreenElement.appendChild(dialog);
|
||||
else
|
||||
root_document.body.appendChild(dialog);
|
||||
|
||||
//compute best position
|
||||
var rect = canvas.getBoundingClientRect();
|
||||
|
||||
var left = ( event ? event.clientX : (rect.left + rect.width * 0.5) ) - 80;
|
||||
var top = ( event ? event.clientY : (rect.top + rect.height * 0.5) ) - 20;
|
||||
dialog.style.left = left + "px";
|
||||
dialog.style.top = top + "px";
|
||||
|
||||
/*
|
||||
var offsetx = -20;
|
||||
var offsety = -20;
|
||||
if (rect) {
|
||||
@@ -9186,8 +9200,9 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
dialog.style.left = canvas.width * 0.5 + offsetx + "px";
|
||||
dialog.style.top = canvas.height * 0.5 + offsety + "px";
|
||||
}
|
||||
|
||||
canvas.parentNode.appendChild(dialog);
|
||||
*/
|
||||
|
||||
input.focus();
|
||||
|
||||
function select(name) {
|
||||
@@ -10177,7 +10192,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
if (
|
||||
options.event &&
|
||||
options.event.constructor !== MouseEvent &&
|
||||
options.event.constructor !== CustomEvent
|
||||
options.event.constructor !== CustomEvent &&
|
||||
options.event.constructor !== PointerEvent
|
||||
) {
|
||||
console.error(
|
||||
"Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."
|
||||
@@ -10659,7 +10675,7 @@ if (typeof exports != "undefined") {
|
||||
this.enabled = true;
|
||||
|
||||
//create inner graph
|
||||
this.subgraph = new LGraph();
|
||||
this.subgraph = new LiteGraph.LGraph();
|
||||
this.subgraph._subgraph_node = this;
|
||||
this.subgraph._is_subgraph = true;
|
||||
|
||||
|
||||
266
build/litegraph.min.js
vendored
266
build/litegraph.min.js
vendored
@@ -1,13 +1,13 @@
|
||||
(function(w){function c(a){e.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function r(a,b,d,t,n,e){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=t;this.target_id=n;this.target_slot=e;this._data=null;this._pos=new Float32Array(2)}function l(a){this._ctor(a)}function f(a){this._ctor(a)}function s(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=0.1;this.onredraw=null;this.enabled=!0;this.last_mouse=
|
||||
(function(w){function c(a){e.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function s(a,b,d,t,n,e){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=t;this.target_id=n;this.target_slot=e;this._data=null;this._pos=new Float32Array(2)}function l(a){this._ctor(a)}function f(a){this._ctor(a)}function r(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=0.1;this.onredraw=null;this.enabled=!0;this.last_mouse=
|
||||
[0,0];this.element=null;this.visible_area=new Float32Array(4);a&&(this.element=a,b||this.bindEvents(a))}function k(a,b,d){d=d||{};this.background_image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
|
||||
a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new s;this.zoom_modify_alpha=!0;this.title_text_font=""+e.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+e.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=e.NODE_TITLE_COLOR;this.default_link_color=e.LINK_COLOR;this.default_connection_color={input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=
|
||||
a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new r;this.zoom_modify_alpha=!0;this.title_text_font=""+e.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+e.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=e.NODE_TITLE_COLOR;this.default_link_color=e.LINK_COLOR;this.default_connection_color={input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=
|
||||
!0;this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.allow_reconnect_links=!1;this.filter=this.dragging_rectangle=null;this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=
|
||||
!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=e.SPLINE_LINK;this.canvas_mouse=[0,0];this.onSelectionChange=this.onNodeMoved=this.onDrawLinkTooltip=this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.over_link_center=this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=this.ds.visible_area;
|
||||
this.visible_links=[];b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();this.autoresize=d.autoresize}function y(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function u(a,b,d,t,n,e){return d<a&&d+n>a&&t<b&&t+e>b?!0:!1}function v(a,b){var d=a[0]+a[2],t=a[1]+a[3],n=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>n||d<b[0]||t<b[1]?!1:!0}function z(a,b){function d(a){var d=parseInt(n.style.top);n.style.top=(d+a.deltaY*b.scroll_speed).toFixed()+
|
||||
"px";a.preventDefault();return!0}this.options=b=b||{};var t=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&b.event.constructor!==MouseEvent&&b.event.constructor!==CustomEvent&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var n=
|
||||
document.createElement("div");n.className="litegraph litecontextmenu litemenubar-panel";b.className&&(n.className+=" "+b.className);n.style.minWidth=100;n.style.minHeight=100;n.style.pointerEvents="none";setTimeout(function(){n.style.pointerEvents="auto"},100);n.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);n.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);n.addEventListener("mousedown",function(a){if(2==a.button)return t.close(),
|
||||
a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);n.addEventListener("wheel",d,!0);n.addEventListener("mousewheel",d,!0);this.root=n;if(b.title){var e=document.createElement("div");e.className="litemenu-title";e.innerHTML=b.title;n.appendChild(e)}var e=0,c;for(c in a){var h=a.constructor==Array?a[c]:c;null!=h&&h.constructor!==String&&(h=void 0===h.content?String(h):h.content);this.addItem(h,a[c],b);e++}n.addEventListener("mouseleave",function(a){t.lock||(n.closing_timer&&clearTimeout(n.closing_timer),
|
||||
n.closing_timer=setTimeout(t.close.bind(t,a),500))});n.addEventListener("mouseenter",function(a){n.closing_timer&&clearTimeout(n.closing_timer)});c=document;b.event&&(c=b.event.target.ownerDocument);c||(c=document);c.fullscreenElement?c.fullscreenElement.appendChild(n):c.body.appendChild(n);e=b.left||0;c=b.top||0;if(b.event){e=b.event.clientX-10;c=b.event.clientY-10;b.title&&(c-=20);b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width);var h=document.body.getBoundingClientRect(),
|
||||
"px";a.preventDefault();return!0}this.options=b=b||{};var t=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&b.event.constructor!==MouseEvent&&b.event.constructor!==CustomEvent&&b.event.constructor!==PointerEvent&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),
|
||||
b.event=null);var n=document.createElement("div");n.className="litegraph litecontextmenu litemenubar-panel";b.className&&(n.className+=" "+b.className);n.style.minWidth=100;n.style.minHeight=100;n.style.pointerEvents="none";setTimeout(function(){n.style.pointerEvents="auto"},100);n.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);n.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);n.addEventListener("mousedown",function(a){if(2==
|
||||
a.button)return t.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);n.addEventListener("wheel",d,!0);n.addEventListener("mousewheel",d,!0);this.root=n;if(b.title){var e=document.createElement("div");e.className="litemenu-title";e.innerHTML=b.title;n.appendChild(e)}var e=0,c;for(c in a){var h=a.constructor==Array?a[c]:c;null!=h&&h.constructor!==String&&(h=void 0===h.content?String(h):h.content);this.addItem(h,a[c],b);e++}n.addEventListener("mouseleave",function(a){t.lock||(n.closing_timer&&
|
||||
clearTimeout(n.closing_timer),n.closing_timer=setTimeout(t.close.bind(t,a),500))});n.addEventListener("mouseenter",function(a){n.closing_timer&&clearTimeout(n.closing_timer)});c=document;b.event&&(c=b.event.target.ownerDocument);c||(c=document);c.fullscreenElement?c.fullscreenElement.appendChild(n):c.body.appendChild(n);e=b.left||0;c=b.top||0;if(b.event){e=b.event.clientX-10;c=b.event.clientY-10;b.title&&(c-=20);b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width);var h=document.body.getBoundingClientRect(),
|
||||
g=n.getBoundingClientRect();e>h.width-g.width-10&&(e=h.width-g.width-10);c>h.height-g.height-10&&(c=h.height-g.height-10)}n.style.left=e+"px";n.style.top=c+"px";b.scale&&(n.style.transform="scale("+b.scale+")")}var e=w.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,
|
||||
NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,
|
||||
ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";
|
||||
@@ -44,10 +44,10 @@ null};c.prototype.renameOutput=function(a,b){if(!this.outputs[a])return!1;if(thi
|
||||
b,this._version++,this.onOutputTypeChanged)this.onOutputTypeChanged(a,b)};c.prototype.removeOutput=function(a){if(!this.outputs[a])return!1;delete this.outputs[a];this._version++;if(this.onOutputRemoved)this.onOutputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};c.prototype.triggerInput=function(a,b){for(var d=this.findNodesByTitle(a),e=0;e<d.length;++e)d[e].onTrigger(b)};c.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),e=0;e<d.length;++e)d[e].setTrigger(b)};
|
||||
c.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};c.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};c.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};c.prototype.change=
|
||||
function(){e.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};c.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};c.prototype.removeLink=function(a){if(a=this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};c.prototype.serialize=function(){for(var a=[],b=0,d=this._nodes.length;b<d;++b)a.push(this._nodes[b].serialize());d=[];for(b in this.links){var t=this.links[b];
|
||||
if(!t.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var n=new r;for(b in t)n[b]=t[b];t=this.links[b]=n}d.push(t.serialize())}t=[];for(b=0;b<this._groups.length;++b)t.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:d,groups:t,config:this.config,version:e.VERSION}};c.prototype.configure=function(a,b){if(a){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var t=[],
|
||||
n=0;n<a.links.length;++n){var c=a.links[n];if(c){var h=new r;h.configure(c);t[h.id]=h}else console.warn("serialized graph link data contains errors, skipping.")}a.links=t}for(n in a)this[n]=a[n];t=!1;this._nodes=[];if(d){n=0;for(c=d.length;n<c;++n){var h=d[n],g=e.createNode(h.type,h.title);g||(e.debug&&console.log("Node not found or has errors: "+h.type),g=new l,g.last_serialization=h,t=g.has_errors=!0);g.id=h.id;this.add(g,!0)}n=0;for(c=d.length;n<c;++n)h=d[n],(g=this.getNodeById(h.id))&&g.configure(h)}this._groups.length=
|
||||
if(!t.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var n=new s;for(b in t)n[b]=t[b];t=this.links[b]=n}d.push(t.serialize())}t=[];for(b=0;b<this._groups.length;++b)t.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:d,groups:t,config:this.config,version:e.VERSION}};c.prototype.configure=function(a,b){if(a){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var t=[],
|
||||
n=0;n<a.links.length;++n){var c=a.links[n];if(c){var h=new s;h.configure(c);t[h.id]=h}else console.warn("serialized graph link data contains errors, skipping.")}a.links=t}for(n in a)this[n]=a[n];t=!1;this._nodes=[];if(d){n=0;for(c=d.length;n<c;++n){var h=d[n],g=e.createNode(h.type,h.title);g||(e.debug&&console.log("Node not found or has errors: "+h.type),g=new l,g.last_serialization=h,t=g.has_errors=!0);g.id=h.id;this.add(g,!0)}n=0;for(c=d.length;n<c;++n)h=d[n],(g=this.getNodeById(h.id))&&g.configure(h)}this._groups.length=
|
||||
0;if(a.groups)for(n=0;n<a.groups.length;++n)d=new e.LGraphGroup,d.configure(a.groups[n]),this.add(d);this.updateExecutionOrder();this._version++;this.setDirtyCanvas(!0,!0);return t}};c.prototype.load=function(a){var b=this,d=new XMLHttpRequest;d.open("GET",a,!0);d.send(null);d.onload=function(a){200!==d.status?console.error("Error loading graph:",d.status,d.response):(a=JSON.parse(d.response),b.configure(a))};d.onerror=function(a){console.error("Error loading graph:",a)}};c.prototype.onNodeTrace=
|
||||
function(a,b,d){};r.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};r.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};e.LLink=r;w.LGraphNode=e.LGraphNode=l;l.prototype._ctor=
|
||||
function(a,b,d){};s.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};s.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};e.LLink=s;w.LGraphNode=e.LGraphNode=l;l.prototype._ctor=
|
||||
function(a){this.title=a||"Unnamed";this.size=[e.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};l.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("properties"==
|
||||
b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=e.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d<this.inputs.length;++d){b=this.inputs[d];var t=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(e.INPUT,d,!0,t,b)}if(this.outputs)for(d=
|
||||
0;d<this.outputs.length;++d){var n=this.outputs[d];if(n.links)for(b=0;b<n.links.length;++b)t=this.graph?this.graph.links[n.links[b]]:null,this.onConnectionsChange(e.OUTPUT,d,!0,t,n)}}if(this.widgets){for(d=0;d<this.widgets.length;++d)b=this.widgets[d],b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(d=0;d<a.widgets_values.length;++d)this.widgets[d]&&(this.widgets[d].value=a.widgets_values[d])}if(this.onConfigure)this.onConfigure(a)};
|
||||
@@ -74,7 +74,7 @@ l.prototype.isPointInside=function(a,b,d,t){d=d||0;var n=this.graph&&this.graph.
|
||||
0,n=this.inputs.length;e<n;++e){var c=this.inputs[e];this.getConnectionPos(!0,e,d);if(u(a,b,d[0]-10,d[1]-5,20,10))return{input:c,slot:e,link_pos:d}}if(this.outputs)for(e=0,n=this.outputs.length;e<n;++e)if(c=this.outputs[e],this.getConnectionPos(!1,e,d),u(a,b,d[0]-10,d[1]-5,20,10))return{output:c,slot:e,link_pos:d};return null};l.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return b;return-1};l.prototype.findOutputSlot=
|
||||
function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};l.prototype.connect=function(a,b,d){d=d||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return e.debug&&
|
||||
console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===e.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&&b.disconnectInput(d);var c=this.outputs[a];
|
||||
if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return null;var n=b.inputs[d],h=null;if(e.isValidConnection(c.type,n.type)){h=new r(++this.graph.last_link_id,n.type,this.id,a,b.id,d);this.graph.links[h.id]=h;null==c.links&&(c.links=[]);c.links.push(h.id);b.inputs[d].link=h.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,h,c);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,h,n);this.graph&&this.graph.onNodeConnectionChange&&
|
||||
if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return null;var n=b.inputs[d],h=null;if(e.isValidConnection(c.type,n.type)){h=new s(++this.graph.last_link_id,n.type,this.id,a,b.id,d);this.graph.links[h.id]=h;null==c.links&&(c.links=[]);c.links.push(h.id);b.inputs[d].link=h.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,h,c);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,h,n);this.graph&&this.graph.onNodeConnectionChange&&
|
||||
(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this,h);return h};l.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||
|
||||
!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var c=0,n=d.links.length;c<n;c++){var h=d.links[c],g=this.graph.links[h];if(g.target_id==b.id){d.links.splice(c,1);var m=b.inputs[g.target_slot];m.link=null;delete this.graph.links[h];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,g.target_slot,!1,g,m);if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!1,g,d);
|
||||
if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,this,a),this.graph.onNodeConnectionChange(e.INPUT,b,g.target_slot));break}}}else{c=0;for(n=d.links.length;c<n;c++)if(h=d.links[c],g=this.graph.links[h]){b=this.graph.getNodeById(g.target_id);this.graph&&this.graph._version++;if(b){m=b.inputs[g.target_slot];m.link=null;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,
|
||||
@@ -88,13 +88,13 @@ b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=
|
||||
!0)};l.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};l.prototype.localToScreen=function(a,b,d){return[(a+this.pos[0])*d.scale+d.offset[0],(b+this.pos[1])*d.scale+d.offset[1]]};w.LGraphGroup=e.LGraphGroup=f;f.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=k.node_colors.pale_blue?k.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=
|
||||
this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};f.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;
|
||||
this.font=a.font};f.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};f.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d<this._nodes.length;++d){var e=this._nodes[d];e.pos[0]+=a;e.pos[1]+=b}};f.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var e=
|
||||
a[d];e.getBounding(b);v(this._bounding,b)&&this._nodes.push(e)}};f.prototype.isPointInside=l.prototype.isPointInside;f.prototype.setDirtyCanvas=l.prototype.setDirtyCanvas;e.DragAndScale=s;s.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",
|
||||
this._binded_mouse_callback,!1)};s.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],d=a+this.element.width/this.scale,e=b+this.element.height/this.scale;this.visible_area[0]=a;this.visible_area[1]=b;this.visible_area[2]=d-a;this.visible_area[3]=e-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};s.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),e=a.clientX-d.left,
|
||||
a[d];e.getBounding(b);v(this._bounding,b)&&this._nodes.push(e)}};f.prototype.isPointInside=l.prototype.isPointInside;f.prototype.setDirtyCanvas=l.prototype.setDirtyCanvas;e.DragAndScale=r;r.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",
|
||||
this._binded_mouse_callback,!1)};r.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],d=a+this.element.width/this.scale,e=b+this.element.height/this.scale;this.visible_area[0]=a;this.visible_area[1]=b;this.visible_area[2]=d-a;this.visible_area[3]=e-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};r.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),e=a.clientX-d.left,
|
||||
d=a.clientY-d.top;a.canvasx=e;a.canvasy=d;a.dragging=this.dragging;var n=!1;this.onmouse&&(n=this.onmouse(a));if("mousedown"==a.type)this.dragging=!0,b.removeEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback);else if("mousemove"==a.type)n||(b=e-this.last_mouse[0],n=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,n));else if("mouseup"==a.type)this.dragging=
|
||||
!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback);else if("mousewheel"==a.type||"wheel"==a.type||"DOMMouseScroll"==a.type)a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta);this.last_mouse[0]=
|
||||
e;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};s.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};s.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};s.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};s.prototype.mouseDrag=function(a,b){this.offset[0]+=
|
||||
a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};s.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var e=this.convertCanvasToOffset(b),d=[e[0]-d[0],e[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};
|
||||
s.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};s.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};w.LGraphCanvas=e.LGraphCanvas=k;k.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};k.gradients={};k.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=
|
||||
e;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};r.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};r.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};r.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};r.prototype.mouseDrag=function(a,b){this.offset[0]+=
|
||||
a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};r.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var e=this.convertCanvasToOffset(b),d=[e[0]-d[0],e[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};
|
||||
r.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};r.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};w.LGraphCanvas=e.LGraphCanvas=k;k.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};k.gradients={};k.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=
|
||||
this.node_over=this.node_dragged=null;this.highlighted_links={};this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};k.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this.setDirty(!0,!0)))};k.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";
|
||||
if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.setDirty(!0,!0)};k.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};k.prototype.getCurrentGraph=
|
||||
function(){return this.graph};k.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);
|
||||
@@ -170,8 +170,8 @@ m[0],-6+m[1],12+m[2],12+m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE&&a.flags.collaps
|
||||
e.getTime(),d=this.visible_area;C[0]=d[0]-20;C[1]=d[1]-20;C[2]=d[2]+40;C[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,c=0,n=d.length;c<n;++c){var g=d[c];if(g.inputs&&g.inputs.length)for(var m=0;m<g.inputs.length;++m){var k=g.inputs[m];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var f=this.graph.getNodeById(k.origin_id);if(null!=f){var l=k.origin_slot,u=null,u=-1==l?[f.pos[0]+10,f.pos[1]+10]:
|
||||
f.getConnectionPos(!1,l,q),x=g.getConnectionPos(!0,m,p);h[0]=u[0];h[1]=u[1];h[2]=x[0]-u[0];h[3]=x[1]-u[1];0>h[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(v(h,C)){var A=f.outputs[l],l=g.inputs[m];if(A&&l&&(f=A.dir||(f.horizontal?e.DOWN:e.RIGHT),l=l.dir||(g.horizontal?e.UP:e.LEFT),this.renderLink(a,u,x,k,!1,0,null,f,l),k&&k._last_time&&1E3>b-k._last_time)){var A=2-0.002*(b-k._last_time),J=a.globalAlpha;a.globalAlpha=J*A;this.renderLink(a,u,x,k,!0,A,"white",f,l);
|
||||
a.globalAlpha=J}}}}}}a.globalAlpha=1};k.prototype.renderLink=function(a,b,d,c,n,h,g,m,p,q){c&&this.visible_links.push(c);!g&&c&&(g=c.color||k.link_type_colors[c.type]);g||(g=this.default_link_color);null!=c&&this.highlighted_links[c.id]&&(g="#FFF");m=m||e.RIGHT;p=p||e.LEFT;var f=y(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=0.5);a.beginPath();for(var l=0;l<q;l+=1){var A=5*(l-0.5*(q-1));if(this.links_render_mode==
|
||||
e.SPLINE_LINK){a.moveTo(b[0],b[1]+A);var u=0,x=0,v=0,s=0;switch(m){case e.LEFT:u=-0.25*f;break;case e.RIGHT:u=0.25*f;break;case e.UP:x=-0.25*f;break;case e.DOWN:x=0.25*f}switch(p){case e.LEFT:v=-0.25*f;break;case e.RIGHT:v=0.25*f;break;case e.UP:s=-0.25*f;break;case e.DOWN:s=0.25*f}a.bezierCurveTo(b[0]+u,b[1]+x+A,d[0]+v,d[1]+s+A,d[0],d[1]+A)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+A);s=v=x=u=0;switch(m){case e.LEFT:u=-1;break;case e.RIGHT:u=1;break;case e.UP:x=-1;break;case e.DOWN:x=
|
||||
1}switch(p){case e.LEFT:v=-1;break;case e.RIGHT:v=1;break;case e.UP:s=-1;break;case e.DOWN:s=1}a.lineTo(b[0]+15*u,b[1]+15*x+A);a.lineTo(d[0]+15*v,d[1]+15*s+A);a.lineTo(d[0],d[1]+A)}else if(this.links_render_mode==e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),A=b[0],u=b[1],x=d[0],v=d[1],m==e.RIGHT?A+=10:u+=10,p==e.LEFT?x-=10:v-=10,a.lineTo(A,u),a.lineTo(0.5*(A+x),u),a.lineTo(0.5*(A+x),v),a.lineTo(x,v),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!n&&(a.strokeStyle="rgba(0,0,0,0.5)",
|
||||
e.SPLINE_LINK){a.moveTo(b[0],b[1]+A);var u=0,x=0,v=0,r=0;switch(m){case e.LEFT:u=-0.25*f;break;case e.RIGHT:u=0.25*f;break;case e.UP:x=-0.25*f;break;case e.DOWN:x=0.25*f}switch(p){case e.LEFT:v=-0.25*f;break;case e.RIGHT:v=0.25*f;break;case e.UP:r=-0.25*f;break;case e.DOWN:r=0.25*f}a.bezierCurveTo(b[0]+u,b[1]+x+A,d[0]+v,d[1]+r+A,d[0],d[1]+A)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+A);r=v=x=u=0;switch(m){case e.LEFT:u=-1;break;case e.RIGHT:u=1;break;case e.UP:x=-1;break;case e.DOWN:x=
|
||||
1}switch(p){case e.LEFT:v=-1;break;case e.RIGHT:v=1;break;case e.UP:r=-1;break;case e.DOWN:r=1}a.lineTo(b[0]+15*u,b[1]+15*x+A);a.lineTo(d[0]+15*v,d[1]+15*r+A);a.lineTo(d[0],d[1]+A)}else if(this.links_render_mode==e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),A=b[0],u=b[1],x=d[0],v=d[1],m==e.RIGHT?A+=10:u+=10,p==e.LEFT?x-=10:v-=10,a.lineTo(A,u),a.lineTo(0.5*(A+x),u),a.lineTo(0.5*(A+x),v),a.lineTo(x,v),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!n&&(a.strokeStyle="rgba(0,0,0,0.5)",
|
||||
a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=g;a.stroke();n=this.computeConnectionPoint(b,d,0.5,m,p);c&&c._pos&&(c._pos[0]=n[0],c._pos[1]=n[1]);0.6<=this.ds.scale&&this.highquality_render&&p!=e.CENTER&&(this.render_connection_arrows&&(l=this.computeConnectionPoint(b,d,0.25,m,p),c=this.computeConnectionPoint(b,d,0.26,m,p),q=this.computeConnectionPoint(b,d,0.75,m,p),f=this.computeConnectionPoint(b,d,0.76,m,p),u=A=0,this.render_curved_connections?(A=-Math.atan2(c[0]-l[0],
|
||||
c[1]-l[1]),u=-Math.atan2(f[0]-q[0],f[1]-q[1])):u=A=d[1]>b[1]?0:Math.PI,a.save(),a.translate(l[0],l[1]),a.rotate(A),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(q[0],q[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(n[0],n[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=g,l=0;5>l;++l)h=(0.001*e.getTime()+0.2*l)%1,n=this.computeConnectionPoint(b,d,h,m,p),a.beginPath(),a.arc(n[0],
|
||||
n[1],5,0,2*Math.PI),a.fill()};k.prototype.computeConnectionPoint=function(a,b,d,c,n){c=c||e.RIGHT;n=n||e.LEFT;var h=y(a,b),g=[a[0],a[1]],m=[b[0],b[1]];switch(c){case e.LEFT:g[0]+=-0.25*h;break;case e.RIGHT:g[0]+=0.25*h;break;case e.UP:g[1]+=-0.25*h;break;case e.DOWN:g[1]+=0.25*h}switch(n){case e.LEFT:m[0]+=-0.25*h;break;case e.RIGHT:m[0]+=0.25*h;break;case e.UP:m[1]+=-0.25*h;break;case e.DOWN:m[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);n=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+n*g[0]+h*m[0]+d*b[0],
|
||||
@@ -205,13 +205,13 @@ l.scrollIntoView())}function c(){function a(d,e){var c=document.createElement("d
|
||||
e.searchbox_extras[m];if(-1!==t.desc.toLowerCase().indexOf(d)){var x=e.registered_node_types[t.type];if(!x||!x.filter||x.filter==l)if(a(t.desc,"searchbox_extra"),-1!==k.search_limit&&h++>k.search_limit)break}}t=null;if(Array.prototype.filter)t=Object.keys(e.registered_node_types).filter(v);else for(m in t=[],e.registered_node_types)v(m)&&t.push(m);for(m=0;m<t.length&&!(a(t[m]),-1!==k.search_limit&&h++>k.search_limit);m++);var v=function(a){var b=e.registered_node_types[a];return l&&b.filter!=l?!1:
|
||||
-1!==a.toLowerCase().indexOf(d)}}}var g=this,h=document.createElement("div");h.className="litegraph litesearchbox graphdialog rounded";h.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";h.close=function(){g.search_box=null;document.body.focus();setTimeout(function(){g.canvas.focus()},20);h.parentNode&&h.parentNode.removeChild(h)};var m=null;1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseenter",
|
||||
function(a){m&&(clearTimeout(m),m=null)});h.addEventListener("mouseleave",function(a){m=setTimeout(function(){h.close()},500)});g.search_box&&g.search_box.close();g.search_box=h;var f=h.querySelector(".helper"),q=null,p=null,l=null,u=h.querySelector("input");u&&(u.addEventListener("blur",function(a){this.focus()}),u.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)h.close();else if(13==a.keyCode)l?b(l.innerHTML):q?b(q):h.close();else{p&&
|
||||
clearInterval(p);p=setTimeout(c,10);return}a.preventDefault();a.stopPropagation()}));var A=k.active_canvas,x=A.canvas,v=x.getBoundingClientRect(),s=-20,z=-20;v&&(s-=v.left,z-=v.top);a?(h.style.left=a.clientX+s+"px",h.style.top=a.clientY+z+"px"):(h.style.left=0.5*x.width+s+"px",h.style.top=0.5*x.height+z+"px");x.parentNode.appendChild(h);u.focus();return h};k.prototype.showEditPropertyValue=function(a,b,d){function e(){c(p.value)}function c(d){"number"==typeof a.properties[b]&&(d=Number(d));if("array"==
|
||||
g||"object"==g)d=JSON.parse(d);a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);k.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var g="string";null!==a.properties[b]&&(g=typeof a.properties[b]);var h=null;a.getPropertyInfo&&(h=a.getPropertyInfo(b));if(a.properties_info)for(var m=0;m<a.properties_info.length;++m)if(a.properties_info[m].name==b){h=a.properties_info[m];break}void 0!==h&&null!==h&&h.type&&(g=h.type);var f="";if("string"==
|
||||
g||"number"==g||"array"==g||"object"==g)f="<input autofocus type='text' class='value'/>";else if("enum"==g&&h.values){f="<select autofocus type='text' class='value'>";for(m in h.values)var q=h.values.constructor===Array?h.values[m]:m,f=f+("<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+h.values[m]+"</option>");f+="</select>"}else if("boolean"==g)f="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+g);return}var k=
|
||||
this.createDialog("<span class='name'>"+b+"</span>"+f+"<button>OK</button>",d);if("enum"==g&&h.values){var p=k.querySelector("select");p.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==g)(p=k.querySelector("input"))&&p.addEventListener("click",function(a){c(!!p.checked)});else if(p=k.querySelector("input"))p.addEventListener("blur",function(a){this.focus()}),q=void 0!==a.properties[b]?a.properties[b]:"",q=JSON.stringify(q),p.value=q,p.addEventListener("keydown",function(a){13==
|
||||
a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});k.querySelector("button").addEventListener("click",e)}};k.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),c=-20,g=-20;e&&(c-=e.left,g-=e.top);b.position?(c+=b.position[0],g+=b.position[1]):b.event?(c+=b.event.clientX,g+=b.event.clientY):(c+=0.5*this.canvas.width,g+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=g+"px";
|
||||
this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};k.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};k.onMenuNodePin=function(a,b,d,e,c){c.pin()};k.onMenuNodeMode=function(a,b,d,c,g){new e.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(g)switch(a){case "On Event":g.mode=e.ON_EVENT;break;case "On Trigger":g.mode=e.ON_TRIGGER;break;case "Never":g.mode=e.NEVER;break;default:g.mode=e.ALWAYS}},
|
||||
parentMenu:c,node:g});return!1};k.onMenuNodeColors=function(a,b,d,c,g){if(!g)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var h in k.node_colors)a=k.node_colors[h],a={value:h,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+h+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){g&&((a=a.value?k.node_colors[a.value]:
|
||||
clearInterval(p);p=setTimeout(c,10);return}a.preventDefault();a.stopPropagation()}));var A=k.active_canvas,x=A.canvas,v=x.ownerDocument||document;v.fullscreenElement?v.fullscreenElement.appendChild(h):v.body.appendChild(h);x=x.getBoundingClientRect();v=(a?a.clientY:x.top+0.5*x.height)-20;h.style.left=(a?a.clientX:x.left+0.5*x.width)-80+"px";h.style.top=v+"px";u.focus();return h};k.prototype.showEditPropertyValue=function(a,b,d){function e(){c(p.value)}function c(d){"number"==typeof a.properties[b]&&
|
||||
(d=Number(d));if("array"==g||"object"==g)d=JSON.parse(d);a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);k.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var g="string";null!==a.properties[b]&&(g=typeof a.properties[b]);var h=null;a.getPropertyInfo&&(h=a.getPropertyInfo(b));if(a.properties_info)for(var m=0;m<a.properties_info.length;++m)if(a.properties_info[m].name==b){h=a.properties_info[m];break}void 0!==h&&null!==h&&h.type&&
|
||||
(g=h.type);var f="";if("string"==g||"number"==g||"array"==g||"object"==g)f="<input autofocus type='text' class='value'/>";else if("enum"==g&&h.values){f="<select autofocus type='text' class='value'>";for(m in h.values)var q=h.values.constructor===Array?h.values[m]:m,f=f+("<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+h.values[m]+"</option>");f+="</select>"}else if("boolean"==g)f="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+
|
||||
g);return}var k=this.createDialog("<span class='name'>"+b+"</span>"+f+"<button>OK</button>",d);if("enum"==g&&h.values){var p=k.querySelector("select");p.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==g)(p=k.querySelector("input"))&&p.addEventListener("click",function(a){c(!!p.checked)});else if(p=k.querySelector("input"))p.addEventListener("blur",function(a){this.focus()}),q=void 0!==a.properties[b]?a.properties[b]:"",q=JSON.stringify(q),p.value=q,p.addEventListener("keydown",
|
||||
function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});k.querySelector("button").addEventListener("click",e)}};k.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),c=-20,g=-20;e&&(c-=e.left,g-=e.top);b.position?(c+=b.position[0],g+=b.position[1]):b.event?(c+=b.event.clientX,g+=b.event.clientY):(c+=0.5*this.canvas.width,g+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=
|
||||
g+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};k.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};k.onMenuNodePin=function(a,b,d,e,c){c.pin()};k.onMenuNodeMode=function(a,b,d,c,g){new e.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(g)switch(a){case "On Event":g.mode=e.ON_EVENT;break;case "On Trigger":g.mode=e.ON_TRIGGER;break;case "Never":g.mode=e.NEVER;break;default:g.mode=
|
||||
e.ALWAYS}},parentMenu:c,node:g});return!1};k.onMenuNodeColors=function(a,b,d,c,g){if(!g)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var h in k.node_colors)a=k.node_colors[h],a={value:h,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+h+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){g&&((a=a.value?k.node_colors[a.value]:
|
||||
null)?g.constructor===e.LGraphGroup?g.color=a.groupcolor:(g.color=a.color,g.bgcolor=a.bgcolor):(delete g.color,delete g.bgcolor),g.setDirtyCanvas(!0,!0))},parentMenu:c,node:g});return!1};k.onMenuNodeShapes=function(a,b,d,c,g){if(!g)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){g&&(g.shape=a,g.setDirtyCanvas(!0))},parentMenu:c,node:g});return!1};k.onMenuNodeRemove=function(a,b,d,e,c){if(!c)throw"no node passed";!1!==c.removable&&(c.graph.remove(c),c.setDirtyCanvas(!0,
|
||||
!0))};k.onMenuNodeClone=function(a,b,d,c,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))};k.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},
|
||||
purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};k.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:k.onMenuAdd},{content:"Add Group",callback:k.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));
|
||||
@@ -231,25 +231,25 @@ function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);
|
||||
!1:!1};e.ContextMenu=z;e.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};e.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,
|
||||
b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=
|
||||
window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
(function(w){function c(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function r(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onTrigger=this.onSubgraphTrigger.bind(this);this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);
|
||||
(function(w){function c(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function s(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new p.LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onTrigger=this.onSubgraphTrigger.bind(this);this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);
|
||||
this.subgraph.onInputRemoved=this.onSubgraphRemovedInput.bind(this);this.subgraph.onOutputAdded=this.onSubgraphNewOutput.bind(this);this.subgraph.onOutputRenamed=this.onSubgraphRenamedOutput.bind(this);this.subgraph.onOutputTypeChanged=this.onSubgraphTypeChangeOutput.bind(this);this.subgraph.onOutputRemoved=this.onSubgraphRemovedOutput.bind(this)}function l(){this.addOutput("","number");this.name_in_graph="";this.properties={name:"",type:"number",value:0};var a=this;this.name_widget=this.addWidget("text",
|
||||
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function f(){this.addInput("","");this.name_in_graph="";this.properties={};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return a.name_in_graph},set:function(b){""!=
|
||||
b&&b!=a.name_in_graph&&(a.name_in_graph?a.graph.renameOutput(a.name_in_graph,b):a.graph.addOutput(b,a.properties.type),a.name_widget.value=b,a.name_in_graph=b)},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return a.inputs[0].type},set:function(b){if("action"==b||"event"==b)b=p.ACTION;a.inputs[0].type=b;a.name_in_graph&&a.graph.changeOutputType(a.name_in_graph,a.inputs[0].type);a.type_widget.value=b||""},enumerable:!0});this.name_widget=this.addWidget("text","Name",
|
||||
this.properties.name,function(b){b&&(a.properties.name=b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.properties.type=b||""});this.widgets_up=!0;this.size=[180,60]}function s(){this.addOutput("value","number");this.addProperty("value",1)}function k(){this.addOutput("","string");this.addProperty("value","");this.widget=this.addWidget("text","value","",this.setValue.bind(this));this.widgets_up=!0;this.size=[100,30]}function y(){this.addOutput("","");this.addProperty("value",
|
||||
this.properties.name,function(b){b&&(a.properties.name=b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.properties.type=b||""});this.widgets_up=!0;this.size=[180,60]}function r(){this.addOutput("value","number");this.addProperty("value",1)}function k(){this.addOutput("","string");this.addProperty("value","");this.widget=this.addWidget("text","value","",this.setValue.bind(this));this.widgets_up=!0;this.size=[100,30]}function y(){this.addOutput("","");this.addProperty("value",
|
||||
"");this.widget=this.addWidget("text","json","",this.setValue.bind(this));this.widgets_up=!0;this.size=[140,30];this._value=null}function u(){this.addInput("obj","");this.addOutput("","");this.addProperty("value","");this.widget=this.addWidget("text","prop.","",this.setValue.bind(this));this.widgets_up=!0;this.size=[140,30];this._value=null}function v(){this.addInput("obj","");this.addOutput("keys","array");this.size=[140,30]}function z(){this.addInput("A","object");this.addInput("B","object");this.addOutput("",
|
||||
"object");this._result={};var a=this;this.addWidget("button","clear","",function(){a._result={}});this.size=this.computeSize()}function e(){this.size=[60,30];this.addInput("in");this.addOutput("out");this.properties={varname:"myname",global:!1};this.value=null}function x(){this.size=[60,30];this.addInput("data",0);this.addInput("download",p.ACTION);this.properties={filename:"data.json"};this.value=null;var a=this;this.addWidget("button","Download","",function(b){a.value&&a.downloadAsFile()})}function g(){this.size=
|
||||
[60,30];this.addInput("value",0,{label:""});this.value=0}function m(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,30]}function C(){this.mode=p.ON_EVENT;this.size=[80,30];this.addProperty("msg","");this.addInput("log",p.EVENT);this.addInput("msg",0)}function h(){this.mode=p.ON_EVENT;this.addProperty("msg","");this.addInput("",p.EVENT);var a=this;this.widget=this.addWidget("text","Text","",function(b){a.properties.msg=b});this.widgets_up=!0;this.size=[200,30]}function q(){this.size=
|
||||
[60,30];this.addProperty("onExecute","return A;");this.addInput("A","");this.addInput("B","");this.addOutput("out","");this._func=null;this.data={}}var p=w.LiteGraph;c.title="Time";c.desc="Time";c.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};p.registerNodeType("basic/time",c);r.title="Subgraph";r.desc="Graph inside a node";r.title_color="#334";r.prototype.onGetInputs=function(){return[["enabled","boolean"]]};r.prototype.onDrawTitle=
|
||||
function(a){if(!this.flags.collapsed){a.fillStyle="#555";var b=p.NODE_TITLE_HEIGHT,d=this.size[0]-b;a.fillRect(d,-b,b,b);a.fillStyle="#333";a.beginPath();a.moveTo(d+0.2*b,0.6*-b);a.lineTo(d+0.8*b,0.6*-b);a.lineTo(d+0.5*b,0.3*-b);a.fill()}};r.prototype.onDblClick=function(a,b,d){var c=this;setTimeout(function(){d.openSubgraph(c.subgraph)},10)};r.prototype.onMouseDown=function(a,b,d){if(!this.flags.collapsed&&b[0]>this.size[0]-p.NODE_TITLE_HEIGHT&&0>b[1]){var c=this;setTimeout(function(){d.openSubgraph(c.subgraph)},
|
||||
10)}};r.prototype.onAction=function(a,b){this.subgraph.onAction(a,b)};r.prototype.onExecute=function(){if(this.enabled=this.getInputOrProperty("enabled")){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],d=this.getInputData(a);this.subgraph.setInputData(b.name,d)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)d=this.subgraph.getOutputData(this.outputs[a].name),this.setOutputData(a,d)}};r.prototype.sendEventToAllNodes=function(a,b,d){this.enabled&&
|
||||
this.subgraph.sendEventToAllNodes(a,b,d)};r.prototype.onSubgraphTrigger=function(a,b){var d=this.findOutputSlot(a);-1!=d&&this.triggerSlot(d)};r.prototype.onSubgraphNewInput=function(a,b){-1==this.findInputSlot(a)&&this.addInput(a,b)};r.prototype.onSubgraphRenamedInput=function(a,b){var d=this.findInputSlot(a);-1!=d&&(this.getInputInfo(d).name=b)};r.prototype.onSubgraphTypeChangeInput=function(a,b){var d=this.findInputSlot(a);-1!=d&&(this.getInputInfo(d).type=b)};r.prototype.onSubgraphRemovedInput=
|
||||
function(a){a=this.findInputSlot(a);-1!=a&&this.removeInput(a)};r.prototype.onSubgraphNewOutput=function(a,b){-1==this.findOutputSlot(a)&&this.addOutput(a,b)};r.prototype.onSubgraphRenamedOutput=function(a,b){var d=this.findOutputSlot(a);-1!=d&&(this.getOutputInfo(d).name=b)};r.prototype.onSubgraphTypeChangeOutput=function(a,b){var d=this.findOutputSlot(a);-1!=d&&(this.getOutputInfo(d).type=b)};r.prototype.onSubgraphRemovedOutput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeOutput(a)};r.prototype.getExtraMenuOptions=
|
||||
function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};r.prototype.onResize=function(a){a[1]+=20};r.prototype.serialize=function(){var a=LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};r.prototype.clone=function(){var a=p.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};p.Subgraph=r;p.registerNodeType("graph/subgraph",r);l.title="Input";l.desc="Input of the graph";
|
||||
[60,30];this.addProperty("onExecute","return A;");this.addInput("A","");this.addInput("B","");this.addOutput("out","");this._func=null;this.data={}}var p=w.LiteGraph;c.title="Time";c.desc="Time";c.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};p.registerNodeType("basic/time",c);s.title="Subgraph";s.desc="Graph inside a node";s.title_color="#334";s.prototype.onGetInputs=function(){return[["enabled","boolean"]]};s.prototype.onDrawTitle=
|
||||
function(a){if(!this.flags.collapsed){a.fillStyle="#555";var b=p.NODE_TITLE_HEIGHT,d=this.size[0]-b;a.fillRect(d,-b,b,b);a.fillStyle="#333";a.beginPath();a.moveTo(d+0.2*b,0.6*-b);a.lineTo(d+0.8*b,0.6*-b);a.lineTo(d+0.5*b,0.3*-b);a.fill()}};s.prototype.onDblClick=function(a,b,d){var c=this;setTimeout(function(){d.openSubgraph(c.subgraph)},10)};s.prototype.onMouseDown=function(a,b,d){if(!this.flags.collapsed&&b[0]>this.size[0]-p.NODE_TITLE_HEIGHT&&0>b[1]){var c=this;setTimeout(function(){d.openSubgraph(c.subgraph)},
|
||||
10)}};s.prototype.onAction=function(a,b){this.subgraph.onAction(a,b)};s.prototype.onExecute=function(){if(this.enabled=this.getInputOrProperty("enabled")){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],d=this.getInputData(a);this.subgraph.setInputData(b.name,d)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)d=this.subgraph.getOutputData(this.outputs[a].name),this.setOutputData(a,d)}};s.prototype.sendEventToAllNodes=function(a,b,d){this.enabled&&
|
||||
this.subgraph.sendEventToAllNodes(a,b,d)};s.prototype.onSubgraphTrigger=function(a,b){var d=this.findOutputSlot(a);-1!=d&&this.triggerSlot(d)};s.prototype.onSubgraphNewInput=function(a,b){-1==this.findInputSlot(a)&&this.addInput(a,b)};s.prototype.onSubgraphRenamedInput=function(a,b){var d=this.findInputSlot(a);-1!=d&&(this.getInputInfo(d).name=b)};s.prototype.onSubgraphTypeChangeInput=function(a,b){var d=this.findInputSlot(a);-1!=d&&(this.getInputInfo(d).type=b)};s.prototype.onSubgraphRemovedInput=
|
||||
function(a){a=this.findInputSlot(a);-1!=a&&this.removeInput(a)};s.prototype.onSubgraphNewOutput=function(a,b){-1==this.findOutputSlot(a)&&this.addOutput(a,b)};s.prototype.onSubgraphRenamedOutput=function(a,b){var d=this.findOutputSlot(a);-1!=d&&(this.getOutputInfo(d).name=b)};s.prototype.onSubgraphTypeChangeOutput=function(a,b){var d=this.findOutputSlot(a);-1!=d&&(this.getOutputInfo(d).type=b)};s.prototype.onSubgraphRemovedOutput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeOutput(a)};s.prototype.getExtraMenuOptions=
|
||||
function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};s.prototype.onResize=function(a){a[1]+=20};s.prototype.serialize=function(){var a=LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};s.prototype.clone=function(){var a=p.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};p.Subgraph=s;p.registerNodeType("graph/subgraph",s);l.title="Input";l.desc="Input of the graph";
|
||||
l.prototype.onConfigure=function(){this.updateType()};l.prototype.updateType=function(){var a=this.properties.type;this.type_widget.value=a;"number"==a?(this.value_widget.type="number",this.value_widget.value=0):"bool"==a?(this.value_widget.type="toggle",this.value_widget.value=!0):"string"==a?(this.value_widget.type="text",this.value_widget.value=""):(this.value_widget.type=null,this.value_widget.value=null);this.properties.value=this.value_widget.value};l.prototype.onPropertyChanged=function(a,
|
||||
b){if("name"==a){if(""==b||b==this.name_in_graph||"enabled"==b)return!1;this.graph&&(this.name_in_graph?this.graph.renameInput(this.name_in_graph,b):this.graph.addInput(b,this.properties.type));this.name_in_graph=this.name_widget.value=b}else"type"==a&&this.updateType(b||"")};l.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};l.prototype.onAction=function(a,b){this.properties.type==p.EVENT&&this.triggerSlot(0,b)};l.prototype.onExecute=function(){var a=this.graph.inputs[this.properties.name];
|
||||
a||this.setOutputData(0,this.properties.value);this.setOutputData(0,void 0===a.value?this.properties.value:a.value)};l.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeInput(this.name_in_graph)};p.GraphInput=l;p.registerNodeType("graph/input",l);f.title="Output";f.desc="Output of the graph";f.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setOutputData(this.properties.name,this._value)};f.prototype.onAction=function(a,b){this.properties.type==p.ACTION&&
|
||||
this.graph.trigger(this.properties.name,b)};f.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeOutput(this.name_in_graph)};f.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};p.GraphOutput=f;p.registerNodeType("graph/output",f);s.title="Const Number";s.desc="Constant number";s.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};s.prototype.getTitle=function(){return this.flags.collapsed?this.properties.value:
|
||||
this.title};s.prototype.setValue=function(a){this.properties.value=a};s.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};p.registerNodeType("basic/const",s);k.title="Const String";k.desc="Constant string";k.prototype.setValue=function(a){this.properties.value=a};k.prototype.onPropertyChanged=function(a,b){this.widget.value=b};k.prototype.getTitle=s.prototype.getTitle;k.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};p.registerNodeType("basic/string",
|
||||
this.graph.trigger(this.properties.name,b)};f.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeOutput(this.name_in_graph)};f.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};p.GraphOutput=f;p.registerNodeType("graph/output",f);r.title="Const Number";r.desc="Constant number";r.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};r.prototype.getTitle=function(){return this.flags.collapsed?this.properties.value:
|
||||
this.title};r.prototype.setValue=function(a){this.properties.value=a};r.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};p.registerNodeType("basic/const",r);k.title="Const String";k.desc="Constant string";k.prototype.setValue=function(a){this.properties.value=a};k.prototype.onPropertyChanged=function(a,b){this.widget.value=b};k.prototype.getTitle=r.prototype.getTitle;k.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};p.registerNodeType("basic/string",
|
||||
k);y.title="Const Data";y.desc="Constant Data";y.prototype.setValue=function(a){this.properties.value=a;this.onPropertyChanged("value",a)};y.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value=JSON.parse(b),this.boxcolor="#AEA"}catch(d){this.boxcolor="red"}};y.prototype.onExecute=function(){this.setOutputData(0,this._value)};p.registerNodeType("basic/data",y);u.title="Object property";u.desc="Outputs the property of an object";u.prototype.setValue=function(a){this.properties.value=
|
||||
a;this.widget.value=a};u.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};u.prototype.onPropertyChanged=function(a,b){this.widget.value=b};u.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a[this.properties.value])};p.registerNodeType("basic/object_property",u);v.title="Object keys";v.desc="Outputs an array with the keys of an object";v.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,
|
||||
Object.keys(a))};p.registerNodeType("basic/object_keys",v);z.title="Merge Objects";z.desc="Creates an object copying properties from others";z.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),d=this._result;if(a)for(var c in a)d[c]=a[c];if(b)for(c in b)d[c]=b[c];this.setOutputData(0,d)};p.registerNodeType("basic/merge_objects",z);e.title="Variable";e.desc="store/read variable value";e.prototype.onExecute=function(){this.value=this.getInputData(0);this.graph&&(this.graph.vars[this.properties.varname]=
|
||||
@@ -261,24 +261,24 @@ function(){return[["log",p.ACTION],["warn",p.ACTION],["error",p.ACTION]]};p.regi
|
||||
q.title="Script";q.desc="executes a code (max 100 characters)";q.widgets_info={onExecute:{type:"code"}};q.prototype.onPropertyChanged=function(a,b){"onExecute"==a&&p.allow_scripts?this.compileCode(b):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};q.prototype.compileCode=function(a){this._func=null;if(256<a.length)console.warn("Script too long, max 256 chars");else{for(var b=a.toLowerCase(),d="script body document eval nodescript function".split(" "),c=0;c<d.length;++c)if(-1!=
|
||||
b.indexOf(d[c])){console.warn("invalid script");return}try{this._func=new Function("A","B","C","DATA","node",a)}catch(e){console.error("Error parsing script"),console.error(e)}}};q.prototype.onExecute=function(){if(this._func)try{var a=this.getInputData(0),b=this.getInputData(1),d=this.getInputData(2);this.setOutputData(0,this._func(a,b,d,this.data,this))}catch(c){console.error("Error in script"),console.error(c)}};q.prototype.onGetOutputs=function(){return[["C",""]]};p.registerNodeType("basic/script",
|
||||
q)})(this);
|
||||
(function(w){function c(){this.size=[60,30];this.addInput("event",v.ACTION)}function r(){this.size=[60,30];this.addInput("in","");this.addOutput("true",v.EVENT);this.addOutput("change",v.EVENT);this.was_true=!1}function l(){this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",
|
||||
v.EVENT);this.addOutput("",v.EVENT);this.size=[120,30];this.flags={horizontal:!0,render_box:!1}}function f(){this.size=[60,30];this.addInput("event",v.ACTION);this.addOutput("event",v.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function s(){this.addInput("inc",v.ACTION);this.addInput("dec",v.ACTION);this.addInput("reset",v.ACTION);this.addOutput("change",v.EVENT);this.addOutput("num","number");this.num=0}function k(){this.size=[60,30];this.addProperty("time_in_ms",1E3);
|
||||
(function(w){function c(){this.size=[60,30];this.addInput("event",v.ACTION)}function s(){this.size=[60,30];this.addInput("in","");this.addOutput("true",v.EVENT);this.addOutput("change",v.EVENT);this.was_true=!1}function l(){this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addInput("",v.ACTION);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",v.EVENT);this.addOutput("",
|
||||
v.EVENT);this.addOutput("",v.EVENT);this.size=[120,30];this.flags={horizontal:!0,render_box:!1}}function f(){this.size=[60,30];this.addInput("event",v.ACTION);this.addOutput("event",v.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function r(){this.addInput("inc",v.ACTION);this.addInput("dec",v.ACTION);this.addInput("reset",v.ACTION);this.addOutput("change",v.EVENT);this.addOutput("num","number");this.num=0}function k(){this.size=[60,30];this.addProperty("time_in_ms",1E3);
|
||||
this.addInput("event",v.ACTION);this.addOutput("on_time",v.EVENT);this._pending=[]}function y(){this.addProperty("interval",1E3);this.addProperty("event","tick");this.addOutput("on_tick",v.EVENT);this.time=0;this.last_interval=1E3;this.triggered=!1}function u(){this.addInput("data","");this.addInput("assign",v.ACTION);this.addOutput("data","");this._last_value=null;this.properties={data:null,serialize:!0};var c=this;this.addWidget("button","store","",function(){c.properties.data=c._last_value})}var v=
|
||||
w.LiteGraph;c.title="Log Event";c.desc="Log event in console";c.prototype.onAction=function(c,e){console.log(c,e)};v.registerNodeType("events/log",c);r.title="TriggerEvent";r.desc="Triggers event if value is true";r.prototype.onExecute=function(c,e){var f=this.getInputData(0);f&&this.triggerSlot(0,e);f&&!this.was_true&&this.triggerSlot(1,e);this.was_true=f};v.registerNodeType("events/trigger",r);l.title="Sequencer";l.desc="Trigger events when an event arrives";l.prototype.getTitle=function(){return""};
|
||||
w.LiteGraph;c.title="Log Event";c.desc="Log event in console";c.prototype.onAction=function(c,e){console.log(c,e)};v.registerNodeType("events/log",c);s.title="TriggerEvent";s.desc="Triggers event if value is true";s.prototype.onExecute=function(c,e){var f=this.getInputData(0);f&&this.triggerSlot(0,e);f&&!this.was_true&&this.triggerSlot(1,e);this.was_true=f};v.registerNodeType("events/trigger",s);l.title="Sequencer";l.desc="Trigger events when an event arrives";l.prototype.getTitle=function(){return""};
|
||||
l.prototype.onAction=function(c,e){if(this.outputs)for(var f=0;f<this.outputs.length;++f)this.triggerSlot(f,e)};v.registerNodeType("events/sequencer",l);f.title="Filter Event";f.desc="Blocks events that do not match the filter";f.prototype.onAction=function(c,e){if(null!=e&&(!this.properties.equal_to||this.properties.equal_to==e)){if(this.properties.has_property){var f=e[this.properties.has_property];if(null==f||this.properties.property_equal_to&&this.properties.property_equal_to!=f)return}this.triggerSlot(0,
|
||||
e)}};v.registerNodeType("events/filter",f);s.title="Counter";s.desc="Counts events";s.prototype.getTitle=function(){return this.flags.collapsed?String(this.num):this.title};s.prototype.onAction=function(c,e){var f=this.num;"inc"==c?this.num+=1:"dec"==c?this.num-=1:"reset"==c&&(this.num=0);this.num!=f&&this.trigger("change",this.num)};s.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.fillStyle="#AAA",c.font="20px Arial",c.textAlign="center",c.fillText(this.num,0.5*this.size[0],0.5*
|
||||
this.size[1]))};s.prototype.onExecute=function(){this.setOutputData(1,this.num)};v.registerNodeType("events/counter",s);k.title="Delay";k.desc="Delays one event";k.prototype.onAction=function(c,e){var f=this.properties.time_in_ms;0>=f?this.trigger(null,e):this._pending.push([f,e])};k.prototype.onExecute=function(){var c=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var e=0;e<this._pending.length;++e){var f=this._pending[e];f[0]-=c;0<f[0]||
|
||||
e)}};v.registerNodeType("events/filter",f);r.title="Counter";r.desc="Counts events";r.prototype.getTitle=function(){return this.flags.collapsed?String(this.num):this.title};r.prototype.onAction=function(c,e){var f=this.num;"inc"==c?this.num+=1:"dec"==c?this.num-=1:"reset"==c&&(this.num=0);this.num!=f&&this.trigger("change",this.num)};r.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.fillStyle="#AAA",c.font="20px Arial",c.textAlign="center",c.fillText(this.num,0.5*this.size[0],0.5*
|
||||
this.size[1]))};r.prototype.onExecute=function(){this.setOutputData(1,this.num)};v.registerNodeType("events/counter",r);k.title="Delay";k.desc="Delays one event";k.prototype.onAction=function(c,e){var f=this.properties.time_in_ms;0>=f?this.trigger(null,e):this._pending.push([f,e])};k.prototype.onExecute=function(){var c=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var e=0;e<this._pending.length;++e){var f=this._pending[e];f[0]-=c;0<f[0]||
|
||||
(this._pending.splice(e,1),--e,this.trigger(null,f[1]))}};k.prototype.onGetInputs=function(){return[["event",v.ACTION],["time_in_ms","number"]]};v.registerNodeType("events/delay",k);y.title="Timer";y.desc="Sends an event every N milliseconds";y.prototype.onStart=function(){this.time=0};y.prototype.getTitle=function(){return"Timer: "+this.last_interval.toString()+"ms"};y.on_color="#AAA";y.off_color="#222";y.prototype.onDrawBackground=function(){this.boxcolor=this.triggered?y.on_color:y.off_color;this.triggered=
|
||||
!1};y.prototype.onExecute=function(){var c=0==this.time;this.time+=1E3*this.graph.elapsed_time;this.last_interval=Math.max(1,this.getInputOrProperty("interval")|0);!c&&(this.time<this.last_interval||isNaN(this.last_interval))?this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!1):(this.triggered=!0,this.time%=this.last_interval,this.trigger("on_tick",this.properties.event),this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!0))};y.prototype.onGetInputs=function(){return[["interval",
|
||||
"number"]]};y.prototype.onGetOutputs=function(){return[["tick","boolean"]]};v.registerNodeType("events/timer",y);u.title="Data Store";u.desc="Stores data and only changes when event is received";u.prototype.onExecute=function(){this._last_value=this.getInputData(0);this.setOutputData(0,this.properties.data)};u.prototype.onAction=function(c,e){this.properties.data=this._last_value};u.prototype.onSerialize=function(c){null!=c.data&&(!1==this.properties.serialize||c.data.constructor!==String&&c.data.constructor!==
|
||||
Number&&c.data.constructor!==Boolean&&c.data.constructor!==Array&&c.data.constructor!==Object)&&(c.data=null)};v.registerNodeType("basic/data_store",u)})(this);
|
||||
(function(w){function c(){this.addOutput("",z.EVENT);this.addOutput("","boolean");this.addProperty("text","click me");this.addProperty("font_size",30);this.addProperty("message","");this.size=[164,84];this.clicked=!1}function r(){this.addInput("","boolean");this.addInput("e",z.ACTION);this.addOutput("v","boolean");this.addOutput("e",z.EVENT);this.properties={font:"",value:!1};this.size=[160,44]}function l(){this.addOutput("","number");this.size=[80,60];this.properties={min:-1E3,max:1E3,value:1,step:1};
|
||||
this.old_y=-1;this._precision=this._remainder=0;this.mouse_captured=!1}function f(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,color:"#7AF",precision:2};this.value=-1}function s(){this.addOutput("","number");this.properties={value:0.5,min:0,max:1,text:"V"};var c=this;this.size=[140,40];this.slider=this.addWidget("slider","V",this.properties.value,function(f){c.properties.value=f},this.properties);this.widgets_up=!0}function k(){this.size=[160,26];this.addOutput("",
|
||||
(function(w){function c(){this.addOutput("",z.EVENT);this.addOutput("","boolean");this.addProperty("text","click me");this.addProperty("font_size",30);this.addProperty("message","");this.size=[164,84];this.clicked=!1}function s(){this.addInput("","boolean");this.addInput("e",z.ACTION);this.addOutput("v","boolean");this.addOutput("e",z.EVENT);this.properties={font:"",value:!1};this.size=[160,44]}function l(){this.addOutput("","number");this.size=[80,60];this.properties={min:-1E3,max:1E3,value:1,step:1};
|
||||
this.old_y=-1;this._precision=this._remainder=0;this.mouse_captured=!1}function f(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,color:"#7AF",precision:2};this.value=-1}function r(){this.addOutput("","number");this.properties={value:0.5,min:0,max:1,text:"V"};var c=this;this.size=[140,40];this.slider=this.addWidget("slider","V",this.properties.value,function(f){c.properties.value=f},this.properties);this.widgets_up=!0}function k(){this.size=[160,26];this.addOutput("",
|
||||
"number");this.properties={color:"#7AF",min:0,max:1,value:0.5};this.value=-1}function y(){this.size=[160,26];this.addInput("","number");this.properties={min:0,max:1,value:0,color:"#AAF"}}function u(){this.addInputs("",0);this.properties={value:"...",font:"Arial",fontsize:18,color:"#AAA",align:"left",glowSize:0,decimals:1}}function v(){this.size=[200,100];this.properties={borderColor:"#ffffff",bgcolorTop:"#f0f0f0",bgcolorBottom:"#e0e0e0",shadowSize:2,borderRadius:3}}var z=w.LiteGraph;c.title="Button";
|
||||
c.desc="Triggers an event";c.font="Arial";c.prototype.onDrawForeground=function(e){if(!this.flags.collapsed&&(e.fillStyle="black",e.fillRect(11,11,this.size[0]-20,this.size[1]-20),e.fillStyle="#AAF",e.fillRect(9,9,this.size[0]-20,this.size[1]-20),e.fillStyle=this.clicked?"white":this.mouseOver?"#668":"#334",e.fillRect(10,10,this.size[0]-20,this.size[1]-20),this.properties.text||0===this.properties.text)){var f=this.properties.font_size||30;e.textAlign="center";e.fillStyle=this.clicked?"black":"white";
|
||||
e.font=f+"px "+c.font;e.fillText(this.properties.text,0.5*this.size[0],0.5*this.size[1]+0.3*f);e.textAlign="left"}};c.prototype.onMouseDown=function(c,f){if(1<f[0]&&1<f[1]&&f[0]<this.size[0]-2&&f[1]<this.size[1]-2)return this.clicked=!0,this.triggerSlot(0,this.properties.message),!0};c.prototype.onExecute=function(){this.setOutputData(1,this.clicked)};c.prototype.onMouseUp=function(c){this.clicked=!1};z.registerNodeType("widget/button",c);r.title="Toggle";r.desc="Toggles between true or false";r.prototype.onDrawForeground=
|
||||
function(c){if(!this.flags.collapsed){var f=0.5*this.size[1],g=0.8*this.size[1];c.font=this.properties.font||(0.8*f).toFixed(0)+"px Arial";var m=c.measureText(this.title).width,m=0.5*(this.size[0]-(m+f));c.fillStyle="#AAA";c.fillRect(m,g-f,f,f);c.fillStyle=this.properties.value?"#AEF":"#000";c.fillRect(m+0.25*f,g-f+0.25*f,0.5*f,0.5*f);c.textAlign="left";c.fillStyle="#AAA";c.fillText(this.title,1.2*f+m,0.85*g);c.textAlign="left"}};r.prototype.onAction=function(c){this.properties.value=!this.properties.value;
|
||||
this.trigger("e",this.properties.value)};r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c);this.setOutputData(0,this.properties.value)};r.prototype.onMouseDown=function(c,f){if(1<f[0]&&1<f[1]&&f[0]<this.size[0]-2&&f[1]<this.size[1]-2)return this.properties.value=!this.properties.value,this.graph._version++,this.trigger("e",this.properties.value),!0};z.registerNodeType("widget/toggle",r);l.title="Number";l.desc="Widget to select number value";l.pixels_threshold=
|
||||
e.font=f+"px "+c.font;e.fillText(this.properties.text,0.5*this.size[0],0.5*this.size[1]+0.3*f);e.textAlign="left"}};c.prototype.onMouseDown=function(c,f){if(1<f[0]&&1<f[1]&&f[0]<this.size[0]-2&&f[1]<this.size[1]-2)return this.clicked=!0,this.triggerSlot(0,this.properties.message),!0};c.prototype.onExecute=function(){this.setOutputData(1,this.clicked)};c.prototype.onMouseUp=function(c){this.clicked=!1};z.registerNodeType("widget/button",c);s.title="Toggle";s.desc="Toggles between true or false";s.prototype.onDrawForeground=
|
||||
function(c){if(!this.flags.collapsed){var f=0.5*this.size[1],g=0.8*this.size[1];c.font=this.properties.font||(0.8*f).toFixed(0)+"px Arial";var m=c.measureText(this.title).width,m=0.5*(this.size[0]-(m+f));c.fillStyle="#AAA";c.fillRect(m,g-f,f,f);c.fillStyle=this.properties.value?"#AEF":"#000";c.fillRect(m+0.25*f,g-f+0.25*f,0.5*f,0.5*f);c.textAlign="left";c.fillStyle="#AAA";c.fillText(this.title,1.2*f+m,0.85*g);c.textAlign="left"}};s.prototype.onAction=function(c){this.properties.value=!this.properties.value;
|
||||
this.trigger("e",this.properties.value)};s.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c);this.setOutputData(0,this.properties.value)};s.prototype.onMouseDown=function(c,f){if(1<f[0]&&1<f[1]&&f[0]<this.size[0]-2&&f[1]<this.size[1]-2)return this.properties.value=!this.properties.value,this.graph._version++,this.trigger("e",this.properties.value),!0};z.registerNodeType("widget/toggle",s);l.title="Number";l.desc="Widget to select number value";l.pixels_threshold=
|
||||
10;l.markers_color="#666";l.prototype.onDrawForeground=function(c){var f=0.5*this.size[0],g=this.size[1];30<g?(c.fillStyle=l.markers_color,c.beginPath(),c.moveTo(f,0.1*g),c.lineTo(f+0.1*g,0.2*g),c.lineTo(f+-0.1*g,0.2*g),c.fill(),c.beginPath(),c.moveTo(f,0.9*g),c.lineTo(f+0.1*g,0.8*g),c.lineTo(f+-0.1*g,0.8*g),c.fill(),c.font=(0.7*g).toFixed(1)+"px Arial"):c.font=(0.8*g).toFixed(1)+"px Arial";c.textAlign="center";c.font=(0.7*g).toFixed(1)+"px Arial";c.fillStyle="#EEE";c.fillText(this.properties.value.toFixed(this._precision),
|
||||
f,0.75*g)};l.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};l.prototype.onPropertyChanged=function(c,f){var g=(this.properties.step+"").split(".");this._precision=1<g.length?g[1].length:0};l.prototype.onMouseDown=function(c,f){if(!(0>f[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};l.prototype.onMouseMove=function(c){if(this.mouse_captured){var f=this.old_y-c.canvasY;c.shiftKey&&(f*=10);if(c.metaKey||c.altKey)f*=0.1;this.old_y=c.canvasY;
|
||||
c=this._remainder+f/l.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+(c|0)*this.properties.step,this.properties.min,this.properties.max);this.properties.value=c;this.graph._version++;this.setDirtyCanvas(!0)}};l.prototype.onMouseUp=function(c,f){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(f[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.graph._version++,this.setDirtyCanvas(!0));this.mouse_captured&&
|
||||
@@ -286,7 +286,7 @@ c=this._remainder+f/l.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.pro
|
||||
c.beginPath();c.moveTo(0,0);c.arc(0,0,m,0,1.5*Math.PI);c.fill();c.strokeStyle="black";c.fillStyle=this.properties.color;c.lineWidth=2;c.beginPath();c.moveTo(0,0);c.arc(0,0,m-4,0,1.5*Math.PI*Math.max(0.01,this.value));c.closePath();c.fill();c.lineWidth=1;c.globalAlpha=1;c.restore();c.fillStyle="black";c.beginPath();c.arc(f,g,0.75*m,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":this.properties.color;c.beginPath();var k=this.value*Math.PI*1.5+0.75*Math.PI;c.arc(f+Math.cos(k)*m*0.65,g+Math.sin(k)*
|
||||
m*0.65,0.05*m,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";c.font=Math.floor(0.5*m)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision),f,g+0.15*m)}};f.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=z.colorToString([this.value,this.value,this.value])};f.prototype.onMouseDown=function(c){this.center=[0.5*this.size[0],0.5*this.size[1]+20];this.radius=0.5*this.size[0];if(20>c.canvasY-this.pos[1]||
|
||||
z.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};f.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var f=this.value,f=f-0.01*(c[1]-this.oldmouse[1]);1<f?f=1:0>f&&(f=0);this.value=f;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};
|
||||
f.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};f.prototype.onPropertyChanged=function(c,f){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(f),!0};z.registerNodeType("widget/knob",f);s.title="Inner Slider";s.prototype.onPropertyChanged=function(c,f){"value"==c&&(this.slider.value=f)};s.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};z.registerNodeType("widget/internal_slider",s);k.title="H.Slider";k.desc=
|
||||
f.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};f.prototype.onPropertyChanged=function(c,f){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(f),!0};z.registerNodeType("widget/knob",f);r.title="Inner Slider";r.prototype.onPropertyChanged=function(c,f){"value"==c&&(this.slider.value=f)};r.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};z.registerNodeType("widget/internal_slider",r);k.title="H.Slider";k.desc=
|
||||
"Linear slider controller";k.prototype.onDrawForeground=function(c){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min));c.globalAlpha=1;c.lineWidth=1;c.fillStyle="#000";c.fillRect(2,2,this.size[0]-4,this.size[1]-4);c.fillStyle=this.properties.color;c.beginPath();c.rect(4,4,(this.size[0]-8)*this.value,this.size[1]-8);c.fill()};k.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*
|
||||
this.value;this.setOutputData(0,this.properties.value);this.boxcolor=z.colorToString([this.value,this.value,this.value])};k.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};k.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var f=this.value,f=f+(c[0]-this.oldmouse[0])/this.size[0];1<f?f=1:0>f&&(f=0);this.value=f;this.oldmouse=c;this.setDirtyCanvas(!0)}};
|
||||
k.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};k.prototype.onMouseLeave=function(c){};z.registerNodeType("widget/hslider",k);y.title="Progress";y.desc="Shows data in linear progress";y.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};y.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.color;var f=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),f=Math.min(1,
|
||||
@@ -295,18 +295,18 @@ f),f=Math.max(0,f);c.fillRect(2,2,(this.size[0]-4)*f,this.size[1]-4)};z.register
|
||||
this.getInputData(0);null!=c&&(this.properties.value=c)};u.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var f=0,g;for(g in c){var m=this.last_ctx.measureText(c[g]).width;f<m&&(f=m)}this.size[0]=f+20;this.size[1]=4+c.length*this.properties.fontsize;this.setDirtyCanvas(!0)}};u.prototype.onPropertyChanged=function(c,f){this.properties[c]=f;this.str="number"==typeof f?f.toFixed(3):f;return!0};z.registerNodeType("widget/text",
|
||||
u);v.title="Panel";v.desc="Non interactive panel";v.widgets=[{name:"update",text:"Update",type:"button"}];v.prototype.createGradient=function(c){""==this.properties.bgcolorTop||""==this.properties.bgcolorBottom?this.lineargradient=0:(this.lineargradient=c.createLinearGradient(0,0,0,this.size[1]),this.lineargradient.addColorStop(0,this.properties.bgcolorTop),this.lineargradient.addColorStop(1,this.properties.bgcolorBottom))};v.prototype.onDrawForeground=function(c){this.flags.collapsed||(null==this.lineargradient&&
|
||||
this.createGradient(c),this.lineargradient&&(c.lineWidth=1,c.strokeStyle=this.properties.borderColor,c.fillStyle=this.lineargradient,this.properties.shadowSize?(c.shadowColor="#000",c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.shadowSize):c.shadowColor="transparent",c.roundRect(0,0,this.size[0]-1,this.size[1]-1,this.properties.shadowSize),c.fill(),c.shadowColor="transparent",c.stroke()))};z.registerNodeType("widget/panel",v)})(this);
|
||||
(function(w){function c(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",r.EVENT);this.properties={gamepad_index:0,threshold:0.1};this._left_axis=new Float32Array(2);this._right_axis=new Float32Array(2);this._triggers=new Float32Array(2);this._previous_buttons=new Uint8Array(17);this._current_buttons=new Uint8Array(17)}var r=w.LiteGraph;c.title="Gamepad";c.desc="gets the input of the gamepad";c.CENTER=0;c.LEFT=1;c.RIGHT=2;c.UP=4;c.DOWN=
|
||||
(function(w){function c(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",s.EVENT);this.properties={gamepad_index:0,threshold:0.1};this._left_axis=new Float32Array(2);this._right_axis=new Float32Array(2);this._triggers=new Float32Array(2);this._previous_buttons=new Uint8Array(17);this._current_buttons=new Uint8Array(17)}var s=w.LiteGraph;c.title="Gamepad";c.desc="gets the input of the gamepad";c.CENTER=0;c.LEFT=1;c.RIGHT=2;c.UP=4;c.DOWN=
|
||||
8;c.zero=new Float32Array(2);c.buttons="a b x y lb rb lt rt back start ls rs home".split(" ");c.prototype.onExecute=function(){var l=this.getGamepad(),f=this.properties.threshold||0;l&&(this._left_axis[0]=Math.abs(l.xbox.axes.lx)>f?l.xbox.axes.lx:0,this._left_axis[1]=Math.abs(l.xbox.axes.ly)>f?l.xbox.axes.ly:0,this._right_axis[0]=Math.abs(l.xbox.axes.rx)>f?l.xbox.axes.rx:0,this._right_axis[1]=Math.abs(l.xbox.axes.ry)>f?l.xbox.axes.ry:0,this._triggers[0]=Math.abs(l.xbox.axes.ltrigger)>f?l.xbox.axes.ltrigger:
|
||||
0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>f?l.xbox.axes.rtrigger:0);if(this.outputs)for(f=0;f<this.outputs.length;f++){var s=this.outputs[f];if(s.links&&s.links.length){var k=null;if(l)switch(s.name){case "left_axis":k=this._left_axis;break;case "right_axis":k=this._right_axis;break;case "left_x_axis":k=this._left_axis[0];break;case "left_y_axis":k=this._left_axis[1];break;case "right_x_axis":k=this._right_axis[0];break;case "right_y_axis":k=this._right_axis[1];break;case "trigger_left":k=
|
||||
0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>f?l.xbox.axes.rtrigger:0);if(this.outputs)for(f=0;f<this.outputs.length;f++){var r=this.outputs[f];if(r.links&&r.links.length){var k=null;if(l)switch(r.name){case "left_axis":k=this._left_axis;break;case "right_axis":k=this._right_axis;break;case "left_x_axis":k=this._left_axis[0];break;case "left_y_axis":k=this._left_axis[1];break;case "right_x_axis":k=this._right_axis[0];break;case "right_y_axis":k=this._right_axis[1];break;case "trigger_left":k=
|
||||
this._triggers[0];break;case "trigger_right":k=this._triggers[1];break;case "a_button":k=l.xbox.buttons.a?1:0;break;case "b_button":k=l.xbox.buttons.b?1:0;break;case "x_button":k=l.xbox.buttons.x?1:0;break;case "y_button":k=l.xbox.buttons.y?1:0;break;case "lb_button":k=l.xbox.buttons.lb?1:0;break;case "rb_button":k=l.xbox.buttons.rb?1:0;break;case "ls_button":k=l.xbox.buttons.ls?1:0;break;case "rs_button":k=l.xbox.buttons.rs?1:0;break;case "hat_left":k=l.xbox.hatmap&c.LEFT;break;case "hat_right":k=
|
||||
l.xbox.hatmap&c.RIGHT;break;case "hat_up":k=l.xbox.hatmap&c.UP;break;case "hat_down":k=l.xbox.hatmap&c.DOWN;break;case "hat":k=l.xbox.hatmap;break;case "start_button":k=l.xbox.buttons.start?1:0;break;case "back_button":k=l.xbox.buttons.back?1:0;break;case "button_pressed":for(s=0;s<this._current_buttons.length;++s)this._current_buttons[s]&&!this._previous_buttons[s]&&this.triggerSlot(f,c.buttons[s])}else switch(s.name){case "button_pressed":break;case "left_axis":case "right_axis":k=c.zero;break;
|
||||
l.xbox.hatmap&c.RIGHT;break;case "hat_up":k=l.xbox.hatmap&c.UP;break;case "hat_down":k=l.xbox.hatmap&c.DOWN;break;case "hat":k=l.xbox.hatmap;break;case "start_button":k=l.xbox.buttons.start?1:0;break;case "back_button":k=l.xbox.buttons.back?1:0;break;case "button_pressed":for(r=0;r<this._current_buttons.length;++r)this._current_buttons[r]&&!this._previous_buttons[r]&&this.triggerSlot(f,c.buttons[r])}else switch(r.name){case "button_pressed":break;case "left_axis":case "right_axis":k=c.zero;break;
|
||||
default:k=0}this.setOutputData(f,k)}}};c.mapping={a:0,b:1,x:2,y:3,lb:4,rb:5,lt:6,rt:7,back:8,start:9,ls:10,rs:11};c.mapping_array="a b x y lb rb lt rt back start ls rs".split(" ");c.prototype.getGamepad=function(){var l=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!l)return null;var f=l.call(navigator),l=null;this._previous_buttons.set(this._current_buttons);for(l=this.properties.gamepad_index;4>l;l++)if(f[l]){l=f[l];f=this.xbox_mapping;f||(f=this.xbox_mapping={axes:[],
|
||||
buttons:{},hat:"",hatmap:c.CENTER});f.axes.lx=l.axes[0];f.axes.ly=l.axes[1];f.axes.rx=l.axes[2];f.axes.ry=l.axes[3];f.axes.ltrigger=l.buttons[6].value;f.axes.rtrigger=l.buttons[7].value;f.hat="";f.hatmap=c.CENTER;for(var s=0;s<l.buttons.length;s++)if(this._current_buttons[s]=l.buttons[s].pressed,12>s)f.buttons[c.mapping_array[s]]=l.buttons[s].pressed,l.buttons[s].was_pressed&&this.trigger(c.mapping_array[s]+"_button_event");else switch(s){case 12:l.buttons[s].pressed&&(f.hat+="up",f.hatmap|=c.UP);
|
||||
break;case 13:l.buttons[s].pressed&&(f.hat+="down",f.hatmap|=c.DOWN);break;case 14:l.buttons[s].pressed&&(f.hat+="left",f.hatmap|=c.LEFT);break;case 15:l.buttons[s].pressed&&(f.hat+="right",f.hatmap|=c.RIGHT);break;case 16:f.buttons.home=l.buttons[s].pressed}l.xbox=f;return l}};c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var f=this._left_axis,s=this._right_axis;c.strokeStyle="#88A";c.strokeRect(0.5*(f[0]+1)*this.size[0]-4,0.5*(f[1]+1)*this.size[1]-4,8,8);c.strokeStyle="#8A8";
|
||||
c.strokeRect(0.5*(s[0]+1)*this.size[0]-4,0.5*(s[1]+1)*this.size[1]-4,8,8);f=this.size[1]/this._current_buttons.length;c.fillStyle="#AEB";for(s=0;s<this._current_buttons.length;++s)this._current_buttons[s]&&c.fillRect(0,f*s,6,f)}};c.prototype.onGetOutputs=function(){return[["left_axis","vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button",
|
||||
"number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start_button","number"],["back_button","number"],["a_button_event",r.EVENT],["b_button_event",r.EVENT],["x_button_event",r.EVENT],["y_button_event",r.EVENT],["lb_button_event",r.EVENT],["rb_button_event",r.EVENT],["ls_button_event",r.EVENT],["rs_button_event",r.EVENT],["start_button_event",r.EVENT],["back_button_event",r.EVENT],["hat_left","number"],["hat_right",
|
||||
"number"],["hat_up","number"],["hat_down","number"],["hat","number"],["button_pressed",r.EVENT]]};r.registerNodeType("input/gamepad",c)})(this);
|
||||
(function(w){function c(){this.addInput("in","*");this.size=[80,30]}function r(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function l(){this.addInput("in");this.addOutput("out")}function f(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",1);this.size=[80,30]}function s(){this.addOutput("value","number");this.addProperty("min",
|
||||
buttons:{},hat:"",hatmap:c.CENTER});f.axes.lx=l.axes[0];f.axes.ly=l.axes[1];f.axes.rx=l.axes[2];f.axes.ry=l.axes[3];f.axes.ltrigger=l.buttons[6].value;f.axes.rtrigger=l.buttons[7].value;f.hat="";f.hatmap=c.CENTER;for(var r=0;r<l.buttons.length;r++)if(this._current_buttons[r]=l.buttons[r].pressed,12>r)f.buttons[c.mapping_array[r]]=l.buttons[r].pressed,l.buttons[r].was_pressed&&this.trigger(c.mapping_array[r]+"_button_event");else switch(r){case 12:l.buttons[r].pressed&&(f.hat+="up",f.hatmap|=c.UP);
|
||||
break;case 13:l.buttons[r].pressed&&(f.hat+="down",f.hatmap|=c.DOWN);break;case 14:l.buttons[r].pressed&&(f.hat+="left",f.hatmap|=c.LEFT);break;case 15:l.buttons[r].pressed&&(f.hat+="right",f.hatmap|=c.RIGHT);break;case 16:f.buttons.home=l.buttons[r].pressed}l.xbox=f;return l}};c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var f=this._left_axis,r=this._right_axis;c.strokeStyle="#88A";c.strokeRect(0.5*(f[0]+1)*this.size[0]-4,0.5*(f[1]+1)*this.size[1]-4,8,8);c.strokeStyle="#8A8";
|
||||
c.strokeRect(0.5*(r[0]+1)*this.size[0]-4,0.5*(r[1]+1)*this.size[1]-4,8,8);f=this.size[1]/this._current_buttons.length;c.fillStyle="#AEB";for(r=0;r<this._current_buttons.length;++r)this._current_buttons[r]&&c.fillRect(0,f*r,6,f)}};c.prototype.onGetOutputs=function(){return[["left_axis","vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button",
|
||||
"number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start_button","number"],["back_button","number"],["a_button_event",s.EVENT],["b_button_event",s.EVENT],["x_button_event",s.EVENT],["y_button_event",s.EVENT],["lb_button_event",s.EVENT],["rb_button_event",s.EVENT],["ls_button_event",s.EVENT],["rs_button_event",s.EVENT],["start_button_event",s.EVENT],["back_button_event",s.EVENT],["hat_left","number"],["hat_right",
|
||||
"number"],["hat_up","number"],["hat_down","number"],["hat","number"],["button_pressed",s.EVENT]]};s.registerNodeType("input/gamepad",c)})(this);
|
||||
(function(w){function c(){this.addInput("in","*");this.size=[80,30]}function s(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function l(){this.addInput("in");this.addOutput("out")}function f(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",1);this.size=[80,30]}function r(){this.addOutput("value","number");this.addProperty("min",
|
||||
0);this.addProperty("max",1);this.size=[80,30]}function k(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("min",0);this.addProperty("max",1);this.addProperty("smooth",!0);this.size=[90,30]}function y(){this.addOutput("out","number");this.addProperty("min_time",1);this.addProperty("max_time",2);this.addProperty("duration",0.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function u(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,
|
||||
30];this.addProperty("min",0);this.addProperty("max",1)}function v(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function z(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function e(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function x(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function g(){this.addInput("in","number");this.addOutput("out",
|
||||
"number");this.size=[80,30];this.properties={A:0,B:1}}function m(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function C(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}function h(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function q(){this.addInput("in",
|
||||
@@ -315,11 +315,11 @@ c.strokeRect(0.5*(s[0]+1)*this.size[0]-4,0.5*(s[1]+1)*this.size[1]-4,8,8);f=this
|
||||
"nodes/imgs/icon-sin.png"}function n(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,d){d.properties.formula=a});this.addWidget("toggle","allow",B.allow_scripts,function(a){B.allow_scripts=a});this._func=null}function K(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function E(){this.addInputs([["x",
|
||||
"number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function G(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function H(){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 F(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");
|
||||
this.addOutput("z","number");this.addOutput("w","number")}function I(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var B=w.LiteGraph;c.title="Converter";c.desc="type A to type B";c.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var d=this.outputs[b];if(d.links&&d.links.length){var c=null;switch(d.name){case "number":c=
|
||||
a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":c=1;switch(d.name){case "vec2":c=2;break;case "vec3":c=3;break;case "vec4":c=4}c=new Float32Array(c);if(a.length)for(d=0;d<a.length&&d<c.length;d++)c[d]=a[d];else c[0]=parseFloat(a)}this.setOutputData(b,c)}}};c.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};B.registerNodeType("math/converter",c);r.title="Bypass";r.desc="removes the type";r.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0);this.setOutputData(0,a)};B.registerNodeType("math/bypass",r);l.title="to Number";l.desc="Cast to number";l.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,Number(a))};B.registerNodeType("math/to_number",l);f.title="Range";f.desc="Convert a number from one range to another";f.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};f.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=
|
||||
a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":c=1;switch(d.name){case "vec2":c=2;break;case "vec3":c=3;break;case "vec4":c=4}c=new Float32Array(c);if(a.length)for(d=0;d<a.length&&d<c.length;d++)c[d]=a[d];else c[0]=parseFloat(a)}this.setOutputData(b,c)}}};c.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};B.registerNodeType("math/converter",c);s.title="Bypass";s.desc="removes the type";s.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0);this.setOutputData(0,a)};B.registerNodeType("math/bypass",s);l.title="to Number";l.desc="Cast to number";l.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,Number(a))};B.registerNodeType("math/to_number",l);f.title="Range";f.desc="Convert a number from one range to another";f.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};f.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=
|
||||
this.inputs[a],d=this.getInputData(a);void 0!==d&&(this.properties[b.name]=d)}d=this.properties["in"];if(void 0===d||null===d||d.constructor!==Number)d=0;a=this.properties.in_min;b=this.properties.out_min;this._last_v=(d-a)/(this.properties.in_max-a)*(this.properties.out_max-b)+b;this.setOutputData(0,this._last_v)};f.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};f.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],
|
||||
["out_min","number"],["out_max","number"]]};B.registerNodeType("math/range",f);s.title="Rand";s.desc="Random number";s.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],d=this.getInputData(a);void 0!==d&&(this.properties[b.name]=d)}a=this.properties.min;b=this.properties.max;this._last_v=Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};s.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};s.prototype.onGetInputs=
|
||||
function(){return[["min","number"],["max","number"]]};B.registerNodeType("math/rand",s);k.title="Noise";k.desc="Random number with temporal continuity";k.data=null;k.getValue=function(a,b){if(!k.data){k.data=new Float32Array(1024);for(var d=0;d<k.data.length;++d)k.data[d]=Math.random()}a%=1024;0>a&&(a+=1024);var c=Math.floor(a);a-=c;d=k.data[c];c=k.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return d*(1-a)+c*a};k.prototype.onExecute=function(){var a=this.getInputData(0)||0,a=k.getValue(a,this.properties.smooth),
|
||||
["out_min","number"],["out_max","number"]]};B.registerNodeType("math/range",f);r.title="Rand";r.desc="Random number";r.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],d=this.getInputData(a);void 0!==d&&(this.properties[b.name]=d)}a=this.properties.min;b=this.properties.max;this._last_v=Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};r.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};r.prototype.onGetInputs=
|
||||
function(){return[["min","number"],["max","number"]]};B.registerNodeType("math/rand",r);k.title="Noise";k.desc="Random number with temporal continuity";k.data=null;k.getValue=function(a,b){if(!k.data){k.data=new Float32Array(1024);for(var d=0;d<k.data.length;++d)k.data[d]=Math.random()}a%=1024;0>a&&(a+=1024);var c=Math.floor(a);a-=c;d=k.data[c];c=k.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return d*(1-a)+c*a};k.prototype.onExecute=function(){var a=this.getInputData(0)||0,a=k.getValue(a,this.properties.smooth),
|
||||
b=this.properties.min;this._last_v=a*(this.properties.max-b)+b;this.setOutputData(0,this._last_v)};k.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};B.registerNodeType("math/noise",k);y.title="Spikes";y.desc="spike every random time";y.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0<this._blink_time&&(a=1/(Math.pow(this._blink_time/this.properties.duration*8-4,4)+1));0>this._remaining_time?(this._remaining_time=
|
||||
Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};B.registerNodeType("math/spikes",y);u.title="Clamp";u.desc="Clamp number between min and max";u.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))};u.prototype.getCode=function(a){a="";this.isInputConnected(0)&&
|
||||
(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};B.registerNodeType("math/clamp",u);v.title="Lerp";v.desc="Linear Interpolation";v.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);null==b&&(b=0);var d=this.properties.f,c=this.getInputData(2);void 0!==c&&(d=c);this.setOutputData(0,a*(1-d)+b*d)};v.prototype.onGetInputs=function(){return[["f","number"]]};B.registerNodeType("math/lerp",v);z.title="Abs";z.desc="Absolute";z.prototype.onExecute=
|
||||
@@ -347,13 +347,13 @@ a[3]))};B.registerNodeType("math3d/vec4-to-xyzw",F);I.title="XYZW->Vec4";I.desc=
|
||||
"rotate a point",w.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))},B.registerNodeType("math3d/rotate_vec3",w),w=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},w.title="Mult. Quat",w.desc="rotate quaternion",w.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))}},B.registerNodeType("math3d/mult-quat",w),w=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},w.title="Quat Slerp",w.desc="quaternion spherical interpolation",w.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);if(null!=b){var d=this.properties.factor;
|
||||
null!=this.getInputData(2)&&(d=this.getInputData(2));a=quat.slerp(this._value,a,b,d);this.setOutputData(0,a)}}},B.registerNodeType("math3d/quat-slerp",w))})(this);
|
||||
(function(w){function c(){this.addInput("A","number,vec3");this.addInput("B","number,vec3");this.addOutput("=","vec3");this.addProperty("OP","+","enum",{values:c.values});this._result=vec3.create()}function r(){this.addInput("in","vec3");this.addInput("f","number");this.addOutput("out","vec3");this.properties={f:1};this._data=new Float32Array(3)}function l(){this.addInput("in","vec3");this.addOutput("out","number")}function f(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}
|
||||
function s(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:0.5};this._data=new Float32Array(3)}function k(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out","number")}var y=w.LiteGraph;c.values="+ - * / % ^ max min".split(" ");c.title="Operation";c.desc="Easy math 3D operators";c["@OP"]={type:"enum",title:"operation",values:c.values};c.size=[100,60];c.prototype.getTitle=function(){return"max"==
|
||||
(function(w){function c(){this.addInput("A","number,vec3");this.addInput("B","number,vec3");this.addOutput("=","vec3");this.addProperty("OP","+","enum",{values:c.values});this._result=vec3.create()}function s(){this.addInput("in","vec3");this.addInput("f","number");this.addOutput("out","vec3");this.properties={f:1};this._data=new Float32Array(3)}function l(){this.addInput("in","vec3");this.addOutput("out","number")}function f(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}
|
||||
function r(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:0.5};this._data=new Float32Array(3)}function k(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out","number")}var y=w.LiteGraph;c.values="+ - * / % ^ max min".split(" ");c.title="Operation";c.desc="Easy math 3D operators";c["@OP"]={type:"enum",title:"operation",values:c.values};c.size=[100,60];c.prototype.getTitle=function(){return"max"==
|
||||
this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};c.prototype.onExecute=function(){var c=this.getInputData(0),f=this.getInputData(1);if(null!=c&&null!=f){c.constructor===Number&&(c=[c,c,c]);f.constructor===Number&&(f=[f,f,f]);var k=this._result;switch(this.properties.OP){case "+":k=vec3.add(k,c,f);break;case "-":k=vec3.sub(k,c,f);break;case "x":case "X":case "*":k=vec3.mul(k,c,f);break;case "/":k=vec3.div(k,c,f);break;case "%":k[0]=c[0]%f[0];k[1]=
|
||||
c[1]%f[1];k[2]=c[2]%f[2];break;case "^":k[0]=Math.pow(c[0],f[0]);k[1]=Math.pow(c[1],f[1]);k[2]=Math.pow(c[2],f[2]);break;case "max":k[0]=Math.max(c[0],f[0]);k[1]=Math.max(c[1],f[1]);k[2]=Math.max(c[2],f[2]);break;case "min":k[0]=Math.min(c[0],f[0]);k[1]=Math.min(c[1],f[1]);k[2]=Math.min(c[2],f[2]);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,k)}};c.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.font="40px Arial",c.fillStyle="#666",c.textAlign=
|
||||
"center",c.fillText(this.properties.OP,0.5*this.size[0],0.5*(this.size[1]+y.NODE_TITLE_HEIGHT)),c.textAlign="left")};y.registerNodeType("math3d/operation",c);r.title="vec3_scale";r.desc="scales the components of a vec3";r.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=this.getInputData(1);null==f&&(f=this.properties.f);var k=this._data;k[0]=c[0]*f;k[1]=c[1]*f;k[2]=c[2]*f;this.setOutputData(0,k)}};y.registerNodeType("math3d/vec3-scale",r);l.title="vec3_length";l.desc="returns the module of a vector";
|
||||
l.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(c=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),this.setOutputData(0,c))};y.registerNodeType("math3d/vec3-length",l);f.title="vec3_normalize";f.desc="returns the vector normalized";f.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),k=this._data;k[0]=c[0]/f;k[1]=c[1]/f;k[2]=c[2]/f;this.setOutputData(0,k)}};y.registerNodeType("math3d/vec3-normalize",f);s.title="vec3_lerp";
|
||||
s.desc="returns the interpolated vector";s.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=this.getInputData(1);if(null!=f){var k=this.getInputOrProperty("f"),e=this._data;e[0]=c[0]*(1-k)+f[0]*k;e[1]=c[1]*(1-k)+f[1]*k;e[2]=c[2]*(1-k)+f[2]*k;this.setOutputData(0,e)}}};y.registerNodeType("math3d/vec3-lerp",s);k.title="vec3_dot";k.desc="returns the dot product";k.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=this.getInputData(1);null!=f&&this.setOutputData(0,
|
||||
"center",c.fillText(this.properties.OP,0.5*this.size[0],0.5*(this.size[1]+y.NODE_TITLE_HEIGHT)),c.textAlign="left")};y.registerNodeType("math3d/operation",c);s.title="vec3_scale";s.desc="scales the components of a vec3";s.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=this.getInputData(1);null==f&&(f=this.properties.f);var k=this._data;k[0]=c[0]*f;k[1]=c[1]*f;k[2]=c[2]*f;this.setOutputData(0,k)}};y.registerNodeType("math3d/vec3-scale",s);l.title="vec3_length";l.desc="returns the module of a vector";
|
||||
l.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(c=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),this.setOutputData(0,c))};y.registerNodeType("math3d/vec3-length",l);f.title="vec3_normalize";f.desc="returns the vector normalized";f.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),k=this._data;k[0]=c[0]/f;k[1]=c[1]/f;k[2]=c[2]/f;this.setOutputData(0,k)}};y.registerNodeType("math3d/vec3-normalize",f);r.title="vec3_lerp";
|
||||
r.desc="returns the interpolated vector";r.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=this.getInputData(1);if(null!=f){var k=this.getInputOrProperty("f"),e=this._data;e[0]=c[0]*(1-k)+f[0]*k;e[1]=c[1]*(1-k)+f[1]*k;e[2]=c[2]*(1-k)+f[2]*k;this.setOutputData(0,e)}}};y.registerNodeType("math3d/vec3-lerp",r);k.title="vec3_dot";k.desc="returns the dot product";k.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=this.getInputData(1);null!=f&&this.setOutputData(0,
|
||||
c[0]*f[0]+c[1]*f[1]+c[2]*f[2])}};y.registerNodeType("math3d/vec3-dot",k);w.glMatrix?(w=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1,normalize:!1};this._value=quat.create()},w.title="Quaternion",w.desc="quaternion",w.prototype.onExecute=function(){this._value[0]=this.getInputOrProperty("x");this._value[1]=this.getInputOrProperty("y");this._value[2]=this.getInputOrProperty("z");this._value[3]=this.getInputOrProperty("w");this.properties.normalize&&quat.normalize(this._value,
|
||||
this._value);this.setOutputData(0,this._value)},w.prototype.onGetInputs=function(){return[["x","number"],["y","number"],["z","number"],["w","number"]]},y.registerNodeType("math3d/quaternion",w),w=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()},w.title="Rotation",w.desc="quaternion rotation",w.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.angle);
|
||||
var f=this.getInputData(1);null==f&&(f=this.properties.axis);c=quat.setAxisAngle(this._value,f,0.0174532925*c);this.setOutputData(0,c)},y.registerNodeType("math3d/rotation",w),w=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},w.title="Rot. Vec3",w.desc="rotate a point",w.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.vec);var f=this.getInputData(1);null==f?this.setOutputData(c):this.setOutputData(0,
|
||||
@@ -361,24 +361,24 @@ vec3.transformQuat(vec3.create(),c,f))},y.registerNodeType("math3d/rotate_vec3",
|
||||
"quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},w.title="Quat Slerp",w.desc="quaternion spherical interpolation",w.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var f=this.getInputData(1);if(null!=f){var k=this.properties.factor;null!=this.getInputData(2)&&(k=this.getInputData(2));c=quat.slerp(this._value,c,f,k);this.setOutputData(0,c)}}},y.registerNodeType("math3d/quat-slerp",w),w=function(){this.addInput("vec3",
|
||||
"vec3");this.addOutput("remap","vec3");this.addOutput("clamped","vec3");this.properties={clamp:!0,range_min:[-1,-1,0],range_max:[1,1,0],target_min:[-1,-1,0],target_max:[1,1,0]};this._value=vec3.create();this._clamped=vec3.create()},w.title="Remap Range",w.desc="remap a 3D range",w.prototype.onExecute=function(){var c=this.getInputData(0);c&&this._value.set(c);for(var c=this.properties.range_min,f=this.properties.range_max,k=this.properties.target_min,e=this.properties.target_max,l=0;3>l;++l){var g=
|
||||
f[l]-c[l];this._clamped[l]=Math.clamp(this._value[l],c[l],f[l]);0==g?this._value[l]=0.5*(k[l]+e[l]):(g=(this._value[l]-c[l])/g,this.properties.clamp&&(g=Math.clamp(g,0,1)),this._value[l]=k[l]+g*(e[l]-k[l]))}this.setOutputData(0,this._value);this.setOutputData(1,this._clamped)},y.registerNodeType("math3d/remap_range",w)):console.warn("No glmatrix found, some Math3D nodes may not work")})(this);
|
||||
(function(w){function c(c,f){return c==f}function r(c){return null!=c&&c.constructor===String?c.toUpperCase():c}w=w.LiteGraph;w.wrapFunctionAsNode("string/toString",c,["*"],"String");w.wrapFunctionAsNode("string/compare",c,["String","String"],"Boolean");w.wrapFunctionAsNode("string/concatenate",function(c,f){return void 0===c?f:void 0===f?c:c+f},["String","String"],"String");w.wrapFunctionAsNode("string/contains",function(c,f){return void 0===c||void 0===f?!1:-1!=c.indexOf(f)},["String","String"],
|
||||
"Boolean");w.wrapFunctionAsNode("string/toUpperCase",r,["String"],"String");w.wrapFunctionAsNode("string/split",r,["String","String"],"Array");w.wrapFunctionAsNode("string/toFixed",function(c){return null!=c&&c.constructor===Number?c.toFixed(this.properties.precision):c},["Number"],"String",{precision:0})})(this);
|
||||
(function(w){function c(){this.addInput("sel","number");this.addInput("A");this.addInput("B");this.addInput("C");this.addInput("D");this.addOutput("out");this.selected=0}function r(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}var l=w.LiteGraph;c.title="Selector";c.desc="selects an output";c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){c.fillStyle="#AFB";
|
||||
var s=(this.selected+1)*l.NODE_SLOT_HEIGHT+6;c.beginPath();c.moveTo(50,s);c.lineTo(50,s+l.NODE_SLOT_HEIGHT);c.lineTo(34,s+0.5*l.NODE_SLOT_HEIGHT);c.fill()}};c.prototype.onExecute=function(){var c=this.getInputData(0);if(null==c||c.constructor!==Number)c=0;this.selected=c=Math.round(c)%(this.inputs.length-1);c=this.getInputData(c+1);void 0!==c&&this.setOutputData(0,c)};c.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};l.registerNodeType("logic/selector",c);r.title="Sequence";
|
||||
r.desc="select one element from a sequence from a string";r.prototype.onPropertyChanged=function(c,l){"sequence"==c&&(this.values=l.split(","))};r.prototype.onExecute=function(){var c=this.getInputData(1);c&&c!=this.current_sequence&&(this.values=c.split(","),this.current_sequence=c);c=this.getInputData(0);null==c&&(c=0);this.index=c=Math.round(c)%this.values.length;this.setOutputData(0,this.values[c])};l.registerNodeType("logic/sequence",r)})(this);
|
||||
(function(w){function c(){this.addInput("A","Number");this.addInput("B","Number");this.addInput("C","Number");this.addInput("D","Number");this.values=[[],[],[],[]];this.properties={scale:2}}function r(){this.addOutput("frame","image");this.properties={url:""}}function l(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function f(){this.addInput("","image,canvas");this.size=[200,200]}function s(){this.addInputs([["img1",
|
||||
(function(w){function c(c,f){return c==f}function s(c){return null!=c&&c.constructor===String?c.toUpperCase():c}w=w.LiteGraph;w.wrapFunctionAsNode("string/toString",c,["*"],"String");w.wrapFunctionAsNode("string/compare",c,["String","String"],"Boolean");w.wrapFunctionAsNode("string/concatenate",function(c,f){return void 0===c?f:void 0===f?c:c+f},["String","String"],"String");w.wrapFunctionAsNode("string/contains",function(c,f){return void 0===c||void 0===f?!1:-1!=c.indexOf(f)},["String","String"],
|
||||
"Boolean");w.wrapFunctionAsNode("string/toUpperCase",s,["String"],"String");w.wrapFunctionAsNode("string/split",s,["String","String"],"Array");w.wrapFunctionAsNode("string/toFixed",function(c){return null!=c&&c.constructor===Number?c.toFixed(this.properties.precision):c},["Number"],"String",{precision:0})})(this);
|
||||
(function(w){function c(){this.addInput("sel","number");this.addInput("A");this.addInput("B");this.addInput("C");this.addInput("D");this.addOutput("out");this.selected=0}function s(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}var l=w.LiteGraph;c.title="Selector";c.desc="selects an output";c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){c.fillStyle="#AFB";
|
||||
var r=(this.selected+1)*l.NODE_SLOT_HEIGHT+6;c.beginPath();c.moveTo(50,r);c.lineTo(50,r+l.NODE_SLOT_HEIGHT);c.lineTo(34,r+0.5*l.NODE_SLOT_HEIGHT);c.fill()}};c.prototype.onExecute=function(){var c=this.getInputData(0);if(null==c||c.constructor!==Number)c=0;this.selected=c=Math.round(c)%(this.inputs.length-1);c=this.getInputData(c+1);void 0!==c&&this.setOutputData(0,c)};c.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};l.registerNodeType("logic/selector",c);s.title="Sequence";
|
||||
s.desc="select one element from a sequence from a string";s.prototype.onPropertyChanged=function(c,l){"sequence"==c&&(this.values=l.split(","))};s.prototype.onExecute=function(){var c=this.getInputData(1);c&&c!=this.current_sequence&&(this.values=c.split(","),this.current_sequence=c);c=this.getInputData(0);null==c&&(c=0);this.index=c=Math.round(c)%this.values.length;this.setOutputData(0,this.values[c])};l.registerNodeType("logic/sequence",s)})(this);
|
||||
(function(w){function c(){this.addInput("A","Number");this.addInput("B","Number");this.addInput("C","Number");this.addInput("D","Number");this.values=[[],[],[],[]];this.properties={scale:2}}function s(){this.addOutput("frame","image");this.properties={url:""}}function l(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function f(){this.addInput("","image,canvas");this.size=[200,200]}function r(){this.addInputs([["img1",
|
||||
"image"],["img2","image"],["fade","number"]]);this.addOutput("","image");this.properties={fade:0.5,width:512,height:512}}function k(){this.addInput("","image");this.addOutput("","image");this.properties={width:256,height:256,x:0,y:0,scale:1};this.size=[50,20]}function y(){this.addInput("clear",x.ACTION);this.addOutput("","canvas");this.properties={width:512,height:512,autoclear:!0};this.canvas=document.createElement("canvas");this.ctx=this.canvas.getContext("2d")}function u(){this.addInput("canvas",
|
||||
"canvas");this.addInput("img","image,canvas");this.addInput("x","number");this.addInput("y","number");this.properties={x:0,y:0,opacity:1}}function v(){this.addInput("canvas","canvas");this.addInput("x","number");this.addInput("y","number");this.addInput("w","number");this.addInput("h","number");this.properties={x:0,y:0,w:10,h:10,color:"white",opacity:1}}function z(){this.addInput("t","number");this.addOutputs([["frame","image"],["t","number"],["d","number"]]);this.properties={url:"",use_proxy:!0}}
|
||||
function e(){this.addOutput("Webcam","image");this.properties={facingMode:"user"};this.boxcolor="black";this.frame=0}var x=w.LiteGraph;c.title="Plot";c.desc="Plots data over time";c.colors=["#FFF","#F99","#9F9","#99F"];c.prototype.onExecute=function(c){if(!this.flags.collapsed){c=this.size;for(var e=0;4>e;++e){var f=this.getInputData(e);if(null!=f){var h=this.values[e];h.push(f);h.length>c[0]&&h.shift()}}}};c.prototype.onDrawBackground=function(e){if(!this.flags.collapsed){var f=this.size,k=0.5*f[1]/
|
||||
this.properties.scale,h=c.colors,q=0.5*f[1];e.fillStyle="#000";e.fillRect(0,0,f[0],f[1]);e.strokeStyle="#555";e.beginPath();e.moveTo(0,q);e.lineTo(f[0],q);e.stroke();if(this.inputs)for(var p=0;4>p;++p){var a=this.values[p];if(this.inputs[p]&&this.inputs[p].link){e.strokeStyle=h[p];e.beginPath();var b=a[0]*k*-1+q;e.moveTo(0,Math.clamp(b,0,f[1]));for(var d=1;d<a.length&&d<f[0];++d)b=a[d]*k*-1+q,e.lineTo(d,Math.clamp(b,0,f[1]));e.stroke()}}}};x.registerNodeType("graphics/plot",c);r.title="Image";r.desc=
|
||||
"Image loader";r.widgets=[{name:"load",text:"Load",type:"button"}];r.supported_extensions=["jpg","jpeg","png","gif"];r.prototype.onAdded=function(){""!=this.properties.url&&null==this.img&&this.loadImage(this.properties.url)};r.prototype.onDrawBackground=function(c){this.flags.collapsed||this.img&&5<this.size[0]&&5<this.size[1]&&this.img.width&&c.drawImage(this.img,0,0,this.size[0],this.size[1])};r.prototype.onExecute=function(){this.img||(this.boxcolor="#000");this.img&&this.img.width?this.setOutputData(0,
|
||||
this.img):this.setOutputData(0,null);this.img&&this.img.dirty&&(this.img.dirty=!1)};r.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"url"==c&&""!=e&&this.loadImage(e);return!0};r.prototype.loadImage=function(c,e){if(""==c)this.img=null;else{this.img=document.createElement("img");"http"==c.substr(0,4)&&x.proxy&&(c=x.proxy+c.substr(c.indexOf(":")+3));this.img.src=c;this.boxcolor="#F95";var f=this;this.img.onload=function(){e&&e(this);f.trace("Image loaded, size: "+f.img.width+"x"+f.img.height);
|
||||
this.dirty=!0;f.boxcolor="#9F9";f.setDirtyCanvas(!0)};this.img.onerror=function(){console.log("error loading the image:"+c)}}};r.prototype.onWidget=function(c,e){"load"==e.name&&this.loadImage(this.properties.url)};r.prototype.onDropFile=function(c){var e=this;this._url&&URL.revokeObjectURL(this._url);this._url=URL.createObjectURL(c);this.properties.url=this._url;this.loadImage(this._url,function(c){e.size[1]=c.height/c.width*e.size[0]})};x.registerNodeType("graphics/image",r);l.title="Palette";l.desc=
|
||||
this.properties.scale,h=c.colors,q=0.5*f[1];e.fillStyle="#000";e.fillRect(0,0,f[0],f[1]);e.strokeStyle="#555";e.beginPath();e.moveTo(0,q);e.lineTo(f[0],q);e.stroke();if(this.inputs)for(var p=0;4>p;++p){var a=this.values[p];if(this.inputs[p]&&this.inputs[p].link){e.strokeStyle=h[p];e.beginPath();var b=a[0]*k*-1+q;e.moveTo(0,Math.clamp(b,0,f[1]));for(var d=1;d<a.length&&d<f[0];++d)b=a[d]*k*-1+q,e.lineTo(d,Math.clamp(b,0,f[1]));e.stroke()}}}};x.registerNodeType("graphics/plot",c);s.title="Image";s.desc=
|
||||
"Image loader";s.widgets=[{name:"load",text:"Load",type:"button"}];s.supported_extensions=["jpg","jpeg","png","gif"];s.prototype.onAdded=function(){""!=this.properties.url&&null==this.img&&this.loadImage(this.properties.url)};s.prototype.onDrawBackground=function(c){this.flags.collapsed||this.img&&5<this.size[0]&&5<this.size[1]&&this.img.width&&c.drawImage(this.img,0,0,this.size[0],this.size[1])};s.prototype.onExecute=function(){this.img||(this.boxcolor="#000");this.img&&this.img.width?this.setOutputData(0,
|
||||
this.img):this.setOutputData(0,null);this.img&&this.img.dirty&&(this.img.dirty=!1)};s.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"url"==c&&""!=e&&this.loadImage(e);return!0};s.prototype.loadImage=function(c,e){if(""==c)this.img=null;else{this.img=document.createElement("img");"http"==c.substr(0,4)&&x.proxy&&(c=x.proxy+c.substr(c.indexOf(":")+3));this.img.src=c;this.boxcolor="#F95";var f=this;this.img.onload=function(){e&&e(this);f.trace("Image loaded, size: "+f.img.width+"x"+f.img.height);
|
||||
this.dirty=!0;f.boxcolor="#9F9";f.setDirtyCanvas(!0)};this.img.onerror=function(){console.log("error loading the image:"+c)}}};s.prototype.onWidget=function(c,e){"load"==e.name&&this.loadImage(this.properties.url)};s.prototype.onDropFile=function(c){var e=this;this._url&&URL.revokeObjectURL(this._url);this._url=URL.createObjectURL(c);this.properties.url=this._url;this.loadImage(this._url,function(c){e.size[1]=c.height/c.width*e.size[0]})};x.registerNodeType("graphics/image",s);l.title="Palette";l.desc=
|
||||
"Generates a color";l.prototype.onExecute=function(){var c=[];null!=this.properties.colorA&&c.push(hex2num(this.properties.colorA));null!=this.properties.colorB&&c.push(hex2num(this.properties.colorB));null!=this.properties.colorC&&c.push(hex2num(this.properties.colorC));null!=this.properties.colorD&&c.push(hex2num(this.properties.colorD));var e=this.getInputData(0);null==e&&(e=0.5);1<e?e=1:0>e&&(e=0);if(0!=c.length){var f=[0,0,0];if(0==e)f=c[0];else if(1==e)f=c[c.length-1];else{var h=(c.length-1)*
|
||||
e,e=c[Math.floor(h)],c=c[Math.floor(h)+1],h=h-Math.floor(h);f[0]=e[0]*(1-h)+c[0]*h;f[1]=e[1]*(1-h)+c[1]*h;f[2]=e[2]*(1-h)+c[2]*h}for(var k in f)f[k]/=255;this.boxcolor=colorToString(f);this.setOutputData(0,f)}};x.registerNodeType("color/palette",l);f.title="Frame";f.desc="Frame viewerew";f.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"view",text:"View Image",type:"button"}];f.prototype.onDrawBackground=function(c){this.frame&&!this.flags.collapsed&&c.drawImage(this.frame,0,0,this.size[0],
|
||||
this.size[1])};f.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};f.prototype.onWidget=function(c,e){if("resize"==e.name&&this.frame){var f=this.frame.width,h=this.frame.height;f||null==this.frame.videoWidth||(f=this.frame.videoWidth,h=this.frame.videoHeight);f&&h&&(this.size=[f,h]);this.setDirtyCanvas(!0,!0)}else"view"==e.name&&this.show()};f.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};x.registerNodeType("graphics/frame",f);s.title=
|
||||
"Image fade";s.desc="Fades between images";s.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];s.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};s.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};s.prototype.onExecute=
|
||||
function(){var c=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;var e=this.getInputData(0);null!=e&&c.drawImage(e,0,0,this.canvas.width,this.canvas.height);e=this.getInputData(2);null==e?e=this.properties.fade:this.properties.fade=e;c.globalAlpha=e;e=this.getInputData(1);null!=e&&c.drawImage(e,0,0,this.canvas.width,this.canvas.height);c.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};x.registerNodeType("graphics/imagefade",s);k.title="Crop";k.desc="Crop Image";
|
||||
this.size[1])};f.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};f.prototype.onWidget=function(c,e){if("resize"==e.name&&this.frame){var f=this.frame.width,h=this.frame.height;f||null==this.frame.videoWidth||(f=this.frame.videoWidth,h=this.frame.videoHeight);f&&h&&(this.size=[f,h]);this.setDirtyCanvas(!0,!0)}else"view"==e.name&&this.show()};f.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};x.registerNodeType("graphics/frame",f);r.title=
|
||||
"Image fade";r.desc="Fades between images";r.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];r.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};r.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};r.prototype.onExecute=
|
||||
function(){var c=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;var e=this.getInputData(0);null!=e&&c.drawImage(e,0,0,this.canvas.width,this.canvas.height);e=this.getInputData(2);null==e?e=this.properties.fade:this.properties.fade=e;c.globalAlpha=e;e=this.getInputData(1);null!=e&&c.drawImage(e,0,0,this.canvas.width,this.canvas.height);c.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};x.registerNodeType("graphics/imagefade",r);k.title="Crop";k.desc="Crop Image";
|
||||
k.prototype.onAdded=function(){this.createCanvas()};k.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};k.prototype.onExecute=function(){var c=this.getInputData(0);c&&(c.width?(this.canvas.getContext("2d").drawImage(c,-this.properties.x,-this.properties.y,c.width*this.properties.scale,c.height*this.properties.scale),this.setOutputData(0,this.canvas)):this.setOutputData(0,null))};k.prototype.onDrawBackground=
|
||||
function(c){this.flags.collapsed||this.canvas&&c.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,this.size[0],this.size[1])};k.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"scale"==c?(this.properties[c]=parseFloat(e),0==this.properties[c]&&(this.trace("Error in scale"),this.properties[c]=1)):this.properties[c]=parseInt(e);this.createCanvas();return!0};x.registerNodeType("graphics/cropImage",k);y.title="Canvas";y.desc="Canvas to render stuff";y.prototype.onExecute=
|
||||
function(){var c=this.canvas,e=this.properties.width|0,f=this.properties.height|0;c.width!=e&&(c.width=e);c.height!=f&&(c.height=f);this.properties.autoclear&&this.ctx.clearRect(0,0,c.width,c.height);this.setOutputData(0,c)};y.prototype.onAction=function(c,e){"clear"==c&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)};x.registerNodeType("graphics/canvas",y);u.title="DrawImage";u.desc="Draws image into a canvas";u.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var e=
|
||||
@@ -393,9 +393,9 @@ this.trigger("stream_closed")}};e.prototype.onPropertyChanged=function(c,e){"fac
|
||||
function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){this._video.frame=++this.frame;this._video.width=this._video.videoWidth;this._video.height=this._video.videoHeight;this.setOutputData(0,this._video);for(var c=1;c<this.outputs.length;++c)if(this.outputs[c])switch(this.outputs[c].name){case "width":this.setOutputData(c,this._video.videoWidth);break;case "height":this.setOutputData(c,this._video.videoHeight)}}};e.prototype.getExtraMenuOptions=
|
||||
function(c){var e=this;return[{content:e.properties.show?"Hide Frame":"Show Frame",callback:function(){e.properties.show=!e.properties.show}}]};e.prototype.onDrawBackground=function(c){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};e.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",x.EVENT],["stream_closed",x.EVENT],["stream_error",x.EVENT]]};
|
||||
x.registerNodeType("graphics/webcam",e)})(this);
|
||||
(function(w){function c(){this.addOutput("Texture","Texture");this.properties={name:"",filter:!0};this.size=[c.image_preview_size,c.image_preview_size]}function r(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[c.image_preview_size,c.image_preview_size]}function l(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",generate_mipmaps:!1}}function f(){this.addInput("Texture","Texture");this.addInput("TextureB",
|
||||
(function(w){function c(){this.addOutput("Texture","Texture");this.properties={name:"",filter:!0};this.size=[c.image_preview_size,c.image_preview_size]}function s(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[c.image_preview_size,c.image_preview_size]}function l(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",generate_mipmaps:!1}}function f(){this.addInput("Texture","Texture");this.addInput("TextureB",
|
||||
"Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="<p>pixelcode must be vec3, uvcode must be vec2, is optional</p>\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture <strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time <strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";this.properties={value:1,pixelcode:"color + colorB * value",uvcode:"",precision:c.DEFAULT};this.has_error=!1}
|
||||
function s(){this.addOutput("out","Texture");this.properties={code:"",u_value:1,u_color:[1,1,1,1],width:512,height:512,precision:c.DEFAULT};this.properties.code="//time: time in seconds\n//texSize: vec2 with res\nuniform float u_value;\nuniform vec4 u_color;\n\nvoid main() {\n vec2 uv = v_coord;\n vec3 color = vec3(0.0);\n\t//your code here\n\tcolor.xy=uv;\n\ngl_FragColor = vec4(color, 1.0);\n}\n";this._uniforms={u_value:1,u_color:vec4.create(),in_texture:0,texSize:vec2.create(),time:0}}function k(){this.addInput("in",
|
||||
function r(){this.addOutput("out","Texture");this.properties={code:"",u_value:1,u_color:[1,1,1,1],width:512,height:512,precision:c.DEFAULT};this.properties.code="//time: time in seconds\n//texSize: vec2 with res\nuniform float u_value;\nuniform vec4 u_color;\n\nvoid main() {\n vec2 uv = v_coord;\n vec3 color = vec3(0.0);\n\t//your code here\n\tcolor.xy=uv;\n\ngl_FragColor = vec4(color, 1.0);\n}\n";this._uniforms={u_value:1,u_color:vec4.create(),in_texture:0,texSize:vec2.create(),time:0}}function k(){this.addInput("in",
|
||||
"Texture");this.addInput("scale","vec2");this.addInput("offset","vec2");this.addOutput("out","Texture");this.properties={offset:vec2.fromValues(0,0),scale:vec2.fromValues(1,1),precision:c.DEFAULT}}function y(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:0.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}
|
||||
function u(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1};this.size[0]=130}function v(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function z(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function e(){this.addInput("Texture","Texture");this.addOutput("tex",
|
||||
"Texture");this.addOutput("avg","vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)}function x(){this.addInput("Texture","Texture");this.addOutput("min_t","Texture");this.addOutput("max_t","Texture");this.addOutput("min","vec4");this.addOutput("max","vec4");this.properties={mode:"max",use_previous_frame:!0};this._uniforms={u_texture:0};this._max=new Float32Array(4);this._min=
|
||||
@@ -418,7 +418,7 @@ function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&th
|
||||
(e=a.width/a.height);this.setOutputData(b,e)}}}},c.prototype.onResourceRenamed=function(a,b){this.properties.name==a&&(this.properties.name=b)},c.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||20>=this.size[1]))if(this._drop_texture&&a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=c.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=
|
||||
this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}},c.generateLowResTexturePreview=function(a){if(!a)return null;var b=c.image_preview_size,d=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)d=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=d=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(d);a=this._preview_canvas;
|
||||
a||(this._preview_canvas=a=createCanvas(b,b));d&&d.toCanvas(a);return a},c.prototype.getResources=function(a){this.properties.name&&(a[this.properties.name]=GL.Texture);return a},c.prototype.onGetInputs=function(){return[["in","Texture"]]},c.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]},c.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g,function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},D.registerNodeType("texture/texture",
|
||||
c),r.title="Preview",r.desc="Show a texture in the graph canvas",r.allow_preview=!1,r.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||r.allow_preview)){var b=this.getInputData(0);if(b){var d=null,d=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(d,0,0,this.size[0],this.size[1]);a.restore()}}},D.registerNodeType("texture/preview",r),l.title="Save",l.desc="Save a texture in the repository",
|
||||
c),s.title="Preview",s.desc="Show a texture in the graph canvas",s.allow_preview=!1,s.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||s.allow_preview)){var b=this.getInputData(0);if(b){var d=null,d=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(d,0,0,this.size[0],this.size[1]);a.restore()}}},D.registerNodeType("texture/preview",s),l.title="Save",l.desc="Save a texture in the repository",
|
||||
l.prototype.getPreviewTexture=function(){return this._texture},l.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.generate_mipmaps&&(a.bind(0),a.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR),gl.generateMipmap(a.texture_type),a.unbind(0)),this.properties.name&&(c.storeTexture?c.storeTexture(this.properties.name,a):c.getTexturesContainer()[this.properties.name]=a),this._texture=a,this.setOutputData(0,a),this.setOutputData(1,this.properties.name))},D.registerNodeType("texture/save",
|
||||
l),f.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},f.title="Operation",f.desc="Texture shader operation",f.presets={},f.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},f.prototype.onPropertyChanged=function(){this.has_error=!1},f.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||
|
||||
!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())},f.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,e=512;a?(d=a.width,e=a.height):b&&(d=b.width,e=b.height);b||(b=GL.Texture.getWhiteTexture());var h=c.getTextureType(this.properties.precision,
|
||||
@@ -427,11 +427,11 @@ h+"|"+g)){var m=c.replaceCode(f.pixel_shader,{UV_CODE:h,PIXEL_CODE:g});try{k=new
|
||||
gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:p,texSize:[d,e],time:n}).draw(c)});this.setOutputData(0,this._tex)}}}},f.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t",
|
||||
f.registerPreset=function(a,b){f.presets[a]=b},f.registerPreset("",""),f.registerPreset("bypass","color"),f.registerPreset("add","color + colorB * value"),f.registerPreset("substract","(color - colorB) * value"),f.registerPreset("mate","mix( color, colorB, color4B.a * value)"),f.registerPreset("invert","vec3(1.0) - color"),f.registerPreset("multiply","color * colorB * value"),f.registerPreset("divide","(color / colorB) / value"),f.registerPreset("difference","abs(color - colorB) * value"),f.registerPreset("max",
|
||||
"max(color, colorB) * value"),f.registerPreset("min","min(color, colorB) * value"),f.registerPreset("displace","texture2D(u_texture, uv + (colorB.xy - vec2(0.5)) * value).xyz"),f.registerPreset("grayscale","vec3(color.x + color.y + color.z) * value / 3.0"),f.registerPreset("saturation","mix( vec3(color.x + color.y + color.z) / 3.0, color, value )"),f.registerPreset("threshold","vec3(color.x > colorB.x * value ? 1.0 : 0.0,color.y > colorB.y * value ? 1.0 : 0.0,color.z > colorB.z * value ? 1.0 : 0.0)"),
|
||||
f.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(f.presets),callback:function(c){var d=f.presets[c];d&&(b.setProperty("pixelcode",d),b.title=c,a.refresh())}})},D.registerNodeType("texture/operation",f),s.title="Shader",s.desc="Texture shader",s.widgets_info={code:{type:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},s.prototype.onPropertyChanged=function(a,b){if("code"==a){var c=this.getShader();if(c){var d=c.uniformInfo;if(this.inputs)for(var e={},
|
||||
f.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(f.presets),callback:function(c){var d=f.presets[c];d&&(b.setProperty("pixelcode",d),b.title=c,a.refresh())}})},D.registerNodeType("texture/operation",f),r.title="Shader",r.desc="Texture shader",r.widgets_info={code:{type:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},r.prototype.onPropertyChanged=function(a,b){if("code"==a){var c=this.getShader();if(c){var d=c.uniformInfo;if(this.inputs)for(var e={},
|
||||
h=0;h<this.inputs.length;++h){var f=this.getInputInfo(h);f&&(d[f.name]&&!e[f.name]?e[f.name]=!0:(this.removeInput(h),h--))}for(h in d)if(f=c.uniformInfo[h],null!==f.loc&&"time"!=h){d="number";if(this._shader.samplers[h])d="texture";else switch(f.size){case 1:d="number";break;case 2:d="vec2";break;case 3:d="vec3";break;case 4:d="vec4";break;case 9:d="mat3";break;case 16:d="mat4";break;default:continue}f=this.findInputSlot(h);-1==f?this.addInput(h,d):(e=this.getInputInfo(f),e)?e.type!=d&&(this.removeInput(f,
|
||||
d),this.addInput(h,d)):this.addInput(h,d)}}}},s.prototype.getShader=function(){if(this._shader&&this._shader_code==this.properties.code)return this._shader;this._shader_code=this.properties.code;if(this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.pixel_shader+this.properties.code))this.boxcolor="green";else return this.boxcolor="red",null;return this._shader},s.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getShader();if(a){var b=0,d=null;if(this.inputs)for(var e=
|
||||
d),this.addInput(h,d)):this.addInput(h,d)}}}},r.prototype.getShader=function(){if(this._shader&&this._shader_code==this.properties.code)return this._shader;this._shader_code=this.properties.code;if(this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,r.pixel_shader+this.properties.code))this.boxcolor="green";else return this.boxcolor="red",null;return this._shader},r.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getShader();if(a){var b=0,d=null;if(this.inputs)for(var e=
|
||||
0;e<this.inputs.length;++e){var h=this.getInputInfo(e),f=this.getInputData(e);null!=f&&(f.constructor===GL.Texture&&(f.bind(b),d||(d=f),f=b,b++),a.setUniform(h.name,f))}var g=this._uniforms,b=c.getTextureType(this.properties.precision,d),e=this.properties.width|0,h=this.properties.height|0;0==e&&(e=d?d.width:gl.canvas.width);0==h&&(h=d?d.height:gl.canvas.height);g.texSize[0]=e;g.texSize[1]=h;g.time=this.graph.getTime();g.u_value=this.properties.u_value;g.u_color.set(this.properties.u_color);this._tex&&
|
||||
this._tex.type==b&&this._tex.width==e&&this._tex.height==h||(this._tex=new GL.Texture(e,h,{type:b,format:gl.RGBA,filter:gl.LINEAR}));this._tex.drawTo(function(){a.uniforms(g).draw(GL.Mesh.getScreenQuad())});this.setOutputData(0,this._tex)}}},s.pixel_shader="precision highp float;\n\t\t\n\t\tvarying vec2 v_coord;\n\t\tuniform float time;\n",D.registerNodeType("texture/shader",s),k.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},k.title="Scale/Offset",k.desc="Applies an scaling and offseting",
|
||||
this._tex.type==b&&this._tex.width==e&&this._tex.height==h||(this._tex=new GL.Texture(e,h,{type:b,format:gl.RGBA,filter:gl.LINEAR}));this._tex.drawTo(function(){a.uniforms(g).draw(GL.Mesh.getScreenQuad())});this.setOutputData(0,this._tex)}}},r.pixel_shader="precision highp float;\n\t\t\n\t\tvarying vec2 v_coord;\n\t\tuniform float time;\n",D.registerNodeType("texture/shader",r),k.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},k.title="Scale/Offset",k.desc="Applies an scaling and offseting",
|
||||
k.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0)&&a)if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=a.width,d=a.height,e=this.precision===c.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT;this.precision===c.DEFAULT&&(e=a.type);this._tex&&this._tex.width==b&&this._tex.height==d&&this._tex.type==e||(this._tex=new GL.Texture(b,d,{type:e,format:gl.RGBA,filter:gl.LINEAR}));var h=this._shader;h||(h=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,
|
||||
k.pixel_shader));var f=this.getInputData(1);f?(this.properties.scale[0]=f[0],this.properties.scale[1]=f[1]):f=this.properties.scale;var g=this.getInputData(2);g?(this.properties.offset[0]=g[0],this.properties.offset[1]=g[1]):g=this.properties.offset;this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a.bind(0);var b=Mesh.getScreenQuad();h.uniforms({u_texture:0,u_scale:f,u_offset:g}).draw(b)});this.setOutputData(0,this._tex)}},k.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 u_scale;\n\t\tuniform vec2 u_offset;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\tuv = uv / u_scale - u_offset;\n\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t}\n\t\t",
|
||||
D.registerNodeType("texture/scaleOffset",k),y.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},y.title="Warp",y.desc="Texture warp operation",y.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1),d=512,e=512;a?(d=a.width,e=a.height):b&&(d=b.width,e=b.height);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):
|
||||
@@ -488,8 +488,8 @@ b)}}},D.registerNodeType("texture/blur",K),E.title="Glow",E.desc="Filters a text
|
||||
k||(k=E._cut_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,E.cut_pixel_shader));gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);f.u_threshold=this.getInputOrProperty("threshold");var m=g[0]=GL.Texture.getTemporary(b,d,e);a.blit(m,k.uniforms(f));var q=m,p=this.getInputOrProperty("iterations"),p=Math.clamp(p,1,16)|0,n=f.u_texel_size,l=this.getInputOrProperty("intensity");f.u_intensity=1;f.u_delta=this.properties.scale;k=E._shader;k||(k=E._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,E.scale_pixel_shader));
|
||||
for(var t=1;t<p;t++){b>>=1;1<(d|0)&&(d>>=1);if(2>b)break;m=g[t]=GL.Texture.getTemporary(b,d,e);n[0]=1/q.width;n[1]=1/q.height;q.blit(m,k.uniforms(f));q=m}this.isOutputConnected(2)&&(b=this._average_texture,b&&b.type==a.type&&b.format==a.format||(b=this._average_texture=new GL.Texture(1,1,{type:a.type,format:a.format,filter:gl.LINEAR})),n[0]=1/q.width,n[1]=1/q.height,f.u_intensity=l,f.u_delta=1,q.blit(b,k.uniforms(f)),this.setOutputData(2,b));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);f.u_intensity=
|
||||
this.getInputOrProperty("persistence");f.u_delta=0.5;for(t-=2;0<=t;t--)m=g[t],g[t]=null,n[0]=1/q.width,n[1]=1/q.height,q.blit(m,k.uniforms(f)),GL.Texture.releaseTemporary(q),q=m;gl.disable(gl.BLEND);this.isOutputConnected(1)&&(g=this._glow_texture,g&&g.width==a.width&&g.height==a.height&&g.type==h&&g.format==a.format||(g=this._glow_texture=new GL.Texture(a.width,a.height,{type:h,format:a.format,filter:gl.LINEAR})),q.blit(g),this.setOutputData(1,g));if(this.isOutputConnected(0)){g=this._final_texture;
|
||||
g&&g.width==a.width&&g.height==a.height&&g.type==h&&g.format==a.format||(g=this._final_texture=new GL.Texture(a.width,a.height,{type:h,format:a.format,filter:gl.LINEAR}));var s=this.getInputData(1),u=this.getInputOrProperty("dirt_factor");f.u_intensity=l;k=s?E._dirt_final_shader:E._final_shader;k||(k=s?E._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,E.final_pixel_shader,{USE_DIRT:""}):E._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,E.final_pixel_shader));g.drawTo(function(){a.bind(0);
|
||||
q.bind(1);s&&(k.setUniform("u_dirt_factor",u),k.setUniform("u_dirt_texture",s.bind(2)));k.toViewport(f)});this.setOutputData(0,g)}GL.Texture.releaseTemporary(q)}},E.cut_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_threshold;\n\tvoid main() {\n\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t}",E.scale_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t}",
|
||||
g&&g.width==a.width&&g.height==a.height&&g.type==h&&g.format==a.format||(g=this._final_texture=new GL.Texture(a.width,a.height,{type:h,format:a.format,filter:gl.LINEAR}));var r=this.getInputData(1),u=this.getInputOrProperty("dirt_factor");f.u_intensity=l;k=r?E._dirt_final_shader:E._final_shader;k||(k=r?E._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,E.final_pixel_shader,{USE_DIRT:""}):E._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,E.final_pixel_shader));g.drawTo(function(){a.bind(0);
|
||||
q.bind(1);r&&(k.setUniform("u_dirt_factor",u),k.setUniform("u_dirt_texture",r.bind(2)));k.toViewport(f)});this.setOutputData(0,g)}GL.Texture.releaseTemporary(q)}},E.cut_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_threshold;\n\tvoid main() {\n\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t}",E.scale_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t}",
|
||||
E.final_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform sampler2D u_glow_texture;\n\t#ifdef USE_DIRT\n\t\tuniform sampler2D u_dirt_texture;\n\t#endif\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\tuniform float u_dirt_factor;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_glow_texture, uv + o.xy ) + texture2D( u_glow_texture, uv + o.zy) + texture2D( u_glow_texture, uv + o.xw) + texture2D( u_glow_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tvec4 glow = sampleBox( v_coord );\n\t\t#ifdef USE_DIRT\n\t\t\tglow = mix( glow, glow * texture2D( u_dirt_texture, v_coord ), u_dirt_factor );\n\t\t#endif\n\t\tgl_FragColor = texture2D( u_texture, v_coord ) + u_intensity * glow;\n\t}",
|
||||
D.registerNodeType("texture/glow",E),G.title="Kuwahara Filter",G.desc="Filters a texture giving an artistic oil canvas painting",G.max_radius=10,G._shaders=[],G.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),G.max_radius);if(0==
|
||||
b)this.setOutputData(0,a);else{var c=this.properties.intensity,d=D.camera_aspect;d||void 0===window.gl||(d=gl.canvas.height/gl.canvas.width);d||(d=1);d=this.properties.preserve_aspect?d:1;G._shaders[b]||(G._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,G.pixel_shader,{RADIUS:b.toFixed(0)}));var e=G._shaders[b],h=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(h)});
|
||||
@@ -519,51 +519,51 @@ precision:{widget:"combo",values:c.MODE_VALUES}},M.prototype.onExecute=function(
|
||||
(e=M._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,M.pixel_shader));b.u_key_color=this.properties.key_color;b.u_threshold=this.properties.threshold;b.u_slope=this.properties.slope;this._tex.drawTo(function(){a.bind(0);e.uniforms(b).draw(d)});this.setOutputData(0,this._tex)}}},M.pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec3 u_key_color;\n\t\tuniform float u_threshold;\n\t\tuniform float u_slope;\n\t\t\n\t\tvoid main() {\n\t\t\tvec3 color = texture2D( u_texture, v_coord ).xyz;\n\t\t\tfloat diff = length( normalize(color) - normalize(u_key_color) );\n\t\t\tfloat edge = u_threshold * (1.0 - u_slope);\n\t\t\tfloat alpha = smoothstep( edge, u_threshold, diff);\n\t\t\tgl_FragColor = vec4( color, alpha );\n\t\t}",
|
||||
D.registerNodeType("texture/matte",M),N.title="CubemapToTexture2D",N.desc="Transforms a CUBEMAP texture into a TEXTURE2D in Polar Representation",N.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a&&a.texture_type==GL.TEXTURE_CUBE_MAP){!this._last_tex||this._last_tex.height==a.height&&this._last_tex.type==a.type||(this._last_tex=null);var b=this.getInputOrProperty("yaw");this._last_tex=GL.Texture.cubemapToTexture2D(a,a.height,this._last_tex,!0,b);this.setOutputData(0,
|
||||
this._last_tex)}}},D.registerNodeType("texture/cubemapToTexture2D",N))})(this);
|
||||
(function(w){function c(){this.addOutput("out","geometry");this.addOutput("points","array");this.properties={radius:1,num_points:4096,regular:!1,mode:c.SPHERE};this.points=new Float32Array(3*this.properties.num_points);this.must_update=!0;this.version=0;this.geometry={vertices:null,_id:1E5*Math.random()|0}}function r(){this.addInput("mesh","mesh");this.addOutput("out","geometry");this.geometry={};this.last_mesh=null}function l(){this.addInput("in","geometry");this.addOutput("out","geometry");this.properties=
|
||||
{code:"V[1] += 0.01 * Math.sin(I + T*0.001);",execute_every_frame:!1};this.geometry=null;this.version=this.geometry_id=-1;this.must_update=!0;this.func=this.vertices=null}function f(){this.addInput("in","geometry");this.addOutput("out","geometry");this.properties={min_dist:0.4,max_dist:0.5,max_connections:0,probability:1};this.version=this.geometry_id=-1;this.my_version=1;this.must_update=!0}function s(){this.addInput("in","geometry");this.addInput("mat4","mat4");this.addInput("tex","texture");this.addOutput("mesh",
|
||||
(function(w){function c(){this.addOutput("out","geometry");this.addOutput("points","array");this.properties={radius:1,num_points:4096,regular:!1,mode:c.SPHERE};this.points=new Float32Array(3*this.properties.num_points);this.must_update=!0;this.version=0;this.geometry={vertices:null,_id:1E5*Math.random()|0}}function s(){this.addInput("mesh","mesh");this.addOutput("out","geometry");this.geometry={};this.last_mesh=null}function l(){this.addInput("in","geometry");this.addOutput("out","geometry");this.properties=
|
||||
{code:"V[1] += 0.01 * Math.sin(I + T*0.001);",execute_every_frame:!1};this.geometry=null;this.version=this.geometry_id=-1;this.must_update=!0;this.func=this.vertices=null}function f(){this.addInput("in","geometry");this.addOutput("out","geometry");this.properties={min_dist:0.4,max_dist:0.5,max_connections:0,probability:1};this.version=this.geometry_id=-1;this.my_version=1;this.must_update=!0}function r(){this.addInput("in","geometry");this.addInput("mat4","mat4");this.addInput("tex","texture");this.addOutput("mesh",
|
||||
"mesh");this.properties={enabled:!0,primitive:GL.TRIANGLES,additive:!1,color:[1,1,1],opacity:1};this.color=vec4.create([1,1,1,1]);this.uniforms={u_color:this.color};this.version=-1;this.mesh=null}function k(){this.addInput("in","geometry");this.addInput("mat4","mat4");this.addInput("tex","texture");this.properties={enabled:!0,point_size:0.1,fixed_size:!1,additive:!0,color:[1,1,1],opacity:1};this.color=vec4.create([1,1,1,1]);this.uniforms={u_point_size:1,u_perspective:1,u_point_perspective:1,u_color:this.color};
|
||||
this.version=this.geometry_id=-1;this.mesh=null}var y=w.LiteGraph,u=new Float32Array(16),v=new Float32Array(16),z=new Float32Array(16),e=new Float32Array(16),x={u_view:u,u_projection:v,u_viewprojection:z,u_model:e};y.LGraphRender={onRequestCameraMatrices:null};w.LGraphPoints3D=c;c.RECTANGLE=1;c.CIRCLE=2;c.CUBE=10;c.SPHERE=11;c.HEMISPHERE=12;c.INSIDE_SPHERE=13;c.MODE_VALUES={rectangle:c.RECTANGLE,circle:c.CIRCLE,cube:c.CUBE,sphere:c.SPHERE,hemisphere:c.HEMISPHERE,inside_sphere:c.INSIDE_SPHERE};c.widgets_info=
|
||||
{mode:{widget:"combo",values:c.MODE_VALUES}};c.title="list of points";c.desc="returns an array of points";c.prototype.onPropertyChanged=function(c,e){this.must_update=!0};c.prototype.onExecute=function(){this.must_update&&(this.must_update=!1,this.updatePoints());this.geometry.vertices=this.points;this.geometry._version=this.version;this.setOutputData(0,this.geometry)};c.generatePoints=function(e,f,k,h,q){var p=3*f;h&&h.length==p||(h=new Float32Array(p));if(q)if(k==c.RECTANGLE){p=Math.floor(Math.sqrt(f));
|
||||
for(f=0;f<p;++f)for(k=0;k<p;++k)q=3*f+3*k*p,h[q]=(f/p-0.5)*e*2,h[q+1]=0,h[q+2]=(k/p-0.5)*e*2;h=new Float32Array(h.subarray(0,p*p*3))}else if(k==c.SPHERE){var p=Math.floor(Math.sqrt(f)),a=vec3.create();for(f=0;f<p;++f)for(k=0;k<p;++k)q=3*f+3*k*p,polarToCartesian(a,f/p*2*Math.PI,2*(k/p-0.5)*Math.PI,e),h[q]=a[0],h[q+1]=a[1],h[q+2]=a[2];h=new Float32Array(h.subarray(0,p*p*3))}else{if(k==c.CIRCLE)for(f=0;f<p;f+=3)k=f/p*Math.PI*2,h[f]=Math.cos(k)*e,h[f+1]=0,h[f+2]=Math.sin(k)*e}else if(k==c.RECTANGLE)for(f=
|
||||
0;f<p;f+=3)h[f]=(Math.random()-0.5)*e*2,h[f+1]=0,h[f+2]=(Math.random()-0.5)*e*2;else if(k==c.CUBE)for(f=0;f<p;f+=3)h[f]=(Math.random()-0.5)*e*2,h[f+1]=(Math.random()-0.5)*e*2,h[f+2]=(Math.random()-0.5)*e*2;else if(k==c.SPHERE)for(f=0;f<p;f+=3){var a=Math.random(),b=Math.random();k=2*Math.cos(2*Math.PI*a)*Math.sqrt(b*(1-b));q=1-2*b;a=2*Math.sin(2*Math.PI*a)*Math.sqrt(b*(1-b));h[f]=k*e;h[f+1]=q*e;h[f+2]=a*e}else if(k==c.HEMISPHERE)for(f=0;f<p;f+=3)a=Math.random(),b=Math.random(),k=Math.cos(2*Math.PI*
|
||||
a)*Math.sqrt(1-b*b),q=b,a=Math.sin(2*Math.PI*a)*Math.sqrt(1-b*b),h[f]=k*e,h[f+1]=q*e,h[f+2]=a*e;else if(k==c.CIRCLE)for(f=0;f<p;f+=3)a=Math.random(),b=Math.random(),k=Math.cos(2*Math.PI*a)*Math.sqrt(1-b*b),a=Math.sin(2*Math.PI*a)*Math.sqrt(1-b*b),h[f]=k*e,h[f+1]=0,h[f+2]=a*e;else if(k==c.INSIDE_SPHERE)for(f=0;f<p;f+=3){q=Math.random();k=Math.random();b=2*q*Math.PI;a=Math.acos(2*k-1);k=Math.cbrt(Math.random())*e;q=Math.sin(b);var b=Math.cos(b),d=Math.sin(a),a=Math.cos(a);h[f]=k*d*b;h[f+1]=k*d*q;h[f+
|
||||
2]=k*a}else console.warn("wrong mode in LGraphPoints3D");return h};c.prototype.updatePoints=function(){var e=this.properties.num_points|0;1>e&&(e=1);this.points.length!=3*e&&(this.points=new Float32Array(3*e));this.points=c.generatePoints(this.properties.radius,e,this.properties.mode,this.points,this.properties.regular);this.version++};y.registerNodeType("geometry/points3D",c);r.title="to geometry";r.desc="converts a mesh to geometry";r.prototype.onExecute=function(){var c=this.getInputData(0);if(c){if(c!=
|
||||
this.last_mesh){this.last_mesh=c;for(i in c.vertexBuffers)this.geometry[i]=c.vertexBuffers[i].data;c.indexBuffers.triangles&&(this.geometry.indices=c.indexBuffers.triangles.data);this.geometry._id=1E5*Math.random()|0;this.geometry._version=0}this.setOutputData(0,this.geometry);this.geometry&&this.setOutputData(1,this.geometry.vertices)}};y.registerNodeType("geometry/toGeometry",r);l.title="geoeval";l.desc="eval code";l.widgets_info={code:{widget:"code"}};l.prototype.onConfigure=function(c){this.compileCode()};
|
||||
2]=k*a}else console.warn("wrong mode in LGraphPoints3D");return h};c.prototype.updatePoints=function(){var e=this.properties.num_points|0;1>e&&(e=1);this.points.length!=3*e&&(this.points=new Float32Array(3*e));this.points=c.generatePoints(this.properties.radius,e,this.properties.mode,this.points,this.properties.regular);this.version++};y.registerNodeType("geometry/points3D",c);s.title="to geometry";s.desc="converts a mesh to geometry";s.prototype.onExecute=function(){var c=this.getInputData(0);if(c){if(c!=
|
||||
this.last_mesh){this.last_mesh=c;for(i in c.vertexBuffers)this.geometry[i]=c.vertexBuffers[i].data;c.indexBuffers.triangles&&(this.geometry.indices=c.indexBuffers.triangles.data);this.geometry._id=1E5*Math.random()|0;this.geometry._version=0}this.setOutputData(0,this.geometry);this.geometry&&this.setOutputData(1,this.geometry.vertices)}};y.registerNodeType("geometry/toGeometry",s);l.title="geoeval";l.desc="eval code";l.widgets_info={code:{widget:"code"}};l.prototype.onConfigure=function(c){this.compileCode()};
|
||||
l.prototype.compileCode=function(){if(this.properties.code)try{this.func=new Function("V","I","T",this.properties.code),this.boxcolor="#AFA",this.must_update=!0}catch(c){this.boxcolor="red"}};l.prototype.onPropertyChanged=function(c,e){"code"==c&&(this.properties.code=e,this.compileCode())};l.prototype.onExecute=function(){var c=this.getInputData(0);if(c)if(this.func){if(this.geometry_id!=c._id||this.version!=c._version||this.must_update||this.properties.execute_every_frame){this.must_update=!1;this.geometry_id=
|
||||
c._id;this.properties.execute_every_frame?this.version++:this.version=c._version;var e=this.func,f=getTime();this.geometry||(this.geometry={});for(var h in c)null!=c[h]&&(this.geometry[h]=c[h].constructor==Float32Array?new Float32Array(c[h]):c[h]);this.geometry._id=c._id;this.geometry._version=this.properties.execute_every_frame?this.version:c._version+1;var k=vec3.create(),p=this.vertices;p&&this.vertices.length==c.vertices.length?p.set(c.vertices):p=this.vertices=new Float32Array(c.vertices);for(h=
|
||||
0;h<p.length;h+=3)k[0]=p[h],k[1]=p[h+1],k[2]=p[h+2],e(k,h/3,f),p[h]=k[0],p[h+1]=k[1],p[h+2]=k[2];this.geometry.vertices=p}this.setOutputData(0,this.geometry)}else this.setOutputData(0,c)};y.registerNodeType("geometry/eval",l);f.title="connect points";f.desc="adds indices between near points";f.prototype.onPropertyChanged=function(c,e){this.must_update=!0};f.prototype.onExecute=function(){var c=this.getInputData(0);if(c){if(this.geometry_id!=c._id||this.version!=c._version||this.must_update){this.must_update=
|
||||
!1;this.geometry_id=c._id;this.version=c._version;this.geometry={};for(var e in c)this.geometry[e]=c[e];this.geometry._id=1E5*Math.random()|0;this.geometry._version=this.my_version++;var c=c.vertices,f=c.length,h=this.properties.min_dist,k=this.properties.max_dist,p=this.properties.probability,a=this.properties.max_connections,b=[];for(e=0;e<f;e+=3)for(var d=c[e],l=c[e+1],n=c[e+2],s=0,u=e+3;u<f;u+=3){var r=c[u],v=c[u+1],y=c[u+2],r=Math.sqrt((d-r)*(d-r)+(l-v)*(l-v)+(n-y)*(n-y));if(!(r>k||r<h||1>p&&
|
||||
p<Math.random())&&(b.push(e/3,u/3),s+=1,a&&s>a))break}this.geometry.indices=this.indices=new Uint32Array(b)}this.indices&&this.indices.length?(this.geometry.indices=this.indices,this.setOutputData(0,this.geometry)):this.setOutputData(0,null)}};y.registerNodeType("geometry/connectPoints",f);"undefined"!=typeof GL&&(s.title="render",s.desc="renders a geometry",s.PRIMITIVE_VALUES={points:GL.POINTS,lines:GL.LINES,line_loop:GL.LINE_LOOP,line_strip:GL.LINE_STRIP,triangles:GL.TRIANGLES,triangle_fan:GL.TRIANGLE_FAN,
|
||||
triangle_strip:GL.TRIANGLE_STRIP},s.widgets_info={primitive:{widget:"combo",values:s.PRIMITIVE_VALUES},color:{widget:"color"}},s.prototype.updateMesh=function(c){this.mesh||(this.mesh=new GL.Mesh);for(var e in c)if("_"!=e[0]){var f=c[e],h=GL.Mesh.common_buffers[e];if(h||"indices"==e){var h=h?h.spacing:3,k=this.mesh.vertexBuffers[e];k&&k.data.length==f.length?(k.data.set(f),k.upload(GL.DYNAMIC_DRAW)):k=new GL.Buffer("indices"==e?GL.ELEMENT_ARRAY_BUFFER:GL.ARRAY_BUFFER,f,h,GL.DYNAMIC_DRAW);this.mesh.addBuffer(e,
|
||||
k)}}this.geometry_id=this.mesh.id=c._id;this.version=this.mesh.version=c._version;return this.mesh},s.prototype.onExecute=function(){if(this.properties.enabled){var c=this.getInputData(0);if(c)if(this.version==c._version&&this.geometry_id==c._id||this.updateMesh(c),y.LGraphRender.onRequestCameraMatrices){y.LGraphRender.onRequestCameraMatrices(u,v,z);c=null;this.getInputData(2)?(c=gl.shaders.textured)||(c=gl.shaders.textured=new GL.Shader(k.vertex_shader_code,k.fragment_shader_code,{USE_TEXTURE:""})):
|
||||
!1;this.geometry_id=c._id;this.version=c._version;this.geometry={};for(var e in c)this.geometry[e]=c[e];this.geometry._id=1E5*Math.random()|0;this.geometry._version=this.my_version++;var c=c.vertices,f=c.length,h=this.properties.min_dist,k=this.properties.max_dist,p=this.properties.probability,a=this.properties.max_connections,b=[];for(e=0;e<f;e+=3)for(var d=c[e],l=c[e+1],n=c[e+2],r=0,u=e+3;u<f;u+=3){var s=c[u],v=c[u+1],y=c[u+2],s=Math.sqrt((d-s)*(d-s)+(l-v)*(l-v)+(n-y)*(n-y));if(!(s>k||s<h||1>p&&
|
||||
p<Math.random())&&(b.push(e/3,u/3),r+=1,a&&r>a))break}this.geometry.indices=this.indices=new Uint32Array(b)}this.indices&&this.indices.length?(this.geometry.indices=this.indices,this.setOutputData(0,this.geometry)):this.setOutputData(0,null)}};y.registerNodeType("geometry/connectPoints",f);"undefined"!=typeof GL&&(r.title="render",r.desc="renders a geometry",r.PRIMITIVE_VALUES={points:GL.POINTS,lines:GL.LINES,line_loop:GL.LINE_LOOP,line_strip:GL.LINE_STRIP,triangles:GL.TRIANGLES,triangle_fan:GL.TRIANGLE_FAN,
|
||||
triangle_strip:GL.TRIANGLE_STRIP},r.widgets_info={primitive:{widget:"combo",values:r.PRIMITIVE_VALUES},color:{widget:"color"}},r.prototype.updateMesh=function(c){this.mesh||(this.mesh=new GL.Mesh);for(var e in c)if("_"!=e[0]){var f=c[e],h=GL.Mesh.common_buffers[e];if(h||"indices"==e){var h=h?h.spacing:3,k=this.mesh.vertexBuffers[e];k&&k.data.length==f.length?(k.data.set(f),k.upload(GL.DYNAMIC_DRAW)):k=new GL.Buffer("indices"==e?GL.ELEMENT_ARRAY_BUFFER:GL.ARRAY_BUFFER,f,h,GL.DYNAMIC_DRAW);this.mesh.addBuffer(e,
|
||||
k)}}this.geometry_id=this.mesh.id=c._id;this.version=this.mesh.version=c._version;return this.mesh},r.prototype.onExecute=function(){if(this.properties.enabled){var c=this.getInputData(0);if(c)if(this.version==c._version&&this.geometry_id==c._id||this.updateMesh(c),y.LGraphRender.onRequestCameraMatrices){y.LGraphRender.onRequestCameraMatrices(u,v,z);c=null;this.getInputData(2)?(c=gl.shaders.textured)||(c=gl.shaders.textured=new GL.Shader(k.vertex_shader_code,k.fragment_shader_code,{USE_TEXTURE:""})):
|
||||
(c=gl.shaders.flat)||(c=gl.shaders.flat=new GL.Shader(k.vertex_shader_code,k.fragment_shader_code));this.color.set(this.properties.color);this.color[3]=this.properties.opacity;var f=this.getInputData(1);f?e.set(f):mat4.identity(e);this.uniforms.u_point_size=1;f=this.properties.primitive;c.uniforms(x);c.uniforms(this.uniforms);1<=this.properties.opacity?gl.disable(gl.BLEND):gl.enable(gl.BLEND);gl.enable(gl.DEPTH_TEST);this.properties.additive?(gl.blendFunc(gl.SRC_ALPHA,gl.ONE),gl.depthMask(!1)):gl.blendFunc(gl.SRC_ALPHA,
|
||||
gl.ONE_MINUS_SRC_ALPHA);c.draw(this.mesh,f,"indices");gl.disable(gl.BLEND);gl.depthMask(!0)}else console.warn("cannot render geometry, LiteGraph.onRequestCameraMatrices is null, remember to fill this with a callback(view_matrix, projection_matrix,viewprojection_matrix) to use 3D rendering from the graph")}},y.registerNodeType("geometry/render",s),k.widgets_info={color:{widget:"color"}},k.prototype.updateMesh=function(c){this.buffer&&this.buffer.data.length==c.vertices.length?(this.buffer.data.set(c.vertices),
|
||||
gl.ONE_MINUS_SRC_ALPHA);c.draw(this.mesh,f,"indices");gl.disable(gl.BLEND);gl.depthMask(!0)}else console.warn("cannot render geometry, LiteGraph.onRequestCameraMatrices is null, remember to fill this with a callback(view_matrix, projection_matrix,viewprojection_matrix) to use 3D rendering from the graph")}},y.registerNodeType("geometry/render",r),k.widgets_info={color:{widget:"color"}},k.prototype.updateMesh=function(c){this.buffer&&this.buffer.data.length==c.vertices.length?(this.buffer.data.set(c.vertices),
|
||||
this.buffer.upload(GL.DYNAMIC_DRAW)):this.buffer=new GL.Buffer(GL.ARRAY_BUFFER,c.vertices,3,GL.DYNAMIC_DRAW);this.mesh||(this.mesh=new GL.Mesh);this.mesh.addBuffer("vertices",this.buffer);this.geometry_id=this.mesh.id=c._id;this.version=this.mesh.version=c._version},k.prototype.onExecute=function(){if(this.properties.enabled){var c=this.getInputData(0);if(c)if(this.version==c._version&&this.geometry_id==c._id||this.updateMesh(c),y.LGraphRender.onRequestCameraMatrices){y.LGraphRender.onRequestCameraMatrices(u,
|
||||
v,z);c=null;this.getInputData(2)?(c=gl.shaders.textured_points)||(c=gl.shaders.textured_points=new GL.Shader(k.vertex_shader_code,k.fragment_shader_code,{USE_TEXTURED_POINTS:""})):(c=gl.shaders.points)||(c=gl.shaders.points=new GL.Shader(k.vertex_shader_code,k.fragment_shader_code,{USE_POINTS:""}));this.color.set(this.properties.color);this.color[3]=this.properties.opacity;var f=this.getInputData(1);f?e.set(f):mat4.identity(e);this.uniforms.u_point_size=this.properties.point_size;this.uniforms.u_point_perspective=
|
||||
this.properties.fixed_size?0:1;this.uniforms.u_perspective=gl.viewport_data[3]*v[5];c.uniforms(x);c.uniforms(this.uniforms);1<=this.properties.opacity?gl.disable(gl.BLEND):gl.enable(gl.BLEND);gl.enable(gl.DEPTH_TEST);this.properties.additive?(gl.blendFunc(gl.SRC_ALPHA,gl.ONE),gl.depthMask(!1)):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA);c.draw(this.mesh,GL.POINTS);gl.disable(gl.BLEND);gl.depthMask(!0)}else console.warn("cannot render geometry, LiteGraph.onRequestCameraMatrices is null, remember to fill this with a callback(view_matrix, projection_matrix,viewprojection_matrix) to use 3D rendering from the graph")}},
|
||||
y.registerNodeType("geometry/render_points",k),k.vertex_shader_code="\t\tprecision mediump float;\n\t\tattribute vec3 a_vertex;\n\t\tvarying vec3 v_vertex;\n\t\tattribute vec3 a_normal;\n\t\tvarying vec3 v_normal;\n\t\t#ifdef USE_COLOR\n\t\t\tattribute vec4 a_color;\n\t\t\tvarying vec4 v_color;\n\t\t#endif\n\t\tattribute vec2 a_coord;\n\t\tvarying vec2 v_coord;\n\t\t#ifdef USE_SIZE\n\t\t\tattribute float a_extra;\n\t\t#endif\n\t\t#ifdef USE_INSTANCING\n\t\t\tattribute mat4 u_model;\n\t\t#else\n\t\t\tuniform mat4 u_model;\n\t\t#endif\n\t\tuniform mat4 u_viewprojection;\n\t\tuniform float u_point_size;\n\t\tuniform float u_perspective;\n\t\tuniform float u_point_perspective;\n\t\tfloat computePointSize(float radius, float w)\n\t\t{\n\t\t\tif(radius < 0.0)\n\t\t\t\treturn -radius;\n\t\t\treturn u_perspective * radius / w;\n\t\t}\n\t\tvoid main() {\n\t\t\tv_coord = a_coord;\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tv_color = a_color;\n\t\t\t#endif\n\t\t\tv_vertex = ( u_model * vec4( a_vertex, 1.0 )).xyz;\n\t\t\tv_normal = ( u_model * vec4( a_normal, 0.0 )).xyz;\n\t\t\tgl_Position = u_viewprojection * vec4(v_vertex,1.0);\n\t\t\tgl_PointSize = u_point_size;\n\t\t\t#ifdef USE_SIZE\n\t\t\t\tgl_PointSize = a_extra;\n\t\t\t#endif\n\t\t\tif(u_point_perspective != 0.0)\n\t\t\t\tgl_PointSize = computePointSize( gl_PointSize, gl_Position.w );\n\t\t}\t",
|
||||
k.fragment_shader_code="\t\tprecision mediump float;\n\t\tuniform vec4 u_color;\n\t\t#ifdef USE_COLOR\n\t\t\tvarying vec4 v_color;\n\t\t#endif\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tvoid main() {\n\t\t\tvec4 color = u_color;\n\t\t\t#ifdef USE_TEXTURED_POINTS\n\t\t\t\tcolor *= texture2D(u_texture, gl_PointCoord.xy);\n\t\t\t#else\n\t\t\t\t#ifdef USE_TEXTURE\n\t\t\t\t color *= texture2D(u_texture, v_coord);\n\t\t\t\t if(color.a < 0.1)\n\t\t\t\t\tdiscard;\n\t\t\t\t#endif\n\t\t\t\t#ifdef USE_POINTS\n\t\t\t\t\tfloat dist = length( gl_PointCoord.xy - vec2(0.5) );\n\t\t\t\t\tif( dist > 0.45 )\n\t\t\t\t\t\tdiscard;\n\t\t\t\t#endif\n\t\t\t#endif\n\t\t\t#ifdef USE_COLOR\n\t\t\t\tcolor *= v_color;\n\t\t\t#endif\n\t\t\tgl_FragColor = color;\n\t\t}\t")})(this);
|
||||
(function(w){var c=w.LiteGraph;if("undefined"!=typeof GL){var r=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};r._shader||(r._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,r.pixel_shader),r._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]}))};r.title="Lens";r.desc="Camera Lens distortion";r.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};r.prototype.onExecute=function(){var c=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,c);else if(c){this._tex=LGraphTexture.getTargetTexture(c,this._tex,this.properties.precision);var f=this.properties.aberration;this.isInputConnected(1)&&(f=this.getInputData(1),
|
||||
this.properties.aberration=f);var l=this.properties.distortion;this.isInputConnected(2)&&(l=this.getInputData(2),this.properties.distortion=l);var s=this.properties.blur;this.isInputConnected(3)&&(s=this.getInputData(3),this.properties.blur=s);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var w=Mesh.getScreenQuad(),e=r._shader;this._tex.drawTo(function(){c.bind(0);e.uniforms({u_texture:0,u_aberration:f,u_distortion:l,u_blur:s}).draw(w)});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_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";
|
||||
c.registerNodeType("fx/lens",r);w.LGraphFXLens=r;var l=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}};l.title="Bokeh";l.desc="applies an Bokeh effect";l.widgets_info={shape:{widget:"texture"}};l.prototype.onExecute=function(){var c=this.getInputData(0),f=this.getInputData(1),s=this.getInputData(2);
|
||||
if(c&&s&&this.properties.shape){f||(f=c);var r=LGraphTexture.getTexture(this.properties.shape);if(r){var w=this.properties.threshold;this.isInputConnected(3)&&(w=this.getInputData(3),this.properties.threshold=w);var e=gl.UNSIGNED_BYTE;this.properties.high_precision&&(e=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==e&&this._temp_texture.width==c.width&&this._temp_texture.height==c.height||(this._temp_texture=new GL.Texture(c.width,c.height,{type:e,format:gl.RGBA,
|
||||
(function(w){var c=w.LiteGraph;if("undefined"!=typeof GL){var s=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};s._shader||(s._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,s.pixel_shader),s._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]}))};s.title="Lens";s.desc="Camera Lens distortion";s.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};s.prototype.onExecute=function(){var c=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,c);else if(c){this._tex=LGraphTexture.getTargetTexture(c,this._tex,this.properties.precision);var f=this.properties.aberration;this.isInputConnected(1)&&(f=this.getInputData(1),
|
||||
this.properties.aberration=f);var l=this.properties.distortion;this.isInputConnected(2)&&(l=this.getInputData(2),this.properties.distortion=l);var r=this.properties.blur;this.isInputConnected(3)&&(r=this.getInputData(3),this.properties.blur=r);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var w=Mesh.getScreenQuad(),e=s._shader;this._tex.drawTo(function(){c.bind(0);e.uniforms({u_texture:0,u_aberration:f,u_distortion:l,u_blur:r}).draw(w)});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_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";
|
||||
c.registerNodeType("fx/lens",s);w.LGraphFXLens=s;var l=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}};l.title="Bokeh";l.desc="applies an Bokeh effect";l.widgets_info={shape:{widget:"texture"}};l.prototype.onExecute=function(){var c=this.getInputData(0),f=this.getInputData(1),r=this.getInputData(2);
|
||||
if(c&&r&&this.properties.shape){f||(f=c);var s=LGraphTexture.getTexture(this.properties.shape);if(s){var w=this.properties.threshold;this.isInputConnected(3)&&(w=this.getInputData(3),this.properties.threshold=w);var e=gl.UNSIGNED_BYTE;this.properties.high_precision&&(e=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==e&&this._temp_texture.width==c.width&&this._temp_texture.height==c.height||(this._temp_texture=new GL.Texture(c.width,c.height,{type:e,format:gl.RGBA,
|
||||
filter:gl.LINEAR}));var x=l._first_shader;x||(x=l._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,l._first_pixel_shader));var g=l._second_shader;g||(g=l._second_shader=new GL.Shader(l._second_vertex_shader,l._second_pixel_shader));var m=this._points_mesh;m&&m._width==c.width&&m._height==c.height&&2==m._spacing||(m=this.createPointsMesh(c.width,c.height,2));var C=Mesh.getScreenQuad(),h=this.properties.size,q=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){c.bind(0);
|
||||
f.bind(1);s.bind(2);x.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[c.width,c.height]}).draw(C)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);c.bind(0);r.bind(3);g.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:q,u_threshold:w,u_pointSize:h,u_itexsize:[1/c.width,1/c.height]}).draw(m,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,c)};l.prototype.createPointsMesh=function(c,f,l){for(var s=Math.round(c/l),r=Math.round(f/
|
||||
l),e=new Float32Array(s*r*2),w=-1,g=2/c*l,m=2/f*l,C=0;C<r;++C){for(var h=-1,q=0;q<s;++q){var p=C*s*2+2*q;e[p]=h;e[p+1]=w;h+=g}w+=m}this._points_mesh=GL.Mesh.load({vertices2D:e});this._points_mesh._width=c;this._points_mesh._height=f;this._points_mesh._spacing=l;return this._points_mesh};l._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";
|
||||
f.bind(1);r.bind(2);x.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[c.width,c.height]}).draw(C)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);c.bind(0);s.bind(3);g.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:q,u_threshold:w,u_pointSize:h,u_itexsize:[1/c.width,1/c.height]}).draw(m,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,c)};l.prototype.createPointsMesh=function(c,f,l){for(var r=Math.round(c/l),s=Math.round(f/
|
||||
l),e=new Float32Array(r*s*2),w=-1,g=2/c*l,m=2/f*l,C=0;C<s;++C){for(var h=-1,q=0;q<r;++q){var p=C*r*2+2*q;e[p]=h;e[p+1]=w;h+=g}w+=m}this._points_mesh=GL.Mesh.load({vertices2D:e});this._points_mesh._width=c;this._points_mesh._height=f;this._points_mesh._spacing=l;return this._points_mesh};l._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";
|
||||
l._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";
|
||||
l._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";c.registerNodeType("fx/bokeh",l);w.LGraphFXBokeh=l;var f=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}};f.title="FX";f.desc="applies an FX from a list";f.widgets_info={fx:{widget:"combo",values:["halftone","pixelate","lowpalette","noise","gamma"]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};f.shaders={};f.prototype.onExecute=function(){if(this.isOutputConnected(0)){var c=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,c);else if(c){this._tex=
|
||||
LGraphTexture.getTargetTexture(c,this._tex,this.properties.precision);var l=this.properties.value1;this.isInputConnected(1)&&(l=this.getInputData(1),this.properties.value1=l);var s=this.properties.value2;this.isInputConnected(2)&&(s=this.getInputData(2),this.properties.value2=s);var r=this.properties.fx,z=f.shaders[r];if(!z){var e=f["pixel_shader_"+r];if(!e)return;z=f.shaders[r]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,e)}gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var x=Mesh.getScreenQuad(),
|
||||
g;g=w.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var m=null;"noise"==r&&(m=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){c.bind(0);"noise"==r&&m.bind(1);z.uniforms({u_texture:0,u_noise:1,u_size:[c.width,c.height],u_rand:[Math.random(),Math.random()],u_value1:l,u_value2:s,u_camera_planes:g}).draw(x)});this.setOutputData(0,this._tex)}}};f.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";
|
||||
LGraphTexture.getTargetTexture(c,this._tex,this.properties.precision);var l=this.properties.value1;this.isInputConnected(1)&&(l=this.getInputData(1),this.properties.value1=l);var r=this.properties.value2;this.isInputConnected(2)&&(r=this.getInputData(2),this.properties.value2=r);var s=this.properties.fx,z=f.shaders[s];if(!z){var e=f["pixel_shader_"+s];if(!e)return;z=f.shaders[s]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,e)}gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var x=Mesh.getScreenQuad(),
|
||||
g;g=w.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var m=null;"noise"==s&&(m=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){c.bind(0);"noise"==s&&m.bind(1);z.uniforms({u_texture:0,u_noise:1,u_size:[c.width,c.height],u_rand:[Math.random(),Math.random()],u_value1:l,u_value2:r,u_camera_planes:g}).draw(x)});this.setOutputData(0,this._tex)}}};f.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";
|
||||
f.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";f.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";
|
||||
f.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";
|
||||
f.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";c.registerNodeType("fx/generic",f);w.LGraphFXGeneric=f;var s=function(){this.addInput("Tex.","Texture");this.addInput("intensity","number");this.addOutput("Texture",
|
||||
"Texture");this.properties={intensity:1,invert:!1,precision:LGraphTexture.DEFAULT};s._shader||(s._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.pixel_shader))};s.title="Vigneting";s.desc="Vigneting";s.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};s.prototype.onExecute=function(){var c=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,c);else if(c){this._tex=LGraphTexture.getTargetTexture(c,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 l=Mesh.getScreenQuad(),r=s._shader,w=this.properties.invert;this._tex.drawTo(function(){c.bind(0);r.uniforms({u_texture:0,u_intensity:f,u_isize:[1/c.width,1/c.height],u_invert:w?1:0}).draw(l)});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 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";
|
||||
c.registerNodeType("fx/vigneting",s);w.LGraphFXVigneting=s}})(this);
|
||||
(function(w){function c(c){this.cmd=this.channel=0;this.data=new Uint32Array(3);c&&this.setup(c)}function r(c,e){navigator.requestMIDIAccess?(this.on_ready=c,this.state={note:[],cc:[]},navigator.requestMIDIAccess().then(this.onMIDISuccess.bind(this),this.onMIDIFailure.bind(this))):(this.error="not suppoorted",e?e("Not supported"):console.error("MIDI NOT SUPPORTED, enable by chrome://flags"))}function l(){this.addOutput("on_midi",m.EVENT);this.addOutput("out","midi");this.properties={port:0};this._current_midi_event=
|
||||
this._last_midi_event=null;this.boxcolor="#AAA";this._last_time=0;var c=this;new r(function(e){c._midi=e;if(c._waiting)c.onStart();c._waiting=!1})}function f(){this.addInput("send",m.EVENT);this.properties={port:0};var c=this;new r(function(e){c._midi=e})}function s(){this.addInput("on_midi",m.EVENT);this._str="";this.size=[200,40]}function k(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};var c=this;this._learning=!1;this.addWidget("button","Learn","",function(){c._learning=!0;c.boxcolor=
|
||||
f.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";c.registerNodeType("fx/generic",f);w.LGraphFXGeneric=f;var r=function(){this.addInput("Tex.","Texture");this.addInput("intensity","number");this.addOutput("Texture",
|
||||
"Texture");this.properties={intensity:1,invert:!1,precision:LGraphTexture.DEFAULT};r._shader||(r._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,r.pixel_shader))};r.title="Vigneting";r.desc="Vigneting";r.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};r.prototype.onExecute=function(){var c=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,c);else if(c){this._tex=LGraphTexture.getTargetTexture(c,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 l=Mesh.getScreenQuad(),s=r._shader,w=this.properties.invert;this._tex.drawTo(function(){c.bind(0);s.uniforms({u_texture:0,u_intensity:f,u_isize:[1/c.width,1/c.height],u_invert:w?1:0}).draw(l)});this.setOutputData(0,this._tex)}};r.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_intensity;\n\t\t\tuniform int u_invert;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat luminance = 1.0 - length( v_coord - vec2(0.5) ) * 1.414;\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tif(u_invert == 1)\n\t\t\t\t\tluminance = 1.0 - luminance;\n\t\t\t\tluminance = mix(1.0, luminance, u_intensity);\n\t\t\t gl_FragColor = vec4( luminance * color.xyz, color.a);\n\t\t\t}\n\t\t\t";
|
||||
c.registerNodeType("fx/vigneting",r);w.LGraphFXVigneting=r}})(this);
|
||||
(function(w){function c(c){this.cmd=this.channel=0;this.data=new Uint32Array(3);c&&this.setup(c)}function s(c,e){navigator.requestMIDIAccess?(this.on_ready=c,this.state={note:[],cc:[]},navigator.requestMIDIAccess().then(this.onMIDISuccess.bind(this),this.onMIDIFailure.bind(this))):(this.error="not suppoorted",e?e("Not supported"):console.error("MIDI NOT SUPPORTED, enable by chrome://flags"))}function l(){this.addOutput("on_midi",m.EVENT);this.addOutput("out","midi");this.properties={port:0};this._current_midi_event=
|
||||
this._last_midi_event=null;this.boxcolor="#AAA";this._last_time=0;var c=this;new s(function(e){c._midi=e;if(c._waiting)c.onStart();c._waiting=!1})}function f(){this.addInput("send",m.EVENT);this.properties={port:0};var c=this;new s(function(e){c._midi=e})}function r(){this.addInput("on_midi",m.EVENT);this._str="";this.size=[200,40]}function k(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};var c=this;this._learning=!1;this.addWidget("button","Learn","",function(){c._learning=!0;c.boxcolor=
|
||||
"#FA3"});this.addInput("in",m.EVENT);this.addOutput("on_midi",m.EVENT);this.boxcolor="#AAA"}function y(){this.properties={channel:0,cmd:144,value1:1,value2:1};this.addInput("send",m.EVENT);this.addInput("assign",m.EVENT);this.addOutput("on_midi",m.EVENT);this.midi_event=new c;this.gate=!1}function u(){this.properties={cc:1,value:0};this.addOutput("value","number")}function v(){this.addInput("generate",m.ACTION);this.addInput("scale","string");this.addInput("octave","number");this.addOutput("note",
|
||||
m.EVENT);this.properties={notes:"A,A#,B,C,C#,D,D#,E,F,F#,G,G#",octave:2,duration:0.5,mode:"sequence"};this.notes_pitches=v.processScale(this.properties.notes);this.sequence_index=0}function z(){this.properties={amount:0};this.addInput("in",m.ACTION);this.addInput("amount","number");this.addOutput("out",m.EVENT);this.midi_event=new c}function e(){this.properties={scale:"A,A#,B,C,C#,D,D#,E,F,F#,G,G#"};this.addInput("note",m.ACTION);this.addInput("scale","string");this.addOutput("out",m.EVENT);this.valid_notes=
|
||||
Array(12);this.offset_notes=Array(12);this.processScale(this.properties.scale)}function x(){this.properties={volume:0.5,duration:1};this.addInput("note",m.ACTION);this.addInput("volume","number");this.addInput("duration","number");this.addOutput("note",m.EVENT);"undefined"==typeof AudioSynth?(console.error("Audiosynth.js not included, LGMidiPlay requires that library"),this.boxcolor="red"):this.instrument=(this.synth=new AudioSynth).createInstrument("piano")}function g(){this.properties={num_octaves:2,
|
||||
@@ -574,22 +574,22 @@ Object.defineProperty(c.prototype,"octave",{get:function(){return this.cmd!=c.NO
|
||||
case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return c.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return c.CHANNELPRESSURE;case "PITCH BEND":case "PITCHBEND":return c.PITCHBEND;case "TIME TICK":case "TIMETICK":return c.TIMETICK;default:return Number(e)}};c.toNoteString=function(e,f){e=Math.round(e);var g,a=Math.floor((e-24)/12+1);g=(e-21)%12;0>g&&(g=12+g);return c.notes[g]+(f?"":a)};c.NoteStringToPitch=function(e){e=e.toUpperCase();var f=e[0],g=4;"#"==e[1]?(f+="#",2<e.length&&
|
||||
(g=Number(e[2]))):1<e.length&&(g=Number(e[1]));e=c.note_to_index[f];return null==e?null:12*(g-1)+e+21};c.prototype.toString=function(){var e=""+this.channel+". ";switch(this.cmd){case c.NOTEON:e+="NOTEON "+c.toNoteString(this.data[1]);break;case c.NOTEOFF:e+="NOTEOFF "+c.toNoteString(this.data[1]);break;case c.CONTROLLERCHANGE:e+="CC "+this.data[1]+" "+this.data[2];break;case c.PROGRAMCHANGE:e+="PC "+this.data[1];break;case c.PITCHBEND:e+="PITCHBEND "+this.getPitchBend();break;case c.KEYPRESSURE:e+=
|
||||
"KEYPRESS "+this.data[1]}return e};c.prototype.toHexString=function(){for(var c="",e=0;e<this.data.length;e++)c+=this.data[e].toString(16)+" "};c.prototype.toJSON=function(){return{data:[this.data[0],this.data[1],this.data[2]],object_class:"MIDIEvent"}};c.NOTEOFF=128;c.NOTEON=144;c.KEYPRESSURE=160;c.CONTROLLERCHANGE=176;c.PROGRAMCHANGE=192;c.CHANNELPRESSURE=208;c.PITCHBEND=224;c.TIMETICK=248;c.commands={128:"note off",144:"note on",160:"key pressure",176:"controller change",192:"program change",208:"channel pressure",
|
||||
224:"pitch bend",240:"system",242:"Song pos",243:"Song select",246:"Tune request",248:"time tick",250:"Start Song",251:"Continue Song",252:"Stop Song",254:"Sensing",255:"Reset"};c.commands_short={128:"NOTEOFF",144:"NOTEOFF",160:"KEYP",176:"CC",192:"PC",208:"CP",224:"PB",240:"SYS",242:"POS",243:"SELECT",246:"TUNEREQ",248:"TT",250:"START",251:"CONTINUE",252:"STOP",254:"SENS",255:"RESET"};c.commands_reversed={};for(var C in c.commands)c.commands_reversed[c.commands[C]]=C;r.input=null;r.MIDIEvent=c;r.prototype.onMIDISuccess=
|
||||
function(c){console.log("MIDI ready!");console.log(c);this.midi=c;this.updatePorts();if(this.on_ready)this.on_ready(this)};r.prototype.updatePorts=function(){var c=this.midi;this.input_ports=c.inputs;for(var e=0,f=this.input_ports.values(),a=f.next();a&&!1===a.done;)a=a.value,console.log("Input port [type:'"+a.type+"'] id:'"+a.id+"' manufacturer:'"+a.manufacturer+"' name:'"+a.name+"' version:'"+a.version+"'"),e++,a=f.next();this.num_input_ports=e;e=0;this.output_ports=c.outputs;f=this.output_ports.values();
|
||||
for(a=f.next();a&&!1===a.done;)a=a.value,console.log("Output port [type:'"+a.type+"'] id:'"+a.id+"' manufacturer:'"+a.manufacturer+"' name:'"+a.name+"' version:'"+a.version+"'"),e++,a=f.next();this.num_output_ports=e};r.prototype.onMIDIFailure=function(c){console.error("Failed to get MIDI access - "+c)};r.prototype.openInputPort=function(e,f){var g=this.input_ports.get("input-"+e);if(!g)return!1;r.input=this;var a=this;g.onmidimessage=function(b){var d=new c(b.data);a.updateState(d);f&&f(b.data,d);
|
||||
if(r.on_message)r.on_message(b.data,d)};console.log("port open: ",g);return!0};r.parseMsg=function(c){};r.prototype.updateState=function(e){switch(e.cmd){case c.NOTEON:this.state.note[e.value1|0]=e.value2;break;case c.NOTEOFF:this.state.note[e.value1|0]=0;break;case c.CONTROLLERCHANGE:this.state.cc[e.getCC()]=e.getCCValue()}};r.prototype.sendMIDI=function(e,f){if(f){var g=this.output_ports.get("output-"+e);g&&(r.output=this,f.constructor===c?g.send(f.data):g.send(f))}};l.MIDIInterface=r;l.title="MIDI Input";
|
||||
224:"pitch bend",240:"system",242:"Song pos",243:"Song select",246:"Tune request",248:"time tick",250:"Start Song",251:"Continue Song",252:"Stop Song",254:"Sensing",255:"Reset"};c.commands_short={128:"NOTEOFF",144:"NOTEOFF",160:"KEYP",176:"CC",192:"PC",208:"CP",224:"PB",240:"SYS",242:"POS",243:"SELECT",246:"TUNEREQ",248:"TT",250:"START",251:"CONTINUE",252:"STOP",254:"SENS",255:"RESET"};c.commands_reversed={};for(var C in c.commands)c.commands_reversed[c.commands[C]]=C;s.input=null;s.MIDIEvent=c;s.prototype.onMIDISuccess=
|
||||
function(c){console.log("MIDI ready!");console.log(c);this.midi=c;this.updatePorts();if(this.on_ready)this.on_ready(this)};s.prototype.updatePorts=function(){var c=this.midi;this.input_ports=c.inputs;for(var e=0,f=this.input_ports.values(),a=f.next();a&&!1===a.done;)a=a.value,console.log("Input port [type:'"+a.type+"'] id:'"+a.id+"' manufacturer:'"+a.manufacturer+"' name:'"+a.name+"' version:'"+a.version+"'"),e++,a=f.next();this.num_input_ports=e;e=0;this.output_ports=c.outputs;f=this.output_ports.values();
|
||||
for(a=f.next();a&&!1===a.done;)a=a.value,console.log("Output port [type:'"+a.type+"'] id:'"+a.id+"' manufacturer:'"+a.manufacturer+"' name:'"+a.name+"' version:'"+a.version+"'"),e++,a=f.next();this.num_output_ports=e};s.prototype.onMIDIFailure=function(c){console.error("Failed to get MIDI access - "+c)};s.prototype.openInputPort=function(e,f){var g=this.input_ports.get("input-"+e);if(!g)return!1;s.input=this;var a=this;g.onmidimessage=function(b){var d=new c(b.data);a.updateState(d);f&&f(b.data,d);
|
||||
if(s.on_message)s.on_message(b.data,d)};console.log("port open: ",g);return!0};s.parseMsg=function(c){};s.prototype.updateState=function(e){switch(e.cmd){case c.NOTEON:this.state.note[e.value1|0]=e.value2;break;case c.NOTEOFF:this.state.note[e.value1|0]=0;break;case c.CONTROLLERCHANGE:this.state.cc[e.getCC()]=e.getCCValue()}};s.prototype.sendMIDI=function(e,f){if(f){var g=this.output_ports.get("output-"+e);g&&(s.output=this,f.constructor===c?g.send(f.data):g.send(f))}};l.MIDIInterface=s;l.title="MIDI Input";
|
||||
l.desc="Reads MIDI from a input port";l.color="#243";l.prototype.getPropertyInfo=function(c){if(this._midi&&"port"==c){c={};for(var e=0;e<this._midi.input_ports.size;++e){var f=this._midi.input_ports.get("input-"+e);c[e]=e+".- "+f.name+" version:"+f.version}return{type:"enum",values:c}}};l.prototype.onStart=function(){this._midi?this._midi.openInputPort(this.properties.port,this.onMIDIEvent.bind(this)):this._waiting=!0};l.prototype.onMIDIEvent=function(e,f){this._last_midi_event=f;this.boxcolor="#AFA";
|
||||
this._last_time=m.getTime();this.trigger("on_midi",f);f.cmd==c.NOTEON?this.trigger("on_noteon",f):f.cmd==c.NOTEOFF?this.trigger("on_noteoff",f):f.cmd==c.CONTROLLERCHANGE?this.trigger("on_cc",f):f.cmd==c.PROGRAMCHANGE?this.trigger("on_pc",f):f.cmd==c.PITCHBEND&&this.trigger("on_pitchbend",f)};l.prototype.onDrawBackground=function(c){this.boxcolor="#AAA";if(!this.flags.collapsed&&this._last_midi_event){c.fillStyle="white";var e=m.getTime(),e=1-Math.max(0,0.001*(e-this._last_time));if(0<e){var f=c.globalAlpha;
|
||||
c.globalAlpha*=e;c.font="12px Tahoma";c.fillText(this._last_midi_event.toString(),2,0.5*this.size[1]+3);c.globalAlpha=f}}};l.prototype.onExecute=function(){if(this.outputs)for(var c=this._last_midi_event,e=0;e<this.outputs.length;++e){var f=null;switch(this.outputs[e].name){case "midi":f=this._midi;break;case "last_midi":f=c;break;default:continue}this.setOutputData(e,f)}};l.prototype.onGetOutputs=function(){return[["last_midi","midi"],["on_midi",m.EVENT],["on_noteon",m.EVENT],["on_noteoff",m.EVENT],
|
||||
["on_cc",m.EVENT],["on_pc",m.EVENT],["on_pitchbend",m.EVENT]]};m.registerNodeType("midi/input",l);f.MIDIInterface=r;f.title="MIDI Output";f.desc="Sends MIDI to output channel";f.color="#243";f.prototype.getPropertyInfo=function(c){if(this._midi&&"port"==c){c={};for(var e=0;e<this._midi.output_ports.size;++e){var f=this._midi.output_ports.get(e);c[e]=e+".- "+f.name+" version:"+f.version}return{type:"enum",values:c}}};f.prototype.onAction=function(c,e){this._midi&&("send"==c&&this._midi.sendMIDI(this.port,
|
||||
e),this.trigger("midi",e))};f.prototype.onGetInputs=function(){return[["send",m.ACTION]]};f.prototype.onGetOutputs=function(){return[["on_midi",m.EVENT]]};m.registerNodeType("midi/output",f);s.title="MIDI Show";s.desc="Shows MIDI in the graph";s.color="#243";s.prototype.getTitle=function(){return this.flags.collapsed?this._str:this.title};s.prototype.onAction=function(e,f){f&&(this._str=f.constructor===c?f.toString():"???")};s.prototype.onDrawForeground=function(c){this._str&&!this.flags.collapsed&&
|
||||
(c.font="30px Arial",c.fillText(this._str,10,0.8*this.size[1]))};s.prototype.onGetInputs=function(){return[["in",m.ACTION]]};s.prototype.onGetOutputs=function(){return[["on_midi",m.EVENT]]};m.registerNodeType("midi/show",s);k.title="MIDI Filter";k.desc="Filters MIDI messages";k.color="#243";k["@cmd"]={type:"enum",title:"Command",values:c.commands_reversed};k.prototype.getTitle=function(){var e=null,e=-1==this.properties.cmd?"Nothing":c.commands_short[this.properties.cmd]||"Unknown";-1!=this.properties.min_value&&
|
||||
["on_cc",m.EVENT],["on_pc",m.EVENT],["on_pitchbend",m.EVENT]]};m.registerNodeType("midi/input",l);f.MIDIInterface=s;f.title="MIDI Output";f.desc="Sends MIDI to output channel";f.color="#243";f.prototype.getPropertyInfo=function(c){if(this._midi&&"port"==c){c={};for(var e=0;e<this._midi.output_ports.size;++e){var f=this._midi.output_ports.get(e);c[e]=e+".- "+f.name+" version:"+f.version}return{type:"enum",values:c}}};f.prototype.onAction=function(c,e){this._midi&&("send"==c&&this._midi.sendMIDI(this.port,
|
||||
e),this.trigger("midi",e))};f.prototype.onGetInputs=function(){return[["send",m.ACTION]]};f.prototype.onGetOutputs=function(){return[["on_midi",m.EVENT]]};m.registerNodeType("midi/output",f);r.title="MIDI Show";r.desc="Shows MIDI in the graph";r.color="#243";r.prototype.getTitle=function(){return this.flags.collapsed?this._str:this.title};r.prototype.onAction=function(e,f){f&&(this._str=f.constructor===c?f.toString():"???")};r.prototype.onDrawForeground=function(c){this._str&&!this.flags.collapsed&&
|
||||
(c.font="30px Arial",c.fillText(this._str,10,0.8*this.size[1]))};r.prototype.onGetInputs=function(){return[["in",m.ACTION]]};r.prototype.onGetOutputs=function(){return[["on_midi",m.EVENT]]};m.registerNodeType("midi/show",r);k.title="MIDI Filter";k.desc="Filters MIDI messages";k.color="#243";k["@cmd"]={type:"enum",title:"Command",values:c.commands_reversed};k.prototype.getTitle=function(){var e=null,e=-1==this.properties.cmd?"Nothing":c.commands_short[this.properties.cmd]||"Unknown";-1!=this.properties.min_value&&
|
||||
-1!=this.properties.max_value&&(e+=" "+(this.properties.min_value==this.properties.max_value?this.properties.max_value:this.properties.min_value+".."+this.properties.max_value));return"Filter: "+e};k.prototype.onPropertyChanged=function(e,f){if("cmd"==e){var g=Number(f);isNaN(g)&&(g=c.commands[f]||0);this.properties.cmd=g}};k.prototype.onAction=function(e,f){if(f&&f.constructor===c){if(this._learning)this._learning=!1,this.boxcolor="#AAA",this.properties.channel=f.channel,this.properties.cmd=f.cmd,
|
||||
this.properties.min_value=this.properties.max_value=f.data[1];else if(-1!=this.properties.channel&&f.channel!=this.properties.channel||-1!=this.properties.cmd&&f.cmd!=this.properties.cmd||-1!=this.properties.min_value&&f.data[1]<this.properties.min_value||-1!=this.properties.max_value&&f.data[1]>this.properties.max_value)return;this.trigger("on_midi",f)}};m.registerNodeType("midi/filter",k);y.title="MIDIEvent";y.desc="Create a MIDI Event";y.color="#243";y.prototype.onAction=function(e,f){"assign"==
|
||||
e?(this.properties.channel=f.channel,this.properties.cmd=f.cmd,this.properties.value1=f.data[1],this.properties.value2=f.data[2],f.cmd==c.NOTEON?this.gate=!0:f.cmd==c.NOTEOFF&&(this.gate=!1)):(f=this.midi_event,f.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?f.setCommandFromString(this.properties.cmd):f.cmd=this.properties.cmd,f.data[0]=f.cmd|f.channel,f.data[1]=Number(this.properties.value1),f.data[2]=Number(this.properties.value2),this.trigger("on_midi",
|
||||
f))};y.prototype.onExecute=function(){var e=this.properties;if(this.inputs)for(var f=0;f<this.inputs.length;++f){var g=this.inputs[f];if(-1!=g.link)switch(g.name){case "note":g=this.getInputData(f),null!=g&&(g.constructor===String&&(g=c.NoteStringToPitch(g)),this.properties.value1=(g|0)%255)}}if(this.outputs)for(f=0;f<this.outputs.length;++f){switch(this.outputs[f].name){case "midi":g=new c;g.setup([e.cmd,e.value1,e.value2]);g.channel=e.channel;break;case "command":g=e.cmd;break;case "cc":g=e.value1;
|
||||
break;case "cc_value":g=e.value2;break;case "note":g=e.cmd==c.NOTEON||e.cmd==c.NOTEOFF?e.value1:null;break;case "velocity":g=e.cmd==c.NOTEON?e.value2:null;break;case "pitch":g=e.cmd==c.NOTEON?c.computePitch(e.value1):null;break;case "pitchbend":g=e.cmd==c.PITCHBEND?c.computePitchBend(e.value1,e.value2):null;break;case "gate":g=this.gate;break;default:continue}null!==g&&this.setOutputData(f,g)}};y.prototype.onPropertyChanged=function(e,f){"cmd"==e&&(this.properties.cmd=c.computeCommandFromString(f))};
|
||||
y.prototype.onGetInputs=function(){return[["note","number"]]};y.prototype.onGetOutputs=function(){return[["midi","midi"],["on_midi",m.EVENT],["command","number"],["note","number"],["velocity","number"],["cc","number"],["cc_value","number"],["pitch","number"],["gate","bool"],["pitchbend","number"]]};m.registerNodeType("midi/event",y);u.title="MIDICC";u.desc="gets a Controller Change";u.color="#243";u.prototype.onExecute=function(){r.input&&(this.properties.value=r.input.state.cc[this.properties.cc]);
|
||||
y.prototype.onGetInputs=function(){return[["note","number"]]};y.prototype.onGetOutputs=function(){return[["midi","midi"],["on_midi",m.EVENT],["command","number"],["note","number"],["velocity","number"],["cc","number"],["cc_value","number"],["pitch","number"],["gate","bool"],["pitchbend","number"]]};m.registerNodeType("midi/event",y);u.title="MIDICC";u.desc="gets a Controller Change";u.color="#243";u.prototype.onExecute=function(){s.input&&(this.properties.value=s.input.state.cc[this.properties.cc]);
|
||||
this.setOutputData(0,this.properties.value)};m.registerNodeType("midi/cc",u);v.title="MIDI Generator";v.desc="Generates a random MIDI note";v.color="#243";v.processScale=function(e){e=e.split(",");for(var f=0;f<e.length;++f){var g=e[f];e[f]=2==g.length&&"#"!=g[1]||2<g.length?-m.MIDIEvent.NoteStringToPitch(g):c.note_to_index[g]||0}return e};v.prototype.onPropertyChanged=function(c,e){"notes"==c&&(this.notes_pitches=v.processScale(e))};v.prototype.onExecute=function(){var c=this.getInputData(2);null!=
|
||||
c&&(this.properties.octave=c);if(c=this.getInputData(1))this.notes_pitches=v.processScale(c)};v.prototype.onAction=function(e,f){var g=0,a=this.notes_pitches.length,b=0;"sequence"==this.properties.mode?b=this.sequence_index=(this.sequence_index+1)%a:"random"==this.properties.mode&&(b=Math.floor(Math.random()*a));a=this.notes_pitches[b];g=0<=a?a+12*(this.properties.octave-1)+33:-a;f=new c;f.setup([c.NOTEON,g,10]);a=this.properties.duration||1;this.trigger("note",f);setTimeout(function(){var a=new c;
|
||||
a.setup([c.NOTEOFF,g,0]);this.trigger("note",a)}.bind(this),1E3*a)};m.registerNodeType("midi/generator",v);z.title="MIDI Transpose";z.desc="Transpose a MIDI note";z.color="#243";z.prototype.onAction=function(e,f){f&&f.constructor===c&&(f.data[0]==c.NOTEON||f.data[0]==c.NOTEOFF?(this.midi_event=new c,this.midi_event.setup(f.data),this.midi_event.data[1]=Math.round(this.midi_event.data[1]+this.properties.amount),this.trigger("out",this.midi_event)):this.trigger("out",f))};z.prototype.onExecute=function(){var c=
|
||||
@@ -601,9 +601,9 @@ this.keys.length=e;var f=this.size[0]/(7*this.properties.num_octaves),a=this.siz
|
||||
7*Math.floor(b/12)*e+d.x*e,n=e*d.w,d=f*d.h;if(!(c[0]<k||c[0]>k+n||c[1]>d))return b}}return-1};g.prototype.onAction=function(e,f){if("reset"==e)for(var g=0;g<this.keys.length;++g)this.keys[g]=!1;else f&&f.constructor===c&&(g=f.data[1]-(12*(this.properties.start_octave-1)+29),0<=g&&g<this.keys.length&&(f.data[0]==c.NOTEON?this.keys[g]=!0:f.data[0]==c.NOTEOFF&&(this.keys[g]=!1)),this.trigger("note",f))};g.prototype.onMouseDown=function(e,f){if(!(0>f[1])){var g=this.getKeyIndex(f);this.keys[g]=!0;this._last_key=
|
||||
g;var g=12*(this.properties.start_octave-1)+29+g,a=new c;a.setup([c.NOTEON,g,100]);this.trigger("note",a);return!0}};g.prototype.onMouseMove=function(e,f){if(!(0>f[1]||-1==this._last_key)){this.setDirtyCanvas(!0);var g=this.getKeyIndex(f);if(this._last_key==g)return!0;this.keys[this._last_key]=!1;var a=12*(this.properties.start_octave-1)+29+this._last_key,b=new c;b.setup([c.NOTEOFF,a,100]);this.trigger("note",b);this.keys[g]=!0;a=12*(this.properties.start_octave-1)+29+g;b=new c;b.setup([c.NOTEON,
|
||||
a,100]);this.trigger("note",b);this._last_key=g;return!0}};g.prototype.onMouseUp=function(e,f){if(!(0>f[1])){var g=this.getKeyIndex(f);this.keys[g]=!1;this._last_key=-1;var g=12*(this.properties.start_octave-1)+29+g,a=new c;a.setup([c.NOTEOFF,g,100]);this.trigger("note",a);return!0}};m.registerNodeType("midi/keys",g)})(this);
|
||||
(function(w){function c(){this.properties={src:"",gain:0.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audiobuffer=null;this._audionodes=[];this._last_sourcenode=null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=p.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function r(){this.properties={gain:0.5};this._audionodes=[];this._media_stream=
|
||||
(function(w){function c(){this.properties={src:"",gain:0.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audiobuffer=null;this._audionodes=[];this._last_sourcenode=null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=p.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function s(){this.properties={gain:0.5};this._audionodes=[];this._media_stream=
|
||||
null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=p.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function l(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:0.5};this.audionode=p.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 f(){this.properties={gain:1};this.audionode=p.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function s(){this.properties={impulse_src:"",normalize:!0};this.audionode=p.getAudioContext().createConvolver();
|
||||
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 f(){this.properties={gain:1};this.audionode=p.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function r(){this.properties={impulse_src:"",normalize:!0};this.audionode=p.getAudioContext().createConvolver();
|
||||
this.addInput("in","audio");this.addOutput("out","audio")}function k(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=p.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function y(){this.properties={};this.audionode=p.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function u(){this.properties={gain1:0.5,gain2:0.5};
|
||||
this.audionode=p.getAudioContext().createGain();this.audionode1=p.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=p.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 v(){this.properties=
|
||||
{A:0.1,D:0.1,S:0.1,R:0.1};this.audionode=p.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","bool");this.addOutput("out","audio");this.gate=!1}function z(){this.properties={delayTime:0.5};this.audionode=p.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function e(){this.properties={frequency:350,detune:0,Q:1};
|
||||
@@ -620,15 +620,15 @@ this.properties.autoplay&&this.playBuffer(this._audiobuffer)};c.prototype.onStop
|
||||
0;a<this.outputs.length;++a)"buffer"==this.outputs[a].name&&this._audiobuffer&&this.setOutputData(a,this._audiobuffer)};c.prototype.onAction=function(a){this._audiobuffer&&("Play"==a?this.playBuffer(this._audiobuffer):"Stop"==a&&this.stopAllSounds())};c.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};c.prototype.playBuffer=
|
||||
function(a){var b=this,c=p.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};c.prototype.loadSound=function(a){function b(a){this.boxcolor=q.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=p.loadSound(a,b),this._loading_audio=!0,this.boxcolor="#AA4")};c.prototype.onConnectionsChange=p.onConnectionsChange;c.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",q.ACTION],["Stop",q.ACTION]]};c.prototype.onGetOutputs=function(){return[["buffer",
|
||||
"audiobuffer"],["ended",q.EVENT]]};c.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};c.title="Source";c.desc="Plays audio";q.registerNodeType("audio/source",c);r.prototype.onAdded=function(a){if(a.status===LGraph.STATUS_RUNNING)this.onStart()};r.prototype.onStart=function(){null!=this._media_stream||this._waiting_confirmation||this.openStream()};r.prototype.onStop=function(){this.audionode.gain.value=
|
||||
0};r.prototype.onPause=function(){this.audionode.gain.value=0};r.prototype.onUnpause=function(){this.audionode.gain.value=this.properties.gain};r.prototype.onRemoved=function(){this.audionode.gain.value=0;this.audiosource_node&&(this.audiosource_node.disconnect(this.audionode),this.audiosource_node=null);if(this._media_stream){var a=this._media_stream.getTracks();a.length&&a[0].stop()}};r.prototype.openStream=function(){function a(a){console.log("Media rejected",a);b._media_stream=!1;b.boxcolor="red"}
|
||||
if(navigator.mediaDevices){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then(this.streamReady.bind(this))["catch"](a);var b=this}else console.log("getUserMedia() is not supported in your browser, use chrome and enable WebRTC from about://flags")};r.prototype.streamReady=function(a){this._media_stream=a;this.audiosource_node&&this.audiosource_node.disconnect(this.audionode);this.audiosource_node=p.getAudioContext().createMediaStreamSource(a);this.audiosource_node.graphnode=
|
||||
this;this.audiosource_node.connect(this.audionode);this.boxcolor="white"};r.prototype.onExecute=function(){null!=this._media_stream||this._waiting_confirmation||this.openStream();if(this.inputs)for(var a=0;a<this.inputs.length;++a){var b=this.inputs[a];if(null!=b.link){var c=this.getInputData(a);void 0!==c&&"gain"==b.name&&(this.audionode.gain.value=this.properties.gain=c)}}};r.prototype.onAction=function(a){"Play"==a?this.audionode.gain.value=this.properties.gain:"Stop"==a&&(this.audionode.gain.value=
|
||||
0)};r.prototype.onPropertyChanged=function(a,b){"gain"==a&&(this.audionode.gain.value=b)};r.prototype.onConnectionsChange=p.onConnectionsChange;r.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",q.ACTION],["Stop",q.ACTION]]};r.title="MediaSource";r.desc="Plays microphone";q.registerNodeType("audio/media_source",r);l.prototype.onPropertyChanged=function(a,b){this.audionode[a]=b};l.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.audionode.frequencyBinCount;
|
||||
"audiobuffer"],["ended",q.EVENT]]};c.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};c.title="Source";c.desc="Plays audio";q.registerNodeType("audio/source",c);s.prototype.onAdded=function(a){if(a.status===LGraph.STATUS_RUNNING)this.onStart()};s.prototype.onStart=function(){null!=this._media_stream||this._waiting_confirmation||this.openStream()};s.prototype.onStop=function(){this.audionode.gain.value=
|
||||
0};s.prototype.onPause=function(){this.audionode.gain.value=0};s.prototype.onUnpause=function(){this.audionode.gain.value=this.properties.gain};s.prototype.onRemoved=function(){this.audionode.gain.value=0;this.audiosource_node&&(this.audiosource_node.disconnect(this.audionode),this.audiosource_node=null);if(this._media_stream){var a=this._media_stream.getTracks();a.length&&a[0].stop()}};s.prototype.openStream=function(){function a(a){console.log("Media rejected",a);b._media_stream=!1;b.boxcolor="red"}
|
||||
if(navigator.mediaDevices){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then(this.streamReady.bind(this))["catch"](a);var b=this}else console.log("getUserMedia() is not supported in your browser, use chrome and enable WebRTC from about://flags")};s.prototype.streamReady=function(a){this._media_stream=a;this.audiosource_node&&this.audiosource_node.disconnect(this.audionode);this.audiosource_node=p.getAudioContext().createMediaStreamSource(a);this.audiosource_node.graphnode=
|
||||
this;this.audiosource_node.connect(this.audionode);this.boxcolor="white"};s.prototype.onExecute=function(){null!=this._media_stream||this._waiting_confirmation||this.openStream();if(this.inputs)for(var a=0;a<this.inputs.length;++a){var b=this.inputs[a];if(null!=b.link){var c=this.getInputData(a);void 0!==c&&"gain"==b.name&&(this.audionode.gain.value=this.properties.gain=c)}}};s.prototype.onAction=function(a){"Play"==a?this.audionode.gain.value=this.properties.gain:"Stop"==a&&(this.audionode.gain.value=
|
||||
0)};s.prototype.onPropertyChanged=function(a,b){"gain"==a&&(this.audionode.gain.value=b)};s.prototype.onConnectionsChange=p.onConnectionsChange;s.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",q.ACTION],["Stop",q.ACTION]]};s.title="MediaSource";s.desc="Plays microphone";q.registerNodeType("audio/media_source",s);l.prototype.onPropertyChanged=function(a,b){this.audionode[a]=b};l.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)}}};l.prototype.onGetInputs=function(){return[["minDecibels","number"],["maxDecibels","number"],["smoothingTimeConstant","number"]]};l.prototype.onGetOutputs=function(){return[["freqs","array"],["samples","array"]]};l.title="Analyser";l.desc="Audio Analyser";q.registerNodeType("audio/analyser",l);f.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)}};p.createAudioNodeWrapper(f);f.title="Gain";f.desc="Audio gain";q.registerNodeType("audio/gain",f);p.createAudioNodeWrapper(s);s.prototype.onRemove=function(){this._dropped_url&&URL.revokeObjectURL(this._dropped_url)};s.prototype.onPropertyChanged=function(a,b){"impulse_src"==a?this.loadImpulse(b):"normalize"==a&&(this.audionode.normalize=b)};s.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)};s.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=p.loadSound(a,b),this._loading_impulse=!0)};s.title="Convolver";s.desc="Convolves the signal (used for reverb)";q.registerNodeType("audio/convolver",s);p.createAudioNodeWrapper(k);
|
||||
c)}};p.createAudioNodeWrapper(f);f.title="Gain";f.desc="Audio gain";q.registerNodeType("audio/gain",f);p.createAudioNodeWrapper(r);r.prototype.onRemove=function(){this._dropped_url&&URL.revokeObjectURL(this._dropped_url)};r.prototype.onPropertyChanged=function(a,b){"impulse_src"==a?this.loadImpulse(b):"normalize"==a&&(this.audionode.normalize=b)};r.prototype.onDropFile=function(a){this._dropped_url&&URL.revokeObjectURL(this._dropped_url);this._dropped_url=URL.createObjectURL(a);this.properties.impulse_src=
|
||||
this._dropped_url;this.loadImpulse(this._dropped_url)};r.prototype.loadImpulse=function(a){function b(a){c._impulse_buffer=a;c.audionode.buffer=a;console.log("Impulse signal set");c._loading_impulse=!1}var c=this;this._request&&(this._request.abort(),this._request=null);this._impulse_buffer=null;this._loading_impulse=!1;a&&(this._request=p.loadSound(a,b),this._loading_impulse=!0)};r.title="Convolver";r.desc="Convolves the signal (used for reverb)";q.registerNodeType("audio/convolver",r);p.createAudioNodeWrapper(k);
|
||||
k.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)}}};k.prototype.onGetInputs=function(){return[["threshold","number"],["knee","number"],["ratio","number"],["reduction","number"],["attack","number"],["release","number"]]};k.title="DynamicsCompressor";k.desc="Dynamics Compressor";q.registerNodeType("audio/dynamicsCompressor",k);y.prototype.onExecute=
|
||||
function(){if(this.inputs&&this.inputs.length){var a=this.getInputData(1);void 0!==a&&(this.audionode.curve=a)}};y.prototype.setWaveShape=function(a){this.audionode.curve=a};p.createAudioNodeWrapper(y);u.prototype.getAudioNodeInInputSlot=function(a){if(0==a)return this.audionode1;if(2==a)return this.audionode2};u.prototype.onPropertyChanged=function(a,b){"gain1"==a?this.audionode1.gain.value=b:"gain2"==a&&(this.audionode2.gain.value=b)};u.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)))}};p.createAudioNodeWrapper(u);u.title="Mixer";u.desc="Audio mixer";q.registerNodeType("audio/mixer",u);v.prototype.onExecute=function(){var a=p.getAudioContext().currentTime,b=this.audionode.gain,c=this.getInputData(1),e=this.getInputOrProperty("A"),f=this.getInputOrProperty("D"),g=this.getInputOrProperty("S"),
|
||||
@@ -642,14 +642,14 @@ b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.
|
||||
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 e=
|
||||
b.getChannelData(c),f=a.getChannelData(c),g=0;g<b.length;g++)f[g]=e[g]}};p.createAudioNodeWrapper(C);C.title="Script";C.desc="apply script to signal";q.registerNodeType("audio/script",C);h.title="Destination";h.desc="Audio output";q.registerNodeType("audio/destination",h)})(this);
|
||||
(function(w){function c(){this.size=[60,20];this.addInput("send",l.ACTION);this.addOutput("received",l.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph",only_send_changes:!0};this._ws=null;this._last_sent_data=[];this._last_received_data=[]}function r(){this.room_widget=this.addWidget("text","Room","lgraph",this.setRoom.bind(this));this.addWidget("button","Reconnect",null,this.connectSocket.bind(this));this.addInput("send",l.ACTION);this.addOutput("received",
|
||||
(function(w){function c(){this.size=[60,20];this.addInput("send",l.ACTION);this.addOutput("received",l.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph",only_send_changes:!0};this._ws=null;this._last_sent_data=[];this._last_received_data=[]}function s(){this.room_widget=this.addWidget("text","Room","lgraph",this.setRoom.bind(this));this.addWidget("button","Reconnect",null,this.connectSocket.bind(this));this.addInput("send",l.ACTION);this.addOutput("received",
|
||||
l.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"tamats.com:55000",room:"lgraph",only_send_changes:!0};this._server=null;this.connectSocket();this._last_sent_data=[];this._last_received_data=[];"undefined"==typeof SillyClient&&console.warn("remember to add SillyClient.js to your project: https://tamats.com/projects/sillyserver/src/sillyclient.js")}var l=w.LiteGraph;c.title="WebSocket";c.desc="Send data through a websocket";c.prototype.onPropertyChanged=function(c,l){"url"==
|
||||
c&&this.connectSocket()};c.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var c=this.properties.room,l=this.properties.only_send_changes,k=1;k<this.inputs.length;++k){var r=this.getInputData(k);if(null!=r){var u;try{u=JSON.stringify({type:0,room:c,channel:k,data:r})}catch(v){continue}l&&this._last_sent_data[k]==u||(this._last_sent_data[k]=u,this._ws.send(u))}}for(k=1;k<this.outputs.length;++k)this.setOutputData(k,
|
||||
this._last_received_data[k]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};c.prototype.connectSocket=function(){var c=this,s=this.properties.url;"ws"!=s.substr(0,2)&&(s="ws://"+s);this._ws=new WebSocket(s);this._ws.onopen=function(){console.log("ready");c.boxcolor="#6C6"};this._ws.onmessage=function(k){c.boxcolor="#AFA";var s=JSON.parse(k.data);if(!s.room||s.room==this.properties.room)if(1==k.data.type)if(s.data.object_class&&l[s.data.object_class]){k=null;try{k=new l[s.data.object_class](s.data),
|
||||
c.triggerSlot(0,k)}catch(r){}}else c.triggerSlot(0,s.data);else c._last_received_data[k.data.channel||0]=s.data};this._ws.onerror=function(k){console.log("couldnt connect to websocket");c.boxcolor="#E88"};this._ws.onclose=function(k){console.log("connection closed");c.boxcolor="#000"}};c.prototype.send=function(c){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:c}))};c.prototype.onAction=function(c,l){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,
|
||||
room:this.properties.room,action:c,data:l})};c.prototype.onGetInputs=function(){return[["in",0]]};c.prototype.onGetOutputs=function(){return[["out",0]]};l.registerNodeType("network/websocket",c);r.title="SillyClient";r.desc="Connects to SillyServer to broadcast messages";r.prototype.onPropertyChanged=function(c,l){"room"==c&&(this.room_widget.value=l);this.connectSocket()};r.prototype.setRoom=function(c){this.properties.room=c;this.room_widget.value=c;this.connectSocket()};r.prototype.onDrawForeground=
|
||||
function(){for(var c=1;c<this.inputs.length;++c){var l=this.inputs[c];l.label="in_"+c}for(c=1;c<this.outputs.length;++c)l=this.outputs[c],l.label="out_"+c};r.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var c=this.properties.only_send_changes,l=1;l<this.inputs.length;++l){var k=this.getInputData(l),r=this._last_sent_data[l];if(null!=k){if(c){var u=!0;if(k&&k.length&&r&&r.length==k.length&&k.constructor!==String)for(var v=0;v<k.length;++v){if(r[v]!=k[v]){u=!1;break}}else this._last_sent_data[l]!=
|
||||
k&&(u=!1);if(u)continue}this._server.sendMessage({type:0,channel:l,data:k});if(k.length&&k.constructor!==String)if(this._last_sent_data[l])for(this._last_sent_data[l].length=k.length,v=0;v<k.length;++v)this._last_sent_data[l][v]=k[v];else this._last_sent_data[l]=k.constructor===Array?k.concat():new k.constructor(k);else this._last_sent_data[l]=k}}for(l=1;l<this.outputs.length;++l)this.setOutputData(l,this._last_received_data[l]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};r.prototype.connectSocket=
|
||||
c&&this.connectSocket()};c.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var c=this.properties.room,l=this.properties.only_send_changes,k=1;k<this.inputs.length;++k){var s=this.getInputData(k);if(null!=s){var u;try{u=JSON.stringify({type:0,room:c,channel:k,data:s})}catch(v){continue}l&&this._last_sent_data[k]==u||(this._last_sent_data[k]=u,this._ws.send(u))}}for(k=1;k<this.outputs.length;++k)this.setOutputData(k,
|
||||
this._last_received_data[k]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};c.prototype.connectSocket=function(){var c=this,r=this.properties.url;"ws"!=r.substr(0,2)&&(r="ws://"+r);this._ws=new WebSocket(r);this._ws.onopen=function(){console.log("ready");c.boxcolor="#6C6"};this._ws.onmessage=function(k){c.boxcolor="#AFA";var r=JSON.parse(k.data);if(!r.room||r.room==this.properties.room)if(1==k.data.type)if(r.data.object_class&&l[r.data.object_class]){k=null;try{k=new l[r.data.object_class](r.data),
|
||||
c.triggerSlot(0,k)}catch(s){}}else c.triggerSlot(0,r.data);else c._last_received_data[k.data.channel||0]=r.data};this._ws.onerror=function(k){console.log("couldnt connect to websocket");c.boxcolor="#E88"};this._ws.onclose=function(k){console.log("connection closed");c.boxcolor="#000"}};c.prototype.send=function(c){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:c}))};c.prototype.onAction=function(c,l){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,
|
||||
room:this.properties.room,action:c,data:l})};c.prototype.onGetInputs=function(){return[["in",0]]};c.prototype.onGetOutputs=function(){return[["out",0]]};l.registerNodeType("network/websocket",c);s.title="SillyClient";s.desc="Connects to SillyServer to broadcast messages";s.prototype.onPropertyChanged=function(c,l){"room"==c&&(this.room_widget.value=l);this.connectSocket()};s.prototype.setRoom=function(c){this.properties.room=c;this.room_widget.value=c;this.connectSocket()};s.prototype.onDrawForeground=
|
||||
function(){for(var c=1;c<this.inputs.length;++c){var l=this.inputs[c];l.label="in_"+c}for(c=1;c<this.outputs.length;++c)l=this.outputs[c],l.label="out_"+c};s.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var c=this.properties.only_send_changes,l=1;l<this.inputs.length;++l){var k=this.getInputData(l),s=this._last_sent_data[l];if(null!=k){if(c){var u=!0;if(k&&k.length&&s&&s.length==k.length&&k.constructor!==String)for(var v=0;v<k.length;++v){if(s[v]!=k[v]){u=!1;break}}else this._last_sent_data[l]!=
|
||||
k&&(u=!1);if(u)continue}this._server.sendMessage({type:0,channel:l,data:k});if(k.length&&k.constructor!==String)if(this._last_sent_data[l])for(this._last_sent_data[l].length=k.length,v=0;v<k.length;++v)this._last_sent_data[l][v]=k[v];else this._last_sent_data[l]=k.constructor===Array?k.concat():new k.constructor(k);else this._last_sent_data[l]=k}}for(l=1;l<this.outputs.length;++l)this.setOutputData(l,this._last_received_data[l]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};s.prototype.connectSocket=
|
||||
function(){var c=this;if("undefined"==typeof SillyClient)this._error||console.error("SillyClient node cannot be used, you must include SillyServer.js"),this._error=!0;else if(this._server=new SillyClient,this._server.on_ready=function(){console.log("ready");c.boxcolor="#6C6"},this._server.on_message=function(k,s){var r=null;try{r=JSON.parse(s)}catch(v){return}if(1==r.type)if(r.data.object_class&&l[r.data.object_class]){var w=null;try{w=new l[r.data.object_class](r.data),c.triggerSlot(0,w)}catch(e){return}}else c.triggerSlot(0,
|
||||
r.data);else c._last_received_data[r.channel||0]=r.data;c.boxcolor="#AFA"},this._server.on_error=function(k){console.log("couldnt connect to websocket");c.boxcolor="#E88"},this._server.on_close=function(k){console.log("connection closed");c.boxcolor="#000"},this.properties.url&&this.properties.room){try{this._server.connect(this.properties.url,this.properties.room)}catch(s){console.error("SillyServer error: "+s);this._server=null;return}this._final_url=this.properties.url+"/"+this.properties.room}};
|
||||
r.prototype.send=function(c){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,data:c})};r.prototype.onAction=function(c,l){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,action:c,data:l})};r.prototype.onGetInputs=function(){return[["in",0]]};r.prototype.onGetOutputs=function(){return[["out",0]]};l.registerNodeType("network/sillyclient",r)})(this);
|
||||
s.prototype.send=function(c){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,data:c})};s.prototype.onAction=function(c,l){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,action:c,data:l})};s.prototype.onGetInputs=function(){return[["in",0]]};s.prototype.onGetOutputs=function(){return[["out",0]]};l.registerNodeType("network/sillyclient",s)})(this);
|
||||
|
||||
@@ -9169,7 +9169,21 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
var graphcanvas = LGraphCanvas.active_canvas;
|
||||
var canvas = graphcanvas.canvas;
|
||||
|
||||
var root_document = canvas.ownerDocument || document;
|
||||
if( root_document.fullscreenElement )
|
||||
root_document.fullscreenElement.appendChild(dialog);
|
||||
else
|
||||
root_document.body.appendChild(dialog);
|
||||
|
||||
//compute best position
|
||||
var rect = canvas.getBoundingClientRect();
|
||||
|
||||
var left = ( event ? event.clientX : (rect.left + rect.width * 0.5) ) - 80;
|
||||
var top = ( event ? event.clientY : (rect.top + rect.height * 0.5) ) - 20;
|
||||
dialog.style.left = left + "px";
|
||||
dialog.style.top = top + "px";
|
||||
|
||||
/*
|
||||
var offsetx = -20;
|
||||
var offsety = -20;
|
||||
if (rect) {
|
||||
@@ -9184,8 +9198,9 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
dialog.style.left = canvas.width * 0.5 + offsetx + "px";
|
||||
dialog.style.top = canvas.height * 0.5 + offsety + "px";
|
||||
}
|
||||
|
||||
canvas.parentNode.appendChild(dialog);
|
||||
*/
|
||||
|
||||
input.focus();
|
||||
|
||||
function select(name) {
|
||||
|
||||
Reference in New Issue
Block a user