fixes in searchbox

This commit is contained in:
tamat
2019-05-27 20:10:47 +02:00
parent 50d3fb77bd
commit 54bc9b46cc
3 changed files with 44 additions and 30 deletions

View File

@@ -480,7 +480,7 @@
}, },
registerSearchboxExtra: function(node_type, description, data) { registerSearchboxExtra: function(node_type, description, data) {
this.searchbox_extras[description] = { this.searchbox_extras[description.toLowerCase()] = {
type: node_type, type: node_type,
desc: description, desc: description,
data: data data: data
@@ -9109,7 +9109,7 @@ LGraphNode.prototype.executeAction = function(action)
if (that.onSearchBoxSelection) { if (that.onSearchBoxSelection) {
that.onSearchBoxSelection(name, event, graphcanvas); that.onSearchBoxSelection(name, event, graphcanvas);
} else { } else {
var extra = LiteGraph.searchbox_extras[name]; var extra = LiteGraph.searchbox_extras[name.toLowerCase()];
if (extra) { if (extra) {
name = extra.type; name = extra.type;
} }
@@ -9125,10 +9125,7 @@ LGraphNode.prototype.executeAction = function(action)
if (extra && extra.data) { if (extra && extra.data) {
if (extra.data.properties) { if (extra.data.properties) {
for (var i in extra.data.properties) { for (var i in extra.data.properties) {
node.addProperty( node.addProperty( i, extra.data.properties[i] );
extra.data.properties[i][0],
extra.data.properties[i][0]
);
} }
} }
if (extra.data.inputs) { if (extra.data.inputs) {

View File

@@ -470,8 +470,7 @@
this.addInput("TextureB", "Texture"); this.addInput("TextureB", "Texture");
this.addInput("value", "number"); this.addInput("value", "number");
this.addOutput("Texture", "Texture"); this.addOutput("Texture", "Texture");
this.help = this.help = "<p>pixelcode must be vec3, uvcode must be vec2, is optional</p>\
"<p>pixelcode must be vec3, uvcode must be vec2, is optional</p>\
<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture <strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time <strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>"; <p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture <strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time <strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";
this.properties = { this.properties = {
@@ -845,10 +844,7 @@
} }
var uniforms = this._uniforms; var uniforms = this._uniforms;
var type = LGraphTexture.getTextureType( var type = LGraphTexture.getTextureType( this.properties.precision, in_tex );
this.properties.precision,
in_tex
);
//render to texture //render to texture
var w = this.properties.width | 0; var w = this.properties.width | 0;
@@ -920,10 +916,7 @@
var width = tex.width; var width = tex.width;
var height = tex.height; var height = tex.height;
var type = var type = this.precision === LGraphTexture.LOW ? gl.UNSIGNED_BYTE : gl.HIGH_PRECISION_FORMAT;
this.precision === LGraphTexture.LOW
? gl.UNSIGNED_BYTE
: gl.HIGH_PRECISION_FORMAT;
if (this.precision === LGraphTexture.DEFAULT) { if (this.precision === LGraphTexture.DEFAULT) {
type = tex.type; type = tex.type;
} }
@@ -4387,6 +4380,7 @@
code: "", code: "",
width: 512, width: 512,
height: 512, height: 512,
clear: true,
precision: LGraphTexture.DEFAULT precision: LGraphTexture.DEFAULT
}; };
this._func = null; this._func = null;
@@ -4394,8 +4388,8 @@
} }
LGraphTextureCanvas2D.title = "Canvas2D"; LGraphTextureCanvas2D.title = "Canvas2D";
LGraphTextureCanvas2D.desc = LGraphTextureCanvas2D.desc = "Executes Canvas2D code inside a texture or the viewport.";
"Executes Canvas2D code inside a texture or the viewport"; LGraphTextureCanvas2D.help = "Set width and height to 0 to match viewport size.";
LGraphTextureCanvas2D.widgets_info = { LGraphTextureCanvas2D.widgets_info = {
precision: { widget: "combo", values: LGraphTexture.MODE_VALUES }, precision: { widget: "combo", values: LGraphTexture.MODE_VALUES },
@@ -4411,13 +4405,7 @@
if (name == "code" && LiteGraph.allow_scripts) { if (name == "code" && LiteGraph.allow_scripts) {
this._func = null; this._func = null;
try { try {
this._func = new Function( this._func = new Function( "canvas", "ctx", "time", "script", value );
"canvas",
"ctx",
"time",
"script",
value
);
this.boxcolor = "#00FF00"; this.boxcolor = "#00FF00";
} catch (err) { } catch (err) {
this.boxcolor = "#FF0000"; this.boxcolor = "#FF0000";
@@ -4443,17 +4431,26 @@
var width = this.properties.width || gl.canvas.width; var width = this.properties.width || gl.canvas.width;
var height = this.properties.height || gl.canvas.height; var height = this.properties.height || gl.canvas.height;
var temp = this._temp_texture; var temp = this._temp_texture;
if (!temp || temp.width != width || temp.height != height) { var type = LGraphTexture.getTextureType( this.properties.precision );
if (!temp || temp.width != width || temp.height != height || temp.type != type ) {
temp = this._temp_texture = new GL.Texture(width, height, { temp = this._temp_texture = new GL.Texture(width, height, {
format: gl.RGBA, format: gl.RGBA,
filter: gl.LINEAR filter: gl.LINEAR,
type: type
}); });
} }
var properties = this.properties;
var that = this; var that = this;
var time = this.graph.getTime(); var time = this.graph.getTime();
temp.drawTo(function() { temp.drawTo(function() {
gl.start2D(); gl.start2D();
if(properties.clear)
{
gl.clearColor(0,0,0,0);
gl.clear( gl.COLOR_BUFFER_BIT );
}
try { try {
if (func.draw) { if (func.draw) {
func.draw.call(that, gl.canvas, gl, time, func); func.draw.call(that, gl.canvas, gl, time, func);
@@ -4474,6 +4471,8 @@
LiteGraph.registerNodeType("texture/canvas2D", LGraphTextureCanvas2D); LiteGraph.registerNodeType("texture/canvas2D", LGraphTextureCanvas2D);
// To do chroma keying *****************
function LGraphTextureMatte() { function LGraphTextureMatte() {
this.addInput("in", "Texture"); this.addInput("in", "Texture");

View File

@@ -584,9 +584,9 @@
this.addProperty("OP", "+", "enum", { values: MathOperation.values }); this.addProperty("OP", "+", "enum", { values: MathOperation.values });
} }
MathOperation.values = ["+", "-", "*", "/", "%", "^"]; MathOperation.values = ["+", "-", "*", "/", "%", "^", "max", "min"];
MathOperation.title = "Operation"; MathOperation.title = "Operation";
MathOperation.desc = "Easy math operators"; MathOperation.desc = "Easy math operators";
MathOperation["@OP"] = { MathOperation["@OP"] = {
type: "enum", type: "enum",
@@ -596,6 +596,8 @@
MathOperation.size = [100, 60]; MathOperation.size = [100, 60];
MathOperation.prototype.getTitle = function() { MathOperation.prototype.getTitle = function() {
if(this.properties.OP == "max" || this.properties.OP == "min")
return this.properties.OP + "(A,B)";
return "A " + this.properties.OP + " B"; return "A " + this.properties.OP + " B";
}; };
@@ -643,6 +645,12 @@
case "^": case "^":
result = Math.pow(A, B); result = Math.pow(A, B);
break; break;
case "max":
result = Math.max(A, B);
break;
case "min":
result = Math.min(A, B);
break;
default: default:
console.warn("Unknown operation: " + this.properties.OP); console.warn("Unknown operation: " + this.properties.OP);
} }
@@ -667,6 +675,16 @@
LiteGraph.registerNodeType("math/operation", MathOperation); LiteGraph.registerNodeType("math/operation", MathOperation);
LiteGraph.registerSearchboxExtra("math/operation", "MAX", {
properties: {OP:"max"},
title: "MAX()"
});
LiteGraph.registerSearchboxExtra("math/operation", "MIN", {
properties: {OP:"min"},
title: "MIN()"
});
//Math compare //Math compare
function MathCompare() { function MathCompare() {
this.addInput("A", "number"); this.addInput("A", "number");
@@ -864,7 +882,7 @@
MathTrigonometry.title = "Trigonometry"; MathTrigonometry.title = "Trigonometry";
MathTrigonometry.desc = "Sin Cos Tan"; MathTrigonometry.desc = "Sin Cos Tan";
MathTrigonometry.filter = "shader"; //MathTrigonometry.filter = "shader";
MathTrigonometry.prototype.onExecute = function() { MathTrigonometry.prototype.onExecute = function() {
var v = this.getInputData(0); var v = this.getInputData(0);