added support for nodejs

This commit is contained in:
tamat
2018-03-08 12:58:39 +01:00
parent 1df90b5348
commit f984476c83
17 changed files with 555 additions and 628 deletions

View File

@@ -172,7 +172,7 @@ var LiteGraph = global.LiteGraph = {
title = title || base_class.title || type;
var node = new base_class( name );
var node = new base_class( title );
node.type = type;
if(!node.title) node.title = title;
@@ -311,10 +311,18 @@ var LiteGraph = global.LiteGraph = {
}
};
//timer that works everywhere
if(typeof(performance) != "undefined")
LiteGraph.getTime = function getTime() { return performance.now(); }
LiteGraph.getTime = performance.now.bind(performance);
else if(typeof(Date) != "undefined" && Date.now)
LiteGraph.getTime = Date.now.bind(Date);
else if(typeof(process) != "undefined")
LiteGraph.getTime = function(){
var t = process.hrtime();
return t[0]*0.001 + t[1]*(1e-6);
}
else
LiteGraph.getTime = function getTime() { return Date.now(); }
LiteGraph.getTime = function getTime() { return (new Date).getTime(); }
@@ -332,7 +340,7 @@ else
* @constructor
*/
global.LGraph = LiteGraph.LGraph = function LGraph()
function LGraph()
{
if (LiteGraph.debug)
console.log("Graph created");
@@ -340,6 +348,8 @@ global.LGraph = LiteGraph.LGraph = function LGraph()
this.clear();
}
global.LGraph = LiteGraph.LGraph = LGraph;
//default supported types
LGraph.supported_types = ["number","string","boolean"];
@@ -1382,11 +1392,13 @@ LGraph.prototype.onNodeTrace = function(node, msg, color)
* @param {String} name a name for the node
*/
global.LGraphNode = LiteGraph.LGraphNode = function LGraphNode(title)
function LGraphNode(title)
{
this._ctor();
}
global.LGraphNode = LiteGraph.LGraphNode = LGraphNode;
LGraphNode.prototype._ctor = function( title )
{
this.title = title || "Unnamed";
@@ -2680,7 +2692,7 @@ LGraphNode.prototype.localToScreen = function(x,y, graphcanvas)
* @param {LGraph} graph [optional]
* @param {Object} options [optional] { skip_rendering, autoresize }
*/
global.LGraphCanvas = LiteGraph.LGraphCanvas = function LGraphCanvas( canvas, graph, options )
function LGraphCanvas( canvas, graph, options )
{
options = options || {};
@@ -2732,6 +2744,8 @@ global.LGraphCanvas = LiteGraph.LGraphCanvas = function LGraphCanvas( canvas, gr
this.autoresize = options.autoresize;
}
global.LGraphCanvas = LiteGraph.LGraphCanvas = LGraphCanvas;
LGraphCanvas.link_type_colors = {"-1":"#F85",'number':"#AAC","node":"#DCA"};
@@ -6184,7 +6198,7 @@ LiteGraph.createNodetypeWrapper = function( class_object )
//LiteGraph.registerNodeType("scene/global", LGraphGlobal );
*/
if(typeof(window) !== undefined && !window["requestAnimationFrame"] )
if( typeof(window) != "undefined" && !window["requestAnimationFrame"] )
{
window.requestAnimationFrame = window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
@@ -6194,3 +6208,6 @@ if(typeof(window) !== undefined && !window["requestAnimationFrame"] )
}
})(this);
if(typeof(exports) != "undefined")
exports.LiteGraph = this.LiteGraph;

View File

@@ -1,7 +1,6 @@
//not tested nor finished
(function( global )
{
var LiteGraph = global.LiteGraph;
var LGAudio = {};
global.LGAudio = LGAudio;
@@ -1254,4 +1253,4 @@ LiteGraph.registerNodeType("audio/destination", LGAudioDestination);
})( window );
})( this );

View File

