@luma.gl/engine 9.0.0-alpha.46 → 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/LICENSE +34 -0
- package/dist/dist.dev.js +220 -34
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +6 -2
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +125 -78
- package/dist/model/model.d.ts +2 -0
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +1 -0
- package/dist/model/model.js.map +1 -1
- package/dist/transform/transform.d.ts +24 -57
- package/dist/transform/transform.d.ts.map +1 -1
- package/dist/transform/transform.js +66 -24
- package/dist/transform/transform.js.map +1 -1
- package/dist.min.js +62 -45
- package/package.json +5 -5
- package/src/geometry/gpu-geometry.ts +3 -2
- package/src/model/model.ts +4 -0
- package/src/transform/transform.ts +125 -113
package/LICENSE
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
luma.gl is provided under the MIT license
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 vis.gl contributors
|
|
4
|
+
|
|
5
|
+
This software includes parts initially developed by Uber and open sourced under MIT license.
|
|
6
|
+
Copyright (c) 2015 Uber Technologies, Inc.
|
|
7
|
+
|
|
8
|
+
This software includes parts of PhiloGL (https://github.com/philogb/philogl)
|
|
9
|
+
under MIT license. PhiloGL parts Copyright © 2013 Sencha Labs.
|
|
10
|
+
|
|
11
|
+
This software includes adaptations of some postprocessing code from
|
|
12
|
+
THREE.js (https://github.com/mrdoob/three.js/) under MIT license.
|
|
13
|
+
THREE.js parts Copyright © 2010-2018 three.js authors.
|
|
14
|
+
|
|
15
|
+
Additional attribution given in specific source files.
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
in the Software without restriction, including without limitation the rights
|
|
20
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
furnished to do so, subject to the following conditions:
|
|
23
|
+
|
|
24
|
+
The above copyright notice and this permission notice shall be included in
|
|
25
|
+
all copies or substantial portions of the Software.
|
|
26
|
+
|
|
27
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
33
|
+
THE SOFTWARE.
|
|
34
|
+
|
package/dist/dist.dev.js
CHANGED
|
@@ -1908,6 +1908,53 @@ var __exports__ = (() => {
|
|
|
1908
1908
|
}
|
|
1909
1909
|
};
|
|
1910
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
|
+
|
|
1911
1958
|
// ../core/src/lib/utils/uniform.ts
|
|
1912
1959
|
function isUniformValue(value) {
|
|
1913
1960
|
return isNumberArray(value) !== null || typeof value === "number" || typeof value === "boolean";
|
|
@@ -3395,6 +3442,88 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
|
|
|
3395
3442
|
}
|
|
3396
3443
|
};
|
|
3397
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
|
+
|
|
3398
3527
|
// ../../node_modules/@math.gl/core/dist/lib/common.js
|
|
3399
3528
|
var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
|
|
3400
3529
|
var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
|
|
@@ -5368,9 +5497,13 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
|
|
|
5368
5497
|
data: attribute.value,
|
|
5369
5498
|
id: `${attributeName}-buffer`
|
|
5370
5499
|
});
|
|
5500
|
+
const {
|
|
5501
|
+
value,
|
|
5502
|
+
size
|
|
5503
|
+
} = attribute;
|
|
5371
5504
|
bufferLayout.push({
|
|
5372
5505
|
name: name2,
|
|
5373
|
-
format:
|
|
5506
|
+
format: getVertexFormatFromAttribute(value, size)
|
|
5374
5507
|
});
|
|
5375
5508
|
}
|
|
5376
5509
|
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
|
|
@@ -5809,6 +5942,7 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
|
|
|
5809
5942
|
indexBuffer: null,
|
|
5810
5943
|
attributes: {},
|
|
5811
5944
|
constantAttributes: {},
|
|
5945
|
+
varyings: [],
|
|
5812
5946
|
pipelineFactory: void 0,
|
|
5813
5947
|
transformFeedback: void 0,
|
|
5814
5948
|
shaderAssembler: ShaderAssembler.getDefaultShaderAssembler()
|
|
@@ -5828,68 +5962,120 @@ ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
|
|
|
5828
5962
|
|
|
5829
5963
|
// src/transform/transform.ts
|
|
5830
5964
|
var Transform = class {
|
|
5831
|
-
/**
|
|
5832
|
-
* Check if Transforms are supported (they are not under WebGL1)
|
|
5833
|
-
* @todo differentiate writing to buffer vs not
|
|
5834
|
-
*/
|
|
5965
|
+
/** @deprecated Use device feature test. */
|
|
5835
5966
|
static isSupported(device) {
|
|
5836
|
-
return
|
|
5967
|
+
return device.features.has("transform-feedback-webgl2");
|
|
5837
5968
|
}
|
|
5838
|
-
// model: Model;
|
|
5839
|
-
elementCount = 0;
|
|
5840
5969
|
// bufferTransform: BufferTransform | null = null;
|
|
5841
5970
|
// textureTransform: TextureTransform | null = null;
|
|
5842
5971
|
elementIDBuffer = null;
|
|
5843
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);
|
|
5844
5995
|
}
|
|
5845
|
-
/**
|
|
5996
|
+
/** Destroy owned resources. */
|
|
5846
5997
|
destroy() {
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
this.destroy();
|
|
5998
|
+
if (this.model) {
|
|
5999
|
+
this.model.destroy();
|
|
6000
|
+
}
|
|
5851
6001
|
}
|
|
5852
6002
|
/** Run one transform loop. */
|
|
5853
6003
|
run(options) {
|
|
5854
6004
|
const {
|
|
5855
|
-
|
|
6005
|
+
framebuffer,
|
|
6006
|
+
parameters,
|
|
6007
|
+
discard,
|
|
6008
|
+
uniforms
|
|
5856
6009
|
} = options || {};
|
|
5857
|
-
const
|
|
5858
|
-
|
|
5859
|
-
|
|
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();
|
|
5860
6019
|
}
|
|
5861
6020
|
/** swap resources if a map is provided */
|
|
5862
6021
|
swap() {
|
|
6022
|
+
throw new Error("Not implemented");
|
|
5863
6023
|
}
|
|
5864
|
-
/**
|
|
6024
|
+
/** Returns the {@link Buffer} or {@link BufferRange} for given varying name. */
|
|
5865
6025
|
getBuffer(varyingName) {
|
|
5866
|
-
return
|
|
6026
|
+
return this.transformFeedback.getBuffer(varyingName);
|
|
6027
|
+
}
|
|
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);
|
|
5867
6039
|
}
|
|
5868
|
-
/**
|
|
6040
|
+
/**
|
|
6041
|
+
* Return data either from Buffer or from Texture.
|
|
6042
|
+
* @deprecated Prefer {@link readAsync}.
|
|
6043
|
+
*/
|
|
5869
6044
|
getData(options = {}) {
|
|
6045
|
+
throw new Error("Not implemented");
|
|
5870
6046
|
}
|
|
5871
6047
|
/** Return framebuffer object if rendering to textures */
|
|
5872
6048
|
getFramebuffer() {
|
|
5873
|
-
|
|
6049
|
+
throw new Error("Not implemented");
|
|
5874
6050
|
}
|
|
5875
6051
|
/** Update some or all buffer/texture bindings. */
|
|
5876
6052
|
update(props) {
|
|
6053
|
+
throw new Error("Not implemented");
|
|
5877
6054
|
}
|
|
5878
6055
|
// Private
|
|
5879
6056
|
_updateModelProps(props) {
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
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
|
+
// }
|
|
5893
6079
|
};
|
|
5894
6080
|
|
|
5895
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,
|
|
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,EAA4C,MAAM,eAAe,CAAC;AACxF,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,EAAE,MAAM,CAAC;IACpB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|
@@ -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:
|
|
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","
|
|
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,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