@luma.gl/engine 9.0.0-alpha.45 → 9.0.0-alpha.47

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
@@ -1308,10 +1308,10 @@ var __exports__ = (() => {
1308
1308
  // Device loss
1309
1309
  /** `true` if device is already lost */
1310
1310
  /** Promise that resolves when device is lost */
1311
- /**
1312
- * Trigger device loss.
1313
- * @returns `true` if context loss could actually be triggered.
1314
- * @note primarily intended for testing how application reacts to device loss
1311
+ /**
1312
+ * Trigger device loss.
1313
+ * @returns `true` if context loss could actually be triggered.
1314
+ * @note primarily intended for testing how application reacts to device loss
1315
1315
  */
1316
1316
  loseDevice() {
1317
1317
  return false;
@@ -1340,9 +1340,10 @@ var __exports__ = (() => {
1340
1340
  }
1341
1341
  /** Create a temporary texture view of a video source */
1342
1342
  /** Create a sampler */
1343
+ /** Create a Framebuffer. Must have at least one attachment. */
1343
1344
  /** Create a shader */
1344
1345
  /** Create a render pipeline (aka program) */
1345
- /** Create a compute pipeline (aka program) */
1346
+ /** Create a compute pipeline (aka program). WebGPU only. */
1346
1347
  createCommandEncoder(props = {}) {
1347
1348
  throw new Error("not implemented");
1348
1349
  }
@@ -1350,7 +1351,8 @@ var __exports__ = (() => {
1350
1351
  /** Create a RenderPass */
1351
1352
  /** Create a ComputePass */
1352
1353
  /** Get a renderpass that is set up to render to the primary CanvasContext */
1353
- // Resource creation helpers
1354
+ /** Create a transform feedback (immutable set of output buffer bindings). WebGL 2 only. */
1355
+ // Implementation
1354
1356
  _getBufferProps(props) {
1355
1357
  if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
1356
1358
  props = {
@@ -1446,10 +1448,10 @@ var __exports__ = (() => {
1446
1448
  this.bufferLayout = this.props.bufferLayout || [];
1447
1449
  }
1448
1450
  /** Set bindings (stored on pipeline and set before each call) */
1449
- /** Uniforms
1451
+ /** Uniforms
1450
1452
  * @deprecated Only supported on WebGL devices.
1451
1453
  * @note textures, samplers and uniform buffers should be set via `setBindings()`, these are not considered uniforms.
1452
- * @note In WebGL uniforms have a performance penalty, they are reset before each call to enable pipeline sharing.
1454
+ * @note In WebGL uniforms have a performance penalty, they are reset before each call to enable pipeline sharing.
1453
1455
  */
1454
1456
  /** Draw call */
1455
1457
  };
@@ -1906,6 +1908,53 @@ var __exports__ = (() => {
1906
1908
  }
1907
1909
  };
1908
1910
 
1911
+ // ../core/src/adapter/type-utils/vertex-format-from-attribute.ts
1912
+ function getDataTypeFromTypedArray(arrayOrType) {
1913
+ const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
1914
+ switch (type) {
1915
+ case Float32Array:
1916
+ return "float32";
1917
+ case Uint16Array:
1918
+ return "uint16";
1919
+ case Uint32Array:
1920
+ return "uint32";
1921
+ case Uint8Array:
1922
+ case Uint8ClampedArray:
1923
+ return "uint8";
1924
+ case Int8Array:
1925
+ return "sint8";
1926
+ case Int16Array:
1927
+ return "sint16";
1928
+ case Int32Array:
1929
+ return "sint32";
1930
+ default:
1931
+ throw new Error(type.constructor.name);
1932
+ }
1933
+ }
1934
+ function getVertexFormatFromAttribute(typedArray, size) {
1935
+ if (!size || size > 4) {
1936
+ throw new Error(`size ${size}`);
1937
+ }
1938
+ const components = size;
1939
+ const dataType = getDataTypeFromTypedArray(typedArray);
1940
+ if (dataType === "uint8" || dataType === "sint8") {
1941
+ if (components === 1 || components === 3) {
1942
+ throw new Error(`size: ${size}`);
1943
+ }
1944
+ return `${dataType}x${components}`;
1945
+ }
1946
+ if (dataType === "uint16" || dataType === "sint16") {
1947
+ if (components === 1 || components === 3) {
1948
+ throw new Error(`size: ${size}`);
1949
+ }
1950
+ return `${dataType}x${components}`;
1951
+ }
1952
+ if (components === 1) {
1953
+ return dataType;
1954
+ }
1955
+ return `${dataType}x${components}`;
1956
+ }
1957
+
1909
1958
  // ../core/src/lib/utils/uniform.ts
1910
1959
  function isUniformValue(value) {
1911
1960
  return isNumberArray(value) !== null || typeof value === "number" || typeof value === "boolean";
@@ -3393,6 +3442,88 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
3393
3442
  }
3394
3443
  };
3395
3444
 
3445
+ // ../shadertools/src/lib/glsl-utils/get-shader-info.ts
3446
+ function getShaderInfo(source, defaultName) {
3447
+ return {
3448
+ name: getShaderName(source, defaultName),
3449
+ language: "glsl",
3450
+ version: getShaderVersion(source)
3451
+ };
3452
+ }
3453
+ function getShaderName(shader, defaultName = "unnamed") {
3454
+ const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
3455
+ const match = SHADER_NAME_REGEXP.exec(shader);
3456
+ return match ? match[1] : defaultName;
3457
+ }
3458
+ function getShaderVersion(source) {
3459
+ let version = 100;
3460
+ const words = source.match(/[^\s]+/g);
3461
+ if (words && words.length >= 2 && words[0] === "#version") {
3462
+ const v = parseInt(words[1], 10);
3463
+ if (Number.isFinite(v)) {
3464
+ version = v;
3465
+ }
3466
+ }
3467
+ return version;
3468
+ }
3469
+
3470
+ // ../shadertools/src/lib/glsl-utils/shader-utils.ts
3471
+ var FS100 = glsl2`void main() {gl_FragColor = vec4(0);}`;
3472
+ var FS_GLES = glsl2`\
3473
+ out vec4 transform_output;
3474
+ void main() {
3475
+ transform_output = vec4(0);
3476
+ }`;
3477
+ var FS300 = `#version 300 es
3478
+ ${FS_GLES}`;
3479
+ function getPassthroughFS(options) {
3480
+ const {
3481
+ version = 100,
3482
+ input,
3483
+ inputType,
3484
+ output
3485
+ } = options || {};
3486
+ if (!input) {
3487
+ if (version === 300) {
3488
+ return FS300;
3489
+ } else if (version > 300) {
3490
+ return `#version ${version}
3491
+ ${FS_GLES}`;
3492
+ }
3493
+ return FS100;
3494
+ }
3495
+ if (!inputType) {
3496
+ throw new Error("inputType");
3497
+ }
3498
+ const outputValue = convertToVec4(input, inputType);
3499
+ if (version >= 300) {
3500
+ return `#version ${version} ${version === 300 ? "es" : ""}
3501
+ in ${inputType} ${input};
3502
+ out vec4 ${output};
3503
+ void main() {
3504
+ ${output} = ${outputValue};
3505
+ }`;
3506
+ }
3507
+ return `varying ${inputType} ${input};
3508
+ void main() {
3509
+ gl_FragColor = ${outputValue};
3510
+ }`;
3511
+ }
3512
+ function convertToVec4(variable, type) {
3513
+ switch (type) {
3514
+ case "float":
3515
+ return `vec4(${variable}, 0.0, 0.0, 1.0)`;
3516
+ case "vec2":
3517
+ return `vec4(${variable}, 0.0, 1.0)`;
3518
+ case "vec3":
3519
+ return `vec4(${variable}, 1.0)`;
3520
+ case "vec4":
3521
+ return variable;
3522
+ default:
3523
+ throw new Error(type);
3524
+ }
3525
+ }
3526
+
3396
3527
  // ../../node_modules/@math.gl/core/dist/lib/common.js
3397
3528
  var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
3398
3529
  var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
@@ -5366,9 +5497,13 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
5366
5497
  data: attribute.value,
5367
5498
  id: `${attributeName}-buffer`
5368
5499
  });
5500
+ const {
5501
+ value,
5502
+ size
5503
+ } = attribute;
5369
5504
  bufferLayout.push({
5370
5505
  name: name2,
5371
- format: `float32x${attribute.size}`
5506
+ format: getVertexFormatFromAttribute(value, size)
5372
5507
  });
5373
5508
  }
5374
5509
  const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
@@ -5501,6 +5636,8 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
5501
5636
  * @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
5502
5637
  * @todo - allow application to define multiple vertex arrays?
5503
5638
  * */
5639
+ /** TransformFeedback, WebGL 2 only. */
5640
+ transformFeedback = null;
5504
5641
  _pipelineNeedsUpdate = "newly created";
5505
5642
  _attributeInfos = {};
5506
5643
  _gpuGeometry = null;
@@ -5570,6 +5707,9 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
5570
5707
  if (props.moduleSettings) {
5571
5708
  this.updateModuleSettings(props.moduleSettings);
5572
5709
  }
5710
+ if (props.transformFeedback) {
5711
+ this.transformFeedback = props.transformFeedback;
5712
+ }
5573
5713
  this.setUniforms(this._getModuleUniforms());
5574
5714
  Object.seal(this);
5575
5715
  }
@@ -5585,7 +5725,8 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
5585
5725
  renderPass,
5586
5726
  vertexArray: this.vertexArray,
5587
5727
  vertexCount: this.vertexCount,
5588
- instanceCount: this.instanceCount
5728
+ instanceCount: this.instanceCount,
5729
+ transformFeedback: this.transformFeedback
5589
5730
  });
5590
5731
  }