@@ -1,6 +1,6 @@
//basic nodes
(function(){
(function(global){
var LiteGraph = global.LiteGraph;
//Constant
function Time()
@@ -461,4 +461,4 @@ LiteGraph.registerNodeType("basic/script", NodeScript );
})();
})(this);

View File

@@ -1,5 +1,6 @@
//event related nodes
(function(){
(function(global){
var LiteGraph = global.LiteGraph;
//Show value inside the debug console
function LogEvent()
@@ -146,4 +147,4 @@ DelayEvent.prototype.onGetInputs = function()
LiteGraph.registerNodeType("events/delay", DelayEvent );
})();
})(this);

View File

@@ -1,7 +1,10 @@
(function(global){
var LiteGraph = global.LiteGraph;
//Works with Litegl.js to create WebGL nodes
if(typeof(LiteGraph) != "undefined")
if(typeof(GL) != "undefined")
{
// Texture Lens *****************************************
function LGraphFXLens()
{
@@ -555,5 +558,7 @@ if(typeof(LiteGraph) != "undefined")
";
LiteGraph.registerNodeType("fx/vigneting", LGraphFXVigneting );
window.LGraphFXVigneting = LGraphFXVigneting;
}
global.LGraphFXVigneting = LGraphFXVigneting;
}
})(this);

View File

@@ -1,14 +1,20 @@
(function(global){
var LiteGraph = global.LiteGraph;
//Works with Litegl.js to create WebGL nodes
var LGraphTexture
if(typeof(LiteGraph) != "undefined")
global.LGraphTexture = null;
if(typeof(GL) != "undefined")
{
LGraphTexture = function()
function LGraphTexture()
{
this.addOutput("Texture","Texture");
this.properties = { name:"", filter: true };
this.size = [LGraphTexture.image_preview_size, LGraphTexture.image_preview_size];
}
global.LGraphTexture = LGraphTexture;
LGraphTexture.title = "Texture";
LGraphTexture.desc = "Texture";
LGraphTexture.widgets_info = {"name": { widget:"texture"}, "filter": { widget:"checkbox"} };
@@ -2463,4 +2469,6 @@ LGraphTextureKuwaharaFilter.pixel_shader = "\n\
LiteGraph.registerNodeType("texture/cubemap", LGraphCubemap );
} //litegl.js defined
} //litegl.js defined
})(this);

View File

