@luma.gl/engine 9.4.0 → 10.0.0-alpha.1

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 (52) 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 +22 -7
  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/animation-loop/make-animation-loop.d.ts.map +1 -1
  8. package/dist/animation-loop/make-animation-loop.js +3 -1
  9. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  10. package/dist/compute/computation.d.ts +12 -0
  11. package/dist/compute/computation.d.ts.map +1 -1
  12. package/dist/compute/computation.js +85 -22
  13. package/dist/compute/computation.js.map +1 -1
  14. package/dist/compute/kernel.d.ts +54 -0
  15. package/dist/compute/kernel.d.ts.map +1 -0
  16. package/dist/compute/kernel.js +103 -0
  17. package/dist/compute/kernel.js.map +1 -0
  18. package/dist/compute/render-kernel.d.ts +65 -0
  19. package/dist/compute/render-kernel.d.ts.map +1 -0
  20. package/dist/compute/render-kernel.js +129 -0
  21. package/dist/compute/render-kernel.js.map +1 -0
  22. package/dist/controls/orbit-controls.d.ts +9 -2
  23. package/dist/controls/orbit-controls.d.ts.map +1 -1
  24. package/dist/controls/orbit-controls.js +55 -8
  25. package/dist/controls/orbit-controls.js.map +1 -1
  26. package/dist/dist.dev.js +502 -134
  27. package/dist/dist.min.js +23 -23
  28. package/dist/index.cjs +504 -117
  29. package/dist/index.cjs.map +3 -3
  30. package/dist/index.d.ts +4 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +2 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/model/model.d.ts +13 -2
  35. package/dist/model/model.d.ts.map +1 -1
  36. package/dist/model/model.js +137 -66
  37. package/dist/model/model.js.map +1 -1
  38. package/dist/passes/shader-pass-renderer.d.ts +12 -12
  39. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  40. package/dist/passes/shader-pass-renderer.js +17 -17
  41. package/dist/passes/shader-pass-renderer.js.map +1 -1
  42. package/package.json +4 -4
  43. package/src/animation-loop/animation-loop.ts +36 -14
  44. package/src/animation-loop/animation-props.ts +4 -1
  45. package/src/animation-loop/make-animation-loop.ts +3 -1
  46. package/src/compute/computation.ts +83 -30
  47. package/src/compute/kernel.ts +146 -0
  48. package/src/compute/render-kernel.ts +192 -0
  49. package/src/controls/orbit-controls.ts +61 -9
  50. package/src/index.ts +12 -0
  51. package/src/model/model.ts +149 -87
  52. 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,