5591
5732
  // Update fixed fields (can trigger pipeline rebuild)
@@ -5675,6 +5816,12 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
5675
5816
  Object.assign(this.bindings, bindings);
5676
5817
  Object.assign(this.uniforms, uniforms);
5677
5818
  }
5819
+ /**
5820
+ * Updates optional transform feedback. WebGL 2 only.
5821
+ */
5822
+ setTransformFeedback(transformFeedback) {
5823
+ this.transformFeedback = transformFeedback;
5824
+ }
5678
5825
  /**
5679
5826
  * @deprecated Updates shader module settings (which results in uniforms being set)
5680
5827
  */
@@ -5715,6 +5862,7 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
5715
5862
  for (const [bufferName, buffer] of Object.entries(buffers)) {
5716
5863
  const bufferLayout = this.bufferLayout.find((layout) => layout.name === bufferName);
5717
5864
  if (!bufferLayout) {
5865
+ log.warn(`Model(${this.id}): Missing layout for buffer "${bufferName}".`)();
5718
5866
  continue;
5719
5867
  }
5720
5868
  const attributeNames = bufferLayout.attributes ? bufferLayout.attributes?.map((layout) => layout.attribute) : [bufferLayout.name];
@@ -5794,7 +5942,9 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
5794
5942
  indexBuffer: null,
5795
5943
  attributes: {},
5796
5944
  constantAttributes: {},
5945
+ varyings: [],
5797
5946
  pipelineFactory: void 0,
5947
+ transformFeedback: void 0,
5798
5948
  shaderAssembler: ShaderAssembler.getDefaultShaderAssembler()
5799
5949
  });
