Skip to content

Commit f9d006c

Browse files
author
tamat
committed
fixes in subgraph
1 parent 55ad1b2 commit f9d006c

5 files changed

Lines changed: 656 additions & 638 deletions

File tree

build/litegraph.js

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@
266266
this.registerNodeType(name, classobj);
267267
},
268268

269+
/**
270+
* Removes all previously registered node's types
271+
*/
272+
clearRegisteredTypes: function() {
273+
this.registered_node_types = {};
274+
this.node_types_by_file_extension = {};
275+
this.Nodes = {};
276+
this.searchbox_extras = {};
277+
},
278+
269279
/**
270280
* Adds this method to all nodetypes, existing and to be created
271281
* (You can add it to LGraphNode.prototype but then existing node types wont have it)
@@ -1581,10 +1591,10 @@
15811591
return;
15821592
}
15831593

1584-
node.graph.beforeChange();
1594+
this.beforeChange();
15851595
this.inputs[name] = { name: name, type: type, value: value };
15861596
this._version++;
1587-
node.graph.afterChange();
1597+
this.afterChange();
15881598

15891599
if (this.onInputAdded) {
15901600
this.onInputAdded(name, type);
@@ -11944,7 +11954,10 @@ if (typeof exports != "undefined") {
1194411954
var over = LiteGraph.isInsideRectangle(pos[0],pos[1],this.pos[0],this.pos[1] + y,this.size[0],LiteGraph.NODE_TITLE_HEIGHT);
1194511955
ctx.fillStyle = over ? "#555" : "#222";
1194611956
ctx.beginPath();
11947-
ctx.roundRect( 0, y, this.size[0]+1, LiteGraph.NODE_TITLE_HEIGHT, 0, 8);
11957+
if (this._shape == LiteGraph.BOX_SHAPE)
11958+
ctx.rect(0, y, this.size[0]+1, LiteGraph.NODE_TITLE_HEIGHT);
11959+
else
11960+
ctx.roundRect( 0, y, this.size[0]+1, LiteGraph.NODE_TITLE_HEIGHT, 0, 8);
1194811961
ctx.fill();
1194911962

1195011963
//button
@@ -12226,15 +12239,21 @@ if (typeof exports != "undefined") {
1222612239
this.updateType();
1222712240
}
1222812241

12242+
//ensures the type in the node output and the type in the associated graph input are the same
1222912243
GraphInput.prototype.updateType = function()
1223012244
{
1223112245
var type = this.properties.type;
1223212246
this.type_widget.value = type;
12247+
12248+
//update output
1223312249
if(this.outputs[0].type != type)
1223412250
{
12251+
if (!LiteGraph.isValidConnection(this.outputs[0].type,type))
12252+
this.disconnectOutput(0);
1223512253
this.outputs[0].type = type;
12236-
this.disconnectOutput(0);
1223712254
}
12255+
12256+
//update widget
1223812257
if(type == "number")
1223912258
{
1224012259
this.value_widget.type = "number";
@@ -12256,8 +12275,14 @@ if (typeof exports != "undefined") {
1225612275
this.value_widget.value = null;
1225712276
}
1225812277
this.properties.value = this.value_widget.value;
12278+
12279+
//update graph
12280+
if (this.graph && this.name_in_graph) {
12281+
this.graph.changeInputType(this.name_in_graph, type);
12282+
}
1225912283
}
1226012284

12285+
//this is executed AFTER the property has changed
1226112286
GraphInput.prototype.onPropertyChanged = function(name,v)
1226212287
{
1226312288
if( name == "name" )
@@ -12279,8 +12304,7 @@ if (typeof exports != "undefined") {
1227912304
}
1228012305
else if( name == "type" )
1228112306
{
12282-
v = v || "";
12283-
this.updateType(v);
12307+
this.updateType();
1228412308
}
1228512309
else if( name == "value" )
1228612310
{
@@ -12357,6 +12381,8 @@ if (typeof exports != "undefined") {
1235712381
if (v == "action" || v == "event") {
1235812382
v = LiteGraph.ACTION;
1235912383
}
12384+
if (!LiteGraph.isValidConnection(that.inputs[0].type,v))
12385+
that.disconnectInput(0);
1236012386
that.inputs[0].type = v;
1236112387
if (that.name_in_graph) {
1236212388
//already added
@@ -23135,7 +23161,7 @@ void main(void){\n\
2313523161
"mod": "T mod(T x,T y)", //"T mod(T x,float y)"
2313623162
"min": "T min(T x,T y)",
2313723163
"max": "T max(T x,T y)",
23138-
"clamp": "T clamp(T x,T minVal,T maxVal)",
23164+
"clamp": "T clamp(T x,T minVal = 0.0,T maxVal = 1.0)",
2313923165
"mix": "T mix(T x,T y,T a)", //"T mix(T x,T y,float a)"
2314023166
"step": "T step(T edge, T x)", //"T step(float edge, T x)"
2314123167
"smoothstep": "T smoothstep(T edge, T x)", //"T smoothstep(float edge, T x)"
@@ -23165,8 +23191,13 @@ void main(void){\n\
2316523191
var params = op.substr(index2 + 1, op.length - index2 - 2).split(",");
2316623192
for(var j in params)
2316723193
{
23168-
var p = params[j].split(" ");
23169-
params[j] = { type: p[0], name: p[1] };
23194+
var p = params[j].split(" ").filter(function(a){ return a; });
23195+
params[j] = { type: p[0].trim(), name: p[1].trim() };
23196+
if(params[j].name.indexOf("=") != -1)
23197+
{
23198+
params[j].name.split("=");
23199+
}
23200+
2317023201
}
2317123202
GLSL_functions[i] = { return_type: return_type, func: func_name, params: params };
2317223203
GLSL_functions_name.push( func_name );
@@ -23642,7 +23673,10 @@ gl_FragColor = color;\n\
2364223673
var over = LiteGraph.isInsideRectangle(pos[0],pos[1],this.pos[0],this.pos[1] + y,this.size[0],LiteGraph.NODE_TITLE_HEIGHT);
2364323674
ctx.fillStyle = over ? "#555" : "#222";
2364423675
ctx.beginPath();
23645-
ctx.roundRect( 0, y, this.size[0]+1, LiteGraph.NODE_TITLE_HEIGHT, 0, 8);
23676+
if (this._shape == LiteGraph.BOX_SHAPE)
23677+
ctx.rect(0, y, this.size[0]+1, LiteGraph.NODE_TITLE_HEIGHT);
23678+
else
23679+
ctx.roundRect( 0, y, this.size[0]+1, LiteGraph.NODE_TITLE_HEIGHT, 0, 8);
2364623680
ctx.fill();
2364723681

2364823682
//button
@@ -23674,7 +23708,12 @@ gl_FragColor = color;\n\
2367423708

2367523709
LiteGraph.registerNodeType( "texture/shaderGraph", LGraphShaderGraph );
2367623710

23677-
//Shader Nodes ***************************
23711+
function shaderNodeFromFunction( classname, params, return_type, code )
23712+
{
23713+
//TODO
23714+
}
23715+
23716+
//Shader Nodes ***********************************************************
2367823717

2367923718
//applies a shader graph to a code
2368023719
function LGraphShaderUniform() {
@@ -24334,37 +24373,7 @@ gl_FragColor = color;\n\
2433424373
})(this);
2433524374

2433624375

24337-
/*
24338-
// https://blog.undefinist.com/writing-a-shader-graph/
24339-
24340-
\sin
24341-
f,Out
24342-
float->float
24343-
{1} = sin({0});
24344-
24345-
\mul
24346-
A,B,Out
24347-
T,T->T
24348-
T,float->T
24349-
{2} = {0} * {1};
24350-
24351-
\clamp
24352-
f,min,max,Out
24353-
float,float=0,float=1->float
24354-
vec2,vec2=vec2(0.0),vec2=vec2(1.0)->vec2
24355-
vec3,vec3=vec3(0.0),vec3=vec3(1.0)->vec3
24356-
vec4,vec4=vec4(0.0),vec4=vec4(1.0)->vec4
24357-
{3}=clamp({0},{1},{2});
24358-
24359-
\mix
24360-
A,B,f,Out
24361-
float,float,float->float
24362-
vec2,vec2,float->vec2
24363-
vec3,vec3,float->vec3
24364-
vec4,vec4,float->vec4
24365-
{3} = mix({0},{1},{2});
24366-
24367-
*/
24376+
2436824377
(function(global) {
2436924378
var LiteGraph = global.LiteGraph;
2437024379

0 commit comments

Comments
 (0)