@@ -3472,6 +3474,7 @@ var __exports__ = (() => {
3472
3474
  var AnimationLoop = class _AnimationLoop {
3473
3475
  static defaultAnimationLoopProps = {
3474
3476
  device: null,
3477
+ mobileQuality: void 0,
3475
3478
  onAddHTML: () => "",
3476
3479
  onInitialize: async () => null,
3477
3480
  onRender: () => {
@@ -3540,8 +3543,11 @@ var __exports__ = (() => {
3540
3543
  this.destroy();
3541
3544
  }
3542
3545
  reportError(error) {
3543
- this.props.onError(error);
3544
3546
  this._error = error;
3547
+ this.props.onError(error);
3548
+ if (this.props.onError === _AnimationLoop.defaultAnimationLoopProps.onError && typeof window !== "undefined" && typeof ErrorEvent !== "undefined") {
3549
+ window.dispatchEvent(new ErrorEvent("error", { error, message: error.message }));
3550
+ }
3545
3551
  }
3546
3552
  /** Flags this animation loop as needing redraw */
3547
3553
  setNeedsRedraw(reason) {
@@ -3607,14 +3613,15 @@ var __exports__ = (() => {
3607
3613
  /** Stops a render loop if already running, finalizing */
3608
3614
  stop() {
3609
3615
  if (this._running) {
3610
- if (this.animationProps && !this._error) {
3611
- this.props.onFinalize(this.animationProps);
3612
- }
3616
+ const animationProps = this.animationProps;
3613
3617
  this._cancelAnimationFrame();
3614
3618
  this._nextFramePromise = null;
3615
3619
  this._resolveNextFrame = null;
3616
3620
  this._running = false;
3617
3621
  this._lastFrameTime = 0;
3622
+ if (animationProps) {
3623
+ this.props.onFinalize(animationProps);
3624
+ }
3618
3625
  }
3619
3626
  return this;
3620
3627
  }
@@ -3704,8 +3711,14 @@ var __exports__ = (() => {
3704
3711
  if (!this._running) {
3705
3712
  return;
3706
3713
  }
3707
- this.redraw(time, animationFrame ?? null);
3708
- this._requestAnimationFrame();
3714
+ try {
3715
+ this.redraw(time, animationFrame ?? null);
3716
+ this._requestAnimationFrame();
3717
+ } catch (error) {
3718
+ const renderError = error instanceof Error ? error : new Error(String(error));
3719
+ this.reportError(renderError);
3720
+ this.stop();
3721
+ }
3709
3722
  }
3710
3723
  // Called on each frame, can be overridden to call onRender multiple times
3711
3724
  // to support e.g. stereoscopic rendering
@@ -3754,8 +3767,9 @@ var __exports__ = (() => {
3754
3767
  tock: 0,
3755
3768
  // Experimental
3756
3769
  animationFrame: null,
3757
- _mousePosition: null
3770
+ _mousePosition: null,
3758
3771
  // Event props
3772
+ mobileQuality: this.props.mobileQuality
3759
3773
  };
3760
3774
  }
3761
3775
  _getAnimationProps() {
@@ -3931,7 +3945,9 @@ var __exports__ = (() => {
3931
3945
  } catch (error) {
3932
3946
  console.error(error);
3933
3947
  renderLoop = null;
3934
- setError(animationProps.animationLoop.device, error);
3948
+ const initializationError = error instanceof Error ? error : new Error(String(error));
3949
+ setError(animationProps.animationLoop.device, initializationError);
3950
+ animationProps.animationLoop.reportError(initializationError);
3935
3951
  animationProps.animationLoop.stop();
3936
3952
  return null;
3937
3953
  }
@@ -3992,6 +4008,7 @@ var __exports__ = (() => {
3992
4008
  distance: 10,
3993
4009
  yaw: 0,
3994
4010
  pitch: 0.25,
4011
+ roll: 0,
3995
4012
  minDistance: 1,
3996
4013
  maxDistance: 100,
3997
4014
  minPitch: -Math.PI / 2 + 0.01,
@@ -3999,6 +4016,7 @@ var __exports__ = (() => {
3999
4016
  rotateSpeed: 6e-3,
4000
4017
  zoomSpeed: 1e-3,
4001
4018
  enabled: true,
4019
+ enableRotate: false,
4002
4020
  enableZoom: true,
4003
4021
  enablePan: false,
4004
4022
  panSpeed: 18e-4,
@@ -4010,11 +4028,13 @@ var __exports__ = (() => {
4010
4028
  props;
4011
4029
  yaw;
4012
4030
  pitch;
4031
+ roll;
4013
4032
  distance;
4014
4033
  dragging = false;
4015
4034
  activePointers = /* @__PURE__ */ new Map();
4016
4035
  lastPointer = [0, 0];
4017
4036
  previousPinchDistance = null;
4037
+ previousPinchAngle = null;
4018
4038
  previousTimeMilliseconds = null;
4019
4039
  previousCursor;
4020
4040
  previousTouchAction;
@@ -4024,6 +4044,7 @@ var __exports__ = (() => {
4024
4044
  this.props.target = [...this.props.target];
4025
4045
  this.yaw = this.props.yaw;
4026
4046
  this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
4047
+ this.roll = this.props.roll;
4027
4048
  this.distance = clampNumber(
4028
4049
  this.props.distance,
4029
4050
  this.props.minDistance,
@@ -4059,6 +4080,32 @@ var __exports__ = (() => {
4059
4080
  this.props.target[2] + horizontalDistance * Math.cos(this.yaw)
4060
4081
  ];
4061
4082
  }
4083
+ /** Returns the camera up direction after applying pitch and optional two-finger roll. */
4084
+ getUpDirection() {
4085
+ return this.getCameraFrame().up;
4086
+ }
4087
+ getCameraFrame() {
4088
+ const sineYaw = Math.sin(this.yaw);
4089
+ const cosineYaw = Math.cos(this.yaw);
4090
+ const sinePitch = Math.sin(this.pitch);
4091
+ const cosinePitch = Math.cos(this.pitch);
4092
+ const sineRoll = Math.sin(this.roll);
4093
+ const cosineRoll = Math.cos(this.roll);
4094
+ const right = [cosineYaw, 0, -sineYaw];
4095
+ const up = [-sinePitch * sineYaw, cosinePitch, -sinePitch * cosineYaw];
4096
+ return {
4097
+ right: [
4098
+ right[0] * cosineRoll - up[0] * sineRoll,
4099
+ right[1] * cosineRoll - up[1] * sineRoll,
4100
+ right[2] * cosineRoll - up[2] * sineRoll
4101
+ ],
4102
+ up: [
4103
+ up[0] * cosineRoll + right[0] * sineRoll,
4104
+ up[1] * cosineRoll + right[1] * sineRoll,
4105
+ up[2] * cosineRoll + right[2] * sineRoll
4106
+ ]
4107
+ };
4108
+ }
4062
4109
  /** Enables or pauses automatic rotation without losing the current manual angle. */
4063
4110
  setAutoRotate(autoRotate) {
4064
4111
  this.props.autoRotate = autoRotate;
@@ -4078,6 +4125,9 @@ var __exports__ = (() => {
4078
4125
  if (props.pitch !== void 0 || props.minPitch !== void 0 || props.maxPitch !== void 0) {
4079
4126
  this.pitch = clampNumber(props.pitch ?? this.pitch, this.props.minPitch, this.props.maxPitch);
4080
4127
  }
4128
+ if (props.roll !== void 0) {
4129
+ this.roll = props.roll;
4130
+ }
4081
4131
  if (props.distance !== void 0 || props.minDistance !== void 0 || props.maxDistance !== void 0) {
4082
4132
  this.distance = clampNumber(
4083
4133
  props.distance ?? this.distance,
@@ -4086,10 +4136,11 @@ var __exports__ = (() => {
4086
4136
  );
4087
4137
  }
4088
4138
  }
4089
- /** Restores the configured starting angle and zoom. */
4139
+ /** Restores the configured starting orbit, roll, and zoom. */
4090
4140
  reset() {
4091
4141
  this.yaw = this.props.yaw;
4092
4142
  this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
4143
+ this.roll = this.props.roll;
4093
4144
  this.distance = clampNumber(
4094
4145
  this.props.distance,
4095
4146
  this.props.minDistance,
@@ -4118,9 +4169,10 @@ var __exports__ = (() => {
4118
4169
  if (this.activePointers.size === 1) {
4119
4170
  this.lastPointer = [event.clientX, event.clientY];
4120
4171
  } else {
4121
- const { center, distance } = this.getMultiPointerState();
4172
+ const { center, distance, angle: angle2 } = this.getMultiPointerState();
4122
4173
  this.lastPointer = center;
4123
4174
  this.previousPinchDistance = distance;
4175
+ this.previousPinchAngle = distance > 0 ? angle2 : null;
4124
4176
  }
4125
4177
  this.canvas.setPointerCapture(event.pointerId);
4126
4178
  this.canvas.style.cursor = "grabbing";
@@ -4131,7 +4183,7 @@ var __exports__ = (() => {
4131
4183
  }
4132
4184
  this.activePointers.set(event.pointerId, [event.clientX, event.clientY]);
4133
4185
  if (this.activePointers.size > 1) {
4134
- const { center, distance } = this.getMultiPointerState();
4186
+ const { center, distance, angle: angle2 } = this.getMultiPointerState();
4135
4187
  if (this.props.enablePan) {
4136
4188
  this.panTarget(center[0] - this.lastPointer[0], center[1] - this.lastPointer[1]);
4137
4189
  }
@@ -4142,8 +4194,12 @@ var __exports__ = (() => {
4142
4194
  this.props.maxDistance
4143
4195
  );
4144
4196
  }
4197
+ if (this.props.enableRotate && this.previousPinchAngle !== null && distance > 0) {
4198
+ this.roll += normalizeAngleDelta(angle2 - this.previousPinchAngle);
4199
+ }
4145
4200
  this.lastPointer = center;
4146
4201
  this.previousPinchDistance = distance;
4202
+ this.previousPinchAngle = distance > 0 ? angle2 : null;
4147
4203
  return;
4148
4204
  }
4149
4205
  const deltaX = event.clientX - this.lastPointer[0];
@@ -4169,6 +4225,7 @@ var __exports__ = (() => {
4169
4225
  }
4170
4226
  this.activePointers.delete(event.pointerId);
4171
4227
  this.previousPinchDistance = null;
4228
+ this.previousPinchAngle = null;
4172
4229
  const remainingPointer = this.activePointers.entries().next().value;
4173
4230
  if (remainingPointer) {
4174
4231
  this.lastPointer = remainingPointer[1];
@@ -4185,6 +4242,7 @@ var __exports__ = (() => {
4185
4242
  }
4186
4243
  this.activePointers.clear();
4187
4244
  this.previousPinchDistance = null;
4245
+ this.previousPinchAngle = null;
4188
4246
  this.canvas.style.cursor = "grab";
4189
4247
  }
4190
4248
  getMultiPointerState() {
@@ -4193,15 +4251,17 @@ var __exports__ = (() => {
4193
4251
  const deltaY = secondPointer[1] - firstPointer[1];
4194
4252
  return {
4195
4253
  center: [(firstPointer[0] + secondPointer[0]) / 2, (firstPointer[1] + secondPointer[1]) / 2],
4196
- distance: Math.hypot(deltaX, deltaY)
4254
+ distance: Math.hypot(deltaX, deltaY),
4255
+ angle: Math.atan2(deltaY, deltaX)
4197
4256
  };
4198
4257
  }
4199
4258
  panTarget(deltaX, deltaY) {
4200
4259
  const panScale = this.distance * this.props.panSpeed;
4260
+ const { right, up } = this.getCameraFrame();
4201
4261
  this.props.target = [
4202
- this.props.target[0] - Math.cos(this.yaw) * deltaX * panScale,
4203
- this.props.target[1] + deltaY * panScale,
4204
- this.props.target[2] + Math.sin(this.yaw) * deltaX * panScale
4262
+ this.props.target[0] + (-right[0] * deltaX + up[0] * deltaY) * panScale,
4263
+ this.props.target[1] + (-right[1] * deltaX + up[1] * deltaY) * panScale,
4264
+ this.props.target[2] + (-right[2] * deltaX + up[2] * deltaY) * panScale
4205
4265
  ];
4206
4266
  }
4207
4267
  handleWheel = (event) => {
@@ -4221,6 +4281,9 @@ var __exports__ = (() => {
4221
4281
  function clampNumber(value, minimum, maximum) {
4222
4282
  return Math.min(Math.max(value, minimum), maximum);
4223
4283
  }
4284
+ function normalizeAngleDelta(angle2) {
4285
+ return Math.atan2(Math.sin(angle2), Math.cos(angle2));
4286
+ }
4224
4287
 
4225
4288
  // src/model/model.ts
4226
4289
  var import_core13 = __toESM(require_core(), 1);
@@ -5258,6 +5321,28 @@ var __exports__ = (() => {
5258
5321
  "depth32float-stencil8"
5259
5322
  ];
5260
5323
  var Model = class _Model {
5324
+ /** Creates a model while allowing the backend to compile its render pipeline asynchronously. */
5325
+ static async createAsync(device, props) {
5326
+ const ownsCompilation = !import_core13.PipelineFactory.getAsyncCompilation(device);
5327
+ const asyncCompilation = ownsCompilation ? import_core13.PipelineFactory.beginAsyncCompilation(device) : import_core13.PipelineFactory.getAsyncCompilation(device);
5328
+ let model;
5329
+ try {
5330
+ model = new _Model(device, props);
5331
+ } finally {
5332
+ if (ownsCompilation) import_core13.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
5333
+ }
5334
+ try {
5335
+ if (ownsCompilation) {
5336
+ await Promise.all(asyncCompilation);
5337
+ } else {
5338
+ await model._pipelineInitialization;
5339
+ }
5340
+ return model;
5341
+ } catch (error) {
5342
+ model.destroy();
5343
+ throw error;
5344
+ }
5345
+ }
5261
5346
  static defaultProps = {
5262
5347
  ...import_core13.RenderPipeline.defaultProps,
5263
5348
  source: void 0,
@@ -5324,7 +5409,7 @@ var __exports__ = (() => {
5324
5409
  instanceCount = 0;
5325
5410
  /** Vertex count */
5326
5411
  vertexCount;
5327
- /** Indexed draw count override. Undefined draws the full bound index buffer. */
5412
+ /** Indexed draw count override. Undefined uses vertexCount, then the full bound index buffer. */
5328
5413
  indexCount;
5329
5414
  /** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
5330
5415
  firstVertex;
@@ -5365,9 +5450,11 @@ var __exports__ = (() => {
5365
5450
  _needsRedraw = "initializing";
5366
5451
  _drawBlockedReason = false;
5367
5452
  _destroyed = false;
5453
+ _vertexCountSet = false;
5368
5454
  /** "Time" of last draw. Monotonically increasing timestamp */
5369
5455
  _lastDrawTimestamp = -1;
5370
5456
  _bindingTable = [];
5457
+ _pipelineInitialization;
5371
5458
  get [Symbol.toStringTag]() {
5372
5459
  return "Model";
5373
5460
  }
@@ -5376,11 +5463,13 @@ var __exports__ = (() => {
5376
5463
  }
5377
5464
  constructor(device, props) {
5378
5465
  const defaultShaderAssembler = _Model.defaultProps.shaderAssembler;
5466
+ const vertexCountSet = Object.hasOwn(props, "vertexCount");
5379
5467
  this.props = {
5380
5468
  ..._Model.defaultProps,
5381
5469
  ...props,
5382
5470
  shaderAssembler: props.shaderAssembler ?? (isShaderAssemblerForLanguage(defaultShaderAssembler, device.info.shadingLanguage) ? defaultShaderAssembler : import_shadertools3.ShaderAssembler.getDefaultShaderAssembler(device.info.shadingLanguage))
5383
5471
  };
5472
+ this._vertexCountSet = vertexCountSet;
5384
5473
  props = this.props;
5385
5474
  this.id = props.id || uid("model");
5386
5475
  this.device = device;
@@ -5470,45 +5559,42 @@ var __exports__ = (() => {
5470
5559
  }
5471
5560
  this.pipelineFactory = props.pipelineFactory || import_core13.PipelineFactory.getDefaultPipelineFactory(this.device);
5472
5561
  this.shaderFactory = props.shaderFactory || import_core13.ShaderFactory.getDefaultShaderFactory(this.device);
5473
- this.pipeline = this._updatePipeline();
5474
- this.vertexArray = device.createVertexArray({
5562
+ const asyncCompilation = import_core13.PipelineFactory.getAsyncCompilation(this.device);
5563
+ if (asyncCompilation) {
5564
+ this._pipelineInitialization = this._initializePipelineAsync(props);
5565
+ asyncCompilation.push(this._pipelineInitialization);
5566
+ } else {
5567
+ this.pipeline = this._updatePipeline();
5568
+ this._initializePipelineResources(props);
5569
+ }
5570
+ }
5571
+ async _initializePipelineAsync(props) {
5572
+ await this._updatePipelineAsync();
5573
+ this._initializePipelineResources(props);
5574
+ }
5575
+ _initializePipelineResources(props) {
5576
+ this.vertexArray = this.device.createVertexArray({
5475
5577
  shaderLayout: this.pipeline.shaderLayout,
5476
5578
  bufferLayout: this.pipeline.bufferLayout
5477
5579
  });
5478
- if (this._gpuGeometry) {
5479
- this._setGeometryAttributes(this._gpuGeometry);
5480
- }
5481
- if ("isInstanced" in props) {
5482
- this.isInstanced = props.isInstanced;
5483
- }
5484
- if (props.instanceCount) {
5485
- this.setInstanceCount(props.instanceCount);
5486
- }
5487
- if (props.vertexCount) {
5488
- this.setVertexCount(props.vertexCount);
5489
- }
5490
- if (props.indexBuffer) {
5491
- this.setIndexBuffer(props.indexBuffer);
5492
- }
5493
- if (props.attributes) {
5494
- this.setAttributes(props.attributes);
5495
- }
5496
- if (props.constantAttributes) {
5497
- this.setConstantAttributes(props.constantAttributes);
5498
- }
5499
- if (props.bindings) {
5500
- this.setBindings(props.bindings);
5501
- }
5502
- if (props.transformFeedback) {
5503
- this.transformFeedback = props.transformFeedback;
5504
- }
5580
+ if (this._gpuGeometry) this._setGeometryAttributes(this._gpuGeometry);
5581
+ if ("isInstanced" in props) this.isInstanced = props.isInstanced;
5582
+ if (props.instanceCount) this.setInstanceCount(props.instanceCount);
5583
+ if (props.vertexCount) this.setVertexCount(props.vertexCount);
5584
+ if (props.indexBuffer) this.setIndexBuffer(props.indexBuffer);
5585
+ if (props.attributes) this.setAttributes(props.attributes);
5586
+ if (props.constantAttributes) this.setConstantAttributes(props.constantAttributes);
5587
+ if (props.bindings) this.setBindings(props.bindings);
5588
+ if (props.transformFeedback) this.transformFeedback = props.transformFeedback;
5505
5589
  }
5506
5590
  destroy() {
5507
5591
  if (!this._destroyed) {
5508
- this.pipelineFactory.release(this.pipeline);
5509
- this.shaderFactory.release(this.pipeline.vs);
5510
- if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
5511
- this.shaderFactory.release(this.pipeline.fs);
5592
+ if (this.pipeline) {
5593
+ this.pipelineFactory.release(this.pipeline);
5594
+ this.shaderFactory.release(this.pipeline.vs);
5595
+ if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
5596
+ this.shaderFactory.release(this.pipeline.fs);
5597
+ }
5512
5598
  }
5513
5599
  this._uniformStore.destroy();
5514
5600
  this._gpuGeometry?.destroy();
@@ -5598,7 +5684,7 @@ var __exports__ = (() => {
5598
5684
  const syncBindings = this._getBindings(shaderLayout);
5599
5685
  const syncBindGroups = this._getBindGroups(shaderLayout, syncBindings);
5600
5686
  const { indexBuffer } = this.vertexArray;
5601
- const indexCount = indexBuffer ? this.indexCount ?? indexBuffer.byteLength / (indexBuffer.indexType === "uint32" ? 4 : 2) : void 0;
5687
+ const indexCount = indexBuffer ? this.indexCount ?? (this._vertexCountSet ? this.vertexCount : indexBuffer.byteLength / (indexBuffer.indexType === "uint32" ? 4 : 2)) : void 0;
5602
5688
  renderPass.setPipeline(this.pipeline);
5603
5689
  renderPass.setBindings(syncBindGroups, {
5604
5690
  _bindGroupCacheKeys: this._getBindGroupCacheKeys()
@@ -5721,6 +5807,7 @@ var __exports__ = (() => {
5721
5807
  */
5722
5808
  setVertexCount(vertexCount) {
5723
5809
  this.vertexCount = vertexCount;
5810
+ this._vertexCountSet = true;
5724
5811
  this.setNeedsRedraw("vertexCount");
5725
5812
  }
5726
5813
  /** Updates the indexed draw count override. */
@@ -5966,6 +6053,7 @@ var __exports__ = (() => {
5966
6053
  }
5967
6054
  }
5968
6055
  this.vertexCount = gpuGeometry.vertexCount;
6056
+ this._vertexCountSet = true;
5969
6057
  this.setIndexBuffer(gpuGeometry.indices || null);
5970
6058
  this.setAttributes(gpuGeometry.attributes, { disableWarnings: true });
5971
6059
  this.setAttributes(attributes, { disableWarnings: this.props.disableWarnings });
@@ -5979,36 +6067,55 @@ var __exports__ = (() => {
5979
6067
  }
5980
6068
  /** Update pipeline if needed */
5981
6069
  _updatePipeline() {
5982
- if (this._pipelineNeedsUpdate) {
5983
- let prevShaderVs = null;
5984
- let prevShaderFs = null;
5985
- if (this.pipeline) {
5986
- import_core13.log.log(
5987
- 1,
5988
- `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`
5989
- )();
5990
- prevShaderVs = this.pipeline.vs;
5991
- prevShaderFs = this.pipeline.fs;
5992
- }
5993
- this._pipelineNeedsUpdate = false;
5994
- const vs4 = this.shaderFactory.createShader({
5995
- id: `${this.id}-vertex`,
5996
- stage: "vertex",
5997
- source: this.source || this.vs,
6070
+ const update = this._preparePipelineUpdate();
6071
+ if (update) {
6072
+ this.pipeline = this.pipelineFactory.createRenderPipeline(update.props);
6073
+ this._finishPipelineUpdate(update);
6074
+ }
6075
+ return this.pipeline;
6076
+ }
6077
+ /** Creates or replaces the render pipeline through the backend's asynchronous compilation path. */
6078
+ async _updatePipelineAsync() {
6079
+ const update = this._preparePipelineUpdate();
6080
+ if (update) {
6081
+ try {
6082
+ this.pipeline = await this.pipelineFactory.createRenderPipelineAsync(update.props);
6083
+ } catch (error) {
6084
+ this._releasePipelineShaders(update.vertexShader, update.fragmentShader);
6085
+ this._pipelineNeedsUpdate = "asynchronous pipeline creation failed";
6086
+ throw error;
6087
+ }
6088
+ this._finishPipelineUpdate(update);
6089
+ }
6090
+ return this.pipeline;
6091
+ }
6092
+ _preparePipelineUpdate() {
6093
+ if (!this._pipelineNeedsUpdate) return null;
6094
+ const previousVertexShader = this.pipeline?.vs ?? null;
6095
+ const previousFragmentShader = this.pipeline?.fs ?? null;
6096
+ if (this.pipeline) {
6097
+ import_core13.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
6098
+ }
6099
+ this._pipelineNeedsUpdate = false;
6100
+ const vertexShader = this.shaderFactory.createShader({
6101
+ id: `${this.id}-vertex`,
6102
+ stage: "vertex",
6103
+ source: this.source || this.vs,
6104
+ debugShaders: this.props.debugShaders
6105
+ });
6106
+ let fragmentShader = null;
6107
+ if (this.source) {
6108
+ fragmentShader = vertexShader;
6109
+ } else if (this.fs) {
6110
+ fragmentShader = this.shaderFactory.createShader({
6111
+ id: `${this.id}-fragment`,
6112
+ stage: "fragment",
6113
+ source: this.fs,
5998
6114
  debugShaders: this.props.debugShaders
5999
6115
  });
6000
- let fs4 = null;
6001
- if (this.source) {
6002
- fs4 = vs4;
6003
- } else if (this.fs) {
6004
- fs4 = this.shaderFactory.createShader({
6005
- id: `${this.id}-fragment`,
6006
- stage: "fragment",
6007
- source: this.source || this.fs,
6008
- debugShaders: this.props.debugShaders
6009
- });
6010
- }
6011
- this.pipeline = this.pipelineFactory.createRenderPipeline({
6116
+ }
6117
+ return {
6118
+ props: {
6012
6119
  ...this.props,
6013
6120
  bindings: void 0,
6014
6121
  bufferLayout: this.bufferLayout,
@@ -6017,19 +6124,27 @@ var __exports__ = (() => {
6017
6124
  topology: this.topology,
6018
6125
  parameters: this.parameters,
6019
6126
  bindGroups: void 0,
6020
- vs: vs4,
6021
- fs: fs4
6022
- });
6023
- this._attributeInfos = (0, import_core13.getAttributeInfosFromLayouts)(
6024
- this.pipeline.shaderLayout,
6025
- this.bufferLayout
6026
- );
6027
- if (prevShaderVs) this.shaderFactory.release(prevShaderVs);
6028
- if (prevShaderFs && prevShaderFs !== prevShaderVs) {
6029
- this.shaderFactory.release(prevShaderFs);
6030
- }
6127
+ vs: vertexShader,
6128
+ fs: fragmentShader
6129
+ },
6130
+ vertexShader,
6131
+ fragmentShader,
6132
+ previousVertexShader,
6133
+ previousFragmentShader
6134
+ };
6135
+ }
6136
+ _finishPipelineUpdate(update) {
6137
+ this._attributeInfos = (0, import_core13.getAttributeInfosFromLayouts)(
6138
+ this.pipeline.shaderLayout,
6139
+ this.bufferLayout
6140
+ );
6141
+ this._releasePipelineShaders(update.previousVertexShader, update.previousFragmentShader);
6142
+ }
6143
+ _releasePipelineShaders(vertexShader, fragmentShader) {
6144
+ if (vertexShader) this.shaderFactory.release(vertexShader);
6145
+ if (fragmentShader && fragmentShader !== vertexShader) {
6146
+ this.shaderFactory.release(fragmentShader);
6031
6147
  }
6032
- return this.pipeline;
6033
6148
  }
6034
6149
  /** Throttle draw call logging */
6035
6150
  _lastLogTime = 0;
@@ -10278,6 +10393,33 @@ void main(void) {
10278
10393
  var LOG_DRAW_PRIORITY2 = 2;
10279
10394
  var LOG_DRAW_TIMEOUT2 = 1e4;
10280
10395
  var Computation = class _Computation {
10396
+ /**
10397
+ * Creates a computation while allowing the backend to compile its pipeline asynchronously.
10398
+ *
10399
+ * Use this factory when several independent computations can be prepared together. Calling the
10400
+ * constructor remains the synchronous compatibility path.
10401
+ */
10402
+ static async createAsync(device, props) {
10403
+ const ownsCompilation = !import_core27.PipelineFactory.getAsyncCompilation(device);
10404
+ const asyncCompilation = ownsCompilation ? import_core27.PipelineFactory.beginAsyncCompilation(device) : import_core27.PipelineFactory.getAsyncCompilation(device);
10405
+ let computation;
10406
+ try {
10407
+ computation = new _Computation(device, props);
10408
+ } finally {
10409
+ if (ownsCompilation) import_core27.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
10410
+ }
10411
+ try {
10412
+ if (ownsCompilation) {
10413
+ await Promise.all(asyncCompilation);
10414
+ } else {
10415
+ await computation._pipelineInitialization;
10416
+ }
10417
+ return computation;
10418
+ } catch (error) {
10419
+ computation.destroy();
10420
+ throw error;
10421
+ }
10422
+ }
10281
10423
  static defaultProps = {
10282
10424
  ...import_core27.ComputePipeline.defaultProps,
10283
10425
  id: "unnamed",
@@ -10316,6 +10458,7 @@ void main(void) {
10316
10458
  _getModuleUniforms;
10317
10459
  props;
10318
10460
  _destroyed = false;
10461
+ _pipelineInitialization;
10319
10462
  constructor(device, props) {
10320
10463
  if (device.type !== "webgpu") {
10321
10464
  throw new Error("Computation is only supported in WebGPU");
@@ -10366,15 +10509,21 @@ void main(void) {
10366
10509
  this.props.shaderLayout || inferredShaderLayout || null,
10367
10510
  modules
10368
10511
  ) || null;
10369
- this.pipeline = this._updatePipeline();
10512
+ const asyncCompilation = import_core27.PipelineFactory.getAsyncCompilation(this.device);
10513
+ if (asyncCompilation) {
10514
+ this._pipelineInitialization = this._updatePipelineAsync();
10515
+ asyncCompilation.push(this._pipelineInitialization);
10516
+ } else {
10517
+ this.pipeline = this._updatePipeline();
10518
+ }
10370
10519
  if (props.bindings) {
10371
10520
  this.setBindings(props.bindings);
10372
10521
  }
10373
10522
  }
10374
10523
  destroy() {
10375
10524
  if (this._destroyed) return;
10376
- this.pipelineFactory.release(this.pipeline);
10377
- this.shaderFactory.release(this.shader);
10525
+ if (this.pipeline) this.pipelineFactory.release(this.pipeline);
10526
+ if (this.shader) this.shaderFactory.release(this.shader);
10378
10527
  this._uniformStore.destroy();
10379
10528
  this._destroyed = true;
10380
10529
  }
@@ -10469,32 +10618,47 @@ void main(void) {
10469
10618
  this._pipelineNeedsUpdate = this._pipelineNeedsUpdate || reason;
10470
10619
  }
10471
10620
  _updatePipeline() {
10472
- if (this._pipelineNeedsUpdate) {
10473
- let prevShader = null;
10474
- if (this.pipeline) {
10475
- import_core27.log.log(
10476
- 1,
10477
- `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`
10478
- )();
10479
- prevShader = this.shader;
10480
- }
10481
- this._pipelineNeedsUpdate = false;
10482
- this.shader = this.shaderFactory.createShader({
10483
- id: `${this.id}-fragment`,
10484
- stage: "compute",
10485
- source: this.source,
10486
- debugShaders: this.props.debugShaders
10487
- });
10488
- this.pipeline = this.pipelineFactory.createComputePipeline({
10489
- ...this.props,
10490
- shader: this.shader
10491
- });
10492
- if (prevShader) {
10493
- this.shaderFactory.release(prevShader);
10621
+ const update = this._preparePipelineUpdate();
10622
+ if (update) {
10623
+ this.pipeline = this.pipelineFactory.createComputePipeline(update.props);
10624
+ this._finishPipelineUpdate(update.previousShader);
10625
+ }
10626
+ return this.pipeline;
10627
+ }
10628
+ /** Creates or replaces the pipeline through the backend's asynchronous compilation path. */
10629
+ async _updatePipelineAsync() {
10630
+ const update = this._preparePipelineUpdate();
10631
+ if (update) {
10632
+ try {
10633
+ this.pipeline = await this.pipelineFactory.createComputePipelineAsync(update.props);
10634
+ } catch (error) {
10635
+ this.shaderFactory.release(this.shader);
10636
+ this.shader = update.previousShader;
10637
+ this._pipelineNeedsUpdate = "asynchronous pipeline creation failed";
10638
+ throw error;
10494
10639
  }
10640
+ this._finishPipelineUpdate(update.previousShader);
10495
10641
  }
10496
10642
  return this.pipeline;
10497
10643
  }
10644
+ _preparePipelineUpdate() {
10645
+ if (!this._pipelineNeedsUpdate) return null;
10646
+ const previousShader = this.pipeline ? this.shader : null;
10647
+ if (this.pipeline) {
10648
+ import_core27.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
10649
+ }
10650
+ this._pipelineNeedsUpdate = false;
10651
+ this.shader = this.shaderFactory.createShader({
10652
+ id: `${this.id}-fragment`,
10653
+ stage: "compute",
10654
+ source: this.source,
10655
+ debugShaders: this.props.debugShaders
10656
+ });
10657
+ return { props: { ...this.props, shader: this.shader }, previousShader };
10658
+ }
10659
+ _finishPipelineUpdate(previousShader) {
10660
+ if (previousShader) this.shaderFactory.release(previousShader);
10661
+ }
10498
10662
  /** Throttle draw call logging */
10499
10663
  _lastLogTime = 0;
10500
10664
  _logOpen = false;
@@ -10731,7 +10895,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
10731
10895
  passRenderer.resize(size);
10732
10896
  }
10733
10897
  }
10734
- /** Invalidates persistent pipeline targets without destroying their allocations. */
10898
+ /** Invalidates persistent composite-pass targets without destroying their allocations. */
10735
10899
  resetHistory() {
10736
10900
  for (const passRenderer of this.passRenderers) {
10737
10901
  passRenderer.resetHistory();
@@ -10872,11 +11036,11 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
10872
11036
  this.device = device;
10873
11037
  this.shaderInputs = shaderInputs;
10874
11038
  this.passDefinition = passDefinition;
10875
- if (isShaderPassPipeline(passDefinition)) {
11039
+ if (isCompositeShaderPass(passDefinition)) {
10876
11040
  validateRenderTargetNames(passDefinition.name, passDefinition.renderTargets || {});
10877
11041
  this.renderTargets = createManagedRenderTargets(device, passDefinition.renderTargets || {});
10878
11042
  if (supportsComputeOptimization(device, passDefinition)) {
10879
- this.computeRenderer = new PipelineComputeRenderer(
11043
+ this.computeRenderer = new CompositeShaderPassComputeRenderer(
10880
11044
  device,
10881
11045
  passDefinition.compute,
10882
11046
  this.renderTargets,
@@ -11024,13 +11188,13 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11024
11188
  }
11025
11189
  return resolvedBindings;
11026
11190
  }
11027
- createStepExecutions(pipeline, step, flipY) {
11191
+ createStepExecutions(compositeShaderPass, step, flipY) {
11028
11192
  validateShaderPassDoesNotOwnRenderTargets(
11029
11193
  step.shaderPass,
11030
- `${pipeline.name}/${step.shaderPass.name}`
11194
+ `${compositeShaderPass.name}/${step.shaderPass.name}`
11031
11195
  );
11032
11196
  return this.createPassExecutions(step.shaderPass, {
11033
- ownerName: `${pipeline.name}/${step.shaderPass.name}`,
11197
+ ownerName: `${compositeShaderPass.name}/${step.shaderPass.name}`,
11034
11198
  firstInputs: step.inputs,
11035
11199
  lastOutput: step.output,
11036
11200
  uniformOverrides: step.uniforms,
@@ -11074,7 +11238,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11074
11238
  return this.passDefinition.name;
11075
11239
  }
11076
11240
  };
11077
- var PipelineComputeRenderer = class {
11241
+ var CompositeShaderPassComputeRenderer = class {
11078
11242
  optimization;
11079
11243
  renderTargets;
11080
11244
  shaderInputs;
@@ -11209,14 +11373,14 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11209
11373
  };
11210
11374
  function getExecutableShaderPasses(shaderPasses) {
11211
11375
  return shaderPasses.flatMap(
11212
- (shaderPass) => isShaderPassPipeline(shaderPass) ? shaderPass.steps.map((step) => step.shaderPass) : [shaderPass]
11376
+ (shaderPass) => isCompositeShaderPass(shaderPass) ? shaderPass.steps.map((step) => step.shaderPass) : [shaderPass]
11213
11377
  );
11214
11378
  }
11215
- function isShaderPassPipeline(shaderPass) {
11379
+ function isCompositeShaderPass(shaderPass) {
11216
11380
  return "steps" in shaderPass;
11217
11381
  }
11218
- function supportsComputeOptimization(device, pipeline) {
11219
- const optimization = pipeline.compute;
11382
+ function supportsComputeOptimization(device, compositeShaderPass) {
11383
+ const optimization = compositeShaderPass.compute;
11220
11384
  if (!optimization || device.type !== "webgpu") {
11221
11385
  return false;
11222
11386
  }
@@ -11225,7 +11389,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11225
11389
  return false;
11226
11390
  }
11227
11391
  return outputNames.every((targetName) => {
11228
- const target = pipeline.renderTargets?.[targetName];
11392
+ const target = compositeShaderPass.renderTargets?.[targetName];
11229
11393
  if (!target?.storage) {
11230
11394
  return false;
11231
11395
  }
@@ -11237,7 +11401,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11237
11401
  const renderTargets = shaderPass.renderTargets;
11238
11402
  if (renderTargets && Object.keys(renderTargets).length > 0) {
11239
11403
  throw new Error(
11240
- `${ownerName}: ShaderPass.renderTargets is not supported; use ShaderPassPipeline.renderTargets instead`
11404
+ `${ownerName}: ShaderPass.renderTargets is not supported; use CompositeShaderPass.renderTargets instead`
11241
11405
  );
11242
11406
  }
11243
11407
  }
@@ -11426,8 +11590,212 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
11426
11590
  return [sourceAspect / outputAspect, 1];
11427
11591
  }
11428
11592
 
11429
- // src/modules/picking/picking-manager.ts
11593
+ // src/compute/kernel.ts
11430
11594
  var import_core29 = __toESM(require_core(), 1);
11595
+ var Kernel = class _Kernel {
11596
+ /** Creates a kernel while allowing the backend to compile its pipeline asynchronously. */
11597
+ static async createAsync(device, props) {
11598
+ const ownsCompilation = !import_core29.PipelineFactory.getAsyncCompilation(device);
11599
+ const asyncCompilation = ownsCompilation ? import_core29.PipelineFactory.beginAsyncCompilation(device) : import_core29.PipelineFactory.getAsyncCompilation(device);
11600
+ let kernel;
11601
+ try {
11602
+ kernel = new _Kernel(device, props);
11603
+ } finally {
11604
+ if (ownsCompilation) import_core29.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
11605
+ }
11606
+ try {
11607
+ if (ownsCompilation) {
11608
+ await Promise.all(asyncCompilation);
11609
+ } else {
11610
+ await kernel._pipelineInitialization;
11611
+ }
11612
+ return kernel;
11613
+ } catch (error) {
11614
+ kernel.destroy();
11615
+ throw error;
11616
+ }
11617
+ }
11618
+ device;
11619
+ id;
11620
+ source;
11621
+ pipelineFactory;
11622
+ shaderFactory;
11623
+ shader;
11624
+ pipeline;
11625
+ _pipelineInitialization;
11626
+ _destroyed = false;
11627
+ constructor(device, props) {
11628
+ if (device.type !== "webgpu") {
11629
+ throw new Error("Kernel is only supported in WebGPU");
11630
+ }
11631
+ const { source: source4, pipelineFactory, shaderFactory, debugShaders, ...pipelineProps } = props;
11632
+ this.device = device;
11633
+ this.id = props.id ?? "kernel";
11634
+ this.source = source4;
11635
+ this.pipelineFactory = pipelineFactory ?? import_core29.PipelineFactory.getDefaultPipelineFactory(device);
11636
+ this.shaderFactory = shaderFactory ?? import_core29.ShaderFactory.getDefaultShaderFactory(device);
11637
+ this.shader = this.shaderFactory.createShader({
11638
+ id: `${this.id}-compute`,
11639
+ stage: "compute",
11640
+ source: this.source,
11641
+ debugShaders
11642
+ });
11643
+ const computePipelineProps = { ...pipelineProps, shader: this.shader };
11644
+ const asyncCompilation = import_core29.PipelineFactory.getAsyncCompilation(device);
11645
+ if (asyncCompilation) {
11646
+ const pipelineInitialization = this.pipelineFactory.createComputePipelineAsync(computePipelineProps);
11647
+ this._pipelineInitialization = pipelineInitialization;
11648
+ asyncCompilation.push(
11649
+ pipelineInitialization.then((pipeline) => {
11650
+ this.pipeline = pipeline;
11651
+ return pipeline;
11652
+ })
11653
+ );
11654
+ } else {
11655
+ this.pipeline = this.pipelineFactory.createComputePipeline(computePipelineProps);
11656
+ }
11657
+ }
11658
+ /** Applies per-dispatch bindings and records a direct compute dispatch. */
11659
+ dispatch(computePass, options) {
11660
+ this._setPipeline(computePass, options.bindings);
11661
+ computePass.dispatch(options.x, options.y, options.z);
11662
+ }
11663
+ /** Applies per-dispatch bindings and records a GPU-driven indirect compute dispatch. */
11664
+ dispatchIndirect(computePass, options) {
11665
+ this._setPipeline(computePass, options.bindings);
11666
+ computePass.dispatchIndirect(options.indirectBuffer, options.indirectOffset ?? 0);
11667
+ }
11668
+ destroy() {
11669
+ if (this._destroyed) return;
11670
+ if (this.pipeline) this.pipelineFactory.release(this.pipeline);
11671
+ this.shaderFactory.release(this.shader);
11672
+ this._destroyed = true;
11673
+ }
11674
+ _setPipeline(computePass, bindings = {}) {
11675
+ computePass.setPipeline(this.pipeline);
11676
+ computePass.setBindings(bindings);
11677
+ }
11678
+ };
11679
+
11680
+ // src/compute/render-kernel.ts
11681
+ var import_core30 = __toESM(require_core(), 1);
11682
+ var RenderKernel = class _RenderKernel {
11683
+ /** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
11684
+ static async createAsync(device, props) {
11685
+ const ownsCompilation = !import_core30.PipelineFactory.getAsyncCompilation(device);
11686
+ const asyncCompilation = ownsCompilation ? import_core30.PipelineFactory.beginAsyncCompilation(device) : import_core30.PipelineFactory.getAsyncCompilation(device);
11687
+ let kernel;
11688
+ try {
11689
+ kernel = new _RenderKernel(device, props);
11690
+ } finally {
11691
+ if (ownsCompilation) import_core30.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
11692
+ }
11693
+ try {
11694
+ if (ownsCompilation) {
11695
+ await Promise.all(asyncCompilation);
11696
+ } else {
11697
+ await kernel._pipelineInitialization;
11698
+ }
11699
+ return kernel;
11700
+ } catch (error) {
11701
+ kernel.destroy();
11702
+ throw error;
11703
+ }
11704
+ }
11705
+ device;
11706
+ id;
11707
+ vertexSource;
11708
+ fragmentSource;
11709
+ pipelineFactory;
11710
+ shaderFactory;
11711
+ vertexShader;
11712
+ fragmentShader;
11713
+ pipeline;
11714
+ _pipelineInitialization;
11715
+ _destroyed = false;
11716
+ constructor(device, props) {
11717
+ if (device.type !== "webgpu") {
11718
+ throw new Error("RenderKernel is only supported in WebGPU");
11719
+ }
11720
+ const {
11721
+ vertexSource,
11722
+ fragmentSource,
11723
+ pipelineFactory,
11724
+ shaderFactory,
11725
+ debugShaders,
11726
+ ...pipelineProps
11727
+ } = props;
11728
+ this.device = device;
11729
+ this.id = props.id ?? "render-kernel";
11730
+ this.vertexSource = vertexSource;
11731
+ this.fragmentSource = fragmentSource;
11732
+ this.pipelineFactory = pipelineFactory ?? import_core30.PipelineFactory.getDefaultPipelineFactory(device);
11733
+ this.shaderFactory = shaderFactory ?? import_core30.ShaderFactory.getDefaultShaderFactory(device);
11734
+ this.vertexShader = this.shaderFactory.createShader({
11735
+ id: `${this.id}-vertex`,
11736
+ stage: "vertex",
11737
+ source: this.vertexSource,
11738
+ debugShaders
11739
+ });
11740
+ this.fragmentShader = this.fragmentSource ? this.shaderFactory.createShader({
11741
+ id: `${this.id}-fragment`,
11742
+ stage: "fragment",
11743
+ source: this.fragmentSource,
11744
+ debugShaders
11745
+ }) : null;
11746
+ const renderPipelineProps = {
11747
+ ...pipelineProps,
11748
+ vs: this.vertexShader,
11749
+ fs: this.fragmentShader
11750
+ };
11751
+ const asyncCompilation = import_core30.PipelineFactory.getAsyncCompilation(device);
11752
+ if (asyncCompilation) {
11753
+ const pipelineInitialization = this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
11754
+ this._pipelineInitialization = pipelineInitialization;
11755
+ asyncCompilation.push(
11756
+ pipelineInitialization.then((pipeline) => {
11757
+ this.pipeline = pipeline;
11758
+ return pipeline;
11759
+ })
11760
+ );
11761
+ } else {
11762
+ this.pipeline = this.pipelineFactory.createRenderPipeline(renderPipelineProps);
11763
+ }
11764
+ }
11765
+ /** Applies per-draw bindings/vertex state and records a direct draw. */
11766
+ draw(renderPass, options) {
11767
+ const { bindings = {}, vertexArray, ...drawOptions } = options;
11768
+ this._setPipeline(renderPass, bindings, vertexArray);
11769
+ return renderPass.draw(drawOptions);
11770
+ }
11771
+ /** Applies per-draw state and records a non-indexed indirect draw. */
11772
+ drawIndirect(renderPass, options) {
11773
+ const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
11774
+ this._setPipeline(renderPass, bindings, vertexArray);
11775
+ renderPass.drawIndirect(indirectBuffer, indirectOffset);
11776
+ }
11777
+ /** Applies per-draw state and records an indexed indirect draw. */
11778
+ drawIndexedIndirect(renderPass, options) {
11779
+ const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
11780
+ this._setPipeline(renderPass, bindings, vertexArray);
11781
+ renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
11782
+ }
11783
+ destroy() {
11784
+ if (this._destroyed) return;
11785
+ if (this.pipeline) this.pipelineFactory.release(this.pipeline);
11786
+ this.shaderFactory.release(this.vertexShader);
11787
+ if (this.fragmentShader) this.shaderFactory.release(this.fragmentShader);
11788
+ this._destroyed = true;
11789
+ }
11790
+ _setPipeline(renderPass, bindings, vertexArray) {
11791
+ renderPass.setPipeline(this.pipeline);
11792
+ renderPass.setBindings(bindings);
11793
+ renderPass.setVertexArray(vertexArray);
11794
+ }
11795
+ };
11796
+
11797
+ // src/modules/picking/picking-manager.ts
11798
+ var import_core31 = __toESM(require_core(), 1);
11431
11799
 
11432
11800
  // src/modules/picking/picking-uniforms.ts
11433
11801
  var DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
@@ -11691,13 +12059,13 @@ layout(std140) uniform pickingUniforms {
11691
12059
  format: "rgba8unorm",
11692
12060
  width: 1,
11693
12061
  height: 1,
11694
- usage: import_core29.Texture.RENDER_ATTACHMENT
12062
+ usage: import_core31.Texture.RENDER_ATTACHMENT
11695
12063
  });
11696
12064
  const pickingTexture = this.device.createTexture({
11697
12065
  format: "rg32sint",
11698
12066
  width: 1,
11699
12067
  height: 1,
11700
- usage: import_core29.Texture.RENDER_ATTACHMENT | import_core29.Texture.COPY_SRC
12068
+ usage: import_core31.Texture.RENDER_ATTACHMENT | import_core31.Texture.COPY_SRC
11701
12069
  });
11702
12070
  return this.device.createFramebuffer({
11703
12071
  colorAttachments: [colorTexture, pickingTexture],
@@ -11709,7 +12077,7 @@ layout(std140) uniform pickingUniforms {
11709
12077
  format: "rgba8unorm",
11710
12078
  width: 1,
11711
12079
  height: 1,
11712
- usage: import_core29.Texture.RENDER_ATTACHMENT | import_core29.Texture.COPY_SRC
12080
+ usage: import_core31.Texture.RENDER_ATTACHMENT | import_core31.Texture.COPY_SRC
11713
12081
  });
11714
12082
  return this.device.createFramebuffer({
11715
12083
  colorAttachments: [pickingTexture],
@@ -11731,7 +12099,7 @@ layout(std140) uniform pickingUniforms {
11731
12099
  const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
11732
12100
  const readBuffer = this.device.createBuffer({
11733
12101
  byteLength: layout.byteLength,
11734
- usage: import_core29.Buffer.COPY_DST | import_core29.Buffer.MAP_READ
12102
+ usage: import_core31.Buffer.COPY_DST | import_core31.Buffer.MAP_READ
11735
12103
  });
11736
12104
  try {
11737
12105
  pickTexture.readBuffer(
@@ -11767,7 +12135,7 @@ layout(std140) uniform pickingUniforms {
11767
12135
  const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
11768
12136
  const readBuffer = this.device.createBuffer({
11769
12137
  byteLength: layout.byteLength,
11770
- usage: import_core29.Buffer.COPY_DST | import_core29.Buffer.MAP_READ
12138
+ usage: import_core31.Buffer.COPY_DST | import_core31.Buffer.MAP_READ
11771
12139
  });
11772
12140
  try {
11773
12141
  pickTexture.readBuffer(