5800
5950
  function mergeBufferLayouts(layouts1, layouts2) {
@@ -5812,68 +5962,120 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
5812
5962
 
5813
5963
  // src/transform/transform.ts
5814
5964
  var Transform = class {
5815
- /**
5816
- * Check if Transforms are supported (they are not under WebGL1)
5817
- * @todo differentiate writing to buffer vs not
5818
- */
5965
+ /** @deprecated Use device feature test. */
5819
5966
  static isSupported(device) {
5820
- return false;
5967
+ return device.features.has("transform-feedback-webgl2");
5821
5968
  }
5822
- // model: Model;
5823
- elementCount = 0;
5824
5969
  // bufferTransform: BufferTransform | null = null;
5825
5970
  // textureTransform: TextureTransform | null = null;
5826
5971
  elementIDBuffer = null;
5827
5972
  constructor(device, props = {}) {
5973
+ assert2(device.features.has("transform-feedback-webgl2"), "Device must support transform feedback");
5974
+ this.device = device;
5975
+ this.model = new Model(this.device, {
5976
+ vs: props.vs,
5977
+ fs: props.fs || getPassthroughFS({
5978
+ version: getShaderInfo(props.vs).version
5979
+ }),
5980
+ id: props.id || "transform-model",
5981
+ varyings: props.varyings,
5982
+ attributes: props.attributes,
5983
+ bufferLayout: props.bufferLayout,
5984
+ topology: props.topology || "point-list",
5985
+ vertexCount: props.vertexCount,
5986
+ defines: props.defines,
5987
+ modules: props.modules
5988
+ });
5989
+ this.transformFeedback = this.device.createTransformFeedback({
5990
+ layout: this.model.pipeline.shaderLayout,
5991
+ buffers: props.feedbackBuffers
5992
+ });
5993
+ this.model.setTransformFeedback(this.transformFeedback);
5994
+ Object.seal(this);
5828
5995
  }
5829
- /** Delete owned resources. */
5996
+ /** Destroy owned resources. */
5830
5997
  destroy() {
5831
- }
5832
- /** @deprecated Use destroy*() */
5833
- delete() {
5834
- this.destroy();
5998
+ if (this.model) {
5999
+ this.model.destroy();
6000
+ }
5835
6001
  }
5836
6002
  /** Run one transform loop. */
5837
6003
  run(options) {
5838
6004
  const {
5839
- clearRenderTarget = true
6005
+ framebuffer,
6006
+ parameters,
6007
+ discard,
6008
+ uniforms
5840
6009
  } = options || {};
5841
- const updatedOpts = this._updateDrawOptions(options);
5842
- if (clearRenderTarget && updatedOpts.framebuffer) {
5843
- }
6010
+ const renderPass = this.device.beginRenderPass({
6011
+ framebuffer,
6012
+ parameters,
6013
+ discard
6014
+ });
6015
+ if (uniforms)
6016
+ this.model.setUniforms(uniforms);
6017
+ this.model.draw(renderPass);
6018
+ renderPass.end();
5844
6019
  }
5845
6020
  /** swap resources if a map is provided */
5846
6021
  swap() {
6022
+ throw new Error("Not implemented");
5847
6023
  }
5848
- /** Return Buffer object for given varying name. */
6024
+ /** Returns the {@link Buffer} or {@link BufferRange} for given varying name. */
5849
6025
  getBuffer(varyingName) {
5850
- return null;
6026
+ return this.transformFeedback.getBuffer(varyingName);
5851
6027
  }
5852
- /** Return data either from Buffer or from Texture */
6028
+ readAsync(varyingName) {
6029
+ const result = this.getBuffer(varyingName);
6030
+ if (result instanceof Buffer2) {
6031
+ return result.readAsync();
6032
+ }
6033
+ const {
6034
+ buffer,
6035
+ byteOffset = 0,
6036
+ byteLength = buffer.byteLength
6037
+ } = result;
6038
+ return buffer.readAsync(byteOffset, byteLength);
6039
+ }
6040
+ /**
6041
+ * Return data either from Buffer or from Texture.
6042
+ * @deprecated Prefer {@link readAsync}.
6043
+ */
5853
6044
  getData(options = {}) {
6045
+ throw new Error("Not implemented");
5854
6046
  }
5855
6047
  /** Return framebuffer object if rendering to textures */
5856
6048
  getFramebuffer() {
5857
- return null;
6049
+ throw new Error("Not implemented");
5858
6050
  }
5859
6051
  /** Update some or all buffer/texture bindings. */
5860
6052
  update(props) {
6053
+ throw new Error("Not implemented");
5861
6054
  }
5862
6055
  // Private
5863
6056
  _updateModelProps(props) {
5864
- const updatedProps = {
5865
- ...props
5866
- };
5867
- return updatedProps;
5868
- }
5869
- _buildResourceTransforms(props) {
5870
- }
5871
- _updateDrawOptions(options) {
5872
- const updatedOpts = {
5873
- ...options
5874
- };
5875
- return updatedOpts;
5876
- }
6057
+ throw new Error("Not implemented");
6058
+ }
6059
+ // _buildResourceTransforms(props: TransformProps) {
6060
+ // if (canCreateBufferTransform(props)) {
6061
+ // this.bufferTransform = new BufferTransform(this.device, props);
6062
+ // }
6063
+ // if (canCreateTextureTransform(props)) {
6064
+ // this.textureTransform = new TextureTransform(this.device, props);
6065
+ // }
6066
+ // assert(
6067
+ // this.bufferTransform || this.textureTransform,
6068
+ // 'must provide source/feedback buffers or source/target textures'
6069
+ // );
6070
+ // }
6071
+ // _updateDrawOptions(options: TransformRunOptions): TransformDrawOptions {
6072
+ // const updatedOpts = {...options};
6073
+ // const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean) ;
6074
+ // for (const resourceTransform of resourceTransforms) {
6075
+ // updatedOpts = Object.assign(updatedOpts, resourceTransform.getDrawOptions(updatedOpts));
6076
+ // }
6077
+ // return updatedOpts;
6078
+ // }
5877
6079
  };
