@luma.gl/engine 9.4.2 → 10.0.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.
Files changed (48) hide show
  1. package/dist/animation-loop/animation-loop.d.ts +12 -5
  2. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  3. package/dist/animation-loop/animation-loop.js +3 -1
  4. package/dist/animation-loop/animation-loop.js.map +1 -1
  5. package/dist/animation-loop/animation-props.d.ts +3 -1
  6. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  7. package/dist/compute/computation.d.ts +12 -0
  8. package/dist/compute/computation.d.ts.map +1 -1
  9. package/dist/compute/computation.js +85 -22
  10. package/dist/compute/computation.js.map +1 -1
  11. package/dist/compute/kernel.d.ts +54 -0
  12. package/dist/compute/kernel.d.ts.map +1 -0
  13. package/dist/compute/kernel.js +103 -0
  14. package/dist/compute/kernel.js.map +1 -0
  15. package/dist/compute/render-kernel.d.ts +65 -0
  16. package/dist/compute/render-kernel.d.ts.map +1 -0
  17. package/dist/compute/render-kernel.js +129 -0
  18. package/dist/compute/render-kernel.js.map +1 -0
  19. package/dist/controls/orbit-controls.d.ts +9 -2
  20. package/dist/controls/orbit-controls.d.ts.map +1 -1
  21. package/dist/controls/orbit-controls.js +55 -8
  22. package/dist/controls/orbit-controls.js.map +1 -1
  23. package/dist/dist.dev.js +547 -358
  24. package/dist/dist.min.js +21 -21
  25. package/dist/index.cjs +479 -109
  26. package/dist/index.cjs.map +3 -3
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +2 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/model/model.d.ts +10 -0
  32. package/dist/model/model.d.ts.map +1 -1
  33. package/dist/model/model.js +129 -65
  34. package/dist/model/model.js.map +1 -1
  35. package/dist/passes/shader-pass-renderer.d.ts +12 -12
  36. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  37. package/dist/passes/shader-pass-renderer.js +17 -17
  38. package/dist/passes/shader-pass-renderer.js.map +1 -1
  39. package/package.json +6 -6
  40. package/src/animation-loop/animation-loop.ts +16 -7
  41. package/src/animation-loop/animation-props.ts +4 -1
  42. package/src/compute/computation.ts +83 -30
  43. package/src/compute/kernel.ts +146 -0
  44. package/src/compute/render-kernel.ts +192 -0
  45. package/src/controls/orbit-controls.ts +61 -9
  46. package/src/index.ts +12 -0
  47. package/src/model/model.ts +140 -85
  48. package/src/passes/shader-pass-renderer.ts +28 -25
