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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.dev.js CHANGED
@@ -7507,13 +7507,47 @@ void main(void) {
7507
7507
  };
7508
7508
 
7509
7509
  // src/scenegraph/group-node.ts
7510
- var import_core20 = __toESM(require_core(), 1);
7510
+ var import_core21 = __toESM(require_core(), 1);
7511
+
7512
+ // src/scenegraph/scenegraph-bounds.ts
7513
+ function makeEmptyScenegraphBounds() {
7514
+ return [
7515
+ [Infinity, Infinity, Infinity],
7516
+ [-Infinity, -Infinity, -Infinity]
7517
+ ];
7518
+ }
7519
+ function expandScenegraphBounds(targetBounds, sourceBounds, transform) {
7520
+ const transformMatrix = new Matrix4(transform);
7521
+ for (let cornerIndex = 0; cornerIndex < 8; cornerIndex++) {
7522
+ const corner = new Vector3(
7523
+ sourceBounds[cornerIndex & 1 ? 1 : 0][0],
7524
+ sourceBounds[cornerIndex & 2 ? 1 : 0][1],
7525
+ sourceBounds[cornerIndex & 4 ? 1 : 0][2]
7526
+ );
7527
+ transformMatrix.transformAsPoint(corner, corner);
7528
+ for (let componentIndex = 0; componentIndex < 3; componentIndex++) {
7529
+ targetBounds[0][componentIndex] = Math.min(
7530
+ targetBounds[0][componentIndex],
7531
+ corner[componentIndex]
7532
+ );
7533
+ targetBounds[1][componentIndex] = Math.max(
7534
+ targetBounds[1][componentIndex],
7535
+ corner[componentIndex]
7536
+ );
7537
+ }
7538
+ }
7539
+ }
7540
+ function areScenegraphBoundsDefined(bounds) {
7541
+ return Number.isFinite(bounds[0][0]);
7542
+ }
7543
+
7544
+ // src/scenegraph/group-node.ts
7511
7545
  var GroupNode = class extends ScenegraphNode {
7512
7546
  children;
7513
7547
  constructor(props = {}) {
7514
7548
  props = Array.isArray(props) ? { children: props } : props;
7515
7549
  const { children = [] } = props;
7516
- import_core20.log.assert(
7550
+ import_core21.log.assert(
7517
7551
  children.every((child) => child instanceof ScenegraphNode),
7518
7552
  "every child must an instance of ScenegraphNode"
7519
7553
  );
@@ -7521,32 +7555,16 @@ void main(void) {
7521
7555
  this.children = children;
7522
7556
  }
7523
7557
  getBounds() {
7524
- const result = [
7525
- [Infinity, Infinity, Infinity],
7526
- [-Infinity, -Infinity, -Infinity]
7527
- ];
7558
+ const result = makeEmptyScenegraphBounds();
7528
7559
  this.traverse((node, { worldMatrix }) => {
7529
7560
  const bounds = node.getBounds();
7530
7561
  if (!bounds) {
7531
7562
  return;
7532
7563
  }
7533
- const [min, max] = bounds;
7534
- const center = new Vector3(min).add(max).divide([2, 2, 2]);
7535
- worldMatrix.transformAsPoint(center, center);
7536
- const halfSize = new Vector3(max).subtract(min).divide([2, 2, 2]);
7537
- worldMatrix.transformAsVector(halfSize, halfSize);
7538
- for (let v = 0; v < 8; v++) {
7539
- const position = new Vector3(v & 1 ? -1 : 1, v & 2 ? -1 : 1, v & 4 ? -1 : 1).multiply(halfSize).add(center);
7540
- for (let i = 0; i < 3; i++) {
7541
- result[0][i] = Math.min(result[0][i], position[i]);
7542
- result[1][i] = Math.max(result[1][i], position[i]);
7543
- }
7544
- }
7564
+ const nodeWorldMatrix = new Matrix4(worldMatrix).multiplyRight(node.matrix);
7565
+ expandScenegraphBounds(result, bounds, nodeWorldMatrix);
7545
7566
  });
7546
- if (!Number.isFinite(result[0][0])) {
7547
- return null;
7548
- }
7549
- return result;
7567
+ return areScenegraphBoundsDefined(result) ? result : null;
7550
7568
  }
7551
7569
  destroy() {
7552
7570
  this.children.forEach((child) => child.destroy());
@@ -7586,6 +7604,33 @@ void main(void) {
7586
7604
  }
7587
7605
  }
7588
7606
  }
7607
+ /** Visits leaf nodes ordered by the camera-space centers of their aggregate bounds. */
7608
+ traverseDepthSorted(visitor, { viewMatrix, worldMatrix = new Matrix4(), order = "back-to-front" }) {
7609
+ const cameraMatrix = new Matrix4(viewMatrix);
7610
+ const nodes = [];
7611
+ this.traverse(
7612
+ (node, context) => {
7613
+ const bounds = node.getBounds();
7614
+ const center = bounds ? new Vector3(bounds[0]).add(bounds[1]).divide([2, 2, 2]) : new Vector3();
7615
+ const nodeWorldMatrix = new Matrix4(context.worldMatrix).multiplyRight(node.matrix);
7616
+ nodeWorldMatrix.transformAsPoint(center, center);
7617
+ cameraMatrix.transformAsPoint(center, center);
7618
+ nodes.push({
7619
+ node,
7620
+ context: { worldMatrix: nodeWorldMatrix, bounds, depth: -center[2] },
7621
+ index: nodes.length
7622
+ });
7623
+ },
7624
+ { worldMatrix: new Matrix4(worldMatrix) }
7625
+ );
7626
+ const direction = order === "back-to-front" ? -1 : 1;
7627
+ nodes.sort(
7628
+ (first, second) => direction * (first.context.depth - second.context.depth) || first.index - second.index
7629
+ );
7630
+ for (const { node, context } of nodes) {
7631
+ visitor(node, context);
7632
+ }
7633
+ }
7589
7634
  preorderTraversal(visitor, { worldMatrix = new Matrix4() } = {}) {
7590
7635
  const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);
7591
7636
  visitor(this, { worldMatrix: modelMatrix });
@@ -7602,6 +7647,7 @@ void main(void) {
7602
7647
  // src/scenegraph/model-node.ts
7603
7648
  var ModelNode = class extends ScenegraphNode {
7604
7649
  model;
7650
+ instanceMatrices;
7605
7651
  bounds = null;
7606
7652
  managedResources;
7607
7653
  // TODO - is this used? override callbacks to make sure we call them with this
@@ -7612,7 +7658,8 @@ void main(void) {
7612
7658
  super(props);
7613
7659
  this.model = props.model;
7614
7660
  this.managedResources = props.managedResources || [];
7615
- this.bounds = props.bounds || null;
7661
+ this.instanceMatrices = props.instanceMatrices || null;
7662
+ this.bounds = props.bounds ? this.instanceMatrices ? getInstancedScenegraphBounds(props.bounds, this.instanceMatrices) : props.bounds : null;
7616
7663
  this.setProps(props);
7617
7664
  }
7618
7665
  destroy() {
@@ -7631,6 +7678,13 @@ void main(void) {
7631
7678
  return this.model.draw(renderPass);
7632
7679
  }
7633
7680
  };
7681
+ function getInstancedScenegraphBounds(bounds, instanceMatrices) {
7682
+ const instancedBounds = makeEmptyScenegraphBounds();
7683
+ for (const instanceMatrix of instanceMatrices) {
7684
+ expandScenegraphBounds(instancedBounds, bounds, instanceMatrix);
7685
+ }
7686
+ return areScenegraphBoundsDefined(instancedBounds) ? instancedBounds : null;
7687
+ }
7634
7688
 
7635
7689
  // src/geometries/cube-geometry.ts
7636
7690
  var CubeGeometry = class extends Geometry {
@@ -8624,7 +8678,7 @@ void main(void) {
8624
8678
  }
8625
8679
 
8626
8680
  // src/dynamic-texture/video-texture.ts
8627
- var import_core22 = __toESM(require_core(), 1);
8681
+ var import_core23 = __toESM(require_core(), 1);
8628
8682
  var VideoTexture = class {
8629
8683
  /** Device used to create copied and native external texture bindings. */
8630
8684
  device;
@@ -8673,7 +8727,7 @@ void main(void) {
8673
8727
  * @param props Live video source and copied texture options.
8674
8728
  */
8675
8729
  constructor(device, props) {
8676
- (0, import_core22.assert)(isHTMLVideoElementSource(props?.source) || isVideoFrameSource(props?.source));
8730
+ (0, import_core23.assert)(isHTMLVideoElementSource(props?.source) || isVideoFrameSource(props?.source));
8677
8731
  this.device = device;
8678
8732
  this.id = props.id || uid("video-texture");
8679
8733
  this._source = props.source;
@@ -8687,7 +8741,7 @@ void main(void) {
8687
8741
  * @param source Next caller-owned video source to follow.
8688
8742
  */
8689
8743
  setSource(source4) {
8690
- (0, import_core22.assert)(isHTMLVideoElementSource(source4) || isVideoFrameSource(source4));
8744
+ (0, import_core23.assert)(isHTMLVideoElementSource(source4) || isVideoFrameSource(source4));
8691
8745
  this._destroyExternalTexture();
8692
8746
  this._source = source4;
8693
8747
  this._sourceVersion++;
@@ -8765,7 +8819,7 @@ void main(void) {
8765
8819
  width: size.width,
8766
8820
  height: size.height,
8767
8821
  format: "rgba8unorm",
8768
- usage: import_core22.Texture.SAMPLE | import_core22.Texture.COPY_DST,
8822
+ usage: import_core23.Texture.SAMPLE | import_core23.Texture.COPY_DST,
8769
8823
  mipLevels: 1,
8770
8824
  sampler: this._sampler
8771
8825
  });
@@ -8800,7 +8854,7 @@ void main(void) {
8800
8854
  */
8801
8855
  _getResolvedSize() {
8802
8856
  const size = getVideoTextureSourceSize(this._source);
8803
- (0, import_core22.assert)(size.width > 0 && size.height > 0);
8857
+ (0, import_core23.assert)(size.width > 0 && size.height > 0);
8804
8858
  return size;
8805
8859
  }
8806
8860
  /** Observes current source readiness and frame identity before binding resolution. */
@@ -8865,11 +8919,11 @@ void main(void) {
8865
8919
  }
8866
8920
 
8867
8921
  // src/passes/shader-pass-renderer.ts
8868
- var import_core24 = __toESM(require_core(), 1);
8922
+ var import_core25 = __toESM(require_core(), 1);
8869
8923
  var import_shadertools5 = __toESM(require_shadertools(), 1);
8870
8924
 
8871
8925
  // src/compute/swap.ts
8872
- var import_core23 = __toESM(require_core(), 1);
8926
+ var import_core24 = __toESM(require_core(), 1);
8873
8927
  var Swap = class {
8874
8928
  id;
8875
8929
  /** The current resource - usually the source for renders or computations */
@@ -8901,7 +8955,7 @@ void main(void) {
8901
8955
  (colorAttachment) => typeof colorAttachment !== "string" ? colorAttachment : device.createTexture({
8902
8956
  id: `${props.id}-texture-0`,
8903
8957
  format: colorAttachment,
8904
- usage: import_core23.Texture.SAMPLE | import_core23.Texture.RENDER | import_core23.Texture.COPY_SRC | import_core23.Texture.COPY_DST,
8958
+ usage: import_core24.Texture.SAMPLE | import_core24.Texture.RENDER | import_core24.Texture.COPY_SRC | import_core24.Texture.COPY_DST,
8905
8959
  width,
8906
8960
  height
8907
8961
  })
@@ -8911,7 +8965,7 @@ void main(void) {
8911
8965
  (colorAttachment) => typeof colorAttachment !== "string" ? colorAttachment : device.createTexture({
8912
8966
  id: `${props.id}-texture-1`,
8913
8967
  format: colorAttachment,
8914
- usage: import_core23.Texture.SAMPLE | import_core23.Texture.RENDER | import_core23.Texture.COPY_SRC | import_core23.Texture.COPY_DST,
8968
+ usage: import_core24.Texture.SAMPLE | import_core24.Texture.RENDER | import_core24.Texture.COPY_SRC | import_core24.Texture.COPY_DST,
8915
8969
  width,
8916
8970
  height
8917
8971
  })
@@ -9628,7 +9682,8 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
9628
9682
  width: targetSize[0],
9629
9683
  height: targetSize[1],
9630
9684
  format: spec.format || device.preferredColorFormat,
9631
- usage: import_core24.Texture.SAMPLE | import_core24.Texture.RENDER | import_core24.Texture.COPY_SRC | import_core24.Texture.COPY_DST
9685
+ usage: import_core25.Texture.SAMPLE | import_core25.Texture.RENDER | import_core25.Texture.COPY_SRC | import_core25.Texture.COPY_DST,
9686
+ ...spec.sampler ? { sampler: spec.sampler } : {}
9632
9687
  });
9633
9688
  const framebuffer = device.createFramebuffer({
9634
9689
  id: `${name}-framebuffer`,
@@ -9682,7 +9737,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
9682
9737
  }
9683
9738
 
9684
9739
  // src/compute/computation.ts
9685
- var import_core25 = __toESM(require_core(), 1);
9740
+ var import_core26 = __toESM(require_core(), 1);
9686
9741
  var import_shadertools6 = __toESM(require_shadertools(), 1);
9687
9742
  var LOG_DRAW_PRIORITY2 = 2;
9688
9743
  var LOG_DRAW_TIMEOUT2 = 1e4;
@@ -9736,8 +9791,8 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
9736
9791
  const modules = mergeShaderModules(this.props.modules, this.shaderInputs?.getModules());
9737
9792
  const defines = { ...resolvedPlugins.defines, ...this.props.defines };
9738
9793
  this.props.shaderLayout = mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
9739
- this.pipelineFactory = props.pipelineFactory || import_core25.PipelineFactory.getDefaultPipelineFactory(this.device);
9740
- this.shaderFactory = props.shaderFactory || import_core25.ShaderFactory.getDefaultShaderFactory(this.device);
9794
+ this.pipelineFactory = props.pipelineFactory || import_core26.PipelineFactory.getDefaultPipelineFactory(this.device);
9795
+ this.shaderFactory = props.shaderFactory || import_core26.ShaderFactory.getDefaultShaderFactory(this.device);
9741
9796
  const { source: source4, getUniforms: getUniforms2 } = this.props.shaderAssembler.assembleWGSLShader({
9742
9797
  platformInfo,
9743
9798
  ...this.props,
@@ -9801,7 +9856,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
9801
9856
  }
9802
9857
  setShaderInputs(shaderInputs) {
9803
9858
  this.shaderInputs = shaderInputs;
9804
- this._uniformStore = new import_core25.UniformStore(this.device, this.shaderInputs.modules);
9859
+ this._uniformStore = new import_core26.UniformStore(this.device, this.shaderInputs.modules);
9805
9860
  for (const [moduleName, module] of Object.entries(this.shaderInputs.modules)) {
9806
9861
  if (shaderModuleHasUniforms(module)) {
9807
9862
  const uniformBuffer = this._uniformStore.getManagedUniformBuffer(moduleName);
@@ -9846,7 +9901,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
9846
9901
  if (this._pipelineNeedsUpdate) {
9847
9902
  let prevShader = null;
9848
9903
  if (this.pipeline) {
9849
- import_core25.log.log(
9904
+ import_core26.log.log(
9850
9905
  1,
9851
9906
  `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`
9852
9907
  )();
@@ -9873,33 +9928,33 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
9873
9928
  _lastLogTime = 0;
9874
9929
  _logOpen = false;
9875
9930
  _logDrawCallStart() {
9876
- const logDrawTimeout = import_core25.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT2;
9877
- if (import_core25.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
9931
+ const logDrawTimeout = import_core26.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT2;
9932
+ if (import_core26.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
9878
9933
  return;
9879
9934
  }
9880
9935
  this._lastLogTime = Date.now();
9881
9936
  this._logOpen = true;
9882
- import_core25.log.group(LOG_DRAW_PRIORITY2, `>>> DRAWING MODEL ${this.id}`, { collapsed: import_core25.log.level <= 2 })();
9937
+ import_core26.log.group(LOG_DRAW_PRIORITY2, `>>> DRAWING MODEL ${this.id}`, { collapsed: import_core26.log.level <= 2 })();
9883
9938
  }
9884
9939
  _logDrawCallEnd() {
9885
9940
  if (this._logOpen) {
9886
9941
  const uniformTable = this.shaderInputs.getDebugTable();
9887
- import_core25.log.table(LOG_DRAW_PRIORITY2, uniformTable)();
9888
- import_core25.log.groupEnd(LOG_DRAW_PRIORITY2)();
9942
+ import_core26.log.table(LOG_DRAW_PRIORITY2, uniformTable)();
9943
+ import_core26.log.groupEnd(LOG_DRAW_PRIORITY2)();
9889
9944
  this._logOpen = false;
9890
9945
  }
9891
9946
  }
9892
9947
  _drawCount = 0;
9893
9948
  // TODO - fix typing of luma data types
9894
9949
  _getBufferOrConstantValues(attribute, dataType) {
9895
- const TypedArrayConstructor = import_core25.dataTypeDecoder.getTypedArrayConstructor(dataType);
9896
- const typedArray = attribute instanceof import_core25.Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
9950
+ const TypedArrayConstructor = import_core26.dataTypeDecoder.getTypedArrayConstructor(dataType);
9951
+ const typedArray = attribute instanceof import_core26.Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
9897
9952
  return typedArray.toString();
9898
9953
  }
9899
9954
  };
9900
9955
  var Computation = _Computation;
9901
9956
  __publicField(Computation, "defaultProps", {
9902
- ...import_core25.ComputePipeline.defaultProps,
9957
+ ...import_core26.ComputePipeline.defaultProps,
9903
9958
  id: "unnamed",
9904
9959
  handle: void 0,
9905
9960
  userData: {},
@@ -9927,7 +9982,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
9927
9982
  }
9928
9983
 
9929
9984
  // src/modules/picking/picking-manager.ts
9930
- var import_core26 = __toESM(require_core(), 1);
9985
+ var import_core27 = __toESM(require_core(), 1);
9931
9986
 
9932
9987
  // src/modules/picking/picking-uniforms.ts
9933
9988
  var DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
@@ -10183,13 +10238,13 @@ layout(std140) uniform pickingUniforms {
10183
10238
  format: "rgba8unorm",
10184
10239
  width: 1,
10185
10240
  height: 1,
10186
- usage: import_core26.Texture.RENDER_ATTACHMENT
10241
+ usage: import_core27.Texture.RENDER_ATTACHMENT
10187
10242
  });
10188
10243
  const pickingTexture = this.device.createTexture({
10189
10244
  format: "rg32sint",
10190
10245
  width: 1,
10191
10246
  height: 1,
10192
- usage: import_core26.Texture.RENDER_ATTACHMENT | import_core26.Texture.COPY_SRC
10247
+ usage: import_core27.Texture.RENDER_ATTACHMENT | import_core27.Texture.COPY_SRC
10193
10248
  });
10194
10249
  return this.device.createFramebuffer({
10195
10250
  colorAttachments: [colorTexture, pickingTexture],
@@ -10201,7 +10256,7 @@ layout(std140) uniform pickingUniforms {
10201
10256
  format: "rgba8unorm",
10202
10257
  width: 1,
10203
10258
  height: 1,
10204
- usage: import_core26.Texture.RENDER_ATTACHMENT | import_core26.Texture.COPY_SRC
10259
+ usage: import_core27.Texture.RENDER_ATTACHMENT | import_core27.Texture.COPY_SRC
10205
10260
  });
10206
10261
  return this.device.createFramebuffer({
10207
10262
  colorAttachments: [pickingTexture],
@@ -10223,7 +10278,7 @@ layout(std140) uniform pickingUniforms {
10223
10278
  const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
10224
10279
  const readBuffer = this.device.createBuffer({
10225
10280
  byteLength: layout.byteLength,
10226
- usage: import_core26.Buffer.COPY_DST | import_core26.Buffer.MAP_READ
10281
+ usage: import_core27.Buffer.COPY_DST | import_core27.Buffer.MAP_READ
10227
10282
  });
10228
10283
  try {
10229
10284
  pickTexture.readBuffer(
@@ -10259,7 +10314,7 @@ layout(std140) uniform pickingUniforms {
10259
10314
  const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
10260
10315
  const readBuffer = this.device.createBuffer({
10261
10316
  byteLength: layout.byteLength,
10262
- usage: import_core26.Buffer.COPY_DST | import_core26.Buffer.MAP_READ
10317
+ usage: import_core27.Buffer.COPY_DST | import_core27.Buffer.MAP_READ
10263
10318
  });
10264
10319
  try {
10265
10320
  pickTexture.readBuffer(