5878
6080
 
5879
6081
  // src/shadertools/shader-module-uniforms.ts
@@ -1 +1 @@
1
- {"version":3,"file":"gpu-geometry.d.ts","sourceRoot":"","sources":["../../src/geometry/gpu-geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AACnE,OAAO,EAAC,MAAM,EAAE,MAAM,EAAc,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAEnD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oEAAoE;IACpE,QAAQ,EACJ,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,iBAAiB,GACjB,eAAe,GACf,gBAAgB,GAChB,oBAAoB,CAAC;IACzB,sDAAsD;IACtD,WAAW,EAA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M,CAAC;IAIvC,UAAU,IAAI,MAAM,GAAG,IAAI;IAI3B,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAKjD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,WAAW,CAc7F;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAMjG;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,GACjB;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,YAAY,EAAE,YAAY,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,CAoBzF"}
@@ -1,4 +1,4 @@
1
- import { Buffer, uid, assert } from '@luma.gl/core';
1
+ import { Buffer, uid, assert, getVertexFormatFromAttribute } from '@luma.gl/core';
2
2
  export class GPUGeometry {
3
3
  constructor(props) {
4
4
  this.id = void 0;
@@ -87,9 +87,13 @@ export function getAttributeBuffersFromGeometry(device, geometry) {
87
87
  data: attribute.value,
88
88
  id: `${attributeName}-buffer`
89
89
  });
90
+ const {
91
+ value,
92
+ size
93
+ } = attribute;
90
94
  bufferLayout.push({
91
95
  name,
92
- format: `float32x${attribute.size}`
96
+ format: getVertexFormatFromAttribute(value, size)
93
97
  });
94
98
  }
95
99
  const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
@@ -1 +1 @@
1
- {"version":3,"file":"gpu-geometry.js","names":["Buffer","uid","assert","GPUGeometry","constructor","props","id","userData","topology","bufferLayout","vertexCount","indices","attributes","usage","INDEX","destroy","_this$attributes$colo","positions","normals","texCoords","colors","getVertexCount","getAttributes","getIndexes","_calculateVertexCount","byteLength","makeGPUGeometry","device","geometry","getIndexBufferFromGeometry","getAttributeBuffersFromGeometry","undefined","data","value","createBuffer","attributeName","attribute","Object","entries","name","push","format","size"],"sources":["../../src/geometry/gpu-geometry.ts"],"sourcesContent":["import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';\nimport {Device, Buffer, uid, assert} from '@luma.gl/core';\nimport type {Geometry} from '../geometry/geometry';\n\nexport type GPUGeometryProps = {\n id?: string;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology:\n | 'point-list'\n | 'line-list'\n | 'line-strip'\n | 'line-loop-webgl'\n | 'triangle-list'\n | 'triangle-strip'\n | 'triangle-fan-webgl';\n /** Auto calculated from attributes if not provided */\n vertexCount: number;\n bufferLayout: BufferLayout[];\n indices?: Buffer | null;\n attributes: Record<string, Buffer>;\n};\n\nexport class GPUGeometry {\n readonly id: string;\n userData: Record<string, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n readonly topology?: PrimitiveTopology;\n readonly bufferLayout: BufferLayout[] = [];\n\n readonly vertexCount: number;\n readonly indices?: Buffer | null;\n readonly attributes: Record<string, Buffer>;\n\n constructor(props: GPUGeometryProps) {\n this.id = props.id || uid('geometry');\n this.topology = props.topology;\n this.indices = props.indices || null;\n this.attributes = props.attributes;\n\n this.vertexCount = props.vertexCount;\n\n this.bufferLayout = props.bufferLayout || [];\n\n if (this.indices) {\n assert(this.indices.usage === Buffer.INDEX);\n }\n }\n\n destroy(): void {\n this.indices.destroy();\n this.attributes.positions.destroy();\n this.attributes.normals.destroy();\n this.attributes.texCoords.destroy();\n this.attributes.colors?.destroy();\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n getAttributes(): Record<string, Buffer> {\n return this.attributes;\n }\n\n getIndexes(): Buffer | null {\n return this.indices;\n }\n\n _calculateVertexCount(positions: Buffer): number {\n // Assume that positions is a fully packed float32x3 buffer\n const vertexCount = positions.byteLength / 12;\n return vertexCount;\n }\n}\n\nexport function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry {\n if (geometry instanceof GPUGeometry) {\n return geometry;\n }\n\n const indices = getIndexBufferFromGeometry(device, geometry);\n const {attributes, bufferLayout} = getAttributeBuffersFromGeometry(device, geometry);\n return new GPUGeometry({\n topology: geometry.topology || 'triangle-list',\n bufferLayout,\n vertexCount: geometry.vertexCount,\n indices,\n attributes\n });\n}\n\nexport function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {\n if (!geometry.indices) {\n return undefined;\n }\n const data = geometry.indices.value;\n return device.createBuffer({usage: Buffer.INDEX, data});\n}\n\nexport function getAttributeBuffersFromGeometry(\n device: Device,\n geometry: Geometry\n): {attributes: Record<string, Buffer>, bufferLayout: BufferLayout[], vertexCount: number} {\n const bufferLayout: BufferLayout[] = [];\n\n const attributes: Record<string, Buffer> = {};\n for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {\n let name: string = attributeName;\n // TODO Map some GLTF attribute names (is this still needed?)\n switch (attributeName) {\n case 'POSITION': name = 'positions'; break;\n case 'NORMAL': name = 'normals'; break;\n case 'TEXCOORD_0': name = 'texCoords'; break;\n }\n attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});\n bufferLayout.push({name, format: `float32x${attribute.size as 2 | 3 | 4}`});\n }\n\n const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)\n\n return {attributes, bufferLayout, vertexCount};\n}\n"],"mappings":"AACA,SAAgBA,MAAM,EAAEC,GAAG,EAAEC,MAAM,QAAO,eAAe;AAqBzD,OAAO,MAAMC,WAAW,CAAC;EAYvBC,WAAWA,CAACC,KAAuB,EAAE;IAAA,KAX5BC,EAAE;IAAA,KACXC,QAAQ,GAA4B,CAAC,CAAC;IAAA,KAG7BC,QAAQ;IAAA,KACRC,YAAY,GAAmB,EAAE;IAAA,KAEjCC,WAAW;IAAA,KACXC,OAAO;IAAA,KACPC,UAAU;IAGjB,IAAI,CAACN,EAAE,GAAGD,KAAK,CAACC,EAAE,IAAIL,GAAG,CAAC,UAAU,CAAC;IACrC,IAAI,CAACO,QAAQ,GAAGH,KA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;IAAQ,CAAC,CAAC;IAC9F1B,YAAY,CAAC+B,IAAI,CAAC;MAACD,IAAI;MAAEE,MAAM,EAAG,WAAUL,SAAS,CAACM,IAAkB;IAAC,CAAC,CAAC;EAC7E;EAEA,MAAMhC,WAAW,GAAGkB,QAAQ,CAACJ,qBAAqB,CAACI,QAAQ,CAAChB,UAAU,EAAEgB,QAAQ,CAACjB,OAAO,CAAC;EAEzF,OAAO;IAACC,UAAU;IAAEH,YAAY;IAAEC;EAAW,CAAC;AAChD"}
1
+ {"version":3,"file":"gpu-geometry.js","names":["Buffer","uid","assert","getVertexFormatFromAttribute","GPUGeometry","constructor","props","id","userData","topology","bufferLayout","vertexCount","indices","attributes","usage","INDEX","destroy","_this$attributes$colo","positions","normals","texCoords","colors","getVertexCount","getAttributes","getIndexes","_calculateVertexCount","byteLength","makeGPUGeometry","device","geometry","getIndexBufferFromGeometry","getAttributeBuffersFromGeometry","undefined","data","value","createBuffer","attributeName","attribute","Object","entries","name","size","push","format"],"sources":["../../src/geometry/gpu-geometry.ts"],"sourcesContent":["import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';\nimport {Device, Buffer, uid, assert, getVertexFormatFromAttribute} from '@luma.gl/core';\nimport type {Geometry} from '../geometry/geometry';\n\nexport type GPUGeometryProps = {\n id?: string;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology:\n | 'point-list'\n | 'line-list'\n | 'line-strip'\n | 'line-loop-webgl'\n | 'triangle-list'\n | 'triangle-strip'\n | 'triangle-fan-webgl';\n /** Auto calculated from attributes if not provided */\n vertexCount: number;\n bufferLayout: BufferLayout[];\n indices?: Buffer | null;\n attributes: Record<string, Buffer>;\n};\n\nexport class GPUGeometry {\n readonly id: string;\n userData: Record<string, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n readonly topology?: PrimitiveTopology;\n readonly bufferLayout: BufferLayout[] = [];\n\n readonly vertexCount: number;\n readonly indices?: Buffer | null;\n readonly attributes: Record<string, Buffer>;\n\n constructor(props: GPUGeometryProps) {\n this.id = props.id || uid('geometry');\n this.topology = props.topology;\n this.indices = props.indices || null;\n this.attributes = props.attributes;\n\n this.vertexCount = props.vertexCount;\n\n this.bufferLayout = props.bufferLayout || [];\n\n if (this.indices) {\n assert(this.indices.usage === Buffer.INDEX);\n }\n }\n\n destroy(): void {\n this.indices.destroy();\n this.attributes.positions.destroy();\n this.attributes.normals.destroy();\n this.attributes.texCoords.destroy();\n this.attributes.colors?.destroy();\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n getAttributes(): Record<string, Buffer> {\n return this.attributes;\n }\n\n getIndexes(): Buffer | null {\n return this.indices;\n }\n\n _calculateVertexCount(positions: Buffer): number {\n // Assume that positions is a fully packed float32x3 buffer\n const vertexCount = positions.byteLength / 12;\n return vertexCount;\n }\n}\n\nexport function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry {\n if (geometry instanceof GPUGeometry) {\n return geometry;\n }\n\n const indices = getIndexBufferFromGeometry(device, geometry);\n const {attributes, bufferLayout} = getAttributeBuffersFromGeometry(device, geometry);\n return new GPUGeometry({\n topology: geometry.topology || 'triangle-list',\n bufferLayout,\n vertexCount: geometry.vertexCount,\n indices,\n attributes\n });\n}\n\nexport function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {\n if (!geometry.indices) {\n return undefined;\n }\n const data = geometry.indices.value;\n return device.createBuffer({usage: Buffer.INDEX, data});\n}\n\nexport function getAttributeBuffersFromGeometry(\n device: Device,\n geometry: Geometry\n): {attributes: Record<string, Buffer>, bufferLayout: BufferLayout[], vertexCount: number} {\n const bufferLayout: BufferLayout[] = [];\n\n const attributes: Record<string, Buffer> = {};\n for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {\n let name: string = attributeName;\n // TODO Map some GLTF attribute names (is this still needed?)\n switch (attributeName) {\n case 'POSITION': name = 'positions'; break;\n case 'NORMAL': name = 'normals'; break;\n case 'TEXCOORD_0': name = 'texCoords'; break;\n }\n attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});\n const {value, size} = attribute;\n bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size)});\n }\n\n const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)\n\n return {attributes, bufferLayout, vertexCount};\n}\n"],"mappings":"AACA,SAAgBA,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,4BAA4B,QAAO,eAAe;AAqBvF,OAAO,MAAMC,WAAW,CAAC;EAYvBC,WAAWA,CAACC,KAAuB,EAAE;IAAA,KAX5BC,EAAE;IAAA,KACXC,QAAQ,GAA4B,CAAC,CAAC;IAAA,KAG7BC,QAAQ;IAAA,KACRC,YAAY,GAAmB,EAAE;IAAA,KAEjCC,WAAW;IAAA,KACXC,OAAO;IAAA,KACPC,UAAU;IAGjB,IAAI,CAACN,EAAE,GAAGD,KAAK,CAACC,EAAE,IAAIN,GAAG,CAAC,UAAU,CAAC;IACrC,IAAI,CAACQ,QAAQ,GAAGH,KAAK,CAACG,QAAQ;IAC9B,IAAI,CAACG,OAAO,GAAGN,KAAK,CAACM,OAAO,IAAI,IAAI;IACpC,IAAI,CAACC,UAAU,GAAGP,KAAK,CAACO,UAAU;IAElC,IAAI,CAACF,WAAW,GAAGL,KAAK,CAACK,WAAW;IAEpC,IAAI,CAACD,YAAY,GAAGJ,KAAK,CAACI,YAAY,IAAI,EAAE;IAE5C,IAAI,IAAI,CAACE,OAAO,EAAE;MAChBV,MAAM,CAAC,IAAI,CAACU,OAAO,CAACE,KAAK,KAAKd,MAAM,CAACe,KAAK,CAAC;IAC7C;EACF;EAEAC,OAAOA,CAAA,EAAS;IAAA,IAAAC,qBAAA;IACd,IAAI,CAACL,OAAO,CAACI,OAAO,CAAC,CAAC;IACtB,IAAI,CAACH,UAAU,CAACK,SAAS,CAACF,OAAO,CAAC,CAAC;IACnC,IAAI,CAACH,UAAU,CAACM,OAAO,CAACH,OAAO,CAAC,CAAC;IACjC,IAAI,CAACH,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