package/dist/dist.dev.js CHANGED
@@ -82,6 +82,7 @@ var __exports__ = (() => {
82
82
  Geometry: () => Geometry,
83
83
  GroupNode: () => GroupNode,
84
84
  IcoSphereGeometry: () => IcoSphereGeometry,
85
+ Kernel: () => Kernel,
85
86
  KeyFrames: () => KeyFrames,
86
87
  LegacyPickingManager: () => LegacyPickingManager,
87
88
  Material: () => Material,
@@ -92,6 +93,7 @@ var __exports__ = (() => {
92
93
  PickingManager: () => PickingManager,
93
94
  PlaneGeometry: () => PlaneGeometry,
94
95
  PointLightModel: () => PointLightModel,
96
+ RenderKernel: () => RenderKernel,
95
97
  ScenegraphNode: () => ScenegraphNode,
96
98
  ShaderInputs: () => ShaderInputs,
97
99
  ShaderPassRenderer: () => ShaderPassRenderer,
@@ -1115,10 +1117,6 @@ var __exports__ = (() => {
1115
1117
  toTarget(target) {
1116
1118
  return target ? this.to(target) : this;
1117
1119
  }
1118
- /** @deprecated */
1119
- toFloat32Array() {
1120
- return new Float32Array(this);
1121
- }
1122
1120
  toString() {
1123
1121
  return this.formatString(config);
1124
1122
  }
@@ -1245,51 +1243,6 @@ var __exports__ = (() => {
1245
1243
  }
1246
1244
  return valid;
1247
1245
  }
1248
- // three.js compatibility
1249
- /** @deprecated */
1250
- sub(a) {
1251
- return this.subtract(a);
1252
- }
1253
- /** @deprecated */
1254
- setScalar(a) {
1255
- for (let i = 0; i < this.ELEMENTS; ++i) {
1256
- this[i] = a;
1257
- }
1258
- return this.check();
1259
- }
1260
- /** @deprecated */
1261
- addScalar(a) {
1262
- for (let i = 0; i < this.ELEMENTS; ++i) {
1263
- this[i] += a;
1264
- }
1265
- return this.check();
1266
- }
1267
- /** @deprecated */
1268
- subScalar(a) {
1269
- return this.addScalar(-a);
1270
- }
1271
- /** @deprecated */
1272
- multiplyScalar(scalar) {
1273
- for (let i = 0; i < this.ELEMENTS; ++i) {
1274
- this[i] *= scalar;
1275
- }
1276
- return this.check();
1277
- }
1278
- /** @deprecated */
1279
- divideScalar(a) {
1280
- return this.multiplyByScalar(1 / a);
1281
- }
1282
- /** @deprecated */
1283
- clampScalar(min, max) {
1284
- for (let i = 0; i < this.ELEMENTS; ++i) {
1285
- this[i] = Math.min(Math.max(this[i], min), max);
1286
- }
1287
- return this.check();
1288
- }
1289
- /** @deprecated */
1290
- get elements() {
1291
- return this;
1292
- }
1293
1246
  };
1294
1247
 
1295
1248
  // ../../node_modules/@math.gl/core/dist/lib/validators.js
@@ -1317,6 +1270,64 @@ var __exports__ = (() => {
1317
1270
  return v;
1318
1271
  }
1319
1272
 
1273
+ // ../../node_modules/@math.gl/core/dist/classes/base/matrix.js
1274
+ var Matrix = class extends MathArray {
1275
+ // fromObject(object) {
1276
+ // const array = object.elements;
1277
+ // return this.fromRowMajor(array);
1278
+ // }
1279
+ // toObject(object) {
1280
+ // const array = object.elements;
1281
+ // this.toRowMajor(array);
1282
+ // return object;
1283
+ // }
1284
+ // TODO better override formatString?
1285
+ toString() {
1286
+ let string = "[";
1287
+ if (config.printRowMajor) {
1288
+ string += "row-major:";
1289
+ for (let row = 0; row < this.RANK; ++row) {
1290
+ for (let col = 0; col < this.RANK; ++col) {
1291
+ string += ` ${this[col * this.RANK + row]}`;
1292
+ }
1293
+ }
1294
+ } else {
1295
+ string += "column-major:";
1296
+ for (let i = 0; i < this.ELEMENTS; ++i) {
1297
+ string += ` ${this[i]}`;
1298
+ }
1299
+ }
1300
+ string += "]";
1301
+ return string;
1302
+ }
1303
+ getElementIndex(row, col) {
1304
+ return col * this.RANK + row;
1305
+ }
1306
+ // By default assumes row major indices
1307
+ getElement(row, col) {
1308
+ return this[col * this.RANK + row];
1309
+ }
1310
+ // By default assumes row major indices
1311
+ setElement(row, col, value) {
1312
+ this[col * this.RANK + row] = checkNumber(value);
1313
+ return this;
1314
+ }
1315
+ getColumn(columnIndex, result = new Array(this.RANK).fill(-0)) {
1316
+ const firstIndex = columnIndex * this.RANK;
1317
+ for (let i = 0; i < this.RANK; ++i) {
1318
+ result[i] = this[firstIndex + i];
1319
+ }
1320
+ return result;
1321
+ }
1322
+ setColumn(columnIndex, columnVector) {
1323
+ const firstIndex = columnIndex * this.RANK;
1324
+ for (let i = 0; i < this.RANK; ++i) {
1325
+ this[firstIndex + i] = columnVector[i];
1326
+ }
1327
+ return this;
1328
+ }
1329
+ };
1330
+
1320
1331
  // ../../node_modules/@math.gl/core/dist/lib/assert.js
1321
1332
  function assert(condition, message) {
1322
1333
  if (!condition) {
@@ -1443,24 +1454,18 @@ var __exports__ = (() => {
1443
1454
  return this.copy(a).multiply(b);
1444
1455
  }
1445
1456
  addScaledVector(a, b) {
1446
- return this.add(new this.constructor(a).multiplyScalar(b));
1457
+ for (let i = 0; i < this.ELEMENTS; ++i) {
1458
+ this[i] += a[i] * b;
1459
+ }
1460
+ return this.check();
1447
1461
  }
1448
1462
  };
1449
1463
 
1450
1464
  // ../../node_modules/@math.gl/core/dist/gl-matrix/common.js
1451
1465
  var EPSILON = 1e-6;
1452
- var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
1453
1466
  var degree = Math.PI / 180;
1454
1467
 
1455
1468
  // ../../node_modules/@math.gl/core/dist/gl-matrix/vec2.js
1456
- function create() {
1457
- const out = new ARRAY_TYPE(2);
1458
- if (ARRAY_TYPE != Float32Array) {
1459
- out[0] = 0;
1460
- out[1] = 0;
1461
- }
1462
- return out;
1463
- }
1464
1469
  function transformMat4(out, a, m) {
1465
1470
  const x = a[0];
1466
1471
  const y = a[1];
@@ -1468,32 +1473,6 @@ var __exports__ = (() => {
1468
1473
  out[1] = m[1] * x + m[5] * y + m[13];
1469
1474
  return out;
1470
1475
  }
1471
- var forEach = (function() {
1472
- const vec = create();
1473
- return function(a, stride, offset, count, fn, arg) {
1474
- let i;
1475
- let l;
1476
- if (!stride) {
1477
- stride = 2;
1478
- }
1479
- if (!offset) {
1480
- offset = 0;
1481
- }
1482
- if (count) {
1483
- l = Math.min(count * stride + offset, a.length);
1484
- } else {
1485
- l = a.length;
1486
- }
1487
- for (i = offset; i < l; i += stride) {
1488
- vec[0] = a[i];
1489
- vec[1] = a[i + 1];
1490
- fn(vec, vec, arg);
1491
- a[i] = vec[0];
1492
- a[i + 1] = vec[1];
1493
- }
1494
- return a;
1495
- };
1496
- })();
1497
1476
 
1498
1477
  // ../../node_modules/@math.gl/core/dist/lib/gl-matrix-extras.js
1499
1478
  function vec2_transformMat4AsVector(out, a, m) {
@@ -1524,15 +1503,6 @@ var __exports__ = (() => {
1524
1503
  }
1525
1504
 
1526
1505
  // ../../node_modules/@math.gl/core/dist/gl-matrix/vec3.js
1527
- function create2() {
1528
- const out = new ARRAY_TYPE(3);
1529
- if (ARRAY_TYPE != Float32Array) {
1530
- out[0] = 0;
1531
- out[1] = 0;
1532
- out[2] = 0;
1533
- }
1534
- return out;
1535
- }
1536
1506
  function dot(a, b) {
1537
1507
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
1538
1508
  }
@@ -1647,34 +1617,6 @@ var __exports__ = (() => {
1647
1617
  const cosine = mag && dot(a, b) / mag;
1648
1618
  return Math.acos(Math.min(Math.max(cosine, -1), 1));
1649
1619
  }
1650
- var forEach2 = (function() {
1651
- const vec = create2();
1652
- return function(a, stride, offset, count, fn, arg) {
1653
- let i;
1654
- let l;
1655
- if (!stride) {
1656
- stride = 3;
1657
- }
1658
- if (!offset) {
1659
- offset = 0;
1660
- }
1661
- if (count) {
1662
- l = Math.min(count * stride + offset, a.length);
1663
- } else {
1664
- l = a.length;
1665
- }
1666
- for (i = offset; i < l; i += stride) {
1667
- vec[0] = a[i];
1668
- vec[1] = a[i + 1];
1669
- vec[2] = a[i + 2];
1670
- fn(vec, vec, arg);
1671
- a[i] = vec[0];
1672
- a[i + 1] = vec[1];
1673
- a[i + 2] = vec[2];
1674
- }
1675
- return a;
1676
- };
1677
- })();
1678
1620
 
1679
1621
  // ../../node_modules/@math.gl/core/dist/classes/vector3.js
1680
1622
  var ORIGIN = [0, 0, 0];
@@ -1797,64 +1739,6 @@ var __exports__ = (() => {
1797
1739
  }
1798
1740
  };
1799
1741
 
1800
- // ../../node_modules/@math.gl/core/dist/classes/base/matrix.js
1801
- var Matrix = class extends MathArray {
1802
- // fromObject(object) {
1803
- // const array = object.elements;
1804
- // return this.fromRowMajor(array);
1805
- // }
1806
- // toObject(object) {
1807
- // const array = object.elements;
1808
- // this.toRowMajor(array);
1809
- // return object;
1810
- // }
1811
- // TODO better override formatString?
1812
- toString() {
1813
- let string = "[";
1814
- if (config.printRowMajor) {
1815
- string += "row-major:";
1816
- for (let row = 0; row < this.RANK; ++row) {
1817
- for (let col = 0; col < this.RANK; ++col) {
1818
- string += ` ${this[col * this.RANK + row]}`;
1819
- }
1820
- }
1821
- } else {
1822
- string += "column-major:";
1823
- for (let i = 0; i < this.ELEMENTS; ++i) {
1824
- string += ` ${this[i]}`;
1825
- }
1826
- }
1827
- string += "]";
1828
- return string;
1829
- }
1830
- getElementIndex(row, col) {
1831
- return col * this.RANK + row;
1832
- }
1833
- // By default assumes row major indices
1834
- getElement(row, col) {
1835
- return this[col * this.RANK + row];
1836
- }
1837
- // By default assumes row major indices
1838
- setElement(row, col, value) {
1839
- this[col * this.RANK + row] = checkNumber(value);
1840
- return this;
1841
- }
1842
- getColumn(columnIndex, result = new Array(this.RANK).fill(-0)) {
1843
- const firstIndex = columnIndex * this.RANK;
1844
- for (let i = 0; i < this.RANK; ++i) {
1845
- result[i] = this[firstIndex + i];
1846
- }
1847
- return result;
1848
- }
1849
- setColumn(columnIndex, columnVector) {
1850
- const firstIndex = columnIndex * this.RANK;
1851
- for (let i = 0; i < this.RANK; ++i) {
1852
- this[firstIndex + i] = columnVector[i];
1853
- }
1854
- return this;
1855
- }
1856
- };
1857
-
1858
1742
  // ../../node_modules/@math.gl/core/dist/gl-matrix/mat4.js
1859
1743
  function identity(out) {
1860
1744
  out[0] = 1;
@@ -2480,16 +2364,6 @@ var __exports__ = (() => {
2480
2364
  }
2481
2365
 
2482
2366
  // ../../node_modules/@math.gl/core/dist/gl-matrix/vec4.js
2483
- function create3() {
2484
- const out = new ARRAY_TYPE(4);
2485
- if (ARRAY_TYPE != Float32Array) {
2486
- out[0] = 0;
2487
- out[1] = 0;
2488
- out[2] = 0;
2489
- out[3] = 0;
2490
- }
2491
- return out;
2492
- }
2493
2367
  function transformMat43(out, a, m) {
2494
2368
  const x = a[0];
2495
2369
  const y = a[1];
@@ -2501,36 +2375,6 @@ var __exports__ = (() => {
2501
2375
  out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
2502
2376
  return out;
2503
2377
  }
2504
- var forEach3 = (function() {
2505
- const vec = create3();
2506
- return function(a, stride, offset, count, fn, arg) {
2507
- let i;
2508
- let l;
2509
- if (!stride) {
2510
- stride = 4;
2511
- }
2512
- if (!offset) {
2513
- offset = 0;
2514
- }
2515
- if (count) {
2516
- l = Math.min(count * stride + offset, a.length);
2517
- } else {
2518
- l = a.length;
2519
- }
2520
- for (i = offset; i < l; i += stride) {
2521
- vec[0] = a[i];
2522
- vec[1] = a[i + 1];
2523
- vec[2] = a[i + 2];
2524
- vec[3] = a[i + 3];
2525
- fn(vec, vec, arg);
2526
- a[i] = vec[0];
2527
- a[i + 1] = vec[1];
2528
- a[i + 2] = vec[2];
2529
- a[i + 3] = vec[3];
2530
- }
2531
- return a;
2532
- };
2533
- })();
2534
2378
 
2535
2379
  // ../../node_modules/@math.gl/core/dist/classes/matrix4.js
2536
2380
  var INDICES;
@@ -2683,6 +2527,14 @@ var __exports__ = (() => {
2683
2527
  fromQuat(this, quaternion);
2684
2528
  return this.check();
2685
2529
  }
2530
+ /**
2531
+ * Sets this matrix from a 3x3 matrix, with zero translation.
2532
+ * @param matrix3 - 3x3 matrix in column-major order.
2533
+ * @returns This matrix.
2534
+ */
2535
+ fromMatrix3(matrix3) {
2536
+ return this.set(matrix3[0], matrix3[1], matrix3[2], 0, matrix3[3], matrix3[4], matrix3[5], 0, matrix3[6], matrix3[7], matrix3[8], 0, 0, 0, 0, 1);
2537
+ }
2686
2538
  /**
2687
2539
  * Generates a frustum matrix with the given bounds
2688
2540
  * @param view.left - Left bound of the frustum
@@ -2983,18 +2835,6 @@ var __exports__ = (() => {
2983
2835
  checkVector(out, vector.length);
2984
2836
  return out;
2985
2837
  }
2986
- /** @deprecated */
2987
- transformPoint(vector, result) {
2988
- return this.transformAsPoint(vector, result);
2989
- }
2990
- /** @deprecated */
2991
- transformVector(vector, result) {
2992
- return this.transformAsPoint(vector, result);
2993
- }
2994
- /** @deprecated */
2995
- transformDirection(vector, result) {
2996
- return this.transformAsVector(vector, result);
2997
- }
2998
2838
  // three.js math API compatibility
2999
2839
  makeRotationX(radians) {
3000
2840
  return this.identity().rotateX(radians);
@@ -3472,6 +3312,7 @@ var __exports__ = (() => {
3472
3312
  var AnimationLoop = class _AnimationLoop {
3473
3313
  static defaultAnimationLoopProps = {
3474
3314
  device: null,
3315
+ mobileQuality: void 0,
3475
3316
  onAddHTML: () => "",
3476
3317
  onInitialize: async () => null,
3477
3318
  onRender: () => {
@@ -3764,8 +3605,9 @@ var __exports__ = (() => {
3764
3605
  tock: 0,
3765
3606
  // Experimental
3766
3607
  animationFrame: null,
3767
- _mousePosition: null
3608
+ _mousePosition: null,
3768
3609
  // Event props
3610
+ mobileQuality: this.props.mobileQuality
3769
3611
  };
3770
3612
  }
3771
3613
  _getAnimationProps() {
@@ -4004,6 +3846,7 @@ var __exports__ = (() => {
4004
3846
  distance: 10,
4005
3847
  yaw: 0,
4006
3848
  pitch: 0.25,
3849
+ roll: 0,
4007
3850
  minDistance: 1,
4008
3851
  maxDistance: 100,
4009
3852
  minPitch: -Math.PI / 2 + 0.01,
@@ -4011,6 +3854,7 @@ var __exports__ = (() => {
4011
3854
  rotateSpeed: 6e-3,
4012
3855
  zoomSpeed: 1e-3,
4013
3856
  enabled: true,
3857
+ enableRotate: false,
4014
3858
  enableZoom: true,
4015
3859
  enablePan: false,
4016
3860
  panSpeed: 18e-4,
@@ -4022,11 +3866,13 @@ var __exports__ = (() => {
4022
3866
  props;
4023
3867
  yaw;
4024
3868
  pitch;
3869
+ roll;
4025
3870
  distance;
4026
3871
  dragging = false;
4027
3872
  activePointers = /* @__PURE__ */ new Map();
4028
3873
  lastPointer = [0, 0];
4029
3874
  previousPinchDistance = null;
3875
+ previousPinchAngle = null;
4030
3876
  previousTimeMilliseconds = null;
4031
3877
  previousCursor;
4032
3878
  previousTouchAction;
@@ -4036,6 +3882,7 @@ var __exports__ = (() => {
4036
3882
  this.props.target = [...this.props.target];
4037
3883
  this.yaw = this.props.yaw;
4038
3884
  this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
3885
+ this.roll = this.props.roll;
4039
3886
  this.distance = clampNumber(
4040
3887
  this.props.distance,
4041
3888
  this.props.minDistance,
@@ -4071,6 +3918,32 @@ var __exports__ = (() => {
4071
3918
  this.props.target[2] + horizontalDistance * Math.cos(this.yaw)
4072
3919
  ];
4073
3920
  }
3921
+ /** Returns the camera up direction after applying pitch and optional two-finger roll. */
3922
+ getUpDirection() {
3923
+ return this.getCameraFrame().up;
3924
+ }
3925
+ getCameraFrame() {
3926
+ const sineYaw = Math.sin(this.yaw);
3927
+ const cosineYaw = Math.cos(this.yaw);
3928
+ const sinePitch = Math.sin(this.pitch);
3929
+ const cosinePitch = Math.cos(this.pitch);
3930
+ const sineRoll = Math.sin(this.roll);
3931
+ const cosineRoll = Math.cos(this.roll);
3932
+ const right = [cosineYaw, 0, -sineYaw];
3933
+ const up = [-sinePitch * sineYaw, cosinePitch, -sinePitch * cosineYaw];
3934
+ return {
3935
+ right: [
3936
+ right[0] * cosineRoll - up[0] * sineRoll,
3937
+ right[1] * cosineRoll - up[1] * sineRoll,
3938
+ right[2] * cosineRoll - up[2] * sineRoll
3939
+ ],
3940
+ up: [
3941
+ up[0] * cosineRoll + right[0] * sineRoll,
3942
+ up[1] * cosineRoll + right[1] * sineRoll,
3943
+ up[2] * cosineRoll + right[2] * sineRoll
3944
+ ]
3945
+ };
3946
+ }
4074
3947
  /** Enables or pauses automatic rotation without losing the current manual angle. */
4075
3948
  setAutoRotate(autoRotate) {
4076
3949
  this.props.autoRotate = autoRotate;
@@ -4090,6 +3963,9 @@ var __exports__ = (() => {
4090
3963
  if (props.pitch !== void 0 || props.minPitch !== void 0 || props.maxPitch !== void 0) {
4091
3964
  this.pitch = clampNumber(props.pitch ?? this.pitch, this.props.minPitch, this.props.maxPitch);
4092
3965
  }
3966
+ if (props.roll !== void 0) {
3967
+ this.roll = props.roll;
3968
+ }
4093
3969
  if (props.distance !== void 0 || props.minDistance !== void 0 || props.maxDistance !== void 0) {
4094
3970
  this.distance = clampNumber(
4095
3971
  props.distance ?? this.distance,
@@ -4098,10 +3974,11 @@ var __exports__ = (() => {
4098
3974
  );
4099
3975
  }
4100
3976
  }
4101
- /** Restores the configured starting angle and zoom. */
3977
+ /** Restores the configured starting orbit, roll, and zoom. */
4102
3978
  reset() {
4103
3979
  this.yaw = this.props.yaw;
4104
3980
  this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
3981
+ this.roll = this.props.roll;
4105
3982
  this.distance = clampNumber(
4106
3983
  this.props.distance,
4107
3984
  this.props.minDistance,
@@ -4130,9 +4007,10 @@ var __exports__ = (() => {
4130
4007
  if (this.activePointers.size === 1) {
4131
4008
  this.lastPointer = [event.clientX, event.clientY];
4132
4009
  } else {
4133
- const { center, distance } = this.getMultiPointerState();
4010
+ const { center, distance, angle: angle2 } = this.getMultiPointerState();
4134
4011
  this.lastPointer = center;
4135
4012
  this.previousPinchDistance = distance;
4013
+ this.previousPinchAngle = distance > 0 ? angle2 : null;
4136
4014
  }
4137
4015
  this.canvas.setPointerCapture(event.pointerId);
4138
4016
  this.canvas.style.cursor = "grabbing";
@@ -4143,7 +4021,7 @@ var __exports__ = (() => {
4143
4021
  }
4144
4022
  this.activePointers.set(event.pointerId, [event.clientX, event.clientY]);
4145
4023
  if (this.activePointers.size > 1) {
4146
- const { center, distance } = this.getMultiPointerState();
4024
+ const { center, distance, angle: angle2 } = this.getMultiPointerState();
4147
4025
  if (this.props.enablePan) {
4148
4026
  this.panTarget(center[0] - this.lastPointer[0], center[1] - this.lastPointer[1]);
4149
4027
  }
@@ -4154,8 +4032,12 @@ var __exports__ = (() => {
4154
4032
  this.props.maxDistance
4155
4033
  );
4156
4034
  }
4035
+ if (this.props.enableRotate && this.previousPinchAngle !== null && distance > 0) {
4036
+ this.roll += normalizeAngleDelta(angle2 - this.previousPinchAngle);
4037
+ }
4157
4038
  this.lastPointer = center;
4158
4039
  this.previousPinchDistance = distance;
4040
+ this.previousPinchAngle = distance > 0 ? angle2 : null;
4159
4041
  return;
4160
4042
  }
4161
4043
  const deltaX = event.clientX - this.lastPointer[0];
@@ -4181,6 +4063,7 @@ var __exports__ = (() => {
4181
4063
  }
4182
4064
  this.activePointers.delete(event.pointerId);
4183
4065
  this.previousPinchDistance = null;
4066
+ this.previousPinchAngle = null;
4184
4067
  const remainingPointer = this.activePointers.entries().next().value;
4185
4068
  if (remainingPointer) {
4186
4069
  this.lastPointer = remainingPointer[1];
@@ -4197,6 +4080,7 @@ var __exports__ = (() => {
4197
4080
  }
4198
4081
  this.activePointers.clear();
4199
4082
  this.previousPinchDistance = null;
4083
+ this.previousPinchAngle = null;
4200
4084
  this.canvas.style.cursor = "grab";
4201
4085
  }
4202
4086
  getMultiPointerState() {
@@ -4205,15 +4089,17 @@ var __exports__ = (() => {
4205
4089
  const deltaY = secondPointer[1] - firstPointer[1];
4206
4090
  return {
4207
4091
  center: [(firstPointer[0] + secondPointer[0]) / 2, (firstPointer[1] + secondPointer[1]) / 2],
4208
- distance: Math.hypot(deltaX, deltaY)
4092
+ distance: Math.hypot(deltaX, deltaY),
4093
+ angle: Math.atan2(deltaY, deltaX)
4209
4094
  };
4210
4095
  }
4211
4096
  panTarget(deltaX, deltaY) {
4212
4097
  const panScale = this.distance * this.props.panSpeed;
4098
+ const { right, up } = this.getCameraFrame();
4213
4099
  this.props.target = [
4214
- this.props.target[0] - Math.cos(this.yaw) * deltaX * panScale,
4215
- this.props.target[1] + deltaY * panScale,
4216
- this.props.target[2] + Math.sin(this.yaw) * deltaX * panScale
4100
+ this.props.target[0] + (-right[0] * deltaX + up[0] * deltaY) * panScale,
4101
+ this.props.target[1] + (-right[1] * deltaX + up[1] * deltaY) * panScale,
4102
+ this.props.target[2] + (-right[2] * deltaX + up[2] * deltaY) * panScale
4217
4103
  ];
4218
4104
  }
4219
4105
  handleWheel = (event) => {
@@ -4233,6 +4119,9 @@ var __exports__ = (() => {
4233
4119
  function clampNumber(value, minimum, maximum) {
4234
4120
  return Math.min(Math.max(value, minimum), maximum);
4235
4121
  }
4122
+ function normalizeAngleDelta(angle2) {
4123
+ return Math.atan2(Math.sin(angle2), Math.cos(angle2));
4124
+ }
4236
4125
 
4237
4126
  // src/model/model.ts
4238
4127
  var import_core13 = __toESM(require_core(), 1);
@@ -5270,6 +5159,28 @@ var __exports__ = (() => {
5270
5159
  "depth32float-stencil8"
5271
5160
  ];
5272
5161
  var Model = class _Model {
5162
+ /** Creates a model while allowing the backend to compile its render pipeline asynchronously. */
5163
+ static async createAsync(device, props) {
5164
+ const ownsCompilation = !import_core13.PipelineFactory.getAsyncCompilation(device);
5165
+ const asyncCompilation = ownsCompilation ? import_core13.PipelineFactory.beginAsyncCompilation(device) : import_core13.PipelineFactory.getAsyncCompilation(device);
5166
+ let model;
5167
+ try {
5168
+ model = new _Model(device, props);
5169
+ } finally {
5170
+ if (ownsCompilation) import_core13.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
5171
+ }
5172
+ try {
5173
+ if (ownsCompilation) {
5174
+ await Promise.all(asyncCompilation);
5175
+ } else {
5176
+ await model._pipelineInitialization;
5177
+ }
5178
+ return model;
5179
+ } catch (error) {
5180
+ model.destroy();
5181
+ throw error;
5182
+ }
5183
+ }
5273
5184
  static defaultProps = {
5274
5185
  ...import_core13.RenderPipeline.defaultProps,
5275
5186
  source: void 0,
@@ -5381,6 +5292,7 @@ var __exports__ = (() => {
5381
5292
  /** "Time" of last draw. Monotonically increasing timestamp */
5382
5293
  _lastDrawTimestamp = -1;
5383
5294
  _bindingTable = [];
5295
+ _pipelineInitialization;
5384
5296
  get [Symbol.toStringTag]() {
5385
5297
  return "Model";
5386
5298
  }
@@ -5389,7 +5301,7 @@ var __exports__ = (() => {
5389
5301
  }
5390
5302
  constructor(device, props) {
5391
5303
  const defaultShaderAssembler = _Model.defaultProps.shaderAssembler;
5392
- const vertexCountSet = props.vertexCount !== void 0;
5304
+ const vertexCountSet = Object.hasOwn(props, "vertexCount");
5393
5305
  this.props = {
5394
5306
  ..._Model.defaultProps,
5395
5307
  ...props,
@@ -5485,45 +5397,42 @@ var __exports__ = (() => {
5485
5397
  }
5486
5398
  this.pipelineFactory = props.pipelineFactory || import_core13.PipelineFactory.getDefaultPipelineFactory(this.device);
5487
5399
  this.shaderFactory = props.shaderFactory || import_core13.ShaderFactory.getDefaultShaderFactory(this.device);
5488
- this.pipeline = this._updatePipeline();
5489
- this.vertexArray = device.createVertexArray({
5400
+ const asyncCompilation = import_core13.PipelineFactory.getAsyncCompilation(this.device);
5401
+ if (asyncCompilation) {
5402
+ this._pipelineInitialization = this._initializePipelineAsync(props);
5403
+ asyncCompilation.push(this._pipelineInitialization);
5404
+ } else {
5405
+ this.pipeline = this._updatePipeline();
5406
+ this._initializePipelineResources(props);
5407
+ }
5408
+ }
5409
+ async _initializePipelineAsync(props) {
5410
+ await this._updatePipelineAsync();
5411
+ this._initializePipelineResources(props);
5412
+ }
5413
+ _initializePipelineResources(props) {
5414
+ this.vertexArray = this.device.createVertexArray({
5490
5415
  shaderLayout: this.pipeline.shaderLayout,
5491
5416
  bufferLayout: this.pipeline.bufferLayout
5492
5417
  });
5493
- if (this._gpuGeometry) {
5494
- this._setGeometryAttributes(this._gpuGeometry);
5495
- }
5496
- if ("isInstanced" in props) {
5497
- this.isInstanced = props.isInstanced;
5498
- }
5499
- if (props.instanceCount) {
5500
- this.setInstanceCount(props.instanceCount);
5501
- }
5502
- if (props.vertexCount) {
5503
- this.setVertexCount(props.vertexCount);
5504
- }
5505
- if (props.indexBuffer) {
5506
- this.setIndexBuffer(props.indexBuffer);
5507
- }
5508
- if (props.attributes) {
5509
- this.setAttributes(props.attributes);
5510
- }
5511
- if (props.constantAttributes) {
5512
- this.setConstantAttributes(props.constantAttributes);
5513
- }
5514
- if (props.bindings) {
5515
- this.setBindings(props.bindings);
5516
- }
5517
- if (props.transformFeedback) {
5518
- this.transformFeedback = props.transformFeedback;
5519
- }
5418
+ if (this._gpuGeometry) this._setGeometryAttributes(this._gpuGeometry);
5419
+ if ("isInstanced" in props) this.isInstanced = props.isInstanced;
5420
+ if (props.instanceCount) this.setInstanceCount(props.instanceCount);
5421
+ if (props.vertexCount) this.setVertexCount(props.vertexCount);
5422
+ if (props.indexBuffer) this.setIndexBuffer(props.indexBuffer);
5423
+ if (props.attributes) this.setAttributes(props.attributes);
5424
+ if (props.constantAttributes) this.setConstantAttributes(props.constantAttributes);
5425
+ if (props.bindings) this.setBindings(props.bindings);
5426
+ if (props.transformFeedback) this.transformFeedback = props.transformFeedback;
5520
5427
  }
5521
5428
  destroy() {
5522
5429
  if (!this._destroyed) {
5523
- this.pipelineFactory.release(this.pipeline);
5524
- this.shaderFactory.release(this.pipeline.vs);
5525
- if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
5526
- this.shaderFactory.release(this.pipeline.fs);
5430
+ if (this.pipeline) {
5431
+ this.pipelineFactory.release(this.pipeline);
5432
+ this.shaderFactory.release(this.pipeline.vs);
5433
+ if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
5434
+ this.shaderFactory.release(this.pipeline.fs);
5435
+ }
5527
5436
  }
5528
5437
  this._uniformStore.destroy();
5529
5438
  this._gpuGeometry?.destroy();
@@ -5996,36 +5905,55 @@ var __exports__ = (() => {
5996
5905
  }
5997
5906
  /** Update pipeline if needed */
5998
5907
  _updatePipeline() {
5999
- if (this._pipelineNeedsUpdate) {
6000
- let prevShaderVs = null;
6001
- let prevShaderFs = null;
6002
- if (this.pipeline) {
6003
- import_core13.log.log(
6004
- 1,
6005
- `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`
6006
- )();
6007
- prevShaderVs = this.pipeline.vs;
6008
- prevShaderFs = this.pipeline.fs;
6009
- }
6010
- this._pipelineNeedsUpdate = false;
6011
- const vs4 = this.shaderFactory.createShader({
6012
- id: `${this.id}-vertex`,
6013
- stage: "vertex",
6014
- source: this.source || this.vs,
5908
+ const update = this._preparePipelineUpdate();
5909
+ if (update) {
5910
+ this.pipeline = this.pipelineFactory.createRenderPipeline(update.props);
5911
+ this._finishPipelineUpdate(update);
5912
+ }
5913
+ return this.pipeline;
5914
+ }
5915
+ /** Creates or replaces the render pipeline through the backend's asynchronous compilation path. */
5916
+ async _updatePipelineAsync() {
5917
+ const update = this._preparePipelineUpdate();
5918
+ if (update) {
5919
+ try {
5920
+ this.pipeline = await this.pipelineFactory.createRenderPipelineAsync(update.props);
5921
+ } catch (error) {
5922
+ this._releasePipelineShaders(update.vertexShader, update.fragmentShader);
5923
+ this._pipelineNeedsUpdate = "asynchronous pipeline creation failed";
5924
+ throw error;
5925
+ }
5926
+ this._finishPipelineUpdate(update);
5927
+ }
5928
+ return this.pipeline;
5929
+ }
5930
+ _preparePipelineUpdate() {
5931
+ if (!this._pipelineNeedsUpdate) return null;
5932
+ const previousVertexShader = this.pipeline?.vs ?? null;
5933
+ const previousFragmentShader = this.pipeline?.fs ?? null;
5934
+ if (this.pipeline) {
5935
+ import_core13.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
5936
+ }
5937
+ this._pipelineNeedsUpdate = false;
5938
+ const vertexShader = this.shaderFactory.createShader({
5939
+ id: `${this.id}-vertex`,
5940
+ stage: "vertex",
5941
+ source: this.source || this.vs,
5942
+ debugShaders: this.props.debugShaders
5943
+ });
5944
+ let fragmentShader = null;
5945
+ if (this.source) {
5946
+ fragmentShader = vertexShader;
5947
+ } else if (this.fs) {
5948
+ fragmentShader = this.shaderFactory.createShader({
5949
+ id: `${this.id}-fragment`,
5950
+ stage: "fragment",
5951
+ source: this.fs,
6015
5952
  debugShaders: this.props.debugShaders
6016
5953
  });
6017
- let fs4 = null;
6018
- if (this.source) {
6019
- fs4 = vs4;
6020
- } else if (this.fs) {
6021
- fs4 = this.shaderFactory.createShader({
6022
- id: `${this.id}-fragment`,
6023
- stage: "fragment",
6024
- source: this.source || this.fs,
6025
- debugShaders: this.props.debugShaders
6026
- });
6027
- }
6028
- this.pipeline = this.pipelineFactory.createRenderPipeline({
5954
+ }
5955
+ return {
5956
+ props: {
6029
5957
  ...this.props,
6030
5958
  bindings: void 0,
6031
5959
  bufferLayout: this.bufferLayout,
@@ -6034,19 +5962,27 @@ var __exports__ = (() => {
6034
5962
  topology: this.topology,
6035
5963
  parameters: this.parameters,
6036
5964
  bindGroups: void 0,
6037
- vs: vs4,
6038
- fs: fs4
6039
- });
6040
- this._attributeInfos = (0, import_core13.getAttributeInfosFromLayouts)(
6041
- this.pipeline.shaderLayout,
6042
- this.bufferLayout
6043
- );
6044
- if (prevShaderVs) this.shaderFactory.release(prevShaderVs);
6045
- if (prevShaderFs && prevShaderFs !== prevShaderVs) {
6046
- this.shaderFactory.release(prevShaderFs);
6047
- }
5965
+ vs: vertexShader,
5966
+ fs: fragmentShader
5967
+ },
5968
+ vertexShader,
5969
+ fragmentShader,
5970
+ previousVertexShader,
5971
+ previousFragmentShader
5972
+ };
5973
+ }
5974
+ _finishPipelineUpdate(update) {
5975
+ this._attributeInfos = (0, import_core13.getAttributeInfosFromLayouts)(
5976
+ this.pipeline.shaderLayout,
5977
+ this.bufferLayout
5978
+ );
5979
+ this._releasePipelineShaders(update.previousVertexShader, update.previousFragmentShader);
5980
+ }
5981
+ _releasePipelineShaders(vertexShader, fragmentShader) {
5982
+ if (vertexShader) this.shaderFactory.release(vertexShader);
5983
+ if (fragmentShader && fragmentShader !== vertexShader) {
5984
+ this.shaderFactory.release(fragmentShader);
6048
5985
  }
6049
- return this.pipeline;
6050
5986
  }
6051
5987
  /** Throttle draw call logging */
6052
5988
  _lastLogTime = 0;
@@ -10295,6 +10231,33 @@ void main(void) {
10295
10231
  var LOG_DRAW_PRIORITY2 = 2;
10296
10232
  var LOG_DRAW_TIMEOUT2 = 1e4;
10297
10233
  var Computation = class _Computation {
10234
+ /**
10235
+ * Creates a computation while allowing the backend to compile its pipeline asynchronously.
10236
+ *
10237
+ * Use this factory when several independent computations can be prepared together. Calling the
10238
+ * constructor remains the synchronous compatibility path.
10239
+ */
10240
+ static async createAsync(device, props) {
10241
+ const ownsCompilation = !import_core27.PipelineFactory.getAsyncCompilation(device);
10242
+ const asyncCompilation = ownsCompilation ? import_core27.PipelineFactory.beginAsyncCompilation(device) : import_core27.PipelineFactory.getAsyncCompilation(device);
10243
+ let computation;
10244
+ try {
10245
+ computation = new _Computation(device, props);
10246
+ } finally {
10247
+ if (ownsCompilation) import_core27.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
10248
+ }
10249
+ try {
10250
+ if (ownsCompilation) {
10251
+ await Promise.all(asyncCompilation);
10252
+ } else {
10253
+ await computation._pipelineInitialization;
10254
+ }
10255
+ return computation;
10256
+ } catch (error) {
10257
+ computation.destroy();
10258
+ throw error;
10259
+ }
10260
+ }
10298
10261
  static defaultProps = {
10299
10262
  ...import_core27.ComputePipeline.defaultProps,
10300
10263
  id: "unnamed",
@@ -10333,6 +10296,7 @@ void main(void) {
10333
10296
  _getModuleUniforms;
10334
10297
  props;
10335
10298
  _destroyed = false;
10299
+ _pipelineInitialization;
10336
10300
  constructor(device, props) {
10337
10301
  if (device.type !== "webgpu") {
10338
10302
  throw new Error("Computation is only supported in WebGPU");
@@ -10383,15 +10347,21 @@ void main(void) {
10383
10347
  this.props.shaderLayout || inferredShaderLayout || null,
10384
10348
  modules
10385
10349
  ) || null;
10386
- this.pipeline = this._updatePipeline();
10350
+ const asyncCompilation = import_core27.PipelineFactory.getAsyncCompilation(this.device);
10351
+ if (asyncCompilation) {
10352
+ this._pipelineInitialization = this._updatePipelineAsync();
10353
+ asyncCompilation.push(this._pipelineInitialization);
10354
+ } else {
10355
+ this.pipeline = this._updatePipeline();
10356
+ }
10387
10357
  if (props.bindings) {
10388
10358
  this.setBindings(props.bindings);
10389
10359
  }
10390
10360
  }
10391
10361
  destroy() {
10392
10362
  if (this._destroyed) return;
10393
- this.pipelineFactory.release(this.pipeline);
10394
- this.shaderFactory.release(this.shader);
10363
+ if (this.pipeline) this.pipelineFactory.release(this.pipeline);
10364
+ if (this.shader) this.shaderFactory.release(this.shader);
10395
10365
  this._uniformStore.destroy();
10396
10366
  this._destroyed = true;
10397
10367
  }
@@ -10486,32 +10456,47 @@ void main(void) {
10486
10456
  this._pipelineNeedsUpdate = this._pipelineNeedsUpdate || reason;
10487
10457
  }
10488
10458
  _updatePipeline() {
10489
- if (this._pipelineNeedsUpdate) {
10490
- let prevShader = null;
10491
- if (this.pipeline) {
10492
- import_core27.log.log(
10493
- 1,
10494
- `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`
10495
- )();
10496
- prevShader = this.shader;
10497
- }
10498
- this._pipelineNeedsUpdate = false;
10499
- this.shader = this.shaderFactory.createShader({
10500
- id: `${this.id}-fragment`,
10501
- stage: "compute",
10502
- source: this.source,
10503
- debugShaders: this.props.debugShaders
10504
- });
10505
- this.pipeline = this.pipelineFactory.createComputePipeline({
10506
- ...this.props,
10507
- shader: this.shader
10508
- });
10509
- if (prevShader) {
10510
- this.shaderFactory.release(prevShader);
10459
+ const update = this._preparePipelineUpdate();
10460
+ if (update) {
10461
+ this.pipeline = this.pipelineFactory.createComputePipeline(update.props);
10462
+ this._finishPipelineUpdate(update.previousShader);
10463
+ }
10464
+ return this.pipeline;
10465
+ }
10466
+ /** Creates or replaces the pipeline through the backend's asynchronous compilation path. */
10467
+ async _updatePipelineAsync() {
10468
+ const update = this._preparePipelineUpdate();
10469
+ if (update) {
10470
+ try {
10471
+ this.pipeline = await this.pipelineFactory.createComputePipelineAsync(update.props);
10472
+ } catch (error) {
10473
+ this.shaderFactory.release(this.shader);
10474
+ this.shader = update.previousShader;
10475
+ this._pipelineNeedsUpdate = "asynchronous pipeline creation failed";
10476
+ throw error;
10511
10477
  }
10478
+ this._finishPipelineUpdate(update.previousShader);
10512
10479
  }
10513
10480
  return this.pipeline;
10514
10481
  }
10482
+ _preparePipelineUpdate() {
10483
+ if (!this._pipelineNeedsUpdate) return null;
10484
+ const previousShader = this.pipeline ? this.shader : null;
10485
+ if (this.pipeline) {
10486
+ import_core27.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
10487
+ }
10488
+ this._pipelineNeedsUpdate = false;
10489
+ this.shader = this.shaderFactory.createShader({
10490
+ id: `${this.id}-fragment`,
10491
+ stage: "compute",
10492
+ source: this.source,
10493
+ debugShaders: this.props.debugShaders
10494
+ });
10495
+ return { props: { ...this.props, shader: this.shader }, previousShader };
10496
+ }
10497
+ _finishPipelineUpdate(previousShader) {
10498
+ if (previousShader) this.shaderFactory.release(previousShader);
10499
+ }
10515
10500
  /** Throttle draw call logging */
10516
10501
  _lastLogTime = 0;
10517
10502
  _logOpen = false;
@@ -10748,7 +10733,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
10748
10733
  passRenderer.resize(size);
10749
10734
  }
10750
10735
  }
10751
- /** Invalidates persistent pipeline targets without destroying their allocations. */
10736
+ /** Invalidates persistent composite-pass targets without destroying their allocations. */
10752
10737
  resetHistory() {
10753
10738
  for (const passRenderer of this.passRenderers) {
10754
10739
  passRenderer.resetHistory();
@@ -10889,11 +10874,11 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
10889
10874
  this.device = device;
10890
10875
  this.shaderInputs = shaderInputs;
10891
10876
  this.passDefinition = passDefinition;
10892
- if (isShaderPassPipeline(passDefinition)) {
10877
+ if (isCompositeShaderPass(passDefinition)) {
10893
10878
  validateRenderTargetNames(passDefinition.name, passDefinition.renderTargets || {});
10894
10879
  this.renderTargets = createManagedRenderTargets(device, passDefinition.renderTargets || {});
10895
10880
  if (supportsComputeOptimization(device, passDefinition)) {
10896
- this.computeRenderer = new PipelineComputeRenderer(
10881
+ this.computeRenderer = new CompositeShaderPassComputeRenderer(
10897
10882
  device,
10898
10883
  passDefinition.compute,
10899
10884
  this.renderTargets,
@@ -11041,13 +11026,13 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11041
11026
  }
11042
11027
  return resolvedBindings;
11043
11028
  }
11044
- createStepExecutions(pipeline, step, flipY) {
11029
+ createStepExecutions(compositeShaderPass, step, flipY) {
11045
11030
  validateShaderPassDoesNotOwnRenderTargets(
11046
11031
  step.shaderPass,
11047
- `${pipeline.name}/${step.shaderPass.name}`
11032
+ `${compositeShaderPass.name}/${step.shaderPass.name}`
11048
11033
  );
11049
11034
  return this.createPassExecutions(step.shaderPass, {
11050
- ownerName: `${pipeline.name}/${step.shaderPass.name}`,
11035
+ ownerName: `${compositeShaderPass.name}/${step.shaderPass.name}`,
11051
11036
  firstInputs: step.inputs,
11052
11037
  lastOutput: step.output,
11053
11038
  uniformOverrides: step.uniforms,
@@ -11091,7 +11076,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11091
11076
  return this.passDefinition.name;
11092
11077
  }
11093
11078
  };
11094
- var PipelineComputeRenderer = class {
11079
+ var CompositeShaderPassComputeRenderer = class {
11095
11080
  optimization;
11096
11081
  renderTargets;
11097
11082
  shaderInputs;
@@ -11226,14 +11211,14 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11226
11211
  };
11227
11212
  function getExecutableShaderPasses(shaderPasses) {
11228
11213
  return shaderPasses.flatMap(
11229
- (shaderPass) => isShaderPassPipeline(shaderPass) ? shaderPass.steps.map((step) => step.shaderPass) : [shaderPass]
11214
+ (shaderPass) => isCompositeShaderPass(shaderPass) ? shaderPass.steps.map((step) => step.shaderPass) : [shaderPass]
11230
11215
  );
11231
11216
  }
11232
- function isShaderPassPipeline(shaderPass) {
11217
+ function isCompositeShaderPass(shaderPass) {
11233
11218
  return "steps" in shaderPass;
11234
11219
  }
11235
- function supportsComputeOptimization(device, pipeline) {
11236
- const optimization = pipeline.compute;
11220
+ function supportsComputeOptimization(device, compositeShaderPass) {
11221
+ const optimization = compositeShaderPass.compute;
11237
11222
  if (!optimization || device.type !== "webgpu") {
11238
11223
  return false;
11239
11224
  }
@@ -11242,7 +11227,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11242
11227
  return false;
11243
11228
  }
11244
11229
  return outputNames.every((targetName) => {
11245
- const target = pipeline.renderTargets?.[targetName];
11230
+ const target = compositeShaderPass.renderTargets?.[targetName];
11246
11231
  if (!target?.storage) {
11247
11232
  return false;
11248
11233
  }
@@ -11254,7 +11239,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11254
11239
  const renderTargets = shaderPass.renderTargets;
11255
11240
  if (renderTargets && Object.keys(renderTargets).length > 0) {
11256
11241
  throw new Error(
11257
- `${ownerName}: ShaderPass.renderTargets is not supported; use ShaderPassPipeline.renderTargets instead`
11242
+ `${ownerName}: ShaderPass.renderTargets is not supported; use CompositeShaderPass.renderTargets instead`
11258
11243
  );
11259
11244
  }
11260
11245
  }
@@ -11443,8 +11428,212 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11443
11428
  return [sourceAspect / outputAspect, 1];
11444
11429
  }
11445
11430
 
11446
- // src/modules/picking/picking-manager.ts
11431
+ // src/compute/kernel.ts
11447
11432
  var import_core29 = __toESM(require_core(), 1);
11433
+ var Kernel = class _Kernel {
11434
+ /** Creates a kernel while allowing the backend to compile its pipeline asynchronously. */
11435
+ static async createAsync(device, props) {
11436
+ const ownsCompilation = !import_core29.PipelineFactory.getAsyncCompilation(device);
11437
+ const asyncCompilation = ownsCompilation ? import_core29.PipelineFactory.beginAsyncCompilation(device) : import_core29.PipelineFactory.getAsyncCompilation(device);
11438
+ let kernel;
11439
+ try {
11440
+ kernel = new _Kernel(device, props);
11441
+ } finally {
11442
+ if (ownsCompilation) import_core29.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
11443
+ }
11444
+ try {
11445
+ if (ownsCompilation) {
11446
+ await Promise.all(asyncCompilation);
11447
+ } else {
11448
+ await kernel._pipelineInitialization;
11449
+ }
11450
+ return kernel;
11451
+ } catch (error) {
11452
+ kernel.destroy();
11453
+ throw error;
11454
+ }
11455
+ }
11456
+ device;
11457
+ id;
11458
+ source;
11459
+ pipelineFactory;
11460
+ shaderFactory;
11461
+ shader;
11462
+ pipeline;
11463
+ _pipelineInitialization;
11464
+ _destroyed = false;
11465
+ constructor(device, props) {
11466
+ if (device.type !== "webgpu") {
11467
+ throw new Error("Kernel is only supported in WebGPU");
11468
+ }
11469
+ const { source: source4, pipelineFactory, shaderFactory, debugShaders, ...pipelineProps } = props;
11470
+ this.device = device;
11471
+ this.id = props.id ?? "kernel";
11472
+ this.source = source4;
11473
+ this.pipelineFactory = pipelineFactory ?? import_core29.PipelineFactory.getDefaultPipelineFactory(device);
11474
+ this.shaderFactory = shaderFactory ?? import_core29.ShaderFactory.getDefaultShaderFactory(device);
11475
+ this.shader = this.shaderFactory.createShader({
11476
+ id: `${this.id}-compute`,
11477
+ stage: "compute",
11478
+ source: this.source,
11479
+ debugShaders
11480
+ });
11481
+ const computePipelineProps = { ...pipelineProps, shader: this.shader };
11482
+ const asyncCompilation = import_core29.PipelineFactory.getAsyncCompilation(device);
11483
+ if (asyncCompilation) {
11484
+ const pipelineInitialization = this.pipelineFactory.createComputePipelineAsync(computePipelineProps);
11485
+ this._pipelineInitialization = pipelineInitialization;
11486
+ asyncCompilation.push(
11487
+ pipelineInitialization.then((pipeline) => {
11488
+ this.pipeline = pipeline;
11489
+ return pipeline;
11490
+ })
11491
+ );
11492
+ } else {
11493
+ this.pipeline = this.pipelineFactory.createComputePipeline(computePipelineProps);
11494
+ }
11495
+ }
11496
+ /** Applies per-dispatch bindings and records a direct compute dispatch. */
11497
+ dispatch(computePass, options) {
11498
+ this._setPipeline(computePass, options.bindings);
11499
+ computePass.dispatch(options.x, options.y, options.z);
11500
+ }
11501
+ /** Applies per-dispatch bindings and records a GPU-driven indirect compute dispatch. */
11502
+ dispatchIndirect(computePass, options) {
11503
+ this._setPipeline(computePass, options.bindings);
11504
+ computePass.dispatchIndirect(options.indirectBuffer, options.indirectOffset ?? 0);
11505
+ }
11506
+ destroy() {
11507
+ if (this._destroyed) return;
11508
+ if (this.pipeline) this.pipelineFactory.release(this.pipeline);
11509
+ this.shaderFactory.release(this.shader);
11510
+ this._destroyed = true;
11511
+ }
11512
+ _setPipeline(computePass, bindings = {}) {
11513
+ computePass.setPipeline(this.pipeline);
11514
+ computePass.setBindings(bindings);
11515
+ }
11516
+ };
11517
+
11518
+ // src/compute/render-kernel.ts
11519
+ var import_core30 = __toESM(require_core(), 1);
11520
+ var RenderKernel = class _RenderKernel {
11521
+ /** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
11522
+ static async createAsync(device, props) {
11523
+ const ownsCompilation = !import_core30.PipelineFactory.getAsyncCompilation(device);
11524
+ const asyncCompilation = ownsCompilation ? import_core30.PipelineFactory.beginAsyncCompilation(device) : import_core30.PipelineFactory.getAsyncCompilation(device);
11525
+ let kernel;
11526
+ try {
11527
+ kernel = new _RenderKernel(device, props);
11528
+ } finally {
11529
+ if (ownsCompilation) import_core30.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
11530
+ }
11531
+ try {
11532
+ if (ownsCompilation) {
11533
+ await Promise.all(asyncCompilation);
11534
+ } else {
11535
+ await kernel._pipelineInitialization;
11536
+ }
11537
+ return kernel;
11538
+ } catch (error) {
11539
+ kernel.destroy();
11540
+ throw error;
11541
+ }
11542
+ }
11543
+ device;
11544
+ id;
11545
+ vertexSource;
11546
+ fragmentSource;
11547
+ pipelineFactory;
11548
+ shaderFactory;
11549
+ vertexShader;
11550
+ fragmentShader;
11551
+ pipeline;
11552
+ _pipelineInitialization;
11553
+ _destroyed = false;
11554
+ constructor(device, props) {
11555
+ if (device.type !== "webgpu") {
11556
+ throw new Error("RenderKernel is only supported in WebGPU");
11557
+ }
11558
+ const {
11559
+ vertexSource,
11560
+ fragmentSource,
11561
+ pipelineFactory,
11562
+ shaderFactory,
11563
+ debugShaders,
11564
+ ...pipelineProps
11565
+ } = props;
11566
+ this.device = device;
11567
+ this.id = props.id ?? "render-kernel";
11568
+ this.vertexSource = vertexSource;
11569
+ this.fragmentSource = fragmentSource;
11570
+ this.pipelineFactory = pipelineFactory ?? import_core30.PipelineFactory.getDefaultPipelineFactory(device);
11571
+ this.shaderFactory = shaderFactory ?? import_core30.ShaderFactory.getDefaultShaderFactory(device);
11572
+ this.vertexShader = this.shaderFactory.createShader({
11573
+ id: `${this.id}-vertex`,
11574
+ stage: "vertex",
11575
+ source: this.vertexSource,
11576
+ debugShaders
11577
+ });
11578
+ this.fragmentShader = this.fragmentSource ? this.shaderFactory.createShader({
11579
+ id: `${this.id}-fragment`,
11580
+ stage: "fragment",
11581
+ source: this.fragmentSource,
11582
+ debugShaders
11583
+ }) : null;
11584
+ const renderPipelineProps = {
11585
+ ...pipelineProps,
11586
+ vs: this.vertexShader,
11587
+ fs: this.fragmentShader
11588
+ };
11589
+ const asyncCompilation = import_core30.PipelineFactory.getAsyncCompilation(device);
11590
+ if (asyncCompilation) {
11591
+ const pipelineInitialization = this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
11592
+ this._pipelineInitialization = pipelineInitialization;
11593
+ asyncCompilation.push(
11594
+ pipelineInitialization.then((pipeline) => {
11595
+ this.pipeline = pipeline;
11596
+ return pipeline;
11597
+ })
11598
+ );
11599
+ } else {
11600
+ this.pipeline = this.pipelineFactory.createRenderPipeline(renderPipelineProps);
11601
+ }
11602
+ }
11603
+ /** Applies per-draw bindings/vertex state and records a direct draw. */
11604
+ draw(renderPass, options) {
11605
+ const { bindings = {}, vertexArray, ...drawOptions } = options;
11606
+ this._setPipeline(renderPass, bindings, vertexArray);
11607
+ return renderPass.draw(drawOptions);
11608
+ }
11609
+ /** Applies per-draw state and records a non-indexed indirect draw. */
11610
+ drawIndirect(renderPass, options) {
11611
+ const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
11612
+ this._setPipeline(renderPass, bindings, vertexArray);
11613
+ renderPass.drawIndirect(indirectBuffer, indirectOffset);
11614
+ }
11615
+ /** Applies per-draw state and records an indexed indirect draw. */
11616
+ drawIndexedIndirect(renderPass, options) {
11617
+ const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
11618
+ this._setPipeline(renderPass, bindings, vertexArray);
11619
+ renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
11620
+ }
11621
+ destroy() {
11622
+ if (this._destroyed) return;
11623
+ if (this.pipeline) this.pipelineFactory.release(this.pipeline);
11624
+ this.shaderFactory.release(this.vertexShader);
11625
+ if (this.fragmentShader) this.shaderFactory.release(this.fragmentShader);
11626
+ this._destroyed = true;
11627
+ }
11628
+ _setPipeline(renderPass, bindings, vertexArray) {
11629
+ renderPass.setPipeline(this.pipeline);
11630
+ renderPass.setBindings(bindings);
11631
+ renderPass.setVertexArray(vertexArray);
11632
+ }
11633
+ };
11634
+
11635
+ // src/modules/picking/picking-manager.ts
11636
+ var import_core31 = __toESM(require_core(), 1);
11448
11637
 
11449
11638
  // src/modules/picking/picking-uniforms.ts
11450
11639
  var DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
@@ -11708,13 +11897,13 @@ layout(std140) uniform pickingUniforms {
11708
11897
  format: "rgba8unorm",
11709
11898
  width: 1,
11710
11899
  height: 1,
11711
- usage: import_core29.Texture.RENDER_ATTACHMENT
11900
+ usage: import_core31.Texture.RENDER_ATTACHMENT
11712
11901
  });
11713
11902
  const pickingTexture = this.device.createTexture({
11714
11903
  format: "rg32sint",
11715
11904
  width: 1,
11716
11905
  height: 1,
11717
- usage: import_core29.Texture.RENDER_ATTACHMENT | import_core29.Texture.COPY_SRC
11906
+ usage: import_core31.Texture.RENDER_ATTACHMENT | import_core31.Texture.COPY_SRC
11718
11907
  });
11719
11908
  return this.device.createFramebuffer({
11720
11909
  colorAttachments: [colorTexture, pickingTexture],
@@ -11726,7 +11915,7 @@ layout(std140) uniform pickingUniforms {
11726
11915
  format: "rgba8unorm",
11727
11916
  width: 1,
11728
11917
  height: 1,
11729
- usage: import_core29.Texture.RENDER_ATTACHMENT | import_core29.Texture.COPY_SRC
11918
+ usage: import_core31.Texture.RENDER_ATTACHMENT | import_core31.Texture.COPY_SRC
11730
11919
  });
11731
11920
  return this.device.createFramebuffer({
11732
11921
  colorAttachments: [pickingTexture],
@@ -11748,7 +11937,7 @@ layout(std140) uniform pickingUniforms {
11748
11937
  const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
11749
11938
  const readBuffer = this.device.createBuffer({
11750
11939
  byteLength: layout.byteLength,
11751
- usage: import_core29.Buffer.COPY_DST | import_core29.Buffer.MAP_READ
11940
+ usage: import_core31.Buffer.COPY_DST | import_core31.Buffer.MAP_READ
11752
11941
  });
11753
11942
  try {
11754
11943
  pickTexture.readBuffer(
@@ -11784,7 +11973,7 @@ layout(std140) uniform pickingUniforms {
11784
11973
  const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
11785
11974
  const readBuffer = this.device.createBuffer({
11786
11975
  byteLength: layout.byteLength,
11787
- usage: import_core29.Buffer.COPY_DST | import_core29.Buffer.MAP_READ
11976
+ usage: import_core31.Buffer.COPY_DST | import_core31.Buffer.MAP_READ
11788
11977
  });
11789
11978
  try {
11790
11979
  pickTexture.readBuffer(