@@ -1,7 +1,5 @@
(function(){
(function(global){
var LiteGraph = global.LiteGraph;
function GraphicsImage()
{
@@ -714,4 +712,4 @@ ImageWebcam.prototype.onDrawBackground = function(ctx)
LiteGraph.registerNodeType("graphics/webcam", ImageWebcam );
})();
})(this);

View File

@@ -1,4 +1,5 @@
(function(){
(function(global){
var LiteGraph = global.LiteGraph;
function GamepadInput()
{
@@ -200,4 +201,4 @@ GamepadInput.prototype.onGetOutputs = function() {
LiteGraph.registerNodeType("input/gamepad", GamepadInput );
})();
})(this);

View File

@@ -1,5 +1,6 @@
//widgets
(function(){
(function(global){
var LiteGraph = global.LiteGraph;
/* Button ****************/
@@ -776,4 +777,4 @@
LiteGraph.registerNodeType("widget/panel", WidgetPanel );
})();
})(this);

View File

@@ -1,3 +1,6 @@
(function(global){
var LiteGraph = global.LiteGraph;
function Selector()
{
this.addInput("sel","boolean");
@@ -35,3 +38,4 @@ Selector.prototype.onGetInputs = function() {
LiteGraph.registerNodeType("logic/selector", Selector);
})(this);

View File

@@ -1,4 +1,5 @@
(function(){
(function(global){
var LiteGraph = global.LiteGraph;
//Converter
function Converter()
@@ -685,7 +686,7 @@ LiteGraph.registerNodeType("math/trigonometry", MathTrigonometry );
//math library for safe math operations without eval
if(window.math)
if(typeof(math) != undefined)
{
function MathFormula()
{
@@ -903,7 +904,7 @@ LiteGraph.registerNodeType("math3d/xyzw-to-vec4", Math3DXYZWToVec4 );
//if glMatrix is installed...
if(window.glMatrix)
if(global.glMatrix)
{
function Math3DQuaternion()
@@ -1038,4 +1039,4 @@ if(window.glMatrix)
} //glMatrix
})();
})(this);

View File

@@ -1,5 +1,6 @@
(function( global )
{
var LiteGraph = global.LiteGraph;
function MIDIEvent( data )
{
@@ -704,10 +705,4 @@ LiteGraph.registerNodeType("midi/cc", LGMIDICC);
function now() { return window.performance.now() }
})( window );
})( this );

View File

@@ -1,5 +1,6 @@
//event related nodes
(function(){
(function(global){
var LiteGraph = global.LiteGraph;
function LGWebSocket()
{
@@ -255,4 +256,4 @@ LGSillyClient.prototype.onGetOutputs = function()
LiteGraph.registerNodeType("network/sillyclient", LGSillyClient );
})();
})(this);

View File

@@ -1,118 +0,0 @@
/*
LiteGraph.registerNodeType("graphics/supergraph", {
title: "Supergraph",
desc: "Shows a nice circular graph",
inputs: [["x","number"],["y","number"],["c","color"]],
outputs: [["","image"]],
widgets: [{name:"clear_alpha",text:"Clear Alpha",type:"minibutton"},{name:"clear_color",text:"Clear color",type:"minibutton"}],
properties: {size:256,bgcolor:"#000",lineWidth:1},
bgcolor: "#000",
flags: {allow_fastrender:true},
onLoad: function()
{
this.createCanvas();
},
createCanvas: function()
{
this.canvas = document.createElement("canvas");
this.canvas.width = this.properties["size"];
this.canvas.height = this.properties["size"];
this.oldpos = null;
this.clearCanvas(true);
},
onExecute: function()
{
var x = this.getInputData(0);
var y = this.getInputData(1);
var c = this.getInputData(2);
if(x == null && y == null) return;
if(!x) x = 0;
if(!y) y = 0;
x*= 0.95;
y*= 0.95;
var size = this.properties["size"];
if(size != this.canvas.width || size != this.canvas.height)
this.createCanvas();
if (!this.oldpos)
{
this.oldpos = [ (x * 0.5 + 0.5) * size, (y*0.5 + 0.5) * size];
return;
}
var ctx = this.canvas.getContext("2d");
if(c == null)
c = "rgba(255,255,255,0.5)";
else if(typeof(c) == "object") //array
c = colorToString(c);
//stroke line
ctx.strokeStyle = c;
ctx.beginPath();
ctx.moveTo( this.oldpos[0], this.oldpos[1] );
this.oldpos = [ (x * 0.5 + 0.5) * size, (y*0.5 + 0.5) * size];
ctx.lineTo( this.oldpos[0], this.oldpos[1] );
ctx.stroke();
this.canvas.dirty = true;
this.setOutputData(0,this.canvas);
},
clearCanvas: function(alpha)
{
var ctx = this.canvas.getContext("2d");
if(alpha)
{
ctx.clearRect(0,0,this.canvas.width,this.canvas.height);
this.trace("Clearing alpha");
}
else
{
ctx.fillStyle = this.properties["bgcolor"];
ctx.fillRect(0,0,this.canvas.width,this.canvas.height);
}
},
onWidget: function(e,widget)
{
if(widget.name == "clear_color")
{
this.clearCanvas(false);
}
else if(widget.name == "clear_alpha")
{
this.clearCanvas(true);
}
},
onPropertyChange: function(name,value)
{
if(name == "size")
{
this.properties["size"] = parseInt(value);
this.createCanvas();
}
else if(name == "bgcolor")
{
this.properties["bgcolor"] = value;
this.createCanvas();
}
else if(name == "lineWidth")
{
this.properties["lineWidth"] = parseInt(value);
this.canvas.getContext("2d").lineWidth = this.properties["lineWidth"];
}
else
return false;
return true;
}
});
*/