@luma.gl/engine 9.0.0-alpha.52 → 9.0.0-alpha.54
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/debug/debug-shader-layout.d.ts +9 -0
- package/dist/debug/debug-shader-layout.d.ts.map +1 -0
- package/dist/debug/debug-shader-layout.js +21 -0
- package/dist/debug/debug-shader-layout.js.map +1 -0
- package/dist/dist.dev.js +142 -52
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +3 -0
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +92 -16
- package/dist/model/model.d.ts +3 -1
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +52 -11
- package/dist/model/model.js.map +1 -1
- package/dist/shader-inputs.d.ts +1 -0
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +13 -0
- package/dist/shader-inputs.js.map +1 -1
- package/dist.min.js +64 -64
- package/package.json +5 -5
- package/src/debug/debug-shader-layout.ts +34 -0
- package/src/geometry/gpu-geometry.ts +1 -0
- package/src/model/model.ts +88 -23
- package/src/shader-inputs.ts +14 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ShaderLayout } from '@luma.gl/core';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts a table suitable for `console.table()` from a shader layout to assist in debugging.
|
|
4
|
+
* @param layout shader layout
|
|
5
|
+
* @param name app should provide the most meaningful name, usually the model or pipeline name / id.
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function getDebugTableForShaderLayout(layout: ShaderLayout, name?: string): Record<string, Record<string, string>>;
|
|
9
|
+
//# sourceMappingURL=debug-shader-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-shader-layout.d.ts","sourceRoot":"","sources":["../../src/debug/debug-shader-layout.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,YAAY,EACpB,IAAI,GAAE,MAAW,GAChB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAkBxC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function getDebugTableForShaderLayout(layout) {
|
|
2
|
+
let name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
3
|
+
const table = {};
|
|
4
|
+
const header = `Shader Layout for ${name}`;
|
|
5
|
+
for (const attributeDeclaration of layout.attributes) {
|
|
6
|
+
if (attributeDeclaration) {
|
|
7
|
+
const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
|
|
8
|
+
table[`in ${glslDeclaration}`] = {
|
|
9
|
+
[header]: attributeDeclaration.stepMode || 'vertex'
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
for (const varyingDeclaration of layout.varyings || []) {
|
|
14
|
+
const glslDeclaration = `${varyingDeclaration.location} ${varyingDeclaration.name}`;
|
|
15
|
+
table[`out ${glslDeclaration}`] = {
|
|
16
|
+
[header]: JSON.stringify(varyingDeclaration.accessor)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return table;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=debug-shader-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-shader-layout.js","names":["getDebugTableForShaderLayout","layout","name","arguments","length","undefined","table","header","attributeDeclaration","attributes","glslDeclaration","location","type","stepMode","varyingDeclaration","varyings","JSON","stringify","accessor"],"sources":["../../src/debug/debug-shader-layout.ts"],"sourcesContent":["// luma.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {ShaderLayout} from '@luma.gl/core';\n\n/**\n * Extracts a table suitable for `console.table()` from a shader layout to assist in debugging.\n * @param layout shader layout\n * @param name app should provide the most meaningful name, usually the model or pipeline name / id.\n * @returns \n */\nexport function getDebugTableForShaderLayout(\n layout: ShaderLayout,\n name: string = ''\n): Record<string, Record<string, string>> {\n const table: Record<string, Record<string, string>> = {};\n\n const header = `Shader Layout for ${name}`;\n\n for (const attributeDeclaration of layout.attributes) {\n if (attributeDeclaration) {\n const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;\n table[`in ${glslDeclaration}`] = {[header]: attributeDeclaration.stepMode || 'vertex'};\n }\n }\n\n for (const varyingDeclaration of layout.varyings || []) {\n const glslDeclaration = `${varyingDeclaration.location} ${varyingDeclaration.name}`;\n table[`out ${glslDeclaration}`] = {[header]: JSON.stringify(varyingDeclaration.accessor)};\n }\n\n return table;\n}\n"],"mappings":"AAYA,OAAO,SAASA,4BAA4BA,CAC1CC,MAAoB,EAEoB;EAAA,IADxCC,IAAY,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAEjB,MAAMG,KAA6C,GAAG,CAAC,CAAC;EAExD,MAAMC,MAAM,GAAI,qBAAoBL,IAAK,EAAC;EAE1C,KAAK,MAAMM,oBAAoB,IAAIP,MAAM,CAACQ,UAAU,EAAE;IACpD,IAAID,oBAAoB,EAAE;MACxB,MAAME,eAAe,GAAI,GAAEF,oBAAoB,CAACG,QAAS,IAAGH,oBAAoB,CAACN,IAAK,KAAIM,oBAAoB,CAACI,IAAK,EAAC;MACrHN,KAAK,CAAE,MAAKI,eAAgB,EAAC,CAAC,GAAG;QAAC,CAACH,MAAM,GAAGC,oBAAoB,CAACK,QAAQ,IAAI;MAAQ,CAAC;IACxF;EACF;EAEA,KAAK,MAAMC,kBAAkB,IAAIb,MAAM,CAACc,QAAQ,IAAI,EAAE,EAAE;IACtD,MAAML,eAAe,GAAI,GAAEI,kBAAkB,CAACH,QAAS,IAAGG,kBAAkB,CAACZ,IAAK,EAAC;IACnFI,KAAK,CAAE,OAAMI,eAAgB,EAAC,CAAC,GAAG;MAAC,CAACH,MAAM,GAAGS,IAAI,CAACC,SAAS,CAACH,kBAAkB,CAACI,QAAQ;IAAC,CAAC;EAC3F;EAEA,OAAOZ,KAAK;AACd"}
|
package/dist/dist.dev.js
CHANGED
|
@@ -764,7 +764,7 @@ var __exports__ = (() => {
|
|
|
764
764
|
id: "@probe.gl/log"
|
|
765
765
|
});
|
|
766
766
|
|
|
767
|
-
// ../core/src/
|
|
767
|
+
// ../core/src/utils/log.ts
|
|
768
768
|
var log = new Log({
|
|
769
769
|
id: "luma.gl"
|
|
770
770
|
});
|
|
@@ -960,7 +960,7 @@ var __exports__ = (() => {
|
|
|
960
960
|
}
|
|
961
961
|
};
|
|
962
962
|
|
|
963
|
-
// ../core/src/
|
|
963
|
+
// ../core/src/utils/stats-manager.ts
|
|
964
964
|
var StatsManager = class {
|
|
965
965
|
stats = /* @__PURE__ */ new Map();
|
|
966
966
|
getStats(name2) {
|
|
@@ -979,14 +979,14 @@ var __exports__ = (() => {
|
|
|
979
979
|
|
|
980
980
|
// ../core/src/init.ts
|
|
981
981
|
function initializeLuma() {
|
|
982
|
-
const VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "
|
|
982
|
+
const VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "running from source";
|
|
983
983
|
const STARTUP_MESSAGE = "set luma.log.level=1 (or higher) to trace rendering";
|
|
984
984
|
if (globalThis.luma && globalThis.luma.VERSION !== VERSION3) {
|
|
985
985
|
throw new Error(`luma.gl - multiple VERSIONs detected: ${globalThis.luma.VERSION} vs ${VERSION3}`);
|
|
986
986
|
}
|
|
987
987
|
if (!globalThis.luma) {
|
|
988
988
|
if (isBrowser()) {
|
|
989
|
-
log.log(1,
|
|
989
|
+
log.log(1, `${VERSION3} - ${STARTUP_MESSAGE}`)();
|
|
990
990
|
}
|
|
991
991
|
globalThis.luma = globalThis.luma || {
|
|
992
992
|
VERSION: VERSION3,
|
|
@@ -999,7 +999,7 @@ var __exports__ = (() => {
|
|
|
999
999
|
}
|
|
1000
1000
|
var VERSION2 = initializeLuma();
|
|
1001
1001
|
|
|
1002
|
-
// ../core/src/
|
|
1002
|
+
// ../core/src/utils/is-array.ts
|
|
1003
1003
|
function isTypedArray(value) {
|
|
1004
1004
|
return ArrayBuffer.isView(value) && !(value instanceof DataView) ? value : null;
|
|
1005
1005
|
}
|
|
@@ -1010,7 +1010,7 @@ var __exports__ = (() => {
|
|
|
1010
1010
|
return isTypedArray(value);
|
|
1011
1011
|
}
|
|
1012
1012
|
|
|
1013
|
-
// ../core/src/
|
|
1013
|
+
// ../core/src/utils/utils.ts
|
|
1014
1014
|
var uidCounters = {};
|
|
1015
1015
|
function uid(id = "id") {
|
|
1016
1016
|
uidCounters[id] = uidCounters[id] || 1;
|
|
@@ -1133,14 +1133,20 @@ var __exports__ = (() => {
|
|
|
1133
1133
|
this.usage = props.usage || 0;
|
|
1134
1134
|
this.indexType = deducedProps.indexType;
|
|
1135
1135
|
}
|
|
1136
|
-
|
|
1136
|
+
readSyncWebGL2(byteOffset, byteLength) {
|
|
1137
1137
|
throw new Error("not implemented");
|
|
1138
1138
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1139
|
+
debugData = new ArrayBuffer(0);
|
|
1140
|
+
_setDebugData(data, byteOffset, byteLength) {
|
|
1141
|
+
const buffer = ArrayBuffer.isView(data) ? data.buffer : data;
|
|
1142
|
+
const debugDataLength = Math.min(data ? data.byteLength : byteLength, _Buffer.DEBUG_DATA_MAX_LENGTH);
|
|
1143
|
+
if (data === null) {
|
|
1144
|
+
this.debugData = new ArrayBuffer(debugDataLength);
|
|
1145
|
+
} else if (byteOffset === 0 && byteLength === data.byteLength) {
|
|
1146
|
+
this.debugData = buffer.slice(0, debugDataLength);
|
|
1147
|
+
} else {
|
|
1148
|
+
this.debugData = buffer.slice(byteOffset, byteOffset + debugDataLength);
|
|
1149
|
+
}
|
|
1144
1150
|
}
|
|
1145
1151
|
};
|
|
1146
1152
|
var Buffer2 = _Buffer;
|
|
@@ -1163,6 +1169,7 @@ var __exports__ = (() => {
|
|
|
1163
1169
|
__publicField(Buffer2, "STORAGE", 128);
|
|
1164
1170
|
__publicField(Buffer2, "INDIRECT", 256);
|
|
1165
1171
|
__publicField(Buffer2, "QUERY_RESOLVE", 512);
|
|
1172
|
+
__publicField(Buffer2, "DEBUG_DATA_MAX_LENGTH", 32);
|
|
1166
1173
|
|
|
1167
1174
|
// ../core/src/adapter/device.ts
|
|
1168
1175
|
var _Device = class {
|
|
@@ -1237,6 +1244,13 @@ var __exports__ = (() => {
|
|
|
1237
1244
|
});
|
|
1238
1245
|
__publicField(Device, "VERSION", VERSION2);
|
|
1239
1246
|
|
|
1247
|
+
// ../core/src/utils/assert.ts
|
|
1248
|
+
function assert2(condition, message) {
|
|
1249
|
+
if (!condition) {
|
|
1250
|
+
throw new Error(message || "luma.gl: assertion failed.");
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1240
1254
|
// ../core/src/lib/luma.ts
|
|
1241
1255
|
var deviceList = /* @__PURE__ */ new Map();
|
|
1242
1256
|
var luma = class {
|
|
@@ -1280,6 +1294,10 @@ var __exports__ = (() => {
|
|
|
1280
1294
|
}
|
|
1281
1295
|
break;
|
|
1282
1296
|
case "best-available":
|
|
1297
|
+
DeviceClass = deviceList.get("webgpu");
|
|
1298
|
+
if (DeviceClass && DeviceClass.isSupported()) {
|
|
1299
|
+
return await DeviceClass.create(props);
|
|
1300
|
+
}
|
|
1283
1301
|
DeviceClass = deviceList.get("webgl");
|
|
1284
1302
|
if (DeviceClass && DeviceClass.isSupported()) {
|
|
1285
1303
|
return await DeviceClass.create(props);
|
|
@@ -1553,13 +1571,6 @@ var __exports__ = (() => {
|
|
|
1553
1571
|
return null;
|
|
1554
1572
|
}
|
|
1555
1573
|
|
|
1556
|
-
// ../core/src/lib/utils/assert.ts
|
|
1557
|
-
function assert2(condition, message) {
|
|
1558
|
-
if (!condition) {
|
|
1559
|
-
throw new Error(message || "luma.gl: assertion failed.");
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
1574
|
// ../core/src/adapter/type-utils/decode-shader-types.ts
|
|
1564
1575
|
var UNIFORM_FORMATS = {
|
|
1565
1576
|
"f32": {
|
|
@@ -1663,7 +1674,7 @@ var __exports__ = (() => {
|
|
|
1663
1674
|
}
|
|
1664
1675
|
}
|
|
1665
1676
|
|
|
1666
|
-
// ../core/src/
|
|
1677
|
+
// ../core/src/utils/array-utils-flat.ts
|
|
1667
1678
|
var arrayBuffer;
|
|
1668
1679
|
function getScratchArrayBuffer(byteLength) {
|
|
1669
1680
|
if (!arrayBuffer || arrayBuffer.byteLength < byteLength) {
|
|
@@ -1744,7 +1755,7 @@ var __exports__ = (() => {
|
|
|
1744
1755
|
}
|
|
1745
1756
|
};
|
|
1746
1757
|
|
|
1747
|
-
// ../core/src/
|
|
1758
|
+
// ../core/src/utils/array-equal.ts
|
|
1748
1759
|
function arrayEqual(a, b, limit = 16) {
|
|
1749
1760
|
if (a !== b) {
|
|
1750
1761
|
return false;
|
|
@@ -1926,6 +1937,30 @@ var __exports__ = (() => {
|
|
|
1926
1937
|
throw new Error(type.constructor.name);
|
|
1927
1938
|
}
|
|
1928
1939
|
}
|
|
1940
|
+
function getTypedArrayFromDataType(dataType) {
|
|
1941
|
+
switch (dataType) {
|
|
1942
|
+
case "float32":
|
|
1943
|
+
return Float32Array;
|
|
1944
|
+
case "uint32":
|
|
1945
|
+
return Uint32Array;
|
|
1946
|
+
case "sint32":
|
|
1947
|
+
return Int32Array;
|
|
1948
|
+
case "uint16":
|
|
1949
|
+
case "unorm16":
|
|
1950
|
+
return Uint16Array;
|
|
1951
|
+
case "sint16":
|
|
1952
|
+
case "snorm16":
|
|
1953
|
+
return Int16Array;
|
|
1954
|
+
case "uint8":
|
|
1955
|
+
case "unorm8":
|
|
1956
|
+
return Uint8Array;
|
|
1957
|
+
case "sint8":
|
|
1958
|
+
case "snorm8":
|
|
1959
|
+
return Int8Array;
|
|
1960
|
+
default:
|
|
1961
|
+
throw new Error(dataType);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1929
1964
|
function getVertexFormatFromAttribute(typedArray, size, normalized) {
|
|
1930
1965
|
if (!size || size > 4) {
|
|
1931
1966
|
throw new Error(`size ${size}`);
|
|
@@ -1976,7 +2011,7 @@ var __exports__ = (() => {
|
|
|
1976
2011
|
return result;
|
|
1977
2012
|
}
|
|
1978
2013
|
|
|
1979
|
-
// ../core/src/
|
|
2014
|
+
// ../core/src/utils/deep-equal.ts
|
|
1980
2015
|
function deepEqual(a, b, depth) {
|
|
1981
2016
|
if (a === b) {
|
|
1982
2017
|
return true;
|
|
@@ -2017,7 +2052,7 @@ var __exports__ = (() => {
|
|
|
2017
2052
|
return false;
|
|
2018
2053
|
}
|
|
2019
2054
|
|
|
2020
|
-
// ../core/src/
|
|
2055
|
+
// ../core/src/utils/request-animation-frame.ts
|
|
2021
2056
|
function requestAnimationFrame(callback) {
|
|
2022
2057
|
return typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame(callback) : setTimeout(callback, 1e3 / 60);
|
|
2023
2058
|
}
|
|
@@ -2025,27 +2060,6 @@ var __exports__ = (() => {
|
|
|
2025
2060
|
return typeof window !== "undefined" && window.cancelAnimationFrame ? window.cancelAnimationFrame(timerId) : clearTimeout(timerId);
|
|
2026
2061
|
}
|
|
2027
2062
|
|
|
2028
|
-
// ../core/src/lib/debug/debug-shader-layout.ts
|
|
2029
|
-
function getDebugTableForShaderLayout(layout, name2 = "") {
|
|
2030
|
-
const table = {};
|
|
2031
|
-
const header = `Shader Layout for ${name2}`;
|
|
2032
|
-
for (const attributeDeclaration of layout.attributes) {
|
|
2033
|
-
if (attributeDeclaration) {
|
|
2034
|
-
const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
|
|
2035
|
-
table[`in ${glslDeclaration}`] = {
|
|
2036
|
-
[header]: attributeDeclaration.stepMode || "vertex"
|
|
2037
|
-
};
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
|
-
for (const varyingDeclaration of layout.varyings || []) {
|
|
2041
|
-
const glslDeclaration = `${varyingDeclaration.location} ${varyingDeclaration.name}`;
|
|
2042
|
-
table[`out ${glslDeclaration}`] = {
|
|
2043
|
-
[header]: JSON.stringify(varyingDeclaration.accessor)
|
|
2044
|
-
};
|
|
2045
|
-
}
|
|
2046
|
-
return table;
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
2063
|
// ../core/src/index.ts
|
|
2050
2064
|
var glsl = (x) => `${x}`;
|
|
2051
2065
|
|
|
@@ -5407,6 +5421,18 @@ void main() {
|
|
|
5407
5421
|
}
|
|
5408
5422
|
return bindings;
|
|
5409
5423
|
}
|
|
5424
|
+
getDebugTable() {
|
|
5425
|
+
const table = {};
|
|
5426
|
+
for (const [moduleName, module] of Object.entries(this.moduleUniforms)) {
|
|
5427
|
+
for (const [key, value] of Object.entries(module)) {
|
|
5428
|
+
table[`${moduleName}.${key}`] = {
|
|
5429
|
+
type: this.modules[moduleName].uniformTypes?.[key],
|
|
5430
|
+
value: String(value)
|
|
5431
|
+
};
|
|
5432
|
+
}
|
|
5433
|
+
}
|
|
5434
|
+
return table;
|
|
5435
|
+
}
|
|
5410
5436
|
};
|
|
5411
5437
|
|
|
5412
5438
|
// src/geometry/gpu-geometry.ts
|
|
@@ -5487,6 +5513,9 @@ void main() {
|
|
|
5487
5513
|
case "TEXCOORD_0":
|
|
5488
5514
|
name2 = "texCoords";
|
|
5489
5515
|
break;
|
|
5516
|
+
case "COLOR_0":
|
|
5517
|
+
name2 = "colors";
|
|
5518
|
+
break;
|
|
5490
5519
|
}
|
|
5491
5520
|
attributes[name2] = device.createBuffer({
|
|
5492
5521
|
data: attribute.value,
|
|
@@ -5603,6 +5632,27 @@ void main() {
|
|
|
5603
5632
|
fs: void 0
|
|
5604
5633
|
});
|
|
5605
5634
|
|
|
5635
|
+
// src/debug/debug-shader-layout.ts
|
|
5636
|
+
function getDebugTableForShaderLayout(layout, name2 = "") {
|
|
5637
|
+
const table = {};
|
|
5638
|
+
const header = `Shader Layout for ${name2}`;
|
|
5639
|
+
for (const attributeDeclaration of layout.attributes) {
|
|
5640
|
+
if (attributeDeclaration) {
|
|
5641
|
+
const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
|
|
5642
|
+
table[`in ${glslDeclaration}`] = {
|
|
5643
|
+
[header]: attributeDeclaration.stepMode || "vertex"
|
|
5644
|
+
};
|
|
5645
|
+
}
|
|
5646
|
+
}
|
|
5647
|
+
for (const varyingDeclaration of layout.varyings || []) {
|
|
5648
|
+
const glslDeclaration = `${varyingDeclaration.location} ${varyingDeclaration.name}`;
|
|
5649
|
+
table[`out ${glslDeclaration}`] = {
|
|
5650
|
+
[header]: JSON.stringify(varyingDeclaration.accessor)
|
|
5651
|
+
};
|
|
5652
|
+
}
|
|
5653
|
+
return table;
|
|
5654
|
+
}
|
|
5655
|
+
|
|
5606
5656
|
// src/model/model.ts
|
|
5607
5657
|
var LOG_DRAW_PRIORITY = 2;
|
|
5608
5658
|
var LOG_DRAW_TIMEOUT = 1e4;
|
|
@@ -5684,7 +5734,7 @@ void main() {
|
|
|
5684
5734
|
this.setUniforms(props.uniforms);
|
|
5685
5735
|
}
|
|
5686
5736
|
if (props.moduleSettings) {
|
|
5687
|
-
|
|
5737
|
+
log.warn("Model.props.moduleSettings is deprecated. Use Model.shaderInputs.setProps()")();
|
|
5688
5738
|
this.updateModuleSettings(props.moduleSettings);
|
|
5689
5739
|
}
|
|
5690
5740
|
if (props.transformFeedback) {
|
|
@@ -5728,7 +5778,7 @@ void main() {
|
|
|
5728
5778
|
}
|
|
5729
5779
|
_setGeometryAttributes(gpuGeometry) {
|
|
5730
5780
|
this.vertexCount = gpuGeometry.vertexCount;
|
|
5731
|
-
this.setAttributes(gpuGeometry.attributes);
|
|
5781
|
+
this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
|
|
5732
5782
|
this.setIndexBuffer(gpuGeometry.indices);
|
|
5733
5783
|
}
|
|
5734
5784
|
setTopology(topology) {
|
|
@@ -5772,7 +5822,7 @@ void main() {
|
|
|
5772
5822
|
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
|
|
5773
5823
|
}
|
|
5774
5824
|
updateModuleSettings(props) {
|
|
5775
|
-
|
|
5825
|
+
log.warn("Model.updateModuleSettings is deprecated. Use Model.shaderInputs.setProps()")();
|
|
5776
5826
|
const {
|
|
5777
5827
|
bindings,
|
|
5778
5828
|
uniforms
|
|
@@ -5793,17 +5843,17 @@ void main() {
|
|
|
5793
5843
|
setTransformFeedback(transformFeedback) {
|
|
5794
5844
|
this.transformFeedback = transformFeedback;
|
|
5795
5845
|
}
|
|
5796
|
-
setAttributes(buffers) {
|
|
5846
|
+
setAttributes(buffers, _option) {
|
|
5797
5847
|
if (buffers.indices) {
|
|
5798
|
-
log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`);
|
|
5848
|
+
log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();
|
|
5799
5849
|
}
|
|
5800
5850
|
for (const [bufferName, buffer] of Object.entries(buffers)) {
|
|
5801
|
-
const bufferLayout = this.bufferLayout.find((layout) => layout.
|
|
5851
|
+
const bufferLayout = this.bufferLayout.find((layout) => getAttributeNames(layout).includes(bufferName));
|
|
5802
5852
|
if (!bufferLayout) {
|
|
5803
5853
|
log.warn(`Model(${this.id}): Missing layout for buffer "${bufferName}".`)();
|
|
5804
5854
|
continue;
|
|
5805
5855
|
}
|
|
5806
|
-
const attributeNames = bufferLayout
|
|
5856
|
+
const attributeNames = getAttributeNames(bufferLayout);
|
|
5807
5857
|
let set = false;
|
|
5808
5858
|
for (const attributeName of attributeNames) {
|
|
5809
5859
|
const attributeInfo = this._attributeInfos[attributeName];
|
|
@@ -5812,7 +5862,7 @@ void main() {
|
|
|
5812
5862
|
set = true;
|
|
5813
5863
|
}
|
|
5814
5864
|
}
|
|
5815
|
-
if (!set) {
|
|
5865
|
+
if (!set && _option !== "ignore-unknown") {
|
|
5816
5866
|
log.warn(`Model(${this.id}): Ignoring buffer "${buffer.id}" for unknown attribute "${bufferName}"`)();
|
|
5817
5867
|
}
|
|
5818
5868
|
}
|
|
@@ -5873,10 +5923,47 @@ void main() {
|
|
|
5873
5923
|
if (this._logOpen) {
|
|
5874
5924
|
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout);
|
|
5875
5925
|
log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
|
|
5926
|
+
const uniformTable = this.shaderInputs.getDebugTable();
|
|
5927
|
+
for (const [name2, value] of Object.entries(this.uniforms)) {
|
|
5928
|
+
uniformTable[name2] = {
|
|
5929
|
+
value
|
|
5930
|
+
};
|
|
5931
|
+
}
|
|
5932
|
+
log.table(LOG_DRAW_PRIORITY, uniformTable)();
|
|
5933
|
+
const attributeTable = this._getAttributeDebugTable();
|
|
5934
|
+
log.table(LOG_DRAW_PRIORITY, this._attributeInfos)();
|
|
5935
|
+
log.table(LOG_DRAW_PRIORITY, attributeTable)();
|
|
5876
5936
|
log.groupEnd(LOG_DRAW_PRIORITY)();
|
|
5877
5937
|
this._logOpen = false;
|
|
5878
5938
|
}
|
|
5879
5939
|
}
|
|
5940
|
+
_getAttributeDebugTable() {
|
|
5941
|
+
const table = {};
|
|
5942
|
+
for (const [name2, attributeInfo] of Object.entries(this._attributeInfos)) {
|
|
5943
|
+
table[attributeInfo.location] = {
|
|
5944
|
+
name: name2,
|
|
5945
|
+
type: attributeInfo.shaderType,
|
|
5946
|
+
values: this._getBufferOrConstantValues(this.vertexArray.attributes[attributeInfo.location], attributeInfo.bufferDataType)
|
|
5947
|
+
};
|
|
5948
|
+
}
|
|
5949
|
+
if (this.vertexArray.indexBuffer) {
|
|
5950
|
+
const {
|
|
5951
|
+
indexBuffer
|
|
5952
|
+
} = this.vertexArray;
|
|
5953
|
+
const values = indexBuffer.indexType === "uint32" ? new Uint32Array(indexBuffer.debugData) : new Uint16Array(indexBuffer.debugData);
|
|
5954
|
+
table.indices = {
|
|
5955
|
+
name: "indices",
|
|
5956
|
+
type: indexBuffer.indexType,
|
|
5957
|
+
values: values.toString()
|
|
5958
|
+
};
|
|
5959
|
+
}
|
|
5960
|
+
return table;
|
|
5961
|
+
}
|
|
5962
|
+
_getBufferOrConstantValues(attribute, dataType) {
|
|
5963
|
+
const TypedArrayConstructor = getTypedArrayFromDataType(dataType);
|
|
5964
|
+
const typedArray = attribute instanceof Buffer2 ? new TypedArrayConstructor(attribute.debugData) : attribute;
|
|
5965
|
+
return typedArray.toString();
|
|
5966
|
+
}
|
|
5880
5967
|
};
|
|
5881
5968
|
var Model = _Model;
|
|
5882
5969
|
__publicField(Model, "defaultProps", {
|
|
@@ -5920,6 +6007,9 @@ void main() {
|
|
|
5920
6007
|
features: device.features
|
|
5921
6008
|
};
|
|
5922
6009
|
}
|
|
6010
|
+
function getAttributeNames(bufferLayout) {
|
|
6011
|
+
return bufferLayout.attributes ? bufferLayout.attributes?.map((layout) => layout.attribute) : [bufferLayout.name];
|
|
6012
|
+
}
|
|
5923
6013
|
|
|
5924
6014
|
// src/transform/buffer-transform.ts
|
|
5925
6015
|
var BufferTransform = class {
|
|
@@ -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,EAA4C,MAAM,eAAe,CAAC;AACxF,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAEnD,MAAM,MAAM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CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAEhC,KAAK,EAAE,gBAAgB;IAenC,OAAO,IAAI,IAAI;IAQf,cAAc,IAAI,MAAM;IAIxB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,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,CAqBzF"}
|
|
@@ -1 +1 @@
|
|
|
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","normalized","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, normalized} = attribute;\n bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)});\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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EACpF,OAAO,IAAIzB,WAAW,CAAC;IACrBK,QAAQ,EAAEoB,QAAQ,CAACpB,QAAQ,IAAI,eAAe;IAC9CC,YAAY;IACZC,WAAW,EAAEkB,QAAQ,CAAClB,WAAW;IACjCC,OAAO;IACPC;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,SAASiB,0BAA0BA,CAACF,MAAc,EAAEC,QAAkB,EAAsB;EACjG,IAAI,CAACA,QAAQ,CAACjB,OAAO,EAAE;IACrB,OAAOoB,SAAS;EAClB;EACA,MAAMC,IAAI,GAAGJ,QAAQ,CAACjB,OAAO,CAACsB,KAAK;EACnC,OAAON,MAAM,CAACO,YAAY,CAAC;IAACrB,KAAK,EAAEd,MAAM,CAACe,KAAK;IAAEkB;EAAI,CAAC,CAAC;AACzD;AAEA,OAAO,SAASF,+BAA+BA,CAC7CH,MAAc,EACdC,QAAkB,EACuE;EACzF,MAAMnB,YAA4B,GAAG,EAAE;EAEvC,MAAMG,UAAkC,GAAG,CAAC,CAAC;EAC7C,KAAK,MAAM,CAACuB,aAAa,EAAEC,SAAS,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACV,QAAQ,CAAChB,UAAU,CAAC,EAAE;IAC5E,IAAI2B,IAAY,GAAGJ,aAAa;IAEhC,QAAQA,aAAa;MACnB,KAAK,UAAU;QAAEI,IAAI,GAAG,WAAW;QAAE;MACrC,KAAK,QAAQ;QAAEA,IAAI,GAAG,SAAS;QAAE;MACjC,KAAK,YAAY;QAAEA,IAAI,GAAG,WAAW;QAAE;
|
|
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","normalized","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 case 'COLOR_0': name = 'colors'; break;\n }\n attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});\n const {value, size, normalized} = attribute;\n bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)});\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,EAA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