@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/strategy/hardCode.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyHardCodeStrategy = exports.hardCodeStrategy = void 0;
|
|
4
|
-
var _1 = require(".");
|
|
5
|
-
var hardCodeStrategy = function (inputs) { return ({
|
|
6
|
-
type: _1.StrategyType.HARD_CODE_INPUTS,
|
|
7
|
-
config: { inputs: inputs },
|
|
8
|
-
}); };
|
|
9
|
-
exports.hardCodeStrategy = hardCodeStrategy;
|
|
10
|
-
var applyHardCodeStrategy = function (strategy, ast, graphNode, siblingNode) {
|
|
11
|
-
return strategy.config.inputs.map(function (input) {
|
|
12
|
-
// Broken out into two lines to enforce type checking on the array.
|
|
13
|
-
var ci = [
|
|
14
|
-
input,
|
|
15
|
-
// Fillers have to return AstNode | Program, and filler is type Filler,
|
|
16
|
-
// so this awkward branch is to make types line up. But I don't think
|
|
17
|
-
// this code path would ever get called
|
|
18
|
-
function (filler) {
|
|
19
|
-
if (!filler || Array.isArray(filler)) {
|
|
20
|
-
throw new Error('Cannot use void filler');
|
|
21
|
-
}
|
|
22
|
-
return filler;
|
|
23
|
-
},
|
|
24
|
-
];
|
|
25
|
-
return ci;
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
exports.applyHardCodeStrategy = applyHardCodeStrategy;
|
package/cjs/strategy/index.js
DELETED
|
@@ -1,25 +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("./hardCode"), exports);
|
|
18
|
-
__exportStar(require("./uniform"), exports);
|
|
19
|
-
__exportStar(require("./assignemntTo"), exports);
|
|
20
|
-
__exportStar(require("./inject"), exports);
|
|
21
|
-
__exportStar(require("./declarationOf"), exports);
|
|
22
|
-
__exportStar(require("./texture2D"), exports);
|
|
23
|
-
__exportStar(require("./namedAttribute"), exports);
|
|
24
|
-
__exportStar(require("./variable"), exports);
|
|
25
|
-
__exportStar(require("./strategy"), exports);
|
package/cjs/strategy/inject.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.applyInjectStrategy = exports.injectStrategy = void 0;
|
|
40
|
-
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
41
|
-
var base_node_1 = require("../graph/base-node");
|
|
42
|
-
var _1 = require(".");
|
|
43
|
-
/**
|
|
44
|
-
* Inject source code into an AST, in a find-and-replace style. This only
|
|
45
|
-
* operates on statements right now
|
|
46
|
-
*/
|
|
47
|
-
var injectStrategy = function (config) { return ({
|
|
48
|
-
type: _1.StrategyType.INJECT,
|
|
49
|
-
config: config,
|
|
50
|
-
}); };
|
|
51
|
-
exports.injectStrategy = injectStrategy;
|
|
52
|
-
// Typescript fucked up flat https://stackoverflow.com/a/61420611/743464
|
|
53
|
-
var combineWs = function (a, b) {
|
|
54
|
-
return [a, b].flat(Infinity);
|
|
55
|
-
};
|
|
56
|
-
// Move whitespace from one node to another. Since whitespace is trailing, if a
|
|
57
|
-
// node is injected after a previous node, move the whitespace from the earlier
|
|
58
|
-
// node to the later one. This keeps comments in the same place
|
|
59
|
-
var transferWhitespace = function (to, from) {
|
|
60
|
-
return 'semi' in to && 'semi' in from
|
|
61
|
-
? [
|
|
62
|
-
__assign(__assign({}, to), { semi: __assign(__assign({}, to.semi), { whitespace: from.semi.whitespace }) }),
|
|
63
|
-
__assign(__assign({}, from), { semi: __assign(__assign({}, from.semi), { whitespace: '\n' }) }),
|
|
64
|
-
]
|
|
65
|
-
: 'whitespace' in to && 'semi' in from
|
|
66
|
-
? [
|
|
67
|
-
__assign(__assign({}, to), { whitespace: combineWs(to.whitespace, from.semi.whitespace) }),
|
|
68
|
-
__assign(__assign({}, from), { semi: __assign(__assign({}, from.semi), { whitespace: '\n' }) }),
|
|
69
|
-
]
|
|
70
|
-
: [to, from];
|
|
71
|
-
};
|
|
72
|
-
var applyInjectStrategy = function (strategy, ast, graphNode, siblingNode) {
|
|
73
|
-
var program = ast.program;
|
|
74
|
-
var _a = strategy.config, find = _a.find, count = _a.count, insert = _a.insert;
|
|
75
|
-
// Total hack for now. Search each function body for statements that when
|
|
76
|
-
// generated, match the user's "find" string.
|
|
77
|
-
var matchedStatements = program.reduce(function (matches, statement) {
|
|
78
|
-
var newMatches = [];
|
|
79
|
-
if (statement.type === 'function') {
|
|
80
|
-
var bodyStatements_1 = statement.body.statements;
|
|
81
|
-
newMatches = bodyStatements_1.reduce(function (innerMatches, bodyStmt, index) {
|
|
82
|
-
var generated = (0, glsl_parser_1.generate)(bodyStmt);
|
|
83
|
-
// console.log(`"${generated}"`);
|
|
84
|
-
var triple = [
|
|
85
|
-
bodyStatements_1,
|
|
86
|
-
bodyStmt,
|
|
87
|
-
index,
|
|
88
|
-
];
|
|
89
|
-
return __spreadArray(__spreadArray([], __read(innerMatches), false), __read((generated.includes(find) ? [triple] : [])), false);
|
|
90
|
-
}, []);
|
|
91
|
-
}
|
|
92
|
-
return __spreadArray(__spreadArray([], __read(matches), false), __read(newMatches), false);
|
|
93
|
-
}, []);
|
|
94
|
-
var name = "Inject ".concat(strategy.config.insert);
|
|
95
|
-
return [
|
|
96
|
-
[
|
|
97
|
-
(0, base_node_1.nodeInput)(name, "filler_".concat(name), 'filler', undefined, // Data type for what plugs into this filler
|
|
98
|
-
['code', 'data'], false),
|
|
99
|
-
function (fillerAst) {
|
|
100
|
-
var toInsert = Array.isArray(fillerAst)
|
|
101
|
-
? fillerAst
|
|
102
|
-
: [fillerAst];
|
|
103
|
-
// Loop backwards through the matches because when we inject code into
|
|
104
|
-
// parent nodes, it modifies the statement list arrays
|
|
105
|
-
for (
|
|
106
|
-
// Only go as many count replacements as specified in the config
|
|
107
|
-
var i = Math.min(matchedStatements.length - 1, count); i >= 0; i--) {
|
|
108
|
-
var _a = __read(matchedStatements[i], 3), parent = _a[0], stmt = _a[1], index = _a[2];
|
|
109
|
-
if (insert === 'after') {
|
|
110
|
-
var _b = __read(toInsert), first = _b[0], rest = _b.slice(1);
|
|
111
|
-
var _c = __read(transferWhitespace(first, stmt), 2), newFirst = _c[0], updatedStmt = _c[1];
|
|
112
|
-
var newStatements = __spreadArray([newFirst], __read(rest), false);
|
|
113
|
-
parent.splice.apply(parent, __spreadArray([index, 1, updatedStmt], __read(newStatements), false));
|
|
114
|
-
}
|
|
115
|
-
else if (insert === 'before') {
|
|
116
|
-
parent.splice.apply(parent, __spreadArray([index - 1, 0], __read(toInsert), false));
|
|
117
|
-
}
|
|
118
|
-
else if (insert === 'replace') {
|
|
119
|
-
throw new Error('not yet implemented');
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return ast;
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
];
|
|
126
|
-
};
|
|
127
|
-
exports.applyInjectStrategy = applyInjectStrategy;
|
|
@@ -1,53 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.applyNamedAttributeStrategy = exports.namedAttributeStrategy = void 0;
|
|
20
|
-
var base_node_1 = require("../graph/base-node");
|
|
21
|
-
var _1 = require(".");
|
|
22
|
-
var ast_1 = require("../util/ast");
|
|
23
|
-
var namedAttributeStrategy = function (attributeName) { return ({
|
|
24
|
-
type: _1.StrategyType.NAMED_ATTRIBUTE,
|
|
25
|
-
config: { attributeName: attributeName },
|
|
26
|
-
}); };
|
|
27
|
-
exports.namedAttributeStrategy = namedAttributeStrategy;
|
|
28
|
-
var applyNamedAttributeStrategy = function (strategy, ast, graphNode, siblingNode) {
|
|
29
|
-
var program = ast;
|
|
30
|
-
var attributeName = strategy.config.attributeName;
|
|
31
|
-
return [
|
|
32
|
-
[
|
|
33
|
-
(0, base_node_1.nodeInput)(attributeName, "filler_".concat(attributeName), 'filler', undefined, // Data type for what plugs into this filler
|
|
34
|
-
['code', 'data'], true),
|
|
35
|
-
function (fillerAst) {
|
|
36
|
-
Object.entries(program.scopes[0].bindings).forEach(function (_a) {
|
|
37
|
-
var _b = __read(_a, 2), name = _b[0], binding = _b[1];
|
|
38
|
-
binding.references.forEach(function (ref) {
|
|
39
|
-
// Rename the variable usage only if it's not the identifier, to
|
|
40
|
-
// avoid filling in `in vec3 replaceMe;` with `replacer()`
|
|
41
|
-
if (ref.type === 'identifier' &&
|
|
42
|
-
ref !== binding.declaration &&
|
|
43
|
-
ref.identifier === attributeName) {
|
|
44
|
-
ref.identifier = (0, ast_1.generateFiller)(fillerAst);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
return ast;
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
];
|
|
52
|
-
};
|
|
53
|
-
exports.applyNamedAttributeStrategy = applyNamedAttributeStrategy;
|
package/cjs/strategy/strategy.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.applyStrategy = exports.StrategyType = void 0;
|
|
5
|
-
var hardCode_1 = require("./hardCode");
|
|
6
|
-
var uniform_1 = require("./uniform");
|
|
7
|
-
var assignemntTo_1 = require("./assignemntTo");
|
|
8
|
-
var declarationOf_1 = require("./declarationOf");
|
|
9
|
-
var texture2D_1 = require("./texture2D");
|
|
10
|
-
var namedAttribute_1 = require("./namedAttribute");
|
|
11
|
-
var variable_1 = require("./variable");
|
|
12
|
-
var inject_1 = require("./inject");
|
|
13
|
-
var StrategyType;
|
|
14
|
-
(function (StrategyType) {
|
|
15
|
-
StrategyType["VARIABLE"] = "Variable Names";
|
|
16
|
-
StrategyType["ASSIGNMENT_TO"] = "Assignment To";
|
|
17
|
-
StrategyType["DECLARATION_OF"] = "Variable Declaration";
|
|
18
|
-
StrategyType["TEXTURE_2D"] = "Texture2D";
|
|
19
|
-
StrategyType["NAMED_ATTRIBUTE"] = "Named Attribute";
|
|
20
|
-
StrategyType["UNIFORM"] = "Uniform";
|
|
21
|
-
StrategyType["INJECT"] = "Inject";
|
|
22
|
-
StrategyType["HARD_CODE_INPUTS"] = "Hard Code Inputs";
|
|
23
|
-
})(StrategyType = exports.StrategyType || (exports.StrategyType = {}));
|
|
24
|
-
var strategyRunners = (_a = {},
|
|
25
|
-
_a[StrategyType.INJECT] = inject_1.applyInjectStrategy,
|
|
26
|
-
_a[StrategyType.HARD_CODE_INPUTS] = hardCode_1.applyHardCodeStrategy,
|
|
27
|
-
_a[StrategyType.UNIFORM] = uniform_1.applyUniformStrategy,
|
|
28
|
-
_a[StrategyType.ASSIGNMENT_TO] = assignemntTo_1.applyAssignmentToStrategy,
|
|
29
|
-
_a[StrategyType.DECLARATION_OF] = declarationOf_1.constApplyDeclarationOf,
|
|
30
|
-
_a[StrategyType.TEXTURE_2D] = texture2D_1.applyTexture2DStrategy,
|
|
31
|
-
_a[StrategyType.NAMED_ATTRIBUTE] = namedAttribute_1.applyNamedAttributeStrategy,
|
|
32
|
-
_a[StrategyType.VARIABLE] = variable_1.applyVariableStrategy,
|
|
33
|
-
_a);
|
|
34
|
-
var applyStrategy = function (strategy, ast, node, sibling) { return strategyRunners[strategy.type](strategy, ast, node, sibling); };
|
|
35
|
-
exports.applyStrategy = applyStrategy;
|
|
@@ -1,192 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
-
if (!m) return o;
|
|
28
|
-
var i = m.call(o), r, ar = [], e;
|
|
29
|
-
try {
|
|
30
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
-
}
|
|
32
|
-
catch (error) { e = { error: error }; }
|
|
33
|
-
finally {
|
|
34
|
-
try {
|
|
35
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
-
}
|
|
37
|
-
finally { if (e) throw e.error; }
|
|
38
|
-
}
|
|
39
|
-
return ar;
|
|
40
|
-
};
|
|
41
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
46
|
-
var glsl_parser_2 = require("@shaderfrog/glsl-parser");
|
|
47
|
-
var _1 = require(".");
|
|
48
|
-
var graphModule = __importStar(require("../graph/graph"));
|
|
49
|
-
var ast_1 = require("../util/ast");
|
|
50
|
-
var preprocessor_1 = __importDefault(require("@shaderfrog/glsl-parser/preprocessor"));
|
|
51
|
-
var orig;
|
|
52
|
-
beforeEach(function () {
|
|
53
|
-
orig = graphModule.mangleName;
|
|
54
|
-
// Terrible hack. in the real world, strategies are applied after mangling
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
graphModule.mangleName = function (name) { return name; };
|
|
57
|
-
});
|
|
58
|
-
afterEach(function () {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
graphModule.mangleName = orig;
|
|
61
|
-
});
|
|
62
|
-
it('named attribute strategy`', function () {
|
|
63
|
-
var source = "\nin vec3 replaceThisAtrribute;\nvoid main() {\n vec2 y = replaceThisAtrribute;\n}\n";
|
|
64
|
-
var ast = glsl_parser_1.parser.parse(source, { quiet: true });
|
|
65
|
-
var fillers = (0, _1.applyStrategy)({
|
|
66
|
-
type: _1.StrategyType.NAMED_ATTRIBUTE,
|
|
67
|
-
config: {
|
|
68
|
-
attributeName: 'replaceThisAtrribute',
|
|
69
|
-
},
|
|
70
|
-
}, ast, { source: source }, {});
|
|
71
|
-
expect(fillers.length).toBe(1);
|
|
72
|
-
fillers[0][1]({
|
|
73
|
-
type: 'literal',
|
|
74
|
-
literal: "myFiller()",
|
|
75
|
-
whitespace: '',
|
|
76
|
-
});
|
|
77
|
-
var result = (0, glsl_parser_2.generate)(ast);
|
|
78
|
-
// Should replace the use of the filler, but not the declaration
|
|
79
|
-
expect(result).toBe("\nin vec3 replaceThisAtrribute;\nvoid main() {\n vec2 y = myFiller();\n}\n");
|
|
80
|
-
});
|
|
81
|
-
it('inject strategy after', function () {
|
|
82
|
-
var source = "\nuniform float x;\n// Some comment\nvoid main() {\n/* some comment */\nre(x, y, z);\n// Middle comment\nre(x, y, z);\n// Final comment\n}";
|
|
83
|
-
var ast = glsl_parser_1.parser.parse(source, { quiet: true });
|
|
84
|
-
var fillers = (0, _1.applyStrategy)({
|
|
85
|
-
type: _1.StrategyType.INJECT,
|
|
86
|
-
config: {
|
|
87
|
-
find: 're(x, y, z);',
|
|
88
|
-
insert: 'after',
|
|
89
|
-
count: Infinity,
|
|
90
|
-
},
|
|
91
|
-
}, ast, { source: source }, {});
|
|
92
|
-
expect(fillers.length).toBe(1);
|
|
93
|
-
fillers[0][1]({
|
|
94
|
-
type: 'literal',
|
|
95
|
-
literal: "someOtherCall(x, y, z);\nsomeOtherCall(x, y, z);",
|
|
96
|
-
whitespace: '',
|
|
97
|
-
});
|
|
98
|
-
var result = (0, glsl_parser_2.generate)(ast);
|
|
99
|
-
// Should fill references
|
|
100
|
-
expect(result).toBe("\nuniform float x;\n// Some comment\nvoid main() {\n/* some comment */\nre(x, y, z);\nsomeOtherCall(x, y, z);\nsomeOtherCall(x, y, z);\n// Middle comment\nre(x, y, z);\nsomeOtherCall(x, y, z);\nsomeOtherCall(x, y, z);\n// Final comment\n}");
|
|
101
|
-
});
|
|
102
|
-
it('inject strategy before', function () {
|
|
103
|
-
var source = "\nuniform float x;\n// Some comment\nvoid main() {\n/* some comment */\nre(x, y, z);\n// Middle comment\nre(x, y, z);\n// Final comment\n}";
|
|
104
|
-
var ast = glsl_parser_1.parser.parse(source, { quiet: true });
|
|
105
|
-
var fillers = (0, _1.applyStrategy)({
|
|
106
|
-
type: _1.StrategyType.INJECT,
|
|
107
|
-
config: {
|
|
108
|
-
find: 're(x, y, z);',
|
|
109
|
-
insert: 'before',
|
|
110
|
-
count: Infinity,
|
|
111
|
-
},
|
|
112
|
-
}, ast, { source: source }, {});
|
|
113
|
-
expect(fillers.length).toBe(1);
|
|
114
|
-
fillers[0][1]({
|
|
115
|
-
type: 'literal',
|
|
116
|
-
literal: "someOtherCall(x, y, z);\nsomeOtherCall(x, y, z);",
|
|
117
|
-
whitespace: '\n',
|
|
118
|
-
});
|
|
119
|
-
var result = (0, glsl_parser_2.generate)(ast);
|
|
120
|
-
// Should fill references
|
|
121
|
-
expect(result).toBe("\nuniform float x;\n// Some comment\nvoid main() {\n/* some comment */\nsomeOtherCall(x, y, z);\nsomeOtherCall(x, y, z);\nre(x, y, z);\n// Middle comment\nsomeOtherCall(x, y, z);\nsomeOtherCall(x, y, z);\nre(x, y, z);\n// Final comment\n}");
|
|
122
|
-
});
|
|
123
|
-
it('correctly fills with uniform strategy', function () {
|
|
124
|
-
var _a, _b, _c;
|
|
125
|
-
var ast = glsl_parser_1.parser.parse("\nlayout(std140,column_major) uniform;\nuniform sampler2D image;\nuniform vec4 input, output, other;\nuniform vec4 zenput;\nuniform Light0 { vec4 y; } x;\nvec3 topLevel = vec3(0.0);\nvoid other(in vec3 param) {}\nvoid main() {\n vec4 computed = texture2D(image, uvPow * 1.0);\n vec4 x = input;\n vec4 y = output;\n vec4 z = zenput;\n}", { quiet: true });
|
|
126
|
-
var fillers = (0, _1.applyStrategy)({ type: _1.StrategyType.UNIFORM, config: {} }, ast, {}, {});
|
|
127
|
-
// It should find uniforms with simple types, excluding sampler2D
|
|
128
|
-
expect(fillers.map(function (_a) {
|
|
129
|
-
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
130
|
-
return name;
|
|
131
|
-
})).toEqual([
|
|
132
|
-
'image',
|
|
133
|
-
'input',
|
|
134
|
-
'output',
|
|
135
|
-
'other',
|
|
136
|
-
'zenput',
|
|
137
|
-
]);
|
|
138
|
-
(_a = fillers.find(function (_a) {
|
|
139
|
-
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
140
|
-
return name === 'input';
|
|
141
|
-
})) === null || _a === void 0 ? void 0 : _a[1]((0, ast_1.makeExpression)('a'));
|
|
142
|
-
(_b = fillers.find(function (_a) {
|
|
143
|
-
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
144
|
-
return name === 'output';
|
|
145
|
-
})) === null || _b === void 0 ? void 0 : _b[1]((0, ast_1.makeExpression)('b'));
|
|
146
|
-
(_c = fillers.find(function (_a) {
|
|
147
|
-
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
148
|
-
return name === 'zenput';
|
|
149
|
-
})) === null || _c === void 0 ? void 0 : _c[1]((0, ast_1.makeExpression)('c'));
|
|
150
|
-
var result = (0, glsl_parser_2.generate)(ast);
|
|
151
|
-
// Should fill references
|
|
152
|
-
expect(result).toContain('vec4 x = a;');
|
|
153
|
-
expect(result).toContain('vec4 y = b;');
|
|
154
|
-
expect(result).toContain('vec4 z = c;');
|
|
155
|
-
// Should preserve things it shouldn't touch
|
|
156
|
-
expect(result).toContain('layout(std140,column_major) uniform;');
|
|
157
|
-
expect(result).toContain('uniform sampler2D image;');
|
|
158
|
-
expect(result).toContain('uniform Light0 { vec4 y; } x;');
|
|
159
|
-
// Should remove uniforms from declarator list
|
|
160
|
-
expect(result).toContain('uniform vec4 other;');
|
|
161
|
-
// Should remove uniform lines
|
|
162
|
-
expect(result).not.toContain('uniform vec4 zenput');
|
|
163
|
-
});
|
|
164
|
-
it('uses name without suffix for single call', function () {
|
|
165
|
-
var ast = glsl_parser_1.parser.parse("\nvoid main() {\n vec4 computed = texture2D(noiseImage, uvPow * 1.0);\n}", { quiet: true });
|
|
166
|
-
expect((0, _1.applyStrategy)({ type: _1.StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
167
|
-
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
168
|
-
return name;
|
|
169
|
-
})).toEqual(['noiseImage']);
|
|
170
|
-
});
|
|
171
|
-
it('finds multiple texture2D inputs for one uniform', function () {
|
|
172
|
-
var ast = glsl_parser_1.parser.parse("\nvoid main() {\n vec4 computed = texture2D(noiseImage, uvPow * 1.0);\n computed += texture2D(noiseImage, uvPow * 2.0);\n}", { quiet: true });
|
|
173
|
-
expect((0, _1.applyStrategy)({ type: _1.StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
174
|
-
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
175
|
-
return name;
|
|
176
|
-
})).toEqual(['noiseImage_0', 'noiseImage_1']);
|
|
177
|
-
});
|
|
178
|
-
it('Make sure texture2D finds preprocessed texture() call', function () {
|
|
179
|
-
// I thought this was a regression, but it wasn't a real bug, but tests seems
|
|
180
|
-
// benign to keep anyway
|
|
181
|
-
var program = "\n#define texture2DBias texture\n\nuniform sampler2D normalMap;\n\nvoid getNormal() {\n vec3 normalMap = unpackNormal(texture2DBias(normalMap, vUv0, textureBias));\n}";
|
|
182
|
-
var pp = (0, preprocessor_1.default)(program, {
|
|
183
|
-
preserve: {
|
|
184
|
-
version: function () { return true; },
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
var ast = glsl_parser_1.parser.parse(pp, { quiet: true });
|
|
188
|
-
expect((0, _1.applyStrategy)({ type: _1.StrategyType.TEXTURE_2D, config: {} }, ast, {}, {}).map(function (_a) {
|
|
189
|
-
var _b = __read(_a, 1), name = _b[0].displayName;
|
|
190
|
-
return name;
|
|
191
|
-
})).toEqual(['normalMapx']);
|
|
192
|
-
});
|
|
@@ -1,88 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.applyTexture2DStrategy = exports.texture2DStrategy = void 0;
|
|
29
|
-
var glsl_parser_1 = require("@shaderfrog/glsl-parser");
|
|
30
|
-
var ast_1 = require("@shaderfrog/glsl-parser/ast");
|
|
31
|
-
var base_node_1 = require("../graph/base-node");
|
|
32
|
-
var _1 = require(".");
|
|
33
|
-
var texture2DStrategy = function () { return ({
|
|
34
|
-
type: _1.StrategyType.TEXTURE_2D,
|
|
35
|
-
config: {},
|
|
36
|
-
}); };
|
|
37
|
-
exports.texture2DStrategy = texture2DStrategy;
|
|
38
|
-
var applyTexture2DStrategy = function (strategy, ast, graphNode, siblingNode) {
|
|
39
|
-
var texture2Dcalls = [];
|
|
40
|
-
var seen = {};
|
|
41
|
-
var visitors = {
|
|
42
|
-
function_call: {
|
|
43
|
-
enter: function (path) {
|
|
44
|
-
var identifier = path.node.identifier;
|
|
45
|
-
if (
|
|
46
|
-
// TODO: 100 vs 300
|
|
47
|
-
((identifier === null || identifier === void 0 ? void 0 : identifier.identifier) === 'texture2D' ||
|
|
48
|
-
(identifier === null || identifier === void 0 ? void 0 : identifier.identifier) === 'texture') &&
|
|
49
|
-
path.key) {
|
|
50
|
-
if (!path.parent) {
|
|
51
|
-
throw new Error('This error is impossible. A function call always has a parent.');
|
|
52
|
-
}
|
|
53
|
-
var name = (0, glsl_parser_1.generate)(path.node.args[0]);
|
|
54
|
-
seen[name] = (seen[name] || 0) + 1;
|
|
55
|
-
texture2Dcalls.push([
|
|
56
|
-
name,
|
|
57
|
-
path.parent,
|
|
58
|
-
path.key,
|
|
59
|
-
// Remove the first argument and comma
|
|
60
|
-
path.node.args.slice(2),
|
|
61
|
-
]);
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
(0, ast_1.visit)(ast, visitors);
|
|
67
|
-
var names = new Set(Object.entries(seen).reduce(function (arr, _a) {
|
|
68
|
-
var _b = __read(_a, 2), name = _b[0], count = _b[1];
|
|
69
|
-
return __spreadArray(__spreadArray([], __read(arr), false), __read((count > 1 ? [name] : [])), false);
|
|
70
|
-
}, []));
|
|
71
|
-
var inputs = texture2Dcalls.map(function (_a, index) {
|
|
72
|
-
var _b = __read(_a, 4), name = _b[0], parent = _b[1], key = _b[2], texture2dArgs = _b[3];
|
|
73
|
-
// Suffix input name if it's used more than once
|
|
74
|
-
var iName = names.has(name) ? "".concat(name, "_").concat(index) : name;
|
|
75
|
-
return [
|
|
76
|
-
(0, base_node_1.nodeInput)(iName, "filler_".concat(iName), 'filler', 'vector4', // Data type for what plugs into this filler
|
|
77
|
-
['code', 'data'], false),
|
|
78
|
-
function (fillerAst) {
|
|
79
|
-
// @ts-ignore
|
|
80
|
-
parent[key] = fillerAst;
|
|
81
|
-
return ast;
|
|
82
|
-
},
|
|
83
|
-
texture2dArgs,
|
|
84
|
-
];
|
|
85
|
-
});
|
|
86
|
-
return inputs;
|
|
87
|
-
};
|
|
88
|
-
exports.applyTexture2DStrategy = applyTexture2DStrategy;
|