@luma.gl/engine 9.0.14 → 9.0.16
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/dist/dist.dev.js +1040 -277
- package/dist/dist.min.js +25 -25
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +2 -2
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +1 -0
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +5 -6
- package/package.json +3 -3
- package/src/model/model.ts +1 -0
- package/src/shader-inputs.ts +6 -7
package/dist/dist.dev.js
CHANGED
|
@@ -273,8 +273,6 @@ var __exports__ = (() => {
|
|
|
273
273
|
// ../../node_modules/@probe.gl/stats/dist/lib/stat.js
|
|
274
274
|
var Stat = class {
|
|
275
275
|
constructor(name, type) {
|
|
276
|
-
this.name = void 0;
|
|
277
|
-
this.type = void 0;
|
|
278
276
|
this.sampleSize = 1;
|
|
279
277
|
this.time = 0;
|
|
280
278
|
this.count = 0;
|
|
@@ -309,26 +307,31 @@ var __exports__ = (() => {
|
|
|
309
307
|
this.sampleSize = samples;
|
|
310
308
|
return this;
|
|
311
309
|
}
|
|
310
|
+
/** Call to increment count (+1) */
|
|
312
311
|
incrementCount() {
|
|
313
312
|
this.addCount(1);
|
|
314
313
|
return this;
|
|
315
314
|
}
|
|
315
|
+
/** Call to decrement count (-1) */
|
|
316
316
|
decrementCount() {
|
|
317
317
|
this.subtractCount(1);
|
|
318
318
|
return this;
|
|
319
319
|
}
|
|
320
|
+
/** Increase count */
|
|
320
321
|
addCount(value) {
|
|
321
322
|
this._count += value;
|
|
322
323
|
this._samples++;
|
|
323
324
|
this._checkSampling();
|
|
324
325
|
return this;
|
|
325
326
|
}
|
|
327
|
+
/** Decrease count */
|
|
326
328
|
subtractCount(value) {
|
|
327
329
|
this._count -= value;
|
|
328
330
|
this._samples++;
|
|
329
331
|
this._checkSampling();
|
|
330
332
|
return this;
|
|
331
333
|
}
|
|
334
|
+
/** Add an arbitrary timing and bump the count */
|
|
332
335
|
addTime(time) {
|
|
333
336
|
this._time += time;
|
|
334
337
|
this.lastTiming = time;
|
|
@@ -336,11 +339,13 @@ var __exports__ = (() => {
|
|
|
336
339
|
this._checkSampling();
|
|
337
340
|
return this;
|
|
338
341
|
}
|
|
342
|
+
/** Start a timer */
|
|
339
343
|
timeStart() {
|
|
340
344
|
this._startTime = getHiResTimestamp();
|
|
341
345
|
this._timerPending = true;
|
|
342
346
|
return this;
|
|
343
347
|
}
|
|
348
|
+
/** End a timer. Adds to time and bumps the timing count. */
|
|
344
349
|
timeEnd() {
|
|
345
350
|
if (!this._timerPending) {
|
|
346
351
|
return this;
|
|
@@ -353,18 +358,22 @@ var __exports__ = (() => {
|
|
|
353
358
|
getSampleAverageCount() {
|
|
354
359
|
return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
|
|
355
360
|
}
|
|
361
|
+
/** Calculate average time / count for the previous window */
|
|
356
362
|
getSampleAverageTime() {
|
|
357
363
|
return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
|
|
358
364
|
}
|
|
365
|
+
/** Calculate counts per second for the previous window */
|
|
359
366
|
getSampleHz() {
|
|
360
367
|
return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
|
|
361
368
|
}
|
|
362
369
|
getAverageCount() {
|
|
363
370
|
return this.samples > 0 ? this.count / this.samples : 0;
|
|
364
371
|
}
|
|
372
|
+
/** Calculate average time / count */
|
|
365
373
|
getAverageTime() {
|
|
366
374
|
return this.samples > 0 ? this.time / this.samples : 0;
|
|
367
375
|
}
|
|
376
|
+
/** Calculate counts per second */
|
|
368
377
|
getHz() {
|
|
369
378
|
return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
|
|
370
379
|
}
|
|
@@ -385,23 +394,20 @@ var __exports__ = (() => {
|
|
|
385
394
|
// ../../node_modules/@probe.gl/stats/dist/lib/stats.js
|
|
386
395
|
var Stats = class {
|
|
387
396
|
constructor(options) {
|
|
388
|
-
this.id = void 0;
|
|
389
397
|
this.stats = {};
|
|
390
398
|
this.id = options.id;
|
|
391
399
|
this.stats = {};
|
|
392
400
|
this._initializeStats(options.stats);
|
|
393
401
|
Object.seal(this);
|
|
394
402
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return this._getOrCreate({
|
|
398
|
-
name,
|
|
399
|
-
type
|
|
400
|
-
});
|
|
403
|
+
/** Acquire a stat. Create if it doesn't exist. */
|
|
404
|
+
get(name, type = "count") {
|
|
405
|
+
return this._getOrCreate({ name, type });
|
|
401
406
|
}
|
|
402
407
|
get size() {
|
|
403
408
|
return Object.keys(this.stats).length;
|
|
404
409
|
}
|
|
410
|
+
/** Reset all stats */
|
|
405
411
|
reset() {
|
|
406
412
|
for (const stat of Object.values(this.stats)) {
|
|
407
413
|
stat.reset();
|
|
@@ -425,15 +431,11 @@ var __exports__ = (() => {
|
|
|
425
431
|
});
|
|
426
432
|
return table;
|
|
427
433
|
}
|
|
428
|
-
_initializeStats() {
|
|
429
|
-
let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
434
|
+
_initializeStats(stats = []) {
|
|
430
435
|
stats.forEach((stat) => this._getOrCreate(stat));
|
|
431
436
|
}
|
|
432
437
|
_getOrCreate(stat) {
|
|
433
|
-
const {
|
|
434
|
-
name,
|
|
435
|
-
type
|
|
436
|
-
} = stat;
|
|
438
|
+
const { name, type } = stat;
|
|
437
439
|
let result = this.stats[name];
|
|
438
440
|
if (!result) {
|
|
439
441
|
if (stat instanceof Stat) {
|
|
@@ -1831,7 +1833,7 @@ void main() {
|
|
|
1831
1833
|
// ../shadertools/src/lib/wgsl/get-shader-layout-wgsl.ts
|
|
1832
1834
|
var import_core4 = __toESM(require_core(), 1);
|
|
1833
1835
|
|
|
1834
|
-
//
|
|
1836
|
+
// ../../node_modules/wgsl_reflect/wgsl_reflect.module.js
|
|
1835
1837
|
var ParseContext = class {
|
|
1836
1838
|
constructor() {
|
|
1837
1839
|
this.constants = /* @__PURE__ */ new Map();
|
|
@@ -1854,23 +1856,50 @@ void main() {
|
|
|
1854
1856
|
evaluateString(context) {
|
|
1855
1857
|
return this.evaluate(context).toString();
|
|
1856
1858
|
}
|
|
1859
|
+
search(callback) {
|
|
1860
|
+
}
|
|
1861
|
+
searchBlock(block, callback) {
|
|
1862
|
+
if (block) {
|
|
1863
|
+
callback(_BlockStart.instance);
|
|
1864
|
+
for (const node of block) {
|
|
1865
|
+
if (node instanceof Array) {
|
|
1866
|
+
this.searchBlock(node, callback);
|
|
1867
|
+
} else {
|
|
1868
|
+
node.search(callback);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
callback(_BlockEnd.instance);
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1857
1874
|
};
|
|
1875
|
+
var _BlockStart = class extends Node {
|
|
1876
|
+
};
|
|
1877
|
+
_BlockStart.instance = new _BlockStart();
|
|
1878
|
+
var _BlockEnd = class extends Node {
|
|
1879
|
+
};
|
|
1880
|
+
_BlockEnd.instance = new _BlockEnd();
|
|
1858
1881
|
var Statement = class extends Node {
|
|
1859
1882
|
constructor() {
|
|
1860
1883
|
super();
|
|
1861
1884
|
}
|
|
1862
1885
|
};
|
|
1863
1886
|
var Function = class extends Statement {
|
|
1864
|
-
constructor(name, args, returnType, body) {
|
|
1887
|
+
constructor(name, args, returnType, body, startLine, endLine) {
|
|
1865
1888
|
super();
|
|
1889
|
+
this.calls = /* @__PURE__ */ new Set();
|
|
1866
1890
|
this.name = name;
|
|
1867
1891
|
this.args = args;
|
|
1868
1892
|
this.returnType = returnType;
|
|
1869
1893
|
this.body = body;
|
|
1894
|
+
this.startLine = startLine;
|
|
1895
|
+
this.endLine = endLine;
|
|
1870
1896
|
}
|
|
1871
1897
|
get astNodeType() {
|
|
1872
1898
|
return "function";
|
|
1873
1899
|
}
|
|
1900
|
+
search(callback) {
|
|
1901
|
+
this.searchBlock(this.body, callback);
|
|
1902
|
+
}
|
|
1874
1903
|
};
|
|
1875
1904
|
var StaticAssert = class extends Statement {
|
|
1876
1905
|
constructor(expression) {
|
|
@@ -1880,6 +1909,9 @@ void main() {
|
|
|
1880
1909
|
get astNodeType() {
|
|
1881
1910
|
return "staticAssert";
|
|
1882
1911
|
}
|
|
1912
|
+
search(callback) {
|
|
1913
|
+
this.expression.search(callback);
|
|
1914
|
+
}
|
|
1883
1915
|
};
|
|
1884
1916
|
var While = class extends Statement {
|
|
1885
1917
|
constructor(condition, body) {
|
|
@@ -1890,6 +1922,10 @@ void main() {
|
|
|
1890
1922
|
get astNodeType() {
|
|
1891
1923
|
return "while";
|
|
1892
1924
|
}
|
|
1925
|
+
search(callback) {
|
|
1926
|
+
this.condition.search(callback);
|
|
1927
|
+
this.searchBlock(this.body, callback);
|
|
1928
|
+
}
|
|
1893
1929
|
};
|
|
1894
1930
|
var Continuing = class extends Statement {
|
|
1895
1931
|
constructor(body) {
|
|
@@ -1899,6 +1935,9 @@ void main() {
|
|
|
1899
1935
|
get astNodeType() {
|
|
1900
1936
|
return "continuing";
|
|
1901
1937
|
}
|
|
1938
|
+
search(callback) {
|
|
1939
|
+
this.searchBlock(this.body, callback);
|
|
1940
|
+
}
|
|
1902
1941
|
};
|
|
1903
1942
|
var For = class extends Statement {
|
|
1904
1943
|
constructor(init, condition, increment, body) {
|
|
@@ -1911,6 +1950,13 @@ void main() {
|
|
|
1911
1950
|
get astNodeType() {
|
|
1912
1951
|
return "for";
|
|
1913
1952
|
}
|
|
1953
|
+
search(callback) {
|
|
1954
|
+
var _a2, _b, _c;
|
|
1955
|
+
(_a2 = this.init) === null || _a2 === void 0 ? void 0 : _a2.search(callback);
|
|
1956
|
+
(_b = this.condition) === null || _b === void 0 ? void 0 : _b.search(callback);
|
|
1957
|
+
(_c = this.increment) === null || _c === void 0 ? void 0 : _c.search(callback);
|
|
1958
|
+
this.searchBlock(this.body, callback);
|
|
1959
|
+
}
|
|
1914
1960
|
};
|
|
1915
1961
|
var Var = class extends Statement {
|
|
1916
1962
|
constructor(name, type, storage, access, value) {
|
|
@@ -1924,6 +1970,11 @@ void main() {
|
|
|
1924
1970
|
get astNodeType() {
|
|
1925
1971
|
return "var";
|
|
1926
1972
|
}
|
|
1973
|
+
search(callback) {
|
|
1974
|
+
var _a2;
|
|
1975
|
+
callback(this);
|
|
1976
|
+
(_a2 = this.value) === null || _a2 === void 0 ? void 0 : _a2.search(callback);
|
|
1977
|
+
}
|
|
1927
1978
|
};
|
|
1928
1979
|
var Override = class extends Statement {
|
|
1929
1980
|
constructor(name, type, value) {
|
|
@@ -1935,6 +1986,10 @@ void main() {
|
|
|
1935
1986
|
get astNodeType() {
|
|
1936
1987
|
return "override";
|
|
1937
1988
|
}
|
|
1989
|
+
search(callback) {
|
|
1990
|
+
var _a2;
|
|
1991
|
+
(_a2 = this.value) === null || _a2 === void 0 ? void 0 : _a2.search(callback);
|
|
1992
|
+
}
|
|
1938
1993
|
};
|
|
1939
1994
|
var Let = class extends Statement {
|
|
1940
1995
|
constructor(name, type, storage, access, value) {
|
|
@@ -1948,6 +2003,11 @@ void main() {
|
|
|
1948
2003
|
get astNodeType() {
|
|
1949
2004
|
return "let";
|
|
1950
2005
|
}
|
|
2006
|
+
search(callback) {
|
|
2007
|
+
var _a2;
|
|
2008
|
+
callback(this);
|
|
2009
|
+
(_a2 = this.value) === null || _a2 === void 0 ? void 0 : _a2.search(callback);
|
|
2010
|
+
}
|
|
1951
2011
|
};
|
|
1952
2012
|
var Const = class extends Statement {
|
|
1953
2013
|
constructor(name, type, storage, access, value) {
|
|
@@ -1964,6 +2024,11 @@ void main() {
|
|
|
1964
2024
|
evaluate(context) {
|
|
1965
2025
|
return this.value.evaluate(context);
|
|
1966
2026
|
}
|
|
2027
|
+
search(callback) {
|
|
2028
|
+
var _a2;
|
|
2029
|
+
callback(this);
|
|
2030
|
+
(_a2 = this.value) === null || _a2 === void 0 ? void 0 : _a2.search(callback);
|
|
2031
|
+
}
|
|
1967
2032
|
};
|
|
1968
2033
|
var IncrementOperator;
|
|
1969
2034
|
(function(IncrementOperator2) {
|
|
@@ -1988,6 +2053,9 @@ void main() {
|
|
|
1988
2053
|
get astNodeType() {
|
|
1989
2054
|
return "increment";
|
|
1990
2055
|
}
|
|
2056
|
+
search(callback) {
|
|
2057
|
+
this.variable.search(callback);
|
|
2058
|
+
}
|
|
1991
2059
|
};
|
|
1992
2060
|
var AssignOperator;
|
|
1993
2061
|
(function(AssignOperator2) {
|
|
@@ -2006,9 +2074,10 @@ void main() {
|
|
|
2006
2074
|
(function(AssignOperator2) {
|
|
2007
2075
|
function parse(val) {
|
|
2008
2076
|
const key = val;
|
|
2009
|
-
if (key == "parse")
|
|
2077
|
+
if (key == "parse") {
|
|
2010
2078
|
throw new Error("Invalid value for AssignOperator");
|
|
2011
|
-
|
|
2079
|
+
}
|
|
2080
|
+
return key;
|
|
2012
2081
|
}
|
|
2013
2082
|
AssignOperator2.parse = parse;
|
|
2014
2083
|
})(AssignOperator || (AssignOperator = {}));
|
|
@@ -2022,6 +2091,10 @@ void main() {
|
|
|
2022
2091
|
get astNodeType() {
|
|
2023
2092
|
return "assign";
|
|
2024
2093
|
}
|
|
2094
|
+
search(callback) {
|
|
2095
|
+
this.variable.search(callback);
|
|
2096
|
+
this.value.search(callback);
|
|
2097
|
+
}
|
|
2025
2098
|
};
|
|
2026
2099
|
var Call = class extends Statement {
|
|
2027
2100
|
constructor(name, args) {
|
|
@@ -2032,6 +2105,12 @@ void main() {
|
|
|
2032
2105
|
get astNodeType() {
|
|
2033
2106
|
return "call";
|
|
2034
2107
|
}
|
|
2108
|
+
search(callback) {
|
|
2109
|
+
for (const node of this.args) {
|
|
2110
|
+
node.search(callback);
|
|
2111
|
+
}
|
|
2112
|
+
callback(this);
|
|
2113
|
+
}
|
|
2035
2114
|
};
|
|
2036
2115
|
var Loop = class extends Statement {
|
|
2037
2116
|
constructor(body, continuing) {
|
|
@@ -2064,6 +2143,12 @@ void main() {
|
|
|
2064
2143
|
get astNodeType() {
|
|
2065
2144
|
return "if";
|
|
2066
2145
|
}
|
|
2146
|
+
search(callback) {
|
|
2147
|
+
this.condition.search(callback);
|
|
2148
|
+
this.searchBlock(this.body, callback);
|
|
2149
|
+
this.searchBlock(this.elseif, callback);
|
|
2150
|
+
this.searchBlock(this.else, callback);
|
|
2151
|
+
}
|
|
2067
2152
|
};
|
|
2068
2153
|
var Return = class extends Statement {
|
|
2069
2154
|
constructor(value) {
|
|
@@ -2073,6 +2158,10 @@ void main() {
|
|
|
2073
2158
|
get astNodeType() {
|
|
2074
2159
|
return "return";
|
|
2075
2160
|
}
|
|
2161
|
+
search(callback) {
|
|
2162
|
+
var _a2;
|
|
2163
|
+
(_a2 = this.value) === null || _a2 === void 0 ? void 0 : _a2.search(callback);
|
|
2164
|
+
}
|
|
2076
2165
|
};
|
|
2077
2166
|
var Enable = class extends Statement {
|
|
2078
2167
|
constructor(name) {
|
|
@@ -2083,6 +2172,25 @@ void main() {
|
|
|
2083
2172
|
return "enable";
|
|
2084
2173
|
}
|
|
2085
2174
|
};
|
|
2175
|
+
var Requires = class extends Statement {
|
|
2176
|
+
constructor(extensions) {
|
|
2177
|
+
super();
|
|
2178
|
+
this.extensions = extensions;
|
|
2179
|
+
}
|
|
2180
|
+
get astNodeType() {
|
|
2181
|
+
return "requires";
|
|
2182
|
+
}
|
|
2183
|
+
};
|
|
2184
|
+
var Diagnostic = class extends Statement {
|
|
2185
|
+
constructor(severity, rule) {
|
|
2186
|
+
super();
|
|
2187
|
+
this.severity = severity;
|
|
2188
|
+
this.rule = rule;
|
|
2189
|
+
}
|
|
2190
|
+
get astNodeType() {
|
|
2191
|
+
return "diagnostic";
|
|
2192
|
+
}
|
|
2193
|
+
};
|
|
2086
2194
|
var Alias = class extends Statement {
|
|
2087
2195
|
constructor(name, type) {
|
|
2088
2196
|
super();
|
|
@@ -2133,9 +2241,11 @@ void main() {
|
|
|
2133
2241
|
}
|
|
2134
2242
|
};
|
|
2135
2243
|
var Struct = class extends Type {
|
|
2136
|
-
constructor(name, members) {
|
|
2244
|
+
constructor(name, members, startLine, endLine) {
|
|
2137
2245
|
super(name);
|
|
2138
2246
|
this.members = members;
|
|
2247
|
+
this.startLine = startLine;
|
|
2248
|
+
this.endLine = endLine;
|
|
2139
2249
|
}
|
|
2140
2250
|
get astNodeType() {
|
|
2141
2251
|
return "struct";
|
|
@@ -2226,6 +2336,12 @@ void main() {
|
|
|
2226
2336
|
get astNodeType() {
|
|
2227
2337
|
return "createExpr";
|
|
2228
2338
|
}
|
|
2339
|
+
search(callback) {
|
|
2340
|
+
callback(this);
|
|
2341
|
+
for (const node of this.args) {
|
|
2342
|
+
node.search(callback);
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2229
2345
|
};
|
|
2230
2346
|
var CallExpr = class extends Expression {
|
|
2231
2347
|
constructor(name, args) {
|
|
@@ -2319,6 +2435,12 @@ void main() {
|
|
|
2319
2435
|
throw new Error("Non const function: " + this.name);
|
|
2320
2436
|
}
|
|
2321
2437
|
}
|
|
2438
|
+
search(callback) {
|
|
2439
|
+
for (const node of this.args) {
|
|
2440
|
+
node.search(callback);
|
|
2441
|
+
}
|
|
2442
|
+
callback(this);
|
|
2443
|
+
}
|
|
2322
2444
|
};
|
|
2323
2445
|
var VariableExpr = class extends Expression {
|
|
2324
2446
|
constructor(name) {
|
|
@@ -2328,6 +2450,19 @@ void main() {
|
|
|
2328
2450
|
get astNodeType() {
|
|
2329
2451
|
return "varExpr";
|
|
2330
2452
|
}
|
|
2453
|
+
search(callback) {
|
|
2454
|
+
callback(this);
|
|
2455
|
+
if (this.postfix) {
|
|
2456
|
+
this.postfix.search(callback);
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
evaluate(context) {
|
|
2460
|
+
const constant = context.constants.get(this.name);
|
|
2461
|
+
if (!constant) {
|
|
2462
|
+
throw new Error("Cannot evaluate node");
|
|
2463
|
+
}
|
|
2464
|
+
return constant.evaluate(context);
|
|
2465
|
+
}
|
|
2331
2466
|
};
|
|
2332
2467
|
var ConstExpr = class extends Expression {
|
|
2333
2468
|
constructor(name, initializer) {
|
|
@@ -2353,6 +2488,9 @@ void main() {
|
|
|
2353
2488
|
}
|
|
2354
2489
|
return this.initializer.evaluate(context);
|
|
2355
2490
|
}
|
|
2491
|
+
search(callback) {
|
|
2492
|
+
this.initializer.search(callback);
|
|
2493
|
+
}
|
|
2356
2494
|
};
|
|
2357
2495
|
var LiteralExpr = class extends Expression {
|
|
2358
2496
|
constructor(value) {
|
|
@@ -2375,6 +2513,9 @@ void main() {
|
|
|
2375
2513
|
get astNodeType() {
|
|
2376
2514
|
return "bitcastExpr";
|
|
2377
2515
|
}
|
|
2516
|
+
search(callback) {
|
|
2517
|
+
this.value.search(callback);
|
|
2518
|
+
}
|
|
2378
2519
|
};
|
|
2379
2520
|
var TypecastExpr = class extends Expression {
|
|
2380
2521
|
constructor(type, args) {
|
|
@@ -2388,6 +2529,9 @@ void main() {
|
|
|
2388
2529
|
evaluate(context) {
|
|
2389
2530
|
return this.args[0].evaluate(context);
|
|
2390
2531
|
}
|
|
2532
|
+
search(callback) {
|
|
2533
|
+
this.searchBlock(this.args, callback);
|
|
2534
|
+
}
|
|
2391
2535
|
};
|
|
2392
2536
|
var GroupingExpr = class extends Expression {
|
|
2393
2537
|
constructor(contents) {
|
|
@@ -2400,6 +2544,18 @@ void main() {
|
|
|
2400
2544
|
evaluate(context) {
|
|
2401
2545
|
return this.contents[0].evaluate(context);
|
|
2402
2546
|
}
|
|
2547
|
+
search(callback) {
|
|
2548
|
+
this.searchBlock(this.contents, callback);
|
|
2549
|
+
}
|
|
2550
|
+
};
|
|
2551
|
+
var ArrayIndex = class extends Expression {
|
|
2552
|
+
constructor(index2) {
|
|
2553
|
+
super();
|
|
2554
|
+
this.index = index2;
|
|
2555
|
+
}
|
|
2556
|
+
search(callback) {
|
|
2557
|
+
this.index.search(callback);
|
|
2558
|
+
}
|
|
2403
2559
|
};
|
|
2404
2560
|
var Operator = class extends Expression {
|
|
2405
2561
|
constructor() {
|
|
@@ -2429,6 +2585,9 @@ void main() {
|
|
|
2429
2585
|
throw new Error("Unknown unary operator: " + this.operator);
|
|
2430
2586
|
}
|
|
2431
2587
|
}
|
|
2588
|
+
search(callback) {
|
|
2589
|
+
this.right.search(callback);
|
|
2590
|
+
}
|
|
2432
2591
|
};
|
|
2433
2592
|
var BinaryOperator = class extends Operator {
|
|
2434
2593
|
constructor(operator, left, right) {
|
|
@@ -2472,6 +2631,10 @@ void main() {
|
|
|
2472
2631
|
throw new Error(`Unknown operator ${this.operator}`);
|
|
2473
2632
|
}
|
|
2474
2633
|
}
|
|
2634
|
+
search(callback) {
|
|
2635
|
+
this.left.search(callback);
|
|
2636
|
+
this.right.search(callback);
|
|
2637
|
+
}
|
|
2475
2638
|
};
|
|
2476
2639
|
var SwitchCase = class extends Node {
|
|
2477
2640
|
constructor() {
|
|
@@ -2487,6 +2650,9 @@ void main() {
|
|
|
2487
2650
|
get astNodeType() {
|
|
2488
2651
|
return "case";
|
|
2489
2652
|
}
|
|
2653
|
+
search(callback) {
|
|
2654
|
+
this.searchBlock(this.body, callback);
|
|
2655
|
+
}
|
|
2490
2656
|
};
|
|
2491
2657
|
var Default = class extends SwitchCase {
|
|
2492
2658
|
constructor(body) {
|
|
@@ -2496,6 +2662,9 @@ void main() {
|
|
|
2496
2662
|
get astNodeType() {
|
|
2497
2663
|
return "default";
|
|
2498
2664
|
}
|
|
2665
|
+
search(callback) {
|
|
2666
|
+
this.searchBlock(this.body, callback);
|
|
2667
|
+
}
|
|
2499
2668
|
};
|
|
2500
2669
|
var Argument = class extends Node {
|
|
2501
2670
|
constructor(name, type, attributes) {
|
|
@@ -2517,6 +2686,10 @@ void main() {
|
|
|
2517
2686
|
get astNodeType() {
|
|
2518
2687
|
return "elseif";
|
|
2519
2688
|
}
|
|
2689
|
+
search(callback) {
|
|
2690
|
+
this.condition.search(callback);
|
|
2691
|
+
this.searchBlock(this.body, callback);
|
|
2692
|
+
}
|
|
2520
2693
|
};
|
|
2521
2694
|
var Member = class extends Node {
|
|
2522
2695
|
constructor(name, type, attributes) {
|
|
@@ -2631,6 +2804,7 @@ void main() {
|
|
|
2631
2804
|
continue: new TokenType("continue", TokenClass.keyword, "continue"),
|
|
2632
2805
|
continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
|
|
2633
2806
|
default: new TokenType("default", TokenClass.keyword, "default"),
|
|
2807
|
+
diagnostic: new TokenType("diagnostic", TokenClass.keyword, "diagnostic"),
|
|
2634
2808
|
discard: new TokenType("discard", TokenClass.keyword, "discard"),
|
|
2635
2809
|
else: new TokenType("else", TokenClass.keyword, "else"),
|
|
2636
2810
|
enable: new TokenType("enable", TokenClass.keyword, "enable"),
|
|
@@ -2648,6 +2822,7 @@ void main() {
|
|
|
2648
2822
|
read: new TokenType("read", TokenClass.keyword, "read"),
|
|
2649
2823
|
read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
|
|
2650
2824
|
return: new TokenType("return", TokenClass.keyword, "return"),
|
|
2825
|
+
requires: new TokenType("requires", TokenClass.keyword, "requires"),
|
|
2651
2826
|
storage: new TokenType("storage", TokenClass.keyword, "storage"),
|
|
2652
2827
|
switch: new TokenType("switch", TokenClass.keyword, "switch"),
|
|
2653
2828
|
true: new TokenType("true", TokenClass.keyword, "true"),
|
|
@@ -2706,13 +2881,11 @@ void main() {
|
|
|
2706
2881
|
hex_float_literal: new TokenType("hex_float_literal", TokenClass.token, /-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),
|
|
2707
2882
|
int_literal: new TokenType("int_literal", TokenClass.token, /-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),
|
|
2708
2883
|
uint_literal: new TokenType("uint_literal", TokenClass.token, /0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),
|
|
2709
|
-
ident: new TokenType("ident", TokenClass.token, /[
|
|
2884
|
+
ident: new TokenType("ident", TokenClass.token, /[_a-zA-Z][0-9a-zA-Z_]*/),
|
|
2710
2885
|
and: new TokenType("and", TokenClass.token, "&"),
|
|
2711
2886
|
and_and: new TokenType("and_and", TokenClass.token, "&&"),
|
|
2712
2887
|
arrow: new TokenType("arrow ", TokenClass.token, "->"),
|
|
2713
2888
|
attr: new TokenType("attr", TokenClass.token, "@"),
|
|
2714
|
-
attr_left: new TokenType("attr_left", TokenClass.token, "[["),
|
|
2715
|
-
attr_right: new TokenType("attr_right", TokenClass.token, "]]"),
|
|
2716
2889
|
forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
|
|
2717
2890
|
bang: new TokenType("bang", TokenClass.token, "!"),
|
|
2718
2891
|
bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
|
|
@@ -2756,6 +2929,63 @@ void main() {
|
|
|
2756
2929
|
shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
|
|
2757
2930
|
shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<=")
|
|
2758
2931
|
};
|
|
2932
|
+
TokenTypes.simpleTokens = {
|
|
2933
|
+
"@": _a.tokens.attr,
|
|
2934
|
+
"{": _a.tokens.brace_left,
|
|
2935
|
+
"}": _a.tokens.brace_right,
|
|
2936
|
+
":": _a.tokens.colon,
|
|
2937
|
+
",": _a.tokens.comma,
|
|
2938
|
+
"(": _a.tokens.paren_left,
|
|
2939
|
+
")": _a.tokens.paren_right,
|
|
2940
|
+
";": _a.tokens.semicolon
|
|
2941
|
+
};
|
|
2942
|
+
TokenTypes.literalTokens = {
|
|
2943
|
+
"&": _a.tokens.and,
|
|
2944
|
+
"&&": _a.tokens.and_and,
|
|
2945
|
+
"->": _a.tokens.arrow,
|
|
2946
|
+
"/": _a.tokens.forward_slash,
|
|
2947
|
+
"!": _a.tokens.bang,
|
|
2948
|
+
"[": _a.tokens.bracket_left,
|
|
2949
|
+
"]": _a.tokens.bracket_right,
|
|
2950
|
+
"=": _a.tokens.equal,
|
|
2951
|
+
"==": _a.tokens.equal_equal,
|
|
2952
|
+
"!=": _a.tokens.not_equal,
|
|
2953
|
+
">": _a.tokens.greater_than,
|
|
2954
|
+
">=": _a.tokens.greater_than_equal,
|
|
2955
|
+
">>": _a.tokens.shift_right,
|
|
2956
|
+
"<": _a.tokens.less_than,
|
|
2957
|
+
"<=": _a.tokens.less_than_equal,
|
|
2958
|
+
"<<": _a.tokens.shift_left,
|
|
2959
|
+
"%": _a.tokens.modulo,
|
|
2960
|
+
"-": _a.tokens.minus,
|
|
2961
|
+
"--": _a.tokens.minus_minus,
|
|
2962
|
+
".": _a.tokens.period,
|
|
2963
|
+
"+": _a.tokens.plus,
|
|
2964
|
+
"++": _a.tokens.plus_plus,
|
|
2965
|
+
"|": _a.tokens.or,
|
|
2966
|
+
"||": _a.tokens.or_or,
|
|
2967
|
+
"*": _a.tokens.star,
|
|
2968
|
+
"~": _a.tokens.tilde,
|
|
2969
|
+
"_": _a.tokens.underscore,
|
|
2970
|
+
"^": _a.tokens.xor,
|
|
2971
|
+
"+=": _a.tokens.plus_equal,
|
|
2972
|
+
"-=": _a.tokens.minus_equal,
|
|
2973
|
+
"*=": _a.tokens.times_equal,
|
|
2974
|
+
"/=": _a.tokens.division_equal,
|
|
2975
|
+
"%=": _a.tokens.modulo_equal,
|
|
2976
|
+
"&=": _a.tokens.and_equal,
|
|
2977
|
+
"|=": _a.tokens.or_equal,
|
|
2978
|
+
"^=": _a.tokens.xor_equal,
|
|
2979
|
+
">>=": _a.tokens.shift_right_equal,
|
|
2980
|
+
"<<=": _a.tokens.shift_left_equal
|
|
2981
|
+
};
|
|
2982
|
+
TokenTypes.regexTokens = {
|
|
2983
|
+
decimal_float_literal: _a.tokens.decimal_float_literal,
|
|
2984
|
+
hex_float_literal: _a.tokens.hex_float_literal,
|
|
2985
|
+
int_literal: _a.tokens.int_literal,
|
|
2986
|
+
uint_literal: _a.tokens.uint_literal,
|
|
2987
|
+
ident: _a.tokens.ident
|
|
2988
|
+
};
|
|
2759
2989
|
TokenTypes.storage_class = [
|
|
2760
2990
|
_a.keywords.function,
|
|
2761
2991
|
_a.keywords.private,
|
|
@@ -2878,7 +3108,7 @@ void main() {
|
|
|
2878
3108
|
_a.keywords.bitcast,
|
|
2879
3109
|
..._a.any_texture_type
|
|
2880
3110
|
];
|
|
2881
|
-
TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block];
|
|
3111
|
+
TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block, _a.keywords.diagnostic];
|
|
2882
3112
|
TokenTypes.assignment_operators = [
|
|
2883
3113
|
_a.tokens.equal,
|
|
2884
3114
|
_a.tokens.plus_equal,
|
|
@@ -2927,8 +3157,9 @@ void main() {
|
|
|
2927
3157
|
scanTokens() {
|
|
2928
3158
|
while (!this._isAtEnd()) {
|
|
2929
3159
|
this._start = this._current;
|
|
2930
|
-
if (!this.scanToken())
|
|
3160
|
+
if (!this.scanToken()) {
|
|
2931
3161
|
throw `Invalid syntax at line ${this._line}`;
|
|
3162
|
+
}
|
|
2932
3163
|
}
|
|
2933
3164
|
this._tokens.push(new Token(TokenTypes.eof, "", this._line));
|
|
2934
3165
|
return this._tokens;
|
|
@@ -2946,8 +3177,9 @@ void main() {
|
|
|
2946
3177
|
if (lexeme == "/") {
|
|
2947
3178
|
if (this._peekAhead() == "/") {
|
|
2948
3179
|
while (lexeme != "\n") {
|
|
2949
|
-
if (this._isAtEnd())
|
|
3180
|
+
if (this._isAtEnd()) {
|
|
2950
3181
|
return true;
|
|
3182
|
+
}
|
|
2951
3183
|
lexeme = this._advance();
|
|
2952
3184
|
}
|
|
2953
3185
|
this._line++;
|
|
@@ -2956,8 +3188,9 @@ void main() {
|
|
|
2956
3188
|
this._advance();
|
|
2957
3189
|
let commentLevel = 1;
|
|
2958
3190
|
while (commentLevel > 0) {
|
|
2959
|
-
if (this._isAtEnd())
|
|
3191
|
+
if (this._isAtEnd()) {
|
|
2960
3192
|
return true;
|
|
3193
|
+
}
|
|
2961
3194
|
lexeme = this._advance();
|
|
2962
3195
|
if (lexeme == "\n") {
|
|
2963
3196
|
this._line++;
|
|
@@ -2979,7 +3212,32 @@ void main() {
|
|
|
2979
3212
|
return true;
|
|
2980
3213
|
}
|
|
2981
3214
|
}
|
|
3215
|
+
const simpleToken = TokenTypes.simpleTokens[lexeme];
|
|
3216
|
+
if (simpleToken) {
|
|
3217
|
+
this._addToken(simpleToken);
|
|
3218
|
+
return true;
|
|
3219
|
+
}
|
|
2982
3220
|
let matchType = TokenTypes.none;
|
|
3221
|
+
const isAlpha = this._isAlpha(lexeme);
|
|
3222
|
+
const isUnderscore = lexeme === "_";
|
|
3223
|
+
if (this._isAlphaNumeric(lexeme)) {
|
|
3224
|
+
let nextChar = this._peekAhead();
|
|
3225
|
+
while (this._isAlphaNumeric(nextChar)) {
|
|
3226
|
+
lexeme += this._advance();
|
|
3227
|
+
nextChar = this._peekAhead();
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
if (isAlpha) {
|
|
3231
|
+
const matchedType = TokenTypes.keywords[lexeme];
|
|
3232
|
+
if (matchedType) {
|
|
3233
|
+
this._addToken(matchedType);
|
|
3234
|
+
return true;
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
if (isAlpha || isUnderscore) {
|
|
3238
|
+
this._addToken(TokenTypes.tokens.ident);
|
|
3239
|
+
return true;
|
|
3240
|
+
}
|
|
2983
3241
|
for (; ; ) {
|
|
2984
3242
|
let matchedType = this._findType(lexeme);
|
|
2985
3243
|
const nextLexeme = this._peekAhead();
|
|
@@ -3012,8 +3270,9 @@ void main() {
|
|
|
3012
3270
|
}
|
|
3013
3271
|
}
|
|
3014
3272
|
if (matchedType === TokenTypes.none) {
|
|
3015
|
-
if (matchType === TokenTypes.none)
|
|
3273
|
+
if (matchType === TokenTypes.none) {
|
|
3016
3274
|
return false;
|
|
3275
|
+
}
|
|
3017
3276
|
this._current--;
|
|
3018
3277
|
this._addToken(matchType);
|
|
3019
3278
|
return true;
|
|
@@ -3022,45 +3281,43 @@ void main() {
|
|
|
3022
3281
|
this._current += lookAhead + 1;
|
|
3023
3282
|
}
|
|
3024
3283
|
matchType = matchedType;
|
|
3025
|
-
if (this._isAtEnd())
|
|
3284
|
+
if (this._isAtEnd()) {
|
|
3026
3285
|
break;
|
|
3286
|
+
}
|
|
3027
3287
|
lexeme += this._advance();
|
|
3028
3288
|
}
|
|
3029
|
-
if (matchType === TokenTypes.none)
|
|
3289
|
+
if (matchType === TokenTypes.none) {
|
|
3030
3290
|
return false;
|
|
3291
|
+
}
|
|
3031
3292
|
this._addToken(matchType);
|
|
3032
3293
|
return true;
|
|
3033
3294
|
}
|
|
3034
3295
|
_findType(lexeme) {
|
|
3035
|
-
for (const name in TokenTypes.
|
|
3036
|
-
const
|
|
3037
|
-
if (this._match(lexeme,
|
|
3038
|
-
return
|
|
3296
|
+
for (const name in TokenTypes.regexTokens) {
|
|
3297
|
+
const type2 = TokenTypes.regexTokens[name];
|
|
3298
|
+
if (this._match(lexeme, type2.rule)) {
|
|
3299
|
+
return type2;
|
|
3039
3300
|
}
|
|
3040
3301
|
}
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
return type;
|
|
3045
|
-
}
|
|
3302
|
+
const type = TokenTypes.literalTokens[lexeme];
|
|
3303
|
+
if (type) {
|
|
3304
|
+
return type;
|
|
3046
3305
|
}
|
|
3047
3306
|
return TokenTypes.none;
|
|
3048
3307
|
}
|
|
3049
3308
|
_match(lexeme, rule) {
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
return true;
|
|
3053
|
-
}
|
|
3054
|
-
} else {
|
|
3055
|
-
const match = rule.exec(lexeme);
|
|
3056
|
-
if (match && match.index == 0 && match[0] == lexeme)
|
|
3057
|
-
return true;
|
|
3058
|
-
}
|
|
3059
|
-
return false;
|
|
3309
|
+
const match = rule.exec(lexeme);
|
|
3310
|
+
return match && match.index == 0 && match[0] == lexeme;
|
|
3060
3311
|
}
|
|
3061
3312
|
_isAtEnd() {
|
|
3062
3313
|
return this._current >= this._source.length;
|
|
3063
3314
|
}
|
|
3315
|
+
_isAlpha(c) {
|
|
3316
|
+
return c >= "a" && c <= "z" || c >= "A" && c <= "Z";
|
|
3317
|
+
}
|
|
3318
|
+
_isAlphaNumeric(c) {
|
|
3319
|
+
return c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c == "_" || c >= "0" && c <= "9";
|
|
3320
|
+
}
|
|
3064
3321
|
_isWhitespace(c) {
|
|
3065
3322
|
return c == " " || c == " " || c == "\r";
|
|
3066
3323
|
}
|
|
@@ -3073,8 +3330,9 @@ void main() {
|
|
|
3073
3330
|
}
|
|
3074
3331
|
_peekAhead(offset = 0) {
|
|
3075
3332
|
offset = offset || 0;
|
|
3076
|
-
if (this._current + offset >= this._source.length)
|
|
3333
|
+
if (this._current + offset >= this._source.length) {
|
|
3077
3334
|
return "\0";
|
|
3335
|
+
}
|
|
3078
3336
|
return this._source[this._current + offset];
|
|
3079
3337
|
}
|
|
3080
3338
|
_addToken(type) {
|
|
@@ -3086,17 +3344,40 @@ void main() {
|
|
|
3086
3344
|
constructor() {
|
|
3087
3345
|
this._tokens = [];
|
|
3088
3346
|
this._current = 0;
|
|
3347
|
+
this._currentLine = 0;
|
|
3089
3348
|
this._context = new ParseContext();
|
|
3349
|
+
this._deferArrayCountEval = [];
|
|
3090
3350
|
}
|
|
3091
3351
|
parse(tokensOrCode) {
|
|
3092
3352
|
this._initialize(tokensOrCode);
|
|
3093
|
-
|
|
3353
|
+
this._deferArrayCountEval.length = 0;
|
|
3354
|
+
const statements = [];
|
|
3094
3355
|
while (!this._isAtEnd()) {
|
|
3095
3356
|
const statement = this._global_decl_or_directive();
|
|
3096
|
-
if (!statement)
|
|
3357
|
+
if (!statement) {
|
|
3097
3358
|
break;
|
|
3359
|
+
}
|
|
3098
3360
|
statements.push(statement);
|
|
3099
3361
|
}
|
|
3362
|
+
if (this._deferArrayCountEval.length > 0) {
|
|
3363
|
+
for (const arrayDecl of this._deferArrayCountEval) {
|
|
3364
|
+
const arrayType = arrayDecl["arrayType"];
|
|
3365
|
+
const countNode = arrayDecl["countNode"];
|
|
3366
|
+
if (countNode instanceof VariableExpr) {
|
|
3367
|
+
const variable = countNode;
|
|
3368
|
+
const name = variable.name;
|
|
3369
|
+
const constant = this._context.constants.get(name);
|
|
3370
|
+
if (constant) {
|
|
3371
|
+
try {
|
|
3372
|
+
const count = constant.evaluate(this._context);
|
|
3373
|
+
arrayType.count = count;
|
|
3374
|
+
} catch (e) {
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
this._deferArrayCountEval.length = 0;
|
|
3380
|
+
}
|
|
3100
3381
|
return statements;
|
|
3101
3382
|
}
|
|
3102
3383
|
_initialize(tokensOrCode) {
|
|
@@ -3113,7 +3394,6 @@ void main() {
|
|
|
3113
3394
|
this._current = 0;
|
|
3114
3395
|
}
|
|
3115
3396
|
_error(token, message) {
|
|
3116
|
-
console.error(token, message);
|
|
3117
3397
|
return {
|
|
3118
3398
|
token,
|
|
3119
3399
|
message,
|
|
@@ -3143,24 +3423,29 @@ void main() {
|
|
|
3143
3423
|
return false;
|
|
3144
3424
|
}
|
|
3145
3425
|
_consume(types, message) {
|
|
3146
|
-
if (this._check(types))
|
|
3426
|
+
if (this._check(types)) {
|
|
3147
3427
|
return this._advance();
|
|
3428
|
+
}
|
|
3148
3429
|
throw this._error(this._peek(), message);
|
|
3149
3430
|
}
|
|
3150
3431
|
_check(types) {
|
|
3151
|
-
if (this._isAtEnd())
|
|
3432
|
+
if (this._isAtEnd()) {
|
|
3152
3433
|
return false;
|
|
3434
|
+
}
|
|
3153
3435
|
const tk = this._peek();
|
|
3154
3436
|
if (types instanceof Array) {
|
|
3155
|
-
|
|
3156
|
-
|
|
3437
|
+
const t = tk.type;
|
|
3438
|
+
const index2 = types.indexOf(t);
|
|
3157
3439
|
return index2 != -1;
|
|
3158
3440
|
}
|
|
3159
3441
|
return tk.type == types;
|
|
3160
3442
|
}
|
|
3161
3443
|
_advance() {
|
|
3162
|
-
|
|
3444
|
+
var _a2, _b;
|
|
3445
|
+
this._currentLine = (_b = (_a2 = this._peek()) === null || _a2 === void 0 ? void 0 : _a2.line) !== null && _b !== void 0 ? _b : -1;
|
|
3446
|
+
if (!this._isAtEnd()) {
|
|
3163
3447
|
this._current++;
|
|
3448
|
+
}
|
|
3164
3449
|
return this._previous();
|
|
3165
3450
|
}
|
|
3166
3451
|
_peek() {
|
|
@@ -3177,6 +3462,16 @@ void main() {
|
|
|
3177
3462
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
3178
3463
|
return type;
|
|
3179
3464
|
}
|
|
3465
|
+
if (this._match(TokenTypes.keywords.diagnostic)) {
|
|
3466
|
+
const directive = this._diagnostic();
|
|
3467
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
3468
|
+
return directive;
|
|
3469
|
+
}
|
|
3470
|
+
if (this._match(TokenTypes.keywords.requires)) {
|
|
3471
|
+
const requires = this._requires_directive();
|
|
3472
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
3473
|
+
return requires;
|
|
3474
|
+
}
|
|
3180
3475
|
if (this._match(TokenTypes.keywords.enable)) {
|
|
3181
3476
|
const enable = this._enable_directive();
|
|
3182
3477
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
@@ -3185,56 +3480,65 @@ void main() {
|
|
|
3185
3480
|
const attrs = this._attribute();
|
|
3186
3481
|
if (this._check(TokenTypes.keywords.var)) {
|
|
3187
3482
|
const _var = this._global_variable_decl();
|
|
3188
|
-
if (_var != null)
|
|
3483
|
+
if (_var != null) {
|
|
3189
3484
|
_var.attributes = attrs;
|
|
3485
|
+
}
|
|
3190
3486
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
3191
3487
|
return _var;
|
|
3192
3488
|
}
|
|
3193
3489
|
if (this._check(TokenTypes.keywords.override)) {
|
|
3194
3490
|
const _override = this._override_variable_decl();
|
|
3195
|
-
if (_override != null)
|
|
3491
|
+
if (_override != null) {
|
|
3196
3492
|
_override.attributes = attrs;
|
|
3493
|
+
}
|
|
3197
3494
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
3198
3495
|
return _override;
|
|
3199
3496
|
}
|
|
3200
3497
|
if (this._check(TokenTypes.keywords.let)) {
|
|
3201
3498
|
const _let = this._global_let_decl();
|
|
3202
|
-
if (_let != null)
|
|
3499
|
+
if (_let != null) {
|
|
3203
3500
|
_let.attributes = attrs;
|
|
3501
|
+
}
|
|
3204
3502
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
3205
3503
|
return _let;
|
|
3206
3504
|
}
|
|
3207
3505
|
if (this._check(TokenTypes.keywords.const)) {
|
|
3208
3506
|
const _const = this._global_const_decl();
|
|
3209
|
-
if (_const != null)
|
|
3507
|
+
if (_const != null) {
|
|
3210
3508
|
_const.attributes = attrs;
|
|
3509
|
+
}
|
|
3211
3510
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
3212
3511
|
return _const;
|
|
3213
3512
|
}
|
|
3214
3513
|
if (this._check(TokenTypes.keywords.struct)) {
|
|
3215
3514
|
const _struct = this._struct_decl();
|
|
3216
|
-
if (_struct != null)
|
|
3515
|
+
if (_struct != null) {
|
|
3217
3516
|
_struct.attributes = attrs;
|
|
3517
|
+
}
|
|
3218
3518
|
return _struct;
|
|
3219
3519
|
}
|
|
3220
3520
|
if (this._check(TokenTypes.keywords.fn)) {
|
|
3221
3521
|
const _fn = this._function_decl();
|
|
3222
|
-
if (_fn != null)
|
|
3522
|
+
if (_fn != null) {
|
|
3223
3523
|
_fn.attributes = attrs;
|
|
3524
|
+
}
|
|
3224
3525
|
return _fn;
|
|
3225
3526
|
}
|
|
3226
3527
|
return null;
|
|
3227
3528
|
}
|
|
3228
3529
|
_function_decl() {
|
|
3229
|
-
if (!this._match(TokenTypes.keywords.fn))
|
|
3530
|
+
if (!this._match(TokenTypes.keywords.fn)) {
|
|
3230
3531
|
return null;
|
|
3532
|
+
}
|
|
3533
|
+
const startLine = this._currentLine;
|
|
3231
3534
|
const name = this._consume(TokenTypes.tokens.ident, "Expected function name.").toString();
|
|
3232
3535
|
this._consume(TokenTypes.tokens.paren_left, "Expected '(' for function arguments.");
|
|
3233
3536
|
const args = [];
|
|
3234
3537
|
if (!this._check(TokenTypes.tokens.paren_right)) {
|
|
3235
3538
|
do {
|
|
3236
|
-
if (this._check(TokenTypes.tokens.paren_right))
|
|
3539
|
+
if (this._check(TokenTypes.tokens.paren_right)) {
|
|
3237
3540
|
break;
|
|
3541
|
+
}
|
|
3238
3542
|
const argAttrs = this._attribute();
|
|
3239
3543
|
const name2 = this._consume(TokenTypes.tokens.ident, "Expected argument name.").toString();
|
|
3240
3544
|
this._consume(TokenTypes.tokens.colon, "Expected ':' for argument type.");
|
|
@@ -3251,19 +3555,22 @@ void main() {
|
|
|
3251
3555
|
if (this._match(TokenTypes.tokens.arrow)) {
|
|
3252
3556
|
const attrs = this._attribute();
|
|
3253
3557
|
_return = this._type_decl();
|
|
3254
|
-
if (_return != null)
|
|
3558
|
+
if (_return != null) {
|
|
3255
3559
|
_return.attributes = attrs;
|
|
3560
|
+
}
|
|
3256
3561
|
}
|
|
3257
3562
|
const body = this._compound_statement();
|
|
3258
|
-
|
|
3563
|
+
const endLine = this._currentLine;
|
|
3564
|
+
return new Function(name, args, _return, body, startLine, endLine);
|
|
3259
3565
|
}
|
|
3260
3566
|
_compound_statement() {
|
|
3261
3567
|
const statements = [];
|
|
3262
3568
|
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for block.");
|
|
3263
3569
|
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
3264
3570
|
const statement = this._statement();
|
|
3265
|
-
if (statement !== null)
|
|
3571
|
+
if (statement !== null) {
|
|
3266
3572
|
statements.push(statement);
|
|
3573
|
+
}
|
|
3267
3574
|
}
|
|
3268
3575
|
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for block.");
|
|
3269
3576
|
return statements;
|
|
@@ -3271,65 +3578,85 @@ void main() {
|
|
|
3271
3578
|
_statement() {
|
|
3272
3579
|
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
3273
3580
|
;
|
|
3274
|
-
if (this._check(TokenTypes.
|
|
3581
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3582
|
+
this._attribute();
|
|
3583
|
+
}
|
|
3584
|
+
if (this._check(TokenTypes.keywords.if)) {
|
|
3275
3585
|
return this._if_statement();
|
|
3276
|
-
|
|
3586
|
+
}
|
|
3587
|
+
if (this._check(TokenTypes.keywords.switch)) {
|
|
3277
3588
|
return this._switch_statement();
|
|
3278
|
-
|
|
3589
|
+
}
|
|
3590
|
+
if (this._check(TokenTypes.keywords.loop)) {
|
|
3279
3591
|
return this._loop_statement();
|
|
3280
|
-
|
|
3592
|
+
}
|
|
3593
|
+
if (this._check(TokenTypes.keywords.for)) {
|
|
3281
3594
|
return this._for_statement();
|
|
3282
|
-
|
|
3595
|
+
}
|
|
3596
|
+
if (this._check(TokenTypes.keywords.while)) {
|
|
3283
3597
|
return this._while_statement();
|
|
3284
|
-
|
|
3598
|
+
}
|
|
3599
|
+
if (this._check(TokenTypes.keywords.continuing)) {
|
|
3285
3600
|
return this._continuing_statement();
|
|
3286
|
-
|
|
3601
|
+
}
|
|
3602
|
+
if (this._check(TokenTypes.keywords.static_assert)) {
|
|
3287
3603
|
return this._static_assert_statement();
|
|
3288
|
-
|
|
3604
|
+
}
|
|
3605
|
+
if (this._check(TokenTypes.tokens.brace_left)) {
|
|
3289
3606
|
return this._compound_statement();
|
|
3607
|
+
}
|
|
3290
3608
|
let result = null;
|
|
3291
|
-
if (this._check(TokenTypes.keywords.return))
|
|
3609
|
+
if (this._check(TokenTypes.keywords.return)) {
|
|
3292
3610
|
result = this._return_statement();
|
|
3293
|
-
else if (this._check([
|
|
3611
|
+
} else if (this._check([
|
|
3294
3612
|
TokenTypes.keywords.var,
|
|
3295
3613
|
TokenTypes.keywords.let,
|
|
3296
3614
|
TokenTypes.keywords.const
|
|
3297
|
-
]))
|
|
3615
|
+
])) {
|
|
3298
3616
|
result = this._variable_statement();
|
|
3299
|
-
else if (this._match(TokenTypes.keywords.discard))
|
|
3617
|
+
} else if (this._match(TokenTypes.keywords.discard)) {
|
|
3300
3618
|
result = new Discard();
|
|
3301
|
-
else if (this._match(TokenTypes.keywords.break))
|
|
3619
|
+
} else if (this._match(TokenTypes.keywords.break)) {
|
|
3302
3620
|
result = new Break();
|
|
3303
|
-
else if (this._match(TokenTypes.keywords.continue))
|
|
3621
|
+
} else if (this._match(TokenTypes.keywords.continue)) {
|
|
3304
3622
|
result = new Continue();
|
|
3305
|
-
else
|
|
3623
|
+
} else {
|
|
3306
3624
|
result = this._increment_decrement_statement() || this._func_call_statement() || this._assignment_statement();
|
|
3307
|
-
|
|
3625
|
+
}
|
|
3626
|
+
if (result != null) {
|
|
3308
3627
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';' after statement.");
|
|
3628
|
+
}
|
|
3309
3629
|
return result;
|
|
3310
3630
|
}
|
|
3311
3631
|
_static_assert_statement() {
|
|
3312
|
-
if (!this._match(TokenTypes.keywords.static_assert))
|
|
3632
|
+
if (!this._match(TokenTypes.keywords.static_assert)) {
|
|
3313
3633
|
return null;
|
|
3314
|
-
|
|
3634
|
+
}
|
|
3635
|
+
const expression = this._optional_paren_expression();
|
|
3315
3636
|
return new StaticAssert(expression);
|
|
3316
3637
|
}
|
|
3317
3638
|
_while_statement() {
|
|
3318
|
-
if (!this._match(TokenTypes.keywords.while))
|
|
3639
|
+
if (!this._match(TokenTypes.keywords.while)) {
|
|
3319
3640
|
return null;
|
|
3320
|
-
|
|
3641
|
+
}
|
|
3642
|
+
const condition = this._optional_paren_expression();
|
|
3643
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3644
|
+
this._attribute();
|
|
3645
|
+
}
|
|
3321
3646
|
const block = this._compound_statement();
|
|
3322
3647
|
return new While(condition, block);
|
|
3323
3648
|
}
|
|
3324
3649
|
_continuing_statement() {
|
|
3325
|
-
if (!this._match(TokenTypes.keywords.continuing))
|
|
3650
|
+
if (!this._match(TokenTypes.keywords.continuing)) {
|
|
3326
3651
|
return null;
|
|
3652
|
+
}
|
|
3327
3653
|
const block = this._compound_statement();
|
|
3328
3654
|
return new Continuing(block);
|
|
3329
3655
|
}
|
|
3330
3656
|
_for_statement() {
|
|
3331
|
-
if (!this._match(TokenTypes.keywords.for))
|
|
3657
|
+
if (!this._match(TokenTypes.keywords.for)) {
|
|
3332
3658
|
return null;
|
|
3659
|
+
}
|
|
3333
3660
|
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
3334
3661
|
const init = !this._check(TokenTypes.tokens.semicolon) ? this._for_init() : null;
|
|
3335
3662
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
@@ -3337,6 +3664,9 @@ void main() {
|
|
|
3337
3664
|
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
3338
3665
|
const increment = !this._check(TokenTypes.tokens.paren_right) ? this._for_increment() : null;
|
|
3339
3666
|
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
3667
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3668
|
+
this._attribute();
|
|
3669
|
+
}
|
|
3340
3670
|
const body = this._compound_statement();
|
|
3341
3671
|
return new For(init, condition, increment, body);
|
|
3342
3672
|
}
|
|
@@ -3349,11 +3679,13 @@ void main() {
|
|
|
3349
3679
|
_variable_statement() {
|
|
3350
3680
|
if (this._check(TokenTypes.keywords.var)) {
|
|
3351
3681
|
const _var = this._variable_decl();
|
|
3352
|
-
if (_var === null)
|
|
3682
|
+
if (_var === null) {
|
|
3353
3683
|
throw this._error(this._peek(), "Variable declaration expected.");
|
|
3684
|
+
}
|
|
3354
3685
|
let value = null;
|
|
3355
|
-
if (this._match(TokenTypes.tokens.equal))
|
|
3686
|
+
if (this._match(TokenTypes.tokens.equal)) {
|
|
3356
3687
|
value = this._short_circuit_or_expression();
|
|
3688
|
+
}
|
|
3357
3689
|
return new Var(_var.name, _var.type, _var.storage, _var.access, value);
|
|
3358
3690
|
}
|
|
3359
3691
|
if (this._match(TokenTypes.keywords.let)) {
|
|
@@ -3362,8 +3694,9 @@ void main() {
|
|
|
3362
3694
|
if (this._match(TokenTypes.tokens.colon)) {
|
|
3363
3695
|
const typeAttrs = this._attribute();
|
|
3364
3696
|
type = this._type_decl();
|
|
3365
|
-
if (type != null)
|
|
3697
|
+
if (type != null) {
|
|
3366
3698
|
type.attributes = typeAttrs;
|
|
3699
|
+
}
|
|
3367
3700
|
}
|
|
3368
3701
|
this._consume(TokenTypes.tokens.equal, "Expected '=' for let.");
|
|
3369
3702
|
const value = this._short_circuit_or_expression();
|
|
@@ -3375,8 +3708,9 @@ void main() {
|
|
|
3375
3708
|
if (this._match(TokenTypes.tokens.colon)) {
|
|
3376
3709
|
const typeAttrs = this._attribute();
|
|
3377
3710
|
type = this._type_decl();
|
|
3378
|
-
if (type != null)
|
|
3711
|
+
if (type != null) {
|
|
3379
3712
|
type.attributes = typeAttrs;
|
|
3713
|
+
}
|
|
3380
3714
|
}
|
|
3381
3715
|
this._consume(TokenTypes.tokens.equal, "Expected '=' for const.");
|
|
3382
3716
|
const value = this._short_circuit_or_expression();
|
|
@@ -3387,8 +3721,9 @@ void main() {
|
|
|
3387
3721
|
_increment_decrement_statement() {
|
|
3388
3722
|
const savedPos = this._current;
|
|
3389
3723
|
const _var = this._unary_expression();
|
|
3390
|
-
if (_var == null)
|
|
3724
|
+
if (_var == null) {
|
|
3391
3725
|
return null;
|
|
3726
|
+
}
|
|
3392
3727
|
if (!this._check(TokenTypes.increment_operators)) {
|
|
3393
3728
|
this._current = savedPos;
|
|
3394
3729
|
return null;
|
|
@@ -3398,20 +3733,24 @@ void main() {
|
|
|
3398
3733
|
}
|
|
3399
3734
|
_assignment_statement() {
|
|
3400
3735
|
let _var = null;
|
|
3401
|
-
if (this._check(TokenTypes.tokens.brace_right))
|
|
3736
|
+
if (this._check(TokenTypes.tokens.brace_right)) {
|
|
3402
3737
|
return null;
|
|
3738
|
+
}
|
|
3403
3739
|
let isUnderscore = this._match(TokenTypes.tokens.underscore);
|
|
3404
|
-
if (!isUnderscore)
|
|
3740
|
+
if (!isUnderscore) {
|
|
3405
3741
|
_var = this._unary_expression();
|
|
3406
|
-
|
|
3742
|
+
}
|
|
3743
|
+
if (!isUnderscore && _var == null) {
|
|
3407
3744
|
return null;
|
|
3745
|
+
}
|
|
3408
3746
|
const type = this._consume(TokenTypes.assignment_operators, "Expected assignment operator.");
|
|
3409
3747
|
const value = this._short_circuit_or_expression();
|
|
3410
3748
|
return new Assign(AssignOperator.parse(type.lexeme), _var, value);
|
|
3411
3749
|
}
|
|
3412
3750
|
_func_call_statement() {
|
|
3413
|
-
if (!this._check(TokenTypes.tokens.ident))
|
|
3751
|
+
if (!this._check(TokenTypes.tokens.ident)) {
|
|
3414
3752
|
return null;
|
|
3753
|
+
}
|
|
3415
3754
|
const savedPos = this._current;
|
|
3416
3755
|
const name = this._consume(TokenTypes.tokens.ident, "Expected function name.");
|
|
3417
3756
|
const args = this._argument_expression_list();
|
|
@@ -3422,8 +3761,12 @@ void main() {
|
|
|
3422
3761
|
return new Call(name.lexeme, args);
|
|
3423
3762
|
}
|
|
3424
3763
|
_loop_statement() {
|
|
3425
|
-
if (!this._match(TokenTypes.keywords.loop))
|
|
3764
|
+
if (!this._match(TokenTypes.keywords.loop)) {
|
|
3426
3765
|
return null;
|
|
3766
|
+
}
|
|
3767
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3768
|
+
this._attribute();
|
|
3769
|
+
}
|
|
3427
3770
|
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
|
|
3428
3771
|
const statements = [];
|
|
3429
3772
|
let statement = this._statement();
|
|
@@ -3438,19 +3781,25 @@ void main() {
|
|
|
3438
3781
|
statement = this._statement();
|
|
3439
3782
|
}
|
|
3440
3783
|
let continuing = null;
|
|
3441
|
-
if (this._match(TokenTypes.keywords.continuing))
|
|
3784
|
+
if (this._match(TokenTypes.keywords.continuing)) {
|
|
3442
3785
|
continuing = this._compound_statement();
|
|
3786
|
+
}
|
|
3443
3787
|
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for loop.");
|
|
3444
3788
|
return new Loop(statements, continuing);
|
|
3445
3789
|
}
|
|
3446
3790
|
_switch_statement() {
|
|
3447
|
-
if (!this._match(TokenTypes.keywords.switch))
|
|
3791
|
+
if (!this._match(TokenTypes.keywords.switch)) {
|
|
3448
3792
|
return null;
|
|
3793
|
+
}
|
|
3449
3794
|
const condition = this._optional_paren_expression();
|
|
3795
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3796
|
+
this._attribute();
|
|
3797
|
+
}
|
|
3450
3798
|
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
|
|
3451
3799
|
const body = this._switch_body();
|
|
3452
|
-
if (body == null || body.length == 0)
|
|
3800
|
+
if (body == null || body.length == 0) {
|
|
3453
3801
|
throw this._error(this._previous(), "Expected 'case' or 'default'.");
|
|
3802
|
+
}
|
|
3454
3803
|
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for switch.");
|
|
3455
3804
|
return new Switch(condition, body);
|
|
3456
3805
|
}
|
|
@@ -3459,6 +3808,9 @@ void main() {
|
|
|
3459
3808
|
if (this._match(TokenTypes.keywords.case)) {
|
|
3460
3809
|
const selector = this._case_selectors();
|
|
3461
3810
|
this._match(TokenTypes.tokens.colon);
|
|
3811
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3812
|
+
this._attribute();
|
|
3813
|
+
}
|
|
3462
3814
|
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
|
|
3463
3815
|
const body = this._case_body();
|
|
3464
3816
|
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
|
|
@@ -3466,6 +3818,9 @@ void main() {
|
|
|
3466
3818
|
}
|
|
3467
3819
|
if (this._match(TokenTypes.keywords.default)) {
|
|
3468
3820
|
this._match(TokenTypes.tokens.colon);
|
|
3821
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3822
|
+
this._attribute();
|
|
3823
|
+
}
|
|
3469
3824
|
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
|
|
3470
3825
|
const body = this._case_body();
|
|
3471
3826
|
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
|
|
@@ -3478,12 +3833,12 @@ void main() {
|
|
|
3478
3833
|
return cases;
|
|
3479
3834
|
}
|
|
3480
3835
|
_case_selectors() {
|
|
3481
|
-
var _a2, _b, _c, _d;
|
|
3482
3836
|
const selectors = [
|
|
3483
|
-
|
|
3837
|
+
this._shift_expression()
|
|
3838
|
+
//?.evaluate(this._context).toString() ?? "",
|
|
3484
3839
|
];
|
|
3485
3840
|
while (this._match(TokenTypes.tokens.comma)) {
|
|
3486
|
-
selectors.push(
|
|
3841
|
+
selectors.push(this._shift_expression());
|
|
3487
3842
|
}
|
|
3488
3843
|
return selectors;
|
|
3489
3844
|
}
|
|
@@ -3493,28 +3848,41 @@ void main() {
|
|
|
3493
3848
|
return [];
|
|
3494
3849
|
}
|
|
3495
3850
|
let statement = this._statement();
|
|
3496
|
-
if (statement == null)
|
|
3851
|
+
if (statement == null) {
|
|
3497
3852
|
return [];
|
|
3853
|
+
}
|
|
3498
3854
|
if (!(statement instanceof Array)) {
|
|
3499
3855
|
statement = [statement];
|
|
3500
3856
|
}
|
|
3501
3857
|
const nextStatement = this._case_body();
|
|
3502
|
-
if (nextStatement.length == 0)
|
|
3858
|
+
if (nextStatement.length == 0) {
|
|
3503
3859
|
return statement;
|
|
3860
|
+
}
|
|
3504
3861
|
return [...statement, nextStatement[0]];
|
|
3505
3862
|
}
|
|
3506
3863
|
_if_statement() {
|
|
3507
|
-
if (!this._match(TokenTypes.keywords.if))
|
|
3864
|
+
if (!this._match(TokenTypes.keywords.if)) {
|
|
3508
3865
|
return null;
|
|
3866
|
+
}
|
|
3509
3867
|
const condition = this._optional_paren_expression();
|
|
3868
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3869
|
+
this._attribute();
|
|
3870
|
+
}
|
|
3510
3871
|
const block = this._compound_statement();
|
|
3511
3872
|
let elseif = [];
|
|
3512
3873
|
if (this._match_elseif()) {
|
|
3874
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3875
|
+
this._attribute();
|
|
3876
|
+
}
|
|
3513
3877
|
elseif = this._elseif_statement(elseif);
|
|
3514
3878
|
}
|
|
3515
3879
|
let _else = null;
|
|
3516
|
-
if (this._match(TokenTypes.keywords.else))
|
|
3880
|
+
if (this._match(TokenTypes.keywords.else)) {
|
|
3881
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3882
|
+
this._attribute();
|
|
3883
|
+
}
|
|
3517
3884
|
_else = this._compound_statement();
|
|
3885
|
+
}
|
|
3518
3886
|
return new If(condition, block, elseif, _else);
|
|
3519
3887
|
}
|
|
3520
3888
|
_match_elseif() {
|
|
@@ -3530,13 +3898,17 @@ void main() {
|
|
|
3530
3898
|
const block = this._compound_statement();
|
|
3531
3899
|
elseif.push(new ElseIf(condition, block));
|
|
3532
3900
|
if (this._match_elseif()) {
|
|
3901
|
+
if (this._check(TokenTypes.tokens.attr)) {
|
|
3902
|
+
this._attribute();
|
|
3903
|
+
}
|
|
3533
3904
|
this._elseif_statement(elseif);
|
|
3534
3905
|
}
|
|
3535
3906
|
return elseif;
|
|
3536
3907
|
}
|
|
3537
3908
|
_return_statement() {
|
|
3538
|
-
if (!this._match(TokenTypes.keywords.return))
|
|
3909
|
+
if (!this._match(TokenTypes.keywords.return)) {
|
|
3539
3910
|
return null;
|
|
3911
|
+
}
|
|
3540
3912
|
const value = this._short_circuit_or_expression();
|
|
3541
3913
|
return new Return(value);
|
|
3542
3914
|
}
|
|
@@ -3634,25 +4006,29 @@ void main() {
|
|
|
3634
4006
|
_singular_expression() {
|
|
3635
4007
|
const expr = this._primary_expression();
|
|
3636
4008
|
const p = this._postfix_expression();
|
|
3637
|
-
if (p)
|
|
4009
|
+
if (p) {
|
|
3638
4010
|
expr.postfix = p;
|
|
4011
|
+
}
|
|
3639
4012
|
return expr;
|
|
3640
4013
|
}
|
|
3641
4014
|
_postfix_expression() {
|
|
3642
4015
|
if (this._match(TokenTypes.tokens.bracket_left)) {
|
|
3643
4016
|
const expr = this._short_circuit_or_expression();
|
|
3644
4017
|
this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
|
|
4018
|
+
const arrayIndex = new ArrayIndex(expr);
|
|
3645
4019
|
const p = this._postfix_expression();
|
|
3646
|
-
if (p)
|
|
3647
|
-
|
|
3648
|
-
|
|
4020
|
+
if (p) {
|
|
4021
|
+
arrayIndex.postfix = p;
|
|
4022
|
+
}
|
|
4023
|
+
return arrayIndex;
|
|
3649
4024
|
}
|
|
3650
4025
|
if (this._match(TokenTypes.tokens.period)) {
|
|
3651
4026
|
const name = this._consume(TokenTypes.tokens.ident, "Expected member name.");
|
|
3652
4027
|
const p = this._postfix_expression();
|
|
3653
4028
|
const expr = new StringExpr(name.lexeme);
|
|
3654
|
-
if (p)
|
|
4029
|
+
if (p) {
|
|
3655
4030
|
expr.postfix = p;
|
|
4031
|
+
}
|
|
3656
4032
|
return expr;
|
|
3657
4033
|
}
|
|
3658
4034
|
return null;
|
|
@@ -3703,12 +4079,14 @@ void main() {
|
|
|
3703
4079
|
return new TypecastExpr(type, args);
|
|
3704
4080
|
}
|
|
3705
4081
|
_argument_expression_list() {
|
|
3706
|
-
if (!this._match(TokenTypes.tokens.paren_left))
|
|
4082
|
+
if (!this._match(TokenTypes.tokens.paren_left)) {
|
|
3707
4083
|
return null;
|
|
4084
|
+
}
|
|
3708
4085
|
const args = [];
|
|
3709
4086
|
do {
|
|
3710
|
-
if (this._check(TokenTypes.tokens.paren_right))
|
|
4087
|
+
if (this._check(TokenTypes.tokens.paren_right)) {
|
|
3711
4088
|
break;
|
|
4089
|
+
}
|
|
3712
4090
|
const arg = this._short_circuit_or_expression();
|
|
3713
4091
|
args.push(arg);
|
|
3714
4092
|
} while (this._match(TokenTypes.tokens.comma));
|
|
@@ -3728,8 +4106,10 @@ void main() {
|
|
|
3728
4106
|
return new GroupingExpr([expr]);
|
|
3729
4107
|
}
|
|
3730
4108
|
_struct_decl() {
|
|
3731
|
-
if (!this._match(TokenTypes.keywords.struct))
|
|
4109
|
+
if (!this._match(TokenTypes.keywords.struct)) {
|
|
3732
4110
|
return null;
|
|
4111
|
+
}
|
|
4112
|
+
const startLine = this._currentLine;
|
|
3733
4113
|
const name = this._consume(TokenTypes.tokens.ident, "Expected name for struct.").toString();
|
|
3734
4114
|
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for struct body.");
|
|
3735
4115
|
const members = [];
|
|
@@ -3739,8 +4119,9 @@ void main() {
|
|
|
3739
4119
|
this._consume(TokenTypes.tokens.colon, "Expected ':' for struct member type.");
|
|
3740
4120
|
const typeAttrs = this._attribute();
|
|
3741
4121
|
const memberType = this._type_decl();
|
|
3742
|
-
if (memberType != null)
|
|
4122
|
+
if (memberType != null) {
|
|
3743
4123
|
memberType.attributes = typeAttrs;
|
|
4124
|
+
}
|
|
3744
4125
|
if (!this._check(TokenTypes.tokens.brace_right))
|
|
3745
4126
|
this._consume(TokenTypes.tokens.comma, "Expected ',' for struct member.");
|
|
3746
4127
|
else
|
|
@@ -3748,32 +4129,37 @@ void main() {
|
|
|
3748
4129
|
members.push(new Member(memberName, memberType, memberAttrs));
|
|
3749
4130
|
}
|
|
3750
4131
|
this._consume(TokenTypes.tokens.brace_right, "Expected '}' after struct body.");
|
|
3751
|
-
const
|
|
4132
|
+
const endLine = this._currentLine;
|
|
4133
|
+
const structNode = new Struct(name, members, startLine, endLine);
|
|
3752
4134
|
this._context.structs.set(name, structNode);
|
|
3753
4135
|
return structNode;
|
|
3754
4136
|
}
|
|
3755
4137
|
_global_variable_decl() {
|
|
3756
4138
|
const _var = this._variable_decl();
|
|
3757
|
-
if (_var && this._match(TokenTypes.tokens.equal))
|
|
4139
|
+
if (_var && this._match(TokenTypes.tokens.equal)) {
|
|
3758
4140
|
_var.value = this._const_expression();
|
|
4141
|
+
}
|
|
3759
4142
|
return _var;
|
|
3760
4143
|
}
|
|
3761
4144
|
_override_variable_decl() {
|
|
3762
4145
|
const _override = this._override_decl();
|
|
3763
|
-
if (_override && this._match(TokenTypes.tokens.equal))
|
|
4146
|
+
if (_override && this._match(TokenTypes.tokens.equal)) {
|
|
3764
4147
|
_override.value = this._const_expression();
|
|
4148
|
+
}
|
|
3765
4149
|
return _override;
|
|
3766
4150
|
}
|
|
3767
4151
|
_global_const_decl() {
|
|
3768
|
-
if (!this._match(TokenTypes.keywords.const))
|
|
4152
|
+
if (!this._match(TokenTypes.keywords.const)) {
|
|
3769
4153
|
return null;
|
|
4154
|
+
}
|
|
3770
4155
|
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3771
4156
|
let type = null;
|
|
3772
4157
|
if (this._match(TokenTypes.tokens.colon)) {
|
|
3773
4158
|
const attrs = this._attribute();
|
|
3774
4159
|
type = this._type_decl();
|
|
3775
|
-
if (type != null)
|
|
4160
|
+
if (type != null) {
|
|
3776
4161
|
type.attributes = attrs;
|
|
4162
|
+
}
|
|
3777
4163
|
}
|
|
3778
4164
|
let value = null;
|
|
3779
4165
|
if (this._match(TokenTypes.tokens.equal)) {
|
|
@@ -3796,15 +4182,17 @@ void main() {
|
|
|
3796
4182
|
return c;
|
|
3797
4183
|
}
|
|
3798
4184
|
_global_let_decl() {
|
|
3799
|
-
if (!this._match(TokenTypes.keywords.let))
|
|
4185
|
+
if (!this._match(TokenTypes.keywords.let)) {
|
|
3800
4186
|
return null;
|
|
4187
|
+
}
|
|
3801
4188
|
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3802
4189
|
let type = null;
|
|
3803
4190
|
if (this._match(TokenTypes.tokens.colon)) {
|
|
3804
4191
|
const attrs = this._attribute();
|
|
3805
4192
|
type = this._type_decl();
|
|
3806
|
-
if (type != null)
|
|
4193
|
+
if (type != null) {
|
|
3807
4194
|
type.attributes = attrs;
|
|
4195
|
+
}
|
|
3808
4196
|
}
|
|
3809
4197
|
let value = null;
|
|
3810
4198
|
if (this._match(TokenTypes.tokens.equal)) {
|
|
@@ -3813,23 +4201,26 @@ void main() {
|
|
|
3813
4201
|
return new Let(name.toString(), type, "", "", value);
|
|
3814
4202
|
}
|
|
3815
4203
|
_const_expression() {
|
|
3816
|
-
if (this._match(TokenTypes.const_literal))
|
|
4204
|
+
if (this._match(TokenTypes.const_literal)) {
|
|
3817
4205
|
return new StringExpr(this._previous().toString());
|
|
4206
|
+
}
|
|
3818
4207
|
const type = this._type_decl();
|
|
3819
4208
|
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
3820
4209
|
let args = [];
|
|
3821
4210
|
while (!this._check(TokenTypes.tokens.paren_right)) {
|
|
3822
4211
|
args.push(this._const_expression());
|
|
3823
|
-
if (!this._check(TokenTypes.tokens.comma))
|
|
4212
|
+
if (!this._check(TokenTypes.tokens.comma)) {
|
|
3824
4213
|
break;
|
|
4214
|
+
}
|
|
3825
4215
|
this._advance();
|
|
3826
4216
|
}
|
|
3827
4217
|
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
3828
4218
|
return new CreateExpr(type, args);
|
|
3829
4219
|
}
|
|
3830
4220
|
_variable_decl() {
|
|
3831
|
-
if (!this._match(TokenTypes.keywords.var))
|
|
4221
|
+
if (!this._match(TokenTypes.keywords.var)) {
|
|
3832
4222
|
return null;
|
|
4223
|
+
}
|
|
3833
4224
|
let storage = "";
|
|
3834
4225
|
let access = "";
|
|
3835
4226
|
if (this._match(TokenTypes.tokens.less_than)) {
|
|
@@ -3843,28 +4234,47 @@ void main() {
|
|
|
3843
4234
|
if (this._match(TokenTypes.tokens.colon)) {
|
|
3844
4235
|
const attrs = this._attribute();
|
|
3845
4236
|
type = this._type_decl();
|
|
3846
|
-
if (type != null)
|
|
4237
|
+
if (type != null) {
|
|
3847
4238
|
type.attributes = attrs;
|
|
4239
|
+
}
|
|
3848
4240
|
}
|
|
3849
4241
|
return new Var(name.toString(), type, storage, access, null);
|
|
3850
4242
|
}
|
|
3851
4243
|
_override_decl() {
|
|
3852
|
-
if (!this._match(TokenTypes.keywords.override))
|
|
4244
|
+
if (!this._match(TokenTypes.keywords.override)) {
|
|
3853
4245
|
return null;
|
|
4246
|
+
}
|
|
3854
4247
|
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3855
4248
|
let type = null;
|
|
3856
4249
|
if (this._match(TokenTypes.tokens.colon)) {
|
|
3857
4250
|
const attrs = this._attribute();
|
|
3858
4251
|
type = this._type_decl();
|
|
3859
|
-
if (type != null)
|
|
4252
|
+
if (type != null) {
|
|
3860
4253
|
type.attributes = attrs;
|
|
4254
|
+
}
|
|
3861
4255
|
}
|
|
3862
4256
|
return new Override(name.toString(), type, null);
|
|
3863
4257
|
}
|
|
4258
|
+
_diagnostic() {
|
|
4259
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('");
|
|
4260
|
+
const severity = this._consume(TokenTypes.tokens.ident, "Expected severity control name.");
|
|
4261
|
+
this._consume(TokenTypes.tokens.comma, "Expected ','");
|
|
4262
|
+
const rule = this._consume(TokenTypes.tokens.ident, "Expected diagnostic rule name.");
|
|
4263
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
4264
|
+
return new Diagnostic(severity.toString(), rule.toString());
|
|
4265
|
+
}
|
|
3864
4266
|
_enable_directive() {
|
|
3865
4267
|
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
3866
4268
|
return new Enable(name.toString());
|
|
3867
4269
|
}
|
|
4270
|
+
_requires_directive() {
|
|
4271
|
+
const extensions = [this._consume(TokenTypes.tokens.ident, "identity expected.").toString()];
|
|
4272
|
+
while (this._match(TokenTypes.tokens.comma)) {
|
|
4273
|
+
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
4274
|
+
extensions.push(name.toString());
|
|
4275
|
+
}
|
|
4276
|
+
return new Requires(extensions);
|
|
4277
|
+
}
|
|
3868
4278
|
_type_alias() {
|
|
3869
4279
|
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
3870
4280
|
this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
|
|
@@ -3899,8 +4309,9 @@ void main() {
|
|
|
3899
4309
|
return new Type(type2.toString());
|
|
3900
4310
|
}
|
|
3901
4311
|
let type = this._texture_sampler_types();
|
|
3902
|
-
if (type)
|
|
4312
|
+
if (type) {
|
|
3903
4313
|
return type;
|
|
4314
|
+
}
|
|
3904
4315
|
if (this._check(TokenTypes.template_types)) {
|
|
3905
4316
|
let type2 = this._advance().toString();
|
|
3906
4317
|
let format = null;
|
|
@@ -3908,8 +4319,9 @@ void main() {
|
|
|
3908
4319
|
if (this._match(TokenTypes.tokens.less_than)) {
|
|
3909
4320
|
format = this._type_decl();
|
|
3910
4321
|
access = null;
|
|
3911
|
-
if (this._match(TokenTypes.tokens.comma))
|
|
4322
|
+
if (this._match(TokenTypes.tokens.comma)) {
|
|
3912
4323
|
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
4324
|
+
}
|
|
3913
4325
|
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for type.");
|
|
3914
4326
|
}
|
|
3915
4327
|
return new TemplateType(type2, format, access);
|
|
@@ -3921,8 +4333,9 @@ void main() {
|
|
|
3921
4333
|
this._consume(TokenTypes.tokens.comma, "Expected ',' for pointer.");
|
|
3922
4334
|
const decl = this._type_decl();
|
|
3923
4335
|
let access = null;
|
|
3924
|
-
if (this._match(TokenTypes.tokens.comma))
|
|
4336
|
+
if (this._match(TokenTypes.tokens.comma)) {
|
|
3925
4337
|
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
4338
|
+
}
|
|
3926
4339
|
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for pointer.");
|
|
3927
4340
|
return new PointerType(pointer, storage.toString(), decl, access);
|
|
3928
4341
|
}
|
|
@@ -3931,6 +4344,7 @@ void main() {
|
|
|
3931
4344
|
let format = null;
|
|
3932
4345
|
let countInt = -1;
|
|
3933
4346
|
const array = this._previous();
|
|
4347
|
+
let countNode = null;
|
|
3934
4348
|
if (this._match(TokenTypes.tokens.less_than)) {
|
|
3935
4349
|
format = this._type_decl();
|
|
3936
4350
|
if (this._context.aliases.has(format.name)) {
|
|
@@ -3938,21 +4352,32 @@ void main() {
|
|
|
3938
4352
|
}
|
|
3939
4353
|
let count = "";
|
|
3940
4354
|
if (this._match(TokenTypes.tokens.comma)) {
|
|
3941
|
-
|
|
3942
|
-
|
|
4355
|
+
countNode = this._shift_expression();
|
|
4356
|
+
try {
|
|
4357
|
+
count = countNode.evaluate(this._context).toString();
|
|
4358
|
+
countNode = null;
|
|
4359
|
+
} catch (e) {
|
|
4360
|
+
count = "1";
|
|
4361
|
+
}
|
|
3943
4362
|
}
|
|
3944
4363
|
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for array.");
|
|
3945
4364
|
countInt = count ? parseInt(count) : 0;
|
|
3946
4365
|
}
|
|
3947
|
-
|
|
4366
|
+
const arrayType = new ArrayType(array.toString(), attrs, format, countInt);
|
|
4367
|
+
if (countNode) {
|
|
4368
|
+
this._deferArrayCountEval.push({ arrayType, countNode });
|
|
4369
|
+
}
|
|
4370
|
+
return arrayType;
|
|
3948
4371
|
}
|
|
3949
4372
|
return null;
|
|
3950
4373
|
}
|
|
3951
4374
|
_texture_sampler_types() {
|
|
3952
|
-
if (this._match(TokenTypes.sampler_type))
|
|
4375
|
+
if (this._match(TokenTypes.sampler_type)) {
|
|
3953
4376
|
return new SamplerType(this._previous().toString(), null, null);
|
|
3954
|
-
|
|
4377
|
+
}
|
|
4378
|
+
if (this._match(TokenTypes.depth_texture_type)) {
|
|
3955
4379
|
return new SamplerType(this._previous().toString(), null, null);
|
|
4380
|
+
}
|
|
3956
4381
|
if (this._match(TokenTypes.sampled_texture_type) || this._match(TokenTypes.multisampled_texture_type)) {
|
|
3957
4382
|
const sampler = this._previous();
|
|
3958
4383
|
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
@@ -3992,31 +4417,9 @@ void main() {
|
|
|
3992
4417
|
}
|
|
3993
4418
|
attributes.push(attr);
|
|
3994
4419
|
}
|
|
3995
|
-
|
|
3996
|
-
if (!this._check(TokenTypes.tokens.attr_right)) {
|
|
3997
|
-
do {
|
|
3998
|
-
const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
3999
|
-
const attr = new Attribute(name.toString(), null);
|
|
4000
|
-
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
4001
|
-
attr.value = [
|
|
4002
|
-
this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString()
|
|
4003
|
-
];
|
|
4004
|
-
if (this._check(TokenTypes.tokens.comma)) {
|
|
4005
|
-
this._advance();
|
|
4006
|
-
do {
|
|
4007
|
-
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
4008
|
-
attr.value.push(v);
|
|
4009
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
4010
|
-
}
|
|
4011
|
-
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
4012
|
-
}
|
|
4013
|
-
attributes.push(attr);
|
|
4014
|
-
} while (this._match(TokenTypes.tokens.comma));
|
|
4015
|
-
}
|
|
4016
|
-
this._consume(TokenTypes.tokens.attr_right, "Expected ']]' after attribute declarations");
|
|
4017
|
-
}
|
|
4018
|
-
if (attributes.length == 0)
|
|
4420
|
+
if (attributes.length == 0) {
|
|
4019
4421
|
return null;
|
|
4422
|
+
}
|
|
4020
4423
|
return attributes;
|
|
4021
4424
|
}
|
|
4022
4425
|
};
|
|
@@ -4074,6 +4477,9 @@ void main() {
|
|
|
4074
4477
|
super(name, attributes);
|
|
4075
4478
|
this.members = [];
|
|
4076
4479
|
this.align = 0;
|
|
4480
|
+
this.startLine = -1;
|
|
4481
|
+
this.endLine = -1;
|
|
4482
|
+
this.inUse = false;
|
|
4077
4483
|
}
|
|
4078
4484
|
get isStruct() {
|
|
4079
4485
|
return true;
|
|
@@ -4179,6 +4585,11 @@ void main() {
|
|
|
4179
4585
|
this.stage = null;
|
|
4180
4586
|
this.inputs = [];
|
|
4181
4587
|
this.outputs = [];
|
|
4588
|
+
this.resources = [];
|
|
4589
|
+
this.startLine = -1;
|
|
4590
|
+
this.endLine = -1;
|
|
4591
|
+
this.inUse = false;
|
|
4592
|
+
this.calls = /* @__PURE__ */ new Set();
|
|
4182
4593
|
this.name = name;
|
|
4183
4594
|
this.stage = stage;
|
|
4184
4595
|
}
|
|
@@ -4198,6 +4609,14 @@ void main() {
|
|
|
4198
4609
|
this.id = id;
|
|
4199
4610
|
}
|
|
4200
4611
|
};
|
|
4612
|
+
var _FunctionResources = class {
|
|
4613
|
+
constructor(node) {
|
|
4614
|
+
this.resources = null;
|
|
4615
|
+
this.inUse = false;
|
|
4616
|
+
this.info = null;
|
|
4617
|
+
this.node = node;
|
|
4618
|
+
}
|
|
4619
|
+
};
|
|
4201
4620
|
var WgslReflect = class {
|
|
4202
4621
|
constructor(code) {
|
|
4203
4622
|
this.uniforms = [];
|
|
@@ -4208,7 +4627,9 @@ void main() {
|
|
|
4208
4627
|
this.overrides = [];
|
|
4209
4628
|
this.structs = [];
|
|
4210
4629
|
this.entry = new EntryFunctions();
|
|
4630
|
+
this.functions = [];
|
|
4211
4631
|
this._types = /* @__PURE__ */ new Map();
|
|
4632
|
+
this._functions = /* @__PURE__ */ new Map();
|
|
4212
4633
|
if (code) {
|
|
4213
4634
|
this.update(code);
|
|
4214
4635
|
}
|
|
@@ -4219,14 +4640,20 @@ void main() {
|
|
|
4219
4640
|
update(code) {
|
|
4220
4641
|
const parser = new WgslParser();
|
|
4221
4642
|
const ast = parser.parse(code);
|
|
4643
|
+
for (const node of ast) {
|
|
4644
|
+
if (node instanceof Function) {
|
|
4645
|
+
this._functions.set(node.name, new _FunctionResources(node));
|
|
4646
|
+
}
|
|
4647
|
+
}
|
|
4222
4648
|
for (const node of ast) {
|
|
4223
4649
|
if (node instanceof Struct) {
|
|
4224
4650
|
const info = this._getTypeInfo(node, null);
|
|
4225
4651
|
if (info instanceof StructInfo) {
|
|
4226
4652
|
this.structs.push(info);
|
|
4227
4653
|
}
|
|
4228
|
-
continue;
|
|
4229
4654
|
}
|
|
4655
|
+
}
|
|
4656
|
+
for (const node of ast) {
|
|
4230
4657
|
if (node instanceof Alias) {
|
|
4231
4658
|
this.aliases.push(this._getAliasInfo(node));
|
|
4232
4659
|
continue;
|
|
@@ -4285,8 +4712,15 @@ void main() {
|
|
|
4285
4712
|
const fragmentStage = this._getAttribute(node, "fragment");
|
|
4286
4713
|
const computeStage = this._getAttribute(node, "compute");
|
|
4287
4714
|
const stage = vertexStage || fragmentStage || computeStage;
|
|
4715
|
+
const fn = new FunctionInfo(node.name, stage === null || stage === void 0 ? void 0 : stage.name);
|
|
4716
|
+
fn.startLine = node.startLine;
|
|
4717
|
+
fn.endLine = node.endLine;
|
|
4718
|
+
this.functions.push(fn);
|
|
4719
|
+
this._functions.get(node.name).info = fn;
|
|
4288
4720
|
if (stage) {
|
|
4289
|
-
|
|
4721
|
+
this._functions.get(node.name).inUse = true;
|
|
4722
|
+
fn.inUse = true;
|
|
4723
|
+
fn.resources = this._findResources(node, !!stage);
|
|
4290
4724
|
fn.inputs = this._getInputs(node.args);
|
|
4291
4725
|
fn.outputs = this._getOutputs(node.returnType);
|
|
4292
4726
|
this.entry[stage.name].push(fn);
|
|
@@ -4294,16 +4728,180 @@ void main() {
|
|
|
4294
4728
|
continue;
|
|
4295
4729
|
}
|
|
4296
4730
|
}
|
|
4731
|
+
for (const fn of this._functions.values()) {
|
|
4732
|
+
if (fn.info) {
|
|
4733
|
+
fn.info.inUse = fn.inUse;
|
|
4734
|
+
this._addCalls(fn.node, fn.info.calls);
|
|
4735
|
+
}
|
|
4736
|
+
}
|
|
4737
|
+
for (const u of this.uniforms) {
|
|
4738
|
+
this._markStructsInUse(u.type);
|
|
4739
|
+
}
|
|
4740
|
+
for (const s of this.storage) {
|
|
4741
|
+
this._markStructsInUse(s.type);
|
|
4742
|
+
}
|
|
4743
|
+
}
|
|
4744
|
+
_markStructsInUse(type) {
|
|
4745
|
+
if (type.isStruct) {
|
|
4746
|
+
type.inUse = true;
|
|
4747
|
+
for (const m of type.members) {
|
|
4748
|
+
this._markStructsInUse(m.type);
|
|
4749
|
+
}
|
|
4750
|
+
} else if (type.isArray) {
|
|
4751
|
+
this._markStructsInUse(type.format);
|
|
4752
|
+
} else if (type.isTemplate) {
|
|
4753
|
+
this._markStructsInUse(type.format);
|
|
4754
|
+
} else {
|
|
4755
|
+
const alias = this._getAlias(type.name);
|
|
4756
|
+
if (alias) {
|
|
4757
|
+
this._markStructsInUse(alias);
|
|
4758
|
+
}
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
_addCalls(fn, calls) {
|
|
4762
|
+
var _a2;
|
|
4763
|
+
for (const call of fn.calls) {
|
|
4764
|
+
const info = (_a2 = this._functions.get(call.name)) === null || _a2 === void 0 ? void 0 : _a2.info;
|
|
4765
|
+
if (info) {
|
|
4766
|
+
calls.add(info);
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
/// Find a resource by its group and binding.
|
|
4771
|
+
findResource(group, binding) {
|
|
4772
|
+
for (const u of this.uniforms) {
|
|
4773
|
+
if (u.group == group && u.binding == binding) {
|
|
4774
|
+
return u;
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4777
|
+
for (const s of this.storage) {
|
|
4778
|
+
if (s.group == group && s.binding == binding) {
|
|
4779
|
+
return s;
|
|
4780
|
+
}
|
|
4781
|
+
}
|
|
4782
|
+
for (const t of this.textures) {
|
|
4783
|
+
if (t.group == group && t.binding == binding) {
|
|
4784
|
+
return t;
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
for (const s of this.samplers) {
|
|
4788
|
+
if (s.group == group && s.binding == binding) {
|
|
4789
|
+
return s;
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
return null;
|
|
4793
|
+
}
|
|
4794
|
+
_findResource(name) {
|
|
4795
|
+
for (const u of this.uniforms) {
|
|
4796
|
+
if (u.name == name) {
|
|
4797
|
+
return u;
|
|
4798
|
+
}
|
|
4799
|
+
}
|
|
4800
|
+
for (const s of this.storage) {
|
|
4801
|
+
if (s.name == name) {
|
|
4802
|
+
return s;
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4805
|
+
for (const t of this.textures) {
|
|
4806
|
+
if (t.name == name) {
|
|
4807
|
+
return t;
|
|
4808
|
+
}
|
|
4809
|
+
}
|
|
4810
|
+
for (const s of this.samplers) {
|
|
4811
|
+
if (s.name == name) {
|
|
4812
|
+
return s;
|
|
4813
|
+
}
|
|
4814
|
+
}
|
|
4815
|
+
return null;
|
|
4816
|
+
}
|
|
4817
|
+
_markStructsFromAST(type) {
|
|
4818
|
+
const info = this._getTypeInfo(type, null);
|
|
4819
|
+
this._markStructsInUse(info);
|
|
4820
|
+
}
|
|
4821
|
+
_findResources(fn, isEntry) {
|
|
4822
|
+
const resources = [];
|
|
4823
|
+
const self = this;
|
|
4824
|
+
const varStack = [];
|
|
4825
|
+
fn.search((node) => {
|
|
4826
|
+
if (node instanceof _BlockStart) {
|
|
4827
|
+
varStack.push({});
|
|
4828
|
+
} else if (node instanceof _BlockEnd) {
|
|
4829
|
+
varStack.pop();
|
|
4830
|
+
} else if (node instanceof Var) {
|
|
4831
|
+
const v = node;
|
|
4832
|
+
if (isEntry && v.type !== null) {
|
|
4833
|
+
this._markStructsFromAST(v.type);
|
|
4834
|
+
}
|
|
4835
|
+
if (varStack.length > 0) {
|
|
4836
|
+
varStack[varStack.length - 1][v.name] = v;
|
|
4837
|
+
}
|
|
4838
|
+
} else if (node instanceof CreateExpr) {
|
|
4839
|
+
const c = node;
|
|
4840
|
+
if (isEntry && c.type !== null) {
|
|
4841
|
+
this._markStructsFromAST(c.type);
|
|
4842
|
+
}
|
|
4843
|
+
} else if (node instanceof Let) {
|
|
4844
|
+
const v = node;
|
|
4845
|
+
if (isEntry && v.type !== null) {
|
|
4846
|
+
this._markStructsFromAST(v.type);
|
|
4847
|
+
}
|
|
4848
|
+
if (varStack.length > 0) {
|
|
4849
|
+
varStack[varStack.length - 1][v.name] = v;
|
|
4850
|
+
}
|
|
4851
|
+
} else if (node instanceof VariableExpr) {
|
|
4852
|
+
const v = node;
|
|
4853
|
+
if (varStack.length > 0) {
|
|
4854
|
+
const varInfo2 = varStack[varStack.length - 1][v.name];
|
|
4855
|
+
if (varInfo2) {
|
|
4856
|
+
return;
|
|
4857
|
+
}
|
|
4858
|
+
}
|
|
4859
|
+
const varInfo = self._findResource(v.name);
|
|
4860
|
+
if (varInfo) {
|
|
4861
|
+
resources.push(varInfo);
|
|
4862
|
+
}
|
|
4863
|
+
} else if (node instanceof CallExpr) {
|
|
4864
|
+
const c = node;
|
|
4865
|
+
const callFn = self._functions.get(c.name);
|
|
4866
|
+
if (callFn) {
|
|
4867
|
+
if (isEntry) {
|
|
4868
|
+
callFn.inUse = true;
|
|
4869
|
+
}
|
|
4870
|
+
fn.calls.add(callFn.node);
|
|
4871
|
+
if (callFn.resources === null) {
|
|
4872
|
+
callFn.resources = self._findResources(callFn.node, isEntry);
|
|
4873
|
+
}
|
|
4874
|
+
resources.push(...callFn.resources);
|
|
4875
|
+
}
|
|
4876
|
+
} else if (node instanceof Call) {
|
|
4877
|
+
const c = node;
|
|
4878
|
+
const callFn = self._functions.get(c.name);
|
|
4879
|
+
if (callFn) {
|
|
4880
|
+
if (isEntry) {
|
|
4881
|
+
callFn.inUse = true;
|
|
4882
|
+
}
|
|
4883
|
+
fn.calls.add(callFn.node);
|
|
4884
|
+
if (callFn.resources === null) {
|
|
4885
|
+
callFn.resources = self._findResources(callFn.node, isEntry);
|
|
4886
|
+
}
|
|
4887
|
+
resources.push(...callFn.resources);
|
|
4888
|
+
}
|
|
4889
|
+
}
|
|
4890
|
+
});
|
|
4891
|
+
return [...new Map(resources.map((r) => [r.name, r])).values()];
|
|
4297
4892
|
}
|
|
4298
4893
|
getBindGroups() {
|
|
4299
4894
|
const groups = [];
|
|
4300
4895
|
function _makeRoom(group, binding) {
|
|
4301
|
-
if (group >= groups.length)
|
|
4896
|
+
if (group >= groups.length) {
|
|
4302
4897
|
groups.length = group + 1;
|
|
4303
|
-
|
|
4898
|
+
}
|
|
4899
|
+
if (groups[group] === void 0) {
|
|
4304
4900
|
groups[group] = [];
|
|
4305
|
-
|
|
4901
|
+
}
|
|
4902
|
+
if (binding >= groups[group].length) {
|
|
4306
4903
|
groups[group].length = binding + 1;
|
|
4904
|
+
}
|
|
4307
4905
|
}
|
|
4308
4906
|
for (const u of this.uniforms) {
|
|
4309
4907
|
_makeRoom(u.group, u.binding);
|
|
@@ -4328,14 +4926,16 @@ void main() {
|
|
|
4328
4926
|
return groups;
|
|
4329
4927
|
}
|
|
4330
4928
|
_getOutputs(type, outputs = void 0) {
|
|
4331
|
-
if (outputs === void 0)
|
|
4929
|
+
if (outputs === void 0) {
|
|
4332
4930
|
outputs = [];
|
|
4931
|
+
}
|
|
4333
4932
|
if (type instanceof Struct) {
|
|
4334
4933
|
this._getStructOutputs(type, outputs);
|
|
4335
4934
|
} else {
|
|
4336
4935
|
const output = this._getOutputInfo(type);
|
|
4337
|
-
if (output !== null)
|
|
4936
|
+
if (output !== null) {
|
|
4338
4937
|
outputs.push(output);
|
|
4938
|
+
}
|
|
4339
4939
|
}
|
|
4340
4940
|
return outputs;
|
|
4341
4941
|
}
|
|
@@ -4365,15 +4965,17 @@ void main() {
|
|
|
4365
4965
|
return null;
|
|
4366
4966
|
}
|
|
4367
4967
|
_getInputs(args, inputs = void 0) {
|
|
4368
|
-
if (inputs === void 0)
|
|
4968
|
+
if (inputs === void 0) {
|
|
4369
4969
|
inputs = [];
|
|
4970
|
+
}
|
|
4370
4971
|
for (const arg of args) {
|
|
4371
4972
|
if (arg.type instanceof Struct) {
|
|
4372
4973
|
this._getStructInputs(arg.type, inputs);
|
|
4373
4974
|
} else {
|
|
4374
4975
|
const input = this._getInputInfo(arg);
|
|
4375
|
-
if (input !== null)
|
|
4976
|
+
if (input !== null) {
|
|
4376
4977
|
inputs.push(input);
|
|
4978
|
+
}
|
|
4377
4979
|
}
|
|
4378
4980
|
}
|
|
4379
4981
|
return inputs;
|
|
@@ -4384,8 +4986,9 @@ void main() {
|
|
|
4384
4986
|
this._getStructInputs(m.type, inputs);
|
|
4385
4987
|
} else {
|
|
4386
4988
|
const input = this._getInputInfo(m);
|
|
4387
|
-
if (input !== null)
|
|
4989
|
+
if (input !== null) {
|
|
4388
4990
|
inputs.push(input);
|
|
4991
|
+
}
|
|
4389
4992
|
}
|
|
4390
4993
|
}
|
|
4391
4994
|
}
|
|
@@ -4418,8 +5021,9 @@ void main() {
|
|
|
4418
5021
|
}
|
|
4419
5022
|
_getAlias(name) {
|
|
4420
5023
|
for (const a of this.aliases) {
|
|
4421
|
-
if (a.name == name)
|
|
5024
|
+
if (a.name == name) {
|
|
4422
5025
|
return a.type;
|
|
5026
|
+
}
|
|
4423
5027
|
}
|
|
4424
5028
|
return null;
|
|
4425
5029
|
}
|
|
@@ -4443,6 +5047,8 @@ void main() {
|
|
|
4443
5047
|
if (type instanceof Struct) {
|
|
4444
5048
|
const s = type;
|
|
4445
5049
|
const info2 = new StructInfo(s.name, attributes);
|
|
5050
|
+
info2.startLine = s.startLine;
|
|
5051
|
+
info2.endLine = s.endLine;
|
|
4446
5052
|
for (const m of s.members) {
|
|
4447
5053
|
const t = this._getTypeInfo(m.type, m.attributes);
|
|
4448
5054
|
info2.members.push(new MemberInfo(m.name, t, m.attributes));
|
|
@@ -4495,8 +5101,9 @@ void main() {
|
|
|
4495
5101
|
for (let mi = 0, ml = struct.members.length; mi < ml; ++mi) {
|
|
4496
5102
|
const member = struct.members[mi];
|
|
4497
5103
|
const sizeInfo = this._getTypeSize(member);
|
|
4498
|
-
if (!sizeInfo)
|
|
5104
|
+
if (!sizeInfo) {
|
|
4499
5105
|
continue;
|
|
5106
|
+
}
|
|
4500
5107
|
(_a2 = this._getAlias(member.type.name)) !== null && _a2 !== void 0 ? _a2 : member.type;
|
|
4501
5108
|
const align = sizeInfo.align;
|
|
4502
5109
|
const size = sizeInfo.size;
|
|
@@ -4513,12 +5120,14 @@ void main() {
|
|
|
4513
5120
|
}
|
|
4514
5121
|
_getTypeSize(type) {
|
|
4515
5122
|
var _a2;
|
|
4516
|
-
if (type === null || type === void 0)
|
|
5123
|
+
if (type === null || type === void 0) {
|
|
4517
5124
|
return null;
|
|
5125
|
+
}
|
|
4518
5126
|
const explicitSize = this._getAttributeNum(type.attributes, "size", 0);
|
|
4519
5127
|
const explicitAlign = this._getAttributeNum(type.attributes, "align", 0);
|
|
4520
|
-
if (type instanceof MemberInfo)
|
|
5128
|
+
if (type instanceof MemberInfo) {
|
|
4521
5129
|
type = type.type;
|
|
5130
|
+
}
|
|
4522
5131
|
if (type instanceof TypeInfo) {
|
|
4523
5132
|
const alias = this._getAlias(type.name);
|
|
4524
5133
|
if (alias !== null) {
|
|
@@ -4551,8 +5160,9 @@ void main() {
|
|
|
4551
5160
|
const N = arrayType.count;
|
|
4552
5161
|
const stride = this._getAttributeNum((_a2 = type === null || type === void 0 ? void 0 : type.attributes) !== null && _a2 !== void 0 ? _a2 : null, "stride", this._roundUp(align, size));
|
|
4553
5162
|
size = N * stride;
|
|
4554
|
-
if (explicitSize)
|
|
5163
|
+
if (explicitSize) {
|
|
4555
5164
|
size = explicitSize;
|
|
5165
|
+
}
|
|
4556
5166
|
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
4557
5167
|
}
|
|
4558
5168
|
if (type instanceof StructInfo) {
|
|
@@ -4589,18 +5199,21 @@ void main() {
|
|
|
4589
5199
|
}
|
|
4590
5200
|
_getAttribute(node, name) {
|
|
4591
5201
|
const obj = node;
|
|
4592
|
-
if (!obj || !obj["attributes"])
|
|
5202
|
+
if (!obj || !obj["attributes"]) {
|
|
4593
5203
|
return null;
|
|
5204
|
+
}
|
|
4594
5205
|
const attrs = obj["attributes"];
|
|
4595
5206
|
for (let a of attrs) {
|
|
4596
|
-
if (a.name == name)
|
|
5207
|
+
if (a.name == name) {
|
|
4597
5208
|
return a;
|
|
5209
|
+
}
|
|
4598
5210
|
}
|
|
4599
5211
|
return null;
|
|
4600
5212
|
}
|
|
4601
5213
|
_getAttributeNum(attributes, name, defaultValue) {
|
|
4602
|
-
if (attributes === null)
|
|
5214
|
+
if (attributes === null) {
|
|
4603
5215
|
return defaultValue;
|
|
5216
|
+
}
|
|
4604
5217
|
for (let a of attributes) {
|
|
4605
5218
|
if (a.name == name) {
|
|
4606
5219
|
let v = a !== null && a.value !== null ? a.value : defaultValue;
|
|
@@ -4660,10 +5273,10 @@ void main() {
|
|
|
4660
5273
|
}
|
|
4661
5274
|
for (const uniform of parsedWGSL.uniforms) {
|
|
4662
5275
|
const members = [];
|
|
4663
|
-
for (const
|
|
5276
|
+
for (const attribute of uniform.type?.members || []) {
|
|
4664
5277
|
members.push({
|
|
4665
|
-
name:
|
|
4666
|
-
type: getType(
|
|
5278
|
+
name: attribute.name,
|
|
5279
|
+
type: getType(attribute.type)
|
|
4667
5280
|
});
|
|
4668
5281
|
}
|
|
4669
5282
|
shaderLayout.bindings.push({
|
|
@@ -4683,7 +5296,7 @@ void main() {
|
|
|
4683
5296
|
const type = getType(wgslAttribute.type);
|
|
4684
5297
|
shaderLayout.attributes.push({
|
|
4685
5298
|
name: wgslAttribute.name,
|
|
4686
|
-
location: wgslAttribute.location,
|
|
5299
|
+
location: Number(wgslAttribute.location),
|
|
4687
5300
|
type
|
|
4688
5301
|
});
|
|
4689
5302
|
}
|
|
@@ -4723,17 +5336,11 @@ void main() {
|
|
|
4723
5336
|
printRowMajor: true,
|
|
4724
5337
|
_cartographicRadians: false
|
|
4725
5338
|
};
|
|
4726
|
-
globalThis.mathgl = globalThis.mathgl || {
|
|
4727
|
-
config: {
|
|
4728
|
-
...DEFAULT_CONFIG
|
|
4729
|
-
}
|
|
4730
|
-
};
|
|
5339
|
+
globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
|
|
4731
5340
|
var config = globalThis.mathgl.config;
|
|
4732
|
-
function formatValue(value, {
|
|
4733
|
-
precision = config.precision
|
|
4734
|
-
} = {}) {
|
|
5341
|
+
function formatValue(value, { precision = config.precision } = {}) {
|
|
4735
5342
|
value = round(value);
|
|
4736
|
-
return
|
|
5343
|
+
return `${parseFloat(value.toPrecision(precision))}`;
|
|
4737
5344
|
}
|
|
4738
5345
|
function isArray(value) {
|
|
4739
5346
|
return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
@@ -4777,28 +5384,12 @@ void main() {
|
|
|
4777
5384
|
}
|
|
4778
5385
|
|
|
4779
5386
|
// ../../node_modules/@math.gl/core/dist/classes/base/math-array.js
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
ExtendableBuiltin.prototype = Object.create(cls.prototype, {
|
|
4787
|
-
constructor: {
|
|
4788
|
-
value: cls,
|
|
4789
|
-
enumerable: false,
|
|
4790
|
-
writable: true,
|
|
4791
|
-
configurable: true
|
|
4792
|
-
}
|
|
4793
|
-
});
|
|
4794
|
-
if (Object.setPrototypeOf) {
|
|
4795
|
-
Object.setPrototypeOf(ExtendableBuiltin, cls);
|
|
4796
|
-
} else {
|
|
4797
|
-
ExtendableBuiltin.__proto__ = cls;
|
|
4798
|
-
}
|
|
4799
|
-
return ExtendableBuiltin;
|
|
4800
|
-
}
|
|
4801
|
-
var MathArray = class extends _extendableBuiltin(Array) {
|
|
5387
|
+
var MathArray = class extends Array {
|
|
5388
|
+
// Common methods
|
|
5389
|
+
/**
|
|
5390
|
+
* Clone the current object
|
|
5391
|
+
* @returns a new copy of this object
|
|
5392
|
+
*/
|
|
4802
5393
|
clone() {
|
|
4803
5394
|
return new this.constructor().copy(this);
|
|
4804
5395
|
}
|
|
@@ -4818,7 +5409,10 @@ void main() {
|
|
|
4818
5409
|
return targetObject;
|
|
4819
5410
|
}
|
|
4820
5411
|
from(arrayOrObject) {
|
|
4821
|
-
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) :
|
|
5412
|
+
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : (
|
|
5413
|
+
// @ts-ignore
|
|
5414
|
+
this.fromObject(arrayOrObject)
|
|
5415
|
+
);
|
|
4822
5416
|
}
|
|
4823
5417
|
to(arrayOrObject) {
|
|
4824
5418
|
if (arrayOrObject === this) {
|
|
@@ -4829,18 +5423,20 @@ void main() {
|
|
|
4829
5423
|
toTarget(target) {
|
|
4830
5424
|
return target ? this.to(target) : this;
|
|
4831
5425
|
}
|
|
5426
|
+
/** @deprecated */
|
|
4832
5427
|
toFloat32Array() {
|
|
4833
5428
|
return new Float32Array(this);
|
|
4834
5429
|
}
|
|
4835
5430
|
toString() {
|
|
4836
5431
|
return this.formatString(config);
|
|
4837
5432
|
}
|
|
5433
|
+
/** Formats string according to options */
|
|
4838
5434
|
formatString(opts) {
|
|
4839
5435
|
let string = "";
|
|
4840
5436
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4841
5437
|
string += (i > 0 ? ", " : "") + formatValue(this[i], opts);
|
|
4842
5438
|
}
|
|
4843
|
-
return
|
|
5439
|
+
return `${opts.printTypes ? this.constructor.name : ""}[${string}]`;
|
|
4844
5440
|
}
|
|
4845
5441
|
equals(array) {
|
|
4846
5442
|
if (!array || this.length !== array.length) {
|
|
@@ -4864,6 +5460,8 @@ void main() {
|
|
|
4864
5460
|
}
|
|
4865
5461
|
return true;
|
|
4866
5462
|
}
|
|
5463
|
+
// Modifiers
|
|
5464
|
+
/** Negates all values in this object */
|
|
4867
5465
|
negate() {
|
|
4868
5466
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4869
5467
|
this[i] = -this[i];
|
|
@@ -4881,12 +5479,14 @@ void main() {
|
|
|
4881
5479
|
}
|
|
4882
5480
|
return this.check();
|
|
4883
5481
|
}
|
|
5482
|
+
/** Minimal */
|
|
4884
5483
|
min(vector) {
|
|
4885
5484
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4886
5485
|
this[i] = Math.min(vector[i], this[i]);
|
|
4887
5486
|
}
|
|
4888
5487
|
return this.check();
|
|
4889
5488
|
}
|
|
5489
|
+
/** Maximal */
|
|
4890
5490
|
max(vector) {
|
|
4891
5491
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4892
5492
|
this[i] = Math.max(vector[i], this[i]);
|
|
@@ -4927,18 +5527,25 @@ void main() {
|
|
|
4927
5527
|
}
|
|
4928
5528
|
return this.check();
|
|
4929
5529
|
}
|
|
5530
|
+
/**
|
|
5531
|
+
* Multiplies all elements by `scale`
|
|
5532
|
+
* Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
|
|
5533
|
+
*/
|
|
4930
5534
|
multiplyByScalar(scalar) {
|
|
4931
5535
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4932
5536
|
this[i] *= scalar;
|
|
4933
5537
|
}
|
|
4934
5538
|
return this.check();
|
|
4935
5539
|
}
|
|
5540
|
+
// Debug checks
|
|
5541
|
+
/** Throws an error if array length is incorrect or contains illegal values */
|
|
4936
5542
|
check() {
|
|
4937
5543
|
if (config.debug && !this.validate()) {
|
|
4938
|
-
throw new Error(
|
|
5544
|
+
throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
|
|
4939
5545
|
}
|
|
4940
5546
|
return this;
|
|
4941
5547
|
}
|
|
5548
|
+
/** Returns false if the array length is incorrect or contains illegal values */
|
|
4942
5549
|
validate() {
|
|
4943
5550
|
let valid = this.length === this.ELEMENTS;
|
|
4944
5551
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
@@ -4946,39 +5553,48 @@ void main() {
|
|
|
4946
5553
|
}
|
|
4947
5554
|
return valid;
|
|
4948
5555
|
}
|
|
5556
|
+
// three.js compatibility
|
|
5557
|
+
/** @deprecated */
|
|
4949
5558
|
sub(a) {
|
|
4950
5559
|
return this.subtract(a);
|
|
4951
5560
|
}
|
|
5561
|
+
/** @deprecated */
|
|
4952
5562
|
setScalar(a) {
|
|
4953
5563
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4954
5564
|
this[i] = a;
|
|
4955
5565
|
}
|
|
4956
5566
|
return this.check();
|
|
4957
5567
|
}
|
|
5568
|
+
/** @deprecated */
|
|
4958
5569
|
addScalar(a) {
|
|
4959
5570
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4960
5571
|
this[i] += a;
|
|
4961
5572
|
}
|
|
4962
5573
|
return this.check();
|
|
4963
5574
|
}
|
|
5575
|
+
/** @deprecated */
|
|
4964
5576
|
subScalar(a) {
|
|
4965
5577
|
return this.addScalar(-a);
|
|
4966
5578
|
}
|
|
5579
|
+
/** @deprecated */
|
|
4967
5580
|
multiplyScalar(scalar) {
|
|
4968
5581
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4969
5582
|
this[i] *= scalar;
|
|
4970
5583
|
}
|
|
4971
5584
|
return this.check();
|
|
4972
5585
|
}
|
|
5586
|
+
/** @deprecated */
|
|
4973
5587
|
divideScalar(a) {
|
|
4974
5588
|
return this.multiplyByScalar(1 / a);
|
|
4975
5589
|
}
|
|
5590
|
+
/** @deprecated */
|
|
4976
5591
|
clampScalar(min, max) {
|
|
4977
5592
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4978
5593
|
this[i] = Math.min(Math.max(this[i], min), max);
|
|
4979
5594
|
}
|
|
4980
5595
|
return this.check();
|
|
4981
5596
|
}
|
|
5597
|
+
/** @deprecated */
|
|
4982
5598
|
get elements() {
|
|
4983
5599
|
return this;
|
|
4984
5600
|
}
|
|
@@ -4998,13 +5614,13 @@ void main() {
|
|
|
4998
5614
|
}
|
|
4999
5615
|
function checkNumber(value) {
|
|
5000
5616
|
if (!Number.isFinite(value)) {
|
|
5001
|
-
throw new Error(
|
|
5617
|
+
throw new Error(`Invalid number ${JSON.stringify(value)}`);
|
|
5002
5618
|
}
|
|
5003
5619
|
return value;
|
|
5004
5620
|
}
|
|
5005
5621
|
function checkVector(v, length, callerName = "") {
|
|
5006
5622
|
if (config.debug && !validateVector(v, length)) {
|
|
5007
|
-
throw new Error(
|
|
5623
|
+
throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
|
|
5008
5624
|
}
|
|
5009
5625
|
return v;
|
|
5010
5626
|
}
|
|
@@ -5012,12 +5628,13 @@ void main() {
|
|
|
5012
5628
|
// ../../node_modules/@math.gl/core/dist/lib/assert.js
|
|
5013
5629
|
function assert2(condition, message) {
|
|
5014
5630
|
if (!condition) {
|
|
5015
|
-
throw new Error(
|
|
5631
|
+
throw new Error(`math.gl assertion ${message}`);
|
|
5016
5632
|
}
|
|
5017
5633
|
}
|
|
5018
5634
|
|
|
5019
5635
|
// ../../node_modules/@math.gl/core/dist/classes/base/vector.js
|
|
5020
5636
|
var Vector = class extends MathArray {
|
|
5637
|
+
// ACCESSORS
|
|
5021
5638
|
get x() {
|
|
5022
5639
|
return this[0];
|
|
5023
5640
|
}
|
|
@@ -5030,12 +5647,24 @@ void main() {
|
|
|
5030
5647
|
set y(value) {
|
|
5031
5648
|
this[1] = checkNumber(value);
|
|
5032
5649
|
}
|
|
5650
|
+
/**
|
|
5651
|
+
* Returns the length of the vector from the origin to the point described by this vector
|
|
5652
|
+
*
|
|
5653
|
+
* @note `length` is a reserved word for Arrays, so `v.length()` will return number of elements
|
|
5654
|
+
* Instead we provide `len` and `magnitude`
|
|
5655
|
+
*/
|
|
5033
5656
|
len() {
|
|
5034
5657
|
return Math.sqrt(this.lengthSquared());
|
|
5035
5658
|
}
|
|
5659
|
+
/**
|
|
5660
|
+
* Returns the length of the vector from the origin to the point described by this vector
|
|
5661
|
+
*/
|
|
5036
5662
|
magnitude() {
|
|
5037
5663
|
return this.len();
|
|
5038
5664
|
}
|
|
5665
|
+
/**
|
|
5666
|
+
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
5667
|
+
*/
|
|
5039
5668
|
lengthSquared() {
|
|
5040
5669
|
let length = 0;
|
|
5041
5670
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
@@ -5043,6 +5672,9 @@ void main() {
|
|
|
5043
5672
|
}
|
|
5044
5673
|
return length;
|
|
5045
5674
|
}
|
|
5675
|
+
/**
|
|
5676
|
+
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
5677
|
+
*/
|
|
5046
5678
|
magnitudeSquared() {
|
|
5047
5679
|
return this.lengthSquared();
|
|
5048
5680
|
}
|
|
@@ -5064,6 +5696,7 @@ void main() {
|
|
|
5064
5696
|
}
|
|
5065
5697
|
return checkNumber(product);
|
|
5066
5698
|
}
|
|
5699
|
+
// MODIFIERS
|
|
5067
5700
|
normalize() {
|
|
5068
5701
|
const length = this.magnitude();
|
|
5069
5702
|
if (length !== 0) {
|
|
@@ -5089,6 +5722,7 @@ void main() {
|
|
|
5089
5722
|
}
|
|
5090
5723
|
return this.check();
|
|
5091
5724
|
}
|
|
5725
|
+
// THREE.js compatibility
|
|
5092
5726
|
lengthSq() {
|
|
5093
5727
|
return this.lengthSquared();
|
|
5094
5728
|
}
|
|
@@ -5361,6 +5995,12 @@ void main() {
|
|
|
5361
5995
|
}
|
|
5362
5996
|
return ZERO;
|
|
5363
5997
|
}
|
|
5998
|
+
/**
|
|
5999
|
+
* @class
|
|
6000
|
+
* @param x
|
|
6001
|
+
* @param y
|
|
6002
|
+
* @param z
|
|
6003
|
+
*/
|
|
5364
6004
|
constructor(x = 0, y = 0, z = 0) {
|
|
5365
6005
|
super(-0, -0, -0);
|
|
5366
6006
|
if (arguments.length === 1 && isArray(x)) {
|
|
@@ -5405,6 +6045,7 @@ void main() {
|
|
|
5405
6045
|
object.z = this[2];
|
|
5406
6046
|
return object;
|
|
5407
6047
|
}
|
|
6048
|
+
// Getters/setters
|
|
5408
6049
|
get ELEMENTS() {
|
|
5409
6050
|
return 3;
|
|
5410
6051
|
}
|
|
@@ -5414,41 +6055,38 @@ void main() {
|
|
|
5414
6055
|
set z(value) {
|
|
5415
6056
|
this[2] = checkNumber(value);
|
|
5416
6057
|
}
|
|
6058
|
+
// ACCESSORS
|
|
5417
6059
|
angle(vector) {
|
|
5418
6060
|
return angle(this, vector);
|
|
5419
6061
|
}
|
|
6062
|
+
// MODIFIERS
|
|
5420
6063
|
cross(vector) {
|
|
5421
6064
|
cross(this, this, vector);
|
|
5422
6065
|
return this.check();
|
|
5423
6066
|
}
|
|
5424
|
-
rotateX({
|
|
5425
|
-
radians,
|
|
5426
|
-
origin = ORIGIN
|
|
5427
|
-
}) {
|
|
6067
|
+
rotateX({ radians, origin = ORIGIN }) {
|
|
5428
6068
|
rotateX(this, this, origin, radians);
|
|
5429
6069
|
return this.check();
|
|
5430
6070
|
}
|
|
5431
|
-
rotateY({
|
|
5432
|
-
radians,
|
|
5433
|
-
origin = ORIGIN
|
|
5434
|
-
}) {
|
|
6071
|
+
rotateY({ radians, origin = ORIGIN }) {
|
|
5435
6072
|
rotateY(this, this, origin, radians);
|
|
5436
6073
|
return this.check();
|
|
5437
6074
|
}
|
|
5438
|
-
rotateZ({
|
|
5439
|
-
radians,
|
|
5440
|
-
origin = ORIGIN
|
|
5441
|
-
}) {
|
|
6075
|
+
rotateZ({ radians, origin = ORIGIN }) {
|
|
5442
6076
|
rotateZ(this, this, origin, radians);
|
|
5443
6077
|
return this.check();
|
|
5444
6078
|
}
|
|
6079
|
+
// Transforms
|
|
6080
|
+
// transforms as point (4th component is implicitly 1)
|
|
5445
6081
|
transform(matrix4) {
|
|
5446
6082
|
return this.transformAsPoint(matrix4);
|
|
5447
6083
|
}
|
|
6084
|
+
// transforms as point (4th component is implicitly 1)
|
|
5448
6085
|
transformAsPoint(matrix4) {
|
|
5449
6086
|
transformMat42(this, this, matrix4);
|
|
5450
6087
|
return this.check();
|
|
5451
6088
|
}
|
|
6089
|
+
// transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
|
|
5452
6090
|
transformAsVector(matrix4) {
|
|
5453
6091
|
vec3_transformMat4AsVector(this, this, matrix4);
|
|
5454
6092
|
return this.check();
|
|
@@ -5469,19 +6107,29 @@ void main() {
|
|
|
5469
6107
|
|
|
5470
6108
|
// ../../node_modules/@math.gl/core/dist/classes/base/matrix.js
|
|
5471
6109
|
var Matrix = class extends MathArray {
|
|
6110
|
+
// fromObject(object) {
|
|
6111
|
+
// const array = object.elements;
|
|
6112
|
+
// return this.fromRowMajor(array);
|
|
6113
|
+
// }
|
|
6114
|
+
// toObject(object) {
|
|
6115
|
+
// const array = object.elements;
|
|
6116
|
+
// this.toRowMajor(array);
|
|
6117
|
+
// return object;
|
|
6118
|
+
// }
|
|
6119
|
+
// TODO better override formatString?
|
|
5472
6120
|
toString() {
|
|
5473
6121
|
let string = "[";
|
|
5474
6122
|
if (config.printRowMajor) {
|
|
5475
6123
|
string += "row-major:";
|
|
5476
6124
|
for (let row = 0; row < this.RANK; ++row) {
|
|
5477
6125
|
for (let col = 0; col < this.RANK; ++col) {
|
|
5478
|
-
string +=
|
|
6126
|
+
string += ` ${this[col * this.RANK + row]}`;
|
|
5479
6127
|
}
|
|
5480
6128
|
}
|
|
5481
6129
|
} else {
|
|
5482
6130
|
string += "column-major:";
|
|
5483
6131
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
5484
|
-
string +=
|
|
6132
|
+
string += ` ${this[i]}`;
|
|
5485
6133
|
}
|
|
5486
6134
|
}
|
|
5487
6135
|
string += "]";
|
|
@@ -5490,9 +6138,11 @@ void main() {
|
|
|
5490
6138
|
getElementIndex(row, col) {
|
|
5491
6139
|
return col * this.RANK + row;
|
|
5492
6140
|
}
|
|
6141
|
+
// By default assumes row major indices
|
|
5493
6142
|
getElement(row, col) {
|
|
5494
6143
|
return this[col * this.RANK + row];
|
|
5495
6144
|
}
|
|
6145
|
+
// By default assumes row major indices
|
|
5496
6146
|
setElement(row, col, value) {
|
|
5497
6147
|
this[col * this.RANK + row] = checkNumber(value);
|
|
5498
6148
|
return this;
|
|
@@ -6258,6 +6908,7 @@ void main() {
|
|
|
6258
6908
|
this[15] = array[15];
|
|
6259
6909
|
return this.check();
|
|
6260
6910
|
}
|
|
6911
|
+
// eslint-disable-next-line max-params
|
|
6261
6912
|
set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
|
|
6262
6913
|
this[0] = m00;
|
|
6263
6914
|
this[1] = m10;
|
|
@@ -6277,6 +6928,8 @@ void main() {
|
|
|
6277
6928
|
this[15] = m33;
|
|
6278
6929
|
return this.check();
|
|
6279
6930
|
}
|
|
6931
|
+
// accepts row major order, stores as column major
|
|
6932
|
+
// eslint-disable-next-line max-params
|
|
6280
6933
|
setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
6281
6934
|
this[0] = m00;
|
|
6282
6935
|
this[1] = m10;
|
|
@@ -6315,25 +6968,41 @@ void main() {
|
|
|
6315
6968
|
result[15] = this[15];
|
|
6316
6969
|
return result;
|
|
6317
6970
|
}
|
|
6971
|
+
// Constructors
|
|
6972
|
+
/** Set to identity matrix */
|
|
6318
6973
|
identity() {
|
|
6319
6974
|
return this.copy(IDENTITY_MATRIX);
|
|
6320
6975
|
}
|
|
6976
|
+
/**
|
|
6977
|
+
*
|
|
6978
|
+
* @param object
|
|
6979
|
+
* @returns self
|
|
6980
|
+
*/
|
|
6981
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6321
6982
|
fromObject(object) {
|
|
6322
6983
|
return this.check();
|
|
6323
6984
|
}
|
|
6985
|
+
/**
|
|
6986
|
+
* Calculates a 4x4 matrix from the given quaternion
|
|
6987
|
+
* @param quaternion Quaternion to create matrix from
|
|
6988
|
+
* @returns self
|
|
6989
|
+
*/
|
|
6324
6990
|
fromQuaternion(quaternion) {
|
|
6325
6991
|
fromQuat(this, quaternion);
|
|
6326
6992
|
return this.check();
|
|
6327
6993
|
}
|
|
6994
|
+
/**
|
|
6995
|
+
* Generates a frustum matrix with the given bounds
|
|
6996
|
+
* @param view.left - Left bound of the frustum
|
|
6997
|
+
* @param view.right - Right bound of the frustum
|
|
6998
|
+
* @param view.bottom - Bottom bound of the frustum
|
|
6999
|
+
* @param view.top - Top bound of the frustum
|
|
7000
|
+
* @param view.near - Near bound of the frustum
|
|
7001
|
+
* @param view.far - Far bound of the frustum. Can be set to Infinity.
|
|
7002
|
+
* @returns self
|
|
7003
|
+
*/
|
|
6328
7004
|
frustum(view) {
|
|
6329
|
-
const {
|
|
6330
|
-
left,
|
|
6331
|
-
right,
|
|
6332
|
-
bottom,
|
|
6333
|
-
top,
|
|
6334
|
-
near = DEFAULT_NEAR,
|
|
6335
|
-
far = DEFAULT_FAR
|
|
6336
|
-
} = view;
|
|
7005
|
+
const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
6337
7006
|
if (far === Infinity) {
|
|
6338
7007
|
computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
|
|
6339
7008
|
} else {
|
|
@@ -6341,35 +7010,47 @@ void main() {
|
|
|
6341
7010
|
}
|
|
6342
7011
|
return this.check();
|
|
6343
7012
|
}
|
|
7013
|
+
/**
|
|
7014
|
+
* Generates a look-at matrix with the given eye position, focal point,
|
|
7015
|
+
* and up axis
|
|
7016
|
+
* @param view.eye - (vector) Position of the viewer
|
|
7017
|
+
* @param view.center - (vector) Point the viewer is looking at
|
|
7018
|
+
* @param view.up - (vector) Up axis
|
|
7019
|
+
* @returns self
|
|
7020
|
+
*/
|
|
6344
7021
|
lookAt(view) {
|
|
6345
|
-
const {
|
|
6346
|
-
eye,
|
|
6347
|
-
center = [0, 0, 0],
|
|
6348
|
-
up = [0, 1, 0]
|
|
6349
|
-
} = view;
|
|
7022
|
+
const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
|
|
6350
7023
|
lookAt(this, eye, center, up);
|
|
6351
7024
|
return this.check();
|
|
6352
7025
|
}
|
|
7026
|
+
/**
|
|
7027
|
+
* Generates a orthogonal projection matrix with the given bounds
|
|
7028
|
+
* from "traditional" view space parameters
|
|
7029
|
+
* @param view.left - Left bound of the frustum
|
|
7030
|
+
* @param view.right number Right bound of the frustum
|
|
7031
|
+
* @param view.bottom - Bottom bound of the frustum
|
|
7032
|
+
* @param view.top number Top bound of the frustum
|
|
7033
|
+
* @param view.near - Near bound of the frustum
|
|
7034
|
+
* @param view.far number Far bound of the frustum
|
|
7035
|
+
* @returns self
|
|
7036
|
+
*/
|
|
6353
7037
|
ortho(view) {
|
|
6354
|
-
const {
|
|
6355
|
-
left,
|
|
6356
|
-
right,
|
|
6357
|
-
bottom,
|
|
6358
|
-
top,
|
|
6359
|
-
near = DEFAULT_NEAR,
|
|
6360
|
-
far = DEFAULT_FAR
|
|
6361
|
-
} = view;
|
|
7038
|
+
const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
6362
7039
|
ortho(this, left, right, bottom, top, near, far);
|
|
6363
7040
|
return this.check();
|
|
6364
7041
|
}
|
|
7042
|
+
/**
|
|
7043
|
+
* Generates an orthogonal projection matrix with the same parameters
|
|
7044
|
+
* as a perspective matrix (plus focalDistance)
|
|
7045
|
+
* @param view.fovy Vertical field of view in radians
|
|
7046
|
+
* @param view.aspect Aspect ratio. Typically viewport width / viewport height
|
|
7047
|
+
* @param view.focalDistance Distance in the view frustum used for extent calculations
|
|
7048
|
+
* @param view.near Near bound of the frustum
|
|
7049
|
+
* @param view.far Far bound of the frustum
|
|
7050
|
+
* @returns self
|
|
7051
|
+
*/
|
|
6365
7052
|
orthographic(view) {
|
|
6366
|
-
const {
|
|
6367
|
-
fovy = DEFAULT_FOVY,
|
|
6368
|
-
aspect = DEFAULT_ASPECT,
|
|
6369
|
-
focalDistance = 1,
|
|
6370
|
-
near = DEFAULT_NEAR,
|
|
6371
|
-
far = DEFAULT_FAR
|
|
6372
|
-
} = view;
|
|
7053
|
+
const { fovy = DEFAULT_FOVY, aspect = DEFAULT_ASPECT, focalDistance = 1, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
6373
7054
|
checkRadians(fovy);
|
|
6374
7055
|
const halfY = fovy / 2;
|
|
6375
7056
|
const top = focalDistance * Math.tan(halfY);
|
|
@@ -6383,32 +7064,53 @@ void main() {
|
|
|
6383
7064
|
far
|
|
6384
7065
|
});
|
|
6385
7066
|
}
|
|
7067
|
+
/**
|
|
7068
|
+
* Generates a perspective projection matrix with the given bounds
|
|
7069
|
+
* @param view.fovy Vertical field of view in radians
|
|
7070
|
+
* @param view.aspect Aspect ratio. typically viewport width/height
|
|
7071
|
+
* @param view.near Near bound of the frustum
|
|
7072
|
+
* @param view.far Far bound of the frustum
|
|
7073
|
+
* @returns self
|
|
7074
|
+
*/
|
|
6386
7075
|
perspective(view) {
|
|
6387
|
-
const {
|
|
6388
|
-
fovy = 45 * Math.PI / 180,
|
|
6389
|
-
aspect = 1,
|
|
6390
|
-
near = 0.1,
|
|
6391
|
-
far = 500
|
|
6392
|
-
} = view;
|
|
7076
|
+
const { fovy = 45 * Math.PI / 180, aspect = 1, near = 0.1, far = 500 } = view;
|
|
6393
7077
|
checkRadians(fovy);
|
|
6394
7078
|
perspective(this, fovy, aspect, near, far);
|
|
6395
7079
|
return this.check();
|
|
6396
7080
|
}
|
|
7081
|
+
// Accessors
|
|
6397
7082
|
determinant() {
|
|
6398
7083
|
return determinant(this);
|
|
6399
7084
|
}
|
|
7085
|
+
/**
|
|
7086
|
+
* Extracts the non-uniform scale assuming the matrix is an affine transformation.
|
|
7087
|
+
* The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
|
|
7088
|
+
* @param result
|
|
7089
|
+
* @returns self
|
|
7090
|
+
*/
|
|
6400
7091
|
getScale(result = [-0, -0, -0]) {
|
|
6401
7092
|
result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
|
|
6402
7093
|
result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
|
|
6403
7094
|
result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
|
|
6404
7095
|
return result;
|
|
6405
7096
|
}
|
|
7097
|
+
/**
|
|
7098
|
+
* Gets the translation portion, assuming the matrix is a affine transformation matrix.
|
|
7099
|
+
* @param result
|
|
7100
|
+
* @returns self
|
|
7101
|
+
*/
|
|
6406
7102
|
getTranslation(result = [-0, -0, -0]) {
|
|
6407
7103
|
result[0] = this[12];
|
|
6408
7104
|
result[1] = this[13];
|
|
6409
7105
|
result[2] = this[14];
|
|
6410
7106
|
return result;
|
|
6411
7107
|
}
|
|
7108
|
+
/**
|
|
7109
|
+
* Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
|
|
7110
|
+
* @param result
|
|
7111
|
+
* @param scaleResult
|
|
7112
|
+
* @returns self
|
|
7113
|
+
*/
|
|
6412
7114
|
getRotation(result, scaleResult) {
|
|
6413
7115
|
result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
6414
7116
|
scaleResult = scaleResult || [-0, -0, -0];
|
|
@@ -6434,6 +7136,12 @@ void main() {
|
|
|
6434
7136
|
result[15] = 1;
|
|
6435
7137
|
return result;
|
|
6436
7138
|
}
|
|
7139
|
+
/**
|
|
7140
|
+
*
|
|
7141
|
+
* @param result
|
|
7142
|
+
* @param scaleResult
|
|
7143
|
+
* @returns self
|
|
7144
|
+
*/
|
|
6437
7145
|
getRotationMatrix3(result, scaleResult) {
|
|
6438
7146
|
result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
6439
7147
|
scaleResult = scaleResult || [-0, -0, -0];
|
|
@@ -6452,6 +7160,7 @@ void main() {
|
|
|
6452
7160
|
result[8] = this[10] * inverseScale2;
|
|
6453
7161
|
return result;
|
|
6454
7162
|
}
|
|
7163
|
+
// Modifiers
|
|
6455
7164
|
transpose() {
|
|
6456
7165
|
transpose(this, this);
|
|
6457
7166
|
return this.check();
|
|
@@ -6460,6 +7169,7 @@ void main() {
|
|
|
6460
7169
|
invert(this, this);
|
|
6461
7170
|
return this.check();
|
|
6462
7171
|
}
|
|
7172
|
+
// Operations
|
|
6463
7173
|
multiplyLeft(a) {
|
|
6464
7174
|
multiply(this, a, this);
|
|
6465
7175
|
return this.check();
|
|
@@ -6468,33 +7178,68 @@ void main() {
|
|
|
6468
7178
|
multiply(this, this, a);
|
|
6469
7179
|
return this.check();
|
|
6470
7180
|
}
|
|
7181
|
+
// Rotates a matrix by the given angle around the X axis
|
|
6471
7182
|
rotateX(radians) {
|
|
6472
7183
|
rotateX2(this, this, radians);
|
|
6473
7184
|
return this.check();
|
|
6474
7185
|
}
|
|
7186
|
+
// Rotates a matrix by the given angle around the Y axis.
|
|
6475
7187
|
rotateY(radians) {
|
|
6476
7188
|
rotateY2(this, this, radians);
|
|
6477
7189
|
return this.check();
|
|
6478
7190
|
}
|
|
7191
|
+
/**
|
|
7192
|
+
* Rotates a matrix by the given angle around the Z axis.
|
|
7193
|
+
* @param radians
|
|
7194
|
+
* @returns self
|
|
7195
|
+
*/
|
|
6479
7196
|
rotateZ(radians) {
|
|
6480
7197
|
rotateZ2(this, this, radians);
|
|
6481
7198
|
return this.check();
|
|
6482
7199
|
}
|
|
7200
|
+
/**
|
|
7201
|
+
*
|
|
7202
|
+
* @param param0
|
|
7203
|
+
* @returns self
|
|
7204
|
+
*/
|
|
6483
7205
|
rotateXYZ(angleXYZ) {
|
|
6484
7206
|
return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
|
|
6485
7207
|
}
|
|
7208
|
+
/**
|
|
7209
|
+
*
|
|
7210
|
+
* @param radians
|
|
7211
|
+
* @param axis
|
|
7212
|
+
* @returns self
|
|
7213
|
+
*/
|
|
6486
7214
|
rotateAxis(radians, axis) {
|
|
6487
7215
|
rotate(this, this, radians, axis);
|
|
6488
7216
|
return this.check();
|
|
6489
7217
|
}
|
|
7218
|
+
/**
|
|
7219
|
+
*
|
|
7220
|
+
* @param factor
|
|
7221
|
+
* @returns self
|
|
7222
|
+
*/
|
|
6490
7223
|
scale(factor) {
|
|
6491
7224
|
scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
|
|
6492
7225
|
return this.check();
|
|
6493
7226
|
}
|
|
7227
|
+
/**
|
|
7228
|
+
*
|
|
7229
|
+
* @param vec
|
|
7230
|
+
* @returns self
|
|
7231
|
+
*/
|
|
6494
7232
|
translate(vector) {
|
|
6495
7233
|
translate(this, this, vector);
|
|
6496
7234
|
return this.check();
|
|
6497
7235
|
}
|
|
7236
|
+
// Transforms
|
|
7237
|
+
/**
|
|
7238
|
+
* Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
|
|
7239
|
+
* @param vector
|
|
7240
|
+
* @param result
|
|
7241
|
+
* @returns self
|
|
7242
|
+
*/
|
|
6498
7243
|
transform(vector, result) {
|
|
6499
7244
|
if (vector.length === 4) {
|
|
6500
7245
|
result = transformMat43(result || [-0, -0, -0, -0], vector, this);
|
|
@@ -6503,10 +7248,14 @@ void main() {
|
|
|
6503
7248
|
}
|
|
6504
7249
|
return this.transformAsPoint(vector, result);
|
|
6505
7250
|
}
|
|
7251
|
+
/**
|
|
7252
|
+
* Transforms any 2 or 3 element array as point (w implicitly 1)
|
|
7253
|
+
* @param vector
|
|
7254
|
+
* @param result
|
|
7255
|
+
* @returns self
|
|
7256
|
+
*/
|
|
6506
7257
|
transformAsPoint(vector, result) {
|
|
6507
|
-
const {
|
|
6508
|
-
length
|
|
6509
|
-
} = vector;
|
|
7258
|
+
const { length } = vector;
|
|
6510
7259
|
let out;
|
|
6511
7260
|
switch (length) {
|
|
6512
7261
|
case 2:
|
|
@@ -6521,6 +7270,12 @@ void main() {
|
|
|
6521
7270
|
checkVector(out, vector.length);
|
|
6522
7271
|
return out;
|
|
6523
7272
|
}
|
|
7273
|
+
/**
|
|
7274
|
+
* Transforms any 2 or 3 element array as vector (w implicitly 0)
|
|
7275
|
+
* @param vector
|
|
7276
|
+
* @param result
|
|
7277
|
+
* @returns self
|
|
7278
|
+
*/
|
|
6524
7279
|
transformAsVector(vector, result) {
|
|
6525
7280
|
let out;
|
|
6526
7281
|
switch (vector.length) {
|
|
@@ -6536,15 +7291,19 @@ void main() {
|
|
|
6536
7291
|
checkVector(out, vector.length);
|
|
6537
7292
|
return out;
|
|
6538
7293
|
}
|
|
7294
|
+
/** @deprecated */
|
|
6539
7295
|
transformPoint(vector, result) {
|
|
6540
7296
|
return this.transformAsPoint(vector, result);
|
|
6541
7297
|
}
|
|
7298
|
+
/** @deprecated */
|
|
6542
7299
|
transformVector(vector, result) {
|
|
6543
7300
|
return this.transformAsPoint(vector, result);
|
|
6544
7301
|
}
|
|
7302
|
+
/** @deprecated */
|
|
6545
7303
|
transformDirection(vector, result) {
|
|
6546
7304
|
return this.transformAsVector(vector, result);
|
|
6547
7305
|
}
|
|
7306
|
+
// three.js math API compatibility
|
|
6548
7307
|
makeRotationX(radians) {
|
|
6549
7308
|
return this.identity().rotateX(radians);
|
|
6550
7309
|
}
|
|
@@ -6741,8 +7500,11 @@ void main() {
|
|
|
6741
7500
|
continue;
|
|
6742
7501
|
}
|
|
6743
7502
|
const oldUniforms = this.moduleUniforms[moduleName];
|
|
6744
|
-
const
|
|
7503
|
+
const oldBindings = this.moduleBindings[moduleName];
|
|
7504
|
+
const uniformsAndBindings = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]) || moduleProps;
|
|
7505
|
+
const { uniforms, bindings } = (0, import_core6.splitUniformsAndBindings)(uniformsAndBindings);
|
|
6745
7506
|
this.moduleUniforms[moduleName] = { ...oldUniforms, ...uniforms };
|
|
7507
|
+
this.moduleBindings[moduleName] = { ...oldBindings, ...bindings };
|
|
6746
7508
|
}
|
|
6747
7509
|
}
|
|
6748
7510
|
/** Merges all bindings for the shader (from the various modules) */
|
|
@@ -7269,6 +8031,7 @@ void main() {
|
|
|
7269
8031
|
/** Update uniform buffers from the model's shader inputs */
|
|
7270
8032
|
updateShaderInputs() {
|
|
7271
8033
|
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
|
|
8034
|
+
this.setBindings(this.shaderInputs.getBindings());
|
|
7272
8035
|
this.setNeedsRedraw("shaderInputs");
|
|
7273
8036
|
}
|
|
7274
8037
|
/**
|