Skip to content

Commit 0b5b1ad

Browse files
author
tamat
committed
lil fixes
1 parent baed06f commit 0b5b1ad

3 files changed

Lines changed: 164 additions & 42 deletions

File tree

build/litegraph.js

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23231,7 +23231,9 @@ void main(void){\n\
2323123231
"distance":"float distance(T p0, T p1)",
2323223232
"normalize":"T normalize(T x)",
2323323233
"dot": "float dot(T x,T y)",
23234-
"cross": "vec3 cross(vec3 x,vec3 y)"
23234+
"cross": "vec3 cross(vec3 x,vec3 y)",
23235+
"reflect": "vec3 reflect(vec3 V,vec3 N)",
23236+
"refract": "vec3 refract(vec3 V,vec3 N, float IOR)"
2323523237
};
2323623238

2323723239
//parse them
@@ -23290,6 +23292,36 @@ void main(void){\n\
2329023292
this.graph._version++;
2329123293
}
2329223294

23295+
/*
23296+
if(!node_ctor.prototype.onGetCode)
23297+
node_ctor.prototype.onGetCode = function()
23298+
{
23299+
//check destination to avoid lonely nodes
23300+
if(!this.shader_destination)
23301+
return;
23302+
//grab inputs with types
23303+
var inputs = [];
23304+
if(this.inputs)
23305+
for(var i = 0; i < this.inputs.length; ++i)
23306+
inputs.push({ type: this.getInputData(i), name: getInputLinkID(this,i) });
23307+
var outputs = [];
23308+
if(this.outputs)
23309+
for(var i = 0; i < this.outputs.length; ++i)
23310+
outputs.push({ name: getOutputLinkID(this,i) });
23311+
//pass to code func
23312+
var results = this.extractCode(inputs);
23313+
//grab output, pass to next
23314+
if(results)
23315+
for(var i = 0; i < results.length; ++i)
23316+
{
23317+
var r = results[i];
23318+
if(!r)
23319+
continue;
23320+
this.setOutputData(i,r.value);
23321+
}
23322+
}
23323+
*/
23324+
2329323325
LiteGraph.registerNodeType( "shader::" + type, node_ctor );
2329423326
}
2329523327

@@ -23940,6 +23972,9 @@ gl_FragColor = fragcolor;\n\
2394023972

