@luma.gl/engine 9.1.0-alpha.1 → 9.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.dev.js CHANGED
@@ -235,15 +235,15 @@ var __exports__ = (() => {
235
235
  return this.values[this.endIndex];
236
236
  }
237
237
  _calculateKeys(time) {
238
- let index2 = 0;
238
+ let index = 0;
239
239
  const numKeys = this.times.length;
240
- for (index2 = 0; index2 < numKeys - 2; ++index2) {
241
- if (this.times[index2 + 1] > time) {
240
+ for (index = 0; index < numKeys - 2; ++index) {
241
+ if (this.times[index + 1] > time) {
242
242
  break;
243
243
  }
244
244
  }
245
- this.startIndex = index2;
246
- this.endIndex = index2 + 1;
245
+ this.startIndex = index;
246
+ this.endIndex = index + 1;
247
247
  const startTime = this.times[this.startIndex];
248
248
  const endTime = this.times[this.endIndex];
249
249
  this.factor = Math.min(Math.max(0, (time - startTime) / (endTime - startTime)), 1);
@@ -902,23 +902,6 @@ var __exports__ = (() => {
902
902
  }
903
903
  return propValidators;
904
904
  }
905
- function getValidatedProperties(properties, propValidators, errorMessage) {
906
- const validated = {};
907
- for (const [key, propsValidator] of Object.entries(propValidators)) {
908
- if (properties && key in properties && !propsValidator.private) {
909
- if (propsValidator.validate) {
910
- assert(
911
- propsValidator.validate(properties[key], propsValidator),
912
- `${errorMessage}: invalid ${key}`
913
- );
914
- }
915
- validated[key] = properties[key];
916
- } else {
917
- validated[key] = propsValidator.value;
918
- }
919
- }
920
- return validated;
921
- }
922
905
  function makePropValidator(propType) {
923
906
  let type = getTypeOf(propType);
924
907
  if (type !== "object") {
@@ -1063,148 +1046,63 @@ var __exports__ = (() => {
1063
1046
  return source;
1064
1047
  }
1065
1048
 
1066
- // ../shadertools/src/lib/shader-module/shader-module-instance.ts
1067
- var index = 1;
1068
- var ShaderModuleInstance = class {
1069
- name;
1070
- vs;
1071
- fs;
1072
- getModuleUniforms;
1073
- dependencies;
1074
- deprecations;
1075
- defines;
1076
- injections;
1077
- uniforms = {};
1078
- uniformTypes = {};
1079
- static instantiateModules(modules) {
1080
- return modules.map((module) => {
1081
- if (module instanceof ShaderModuleInstance) {
1082
- return module;
1083
- }
1084
- assert(
1085
- typeof module !== "string",
1086
- `Shader module use by name is deprecated. Import shader module '${JSON.stringify(
1087
- module
1088
- )}' and use it directly.`
1089
- );
1090
- if (!module.name) {
1091
- console.warn("shader module has no name");
1092
- module.name = `shader-module-${index++}`;
1093
- }
1094
- const moduleObject = new ShaderModuleInstance(module);
1095
- moduleObject.dependencies = ShaderModuleInstance.instantiateModules(
1096
- module.dependencies || []
1097
- );
1098
- return moduleObject;
1099
- });
1100
- }
1101
- constructor(props) {
1102
- const {
1103
- name,
1104
- vs,
1105
- fs,
1106
- dependencies = [],
1107
- uniformPropTypes = {},
1108
- getUniforms,
1109
- deprecations = [],
1110
- defines = {},
1111
- inject = {}
1112
- } = props;
1113
- assert(typeof name === "string");
1114
- this.name = name;
1115
- this.vs = vs;
1116
- this.fs = fs;
1117
- this.getModuleUniforms = getUniforms;
1118
- this.dependencies = ShaderModuleInstance.instantiateModules(dependencies);
1119
- this.deprecations = this._parseDeprecationDefinitions(deprecations);
1120
- this.defines = defines;
1121
- this.injections = normalizeInjections(inject);
1122
- if (uniformPropTypes) {
1123
- this.uniforms = makePropValidators(uniformPropTypes);
1124
- }
1125
- }
1126
- // Extracts the source code chunk for the specified shader type from the named shader module
1127
- getModuleSource(stage) {
1128
- let moduleSource;
1129
- switch (stage) {
1130
- case "vertex":
1131
- moduleSource = this.vs || "";
1132
- break;
1133
- case "fragment":
1134
- moduleSource = this.fs || "";
1135
- break;
1136
- default:
1137
- assert(false);
1138
- }
1139
- const moduleName = this.name.toUpperCase().replace(/[^0-9a-z]/gi, "_");
1140
- return `// ----- MODULE ${this.name} ---------------
1141
-
1142
- #define MODULE_${moduleName}
1143
- ${moduleSource}
1144
-
1145
- `;
1146
- }
1147
- getUniforms(userProps, uniforms) {
1148
- if (this.getModuleUniforms) {
1149
- return this.getModuleUniforms(userProps, uniforms);
1150
- }
1151
- return getValidatedProperties(userProps, this.uniforms, this.name);
1152
- }
1153
- getDefines() {
1154
- return this.defines;
1155
- }
1156
- // Warn about deprecated uniforms or functions
1157
- checkDeprecations(shaderSource, log6) {
1158
- this.deprecations.forEach((def) => {
1159
- if (def.regex?.test(shaderSource)) {
1160
- if (def.deprecated) {
1161
- log6.deprecated(def.old, def.new)();
1162
- } else {
1163
- log6.removed(def.old, def.new)();
1164
- }
1165
- }
1166
- });
1049
+ // ../shadertools/src/lib/shader-module/shader-module.ts
1050
+ function initializeShaderModules(modules) {
1051
+ modules.map((module) => initializeShaderModule(module));
1052
+ }
1053
+ function initializeShaderModule(module) {
1054
+ if (module.instance) {
1055
+ return;
1167
1056
  }
1168
- _parseDeprecationDefinitions(deprecations) {
1169
- deprecations.forEach((def) => {
1170
- switch (def.type) {
1171
- case "function":
1172
- def.regex = new RegExp(`\\b${def.old}\\(`);
1173
- break;
1174
- default:
1175
- def.regex = new RegExp(`${def.type} ${def.old};`);
1176
- }
1177
- });
1178
- return deprecations;
1057
+ initializeShaderModules(module.dependencies || []);
1058
+ const {
1059
+ uniformPropTypes = {},
1060
+ deprecations = [],
1061
+ // defines = {},
1062
+ inject = {}
1063
+ } = module;
1064
+ const instance = {
1065
+ normalizedInjections: normalizeInjections(inject),
1066
+ parsedDeprecations: parseDeprecationDefinitions(deprecations)
1067
+ };
1068
+ if (uniformPropTypes) {
1069
+ instance.propValidators = makePropValidators(uniformPropTypes);
1179
1070
  }
1180
- _defaultGetUniforms(opts = {}) {
1181
- const uniforms = {};
1182
- const propTypes = this.uniforms;
1183
- for (const key in propTypes) {
1184
- const propDef = propTypes[key];
1185
- if (key in opts && !propDef.private) {
1186
- if (propDef.validate) {
1187
- assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);
1188
- }
1189
- uniforms[key] = opts[key];
1071
+ module.instance = instance;
1072
+ }
1073
+ function checkShaderModuleDeprecations(shaderModule, shaderSource, log6) {
1074
+ shaderModule.deprecations?.forEach((def) => {
1075
+ if (def.regex?.test(shaderSource)) {
1076
+ if (def.deprecated) {
1077
+ log6.deprecated(def.old, def.new)();
1190
1078
  } else {
1191
- uniforms[key] = propDef.value;
1079
+ log6.removed(def.old, def.new)();
1192
1080
  }
1193
1081
  }
1194
- return uniforms;
1195
- }
1196
- };
1197
-
1198
- // ../shadertools/src/lib/shader-assembly/resolve-modules.ts
1199
- function resolveModules(modules) {
1200
- const instances = ShaderModuleInstance.instantiateModules(modules);
1201
- return getShaderDependencies(instances);
1082
+ });
1202
1083
  }
1203
- function getShaderDependencies(modules) {
1084
+ function parseDeprecationDefinitions(deprecations) {
1085
+ deprecations.forEach((def) => {
1086
+ switch (def.type) {
1087
+ case "function":
1088
+ def.regex = new RegExp(`\\b${def.old}\\(`);
1089
+ break;
1090
+ default:
1091
+ def.regex = new RegExp(`${def.type} ${def.old};`);
1092
+ }
1093
+ });
1094
+ return deprecations;
1095
+ }
1096
+
1097
+ // ../shadertools/src/lib/shader-module/shader-module-dependencies.ts
1098
+ function getShaderModuleDependencies(modules) {
1099
+ initializeShaderModules(modules);
1204
1100
  const moduleMap = {};
1205
1101
  const moduleDepth = {};
1206
1102
  getDependencyGraph({ modules, level: 0, moduleMap, moduleDepth });
1207
- return Object.keys(moduleDepth).sort((a, b) => moduleDepth[b] - moduleDepth[a]).map((name) => moduleMap[name]);
1103
+ const dependencies = Object.keys(moduleDepth).sort((a, b) => moduleDepth[b] - moduleDepth[a]).map((name) => moduleMap[name]);
1104
+ initializeShaderModules(dependencies);
1105
+ return dependencies;
1208
1106
  }
1209
1107
  function getDependencyGraph(options) {
1210
1108
  const { modules, level, moduleMap, moduleDepth } = options;
@@ -1407,7 +1305,7 @@ ${DECLARATION_INJECT_MARKER}
1407
1305
  precision highp float;
1408
1306
  `;
1409
1307
  function assembleWGSLShader(options) {
1410
- const modules = resolveModules(options.modules || []);
1308
+ const modules = getShaderModuleDependencies(options.modules || []);
1411
1309
  return {
1412
1310
  source: assembleShaderWGSL(options.platformInfo, {
1413
1311
  ...options,
@@ -1420,7 +1318,7 @@ precision highp float;
1420
1318
  }
1421
1319
  function assembleGLSLShaderPair(options) {
1422
1320
  const { vs, fs } = options;
1423
- const modules = resolveModules(options.modules || []);
1321
+ const modules = getShaderModuleDependencies(options.modules || []);
1424
1322
  return {
1425
1323
  vs: assembleShaderGLSL(options.platformInfo, {
1426
1324
  ...options,
@@ -1478,9 +1376,9 @@ precision highp float;
1478
1376
  const modulesToInject = platformInfo.type !== "webgpu" ? modules : [];
1479
1377
  for (const module of modulesToInject) {
1480
1378
  if (log6) {
1481
- module.checkDeprecations(coreSource, log6);
1379
+ checkShaderModuleDeprecations(module, coreSource, log6);
1482
1380
  }
1483
- const moduleSource = module.getModuleSource(stage, "wgsl");
1381
+ const moduleSource = getShaderModuleSource(module, stage);
1484
1382
  assembledSource += moduleSource;
1485
1383
  const injections = module.injections[stage];
1486
1384
  for (const key in injections) {
@@ -1524,7 +1422,7 @@ precision highp float;
1524
1422
  const coreSource = sourceLines.slice(1).join("\n");
1525
1423
  const allDefines = {};
1526
1424
  modules.forEach((module) => {
1527
- Object.assign(allDefines, module.getDefines());
1425
+ Object.assign(allDefines, module.defines);
1528
1426
  });
1529
1427
  Object.assign(allDefines, defines);
1530
1428
  let assembledSource = "";
@@ -1573,11 +1471,11 @@ ${getApplicationDefines(allDefines)}
1573
1471
  }
1574
1472
  for (const module of modules) {
1575
1473
  if (log6) {
1576
- module.checkDeprecations(coreSource, log6);
1474
+ checkShaderModuleDeprecations(module, coreSource, log6);
1577
1475
  }
1578
- const moduleSource = module.getModuleSource(stage);
1476
+ const moduleSource = getShaderModuleSource(module, stage);
1579
1477
  assembledSource += moduleSource;
1580
- const injections = module.injections[stage];
1478
+ const injections = module.instance?.normalizedInjections[stage] || {};
1581
1479
  for (const key in injections) {
1582
1480
  const match = /^(v|f)s:#([\w-]+)$/.exec(key);
1583
1481
  if (match) {
@@ -1606,7 +1504,7 @@ ${getApplicationDefines(allDefines)}
1606
1504
  return function getUniforms(opts) {
1607
1505
  const uniforms = {};
1608
1506
  for (const module of modules) {
1609
- const moduleUniforms = module.getUniforms(opts, uniforms);
1507
+ const moduleUniforms = module.getUniforms?.(opts, uniforms);
1610
1508
  Object.assign(uniforms, moduleUniforms);
1611
1509
  }
1612
1510
  return uniforms;
@@ -1631,6 +1529,32 @@ ${getApplicationDefines(allDefines)}
1631
1529
  }
1632
1530
  return sourceText;
1633
1531
  }
1532
+ function getShaderModuleSource(module, stage) {
1533
+ let moduleSource;
1534
+ switch (stage) {
1535
+ case "vertex":
1536
+ moduleSource = module.vs || "";
1537
+ break;
1538
+ case "fragment":
1539
+ moduleSource = module.fs || "";
1540
+ break;
1541
+ case "wgsl":
1542
+ moduleSource = module.source || "";
1543
+ break;
1544
+ default:
1545
+ assert(false);
1546
+ }
1547
+ if (!module.name) {
1548
+ throw new Error("Shader module must have a name");
1549
+ }
1550
+ const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, "_");
1551
+ return `// ----- MODULE ${module.name} ---------------
1552
+
1553
+ #define MODULE_${moduleName}
1554
+ ${moduleSource}
1555
+
1556
+ `;
1557
+ }
1634
1558
 
1635
1559
  // ../shadertools/src/lib/preprocessor/preprocessor.ts
1636
1560
  var IFDEF_REGEXP = /^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/;
@@ -1740,9 +1664,7 @@ ${getApplicationDefines(allDefines)}
1740
1664
  * Dedupe and combine with default modules
1741
1665
  */
1742
1666
  _getModuleList(appModules = []) {
1743
- const modules = new Array(
1744
- this._defaultModules.length + appModules.length
1745
- );
1667
+ const modules = new Array(this._defaultModules.length + appModules.length);
1746
1668
  const seen = {};
1747
1669
  let count = 0;
1748
1670
  for (let i = 0, len = this._defaultModules.length; i < len; ++i) {
@@ -1760,7 +1682,8 @@ ${getApplicationDefines(allDefines)}
1760
1682
  }
1761
1683
  }
1762
1684
  modules.length = count;
1763
- return ShaderModuleInstance.instantiateModules(modules);
1685
+ initializeShaderModules(modules);
1686
+ return modules;
1764
1687
  }
1765
1688
  };
1766
1689
  var ShaderAssembler = _ShaderAssembler;
@@ -3328,8 +3251,8 @@ void main() {
3328
3251
  const tk = this._peek();
3329
3252
  if (types instanceof Array) {
3330
3253
  const t = tk.type;
3331
- const index2 = types.indexOf(t);
3332
- return index2 != -1;
3254
+ const index = types.indexOf(t);
3255
+ return index != -1;
3333
3256
  }
3334
3257
  return tk.type == types;
3335
3258
  }
@@ -7479,7 +7402,7 @@ void main() {
7479
7402
  */
7480
7403
  // @ts-expect-error Fix typings
7481
7404
  constructor(modules) {
7482
- const allModules = resolveModules(Object.values(modules));
7405
+ const allModules = getShaderModuleDependencies(Object.values(modules));
7483
7406
  import_core7.log.log(
7484
7407
  1,
7485
7408
  "Creating ShaderInputs with modules",
@@ -8262,11 +8185,11 @@ void main() {
8262
8185
  function mergeBufferLayouts(layouts1, layouts2) {
8263
8186
  const layouts = [...layouts1];
8264
8187
  for (const attribute of layouts2) {
8265
- const index2 = layouts.findIndex((attribute2) => attribute2.name === attribute.name);
8266
- if (index2 < 0) {
8188
+ const index = layouts.findIndex((attribute2) => attribute2.name === attribute.name);
8189
+ if (index < 0) {
8267
8190
  layouts.push(attribute);
8268
8191
  } else {
8269
- layouts[index2] = attribute;
8192
+ layouts[index] = attribute;
8270
8193
  }
8271
8194
  }
8272
8195
  return layouts;
@@ -8458,8 +8381,8 @@ void main() {
8458
8381
  }
8459
8382
  // set texture filtering parameters on source textures.
8460
8383
  _setSourceTextureParameters() {
8461
- const index2 = this.currentIndex;
8462
- const { sourceTextures } = this.bindings[index2];
8384
+ const index = this.currentIndex;
8385
+ const { sourceTextures } = this.bindings[index];
8463
8386
  for (const name in sourceTextures) {
8464
8387
  sourceTextures[name].sampler = this.sampler;
8465
8388
  }
@@ -8941,13 +8864,13 @@ void main(void) {
8941
8864
  }
8942
8865
  for (let i = 0; i < nvertical + extra; i++) {
8943
8866
  for (let j = 0; j < nradial; j++) {
8944
- const index2 = (i * nradial + j) * 6;
8945
- indices[index2 + 0] = vertsAroundEdge * (i + 0) + 0 + j;
8946
- indices[index2 + 1] = vertsAroundEdge * (i + 0) + 1 + j;
8947
- indices[index2 + 2] = vertsAroundEdge * (i + 1) + 1 + j;
8948
- indices[index2 + 3] = vertsAroundEdge * (i + 0) + 0 + j;
8949
- indices[index2 + 4] = vertsAroundEdge * (i + 1) + 1 + j;
8950
- indices[index2 + 5] = vertsAroundEdge * (i + 1) + 0 + j;
8867
+ const index = (i * nradial + j) * 6;
8868
+ indices[index + 0] = vertsAroundEdge * (i + 0) + 0 + j;
8869
+ indices[index + 1] = vertsAroundEdge * (i + 0) + 1 + j;
8870
+ indices[index + 2] = vertsAroundEdge * (i + 1) + 1 + j;
8871
+ indices[index + 3] = vertsAroundEdge * (i + 0) + 0 + j;
8872
+ indices[index + 4] = vertsAroundEdge * (i + 1) + 1 + j;
8873
+ indices[index + 5] = vertsAroundEdge * (i + 1) + 0 + j;
8951
8874
  }
8952
8875
  }
8953
8876
  return {
@@ -9761,9 +9684,9 @@ void main(void) {
9761
9684
  }
9762
9685
  const unpackedValue = new value.constructor(vertexCount * size);
9763
9686
  for (let x = 0; x < vertexCount; ++x) {
9764
- const index2 = indices.value[x];
9687
+ const index = indices.value[x];
9765
9688
  for (let i = 0; i < size; i++) {
9766
- unpackedValue[x * size + i] = value[index2 * size + i];
9689
+ unpackedValue[x * size + i] = value[index * size + i];
9767
9690
  }
9768
9691
  }
9769
9692
  unpackedAttributes[attributeName] = { size, value: unpackedValue };
@@ -9845,13 +9768,13 @@ void main(void) {
9845
9768
  const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
9846
9769
  for (let z = 0; z < subdivisions2; z++) {
9847
9770
  for (let x = 0; x < subdivisions1; x++) {
9848
- const index2 = (z * subdivisions1 + x) * 6;
9849
- indices[index2 + 0] = (z + 0) * numVertsAcross + x;
9850
- indices[index2 + 1] = (z + 1) * numVertsAcross + x;
9851
- indices[index2 + 2] = (z + 0) * numVertsAcross + x + 1;
9852
- indices[index2 + 3] = (z + 1) * numVertsAcross + x;
9853
- indices[index2 + 4] = (z + 1) * numVertsAcross + x + 1;
9854
- indices[index2 + 5] = (z + 0) * numVertsAcross + x + 1;
9771
+ const index = (z * subdivisions1 + x) * 6;
9772
+ indices[index + 0] = (z + 0) * numVertsAcross + x;
9773
+ indices[index + 1] = (z + 1) * numVertsAcross + x;
9774
+ indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
9775
+ indices[index + 3] = (z + 1) * numVertsAcross + x;
9776
+ indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
9777
+ indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
9855
9778
  }
9856
9779
  }
9857
9780
  const geometry = {
@@ -9898,9 +9821,9 @@ void main(void) {
9898
9821
  for (let x = 0; x <= nlong; x++) {
9899
9822
  const u = x / nlong;
9900
9823
  const v = y / nlat;
9901
- const index2 = x + y * (nlong + 1);
9902
- const i2 = index2 * 2;
9903
- const i3 = index2 * 3;
9824
+ const index = x + y * (nlong + 1);
9825
+ const i2 = index * 2;
9826
+ const i3 = index * 3;
9904
9827
  const theta = longRange * u;
9905
9828
  const phi = latRange * v;
9906
9829
  const sinTheta = Math.sin(theta);
@@ -9924,13 +9847,13 @@ void main(void) {
9924
9847
  const numVertsAround = nlong + 1;
9925
9848
  for (let x = 0; x < nlong; x++) {
9926
9849
  for (let y = 0; y < nlat; y++) {
9927
- const index2 = (x * nlat + y) * 6;
9928
- indices[index2 + 0] = y * numVertsAround + x;
9929
- indices[index2 + 1] = y * numVertsAround + x + 1;
9930
- indices[index2 + 2] = (y + 1) * numVertsAround + x;
9931
- indices[index2 + 3] = (y + 1) * numVertsAround + x;
9932
- indices[index2 + 4] = y * numVertsAround + x + 1;
9933
- indices[index2 + 5] = (y + 1) * numVertsAround + x + 1;
9850
+ const index = (x * nlat + y) * 6;
9851
+ indices[index + 0] = y * numVertsAround + x;
9852
+ indices[index + 1] = y * numVertsAround + x + 1;
9853
+ indices[index + 2] = (y + 1) * numVertsAround + x;
9854
+ indices[index + 3] = (y + 1) * numVertsAround + x;
9855
+ indices[index + 4] = y * numVertsAround + x + 1;
9856
+ indices[index + 5] = (y + 1) * numVertsAround + x + 1;
9934
9857
  }
9935
9858
  }
9936
9859
  return {