diff --git a/build/litegraph.js b/build/litegraph.js index 77b98aff2..9b2aa6c39 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -14,10 +14,13 @@ var LiteGraph = global.LiteGraph = { + VERSION: 0.4, + CANVAS_GRID_SIZE: 10, - NODE_TITLE_HEIGHT: 20, - NODE_SLOT_HEIGHT: 15, + NODE_TITLE_HEIGHT: 30, + NODE_TITLE_TEXT_Y: 20, + NODE_SLOT_HEIGHT: 20, NODE_WIDGET_HEIGHT: 20, NODE_WIDTH: 140, NODE_MIN_WIDTH: 50, @@ -28,14 +31,14 @@ var LiteGraph = global.LiteGraph = { NODE_TEXT_COLOR: "#AAA", NODE_SUBTEXT_SIZE: 12, NODE_DEFAULT_COLOR: "#333", - NODE_DEFAULT_BGCOLOR: "#444", + NODE_DEFAULT_BGCOLOR: "#353535", NODE_DEFAULT_BOXCOLOR: "#666", NODE_DEFAULT_SHAPE: "box", DEFAULT_SHADOW_COLOR: "rgba(0,0,0,0.5)", DEFAULT_GROUP_FONT: 24, - LINK_COLOR: "#AAD", - EVENT_LINK_COLOR: "#F85", + LINK_COLOR: "#9A9", + EVENT_LINK_COLOR: "#A86", CONNECTING_LINK_COLOR: "#AFA", MAX_NUMBER_OF_NODES: 1000, //avoid infinite loops @@ -67,6 +70,10 @@ var LiteGraph = global.LiteGraph = { RIGHT:4, CENTER:5, + STRAIGHT_LINK: 0, + LINEAR_LINK: 1, + SPLINE_LINK: 2, + NORMAL_TITLE: 0, NO_TITLE: 1, TRANSPARENT_TITLE: 2, @@ -265,13 +272,11 @@ var LiteGraph = global.LiteGraph = { * @param {String} type full name of the node class. p.e. "math/sin" * @return {Class} the node class */ - getNodeType: function(type) { return this.registered_node_types[type]; }, - /** * Returns a list of node types matching one category * @method getNodeType @@ -971,15 +976,14 @@ LGraph.prototype.sendEventToAllNodes = function( eventname, params, mode ) for( var j = 0, l = nodes.length; j < l; ++j ) { var node = nodes[j]; - if(node[eventname] && node.mode == mode ) - { - if(params === undefined) - node[eventname](); - else if(params && params.constructor === Array) - node[eventname].apply( node, params ); - else - node[eventname](params); - } + if( !node[eventname] || node.mode != mode ) + continue; + if(params === undefined) + node[eventname](); + else if(params && params.constructor === Array) + node[eventname].apply( node, params ); + else + node[eventname](params); } } @@ -1617,7 +1621,8 @@ LGraph.prototype.serialize = function() nodes: nodes_info, links: links, groups: groups_info, - config: this.config + config: this.config, + version: LiteGraph.VERSION }; return data; @@ -1830,6 +1835,8 @@ LiteGraph.LLink = LLink; + onDropFile : file dropped over the node + onConnectInput : if returns false the incoming connection will be canceled + onConnectionsChange : a connection changed (new one or removed) (LiteGraph.INPUT or LiteGraph.OUTPUT, slot, true if connected, link_info, input_info ) + + onAction: action slot triggered + + getExtraMenuOptions: to add option to context menu */ /** @@ -2102,6 +2109,35 @@ LGraphNode.prototype.setOutputData = function(slot, data) } } +/** +* sets the output data type, useful when you want to be able to overwrite the data type +* @method setOutputDataType +* @param {number} slot +* @param {String} datatype +*/ +LGraphNode.prototype.setOutputDataType = function(slot, type) +{ + if(!this.outputs) + return; + if(slot == -1 || slot >= this.outputs.length) + return; + var output_info = this.outputs[slot]; + if(!output_info) + return; + //store data in the output itself in case we want to debug + output_info.type = type; + + //if there are connections, pass the data to the connections + if( this.outputs[slot].links ) + { + for(var i = 0; i < this.outputs[slot].links.length; i++) + { + var link_id = this.outputs[slot].links[i]; + this.graph.links[ link_id ].type = type; + } + } +} + /** * Retrieves the input data (data traveling through the connection) from one slot * @method getInputData @@ -2138,6 +2174,32 @@ LGraphNode.prototype.getInputData = function( slot, force_update ) return link.data; } +/** +* Retrieves the input data type (in case this supports multiple input types) +* @method getInputDataType +* @param {number} slot +* @return {String} datatype in string format +*/ +LGraphNode.prototype.getInputDataType = function( slot ) +{ + if(!this.inputs) + return null; //undefined; + + if(slot >= this.inputs.length || this.inputs[slot].link == null) + return null; + var link_id = this.inputs[slot].link; + var link = this.graph.links[ link_id ]; + if(!link) //bug: weird case but it happens sometimes + return null; + var node = this.graph.getNodeById( link.origin_id ); + if(!node) + return link.type; + var output_info = node.outputs[ link.origin_slot ]; + if(output_info) + return output_info.type; + return null; +} + /** * Retrieves the input data from one slot using its name instead of slot number * @method getInputDataByName @@ -2641,11 +2703,14 @@ LGraphNode.prototype.addConnection = function(name,type,pos,direction) */ LGraphNode.prototype.computeSize = function( minHeight, out ) { + if( this.constructor.size ) + return this.constructor.size.concat(); + var rows = Math.max( this.inputs ? this.inputs.length : 1, this.outputs ? this.outputs.length : 1); var size = out || new Float32Array([0,0]); rows = Math.max(rows, 1); var font_size = LiteGraph.NODE_TEXT_SIZE; //although it should be graphcanvas.inner_text_font size - size[1] = (this.constructor.slot_start_y || 0) + rows * (font_size + 1) + 4; + size[1] = (this.constructor.slot_start_y || 0) + rows * LiteGraph.NODE_SLOT_HEIGHT; if( this.widgets && this.widgets.length ) size[1] += this.widgets.length * (LiteGraph.NODE_WIDGET_HEIGHT + 4) + 8; @@ -2689,6 +2754,11 @@ LGraphNode.prototype.computeSize = function( minHeight, out ) return font_size * text.length * 0.6; } + if(this.constructor.min_height && size[1] < this.constructor.min_height) + size[1] = this.constructor.min_height; + + size[1] += 6; //margin + return size; } @@ -3162,6 +3232,8 @@ LGraphNode.prototype.getConnectionPos = function( is_input, slot_number, out ) if( !is_input && this.outputs ) num_slots = this.outputs.length; + var offset = LiteGraph.NODE_SLOT_HEIGHT * 0.5; + if(this.flags.collapsed) { var w = (this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH); @@ -3184,10 +3256,11 @@ LGraphNode.prototype.getConnectionPos = function( is_input, slot_number, out ) return out; } + //weird feature that never got finished if(is_input && slot_number == -1) { - out[0] = this.pos[0] + 10; - out[1] = this.pos[1] + 10; + out[0] = this.pos[0] + LiteGraph.NODE_TITLE_HEIGHT * 0.5; + out[1] = this.pos[1] + LiteGraph.NODE_TITLE_HEIGHT * 0.5; return out; } @@ -3216,12 +3289,12 @@ LGraphNode.prototype.getConnectionPos = function( is_input, slot_number, out ) return out; } - //default + //default vertical slots if(is_input) - out[0] = this.pos[0]; + out[0] = this.pos[0] + offset; else - out[0] = this.pos[0] + this.size[0] + 1; - out[1] = this.pos[1] + 10 + slot_number * LiteGraph.NODE_SLOT_HEIGHT + (this.constructor.slot_start_y || 0); + out[0] = this.pos[0] + this.size[0] + 1 - offset; + out[1] = this.pos[1] + (slot_number + 0.7 ) * LiteGraph.NODE_SLOT_HEIGHT + (this.constructor.slot_start_y || 0); return out; } @@ -3466,6 +3539,202 @@ LGraphGroup.prototype.recomputeInsideNodes = function() LGraphGroup.prototype.isPointInside = LGraphNode.prototype.isPointInside; LGraphGroup.prototype.setDirtyCanvas = LGraphNode.prototype.setDirtyCanvas; + + +//**************************************** + +//Scale and Offset +function DragAndScale( element, skip_events ) +{ + this.offset = new Float32Array([0,0]); + this.scale = 1; + this.max_scale = 10; + this.min_scale = 0.1; + this.onredraw = null; + this.enabled = true; + this.last_mouse = [0,0]; + this.element = null; + this.visible_area = new Float32Array(4); + + if(element) + { + this.element = element; + if(!skip_events) + this.bindEvents( element ); + } +} + +LiteGraph.DragAndScale = DragAndScale; + +DragAndScale.prototype.bindEvents = function( element ) +{ + this.last_mouse = new Float32Array(2); + + this._binded_mouse_callback = this.onMouse.bind(this); + + element.addEventListener("mousedown", this._binded_mouse_callback ); + element.addEventListener("mousemove", this._binded_mouse_callback ); + + element.addEventListener("mousewheel", this._binded_mouse_callback, false); + element.addEventListener("wheel", this._binded_mouse_callback, false); +} + +DragAndScale.prototype.computeVisibleArea = function() +{ + if(!this.element) + { + this.visible_area[0] = this.visible_area[1] = this.visible_area[2] = this.visible_area[3] = 0; + return; + } + var width = this.element.width; + var height = this.element.height; + var startx = -this.offset[0]; + var starty = -this.offset[1]; + var endx = startx + width / this.scale; + var endy = starty + height / this.scale; + this.visible_area[0] = startx; + this.visible_area[1] = starty; + this.visible_area[2] = endx - startx; + this.visible_area[3] = endy - starty; +} + +DragAndScale.prototype.onMouse = function(e) +{ + if(!this.enabled) + return; + + var canvas = this.element; + var rect = canvas.getBoundingClientRect(); + var x = e.clientX - rect.left; + var y = e.clientY - rect.top; + e.canvasx = x; + e.canvasy = y; + e.dragging = this.dragging; + + var ignore = false; + if(this.onmouse) + ignore = this.onmouse(e); + + if(e.type == "mousedown") + { + this.dragging = true; + canvas.removeEventListener("mousemove", this._binded_mouse_callback ); + document.body.addEventListener("mousemove", this._binded_mouse_callback ); + document.body.addEventListener("mouseup", this._binded_mouse_callback ); + } + else if(e.type == "mousemove") + { + if(!ignore) + { + var deltax = x - this.last_mouse[0]; + var deltay = y - this.last_mouse[1]; + if( this.dragging ) + this.mouseDrag( deltax, deltay ); + } + } + else if(e.type == "mouseup") + { + this.dragging = false; + document.body.removeEventListener("mousemove", this._binded_mouse_callback ); + document.body.removeEventListener("mouseup", this._binded_mouse_callback ); + canvas.addEventListener("mousemove", this._binded_mouse_callback ); + } + else if(e.type == "mousewheel" || e.type == "wheel" || e.type == "DOMMouseScroll") + { + e.eventType = "mousewheel"; + if(e.type == "wheel") + e.wheel = -e.deltaY; + else + e.wheel = (e.wheelDeltaY != null ? e.wheelDeltaY : e.detail * -60); + + //from stack overflow + e.delta = e.wheelDelta ? e.wheelDelta/40 : e.deltaY ? -e.deltaY/3 : 0; + this.changeDeltaScale(1.0 + e.delta * 0.05); + } + + this.last_mouse[0] = x; + this.last_mouse[1] = y; + + e.preventDefault(); + e.stopPropagation(); + return false; +} + +DragAndScale.prototype.toCanvasContext = function( ctx ) +{ + ctx.scale( this.scale, this.scale ); + ctx.translate( this.offset[0], this.offset[1] ); +} + +DragAndScale.prototype.convertOffsetToCanvas = function(pos) +{ + //return [pos[0] / this.scale - this.offset[0], pos[1] / this.scale - this.offset[1]]; + return [ (pos[0] + this.offset[0]) * this.scale, (pos[1] + this.offset[1]) * this.scale ]; +} + +DragAndScale.prototype.convertCanvasToOffset = function(pos, out) +{ + out = out || [0,0]; + out[0] = pos[0] / this.scale - this.offset[0]; + out[1] = pos[1] / this.scale - this.offset[1]; + return out; +} + +DragAndScale.prototype.mouseDrag = function(x,y) +{ + this.offset[0] += x / this.scale; + this.offset[1] += y / this.scale; + + if( this.onredraw ) + this.onredraw( this ); +} + +DragAndScale.prototype.changeScale = function( value, zooming_center ) +{ + if(value < this.min_scale) + value = this.min_scale; + else if(value > this.max_scale) + value = this.max_scale; + + if(value == this.scale) + return; + + if(!this.element) + return; + + var rect = this.element.getBoundingClientRect(); + if(!rect) + return; + + zooming_center = zooming_center || [rect.width * 0.5,rect.height * 0.5]; + var center = this.convertCanvasToOffset( zooming_center ); + this.scale = value; + if( Math.abs( this.scale - 1 ) < 0.01 ) + this.scale = 1; + + var new_center = this.convertCanvasToOffset( zooming_center ); + var delta_offset = [new_center[0] - center[0], new_center[1] - center[1]]; + + this.offset[0] += delta_offset[0]; + this.offset[1] += delta_offset[1]; + + if( this.onredraw ) + this.onredraw( this ); +} + +DragAndScale.prototype.changeDeltaScale = function( value, zooming_center ) +{ + this.changeScale( this.scale * value, zooming_center ); +} + +DragAndScale.prototype.reset = function() +{ + this.scale = 1; + this.offset[0] = 0; + this.offset[1] = 0; +} + + //********************************************************************************* // LGraphCanvas: LGraph renderer CLASS //********************************************************************************* @@ -3491,18 +3760,17 @@ function LGraphCanvas( canvas, graph, options ) if(canvas && canvas.constructor === String ) canvas = document.querySelector( canvas ); - this.max_zoom = 10; - this.min_zoom = 0.1; + this.ds = new DragAndScale(); this.zoom_modify_alpha = true; //otherwise it generates ugly patterns when scaling down too much - this.title_text_font = "bold "+LiteGraph.NODE_TEXT_SIZE+"px Arial"; + this.title_text_font = ""+LiteGraph.NODE_TEXT_SIZE+"px Arial"; this.inner_text_font = "normal "+LiteGraph.NODE_SUBTEXT_SIZE+"px Arial"; this.node_title_color = LiteGraph.NODE_TITLE_COLOR; this.default_link_color = LiteGraph.LINK_COLOR; this.default_connection_color = { - input_off: "#AAB", + input_off: "#778", input_on: "#7F7", - output_off: "#AAB", + output_off: "#778", output_on: "#7F7" }; @@ -3510,7 +3778,6 @@ function LGraphCanvas( canvas, graph, options ) this.use_gradients = false; //set to true to render titlebar with gradients this.editor_alpha = 1; //used for transition this.pause_rendering = false; - this.render_shadows = true; this.clear_background = true; this.render_only_selected = true; @@ -3521,18 +3788,24 @@ function LGraphCanvas( canvas, graph, options ) this.allow_interaction = true; //allow to control widgets, buttons, collapse, etc this.allow_searchbox = true; this.allow_reconnect_links = false; //allows to change a connection with having to redo it again + this.drag_mode = false; this.dragging_rectangle = null; this.filter = null; //allows to filter to only accept some type of nodes in a graph this.always_render_background = false; + this.render_shadows = true; this.render_canvas_border = true; this.render_connections_shadows = false; //too much cpu this.render_connections_border = true; - this.render_curved_connections = true; - this.render_connection_arrows = true; + this.render_curved_connections = false; + this.render_connection_arrows = false; + this.render_collapsed_slots = true; this.render_execution_order = false; + this.render_title_colored = true; + + this.links_render_mode = LiteGraph.SPLINE_LINK; this.canvas_mouse = [0,0]; //mouse in canvas graph coordinates, where 0,0 is the top-left corner of the blue rectangle @@ -3552,7 +3825,7 @@ function LGraphCanvas( canvas, graph, options ) this.current_node = null; this.node_widget = null; //used for widgets this.last_mouse_position = [0,0]; - this.visible_area = new Float32Array(4); + this.visible_area = this.ds.visible_area; this.visible_links = []; //link canvas and graph @@ -3570,7 +3843,7 @@ function LGraphCanvas( canvas, graph, options ) global.LGraphCanvas = LiteGraph.LGraphCanvas = LGraphCanvas; -LGraphCanvas.link_type_colors = {"-1":"#F85",'number':"#AAA","node":"#DCA"}; +LGraphCanvas.link_type_colors = {"-1": LiteGraph.EVENT_LINK_COLOR,'number':"#AAA","node":"#DCA"}; LGraphCanvas.gradients = {}; //cache of gradients /** @@ -3585,8 +3858,8 @@ LGraphCanvas.prototype.clear = function() this.render_time = 0; this.fps = 0; - this.scale = 1; - this.offset = [0,0]; + //this.scale = 1; + //this.offset = [0,0]; this.dragging_rectangle = null; @@ -3728,6 +4001,7 @@ LGraphCanvas.prototype.setCanvas = function( canvas, skip_events ) } this.canvas = canvas; + this.ds.element = canvas; if(!canvas) return; @@ -4107,11 +4381,13 @@ LGraphCanvas.prototype.processMouseDown = function(e) } //Search for corner for collapsing + /* if( !skip_action && isInsideRectangle( e.canvasX, e.canvasY, node.pos[0], node.pos[1] - LiteGraph.NODE_TITLE_HEIGHT, LiteGraph.NODE_TITLE_HEIGHT, LiteGraph.NODE_TITLE_HEIGHT )) { node.collapse(); skip_action = true; } + */ //it wasnt clicked on the links boxes if(!skip_action) @@ -4181,7 +4457,7 @@ LGraphCanvas.prototype.processMouseDown = function(e) this.dragging_rectangle = null; var dist = distance( [e.canvasX, e.canvasY], [ this.selected_group.pos[0] + this.selected_group.size[0], this.selected_group.pos[1] + this.selected_group.size[1] ] ); - if( (dist * this.scale) < 10 ) + if( (dist * this.ds.scale) < 10 ) this.selected_group_resizing = true; else this.selected_group.recomputeInsideNodes(); @@ -4273,8 +4549,8 @@ LGraphCanvas.prototype.processMouseMove = function(e) this.selected_group.size = [ e.canvasX - this.selected_group.pos[0], e.canvasY - this.selected_group.pos[1] ]; else { - var deltax = delta[0] / this.scale; - var deltay = delta[1] / this.scale; + var deltax = delta[0] / this.ds.scale; + var deltay = delta[1] / this.ds.scale; this.selected_group.move( deltax, deltay, e.ctrlKey ); if( this.selected_group._nodes.length) this.dirty_canvas = true; @@ -4283,8 +4559,8 @@ LGraphCanvas.prototype.processMouseMove = function(e) } else if(this.dragging_canvas) { - this.offset[0] += delta[0] / this.scale; - this.offset[1] += delta[1] / this.scale; + this.ds.offset[0] += delta[0] / this.ds.scale; + this.ds.offset[1] += delta[1] / this.ds.scale; this.dirty_canvas = true; this.dirty_bgcanvas = true; } @@ -4359,7 +4635,7 @@ LGraphCanvas.prototype.processMouseMove = function(e) if( isInsideRectangle(e.canvasX, e.canvasY, node.pos[0] + node.size[0] - 5, node.pos[1] + node.size[1] - 5 ,5,5 )) this.canvas.style.cursor = "se-resize"; else - this.canvas.style.cursor = ""; + this.canvas.style.cursor = "crosshair"; } } else if(this.canvas) @@ -4376,8 +4652,8 @@ LGraphCanvas.prototype.processMouseMove = function(e) for(var i in this.selected_nodes) { var n = this.selected_nodes[i]; - n.pos[0] += delta[0] / this.scale; - n.pos[1] += delta[1] / this.scale; + n.pos[0] += delta[0] / this.ds.scale; + n.pos[1] += delta[1] / this.ds.scale; } this.dirty_canvas = true; @@ -4526,6 +4802,10 @@ LGraphCanvas.prototype.processMouseUp = function(e) } else if(this.node_dragged) //node being dragged? { + var node = this.node_dragged; + if( node && e.click_time < 300 && isInsideRectangle( e.canvasX, e.canvasY, node.pos[0], node.pos[1] - LiteGraph.NODE_TITLE_HEIGHT, LiteGraph.NODE_TITLE_HEIGHT, LiteGraph.NODE_TITLE_HEIGHT )) + node.collapse(); + this.dirty_canvas = true; this.dirty_bgcanvas = true; this.node_dragged.pos[0] = Math.round(this.node_dragged.pos[0]); @@ -4538,6 +4818,7 @@ LGraphCanvas.prototype.processMouseUp = function(e) { //get node over var node = this.graph.getNodeOnPos( e.canvasX, e.canvasY, this.visible_nodes ); + if ( !node && e.click_time < 300 ) this.deselectAllNodes(); @@ -4588,19 +4869,15 @@ LGraphCanvas.prototype.processMouseWheel = function(e) this.adjustMouseEvent(e); - var zoom = this.scale; + var scale = this.ds.scale; if (delta > 0) - zoom *= 1.1; + scale *= 1.1; else if (delta < 0) - zoom *= 1/(1.1); + scale *= 1/(1.1); - this.setZoom( zoom, [ e.localX, e.localY ] ); - - /* - if(this.rendering_timer_id == null) - this.draw(); - */ + //this.setZoom( scale, [ e.localX, e.localY ] ); + this.ds.changeScale( scale, [ e.localX, e.localY ] ); this.graph.change(); @@ -4615,7 +4892,7 @@ LGraphCanvas.prototype.processMouseWheel = function(e) LGraphCanvas.prototype.isOverNodeBox = function( node, canvasx, canvasy ) { var title_height = LiteGraph.NODE_TITLE_HEIGHT; - if( isInsideRectangle( canvasx, canvasy, node.pos[0] + 2, node.pos[1] + 2 - title_height, title_height - 4,title_height - 4) ) + if( isInsideRectangle( canvasx, canvasy, node.pos[0] + 2, node.pos[1] + 2 - title_height, title_height - 4, title_height - 4) ) return true; return false; } @@ -4728,6 +5005,7 @@ LGraphCanvas.prototype.processKey = function(e) if(block_default) { e.preventDefault(); + e.stopImmediatePropagation(); return false; } } @@ -5045,8 +5323,8 @@ LGraphCanvas.prototype.deleteSelectedNodes = function() **/ LGraphCanvas.prototype.centerOnNode = function(node) { - this.offset[0] = -node.pos[0] - node.size[0] * 0.5 + (this.canvas.width * 0.5 / this.scale); - this.offset[1] = -node.pos[1] - node.size[1] * 0.5 + (this.canvas.height * 0.5 / this.scale); + this.ds.offset[0] = -node.pos[0] - node.size[0] * 0.5 + (this.canvas.width * 0.5 / this.ds.scale); + this.ds.offset[1] = -node.pos[1] - node.size[1] * 0.5 + (this.canvas.height * 0.5 / this.ds.scale); this.setDirty(true,true); } @@ -5059,13 +5337,13 @@ LGraphCanvas.prototype.adjustMouseEvent = function(e) if(this.canvas) { var b = this.canvas.getBoundingClientRect(); - e.localX = e.pageX - b.left; - e.localY = e.pageY - b.top; + e.localX = e.clientX - b.left; + e.localY = e.clientY - b.top; } else { - e.localX = e.pageX; - e.localY = e.pageY; + e.localX = e.clientX; + e.localY = e.clientY; } e.deltaX = e.localX - this.last_mouse_position[0]; @@ -5074,8 +5352,8 @@ LGraphCanvas.prototype.adjustMouseEvent = function(e) this.last_mouse_position[0] = e.localX; this.last_mouse_position[1] = e.localY; - e.canvasX = e.localX / this.scale - this.offset[0]; - e.canvasY = e.localY / this.scale - this.offset[1]; + e.canvasX = e.localX / this.ds.scale - this.ds.offset[0]; + e.canvasY = e.localY / this.ds.scale - this.ds.offset[1]; } /** @@ -5084,12 +5362,14 @@ LGraphCanvas.prototype.adjustMouseEvent = function(e) **/ LGraphCanvas.prototype.setZoom = function(value, zooming_center) { + this.ds.changeScale( value, zooming_center); + /* if(!zooming_center && this.canvas) zooming_center = [this.canvas.width * 0.5,this.canvas.height * 0.5]; var center = this.convertOffsetToCanvas( zooming_center ); - this.scale = value; + this.ds.scale = value; if(this.scale > this.max_zoom) this.scale = this.max_zoom; @@ -5101,39 +5381,35 @@ LGraphCanvas.prototype.setZoom = function(value, zooming_center) this.offset[0] += delta_offset[0]; this.offset[1] += delta_offset[1]; + */ this.dirty_canvas = true; this.dirty_bgcanvas = true; } /** -* converts a coordinate in canvas2D space to graphcanvas space (NAME IS CONFUSION, SHOULD BE THE OTHER WAY AROUND) +* converts a coordinate from graph coordinates to canvas2D coordinates * @method convertOffsetToCanvas **/ LGraphCanvas.prototype.convertOffsetToCanvas = function( pos, out ) { - out = out || []; - out[0] = pos[0] / this.scale - this.offset[0]; - out[1] = pos[1] / this.scale - this.offset[1]; - return out; + return this.ds.convertOffsetToCanvas( pos, out ); } /** -* converts a coordinate in graphcanvas space to canvas2D space (NAME IS CONFUSION, SHOULD BE THE OTHER WAY AROUND) +* converts a coordinate from Canvas2D coordinates to graph space * @method convertCanvasToOffset **/ LGraphCanvas.prototype.convertCanvasToOffset = function( pos, out ) { - out = out || []; - out[0] = (pos[0] + this.offset[0]) * this.scale; - out[1] = (pos[1] + this.offset[1]) * this.scale; - return out; + return this.ds.convertCanvasToOffset( pos, out ); } -LGraphCanvas.prototype.convertEventToCanvas = function(e) +//converts event coordinates from canvas2D to graph coordinates +LGraphCanvas.prototype.convertEventToCanvasOffset = function(e) { var rect = this.canvas.getBoundingClientRect(); - return this.convertOffsetToCanvas([e.pageX - rect.left,e.pageY - rect.top]); + return this.convertCanvasToOffset([e.clientX - rect.left,e.clientY - rect.top]); } /** @@ -5209,16 +5485,7 @@ LGraphCanvas.prototype.draw = function(force_canvas, force_bgcanvas) this.last_draw_time = now; if(this.graph) - { - var startx = -this.offset[0]; - var starty = -this.offset[1]; - var endx = startx + this.canvas.width / this.scale; - var endy = starty + this.canvas.height / this.scale; - this.visible_area[0] = startx; - this.visible_area[1] = starty; - this.visible_area[2] = endx - startx; - this.visible_area[3] = endy - starty; - } + this.ds.computeVisibleArea(); if(this.dirty_bgcanvas || force_bgcanvas || this.always_render_background || (this.graph && this.graph._last_trigger_time && (now - this.graph._last_trigger_time) < 1000) ) this.drawBackCanvas(); @@ -5285,8 +5552,7 @@ LGraphCanvas.prototype.drawFrontCanvas = function() { //apply transformations ctx.save(); - ctx.scale(this.scale,this.scale); - ctx.translate( this.offset[0],this.offset[1] ); + this.ds.toCanvasContext( ctx ); //draw nodes var drawn_nodes = 0; @@ -5458,14 +5724,13 @@ LGraphCanvas.prototype.drawBackCanvas = function() { //apply transformations ctx.save(); - ctx.scale(this.scale,this.scale); - ctx.translate(this.offset[0],this.offset[1]); + this.ds.toCanvasContext(ctx); //render BG - if(this.background_image && this.scale > 0.5 && !bg_already_painted) + if(this.background_image && this.ds.scale > 0.5 && !bg_already_painted) { if (this.zoom_modify_alpha) - ctx.globalAlpha = (1.0 - 0.5 / this.scale) * this.editor_alpha; + ctx.globalAlpha = (1.0 - 0.5 / this.ds.scale) * this.editor_alpha; else ctx.globalAlpha = this.editor_alpha; ctx.imageSmoothingEnabled = ctx.mozImageSmoothingEnabled = ctx.imageSmoothingEnabled = false; @@ -5576,7 +5841,6 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) if(node.onDrawForeground) node.onDrawForeground(ctx, this, this.canvas ); } - return; } @@ -5586,9 +5850,9 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) if(this.render_shadows) { ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR; - ctx.shadowOffsetX = 2 * this.scale; - ctx.shadowOffsetY = 2 * this.scale; - ctx.shadowBlur = 3 * this.scale; + ctx.shadowOffsetX = 2 * this.ds.scale; + ctx.shadowOffsetY = 2 * this.ds.scale; + ctx.shadowBlur = 3 * this.ds.scale; } else ctx.shadowColor = "transparent"; @@ -5607,9 +5871,12 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) { ctx.font = this.inner_text_font; var title = node.getTitle ? node.getTitle() : node.title; - node._collapsed_width = Math.min( node.size[0], ctx.measureText(title).width + 40 );//LiteGraph.NODE_COLLAPSED_WIDTH; - size[0] = node._collapsed_width; - size[1] = 0; + if(title != null) + { + node._collapsed_width = Math.min( node.size[0], ctx.measureText(title).width + LiteGraph.NODE_TITLE_HEIGHT * 2 );//LiteGraph.NODE_COLLAPSED_WIDTH; + size[0] = node._collapsed_width; + size[1] = 0; + } } if( node.clip_area ) //Start clipping @@ -5631,11 +5898,15 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) this.drawNodeShape( node, ctx, size, color, bgcolor, node.is_selected, node.mouseOver ); ctx.shadowColor = "transparent"; + //draw foreground + if(node.onDrawForeground) + node.onDrawForeground( ctx, this, this.canvas ); + //connection slots ctx.textAlign = horizontal ? "center" : "left"; ctx.font = this.inner_text_font; - var render_text = this.scale > 0.6; + var render_text = this.ds.scale > 0.6; var out_slot = this.connecting_output; ctx.lineWidth = 1; @@ -5767,12 +6038,8 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) max_y = 2; this.drawNodeWidgets( node, max_y, ctx, (this.node_widget && this.node_widget[0] == node) ? this.node_widget[1] : null ); } - - //draw foreground - if(node.onDrawForeground) - node.onDrawForeground( ctx, this, this.canvas ); } - else //if collapsed + else if(this.render_collapsed_slots)//if collapsed { var input_slot = null; var output_slot = null; @@ -5809,10 +6076,10 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) x = node._collapsed_width * 0.5; y = -LiteGraph.NODE_TITLE_HEIGHT; } - ctx.fillStyle = slot.color_on || this.default_connection_color.input_on; + ctx.fillStyle = "#686"; ctx.beginPath(); if ( slot.type === LiteGraph.EVENT || slot.shape === LiteGraph.BOX_SHAPE) { - ctx.rect(x - 7 + 0.5, y + 4 - LiteGraph.NODE_TITLE_HEIGHT * 0.5 + 0.5,14,LiteGraph.NODE_TITLE_HEIGHT - 8); + ctx.rect(x - 7 + 0.5, y-4,14,8); } else if (slot.shape === LiteGraph.ARROW_SHAPE) { ctx.moveTo(x + 8, y); ctx.lineTo(x + -4, y - 4); @@ -5833,11 +6100,11 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) x = node._collapsed_width * 0.5; y = 0; } - ctx.fillStyle = slot.color_on || this.default_connection_color.output_on; + ctx.fillStyle = "#686"; ctx.strokeStyle = "black"; ctx.beginPath(); if (slot.type === LiteGraph.EVENT || slot.shape === LiteGraph.BOX_SHAPE) { - ctx.rect( x - 7 + 0.5, y + 4 - LiteGraph.NODE_TITLE_HEIGHT * 0.5 + 0.5,14,LiteGraph.NODE_TITLE_HEIGHT - 8); + ctx.rect( x - 7 + 0.5, y - 4,14,8); } else if (slot.shape === LiteGraph.ARROW_SHAPE) { ctx.moveTo(x + 6, y); ctx.lineTo(x - 6, y - 4); @@ -5847,7 +6114,7 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) ctx.arc(x, y, 4, 0, Math.PI * 2); } ctx.fill(); - ctx.stroke(); + //ctx.stroke(); } } @@ -5870,9 +6137,11 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol ctx.fillStyle = bgcolor; var title_height = LiteGraph.NODE_TITLE_HEIGHT; + var low_quality = this.ds.scale < 0.5; //render node area depending on shape - var shape = node._shape || node.constructor.shape || LiteGraph.BOX_SHAPE; + var shape = node._shape || node.constructor.shape || LiteGraph.ROUND_SHAPE; + var title_mode = node.constructor.title_mode; var render_title = true; @@ -5887,62 +6156,62 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol area[2] = size[0]+1; //w area[3] = render_title ? size[1] + title_height : size[1]; //h + var old_alpha = ctx.globalAlpha; + //full node shape - if(!node.flags.collapsed) + //if(node.flags.collapsed) { ctx.beginPath(); - if(shape == LiteGraph.BOX_SHAPE || this.scale < 0.5) + if(shape == LiteGraph.BOX_SHAPE || low_quality ) ctx.fillRect( area[0], area[1], area[2], area[3] ); else if (shape == LiteGraph.ROUND_SHAPE || shape == LiteGraph.CARD_SHAPE) ctx.roundRect( area[0], area[1], area[2], area[3], this.round_radius, shape == LiteGraph.CARD_SHAPE ? 0 : this.round_radius); else if (shape == LiteGraph.CIRCLE_SHAPE) ctx.arc(size[0] * 0.5, size[1] * 0.5, size[0] * 0.5, 0, Math.PI*2); ctx.fill(); + + ctx.shadowColor = "transparent"; + ctx.fillStyle = "rgba(0,0,0,0.2)"; + ctx.fillRect(0,-1, area[2],2); } ctx.shadowColor = "transparent"; - //image - if (node.bgImage && node.bgImage.width) - ctx.drawImage( node.bgImage, (size[0] - node.bgImage.width) * 0.5 , (size[1] - node.bgImage.height) * 0.5); - - if(node.bgImageUrl && !node.bgImage) - node.bgImage = node.loadImage(node.bgImageUrl); - if( node.onDrawBackground ) node.onDrawBackground( ctx, this, this.canvas ); //title bg (remember, it is rendered ABOVE the node) - if(render_title || title_mode == LiteGraph.TRANSPARENT_TITLE ) + if( render_title || title_mode == LiteGraph.TRANSPARENT_TITLE ) { //title bar if(node.onDrawTitleBar) { - node.onDrawTitleBar(ctx, title_height, size, this.scale, fgcolor); + node.onDrawTitleBar(ctx, title_height, size, this.ds.scale, fgcolor); } - else if(title_mode != LiteGraph.TRANSPARENT_TITLE) //!node.flags.collapsed) + else if(title_mode != LiteGraph.TRANSPARENT_TITLE && (node.constructor.title_color || this.render_title_colored )) { + var title_color = node.constructor.title_color || fgcolor; + if(node.flags.collapsed) ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR; //* gradient test if(this.use_gradients) { - var grad = LGraphCanvas.gradients[ fgcolor ]; + var grad = LGraphCanvas.gradients[ title_color ]; if(!grad) { - grad = LGraphCanvas.gradients[ fgcolor ] = ctx.createLinearGradient(0,0,400,0); - grad.addColorStop(0, fgcolor); + grad = LGraphCanvas.gradients[ title_color ] = ctx.createLinearGradient(0,0,400,0); + grad.addColorStop(0, title_color); grad.addColorStop(1, "#000"); } ctx.fillStyle = grad; } else - ctx.fillStyle = fgcolor; + ctx.fillStyle = title_color; - var old_alpha = ctx.globalAlpha; //ctx.globalAlpha = 0.5 * old_alpha; ctx.beginPath(); - if(shape == LiteGraph.BOX_SHAPE || this.scale < 0.5) + if( shape == LiteGraph.BOX_SHAPE || low_quality ) ctx.rect(0, -title_height, size[0]+1, title_height); else if ( shape == LiteGraph.ROUND_SHAPE || shape == LiteGraph.CARD_SHAPE ) ctx.roundRect(0,-title_height,size[0]+1, title_height, this.round_radius, node.flags.collapsed ? this.round_radius : 0); @@ -5951,43 +6220,44 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol } //title box + var box_size = 10; if(node.onDrawTitleBox) { - node.onDrawTitleBox( ctx, title_height, size, this.scale ); + node.onDrawTitleBox( ctx, title_height, size, this.ds.scale ); } else if ( shape == LiteGraph.ROUND_SHAPE || shape == LiteGraph.CIRCLE_SHAPE || shape == LiteGraph.CARD_SHAPE ) { - if( this.scale > 0.5 ) + if( low_quality ) { ctx.fillStyle = "black"; ctx.beginPath(); - ctx.arc(title_height *0.5, title_height * -0.5, (title_height - 8) *0.5,0,Math.PI*2); + ctx.arc(title_height * 0.5, title_height * -0.5, box_size*0.5+1,0,Math.PI*2); ctx.fill(); } ctx.fillStyle = node.boxcolor || LiteGraph.NODE_DEFAULT_BOXCOLOR; ctx.beginPath(); - ctx.arc(title_height *0.5, title_height * -0.5, (title_height - 8) *0.4,0,Math.PI*2); + ctx.arc(title_height * 0.5, title_height * -0.5, box_size*0.5,0,Math.PI*2); ctx.fill(); } else { - if( this.scale > 0.5 ) + if( low_quality ) { ctx.fillStyle = "black"; - ctx.fillRect(4,-title_height + 4,title_height - 8,title_height - 8); + ctx.fillRect( (title_height - box_size) * 0.5 - 1, (title_height + box_size ) * -0.5 - 1, box_size + 2, box_size + 2); } ctx.fillStyle = node.boxcolor || LiteGraph.NODE_DEFAULT_BOXCOLOR; - ctx.fillRect(5,-title_height + 5,title_height - 10,title_height - 10); + ctx.fillRect( (title_height - box_size) * 0.5, (title_height + box_size ) * -0.5, box_size, box_size ); } ctx.globalAlpha = old_alpha; //title text if(node.onDrawTitleText) { - node.onDrawTitleText(ctx, title_height, size, this.scale, this.title_text_font, selected); + node.onDrawTitleText( ctx, title_height, size, this.ds.scale, this.title_text_font, selected); } - if( this.scale > 0.5 ) + if( !low_quality ) { ctx.font = this.title_text_font; var title = node.getTitle(); @@ -6001,13 +6271,13 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol { ctx.textAlign = "center"; var measure = ctx.measureText(title); - ctx.fillText( title, title_height + measure.width * 0.5, -title_height * 0.2 ); + ctx.fillText( title, title_height + measure.width * 0.5, LiteGraph.NODE_TITLE_TEXT_Y - title_height ); ctx.textAlign = "left"; } else { ctx.textAlign = "left"; - ctx.fillText( title, title_height, -title_height * 0.2 ); + ctx.fillText( title, title_height, LiteGraph.NODE_TITLE_TEXT_Y - title_height ); } } } @@ -6030,7 +6300,7 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol ctx.lineWidth = 1; ctx.globalAlpha = 0.8; ctx.beginPath(); - if(shape == LiteGraph.BOX_SHAPE) + if( shape == LiteGraph.BOX_SHAPE ) ctx.rect(-6 + area[0],-6 + area[1], 12 + area[2], 12 + area[3] ); else if (shape == LiteGraph.ROUND_SHAPE || (shape == LiteGraph.CARD_SHAPE && node.flags.collapsed) ) ctx.roundRect(-6 + area[0],-6 + area[1], 12 + area[2], 12 + area[3] , this.round_radius * 2); @@ -6045,6 +6315,11 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol } } +var margin_area = new Float32Array(4); +var link_bounding = new Float32Array(4); +var tempA = new Float32Array(2); +var tempB = new Float32Array(2); + /** * draws every connection visible in the canvas * OPTIMIZE THIS: precatch connections position instead of recomputing them every time @@ -6054,10 +6329,7 @@ LGraphCanvas.prototype.drawConnections = function(ctx) { var now = LiteGraph.getTime(); var visible_area = this.visible_area; - var margin_area = new Float32Array([visible_area[0] - 20, visible_area[1] - 20, visible_area[2] + 40, visible_area[3] + 40 ]); - var link_bounding = new Float32Array(4); - var tempA = new Float32Array(2); - var tempB = new Float32Array(2); + margin_area[0] = visible_area[0] - 20; margin_area[1] = visible_area[1] - 20; margin_area[2] = visible_area[2] + 40; margin_area[3] = visible_area[3] + 40; //draw connections ctx.lineWidth = this.connections_width; @@ -6146,82 +6418,117 @@ LGraphCanvas.prototype.drawConnections = function(ctx) * @param {string} color the color for the link * @param {number} start_dir the direction enum * @param {number} end_dir the direction enum +* @param {number} num_sublines number of sublines (useful to represent vec3 or rgb) **/ -LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow, color, start_dir, end_dir ) +LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow, color, start_dir, end_dir, num_sublines ) { if(link) this.visible_links.push( link ); - if(!this.highquality_render) - { - ctx.beginPath(); - ctx.moveTo(a[0],a[1]); - ctx.lineTo(b[0],b[1]); - ctx.stroke(); - - if(link && link._pos) - { - link._pos[0] = (a[0] + b[0]) * 0.5; - link._pos[1] = (a[1] + b[1]) * 0.5; - } - return; - } - - start_dir = start_dir || LiteGraph.RIGHT; - end_dir = end_dir || LiteGraph.LEFT; - - var dist = distance(a,b); - - if(this.render_connections_border && this.scale > 0.6) - ctx.lineWidth = this.connections_width + 4; - //choose color if( !color && link ) color = link.color || LGraphCanvas.link_type_colors[ link.type ]; if( !color ) color = this.default_link_color; - if( link != null && this.highlighted_links[ link.id ] ) color = "#FFF"; + start_dir = start_dir || LiteGraph.RIGHT; + end_dir = end_dir || LiteGraph.LEFT; + + var dist = distance(a,b); + + if(this.render_connections_border && this.ds.scale > 0.6) + ctx.lineWidth = this.connections_width + 4; + ctx.lineJoin = "round"; + num_sublines = num_sublines || 1; + if(num_sublines > 1) + ctx.lineWidth = 0.5; + //begin line shape ctx.beginPath(); + for(var i = 0; i < num_sublines; i += 1) + { + var offsety = (i - (num_sublines-1)*0.5)*5; - if(this.render_curved_connections) //splines - { - ctx.moveTo(a[0],a[1]); - var start_offset_x = 0; - var start_offset_y = 0; - var end_offset_x = 0; - var end_offset_y = 0; - switch(start_dir) + if(this.links_render_mode == LiteGraph.SPLINE_LINK) { - case LiteGraph.LEFT: start_offset_x = dist*-0.25; break; - case LiteGraph.RIGHT: start_offset_x = dist*0.25; break; - case LiteGraph.UP: start_offset_y = dist*-0.25; break; - case LiteGraph.DOWN: start_offset_y = dist*0.25; break; + ctx.moveTo(a[0],a[1] + offsety); + var start_offset_x = 0; + var start_offset_y = 0; + var end_offset_x = 0; + var end_offset_y = 0; + switch(start_dir) + { + case LiteGraph.LEFT: start_offset_x = dist*-0.25; break; + case LiteGraph.RIGHT: start_offset_x = dist*0.25; break; + case LiteGraph.UP: start_offset_y = dist*-0.25; break; + case LiteGraph.DOWN: start_offset_y = dist*0.25; break; + } + switch(end_dir) + { + case LiteGraph.LEFT: end_offset_x = dist*-0.25; break; + case LiteGraph.RIGHT: end_offset_x = dist*0.25; break; + case LiteGraph.UP: end_offset_y = dist*-0.25; break; + case LiteGraph.DOWN: end_offset_y = dist*0.25; break; + } + ctx.bezierCurveTo(a[0] + start_offset_x, a[1] + start_offset_y + offsety, + b[0] + end_offset_x , b[1] + end_offset_y + offsety, + b[0], b[1] + offsety); } - switch(end_dir) + else if(this.links_render_mode == LiteGraph.LINEAR_LINK) { - case LiteGraph.LEFT: end_offset_x = dist*-0.25; break; - case LiteGraph.RIGHT: end_offset_x = dist*0.25; break; - case LiteGraph.UP: end_offset_y = dist*-0.25; break; - case LiteGraph.DOWN: end_offset_y = dist*0.25; break; + ctx.moveTo(a[0],a[1] + offsety); + var start_offset_x = 0; + var start_offset_y = 0; + var end_offset_x = 0; + var end_offset_y = 0; + switch(start_dir) + { + case LiteGraph.LEFT: start_offset_x = -1; break; + case LiteGraph.RIGHT: start_offset_x = 1; break; + case LiteGraph.UP: start_offset_y = -1; break; + case LiteGraph.DOWN: start_offset_y = 1; break; + } + switch(end_dir) + { + case LiteGraph.LEFT: end_offset_x = -1; break; + case LiteGraph.RIGHT: end_offset_x = 1; break; + case LiteGraph.UP: end_offset_y = -1; break; + case LiteGraph.DOWN: end_offset_y = 1; break; + } + var l = 15; + ctx.lineTo(a[0] + start_offset_x * l, a[1] + start_offset_y * l + offsety); + ctx.lineTo(b[0] + end_offset_x * l, b[1] + end_offset_y * l + offsety); + ctx.lineTo(b[0],b[1] + offsety); } - ctx.bezierCurveTo(a[0] + start_offset_x, a[1] + start_offset_y, - b[0] + end_offset_x , b[1] + end_offset_y, - b[0], b[1] ); - } - else //lines - { - ctx.moveTo(a[0]+10,a[1]); - ctx.lineTo(((a[0]+10) + (b[0]-10))*0.5,a[1]); - ctx.lineTo(((a[0]+10) + (b[0]-10))*0.5,b[1]); - ctx.lineTo(b[0]-10,b[1]); + else if(this.links_render_mode == LiteGraph.STRAIGHT_LINK) + { + ctx.moveTo(a[0], a[1]); + var start_x = a[0]; + var start_y = a[1]; + var end_x = b[0]; + var end_y = b[1]; + if( start_dir == LiteGraph.RIGHT ) + start_x += 10; + else + start_y += 10; + if( end_dir == LiteGraph.LEFT ) + end_x -= 10; + else + end_y -= 10; + ctx.lineTo(start_x, start_y); + ctx.lineTo((start_x + end_x)*0.5,start_y); + ctx.lineTo((start_x + end_x)*0.5,end_y); + ctx.lineTo(end_x, end_y); + ctx.lineTo(b[0],b[1]); + } + else + return; //unknown } //rendering the outline of the connection can be a little bit slow - if(this.render_connections_border && this.scale > 0.6 && !skip_border) + if(this.render_connections_border && this.ds.scale > 0.6 && !skip_border) { ctx.strokeStyle = "rgba(0,0,0,0.5)"; ctx.stroke(); @@ -6240,10 +6547,10 @@ LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow } //render arrow in the middle - if( this.render_connection_arrows && this.scale >= 0.6 ) + if( this.ds.scale >= 0.6 && this.highquality_render && end_dir != LiteGraph.CENTER ) { //render arrow - if(this.render_connection_arrows && this.scale > 0.6) + if( this.render_connection_arrows ) { //compute two points in the connection var posA = this.computeConnectionPoint( a, b, 0.25, start_dir, end_dir ); @@ -6281,12 +6588,12 @@ LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow ctx.lineTo(+5,-3); ctx.fill(); ctx.restore(); - - //circle - ctx.beginPath(); - ctx.arc(pos[0],pos[1],5,0,Math.PI*2); - ctx.fill(); } + + //circle + ctx.beginPath(); + ctx.arc(pos[0],pos[1],5,0,Math.PI*2); + ctx.fill(); } //render flowing points @@ -6304,6 +6611,7 @@ LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow } } +//returns the link center point based on curvature LGraphCanvas.prototype.computeConnectionPoint = function(a,b,t,start_dir,end_dir) { start_dir = start_dir || LiteGraph.RIGHT; @@ -6376,9 +6684,12 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge var widgets = node.widgets; posY += 2; var H = LiteGraph.NODE_WIDGET_HEIGHT; - var show_text = this.scale > 0.5; + var show_text = this.ds.scale > 0.5; ctx.save(); ctx.globalAlpha = this.editor_alpha; + var outline_color = "#666"; + var background_color = "#222"; + var margin = 15; for(var i = 0; i < widgets.length; ++i) { @@ -6387,7 +6698,7 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge if(w.y) y = w.y; w.last_y = y; - ctx.strokeStyle = "#AAA"; + ctx.strokeStyle = outline_color; ctx.fillStyle = "#222"; ctx.textAlign = "left"; @@ -6400,8 +6711,8 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge w.clicked = false; this.dirty_canvas = true; } - ctx.fillRect(10,y,width-20,H); - ctx.strokeRect(10,y,width-20,H); + ctx.fillRect(margin,y,width-margin*2,H); + ctx.strokeRect(margin,y,width-margin*2,H); if(show_text) { ctx.textAlign = "center"; @@ -6411,39 +6722,39 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge break; case "toggle": ctx.textAlign = "left"; - ctx.strokeStyle = "#AAA"; - ctx.fillStyle = "#111"; + ctx.strokeStyle = outline_color; + ctx.fillStyle = background_color; ctx.beginPath(); - ctx.roundRect( 10, posY, width - 20, H,H*0.5 ); + ctx.roundRect( margin, posY, width - margin*2, H,H*0.5 ); ctx.fill(); ctx.stroke(); ctx.fillStyle = w.value ? "#89A" : "#333"; ctx.beginPath(); - ctx.arc( width - 20, y + H*0.5, H * 0.36, 0, Math.PI * 2 ); + ctx.arc( width - margin*2, y + H*0.5, H * 0.36, 0, Math.PI * 2 ); ctx.fill(); if(show_text) { ctx.fillStyle = "#999"; if(w.name != null) - ctx.fillText( w.name, 20, y + H*0.7 ); + ctx.fillText( w.name, margin*2, y + H*0.7 ); ctx.fillStyle = w.value ? "#DDD" : "#888"; ctx.textAlign = "right"; - ctx.fillText( w.value ? (w.options.on || "true") : (w.options.off || "false"), width - 30, y + H*0.7 ); + ctx.fillText( w.value ? (w.options.on || "true") : (w.options.off || "false"), width - 40, y + H*0.7 ); } break; case "slider": - ctx.fillStyle = "#111"; - ctx.fillRect(10,y,width-20,H); + ctx.fillStyle = background_color; + ctx.fillRect(margin,y,width-margin*2,H); var range = w.options.max - w.options.min; var nvalue = (w.value - w.options.min) / range; ctx.fillStyle = active_widget == w ? "#89A" : "#678"; - ctx.fillRect(10,y,nvalue*(width-20),H); - ctx.strokeRect(10,y,width-20,H); + ctx.fillRect(margin,y,nvalue*(width-margin*2),H); + ctx.strokeRect(margin,y,width-margin*2,H); if( w.marker ) { var marker_nvalue = (w.marker - w.options.min) / range; ctx.fillStyle = "#AA9"; - ctx.fillRect(10 + marker_nvalue*(width-20),y,2,H); + ctx.fillRect(margin + marker_nvalue*(width-margin*2),y,2,H); } if(show_text) { @@ -6455,50 +6766,50 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge case "number": case "combo": ctx.textAlign = "left"; - ctx.strokeStyle = "#AAA"; - ctx.fillStyle = "#111"; + ctx.strokeStyle = outline_color; + ctx.fillStyle = background_color; ctx.beginPath(); - ctx.roundRect( 10, posY, width - 20, H,H*0.5 ); + ctx.roundRect( margin, posY, width - margin*2, H,H*0.5 ); ctx.fill(); ctx.stroke(); if(show_text) { ctx.fillStyle = "#AAA"; ctx.beginPath(); - ctx.moveTo( 26, posY + 5 ); - ctx.lineTo( 16, posY + H*0.5 ); - ctx.lineTo( 26, posY + H - 5 ); - ctx.moveTo( width - 26, posY + 5 ); - ctx.lineTo( width - 16, posY + H*0.5 ); - ctx.lineTo( width - 26, posY + H - 5 ); + ctx.moveTo( margin + 16, posY + 5 ); + ctx.lineTo( margin + 6, posY + H*0.5 ); + ctx.lineTo( margin + 16, posY + H - 5 ); + ctx.moveTo( width - margin - 16, posY + 5 ); + ctx.lineTo( width - margin - 6, posY + H*0.5 ); + ctx.lineTo( width - margin - 16, posY + H - 5 ); ctx.fill(); ctx.fillStyle = "#999"; - ctx.fillText( w.name, 30, y + H*0.7 ); + ctx.fillText( w.name, margin*2 + 5, y + H*0.7 ); ctx.fillStyle = "#DDD"; ctx.textAlign = "right"; if(w.type == "number") - ctx.fillText( Number(w.value).toFixed( w.options.precision !== undefined ? w.options.precision : 3), width - 40, y + H*0.7 ); + ctx.fillText( Number(w.value).toFixed( w.options.precision !== undefined ? w.options.precision : 3), width - margin*2 - 20, y + H*0.7 ); else - ctx.fillText( w.value, width - 40, y + H*0.7 ); + ctx.fillText( w.value, width - margin*2 - 20, y + H*0.7 ); } break; case "string": case "text": ctx.textAlign = "left"; - ctx.strokeStyle = "#AAA"; - ctx.fillStyle = "#111"; + ctx.strokeStyle = outline_color; + ctx.fillStyle = background_color; ctx.beginPath(); - ctx.roundRect( 10, posY, width - 20, H,H*0.5 ); + ctx.roundRect( margin, posY, width - margin*2, H,H*0.5 ); ctx.fill(); ctx.stroke(); if(show_text) { ctx.fillStyle = "#999"; if(w.name != null) - ctx.fillText( w.name, 20, y + H*0.7 ); + ctx.fillText( w.name, margin*2, y + H*0.7 ); ctx.fillStyle = "#DDD"; ctx.textAlign = "right"; - ctx.fillText( w.value, width - 20, y + H*0.7 ); + ctx.fillText( w.value, width - margin*2, y + H*0.7 ); } break; default: @@ -6584,7 +6895,7 @@ LGraphCanvas.prototype.processNodeWidgets = function( node, pos, event, active_w } else { - var menu = new LiteGraph.ContextMenu( values, { event: event, className: "dark", callback: inner_clicked.bind(w) }, ref_window ); + var menu = new LiteGraph.ContextMenu( values, { scale: Math.max(1,this.ds.scale), event: event, className: "dark", callback: inner_clicked.bind(w) }, ref_window ); function inner_clicked( v, option, event ) { this.value = v; @@ -6668,6 +6979,15 @@ LGraphCanvas.prototype.drawGroups = function(canvas, ctx) ctx.restore(); } +LGraphCanvas.prototype.adjustNodesSize = function() +{ + var nodes = this.graph._nodes; + for(var i = 0; i < nodes.length; ++i) + nodes[i].size = nodes[i].computeSize(); + this.setDirty(true,true); +} + + /** * resizes the canvas to a given size, if no size is passed, then it tries to fill the parentNode * @method resize @@ -6777,7 +7097,7 @@ LGraphCanvas.onGroupAdd = function(info,entry,mouse_event) var ref_window = canvas.getCanvasWindow(); var group = new LiteGraph.LGraphGroup(); - group.pos = canvas.convertEventToCanvas( mouse_event ); + group.pos = canvas.convertEventToCanvasOffset( mouse_event ); canvas.graph.add( group ); } @@ -6814,7 +7134,7 @@ LGraphCanvas.onMenuAdd = function( node, options, e, prev_menu ) var node = LiteGraph.createNode( v.value ); if(node) { - node.pos = canvas.convertEventToCanvas( first_event ); + node.pos = canvas.convertEventToCanvasOffset( first_event ); canvas.graph.add( node ); } } @@ -7073,8 +7393,8 @@ LGraphCanvas.onShowPropertyEditor = function( item, options, e, menu, node ) if( event ) { - dialog.style.left = (event.pageX + offsetx) + "px"; - dialog.style.top = (event.pageY + offsety)+ "px"; + dialog.style.left = (event.clientX + offsetx) + "px"; + dialog.style.top = (event.clientY + offsety)+ "px"; } else { @@ -7098,7 +7418,8 @@ LGraphCanvas.onShowPropertyEditor = function( item, options, e, menu, node ) else if( item.type == "Boolean" ) value = Boolean(value); node[ property ] = value; - dialog.parentNode.removeChild( dialog ); + if(dialog.parentNode) + dialog.parentNode.removeChild( dialog ); node.setDirtyCanvas(true,true); } } @@ -7115,9 +7436,13 @@ LGraphCanvas.prototype.prompt = function( title, value, callback, event ) dialog.close = function() { that.prompt_box = null; - dialog.parentNode.removeChild( dialog ); + if(dialog.parentNode) + dialog.parentNode.removeChild( dialog ); } + if(this.ds.scale > 1) + dialog.style.transform = "scale("+this.ds.scale+")"; + dialog.addEventListener("mouseleave",function(e){ dialog.close(); }); @@ -7173,8 +7498,8 @@ LGraphCanvas.prototype.prompt = function( title, value, callback, event ) if( event ) { - dialog.style.left = (event.pageX + offsetx) + "px"; - dialog.style.top = (event.pageY + offsety)+ "px"; + dialog.style.left = (event.clientX + offsetx) + "px"; + dialog.style.top = (event.clientY + offsety)+ "px"; } else { @@ -7201,12 +7526,30 @@ LGraphCanvas.prototype.showSearchBox = function(event) dialog.close = function() { that.search_box = null; - setTimeout( function(){ that.canvas.focus(); },10 ); //important, if canvas loses focus keys wont be captured - dialog.parentNode.removeChild( dialog ); + document.body.focus(); + setTimeout( function(){ that.canvas.focus(); },20 ); //important, if canvas loses focus keys wont be captured + if(dialog.parentNode) + dialog.parentNode.removeChild( dialog ); } + var timeout_close = null; + + if(this.ds.scale > 1) + dialog.style.transform = "scale("+this.ds.scale+")"; + + dialog.addEventListener("mouseenter",function(e){ + if(timeout_close) + { + clearTimeout(timeout_close); + timeout_close = null; + } + }); + dialog.addEventListener("mouseleave",function(e){ - dialog.close(); + //dialog.close(); + timeout_close = setTimeout(function(){ + dialog.close(); + },500); }); if(that.search_box) @@ -7268,8 +7611,8 @@ LGraphCanvas.prototype.showSearchBox = function(event) if( event ) { - dialog.style.left = (event.pageX + offsetx) + "px"; - dialog.style.top = (event.pageY + offsety)+ "px"; + dialog.style.left = (event.clientX + offsetx) + "px"; + dialog.style.top = (event.clientY + offsety)+ "px"; } else { @@ -7295,7 +7638,7 @@ LGraphCanvas.prototype.showSearchBox = function(event) var node = LiteGraph.createNode( name ); if(node) { - node.pos = graphcanvas.convertEventToCanvas( event ); + node.pos = graphcanvas.convertEventToCanvasOffset( event ); graphcanvas.graph.add( node ); } @@ -7568,8 +7911,8 @@ LGraphCanvas.prototype.createDialog = function( html, options ) } else if( options.event ) { - offsetx += options.event.pageX; - offsety += options.event.pageY; + offsetx += options.event.clientX; + offsety += options.event.clientY; } else //centered { @@ -8192,8 +8535,8 @@ function ContextMenu( values, options ) var top = options.top || 0; if(options.event) { - left = (options.event.pageX - 10); - top = (options.event.pageY - 10); + left = (options.event.clientX - 10); + top = (options.event.clientY - 10); if(options.title) top -= 20; @@ -8214,6 +8557,9 @@ function ContextMenu( values, options ) root.style.left = left + "px"; root.style.top = top + "px"; + + if(options.scale) + root.style.transform = "scale("+options.scale+")"; } ContextMenu.prototype.addItem = function( name, value, options ) @@ -8379,8 +8725,8 @@ ContextMenu.prototype.getFirstEvent = function() ContextMenu.isCursorOverElement = function( event, element ) { - var left = event.pageX; - var top = event.pageY; + var left = event.clientX; + var top = event.clientY; var rect = element.getBoundingClientRect(); if(!rect) return false; @@ -8499,7 +8845,7 @@ LiteGraph.registerNodeType("basic/time", Time); function Subgraph() { var that = this; - this.size = [120,80]; + this.size = [140,80]; //create inner graph this.subgraph = new LGraph(); @@ -8514,19 +8860,18 @@ function Subgraph() this.subgraph.onGlobalOutputRenamed = this.onSubgraphRenamedGlobalOutput.bind(this); this.subgraph.onGlobalOutputTypeChanged = this.onSubgraphTypeChangeGlobalOutput.bind(this); - this.color = "#335"; - this.bgcolor = "#557"; } Subgraph.title = "Subgraph"; Subgraph.desc = "Graph inside a node"; +Subgraph.title_color = "#334"; Subgraph.prototype.onDrawTitle = function(ctx) { if(this.flags.collapsed) return; - ctx.fillStyle = "#AAA"; + ctx.fillStyle = "#555"; var w = LiteGraph.NODE_TITLE_HEIGHT; var x = this.size[0] - w; ctx.fillRect( x, -w, w,w ); @@ -8822,6 +9167,13 @@ ConstantNumber.prototype.onExecute = function() this.setOutputData(0, parseFloat( this.properties["value"] ) ); } +ConstantNumber.prototype.getTitle = function() +{ + if(this.flags.collapsed) + return this.properties.value; + return this.title; +} + ConstantNumber.prototype.setValue = function(v) { this.properties.value = v; @@ -8841,6 +9193,7 @@ function ConstantString() this.addProperty( "value", "" ); this.widget = this.addWidget("text","value","", this.setValue.bind(this) ); this.widgets_up = true; + this.size = [100,30]; } ConstantString.title = "Const String"; @@ -8856,6 +9209,8 @@ ConstantString.prototype.onPropertyChanged = function(name,value) this.widget.value = value; } +ConstantString.prototype.getTitle = ConstantNumber.prototype.getTitle; + ConstantString.prototype.onExecute = function() { this.setOutputData(0, this.properties["value"] ); @@ -8864,6 +9219,92 @@ ConstantString.prototype.onExecute = function() LiteGraph.registerNodeType("basic/string", ConstantString ); +function ConstantData() +{ + this.addOutput("",""); + this.addProperty( "value", "" ); + this.widget = this.addWidget("text","json","", this.setValue.bind(this) ); + this.widgets_up = true; + this.size = [140,30]; + this._value = null; +} + +ConstantData.title = "Const Data"; +ConstantData.desc = "Constant Data"; + +ConstantData.prototype.setValue = function(v) +{ + this.properties.value = v; + this.onPropertyChanged("value",v); +} + +ConstantData.prototype.onPropertyChanged = function(name,value) +{ + this.widget.value = value; + if(value == null || value == "") + return; + + try + { + this._value = JSON.parse(value); + this.boxcolor = "#AEA"; + } + catch (err) + { + this.boxcolor = "red"; + } +} + +ConstantData.prototype.onExecute = function() +{ + this.setOutputData(0, this._value ); +} + +LiteGraph.registerNodeType("basic/data", ConstantData ); + + +function ObjectProperty() +{ + this.addInput("obj",""); + this.addOutput("",""); + this.addProperty( "value", "" ); + this.widget = this.addWidget("text","prop.","", this.setValue.bind(this) ); + this.widgets_up = true; + this.size = [140,30]; + this._value = null; +} + +ObjectProperty.title = "Object property"; +ObjectProperty.desc = "Outputs the property of an object"; + +ObjectProperty.prototype.setValue = function(v) +{ + this.properties.value = v; + this.widget.value = v; +} + +ObjectProperty.prototype.getTitle = function() +{ + if(this.flags.collapsed) + return "in." + this.properties.value; + return this.title; +} + +ObjectProperty.prototype.onPropertyChanged = function(name,value) +{ + this.widget.value = value; +} + +ObjectProperty.prototype.onExecute = function() +{ + var data = this.getInputData(0); + if(data != null) + this.setOutputData(0, data[ this.properties.value ] ); +} + +LiteGraph.registerNodeType("basic/object_property", ObjectProperty ); + + //Watch a value in the editor function Watch() { @@ -8881,6 +9322,13 @@ Watch.prototype.onExecute = function() this.value = this.getInputData(0); } +Watch.prototype.getTitle = function() +{ + if(this.flags.collapsed) + return this.inputs[0].label; + return this.title; +} + Watch.toString = function( o ) { if( o == null ) @@ -8907,23 +9355,23 @@ Watch.prototype.onDrawBackground = function(ctx) LiteGraph.registerNodeType("basic/watch", Watch); -//Watch a value in the editor -function Pass() +//in case one type doesnt match other type but you want to connect them anyway +function Cast() { this.addInput("in",0); this.addOutput("out",0); this.size = [40,20]; } -Pass.title = "Pass"; -Pass.desc = "Allows to connect different types"; +Cast.title = "Cast"; +Cast.desc = "Allows to connect different types"; -Pass.prototype.onExecute = function() +Cast.prototype.onExecute = function() { this.setOutputData( 0, this.getInputData(0) ); } -LiteGraph.registerNodeType("basic/pass", Pass); +LiteGraph.registerNodeType("basic/cast", Cast); //Show value inside the debug console @@ -9196,7 +9644,7 @@ LiteGraph.registerNodeType("events/counter", EventCounter ); function DelayEvent() { this.size = [60,20]; - this.addProperty( "time", 1000 ); + this.addProperty( "time_in_ms", 1000 ); this.addInput("event", LiteGraph.ACTION); this.addOutput("on_time", LiteGraph.EVENT); @@ -9208,13 +9656,20 @@ DelayEvent.desc = "Delays one event"; DelayEvent.prototype.onAction = function(action, param) { - this._pending.push([ this.properties.time, param ]); + var time = this.properties.time_in_ms; + if(time <= 0) + this.trigger(null, param); + else + this._pending.push([ time, param ]); } DelayEvent.prototype.onExecute = function() { var dt = this.graph.elapsed_time * 1000; //in ms + if(this.isInputConnected(1)) + this.properties.time_in_ms = this.getInputData(1); + for(var i = 0; i < this._pending.length; ++i) { var action = this._pending[i]; @@ -9233,7 +9688,7 @@ DelayEvent.prototype.onExecute = function() DelayEvent.prototype.onGetInputs = function() { - return [["event",LiteGraph.ACTION]]; + return [["event",LiteGraph.ACTION],["time_in_ms","number"]]; } LiteGraph.registerNodeType("events/delay", DelayEvent ); @@ -9317,11 +9772,11 @@ var LiteGraph = global.LiteGraph; function WidgetButton() { - this.addOutput( "clicked", LiteGraph.EVENT ); - this.addProperty( "text","" ); - this.addProperty( "font_size", 40 ); + this.addOutput( "", LiteGraph.EVENT ); + this.addProperty( "text","click me" ); + this.addProperty( "font_size", 30 ); this.addProperty( "message", "" ); - this.size = [64,84]; + this.size = [164,84]; } WidgetButton.title = "Button"; @@ -9332,15 +9787,13 @@ var LiteGraph = global.LiteGraph; { if(this.flags.collapsed) return; - - //ctx.font = "40px Arial"; - //ctx.textAlign = "center"; + var margin = 10; ctx.fillStyle = "black"; - ctx.fillRect(1,1,this.size[0] - 3, this.size[1] - 3); + ctx.fillRect(margin+1,margin+1,this.size[0] - margin*2, this.size[1] - margin*2); ctx.fillStyle = "#AAF"; - ctx.fillRect(0,0,this.size[0] - 3, this.size[1] - 3); + ctx.fillRect(margin-1,margin-1,this.size[0] - margin*2, this.size[1] - margin*2); ctx.fillStyle = this.clicked ? "white" : (this.mouseOver ? "#668" : "#334"); - ctx.fillRect(1,1,this.size[0] - 4, this.size[1] - 4); + ctx.fillRect(margin,margin,this.size[0] - margin*2, this.size[1] - margin*2); if( this.properties.text || this.properties.text === 0 ) { @@ -9544,117 +9997,87 @@ var LiteGraph = global.LiteGraph; { this.addOutput("",'number'); this.size = [64,84]; - this.properties = {min:0,max:1,value:0.5,wcolor:"#7AF",size:50}; + this.properties = { min:0, max:1, value:0.5, color:"#7AF", precision: 2 }; + this.value = -1; } WidgetKnob.title = "Knob"; WidgetKnob.desc = "Circular controller"; - WidgetKnob.widgets = [{name:"increase",text:"+",type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}]; - - - WidgetKnob.prototype.onAdded = function() - { - this.value = (this.properties["value"] - this.properties["min"]) / (this.properties["max"] - this.properties["min"]); - - this.imgbg = this.loadImage("imgs/knob_bg.png"); - this.imgfg = this.loadImage("imgs/knob_fg.png"); - } - - WidgetKnob.prototype.onDrawImageKnob = function(ctx) - { - if(!this.imgfg || !this.imgfg.width) return; - - var d = this.imgbg.width*0.5; - var scale = this.size[0] / this.imgfg.width; - - ctx.save(); - ctx.translate(0,20); - ctx.scale(scale,scale); - ctx.drawImage(this.imgbg,0,0); - //ctx.drawImage(this.imgfg,0,20); - - ctx.translate(d,d); - ctx.rotate(this.value * (Math.PI*2) * 6/8 + Math.PI * 10/8); - //ctx.rotate(this.value * (Math.PI*2)); - ctx.translate(-d,-d); - ctx.drawImage(this.imgfg,0,0); - - ctx.restore(); - - if(this.title) - { - ctx.font = "bold 16px Criticized,Tahoma"; - ctx.fillStyle="rgba(100,100,100,0.8)"; - ctx.textAlign = "center"; - ctx.fillText(this.title.toUpperCase(), this.size[0] * 0.5, 18 ); - ctx.textAlign = "left"; - } - } - - WidgetKnob.prototype.onDrawVectorKnob = function(ctx) - { - if(!this.imgfg || !this.imgfg.width) return; - - //circle around - ctx.lineWidth = 1; - ctx.strokeStyle= this.mouseOver ? "#FFF" : "#AAA"; - ctx.fillStyle="#000"; - ctx.beginPath(); - ctx.arc(this.size[0] * 0.5,this.size[1] * 0.5 + 10,this.properties.size * 0.5,0,Math.PI*2,true); - ctx.stroke(); - - if(this.value > 0) - { - ctx.strokeStyle=this.properties["wcolor"]; - ctx.lineWidth = (this.properties.size * 0.2); - ctx.beginPath(); - ctx.arc(this.size[0] * 0.5,this.size[1] * 0.5 + 10,this.properties.size * 0.35,Math.PI * -0.5 + Math.PI*2 * this.value,Math.PI * -0.5,true); - ctx.stroke(); - ctx.lineWidth = 1; - } - - ctx.font = (this.properties.size * 0.2) + "px Arial"; - ctx.fillStyle="#AAA"; - ctx.textAlign = "center"; - - var str = this.properties["value"]; - if(typeof(str) == 'number') - str = str.toFixed(2); - - ctx.fillText(str,this.size[0] * 0.5,this.size[1]*0.65); - ctx.textAlign = "left"; - } + WidgetKnob.size = [ 80, 100 ]; WidgetKnob.prototype.onDrawForeground = function(ctx) { - this.onDrawImageKnob(ctx); + if(this.flags.collapsed) + return; + + if(this.value == -1) + this.value = (this.properties.value - this.properties.min) / (this.properties.max - this.properties.min ); + + var center_x = this.size[0] * 0.5; + var center_y = this.size[1] * 0.5; + var radius = Math.min( this.size[0], this.size[1] ) * 0.5 - 5; + var w = Math.floor( radius * 0.05 ); + + ctx.globalAlpha = 1; + ctx.save(); + ctx.translate( center_x, center_y ); + ctx.rotate(Math.PI*0.75); + + //bg + ctx.fillStyle = "rgba(0,0,0,0.5)"; + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.arc( 0, 0, radius, 0, Math.PI*1.5 ); + ctx.fill(); + + //value + ctx.strokeStyle = "black"; + ctx.fillStyle = this.properties.color; + ctx.lineWidth = 2; + ctx.beginPath(); + ctx.moveTo(0,0); + ctx.arc(0,0, radius - 4, 0, Math.PI*1.5 * Math.max(0.01,this.value) ); + ctx.closePath(); + ctx.fill(); + //ctx.stroke(); + ctx.lineWidth = 1; + ctx.globalAlpha = 1; + ctx.restore(); + + //inner + ctx.fillStyle = "black"; + ctx.beginPath(); + ctx.arc( center_x, center_y, radius*0.75, 0, Math.PI*2, true ); + ctx.fill(); + + //miniball + ctx.fillStyle = this.mouseOver ? "white" : this.properties.color; + ctx.beginPath(); + var angle = this.value * Math.PI*1.5 + Math.PI*0.75; + ctx.arc( center_x + Math.cos(angle) * radius * 0.65, center_y + Math.sin(angle) * radius*0.65, radius*0.05, 0, Math.PI*2, true ); + ctx.fill(); + + //text + ctx.fillStyle = this.mouseOver ? "white" : "#AAA"; + ctx.font = Math.floor(radius * 0.5) + "px Arial"; + ctx.textAlign = "center"; + ctx.fillText( this.properties.value.toFixed(this.properties.precision), center_x, center_y + radius * 0.15); } WidgetKnob.prototype.onExecute = function() { - this.setOutputData(0, this.properties["value"] ); - + this.setOutputData(0, this.properties.value ); this.boxcolor = LiteGraph.colorToString([this.value,this.value,this.value]); } WidgetKnob.prototype.onMouseDown = function(e) { - if(!this.imgfg || !this.imgfg.width) return; - - //this.center = [this.imgbg.width * 0.5, this.imgbg.height * 0.5 + 20]; - //this.radius = this.imgbg.width * 0.5; this.center = [this.size[0] * 0.5, this.size[1] * 0.5 + 20]; this.radius = this.size[0] * 0.5; - if(e.canvasY - this.pos[1] < 20 || LiteGraph.distance([e.canvasX,e.canvasY],[this.pos[0] + this.center[0],this.pos[1] + this.center[1]]) > this.radius) return false; - this.oldmouse = [ e.canvasX - this.pos[0], e.canvasY - this.pos[1] ]; this.captureInput(true); - - /* - var tmp = this.localToScreenSpace(0,0); - this.trace(tmp[0] + "," + tmp[1]); */ return true; } @@ -9666,12 +10089,12 @@ var LiteGraph = global.LiteGraph; var v = this.value; v -= (m[1] - this.oldmouse[1]) * 0.01; - if(v > 1.0) v = 1.0; - else if(v < 0.0) v = 0.0; - + if(v > 1.0) + v = 1.0; + else if(v < 0.0) + v = 0.0; this.value = v; - this.properties["value"] = this.properties["min"] + (this.properties["max"] - this.properties["min"]) * this.value; - + this.properties.value = this.properties.min + (this.properties.max - this.properties.min) * this.value; this.oldmouse = m; this.setDirtyCanvas(true); } @@ -9685,29 +10108,13 @@ var LiteGraph = global.LiteGraph; } } - WidgetKnob.prototype.onMouseLeave = function(e) - { - //this.oldmouse = null; - } - WidgetKnob.prototype.onPropertyChanged = function(name,value) { - if(name=="wcolor") - this.properties[name] = value; - else if(name=="size") - { - value = parseInt(value); - this.properties[name] = value; - this.size = [value+4,value+24]; - this.setDirtyCanvas(true,true); - } - else if(name=="min" || name=="max" || name=="value") + if(name=="min" || name=="max" || name=="value") { this.properties[name] = parseFloat(value); + return true; //block } - else - return false; - return true; } LiteGraph.registerNodeType("widget/knob", WidgetKnob); @@ -9748,70 +10155,35 @@ var LiteGraph = global.LiteGraph; { this.size = [160,26]; this.addOutput("",'number'); - this.properties = {wcolor:"#7AF",min:0,max:1,value:0.5}; + this.properties = {color:"#7AF",min:0,max:1,value:0.5}; + this.value = -1; } WidgetHSlider.title = "H.Slider"; WidgetHSlider.desc = "Linear slider controller"; - WidgetHSlider.prototype.onAdded = function() - { - this.value = 0.5; - this.imgfg = this.loadImage("imgs/slider_fg.png"); - } - - WidgetHSlider.prototype.onDrawVectorial = function(ctx) - { - if(!this.imgfg || !this.imgfg.width) return; - - //border - ctx.lineWidth = 1; - ctx.strokeStyle= this.mouseOver ? "#FFF" : "#AAA"; - ctx.fillStyle="#000"; - ctx.beginPath(); - ctx.rect(2,0,this.size[0]-4,20); - ctx.stroke(); - - ctx.fillStyle=this.properties["wcolor"]; - ctx.beginPath(); - ctx.rect(2+(this.size[0]-4-20)*this.value,0, 20,20); - ctx.fill(); - } - - WidgetHSlider.prototype.onDrawImage = function(ctx) - { - if(!this.imgfg || !this.imgfg.width) - return; - - //border - ctx.lineWidth = 1; - ctx.fillStyle="#000"; - ctx.fillRect(2,9,this.size[0]-4,2); - - ctx.strokeStyle= "#333"; - ctx.beginPath(); - ctx.moveTo(2,9); - ctx.lineTo(this.size[0]-4,9); - ctx.stroke(); - - ctx.strokeStyle= "#AAA"; - ctx.beginPath(); - ctx.moveTo(2,11); - ctx.lineTo(this.size[0]-4,11); - ctx.stroke(); - - ctx.drawImage(this.imgfg, 2+(this.size[0]-4)*this.value - this.imgfg.width*0.5,-this.imgfg.height*0.5 + 10); - }, - WidgetHSlider.prototype.onDrawForeground = function(ctx) { - this.onDrawImage(ctx); + if(this.value == -1) + this.value = (this.properties.value - this.properties.min) / (this.properties.max - this.properties.min ); + + //border + ctx.globalAlpha = 1; + ctx.lineWidth = 1; + ctx.fillStyle = "#000"; + ctx.fillRect(2,2,this.size[0]-4,this.size[1]-4); + + ctx.fillStyle=this.properties.color; + ctx.beginPath(); + ctx.rect(4,4, (this.size[0]-8)*this.value, this.size[1]-8); + ctx.fill(); + } WidgetHSlider.prototype.onExecute = function() { - this.properties["value"] = this.properties["min"] + (this.properties["max"] - this.properties["min"]) * this.value; - this.setOutputData(0, this.properties["value"] ); + this.properties.value = this.properties.min + (this.properties.max - this.properties.min) * this.value; + this.setOutputData(0, this.properties.value ); this.boxcolor = LiteGraph.colorToString([this.value,this.value,this.value]); } @@ -9854,15 +10226,6 @@ var LiteGraph = global.LiteGraph; //this.oldmouse = null; } - WidgetHSlider.prototype.onPropertyChanged = function(name,value) - { - if(name=="wcolor") - this.properties[name] = value; - else - return false; - return true; - } - LiteGraph.registerNodeType("widget/hslider", WidgetHSlider ); @@ -9870,7 +10233,7 @@ var LiteGraph = global.LiteGraph; { this.size = [160,26]; this.addInput("",'number'); - this.properties = {min:0,max:1,value:0,wcolor:"#AAF"}; + this.properties = {min:0,max:1,value:0,color:"#AAF"}; } WidgetProgress.title = "Progress"; @@ -9887,7 +10250,7 @@ var LiteGraph = global.LiteGraph; { //border ctx.lineWidth = 1; - ctx.fillStyle=this.properties.wcolor; + ctx.fillStyle=this.properties.color; var v = (this.properties.value - this.properties.min) / (this.properties.max - this.properties.min); v = Math.min(1,v); v = Math.max(0,v); @@ -9916,7 +10279,7 @@ var LiteGraph = global.LiteGraph; if(this.properties["glowSize"]) { - ctx.shadowColor = this.properties["color"]; + ctx.shadowColor = this.properties.color; ctx.shadowOffsetX = 0; ctx.shadowOffsetY = 0; ctx.shadowBlur = this.properties["glowSize"]; @@ -10458,10 +10821,7 @@ MathRand.prototype.onExecute = function() MathRand.prototype.onDrawBackground = function(ctx) { //show the current value - if(this._last_v) - this.outputs[0].label = this._last_v.toFixed(3); - else - this.outputs[0].label = "?"; + this.outputs[0].label = ( this._last_v || 0 ).toFixed(3); } MathRand.prototype.onGetInputs = function() { @@ -10470,6 +10830,103 @@ MathRand.prototype.onGetInputs = function() { LiteGraph.registerNodeType("math/rand", MathRand); + +//basic continuous noise +function MathNoise() +{ + this.addInput("in","number"); + this.addOutput("out","number"); + this.addProperty( "min", 0 ); + this.addProperty( "max", 1 ); + this.addProperty( "smooth", true ); + this.size = [90,20]; +} + +MathNoise.title = "Noise"; +MathNoise.desc = "Random number with temporal continuity"; +MathNoise.data = null; + +MathNoise.getValue = function(f,smooth) +{ + if( !MathNoise.data ) + { + MathNoise.data = new Float32Array(1024); + for(var i = 0; i < MathNoise.data.length; ++i) + MathNoise.data[i] = Math.random(); + } + f = f % 1024; + if(f < 0) + f += 1024; + var f_min = Math.floor(f); + var f = f - f_min; + var r1 = MathNoise.data[ f_min ]; + var r2 = MathNoise.data[ f_min == 1023 ? 0 : f_min + 1 ]; + if(smooth) + f = f*f*f*(f*(f*6.0-15.0)+10.0); + return r1 * (1-f) + r2 * f; +} + +MathNoise.prototype.onExecute = function() +{ + var f = (this.getInputData(0) || 0); + var r = MathNoise.getValue( f, this.properties.smooth ); + var min = this.properties.min; + var max = this.properties.max; + this._last_v = r * (max-min) + min; + this.setOutputData(0, this._last_v ); +} + +MathNoise.prototype.onDrawBackground = function(ctx) +{ + //show the current value + this.outputs[0].label = ( this._last_v || 0 ).toFixed(3); +} + +LiteGraph.registerNodeType("math/noise", MathNoise); + +//generates spikes every random time +function MathSpikes() +{ + this.addOutput("out","number"); + this.addProperty( "min_time", 1 ); + this.addProperty( "max_time", 2 ); + this.addProperty( "duration", 0.2 ); + this.size = [90,20]; + this._remaining_time = 0; + this._blink_time = 0; +} + +MathSpikes.title = "Spikes"; +MathSpikes.desc = "spike every random time"; + +MathSpikes.prototype.onExecute = function() +{ + var dt = this.graph.elapsed_time; //in secs + + this._remaining_time -= dt; + this._blink_time -= dt; + + var v = 0; + if(this._blink_time > 0) + { + var f = this._blink_time / this.properties.duration; + v = 1/(Math.pow(f*8-4,4)+1); + } + + if( this._remaining_time < 0) + { + 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"; + } + else + this.boxcolor = "#000"; + this.setOutputData( 0, v ); +} + +LiteGraph.registerNodeType("math/spikes", MathSpikes); + + //Math clamp function MathClamp() { @@ -10758,6 +11215,7 @@ MathOperation.values = ["+","-","*","/","%","^"]; MathOperation.title = "Operation"; MathOperation.desc = "Easy math operators"; MathOperation["@OP"] = { type:"enum", title: "operation", values: MathOperation.values }; +MathOperation.size = [100,50]; MathOperation.prototype.getTitle = function() { @@ -10807,9 +11265,9 @@ MathOperation.prototype.onDrawBackground = function(ctx) return; ctx.font = "40px Arial"; - ctx.fillStyle = "#CCC"; + ctx.fillStyle = "#666"; ctx.textAlign = "center"; - ctx.fillText(this.properties.OP, this.size[0] * 0.5, this.size[1] * 0.35 + LiteGraph.NODE_TITLE_HEIGHT ); + ctx.fillText(this.properties.OP, this.size[0] * 0.5, ( this.size[1] + LiteGraph.NODE_TITLE_HEIGHT ) * 0.5 ); ctx.textAlign = "left"; } @@ -11023,12 +11481,20 @@ function MathFormula() this.addInput("y","number"); this.addOutput("","number"); this.properties = {x:1.0, y:1.0, formula:"x+y"}; + this.code_widget = this.addWidget("text","F(x,y)",this.properties.formula,function(v,canvas,node){ node.properties.formula = v; }); this.addWidget("toggle","allow",LiteGraph.allow_scripts,function(v){ LiteGraph.allow_scripts = v; }); this._func = null; } MathFormula.title = "Formula"; MathFormula.desc = "Compute formula"; +MathFormula.size = [160,100]; + +MathAverageFilter.prototype.onPropertyChanged = function( name, value ) +{ + if(name == "formula") + this.code_widget.value = value; +} MathFormula.prototype.onExecute = function() { @@ -11049,19 +11515,27 @@ MathFormula.prototype.onExecute = function() var f = this.properties["formula"]; - if(!this._func || this._func_code != this.properties.formula) + var value; + try { - this._func = new Function( "x","y","TIME", "return " + this.properties.formula ); - this._func_code = this.properties.formula; + if(!this._func || this._func_code != this.properties.formula) + { + this._func = new Function( "x","y","TIME", "return " + this.properties.formula ); + this._func_code = this.properties.formula; + } + value = this._func(x,y,this.graph.globaltime); + this.boxcolor = null; + } + catch (err) + { + this.boxcolor = "red"; } - - var value = this._func(x,y,this.graph.globaltime); this.setOutputData(0, value ); } MathFormula.prototype.getTitle = function() { - return this._func_code || ""; + return this._func_code || "Formula"; } MathFormula.prototype.onDrawBackground = function() @@ -11380,6 +11854,510 @@ if(global.glMatrix) } //glMatrix +})(this); +(function(global){ +var LiteGraph = global.LiteGraph; + +function Math3DVec2ToXYZ() +{ + this.addInput("vec2","vec2"); + this.addOutput("x","number"); + this.addOutput("y","number"); +} + +Math3DVec2ToXYZ.title = "Vec2->XY"; +Math3DVec2ToXYZ.desc = "vector 2 to components"; + +Math3DVec2ToXYZ.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) return; + + this.setOutputData( 0, v[0] ); + this.setOutputData( 1, v[1] ); +} + +LiteGraph.registerNodeType("math3d/vec2-to-xyz", Math3DVec2ToXYZ ); + + +function Math3DXYToVec2() +{ + this.addInputs([["x","number"],["y","number"]]); + this.addOutput("vec2","vec2"); + this.properties = {x:0, y:0}; + this._data = new Float32Array(2); +} + +Math3DXYToVec2.title = "XY->Vec2"; +Math3DXYToVec2.desc = "components to vector2"; + +Math3DXYToVec2.prototype.onExecute = function() +{ + var x = this.getInputData(0); + if(x == null) x = this.properties.x; + var y = this.getInputData(1); + if(y == null) y = this.properties.y; + + var data = this._data; + data[0] = x; + data[1] = y; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/xy-to-vec2", Math3DXYToVec2 ); + + + + +function Math3DVec3ToXYZ() +{ + this.addInput("vec3","vec3"); + this.addOutput("x","number"); + this.addOutput("y","number"); + this.addOutput("z","number"); +} + +Math3DVec3ToXYZ.title = "Vec3->XYZ"; +Math3DVec3ToXYZ.desc = "vector 3 to components"; + +Math3DVec3ToXYZ.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) return; + + this.setOutputData( 0, v[0] ); + this.setOutputData( 1, v[1] ); + this.setOutputData( 2, v[2] ); +} + +LiteGraph.registerNodeType("math3d/vec3-to-xyz", Math3DVec3ToXYZ ); + + +function Math3DXYZToVec3() +{ + 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); +} + +Math3DXYZToVec3.title = "XYZ->Vec3"; +Math3DXYZToVec3.desc = "components to vector3"; + +Math3DXYZToVec3.prototype.onExecute = function() +{ + var x = this.getInputData(0); + if(x == null) x = this.properties.x; + var y = this.getInputData(1); + if(y == null) y = this.properties.y; + var z = this.getInputData(2); + if(z == null) z = this.properties.z; + + var data = this._data; + data[0] = x; + data[1] = y; + data[2] = z; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/xyz-to-vec3", Math3DXYZToVec3 ); + + + +function Math3DVec4ToXYZW() +{ + this.addInput("vec4","vec4"); + this.addOutput("x","number"); + this.addOutput("y","number"); + this.addOutput("z","number"); + this.addOutput("w","number"); +} + +Math3DVec4ToXYZW.title = "Vec4->XYZW"; +Math3DVec4ToXYZW.desc = "vector 4 to components"; + +Math3DVec4ToXYZW.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) return; + + this.setOutputData( 0, v[0] ); + this.setOutputData( 1, v[1] ); + this.setOutputData( 2, v[2] ); + this.setOutputData( 3, v[3] ); +} + +LiteGraph.registerNodeType("math3d/vec4-to-xyzw", Math3DVec4ToXYZW ); + + +function Math3DXYZWToVec4() +{ + 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); +} + +Math3DXYZWToVec4.title = "XYZW->Vec4"; +Math3DXYZWToVec4.desc = "components to vector4"; + +Math3DXYZWToVec4.prototype.onExecute = function() +{ + var x = this.getInputData(0); + if(x == null) x = this.properties.x; + var y = this.getInputData(1); + if(y == null) y = this.properties.y; + var z = this.getInputData(2); + if(z == null) z = this.properties.z; + var w = this.getInputData(3); + if(w == null) w = this.properties.w; + + var data = this._data; + data[0] = x; + data[1] = y; + data[2] = z; + data[3] = w; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/xyzw-to-vec4", Math3DXYZWToVec4 ); + + + +function Math3DVec3Scale() +{ + this.addInput("in","vec3"); + this.addInput("f","number"); + this.addOutput("out","vec3"); + this.properties = {f:1}; + this._data = new Float32Array(3); +} + +Math3DVec3Scale.title = "vec3_scale"; +Math3DVec3Scale.desc = "scales the components of a vec3"; + +Math3DVec3Scale.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) + return; + var f = this.getInputData(1); + if(f == null) f = this.properties.f; + + var data = this._data; + data[0] = v[0] * f; + data[1] = v[1] * f; + data[2] = v[2] * f; + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/vec3-scale", Math3DVec3Scale ); + +function Math3DVec3Length() +{ + this.addInput("in","vec3"); + this.addOutput("out","number"); +} + +Math3DVec3Length.title = "vec3_length"; +Math3DVec3Length.desc = "returns the module of a vector"; + +Math3DVec3Length.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) + return; + var dist = Math.sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ); + this.setOutputData( 0, dist ); +} + +LiteGraph.registerNodeType("math3d/vec3-length", Math3DVec3Length ); + +function Math3DVec3Normalize() +{ + this.addInput("in","vec3"); + this.addOutput("out","vec3"); + this._data = new Float32Array(3); +} + +Math3DVec3Normalize.title = "vec3_normalize"; +Math3DVec3Normalize.desc = "returns the vector normalized"; + +Math3DVec3Normalize.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) + return; + var dist = Math.sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ); + var data = this._data; + data[0] = v[0] / dist; + data[1] = v[1] / dist; + data[2] = v[2] / dist; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/vec3-normalize", Math3DVec3Normalize ); + +function Math3DVec3Lerp() +{ + 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); +} + +Math3DVec3Lerp.title = "vec3_lerp"; +Math3DVec3Lerp.desc = "returns the interpolated vector"; + +Math3DVec3Lerp.prototype.onExecute = function() +{ + var A = this.getInputData(0); + if(A == null) + return; + var B = this.getInputData(1); + if(B == null) + return; + var f = this.getInputOrProperty("f"); + + var data = this._data; + data[0] = A[0] * (1-f) + B[0] * f; + data[1] = A[1] * (1-f) + B[1] * f; + data[2] = A[2] * (1-f) + B[2] * f; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/vec3-lerp", Math3DVec3Lerp ); + + +function Math3DVec3Dot() +{ + this.addInput("A","vec3"); + this.addInput("B","vec3"); + this.addOutput("out","number"); +} + +Math3DVec3Dot.title = "vec3_dot"; +Math3DVec3Dot.desc = "returns the dot product"; + +Math3DVec3Dot.prototype.onExecute = function() +{ + var A = this.getInputData(0); + if(A == null) + return; + var B = this.getInputData(1); + if(B == null) + return; + + var dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]; + this.setOutputData( 0, dot ); +} + +LiteGraph.registerNodeType("math3d/vec3-dot", Math3DVec3Dot ); + + +//if glMatrix is installed... +if(global.glMatrix) +{ + + function Math3DQuaternion() + { + this.addOutput("quat","quat"); + this.properties = { x:0, y:0, z:0, w: 1 }; + this._value = quat.create(); + } + + Math3DQuaternion.title = "Quaternion"; + Math3DQuaternion.desc = "quaternion"; + + Math3DQuaternion.prototype.onExecute = function() + { + this._value[0] = this.properties.x; + this._value[1] = this.properties.y; + this._value[2] = this.properties.z; + this._value[3] = this.properties.w; + this.setOutputData( 0, this._value ); + } + + LiteGraph.registerNodeType("math3d/quaternion", Math3DQuaternion ); + + + function Math3DRotation() + { + this.addInputs([["degrees","number"],["axis","vec3"]]); + this.addOutput("quat","quat"); + this.properties = { angle:90.0, axis: vec3.fromValues(0,1,0) }; + + this._value = quat.create(); + } + + Math3DRotation.title = "Rotation"; + Math3DRotation.desc = "quaternion rotation"; + + Math3DRotation.prototype.onExecute = function() + { + var angle = this.getInputData(0); + if(angle == null) angle = this.properties.angle; + var axis = this.getInputData(1); + if(axis == null) axis = this.properties.axis; + + var R = quat.setAxisAngle( this._value, axis, angle * 0.0174532925 ); + this.setOutputData( 0, R ); + } + + + LiteGraph.registerNodeType("math3d/rotation", Math3DRotation ); + + + //Math3D rotate vec3 + function Math3DRotateVec3() + { + this.addInputs([["vec3","vec3"],["quat","quat"]]); + this.addOutput("result","vec3"); + this.properties = { vec: [0,0,1] }; + } + + Math3DRotateVec3.title = "Rot. Vec3"; + Math3DRotateVec3.desc = "rotate a point"; + + Math3DRotateVec3.prototype.onExecute = function() + { + var vec = this.getInputData(0); + if(vec == null) vec = this.properties.vec; + var quat = this.getInputData(1); + if(quat == null) + this.setOutputData(vec); + else + this.setOutputData( 0, vec3.transformQuat( vec3.create(), vec, quat ) ); + } + + LiteGraph.registerNodeType("math3d/rotate_vec3", Math3DRotateVec3); + + + + function Math3DMultQuat() + { + this.addInputs( [["A","quat"],["B","quat"]] ); + this.addOutput( "A*B","quat" ); + + this._value = quat.create(); + } + + Math3DMultQuat.title = "Mult. Quat"; + Math3DMultQuat.desc = "rotate quaternion"; + + Math3DMultQuat.prototype.onExecute = function() + { + var A = this.getInputData(0); + if(A == null) return; + var B = this.getInputData(1); + if(B == null) return; + + var R = quat.multiply( this._value, A, B ); + this.setOutputData( 0, R ); + } + + LiteGraph.registerNodeType("math3d/mult-quat", Math3DMultQuat ); + + + function Math3DQuatSlerp() + { + this.addInputs( [["A","quat"],["B","quat"],["factor","number"]] ); + this.addOutput( "slerp","quat" ); + this.addProperty( "factor", 0.5 ); + + this._value = quat.create(); + } + + Math3DQuatSlerp.title = "Quat Slerp"; + Math3DQuatSlerp.desc = "quaternion spherical interpolation"; + + Math3DQuatSlerp.prototype.onExecute = function() + { + var A = this.getInputData(0); + if(A == null) + return; + var B = this.getInputData(1); + if(B == null) + return; + var factor = this.properties.factor; + if( this.getInputData(2) != null ) + factor = this.getInputData(2); + + var R = quat.slerp( this._value, A, B, factor ); + this.setOutputData( 0, R ); + } + + LiteGraph.registerNodeType("math3d/quat-slerp", Math3DQuatSlerp ); + +} //glMatrix + +})(this); +//basic nodes +(function(global){ + + var LiteGraph = global.LiteGraph; + + function toString(a) + { + return String(a); + } + + LiteGraph.wrapFunctionAsNode("string/toString",compare, ["*"],"String"); + + function compare(a,b) + { + return a==b; + } + + LiteGraph.wrapFunctionAsNode("string/compare",compare, ["String","String"],"Boolean"); + + function concatenate(a,b) + { + if(a === undefined) + return b; + if(b === undefined) + return a; + return a + b; + } + + LiteGraph.wrapFunctionAsNode("string/concatenate",concatenate, ["String","String"],"String"); + + function contains(a,b) + { + if(a === undefined || b === undefined ) + return false; + return a.indexOf(b) != -1; + } + + LiteGraph.wrapFunctionAsNode("string/contains",contains, ["String","String"],"Boolean"); + + function toUpperCase(a) + { + if(a != null && a.constructor === String) + return a.toUpperCase(); + return a; + } + + LiteGraph.wrapFunctionAsNode("string/toUpperCase",toUpperCase, ["String"],"String"); + + function split(a,b) + { + if(a != null && a.constructor === String) + return a.split(b || " "); + return [a]; + } + + LiteGraph.wrapFunctionAsNode("string/split",toUpperCase, ["String","String"],"Array"); + + + })(this); (function(global){ var LiteGraph = global.LiteGraph; @@ -11404,11 +12382,11 @@ Selector.prototype.onDrawBackground = function(ctx) if(this.flags.collapsed) return; ctx.fillStyle = "#AFB"; - var y = (this.selected + 1) * LiteGraph.NODE_SLOT_HEIGHT + 2; + var y = (this.selected + 1) * LiteGraph.NODE_SLOT_HEIGHT + 6; ctx.beginPath(); - ctx.moveTo(30, y); - ctx.lineTo(30, y+LiteGraph.NODE_SLOT_HEIGHT); - ctx.lineTo(24, y+LiteGraph.NODE_SLOT_HEIGHT*0.5); + ctx.moveTo(50, y); + ctx.lineTo(50, y+LiteGraph.NODE_SLOT_HEIGHT); + ctx.lineTo(34, y+LiteGraph.NODE_SLOT_HEIGHT*0.5); ctx.fill(); } @@ -12340,7 +13318,7 @@ global.LGraphTexture = null; if(typeof(GL) != "undefined") { - LGraphCanvas.link_type_colors["Texture"] = "#AEF"; + LGraphCanvas.link_type_colors["Texture"] = "#987"; function LGraphTexture() { @@ -12448,6 +13426,14 @@ if(typeof(GL) != "undefined") return type; } + LGraphTexture.getWhiteTexture = function() + { + if(this._white_texture) + return this._white_texture; + var texture = this._white_texture = GL.Texture.fromMemory(1,1,[255,255,255,255],{ format: gl.RGBA, wrap: gl.REPEAT, filter: gl.NEAREST }); + return texture; + } + LGraphTexture.getNoiseTexture = function() { if(this._noise_texture) @@ -13497,7 +14483,7 @@ if(typeof(GL) != "undefined") LGraphTextureDownsample.title = "Downsample"; LGraphTextureDownsample.desc = "Downsample Texture"; LGraphTextureDownsample.widgets_info = { - iterations: { type:"number", step: 1, precision: 0, min: 1 }, + iterations: { type:"number", step: 1, precision: 0, min: 0 }, precision: { widget:"combo", values: LGraphTexture.MODE_VALUES } }; @@ -13514,6 +14500,12 @@ if(typeof(GL) != "undefined") if(!tex || tex.texture_type !== GL.TEXTURE_2D ) return; + if( this.properties.iterations < 1) + { + this.setOutputData(0,tex); + return; + } + var shader = LGraphTextureDownsample._shader; if(!shader) LGraphTextureDownsample._shader = shader = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphTextureDownsample.pixel_shader ); @@ -13595,7 +14587,7 @@ if(typeof(GL) != "undefined") - // Texture Copy ***************************************** + // Texture Average ***************************************** function LGraphTextureAverage() { this.addInput("Texture","Texture"); @@ -13622,6 +14614,7 @@ if(typeof(GL) != "undefined") this.setOutputData(2,(v[0] + v[1] + v[2]) / 3); } + //executed before rendering the frame LGraphTextureAverage.prototype.onPreRenderExecute = function() { this.updateAverage(); @@ -13657,6 +14650,8 @@ if(typeof(GL) != "undefined") var shader = LGraphTextureAverage._shader; var uniforms = this._uniforms; uniforms.u_mipmap_offset = this.properties.mipmap_offset; + gl.disable( gl.DEPTH_TEST ); + gl.disable( gl.BLEND ); this._temp_texture.drawTo(function(){ tex.toViewport( shader, uniforms ); }); @@ -13674,7 +14669,6 @@ if(typeof(GL) != "undefined") else if(type == GL.HALF_FLOAT || type == GL.HALF_FLOAT_OES) { //no half floats possible, hard to read back unless copyed to a FLOAT texture, so temp_texture is always forced to FLOAT - //vec4.scale( v,v, 1/(255*255) ); //is this correct? } } } @@ -13702,6 +14696,72 @@ if(typeof(GL) != "undefined") LiteGraph.registerNodeType("texture/average", LGraphTextureAverage ); + + + function LGraphTextureTemporalSmooth() + { + this.addInput("in","Texture"); + this.addInput("factor","Number"); + this.addOutput("out","Texture"); + this.properties = { factor: 0.5 }; + this._uniforms = { u_texture: 0, u_textureB: 1, u_factor: this.properties.factor }; + } + + LGraphTextureTemporalSmooth.title = "Smooth"; + LGraphTextureTemporalSmooth.desc = "Smooth texture over time"; + + LGraphTextureTemporalSmooth.prototype.onExecute = function() + { + var tex = this.getInputData(0); + if(!tex || !this.isOutputConnected(0)) + return; + + if(!LGraphTextureTemporalSmooth._shader) + LGraphTextureTemporalSmooth._shader = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphTextureTemporalSmooth.pixel_shader); + + var temp = this._temp_texture; + if(!temp || temp.type != tex.type || temp.width != tex.width || temp.height != tex.height ) + { + this._temp_texture = new GL.Texture( tex.width, tex.height, { type: tex.type, format: gl.RGBA, filter: gl.NEAREST }); + this._temp_texture2 = new GL.Texture( tex.width, tex.height, { type: tex.type, format: gl.RGBA, filter: gl.NEAREST }); + tex.copyTo( this._temp_texture2 ); + } + + var tempA = this._temp_texture; + var tempB = this._temp_texture2; + + var shader = LGraphTextureTemporalSmooth._shader; + var uniforms = this._uniforms; + uniforms.u_factor = 1.0 - this.getInputOrProperty("factor"); + + gl.disable( gl.BLEND ); + gl.disable( gl.DEPTH_TEST ); + tempA.drawTo(function(){ + tempB.bind(1); + tex.toViewport( shader, uniforms ); + }); + + this.setOutputData(0, tempA ); + + //swap + this._temp_texture = tempB; + this._temp_texture2 = tempA; + } + + LGraphTextureTemporalSmooth.pixel_shader = "precision highp float;\n\ + precision highp float;\n\ + uniform sampler2D u_texture;\n\ + uniform sampler2D u_textureB;\n\ + uniform float u_factor;\n\ + varying vec2 v_coord;\n\ + \n\ + void main() {\n\ + gl_FragColor = mix( texture2D( u_texture, v_coord ), texture2D( u_textureB, v_coord ), u_factor );\n\ + }\n\ + "; + + LiteGraph.registerNodeType("texture/temporal_smooth", LGraphTextureTemporalSmooth ); + // Image To Texture ***************************************** function LGraphImageToTexture() { @@ -13862,7 +14922,7 @@ if(typeof(GL) != "undefined") this.addOutput("B","Texture"); this.addOutput("A","Texture"); - this.properties = {}; + this.properties = { use_luminance: true }; if(!LGraphTextureChannels._shader) LGraphTextureChannels._shader = new GL.Shader( Shader.SCREEN_VERTEX_SHADER, LGraphTextureChannels.pixel_shader ); } @@ -13878,13 +14938,14 @@ if(typeof(GL) != "undefined") if(!this._channels) this._channels = Array(4); + var format = this.properties.use_luminance ? gl.LUMINANCE : gl.RGBA; var connections = 0; for(var i = 0; i < 4; i++) { if(this.isOutputConnected(i)) { - if(!this._channels[i] || this._channels[i].width != texA.width || this._channels[i].height != texA.height || this._channels[i].type != texA.type) - this._channels[i] = new GL.Texture( texA.width, texA.height, { type: texA.type, format: gl.RGBA, filter: gl.LINEAR }); + if(!this._channels[i] || this._channels[i].width != texA.width || this._channels[i].height != texA.height || this._channels[i].type != texA.type || this._channels[i].format != format ) + this._channels[i] = new GL.Texture( texA.width, texA.height, { type: texA.type, format: format, filter: gl.LINEAR }); connections++; } else @@ -13938,40 +14999,55 @@ if(typeof(GL) != "undefined") this.addOutput("Texture","Texture"); - this.properties = {}; - if(!LGraphChannelsTexture._shader) - LGraphChannelsTexture._shader = new GL.Shader( Shader.SCREEN_VERTEX_SHADER, LGraphChannelsTexture.pixel_shader ); + this.properties = { precision: LGraphTexture.DEFAULT, R:1,G:1,B:1,A:1 }; + this._color = vec4.create(); + this._uniforms = { u_textureR:0, u_textureG:1, u_textureB:2, u_textureA:3, u_color: this._color }; } LGraphChannelsTexture.title = "Channels to Texture"; LGraphChannelsTexture.desc = "Split texture channels"; + LGraphChannelsTexture.widgets_info = { + "precision": { widget:"combo", values: LGraphTexture.MODE_VALUES } + }; LGraphChannelsTexture.prototype.onExecute = function() { - var tex = [ this.getInputData(0), - this.getInputData(1), - this.getInputData(2), - this.getInputData(3) ]; - - if(!tex[0] || !tex[1] || !tex[2] || !tex[3]) - return; + var white = LGraphTexture.getWhiteTexture(); + var texR = this.getInputData(0) || white; + var texG = this.getInputData(1) || white; + var texB = this.getInputData(2) || white; + var texA = this.getInputData(3) || white; gl.disable( gl.BLEND ); gl.disable( gl.DEPTH_TEST ); var mesh = Mesh.getScreenQuad(); + if(!LGraphChannelsTexture._shader) + LGraphChannelsTexture._shader = new GL.Shader( Shader.SCREEN_VERTEX_SHADER, LGraphChannelsTexture.pixel_shader ); var shader = LGraphChannelsTexture._shader; - this._tex = LGraphTexture.getTargetTexture( tex[0], this._tex ); + var w = Math.max( texR.width, texG.width, texB.width, texA.width ); + var h = Math.max( texR.height, texG.height, texB.height, texA.height ); + var type = this.properties.precision == LGraphTexture.HIGH ? LGraphTexture.HIGH_PRECISION_FORMAT : gl.UNSIGNED_BYTE; - this._tex.drawTo( function() { - tex[0].bind(0); - tex[1].bind(1); - tex[2].bind(2); - tex[3].bind(3); - shader.uniforms({u_textureR:0, u_textureG:1, u_textureB:2, u_textureA:3 }).draw(mesh); + if( !this._texture || this._texture.width != w || this._texture.height != h || this._texture.type != type ) + this._texture = new GL.Texture(w,h,{ type: type, format: gl.RGBA, filter: gl.LINEAR }); + + var color = this._color; + color[0] = this.properties.R; + color[1] = this.properties.G; + color[2] = this.properties.B; + color[3] = this.properties.A; + var uniforms = this._uniforms; + + this._texture.drawTo( function() { + texR.bind(0); + texG.bind(1); + texB.bind(2); + texA.bind(3); + shader.uniforms( uniforms ).draw(mesh); }); - this.setOutputData(0, this._tex); + this.setOutputData(0, this._texture ); } LGraphChannelsTexture.pixel_shader = "precision highp float;\n\ @@ -13981,9 +15057,10 @@ if(typeof(GL) != "undefined") uniform sampler2D u_textureG;\n\ uniform sampler2D u_textureB;\n\ uniform sampler2D u_textureA;\n\ + uniform vec4 u_color;\n\ \n\ void main() {\n\ - gl_FragColor = vec4( \ + gl_FragColor = u_color * vec4( \ texture2D(u_textureR, v_coord).r,\ texture2D(u_textureG, v_coord).r,\ texture2D(u_textureB, v_coord).r,\ @@ -15292,7 +16369,7 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ function LGraphToneMapping() { this.addInput("in","Texture"); - this.addInput("avg","number"); + this.addInput("avg","number,Texture"); this.addOutput("out","Texture"); this.properties = { enabled: true, scale:1, gamma: 1, average_lum: 1, lum_white: 1, precision: LGraphTexture.LOW }; @@ -15336,19 +16413,31 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ if(!temp || temp.width != tex.width || temp.height != tex.height || temp.type != tex.type ) temp = this._temp_texture = new GL.Texture( tex.width, tex.height, { type: tex.type, format: gl.RGBA, filter: gl.LINEAR }); - //apply shader - var shader = LGraphToneMapping._shader; - if(!shader) - shader = LGraphToneMapping._shader = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphToneMapping.pixel_shader ); - var avg = this.getInputData(1); - if(avg != null) - this.properties.average_lum = avg; + if(avg == null) + avg = this.properties.average_lum; var uniforms = this._uniforms; + var shader = null; + + if( avg.constructor === Number ) + { + this.properties.average_lum = avg; + uniforms.u_average_lum = this.properties.average_lum; + shader = LGraphToneMapping._shader; + if(!shader) + shader = LGraphToneMapping._shader = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphToneMapping.pixel_shader ); + } + else if( avg.constructor === GL.Texture ) + { + uniforms.u_average_texture = avg.bind(1); + shader = LGraphToneMapping._shader_texture; + if(!shader) + shader = LGraphToneMapping._shader_texture = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphToneMapping.pixel_shader, { AVG_TEXTURE:"" } ); + } + uniforms.u_lumwhite2 = this.properties.lum_white * this.properties.lum_white; uniforms.u_scale = this.properties.scale; - uniforms.u_average_lum = this.properties.average_lum; uniforms.u_igamma = 1/this.properties.gamma; //apply shader @@ -15365,7 +16454,11 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ varying vec2 v_coord;\n\ uniform sampler2D u_texture;\n\ uniform float u_scale;\n\ - uniform float u_average_lum;\n\ + #ifdef AVG_TEXTURE\n\ + uniform sampler2D u_average_texture;\n\ + #else\n\ + uniform float u_average_lum;\n\ + #endif\n\ uniform float u_lumwhite2;\n\ uniform float u_igamma;\n\ vec3 RGB2xyY (vec3 rgb)\n\ @@ -15384,9 +16477,16 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ void main() {\n\ vec4 color = texture2D( u_texture, v_coord );\n\ vec3 rgb = color.xyz;\n\ + float average_lum = 0.0;\n\ + #ifdef AVG_TEXTURE\n\ + vec3 pixel = texture2D(u_average_texture,vec2(0.5)).xyz;\n\ + average_lum = (pixel.x + pixel.y + pixel.z) / 3.0;\n\ + #else\n\ + average_lum = u_average_lum;\n\ + #endif\n\ //Ld - this part of the code is the same for both versions\n\ float lum = dot(rgb, vec3(0.2126, 0.7152, 0.0722));\n\ - float L = (u_scale / u_average_lum) * lum;\n\ + float L = (u_scale / average_lum) * lum;\n\ float Ld = (L * (1.0 + L / u_lumwhite2)) / (1.0 + L);\n\ //first\n\ //vec3 xyY = RGB2xyY(rgb);\n\ @@ -15407,6 +16507,7 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ this.addOutput("out","Texture"); this.properties = { width: 512, height: 512, seed:0, persistence: 0.1, octaves: 8, scale: 1, offset: [0,0], amplitude: 1, precision: LGraphTexture.DEFAULT }; this._key = 0; + this._texture = null; this._uniforms = { u_persistence: 0.1, u_seed: 0, u_offset: vec2.create(), u_scale: 1, u_viewport: vec2.create() }; } @@ -15420,6 +16521,11 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ octaves: { type: "Number", precision: 0, step: 1, min: 1, max: 50 } }; + LGraphTexturePerlin.prototype.onGetInputs = function() + { + return [["seed","Number"],["persistence","Number"],["octaves","Number"],["scale","Number"],["amplitude","Number"],["offset","vec2"]]; + } + LGraphTexturePerlin.prototype.onExecute = function() { if(!this.isOutputConnected(0)) @@ -15431,12 +16537,19 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ if(h == 0) h = gl.viewport_data[3]; //0 means default var type = LGraphTexture.getTextureType( this.properties.precision ); - var temp = this._temp_texture; + var temp = this._texture; if(!temp || temp.width != w || temp.height != h || temp.type != type ) - temp = this._temp_texture = new GL.Texture( w, h, { type: type, format: gl.RGB, filter: gl.LINEAR }); + temp = this._texture = new GL.Texture( w, h, { type: type, format: gl.RGB, filter: gl.LINEAR }); - //reusing old - var key = w + h + type + this.properties.persistence + this.properties.octaves + this.properties.scale + this.properties.seed + this.properties.offset[0] + this.properties.offset[1] + this.properties.amplitude; + var persistence = this.getInputOrProperty("persistence"); + var octaves = this.getInputOrProperty("octaves"); + var offset = this.getInputOrProperty("offset"); + var scale = this.getInputOrProperty("scale"); + var amplitude = this.getInputOrProperty("amplitude"); + var seed = this.getInputOrProperty("seed"); + + //reusing old texture + var key = "" + w + h + type + persistence + octaves + scale + seed + offset[0] + offset[1] + amplitude; if(key == this._key) { this.setOutputData( 0, temp ); @@ -15446,15 +16559,14 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ //gather uniforms var uniforms = this._uniforms; - uniforms.u_persistence = this.properties.persistence; - uniforms.u_octaves = this.properties.octaves; - uniforms.u_offset[0] = this.properties.offset[0]; - uniforms.u_offset[1] = this.properties.offset[1]; - uniforms.u_scale = this.properties.scale; - uniforms.u_amplitude = this.properties.amplitude; + uniforms.u_persistence = persistence; + uniforms.u_octaves = octaves; + uniforms.u_offset.set( offset ); + uniforms.u_scale = scale; + uniforms.u_amplitude = amplitude; + uniforms.u_seed = seed * 128; uniforms.u_viewport[0] = w; uniforms.u_viewport[1] = h; - uniforms.u_seed = this.properties.seed * 128; //render var shader = LGraphTexturePerlin._shader; @@ -17067,6 +18179,12 @@ LGMIDIShow.title = "MIDI Show"; LGMIDIShow.desc = "Shows MIDI in the graph"; LGMIDIShow.color = MIDI_COLOR; +LGMIDIShow.prototype.getTitle = function() +{ + if(this.flags.collapsed) + return this._str; + return this.title; +} LGMIDIShow.prototype.onAction = function(event, midi_event ) { @@ -17080,7 +18198,7 @@ LGMIDIShow.prototype.onAction = function(event, midi_event ) LGMIDIShow.prototype.onDrawForeground = function( ctx ) { - if( !this._str ) + if( !this._str || this.flags.collapsed ) return; ctx.font = "30px Arial"; @@ -17196,6 +18314,7 @@ function LGMIDIEvent() this.addOutput( "on_midi", LiteGraph.EVENT ); this.midi_event = new MIDIEvent(); + this.gate = false; } LGMIDIEvent.title = "MIDIEvent"; @@ -17210,6 +18329,10 @@ LGMIDIEvent.prototype.onAction = function( event, midi_event ) this.properties.cmd = midi_event.cmd; this.properties.value1 = midi_event.data[1]; this.properties.value2 = midi_event.data[2]; + if( midi_event.cmd == MIDIEvent.NOTEON ) + this.gate = true; + else if( midi_event.cmd == MIDIEvent.NOTEOFF ) + this.gate = false; return; } @@ -17273,6 +18396,7 @@ LGMIDIEvent.prototype.onExecute = function() case "velocity": v = props.cmd == MIDIEvent.NOTEON ? props.value2 : null; break; case "pitch": v = props.cmd == MIDIEvent.NOTEON ? MIDIEvent.computePitch( props.value1 ) : null; break; case "pitchbend": v = props.cmd == MIDIEvent.PITCHBEND ? MIDIEvent.computePitchBend( props.value1, props.value2 ) : null; break; + case "gate": v = this.gate; break; default: continue; } @@ -17302,6 +18426,7 @@ LGMIDIEvent.prototype.onGetOutputs = function() { ["cc","number"], ["cc_value","number"], ["pitch","number"], + ["gate","bool"], ["pitchbend","number"] ]; } @@ -17637,7 +18762,7 @@ LGMIDIKeys.keys = [ {x:5.75,w:0.5,h:0.6,t:1}, {x:6,w:1,h:1,t:0}]; -LGMIDIKeys.prototype.onDrawBackground = function(ctx) +LGMIDIKeys.prototype.onDrawForeground = function(ctx) { if(this.flags.collapsed) return; @@ -17647,6 +18772,8 @@ LGMIDIKeys.prototype.onDrawBackground = function(ctx) var key_width = this.size[0] / (this.properties.num_octaves * 7); var key_height = this.size[1]; + ctx.globalAlpha = 1; + for(var k = 0; k < 2; k++) //draw first whites (0) then blacks (1) for(var i = 0; i < num_keys; ++i) { @@ -18742,6 +19869,67 @@ LGAudioMixer.desc = "Audio mixer"; LiteGraph.registerNodeType("audio/mixer", LGAudioMixer); +function LGAudioADSR() +{ + //default + this.properties = { + A: 0.1, + D: 0.1, + S: 0.1, + R: 0.1 + }; + + this.audionode = LGAudio.getAudioContext().createGain(); + this.audionode.gain.value = 0; + this.addInput("in","audio"); + this.addInput("gate","bool"); + this.addOutput("out","audio"); + this.gate = false; +} + +LGAudioADSR.prototype.onExecute = function() +{ + var audioContext = LGAudio.getAudioContext(); + var now = audioContext.currentTime; + var node = this.audionode; + var gain = node.gain; + var current_gate = this.getInputData(1); + + var A = this.getInputOrProperty("A"); + var D = this.getInputOrProperty("D"); + var S = this.getInputOrProperty("S"); + var R = this.getInputOrProperty("R"); + + if( !this.gate && current_gate ) + { + gain.cancelScheduledValues(0); + gain.setValueAtTime( 0, now ); + gain.linearRampToValueAtTime(1, now + A ); + gain.linearRampToValueAtTime(S, now + A + D ); + } + else if( this.gate && !current_gate ) + { + gain.cancelScheduledValues( 0 ); + gain.setValueAtTime( gain.value, now ); + gain.linearRampToValueAtTime( 0, now + R ); + } + + this.gate = current_gate; +} + +LGAudioADSR.prototype.onGetInputs = function() +{ + return [["A","number"],["D","number"],["S","number"],["R","number"]]; +} + + +LGAudio.createAudioNodeWrapper( LGAudioADSR ); + +LGAudioADSR.title = "ADSR"; +LGAudioADSR.desc = "Audio envelope"; +LiteGraph.registerNodeType("audio/adsr", LGAudioADSR); + + function LGAudioDelay() { //default @@ -18840,7 +20028,13 @@ LGAudioOscillatorNode.prototype.onStart = function() if(!this.audionode.started) { this.audionode.started = true; - this.audionode.start(); + try + { + this.audionode.start(); + } + catch (err) + { + } } } @@ -19202,13 +20396,13 @@ LGWebSocket.desc = "Send data through a websocket"; LGWebSocket.prototype.onPropertyChanged = function(name,value) { if(name == "url") - this.createSocket(); + this.connectSocket(); } LGWebSocket.prototype.onExecute = function() { if(!this._ws && this.properties.url) - this.createSocket(); + this.connectSocket(); if(!this._ws || this._ws.readyState != WebSocket.OPEN ) return; @@ -19244,7 +20438,7 @@ LGWebSocket.prototype.onExecute = function() this.boxcolor = "#6C6"; } -LGWebSocket.prototype.createSocket = function() +LGWebSocket.prototype.connectSocket = function() { var that = this; var url = this.properties.url; @@ -19327,7 +20521,10 @@ LiteGraph.registerNodeType("network/websocket", LGWebSocket ); function LGSillyClient() { - this.size = [60,20]; + //this.size = [60,20]; + this.room_widget = this.addWidget("text","Room","lgraph",this.setRoom.bind(this)); + this.addWidget("button","Reconnect",null,this.connectSocket.bind(this)); + this.addInput("send", LiteGraph.ACTION); this.addOutput("received", LiteGraph.EVENT); this.addInput("in", 0 ); @@ -19339,9 +20536,10 @@ function LGSillyClient() }; this._server = null; - this.createSocket(); + this.connectSocket(); this._last_sent_data = []; this._last_received_data = []; + } LGSillyClient.title = "SillyClient"; @@ -19349,11 +20547,30 @@ LGSillyClient.desc = "Connects to SillyServer to broadcast messages"; LGSillyClient.prototype.onPropertyChanged = function(name,value) { - var final_url = (this.properties.url + "/" + this.properties.room); - if(this._server && this._final_url != final_url ) + if(name == "room") + this.room_widget.value = value; + this.connectSocket(); +} + +LGSillyClient.prototype.setRoom = function(room_name) +{ + this.properties.room = room_name; + this.room_widget.value = room_name; + this.connectSocket(); +} + +//force label names +LGSillyClient.prototype.onDrawForeground = function() +{ + for(var i = 1; i < this.inputs.length; ++i) { - this._server.connect( this.properties.url, this.properties.room ); - this._final_url = final_url; + var slot = this.inputs[i]; + slot.label = "in_" + i; + } + for(var i = 1; i < this.outputs.length; ++i) + { + var slot = this.outputs[i]; + slot.label = "out_" + i; } } @@ -19383,7 +20600,7 @@ LGSillyClient.prototype.onExecute = function() this.boxcolor = "#6C6"; } -LGSillyClient.prototype.createSocket = function() +LGSillyClient.prototype.connectSocket = function() { var that = this; if(typeof(SillyClient) == "undefined") @@ -19412,7 +20629,7 @@ LGSillyClient.prototype.createSocket = function() return; } - if(data.type == 1) + if(data.type == 1) //EVENT slot { if(data.data.object_class && LiteGraph[data.data.object_class] ) { @@ -19430,7 +20647,7 @@ LGSillyClient.prototype.createSocket = function() else that.triggerSlot( 0, data.data ); } - else + else //for FLOW slots that._last_received_data[ data.channel || 0 ] = data.data; that.boxcolor = "#AFA"; } @@ -19447,7 +20664,16 @@ LGSillyClient.prototype.createSocket = function() if(this.properties.url && this.properties.room) { - this._server.connect( this.properties.url, this.properties.room ); + try + { + this._server.connect( this.properties.url, this.properties.room ); + } + catch (err) + { + console.error("SillyServer error: " + err ); + this._server = null; + return; + } this._final_url = (this.properties.url + "/" + this.properties.room); } } diff --git a/build/litegraph.min.js b/build/litegraph.min.js index d3b810c59..e64ef877c 100755 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -1,551 +1,586 @@ -(function(w){function c(a){h.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function k(a,b,d,f,e,m){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=f;this.target_id=e;this.target_slot=m;this._data=null;this._pos=new Float32Array(2)}function r(a){this._ctor(a)}function q(a){this._ctor(a)}function g(a,b,d){d=d||{};this.background_image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; -a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.min_zoom=0.1;this.zoom_modify_alpha=!0;this.title_text_font="bold "+h.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+h.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=h.NODE_TITLE_COLOR;this.default_link_color=h.LINK_COLOR;this.default_connection_color={input_off:"#AAB",input_on:"#7F7",output_off:"#AAB",output_on:"#7F7"};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering= -!1;this.render_only_selected=this.clear_background=this.render_shadows=!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=!0;this.render_connections_shadows=!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.render_execution_order= -!1;this.canvas_mouse=[0,0];this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=new Float32Array(4);this.visible_links=[];b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();this.autoresize=d.autoresize}function t(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,f,e,m){return da&&fb?!0:!1}function y(a,b){var d=a[0]+a[2],f=a[1]+a[3],e=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>e||dh.width-c.width-10&&(m=h.width-c.width-10);n>h.height-c.height-10&&(n=h.height-c.height-10)}e.style.left=m+"px";e.style.top=n+"px"}var h=w.LiteGraph={CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:20,NODE_SLOT_HEIGHT:15,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:"#444",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,LINK_COLOR:"#AAD",EVENT_LINK_COLOR:"#F85",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,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype"; -b.type=a;h.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,f=a.lastIndexOf("/");b.category=a.substr(0,f);b.title||(b.title=d);if(b.prototype)for(var e in r.prototype)b.prototype[e]||(b.prototype[e]=r.prototype[e]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=h.BOX_SHAPE;break;case "round":this._shape=h.ROUND_SHAPE;break;case "circle":this._shape=h.CIRCLE_SHAPE;break;case "card":this._shape=h.CARD_SHAPE; -break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(e in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[e].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,f){for(var e=Array(b.length), -m="",n=h.getParameterNames(b),c=0;cn&&(n=e.size[0]),h+=e.size[1]+a;b+=n+a}this.setDirtyCanvas(!0,!0)};c.prototype.getTime=function(){return this.globaltime};c.prototype.getFixedTime=function(){return this.fixedtime};c.prototype.getElapsedTime=function(){return this.elapsed_time};c.prototype.sendEventToAllNodes=function(a,b,d){d=d||h.ALWAYS;var f=this._nodes_in_order?this._nodes_in_order:this._nodes; -if(f)for(var e=0,m=f.length;e=h.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_ida.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};r.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]=h.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d=this.inputs.length||null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;var f=this.graph.getNodeById(d.origin_id);if(!f)return d.data;if(f.updateOutputData)f.updateOutputData(d.origin_slot); -else if(f.onExecute)f.onExecute();return d.data}};r.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};r.prototype.isInputConnected=function(a){return this.inputs?a=this.inputs.length)return null;a=this.inputs[a];return a&&null!== -a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};r.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};r.prototype.getOutputInfo= -function(a){return this.outputs?a=this.outputs.length)return null; -a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],d=0;da&&this.pos[1]-e-db)return!0;return!1};r.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var f=0,e=this.inputs.length;f=this.outputs.length)return h.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 h.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d=== -h.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&&b.disconnectInput(d);var f=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,f.type,f))return null;var e=b.inputs[d],m=null;if(h.isValidConnection(f.type,e.type)){m=new k(this.graph.last_link_id++,e.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==f.links&&(f.links=[]);f.links.push(m.id);b.inputs[d].link=m.id;this.graph&&this.graph._version++; -if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!0,m,f);if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,d,!0,m,e);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(h.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this,m);return m};r.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+ -a),!1}else if(!this.outputs||a>=this.outputs.length)return h.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 f=0,e=d.links.length;f=this.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var f=this.graph.links[d];if(f){var e= -this.graph.getNodeById(f.origin_id);if(!e)return!1;var m=e.outputs[f.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var n=0,c=m.links.length;nb&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&f>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/f*(b+0.5),d[1]=a?this.pos[1]-h.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]:this.pos[0]+this.size[0]+ -1;d[1]=this.pos[1]+10+b*h.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};r.prototype.alignToGrid=function(){this.pos[0]=h.CANVAS_GRID_SIZE*Math.round(this.pos[0]/h.CANVAS_GRID_SIZE);this.pos[1]=h.CANVAS_GRID_SIZE*Math.round(this.pos[1]/h.CANVAS_GRID_SIZE)};r.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>r.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};r.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty", -[a,b])};r.prototype.loadImage=function(a){var b=new Image;b.src=h.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};r.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;da.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};q.prototype.configure=function(a){this.title=a.title; -this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};q.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}};q.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d element, you passed a "+a.localName;throw"This browser doesnt support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};g.prototype._doNothing=function(a){a.preventDefault(); -return!1};g.prototype._doReturnTrue=function(a){a.preventDefault();return!0};g.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel", -this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback, -!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};g.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback); -this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler); -this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};g.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};g.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas"; -if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};g.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};g.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};g.prototype.startRendering=function(){function a(){this.pause_rendering|| -this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};g.prototype.stopRendering=function(){this.is_rendering=!1};g.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();g.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup", -this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),f=!1,e=300>h.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();h.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,f=!0);var m= -!1;if(d&&this.allow_interaction&&!f){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!f&&!1!==d.resizable&&u(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor="se-resize",f=!0;else{if(d.outputs)for(var n=0,c=d.outputs.length;nm[0]+4||a.canvasYm[1]+4)){this.showLinkMenu(d,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&(a.ctrlKey&&(this.dragging_rectangle=null),10>t([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());e&&this.showSearchBox(a); -m=!0}!f&&m&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(d,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=h.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}};g.prototype.processMouseMove= -function(a){this.autoresize&&this.resize();if(this.graph){g.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0], -this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(d[0]/this.scale,d[1]/this.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.offset[0]+=d[0]/this.scale,this.offset[1]+=d[1]/this.scale,this.dirty_bgcanvas= -this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,e=this.graph._nodes.length;bthis.dragging_rectangle[3]?this.dragging_rectangle[1]-e:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-f:this.dragging_rectangle[0];this.dragging_rectangle[1]=m;this.dragging_rectangle[2]=f;this.dragging_rectangle[3]=e;e=[];for(m=0;ma.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX- -this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};g.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.scale;0b&&(d*=1/1.1);this.setZoom(d,[a.localX,a.localY]); -this.graph.change();a.preventDefault();return!1}};g.prototype.isOverNodeBox=function(a,b,d){var f=h.NODE_TITLE_HEIGHT;return u(b,d,a.pos[0]+2,a.pos[1]+2-f,f-4,f-4)?!0:!1};g.prototype.isOverNodeInput=function(a,b,d,f){if(a.inputs)for(var e=0,m=a.inputs.length;ethis.max_zoom?this.scale=this.max_zoom:this.scaled-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+= -1}};g.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b, -a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d> ";b.fillText(f+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();b.scale(this.scale,this.scale);b.translate(this.offset[0],this.offset[1]);if(this.background_image&&0.5this.scale?b.fillRect(s[0],s[1],s[2],s[3]):c==h.ROUND_SHAPE||c==h.CARD_SHAPE? -b.roundRect(s[0],s[1],s[2],s[3],this.round_radius,c==h.CARD_SHAPE?0:this.round_radius):c==h.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI),b.fill());b.shadowColor="transparent";a.bgImage&&a.bgImage.width&&b.drawImage(a.bgImage,0.5*(d[0]-a.bgImage.width),0.5*(d[1]-a.bgImage.height));a.bgImageUrl&&!a.bgImage&&(a.bgImage=a.loadImage(a.bgImageUrl));if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(p||l==h.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,d,this.scale, -f);else if(l!=h.TRANSPARENT_TITLE){a.flags.collapsed&&(b.shadowColor=h.DEFAULT_SHADOW_COLOR);this.use_gradients?(n=g.gradients[f],n||(n=g.gradients[f]=b.createLinearGradient(0,0,400,0),n.addColorStop(0,f),n.addColorStop(1,"#000")),b.fillStyle=n):b.fillStyle=f;var k=b.globalAlpha;b.beginPath();c==h.BOX_SHAPE||0.5>this.scale?b.rect(0,-e,d[0]+1,e):c!=h.ROUND_SHAPE&&c!=h.CARD_SHAPE||b.roundRect(0,-e,d[0]+1,e,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b, -e,d,this.scale);else c==h.ROUND_SHAPE||c==h.CIRCLE_SHAPE||c==h.CARD_SHAPE?(0.5f[2]&&(f[0]+=f[2],f[2]=Math.abs(f[2]));0>f[3]&&(f[1]+=f[3],f[3]=Math.abs(f[3]));if(y(f,d)){var H=k.outputs[q],q=g.inputs[l];if(H&&q&&(k=H.dir||(k.horizontal?h.DOWN:h.RIGHT),q=q.dir||(g.horizontal?h.UP:h.LEFT),this.renderLink(a,z,G,p,!1,0,null,k,q),p&&p._last_time&&1E3>b-p._last_time)){var H=2-0.002*(b-p._last_time),r=a.globalAlpha;a.globalAlpha=r*H;this.renderLink(a,z,G,p,!0,H,"white",k,q);a.globalAlpha=r}}}}}}a.globalAlpha=1};g.prototype.renderLink= -function(a,b,d,f,e,m,n,c,s){f&&this.visible_links.push(f);if(this.highquality_render){c=c||h.RIGHT;s=s||h.LEFT;var l=t(b,d);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(f[0], -f[1]),a.rotate(q),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(p[0],p[1]),a.rotate(r),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(m)for(a.fillStyle=n,m=0;5>m;++m)n=(0.001*h.getTime()+0.2*m)%1,e=this.computeConnectionPoint(b,d,n,c,s),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(d[0],d[1]),a.stroke(), -f&&f._pos&&(f._pos[0]=0.5*(b[0]+d[0]),f._pos[1]=0.5*(b[1]+d[1]))};g.prototype.computeConnectionPoint=function(a,b,d,f,e){f=f||h.RIGHT;e=e||h.LEFT;var m=t(a,b),n=[a[0],a[1]],c=[b[0],b[1]];switch(f){case h.LEFT:n[0]+=-0.25*m;break;case h.RIGHT:n[0]+=0.25*m;break;case h.UP:n[1]+=-0.25*m;break;case h.DOWN:n[1]+=0.25*m}switch(e){case h.LEFT:c[0]+=-0.25*m;break;case h.RIGHT:c[0]+=0.25*m;break;case h.UP:c[1]+=-0.25*m;break;case h.DOWN:c[1]+=0.25*m}f=(1-d)*(1-d)*(1-d);e=3*(1-d)*(1-d)*d;m=3*(1-d)*d*d;d*=d* -d;return[f*a[0]+e*n[0]+m*c[0]+d*b[0],f*a[1]+e*n[1]+m*c[1]+d*b[1]]};g.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;dp.last_y&&mp.options.max&&(p.value=p.options.max);else if("mousedown"==d.type)if((f=p.options.values)&&f.constructor===Function&&(f=p.options.values(p,a)),e=40>e?-1:e>c-40?1:0,"number"==p.type)p.value+=0.1*e*(p.options.step||1),null!=p.options.min&&p.valuep.options.max&&(p.value=p.options.max);else if(e)d=f.indexOf(p.value)+e,d>=f.length&&(d=0),0>d&&(d=f.length-1),p.value=f[d];else{new h.ContextMenu(f,{event:d,className:"dark",callback:k.bind(p)},s);var k=function(a,d,b){this.value=a;g.dirty_canvas=!0;return!1}}p.callback&&setTimeout(function(){this.callback(this.value,g,a,b)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(p.value=!p.value,p.callback&&setTimeout(function(){p.callback(p.value, -g,a,b)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",p.value,function(d){this.value=d;p.callback&&p.callback(d,g,a)}.bind(p),d);break;default:p.mouse&&p.mouse(ctx,d,[e,m],a)}return p}}return null};g.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var f=0;fd&&0.01>b.editor_alpha&&(clearInterval(f),1>d&&(b.live_mode=!0));1"+p+""+a+"",value:p});if(l.length)return new h.ContextMenu(l,{event:d,callback:m,parentMenu:f,allow_html:!0,node:e},b),!1}};g.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};g.onResizeNode=function(a,b,d,f,e){e&&(e.size=e.computeSize(), -e.setDirtyCanvas(!0,!0))};g.prototype.showLinkMenu=function(a,b){var d=this;new h.ContextMenu(["Delete"],{event:b,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};g.onShowPropertyEditor=function(a,b,d,f,e){function m(){var d=p.value;"Number"==a.type?d=Number(d):"Boolean"==a.type&&(d=Boolean(d));e[c]=d;l.parentNode.removeChild(l);e.setDirtyCanvas(!0,!0)}var c=a.property||"title";b=e[c];var l=document.createElement("div");l.className="graphdialog";l.innerHTML=""; -l.querySelector(".name").innerText=c;var p=l.querySelector("input");p&&(p.value=b,p.addEventListener("blur",function(a){this.focus()}),p.addEventListener("keydown",function(a){13==a.keyCode&&(m(),a.preventDefault(),a.stopPropagation())}));b=g.active_canvas.canvas;d=b.getBoundingClientRect();var h=f=-20;d&&(f-=d.left,h-=d.top);event?(l.style.left=event.pageX+f+"px",l.style.top=event.pageY+h+"px"):(l.style.left=0.5*b.width+f+"px",l.style.top=0.5*b.height+h+"px");l.querySelector("button").addEventListener("click", -m);b.parentNode.appendChild(l)};g.prototype.prompt=function(a,b,d,f){var e=this;a=a||"";var m=document.createElement("div");m.className="graphdialog rounded";m.innerHTML=" ";m.close=function(){e.prompt_box=null;m.parentNode.removeChild(m)};m.addEventListener("mouseleave",function(a){m.close()});e.prompt_box&&e.prompt_box.close();e.prompt_box=m;m.querySelector(".name").innerText=a;m.querySelector(".value").value= -b;var c=m.querySelector("input");c.addEventListener("keydown",function(a){if(27==a.keyCode)m.close();else if(13==a.keyCode)d&&d(this.value),m.close();else return;a.preventDefault();a.stopPropagation()});m.querySelector("button").addEventListener("click",function(a){d&&d(c.value);e.setDirty(!0);m.close()});a=g.active_canvas.canvas;b=a.getBoundingClientRect();var l=-20,p=-20;b&&(l-=b.left,p-=b.top);f?(m.style.left=f.pageX+l+"px",m.style.top=f.pageY+p+"px"):(m.style.left=0.5*a.width+l+"px",m.style.top= -0.5*a.height+p+"px");a.parentNode.appendChild(m);setTimeout(function(){c.focus()},10);return m};g.search_limit=-1;g.prototype.showSearchBox=function(a){function b(d){if(d)if(e.onSearchBoxSelection)e.onSearchBoxSelection(d,a,q);else{var b=h.searchbox_extras[d];b&&(d=b.type);if(d=h.createNode(d))d.pos=q.convertEventToCanvas(a),q.graph.add(d);if(b&&b.data){if(b.data.properties)for(var f in b.data.properties)d.addProperty(b.data.properties[f][0],b.data.properties[f][0]);if(b.data.inputs)for(f in d.inputs= -[],b.data.inputs)d.addOutput(b.data.inputs[f][0],b.data.inputs[f][1]);if(b.data.outputs)for(f in d.outputs=[],b.data.outputs)d.addOutput(b.data.outputs[f][0],b.data.outputs[f][1]);b.data.title&&(d.title=b.data.title);b.data.json&&d.configure(b.data.json)}}c.close()}function d(a){var d=s;s&&s.classList.remove("selected");s?(s=a?s.nextSibling:s.previousSibling)||(s=d):s=a?n.childNodes[0]:n.childNodes[n.childNodes.length];s&&(s.classList.add("selected"),s.scrollIntoView())}function f(){function a(d, -e){var f=document.createElement("div");l||(l=d);f.innerText=d;f.dataset.type=escape(d);f.className="litegraph lite-search-item";e&&(f.className+=" "+e);f.addEventListener("click",function(a){b(unescape(this.dataset.type))});n.appendChild(f)}p=null;var d=k.value;l=null;n.innerHTML="";if(d)if(e.onSearchBox){var f=e.onSearchBox(help,d,q);if(f)for(var z=0;zg.search_limit))break}if(Array.prototype.filter)for(c=Object.keys(h.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(d)}),z=0;zg.search_limit);z++);else for(z in h.registered_node_types)if(-1!=z.indexOf(d)&&(a(z),-1!==g.search_limit&&f++>g.search_limit))break}}var e=this,c=document.createElement("div");c.className="litegraph litesearchbox graphdialog rounded";c.innerHTML= -"Search
";c.close=function(){e.search_box=null;setTimeout(function(){e.canvas.focus()},10);c.parentNode.removeChild(c)};c.addEventListener("mouseleave",function(a){c.close()});e.search_box&&e.search_box.close();e.search_box=c;var n=c.querySelector(".helper"),l=null,p=null,s=null,k=c.querySelector("input");k&&(k.addEventListener("blur",function(a){this.focus()}),k.addEventListener("keydown",function(a){if(38== -a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)c.close();else if(13==a.keyCode)s?b(s.innerHTML):l?b(l):c.close();else{p&&clearInterval(p);p=setTimeout(f,10);return}a.preventDefault();a.stopPropagation()}));var q=g.active_canvas,r=q.canvas,t=r.getBoundingClientRect(),z=-20,G=-20;t&&(z-=t.left,G-=t.top);a?(c.style.left=a.pageX+z+"px",c.style.top=a.pageY+G+"px"):(c.style.left=0.5*r.width+z+"px",c.style.top=0.5*r.height+G+"px");r.parentNode.appendChild(c);k.focus();return c};g.prototype.showEditPropertyValue= -function(a,b,d){function f(){e(k.value)}function e(d){"number"==typeof a.properties[b]&&(d=Number(d));"array"==c&&(d=d.split(",").map(Number));a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);h.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var c="string";null!==a.properties[b]&&(c=typeof a.properties[b]);"object"==c&&a.properties[b].length&&(c="array");var l=null;a.getPropertyInfo&&(l=a.getPropertyInfo(b));if(a.properties_info)for(var p= -0;p";else if("enum"==c&&l.values){g=""}else if("boolean"== -c)g="";else{console.warn("unknown type: "+c);return}var h=this.createDialog(""+b+""+g+"",d);if("enum"==c&&l.values){var k=h.querySelector("select");k.addEventListener("change",function(a){e(a.target.value)})}else if("boolean"==c)(k=h.querySelector("input"))&&k.addEventListener("click",function(a){e(!!k.checked)});else if(k=h.querySelector("input"))k.addEventListener("blur", -function(a){this.focus()}),k.value=void 0!==a.properties[b]?a.properties[b]:"",k.addEventListener("keydown",function(a){13==a.keyCode&&(f(),a.preventDefault(),a.stopPropagation())});h.querySelector("button").addEventListener("click",f)}};g.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var f=this.canvas.getBoundingClientRect(),e=-20,c=-20;f&&(e-=f.left,c-=f.top);b.position?(e+=b.position[0],c+=b.position[1]):b.event?(e+=b.event.pageX, -c+=b.event.pageY):(e+=0.5*this.canvas.width,c+=0.5*this.canvas.height);d.style.left=e+"px";d.style.top=c+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};g.onMenuNodeCollapse=function(a,b,d,f,e){e.collapse()};g.onMenuNodePin=function(a,b,d,f,e){e.pin()};g.onMenuNodeMode=function(a,b,d,f,e){new h.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(e)switch(a){case "On Event":e.mode=h.ON_EVENT; -break;case "On Trigger":e.mode=h.ON_TRIGGER;break;case "Never":e.mode=h.NEVER;break;default:e.mode=h.ALWAYS}},parentMenu:f,node:e});return!1};g.onMenuNodeColors=function(a,b,d,f,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var c in g.node_colors)a=g.node_colors[c],a={value:c,content:""+c+""},b.push(a);new h.ContextMenu(b,{event:d,callback:function(a){e&&((a=a.value?g.node_colors[a.value]:null)?e.constructor===h.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:f,node:e});return!1};g.onMenuNodeShapes=function(a,b,d,f,e){if(!e)throw"no node passed";new h.ContextMenu(h.VALID_SHAPES,{event:d,callback:function(a){e&&(e.shape=a,e.setDirtyCanvas(!0))},parentMenu:f,node:e});return!1}; -g.onMenuNodeRemove=function(a,b,d,f,e){if(!e)throw"no node passed";!1!==e.removable&&(e.graph.remove(e),e.setDirtyCanvas(!0,!0))};g.onMenuNodeClone=function(a,b,d,f,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))};g.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"}};g.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:g.onMenuAdd},{content:"Add Group",callback:g.onGroupAdd}],this._graph_stack&& -0Name",e),m=l.querySelector("input");m&&c&&(m.value=c.label);l.querySelector("button").addEventListener("click",function(a){m.value&&(c&&(c.label=m.value),d.setDirty(!0));l.close()})}},extra:a},l=null;a&&(l=a.getSlotInPosition(b.canvasX,b.canvasY),g.active_node=a);l?(e=[],l&&l.output&& -l.output.links&&l.output.links.length&&e.push({content:"Disconnect Links",slot:l}),e.push(l.locked?"Cannot remove":{content:"Remove Slot",slot:l}),e.push(l.nameLocked?"Cannot rename":{content:"Rename Slot",slot:l}),c.title=(l.input?l.input.type:l.output.type)||"*",l.input&&l.input.type==h.ACTION&&(c.title="Action"),l.output&&l.output.type==h.EVENT&&(c.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(l=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group", -has_submenu:!0,submenu:{title:"Group",extra:l,options:this.getGroupMenuOptions(l)}}));e&&new h.ContextMenu(e,c,f)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,f,e,c){void 0===e&&(e=5);void 0===c&&(c=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+f-c);this.quadraticCurveTo(a+d,b+f,a+d-c,b+f);this.lineTo(a+c,b+f);this.quadraticCurveTo(a,b+f,a,b+f-c);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)}); -h.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};h.distance=t;h.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};h.isInsideRectangle=u;h.growBounding=function(a,b,d){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};h.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};h.overlapBounding= -y;h.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,f,e,c=0;6>c;c+=2)f="0123456789ABCDEF".indexOf(a.charAt(c)),e="0123456789ABCDEF".indexOf(a.charAt(c+1)),b[d]=16*f+e,d++;return b};h.num2hex=function(a){for(var b="#",d,f,e=0;3>e;e++)d=a[e]/16,f=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(f);return b};v.prototype.addItem=function(a,b,d){function f(a){var d=this.value;d&&d.has_submenu&&e.call(this,a)}function e(a){var b=this.value, -e=!0;c.current_submenu&&c.current_submenu.close(a);if(d.callback){var f=d.callback.call(this,b,d,a,c,d.node);!0===f&&(e=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(f=b.callback.call(this,b,d,a,c,d.extra),!0===f&&(e=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new c.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:c,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra, -autoopen:d.autoopen});e=!1}e&&!c.lock&&c.close()}var c=this;d=d||{};var l=document.createElement("div");l.className="litemenu-entry submenu";var p=!1;if(null===b)l.classList.add("separator");else{l.innerHTML=b&&b.title?b.title:a;if(l.value=b)b.disabled&&(p=!0,l.classList.add("disabled")),(b.submenu||b.has_submenu)&&l.classList.add("has_submenu");"function"==typeof b?(l.dataset.value=a,l.onclick_callback=b):l.dataset.value=b;b.className&&(l.className+=" "+b.className)}this.root.appendChild(l);p||l.addEventListener("click", -e);d.autoopen&&l.addEventListener("mouseenter",f);return l};v.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!v.isCursorOverElement(a,this.parentMenu.root)&&v.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};v.trigger= -function(a,b,d,f){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,d);e.srcElement=f;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};v.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};v.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};v.isCursorOverElement=function(a,b){var d=a.pageX,f=a.pageY,e=b.getBoundingClientRect(); -return e?f>e.top&&fe.left&&da?b:dthis.size[0]-l.NODE_TITLE_HEIGHT&&0>g[1]){var b=this;setTimeout(function(){a.openSubgraph(b.subgraph)},10)}};k.prototype.onSubgraphNewGlobalInput=function(c,l){this.addInput(c,l)};k.prototype.onSubgraphRenamedGlobalInput=function(c,l){var a=this.findInputSlot(c);-1!=a&&(this.getInputInfo(a).name=l)};k.prototype.onSubgraphTypeChangeGlobalInput=function(c, -l){var a=this.findInputSlot(c);-1!=a&&(this.getInputInfo(a).type=l)};k.prototype.onSubgraphNewGlobalOutput=function(c,l){this.addOutput(c,l)};k.prototype.onSubgraphRenamedGlobalOutput=function(c,l){var a=this.findOutputSlot(c);-1!=a&&(this.getOutputInfo(a).name=l)};k.prototype.onSubgraphTypeChangeGlobalOutput=function(c,l){var a=this.findOutputSlot(c);-1!=a&&(this.getOutputInfo(a).type=l)};k.prototype.getExtraMenuOptions=function(c){var l=this;return[{content:"Open",callback:function(){c.openSubgraph(l.subgraph)}}]}; -k.prototype.onResize=function(c){c[1]+=20};k.prototype.onExecute=function(){if(this.inputs)for(var c=0;cg[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};r.prototype.onMouseMove=function(c){if(this.mouse_captured){var g=this.old_y-c.canvasY;c.shiftKey&&(g*=10);if(c.metaKey||c.altKey)g*=0.1;this.old_y=c.canvasY;c=this._remainder+g/r.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)}};r.prototype.onMouseUp=function(c,g){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(g[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.graph._version++,this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};h.registerNodeType("widget/number",r);q.title="Knob";q.desc="Circular controller";q.widgets=[{name:"increase",text:"+",type:"minibutton"},{name:"decrease",text:"-", -type:"minibutton"}];q.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};q.prototype.onDrawImageKnob=function(c){if(this.imgfg&&this.imgfg.width){var g=0.5*this.imgbg.width,h=this.size[0]/this.imgfg.width;c.save();c.translate(0,20);c.scale(h,h);c.drawImage(this.imgbg,0,0);c.translate(g,g);c.rotate(2*this.value*Math.PI*6/8+10*Math.PI/ -8);c.translate(-g,-g);c.drawImage(this.imgfg,0,0);c.restore();this.title&&(c.font="bold 16px Criticized,Tahoma",c.fillStyle="rgba(100,100,100,0.8)",c.textAlign="center",c.fillText(this.title.toUpperCase(),0.5*this.size[0],18),c.textAlign="left")}};q.prototype.onDrawVectorKnob=function(c){if(this.imgfg&&this.imgfg.width){c.lineWidth=1;c.strokeStyle=this.mouseOver?"#FFF":"#AAA";c.fillStyle="#000";c.beginPath();c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.5*this.properties.size,0,2*Math.PI,!0);c.stroke(); -0c.canvasY-this.pos[1]||h.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}};q.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var g=this.value,g=g-0.01*(c[1]-this.oldmouse[1]);1g&&(g=0);this.value=g;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};q.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};q.prototype.onMouseLeave=function(c){};q.prototype.onPropertyChanged=function(c, -g){if("wcolor"==c)this.properties[c]=g;else if("size"==c)g=parseInt(g),this.properties[c]=g,this.size=[g+4,g+24],this.setDirtyCanvas(!0,!0);else if("min"==c||"max"==c||"value"==c)this.properties[c]=parseFloat(g);else return!1;return!0};h.registerNodeType("widget/knob",q);g.title="Internal Slider";g.prototype.onPropertyChanged=function(c,g){"value"==c&&(this.slider.value=g)};g.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};h.registerNodeType("widget/internal_slider",g); -t.title="H.Slider";t.desc="Linear slider controller";t.prototype.onAdded=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};t.prototype.onDrawVectorial=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.strokeStyle=this.mouseOver?"#FFF":"#AAA",c.fillStyle="#000",c.beginPath(),c.rect(2,0,this.size[0]-4,20),c.stroke(),c.fillStyle=this.properties.wcolor,c.beginPath(),c.rect(2+(this.size[0]-4-20)*this.value,0,20,20),c.fill())};t.prototype.onDrawImage=function(c){this.imgfg&& -this.imgfg.width&&(c.lineWidth=1,c.fillStyle="#000",c.fillRect(2,9,this.size[0]-4,2),c.strokeStyle="#333",c.beginPath(),c.moveTo(2,9),c.lineTo(this.size[0]-4,9),c.stroke(),c.strokeStyle="#AAA",c.beginPath(),c.moveTo(2,11),c.lineTo(this.size[0]-4,11),c.stroke(),c.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};t.prototype.onDrawForeground=function(c){this.onDrawImage(c)};t.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=h.colorToString([this.value,this.value,this.value])};t.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};t.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var g=this.value,g=g+(c[0]-this.oldmouse[0])/this.size[0];1g&& -(g=0);this.value=g;this.oldmouse=c;this.setDirtyCanvas(!0)}};t.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};t.prototype.onMouseLeave=function(c){};t.prototype.onPropertyChanged=function(c,g){if("wcolor"==c)this.properties[c]=g;else return!1;return!0};h.registerNodeType("widget/hslider",t);u.title="Progress";u.desc="Shows data in linear progress";u.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};u.prototype.onDrawForeground= -function(c){c.lineWidth=1;c.fillStyle=this.properties.wcolor;var g=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),g=Math.min(1,g),g=Math.max(0,g);c.fillRect(2,2,(this.size[0]-4)*g,this.size[1]-4)};h.registerNodeType("widget/progress",u);y.title="Text";y.desc="Shows the input value";y.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];y.prototype.onDrawForeground= -function(c){c.fillStyle=this.properties.color;var g=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var h=this.properties.fontsize;c.textAlign=this.properties.align;c.font=h.toString()+"px "+this.properties.font;this.str="number"==typeof g?g.toFixed(this.properties.decimals):g;if("string"==typeof this.str){var g=this.str.split("\\n"),a;for(a in g)c.fillText(g[a], -"left"==this.properties.align?15:this.size[0]-15,-0.15*h+h*(parseInt(a)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};y.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};y.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var g=0,h;for(h in c){var a=this.last_ctx.measureText(c[h]).width;gq?k.xbox.axes.lx:0,this._left_axis[1]=Math.abs(k.xbox.axes.ly)>q?k.xbox.axes.ly:0,this._right_axis[0]=Math.abs(k.xbox.axes.rx)>q?k.xbox.axes.rx:0,this._right_axis[1]=Math.abs(k.xbox.axes.ry)>q?k.xbox.axes.ry:0,this._triggers[0]=Math.abs(k.xbox.axes.ltrigger)>q?k.xbox.axes.ltrigger: -0,this._triggers[1]=Math.abs(k.xbox.axes.rtrigger)>q?k.xbox.axes.rtrigger:0);if(this.outputs)for(q=0;qk;k++)if(q[k]){k=q[k];q=this.xbox_mapping;q||(q=this.xbox_mapping={axes:[],buttons:{},hat:"",hatmap:c.CENTER});q.axes.lx=k.axes[0];q.axes.ly=k.axes[1];q.axes.rx=k.axes[2];q.axes.ry=k.axes[3];q.axes.ltrigger=k.buttons[6].value; -q.axes.rtrigger=k.buttons[7].value;q.hat="";q.hatmap=c.CENTER;for(var g=0;ga&&rb?!0:!1}function z(a,b){var e=a[0]+a[2],r=a[1]+a[3],h=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>h||ek.width-d.width-10&&(c=k.width-d.width-10);f>k.height-d.height-10&&(f=k.height-d.height-10)}h.style.left=c+"px";h.style.top=f+"px";b.scale&&(h.style.transform="scale("+b.scale+")")}var c=u.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10, +NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3, +DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{}, +Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;c.debug&&console.log("Node registered: "+a);a.split("/");var e=b.name,r=a.lastIndexOf("/");b.category=a.substr(0,r);b.title||(b.title=e);if(b.prototype)for(var h in q.prototype)b.prototype[h]||(b.prototype[h]=q.prototype[h]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape= +c.BOX_SHAPE;break;case "round":this._shape=c.ROUND_SHAPE;break;case "circle":this._shape=c.CIRCLE_SHAPE;break;case "card":this._shape=c.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[e]=b);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(h in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[h].toLowerCase()]= +b},wrapFunctionAsNode:function(a,b,e,r){for(var h=Array(b.length),f="",k=c.getParameterNames(b),d=0;df&&(f=h.size[0]),k+=h.size[1]+a;b+=f+a}this.setDirtyCanvas(!0,!0)};d.prototype.getTime=function(){return this.globaltime};d.prototype.getFixedTime=function(){return this.fixedtime};d.prototype.getElapsedTime=function(){return this.elapsed_time};d.prototype.sendEventToAllNodes=function(a,b,e){e=e||c.ALWAYS;var r=this._nodes_in_order?this._nodes_in_order:this._nodes; +if(r)for(var h=0,f=r.length;h=c.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_ida.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};q.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("properties"==b)for(var e in a.properties){if(this.properties[e]= +a.properties[e],this.onPropertyChanged)this.onPropertyChanged(e,a.properties[e])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=c.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(e=0;e=this.outputs.length)){var e=this.outputs[a];if(e&&(e._data=b,this.outputs[a].links))for(e=0;e=this.outputs.length)){var e=this.outputs[a];if(e&&(e.type=b,this.outputs[a].links))for(e=0;e=this.inputs.length||null==this.inputs[a].link)){var e=this.graph.links[this.inputs[a].link];if(!e)return null;if(!b)return e.data;var c=this.graph.getNodeById(e.origin_id);if(!c)return e.data;if(c.updateOutputData)c.updateOutputData(e.origin_slot);else if(c.onExecute)c.onExecute();return e.data}};q.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id); +return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};q.prototype.getInputDataByName=function(a,b){var e=this.findInputSlot(a);return-1==e?null:this.getInputData(e,b)};q.prototype.isInputConnected=function(a){return this.inputs?a=this.inputs.length)return null;a=this.inputs[a];return a&& +null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};q.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,e=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};q.prototype.getOutputInfo= +function(a){return this.outputs?a=this.outputs.length)return null; +a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],e=0;ea&&this.pos[1]-h-eb)return!0;return!1};q.prototype.getSlotInPosition=function(a,b){var e=new Float32Array(2);if(this.inputs)for(var c=0,h=this.inputs.length;c=this.outputs.length)return c.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b)); +if(!b)throw"target node is null";if(b==this)return null;if(e.constructor===String){if(e=b.findInputSlot(e),-1==e)return c.debug&&console.log("Connect: Error, no slot of name "+e),null}else{if(e===c.EVENT)return null;if(!b.inputs||e>=b.inputs.length)return c.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[e].link&&b.disconnectInput(e);var r=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(e,r.type,r))return null;var h=b.inputs[e],f=null;if(c.isValidConnection(r.type, +h.type)){f=new l(this.graph.last_link_id++,h.type,this.id,a,b.id,e);this.graph.links[f.id]=f;null==r.links&&(r.links=[]);r.links.push(f.id);b.inputs[e].link=f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(c.OUTPUT,a,!0,f,r);if(b.onConnectionsChange)b.onConnectionsChange(c.INPUT,e,!0,f,h);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(c.INPUT,b,e,this,a),this.graph.onNodeConnectionChange(c.OUTPUT,this,a,b,e))}this.setDirtyCanvas(!1, +!0);this.graph.connectionChange(this,f);return f};q.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return c.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return c.debug&&console.log("Connect: Error, slot number not found"),!1;var e=this.outputs[a];if(!e||!e.links||0==e.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found"; +for(var r=0,h=e.links.length;r=this.inputs.length)return c.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var e=this.inputs[a].link;this.inputs[a].link=null;var r=this.graph.links[e];if(r){var h=this.graph.getNodeById(r.origin_id);if(!h)return!1;var f=h.outputs[r.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var k=0,d=f.links.length;kb&&this.inputs[b].pos)return e[0]=this.pos[0]+this.inputs[b].pos[0],e[1]=this.pos[1]+this.inputs[b].pos[1],e;if(!a&&r>b&&this.outputs[b].pos)return e[0]=this.pos[0]+this.outputs[b].pos[0], +e[1]=this.pos[1]+this.outputs[b].pos[1],e;if(this.horizontal)return e[0]=this.pos[0]+this.size[0]/r*(b+0.5),e[1]=a?this.pos[1]-c.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],e;e[0]=a?this.pos[0]+h:this.pos[0]+this.size[0]+1-h;e[1]=this.pos[1]+(b+0.7)*c.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return e};q.prototype.alignToGrid=function(){this.pos[0]=c.CANVAS_GRID_SIZE*Math.round(this.pos[0]/c.CANVAS_GRID_SIZE);this.pos[1]=c.CANVAS_GRID_SIZE*Math.round(this.pos[1]/c.CANVAS_GRID_SIZE)};q.prototype.trace= +function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>q.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};q.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};q.prototype.loadImage=function(a){var b=new Image;b.src=c.node_images_path+a;b.ready=!1;var e=this;b.onload=function(){this.ready=!0;e.setDirtyCanvas(!0)};return b};q.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b= +this.graph.list_of_graphcanvas,e=0;ea.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0}); +Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};g.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};g.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};g.prototype.move= +function(a,b,e){this._pos[0]+=a;this._pos[1]+=b;if(!e)for(e=0;ethis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var e=this.element.getBoundingClientRect(); +if(e){b=b||[0.5*e.width,0.5*e.height];e=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var c=this.convertCanvasToOffset(b),e=[c[0]-e[0],c[1]-e[1]];this.offset[0]+=e[0];this.offset[1]+=e[1];if(this.onredraw)this.onredraw(this)}}};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};u.LGraphCanvas=c.LGraphCanvas=m;m.link_type_colors={"-1":c.EVENT_LINK_COLOR,number:"#AAA", +node:"#DCA"};m.gradients={};m.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]); +if(this.onClear)this.onClear()};m.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this.setDirty(!0,!0)))};m.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.setDirty(!0,!0)};m.prototype.closeSubgraph=function(){if(this._graph_stack&& +0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};m.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas"; +a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a element, you passed a "+a.localName;throw"This browser doesnt support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL()); +this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};m.prototype._doNothing=function(a){a.preventDefault();return!1};m.prototype._doReturnTrue=function(a){a.preventDefault();return!0};m.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback= +this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel", +this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};m.prototype.unbindEvents=function(){if(this._events_binded){var a= +this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter", +this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};m.getFileExtension=function(a){var b=a.indexOf("?");-1!= +b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};m.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};m.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas= +!0)};m.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};m.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};m.prototype.stopRendering=function(){this.is_rendering=!1};m.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a); +var b=this.getCanvasWindow();m.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),f=!1,h=300>c.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();c.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1== +a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,f=!0);var k=!1;if(e&&this.allow_interaction&&!f){this.live_mode||e.flags.pinned||this.bringToFront(e);if(!this.connecting_node&&!e.flags.collapsed&&!this.live_mode)if(!f&&!1!==e.resizable&&B(a.canvasX,a.canvasY,e.pos[0]+e.size[0]-5,e.pos[1]+e.size[1]-5,10,10))this.resizing_node=e,this.canvas.style.cursor= +"se-resize",f=!0;else{if(e.outputs)for(var d=0,n=e.outputs.length;dk[0]+4||a.canvasYk[1]+4)){this.showLinkMenu(e,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&(a.ctrlKey&&(this.dragging_rectangle=null),10>w([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing= +!0:this.selected_group.recomputeInsideNodes());h&&this.showSearchBox(a);k=!0}!f&&k&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(e,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=c.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation(); +if(this.onMouseDown)this.onMouseDown(a);return!1}}};m.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){m.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],e=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,this.node_widget[1]),this.dirty_canvas= +!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(e[0]/this.ds.scale,e[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+= +e[0]/this.ds.scale,this.ds.offset[1]+=e[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,h=this.graph._nodes.length;bthis.dragging_rectangle[3]?this.dragging_rectangle[1]-h:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-f:this.dragging_rectangle[0];this.dragging_rectangle[1]=k;this.dragging_rectangle[2]=f;this.dragging_rectangle[3]=h;h=[];for(k=0;ka.click_time&& +B(a.canvasX,a.canvasY,f.pos[0],f.pos[1]-c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT)&&f.collapse(),this.dirty_bgcanvas=this.dirty_canvas=!0,this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]),this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]),this.graph.config.align_to_grid&&this.node_dragged.alignToGrid(),this.node_dragged=null;else{f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!f&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas= +!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change(); +a.stopPropagation();a.preventDefault();return!1}};m.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var e=this.ds.scale;0b&&(e*=1/1.1);this.ds.changeScale(e,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};m.prototype.isOverNodeBox=function(a,b,e){var f=c.NODE_TITLE_HEIGHT;return B(b,e,a.pos[0]+2,a.pos[1]+2-f,f-4,f-4)?!0:!1};m.prototype.isOverNodeInput=function(a, +b,e,c){if(a.inputs)for(var h=0,f=a.inputs.length;he-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};m.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(), +a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),e=0;e> ";b.fillText(c+e.getTitle(),0.5*a.width,40);b.restore()}e=!1;this.onRenderBackground&&(e=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save(); +this.ds.toCanvasContext(b);if(this.background_image&&0.5this.ds.scale,t=a._shape||a.constructor.shape||c.ROUND_SHAPE,l=a.constructor.title_mode,p=!0;l==c.TRANSPARENT_TITLE?p=!1:l==c.AUTOHIDE_TITLE&&n&&(p=!0);f[0]=0;f[1]=p?-h:0;f[2]=e[0]+1;f[3]=p?e[1]+h:e[1];n=b.globalAlpha;b.beginPath();t==c.BOX_SHAPE||g?b.fillRect(f[0],f[1],f[2],f[3]):t==c.ROUND_SHAPE||t==c.CARD_SHAPE? +b.roundRect(f[0],f[1],f[2],f[3],this.round_radius,t==c.CARD_SHAPE?0:this.round_radius):t==c.CIRCLE_SHAPE&&b.arc(0.5*e[0],0.5*e[1],0.5*e[0],0,2*Math.PI);b.fill();b.shadowColor="transparent";b.fillStyle="rgba(0,0,0,0.2)";b.fillRect(0,-1,f[2],2);b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(p||l==c.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,h,e,this.ds.scale,k);else if(l!=c.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){p= +a.constructor.title_color||k;a.flags.collapsed&&(b.shadowColor=c.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var C=m.gradients[p];C||(C=m.gradients[p]=b.createLinearGradient(0,0,400,0),C.addColorStop(0,p),C.addColorStop(1,"#000"));b.fillStyle=C}else b.fillStyle=p;b.beginPath();t==c.BOX_SHAPE||g?b.rect(0,-h,e[0]+1,h):t!=c.ROUND_SHAPE&&t!=c.CARD_SHAPE||b.roundRect(0,-h,e[0]+1,h,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b, +h,e,this.ds.scale);else t==c.ROUND_SHAPE||t==c.CIRCLE_SHAPE||t==c.CARD_SHAPE?(g&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*h,-0.5*h,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||c.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*h,-0.5*h,5,0,2*Math.PI),b.fill()):(g&&(b.fillStyle="black",b.fillRect(0.5*(h-10)-1,-0.5*(h+10)-1,12,12)),b.fillStyle=a.boxcolor||c.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(h-10),-0.5*(h+10),10,10));b.globalAlpha=n;if(a.onDrawTitleText)a.onDrawTitleText(b,h,e,this.ds.scale, +this.title_text_font,d);!g&&(b.font=this.title_text_font,g=a.getTitle())&&(b.fillStyle=d?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",n=b.measureText(g),b.fillText(g,h+0.5*n.width,c.NODE_TITLE_TEXT_Y-h),b.textAlign="left"):(b.textAlign="left",b.fillText(g,h,c.NODE_TITLE_TEXT_Y-h)));if(a.onDrawTitle)a.onDrawTitle(b)}if(d){if(a.onBounding)a.onBounding(f);l==c.TRANSPARENT_TITLE&&(f[1]-=h,f[3]+=h);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();t== +c.BOX_SHAPE?b.rect(-6+f[0],-6+f[1],12+f[2],12+f[3]):t==c.ROUND_SHAPE||t==c.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+f[0],-6+f[1],12+f[2],12+f[3],2*this.round_radius):t==c.CARD_SHAPE?b.roundRect(-6+f[0],-6+f[1],12+f[2],12+f[3],2*this.round_radius,2):t==c.CIRCLE_SHAPE&&b.arc(0.5*e[0],0.5*e[1],0.5*e[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=k;b.globalAlpha=1}};var A=new Float32Array(4),k=new Float32Array(4),t=new Float32Array(2),v=new Float32Array(2);m.prototype.drawConnections= +function(a){var b=c.getTime(),e=this.visible_area;A[0]=e[0]-20;A[1]=e[1]-20;A[2]=e[2]+40;A[3]=e[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var e=this.graph._nodes,f=0,h=e.length;fk[2]&&(k[0]+=k[2],k[2]=Math.abs(k[2]));0>k[3]&&(k[1]+=k[3],k[3]=Math.abs(k[3]));if(z(k,A)){var D=g.outputs[l],l=d.inputs[n];if(D&&l&&(g=D.dir||(g.horizontal?c.DOWN:c.RIGHT),l=l.dir||(d.horizontal?c.UP:c.LEFT),this.renderLink(a,p,C,m,!1,0,null,g,l),m&&m._last_time&&1E3>b-m._last_time)){var D=2-0.002*(b-m._last_time),E=a.globalAlpha;a.globalAlpha=E*D;this.renderLink(a,p,C,m,!0, +D,"white",g,l);a.globalAlpha=E}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,e,f,h,k,d,n,g,t){f&&this.visible_links.push(f);!d&&f&&(d=f.color||m.link_type_colors[f.type]);d||(d=this.default_link_color);null!=f&&this.highlighted_links[f.id]&&(d="#FFF");n=n||c.RIGHT;g=g||c.LEFT;var p=w(b,e);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(C[0],C[1]),a.rotate(D),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(t[0],t[1]),a.rotate(E),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(h[0],h[1],5,0,2*Math.PI),a.fill());if(k)for(a.fillStyle=d,C=0;5>C;++C)k=(0.001*c.getTime()+0.2*C)%1,h=this.computeConnectionPoint(b,e,k,n,g),a.beginPath(),a.arc(h[0], +h[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,e,f,h){f=f||c.RIGHT;h=h||c.LEFT;var k=w(a,b),d=[a[0],a[1]],n=[b[0],b[1]];switch(f){case c.LEFT:d[0]+=-0.25*k;break;case c.RIGHT:d[0]+=0.25*k;break;case c.UP:d[1]+=-0.25*k;break;case c.DOWN:d[1]+=0.25*k}switch(h){case c.LEFT:n[0]+=-0.25*k;break;case c.RIGHT:n[0]+=0.25*k;break;case c.UP:n[1]+=-0.25*k;break;case c.DOWN:n[1]+=0.25*k}f=(1-e)*(1-e)*(1-e);h=3*(1-e)*(1-e)*e;k=3*(1-e)*e*e;e*=e*e;return[f*a[0]+h*d[0]+k*n[0]+e*b[0], +f*a[1]+h*d[1]+k*n[1]+e*b[1]]};m.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,e=0;ep.last_y&&dp.options.max&&(p.value=p.options.max);else if("mousedown"==e.type)if((f=p.options.values)&&f.constructor===Function&&(f=p.options.values(p,a)),h=40>h?-1:h>k-40?1:0,"number"==p.type)p.value+=0.1*h*(p.options.step||1),null!=p.options.min&&p.valuep.options.max&&(p.value=p.options.max);else if(h)e=f.indexOf(p.value)+h,e>=f.length&&(e=0),0>e&&(e=f.length-1),p.value=f[e];else{new c.ContextMenu(f,{scale:Math.max(1,this.ds.scale),event:e,className:"dark",callback:C.bind(p)},g);var C=function(a,b,e){this.value=a;n.dirty_canvas=!0;return!1}}p.callback&&setTimeout(function(){this.callback(this.value,n,a,b)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==e.type&&(p.value=!p.value,p.callback&&setTimeout(function(){p.callback(p.value, +n,a,b)},20));break;case "string":case "text":"mousedown"==e.type&&this.prompt("Value",p.value,function(b){this.value=b;p.callback&&p.callback(b,n,a)}.bind(p),e);break;default:p.mouse&&p.mouse(ctx,e,[h,d],a)}return p}}return null};m.prototype.drawGroups=function(a,b){if(this.graph){var e=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var f=0;fe&&0.01>b.editor_alpha&&(clearInterval(c),1>e&&(b.live_mode=!0));1"+g+""+a+"",value:g});if(n.length)return new c.ContextMenu(n,{event:e,callback:d,parentMenu:f,allow_html:!0,node:h},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div"); +b.innerText=a;return b.innerHTML};m.onResizeNode=function(a,b,e,c,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};m.prototype.showLinkMenu=function(a,b){var e=this;new c.ContextMenu(["Delete"],{event:b,callback:function(b){switch(b){case "Delete":e.graph.removeLink(a.id)}}});return!1};m.onShowPropertyEditor=function(a,b,e,c,f){function d(){var b=g.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));f[k]=b;n.parentNode&&n.parentNode.removeChild(n);f.setDirtyCanvas(!0,!0)}var k= +a.property||"title";b=f[k];var n=document.createElement("div");n.className="graphdialog";n.innerHTML="";n.querySelector(".name").innerText=k;var g=n.querySelector("input");g&&(g.value=b,g.addEventListener("blur",function(a){this.focus()}),g.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())}));b=m.active_canvas.canvas;e=b.getBoundingClientRect();var t=c=-20;e&&(c-= +e.left,t-=e.top);event?(n.style.left=event.clientX+c+"px",n.style.top=event.clientY+t+"px"):(n.style.left=0.5*b.width+c+"px",n.style.top=0.5*b.height+t+"px");n.querySelector("button").addEventListener("click",d);b.parentNode.appendChild(n)};m.prototype.prompt=function(a,b,e,c){var f=this;a=a||"";var d=document.createElement("div");d.className="graphdialog rounded";d.innerHTML=" ";d.close=function(){f.prompt_box= +null;d.parentNode&&d.parentNode.removeChild(d)};1m.search_limit))break}if(Array.prototype.filter)for(k=Object.keys(c.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(e)}),d=0;dm.search_limit);d++); +else for(d in c.registered_node_types)if(-1!=d.indexOf(e)&&(a(d),-1!==m.search_limit&&p++>m.search_limit))break}}var h=this,d=document.createElement("div");d.className="litegraph litesearchbox graphdialog rounded";d.innerHTML="Search
";d.close=function(){h.search_box=null;document.body.focus();setTimeout(function(){h.canvas.focus()},20);d.parentNode&&d.parentNode.removeChild(d)};var k=null;1";else if("enum"==d&&k.values){g=""}else if("boolean"==d)g="";else{console.warn("unknown type: "+d);return}var p=this.createDialog(""+b+""+g+"",e);if("enum"==d&&k.values){var C=p.querySelector("select");C.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==d)(C=p.querySelector("input"))&&C.addEventListener("click",function(a){f(!!C.checked)});else if(C=p.querySelector("input"))C.addEventListener("blur",function(a){this.focus()}),C.value=void 0!==a.properties[b]?a.properties[b]: +"",C.addEventListener("keydown",function(a){13==a.keyCode&&(c(),a.preventDefault(),a.stopPropagation())});p.querySelector("button").addEventListener("click",c)}};m.prototype.createDialog=function(a,b){b=b||{};var e=document.createElement("div");e.className="graphdialog";e.innerHTML=a;var c=this.canvas.getBoundingClientRect(),f=-20,d=-20;c&&(f-=c.left,d-=c.top);b.position?(f+=b.position[0],d+=b.position[1]):b.event?(f+=b.event.clientX,d+=b.event.clientY):(f+=0.5*this.canvas.width,d+=0.5*this.canvas.height); +e.style.left=f+"px";e.style.top=d+"px";this.canvas.parentNode.appendChild(e);e.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return e};m.onMenuNodeCollapse=function(a,b,e,c,f){f.collapse()};m.onMenuNodePin=function(a,b,e,c,f){f.pin()};m.onMenuNodeMode=function(a,b,e,f,d){new c.ContextMenu(["Always","On Event","On Trigger","Never"],{event:e,callback:function(a){if(d)switch(a){case "On Event":d.mode=c.ON_EVENT;break;case "On Trigger":d.mode=c.ON_TRIGGER;break;case "Never":d.mode= +c.NEVER;break;default:d.mode=c.ALWAYS}},parentMenu:f,node:d});return!1};m.onMenuNodeColors=function(a,b,e,f,d){if(!d)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var k in m.node_colors)a=m.node_colors[k],a={value:k,content:""+k+""},b.push(a);new c.ContextMenu(b,{event:e,callback:function(a){d&& +((a=a.value?m.node_colors[a.value]:null)?d.constructor===c.LGraphGroup?d.color=a.groupcolor:(d.color=a.color,d.bgcolor=a.bgcolor):(delete d.color,delete d.bgcolor),d.setDirtyCanvas(!0,!0))},parentMenu:f,node:d});return!1};m.onMenuNodeShapes=function(a,b,e,f,d){if(!d)throw"no node passed";new c.ContextMenu(c.VALID_SHAPES,{event:e,callback:function(a){d&&(d.shape=a,d.setDirtyCanvas(!0))},parentMenu:f,node:d});return!1};m.onMenuNodeRemove=function(a,b,e,c,f){if(!f)throw"no node passed";!1!==f.removable&& +(f.graph.remove(f),f.setDirtyCanvas(!0,!0))};m.onMenuNodeClone=function(a,b,e,c,f){!1!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.add(a),f.setDirtyCanvas(!0,!0))};m.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233", +bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};m.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:m.onMenuAdd},{content:"Add Group",callback:m.onGroupAdd}],this._graph_stack&&0Name",c),k=d.querySelector("input");k&&p&&(k.value=p.label);d.querySelector("button").addEventListener("click",function(a){k.value&&(p&&(p.label=k.value),e.setDirty(!0));d.close()})}},extra:a},n=null;a&&(n=a.getSlotInPosition(b.canvasX,b.canvasY),m.active_node=a);n?(d=[],n&&n.output&&n.output.links&&n.output.links.length&&d.push({content:"Disconnect Links",slot:n}),d.push(n.locked?"Cannot remove":{content:"Remove Slot", +slot:n}),d.push(n.nameLocked?"Cannot rename":{content:"Rename Slot",slot:n}),k.title=(n.input?n.input.type:n.output.type)||"*",n.input&&n.input.type==c.ACTION&&(k.title="Action"),n.output&&n.output.type==c.EVENT&&(k.title="Event")):a?d=this.getNodeMenuOptions(a):(d=this.getCanvasMenuOptions(),(n=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&d.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:n,options:this.getGroupMenuOptions(n)}}));d&&new c.ContextMenu(d,k,f)};this.CanvasRenderingContext2D&& +(CanvasRenderingContext2D.prototype.roundRect=function(a,b,e,c,f,d){void 0===f&&(f=5);void 0===d&&(d=f);this.moveTo(a+f,b);this.lineTo(a+e-f,b);this.quadraticCurveTo(a+e,b,a+e,b+f);this.lineTo(a+e,b+c-d);this.quadraticCurveTo(a+e,b+c,a+e-d,b+c);this.lineTo(a+d,b+c);this.quadraticCurveTo(a,b+c,a,b+c-d);this.lineTo(a,b+f);this.quadraticCurveTo(a,b,a+f,b)});c.compareObjects=function(a,b){for(var e in a)if(a[e]!=b[e])return!1;return!0};c.distance=w;c.colorToString=function(a){return"rgba("+Math.round(255* +a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};c.isInsideRectangle=B;c.growBounding=function(a,b,e){ba[2]&&(a[2]=b);ea[3]&&(a[3]=e)};c.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};c.overlapBounding=z;c.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),e=0,c,f,d=0;6>d;d+=2)c="0123456789ABCDEF".indexOf(a.charAt(d)), +f="0123456789ABCDEF".indexOf(a.charAt(d+1)),b[e]=16*c+f,e++;return b};c.num2hex=function(a){for(var b="#",e,c,f=0;3>f;f++)e=a[f]/16,c=a[f]%16,b+="0123456789ABCDEF".charAt(e)+"0123456789ABCDEF".charAt(c);return b};y.prototype.addItem=function(a,b,e){function c(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,c=!0;d.current_submenu&&d.current_submenu.close(a);if(e.callback){var k=e.callback.call(this,b,e,a,d,e.node);!0===k&&(c=!1)}if(b&&(b.callback&&!e.ignore_item_callbacks&& +!0!==b.disabled&&(k=b.callback.call(this,b,e,a,d,e.extra),!0===k&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new d.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:d,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:e.autoopen});c=!1}c&&!d.lock&&d.close()}var d=this;e=e||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var n=!1;if(null===b)k.classList.add("separator"); +else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(n=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);n||k.addEventListener("click",f);e.autoopen&&k.addEventListener("mouseenter",c);return k};y.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&& +!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!y.isCursorOverElement(a,this.parentMenu.root)&&y.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};y.trigger=function(a,b,e,c){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,e);f.srcElement=c;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f); +return f};y.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};y.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};y.isCursorOverElement=function(a,b){var e=a.clientX,c=a.clientY,f=b.getBoundingClientRect();return f?c>f.top&&cf.left&&ea?b:ethis.size[0]-n.NODE_TITLE_HEIGHT&&0>d[1]){var g=this;setTimeout(function(){k.openSubgraph(g.subgraph)},10)}};l.prototype.onSubgraphNewGlobalInput=function(c,d){this.addInput(c,d)};l.prototype.onSubgraphRenamedGlobalInput=function(c,d){var k=this.findInputSlot(c);-1!=k&&(this.getInputInfo(k).name=d)};l.prototype.onSubgraphTypeChangeGlobalInput=function(c,d){var k=this.findInputSlot(c);-1!=k&&(this.getInputInfo(k).type=d)};l.prototype.onSubgraphNewGlobalOutput=function(c,d){this.addOutput(c,d)}; +l.prototype.onSubgraphRenamedGlobalOutput=function(c,d){var k=this.findOutputSlot(c);-1!=k&&(this.getOutputInfo(k).name=d)};l.prototype.onSubgraphTypeChangeGlobalOutput=function(c,d){var k=this.findOutputSlot(c);-1!=k&&(this.getOutputInfo(k).type=d)};l.prototype.getExtraMenuOptions=function(c){var d=this;return[{content:"Open",callback:function(){c.openSubgraph(d.subgraph)}}]};l.prototype.onResize=function(c){c[1]+=20};l.prototype.onExecute=function(){if(this.inputs)for(var c=0;c=m?this.trigger(null,g):this._pending.push([m,g])};s.prototype.onExecute=function(){var d=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var g=0;gd[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};q.prototype.onMouseMove=function(c){if(this.mouse_captured){var d=this.old_y-c.canvasY;c.shiftKey&&(d*=10);if(c.metaKey||c.altKey)d*=0.1;this.old_y=c.canvasY;c=this._remainder+d/q.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+(c|0)*this.properties.step,this.properties.min,this.properties.max); +this.properties.value=c;this.graph._version++;this.setDirtyCanvas(!0)}};q.prototype.onMouseUp=function(c,d){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(d[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.graph._version++,this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};y.registerNodeType("widget/number",q);g.title="Knob";g.desc="Circular controller";g.size=[80,100];g.prototype.onDrawForeground= +function(c){if(!this.flags.collapsed){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min));var d=0.5*this.size[0],n=0.5*this.size[1],f=0.5*Math.min(this.size[0],this.size[1])-5;c.globalAlpha=1;c.save();c.translate(d,n);c.rotate(0.75*Math.PI);c.fillStyle="rgba(0,0,0,0.5)";c.beginPath();c.moveTo(0,0);c.arc(0,0,f,0,1.5*Math.PI);c.fill();c.strokeStyle="black";c.fillStyle=this.properties.color;c.lineWidth=2;c.beginPath();c.moveTo(0,0);c.arc(0, +0,f-4,0,1.5*Math.PI*Math.max(0.01,this.value));c.closePath();c.fill();c.lineWidth=1;c.globalAlpha=1;c.restore();c.fillStyle="black";c.beginPath();c.arc(d,n,0.75*f,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":this.properties.color;c.beginPath();var g=this.value*Math.PI*1.5+0.75*Math.PI;c.arc(d+Math.cos(g)*f*0.65,n+Math.sin(g)*f*0.65,0.05*f,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";c.font=Math.floor(0.5*f)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision), +d,n+0.15*f)}};g.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=y.colorToString([this.value,this.value,this.value])};g.prototype.onMouseDown=function(c){this.center=[0.5*this.size[0],0.5*this.size[1]+20];this.radius=0.5*this.size[0];if(20>c.canvasY-this.pos[1]||y.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0}; +g.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var d=this.value,d=d-0.01*(c[1]-this.oldmouse[1]);1d&&(d=0);this.value=d;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};g.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};g.prototype.onPropertyChanged=function(c,d){if("min"==c||"max"==c||"value"==c)return this.properties[c]= +parseFloat(d),!0};y.registerNodeType("widget/knob",g);s.title="Internal Slider";s.prototype.onPropertyChanged=function(c,d){"value"==c&&(this.slider.value=d)};s.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};y.registerNodeType("widget/internal_slider",s);m.title="H.Slider";m.desc="Linear slider controller";m.prototype.onDrawForeground=function(c){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min));c.globalAlpha= +1;c.lineWidth=1;c.fillStyle="#000";c.fillRect(2,2,this.size[0]-4,this.size[1]-4);c.fillStyle=this.properties.color;c.beginPath();c.rect(4,4,(this.size[0]-8)*this.value,this.size[1]-8);c.fill()};m.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=y.colorToString([this.value,this.value,this.value])};m.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1; +this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};m.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var d=this.value,d=d+(c[0]-this.oldmouse[0])/this.size[0];1d&&(d=0);this.value=d;this.oldmouse=c;this.setDirtyCanvas(!0)}};m.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};m.prototype.onMouseLeave=function(c){};y.registerNodeType("widget/hslider",m);w.title="Progress";w.desc= +"Shows data in linear progress";w.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};w.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.color;var d=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),d=Math.min(1,d),d=Math.max(0,d);c.fillRect(2,2,(this.size[0]-4)*d,this.size[1]-4)};y.registerNodeType("widget/progress",w);B.title="Text";B.desc="Shows the input value";B.widgets=[{name:"resize", +text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];B.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var d=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var n=this.properties.fontsize;c.textAlign=this.properties.align;c.font=n.toString()+"px "+this.properties.font; +this.str="number"==typeof d?d.toFixed(this.properties.decimals):d;if("string"==typeof this.str){var d=this.str.split("\\n"),f;for(f in d)c.fillText(d[f],"left"==this.properties.align?15:this.size[0]-15,-0.15*n+n*(parseInt(f)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};B.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};B.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+ +"px "+this.properties.font;var d=0,n;for(n in c){var f=this.last_ctx.measureText(c[n]).width;dg?l.xbox.axes.lx:0,this._left_axis[1]=Math.abs(l.xbox.axes.ly)>g?l.xbox.axes.ly:0,this._right_axis[0]=Math.abs(l.xbox.axes.rx)>g?l.xbox.axes.rx:0,this._right_axis[1]=Math.abs(l.xbox.axes.ry)>g?l.xbox.axes.ry:0,this._triggers[0]=Math.abs(l.xbox.axes.ltrigger)>g?l.xbox.axes.ltrigger: +0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>g?l.xbox.axes.rtrigger:0);if(this.outputs)for(g=0;gl;l++)if(g[l]){l=g[l];g=this.xbox_mapping;g||(g=this.xbox_mapping={axes:[],buttons:{},hat:"",hatmap:d.CENTER});g.axes.lx=l.axes[0];g.axes.ly=l.axes[1];g.axes.rx=l.axes[2];g.axes.ry=l.axes[3];g.axes.ltrigger=l.buttons[6].value; +g.axes.rtrigger=l.buttons[7].value;g.hat="";g.hatmap=d.CENTER;for(var s=0;s","string",{values:f.values});this.size=[60,40]}function e(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function m(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="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.addWidget("toggle","allow",x.allow_scripts,function(a){x.allow_scripts=a});this._func=null}function B(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function A(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function C(){this.addInput("vec3", -"vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function E(){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 D(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function F(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]); -this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var x=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;bb&&(this._current=0);for(var d=a=0;db&&(b=1);this.properties.samples=Math.round(b);var d=this._values;this._values=new Float32Array(this.properties.samples);d.length<=this._values.length?this._values.set(d):this._values.set(d.subarray(0,this._values.length))};x.registerNodeType("math/average",s);a.title="TendTo";a.desc="moves the output value always closer to the input";a.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor; -this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};x.registerNodeType("math/tendTo",a);b.values="+-*/%^".split("");b.title="Operation";b.desc="Easy math operators";b["@OP"]={type:"enum",title:"operation",values:b.values};b.prototype.getTitle=function(){return"A "+this.properties.OP+" B"};b.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};b.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1); -null!=a?this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=b:b=this.properties.B;var d=0;switch(this.properties.OP){case "+":d=a+b;break;case "-":d=a-b;break;case "x":case "X":case "*":d=a*b;break;case "/":d=a/b;break;case "%":d=a%b;break;case "^":d=Math.pow(a,b);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,d)};b.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#CCC",a.textAlign="center",a.fillText(this.properties.OP, -0.5*this.size[0],0.35*this.size[1]+x.NODE_TITLE_HEIGHT),a.textAlign="left")};x.registerNodeType("math/operation",b);d.title="Compare";d.desc="compares between two values";d.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var d=0,c=this.outputs.length;dB":value=a>b;break;case "A=B":value=a>=b}this.setOutputData(d,value)}}};d.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};x.registerNodeType("math/compare",d);x.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});x.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]], -title:"A!=B"});x.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});x.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"});x.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});f.values="> < == != <= >=".split(" ");f["@OP"]={type:"enum",title:"operation",values:f.values};f.title="Condition";f.desc="evaluates condition between A and B"; -f.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var d=!0;switch(this.properties.OP){case ">":d=a>b;break;case "<":d=a=":d=a>=b}this.setOutputData(0,d)};x.registerNodeType("math/condition",f);e.title="Accumulate";e.desc="Increments a value every time";e.prototype.onExecute=function(){null=== -this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};x.registerNodeType("math/accumulate",e);m.title="Trigonometry";m.desc="Sin Cos Tan";m.filter="shader";m.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,d=this.findInputSlot("amplitude");-1!=d&&(b=this.getInputData(d));var c= -this.properties.offset,d=this.findInputSlot("offset");-1!=d&&(c=this.getInputData(d));for(var d=0,e=this.outputs.length;dXY";B.desc="vector 2 to components";B.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};x.registerNodeType("math3d/vec2-to-xyz",B);A.title="XY->Vec2";A.desc="components to vector2";A.prototype.onExecute=function(){var a=this.getInputData(0); -null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this._data;d[0]=a;d[1]=b;this.setOutputData(0,d)};x.registerNodeType("math3d/xy-to-vec2",A);C.title="Vec3->XYZ";C.desc="vector 3 to components";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};x.registerNodeType("math3d/vec3-to-xyz",C);E.title="XYZ->Vec3";E.desc="components to vector3";E.prototype.onExecute= -function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this._data;c[0]=a;c[1]=b;c[2]=d;this.setOutputData(0,c)};x.registerNodeType("math3d/xyz-to-vec3",E);D.title="Vec4->XYZW";D.desc="vector 4 to components";D.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3, -a[3]))};x.registerNodeType("math3d/vec4-to-xyzw",D);F.title="XYZW->Vec4";F.desc="components to vector4";F.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this.getInputData(3);null==c&&(c=this.properties.w);var e=this._data;e[0]=a;e[1]=b;e[2]=d;e[3]=c;this.setOutputData(0,e)};x.registerNodeType("math3d/xyzw-to-vec4",F);w.glMatrix&&(w=function(){this.addOutput("quat", -"quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},w.title="Quaternion",w.desc="quaternion",w.prototype.onExecute=function(){this._value[0]=this.properties.x;this._value[1]=this.properties.y;this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},x.registerNodeType("math3d/quaternion",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 a=this.getInputData(0);null==a&&(a=this.properties.angle);var b=this.getInputData(1);null==b&&(b=this.properties.axis);a=quat.setAxisAngle(this._value,b,0.0174532925*a);this.setOutputData(0,a)},x.registerNodeType("math3d/rotation",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 a=this.getInputData(0);null==a&&(a=this.properties.vec);var b=this.getInputData(1);null==b?this.setOutputData(a):this.setOutputData(0,vec3.transformQuat(vec3.create(),a,b))},x.registerNodeType("math3d/rotate_vec3",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))}},x.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)}}},x.registerNodeType("math3d/quat-slerp",w))})(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 k(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}var r=w.LiteGraph;c.title="Selector";c.desc="selects an output";c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){c.fillStyle="#AFB"; -var g=(this.selected+1)*r.NODE_SLOT_HEIGHT+2;c.beginPath();c.moveTo(30,g);c.lineTo(30,g+r.NODE_SLOT_HEIGHT);c.lineTo(24,g+0.5*r.NODE_SLOT_HEIGHT);c.fill()}};c.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(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]]};r.registerNodeType("logic/selector",c);k.title="Sequence";k.desc="select one element from a sequence from a string"; -k.prototype.onPropertyChanged=function(c,g){"sequence"==c&&(this.values=g.split(","))};k.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])};r.registerNodeType("logic/sequence",k)})(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 k(){this.addOutput("frame","image");this.properties={url:""}}function r(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function q(){this.addInput("","image,canvas");this.size=[200,200]}function g(){this.addInputs([["img1", -"image"],["img2","image"],["fade","number"]]);this.addOutput("","image");this.properties={fade:0.5,width:512,height:512}}function t(){this.addInput("","image");this.addOutput("","image");this.properties={width:256,height:256,x:0,y:0,scale:1};this.size=[50,20]}function u(){this.addInput("clear",p.ACTION);this.addOutput("","canvas");this.properties={width:512,height:512,autoclear:!0};this.canvas=document.createElement("canvas");this.ctx=this.canvas.getContext("2d")}function y(){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 h(){this.addInput("t","number");this.addOutputs([["frame","image"],["t","number"],["d","number"]]);this.properties={url:"",use_proxy:!0}} -function l(){this.addOutput("Webcam","image");this.properties={facingMode:"user"};this.boxcolor="black";this.frame=0}var p=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 a=0;4>a;++a){var b=this.getInputData(a);if(null!=b){var d=this.values[a];d.push(b);d.length>c[0]&&d.shift()}}}};c.prototype.onDrawBackground=function(g){if(!this.flags.collapsed){var a=this.size,b=0.5*a[1]/ -this.properties.scale,d=c.colors,f=0.5*a[1];g.fillStyle="#000";g.fillRect(0,0,a[0],a[1]);g.strokeStyle="#555";g.beginPath();g.moveTo(0,f);g.lineTo(a[0],f);g.stroke();if(this.inputs)for(var e=0;4>e;++e){var h=this.values[e];if(this.inputs[e]&&this.inputs[e].link){g.strokeStyle=d[e];g.beginPath();var k=h[0]*b*-1+f;g.moveTo(0,Math.clamp(k,0,a[1]));for(var l=1;la&&(a=0);if(0!=c.length){var b=[0,0,0];if(0==a)b=c[0];else if(1==a)b=c[c.length-1];else{var d=(c.length-1)*a,a=c[Math.floor(d)],c=c[Math.floor(d)+1],d=d-Math.floor(d);b[0]=a[0]* -(1-d)+c[0]*d;b[1]=a[1]*(1-d)+c[1]*d;b[2]=a[2]*(1-d)+c[2]*d}for(var f in b)b[f]/=255;this.boxcolor=colorToString(b);this.setOutputData(0,b)}};p.registerNodeType("color/palette",r);q.title="Frame";q.desc="Frame viewerew";q.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"view",text:"View Image",type:"button"}];q.prototype.onDrawBackground=function(c){this.frame&&!this.flags.collapsed&&c.drawImage(this.frame,0,0,this.size[0],this.size[1])};q.prototype.onExecute=function(){this.frame=this.getInputData(0); -this.setDirtyCanvas(!0)};q.prototype.onWidget=function(c,a){if("resize"==a.name&&this.frame){var b=this.frame.width,d=this.frame.height;b||null==this.frame.videoWidth||(b=this.frame.videoWidth,d=this.frame.videoHeight);b&&d&&(this.size=[b,d]);this.setDirtyCanvas(!0,!0)}else"view"==a.name&&this.show()};q.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};p.registerNodeType("graphics/frame",q);g.title="Image fade";g.desc="Fades between images";g.widgets=[{name:"resizeA",text:"Resize to A", -type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];g.prototype.onAdded=function(){this.createCanvas();var c=this.canvas.getContext("2d");c.fillStyle="#000";c.fillRect(0,0,this.properties.width,this.properties.height)};g.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};g.prototype.onExecute=function(){var c=this.canvas.getContext("2d");this.canvas.width=this.canvas.width; -var a=this.getInputData(0);null!=a&&c.drawImage(a,0,0,this.canvas.width,this.canvas.height);a=this.getInputData(2);null==a?a=this.properties.fade:this.properties.fade=a;c.globalAlpha=a;a=this.getInputData(1);null!=a&&c.drawImage(a,0,0,this.canvas.width,this.canvas.height);c.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};p.registerNodeType("graphics/imagefade",g);t.title="Crop";t.desc="Crop Image";t.prototype.onAdded=function(){this.createCanvas()};t.prototype.createCanvas= -function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};t.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))};t.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])};t.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;"scale"==c?(this.properties[c]=parseFloat(a),0==this.properties[c]&&(this.trace("Error in scale"),this.properties[c]=1)):this.properties[c]=parseInt(a);this.createCanvas();return!0};p.registerNodeType("graphics/cropImage",t);u.title="Canvas";u.desc="Canvas to render stuff";u.prototype.onExecute=function(){var c=this.canvas,a=this.properties.width|0,b=this.properties.height| -0;c.width!=a&&(c.width=a);c.height!=b&&(c.height=b);this.properties.autoclear&&this.ctx.clearRect(0,0,c.width,c.height);this.setOutputData(0,c)};u.prototype.onAction=function(c,a){"clear"==c&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)};p.registerNodeType("graphics/canvas",u);y.title="DrawImage";y.desc="Draws image into a canvas";y.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var a=this.getInputOrProperty("img");if(a){var b=this.getInputOrProperty("x"),d=this.getInputOrProperty("y"); -c.getContext("2d").drawImage(a,b,d)}}};p.registerNodeType("graphics/drawImage",y);v.title="DrawRectangle";v.desc="Draws rectangle in canvas";v.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var a=this.getInputOrProperty("x"),b=this.getInputOrProperty("y"),d=this.getInputOrProperty("w"),f=this.getInputOrProperty("h");c.getContext("2d").fillRect(a,b,d,f)}};p.registerNodeType("graphics/drawRectangle",v);h.title="Video";h.desc="Video playback";h.widgets=[{name:"play",text:"PLAY",type:"minibutton"}, -{name:"stop",text:"STOP",type:"minibutton"},{name:"demo",text:"Demo video",type:"button"},{name:"mute",text:"Mute video",type:"button"}];h.prototype.onExecute=function(){if(this.properties.url&&(this.properties.url!=this._video_url&&this.loadVideo(this.properties.url),this._video&&0!=this._video.width)){var c=this.getInputData(0);c&&0<=c&&1>=c&&(this._video.currentTime=c*this._video.duration,this._video.pause());this._video.dirty=!0;this.setOutputData(0,this._video);this.setOutputData(1,this._video.currentTime); -this.setOutputData(2,this._video.duration);this.setDirtyCanvas(!0)}};h.prototype.onStart=function(){this.play()};h.prototype.onStop=function(){this.stop()};h.prototype.loadVideo=function(c){this._video_url=c;this.properties.use_proxy&&"http"==c.substr(0,4)&&p.proxy&&(c=p.proxy+c.substr(c.indexOf(":")+3));this._video=document.createElement("video");this._video.src=c;this._video.type="type=video/mp4";this._video.muted=!0;this._video.autoplay=!0;var a=this;this._video.addEventListener("loadedmetadata", -function(b){a.trace("Duration: "+this.duration+" seconds");a.trace("Size: "+this.videoWidth+","+this.videoHeight);a.setDirtyCanvas(!0);this.width=this.videoWidth;this.height=this.videoHeight});this._video.addEventListener("progress",function(a){});this._video.addEventListener("error",function(b){console.log("Error loading video: "+this.src);a.trace("Error loading video: "+this.src);if(this.error)switch(this.error.code){case this.error.MEDIA_ERR_ABORTED:a.trace("You stopped the video.");break;case this.error.MEDIA_ERR_NETWORK:a.trace("Network error - please try again later."); -break;case this.error.MEDIA_ERR_DECODE:a.trace("Video is broken..");break;case this.error.MEDIA_ERR_SRC_NOT_SUPPORTED:a.trace("Sorry, your browser can't play this video.")}});this._video.addEventListener("ended",function(b){a.trace("Ended.");this.play()})};h.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;"url"==c&&""!=a&&this.loadVideo(a);return!0};h.prototype.play=function(){this._video&&this._video.play()};h.prototype.playPause=function(){this._video&&(this._video.paused?this.play(): -this.pause())};h.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};h.prototype.pause=function(){this._video&&(this.trace("Video paused"),this._video.pause())};h.prototype.onWidget=function(c,a){};p.registerNodeType("graphics/video",h);l.title="Webcam";l.desc="Webcam image";l.is_webcam_open=!1;l.prototype.openStream=function(){function c(b){console.log("Webcam rejected",b);a._webcam_stream=!1;l.is_webcam_open=!1;a.boxcolor="red";a.trigger("stream_error")}if(navigator.getUserMedia){this._waiting_confirmation= -!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this))["catch"](c);var a=this}};l.prototype.closeStream=function(){if(this._webcam_stream){var c=this._webcam_stream.getTracks();if(c.length)for(var a=0;a=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};l.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",p.EVENT],["stream_closed",p.EVENT],["stream_error",p.EVENT]]};p.registerNodeType("graphics/webcam",l)})(this); -(function(w){var c=w.LiteGraph;w.LGraphTexture=null;if("undefined"!=typeof GL){LGraphCanvas.link_type_colors.Texture="#AEF";var k=function(){this.addOutput("Texture","Texture");this.properties={name:"",filter:!0};this.size=[k.image_preview_size,k.image_preview_size]};w.LGraphTexture=k;k.title="Texture";k.desc="Texture";k.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}};k.loadTextureCallback=null;k.image_preview_size=256;k.PASS_THROUGH=1;k.COPY=2;k.LOW=3;k.HIGH=4;k.REUSE=5;k.DEFAULT= -2;k.MODE_VALUES={"pass through":k.PASS_THROUGH,copy:k.COPY,low:k.LOW,high:k.HIGH,reuse:k.REUSE,"default":k.DEFAULT};k.getTexturesContainer=function(){return gl.textures};k.loadTexture=function(a,b){b=b||{};var d=a;"http://"==d.substr(0,7)&&c.proxy&&(d=c.proxy+d.substr(7));return k.getTexturesContainer()[a]=GL.Texture.fromURL(d,b)};k.getTexture=function(a){var b=this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a): -b};k.getTargetTexture=function(a,b,d){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var c=null;switch(d){case k.LOW:c=gl.UNSIGNED_BYTE;break;case k.HIGH:c=gl.HIGH_PRECISION_FORMAT;break;case k.REUSE:return a;default:c=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==c||(b=new GL.Texture(a.width,a.height,{type:c,format:gl.RGBA,filter:gl.LINEAR}));return b};k.getTextureType=function(a,b){var d=b?b.type:gl.UNSIGNED_BYTE;switch(a){case k.HIGH:d=gl.HIGH_PRECISION_FORMAT; -break;case k.LOW:d=gl.UNSIGNED_BYTE}return d};k.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576),b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})};k.prototype.onDropFile=function(a,b,d){if(a){var c=null;"string"==typeof a?c=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?c=GL.Texture.fromDDSInMemory(a):(a=new Blob([d]),a=URL.createObjectURL(a), -c=GL.Texture.fromURL(a));this._drop_texture=c;this.properties.name=b}else this._drop_texture=null,this.properties.name=""};k.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]};k.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=k.getTexture(this.properties.name));if(a){this._last_tex= -a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,a);for(var b=1;b=this.size[1]))if(this._drop_texture&&a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=k.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}};k.generateLowResTexturePreview= -function(a){if(!a)return null;var b=k.image_preview_size,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};k.prototype.getResources=function(a){a[this.properties.name]=GL.Texture;return a};k.prototype.onGetInputs=function(){return[["in","Texture"]]};k.prototype.onGetOutputs= -function(){return[["width","number"],["height","number"],["aspect","number"]]};c.registerNodeType("texture/texture",k);var r=function(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[k.image_preview_size,k.image_preview_size]};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:k.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()}}};c.registerNodeType("texture/preview",r);var q=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={name:""}};q.title="Save";q.desc="Save a texture in the repository";q.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(k.storeTexture?k.storeTexture(this.properties.name,a):k.getTexturesContainer()[this.properties.name]= -a),this.setOutputData(0,a))};c.registerNodeType("texture/save",q);var g=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="

pixelcode must be vec3

\t\t\t

uvcode must be vec2, is optional

\t\t\t

uv: tex. coords

color: texture

colorB: textureB

time: scene time

value: input value

"; -this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value",precision:k.DEFAULT}};g.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo",values:k.MODE_VALUES}};g.title="Operation";g.desc="Texture shader operation";g.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};g.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())};g.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,c=512;a?(d=a.width,c=a.height):b&&(d=b.width,c=b.height);var e=k.getTextureType(this.properties.precision, -a);this._tex=a||this._tex?k.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,c,{type:e,format:gl.RGBA,filter:gl.LINEAR});e="";this.properties.uvcode&&(e="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(e=this.properties.uvcode));var f="";this.properties.pixelcode&&(f="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(f=this.properties.pixelcode));var h=this._shader;if(!h||this._shader_code!=e+"|"+f){try{this._shader= -new GL.Shader(Shader.SCREEN_VERTEX_SHADER,g.pixel_shader,{UV_CODE:e,PIXEL_CODE:f}),this.boxcolor="#00FF00"}catch(m){console.log("Error compiling shader: ",m);this.boxcolor="#FF0000";return}this.boxcolor="#FF0000";this._shader_code=e+"|"+f;h=this._shader}if(h){this.boxcolor="green";var n=this.getInputData(2);null!=n?this.properties.value=n:n=parseFloat(this.properties.value);var l=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND); -a&&a.bind(0);b&&b.bind(1);var e=Mesh.getScreenQuad();h.uniforms({u_texture:0,u_textureB:1,value:n,texSize:[d,c],time:l}).draw(e)});this.setOutputData(0,this._tex)}else this.boxcolor="red"}}};g.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tUV_CODE;\n\t\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\tPIXEL_CODE;\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t"; -c.registerNodeType("texture/operation",g);var t=function(){this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,precision:k.DEFAULT};this.properties.code="\nvoid main() {\n vec2 uv = v_coord;\n vec3 color = vec3(0.0);\n//your code here\n\ngl_FragColor = vec4(color, 1.0);\n}\n";this._uniforms={in_texture:0,texSize:vec2.create(),time:0}};t.title="Shader";t.desc="Texture shader";t.widgets_info={code:{type:"code"},precision:{widget:"combo",values:k.MODE_VALUES}};t.prototype.onPropertyChanged= -function(a,b){if("code"==a){var d=this.getShader();if(d){var c=d.uniformInfo;if(this.inputs)for(var e={},f=0;f lumaMax))\n\t\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\t\telse\n\t\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\t\tif(u_igamma != 1.0)\n\t\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\t\treturn color;\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t\t}\n\t\t\t"; -v.gamma_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_igamma;\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t\t gl_FragColor = color;\n\t\t\t}\n\t\t\t";c.registerNodeType("texture/toviewport",v);q=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1, -precision:k.DEFAULT}};q.title="Copy";q.desc="Copy Texture";q.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:k.MODE_VALUES}};q.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,d=a.height;0!=this.properties.size&&(d=b=this.properties.size);var c=this._temp_texture,e=a.type;this.properties.precision===k.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===k.HIGH&& -(e=gl.HIGH_PRECISION_FORMAT);c&&c.width==b&&c.height==d&&c.type==e||(c=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(d)&&(c=gl.LINEAR_MIPMAP_LINEAR),this._temp_texture=new GL.Texture(b,d,{type:e,format:gl.RGBA,minFilter:c,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}};c.registerNodeType("texture/copy", -q);var h=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:k.DEFAULT}};h.title="Downsample";h.desc="Downsample Texture";h.widgets_info={iterations:{type:"number",step:1,precision:0,min:1},precision:{widget:"combo",values:k.MODE_VALUES}};h.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D){var b=h._shader;b||(h._shader= -b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,h.pixel_shader));var d=a.width|0,c=a.height|0,e=a.type;this.properties.precision===k.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===k.HIGH&&(e=gl.HIGH_PRECISION_FORMAT);var f=this.properties.iterations||1,g=a,m=null,n=[],a={type:e,format:a.format},e=vec2.create(),l={u_offset:e};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var q=0;q>1||0;c=c>>1||0;m=GL.Texture.getTemporary(d,c,a);n.push(m);g.setParameter(GL.TEXTURE_MAG_FILTER, -GL.NEAREST);g.copyTo(m,b,l);if(1==d&&1==c)break;g=m}this._texture=n.pop();for(q=0;qd;++d)b[d]=Math.random();l._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}d=this._temp_texture;b=gl.UNSIGNED_BYTE;a.type!=b&&(b=gl.FLOAT);d&&d.type==b||(this._temp_texture=new GL.Texture(1,1,{type:b,format:gl.RGBA,filter:gl.NEAREST}));var c=l._shader,e=this._uniforms;e.u_mipmap_offset=this.properties.mipmap_offset;this._temp_texture.drawTo(function(){a.toViewport(c,e)});if(this.isOutputConnected(1)||this.isOutputConnected(2))if(d=this._temp_texture.getPixels()){var f= -this._luminance,b=this._temp_texture.type;f.set(d);b==gl.UNSIGNED_BYTE&&vec4.scale(f,f,1/255)}}};l.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t"; -c.registerNodeType("texture/average",l);q=function(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}};q.title="Image to Texture";q.desc="Uploads an image to the GPU";q.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,d=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var c=this._temp_texture;c&&c.width==b&&c.height==d||(this._temp_texture=new GL.Texture(b,d,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(e){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+ -e);return}this.setOutputData(0,this._temp_texture)}}};c.registerNodeType("texture/imageToTexture",q);var p=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={intensity:1,precision:k.DEFAULT,texture:null};p._shader||(p._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,p.pixel_shader))};p.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:k.MODE_VALUES}};p.title="LUT";p.desc= -"Apply LUT to Texture";p.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===k.PASS_THROUGH)this.setOutputData(0,a);else if(a){var b=this.getInputData(1);b||(b=k.getTexture(this.properties.texture));if(b){b.bind(0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D, -null);var d=this.properties.intensity;this.isInputConnected(2)&&(this.properties.intensity=d=this.getInputData(2));this._tex=k.getTargetTexture(a,this._tex,this.properties.precision);this._tex.drawTo(function(){b.bind(1);a.toViewport(p._shader,{u_texture:0,u_textureB:1,u_amount:d})});this.setOutputData(0,this._tex)}else this.setOutputData(0,a)}}};p.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_amount;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t\t mediump vec2 quad1;\n\t\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t\t mediump vec2 quad2;\n\t\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t\t highp vec2 texPos1;\n\t\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t highp vec2 texPos2;\n\t\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t\t}\n\t\t\t"; -c.registerNodeType("texture/LUT",p);var s=function(){this.addInput("Texture","Texture");this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");this.properties={};s._shader||(s._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.pixel_shader))};s.title="Texture to Channels";s.desc="Split texture channels";s.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b=0,d=0;4>d;d++)this.isOutputConnected(d)? -(this._channels[d]&&this._channels[d].width==a.width&&this._channels[d].height==a.height&&this._channels[d].type==a.type||(this._channels[d]=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR})),b++):this._channels[d]=null;if(b){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);for(var c=Mesh.getScreenQuad(),e=s._shader,f=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],d=0;4>d;d++)this._channels[d]&&(this._channels[d].drawTo(function(){a.bind(0);e.uniforms({u_texture:0,u_mask:f[d]}).draw(c)}), -this.setOutputData(d,this._channels[d]))}}};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 vec4 u_mask;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t\t}\n\t\t\t";c.registerNodeType("texture/textureChannels",s);var a=function(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A", -"Texture");this.addOutput("Texture","Texture");this.properties={};a._shader||(a._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a.pixel_shader))};a.title="Channels to Texture";a.desc="Split texture channels";a.prototype.onExecute=function(){var b=[this.getInputData(0),this.getInputData(1),this.getInputData(2),this.getInputData(3)];if(b[0]&&b[1]&&b[2]&&b[3]){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),c=a._shader;this._tex=k.getTargetTexture(b[0],this._tex);this._tex.drawTo(function(){b[0].bind(0); -b[1].bind(1);b[2].bind(2);b[3].bind(3);c.uniforms({u_textureR:0,u_textureG:1,u_textureB:2,u_textureA:3}).draw(d)});this.setOutputData(0,this._tex)}};a.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_textureR;\n\t\t\tuniform sampler2D u_textureG;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform sampler2D u_textureA;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = vec4( \t\t\t\t\t\ttexture2D(u_textureR, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureG, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureB, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureA, v_coord).r);\n\t\t\t}\n\t\t\t"; -c.registerNodeType("texture/channelsTexture",a);q=function(){this.addOutput("Texture","Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:k.DEFAULT}};q.title="Color";q.desc="Generates a 1x1 texture with a constant color";q.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};q.prototype.onDrawBackground=function(a){var b=this.properties.color;a.fillStyle="rgb("+Math.floor(255*Math.clamp(b[0],0,1))+","+Math.floor(255*Math.clamp(b[1],0,1))+","+Math.floor(255* -Math.clamp(b[2],0,1))+")";this.flags.collapsed?this.boxcolor=a.fillStyle:a.fillRect(0,0,this.size[0],this.size[1])};q.prototype.onExecute=function(){var a=this.properties.precision==k.HIGH?k.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._tex&&this._tex.type==a||(this._tex=new GL.Texture(1,1,{format:gl.RGBA,type:a,minFilter:gl.NEAREST}));a=this.properties.color;if(this.inputs)for(var b=0;b 0.5 ? 1.0 : 0.0, diff.y > 0.5 ? 1.0 : 0.0, diff.z > 0.5 ? 1.0 : 0.0, center.a );\n\t\t\t}\n\t\t\t"; -c.registerNodeType("texture/edges",f);var e=function(){this.addInput("Texture","Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}};e.title="Depth Range";e.desc="Generates a texture with a depth range";e.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0); -if(a){var b=gl.UNSIGNED_BYTE;this.properties.high_precision&&(b=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&&this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGBA,filter:gl.LINEAR}));var d=this._uniforms,b=this.properties.distance;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.distance=b);var c=this.properties.range;this.isInputConnected(2)&& -(c=this.getInputData(2),this.properties.range=c);d.u_distance=b;d.u_range=c;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad();e._shader||(e._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,e.pixel_shader),e._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,e.pixel_shader,{ONLY_DEPTH:""}));var g=this.properties.only_depth?e._shader_onlydepth:e._shader,b=null,b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes: -[0.1,1E3];d.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);g.uniforms(d).draw(f)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}};e.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_distance;\n\t\t\tuniform float u_range;\n\t\t\t\n\t\t\tfloat LinearDepth()\n\t\t\t{\n\t\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat depth = LinearDepth();\n\t\t\t\t#ifdef ONLY_DEPTH\n\t\t\t\t gl_FragColor = vec4(depth);\n\t\t\t\t#else\n\t\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\t\tfloat dof = 1.0;\n\t\t\t\t\tif(diff <= u_range)\n\t\t\t\t\t\tdof = diff / u_range;\n\t\t\t\t gl_FragColor = vec4(dof);\n\t\t\t\t#endif\n\t\t\t}\n\t\t\t"; -c.registerNodeType("texture/depth_range",e);var m=function(){this.addInput("Texture","Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1],precision:k.DEFAULT}};m.title="Blur";m.desc="Blur a texture";m.widgets_info={precision:{widget:"combo",values:k.MODE_VALUES}};m.max_iterations=20;m.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b= -this._final_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var d=this.properties.iterations;this.isInputConnected(1)&&(d=this.getInputData(1),this.properties.iterations=d);d=Math.min(Math.floor(d),m.max_iterations);if(0==d)this.setOutputData(0,a);else{var e=this.properties.intensity;this.isInputConnected(2)&&(e=this.getInputData(2),this.properties.intensity=e);var f=c.camera_aspect; -f||void 0===window.gl||(f=gl.canvas.height/gl.canvas.width);f||(f=1);var f=this.properties.preserve_aspect?f:1,g=this.properties.scale||[1,1];a.applyBlur(f*g[0],g[1],e,b);for(a=1;a>=1;1<(d|0)&&(d>>=1);if(2>b)break;m=g[s]=GL.Texture.getTemporary(b,d,c);p[0]=1/l.width;p[1]=1/l.height;l.blit(m,h.uniforms(f));l=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})),p[0]=1/l.width,p[1]=1/l.height,f.u_intensity= -t,f.u_delta=1,l.blit(b,h.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(s-=2;0<=s;s--)m=g[s],g[s]=null,p[0]=1/l.width,p[1]=1/l.height,l.blit(m,h.uniforms(f)),GL.Texture.releaseTemporary(l),l=m;gl.disable(gl.BLEND);this.isOutputConnected(1)&&(g=this._glow_texture,g&&g.width==a.width&&g.height==a.height&&g.type==e&&g.format==a.format||(g=this._glow_texture=new GL.Texture(a.width,a.height,{type:e, -format:a.format,filter:gl.LINEAR})),l.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==e&&g.format==a.format||(g=this._final_texture=new GL.Texture(a.width,a.height,{type:e,format:a.format,filter:gl.LINEAR}));var r=this.getInputData(1),u=this.getInputOrProperty("dirt_factor");f.u_intensity=t;h=r?n._dirt_final_shader:n._final_shader;h||(h=r?n._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,n.final_pixel_shader, -{USE_DIRT:""}):n._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,n.final_pixel_shader));g.drawTo(function(){a.bind(0);l.bind(1);r&&(h.setUniform("u_dirt_factor",u),h.setUniform("u_dirt_texture",r.bind(2)));h.toViewport(f)});this.setOutputData(0,g)}GL.Texture.releaseTemporary(l)}};n.cut_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_threshold;\n\t\tvoid main() {\n\t\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t\t}"; -n.scale_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_texel_size;\n\t\tuniform float u_delta;\n\t\tuniform float u_intensity;\n\t\t\n\t\tvec4 sampleBox(vec2 uv) {\n\t\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\t\treturn s * 0.25;\n\t\t}\n\t\tvoid main() {\n\t\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t\t}"; -n.final_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_glow_texture;\n\t\t#ifdef USE_DIRT\n\t\t\tuniform sampler2D u_dirt_texture;\n\t\t#endif\n\t\tuniform vec2 u_texel_size;\n\t\tuniform float u_delta;\n\t\tuniform float u_intensity;\n\t\tuniform float u_dirt_factor;\n\t\t\n\t\tvec4 sampleBox(vec2 uv) {\n\t\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\t\tvec4 s = texture2D( u_glow_texture, uv + o.xy ) + texture2D( u_glow_texture, uv + o.zy) + texture2D( u_glow_texture, uv + o.xw) + texture2D( u_glow_texture, uv + o.zw);\n\t\t\treturn s * 0.25;\n\t\t}\n\t\tvoid main() {\n\t\t\tvec4 glow = sampleBox( v_coord );\n\t\t\t#ifdef USE_DIRT\n\t\t\t\tglow = mix( glow, glow * texture2D( u_dirt_texture, v_coord ), u_dirt_factor );\n\t\t\t#endif\n\t\t\tgl_FragColor = texture2D( u_texture, v_coord ) + u_intensity * glow;\n\t\t}"; -c.registerNodeType("texture/glow",n);var B=function(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}};B.title="Kuwahara Filter";B.desc="Filters a texture giving an artistic oil canvas painting";B.max_radius=10;B._shaders=[];B.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),B.max_radius);if(0==b)this.setOutputData(0,a);else{var d=this.properties.intensity,e=c.camera_aspect;e||void 0===window.gl||(e=gl.canvas.height/gl.canvas.width);e||(e=1);e=this.properties.preserve_aspect?e:1;B._shaders[b]||(B._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,B.pixel_shader,{RADIUS:b.toFixed(0)}));var f=B._shaders[b],g=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){f.uniforms({u_texture:0, -u_intensity:d,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(g)});this.setOutputData(0,this._temp_texture)}}};B.pixel_shader="\n\tprecision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_intensity;\n\tuniform vec2 u_resolution;\n\tuniform vec2 u_iResolution;\n\t#ifndef RADIUS\n\t\t#define RADIUS 7\n\t#endif\n\tvoid main() {\n\t\n\t\tconst int radius = RADIUS;\n\t\tvec2 fragCoord = v_coord;\n\t\tvec2 src_size = u_iResolution;\n\t\tvec2 uv = v_coord;\n\t\tfloat n = float((radius + 1) * (radius + 1));\n\t\tint i;\n\t\tint j;\n\t\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\t\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\t\tvec3 c;\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm0 += c;\n\t\t\t\ts0 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm1 += c;\n\t\t\t\ts1 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm2 += c;\n\t\t\t\ts2 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm3 += c;\n\t\t\t\ts3 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfloat min_sigma2 = 1e+2;\n\t\tm0 /= n;\n\t\ts0 = abs(s0 / n - m0 * m0);\n\t\t\n\t\tfloat sigma2 = s0.r + s0.g + s0.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m0, 1.0);\n\t\t}\n\t\t\n\t\tm1 /= n;\n\t\ts1 = abs(s1 / n - m1 * m1);\n\t\t\n\t\tsigma2 = s1.r + s1.g + s1.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m1, 1.0);\n\t\t}\n\t\t\n\t\tm2 /= n;\n\t\ts2 = abs(s2 / n - m2 * m2);\n\t\t\n\t\tsigma2 = s2.r + s2.g + s2.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m2, 1.0);\n\t\t}\n\t\t\n\t\tm3 /= n;\n\t\ts3 = abs(s3 / n - m3 * m3);\n\t\t\n\t\tsigma2 = s3.r + s3.g + s3.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m3, 1.0);\n\t\t}\n\t}\n\t"; -c.registerNodeType("texture/kuwahara",B);var A=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0};A.title="Webcam";A.desc="Webcam texture";A.is_webcam_open=!1;A.prototype.openStream=function(){function a(d){A.is_webcam_open=!1;console.log("Webcam rejected",d);b._webcam_stream=!1;b.boxcolor="red";b.trigger("stream_error")}if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1, -video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this))["catch"](a);var b=this}};A.prototype.closeStream=function(){if(this._webcam_stream){var a=this._webcam_stream.getTracks();if(a.length)for(var b=0;b=this.size[1]||!this._video||(a.save(),a.webgl?this._video_texture&&a.drawImage(this._video_texture,0,0,this.size[0],this.size[1]):a.drawImage(this._video,0,0,this.size[0],this.size[1]),a.restore())};A.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,d=this._video_texture;d&&d.width==a&&d.height==b||(this._video_texture=new GL.Texture(a,b,{format:gl.RGB, -filter:gl.LINEAR}));this._video_texture.uploadImage(this._video);this._video_texture.version=++this.version;this.properties.texture_name&&(k.getTexturesContainer()[this.properties.texture_name]=this._video_texture);this.setOutputData(0,this._video_texture);for(a=1;a=this.size[1]||a.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};c.registerNodeType("texture/cubemap",q)}})(this); -(function(w){var c=w.LiteGraph;if("undefined"!=typeof GL){var k=function(){this.addInput("Texture","Texture");this.addInput("Aberration","number");this.addInput("Distortion","number");this.addInput("Blur","number");this.addOutput("Texture","Texture");this.properties={aberration:1,distortion:1,blur:1,precision:LGraphTexture.DEFAULT};k._shader||(k._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,k.pixel_shader),k._texture=new GL.Texture(3,1,{format:gl.RGB,wrap:gl.CLAMP_TO_EDGE,magFilter:gl.LINEAR, -minFilter:gl.LINEAR,pixel_data:[255,0,0,0,255,0,0,0,255]}))};k.title="Lens";k.desc="Camera Lens distortion";k.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};k.prototype.onExecute=function(){var 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 g=this.properties.aberration;this.isInputConnected(1)&&(g=this.getInputData(1), -this.properties.aberration=g);var q=this.properties.distortion;this.isInputConnected(2)&&(q=this.getInputData(2),this.properties.distortion=q);var r=this.properties.blur;this.isInputConnected(3)&&(r=this.getInputData(3),this.properties.blur=r);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad(),l=k._shader;this._tex.drawTo(function(){c.bind(0);l.uniforms({u_texture:0,u_aberration:g,u_distortion:q,u_blur:r}).draw(h)});this.setOutputData(0,this._tex)}};k.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t"; -c.registerNodeType("fx/lens",k);w.LGraphFXLens=k;var r=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}};r.title="Bokeh";r.desc="applies an Bokeh effect";r.widgets_info={shape:{widget:"texture"}};r.prototype.onExecute=function(){var c=this.getInputData(0),g=this.getInputData(1),k=this.getInputData(2); -if(c&&k&&this.properties.shape){g||(g=c);var q=LGraphTexture.getTexture(this.properties.shape);if(q){var h=this.properties.threshold;this.isInputConnected(3)&&(h=this.getInputData(3),this.properties.threshold=h);var l=gl.UNSIGNED_BYTE;this.properties.high_precision&&(l=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==l&&this._temp_texture.width==c.width&&this._temp_texture.height==c.height||(this._temp_texture=new GL.Texture(c.width,c.height,{type:l,format:gl.RGBA, -filter:gl.LINEAR}));var p=r._first_shader;p||(p=r._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,r._first_pixel_shader));var s=r._second_shader;s||(s=r._second_shader=new GL.Shader(r._second_vertex_shader,r._second_pixel_shader));var a=this._points_mesh;a&&a._width==c.width&&a._height==c.height&&2==a._spacing||(a=this.createPointsMesh(c.width,c.height,2));var b=Mesh.getScreenQuad(),d=this.properties.size,f=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){c.bind(0); -g.bind(1);k.bind(2);p.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[c.width,c.height]}).draw(b)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);c.bind(0);q.bind(3);s.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:f,u_threshold:h,u_pointSize:d,u_itexsize:[1/c.width,1/c.height]}).draw(a,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,c)};r.prototype.createPointsMesh=function(c,g,k){for(var q=Math.round(c/k),h=Math.round(g/ -k),l=new Float32Array(q*h*2),p=-1,s=2/c*k,a=2/g*k,b=0;b=c.NOTEON||b<=c.NOTEOFF)this.channel=a&15};Object.defineProperty(c.prototype, -"velocity",{get:function(){return this.cmd==c.NOTEON?this.data[2]:-1},set:function(a){this.data[2]=a},enumerable:!0});c.notes="A A# B C C# D D# E F F# G G#".split(" ");c.note_to_index={A:0,"A#":1,B:2,C:3,"C#":4,D:5,"D#":6,E:7,F:8,"F#":9,G:10,"G#":11};Object.defineProperty(c.prototype,"note",{get:function(){return this.cmd!=c.NOTEON?-1:c.toNoteString(this.data[1],!0)},set:function(a){throw"notes cannot be assigned this way, must modify the data[1]";},enumerable:!0});Object.defineProperty(c.prototype, -"octave",{get:function(){return this.cmd!=c.NOTEON?-1:Math.floor((this.data[1]-24)/12+1)},set:function(a){throw"octave cannot be assigned this way, must modify the data[1]";},enumerable:!0});c.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};c.computePitch=function(a){return 440*Math.pow(2,(a-69)/12)};c.prototype.getCC=function(){return this.data[1]};c.prototype.getCCValue=function(){return this.data[2]};c.prototype.getPitchBend=function(){return this.data[1]+(this.data[2]<< -7)-8192};c.computePitchBend=function(a,b){return a+(b<<7)-8192};c.prototype.setCommandFromString=function(a){this.cmd=c.computeCommandFromString(a)};c.computeCommandFromString=function(a){if(!a)return 0;if(a&&a.constructor===Number)return a;a=a.toUpperCase();switch(a){case "NOTE ON":case "NOTEON":return c.NOTEON;case "NOTE OFF":case "NOTEOFF":return c.NOTEON;case "KEY PRESSURE":case "KEYPRESSURE":return c.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return c.CONTROLLERCHANGE; -case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return c.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return c.CHANNELPRESSURE;case "PITCH BEND":case "PITCHBEND":return c.PITCHBEND;case "TIME TICK":case "TIMETICK":return c.TIMETICK;default:return Number(a)}};c.toNoteString=function(a,b){a=Math.round(a);var e,g=Math.floor((a-24)/12+1);e=(a-21)%12;0>e&&(e=12+e);return c.notes[e]+(b?"":g)};c.NoteStringToPitch=function(a){a=a.toUpperCase();var b=a[0],e=4;"#"==a[1]?(b+="#",2this.properties.max_value)return;this.trigger("on_midi",b)}};a.registerNodeType("midi/filter",t);u.title="MIDIEvent";u.desc="Create a MIDI Event";u.color="#243";u.prototype.onAction=function(a,b){"assign"==a?(this.properties.channel=b.channel,this.properties.cmd=b.cmd,this.properties.value1=b.data[1],this.properties.value2=b.data[2]):(b= -this.midi_event,b.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?b.setCommandFromString(this.properties.cmd):b.cmd=this.properties.cmd,b.data[0]=b.cmd|b.channel,b.data[1]=Number(this.properties.value1),b.data[2]=Number(this.properties.value2),this.trigger("on_midi",b))};u.prototype.onExecute=function(){var a=this.properties;if(this.inputs)for(var b=0;ba;++a)this.valid_notes[a]=-1!=this.notes_pitches.indexOf(a);for(a=0;12>a;++a)if(this.valid_notes[a])this.offset_notes[a]=0;else for(var b=1;12>b;++b){if(this.valid_notes[(a-b)%12]){this.offset_notes[a]=-b;break}if(this.valid_notes[(a+b)%12]){this.offset_notes[a]=b;break}}};l.prototype.onAction=function(a,b){b&&b.constructor===c&&(b.data[0]==c.NOTEON||b.data[0]==c.NOTEOFF?(this.midi_event=new c,this.midi_event.setup(b.data), -this.midi_event.data[1]+=this.offset_notes[c.note_to_index[b.note]],this.trigger("out",this.midi_event)):this.trigger("out",b))};l.prototype.onExecute=function(){var a=this.getInputData(1);null!=a&&a!=this._current_scale&&this.processScale(a)};a.registerNodeType("midi/quantize",l);p.title="MIDI Play";p.desc="Plays a MIDI note";p.color="#243";p.prototype.onAction=function(a,b){if(b&&b.constructor===c){if(this.instrument&&b.data[0]==c.NOTEON){var e=b.note;if(!e||"undefined"==e||e.constructor!==String)return; -this.instrument.play(e,b.octave,this.properties.duration,this.properties.volume)}this.trigger("note",b)}};p.prototype.onExecute=function(){var a=this.getInputData(1);null!=a&&(this.properties.volume=a);a=this.getInputData(2);null!=a&&(this.properties.duration=a)};a.registerNodeType("midi/play",p);s.title="MIDI Keys";s.desc="Keyboard to play notes";s.color="#243";s.keys=[{x:0,w:1,h:1,t:0},{x:0.75,w:0.5,h:0.6,t:1},{x:1,w:1,h:1,t:0},{x:1.75,w:0.5,h:0.6,t:1},{x:2,w:1,h:1,t:0},{x:2.75,w:0.5,h:0.6,t:1}, -{x:3,w:1,h:1,t:0},{x:4,w:1,h:1,t:0},{x:4.75,w:0.5,h:0.6,t:1},{x:5,w:1,h:1,t:0},{x:5.75,w:0.5,h:0.6,t:1},{x:6,w:1,h:1,t:0}];s.prototype.onDrawBackground=function(a){if(!this.flags.collapsed){var b=12*this.properties.num_octaves;this.keys.length=b;for(var c=this.size[0]/(7*this.properties.num_octaves),g=this.size[1],h=0;2>h;h++)for(var k=0;kl+q||a[1]>k))return h}}return-1};s.prototype.onAction=function(a,b){if("reset"==a)for(var e=0;eb[1])){var e=this.getKeyIndex(b);this.keys[e]=!0;this._last_key=e;var e=12*(this.properties.start_octave-1)+29+e,g=new c;g.setup([c.NOTEON,e,100]);this.trigger("note",g);return!0}};s.prototype.onMouseMove=function(a,b){if(!(0>b[1]||-1==this._last_key)){this.setDirtyCanvas(!0);var e=this.getKeyIndex(b);if(this._last_key==e)return!0;this.keys[this._last_key]= -!1;var g=12*(this.properties.start_octave-1)+29+this._last_key,h=new c;h.setup([c.NOTEOFF,g,100]);this.trigger("note",h);this.keys[e]=!0;g=12*(this.properties.start_octave-1)+29+e;h=new c;h.setup([c.NOTEON,g,100]);this.trigger("note",h);this._last_key=e;return!0}};s.prototype.onMouseUp=function(a,b){if(!(0>b[1])){var e=this.getKeyIndex(b);this.keys[e]=!1;this._last_key=-1;var e=12*(this.properties.start_octave-1)+29+e,g=new c;g.setup([c.NOTEOFF,e,100]);this.trigger("note",g);return!0}};a.registerNodeType("midi/keys", -s)})(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=f.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function k(){this.properties={gain:0.5};this._audionodes=[];this._media_stream= -null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=f.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function r(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:0.5};this.audionode=f.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 q(){this.properties={gain:1};this.audionode=f.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function g(){this.properties={impulse_src:"",normalize:!0};this.audionode=f.getAudioContext().createConvolver(); -this.addInput("in","audio");this.addOutput("out","audio")}function t(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=f.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function u(){this.properties={};this.audionode=f.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function y(){this.properties={gain1:0.5,gain2:0.5}; -this.audionode=f.getAudioContext().createGain();this.audionode1=f.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=f.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= -{delayTime:0.5};this.audionode=f.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function h(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type","lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});this.audionode=f.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out", -"audio")}function l(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=f.getAudioContext().createOscillator();this.addOutput("out","audio")}function p(){this.properties={continuous:!0,mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function s(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal", -"number")}function a(){if(!a.default_code){var b=a.default_function.toString(),c=b.indexOf("{")+1,d=b.lastIndexOf("}");a.default_code=b.substr(c,d-c)}this.properties={code:a.default_code};b=f.getAudioContext();b.createScriptProcessor?this.audionode=b.createScriptProcessor(4096,1,1):(console.warn("ScriptProcessorNode deprecated"),this.audionode=b.createGain());this.processCode();a._bypass_function||(a._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out", -"audio")}function b(){this.audionode=f.getAudioContext().destination;this.addInput("in","audio")}var d=w.LiteGraph,f={};w.LGAudio=f;f.getAudioContext=function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"),null;this._audio_context=new AudioContext;this._audio_context.onmessage=function(a){console.log("msg",a)};this._audio_context.onended=function(a){console.log("ended", -a)};this._audio_context.oncomplete=function(a){console.log("complete",a)}}return this._audio_context};f.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};f.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};f.changeAllAudiosConnections=function(a,b){if(a.inputs)for(var c=0;c=this.size[0]&&(g=this.size[0]-1),a.strokeStyle="red",a.beginPath(),a.moveTo(g,d),a.lineTo(g,0),a.stroke())}};p.title="Visualization";p.desc="Audio Visualization";d.registerNodeType("audio/visualization",p);s.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var a=this.properties.band,b=this.getInputData(1);void 0!==b&&(a=b);b=f.getAudioContext().sampleRate/this._freqs.length; -b=a/b*2;b>=this._freqs.length?b=this._freqs[this._freqs.length-1]:(a=b|0,b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.properties.amplitude)}};s.prototype.onGetInputs=function(){return[["band","number"]]};s.title="Signal";s.desc="extract the signal of some frequency";d.registerNodeType("audio/signal",s);a.prototype.onAdded=function(a){a.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};a["@code"]={widget:"code"};a.prototype.onStart=function(){this.audionode.onaudioprocess= -this._callback};a.prototype.onStop=function(){this.audionode.onaudioprocess=a._bypass_function};a.prototype.onPause=function(){this.audionode.onaudioprocess=a._bypass_function};a.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};a.prototype.onExecute=function(){};a.prototype.onRemoved=function(){this.audionode.onaudioprocess=a._bypass_function};a.prototype.processCode=function(){try{this._script=new new Function("properties",this.properties.code)(this.properties),this._old_code= -this.properties.code,this._callback=this._script.onaudioprocess}catch(b){console.error("Error in onaudioprocess code",b),this._callback=a._bypass_function,this.audionode.onaudioprocess=this._callback}};a.prototype.onPropertyChanged=function(a,b){"code"==a&&(this.properties.code=b,this.processCode(),this.graph&&this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};a.default_function=function(){this.onaudioprocess=function(a){var b=a.inputBuffer;a=a.outputBuffer; -for(var c=0;c","string",{values:a.values});this.size=[60,40]}function b(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function e(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function r(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number"); +this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,e){e.properties.formula=a});this.addWidget("toggle","allow",p.allow_scripts,function(a){p.allow_scripts=a});this._func=null}function h(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function G(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function J(){this.addInput("vec3", +"vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function F(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)}function H(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function I(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]); +this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var p=u.LiteGraph;d.title="Converter";d.desc="type A to type B";d.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;ba&&(a+=1024);var c=Math.floor(a);a-=c;e=m.data[c];c=m.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return e*(1-a)+c*a};m.prototype.onExecute=function(){var a=this.getInputData(0)||0,a=m.getValue(a,this.properties.smooth),b=this.properties.min;this._last_v=a*(this.properties.max-b)+b;this.setOutputData(0, +this._last_v)};m.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};p.registerNodeType("math/noise",m);w.title="Spikes";w.desc="spike every random time";w.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+ +this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};p.registerNodeType("math/spikes",w);B.title="Clamp";B.desc="Clamp number between min and max";B.filter="shader";B.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};B.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+ +","+this.properties.max+")");return a};p.registerNodeType("math/clamp",B);z.title="Lerp";z.desc="Linear Interpolation";z.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);null==b&&(b=0);var e=this.properties.f,c=this.getInputData(2);void 0!==c&&(e=c);this.setOutputData(0,a*(1-e)+b*e)};z.prototype.onGetInputs=function(){return[["f","number"]]};p.registerNodeType("math/lerp",z);y.title="Abs";y.desc="Absolute";y.prototype.onExecute=function(){var a=this.getInputData(0); +null!=a&&this.setOutputData(0,Math.abs(a))};p.registerNodeType("math/abs",y);c.title="Floor";c.desc="Floor number to remove fractional part";c.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};p.registerNodeType("math/floor",c);x.title="Frac";x.desc="Returns fractional part";x.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};p.registerNodeType("math/frac",x);n.title="Smoothstep";n.desc="Smoothstep"; +n.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A,a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}};p.registerNodeType("math/smoothstep",n);f.title="Scale";f.desc="v * factor";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};p.registerNodeType("math/scale",f);A.title="Average";A.desc="Average Filter";A.prototype.onExecute=function(){var a=this.getInputData(0); +null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var e=a=0;eb&&(b=1);this.properties.samples=Math.round(b);var e=this._values;this._values=new Float32Array(this.properties.samples);e.length<=this._values.length?this._values.set(e):this._values.set(e.subarray(0,this._values.length))};p.registerNodeType("math/average",A);k.title= +"TendTo";k.desc="moves the output value always closer to the input";k.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};p.registerNodeType("math/tendTo",k);t.values="+-*/%^".split("");t.title="Operation";t.desc="Easy math operators";t["@OP"]={type:"enum",title:"operation",values:t.values};t.size=[100,50];t.prototype.getTitle=function(){return"A "+this.properties.OP+ +" B"};t.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};t.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=b:b=this.properties.B;var e=0;switch(this.properties.OP){case "+":e=a+b;break;case "-":e=a-b;break;case "x":case "X":case "*":e=a*b;break;case "/":e=a/b;break;case "%":e=a%b;break;case "^":e=Math.pow(a,b);break;default:console.warn("Unknown operation: "+ +this.properties.OP)}this.setOutputData(0,e)};t.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#666",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.5*(this.size[1]+p.NODE_TITLE_HEIGHT)),a.textAlign="left")};p.registerNodeType("math/operation",t);v.title="Compare";v.desc="compares between two values";v.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A; +void 0!==b?this.properties.B=b:b=this.properties.B;for(var e=0,c=this.outputs.length;eB":value=a>b;break;case "A=B":value=a>=b}this.setOutputData(e,value)}}};v.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]}; +p.registerNodeType("math/compare",v);p.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});p.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});p.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});p.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"});p.registerSearchboxExtra("math/compare", +"<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});a.values="> < == != <= >=".split(" ");a["@OP"]={type:"enum",title:"operation",values:a.values};a.title="Condition";a.desc="evaluates condition between A and B";a.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var e=!0;switch(this.properties.OP){case ">":e=a>b;break;case "<":e=a=":e=a>=b}this.setOutputData(0,e)};p.registerNodeType("math/condition",a);b.title="Accumulate";b.desc="Increments a value every time";b.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};p.registerNodeType("math/accumulate",b);e.title="Trigonometry"; +e.desc="Sin Cos Tan";e.filter="shader";e.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,e=this.findInputSlot("amplitude");-1!=e&&(b=this.getInputData(e));var c=this.properties.offset,e=this.findInputSlot("offset");-1!=e&&(c=this.getInputData(e));for(var e=0,d=this.outputs.length;eVec2";G.desc="components to vector2";G.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var e=this._data;e[0]=a;e[1]=b;this.setOutputData(0,e)};p.registerNodeType("math3d/xy-to-vec2", +G);J.title="Vec3->XYZ";J.desc="vector 3 to components";J.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};p.registerNodeType("math3d/vec3-to-xyz",J);F.title="XYZ->Vec3";F.desc="components to vector3";F.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var e=this.getInputData(2);null==e&&(e=this.properties.z); +var c=this._data;c[0]=a;c[1]=b;c[2]=e;this.setOutputData(0,c)};p.registerNodeType("math3d/xyz-to-vec3",F);H.title="Vec4->XYZW";H.desc="vector 4 to components";H.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};p.registerNodeType("math3d/vec4-to-xyzw",H);I.title="XYZW->Vec4";I.desc="components to vector4";I.prototype.onExecute=function(){var a=this.getInputData(0);null== +a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var e=this.getInputData(2);null==e&&(e=this.properties.z);var c=this.getInputData(3);null==c&&(c=this.properties.w);var d=this._data;d[0]=a;d[1]=b;d[2]=e;d[3]=c;this.setOutputData(0,d)};p.registerNodeType("math3d/xyzw-to-vec4",I);u.glMatrix&&(u=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},u.title="Quaternion",u.desc="quaternion",u.prototype.onExecute=function(){this._value[0]= +this.properties.x;this._value[1]=this.properties.y;this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},p.registerNodeType("math3d/quaternion",u),u=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},u.title="Rotation",u.desc="quaternion rotation",u.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.angle); +var b=this.getInputData(1);null==b&&(b=this.properties.axis);a=quat.setAxisAngle(this._value,b,0.0174532925*a);this.setOutputData(0,a)},p.registerNodeType("math3d/rotation",u),u=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},u.title="Rot. Vec3",u.desc="rotate a point",u.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.vec);var b=this.getInputData(1);null==b?this.setOutputData(a):this.setOutputData(0, +vec3.transformQuat(vec3.create(),a,b))},p.registerNodeType("math3d/rotate_vec3",u),u=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},u.title="Mult. Quat",u.desc="rotate quaternion",u.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);null!=b&&(a=quat.multiply(this._value,a,b),this.setOutputData(0,a))}},p.registerNodeType("math3d/mult-quat",u),u=function(){this.addInputs([["A","quat"],["B", +"quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},u.title="Quat Slerp",u.desc="quaternion spherical interpolation",u.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);if(null!=b){var e=this.properties.factor;null!=this.getInputData(2)&&(e=this.getInputData(2));a=quat.slerp(this._value,a,b,e);this.setOutputData(0,a)}}},p.registerNodeType("math3d/quat-slerp",u))})(this); +(function(u){function d(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function l(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function q(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function g(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties= +{x:0,y:0,z:0};this._data=new Float32Array(3)}function s(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function m(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}function w(){this.addInput("in","vec3");this.addInput("f","number");this.addOutput("out","vec3");this.properties= +{f:1};this._data=new Float32Array(3)}function B(){this.addInput("in","vec3");this.addOutput("out","number")}function z(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function y(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:0.5};this._data=new Float32Array(3)}function c(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out","number")}var x=u.LiteGraph;d.title= +"Vec2->XY";d.desc="vector 2 to components";d.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.setOutputData(0,c[0]),this.setOutputData(1,c[1]))};x.registerNodeType("math3d/vec2-to-xyz",d);l.title="XY->Vec2";l.desc="components to vector2";l.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.x);var d=this.getInputData(1);null==d&&(d=this.properties.y);var g=this._data;g[0]=c;g[1]=d;this.setOutputData(0,g)};x.registerNodeType("math3d/xy-to-vec2", +l);q.title="Vec3->XYZ";q.desc="vector 3 to components";q.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.setOutputData(0,c[0]),this.setOutputData(1,c[1]),this.setOutputData(2,c[2]))};x.registerNodeType("math3d/vec3-to-xyz",q);g.title="XYZ->Vec3";g.desc="components to vector3";g.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.x);var d=this.getInputData(1);null==d&&(d=this.properties.y);var g=this.getInputData(2);null==g&&(g=this.properties.z); +var k=this._data;k[0]=c;k[1]=d;k[2]=g;this.setOutputData(0,k)};x.registerNodeType("math3d/xyz-to-vec3",g);s.title="Vec4->XYZW";s.desc="vector 4 to components";s.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.setOutputData(0,c[0]),this.setOutputData(1,c[1]),this.setOutputData(2,c[2]),this.setOutputData(3,c[3]))};x.registerNodeType("math3d/vec4-to-xyzw",s);m.title="XYZW->Vec4";m.desc="components to vector4";m.prototype.onExecute=function(){var c=this.getInputData(0);null== +c&&(c=this.properties.x);var d=this.getInputData(1);null==d&&(d=this.properties.y);var g=this.getInputData(2);null==g&&(g=this.properties.z);var k=this.getInputData(3);null==k&&(k=this.properties.w);var m=this._data;m[0]=c;m[1]=d;m[2]=g;m[3]=k;this.setOutputData(0,m)};x.registerNodeType("math3d/xyzw-to-vec4",m);w.title="vec3_scale";w.desc="scales the components of a vec3";w.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);null==d&&(d=this.properties.f); +var g=this._data;g[0]=c[0]*d;g[1]=c[1]*d;g[2]=c[2]*d;this.setOutputData(0,g)}};x.registerNodeType("math3d/vec3-scale",w);B.title="vec3_length";B.desc="returns the module of a vector";B.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(c=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),this.setOutputData(0,c))};x.registerNodeType("math3d/vec3-length",B);z.title="vec3_normalize";z.desc="returns the vector normalized";z.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d= +Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),g=this._data;g[0]=c[0]/d;g[1]=c[1]/d;g[2]=c[2]/d;this.setOutputData(0,g)}};x.registerNodeType("math3d/vec3-normalize",z);y.title="vec3_lerp";y.desc="returns the interpolated vector";y.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);if(null!=d){var g=this.getInputOrProperty("f"),k=this._data;k[0]=c[0]*(1-g)+d[0]*g;k[1]=c[1]*(1-g)+d[1]*g;k[2]=c[2]*(1-g)+d[2]*g;this.setOutputData(0,k)}}};x.registerNodeType("math3d/vec3-lerp", +y);c.title="vec3_dot";c.desc="returns the dot product";c.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);null!=d&&this.setOutputData(0,c[0]*d[0]+c[1]*d[1]+c[2]*d[2])}};x.registerNodeType("math3d/vec3-dot",c);u.glMatrix&&(u=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},u.title="Quaternion",u.desc="quaternion",u.prototype.onExecute=function(){this._value[0]=this.properties.x;this._value[1]=this.properties.y; +this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},x.registerNodeType("math3d/quaternion",u),u=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},u.title="Rotation",u.desc="quaternion rotation",u.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.angle);var d=this.getInputData(1);null==d&& +(d=this.properties.axis);c=quat.setAxisAngle(this._value,d,0.0174532925*c);this.setOutputData(0,c)},x.registerNodeType("math3d/rotation",u),u=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},u.title="Rot. Vec3",u.desc="rotate a point",u.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.vec);var d=this.getInputData(1);null==d?this.setOutputData(c):this.setOutputData(0,vec3.transformQuat(vec3.create(), +c,d))},x.registerNodeType("math3d/rotate_vec3",u),u=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},u.title="Mult. Quat",u.desc="rotate quaternion",u.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);null!=d&&(c=quat.multiply(this._value,c,d),this.setOutputData(0,c))}},x.registerNodeType("math3d/mult-quat",u),u=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp", +"quat");this.addProperty("factor",0.5);this._value=quat.create()},u.title="Quat Slerp",u.desc="quaternion spherical interpolation",u.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var d=this.getInputData(1);if(null!=d){var g=this.properties.factor;null!=this.getInputData(2)&&(g=this.getInputData(2));c=quat.slerp(this._value,c,d,g);this.setOutputData(0,c)}}},x.registerNodeType("math3d/quat-slerp",u))})(this); +(function(u){function d(d,g){return d==g}function l(d){return null!=d&&d.constructor===String?d.toUpperCase():d}u=u.LiteGraph;u.wrapFunctionAsNode("string/toString",d,["*"],"String");u.wrapFunctionAsNode("string/compare",d,["String","String"],"Boolean");u.wrapFunctionAsNode("string/concatenate",function(d,g){return void 0===d?g:void 0===g?d:d+g},["String","String"],"String");u.wrapFunctionAsNode("string/contains",function(d,g){return void 0===d||void 0===g?!1:-1!=d.indexOf(g)},["String","String"], +"Boolean");u.wrapFunctionAsNode("string/toUpperCase",l,["String"],"String");u.wrapFunctionAsNode("string/split",l,["String","String"],"Array")})(this); +(function(u){function d(){this.addInput("sel","number");this.addInput("A");this.addInput("B");this.addInput("C");this.addInput("D");this.addOutput("out");this.selected=0}function l(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}var q=u.LiteGraph;d.title="Selector";d.desc="selects an output";d.prototype.onDrawBackground=function(d){if(!this.flags.collapsed){d.fillStyle="#AFB"; +var l=(this.selected+1)*q.NODE_SLOT_HEIGHT+6;d.beginPath();d.moveTo(50,l);d.lineTo(50,l+q.NODE_SLOT_HEIGHT);d.lineTo(34,l+0.5*q.NODE_SLOT_HEIGHT);d.fill()}};d.prototype.onExecute=function(){var d=this.getInputData(0);null==d&&(d=0);this.selected=d=Math.round(d)%(this.inputs.length-1);d=this.getInputData(d+1);void 0!==d&&this.setOutputData(0,d)};d.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};q.registerNodeType("logic/selector",d);l.title="Sequence";l.desc="select one element from a sequence from a string"; +l.prototype.onPropertyChanged=function(d,l){"sequence"==d&&(this.values=l.split(","))};l.prototype.onExecute=function(){var d=this.getInputData(1);d&&d!=this.current_sequence&&(this.values=d.split(","),this.current_sequence=d);d=this.getInputData(0);null==d&&(d=0);this.index=d=Math.round(d)%this.values.length;this.setOutputData(0,this.values[d])};q.registerNodeType("logic/sequence",l)})(this); +(function(u){function d(){this.addInput("A","Number");this.addInput("B","Number");this.addInput("C","Number");this.addInput("D","Number");this.values=[[],[],[],[]];this.properties={scale:2}}function l(){this.addOutput("frame","image");this.properties={url:""}}function q(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function g(){this.addInput("","image,canvas");this.size=[200,200]}function s(){this.addInputs([["img1", +"image"],["img2","image"],["fade","number"]]);this.addOutput("","image");this.properties={fade:0.5,width:512,height:512}}function m(){this.addInput("","image");this.addOutput("","image");this.properties={width:256,height:256,x:0,y:0,scale:1};this.size=[50,20]}function w(){this.addInput("clear",x.ACTION);this.addOutput("","canvas");this.properties={width:512,height:512,autoclear:!0};this.canvas=document.createElement("canvas");this.ctx=this.canvas.getContext("2d")}function B(){this.addInput("canvas", +"canvas");this.addInput("img","image,canvas");this.addInput("x","number");this.addInput("y","number");this.properties={x:0,y:0,opacity:1}}function z(){this.addInput("canvas","canvas");this.addInput("x","number");this.addInput("y","number");this.addInput("w","number");this.addInput("h","number");this.properties={x:0,y:0,w:10,h:10,color:"white",opacity:1}}function y(){this.addInput("t","number");this.addOutputs([["frame","image"],["t","number"],["d","number"]]);this.properties={url:"",use_proxy:!0}} +function c(){this.addOutput("Webcam","image");this.properties={facingMode:"user"};this.boxcolor="black";this.frame=0}var x=u.LiteGraph;d.title="Plot";d.desc="Plots data over time";d.colors=["#FFF","#F99","#9F9","#99F"];d.prototype.onExecute=function(c){if(!this.flags.collapsed){c=this.size;for(var d=0;4>d;++d){var g=this.getInputData(d);if(null!=g){var k=this.values[d];k.push(g);k.length>c[0]&&k.shift()}}}};d.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var f=this.size,g=0.5*f[1]/ +this.properties.scale,k=d.colors,m=0.5*f[1];c.fillStyle="#000";c.fillRect(0,0,f[0],f[1]);c.strokeStyle="#555";c.beginPath();c.moveTo(0,m);c.lineTo(f[0],m);c.stroke();if(this.inputs)for(var l=0;4>l;++l){var a=this.values[l];if(this.inputs[l]&&this.inputs[l].link){c.strokeStyle=k[l];c.beginPath();var b=a[0]*g*-1+m;c.moveTo(0,Math.clamp(b,0,f[1]));for(var e=1;ed&&(d=0);if(0!=c.length){var g=[0,0,0];if(0==d)g=c[0];else if(1==d)g=c[c.length-1];else{var k=(c.length-1)*d,d=c[Math.floor(k)],c=c[Math.floor(k)+1],k=k-Math.floor(k);g[0]=d[0]* +(1-k)+c[0]*k;g[1]=d[1]*(1-k)+c[1]*k;g[2]=d[2]*(1-k)+c[2]*k}for(var m in g)g[m]/=255;this.boxcolor=colorToString(g);this.setOutputData(0,g)}};x.registerNodeType("color/palette",q);g.title="Frame";g.desc="Frame viewerew";g.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"view",text:"View Image",type:"button"}];g.prototype.onDrawBackground=function(c){this.frame&&!this.flags.collapsed&&c.drawImage(this.frame,0,0,this.size[0],this.size[1])};g.prototype.onExecute=function(){this.frame=this.getInputData(0); +this.setDirtyCanvas(!0)};g.prototype.onWidget=function(c,d){if("resize"==d.name&&this.frame){var g=this.frame.width,k=this.frame.height;g||null==this.frame.videoWidth||(g=this.frame.videoWidth,k=this.frame.videoHeight);g&&k&&(this.size=[g,k]);this.setDirtyCanvas(!0,!0)}else"view"==d.name&&this.show()};g.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};x.registerNodeType("graphics/frame",g);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 d=this.getInputData(0);null!=d&&c.drawImage(d,0,0,this.canvas.width,this.canvas.height);d=this.getInputData(2);null==d?d=this.properties.fade:this.properties.fade=d;c.globalAlpha=d;d=this.getInputData(1);null!=d&&c.drawImage(d,0,0,this.canvas.width,this.canvas.height);c.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};x.registerNodeType("graphics/imagefade",s);m.title="Crop";m.desc="Crop Image";m.prototype.onAdded=function(){this.createCanvas()};m.prototype.createCanvas= +function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};m.prototype.onExecute=function(){var c=this.getInputData(0);c&&(c.width?(this.canvas.getContext("2d").drawImage(c,-this.properties.x,-this.properties.y,c.width*this.properties.scale,c.height*this.properties.scale),this.setOutputData(0,this.canvas)):this.setOutputData(0,null))};m.prototype.onDrawBackground=function(c){this.flags.collapsed||this.canvas&&c.drawImage(this.canvas, +0,0,this.canvas.width,this.canvas.height,0,0,this.size[0],this.size[1])};m.prototype.onPropertyChanged=function(c,d){this.properties[c]=d;"scale"==c?(this.properties[c]=parseFloat(d),0==this.properties[c]&&(this.trace("Error in scale"),this.properties[c]=1)):this.properties[c]=parseInt(d);this.createCanvas();return!0};x.registerNodeType("graphics/cropImage",m);w.title="Canvas";w.desc="Canvas to render stuff";w.prototype.onExecute=function(){var c=this.canvas,d=this.properties.width|0,g=this.properties.height| +0;c.width!=d&&(c.width=d);c.height!=g&&(c.height=g);this.properties.autoclear&&this.ctx.clearRect(0,0,c.width,c.height);this.setOutputData(0,c)};w.prototype.onAction=function(c,d){"clear"==c&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)};x.registerNodeType("graphics/canvas",w);B.title="DrawImage";B.desc="Draws image into a canvas";B.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var d=this.getInputOrProperty("img");if(d){var g=this.getInputOrProperty("x"),k=this.getInputOrProperty("y"); +c.getContext("2d").drawImage(d,g,k)}}};x.registerNodeType("graphics/drawImage",B);z.title="DrawRectangle";z.desc="Draws rectangle in canvas";z.prototype.onExecute=function(){var c=this.getInputData(0);if(c){var d=this.getInputOrProperty("x"),g=this.getInputOrProperty("y"),k=this.getInputOrProperty("w"),m=this.getInputOrProperty("h");c.getContext("2d").fillRect(d,g,k,m)}};x.registerNodeType("graphics/drawRectangle",z);y.title="Video";y.desc="Video playback";y.widgets=[{name:"play",text:"PLAY",type:"minibutton"}, +{name:"stop",text:"STOP",type:"minibutton"},{name:"demo",text:"Demo video",type:"button"},{name:"mute",text:"Mute video",type:"button"}];y.prototype.onExecute=function(){if(this.properties.url&&(this.properties.url!=this._video_url&&this.loadVideo(this.properties.url),this._video&&0!=this._video.width)){var c=this.getInputData(0);c&&0<=c&&1>=c&&(this._video.currentTime=c*this._video.duration,this._video.pause());this._video.dirty=!0;this.setOutputData(0,this._video);this.setOutputData(1,this._video.currentTime); +this.setOutputData(2,this._video.duration);this.setDirtyCanvas(!0)}};y.prototype.onStart=function(){this.play()};y.prototype.onStop=function(){this.stop()};y.prototype.loadVideo=function(c){this._video_url=c;this.properties.use_proxy&&"http"==c.substr(0,4)&&x.proxy&&(c=x.proxy+c.substr(c.indexOf(":")+3));this._video=document.createElement("video");this._video.src=c;this._video.type="type=video/mp4";this._video.muted=!0;this._video.autoplay=!0;var d=this;this._video.addEventListener("loadedmetadata", +function(c){d.trace("Duration: "+this.duration+" seconds");d.trace("Size: "+this.videoWidth+","+this.videoHeight);d.setDirtyCanvas(!0);this.width=this.videoWidth;this.height=this.videoHeight});this._video.addEventListener("progress",function(c){});this._video.addEventListener("error",function(c){console.log("Error loading video: "+this.src);d.trace("Error loading video: "+this.src);if(this.error)switch(this.error.code){case this.error.MEDIA_ERR_ABORTED:d.trace("You stopped the video.");break;case this.error.MEDIA_ERR_NETWORK:d.trace("Network error - please try again later."); +break;case this.error.MEDIA_ERR_DECODE:d.trace("Video is broken..");break;case this.error.MEDIA_ERR_SRC_NOT_SUPPORTED:d.trace("Sorry, your browser can't play this video.")}});this._video.addEventListener("ended",function(c){d.trace("Ended.");this.play()})};y.prototype.onPropertyChanged=function(c,d){this.properties[c]=d;"url"==c&&""!=d&&this.loadVideo(d);return!0};y.prototype.play=function(){this._video&&this._video.play()};y.prototype.playPause=function(){this._video&&(this._video.paused?this.play(): +this.pause())};y.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};y.prototype.pause=function(){this._video&&(this.trace("Video paused"),this._video.pause())};y.prototype.onWidget=function(c,d){};x.registerNodeType("graphics/video",y);c.title="Webcam";c.desc="Webcam image";c.is_webcam_open=!1;c.prototype.openStream=function(){function d(g){console.log("Webcam rejected",g);f._webcam_stream=!1;c.is_webcam_open=!1;f.boxcolor="red";f.trigger("stream_error")}if(navigator.getUserMedia){this._waiting_confirmation= +!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this))["catch"](d);var f=this}};c.prototype.closeStream=function(){if(this._webcam_stream){var d=this._webcam_stream.getTracks();if(d.length)for(var f=0;f=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};c.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",x.EVENT],["stream_closed",x.EVENT],["stream_error",x.EVENT]]};x.registerNodeType("graphics/webcam",c)})(this); +(function(u){var d=u.LiteGraph;u.LGraphTexture=null;if("undefined"!=typeof GL){LGraphCanvas.link_type_colors.Texture="#987";var l=function(){this.addOutput("Texture","Texture");this.properties={name:"",filter:!0};this.size=[l.image_preview_size,l.image_preview_size]};u.LGraphTexture=l;l.title="Texture";l.desc="Texture";l.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}};l.loadTextureCallback=null;l.image_preview_size=256;l.PASS_THROUGH=1;l.COPY=2;l.LOW=3;l.HIGH=4;l.REUSE=5;l.DEFAULT= +2;l.MODE_VALUES={"pass through":l.PASS_THROUGH,copy:l.COPY,low:l.LOW,high:l.HIGH,reuse:l.REUSE,"default":l.DEFAULT};l.getTexturesContainer=function(){return gl.textures};l.loadTexture=function(a,b){b=b||{};var e=a;"http://"==e.substr(0,7)&&d.proxy&&(e=d.proxy+e.substr(7));return l.getTexturesContainer()[a]=GL.Texture.fromURL(e,b)};l.getTexture=function(a){var b=this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a): +b};l.getTargetTexture=function(a,b,e){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var c=null;switch(e){case l.LOW:c=gl.UNSIGNED_BYTE;break;case l.HIGH:c=gl.HIGH_PRECISION_FORMAT;break;case l.REUSE:return a;default:c=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==c||(b=new GL.Texture(a.width,a.height,{type:c,format:gl.RGBA,filter:gl.LINEAR}));return b};l.getTextureType=function(a,b){var e=b?b.type:gl.UNSIGNED_BYTE;switch(a){case l.HIGH:e=gl.HIGH_PRECISION_FORMAT; +break;case l.LOW:e=gl.UNSIGNED_BYTE}return e};l.getWhiteTexture=function(){return this._white_texture?this._white_texture:this._white_texture=GL.Texture.fromMemory(1,1,[255,255,255,255],{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})};l.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576),b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})}; +l.prototype.onDropFile=function(a,b,e){if(a){var c=null;"string"==typeof a?c=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?c=GL.Texture.fromDDSInMemory(a):(a=new Blob([e]),a=URL.createObjectURL(a),c=GL.Texture.fromURL(a));this._drop_texture=c;this.properties.name=b}else this._drop_texture=null,this.properties.name=""};l.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]};l.prototype.onExecute= +function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=l.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,a);for(var b=1;b=this.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=l.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())}};l.generateLowResTexturePreview=function(a){if(!a)return null;var b=l.image_preview_size,e=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)e=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=e=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(e);a=this._preview_canvas; +a||(this._preview_canvas=a=createCanvas(b,b));e&&e.toCanvas(a);return a};l.prototype.getResources=function(a){a[this.properties.name]=GL.Texture;return a};l.prototype.onGetInputs=function(){return[["in","Texture"]]};l.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};d.registerNodeType("texture/texture",l);var q=function(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[l.image_preview_size,l.image_preview_size]};q.title= +"Preview";q.desc="Show a texture in the graph canvas";q.allow_preview=!1;q.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||q.allow_preview)){var b=this.getInputData(0);if(b){var e=null,e=!b.handle&&a.webgl?b:l.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(e,0,0,this.size[0],this.size[1]);a.restore()}}};d.registerNodeType("texture/preview",q);var g=function(){this.addInput("Texture","Texture");this.addOutput("", +"Texture");this.properties={name:""}};g.title="Save";g.desc="Save a texture in the repository";g.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(l.storeTexture?l.storeTexture(this.properties.name,a):l.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};d.registerNodeType("texture/save",g);var s=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture"); +this.help="

pixelcode must be vec3

\t\t\t

uvcode must be vec2, is optional

\t\t\t

uv: tex. coords

color: texture

colorB: textureB

time: scene time

value: input value

";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value",precision:l.DEFAULT}};s.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo", +values:l.MODE_VALUES}};s.title="Operation";s.desc="Texture shader operation";s.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};s.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())};s.prototype.onExecute=function(){var a= +this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===l.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var e=512,c=512;a?(e=a.width,c=a.height):b&&(e=b.width,c=b.height);var d=l.getTextureType(this.properties.precision,a);this._tex=a||this._tex?l.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(e,c,{type:d,format:gl.RGBA,filter:gl.LINEAR});d="";this.properties.uvcode&& +(d="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(d=this.properties.uvcode));var k="";this.properties.pixelcode&&(k="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(k=this.properties.pixelcode));var f=this._shader;if(!f||this._shader_code!=d+"|"+k){try{this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,s.pixel_shader,{UV_CODE:d,PIXEL_CODE:k}),this.boxcolor="#00FF00"}catch(g){console.log("Error compiling shader: ",g);this.boxcolor="#FF0000"; +return}this.boxcolor="#FF0000";this._shader_code=d+"|"+k;f=this._shader}if(f){this.boxcolor="green";var h=this.getInputData(2);null!=h?this.properties.value=h:h=parseFloat(this.properties.value);var m=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var d=Mesh.getScreenQuad();f.uniforms({u_texture:0,u_textureB:1,value:h,texSize:[e,c],time:m}).draw(d)});this.setOutputData(0,this._tex)}else this.boxcolor= +"red"}}};s.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tUV_CODE;\n\t\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\tPIXEL_CODE;\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t"; +d.registerNodeType("texture/operation",s);var m=function(){this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,precision:l.DEFAULT};this.properties.code="\nvoid main() {\n vec2 uv = v_coord;\n vec3 color = vec3(0.0);\n//your code here\n\ngl_FragColor = vec4(color, 1.0);\n}\n";this._uniforms={in_texture:0,texSize:vec2.create(),time:0}};m.title="Shader";m.desc="Texture shader";m.widgets_info={code:{type:"code"},precision:{widget:"combo",values:l.MODE_VALUES}};m.prototype.onPropertyChanged= +function(a,b){if("code"==a){var e=this.getShader();if(e){var c=e.uniformInfo;if(this.inputs)for(var d={},k=0;k lumaMax))\n\t\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\t\telse\n\t\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\t\tif(u_igamma != 1.0)\n\t\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\t\treturn color;\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t\t}\n\t\t\t"; +z.gamma_pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_igamma;\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t\t gl_FragColor = color;\n\t\t\t}\n\t\t\t";d.registerNodeType("texture/toviewport",z);g=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1, +precision:l.DEFAULT}};g.title="Copy";g.desc="Copy Texture";g.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:l.MODE_VALUES}};g.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,e=a.height;0!=this.properties.size&&(e=b=this.properties.size);var c=this._temp_texture,d=a.type;this.properties.precision===l.LOW?d=gl.UNSIGNED_BYTE:this.properties.precision===l.HIGH&& +(d=gl.HIGH_PRECISION_FORMAT);c&&c.width==b&&c.height==e&&c.type==d||(c=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(e)&&(c=gl.LINEAR_MIPMAP_LINEAR),this._temp_texture=new GL.Texture(b,e,{type:d,format:gl.RGBA,minFilter:c,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}};d.registerNodeType("texture/copy", +g);var y=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:l.DEFAULT}};y.title="Downsample";y.desc="Downsample Texture";y.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:l.MODE_VALUES}};y.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D)if(1>this.properties.iterations)this.setOutputData(0, +a);else{var b=y._shader;b||(y._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,y.pixel_shader));var e=a.width|0,c=a.height|0,d=a.type;this.properties.precision===l.LOW?d=gl.UNSIGNED_BYTE:this.properties.precision===l.HIGH&&(d=gl.HIGH_PRECISION_FORMAT);var k=this.properties.iterations||1,f=a,g=null,h=[],a={type:d,format:a.format},d=vec2.create(),m={u_offset:d};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var t=0;t>1||0;c=c>>1||0;g=GL.Texture.getTemporary(e, +c,a);h.push(g);f.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);f.copyTo(g,b,m);if(1==e&&1==c)break;f=g}this._texture=h.pop();for(t=0;te;++e)b[e]=Math.random();c._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}e=this._temp_texture;b=gl.UNSIGNED_BYTE;a.type!=b&&(b=gl.FLOAT);e&&e.type==b||(this._temp_texture=new GL.Texture(1,1,{type:b,format:gl.RGBA,filter:gl.NEAREST}));var d=c._shader,k=this._uniforms;k.u_mipmap_offset=this.properties.mipmap_offset;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.toViewport(d,k)});if(this.isOutputConnected(1)|| +this.isOutputConnected(2))if(e=this._temp_texture.getPixels()){var f=this._luminance,b=this._temp_texture.type;f.set(e);b==gl.UNSIGNED_BYTE&&vec4.scale(f,f,1/255)}}};c.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t"; +d.registerNodeType("texture/average",c);var x=function(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:0.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}};x.title="Smooth";x.desc="Smooth texture over time";x.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){x._shader||(x._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,x.pixel_shader));var b=this._temp_texture; +b&&b.type==a.type&&b.width==a.width&&b.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.NEAREST}),this._temp_texture2=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.NEAREST}),a.copyTo(this._temp_texture2));var b=this._temp_texture,e=this._temp_texture2,c=x._shader,d=this._uniforms;d.u_factor=1-this.getInputOrProperty("factor");gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);b.drawTo(function(){e.bind(1);a.toViewport(c, +d)});this.setOutputData(0,b);this._temp_texture=e;this._temp_texture2=b}};x.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_factor;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = mix( texture2D( u_texture, v_coord ), texture2D( u_textureB, v_coord ), u_factor );\n\t\t\t}\n\t\t\t";d.registerNodeType("texture/temporal_smooth",x);g=function(){this.addInput("Image", +"image");this.addOutput("","Texture");this.properties={}};g.title="Image to Texture";g.desc="Uploads an image to the GPU";g.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,e=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var c=this._temp_texture;c&&c.width==b&&c.height==e||(this._temp_texture=new GL.Texture(b,e,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(d){console.error("image comes from an unsafe location, cannot be uploaded to webgl: "+ +d);return}this.setOutputData(0,this._temp_texture)}}};d.registerNodeType("texture/imageToTexture",g);var n=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={intensity:1,precision:l.DEFAULT,texture:null};n._shader||(n._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n.pixel_shader))};n.widgets_info={texture:{widget:"texture"},precision:{widget:"combo",values:l.MODE_VALUES}};n.title="LUT";n.desc= +"Apply LUT to Texture";n.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===l.PASS_THROUGH)this.setOutputData(0,a);else if(a){var b=this.getInputData(1);b||(b=l.getTexture(this.properties.texture));if(b){b.bind(0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D, +null);var e=this.properties.intensity;this.isInputConnected(2)&&(this.properties.intensity=e=this.getInputData(2));this._tex=l.getTargetTexture(a,this._tex,this.properties.precision);this._tex.drawTo(function(){b.bind(1);a.toViewport(n._shader,{u_texture:0,u_textureB:1,u_amount:e})});this.setOutputData(0,this._tex)}else this.setOutputData(0,a)}}};n.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_amount;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t\t mediump vec2 quad1;\n\t\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t\t mediump vec2 quad2;\n\t\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t\t highp vec2 texPos1;\n\t\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t highp vec2 texPos2;\n\t\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t\t}\n\t\t\t"; +d.registerNodeType("texture/LUT",n);var f=function(){this.addInput("Texture","Texture");this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");this.properties={use_luminance:!0};f._shader||(f._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader))};f.title="Texture to Channels";f.desc="Split texture channels";f.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b= +this.properties.use_luminance?gl.LUMINANCE:gl.RGBA,e=0,c=0;4>c;c++)this.isOutputConnected(c)?(this._channels[c]&&this._channels[c].width==a.width&&this._channels[c].height==a.height&&this._channels[c].type==a.type&&this._channels[c].format==b||(this._channels[c]=new GL.Texture(a.width,a.height,{type:a.type,format:b,filter:gl.LINEAR})),e++):this._channels[c]=null;if(e){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);for(var d=Mesh.getScreenQuad(),k=f._shader,g=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0, +1]],c=0;4>c;c++)this._channels[c]&&(this._channels[c].drawTo(function(){a.bind(0);k.uniforms({u_texture:0,u_mask:g[c]}).draw(d)}),this.setOutputData(c,this._channels[c]))}}};f.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec4 u_mask;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t\t}\n\t\t\t";d.registerNodeType("texture/textureChannels", +f);var A=function(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={precision:l.DEFAULT,R:1,G:1,B:1,A:1};this._color=vec4.create();this._uniforms={u_textureR:0,u_textureG:1,u_textureB:2,u_textureA:3,u_color:this._color}};A.title="Channels to Texture";A.desc="Split texture channels";A.widgets_info={precision:{widget:"combo",values:l.MODE_VALUES}};A.prototype.onExecute=function(){var a= +l.getWhiteTexture(),b=this.getInputData(0)||a,e=this.getInputData(1)||a,c=this.getInputData(2)||a,d=this.getInputData(3)||a;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var k=Mesh.getScreenQuad();A._shader||(A._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,A.pixel_shader));var f=A._shader,a=Math.max(b.width,e.width,c.width,d.width),g=Math.max(b.height,e.height,c.height,d.height),h=this.properties.precision==l.HIGH?l.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._texture&&this._texture.width==a&& +this._texture.height==g&&this._texture.type==h||(this._texture=new GL.Texture(a,g,{type:h,format:gl.RGBA,filter:gl.LINEAR}));a=this._color;a[0]=this.properties.R;a[1]=this.properties.G;a[2]=this.properties.B;a[3]=this.properties.A;var m=this._uniforms;this._texture.drawTo(function(){b.bind(0);e.bind(1);c.bind(2);d.bind(3);f.uniforms(m).draw(k)});this.setOutputData(0,this._texture)};A.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_textureR;\n\t\t\tuniform sampler2D u_textureG;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform sampler2D u_textureA;\n\t\t\tuniform vec4 u_color;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = u_color * vec4( \t\t\t\t\t\ttexture2D(u_textureR, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureG, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureB, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureA, v_coord).r);\n\t\t\t}\n\t\t\t"; +d.registerNodeType("texture/channelsTexture",A);g=function(){this.addOutput("Texture","Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:l.DEFAULT}};g.title="Color";g.desc="Generates a 1x1 texture with a constant color";g.widgets_info={precision:{widget:"combo",values:l.MODE_VALUES}};g.prototype.onDrawBackground=function(a){var b=this.properties.color;a.fillStyle="rgb("+Math.floor(255*Math.clamp(b[0],0,1))+","+Math.floor(255*Math.clamp(b[1],0,1))+","+Math.floor(255* +Math.clamp(b[2],0,1))+")";this.flags.collapsed?this.boxcolor=a.fillStyle:a.fillRect(0,0,this.size[0],this.size[1])};g.prototype.onExecute=function(){var a=this.properties.precision==l.HIGH?l.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._tex&&this._tex.type==a||(this._tex=new GL.Texture(1,1,{format:gl.RGBA,type:a,minFilter:gl.NEAREST}));a=this.properties.color;if(this.inputs)for(var b=0;b 0.5 ? 1.0 : 0.0, diff.y > 0.5 ? 1.0 : 0.0, diff.z > 0.5 ? 1.0 : 0.0, center.a );\n\t\t\t}\n\t\t\t"; +d.registerNodeType("texture/edges",v);var a=function(){this.addInput("Texture","Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}};a.title="Depth Range";a.desc="Generates a texture with a depth range";a.prototype.onExecute=function(){if(this.isOutputConnected(0)){var b=this.getInputData(0); +if(b){var e=gl.UNSIGNED_BYTE;this.properties.high_precision&&(e=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==e&&this._temp_texture.width==b.width&&this._temp_texture.height==b.height||(this._temp_texture=new GL.Texture(b.width,b.height,{type:e,format:gl.RGBA,filter:gl.LINEAR}));var c=this._uniforms,e=this.properties.distance;this.isInputConnected(1)&&(e=this.getInputData(1),this.properties.distance=e);var d=this.properties.range;this.isInputConnected(2)&& +(d=this.getInputData(2),this.properties.range=d);c.u_distance=e;c.u_range=d;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var k=Mesh.getScreenQuad();a._shader||(a._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a.pixel_shader),a._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a.pixel_shader,{ONLY_DEPTH:""}));var f=this.properties.only_depth?a._shader_onlydepth:a._shader,e=null,e=b.near_far_planes?b.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes: +[0.1,1E3];c.u_camera_planes=e;this._temp_texture.drawTo(function(){b.bind(0);f.uniforms(c).draw(k)});this._temp_texture.near_far_planes=e;this.setOutputData(0,this._temp_texture)}}};a.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_distance;\n\t\t\tuniform float u_range;\n\t\t\t\n\t\t\tfloat LinearDepth()\n\t\t\t{\n\t\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat depth = LinearDepth();\n\t\t\t\t#ifdef ONLY_DEPTH\n\t\t\t\t gl_FragColor = vec4(depth);\n\t\t\t\t#else\n\t\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\t\tfloat dof = 1.0;\n\t\t\t\t\tif(diff <= u_range)\n\t\t\t\t\t\tdof = diff / u_range;\n\t\t\t\t gl_FragColor = vec4(dof);\n\t\t\t\t#endif\n\t\t\t}\n\t\t\t"; +d.registerNodeType("texture/depth_range",a);var b=function(){this.addInput("Texture","Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1],precision:l.DEFAULT}};b.title="Blur";b.desc="Blur a texture";b.widgets_info={precision:{widget:"combo",values:l.MODE_VALUES}};b.max_iterations=20;b.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var e= +this._final_texture;e&&e.width==a.width&&e.height==a.height&&e.type==a.type||(e=this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var c=this.properties.iterations;this.isInputConnected(1)&&(c=this.getInputData(1),this.properties.iterations=c);c=Math.min(Math.floor(c),b.max_iterations);if(0==c)this.setOutputData(0,a);else{var k=this.properties.intensity;this.isInputConnected(2)&&(k=this.getInputData(2),this.properties.intensity=k);var f=d.camera_aspect; +f||void 0===window.gl||(f=gl.canvas.height/gl.canvas.width);f||(f=1);var f=this.properties.preserve_aspect?f:1,g=this.properties.scale||[1,1];a.applyBlur(f*g[0],g[1],k,e);for(a=1;a>=1;1<(c|0)&&(c>>=1);if(2>b)break;m=g[q]=GL.Texture.getTemporary(b,c,d);r[0]=1/t.width;r[1]=1/t.height;t.blit(m,h.uniforms(f));t=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})),r[0]=1/t.width,r[1]=1/t.height,f.u_intensity= +v,f.u_delta=1,t.blit(b,h.uniforms(f)),this.setOutputData(2,b));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);f.u_intensity=this.getInputOrProperty("persistence");f.u_delta=0.5;for(q-=2;0<=q;q--)m=g[q],g[q]=null,r[0]=1/t.width,r[1]=1/t.height,t.blit(m,h.uniforms(f)),GL.Texture.releaseTemporary(t),t=m;gl.disable(gl.BLEND);this.isOutputConnected(1)&&(g=this._glow_texture,g&&g.width==a.width&&g.height==a.height&&g.type==k&&g.format==a.format||(g=this._glow_texture=new GL.Texture(a.width,a.height,{type:k, +format:a.format,filter:gl.LINEAR})),t.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==k&&g.format==a.format||(g=this._final_texture=new GL.Texture(a.width,a.height,{type:k,format:a.format,filter:gl.LINEAR}));var s=this.getInputData(1),w=this.getInputOrProperty("dirt_factor");f.u_intensity=v;h=s?e._dirt_final_shader:e._final_shader;h||(h=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);t.bind(1);s&&(h.setUniform("u_dirt_factor",w),h.setUniform("u_dirt_texture",s.bind(2)));h.toViewport(f)});this.setOutputData(0,g)}GL.Texture.releaseTemporary(t)}};e.cut_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_threshold;\n\t\tvoid main() {\n\t\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t\t}"; +e.scale_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_texel_size;\n\t\tuniform float u_delta;\n\t\tuniform float u_intensity;\n\t\t\n\t\tvec4 sampleBox(vec2 uv) {\n\t\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\t\treturn s * 0.25;\n\t\t}\n\t\tvoid main() {\n\t\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t\t}"; +e.final_pixel_shader="precision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_glow_texture;\n\t\t#ifdef USE_DIRT\n\t\t\tuniform sampler2D u_dirt_texture;\n\t\t#endif\n\t\tuniform vec2 u_texel_size;\n\t\tuniform float u_delta;\n\t\tuniform float u_intensity;\n\t\tuniform float u_dirt_factor;\n\t\t\n\t\tvec4 sampleBox(vec2 uv) {\n\t\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\t\tvec4 s = texture2D( u_glow_texture, uv + o.xy ) + texture2D( u_glow_texture, uv + o.zy) + texture2D( u_glow_texture, uv + o.xw) + texture2D( u_glow_texture, uv + o.zw);\n\t\t\treturn s * 0.25;\n\t\t}\n\t\tvoid main() {\n\t\t\tvec4 glow = sampleBox( v_coord );\n\t\t\t#ifdef USE_DIRT\n\t\t\t\tglow = mix( glow, glow * texture2D( u_dirt_texture, v_coord ), u_dirt_factor );\n\t\t\t#endif\n\t\t\tgl_FragColor = texture2D( u_texture, v_coord ) + u_intensity * glow;\n\t\t}"; +d.registerNodeType("texture/glow",e);var r=function(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}};r.title="Kuwahara Filter";r.desc="Filters a texture giving an artistic oil canvas painting";r.max_radius=10;r._shaders=[];r.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),r.max_radius);if(0==b)this.setOutputData(0,a);else{var e=this.properties.intensity,c=d.camera_aspect;c||void 0===window.gl||(c=gl.canvas.height/gl.canvas.width);c||(c=1);c=this.properties.preserve_aspect?c:1;r._shaders[b]||(r._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,r.pixel_shader,{RADIUS:b.toFixed(0)}));var k=r._shaders[b],f=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){k.uniforms({u_texture:0, +u_intensity:e,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(f)});this.setOutputData(0,this._temp_texture)}}};r.pixel_shader="\n\tprecision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_intensity;\n\tuniform vec2 u_resolution;\n\tuniform vec2 u_iResolution;\n\t#ifndef RADIUS\n\t\t#define RADIUS 7\n\t#endif\n\tvoid main() {\n\t\n\t\tconst int radius = RADIUS;\n\t\tvec2 fragCoord = v_coord;\n\t\tvec2 src_size = u_iResolution;\n\t\tvec2 uv = v_coord;\n\t\tfloat n = float((radius + 1) * (radius + 1));\n\t\tint i;\n\t\tint j;\n\t\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\t\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\t\tvec3 c;\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm0 += c;\n\t\t\t\ts0 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = -radius; j <= 0; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm1 += c;\n\t\t\t\ts1 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm2 += c;\n\t\t\t\ts2 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 0; j <= radius; ++j) {\n\t\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\t\tm3 += c;\n\t\t\t\ts3 += c * c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfloat min_sigma2 = 1e+2;\n\t\tm0 /= n;\n\t\ts0 = abs(s0 / n - m0 * m0);\n\t\t\n\t\tfloat sigma2 = s0.r + s0.g + s0.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m0, 1.0);\n\t\t}\n\t\t\n\t\tm1 /= n;\n\t\ts1 = abs(s1 / n - m1 * m1);\n\t\t\n\t\tsigma2 = s1.r + s1.g + s1.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m1, 1.0);\n\t\t}\n\t\t\n\t\tm2 /= n;\n\t\ts2 = abs(s2 / n - m2 * m2);\n\t\t\n\t\tsigma2 = s2.r + s2.g + s2.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m2, 1.0);\n\t\t}\n\t\t\n\t\tm3 /= n;\n\t\ts3 = abs(s3 / n - m3 * m3);\n\t\t\n\t\tsigma2 = s3.r + s3.g + s3.b;\n\t\tif (sigma2 < min_sigma2) {\n\t\t\tmin_sigma2 = sigma2;\n\t\t\tgl_FragColor = vec4(m3, 1.0);\n\t\t}\n\t}\n\t"; +d.registerNodeType("texture/kuwahara",r);var h=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0};h.title="Webcam";h.desc="Webcam texture";h.is_webcam_open=!1;h.prototype.openStream=function(){function a(e){h.is_webcam_open=!1;console.log("Webcam rejected",e);b._webcam_stream=!1;b.boxcolor="red";b.trigger("stream_error")}if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1, +video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this))["catch"](a);var b=this}};h.prototype.closeStream=function(){if(this._webcam_stream){var a=this._webcam_stream.getTracks();if(a.length)for(var b=0;b=this.size[1]||!this._video||(a.save(),a.webgl?this._video_texture&&a.drawImage(this._video_texture,0,0,this.size[0],this.size[1]):a.drawImage(this._video,0,0,this.size[0],this.size[1]),a.restore())};h.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,e=this._video_texture;e&&e.width==a&&e.height==b||(this._video_texture=new GL.Texture(a,b,{format:gl.RGB, +filter:gl.LINEAR}));this._video_texture.uploadImage(this._video);this._video_texture.version=++this.version;this.properties.texture_name&&(l.getTexturesContainer()[this.properties.texture_name]=this._video_texture);this.setOutputData(0,this._video_texture);for(a=1;a=this.size[1]||a.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};d.registerNodeType("texture/cubemap",g)}})(this); +(function(u){var d=u.LiteGraph;if("undefined"!=typeof GL){var l=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};l._shader||(l._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,l.pixel_shader),l._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]}))};l.title="Lens";l.desc="Camera Lens distortion";l.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};l.prototype.onExecute=function(){var d=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,d);else if(d){this._tex=LGraphTexture.getTargetTexture(d,this._tex,this.properties.precision);var g=this.properties.aberration;this.isInputConnected(1)&&(g=this.getInputData(1), +this.properties.aberration=g);var q=this.properties.distortion;this.isInputConnected(2)&&(q=this.getInputData(2),this.properties.distortion=q);var 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 u=Mesh.getScreenQuad(),c=l._shader;this._tex.drawTo(function(){d.bind(0);c.uniforms({u_texture:0,u_aberration:g,u_distortion:q,u_blur:s}).draw(u)});this.setOutputData(0,this._tex)}};l.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t"; +d.registerNodeType("fx/lens",l);u.LGraphFXLens=l;var q=function(){this.addInput("Texture","Texture");this.addInput("Blurred","Texture");this.addInput("Mask","Texture");this.addInput("Threshold","number");this.addOutput("Texture","Texture");this.properties={shape:"",size:10,alpha:1,threshold:1,high_precision:!1}};q.title="Bokeh";q.desc="applies an Bokeh effect";q.widgets_info={shape:{widget:"texture"}};q.prototype.onExecute=function(){var d=this.getInputData(0),g=this.getInputData(1),l=this.getInputData(2); +if(d&&l&&this.properties.shape){g||(g=d);var s=LGraphTexture.getTexture(this.properties.shape);if(s){var u=this.properties.threshold;this.isInputConnected(3)&&(u=this.getInputData(3),this.properties.threshold=u);var c=gl.UNSIGNED_BYTE;this.properties.high_precision&&(c=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==c&&this._temp_texture.width==d.width&&this._temp_texture.height==d.height||(this._temp_texture=new GL.Texture(d.width,d.height,{type:c,format:gl.RGBA, +filter:gl.LINEAR}));var x=q._first_shader;x||(x=q._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,q._first_pixel_shader));var n=q._second_shader;n||(n=q._second_shader=new GL.Shader(q._second_vertex_shader,q._second_pixel_shader));var f=this._points_mesh;f&&f._width==d.width&&f._height==d.height&&2==f._spacing||(f=this.createPointsMesh(d.width,d.height,2));var A=Mesh.getScreenQuad(),k=this.properties.size,t=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){d.bind(0); +g.bind(1);l.bind(2);x.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[d.width,d.height]}).draw(A)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);d.bind(0);s.bind(3);n.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:t,u_threshold:u,u_pointSize:k,u_itexsize:[1/d.width,1/d.height]}).draw(f,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,d)};q.prototype.createPointsMesh=function(d,g,l){for(var q=Math.round(d/l),s=Math.round(g/ +l),c=new Float32Array(q*s*2),u=-1,n=2/d*l,f=2/g*l,A=0;A=d.NOTEON||f<=d.NOTEOFF)this.channel= +c&15};Object.defineProperty(d.prototype,"velocity",{get:function(){return this.cmd==d.NOTEON?this.data[2]:-1},set:function(c){this.data[2]=c},enumerable:!0});d.notes="A A# B C C# D D# E F F# G G#".split(" ");d.note_to_index={A:0,"A#":1,B:2,C:3,"C#":4,D:5,"D#":6,E:7,F:8,"F#":9,G:10,"G#":11};Object.defineProperty(d.prototype,"note",{get:function(){return this.cmd!=d.NOTEON?-1:d.toNoteString(this.data[1],!0)},set:function(c){throw"notes cannot be assigned this way, must modify the data[1]";},enumerable:!0}); +Object.defineProperty(d.prototype,"octave",{get:function(){return this.cmd!=d.NOTEON?-1:Math.floor((this.data[1]-24)/12+1)},set:function(c){throw"octave cannot be assigned this way, must modify the data[1]";},enumerable:!0});d.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};d.computePitch=function(c){return 440*Math.pow(2,(c-69)/12)};d.prototype.getCC=function(){return this.data[1]};d.prototype.getCCValue=function(){return this.data[2]};d.prototype.getPitchBend=function(){return this.data[1]+ +(this.data[2]<<7)-8192};d.computePitchBend=function(c,d){return c+(d<<7)-8192};d.prototype.setCommandFromString=function(c){this.cmd=d.computeCommandFromString(c)};d.computeCommandFromString=function(c){if(!c)return 0;if(c&&c.constructor===Number)return c;c=c.toUpperCase();switch(c){case "NOTE ON":case "NOTEON":return d.NOTEON;case "NOTE OFF":case "NOTEOFF":return d.NOTEON;case "KEY PRESSURE":case "KEYPRESSURE":return d.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return d.CONTROLLERCHANGE; +case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return d.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return d.CHANNELPRESSURE;case "PITCH BEND":case "PITCHBEND":return d.PITCHBEND;case "TIME TICK":case "TIMETICK":return d.TIMETICK;default:return Number(c)}};d.toNoteString=function(c,f){c=Math.round(c);var g,a=Math.floor((c-24)/12+1);g=(c-21)%12;0>g&&(g=12+g);return d.notes[g]+(f?"":a)};d.NoteStringToPitch=function(c){c=c.toUpperCase();var f=c[0],g=4;"#"==c[1]?(f+="#",2this.properties.max_value)return;this.trigger("on_midi",f)}};f.registerNodeType("midi/filter",m);w.title="MIDIEvent";w.desc="Create a MIDI Event";w.color="#243";w.prototype.onAction=function(c,f){"assign"== +c?(this.properties.channel=f.channel,this.properties.cmd=f.cmd,this.properties.value1=f.data[1],this.properties.value2=f.data[2],f.cmd==d.NOTEON?this.gate=!0:f.cmd==d.NOTEOFF&&(this.gate=!1)):(f=this.midi_event,f.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?f.setCommandFromString(this.properties.cmd):f.cmd=this.properties.cmd,f.data[0]=f.cmd|f.channel,f.data[1]=Number(this.properties.value1),f.data[2]=Number(this.properties.value2),this.trigger("on_midi", +f))};w.prototype.onExecute=function(){var c=this.properties;if(this.inputs)for(var f=0;fc;++c)this.valid_notes[c]=-1!=this.notes_pitches.indexOf(c);for(c=0;12>c;++c)if(this.valid_notes[c])this.offset_notes[c]=0;else for(var d= +1;12>d;++d){if(this.valid_notes[(c-d)%12]){this.offset_notes[c]=-d;break}if(this.valid_notes[(c+d)%12]){this.offset_notes[c]=d;break}}};c.prototype.onAction=function(c,f){f&&f.constructor===d&&(f.data[0]==d.NOTEON||f.data[0]==d.NOTEOFF?(this.midi_event=new d,this.midi_event.setup(f.data),this.midi_event.data[1]+=this.offset_notes[d.note_to_index[f.note]],this.trigger("out",this.midi_event)):this.trigger("out",f))};c.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&& +this.processScale(c)};f.registerNodeType("midi/quantize",c);x.title="MIDI Play";x.desc="Plays a MIDI note";x.color="#243";x.prototype.onAction=function(c,f){if(f&&f.constructor===d){if(this.instrument&&f.data[0]==d.NOTEON){var g=f.note;if(!g||"undefined"==g||g.constructor!==String)return;this.instrument.play(g,f.octave,this.properties.duration,this.properties.volume)}this.trigger("note",f)}};x.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&(this.properties.volume=c);c=this.getInputData(2); +null!=c&&(this.properties.duration=c)};f.registerNodeType("midi/play",x);n.title="MIDI Keys";n.desc="Keyboard to play notes";n.color="#243";n.keys=[{x:0,w:1,h:1,t:0},{x:0.75,w:0.5,h:0.6,t:1},{x:1,w:1,h:1,t:0},{x:1.75,w:0.5,h:0.6,t:1},{x:2,w:1,h:1,t:0},{x:2.75,w:0.5,h:0.6,t:1},{x:3,w:1,h:1,t:0},{x:4,w:1,h:1,t:0},{x:4.75,w:0.5,h:0.6,t:1},{x:5,w:1,h:1,t:0},{x:5.75,w:0.5,h:0.6,t:1},{x:6,w:1,h:1,t:0}];n.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var d=12*this.properties.num_octaves; +this.keys.length=d;var f=this.size[0]/(7*this.properties.num_octaves),a=this.size[1];c.globalAlpha=1;for(var b=0;2>b;b++)for(var e=0;eg+h||c[1]>e))return b}}return-1};n.prototype.onAction=function(c,f){if("reset"==c)for(var g=0;gf[1])){var g=this.getKeyIndex(f);this.keys[g]=!0;this._last_key= +g;var g=12*(this.properties.start_octave-1)+29+g,a=new d;a.setup([d.NOTEON,g,100]);this.trigger("note",a);return!0}};n.prototype.onMouseMove=function(c,f){if(!(0>f[1]||-1==this._last_key)){this.setDirtyCanvas(!0);var g=this.getKeyIndex(f);if(this._last_key==g)return!0;this.keys[this._last_key]=!1;var a=12*(this.properties.start_octave-1)+29+this._last_key,b=new d;b.setup([d.NOTEOFF,a,100]);this.trigger("note",b);this.keys[g]=!0;a=12*(this.properties.start_octave-1)+29+g;b=new d;b.setup([d.NOTEON, +a,100]);this.trigger("note",b);this._last_key=g;return!0}};n.prototype.onMouseUp=function(c,f){if(!(0>f[1])){var g=this.getKeyIndex(f);this.keys[g]=!1;this._last_key=-1;var g=12*(this.properties.start_octave-1)+29+g,a=new d;a.setup([d.NOTEOFF,g,100]);this.trigger("note",a);return!0}};f.registerNodeType("midi/keys",n)})(this); +(function(u){function d(){this.properties={src:"",gain:0.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audiobuffer=null;this._audionodes=[];this._last_sourcenode=null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=v.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function l(){this.properties={gain:0.5};this._audionodes=[];this._media_stream= +null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=v.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function q(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:0.5};this.audionode=v.getAudioContext().createAnalyser();this.audionode.graphnode=this;this.audionode.fftSize=this.properties.fftSize;this.audionode.minDecibels=this.properties.minDecibels;this.audionode.maxDecibels= +this.properties.maxDecibels;this.audionode.smoothingTimeConstant=this.properties.smoothingTimeConstant;this.addInput("in","audio");this.addOutput("freqs","array");this.addOutput("samples","array");this._time_bin=this._freq_bin=null}function g(){this.properties={gain:1};this.audionode=v.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function s(){this.properties={impulse_src:"",normalize:!0};this.audionode=v.getAudioContext().createConvolver(); +this.addInput("in","audio");this.addOutput("out","audio")}function m(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=v.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function w(){this.properties={};this.audionode=v.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function B(){this.properties={gain1:0.5,gain2:0.5}; +this.audionode=v.getAudioContext().createGain();this.audionode1=v.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=v.getAudioContext().createGain();this.audionode2.gain.value=this.properties.gain2;this.audionode1.connect(this.audionode);this.audionode2.connect(this.audionode);this.addInput("in1","audio");this.addInput("in1 gain","number");this.addInput("in2","audio");this.addInput("in2 gain","number");this.addOutput("out","audio")}function z(){this.properties= +{A:0.1,D:0.1,S:0.1,R:0.1};this.audionode=v.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","bool");this.addOutput("out","audio");this.gate=!1}function y(){this.properties={delayTime:0.5};this.audionode=v.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function c(){this.properties={frequency:350,detune:0,Q:1}; +this.addProperty("type","lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});this.audionode=v.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function x(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=v.getAudioContext().createOscillator();this.addOutput("out","audio")}function n(){this.properties= +{continuous:!0,mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function f(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function A(){if(!A.default_code){var a=A.default_function.toString(),b=a.indexOf("{")+1,c=a.lastIndexOf("}");A.default_code=a.substr(b,c-b)}this.properties={code:A.default_code};a=v.getAudioContext();a.createScriptProcessor?this.audionode=a.createScriptProcessor(4096, +1,1):(console.warn("ScriptProcessorNode deprecated"),this.audionode=a.createGain());this.processCode();A._bypass_function||(A._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function k(){this.audionode=v.getAudioContext().destination;this.addInput("in","audio")}var t=u.LiteGraph,v={};u.LGAudio=v;v.getAudioContext=function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"), +null;this._audio_context=new AudioContext;this._audio_context.onmessage=function(a){console.log("msg",a)};this._audio_context.onended=function(a){console.log("ended",a)};this._audio_context.oncomplete=function(a){console.log("complete",a)}}return this._audio_context};v.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};v.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};v.changeAllAudiosConnections=function(a,b){if(a.inputs)for(var c= +0;c=this.size[0]&&(f=this.size[0]-1),a.strokeStyle="red",a.beginPath(),a.moveTo(f,d),a.lineTo(f,0),a.stroke())}};n.title="Visualization";n.desc="Audio Visualization";t.registerNodeType("audio/visualization",n);f.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var a=this.properties.band,b=this.getInputData(1);void 0!==b&&(a=b);b=v.getAudioContext().sampleRate/this._freqs.length;b=a/b*2;b>=this._freqs.length?b=this._freqs[this._freqs.length-1]:(a=b|0, +b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.properties.amplitude)}};f.prototype.onGetInputs=function(){return[["band","number"]]};f.title="Signal";f.desc="extract the signal of some frequency";t.registerNodeType("audio/signal",f);A.prototype.onAdded=function(a){a.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};A["@code"]={widget:"code"};A.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};A.prototype.onStop= +function(){this.audionode.onaudioprocess=A._bypass_function};A.prototype.onPause=function(){this.audionode.onaudioprocess=A._bypass_function};A.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};A.prototype.onExecute=function(){};A.prototype.onRemoved=function(){this.audionode.onaudioprocess=A._bypass_function};A.prototype.processCode=function(){try{this._script=new new Function("properties",this.properties.code)(this.properties),this._old_code=this.properties.code,this._callback= +this._script.onaudioprocess}catch(a){console.error("Error in onaudioprocess code",a),this._callback=A._bypass_function,this.audionode.onaudioprocess=this._callback}};A.prototype.onPropertyChanged=function(a,b){"code"==a&&(this.properties.code=b,this.processCode(),this.graph&&this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};A.default_function=function(){this.onaudioprocess=function(a){var b=a.inputBuffer;a=a.outputBuffer;for(var c=0;c - + @@ -24,6 +24,8 @@ + + diff --git a/demo/js/code.js b/demo/js/code.js index a2252aa51..e4b14134a 100644 --- a/demo/js/code.js +++ b/demo/js/code.js @@ -4,7 +4,7 @@ var editor = new LiteGraph.Editor("main"); window.graphcanvas = editor.graphcanvas; window.graph = editor.graph; window.addEventListener("resize", function() { editor.graphcanvas.resize(); } ); -window.addEventListener("keydown", editor.graphcanvas.processKey.bind(editor.graphcanvas) ); +//window.addEventListener("keydown", editor.graphcanvas.processKey.bind(editor.graphcanvas) ); window.onbeforeunload = function(){ var data = JSON.stringify( graph.serialize() ); localStorage.setItem("litegraphg demo backup", data ); diff --git a/src/litegraph.js b/src/litegraph.js index 95e66ee80..1372a41a7 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -12,10 +12,13 @@ var LiteGraph = global.LiteGraph = { + VERSION: 0.4, + CANVAS_GRID_SIZE: 10, - NODE_TITLE_HEIGHT: 20, - NODE_SLOT_HEIGHT: 15, + NODE_TITLE_HEIGHT: 30, + NODE_TITLE_TEXT_Y: 20, + NODE_SLOT_HEIGHT: 20, NODE_WIDGET_HEIGHT: 20, NODE_WIDTH: 140, NODE_MIN_WIDTH: 50, @@ -26,14 +29,14 @@ var LiteGraph = global.LiteGraph = { NODE_TEXT_COLOR: "#AAA", NODE_SUBTEXT_SIZE: 12, NODE_DEFAULT_COLOR: "#333", - NODE_DEFAULT_BGCOLOR: "#444", + NODE_DEFAULT_BGCOLOR: "#353535", NODE_DEFAULT_BOXCOLOR: "#666", NODE_DEFAULT_SHAPE: "box", DEFAULT_SHADOW_COLOR: "rgba(0,0,0,0.5)", DEFAULT_GROUP_FONT: 24, - LINK_COLOR: "#AAD", - EVENT_LINK_COLOR: "#F85", + LINK_COLOR: "#9A9", + EVENT_LINK_COLOR: "#A86", CONNECTING_LINK_COLOR: "#AFA", MAX_NUMBER_OF_NODES: 1000, //avoid infinite loops @@ -65,6 +68,10 @@ var LiteGraph = global.LiteGraph = { RIGHT:4, CENTER:5, + STRAIGHT_LINK: 0, + LINEAR_LINK: 1, + SPLINE_LINK: 2, + NORMAL_TITLE: 0, NO_TITLE: 1, TRANSPARENT_TITLE: 2, @@ -263,13 +270,11 @@ var LiteGraph = global.LiteGraph = { * @param {String} type full name of the node class. p.e. "math/sin" * @return {Class} the node class */ - getNodeType: function(type) { return this.registered_node_types[type]; }, - /** * Returns a list of node types matching one category * @method getNodeType @@ -969,15 +974,14 @@ LGraph.prototype.sendEventToAllNodes = function( eventname, params, mode ) for( var j = 0, l = nodes.length; j < l; ++j ) { var node = nodes[j]; - if(node[eventname] && node.mode == mode ) - { - if(params === undefined) - node[eventname](); - else if(params && params.constructor === Array) - node[eventname].apply( node, params ); - else - node[eventname](params); - } + if( !node[eventname] || node.mode != mode ) + continue; + if(params === undefined) + node[eventname](); + else if(params && params.constructor === Array) + node[eventname].apply( node, params ); + else + node[eventname](params); } } @@ -1615,7 +1619,8 @@ LGraph.prototype.serialize = function() nodes: nodes_info, links: links, groups: groups_info, - config: this.config + config: this.config, + version: LiteGraph.VERSION }; return data; @@ -1828,6 +1833,8 @@ LiteGraph.LLink = LLink; + onDropFile : file dropped over the node + onConnectInput : if returns false the incoming connection will be canceled + onConnectionsChange : a connection changed (new one or removed) (LiteGraph.INPUT or LiteGraph.OUTPUT, slot, true if connected, link_info, input_info ) + + onAction: action slot triggered + + getExtraMenuOptions: to add option to context menu */ /** @@ -2100,6 +2107,35 @@ LGraphNode.prototype.setOutputData = function(slot, data) } } +/** +* sets the output data type, useful when you want to be able to overwrite the data type +* @method setOutputDataType +* @param {number} slot +* @param {String} datatype +*/ +LGraphNode.prototype.setOutputDataType = function(slot, type) +{ + if(!this.outputs) + return; + if(slot == -1 || slot >= this.outputs.length) + return; + var output_info = this.outputs[slot]; + if(!output_info) + return; + //store data in the output itself in case we want to debug + output_info.type = type; + + //if there are connections, pass the data to the connections + if( this.outputs[slot].links ) + { + for(var i = 0; i < this.outputs[slot].links.length; i++) + { + var link_id = this.outputs[slot].links[i]; + this.graph.links[ link_id ].type = type; + } + } +} + /** * Retrieves the input data (data traveling through the connection) from one slot * @method getInputData @@ -2136,6 +2172,32 @@ LGraphNode.prototype.getInputData = function( slot, force_update ) return link.data; } +/** +* Retrieves the input data type (in case this supports multiple input types) +* @method getInputDataType +* @param {number} slot +* @return {String} datatype in string format +*/ +LGraphNode.prototype.getInputDataType = function( slot ) +{ + if(!this.inputs) + return null; //undefined; + + if(slot >= this.inputs.length || this.inputs[slot].link == null) + return null; + var link_id = this.inputs[slot].link; + var link = this.graph.links[ link_id ]; + if(!link) //bug: weird case but it happens sometimes + return null; + var node = this.graph.getNodeById( link.origin_id ); + if(!node) + return link.type; + var output_info = node.outputs[ link.origin_slot ]; + if(output_info) + return output_info.type; + return null; +} + /** * Retrieves the input data from one slot using its name instead of slot number * @method getInputDataByName @@ -2639,11 +2701,14 @@ LGraphNode.prototype.addConnection = function(name,type,pos,direction) */ LGraphNode.prototype.computeSize = function( minHeight, out ) { + if( this.constructor.size ) + return this.constructor.size.concat(); + var rows = Math.max( this.inputs ? this.inputs.length : 1, this.outputs ? this.outputs.length : 1); var size = out || new Float32Array([0,0]); rows = Math.max(rows, 1); var font_size = LiteGraph.NODE_TEXT_SIZE; //although it should be graphcanvas.inner_text_font size - size[1] = (this.constructor.slot_start_y || 0) + rows * (font_size + 1) + 4; + size[1] = (this.constructor.slot_start_y || 0) + rows * LiteGraph.NODE_SLOT_HEIGHT; if( this.widgets && this.widgets.length ) size[1] += this.widgets.length * (LiteGraph.NODE_WIDGET_HEIGHT + 4) + 8; @@ -2687,6 +2752,11 @@ LGraphNode.prototype.computeSize = function( minHeight, out ) return font_size * text.length * 0.6; } + if(this.constructor.min_height && size[1] < this.constructor.min_height) + size[1] = this.constructor.min_height; + + size[1] += 6; //margin + return size; } @@ -3160,6 +3230,8 @@ LGraphNode.prototype.getConnectionPos = function( is_input, slot_number, out ) if( !is_input && this.outputs ) num_slots = this.outputs.length; + var offset = LiteGraph.NODE_SLOT_HEIGHT * 0.5; + if(this.flags.collapsed) { var w = (this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH); @@ -3182,10 +3254,11 @@ LGraphNode.prototype.getConnectionPos = function( is_input, slot_number, out ) return out; } + //weird feature that never got finished if(is_input && slot_number == -1) { - out[0] = this.pos[0] + 10; - out[1] = this.pos[1] + 10; + out[0] = this.pos[0] + LiteGraph.NODE_TITLE_HEIGHT * 0.5; + out[1] = this.pos[1] + LiteGraph.NODE_TITLE_HEIGHT * 0.5; return out; } @@ -3214,12 +3287,12 @@ LGraphNode.prototype.getConnectionPos = function( is_input, slot_number, out ) return out; } - //default + //default vertical slots if(is_input) - out[0] = this.pos[0]; + out[0] = this.pos[0] + offset; else - out[0] = this.pos[0] + this.size[0] + 1; - out[1] = this.pos[1] + 10 + slot_number * LiteGraph.NODE_SLOT_HEIGHT + (this.constructor.slot_start_y || 0); + out[0] = this.pos[0] + this.size[0] + 1 - offset; + out[1] = this.pos[1] + (slot_number + 0.7 ) * LiteGraph.NODE_SLOT_HEIGHT + (this.constructor.slot_start_y || 0); return out; } @@ -3464,6 +3537,202 @@ LGraphGroup.prototype.recomputeInsideNodes = function() LGraphGroup.prototype.isPointInside = LGraphNode.prototype.isPointInside; LGraphGroup.prototype.setDirtyCanvas = LGraphNode.prototype.setDirtyCanvas; + + +//**************************************** + +//Scale and Offset +function DragAndScale( element, skip_events ) +{ + this.offset = new Float32Array([0,0]); + this.scale = 1; + this.max_scale = 10; + this.min_scale = 0.1; + this.onredraw = null; + this.enabled = true; + this.last_mouse = [0,0]; + this.element = null; + this.visible_area = new Float32Array(4); + + if(element) + { + this.element = element; + if(!skip_events) + this.bindEvents( element ); + } +} + +LiteGraph.DragAndScale = DragAndScale; + +DragAndScale.prototype.bindEvents = function( element ) +{ + this.last_mouse = new Float32Array(2); + + this._binded_mouse_callback = this.onMouse.bind(this); + + element.addEventListener("mousedown", this._binded_mouse_callback ); + element.addEventListener("mousemove", this._binded_mouse_callback ); + + element.addEventListener("mousewheel", this._binded_mouse_callback, false); + element.addEventListener("wheel", this._binded_mouse_callback, false); +} + +DragAndScale.prototype.computeVisibleArea = function() +{ + if(!this.element) + { + this.visible_area[0] = this.visible_area[1] = this.visible_area[2] = this.visible_area[3] = 0; + return; + } + var width = this.element.width; + var height = this.element.height; + var startx = -this.offset[0]; + var starty = -this.offset[1]; + var endx = startx + width / this.scale; + var endy = starty + height / this.scale; + this.visible_area[0] = startx; + this.visible_area[1] = starty; + this.visible_area[2] = endx - startx; + this.visible_area[3] = endy - starty; +} + +DragAndScale.prototype.onMouse = function(e) +{ + if(!this.enabled) + return; + + var canvas = this.element; + var rect = canvas.getBoundingClientRect(); + var x = e.clientX - rect.left; + var y = e.clientY - rect.top; + e.canvasx = x; + e.canvasy = y; + e.dragging = this.dragging; + + var ignore = false; + if(this.onmouse) + ignore = this.onmouse(e); + + if(e.type == "mousedown") + { + this.dragging = true; + canvas.removeEventListener("mousemove", this._binded_mouse_callback ); + document.body.addEventListener("mousemove", this._binded_mouse_callback ); + document.body.addEventListener("mouseup", this._binded_mouse_callback ); + } + else if(e.type == "mousemove") + { + if(!ignore) + { + var deltax = x - this.last_mouse[0]; + var deltay = y - this.last_mouse[1]; + if( this.dragging ) + this.mouseDrag( deltax, deltay ); + } + } + else if(e.type == "mouseup") + { + this.dragging = false; + document.body.removeEventListener("mousemove", this._binded_mouse_callback ); + document.body.removeEventListener("mouseup", this._binded_mouse_callback ); + canvas.addEventListener("mousemove", this._binded_mouse_callback ); + } + else if(e.type == "mousewheel" || e.type == "wheel" || e.type == "DOMMouseScroll") + { + e.eventType = "mousewheel"; + if(e.type == "wheel") + e.wheel = -e.deltaY; + else + e.wheel = (e.wheelDeltaY != null ? e.wheelDeltaY : e.detail * -60); + + //from stack overflow + e.delta = e.wheelDelta ? e.wheelDelta/40 : e.deltaY ? -e.deltaY/3 : 0; + this.changeDeltaScale(1.0 + e.delta * 0.05); + } + + this.last_mouse[0] = x; + this.last_mouse[1] = y; + + e.preventDefault(); + e.stopPropagation(); + return false; +} + +DragAndScale.prototype.toCanvasContext = function( ctx ) +{ + ctx.scale( this.scale, this.scale ); + ctx.translate( this.offset[0], this.offset[1] ); +} + +DragAndScale.prototype.convertOffsetToCanvas = function(pos) +{ + //return [pos[0] / this.scale - this.offset[0], pos[1] / this.scale - this.offset[1]]; + return [ (pos[0] + this.offset[0]) * this.scale, (pos[1] + this.offset[1]) * this.scale ]; +} + +DragAndScale.prototype.convertCanvasToOffset = function(pos, out) +{ + out = out || [0,0]; + out[0] = pos[0] / this.scale - this.offset[0]; + out[1] = pos[1] / this.scale - this.offset[1]; + return out; +} + +DragAndScale.prototype.mouseDrag = function(x,y) +{ + this.offset[0] += x / this.scale; + this.offset[1] += y / this.scale; + + if( this.onredraw ) + this.onredraw( this ); +} + +DragAndScale.prototype.changeScale = function( value, zooming_center ) +{ + if(value < this.min_scale) + value = this.min_scale; + else if(value > this.max_scale) + value = this.max_scale; + + if(value == this.scale) + return; + + if(!this.element) + return; + + var rect = this.element.getBoundingClientRect(); + if(!rect) + return; + + zooming_center = zooming_center || [rect.width * 0.5,rect.height * 0.5]; + var center = this.convertCanvasToOffset( zooming_center ); + this.scale = value; + if( Math.abs( this.scale - 1 ) < 0.01 ) + this.scale = 1; + + var new_center = this.convertCanvasToOffset( zooming_center ); + var delta_offset = [new_center[0] - center[0], new_center[1] - center[1]]; + + this.offset[0] += delta_offset[0]; + this.offset[1] += delta_offset[1]; + + if( this.onredraw ) + this.onredraw( this ); +} + +DragAndScale.prototype.changeDeltaScale = function( value, zooming_center ) +{ + this.changeScale( this.scale * value, zooming_center ); +} + +DragAndScale.prototype.reset = function() +{ + this.scale = 1; + this.offset[0] = 0; + this.offset[1] = 0; +} + + //********************************************************************************* // LGraphCanvas: LGraph renderer CLASS //********************************************************************************* @@ -3489,18 +3758,17 @@ function LGraphCanvas( canvas, graph, options ) if(canvas && canvas.constructor === String ) canvas = document.querySelector( canvas ); - this.max_zoom = 10; - this.min_zoom = 0.1; + this.ds = new DragAndScale(); this.zoom_modify_alpha = true; //otherwise it generates ugly patterns when scaling down too much - this.title_text_font = "bold "+LiteGraph.NODE_TEXT_SIZE+"px Arial"; + this.title_text_font = ""+LiteGraph.NODE_TEXT_SIZE+"px Arial"; this.inner_text_font = "normal "+LiteGraph.NODE_SUBTEXT_SIZE+"px Arial"; this.node_title_color = LiteGraph.NODE_TITLE_COLOR; this.default_link_color = LiteGraph.LINK_COLOR; this.default_connection_color = { - input_off: "#AAB", + input_off: "#778", input_on: "#7F7", - output_off: "#AAB", + output_off: "#778", output_on: "#7F7" }; @@ -3508,7 +3776,6 @@ function LGraphCanvas( canvas, graph, options ) this.use_gradients = false; //set to true to render titlebar with gradients this.editor_alpha = 1; //used for transition this.pause_rendering = false; - this.render_shadows = true; this.clear_background = true; this.render_only_selected = true; @@ -3519,18 +3786,24 @@ function LGraphCanvas( canvas, graph, options ) this.allow_interaction = true; //allow to control widgets, buttons, collapse, etc this.allow_searchbox = true; this.allow_reconnect_links = false; //allows to change a connection with having to redo it again + this.drag_mode = false; this.dragging_rectangle = null; this.filter = null; //allows to filter to only accept some type of nodes in a graph this.always_render_background = false; + this.render_shadows = true; this.render_canvas_border = true; this.render_connections_shadows = false; //too much cpu this.render_connections_border = true; - this.render_curved_connections = true; - this.render_connection_arrows = true; + this.render_curved_connections = false; + this.render_connection_arrows = false; + this.render_collapsed_slots = true; this.render_execution_order = false; + this.render_title_colored = true; + + this.links_render_mode = LiteGraph.SPLINE_LINK; this.canvas_mouse = [0,0]; //mouse in canvas graph coordinates, where 0,0 is the top-left corner of the blue rectangle @@ -3550,7 +3823,7 @@ function LGraphCanvas( canvas, graph, options ) this.current_node = null; this.node_widget = null; //used for widgets this.last_mouse_position = [0,0]; - this.visible_area = new Float32Array(4); + this.visible_area = this.ds.visible_area; this.visible_links = []; //link canvas and graph @@ -3568,7 +3841,7 @@ function LGraphCanvas( canvas, graph, options ) global.LGraphCanvas = LiteGraph.LGraphCanvas = LGraphCanvas; -LGraphCanvas.link_type_colors = {"-1":"#F85",'number':"#AAA","node":"#DCA"}; +LGraphCanvas.link_type_colors = {"-1": LiteGraph.EVENT_LINK_COLOR,'number':"#AAA","node":"#DCA"}; LGraphCanvas.gradients = {}; //cache of gradients /** @@ -3583,8 +3856,8 @@ LGraphCanvas.prototype.clear = function() this.render_time = 0; this.fps = 0; - this.scale = 1; - this.offset = [0,0]; + //this.scale = 1; + //this.offset = [0,0]; this.dragging_rectangle = null; @@ -3726,6 +3999,7 @@ LGraphCanvas.prototype.setCanvas = function( canvas, skip_events ) } this.canvas = canvas; + this.ds.element = canvas; if(!canvas) return; @@ -4105,11 +4379,13 @@ LGraphCanvas.prototype.processMouseDown = function(e) } //Search for corner for collapsing + /* if( !skip_action && isInsideRectangle( e.canvasX, e.canvasY, node.pos[0], node.pos[1] - LiteGraph.NODE_TITLE_HEIGHT, LiteGraph.NODE_TITLE_HEIGHT, LiteGraph.NODE_TITLE_HEIGHT )) { node.collapse(); skip_action = true; } + */ //it wasnt clicked on the links boxes if(!skip_action) @@ -4179,7 +4455,7 @@ LGraphCanvas.prototype.processMouseDown = function(e) this.dragging_rectangle = null; var dist = distance( [e.canvasX, e.canvasY], [ this.selected_group.pos[0] + this.selected_group.size[0], this.selected_group.pos[1] + this.selected_group.size[1] ] ); - if( (dist * this.scale) < 10 ) + if( (dist * this.ds.scale) < 10 ) this.selected_group_resizing = true; else this.selected_group.recomputeInsideNodes(); @@ -4271,8 +4547,8 @@ LGraphCanvas.prototype.processMouseMove = function(e) this.selected_group.size = [ e.canvasX - this.selected_group.pos[0], e.canvasY - this.selected_group.pos[1] ]; else { - var deltax = delta[0] / this.scale; - var deltay = delta[1] / this.scale; + var deltax = delta[0] / this.ds.scale; + var deltay = delta[1] / this.ds.scale; this.selected_group.move( deltax, deltay, e.ctrlKey ); if( this.selected_group._nodes.length) this.dirty_canvas = true; @@ -4281,8 +4557,8 @@ LGraphCanvas.prototype.processMouseMove = function(e) } else if(this.dragging_canvas) { - this.offset[0] += delta[0] / this.scale; - this.offset[1] += delta[1] / this.scale; + this.ds.offset[0] += delta[0] / this.ds.scale; + this.ds.offset[1] += delta[1] / this.ds.scale; this.dirty_canvas = true; this.dirty_bgcanvas = true; } @@ -4357,7 +4633,7 @@ LGraphCanvas.prototype.processMouseMove = function(e) if( isInsideRectangle(e.canvasX, e.canvasY, node.pos[0] + node.size[0] - 5, node.pos[1] + node.size[1] - 5 ,5,5 )) this.canvas.style.cursor = "se-resize"; else - this.canvas.style.cursor = ""; + this.canvas.style.cursor = "crosshair"; } } else if(this.canvas) @@ -4374,8 +4650,8 @@ LGraphCanvas.prototype.processMouseMove = function(e) for(var i in this.selected_nodes) { var n = this.selected_nodes[i]; - n.pos[0] += delta[0] / this.scale; - n.pos[1] += delta[1] / this.scale; + n.pos[0] += delta[0] / this.ds.scale; + n.pos[1] += delta[1] / this.ds.scale; } this.dirty_canvas = true; @@ -4524,6 +4800,10 @@ LGraphCanvas.prototype.processMouseUp = function(e) } else if(this.node_dragged) //node being dragged? { + var node = this.node_dragged; + if( node && e.click_time < 300 && isInsideRectangle( e.canvasX, e.canvasY, node.pos[0], node.pos[1] - LiteGraph.NODE_TITLE_HEIGHT, LiteGraph.NODE_TITLE_HEIGHT, LiteGraph.NODE_TITLE_HEIGHT )) + node.collapse(); + this.dirty_canvas = true; this.dirty_bgcanvas = true; this.node_dragged.pos[0] = Math.round(this.node_dragged.pos[0]); @@ -4536,6 +4816,7 @@ LGraphCanvas.prototype.processMouseUp = function(e) { //get node over var node = this.graph.getNodeOnPos( e.canvasX, e.canvasY, this.visible_nodes ); + if ( !node && e.click_time < 300 ) this.deselectAllNodes(); @@ -4586,19 +4867,15 @@ LGraphCanvas.prototype.processMouseWheel = function(e) this.adjustMouseEvent(e); - var zoom = this.scale; + var scale = this.ds.scale; if (delta > 0) - zoom *= 1.1; + scale *= 1.1; else if (delta < 0) - zoom *= 1/(1.1); + scale *= 1/(1.1); - this.setZoom( zoom, [ e.localX, e.localY ] ); - - /* - if(this.rendering_timer_id == null) - this.draw(); - */ + //this.setZoom( scale, [ e.localX, e.localY ] ); + this.ds.changeScale( scale, [ e.localX, e.localY ] ); this.graph.change(); @@ -4613,7 +4890,7 @@ LGraphCanvas.prototype.processMouseWheel = function(e) LGraphCanvas.prototype.isOverNodeBox = function( node, canvasx, canvasy ) { var title_height = LiteGraph.NODE_TITLE_HEIGHT; - if( isInsideRectangle( canvasx, canvasy, node.pos[0] + 2, node.pos[1] + 2 - title_height, title_height - 4,title_height - 4) ) + if( isInsideRectangle( canvasx, canvasy, node.pos[0] + 2, node.pos[1] + 2 - title_height, title_height - 4, title_height - 4) ) return true; return false; } @@ -4726,6 +5003,7 @@ LGraphCanvas.prototype.processKey = function(e) if(block_default) { e.preventDefault(); + e.stopImmediatePropagation(); return false; } } @@ -5043,8 +5321,8 @@ LGraphCanvas.prototype.deleteSelectedNodes = function() **/ LGraphCanvas.prototype.centerOnNode = function(node) { - this.offset[0] = -node.pos[0] - node.size[0] * 0.5 + (this.canvas.width * 0.5 / this.scale); - this.offset[1] = -node.pos[1] - node.size[1] * 0.5 + (this.canvas.height * 0.5 / this.scale); + this.ds.offset[0] = -node.pos[0] - node.size[0] * 0.5 + (this.canvas.width * 0.5 / this.ds.scale); + this.ds.offset[1] = -node.pos[1] - node.size[1] * 0.5 + (this.canvas.height * 0.5 / this.ds.scale); this.setDirty(true,true); } @@ -5057,13 +5335,13 @@ LGraphCanvas.prototype.adjustMouseEvent = function(e) if(this.canvas) { var b = this.canvas.getBoundingClientRect(); - e.localX = e.pageX - b.left; - e.localY = e.pageY - b.top; + e.localX = e.clientX - b.left; + e.localY = e.clientY - b.top; } else { - e.localX = e.pageX; - e.localY = e.pageY; + e.localX = e.clientX; + e.localY = e.clientY; } e.deltaX = e.localX - this.last_mouse_position[0]; @@ -5072,8 +5350,8 @@ LGraphCanvas.prototype.adjustMouseEvent = function(e) this.last_mouse_position[0] = e.localX; this.last_mouse_position[1] = e.localY; - e.canvasX = e.localX / this.scale - this.offset[0]; - e.canvasY = e.localY / this.scale - this.offset[1]; + e.canvasX = e.localX / this.ds.scale - this.ds.offset[0]; + e.canvasY = e.localY / this.ds.scale - this.ds.offset[1]; } /** @@ -5082,12 +5360,14 @@ LGraphCanvas.prototype.adjustMouseEvent = function(e) **/ LGraphCanvas.prototype.setZoom = function(value, zooming_center) { + this.ds.changeScale( value, zooming_center); + /* if(!zooming_center && this.canvas) zooming_center = [this.canvas.width * 0.5,this.canvas.height * 0.5]; var center = this.convertOffsetToCanvas( zooming_center ); - this.scale = value; + this.ds.scale = value; if(this.scale > this.max_zoom) this.scale = this.max_zoom; @@ -5099,39 +5379,35 @@ LGraphCanvas.prototype.setZoom = function(value, zooming_center) this.offset[0] += delta_offset[0]; this.offset[1] += delta_offset[1]; + */ this.dirty_canvas = true; this.dirty_bgcanvas = true; } /** -* converts a coordinate in canvas2D space to graphcanvas space (NAME IS CONFUSION, SHOULD BE THE OTHER WAY AROUND) +* converts a coordinate from graph coordinates to canvas2D coordinates * @method convertOffsetToCanvas **/ LGraphCanvas.prototype.convertOffsetToCanvas = function( pos, out ) { - out = out || []; - out[0] = pos[0] / this.scale - this.offset[0]; - out[1] = pos[1] / this.scale - this.offset[1]; - return out; + return this.ds.convertOffsetToCanvas( pos, out ); } /** -* converts a coordinate in graphcanvas space to canvas2D space (NAME IS CONFUSION, SHOULD BE THE OTHER WAY AROUND) +* converts a coordinate from Canvas2D coordinates to graph space * @method convertCanvasToOffset **/ LGraphCanvas.prototype.convertCanvasToOffset = function( pos, out ) { - out = out || []; - out[0] = (pos[0] + this.offset[0]) * this.scale; - out[1] = (pos[1] + this.offset[1]) * this.scale; - return out; + return this.ds.convertCanvasToOffset( pos, out ); } -LGraphCanvas.prototype.convertEventToCanvas = function(e) +//converts event coordinates from canvas2D to graph coordinates +LGraphCanvas.prototype.convertEventToCanvasOffset = function(e) { var rect = this.canvas.getBoundingClientRect(); - return this.convertOffsetToCanvas([e.pageX - rect.left,e.pageY - rect.top]); + return this.convertCanvasToOffset([e.clientX - rect.left,e.clientY - rect.top]); } /** @@ -5207,16 +5483,7 @@ LGraphCanvas.prototype.draw = function(force_canvas, force_bgcanvas) this.last_draw_time = now; if(this.graph) - { - var startx = -this.offset[0]; - var starty = -this.offset[1]; - var endx = startx + this.canvas.width / this.scale; - var endy = starty + this.canvas.height / this.scale; - this.visible_area[0] = startx; - this.visible_area[1] = starty; - this.visible_area[2] = endx - startx; - this.visible_area[3] = endy - starty; - } + this.ds.computeVisibleArea(); if(this.dirty_bgcanvas || force_bgcanvas || this.always_render_background || (this.graph && this.graph._last_trigger_time && (now - this.graph._last_trigger_time) < 1000) ) this.drawBackCanvas(); @@ -5283,8 +5550,7 @@ LGraphCanvas.prototype.drawFrontCanvas = function() { //apply transformations ctx.save(); - ctx.scale(this.scale,this.scale); - ctx.translate( this.offset[0],this.offset[1] ); + this.ds.toCanvasContext( ctx ); //draw nodes var drawn_nodes = 0; @@ -5456,14 +5722,13 @@ LGraphCanvas.prototype.drawBackCanvas = function() { //apply transformations ctx.save(); - ctx.scale(this.scale,this.scale); - ctx.translate(this.offset[0],this.offset[1]); + this.ds.toCanvasContext(ctx); //render BG - if(this.background_image && this.scale > 0.5 && !bg_already_painted) + if(this.background_image && this.ds.scale > 0.5 && !bg_already_painted) { if (this.zoom_modify_alpha) - ctx.globalAlpha = (1.0 - 0.5 / this.scale) * this.editor_alpha; + ctx.globalAlpha = (1.0 - 0.5 / this.ds.scale) * this.editor_alpha; else ctx.globalAlpha = this.editor_alpha; ctx.imageSmoothingEnabled = ctx.mozImageSmoothingEnabled = ctx.imageSmoothingEnabled = false; @@ -5574,7 +5839,6 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) if(node.onDrawForeground) node.onDrawForeground(ctx, this, this.canvas ); } - return; } @@ -5584,9 +5848,9 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) if(this.render_shadows) { ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR; - ctx.shadowOffsetX = 2 * this.scale; - ctx.shadowOffsetY = 2 * this.scale; - ctx.shadowBlur = 3 * this.scale; + ctx.shadowOffsetX = 2 * this.ds.scale; + ctx.shadowOffsetY = 2 * this.ds.scale; + ctx.shadowBlur = 3 * this.ds.scale; } else ctx.shadowColor = "transparent"; @@ -5605,9 +5869,12 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) { ctx.font = this.inner_text_font; var title = node.getTitle ? node.getTitle() : node.title; - node._collapsed_width = Math.min( node.size[0], ctx.measureText(title).width + 40 );//LiteGraph.NODE_COLLAPSED_WIDTH; - size[0] = node._collapsed_width; - size[1] = 0; + if(title != null) + { + node._collapsed_width = Math.min( node.size[0], ctx.measureText(title).width + LiteGraph.NODE_TITLE_HEIGHT * 2 );//LiteGraph.NODE_COLLAPSED_WIDTH; + size[0] = node._collapsed_width; + size[1] = 0; + } } if( node.clip_area ) //Start clipping @@ -5629,11 +5896,15 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) this.drawNodeShape( node, ctx, size, color, bgcolor, node.is_selected, node.mouseOver ); ctx.shadowColor = "transparent"; + //draw foreground + if(node.onDrawForeground) + node.onDrawForeground( ctx, this, this.canvas ); + //connection slots ctx.textAlign = horizontal ? "center" : "left"; ctx.font = this.inner_text_font; - var render_text = this.scale > 0.6; + var render_text = this.ds.scale > 0.6; var out_slot = this.connecting_output; ctx.lineWidth = 1; @@ -5765,12 +6036,8 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) max_y = 2; this.drawNodeWidgets( node, max_y, ctx, (this.node_widget && this.node_widget[0] == node) ? this.node_widget[1] : null ); } - - //draw foreground - if(node.onDrawForeground) - node.onDrawForeground( ctx, this, this.canvas ); } - else //if collapsed + else if(this.render_collapsed_slots)//if collapsed { var input_slot = null; var output_slot = null; @@ -5807,10 +6074,10 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) x = node._collapsed_width * 0.5; y = -LiteGraph.NODE_TITLE_HEIGHT; } - ctx.fillStyle = slot.color_on || this.default_connection_color.input_on; + ctx.fillStyle = "#686"; ctx.beginPath(); if ( slot.type === LiteGraph.EVENT || slot.shape === LiteGraph.BOX_SHAPE) { - ctx.rect(x - 7 + 0.5, y + 4 - LiteGraph.NODE_TITLE_HEIGHT * 0.5 + 0.5,14,LiteGraph.NODE_TITLE_HEIGHT - 8); + ctx.rect(x - 7 + 0.5, y-4,14,8); } else if (slot.shape === LiteGraph.ARROW_SHAPE) { ctx.moveTo(x + 8, y); ctx.lineTo(x + -4, y - 4); @@ -5831,11 +6098,11 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) x = node._collapsed_width * 0.5; y = 0; } - ctx.fillStyle = slot.color_on || this.default_connection_color.output_on; + ctx.fillStyle = "#686"; ctx.strokeStyle = "black"; ctx.beginPath(); if (slot.type === LiteGraph.EVENT || slot.shape === LiteGraph.BOX_SHAPE) { - ctx.rect( x - 7 + 0.5, y + 4 - LiteGraph.NODE_TITLE_HEIGHT * 0.5 + 0.5,14,LiteGraph.NODE_TITLE_HEIGHT - 8); + ctx.rect( x - 7 + 0.5, y - 4,14,8); } else if (slot.shape === LiteGraph.ARROW_SHAPE) { ctx.moveTo(x + 6, y); ctx.lineTo(x - 6, y - 4); @@ -5845,7 +6112,7 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) ctx.arc(x, y, 4, 0, Math.PI * 2); } ctx.fill(); - ctx.stroke(); + //ctx.stroke(); } } @@ -5868,9 +6135,11 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol ctx.fillStyle = bgcolor; var title_height = LiteGraph.NODE_TITLE_HEIGHT; + var low_quality = this.ds.scale < 0.5; //render node area depending on shape - var shape = node._shape || node.constructor.shape || LiteGraph.BOX_SHAPE; + var shape = node._shape || node.constructor.shape || LiteGraph.ROUND_SHAPE; + var title_mode = node.constructor.title_mode; var render_title = true; @@ -5885,62 +6154,62 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol area[2] = size[0]+1; //w area[3] = render_title ? size[1] + title_height : size[1]; //h + var old_alpha = ctx.globalAlpha; + //full node shape - if(!node.flags.collapsed) + //if(node.flags.collapsed) { ctx.beginPath(); - if(shape == LiteGraph.BOX_SHAPE || this.scale < 0.5) + if(shape == LiteGraph.BOX_SHAPE || low_quality ) ctx.fillRect( area[0], area[1], area[2], area[3] ); else if (shape == LiteGraph.ROUND_SHAPE || shape == LiteGraph.CARD_SHAPE) ctx.roundRect( area[0], area[1], area[2], area[3], this.round_radius, shape == LiteGraph.CARD_SHAPE ? 0 : this.round_radius); else if (shape == LiteGraph.CIRCLE_SHAPE) ctx.arc(size[0] * 0.5, size[1] * 0.5, size[0] * 0.5, 0, Math.PI*2); ctx.fill(); + + ctx.shadowColor = "transparent"; + ctx.fillStyle = "rgba(0,0,0,0.2)"; + ctx.fillRect(0,-1, area[2],2); } ctx.shadowColor = "transparent"; - //image - if (node.bgImage && node.bgImage.width) - ctx.drawImage( node.bgImage, (size[0] - node.bgImage.width) * 0.5 , (size[1] - node.bgImage.height) * 0.5); - - if(node.bgImageUrl && !node.bgImage) - node.bgImage = node.loadImage(node.bgImageUrl); - if( node.onDrawBackground ) node.onDrawBackground( ctx, this, this.canvas ); //title bg (remember, it is rendered ABOVE the node) - if(render_title || title_mode == LiteGraph.TRANSPARENT_TITLE ) + if( render_title || title_mode == LiteGraph.TRANSPARENT_TITLE ) { //title bar if(node.onDrawTitleBar) { - node.onDrawTitleBar(ctx, title_height, size, this.scale, fgcolor); + node.onDrawTitleBar(ctx, title_height, size, this.ds.scale, fgcolor); } - else if(title_mode != LiteGraph.TRANSPARENT_TITLE) //!node.flags.collapsed) + else if(title_mode != LiteGraph.TRANSPARENT_TITLE && (node.constructor.title_color || this.render_title_colored )) { + var title_color = node.constructor.title_color || fgcolor; + if(node.flags.collapsed) ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR; //* gradient test if(this.use_gradients) { - var grad = LGraphCanvas.gradients[ fgcolor ]; + var grad = LGraphCanvas.gradients[ title_color ]; if(!grad) { - grad = LGraphCanvas.gradients[ fgcolor ] = ctx.createLinearGradient(0,0,400,0); - grad.addColorStop(0, fgcolor); + grad = LGraphCanvas.gradients[ title_color ] = ctx.createLinearGradient(0,0,400,0); + grad.addColorStop(0, title_color); grad.addColorStop(1, "#000"); } ctx.fillStyle = grad; } else - ctx.fillStyle = fgcolor; + ctx.fillStyle = title_color; - var old_alpha = ctx.globalAlpha; //ctx.globalAlpha = 0.5 * old_alpha; ctx.beginPath(); - if(shape == LiteGraph.BOX_SHAPE || this.scale < 0.5) + if( shape == LiteGraph.BOX_SHAPE || low_quality ) ctx.rect(0, -title_height, size[0]+1, title_height); else if ( shape == LiteGraph.ROUND_SHAPE || shape == LiteGraph.CARD_SHAPE ) ctx.roundRect(0,-title_height,size[0]+1, title_height, this.round_radius, node.flags.collapsed ? this.round_radius : 0); @@ -5949,43 +6218,44 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol } //title box + var box_size = 10; if(node.onDrawTitleBox) { - node.onDrawTitleBox( ctx, title_height, size, this.scale ); + node.onDrawTitleBox( ctx, title_height, size, this.ds.scale ); } else if ( shape == LiteGraph.ROUND_SHAPE || shape == LiteGraph.CIRCLE_SHAPE || shape == LiteGraph.CARD_SHAPE ) { - if( this.scale > 0.5 ) + if( low_quality ) { ctx.fillStyle = "black"; ctx.beginPath(); - ctx.arc(title_height *0.5, title_height * -0.5, (title_height - 8) *0.5,0,Math.PI*2); + ctx.arc(title_height * 0.5, title_height * -0.5, box_size*0.5+1,0,Math.PI*2); ctx.fill(); } ctx.fillStyle = node.boxcolor || LiteGraph.NODE_DEFAULT_BOXCOLOR; ctx.beginPath(); - ctx.arc(title_height *0.5, title_height * -0.5, (title_height - 8) *0.4,0,Math.PI*2); + ctx.arc(title_height * 0.5, title_height * -0.5, box_size*0.5,0,Math.PI*2); ctx.fill(); } else { - if( this.scale > 0.5 ) + if( low_quality ) { ctx.fillStyle = "black"; - ctx.fillRect(4,-title_height + 4,title_height - 8,title_height - 8); + ctx.fillRect( (title_height - box_size) * 0.5 - 1, (title_height + box_size ) * -0.5 - 1, box_size + 2, box_size + 2); } ctx.fillStyle = node.boxcolor || LiteGraph.NODE_DEFAULT_BOXCOLOR; - ctx.fillRect(5,-title_height + 5,title_height - 10,title_height - 10); + ctx.fillRect( (title_height - box_size) * 0.5, (title_height + box_size ) * -0.5, box_size, box_size ); } ctx.globalAlpha = old_alpha; //title text if(node.onDrawTitleText) { - node.onDrawTitleText(ctx, title_height, size, this.scale, this.title_text_font, selected); + node.onDrawTitleText( ctx, title_height, size, this.ds.scale, this.title_text_font, selected); } - if( this.scale > 0.5 ) + if( !low_quality ) { ctx.font = this.title_text_font; var title = node.getTitle(); @@ -5999,13 +6269,13 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol { ctx.textAlign = "center"; var measure = ctx.measureText(title); - ctx.fillText( title, title_height + measure.width * 0.5, -title_height * 0.2 ); + ctx.fillText( title, title_height + measure.width * 0.5, LiteGraph.NODE_TITLE_TEXT_Y - title_height ); ctx.textAlign = "left"; } else { ctx.textAlign = "left"; - ctx.fillText( title, title_height, -title_height * 0.2 ); + ctx.fillText( title, title_height, LiteGraph.NODE_TITLE_TEXT_Y - title_height ); } } } @@ -6028,7 +6298,7 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol ctx.lineWidth = 1; ctx.globalAlpha = 0.8; ctx.beginPath(); - if(shape == LiteGraph.BOX_SHAPE) + if( shape == LiteGraph.BOX_SHAPE ) ctx.rect(-6 + area[0],-6 + area[1], 12 + area[2], 12 + area[3] ); else if (shape == LiteGraph.ROUND_SHAPE || (shape == LiteGraph.CARD_SHAPE && node.flags.collapsed) ) ctx.roundRect(-6 + area[0],-6 + area[1], 12 + area[2], 12 + area[3] , this.round_radius * 2); @@ -6043,6 +6313,11 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol } } +var margin_area = new Float32Array(4); +var link_bounding = new Float32Array(4); +var tempA = new Float32Array(2); +var tempB = new Float32Array(2); + /** * draws every connection visible in the canvas * OPTIMIZE THIS: precatch connections position instead of recomputing them every time @@ -6052,10 +6327,7 @@ LGraphCanvas.prototype.drawConnections = function(ctx) { var now = LiteGraph.getTime(); var visible_area = this.visible_area; - var margin_area = new Float32Array([visible_area[0] - 20, visible_area[1] - 20, visible_area[2] + 40, visible_area[3] + 40 ]); - var link_bounding = new Float32Array(4); - var tempA = new Float32Array(2); - var tempB = new Float32Array(2); + margin_area[0] = visible_area[0] - 20; margin_area[1] = visible_area[1] - 20; margin_area[2] = visible_area[2] + 40; margin_area[3] = visible_area[3] + 40; //draw connections ctx.lineWidth = this.connections_width; @@ -6144,82 +6416,117 @@ LGraphCanvas.prototype.drawConnections = function(ctx) * @param {string} color the color for the link * @param {number} start_dir the direction enum * @param {number} end_dir the direction enum +* @param {number} num_sublines number of sublines (useful to represent vec3 or rgb) **/ -LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow, color, start_dir, end_dir ) +LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow, color, start_dir, end_dir, num_sublines ) { if(link) this.visible_links.push( link ); - if(!this.highquality_render) - { - ctx.beginPath(); - ctx.moveTo(a[0],a[1]); - ctx.lineTo(b[0],b[1]); - ctx.stroke(); - - if(link && link._pos) - { - link._pos[0] = (a[0] + b[0]) * 0.5; - link._pos[1] = (a[1] + b[1]) * 0.5; - } - return; - } - - start_dir = start_dir || LiteGraph.RIGHT; - end_dir = end_dir || LiteGraph.LEFT; - - var dist = distance(a,b); - - if(this.render_connections_border && this.scale > 0.6) - ctx.lineWidth = this.connections_width + 4; - //choose color if( !color && link ) color = link.color || LGraphCanvas.link_type_colors[ link.type ]; if( !color ) color = this.default_link_color; - if( link != null && this.highlighted_links[ link.id ] ) color = "#FFF"; + start_dir = start_dir || LiteGraph.RIGHT; + end_dir = end_dir || LiteGraph.LEFT; + + var dist = distance(a,b); + + if(this.render_connections_border && this.ds.scale > 0.6) + ctx.lineWidth = this.connections_width + 4; + ctx.lineJoin = "round"; + num_sublines = num_sublines || 1; + if(num_sublines > 1) + ctx.lineWidth = 0.5; + //begin line shape ctx.beginPath(); + for(var i = 0; i < num_sublines; i += 1) + { + var offsety = (i - (num_sublines-1)*0.5)*5; - if(this.render_curved_connections) //splines - { - ctx.moveTo(a[0],a[1]); - var start_offset_x = 0; - var start_offset_y = 0; - var end_offset_x = 0; - var end_offset_y = 0; - switch(start_dir) + if(this.links_render_mode == LiteGraph.SPLINE_LINK) { - case LiteGraph.LEFT: start_offset_x = dist*-0.25; break; - case LiteGraph.RIGHT: start_offset_x = dist*0.25; break; - case LiteGraph.UP: start_offset_y = dist*-0.25; break; - case LiteGraph.DOWN: start_offset_y = dist*0.25; break; + ctx.moveTo(a[0],a[1] + offsety); + var start_offset_x = 0; + var start_offset_y = 0; + var end_offset_x = 0; + var end_offset_y = 0; + switch(start_dir) + { + case LiteGraph.LEFT: start_offset_x = dist*-0.25; break; + case LiteGraph.RIGHT: start_offset_x = dist*0.25; break; + case LiteGraph.UP: start_offset_y = dist*-0.25; break; + case LiteGraph.DOWN: start_offset_y = dist*0.25; break; + } + switch(end_dir) + { + case LiteGraph.LEFT: end_offset_x = dist*-0.25; break; + case LiteGraph.RIGHT: end_offset_x = dist*0.25; break; + case LiteGraph.UP: end_offset_y = dist*-0.25; break; + case LiteGraph.DOWN: end_offset_y = dist*0.25; break; + } + ctx.bezierCurveTo(a[0] + start_offset_x, a[1] + start_offset_y + offsety, + b[0] + end_offset_x , b[1] + end_offset_y + offsety, + b[0], b[1] + offsety); } - switch(end_dir) + else if(this.links_render_mode == LiteGraph.LINEAR_LINK) { - case LiteGraph.LEFT: end_offset_x = dist*-0.25; break; - case LiteGraph.RIGHT: end_offset_x = dist*0.25; break; - case LiteGraph.UP: end_offset_y = dist*-0.25; break; - case LiteGraph.DOWN: end_offset_y = dist*0.25; break; + ctx.moveTo(a[0],a[1] + offsety); + var start_offset_x = 0; + var start_offset_y = 0; + var end_offset_x = 0; + var end_offset_y = 0; + switch(start_dir) + { + case LiteGraph.LEFT: start_offset_x = -1; break; + case LiteGraph.RIGHT: start_offset_x = 1; break; + case LiteGraph.UP: start_offset_y = -1; break; + case LiteGraph.DOWN: start_offset_y = 1; break; + } + switch(end_dir) + { + case LiteGraph.LEFT: end_offset_x = -1; break; + case LiteGraph.RIGHT: end_offset_x = 1; break; + case LiteGraph.UP: end_offset_y = -1; break; + case LiteGraph.DOWN: end_offset_y = 1; break; + } + var l = 15; + ctx.lineTo(a[0] + start_offset_x * l, a[1] + start_offset_y * l + offsety); + ctx.lineTo(b[0] + end_offset_x * l, b[1] + end_offset_y * l + offsety); + ctx.lineTo(b[0],b[1] + offsety); } - ctx.bezierCurveTo(a[0] + start_offset_x, a[1] + start_offset_y, - b[0] + end_offset_x , b[1] + end_offset_y, - b[0], b[1] ); - } - else //lines - { - ctx.moveTo(a[0]+10,a[1]); - ctx.lineTo(((a[0]+10) + (b[0]-10))*0.5,a[1]); - ctx.lineTo(((a[0]+10) + (b[0]-10))*0.5,b[1]); - ctx.lineTo(b[0]-10,b[1]); + else if(this.links_render_mode == LiteGraph.STRAIGHT_LINK) + { + ctx.moveTo(a[0], a[1]); + var start_x = a[0]; + var start_y = a[1]; + var end_x = b[0]; + var end_y = b[1]; + if( start_dir == LiteGraph.RIGHT ) + start_x += 10; + else + start_y += 10; + if( end_dir == LiteGraph.LEFT ) + end_x -= 10; + else + end_y -= 10; + ctx.lineTo(start_x, start_y); + ctx.lineTo((start_x + end_x)*0.5,start_y); + ctx.lineTo((start_x + end_x)*0.5,end_y); + ctx.lineTo(end_x, end_y); + ctx.lineTo(b[0],b[1]); + } + else + return; //unknown } //rendering the outline of the connection can be a little bit slow - if(this.render_connections_border && this.scale > 0.6 && !skip_border) + if(this.render_connections_border && this.ds.scale > 0.6 && !skip_border) { ctx.strokeStyle = "rgba(0,0,0,0.5)"; ctx.stroke(); @@ -6238,10 +6545,10 @@ LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow } //render arrow in the middle - if( this.render_connection_arrows && this.scale >= 0.6 ) + if( this.ds.scale >= 0.6 && this.highquality_render && end_dir != LiteGraph.CENTER ) { //render arrow - if(this.render_connection_arrows && this.scale > 0.6) + if( this.render_connection_arrows ) { //compute two points in the connection var posA = this.computeConnectionPoint( a, b, 0.25, start_dir, end_dir ); @@ -6279,12 +6586,12 @@ LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow ctx.lineTo(+5,-3); ctx.fill(); ctx.restore(); - - //circle - ctx.beginPath(); - ctx.arc(pos[0],pos[1],5,0,Math.PI*2); - ctx.fill(); } + + //circle + ctx.beginPath(); + ctx.arc(pos[0],pos[1],5,0,Math.PI*2); + ctx.fill(); } //render flowing points @@ -6302,6 +6609,7 @@ LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow } } +//returns the link center point based on curvature LGraphCanvas.prototype.computeConnectionPoint = function(a,b,t,start_dir,end_dir) { start_dir = start_dir || LiteGraph.RIGHT; @@ -6374,9 +6682,12 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge var widgets = node.widgets; posY += 2; var H = LiteGraph.NODE_WIDGET_HEIGHT; - var show_text = this.scale > 0.5; + var show_text = this.ds.scale > 0.5; ctx.save(); ctx.globalAlpha = this.editor_alpha; + var outline_color = "#666"; + var background_color = "#222"; + var margin = 15; for(var i = 0; i < widgets.length; ++i) { @@ -6385,7 +6696,7 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge if(w.y) y = w.y; w.last_y = y; - ctx.strokeStyle = "#AAA"; + ctx.strokeStyle = outline_color; ctx.fillStyle = "#222"; ctx.textAlign = "left"; @@ -6398,8 +6709,8 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge w.clicked = false; this.dirty_canvas = true; } - ctx.fillRect(10,y,width-20,H); - ctx.strokeRect(10,y,width-20,H); + ctx.fillRect(margin,y,width-margin*2,H); + ctx.strokeRect(margin,y,width-margin*2,H); if(show_text) { ctx.textAlign = "center"; @@ -6409,39 +6720,39 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge break; case "toggle": ctx.textAlign = "left"; - ctx.strokeStyle = "#AAA"; - ctx.fillStyle = "#111"; + ctx.strokeStyle = outline_color; + ctx.fillStyle = background_color; ctx.beginPath(); - ctx.roundRect( 10, posY, width - 20, H,H*0.5 ); + ctx.roundRect( margin, posY, width - margin*2, H,H*0.5 ); ctx.fill(); ctx.stroke(); ctx.fillStyle = w.value ? "#89A" : "#333"; ctx.beginPath(); - ctx.arc( width - 20, y + H*0.5, H * 0.36, 0, Math.PI * 2 ); + ctx.arc( width - margin*2, y + H*0.5, H * 0.36, 0, Math.PI * 2 ); ctx.fill(); if(show_text) { ctx.fillStyle = "#999"; if(w.name != null) - ctx.fillText( w.name, 20, y + H*0.7 ); + ctx.fillText( w.name, margin*2, y + H*0.7 ); ctx.fillStyle = w.value ? "#DDD" : "#888"; ctx.textAlign = "right"; - ctx.fillText( w.value ? (w.options.on || "true") : (w.options.off || "false"), width - 30, y + H*0.7 ); + ctx.fillText( w.value ? (w.options.on || "true") : (w.options.off || "false"), width - 40, y + H*0.7 ); } break; case "slider": - ctx.fillStyle = "#111"; - ctx.fillRect(10,y,width-20,H); + ctx.fillStyle = background_color; + ctx.fillRect(margin,y,width-margin*2,H); var range = w.options.max - w.options.min; var nvalue = (w.value - w.options.min) / range; ctx.fillStyle = active_widget == w ? "#89A" : "#678"; - ctx.fillRect(10,y,nvalue*(width-20),H); - ctx.strokeRect(10,y,width-20,H); + ctx.fillRect(margin,y,nvalue*(width-margin*2),H); + ctx.strokeRect(margin,y,width-margin*2,H); if( w.marker ) { var marker_nvalue = (w.marker - w.options.min) / range; ctx.fillStyle = "#AA9"; - ctx.fillRect(10 + marker_nvalue*(width-20),y,2,H); + ctx.fillRect(margin + marker_nvalue*(width-margin*2),y,2,H); } if(show_text) { @@ -6453,50 +6764,50 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge case "number": case "combo": ctx.textAlign = "left"; - ctx.strokeStyle = "#AAA"; - ctx.fillStyle = "#111"; + ctx.strokeStyle = outline_color; + ctx.fillStyle = background_color; ctx.beginPath(); - ctx.roundRect( 10, posY, width - 20, H,H*0.5 ); + ctx.roundRect( margin, posY, width - margin*2, H,H*0.5 ); ctx.fill(); ctx.stroke(); if(show_text) { ctx.fillStyle = "#AAA"; ctx.beginPath(); - ctx.moveTo( 26, posY + 5 ); - ctx.lineTo( 16, posY + H*0.5 ); - ctx.lineTo( 26, posY + H - 5 ); - ctx.moveTo( width - 26, posY + 5 ); - ctx.lineTo( width - 16, posY + H*0.5 ); - ctx.lineTo( width - 26, posY + H - 5 ); + ctx.moveTo( margin + 16, posY + 5 ); + ctx.lineTo( margin + 6, posY + H*0.5 ); + ctx.lineTo( margin + 16, posY + H - 5 ); + ctx.moveTo( width - margin - 16, posY + 5 ); + ctx.lineTo( width - margin - 6, posY + H*0.5 ); + ctx.lineTo( width - margin - 16, posY + H - 5 ); ctx.fill(); ctx.fillStyle = "#999"; - ctx.fillText( w.name, 30, y + H*0.7 ); + ctx.fillText( w.name, margin*2 + 5, y + H*0.7 ); ctx.fillStyle = "#DDD"; ctx.textAlign = "right"; if(w.type == "number") - ctx.fillText( Number(w.value).toFixed( w.options.precision !== undefined ? w.options.precision : 3), width - 40, y + H*0.7 ); + ctx.fillText( Number(w.value).toFixed( w.options.precision !== undefined ? w.options.precision : 3), width - margin*2 - 20, y + H*0.7 ); else - ctx.fillText( w.value, width - 40, y + H*0.7 ); + ctx.fillText( w.value, width - margin*2 - 20, y + H*0.7 ); } break; case "string": case "text": ctx.textAlign = "left"; - ctx.strokeStyle = "#AAA"; - ctx.fillStyle = "#111"; + ctx.strokeStyle = outline_color; + ctx.fillStyle = background_color; ctx.beginPath(); - ctx.roundRect( 10, posY, width - 20, H,H*0.5 ); + ctx.roundRect( margin, posY, width - margin*2, H,H*0.5 ); ctx.fill(); ctx.stroke(); if(show_text) { ctx.fillStyle = "#999"; if(w.name != null) - ctx.fillText( w.name, 20, y + H*0.7 ); + ctx.fillText( w.name, margin*2, y + H*0.7 ); ctx.fillStyle = "#DDD"; ctx.textAlign = "right"; - ctx.fillText( w.value, width - 20, y + H*0.7 ); + ctx.fillText( w.value, width - margin*2, y + H*0.7 ); } break; default: @@ -6582,7 +6893,7 @@ LGraphCanvas.prototype.processNodeWidgets = function( node, pos, event, active_w } else { - var menu = new LiteGraph.ContextMenu( values, { event: event, className: "dark", callback: inner_clicked.bind(w) }, ref_window ); + var menu = new LiteGraph.ContextMenu( values, { scale: Math.max(1,this.ds.scale), event: event, className: "dark", callback: inner_clicked.bind(w) }, ref_window ); function inner_clicked( v, option, event ) { this.value = v; @@ -6666,6 +6977,15 @@ LGraphCanvas.prototype.drawGroups = function(canvas, ctx) ctx.restore(); } +LGraphCanvas.prototype.adjustNodesSize = function() +{ + var nodes = this.graph._nodes; + for(var i = 0; i < nodes.length; ++i) + nodes[i].size = nodes[i].computeSize(); + this.setDirty(true,true); +} + + /** * resizes the canvas to a given size, if no size is passed, then it tries to fill the parentNode * @method resize @@ -6775,7 +7095,7 @@ LGraphCanvas.onGroupAdd = function(info,entry,mouse_event) var ref_window = canvas.getCanvasWindow(); var group = new LiteGraph.LGraphGroup(); - group.pos = canvas.convertEventToCanvas( mouse_event ); + group.pos = canvas.convertEventToCanvasOffset( mouse_event ); canvas.graph.add( group ); } @@ -6812,7 +7132,7 @@ LGraphCanvas.onMenuAdd = function( node, options, e, prev_menu ) var node = LiteGraph.createNode( v.value ); if(node) { - node.pos = canvas.convertEventToCanvas( first_event ); + node.pos = canvas.convertEventToCanvasOffset( first_event ); canvas.graph.add( node ); } } @@ -7071,8 +7391,8 @@ LGraphCanvas.onShowPropertyEditor = function( item, options, e, menu, node ) if( event ) { - dialog.style.left = (event.pageX + offsetx) + "px"; - dialog.style.top = (event.pageY + offsety)+ "px"; + dialog.style.left = (event.clientX + offsetx) + "px"; + dialog.style.top = (event.clientY + offsety)+ "px"; } else { @@ -7096,7 +7416,8 @@ LGraphCanvas.onShowPropertyEditor = function( item, options, e, menu, node ) else if( item.type == "Boolean" ) value = Boolean(value); node[ property ] = value; - dialog.parentNode.removeChild( dialog ); + if(dialog.parentNode) + dialog.parentNode.removeChild( dialog ); node.setDirtyCanvas(true,true); } } @@ -7113,9 +7434,13 @@ LGraphCanvas.prototype.prompt = function( title, value, callback, event ) dialog.close = function() { that.prompt_box = null; - dialog.parentNode.removeChild( dialog ); + if(dialog.parentNode) + dialog.parentNode.removeChild( dialog ); } + if(this.ds.scale > 1) + dialog.style.transform = "scale("+this.ds.scale+")"; + dialog.addEventListener("mouseleave",function(e){ dialog.close(); }); @@ -7171,8 +7496,8 @@ LGraphCanvas.prototype.prompt = function( title, value, callback, event ) if( event ) { - dialog.style.left = (event.pageX + offsetx) + "px"; - dialog.style.top = (event.pageY + offsety)+ "px"; + dialog.style.left = (event.clientX + offsetx) + "px"; + dialog.style.top = (event.clientY + offsety)+ "px"; } else { @@ -7199,12 +7524,30 @@ LGraphCanvas.prototype.showSearchBox = function(event) dialog.close = function() { that.search_box = null; - setTimeout( function(){ that.canvas.focus(); },10 ); //important, if canvas loses focus keys wont be captured - dialog.parentNode.removeChild( dialog ); + document.body.focus(); + setTimeout( function(){ that.canvas.focus(); },20 ); //important, if canvas loses focus keys wont be captured + if(dialog.parentNode) + dialog.parentNode.removeChild( dialog ); } + var timeout_close = null; + + if(this.ds.scale > 1) + dialog.style.transform = "scale("+this.ds.scale+")"; + + dialog.addEventListener("mouseenter",function(e){ + if(timeout_close) + { + clearTimeout(timeout_close); + timeout_close = null; + } + }); + dialog.addEventListener("mouseleave",function(e){ - dialog.close(); + //dialog.close(); + timeout_close = setTimeout(function(){ + dialog.close(); + },500); }); if(that.search_box) @@ -7266,8 +7609,8 @@ LGraphCanvas.prototype.showSearchBox = function(event) if( event ) { - dialog.style.left = (event.pageX + offsetx) + "px"; - dialog.style.top = (event.pageY + offsety)+ "px"; + dialog.style.left = (event.clientX + offsetx) + "px"; + dialog.style.top = (event.clientY + offsety)+ "px"; } else { @@ -7293,7 +7636,7 @@ LGraphCanvas.prototype.showSearchBox = function(event) var node = LiteGraph.createNode( name ); if(node) { - node.pos = graphcanvas.convertEventToCanvas( event ); + node.pos = graphcanvas.convertEventToCanvasOffset( event ); graphcanvas.graph.add( node ); } @@ -7566,8 +7909,8 @@ LGraphCanvas.prototype.createDialog = function( html, options ) } else if( options.event ) { - offsetx += options.event.pageX; - offsety += options.event.pageY; + offsetx += options.event.clientX; + offsety += options.event.clientY; } else //centered { @@ -8190,8 +8533,8 @@ function ContextMenu( values, options ) var top = options.top || 0; if(options.event) { - left = (options.event.pageX - 10); - top = (options.event.pageY - 10); + left = (options.event.clientX - 10); + top = (options.event.clientY - 10); if(options.title) top -= 20; @@ -8212,6 +8555,9 @@ function ContextMenu( values, options ) root.style.left = left + "px"; root.style.top = top + "px"; + + if(options.scale) + root.style.transform = "scale("+options.scale+")"; } ContextMenu.prototype.addItem = function( name, value, options ) @@ -8377,8 +8723,8 @@ ContextMenu.prototype.getFirstEvent = function() ContextMenu.isCursorOverElement = function( event, element ) { - var left = event.pageX; - var top = event.pageY; + var left = event.clientX; + var top = event.clientY; var rect = element.getBoundingClientRect(); if(!rect) return false; diff --git a/src/nodes/audio.js b/src/nodes/audio.js index 8b08b5fa6..fc591b016 100644 --- a/src/nodes/audio.js +++ b/src/nodes/audio.js @@ -968,6 +968,67 @@ LGAudioMixer.desc = "Audio mixer"; LiteGraph.registerNodeType("audio/mixer", LGAudioMixer); +function LGAudioADSR() +{ + //default + this.properties = { + A: 0.1, + D: 0.1, + S: 0.1, + R: 0.1 + }; + + this.audionode = LGAudio.getAudioContext().createGain(); + this.audionode.gain.value = 0; + this.addInput("in","audio"); + this.addInput("gate","bool"); + this.addOutput("out","audio"); + this.gate = false; +} + +LGAudioADSR.prototype.onExecute = function() +{ + var audioContext = LGAudio.getAudioContext(); + var now = audioContext.currentTime; + var node = this.audionode; + var gain = node.gain; + var current_gate = this.getInputData(1); + + var A = this.getInputOrProperty("A"); + var D = this.getInputOrProperty("D"); + var S = this.getInputOrProperty("S"); + var R = this.getInputOrProperty("R"); + + if( !this.gate && current_gate ) + { + gain.cancelScheduledValues(0); + gain.setValueAtTime( 0, now ); + gain.linearRampToValueAtTime(1, now + A ); + gain.linearRampToValueAtTime(S, now + A + D ); + } + else if( this.gate && !current_gate ) + { + gain.cancelScheduledValues( 0 ); + gain.setValueAtTime( gain.value, now ); + gain.linearRampToValueAtTime( 0, now + R ); + } + + this.gate = current_gate; +} + +LGAudioADSR.prototype.onGetInputs = function() +{ + return [["A","number"],["D","number"],["S","number"],["R","number"]]; +} + + +LGAudio.createAudioNodeWrapper( LGAudioADSR ); + +LGAudioADSR.title = "ADSR"; +LGAudioADSR.desc = "Audio envelope"; +LiteGraph.registerNodeType("audio/adsr", LGAudioADSR); + + function LGAudioDelay() { //default @@ -1066,7 +1127,13 @@ LGAudioOscillatorNode.prototype.onStart = function() if(!this.audionode.started) { this.audionode.started = true; - this.audionode.start(); + try + { + this.audionode.start(); + } + catch (err) + { + } } } diff --git a/src/nodes/base.js b/src/nodes/base.js index 82a138fdb..25331735e 100755 --- a/src/nodes/base.js +++ b/src/nodes/base.js @@ -25,7 +25,7 @@ LiteGraph.registerNodeType("basic/time", Time); function Subgraph() { var that = this; - this.size = [120,80]; + this.size = [140,80]; //create inner graph this.subgraph = new LGraph(); @@ -40,19 +40,18 @@ function Subgraph() this.subgraph.onGlobalOutputRenamed = this.onSubgraphRenamedGlobalOutput.bind(this); this.subgraph.onGlobalOutputTypeChanged = this.onSubgraphTypeChangeGlobalOutput.bind(this); - this.color = "#335"; - this.bgcolor = "#557"; } Subgraph.title = "Subgraph"; Subgraph.desc = "Graph inside a node"; +Subgraph.title_color = "#334"; Subgraph.prototype.onDrawTitle = function(ctx) { if(this.flags.collapsed) return; - ctx.fillStyle = "#AAA"; + ctx.fillStyle = "#555"; var w = LiteGraph.NODE_TITLE_HEIGHT; var x = this.size[0] - w; ctx.fillRect( x, -w, w,w ); @@ -348,6 +347,13 @@ ConstantNumber.prototype.onExecute = function() this.setOutputData(0, parseFloat( this.properties["value"] ) ); } +ConstantNumber.prototype.getTitle = function() +{ + if(this.flags.collapsed) + return this.properties.value; + return this.title; +} + ConstantNumber.prototype.setValue = function(v) { this.properties.value = v; @@ -367,6 +373,7 @@ function ConstantString() this.addProperty( "value", "" ); this.widget = this.addWidget("text","value","", this.setValue.bind(this) ); this.widgets_up = true; + this.size = [100,30]; } ConstantString.title = "Const String"; @@ -382,6 +389,8 @@ ConstantString.prototype.onPropertyChanged = function(name,value) this.widget.value = value; } +ConstantString.prototype.getTitle = ConstantNumber.prototype.getTitle; + ConstantString.prototype.onExecute = function() { this.setOutputData(0, this.properties["value"] ); @@ -390,6 +399,92 @@ ConstantString.prototype.onExecute = function() LiteGraph.registerNodeType("basic/string", ConstantString ); +function ConstantData() +{ + this.addOutput("",""); + this.addProperty( "value", "" ); + this.widget = this.addWidget("text","json","", this.setValue.bind(this) ); + this.widgets_up = true; + this.size = [140,30]; + this._value = null; +} + +ConstantData.title = "Const Data"; +ConstantData.desc = "Constant Data"; + +ConstantData.prototype.setValue = function(v) +{ + this.properties.value = v; + this.onPropertyChanged("value",v); +} + +ConstantData.prototype.onPropertyChanged = function(name,value) +{ + this.widget.value = value; + if(value == null || value == "") + return; + + try + { + this._value = JSON.parse(value); + this.boxcolor = "#AEA"; + } + catch (err) + { + this.boxcolor = "red"; + } +} + +ConstantData.prototype.onExecute = function() +{ + this.setOutputData(0, this._value ); +} + +LiteGraph.registerNodeType("basic/data", ConstantData ); + + +function ObjectProperty() +{ + this.addInput("obj",""); + this.addOutput("",""); + this.addProperty( "value", "" ); + this.widget = this.addWidget("text","prop.","", this.setValue.bind(this) ); + this.widgets_up = true; + this.size = [140,30]; + this._value = null; +} + +ObjectProperty.title = "Object property"; +ObjectProperty.desc = "Outputs the property of an object"; + +ObjectProperty.prototype.setValue = function(v) +{ + this.properties.value = v; + this.widget.value = v; +} + +ObjectProperty.prototype.getTitle = function() +{ + if(this.flags.collapsed) + return "in." + this.properties.value; + return this.title; +} + +ObjectProperty.prototype.onPropertyChanged = function(name,value) +{ + this.widget.value = value; +} + +ObjectProperty.prototype.onExecute = function() +{ + var data = this.getInputData(0); + if(data != null) + this.setOutputData(0, data[ this.properties.value ] ); +} + +LiteGraph.registerNodeType("basic/object_property", ObjectProperty ); + + //Watch a value in the editor function Watch() { @@ -407,6 +502,13 @@ Watch.prototype.onExecute = function() this.value = this.getInputData(0); } +Watch.prototype.getTitle = function() +{ + if(this.flags.collapsed) + return this.inputs[0].label; + return this.title; +} + Watch.toString = function( o ) { if( o == null ) @@ -433,23 +535,23 @@ Watch.prototype.onDrawBackground = function(ctx) LiteGraph.registerNodeType("basic/watch", Watch); -//Watch a value in the editor -function Pass() +//in case one type doesnt match other type but you want to connect them anyway +function Cast() { this.addInput("in",0); this.addOutput("out",0); this.size = [40,20]; } -Pass.title = "Pass"; -Pass.desc = "Allows to connect different types"; +Cast.title = "Cast"; +Cast.desc = "Allows to connect different types"; -Pass.prototype.onExecute = function() +Cast.prototype.onExecute = function() { this.setOutputData( 0, this.getInputData(0) ); } -LiteGraph.registerNodeType("basic/pass", Pass); +LiteGraph.registerNodeType("basic/cast", Cast); //Show value inside the debug console diff --git a/src/nodes/events.js b/src/nodes/events.js index 275fcf690..a1c29ca34 100644 --- a/src/nodes/events.js +++ b/src/nodes/events.js @@ -142,7 +142,7 @@ LiteGraph.registerNodeType("events/counter", EventCounter ); function DelayEvent() { this.size = [60,20]; - this.addProperty( "time", 1000 ); + this.addProperty( "time_in_ms", 1000 ); this.addInput("event", LiteGraph.ACTION); this.addOutput("on_time", LiteGraph.EVENT); @@ -154,13 +154,20 @@ DelayEvent.desc = "Delays one event"; DelayEvent.prototype.onAction = function(action, param) { - this._pending.push([ this.properties.time, param ]); + var time = this.properties.time_in_ms; + if(time <= 0) + this.trigger(null, param); + else + this._pending.push([ time, param ]); } DelayEvent.prototype.onExecute = function() { var dt = this.graph.elapsed_time * 1000; //in ms + if(this.isInputConnected(1)) + this.properties.time_in_ms = this.getInputData(1); + for(var i = 0; i < this._pending.length; ++i) { var action = this._pending[i]; @@ -179,7 +186,7 @@ DelayEvent.prototype.onExecute = function() DelayEvent.prototype.onGetInputs = function() { - return [["event",LiteGraph.ACTION]]; + return [["event",LiteGraph.ACTION],["time_in_ms","number"]]; } LiteGraph.registerNodeType("events/delay", DelayEvent ); diff --git a/src/nodes/gltextures.js b/src/nodes/gltextures.js index ccde563c4..d40b62965 100755 --- a/src/nodes/gltextures.js +++ b/src/nodes/gltextures.js @@ -7,7 +7,7 @@ global.LGraphTexture = null; if(typeof(GL) != "undefined") { - LGraphCanvas.link_type_colors["Texture"] = "#AEF"; + LGraphCanvas.link_type_colors["Texture"] = "#987"; function LGraphTexture() { @@ -115,6 +115,14 @@ if(typeof(GL) != "undefined") return type; } + LGraphTexture.getWhiteTexture = function() + { + if(this._white_texture) + return this._white_texture; + var texture = this._white_texture = GL.Texture.fromMemory(1,1,[255,255,255,255],{ format: gl.RGBA, wrap: gl.REPEAT, filter: gl.NEAREST }); + return texture; + } + LGraphTexture.getNoiseTexture = function() { if(this._noise_texture) @@ -1164,7 +1172,7 @@ if(typeof(GL) != "undefined") LGraphTextureDownsample.title = "Downsample"; LGraphTextureDownsample.desc = "Downsample Texture"; LGraphTextureDownsample.widgets_info = { - iterations: { type:"number", step: 1, precision: 0, min: 1 }, + iterations: { type:"number", step: 1, precision: 0, min: 0 }, precision: { widget:"combo", values: LGraphTexture.MODE_VALUES } }; @@ -1181,6 +1189,12 @@ if(typeof(GL) != "undefined") if(!tex || tex.texture_type !== GL.TEXTURE_2D ) return; + if( this.properties.iterations < 1) + { + this.setOutputData(0,tex); + return; + } + var shader = LGraphTextureDownsample._shader; if(!shader) LGraphTextureDownsample._shader = shader = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphTextureDownsample.pixel_shader ); @@ -1262,7 +1276,7 @@ if(typeof(GL) != "undefined") - // Texture Copy ***************************************** + // Texture Average ***************************************** function LGraphTextureAverage() { this.addInput("Texture","Texture"); @@ -1289,6 +1303,7 @@ if(typeof(GL) != "undefined") this.setOutputData(2,(v[0] + v[1] + v[2]) / 3); } + //executed before rendering the frame LGraphTextureAverage.prototype.onPreRenderExecute = function() { this.updateAverage(); @@ -1324,6 +1339,8 @@ if(typeof(GL) != "undefined") var shader = LGraphTextureAverage._shader; var uniforms = this._uniforms; uniforms.u_mipmap_offset = this.properties.mipmap_offset; + gl.disable( gl.DEPTH_TEST ); + gl.disable( gl.BLEND ); this._temp_texture.drawTo(function(){ tex.toViewport( shader, uniforms ); }); @@ -1341,7 +1358,6 @@ if(typeof(GL) != "undefined") else if(type == GL.HALF_FLOAT || type == GL.HALF_FLOAT_OES) { //no half floats possible, hard to read back unless copyed to a FLOAT texture, so temp_texture is always forced to FLOAT - //vec4.scale( v,v, 1/(255*255) ); //is this correct? } } } @@ -1369,6 +1385,72 @@ if(typeof(GL) != "undefined") LiteGraph.registerNodeType("texture/average", LGraphTextureAverage ); + + + function LGraphTextureTemporalSmooth() + { + this.addInput("in","Texture"); + this.addInput("factor","Number"); + this.addOutput("out","Texture"); + this.properties = { factor: 0.5 }; + this._uniforms = { u_texture: 0, u_textureB: 1, u_factor: this.properties.factor }; + } + + LGraphTextureTemporalSmooth.title = "Smooth"; + LGraphTextureTemporalSmooth.desc = "Smooth texture over time"; + + LGraphTextureTemporalSmooth.prototype.onExecute = function() + { + var tex = this.getInputData(0); + if(!tex || !this.isOutputConnected(0)) + return; + + if(!LGraphTextureTemporalSmooth._shader) + LGraphTextureTemporalSmooth._shader = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphTextureTemporalSmooth.pixel_shader); + + var temp = this._temp_texture; + if(!temp || temp.type != tex.type || temp.width != tex.width || temp.height != tex.height ) + { + this._temp_texture = new GL.Texture( tex.width, tex.height, { type: tex.type, format: gl.RGBA, filter: gl.NEAREST }); + this._temp_texture2 = new GL.Texture( tex.width, tex.height, { type: tex.type, format: gl.RGBA, filter: gl.NEAREST }); + tex.copyTo( this._temp_texture2 ); + } + + var tempA = this._temp_texture; + var tempB = this._temp_texture2; + + var shader = LGraphTextureTemporalSmooth._shader; + var uniforms = this._uniforms; + uniforms.u_factor = 1.0 - this.getInputOrProperty("factor"); + + gl.disable( gl.BLEND ); + gl.disable( gl.DEPTH_TEST ); + tempA.drawTo(function(){ + tempB.bind(1); + tex.toViewport( shader, uniforms ); + }); + + this.setOutputData(0, tempA ); + + //swap + this._temp_texture = tempB; + this._temp_texture2 = tempA; + } + + LGraphTextureTemporalSmooth.pixel_shader = "precision highp float;\n\ + precision highp float;\n\ + uniform sampler2D u_texture;\n\ + uniform sampler2D u_textureB;\n\ + uniform float u_factor;\n\ + varying vec2 v_coord;\n\ + \n\ + void main() {\n\ + gl_FragColor = mix( texture2D( u_texture, v_coord ), texture2D( u_textureB, v_coord ), u_factor );\n\ + }\n\ + "; + + LiteGraph.registerNodeType("texture/temporal_smooth", LGraphTextureTemporalSmooth ); + // Image To Texture ***************************************** function LGraphImageToTexture() { @@ -1529,7 +1611,7 @@ if(typeof(GL) != "undefined") this.addOutput("B","Texture"); this.addOutput("A","Texture"); - this.properties = {}; + this.properties = { use_luminance: true }; if(!LGraphTextureChannels._shader) LGraphTextureChannels._shader = new GL.Shader( Shader.SCREEN_VERTEX_SHADER, LGraphTextureChannels.pixel_shader ); } @@ -1545,13 +1627,14 @@ if(typeof(GL) != "undefined") if(!this._channels) this._channels = Array(4); + var format = this.properties.use_luminance ? gl.LUMINANCE : gl.RGBA; var connections = 0; for(var i = 0; i < 4; i++) { if(this.isOutputConnected(i)) { - if(!this._channels[i] || this._channels[i].width != texA.width || this._channels[i].height != texA.height || this._channels[i].type != texA.type) - this._channels[i] = new GL.Texture( texA.width, texA.height, { type: texA.type, format: gl.RGBA, filter: gl.LINEAR }); + if(!this._channels[i] || this._channels[i].width != texA.width || this._channels[i].height != texA.height || this._channels[i].type != texA.type || this._channels[i].format != format ) + this._channels[i] = new GL.Texture( texA.width, texA.height, { type: texA.type, format: format, filter: gl.LINEAR }); connections++; } else @@ -1605,40 +1688,55 @@ if(typeof(GL) != "undefined") this.addOutput("Texture","Texture"); - this.properties = {}; - if(!LGraphChannelsTexture._shader) - LGraphChannelsTexture._shader = new GL.Shader( Shader.SCREEN_VERTEX_SHADER, LGraphChannelsTexture.pixel_shader ); + this.properties = { precision: LGraphTexture.DEFAULT, R:1,G:1,B:1,A:1 }; + this._color = vec4.create(); + this._uniforms = { u_textureR:0, u_textureG:1, u_textureB:2, u_textureA:3, u_color: this._color }; } LGraphChannelsTexture.title = "Channels to Texture"; LGraphChannelsTexture.desc = "Split texture channels"; + LGraphChannelsTexture.widgets_info = { + "precision": { widget:"combo", values: LGraphTexture.MODE_VALUES } + }; LGraphChannelsTexture.prototype.onExecute = function() { - var tex = [ this.getInputData(0), - this.getInputData(1), - this.getInputData(2), - this.getInputData(3) ]; - - if(!tex[0] || !tex[1] || !tex[2] || !tex[3]) - return; + var white = LGraphTexture.getWhiteTexture(); + var texR = this.getInputData(0) || white; + var texG = this.getInputData(1) || white; + var texB = this.getInputData(2) || white; + var texA = this.getInputData(3) || white; gl.disable( gl.BLEND ); gl.disable( gl.DEPTH_TEST ); var mesh = Mesh.getScreenQuad(); + if(!LGraphChannelsTexture._shader) + LGraphChannelsTexture._shader = new GL.Shader( Shader.SCREEN_VERTEX_SHADER, LGraphChannelsTexture.pixel_shader ); var shader = LGraphChannelsTexture._shader; - this._tex = LGraphTexture.getTargetTexture( tex[0], this._tex ); + var w = Math.max( texR.width, texG.width, texB.width, texA.width ); + var h = Math.max( texR.height, texG.height, texB.height, texA.height ); + var type = this.properties.precision == LGraphTexture.HIGH ? LGraphTexture.HIGH_PRECISION_FORMAT : gl.UNSIGNED_BYTE; - this._tex.drawTo( function() { - tex[0].bind(0); - tex[1].bind(1); - tex[2].bind(2); - tex[3].bind(3); - shader.uniforms({u_textureR:0, u_textureG:1, u_textureB:2, u_textureA:3 }).draw(mesh); + if( !this._texture || this._texture.width != w || this._texture.height != h || this._texture.type != type ) + this._texture = new GL.Texture(w,h,{ type: type, format: gl.RGBA, filter: gl.LINEAR }); + + var color = this._color; + color[0] = this.properties.R; + color[1] = this.properties.G; + color[2] = this.properties.B; + color[3] = this.properties.A; + var uniforms = this._uniforms; + + this._texture.drawTo( function() { + texR.bind(0); + texG.bind(1); + texB.bind(2); + texA.bind(3); + shader.uniforms( uniforms ).draw(mesh); }); - this.setOutputData(0, this._tex); + this.setOutputData(0, this._texture ); } LGraphChannelsTexture.pixel_shader = "precision highp float;\n\ @@ -1648,9 +1746,10 @@ if(typeof(GL) != "undefined") uniform sampler2D u_textureG;\n\ uniform sampler2D u_textureB;\n\ uniform sampler2D u_textureA;\n\ + uniform vec4 u_color;\n\ \n\ void main() {\n\ - gl_FragColor = vec4( \ + gl_FragColor = u_color * vec4( \ texture2D(u_textureR, v_coord).r,\ texture2D(u_textureG, v_coord).r,\ texture2D(u_textureB, v_coord).r,\ @@ -2959,7 +3058,7 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ function LGraphToneMapping() { this.addInput("in","Texture"); - this.addInput("avg","number"); + this.addInput("avg","number,Texture"); this.addOutput("out","Texture"); this.properties = { enabled: true, scale:1, gamma: 1, average_lum: 1, lum_white: 1, precision: LGraphTexture.LOW }; @@ -3003,19 +3102,31 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ if(!temp || temp.width != tex.width || temp.height != tex.height || temp.type != tex.type ) temp = this._temp_texture = new GL.Texture( tex.width, tex.height, { type: tex.type, format: gl.RGBA, filter: gl.LINEAR }); - //apply shader - var shader = LGraphToneMapping._shader; - if(!shader) - shader = LGraphToneMapping._shader = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphToneMapping.pixel_shader ); - var avg = this.getInputData(1); - if(avg != null) - this.properties.average_lum = avg; + if(avg == null) + avg = this.properties.average_lum; var uniforms = this._uniforms; + var shader = null; + + if( avg.constructor === Number ) + { + this.properties.average_lum = avg; + uniforms.u_average_lum = this.properties.average_lum; + shader = LGraphToneMapping._shader; + if(!shader) + shader = LGraphToneMapping._shader = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphToneMapping.pixel_shader ); + } + else if( avg.constructor === GL.Texture ) + { + uniforms.u_average_texture = avg.bind(1); + shader = LGraphToneMapping._shader_texture; + if(!shader) + shader = LGraphToneMapping._shader_texture = new GL.Shader( GL.Shader.SCREEN_VERTEX_SHADER, LGraphToneMapping.pixel_shader, { AVG_TEXTURE:"" } ); + } + uniforms.u_lumwhite2 = this.properties.lum_white * this.properties.lum_white; uniforms.u_scale = this.properties.scale; - uniforms.u_average_lum = this.properties.average_lum; uniforms.u_igamma = 1/this.properties.gamma; //apply shader @@ -3032,7 +3143,11 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ varying vec2 v_coord;\n\ uniform sampler2D u_texture;\n\ uniform float u_scale;\n\ - uniform float u_average_lum;\n\ + #ifdef AVG_TEXTURE\n\ + uniform sampler2D u_average_texture;\n\ + #else\n\ + uniform float u_average_lum;\n\ + #endif\n\ uniform float u_lumwhite2;\n\ uniform float u_igamma;\n\ vec3 RGB2xyY (vec3 rgb)\n\ @@ -3051,9 +3166,16 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ void main() {\n\ vec4 color = texture2D( u_texture, v_coord );\n\ vec3 rgb = color.xyz;\n\ + float average_lum = 0.0;\n\ + #ifdef AVG_TEXTURE\n\ + vec3 pixel = texture2D(u_average_texture,vec2(0.5)).xyz;\n\ + average_lum = (pixel.x + pixel.y + pixel.z) / 3.0;\n\ + #else\n\ + average_lum = u_average_lum;\n\ + #endif\n\ //Ld - this part of the code is the same for both versions\n\ float lum = dot(rgb, vec3(0.2126, 0.7152, 0.0722));\n\ - float L = (u_scale / u_average_lum) * lum;\n\ + float L = (u_scale / average_lum) * lum;\n\ float Ld = (L * (1.0 + L / u_lumwhite2)) / (1.0 + L);\n\ //first\n\ //vec3 xyY = RGB2xyY(rgb);\n\ @@ -3074,6 +3196,7 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ this.addOutput("out","Texture"); this.properties = { width: 512, height: 512, seed:0, persistence: 0.1, octaves: 8, scale: 1, offset: [0,0], amplitude: 1, precision: LGraphTexture.DEFAULT }; this._key = 0; + this._texture = null; this._uniforms = { u_persistence: 0.1, u_seed: 0, u_offset: vec2.create(), u_scale: 1, u_viewport: vec2.create() }; } @@ -3087,6 +3210,11 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ octaves: { type: "Number", precision: 0, step: 1, min: 1, max: 50 } }; + LGraphTexturePerlin.prototype.onGetInputs = function() + { + return [["seed","Number"],["persistence","Number"],["octaves","Number"],["scale","Number"],["amplitude","Number"],["offset","vec2"]]; + } + LGraphTexturePerlin.prototype.onExecute = function() { if(!this.isOutputConnected(0)) @@ -3098,12 +3226,19 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ if(h == 0) h = gl.viewport_data[3]; //0 means default var type = LGraphTexture.getTextureType( this.properties.precision ); - var temp = this._temp_texture; + var temp = this._texture; if(!temp || temp.width != w || temp.height != h || temp.type != type ) - temp = this._temp_texture = new GL.Texture( w, h, { type: type, format: gl.RGB, filter: gl.LINEAR }); + temp = this._texture = new GL.Texture( w, h, { type: type, format: gl.RGB, filter: gl.LINEAR }); - //reusing old - var key = w + h + type + this.properties.persistence + this.properties.octaves + this.properties.scale + this.properties.seed + this.properties.offset[0] + this.properties.offset[1] + this.properties.amplitude; + var persistence = this.getInputOrProperty("persistence"); + var octaves = this.getInputOrProperty("octaves"); + var offset = this.getInputOrProperty("offset"); + var scale = this.getInputOrProperty("scale"); + var amplitude = this.getInputOrProperty("amplitude"); + var seed = this.getInputOrProperty("seed"); + + //reusing old texture + var key = "" + w + h + type + persistence + octaves + scale + seed + offset[0] + offset[1] + amplitude; if(key == this._key) { this.setOutputData( 0, temp ); @@ -3113,15 +3248,14 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\ //gather uniforms var uniforms = this._uniforms; - uniforms.u_persistence = this.properties.persistence; - uniforms.u_octaves = this.properties.octaves; - uniforms.u_offset[0] = this.properties.offset[0]; - uniforms.u_offset[1] = this.properties.offset[1]; - uniforms.u_scale = this.properties.scale; - uniforms.u_amplitude = this.properties.amplitude; + uniforms.u_persistence = persistence; + uniforms.u_octaves = octaves; + uniforms.u_offset.set( offset ); + uniforms.u_scale = scale; + uniforms.u_amplitude = amplitude; + uniforms.u_seed = seed * 128; uniforms.u_viewport[0] = w; uniforms.u_viewport[1] = h; - uniforms.u_seed = this.properties.seed * 128; //render var shader = LGraphTexturePerlin._shader; diff --git a/src/nodes/interface.js b/src/nodes/interface.js index d24b5d459..fe525ba1f 100755 --- a/src/nodes/interface.js +++ b/src/nodes/interface.js @@ -6,11 +6,11 @@ var LiteGraph = global.LiteGraph; function WidgetButton() { - this.addOutput( "clicked", LiteGraph.EVENT ); - this.addProperty( "text","" ); - this.addProperty( "font_size", 40 ); + this.addOutput( "", LiteGraph.EVENT ); + this.addProperty( "text","click me" ); + this.addProperty( "font_size", 30 ); this.addProperty( "message", "" ); - this.size = [64,84]; + this.size = [164,84]; } WidgetButton.title = "Button"; @@ -21,15 +21,13 @@ var LiteGraph = global.LiteGraph; { if(this.flags.collapsed) return; - - //ctx.font = "40px Arial"; - //ctx.textAlign = "center"; + var margin = 10; ctx.fillStyle = "black"; - ctx.fillRect(1,1,this.size[0] - 3, this.size[1] - 3); + ctx.fillRect(margin+1,margin+1,this.size[0] - margin*2, this.size[1] - margin*2); ctx.fillStyle = "#AAF"; - ctx.fillRect(0,0,this.size[0] - 3, this.size[1] - 3); + ctx.fillRect(margin-1,margin-1,this.size[0] - margin*2, this.size[1] - margin*2); ctx.fillStyle = this.clicked ? "white" : (this.mouseOver ? "#668" : "#334"); - ctx.fillRect(1,1,this.size[0] - 4, this.size[1] - 4); + ctx.fillRect(margin,margin,this.size[0] - margin*2, this.size[1] - margin*2); if( this.properties.text || this.properties.text === 0 ) { @@ -233,117 +231,87 @@ var LiteGraph = global.LiteGraph; { this.addOutput("",'number'); this.size = [64,84]; - this.properties = {min:0,max:1,value:0.5,wcolor:"#7AF",size:50}; + this.properties = { min:0, max:1, value:0.5, color:"#7AF", precision: 2 }; + this.value = -1; } WidgetKnob.title = "Knob"; WidgetKnob.desc = "Circular controller"; - WidgetKnob.widgets = [{name:"increase",text:"+",type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}]; - - - WidgetKnob.prototype.onAdded = function() - { - this.value = (this.properties["value"] - this.properties["min"]) / (this.properties["max"] - this.properties["min"]); - - this.imgbg = this.loadImage("imgs/knob_bg.png"); - this.imgfg = this.loadImage("imgs/knob_fg.png"); - } - - WidgetKnob.prototype.onDrawImageKnob = function(ctx) - { - if(!this.imgfg || !this.imgfg.width) return; - - var d = this.imgbg.width*0.5; - var scale = this.size[0] / this.imgfg.width; - - ctx.save(); - ctx.translate(0,20); - ctx.scale(scale,scale); - ctx.drawImage(this.imgbg,0,0); - //ctx.drawImage(this.imgfg,0,20); - - ctx.translate(d,d); - ctx.rotate(this.value * (Math.PI*2) * 6/8 + Math.PI * 10/8); - //ctx.rotate(this.value * (Math.PI*2)); - ctx.translate(-d,-d); - ctx.drawImage(this.imgfg,0,0); - - ctx.restore(); - - if(this.title) - { - ctx.font = "bold 16px Criticized,Tahoma"; - ctx.fillStyle="rgba(100,100,100,0.8)"; - ctx.textAlign = "center"; - ctx.fillText(this.title.toUpperCase(), this.size[0] * 0.5, 18 ); - ctx.textAlign = "left"; - } - } - - WidgetKnob.prototype.onDrawVectorKnob = function(ctx) - { - if(!this.imgfg || !this.imgfg.width) return; - - //circle around - ctx.lineWidth = 1; - ctx.strokeStyle= this.mouseOver ? "#FFF" : "#AAA"; - ctx.fillStyle="#000"; - ctx.beginPath(); - ctx.arc(this.size[0] * 0.5,this.size[1] * 0.5 + 10,this.properties.size * 0.5,0,Math.PI*2,true); - ctx.stroke(); - - if(this.value > 0) - { - ctx.strokeStyle=this.properties["wcolor"]; - ctx.lineWidth = (this.properties.size * 0.2); - ctx.beginPath(); - ctx.arc(this.size[0] * 0.5,this.size[1] * 0.5 + 10,this.properties.size * 0.35,Math.PI * -0.5 + Math.PI*2 * this.value,Math.PI * -0.5,true); - ctx.stroke(); - ctx.lineWidth = 1; - } - - ctx.font = (this.properties.size * 0.2) + "px Arial"; - ctx.fillStyle="#AAA"; - ctx.textAlign = "center"; - - var str = this.properties["value"]; - if(typeof(str) == 'number') - str = str.toFixed(2); - - ctx.fillText(str,this.size[0] * 0.5,this.size[1]*0.65); - ctx.textAlign = "left"; - } + WidgetKnob.size = [ 80, 100 ]; WidgetKnob.prototype.onDrawForeground = function(ctx) { - this.onDrawImageKnob(ctx); + if(this.flags.collapsed) + return; + + if(this.value == -1) + this.value = (this.properties.value - this.properties.min) / (this.properties.max - this.properties.min ); + + var center_x = this.size[0] * 0.5; + var center_y = this.size[1] * 0.5; + var radius = Math.min( this.size[0], this.size[1] ) * 0.5 - 5; + var w = Math.floor( radius * 0.05 ); + + ctx.globalAlpha = 1; + ctx.save(); + ctx.translate( center_x, center_y ); + ctx.rotate(Math.PI*0.75); + + //bg + ctx.fillStyle = "rgba(0,0,0,0.5)"; + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.arc( 0, 0, radius, 0, Math.PI*1.5 ); + ctx.fill(); + + //value + ctx.strokeStyle = "black"; + ctx.fillStyle = this.properties.color; + ctx.lineWidth = 2; + ctx.beginPath(); + ctx.moveTo(0,0); + ctx.arc(0,0, radius - 4, 0, Math.PI*1.5 * Math.max(0.01,this.value) ); + ctx.closePath(); + ctx.fill(); + //ctx.stroke(); + ctx.lineWidth = 1; + ctx.globalAlpha = 1; + ctx.restore(); + + //inner + ctx.fillStyle = "black"; + ctx.beginPath(); + ctx.arc( center_x, center_y, radius*0.75, 0, Math.PI*2, true ); + ctx.fill(); + + //miniball + ctx.fillStyle = this.mouseOver ? "white" : this.properties.color; + ctx.beginPath(); + var angle = this.value * Math.PI*1.5 + Math.PI*0.75; + ctx.arc( center_x + Math.cos(angle) * radius * 0.65, center_y + Math.sin(angle) * radius*0.65, radius*0.05, 0, Math.PI*2, true ); + ctx.fill(); + + //text + ctx.fillStyle = this.mouseOver ? "white" : "#AAA"; + ctx.font = Math.floor(radius * 0.5) + "px Arial"; + ctx.textAlign = "center"; + ctx.fillText( this.properties.value.toFixed(this.properties.precision), center_x, center_y + radius * 0.15); } WidgetKnob.prototype.onExecute = function() { - this.setOutputData(0, this.properties["value"] ); - + this.setOutputData(0, this.properties.value ); this.boxcolor = LiteGraph.colorToString([this.value,this.value,this.value]); } WidgetKnob.prototype.onMouseDown = function(e) { - if(!this.imgfg || !this.imgfg.width) return; - - //this.center = [this.imgbg.width * 0.5, this.imgbg.height * 0.5 + 20]; - //this.radius = this.imgbg.width * 0.5; this.center = [this.size[0] * 0.5, this.size[1] * 0.5 + 20]; this.radius = this.size[0] * 0.5; - if(e.canvasY - this.pos[1] < 20 || LiteGraph.distance([e.canvasX,e.canvasY],[this.pos[0] + this.center[0],this.pos[1] + this.center[1]]) > this.radius) return false; - this.oldmouse = [ e.canvasX - this.pos[0], e.canvasY - this.pos[1] ]; this.captureInput(true); - - /* - var tmp = this.localToScreenSpace(0,0); - this.trace(tmp[0] + "," + tmp[1]); */ return true; } @@ -355,12 +323,12 @@ var LiteGraph = global.LiteGraph; var v = this.value; v -= (m[1] - this.oldmouse[1]) * 0.01; - if(v > 1.0) v = 1.0; - else if(v < 0.0) v = 0.0; - + if(v > 1.0) + v = 1.0; + else if(v < 0.0) + v = 0.0; this.value = v; - this.properties["value"] = this.properties["min"] + (this.properties["max"] - this.properties["min"]) * this.value; - + this.properties.value = this.properties.min + (this.properties.max - this.properties.min) * this.value; this.oldmouse = m; this.setDirtyCanvas(true); } @@ -374,29 +342,13 @@ var LiteGraph = global.LiteGraph; } } - WidgetKnob.prototype.onMouseLeave = function(e) - { - //this.oldmouse = null; - } - WidgetKnob.prototype.onPropertyChanged = function(name,value) { - if(name=="wcolor") - this.properties[name] = value; - else if(name=="size") - { - value = parseInt(value); - this.properties[name] = value; - this.size = [value+4,value+24]; - this.setDirtyCanvas(true,true); - } - else if(name=="min" || name=="max" || name=="value") + if(name=="min" || name=="max" || name=="value") { this.properties[name] = parseFloat(value); + return true; //block } - else - return false; - return true; } LiteGraph.registerNodeType("widget/knob", WidgetKnob); @@ -437,70 +389,35 @@ var LiteGraph = global.LiteGraph; { this.size = [160,26]; this.addOutput("",'number'); - this.properties = {wcolor:"#7AF",min:0,max:1,value:0.5}; + this.properties = {color:"#7AF",min:0,max:1,value:0.5}; + this.value = -1; } WidgetHSlider.title = "H.Slider"; WidgetHSlider.desc = "Linear slider controller"; - WidgetHSlider.prototype.onAdded = function() - { - this.value = 0.5; - this.imgfg = this.loadImage("imgs/slider_fg.png"); - } - - WidgetHSlider.prototype.onDrawVectorial = function(ctx) - { - if(!this.imgfg || !this.imgfg.width) return; - - //border - ctx.lineWidth = 1; - ctx.strokeStyle= this.mouseOver ? "#FFF" : "#AAA"; - ctx.fillStyle="#000"; - ctx.beginPath(); - ctx.rect(2,0,this.size[0]-4,20); - ctx.stroke(); - - ctx.fillStyle=this.properties["wcolor"]; - ctx.beginPath(); - ctx.rect(2+(this.size[0]-4-20)*this.value,0, 20,20); - ctx.fill(); - } - - WidgetHSlider.prototype.onDrawImage = function(ctx) - { - if(!this.imgfg || !this.imgfg.width) - return; - - //border - ctx.lineWidth = 1; - ctx.fillStyle="#000"; - ctx.fillRect(2,9,this.size[0]-4,2); - - ctx.strokeStyle= "#333"; - ctx.beginPath(); - ctx.moveTo(2,9); - ctx.lineTo(this.size[0]-4,9); - ctx.stroke(); - - ctx.strokeStyle= "#AAA"; - ctx.beginPath(); - ctx.moveTo(2,11); - ctx.lineTo(this.size[0]-4,11); - ctx.stroke(); - - ctx.drawImage(this.imgfg, 2+(this.size[0]-4)*this.value - this.imgfg.width*0.5,-this.imgfg.height*0.5 + 10); - }, - WidgetHSlider.prototype.onDrawForeground = function(ctx) { - this.onDrawImage(ctx); + if(this.value == -1) + this.value = (this.properties.value - this.properties.min) / (this.properties.max - this.properties.min ); + + //border + ctx.globalAlpha = 1; + ctx.lineWidth = 1; + ctx.fillStyle = "#000"; + ctx.fillRect(2,2,this.size[0]-4,this.size[1]-4); + + ctx.fillStyle=this.properties.color; + ctx.beginPath(); + ctx.rect(4,4, (this.size[0]-8)*this.value, this.size[1]-8); + ctx.fill(); + } WidgetHSlider.prototype.onExecute = function() { - this.properties["value"] = this.properties["min"] + (this.properties["max"] - this.properties["min"]) * this.value; - this.setOutputData(0, this.properties["value"] ); + this.properties.value = this.properties.min + (this.properties.max - this.properties.min) * this.value; + this.setOutputData(0, this.properties.value ); this.boxcolor = LiteGraph.colorToString([this.value,this.value,this.value]); } @@ -543,15 +460,6 @@ var LiteGraph = global.LiteGraph; //this.oldmouse = null; } - WidgetHSlider.prototype.onPropertyChanged = function(name,value) - { - if(name=="wcolor") - this.properties[name] = value; - else - return false; - return true; - } - LiteGraph.registerNodeType("widget/hslider", WidgetHSlider ); @@ -559,7 +467,7 @@ var LiteGraph = global.LiteGraph; { this.size = [160,26]; this.addInput("",'number'); - this.properties = {min:0,max:1,value:0,wcolor:"#AAF"}; + this.properties = {min:0,max:1,value:0,color:"#AAF"}; } WidgetProgress.title = "Progress"; @@ -576,7 +484,7 @@ var LiteGraph = global.LiteGraph; { //border ctx.lineWidth = 1; - ctx.fillStyle=this.properties.wcolor; + ctx.fillStyle=this.properties.color; var v = (this.properties.value - this.properties.min) / (this.properties.max - this.properties.min); v = Math.min(1,v); v = Math.max(0,v); @@ -605,7 +513,7 @@ var LiteGraph = global.LiteGraph; if(this.properties["glowSize"]) { - ctx.shadowColor = this.properties["color"]; + ctx.shadowColor = this.properties.color; ctx.shadowOffsetX = 0; ctx.shadowOffsetY = 0; ctx.shadowBlur = this.properties["glowSize"]; diff --git a/src/nodes/logic.js b/src/nodes/logic.js index 9687c9025..326dd5406 100755 --- a/src/nodes/logic.js +++ b/src/nodes/logic.js @@ -21,11 +21,11 @@ Selector.prototype.onDrawBackground = function(ctx) if(this.flags.collapsed) return; ctx.fillStyle = "#AFB"; - var y = (this.selected + 1) * LiteGraph.NODE_SLOT_HEIGHT + 2; + var y = (this.selected + 1) * LiteGraph.NODE_SLOT_HEIGHT + 6; ctx.beginPath(); - ctx.moveTo(30, y); - ctx.lineTo(30, y+LiteGraph.NODE_SLOT_HEIGHT); - ctx.lineTo(24, y+LiteGraph.NODE_SLOT_HEIGHT*0.5); + ctx.moveTo(50, y); + ctx.lineTo(50, y+LiteGraph.NODE_SLOT_HEIGHT); + ctx.lineTo(34, y+LiteGraph.NODE_SLOT_HEIGHT*0.5); ctx.fill(); } diff --git a/src/nodes/math.js b/src/nodes/math.js index 52b5291c6..23852c936 100755 --- a/src/nodes/math.js +++ b/src/nodes/math.js @@ -197,10 +197,7 @@ MathRand.prototype.onExecute = function() MathRand.prototype.onDrawBackground = function(ctx) { //show the current value - if(this._last_v) - this.outputs[0].label = this._last_v.toFixed(3); - else - this.outputs[0].label = "?"; + this.outputs[0].label = ( this._last_v || 0 ).toFixed(3); } MathRand.prototype.onGetInputs = function() { @@ -209,6 +206,103 @@ MathRand.prototype.onGetInputs = function() { LiteGraph.registerNodeType("math/rand", MathRand); + +//basic continuous noise +function MathNoise() +{ + this.addInput("in","number"); + this.addOutput("out","number"); + this.addProperty( "min", 0 ); + this.addProperty( "max", 1 ); + this.addProperty( "smooth", true ); + this.size = [90,20]; +} + +MathNoise.title = "Noise"; +MathNoise.desc = "Random number with temporal continuity"; +MathNoise.data = null; + +MathNoise.getValue = function(f,smooth) +{ + if( !MathNoise.data ) + { + MathNoise.data = new Float32Array(1024); + for(var i = 0; i < MathNoise.data.length; ++i) + MathNoise.data[i] = Math.random(); + } + f = f % 1024; + if(f < 0) + f += 1024; + var f_min = Math.floor(f); + var f = f - f_min; + var r1 = MathNoise.data[ f_min ]; + var r2 = MathNoise.data[ f_min == 1023 ? 0 : f_min + 1 ]; + if(smooth) + f = f*f*f*(f*(f*6.0-15.0)+10.0); + return r1 * (1-f) + r2 * f; +} + +MathNoise.prototype.onExecute = function() +{ + var f = (this.getInputData(0) || 0); + var r = MathNoise.getValue( f, this.properties.smooth ); + var min = this.properties.min; + var max = this.properties.max; + this._last_v = r * (max-min) + min; + this.setOutputData(0, this._last_v ); +} + +MathNoise.prototype.onDrawBackground = function(ctx) +{ + //show the current value + this.outputs[0].label = ( this._last_v || 0 ).toFixed(3); +} + +LiteGraph.registerNodeType("math/noise", MathNoise); + +//generates spikes every random time +function MathSpikes() +{ + this.addOutput("out","number"); + this.addProperty( "min_time", 1 ); + this.addProperty( "max_time", 2 ); + this.addProperty( "duration", 0.2 ); + this.size = [90,20]; + this._remaining_time = 0; + this._blink_time = 0; +} + +MathSpikes.title = "Spikes"; +MathSpikes.desc = "spike every random time"; + +MathSpikes.prototype.onExecute = function() +{ + var dt = this.graph.elapsed_time; //in secs + + this._remaining_time -= dt; + this._blink_time -= dt; + + var v = 0; + if(this._blink_time > 0) + { + var f = this._blink_time / this.properties.duration; + v = 1/(Math.pow(f*8-4,4)+1); + } + + if( this._remaining_time < 0) + { + 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"; + } + else + this.boxcolor = "#000"; + this.setOutputData( 0, v ); +} + +LiteGraph.registerNodeType("math/spikes", MathSpikes); + + //Math clamp function MathClamp() { @@ -497,6 +591,7 @@ MathOperation.values = ["+","-","*","/","%","^"]; MathOperation.title = "Operation"; MathOperation.desc = "Easy math operators"; MathOperation["@OP"] = { type:"enum", title: "operation", values: MathOperation.values }; +MathOperation.size = [100,50]; MathOperation.prototype.getTitle = function() { @@ -546,9 +641,9 @@ MathOperation.prototype.onDrawBackground = function(ctx) return; ctx.font = "40px Arial"; - ctx.fillStyle = "#CCC"; + ctx.fillStyle = "#666"; ctx.textAlign = "center"; - ctx.fillText(this.properties.OP, this.size[0] * 0.5, this.size[1] * 0.35 + LiteGraph.NODE_TITLE_HEIGHT ); + ctx.fillText(this.properties.OP, this.size[0] * 0.5, ( this.size[1] + LiteGraph.NODE_TITLE_HEIGHT ) * 0.5 ); ctx.textAlign = "left"; } @@ -762,12 +857,20 @@ function MathFormula() this.addInput("y","number"); this.addOutput("","number"); this.properties = {x:1.0, y:1.0, formula:"x+y"}; + this.code_widget = this.addWidget("text","F(x,y)",this.properties.formula,function(v,canvas,node){ node.properties.formula = v; }); this.addWidget("toggle","allow",LiteGraph.allow_scripts,function(v){ LiteGraph.allow_scripts = v; }); this._func = null; } MathFormula.title = "Formula"; MathFormula.desc = "Compute formula"; +MathFormula.size = [160,100]; + +MathAverageFilter.prototype.onPropertyChanged = function( name, value ) +{ + if(name == "formula") + this.code_widget.value = value; +} MathFormula.prototype.onExecute = function() { @@ -788,19 +891,27 @@ MathFormula.prototype.onExecute = function() var f = this.properties["formula"]; - if(!this._func || this._func_code != this.properties.formula) + var value; + try { - this._func = new Function( "x","y","TIME", "return " + this.properties.formula ); - this._func_code = this.properties.formula; + if(!this._func || this._func_code != this.properties.formula) + { + this._func = new Function( "x","y","TIME", "return " + this.properties.formula ); + this._func_code = this.properties.formula; + } + value = this._func(x,y,this.graph.globaltime); + this.boxcolor = null; + } + catch (err) + { + this.boxcolor = "red"; } - - var value = this._func(x,y,this.graph.globaltime); this.setOutputData(0, value ); } MathFormula.prototype.getTitle = function() { - return this._func_code || ""; + return this._func_code || "Formula"; } MathFormula.prototype.onDrawBackground = function() diff --git a/src/nodes/math3d.js b/src/nodes/math3d.js new file mode 100644 index 000000000..58ee492ed --- /dev/null +++ b/src/nodes/math3d.js @@ -0,0 +1,444 @@ +(function(global){ +var LiteGraph = global.LiteGraph; + +function Math3DVec2ToXYZ() +{ + this.addInput("vec2","vec2"); + this.addOutput("x","number"); + this.addOutput("y","number"); +} + +Math3DVec2ToXYZ.title = "Vec2->XY"; +Math3DVec2ToXYZ.desc = "vector 2 to components"; + +Math3DVec2ToXYZ.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) return; + + this.setOutputData( 0, v[0] ); + this.setOutputData( 1, v[1] ); +} + +LiteGraph.registerNodeType("math3d/vec2-to-xyz", Math3DVec2ToXYZ ); + + +function Math3DXYToVec2() +{ + this.addInputs([["x","number"],["y","number"]]); + this.addOutput("vec2","vec2"); + this.properties = {x:0, y:0}; + this._data = new Float32Array(2); +} + +Math3DXYToVec2.title = "XY->Vec2"; +Math3DXYToVec2.desc = "components to vector2"; + +Math3DXYToVec2.prototype.onExecute = function() +{ + var x = this.getInputData(0); + if(x == null) x = this.properties.x; + var y = this.getInputData(1); + if(y == null) y = this.properties.y; + + var data = this._data; + data[0] = x; + data[1] = y; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/xy-to-vec2", Math3DXYToVec2 ); + + + + +function Math3DVec3ToXYZ() +{ + this.addInput("vec3","vec3"); + this.addOutput("x","number"); + this.addOutput("y","number"); + this.addOutput("z","number"); +} + +Math3DVec3ToXYZ.title = "Vec3->XYZ"; +Math3DVec3ToXYZ.desc = "vector 3 to components"; + +Math3DVec3ToXYZ.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) return; + + this.setOutputData( 0, v[0] ); + this.setOutputData( 1, v[1] ); + this.setOutputData( 2, v[2] ); +} + +LiteGraph.registerNodeType("math3d/vec3-to-xyz", Math3DVec3ToXYZ ); + + +function Math3DXYZToVec3() +{ + 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); +} + +Math3DXYZToVec3.title = "XYZ->Vec3"; +Math3DXYZToVec3.desc = "components to vector3"; + +Math3DXYZToVec3.prototype.onExecute = function() +{ + var x = this.getInputData(0); + if(x == null) x = this.properties.x; + var y = this.getInputData(1); + if(y == null) y = this.properties.y; + var z = this.getInputData(2); + if(z == null) z = this.properties.z; + + var data = this._data; + data[0] = x; + data[1] = y; + data[2] = z; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/xyz-to-vec3", Math3DXYZToVec3 ); + + + +function Math3DVec4ToXYZW() +{ + this.addInput("vec4","vec4"); + this.addOutput("x","number"); + this.addOutput("y","number"); + this.addOutput("z","number"); + this.addOutput("w","number"); +} + +Math3DVec4ToXYZW.title = "Vec4->XYZW"; +Math3DVec4ToXYZW.desc = "vector 4 to components"; + +Math3DVec4ToXYZW.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) return; + + this.setOutputData( 0, v[0] ); + this.setOutputData( 1, v[1] ); + this.setOutputData( 2, v[2] ); + this.setOutputData( 3, v[3] ); +} + +LiteGraph.registerNodeType("math3d/vec4-to-xyzw", Math3DVec4ToXYZW ); + + +function Math3DXYZWToVec4() +{ + 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); +} + +Math3DXYZWToVec4.title = "XYZW->Vec4"; +Math3DXYZWToVec4.desc = "components to vector4"; + +Math3DXYZWToVec4.prototype.onExecute = function() +{ + var x = this.getInputData(0); + if(x == null) x = this.properties.x; + var y = this.getInputData(1); + if(y == null) y = this.properties.y; + var z = this.getInputData(2); + if(z == null) z = this.properties.z; + var w = this.getInputData(3); + if(w == null) w = this.properties.w; + + var data = this._data; + data[0] = x; + data[1] = y; + data[2] = z; + data[3] = w; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/xyzw-to-vec4", Math3DXYZWToVec4 ); + + + +function Math3DVec3Scale() +{ + this.addInput("in","vec3"); + this.addInput("f","number"); + this.addOutput("out","vec3"); + this.properties = {f:1}; + this._data = new Float32Array(3); +} + +Math3DVec3Scale.title = "vec3_scale"; +Math3DVec3Scale.desc = "scales the components of a vec3"; + +Math3DVec3Scale.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) + return; + var f = this.getInputData(1); + if(f == null) f = this.properties.f; + + var data = this._data; + data[0] = v[0] * f; + data[1] = v[1] * f; + data[2] = v[2] * f; + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/vec3-scale", Math3DVec3Scale ); + +function Math3DVec3Length() +{ + this.addInput("in","vec3"); + this.addOutput("out","number"); +} + +Math3DVec3Length.title = "vec3_length"; +Math3DVec3Length.desc = "returns the module of a vector"; + +Math3DVec3Length.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) + return; + var dist = Math.sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ); + this.setOutputData( 0, dist ); +} + +LiteGraph.registerNodeType("math3d/vec3-length", Math3DVec3Length ); + +function Math3DVec3Normalize() +{ + this.addInput("in","vec3"); + this.addOutput("out","vec3"); + this._data = new Float32Array(3); +} + +Math3DVec3Normalize.title = "vec3_normalize"; +Math3DVec3Normalize.desc = "returns the vector normalized"; + +Math3DVec3Normalize.prototype.onExecute = function() +{ + var v = this.getInputData(0); + if(v == null) + return; + var dist = Math.sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ); + var data = this._data; + data[0] = v[0] / dist; + data[1] = v[1] / dist; + data[2] = v[2] / dist; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/vec3-normalize", Math3DVec3Normalize ); + +function Math3DVec3Lerp() +{ + 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); +} + +Math3DVec3Lerp.title = "vec3_lerp"; +Math3DVec3Lerp.desc = "returns the interpolated vector"; + +Math3DVec3Lerp.prototype.onExecute = function() +{ + var A = this.getInputData(0); + if(A == null) + return; + var B = this.getInputData(1); + if(B == null) + return; + var f = this.getInputOrProperty("f"); + + var data = this._data; + data[0] = A[0] * (1-f) + B[0] * f; + data[1] = A[1] * (1-f) + B[1] * f; + data[2] = A[2] * (1-f) + B[2] * f; + + this.setOutputData( 0, data ); +} + +LiteGraph.registerNodeType("math3d/vec3-lerp", Math3DVec3Lerp ); + + +function Math3DVec3Dot() +{ + this.addInput("A","vec3"); + this.addInput("B","vec3"); + this.addOutput("out","number"); +} + +Math3DVec3Dot.title = "vec3_dot"; +Math3DVec3Dot.desc = "returns the dot product"; + +Math3DVec3Dot.prototype.onExecute = function() +{ + var A = this.getInputData(0); + if(A == null) + return; + var B = this.getInputData(1); + if(B == null) + return; + + var dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]; + this.setOutputData( 0, dot ); +} + +LiteGraph.registerNodeType("math3d/vec3-dot", Math3DVec3Dot ); + + +//if glMatrix is installed... +if(global.glMatrix) +{ + + function Math3DQuaternion() + { + this.addOutput("quat","quat"); + this.properties = { x:0, y:0, z:0, w: 1 }; + this._value = quat.create(); + } + + Math3DQuaternion.title = "Quaternion"; + Math3DQuaternion.desc = "quaternion"; + + Math3DQuaternion.prototype.onExecute = function() + { + this._value[0] = this.properties.x; + this._value[1] = this.properties.y; + this._value[2] = this.properties.z; + this._value[3] = this.properties.w; + this.setOutputData( 0, this._value ); + } + + LiteGraph.registerNodeType("math3d/quaternion", Math3DQuaternion ); + + + function Math3DRotation() + { + this.addInputs([["degrees","number"],["axis","vec3"]]); + this.addOutput("quat","quat"); + this.properties = { angle:90.0, axis: vec3.fromValues(0,1,0) }; + + this._value = quat.create(); + } + + Math3DRotation.title = "Rotation"; + Math3DRotation.desc = "quaternion rotation"; + + Math3DRotation.prototype.onExecute = function() + { + var angle = this.getInputData(0); + if(angle == null) angle = this.properties.angle; + var axis = this.getInputData(1); + if(axis == null) axis = this.properties.axis; + + var R = quat.setAxisAngle( this._value, axis, angle * 0.0174532925 ); + this.setOutputData( 0, R ); + } + + + LiteGraph.registerNodeType("math3d/rotation", Math3DRotation ); + + + //Math3D rotate vec3 + function Math3DRotateVec3() + { + this.addInputs([["vec3","vec3"],["quat","quat"]]); + this.addOutput("result","vec3"); + this.properties = { vec: [0,0,1] }; + } + + Math3DRotateVec3.title = "Rot. Vec3"; + Math3DRotateVec3.desc = "rotate a point"; + + Math3DRotateVec3.prototype.onExecute = function() + { + var vec = this.getInputData(0); + if(vec == null) vec = this.properties.vec; + var quat = this.getInputData(1); + if(quat == null) + this.setOutputData(vec); + else + this.setOutputData( 0, vec3.transformQuat( vec3.create(), vec, quat ) ); + } + + LiteGraph.registerNodeType("math3d/rotate_vec3", Math3DRotateVec3); + + + + function Math3DMultQuat() + { + this.addInputs( [["A","quat"],["B","quat"]] ); + this.addOutput( "A*B","quat" ); + + this._value = quat.create(); + } + + Math3DMultQuat.title = "Mult. Quat"; + Math3DMultQuat.desc = "rotate quaternion"; + + Math3DMultQuat.prototype.onExecute = function() + { + var A = this.getInputData(0); + if(A == null) return; + var B = this.getInputData(1); + if(B == null) return; + + var R = quat.multiply( this._value, A, B ); + this.setOutputData( 0, R ); + } + + LiteGraph.registerNodeType("math3d/mult-quat", Math3DMultQuat ); + + + function Math3DQuatSlerp() + { + this.addInputs( [["A","quat"],["B","quat"],["factor","number"]] ); + this.addOutput( "slerp","quat" ); + this.addProperty( "factor", 0.5 ); + + this._value = quat.create(); + } + + Math3DQuatSlerp.title = "Quat Slerp"; + Math3DQuatSlerp.desc = "quaternion spherical interpolation"; + + Math3DQuatSlerp.prototype.onExecute = function() + { + var A = this.getInputData(0); + if(A == null) + return; + var B = this.getInputData(1); + if(B == null) + return; + var factor = this.properties.factor; + if( this.getInputData(2) != null ) + factor = this.getInputData(2); + + var R = quat.slerp( this._value, A, B, factor ); + this.setOutputData( 0, R ); + } + + LiteGraph.registerNodeType("math3d/quat-slerp", Math3DQuatSlerp ); + +} //glMatrix + +})(this); \ No newline at end of file diff --git a/src/nodes/midi.js b/src/nodes/midi.js index a351d6502..081193904 100644 --- a/src/nodes/midi.js +++ b/src/nodes/midi.js @@ -635,6 +635,12 @@ LGMIDIShow.title = "MIDI Show"; LGMIDIShow.desc = "Shows MIDI in the graph"; LGMIDIShow.color = MIDI_COLOR; +LGMIDIShow.prototype.getTitle = function() +{ + if(this.flags.collapsed) + return this._str; + return this.title; +} LGMIDIShow.prototype.onAction = function(event, midi_event ) { @@ -648,7 +654,7 @@ LGMIDIShow.prototype.onAction = function(event, midi_event ) LGMIDIShow.prototype.onDrawForeground = function( ctx ) { - if( !this._str ) + if( !this._str || this.flags.collapsed ) return; ctx.font = "30px Arial"; @@ -764,6 +770,7 @@ function LGMIDIEvent() this.addOutput( "on_midi", LiteGraph.EVENT ); this.midi_event = new MIDIEvent(); + this.gate = false; } LGMIDIEvent.title = "MIDIEvent"; @@ -778,6 +785,10 @@ LGMIDIEvent.prototype.onAction = function( event, midi_event ) this.properties.cmd = midi_event.cmd; this.properties.value1 = midi_event.data[1]; this.properties.value2 = midi_event.data[2]; + if( midi_event.cmd == MIDIEvent.NOTEON ) + this.gate = true; + else if( midi_event.cmd == MIDIEvent.NOTEOFF ) + this.gate = false; return; } @@ -841,6 +852,7 @@ LGMIDIEvent.prototype.onExecute = function() case "velocity": v = props.cmd == MIDIEvent.NOTEON ? props.value2 : null; break; case "pitch": v = props.cmd == MIDIEvent.NOTEON ? MIDIEvent.computePitch( props.value1 ) : null; break; case "pitchbend": v = props.cmd == MIDIEvent.PITCHBEND ? MIDIEvent.computePitchBend( props.value1, props.value2 ) : null; break; + case "gate": v = this.gate; break; default: continue; } @@ -870,6 +882,7 @@ LGMIDIEvent.prototype.onGetOutputs = function() { ["cc","number"], ["cc_value","number"], ["pitch","number"], + ["gate","bool"], ["pitchbend","number"] ]; } @@ -1205,7 +1218,7 @@ LGMIDIKeys.keys = [ {x:5.75,w:0.5,h:0.6,t:1}, {x:6,w:1,h:1,t:0}]; -LGMIDIKeys.prototype.onDrawBackground = function(ctx) +LGMIDIKeys.prototype.onDrawForeground = function(ctx) { if(this.flags.collapsed) return; @@ -1215,6 +1228,8 @@ LGMIDIKeys.prototype.onDrawBackground = function(ctx) var key_width = this.size[0] / (this.properties.num_octaves * 7); var key_height = this.size[1]; + ctx.globalAlpha = 1; + for(var k = 0; k < 2; k++) //draw first whites (0) then blacks (1) for(var i = 0; i < num_keys; ++i) { diff --git a/src/nodes/network.js b/src/nodes/network.js index f3a9a5c5f..d2e58d995 100644 --- a/src/nodes/network.js +++ b/src/nodes/network.js @@ -25,13 +25,13 @@ LGWebSocket.desc = "Send data through a websocket"; LGWebSocket.prototype.onPropertyChanged = function(name,value) { if(name == "url") - this.createSocket(); + this.connectSocket(); } LGWebSocket.prototype.onExecute = function() { if(!this._ws && this.properties.url) - this.createSocket(); + this.connectSocket(); if(!this._ws || this._ws.readyState != WebSocket.OPEN ) return; @@ -67,7 +67,7 @@ LGWebSocket.prototype.onExecute = function() this.boxcolor = "#6C6"; } -LGWebSocket.prototype.createSocket = function() +LGWebSocket.prototype.connectSocket = function() { var that = this; var url = this.properties.url; @@ -150,7 +150,10 @@ LiteGraph.registerNodeType("network/websocket", LGWebSocket ); function LGSillyClient() { - this.size = [60,20]; + //this.size = [60,20]; + this.room_widget = this.addWidget("text","Room","lgraph",this.setRoom.bind(this)); + this.addWidget("button","Reconnect",null,this.connectSocket.bind(this)); + this.addInput("send", LiteGraph.ACTION); this.addOutput("received", LiteGraph.EVENT); this.addInput("in", 0 ); @@ -162,9 +165,10 @@ function LGSillyClient() }; this._server = null; - this.createSocket(); + this.connectSocket(); this._last_sent_data = []; this._last_received_data = []; + } LGSillyClient.title = "SillyClient"; @@ -172,11 +176,30 @@ LGSillyClient.desc = "Connects to SillyServer to broadcast messages"; LGSillyClient.prototype.onPropertyChanged = function(name,value) { - var final_url = (this.properties.url + "/" + this.properties.room); - if(this._server && this._final_url != final_url ) + if(name == "room") + this.room_widget.value = value; + this.connectSocket(); +} + +LGSillyClient.prototype.setRoom = function(room_name) +{ + this.properties.room = room_name; + this.room_widget.value = room_name; + this.connectSocket(); +} + +//force label names +LGSillyClient.prototype.onDrawForeground = function() +{ + for(var i = 1; i < this.inputs.length; ++i) { - this._server.connect( this.properties.url, this.properties.room ); - this._final_url = final_url; + var slot = this.inputs[i]; + slot.label = "in_" + i; + } + for(var i = 1; i < this.outputs.length; ++i) + { + var slot = this.outputs[i]; + slot.label = "out_" + i; } } @@ -206,7 +229,7 @@ LGSillyClient.prototype.onExecute = function() this.boxcolor = "#6C6"; } -LGSillyClient.prototype.createSocket = function() +LGSillyClient.prototype.connectSocket = function() { var that = this; if(typeof(SillyClient) == "undefined") @@ -235,7 +258,7 @@ LGSillyClient.prototype.createSocket = function() return; } - if(data.type == 1) + if(data.type == 1) //EVENT slot { if(data.data.object_class && LiteGraph[data.data.object_class] ) { @@ -253,7 +276,7 @@ LGSillyClient.prototype.createSocket = function() else that.triggerSlot( 0, data.data ); } - else + else //for FLOW slots that._last_received_data[ data.channel || 0 ] = data.data; that.boxcolor = "#AFA"; } @@ -270,7 +293,16 @@ LGSillyClient.prototype.createSocket = function() if(this.properties.url && this.properties.room) { - this._server.connect( this.properties.url, this.properties.room ); + try + { + this._server.connect( this.properties.url, this.properties.room ); + } + catch (err) + { + console.error("SillyServer error: " + err ); + this._server = null; + return; + } this._final_url = (this.properties.url + "/" + this.properties.room); } } diff --git a/src/nodes/strings.js b/src/nodes/strings.js new file mode 100644 index 000000000..727d7624f --- /dev/null +++ b/src/nodes/strings.js @@ -0,0 +1,60 @@ +//basic nodes +(function(global){ + + var LiteGraph = global.LiteGraph; + + function toString(a) + { + return String(a); + } + + LiteGraph.wrapFunctionAsNode("string/toString",compare, ["*"],"String"); + + function compare(a,b) + { + return a==b; + } + + LiteGraph.wrapFunctionAsNode("string/compare",compare, ["String","String"],"Boolean"); + + function concatenate(a,b) + { + if(a === undefined) + return b; + if(b === undefined) + return a; + return a + b; + } + + LiteGraph.wrapFunctionAsNode("string/concatenate",concatenate, ["String","String"],"String"); + + function contains(a,b) + { + if(a === undefined || b === undefined ) + return false; + return a.indexOf(b) != -1; + } + + LiteGraph.wrapFunctionAsNode("string/contains",contains, ["String","String"],"Boolean"); + + function toUpperCase(a) + { + if(a != null && a.constructor === String) + return a.toUpperCase(); + return a; + } + + LiteGraph.wrapFunctionAsNode("string/toUpperCase",toUpperCase, ["String"],"String"); + + function split(a,b) + { + if(a != null && a.constructor === String) + return a.split(b || " "); + return [a]; + } + + LiteGraph.wrapFunctionAsNode("string/split",toUpperCase, ["String","String"],"Array"); + + + +})(this); \ No newline at end of file diff --git a/utils/deploy_files.txt b/utils/deploy_files.txt index 23524f697..ef1174155 100755 --- a/utils/deploy_files.txt +++ b/utils/deploy_files.txt @@ -4,6 +4,8 @@ ../src/nodes/interface.js ../src/nodes/input.js ../src/nodes/math.js +../src/nodes/math3d.js +../src/nodes/strings.js ../src/nodes/logic.js ../src/nodes/graphics.js ../src/nodes/gltextures.js