@shaderfrog/core 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/package.json +10 -7
  2. package/cjs/engine.js +0 -218
  3. package/cjs/graph/base-node.js +0 -13
  4. package/cjs/graph/code-nodes.js +0 -23
  5. package/cjs/graph/context.js +0 -253
  6. package/cjs/graph/data-nodes.js +0 -146
  7. package/cjs/graph/edge.js +0 -12
  8. package/cjs/graph/evaluate.js +0 -32
  9. package/cjs/graph/graph-node.js +0 -143
  10. package/cjs/graph/graph-types.js +0 -25
  11. package/cjs/graph/graph.js +0 -533
  12. package/cjs/graph/graph.test.js +0 -173
  13. package/cjs/graph/index.js +0 -27
  14. package/cjs/graph/parsers.js +0 -219
  15. package/cjs/graph/shader-sections.js +0 -268
  16. package/cjs/index.js +0 -19
  17. package/cjs/package.json +0 -1
  18. package/cjs/plugins/babylon/bablyengine.js +0 -597
  19. package/cjs/plugins/babylon/importers.js +0 -66
  20. package/cjs/plugins/babylon/index.js +0 -5
  21. package/cjs/plugins/playcanvas/importers.js +0 -30
  22. package/cjs/plugins/playcanvas/index.js +0 -5
  23. package/cjs/plugins/playcanvas/playengine.js +0 -549
  24. package/cjs/plugins/three/importers.js +0 -17
  25. package/cjs/plugins/three/index.js +0 -6
  26. package/cjs/plugins/three/threngine.js +0 -619
  27. package/cjs/strategy/assignemntTo.js +0 -31
  28. package/cjs/strategy/declarationOf.js +0 -28
  29. package/cjs/strategy/hardCode.js +0 -28
  30. package/cjs/strategy/index.js +0 -25
  31. package/cjs/strategy/inject.js +0 -127
  32. package/cjs/strategy/namedAttribute.js +0 -53
  33. package/cjs/strategy/strategy.js +0 -35
  34. package/cjs/strategy/stratgies.test.js +0 -192
  35. package/cjs/strategy/texture2D.js +0 -88
  36. package/cjs/strategy/uniform.js +0 -195
  37. package/cjs/strategy/variable.js +0 -85
  38. package/cjs/util/ast.js +0 -351
  39. package/cjs/util/ensure.js +0 -11
  40. package/cjs/util/id.js +0 -6
  41. package/esm/engine.d.ts +0 -69
  42. package/esm/graph/base-node.d.ts +0 -36
  43. package/esm/graph/code-nodes.d.ts +0 -44
  44. package/esm/graph/context.d.ts +0 -37
  45. package/esm/graph/data-nodes.d.ts +0 -83
  46. package/esm/graph/edge.d.ts +0 -13
  47. package/esm/graph/evaluate.d.ts +0 -9
  48. package/esm/graph/graph-node.d.ts +0 -8
  49. package/esm/graph/graph-types.d.ts +0 -38
  50. package/esm/graph/graph.d.ts +0 -89
  51. package/esm/graph/graph.test.d.ts +0 -1
  52. package/esm/graph/index.d.ts +0 -11
  53. package/esm/graph/parsers.d.ts +0 -39
  54. package/esm/graph/shader-sections.d.ts +0 -47
  55. package/esm/index.d.ts +0 -3
  56. package/esm/package.json +0 -1
  57. package/esm/plugins/babylon/bablyengine.d.ts +0 -28
  58. package/esm/plugins/babylon/importers.d.ts +0 -3
  59. package/esm/plugins/babylon/index.d.ts +0 -2
  60. package/esm/plugins/playcanvas/importers.d.ts +0 -3
  61. package/esm/plugins/playcanvas/index.d.ts +0 -2
  62. package/esm/plugins/playcanvas/playengine.d.ts +0 -39
  63. package/esm/plugins/three/importers.d.ts +0 -3
  64. package/esm/plugins/three/index.d.ts +0 -2
  65. package/esm/plugins/three/threngine.d.ts +0 -34
  66. package/esm/strategy/assignemntTo.d.ts +0 -9
  67. package/esm/strategy/declarationOf.d.ts +0 -9
  68. package/esm/strategy/hardCode.d.ts +0 -15
  69. package/esm/strategy/index.d.ts +0 -9
  70. package/esm/strategy/inject.d.ts +0 -15
  71. package/esm/strategy/namedAttribute.d.ts +0 -9
  72. package/esm/strategy/strategy.d.ts +0 -28
  73. package/esm/strategy/stratgies.test.d.ts +0 -1
  74. package/esm/strategy/texture2D.d.ts +0 -6
  75. package/esm/strategy/uniform.d.ts +0 -6
  76. package/esm/strategy/variable.d.ts +0 -6
  77. package/esm/util/ast.d.ts +0 -30
  78. package/esm/util/ensure.d.ts +0 -1
  79. package/esm/util/id.d.ts +0 -1
  80. /package/{cjs/engine.d.ts → engine.d.ts} +0 -0
  81. /package/{esm/engine.js → engine.js} +0 -0
  82. /package/{cjs/graph → graph}/base-node.d.ts +0 -0
  83. /package/{esm/graph → graph}/base-node.js +0 -0
  84. /package/{cjs/graph → graph}/code-nodes.d.ts +0 -0
  85. /package/{esm/graph → graph}/code-nodes.js +0 -0
  86. /package/{cjs/graph → graph}/context.d.ts +0 -0
  87. /package/{esm/graph → graph}/context.js +0 -0
  88. /package/{cjs/graph → graph}/data-nodes.d.ts +0 -0
  89. /package/{esm/graph → graph}/data-nodes.js +0 -0
  90. /package/{cjs/graph → graph}/edge.d.ts +0 -0
  91. /package/{esm/graph → graph}/edge.js +0 -0
  92. /package/{cjs/graph → graph}/evaluate.d.ts +0 -0
  93. /package/{esm/graph → graph}/evaluate.js +0 -0
  94. /package/{cjs/graph → graph}/graph-node.d.ts +0 -0
  95. /package/{esm/graph → graph}/graph-node.js +0 -0
  96. /package/{cjs/graph → graph}/graph-types.d.ts +0 -0
  97. /package/{esm/graph → graph}/graph-types.js +0 -0
  98. /package/{cjs/graph → graph}/graph.d.ts +0 -0
  99. /package/{esm/graph → graph}/graph.js +0 -0
  100. /package/{cjs/graph → graph}/graph.test.d.ts +0 -0
  101. /package/{esm/graph → graph}/graph.test.js +0 -0
  102. /package/{cjs/graph → graph}/index.d.ts +0 -0
  103. /package/{esm/graph → graph}/index.js +0 -0
  104. /package/{cjs/graph → graph}/parsers.d.ts +0 -0
  105. /package/{esm/graph → graph}/parsers.js +0 -0
  106. /package/{cjs/graph → graph}/shader-sections.d.ts +0 -0
  107. /package/{esm/graph → graph}/shader-sections.js +0 -0
  108. /package/{cjs/index.d.ts → index.d.ts} +0 -0
  109. /package/{esm/index.js → index.js} +0 -0
  110. /package/{cjs/plugins → plugins}/babylon/bablyengine.d.ts +0 -0
  111. /package/{esm/plugins → plugins}/babylon/bablyengine.js +0 -0
  112. /package/{cjs/plugins → plugins}/babylon/importers.d.ts +0 -0
  113. /package/{esm/plugins → plugins}/babylon/importers.js +0 -0
  114. /package/{cjs/plugins → plugins}/babylon/index.d.ts +0 -0
  115. /package/{esm/plugins → plugins}/babylon/index.js +0 -0
  116. /package/{cjs/plugins → plugins}/playcanvas/importers.d.ts +0 -0
  117. /package/{esm/plugins → plugins}/playcanvas/importers.js +0 -0
  118. /package/{cjs/plugins → plugins}/playcanvas/index.d.ts +0 -0
  119. /package/{esm/plugins → plugins}/playcanvas/index.js +0 -0
  120. /package/{cjs/plugins → plugins}/playcanvas/playengine.d.ts +0 -0
  121. /package/{esm/plugins → plugins}/playcanvas/playengine.js +0 -0
  122. /package/{cjs/plugins → plugins}/three/importers.d.ts +0 -0
  123. /package/{esm/plugins → plugins}/three/importers.js +0 -0
  124. /package/{cjs/plugins → plugins}/three/index.d.ts +0 -0
  125. /package/{esm/plugins → plugins}/three/index.js +0 -0
  126. /package/{cjs/plugins → plugins}/three/threngine.d.ts +0 -0
  127. /package/{esm/plugins → plugins}/three/threngine.js +0 -0
  128. /package/{cjs/strategy → strategy}/assignemntTo.d.ts +0 -0
  129. /package/{esm/strategy → strategy}/assignemntTo.js +0 -0
  130. /package/{cjs/strategy → strategy}/declarationOf.d.ts +0 -0
  131. /package/{esm/strategy → strategy}/declarationOf.js +0 -0
  132. /package/{cjs/strategy → strategy}/hardCode.d.ts +0 -0
  133. /package/{esm/strategy → strategy}/hardCode.js +0 -0
  134. /package/{cjs/strategy → strategy}/index.d.ts +0 -0
  135. /package/{esm/strategy → strategy}/index.js +0 -0
  136. /package/{cjs/strategy → strategy}/inject.d.ts +0 -0
  137. /package/{esm/strategy → strategy}/inject.js +0 -0
  138. /package/{cjs/strategy → strategy}/namedAttribute.d.ts +0 -0
  139. /package/{esm/strategy → strategy}/namedAttribute.js +0 -0
  140. /package/{cjs/strategy → strategy}/strategy.d.ts +0 -0
  141. /package/{esm/strategy → strategy}/strategy.js +0 -0
  142. /package/{cjs/strategy → strategy}/stratgies.test.d.ts +0 -0
  143. /package/{esm/strategy → strategy}/stratgies.test.js +0 -0
  144. /package/{cjs/strategy → strategy}/texture2D.d.ts +0 -0
  145. /package/{esm/strategy → strategy}/texture2D.js +0 -0
  146. /package/{cjs/strategy → strategy}/uniform.d.ts +0 -0
  147. /package/{esm/strategy → strategy}/uniform.js +0 -0
  148. /package/{cjs/strategy → strategy}/variable.d.ts +0 -0
  149. /package/{esm/strategy → strategy}/variable.js +0 -0
  150. /package/{cjs/util → util}/ast.d.ts +0 -0
  151. /package/{esm/util → util}/ast.js +0 -0
  152. /package/{cjs/util → util}/ensure.d.ts +0 -0
  153. /package/{esm/util → util}/ensure.js +0 -0
  154. /package/{cjs/util → util}/id.d.ts +0 -0
  155. /package/{esm/util → util}/id.js +0 -0