2394123973
LGraphShaderUniform.prototype.onGetCode = function( context )
2394223974
{
23975+
if(!this.shader_destination)
23976+
return;
23977+
2394323978
var type = this.properties.type;
2394423979
if( !type )
2394523980
return;
@@ -23977,6 +24012,9 @@ gl_FragColor = fragcolor;\n\
2397724012

2397824013
LGraphShaderAttribute.prototype.onGetCode = function( context )
2397924014
{
24015+
if(!this.shader_destination)
24016+
return;
24017+
2398024018
var type = this.properties.type;
2398124019
if( !type || LGShaders.GLSL_types.indexOf(type) == -1 )
2398224020
return;
@@ -24010,6 +24048,9 @@ gl_FragColor = fragcolor;\n\
2401024048

2401124049
LGraphShaderSampler2D.prototype.onGetCode = function( context )
2401224050
{
24051+
if(!this.shader_destination)
24052+
return;
24053+
2401324054
var texname = getInputLinkID( this, 0 );
2401424055
var varname = getShaderNodeVarName(this);
2401524056
var code = "vec4 " + varname + " = vec4(0.0);\n";
@@ -24122,6 +24163,9 @@ gl_FragColor = fragcolor;\n\
2412224163

2412324164
LGraphShaderConstant.prototype.onGetCode = function( context )
2412424165
{
24166+
if(!this.shader_destination)
24167+
return;
24168+
2412524169
var value = valueToGLSL( this.properties.value, this.properties.type );
2412624170
var link_name = getOutputLinkID(this,0);
2412724171
if(!link_name) //not connected
@@ -24157,6 +24201,9 @@ gl_FragColor = fragcolor;\n\
2415724201

2415824202
LGraphShaderVec2.prototype.onGetCode = function( context )
2415924203
{
24204+
if(!this.shader_destination)
24205+
return;
24206+
2416024207
var props = this.properties;
2416124208

2416224209
var varname = getShaderNodeVarName(this);
@@ -24223,6 +24270,9 @@ gl_FragColor = fragcolor;\n\
2422324270

2422424271
LGraphShaderVec3.prototype.onGetCode = function( context )
2422524272
{
24273+
if(!this.shader_destination)
24274+
return;
24275+
2422624276
var props = this.properties;
2422724277

2422824278
var varname = getShaderNodeVarName(this);
@@ -24287,6 +24337,9 @@ gl_FragColor = fragcolor;\n\
2428724337

2428824338
LGraphShaderVec4.prototype.onGetCode = function( context )
2428924339
{
24340+
if(!this.shader_destination)
24341+
return;
24342+
2429024343
var props = this.properties;
2429124344

2429224345
var varname = getShaderNodeVarName(this);
@@ -24396,6 +24449,9 @@ gl_FragColor = fragcolor;\n\
2439624449

2439724450
LGraphShaderOperation.prototype.onGetCode = function( context )
2439824451
{
24452+
if(!this.shader_destination)
24453+
return;
24454+
2439924455
if(!this.isOutputConnected(0))
2440024456
return;
2440124457

@@ -24492,6 +24548,9 @@ gl_FragColor = fragcolor;\n\
2449224548

2449324549
LGraphShaderFunc.prototype.onGetCode = function( context )
2449424550
{
24551+
if(!this.shader_destination)
24552+
return;
24553+
2449524554
if(!this.isOutputConnected(0))
2449624555
return;
2449724556

@@ -24574,7 +24633,7 @@ gl_FragColor = fragcolor;\n\
2457424633

2457524634
LGraphShaderSnippet.prototype.onGetCode = function( context )
2457624635
{
24577-
if(!this.isOutputConnected(0))
24636+
if(!this.shader_destination || !this.isOutputConnected(0))
2457824637
return;
2457924638

2458024639
var inlinkA = getInputLinkID(this,0);
@@ -24623,7 +24682,7 @@ gl_FragColor = fragcolor;\n\
2462324682

2462424683
LGraphShaderRand.prototype.onGetCode = function( context )
2462524684
{
24626-
if(!this.isOutputConnected(0))
24685+
if(!this.shader_destination || !this.isOutputConnected(0))
2462724686
return;
2462824687

2462924688
var outlink = getOutputLinkID(this,0);
@@ -24648,7 +24707,7 @@ gl_FragColor = fragcolor;\n\
2464824707

2464924708
LGraphShaderTime.prototype.onGetCode = function( context )
2465024709
{
24651-
if(!this.isOutputConnected(0))
24710+
if(!this.shader_destination || !this.isOutputConnected(0))
2465224711
return;
2465324712

2465424713
var outlink = getOutputLinkID(this,0);
@@ -24671,8 +24730,9 @@ gl_FragColor = fragcolor;\n\
2467124730

2467224731
LGraphShaderDither.prototype.onGetCode = function( context )
2467324732
{
24674-
if(!this.isOutputConnected(0))
24733+
if(!this.shader_destination || !this.isOutputConnected(0))
2467524734
return;
24735+
2467624736
var inlink = getInputLinkID(this,0);
2467724737
var return_type = "float";
2467824738
var outlink = getOutputLinkID(this,0);
@@ -24735,7 +24795,7 @@ gl_FragColor = fragcolor;\n\
2473524795

2473624796
LGraphShaderRemap.prototype.onGetCode = function( context )
2473724797
{
24738-
if(!this.isOutputConnected(0))
24798+
if(!this.shader_destination || !this.isOutputConnected(0))
2473924799
return;
2474024800

2474124801
var inlink = getInputLinkID(this,0);

src/litegraph.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8578,6 +8578,7 @@ LGraphNode.prototype.executeAction = function(action)
85788578
ctx.textAlign = "left";
85798579
if(w.disabled)
85808580
ctx.globalAlpha *= 0.5;
8581+
var widget_width = w.width || width;
85818582

85828583
switch (w.type) {
85838584
case "button":
@@ -8586,13 +8587,13 @@ LGraphNode.prototype.executeAction = function(action)
85868587
w.clicked = false;
85878588
this.dirty_canvas = true;
85888589
}
8589-
ctx.fillRect(margin, y, width - margin * 2, H);
8590+
ctx.fillRect(margin, y, widget_width - margin * 2, H);
85908591
if(show_text && !w.disabled)
8591-
ctx.strokeRect( margin, y, width - margin * 2, H );
8592+
ctx.strokeRect( margin, y, widget_width - margin * 2, H );
85928593
if (show_text) {
85938594
ctx.textAlign = "center";
85948595
ctx.fillStyle = text_color;
8595-
ctx.fillText(w.name, width * 0.5, y + H * 0.7);
8596+
ctx.fillText(w.name, widget_width * 0.5, y + H * 0.7);
85968597
}
85978598
break;
85988599
case "toggle":
@@ -8601,15 +8602,15 @@ LGraphNode.prototype.executeAction = function(action)
86018602
ctx.fillStyle = background_color;
86028603
ctx.beginPath();
86038604
if (show_text)
8604-
ctx.roundRect(margin, posY, width - margin * 2, H, H * 0.5);
8605+
ctx.roundRect(margin, posY, widget_width - margin * 2, H, H * 0.5);
86058606
else
8606-
ctx.rect(margin, posY, width - margin * 2, H );
8607+
ctx.rect(margin, posY, widget_width - margin * 2, H );
86078608
ctx.fill();
86088609
if(show_text && !w.disabled)
86098610
ctx.stroke();
86108611
ctx.fillStyle = w.value ? "#89A" : "#333";
86118612
ctx.beginPath();
8612-
ctx.arc( width - margin * 2, y + H * 0.5, H * 0.36, 0, Math.PI * 2 );
8613+
ctx.arc( widget_width - margin * 2, y + H * 0.5, H * 0.36, 0, Math.PI * 2 );
86138614
ctx.fill();
86148615
if (show_text) {
86158616
ctx.fillStyle = secondary_text_color;
@@ -8622,31 +8623,31 @@ LGraphNode.prototype.executeAction = function(action)
86228623
w.value
86238624
? w.options.on || "true"
86248625
: w.options.off || "false",
8625-
width - 40,
8626+
widget_width - 40,
86268627
y + H * 0.7
86278628
);
86288629
}
86298630
break;
86308631
case "slider":
86318632
ctx.fillStyle = background_color;
8632-
ctx.fillRect(margin, y, width - margin * 2, H);
8633+
ctx.fillRect(margin, y, widget_width - margin * 2, H);
86338634
var range = w.options.max - w.options.min;
86348635
var nvalue = (w.value - w.options.min) / range;
86358636
ctx.fillStyle = active_widget == w ? "#89A" : "#678";
8636-
ctx.fillRect(margin, y, nvalue * (width - margin * 2), H);
8637+
ctx.fillRect(margin, y, nvalue * (widget_width - margin * 2), H);
86378638
if(show_text && !w.disabled)
8638-
ctx.strokeRect(margin, y, width - margin * 2, H);
8639+
ctx.strokeRect(margin, y, widget_width - margin * 2, H);
86398640
if (w.marker) {
86408641
var marker_nvalue = (w.marker - w.options.min) / range;
86418642
ctx.fillStyle = "#AA9";
8642-
ctx.fillRect( margin + marker_nvalue * (width - margin * 2), y, 2, H );
8643+
ctx.fillRect( margin + marker_nvalue * (widget_width - margin * 2), y, 2, H );
86438644
}
86448645
if (show_text) {
86458646
ctx.textAlign = "center";
86468647
ctx.fillStyle = text_color;
86478648
ctx.fillText(
86488649
w.name + " " + Number(w.value).toFixed(3),
8649-
width * 0.5,
8650+
widget_width * 0.5,
86508651
y + H * 0.7
86518652
);
86528653
}
@@ -8658,9 +8659,9 @@ LGraphNode.prototype.executeAction = function(action)
86588659
ctx.fillStyle = background_color;
86598660
ctx.beginPath();
86608661
if(show_text)
8661-
ctx.roundRect(margin, posY, width - margin * 2, H, H * 0.5);
8662+
ctx.roundRect(margin, posY, widget_width - margin * 2, H, H * 0.5);
86628663
else
8663-
ctx.rect(margin, posY, width - margin * 2, H );
8664+
ctx.rect(margin, posY, widget_width - margin * 2, H );
86648665
ctx.fill();
86658666
if (show_text) {
86668667
if(!w.disabled)
@@ -8674,9 +8675,9 @@ LGraphNode.prototype.executeAction = function(action)
86748675
ctx.lineTo(margin + 16, posY + H - 5);
86758676
ctx.fill();
86768677
ctx.beginPath();
8677-
ctx.moveTo(width - margin - 16, posY + 5);
8678-
ctx.lineTo(width - margin - 6, posY + H * 0.5);
8679-
ctx.lineTo(width - margin - 16, posY + H - 5);
8678+
ctx.moveTo(widget_width - margin - 16, posY + 5);
8679+
ctx.lineTo(widget_width - margin - 6, posY + H * 0.5);
8680+
ctx.lineTo(widget_width - margin - 16, posY + H - 5);
86808681
ctx.fill();
86818682
}
86828683
ctx.fillStyle = secondary_text_color;
@@ -8690,7 +8691,7 @@ LGraphNode.prototype.executeAction = function(action)
86908691
? w.options.precision
86918692
: 3
86928693
),
8693-
width - margin * 2 - 20,
8694+
widget_width - margin * 2 - 20,
86948695
y + H * 0.7
86958696
);
86968697
} else {
@@ -8705,7 +8706,7 @@ LGraphNode.prototype.executeAction = function(action)
87058706
}
87068707
ctx.fillText(
87078708
v,
8708-
width - margin * 2 - 20,
8709+
widget_width - margin * 2 - 20,
87098710
y + H * 0.7
87108711
);
87118712
}
@@ -8718,14 +8719,14 @@ LGraphNode.prototype.executeAction = function(action)
87188719
ctx.fillStyle = background_color;
87198720
ctx.beginPath();
87208721
if (show_text)
8721-
ctx.roundRect(margin, posY, width - margin * 2, H, H * 0.5);
8722+
ctx.roundRect(margin, posY, widget_width - margin * 2, H, H * 0.5);
87228723
else
8723-
ctx.rect( margin, posY, width - margin * 2, H );
8724+
ctx.rect( margin, posY, widget_width - margin * 2, H );
87248725
ctx.fill();
87258726
if (show_text) {
87268727
ctx.save();
87278728
ctx.beginPath();
8728-
ctx.rect(margin, posY, width - margin * 2, H);
8729+
ctx.rect(margin, posY, widget_width - margin * 2, H);
87298730
ctx.clip();
87308731

87318732
ctx.stroke();
@@ -8735,17 +8736,17 @@ LGraphNode.prototype.executeAction = function(action)
87358736
}
87368737
ctx.fillStyle = text_color;
87378738
ctx.textAlign = "right";
8738-
ctx.fillText(String(w.value).substr(0,30), width - margin * 2, y + H * 0.7); //30 chars max
8739+
ctx.fillText(String(w.value).substr(0,30), widget_width - margin * 2, y + H * 0.7); //30 chars max
87398740
ctx.restore();
87408741
}
87418742
break;
87428743
default:
87438744
if (w.draw) {
8744-
w.draw(ctx, node, width, y, H);
8745+
w.draw(ctx, node, widget_width, y, H);
87458746
}
87468747
break;
87478748
}
8748-
posY += (w.computeSize ? w.computeSize(width)[1] : H) + 4;
8749+
posY += (w.computeSize ? w.computeSize(widget_width)[1] : H) + 4;
87498750
ctx.globalAlpha = this.editor_alpha;
87508751

87518752
}
@@ -8778,14 +8779,15 @@ LGraphNode.prototype.executeAction = function(action)
87788779
if(!w || w.disabled)
87798780
continue;
87808781
var widget_height = w.computeSize ? w.computeSize(width)[1] : LiteGraph.NODE_WIDGET_HEIGHT;
8782+
var widget_width = w.width || width;
87818783
//outside
87828784
if ( w != active_widget &&
8783-
(x < 6 || x > width - 12 || y < w.last_y || y > w.last_y + widget_height) )
8785+
(x < 6 || x > widget_width - 12 || y < w.last_y || y > w.last_y + widget_height) )
87848786
continue;
87858787

87868788
var old_value = w.value;
87878789

8788-
//if ( w == active_widget || (x > 6 && x < width - 12 && y > w.last_y && y < w.last_y + widget_height) ) {
8790+
//if ( w == active_widget || (x > 6 && x < widget_width - 12 && y > w.last_y && y < w.last_y + widget_height) ) {
87898791
//inside widget
87908792
switch (w.type) {
87918793
case "button":
@@ -8802,7 +8804,7 @@ LGraphNode.prototype.executeAction = function(action)
88028804
break;
88038805
case "slider":
88048806
var range = w.options.max - w.options.min;
8805-
var nvalue = Math.clamp((x - 10) / (width - 20), 0, 1);
8807+
var nvalue = Math.clamp((x - 10) / (widget_width - 20), 0, 1);
88068808
w.value =
88078809
w.options.min +
88088810
(w.options.max - w.options.min) * nvalue;
@@ -8834,7 +8836,7 @@ LGraphNode.prototype.executeAction = function(action)
88348836
if( w.type != "number")
88358837
values_list = values.constructor === Array ? values : Object.keys(values);
88368838

8837-
var delta = x < 40 ? -1 : x > width - 40 ? 1 : 0;
8839+
var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0;
88388840
if (w.type == "number") {
88398841
w.value += delta * 0.1 * (w.options.step || 1);
88408842
if ( w.options.min != null && w.value < w.options.min ) {
@@ -8881,7 +8883,7 @@ LGraphNode.prototype.executeAction = function(action)
88818883
} //end mousedown
88828884
else if(event.type == "mouseup" && w.type == "number")
88838885
{
8884-
var delta = x < 40 ? -1 : x > width - 40 ? 1 : 0;
8886+
var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0;
88858887
if (event.click_time < 200 && delta == 0) {
88868888
this.prompt("Value",w.value,function(v) {
88878889
this.value = Number(v);

0 commit comments

Comments
 (0)