fixed bug

This commit is contained in:
tamat
2019-04-01 20:15:17 +02:00
parent 24a4f3a930
commit 7b77be53bf
23 changed files with 4123 additions and 2320 deletions

File diff suppressed because it is too large Load Diff

1135
build/litegraph.min.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -44,7 +44,7 @@
position: relative;
width: 100%;
height: calc( 100% - 80px );
background-color: #292929;
background-color: #1A1A1A;
}
.litegraph-editor .header, .litegraph-editor .footer {

View File

@@ -1,7 +1,7 @@
/* this CSS contains only the basic CSS needed to run the app and use it */
.lgraphcanvas {
cursor: crosshair;
/*cursor: crosshair;*/
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;

View File

@@ -1,689 +1 @@
{
"iteration": 139049,
"last_node_id": 16,
"last_link_id": 16,
"links": {
"0": {
"id": 0,
"origin_id": 0,
"origin_slot": 0,
"target_id": 2,
"target_slot": 0,
"data": null
},
"1": {
"id": 1,
"origin_id": 2,
"origin_slot": 0,
"target_id": 1,
"target_slot": 0,
"data": null
},
"2": {
"id": 2,
"origin_id": 2,
"origin_slot": 0,
"target_id": 3,
"target_slot": 0,
"data": null
},
"3": {
"id": 3,
"origin_id": 3,
"origin_slot": 0,
"target_id": 4,
"target_slot": 0,
"data": null
},
"4": {
"id": 4,
"origin_id": 5,
"origin_slot": 0,
"target_id": 2,
"target_slot": 1,
"data": null
},
"5": {
"id": 5,
"origin_id": 6,
"origin_slot": 0,
"target_id": 0,
"target_slot": 0,
"data": null
},
"6": {
"id": 6,
"origin_id": 7,
"origin_slot": 0,
"target_id": 0,
"target_slot": 1,
"data": null
},
"7": {
"id": 7,
"origin_id": 8,
"origin_slot": 0,
"target_id": 0,
"target_slot": 2,
"data": null
},
"8": {
"id": 8,
"origin_id": 9,
"origin_slot": 0,
"target_id": 0,
"target_slot": 3,
"data": null
},
"9": {
"id": 9,
"origin_id": 9,
"origin_slot": 0,
"target_id": 10,
"target_slot": 0,
"data": null
},
"10": {
"id": 10,
"origin_id": 3,
"origin_slot": 0,
"target_id": 11,
"target_slot": 0,
"data": null
},
"11": {
"id": 11,
"origin_id": 12,
"origin_slot": 0,
"target_id": 11,
"target_slot": 1,
"data": null
},
"12": {
"id": 12,
"origin_id": 11,
"origin_slot": 0,
"target_id": 13,
"target_slot": 0,
"data": null
},
"13": {
"id": 13,
"origin_id": 12,
"origin_slot": 0,
"target_id": 4,
"target_slot": 1,
"data": null
},
"14": {
"id": 14,
"origin_id": 13,
"origin_slot": 0,
"target_id": 14,
"target_slot": 0,
"data": null
},
"15": {
"id": 15,
"origin_id": 12,
"origin_slot": 0,
"target_id": 15,
"target_slot": 0,
"data": null
}
},
"config": {},
"nodes": [
{
"id": 1,
"title": "Destination",
"type": "audio/destination",
"pos": [
673,
171
],
"size": {
"0": 140,
"1": 20
},
"flags": {},
"inputs": [
{
"name": "in",
"type": "audio",
"link": 1
}
],
"mode": 0,
"properties": {}
},
{
"id": 2,
"title": "BiquadFilter",
"type": "audio/biquadfilter",
"pos": [
437,
251
],
"size": {
"0": 140,
"1": 34
},
"flags": {},
"inputs": [
{
"name": "in",
"type": "audio",
"link": 0
},
{
"name": "frequency",
"type": "number",
"link": 4
}
],
"outputs": [
{
"name": "out",
"type": "audio",
"links": [
1,
2
]
}
],
"mode": 0,
"properties": {
"frequency": 350,
"detune": 0,
"Q": 1,
"type": "lowpass"
}
},
{
"id": 6,
"title": "Knob",
"type": "widget/knob",
"pos": [
120,
183
],
"size": [
54,
74
],
"flags": {},
"outputs": [
{
"name": "",
"type": "number",
"links": [
5
]
}
],
"mode": 0,
"properties": {
"min": 0,
"max": 1,
"value": 0.5099999999999996,
"wcolor": "#7AF",
"size": 50
},
"boxcolor": "rgba(128,128,128,1.0)"
},
{
"id": 0,
"title": "Source",
"type": "audio/source",
"pos": [
251,
196
],
"size": {
"0": 140,
"1": 62
},
"flags": {},
"inputs": [
{
"name": "gain",
"type": "number",
"link": 5
},
{
"name": "Play",
"type": -1,
"link": 6
},
{
"name": "Stop",
"type": -1,
"link": 7
},
{
"name": "playbackRate",
"type": "number",
"link": 8
}
],
"outputs": [
{
"name": "out",
"type": "audio",
"links": [
0
]
}
],
"mode": 0,
"properties": {
"src": "demodata/audio.wav",
"gain": 0.5,
"loop": true,
"autoplay": true,
"playbackRate": 0.24000000000000002
}
},
{
"id": 5,
"title": "Knob",
"type": "widget/knob",
"pos": [
125,
293
],
"size": [
54,
74
],
"flags": {},
"outputs": [
{
"name": "",
"type": "number",
"links": [
4
]
}
],
"mode": 0,
"properties": {
"min": 0,
"max": 20000,
"value": 14800.00000000001,
"wcolor": "#7AF",
"size": 50
},
"boxcolor": "rgba(128,128,128,1.0)"
},
{
"id": 10,
"title": "Watch",
"type": "basic/watch",
"pos": [
516,
123
],
"size": {
"0": 140,
"1": 20
},
"flags": {},
"inputs": [
{
"name": "value",
"type": 0,
"link": 9,
"label": "0.240"
}
],
"outputs": [
{
"name": "value",
"type": 0,
"links": null,
"label": ""
}
],
"mode": 0,
"properties": {
"value": 0.24000000000000002
}
},
{
"id": 8,
"title": "Button",
"type": "widget/button",
"pos": [
274,
106
],
"size": [
128,
43
],
"flags": {},
"outputs": [
{
"name": "clicked",
"type": -1,
"links": [
7
]
}
],
"mode": 0,
"properties": {
"text": "Stop",
"font": "40px Arial",
"message": ""
}
},
{
"id": 9,
"title": "Knob",
"type": "widget/knob",
"pos": [
429,
119
],
"size": [
54,
74
],
"flags": {},
"outputs": [
{
"name": "",
"type": "number",
"links": [
8,
9
]
}
],
"mode": 0,
"properties": {
"min": 0,
"max": 4,
"value": 0.24000000000000002,
"wcolor": "#7AF",
"size": 50
},
"boxcolor": "rgba(128,128,128,1.0)"
},
{
"id": 7,
"title": "Button",
"type": "widget/button",
"pos": [
114,
103
],
"size": [
128,
43
],
"flags": {},
"outputs": [
{
"name": "clicked",
"type": -1,
"links": [
6
]
}
],
"mode": 0,
"properties": {
"text": "Play",
"font": "40px Arial",
"message": ""
}
},
{
"id": 3,
"title": "Analyser",
"type": "audio/analyser",
"pos": [
672,
306
],
"size": {
"0": 140,
"1": 20
},
"flags": {},
"inputs": [
{
"name": "in",
"type": "audio",
"link": 2
}
],
"outputs": [
{
"name": "freqs",
"type": "array",
"links": [
3,
10
]
}
],
"mode": 0,
"properties": {
"fftSize": 2048,
"minDecibels": -100,
"maxDecibels": -10,
"smoothingTimeConstant": 0.5
}
},
{
"id": 11,
"title": "Signal",
"type": "audio/signal",
"pos": [
241,
391
],
"size": {
"0": 140,
"1": 34
},
"flags": {},
"inputs": [
{
"name": "freqs",
"type": "array",
"link": 10
},
{
"name": "band",
"type": "number",
"link": 11
}
],
"outputs": [
{
"name": "signal",
"type": "number",
"links": [
12
]
}
],
"mode": 0,
"properties": {
"band": 440,
"amplitude": 1,
"samplerate": 44100
}
},
{
"id": 14,
"title": "Progress",
"type": "widget/progress",
"pos": [
91,
568
],
"size": {
"0": 140,
"1": 20
},
"flags": {},
"inputs": [
{
"name": "",
"type": "number",
"link": 14
}
],
"mode": 0,
"properties": {
"min": 0,
"max": 1,
"value": 0.3843137254901945,
"wcolor": "#AAF"
}
},
{
"id": 13,
"title": "Max. Signal",
"type": "basic/watch",
"pos": [
92,
527
],
"size": {
"0": 140,
"1": 20
},
"flags": {},
"inputs": [
{
"name": "value",
"type": 0,
"link": 12,
"label": "0.396"
}
],
"outputs": [
{
"name": "value",
"type": 0,
"links": [
14
],
"label": ""
}
],
"mode": 0,
"properties": {
"value": 0.3843137254901945
}
},
{
"id": 4,
"title": "Visualization",
"type": "audio/visualization",
"pos": [
253,
497
],
"size": [
662,
180
],
"flags": {},
"inputs": [
{
"name": "freqs",
"type": "array",
"link": 3
},
{
"name": "mark",
"type": "number",
"link": 13
}
],
"mode": 0,
"properties": {
"continuous": true,
"mark": 12000.000000000005,
"samplerate": 44100
}
},
{
"id": 15,
"title": "Watch",
"type": "basic/watch",
"pos": [
93,
398
],
"size": {
"0": 87,
"1": 20
},
"flags": {},
"inputs": [
{
"name": "value",
"type": 0,
"link": 15,
"label": "12000.000"
}
],
"outputs": [
{
"name": "value",
"type": 0,
"links": null,
"label": ""
}
],
"mode": 0,
"properties": {
"value": 12000.000000000005
}
},
{
"id": 12,
"title": "Knob",
"type": "widget/knob",
"pos": [
92,
435
],
"size": [
54,
74
],
"flags": {},
"outputs": [
{
"name": "",
"type": "number",
"links": [
11,
13,
15
]
}
],
"mode": 0,
"properties": {
"min": 0,
"max": 24000,
"value": 12000.000000000005,
"wcolor": "#7AF",
"size": 50
},
"boxcolor": "rgba(128,128,128,1.0)"
}
]
}
{"last_node_id":16,"last_link_id":16,"nodes":[{"id":9,"type":"widget/knob","pos":[440,81],"size":[80,100],"flags":{},"mode":0,"outputs":[{"name":"","type":"number","links":[8,9]}],"properties":{"min":0,"max":4,"value":0.24000000000000002,"wcolor":"#7AF","size":50},"boxcolor":"rgba(128,128,128,1.0)"},{"id":10,"type":"basic/watch","pos":[537,81],"size":{"0":140,"1":26},"flags":{},"mode":0,"inputs":[{"name":"value","type":0,"link":9,"label":"0.000"}],"outputs":[{"name":"value","type":0,"links":null,"label":""}],"properties":{"value":0.24000000000000002}},{"id":1,"type":"audio/destination","pos":[699,83],"size":{"0":140,"1":26},"flags":{},"mode":0,"inputs":[{"name":"in","type":"audio","link":1}],"properties":{}},{"id":6,"type":"widget/knob","pos":[116,179],"size":[80,100],"flags":{},"mode":0,"outputs":[{"name":"","type":"number","links":[5]}],"properties":{"min":0,"max":1,"value":0.5099999999999996,"wcolor":"#7AF","size":50},"boxcolor":"rgba(128,128,128,1.0)"},{"id":0,"type":"audio/source","pos":[272,192],"size":{"0":140,"1":86},"flags":{},"mode":0,"inputs":[{"name":"gain","type":"number","link":5},{"name":"Play","type":-1,"link":6},{"name":"Stop","type":-1,"link":7},{"name":"playbackRate","type":"number","link":8}],"outputs":[{"name":"out","type":"audio","links":[0]}],"properties":{"src":"demodata/audio.wav","gain":0.5,"loop":true,"autoplay":true,"playbackRate":0.24000000000000002},"boxcolor":"#AA4"},{"id":2,"type":"audio/biquadfilter","pos":[442,228],"size":{"0":140,"1":46},"flags":{},"mode":0,"inputs":[{"name":"in","type":"audio","link":0},{"name":"frequency","type":"number","link":4}],"outputs":[{"name":"out","type":"audio","links":[1,2]}],"properties":{"frequency":350,"detune":0,"Q":1,"type":"lowpass"}},{"id":3,"type":"audio/analyser","pos":[704,231],"size":{"0":140,"1":46},"flags":{},"mode":0,"inputs":[{"name":"in","type":"audio","link":2}],"outputs":[{"name":"freqs","type":"array","links":[3,10]},{"name":"samples","type":"array","links":null}],"properties":{"fftSize":2048,"minDecibels":-100,"maxDecibels":-10,"smoothingTimeConstant":0.5}},{"id":11,"type":"audio/signal","pos":[882,395],"size":{"0":140,"1":46},"flags":{},"mode":0,"inputs":[{"name":"freqs","type":"array","link":10},{"name":"band","type":"number","link":11}],"outputs":[{"name":"signal","type":"number","links":[12]}],"properties":{"band":440,"amplitude":1,"samplerate":44100}},{"id":4,"type":"audio/visualization","pos":[885,503],"size":{"0":140,"1":46},"flags":{},"mode":0,"inputs":[{"name":"freqs","type":"array","link":3},{"name":"mark","type":"number","link":13}],"properties":{"continuous":true,"mark":12000.000000000005,"samplerate":44100}},{"id":5,"type":"widget/knob","pos":[112,314],"size":[80,100],"flags":{},"mode":0,"outputs":[{"name":"","type":"number","links":[4]}],"properties":{"min":0,"max":20000,"value":14800.00000000001,"wcolor":"#7AF","size":50},"boxcolor":"rgba(128,128,128,1.0)"},{"id":13,"type":"basic/watch","pos":[110,458],"size":{"0":140,"1":26},"flags":{},"mode":0,"inputs":[{"name":"value","type":0,"link":12,"label":"0.000"}],"outputs":[{"name":"value","type":0,"links":[14],"label":""}],"title":"Max. Signal","properties":{"value":0.3843137254901945}},{"id":14,"type":"widget/progress","pos":[300,460],"size":{"0":140,"1":26},"flags":{},"mode":0,"inputs":[{"name":"","type":"number","link":14}],"properties":{"min":0,"max":1,"value":0.3843137254901945,"wcolor":"#AAF"}},{"id":12,"type":"widget/knob","pos":[460,458],"size":[80,100],"flags":{},"mode":0,"outputs":[{"name":"","type":"number","links":[11,13,15]}],"properties":{"min":0,"max":24000,"value":12000.000000000005,"wcolor":"#7AF","size":50},"boxcolor":"rgba(128,128,128,1.0)"},{"id":15,"type":"basic/watch","pos":[888,598],"size":{"0":140,"1":26},"flags":{},"mode":0,"inputs":[{"name":"value","type":0,"link":15,"label":"0.000"}],"outputs":[{"name":"value","type":0,"links":null,"label":""}],"properties":{"value":12000.000000000005}},{"id":7,"type":"widget/button","pos":[113,83],"size":{"0":141,"1":60},"flags":{},"mode":0,"outputs":[{"name":"clicked","type":-1,"links":[6]}],"properties":{"text":"Play","font_size":30,"message":"","font":"40px Arial"}},{"id":8,"type":"widget/button","pos":[273,83],"size":{"0":143,"1":62},"flags":{},"mode":0,"outputs":[{"name":"clicked","type":-1,"links":[7]}],"properties":{"text":"Stop","font_size":30,"message":"","font":"40px Arial"}}],"links":[[0,0,0,2,0,null],[1,2,0,1,0,null],[2,2,0,3,0,null],[3,3,0,4,0,null],[4,5,0,2,1,null],[5,6,0,0,0,null],[6,7,0,0,1,null],[7,8,0,0,2,null],[8,9,0,0,3,null],[9,9,0,10,0,null],[10,3,0,11,0,null],[11,12,0,11,1,null],[12,11,0,13,0,null],[13,12,0,4,1,null],[14,13,0,14,0,null],[15,12,0,15,0,null]],"groups":[],"config":{}}

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"last_node_id":14,"last_link_id":14,"nodes":[{"id":5,"type":"math/operation","pos":[432,116],"size":{"0":140,"1":34},"flags":{},"mode":0,"inputs":[{"name":"A","type":"number","link":null},{"name":"B","type":"number","link":null}],"outputs":[{"name":"=","type":"number","links":[2]}],"properties":{"A":1,"B":1,"OP":"+"},"color":"#233","bgcolor":"#355","shape":2},{"id":9,"type":"features/slots","pos":[847,479],"size":[100,40],"flags":{"horizontal":true},"mode":0,"inputs":[{"name":"C","type":"number","link":6}],"outputs":[{"name":"A","type":"number","links":null},{"name":"B","type":"number","links":null}],"properties":{}},{"id":10,"type":"widget/knob","pos":[456,189],"size":[54,74],"flags":{},"mode":0,"outputs":[{"name":"","type":"number","links":[9]}],"properties":{"min":0,"max":1,"value":0.5,"wcolor":"#7AF","size":50}},{"id":4,"type":"math/operation","pos":[634,150],"size":{"0":140,"1":34},"flags":{},"mode":0,"inputs":[{"name":"A","type":"number","link":2},{"name":"B","type":"number","link":9}],"outputs":[{"name":"=","type":"number","links":[1]}],"properties":{"A":1,"B":1,"OP":"+"},"shape":2},{"id":2,"type":"features/shape","pos":[850,128],"size":{"0":140,"1":39},"flags":{},"mode":0,"inputs":[{"name":"","type":"number","link":1}],"outputs":[{"name":"","type":"number","links":null}],"properties":{}},{"id":12,"type":"input/gamepad","pos":[594,223],"size":{"0":140,"1":49},"flags":{},"mode":0,"outputs":[{"name":"left_x_axis","type":"number","links":null},{"name":"left_y_axis","type":"number","links":null},{"name":"button_pressed","type":-1,"links":[12]}],"properties":{"gamepad_index":0,"threshold":0.1}},{"id":7,"type":"features/slots","pos":[757,380],"size":[100,40],"flags":{"horizontal":true},"mode":0,"inputs":[{"name":"C","type":"number","link":13}],"outputs":[{"name":"A","type":"number","links":[10]},{"name":"B","type":"number","links":[6]}],"properties":{}},{"id":8,"type":"features/slots","pos":[672,481],"size":[100,40],"flags":{"horizontal":true},"mode":0,"inputs":[{"name":"C","type":"number","link":10}],"outputs":[{"name":"A","type":"number","links":null},{"name":"B","type":"number","links":null}],"properties":{}},{"id":13,"type":"events/log","pos":[863,209],"size":{"0":140,"1":19},"flags":{},"mode":0,"inputs":[{"name":"event","type":-1,"link":12}],"properties":{}},{"id":14,"type":"features/widgets","pos":[476,366],"size":{"0":180,"1":170},"flags":{},"mode":0,"outputs":[{"name":"","type":"number","links":[13]}],"properties":{}}],"links":[[1,4,0,2,0,"number"],[2,5,0,4,0,"number"],[6,7,1,9,0,"number"],[9,10,0,4,1,"number"],[10,7,0,8,0,"number"],[12,12,2,13,0,-1],[13,14,0,7,0,"number"]],"groups":[{"title":"Group","bounding":[418,298,564,255],"color":"#3f789e"}],"config":{}}
{"last_node_id":14,"last_link_id":14,"nodes":[{"id":9,"type":"features/slots","pos":[847,479],"size":[100,40],"flags":{"horizontal":true},"mode":0,"inputs":[{"name":"C","type":"number","link":6}],"outputs":[{"name":"A","type":"number","links":null},{"name":"B","type":"number","links":null}],"properties":{}},{"id":7,"type":"features/slots","pos":[757,380],"size":[100,40],"flags":{"horizontal":true},"mode":0,"inputs":[{"name":"C","type":"number","link":13}],"outputs":[{"name":"A","type":"number","links":[10]},{"name":"B","type":"number","links":[6]}],"properties":{}},{"id":8,"type":"features/slots","pos":[672,481],"size":[100,40],"flags":{"horizontal":true},"mode":0,"inputs":[{"name":"C","type":"number","link":10}],"outputs":[{"name":"A","type":"number","links":null},{"name":"B","type":"number","links":null}],"properties":{}},{"id":5,"type":"math/operation","pos":[413,101],"size":[140,34],"flags":{"collapsed":true},"mode":0,"inputs":[{"name":"A","type":"number","link":null},{"name":"B","type":"number","link":null}],"outputs":[{"name":"=","type":"number","links":[2]}],"properties":{"A":1,"B":1,"OP":"+"},"shape":2},{"id":12,"type":"input/gamepad","pos":[593,208],"size":{"0":175,"1":74},"flags":{},"mode":0,"outputs":[{"name":"left_x_axis","type":"number","links":null},{"name":"left_y_axis","type":"number","links":null},{"name":"button_pressed","type":-1,"links":[12]}],"properties":{"gamepad_index":0,"threshold":0.1}},{"id":13,"type":"events/log","pos":[862,246],"size":{"0":144,"1":32},"flags":{},"mode":0,"inputs":[{"name":"event","type":-1,"link":12}],"properties":{}},{"id":14,"type":"features/widgets","pos":[441,365],"size":{"0":180,"1":170},"flags":{},"mode":0,"outputs":[{"name":"","type":"number","links":[13]}],"properties":{}},{"id":10,"type":"widget/knob","pos":[421,197],"size":[74,92],"flags":{},"mode":0,"outputs":[{"name":"","type":"number","links":[9]}],"properties":{"min":0,"max":1,"value":0.5,"wcolor":"#7AF","size":50}},{"id":4,"type":"math/operation","pos":[596,116],"size":[148,48],"flags":{},"mode":0,"inputs":[{"name":"A","type":"number","link":2},{"name":"B","type":"number","link":9}],"outputs":[{"name":"=","type":"number","links":[1]}],"properties":{"A":1,"B":1,"OP":"+"},"shape":2},{"id":2,"type":"features/shape","pos":[850,97],"size":{"0":140,"1":39},"flags":{},"mode":0,"inputs":[{"name":"","type":"number","link":1}],"outputs":[{"name":"","type":"number","links":null}],"properties":{}}],"links":[[1,4,0,2,0,"number"],[2,5,0,4,0,"number"],[6,7,1,9,0,"number"],[9,10,0,4,1,"number"],[10,7,0,8,0,"number"],[12,12,2,13,0,-1],[13,14,0,7,0,"number"]],"groups":[{"title":"Group","bounding":[418,298,609,255],"color":"#3f789e"}],"config":{}}

File diff suppressed because one or more lines are too long

View File

@@ -14,7 +14,7 @@
</div>
<script type="text/javascript" src="../external/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="http://tamats.com/projects/sillyserver/src/sillyclient.js"></script>
<script type="text/javascript" src="https://tamats.com/projects/sillyserver/src/sillyclient.js"></script>
<script type="text/javascript" src="js/libs/audiosynth.js"></script>
<script type="text/javascript" src="../src/litegraph.js"></script>
@@ -24,6 +24,8 @@
<script type="text/javascript" src="../src/nodes/logic.js"></script>
<script type="text/javascript" src="../src/nodes/events.js"></script>
<script type="text/javascript" src="../src/nodes/math.js"></script>
<script type="text/javascript" src="../src/nodes/math3d.js"></script>
<script type="text/javascript" src="../src/nodes/strings.js"></script>
<script type="text/javascript" src="../src/nodes/interface.js"></script>
<script type="text/javascript" src="../src/nodes/graphics.js"></script>
<script type="text/javascript" src="../src/nodes/input.js"></script>

View File

@@ -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 );

File diff suppressed because it is too large Load Diff

View File

@@ -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)
{
}
}
}

View File

@@ -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

View File

@@ -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 );

View File

@@ -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;

View File

@@ -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"];

View File

@@ -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();
}

View File

@@ -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()

444
src/nodes/math3d.js Normal file
View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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);
}
}

60
src/nodes/strings.js Normal file
View File

@@ -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);

View File

@@ -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