@@ -1,173 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var util_1 = __importDefault(require("util"));
7
- var glsl_parser_1 = require("@shaderfrog/glsl-parser");
8
- var glsl_parser_2 = require("@shaderfrog/glsl-parser");
9
- var graph_node_1 = require("./graph-node");
10
- var shader_sections_1 = require("./shader-sections");
11
- var data_nodes_1 = require("./data-nodes");
12
- var edge_1 = require("./edge");
13
- var evaluate_1 = require("./evaluate");
14
- var inspect = function (thing) {
15
- return console.log(util_1.default.inspect(thing, false, null, true));
16
- };
17
- var mergeBlocks = function (ast1, ast2) {
18
- var s1 = (0, shader_sections_1.findShaderSections)(ast1);
19
- var s2 = (0, shader_sections_1.findShaderSections)(ast2);
20
- var merged = (0, shader_sections_1.mergeShaderSections)(s1, s2);
21
- return (0, glsl_parser_2.generate)((0, shader_sections_1.shaderSectionsToProgram)(merged, {
22
- includePrecisions: true,
23
- includeVersion: true,
24
- }));
25
- };
26
- var dedupe = function (code) {
27
- return (0, glsl_parser_2.generate)((0, shader_sections_1.shaderSectionsToProgram)((0, shader_sections_1.findShaderSections)(glsl_parser_1.parser.parse(code)), {
28
- includePrecisions: true,
29
- includeVersion: true,
30
- }));
31
- };
32
- var counter = 0;
33
- var p = { x: 0, y: 0 };
34
- var id = function () { return '' + counter++; };
35
- var constructor = function () { return ({
36
- config: {
37
- version: 3,
38
- preprocess: false,
39
- strategies: [],
40
- uniforms: [],
41
- },
42
- id: '1',
43
- name: '1',
44
- engine: true,
45
- type: '',
46
- inputs: [],
47
- outputs: [],
48
- position: { x: 0, y: 0 },
49
- source: '',
50
- stage: undefined,
51
- }); };
52
- var engine = {
53
- name: 'three',
54
- displayName: 'Three.js',
55
- evaluateNode: function (node) {
56
- if (node.type === 'number') {
57
- return parseFloat(node.value);
58
- }
59
- return node.value;
60
- },
61
- constructors: {
62
- physical: constructor,
63
- toon: constructor,
64
- },
65
- mergeOptions: {
66
- includePrecisions: true,
67
- includeVersion: true,
68
- },
69
- importers: {},
70
- preserve: new Set(),
71
- parsers: {},
72
- };
73
- // it('graph compiler arbitrary helper test', () => {
74
- // const graph: Graph = {
75
- // nodes: [
76
- // outputNode('0', 'Output v', p, 'vertex'),
77
- // outputNode('1', 'Output f', p, 'fragment'),
78
- // makeSourceNode(
79
- // '2',
80
- // `uniform sampler2D image1;
81
- // uniform sampler2D image2;
82
- // void main() {
83
- // vec3 col = texture2D(image1, posTurn - 0.4 * time).rgb + 1.0;
84
- // vec3 col = texture2D(image2, negTurn - 0.4 * time).rgb + 2.0;
85
- // }
86
- // `,
87
- // 'fragment'
88
- // ),
89
- // makeSourceNode(
90
- // '3',
91
- // `void main() {
92
- // return vec4(0.0);
93
- // }
94
- // `,
95
- // 'fragment'
96
- // ),
97
- // makeSourceNode(
98
- // '4',
99
- // `void main() {
100
- // return vec4(1.0);
101
- // }
102
- // `,
103
- // 'fragment'
104
- // ),
105
- // ],
106
- // edges: [
107
- // makeEdge(id(), '2', '1', 'out', 'filler_frogFragOut', 'fragment'),
108
- // makeEdge(id(), '3', '2', 'out', 'filler_image1', 'fragment'),
109
- // makeEdge(id(), '4', '2', 'out', 'filler_image2', 'fragment'),
110
- // ],
111
- // };
112
- // const engineContext: EngineContext = {
113
- // engine: 'three',
114
- // nodes: {},
115
- // runtime: {},
116
- // debuggingNonsense: {},
117
- // };
118
- // const result = compileGraph(engineContext, engine, graph);
119
- // const built = generate(
120
- // shaderSectionsToProgram(result.fragment, {
121
- // includePrecisions: true,
122
- // includeVersion: true,
123
- // }).program
124
- // );
125
- // expect(built).toBe('hi');
126
- // });
127
- describe('evaluateNode()', function () {
128
- it('evaluates binary nodes', function () {
129
- var finalAdd = (0, graph_node_1.addNode)(id(), p);
130
- var add2 = (0, graph_node_1.addNode)(id(), p);
131
- var num1 = (0, data_nodes_1.numberNode)(id(), 'number', p, '3');
132
- var num2 = (0, data_nodes_1.numberNode)(id(), 'number', p, '5');
133
- var num3 = (0, data_nodes_1.numberNode)(id(), 'number', p, '7');
134
- var graph = {
135
- nodes: [num1, num2, num3, finalAdd, add2],
136
- edges: [
137
- (0, edge_1.makeEdge)(id(), num1.id, finalAdd.id, 'out', 'a'),
138
- (0, edge_1.makeEdge)(id(), add2.id, finalAdd.id, 'out', 'b'),
139
- (0, edge_1.makeEdge)(id(), num2.id, add2.id, 'out', 'a'),
140
- (0, edge_1.makeEdge)(id(), num3.id, add2.id, 'out', 'b'),
141
- ],
142
- };
143
- expect((0, evaluate_1.evaluateNode)(engine, graph, finalAdd)).toBe(15);
144
- });
145
- });
146
- it('should merge uniforms with interface blocks', function () {
147
- var astX = glsl_parser_1.parser.parse("uniform vec2 x;");
148
- var astY = glsl_parser_1.parser.parse("uniform vec2 y, z;\nuniform vec3 a;");
149
- expect(mergeBlocks(astX, astY)).toEqual("uniform vec2 x, y, z;\nuniform vec3 a;\n");
150
- var astL01 = glsl_parser_1.parser.parse("uniform Light0 { vec4 y; } x;", { quiet: true });
151
- var astL02 = glsl_parser_1.parser.parse("uniform Light0 { vec4 y; } x;", { quiet: true });
152
- expect(mergeBlocks(astL01, astL02)).toEqual("uniform Light0 { vec4 y; } x;\n");
153
- var astL001 = glsl_parser_1.parser.parse("uniform Light0 { vec4 y; } x;", {
154
- quiet: true,
155
- });
156
- var astL002 = glsl_parser_1.parser.parse("uniform Light0 x;", { quiet: true });
157
- expect(mergeBlocks(astL001, astL002)).toEqual("uniform Light0 { vec4 y; } x;\n");
158
- var astLo01 = glsl_parser_1.parser.parse("uniform Light0 x;", { quiet: true });
159
- var astLo02 = glsl_parser_1.parser.parse("uniform Light0 { vec4 y; } x;", {
160
- quiet: true,
161
- });
162
- expect(mergeBlocks(astLo01, astLo02)).toEqual("uniform Light0 { vec4 y; } x;\n");
163
- // This may be a bug, look at how the uniforms are merged. I at least want to
164
- // note its current behavior in this test
165
- var vec2Arr1 = glsl_parser_1.parser.parse("uniform vec2 y[5];");
166
- var vec2Arr2 = glsl_parser_1.parser.parse("uniform vec2 y[10];");
167
- expect(mergeBlocks(vec2Arr1, vec2Arr2)).toEqual("uniform vec2 y[10];\n");
168
- var block1 = glsl_parser_1.parser.parse("uniform Scene { mat4 view; };");
169
- var block2 = glsl_parser_1.parser.parse("uniform Scene { mat4 view; };");
170
- expect(mergeBlocks(block1, block2)).toEqual("uniform Scene { mat4 view; };\n");
171
- // Verify these lines are preserved (they go through dedupeUniforms)
172
- expect(dedupe("layout(std140,column_major) uniform;")).toEqual("layout(std140,column_major) uniform;");
173
- });
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./base-node"), exports);
18
- __exportStar(require("./data-nodes"), exports);
19
- __exportStar(require("./graph-node"), exports);
20
- __exportStar(require("./code-nodes"), exports);
21
- __exportStar(require("./edge"), exports);
22
- __exportStar(require("./parsers"), exports);
23
- __exportStar(require("./context"), exports);
24
- __exportStar(require("./evaluate"), exports);
25
- __exportStar(require("./graph-types"), exports);
26
- __exportStar(require("./graph"), exports);
27
- __exportStar(require("./shader-sections"), exports);
@@ -1,219 +0,0 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- var __importDefault = (this && this.__importDefault) || function (mod) {
28
- return (mod && mod.__esModule) ? mod : { "default": mod };
29
- };
30
- var _a;
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.coreParsers = exports.alphabet = void 0;
33
- var glsl_parser_1 = require("@shaderfrog/glsl-parser");
34
- var ast_1 = require("@shaderfrog/glsl-parser/ast");
35
- var preprocessor_1 = __importDefault(require("@shaderfrog/glsl-parser/preprocessor"));
36
- var ast_2 = require("../util/ast");
37
- var strategy_1 = require("../strategy");
38
- var code_nodes_1 = require("./code-nodes");
39
- var base_node_1 = require("./base-node");
40
- var graph_types_1 = require("./graph-types");
41
- var graph_1 = require("./graph");
42
- var ast_3 = require("../util/ast");
43
- /*
44
- * Core graph parsers, which is the plumbing/interface the graph and context
45
- * calls into, to parse, find inputs, etc, and define this per-node type.
46
- */
47
- var log = function () {
48
- var _a;
49
- var args = [];
50
- for (var _i = 0; _i < arguments.length; _i++) {
51
- args[_i] = arguments[_i];
52
- }
53
- return (_a = console.log).call.apply(_a, __spreadArray([console, '\x1b[31m(core.parsers)\x1b[0m'], __read(args), false));
54
- };
55
- exports.alphabet = 'abcdefghijklmnopqrstuvwxyz';
56
- exports.coreParsers = (_a = {},
57
- _a[graph_types_1.NodeType.SOURCE] = {
58
- produceAst: function (engineContext, engine, graph, node, inputEdges) {
59
- var ast;
60
- // @ts-ignore
61
- if (node.expressionOnly) {
62
- node.sourceType = code_nodes_1.SourceType.EXPRESSION;
63
- // @ts-ignore
64
- delete node.expressionOnly;
65
- }
66
- if (node.sourceType === code_nodes_1.SourceType.FN_BODY_FRAGMENT) {
67
- var _a = (0, ast_2.makeFnBodyStatementWithScopes)(node.source), statements = _a.statements, scope = _a.scope;
68
- ast = {
69
- type: 'program',
70
- scopes: [scope],
71
- // @ts-ignore
72
- program: statements,
73
- };
74
- }
75
- else if (node.sourceType === code_nodes_1.SourceType.EXPRESSION) {
76
- var _b = (0, ast_2.makeExpressionWithScopes)(node.source), expression = _b.expression, scope = _b.scope;
77
- ast = {
78
- type: 'program',
79
- scopes: [scope],
80
- // @ts-ignore
81
- program: [expression],
82
- };
83
- }
84
- else {
85
- var preprocessed = node.config.preprocess === false
86
- ? node.source
87
- : (0, preprocessor_1.default)(node.source, {
88
- preserve: {
89
- version: function () { return true; },
90
- },
91
- });
92
- ast = glsl_parser_1.parser.parse(preprocessed);
93
- if (node.config.version === 2 && node.stage) {
94
- (0, ast_2.from2To3)(ast, node.stage);
95
- log('converted ', node, 'to version 3', {
96
- code: (0, glsl_parser_1.generate)(ast),
97
- });
98
- }
99
- // This assumes that expressionOnly nodes don't have a stage and that all
100
- // fragment source code shades have main function, which is probably wrong
101
- if (node.stage === 'fragment') {
102
- (0, ast_2.convert300MainToReturn)(node.id, ast);
103
- }
104
- }
105
- return ast;
106
- },
107
- findInputs: function (engineContext, ast, edges, node, sibling) {
108
- var seen = new Set();
109
- return node.config.strategies
110
- .flatMap(function (strategy) { return (0, strategy_1.applyStrategy)(strategy, ast, node, sibling); })
111
- .filter(function (_a) {
112
- var _b = __read(_a, 2), input = _b[0], _ = _b[1];
113
- if (!seen.has(input.id)) {
114
- seen.add(input.id);
115
- return true;
116
- }
117
- return false;
118
- });
119
- },
120
- produceFiller: function (node, ast) {
121
- return node.sourceType === code_nodes_1.SourceType.EXPRESSION
122
- ? ast.program[0]
123
- : node.sourceType === code_nodes_1.SourceType.FN_BODY_FRAGMENT
124
- ? ast.program
125
- : (0, ast_2.makeExpression)("".concat((0, graph_1.nodeName)(node), "()"));
126
- },
127
- },
128
- // TODO: Output node assumes strategies are still passed in on node creation,
129
- // which might be a little awkward for graph creators?
130
- _a[graph_types_1.NodeType.OUTPUT] = {
131
- produceAst: function (engineContext, engine, graph, node, inputEdges) {
132
- return glsl_parser_1.parser.parse(node.source);
133
- },
134
- findInputs: function (engineContext, ast, edges, node, sibling) {
135
- return __spreadArray(__spreadArray([], __read(node.config.strategies.flatMap(function (strategy) {
136
- return (0, strategy_1.applyStrategy)(strategy, ast, node, sibling);
137
- })), false), [
138
- [
139
- (0, base_node_1.nodeInput)(graph_types_1.MAGIC_OUTPUT_STMTS, "filler_".concat(graph_types_1.MAGIC_OUTPUT_STMTS), 'filler', 'rgba', ['code'], false),
140
- function (fillerAst) {
141
- var fn = ast.program.find(function (stmt) { return stmt.type === 'function'; });
142
- fn === null || fn === void 0 ? void 0 : fn.body.statements.unshift((0, ast_2.makeFnStatement)((0, ast_3.generateFiller)(fillerAst)));
143
- return ast;
144
- },
145
- ],
146
- ], false);
147
- },
148
- produceFiller: function (node, ast) {
149
- return (0, ast_2.makeExpression)('impossible_call()');
150
- },
151
- },
152
- _a[graph_types_1.NodeType.BINARY] = {
153
- produceAst: function (engineContext, engine, graph, iNode, inputEdges) {
154
- var node = iNode;
155
- return (0, ast_2.makeExpression)('(' +
156
- (inputEdges.length
157
- ? inputEdges
158
- .map(function (_, index) { return exports.alphabet.charAt(index); })
159
- .join(" ".concat(node.operator, " "))
160
- : "a ".concat(node.operator, " b")) +
161
- ')');
162
- },
163
- findInputs: function (engineContext, ast, inputEdges, node, sibling) {
164
- return new Array(Math.max(inputEdges.length + 1, 2))
165
- .fill(0)
166
- .map(function (_, index) {
167
- var letter = exports.alphabet.charAt(index);
168
- return [
169
- (0, base_node_1.nodeInput)(letter, letter, 'filler', undefined, ['data', 'code'], false),
170
- function (fillerAst) {
171
- var foundPath;
172
- var visitors = {
173
- identifier: {
174
- enter: function (path) {
175
- if (path.node.identifier === letter) {
176
- foundPath = path;
177
- }
178
- },
179
- },
180
- };
181
- (0, ast_1.visit)(ast, visitors);
182
- if (!foundPath) {
183
- throw new Error("Im drunk and I think this case is impossible, no \"".concat(letter, "\" found in binary node?"));
184
- }
185
- if (foundPath.parent && foundPath.key) {
186
- // @ts-ignore
187
- foundPath.parent[foundPath.key] = fillerAst;
188
- return ast;
189
- }
190
- else {
191
- return fillerAst;
192
- }
193
- },
194
- ];
195
- });
196
- },
197
- produceFiller: function (node, ast) {
198
- return ast;
199
- },
200
- evaluate: function (node, inputEdges, inputNodes, evaluateNode) {
201
- var operator = node.operator;
202
- return inputNodes.map(evaluateNode).reduce(function (num, next) {
203
- if (operator === '+') {
204
- return num + next;
205
- }
206
- else if (operator === '*') {
207
- return num * next;
208
- }
209
- else if (operator === '-') {
210
- return num - next;
211
- }
212
- else if (operator === '/') {
213
- return num / next;
214
- }
215
- throw new Error("Don't know how to evaluate ".concat(operator, " for node ").concat(node.name, " (").concat(node.id, ")"));
216
- });
217
- },
218
- },
219
- _a);