@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.
- package/package.json +10 -7
- package/cjs/engine.js +0 -218
- package/cjs/graph/base-node.js +0 -13
- package/cjs/graph/code-nodes.js +0 -23
- package/cjs/graph/context.js +0 -253
- package/cjs/graph/data-nodes.js +0 -146
- package/cjs/graph/edge.js +0 -12
- package/cjs/graph/evaluate.js +0 -32
- package/cjs/graph/graph-node.js +0 -143
- package/cjs/graph/graph-types.js +0 -25
- package/cjs/graph/graph.js +0 -533
- package/cjs/graph/graph.test.js +0 -173
- package/cjs/graph/index.js +0 -27
- package/cjs/graph/parsers.js +0 -219
- package/cjs/graph/shader-sections.js +0 -268
- package/cjs/index.js +0 -19
- package/cjs/package.json +0 -1
- package/cjs/plugins/babylon/bablyengine.js +0 -597
- package/cjs/plugins/babylon/importers.js +0 -66
- package/cjs/plugins/babylon/index.js +0 -5
- package/cjs/plugins/playcanvas/importers.js +0 -30
- package/cjs/plugins/playcanvas/index.js +0 -5
- package/cjs/plugins/playcanvas/playengine.js +0 -549
- package/cjs/plugins/three/importers.js +0 -17
- package/cjs/plugins/three/index.js +0 -6
- package/cjs/plugins/three/threngine.js +0 -619
- package/cjs/strategy/assignemntTo.js +0 -31
- package/cjs/strategy/declarationOf.js +0 -28
- package/cjs/strategy/hardCode.js +0 -28
- package/cjs/strategy/index.js +0 -25
- package/cjs/strategy/inject.js +0 -127
- package/cjs/strategy/namedAttribute.js +0 -53
- package/cjs/strategy/strategy.js +0 -35
- package/cjs/strategy/stratgies.test.js +0 -192
- package/cjs/strategy/texture2D.js +0 -88
- package/cjs/strategy/uniform.js +0 -195
- package/cjs/strategy/variable.js +0 -85
- package/cjs/util/ast.js +0 -351
- package/cjs/util/ensure.js +0 -11
- package/cjs/util/id.js +0 -6
- package/esm/engine.d.ts +0 -69
- package/esm/graph/base-node.d.ts +0 -36
- package/esm/graph/code-nodes.d.ts +0 -44
- package/esm/graph/context.d.ts +0 -37
- package/esm/graph/data-nodes.d.ts +0 -83
- package/esm/graph/edge.d.ts +0 -13
- package/esm/graph/evaluate.d.ts +0 -9
- package/esm/graph/graph-node.d.ts +0 -8
- package/esm/graph/graph-types.d.ts +0 -38
- package/esm/graph/graph.d.ts +0 -89
- package/esm/graph/graph.test.d.ts +0 -1
- package/esm/graph/index.d.ts +0 -11
- package/esm/graph/parsers.d.ts +0 -39
- package/esm/graph/shader-sections.d.ts +0 -47
- package/esm/index.d.ts +0 -3
- package/esm/package.json +0 -1
- package/esm/plugins/babylon/bablyengine.d.ts +0 -28
- package/esm/plugins/babylon/importers.d.ts +0 -3
- package/esm/plugins/babylon/index.d.ts +0 -2
- package/esm/plugins/playcanvas/importers.d.ts +0 -3
- package/esm/plugins/playcanvas/index.d.ts +0 -2
- package/esm/plugins/playcanvas/playengine.d.ts +0 -39
- package/esm/plugins/three/importers.d.ts +0 -3
- package/esm/plugins/three/index.d.ts +0 -2
- package/esm/plugins/three/threngine.d.ts +0 -34
- package/esm/strategy/assignemntTo.d.ts +0 -9
- package/esm/strategy/declarationOf.d.ts +0 -9
- package/esm/strategy/hardCode.d.ts +0 -15
- package/esm/strategy/index.d.ts +0 -9
- package/esm/strategy/inject.d.ts +0 -15
- package/esm/strategy/namedAttribute.d.ts +0 -9
- package/esm/strategy/strategy.d.ts +0 -28
- package/esm/strategy/stratgies.test.d.ts +0 -1
- package/esm/strategy/texture2D.d.ts +0 -6
- package/esm/strategy/uniform.d.ts +0 -6
- package/esm/strategy/variable.d.ts +0 -6
- package/esm/util/ast.d.ts +0 -30
- package/esm/util/ensure.d.ts +0 -1
- package/esm/util/id.d.ts +0 -1
- /package/{cjs/engine.d.ts → engine.d.ts} +0 -0
- /package/{esm/engine.js → engine.js} +0 -0
- /package/{cjs/graph → graph}/base-node.d.ts +0 -0
- /package/{esm/graph → graph}/base-node.js +0 -0
- /package/{cjs/graph → graph}/code-nodes.d.ts +0 -0
- /package/{esm/graph → graph}/code-nodes.js +0 -0
- /package/{cjs/graph → graph}/context.d.ts +0 -0
- /package/{esm/graph → graph}/context.js +0 -0
- /package/{cjs/graph → graph}/data-nodes.d.ts +0 -0
- /package/{esm/graph → graph}/data-nodes.js +0 -0
- /package/{cjs/graph → graph}/edge.d.ts +0 -0
- /package/{esm/graph → graph}/edge.js +0 -0
- /package/{cjs/graph → graph}/evaluate.d.ts +0 -0
- /package/{esm/graph → graph}/evaluate.js +0 -0
- /package/{cjs/graph → graph}/graph-node.d.ts +0 -0
- /package/{esm/graph → graph}/graph-node.js +0 -0
- /package/{cjs/graph → graph}/graph-types.d.ts +0 -0
- /package/{esm/graph → graph}/graph-types.js +0 -0
- /package/{cjs/graph → graph}/graph.d.ts +0 -0
- /package/{esm/graph → graph}/graph.js +0 -0
- /package/{cjs/graph → graph}/graph.test.d.ts +0 -0
- /package/{esm/graph → graph}/graph.test.js +0 -0
- /package/{cjs/graph → graph}/index.d.ts +0 -0
- /package/{esm/graph → graph}/index.js +0 -0
- /package/{cjs/graph → graph}/parsers.d.ts +0 -0
- /package/{esm/graph → graph}/parsers.js +0 -0
- /package/{cjs/graph → graph}/shader-sections.d.ts +0 -0
- /package/{esm/graph → graph}/shader-sections.js +0 -0
- /package/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{cjs/plugins → plugins}/babylon/bablyengine.d.ts +0 -0
- /package/{esm/plugins → plugins}/babylon/bablyengine.js +0 -0
- /package/{cjs/plugins → plugins}/babylon/importers.d.ts +0 -0
- /package/{esm/plugins → plugins}/babylon/importers.js +0 -0
- /package/{cjs/plugins → plugins}/babylon/index.d.ts +0 -0
- /package/{esm/plugins → plugins}/babylon/index.js +0 -0
- /package/{cjs/plugins → plugins}/playcanvas/importers.d.ts +0 -0
- /package/{esm/plugins → plugins}/playcanvas/importers.js +0 -0
- /package/{cjs/plugins → plugins}/playcanvas/index.d.ts +0 -0
- /package/{esm/plugins → plugins}/playcanvas/index.js +0 -0
- /package/{cjs/plugins → plugins}/playcanvas/playengine.d.ts +0 -0
- /package/{esm/plugins → plugins}/playcanvas/playengine.js +0 -0
- /package/{cjs/plugins → plugins}/three/importers.d.ts +0 -0
- /package/{esm/plugins → plugins}/three/importers.js +0 -0
- /package/{cjs/plugins → plugins}/three/index.d.ts +0 -0
- /package/{esm/plugins → plugins}/three/index.js +0 -0
- /package/{cjs/plugins → plugins}/three/threngine.d.ts +0 -0
- /package/{esm/plugins → plugins}/three/threngine.js +0 -0
- /package/{cjs/strategy → strategy}/assignemntTo.d.ts +0 -0
- /package/{esm/strategy → strategy}/assignemntTo.js +0 -0
- /package/{cjs/strategy → strategy}/declarationOf.d.ts +0 -0
- /package/{esm/strategy → strategy}/declarationOf.js +0 -0
- /package/{cjs/strategy → strategy}/hardCode.d.ts +0 -0
- /package/{esm/strategy → strategy}/hardCode.js +0 -0
- /package/{cjs/strategy → strategy}/index.d.ts +0 -0
- /package/{esm/strategy → strategy}/index.js +0 -0
- /package/{cjs/strategy → strategy}/inject.d.ts +0 -0
- /package/{esm/strategy → strategy}/inject.js +0 -0
- /package/{cjs/strategy → strategy}/namedAttribute.d.ts +0 -0
- /package/{esm/strategy → strategy}/namedAttribute.js +0 -0
- /package/{cjs/strategy → strategy}/strategy.d.ts +0 -0
- /package/{esm/strategy → strategy}/strategy.js +0 -0
- /package/{cjs/strategy → strategy}/stratgies.test.d.ts +0 -0
- /package/{esm/strategy → strategy}/stratgies.test.js +0 -0
- /package/{cjs/strategy → strategy}/texture2D.d.ts +0 -0
- /package/{esm/strategy → strategy}/texture2D.js +0 -0
- /package/{cjs/strategy → strategy}/uniform.d.ts +0 -0
- /package/{esm/strategy → strategy}/uniform.js +0 -0
- /package/{cjs/strategy → strategy}/variable.d.ts +0 -0
- /package/{esm/strategy → strategy}/variable.js +0 -0
- /package/{cjs/util → util}/ast.d.ts +0 -0
- /package/{esm/util → util}/ast.js +0 -0
- /package/{cjs/util → util}/ensure.d.ts +0 -0
- /package/{esm/util → util}/ensure.js +0 -0
- /package/{cjs/util → util}/id.d.ts +0 -0
- /package/{esm/util → util}/id.js +0 -0
package/cjs/graph/graph.test.js
DELETED
|
@@ -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
|
-
});
|
package/cjs/graph/index.js
DELETED
|
@@ -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);
|
package/cjs/graph/parsers.js
DELETED
|
@@ -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);
|