@luma.gl/gltf 9.0.0-alpha.53 → 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/dist.dev.js CHANGED
@@ -975,14 +975,20 @@ var __exports__ = (() => {
975
975
  this.usage = props.usage || 0;
976
976
  this.indexType = deducedProps.indexType;
977
977
  }
978
- write(data, byteOffset) {
978
+ readSyncWebGL2(byteOffset, byteLength) {
979
979
  throw new Error("not implemented");
980
980
  }
981
- readAsync(byteOffset, byteLength) {
982
- throw new Error("not implemented");
983
- }
984
- getData() {
985
- throw new Error("not implemented");
981
+ debugData = new ArrayBuffer(0);
982
+ _setDebugData(data, byteOffset, byteLength) {
983
+ const buffer = ArrayBuffer.isView(data) ? data.buffer : data;
984
+ const debugDataLength = Math.min(data ? data.byteLength : byteLength, _Buffer.DEBUG_DATA_MAX_LENGTH);
985
+ if (data === null) {
986
+ this.debugData = new ArrayBuffer(debugDataLength);
987
+ } else if (byteOffset === 0 && byteLength === data.byteLength) {
988
+ this.debugData = buffer.slice(0, debugDataLength);
989
+ } else {
990
+ this.debugData = buffer.slice(byteOffset, byteOffset + debugDataLength);
991
+ }
986
992
  }
987
993
  };
988
994
  var Buffer2 = _Buffer;
@@ -1005,6 +1011,7 @@ var __exports__ = (() => {
1005
1011
  __publicField(Buffer2, "STORAGE", 128);
1006
1012
  __publicField(Buffer2, "INDIRECT", 256);
1007
1013
  __publicField(Buffer2, "QUERY_RESOLVE", 512);
1014
+ __publicField(Buffer2, "DEBUG_DATA_MAX_LENGTH", 32);
1008
1015
 
1009
1016
  // ../core/src/adapter/device.ts
1010
1017
  var _Device = class {
@@ -2528,6 +2535,30 @@ ${htmlLog}
2528
2535
  throw new Error(type.constructor.name);
2529
2536
  }
2530
2537
  }
2538
+ function getTypedArrayFromDataType(dataType) {
2539
+ switch (dataType) {
2540
+ case "float32":
2541
+ return Float32Array;
2542
+ case "uint32":
2543
+ return Uint32Array;
2544
+ case "sint32":
2545
+ return Int32Array;
2546
+ case "uint16":
2547
+ case "unorm16":
2548
+ return Uint16Array;
2549
+ case "sint16":
2550
+ case "snorm16":
2551
+ return Int16Array;
2552
+ case "uint8":
2553
+ case "unorm8":
2554
+ return Uint8Array;
2555
+ case "sint8":
2556
+ case "snorm8":
2557
+ return Int8Array;
2558
+ default:
2559
+ throw new Error(dataType);
2560
+ }
2561
+ }
2531
2562
  function getVertexFormatFromAttribute(typedArray, size, normalized) {
2532
2563
  if (!size || size > 4) {
2533
2564
  throw new Error(`size ${size}`);
@@ -8046,12 +8077,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
8046
8077
  log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();
8047
8078
  }
8048
8079
  for (const [bufferName, buffer] of Object.entries(buffers)) {
8049
- const bufferLayout = this.bufferLayout.find((layout) => layout.name === bufferName);
8080
+ const bufferLayout = this.bufferLayout.find((layout) => getAttributeNames(layout).includes(bufferName));
8050
8081
  if (!bufferLayout) {
8051
8082
  log.warn(`Model(${this.id}): Missing layout for buffer "${bufferName}".`)();
8052
8083
  continue;
8053
8084
  }
8054
- const attributeNames = bufferLayout.attributes ? bufferLayout.attributes?.map((layout) => layout.attribute) : [bufferLayout.name];
8085
+ const attributeNames = getAttributeNames(bufferLayout);
8055
8086
  let set2 = false;
8056
8087
  for (const attributeName of attributeNames) {
8057
8088
  const attributeInfo = this._attributeInfos[attributeName];
@@ -8128,10 +8159,40 @@ vec4 pbr_filterColor(vec4 colorUnused)
8128
8159
  };
8129
8160
  }
8130
8161
  log.table(LOG_DRAW_PRIORITY, uniformTable)();
8162
+ const attributeTable = this._getAttributeDebugTable();
8163
+ log.table(LOG_DRAW_PRIORITY, this._attributeInfos)();
8164
+ log.table(LOG_DRAW_PRIORITY, attributeTable)();
8131
8165
  log.groupEnd(LOG_DRAW_PRIORITY)();
8132
8166
  this._logOpen = false;
8133
8167
  }
8134
8168
  }
8169
+ _getAttributeDebugTable() {
8170
+ const table = {};
8171
+ for (const [name2, attributeInfo] of Object.entries(this._attributeInfos)) {
8172
+ table[attributeInfo.location] = {
8173
+ name: name2,
8174
+ type: attributeInfo.shaderType,
8175
+ values: this._getBufferOrConstantValues(this.vertexArray.attributes[attributeInfo.location], attributeInfo.bufferDataType)
8176
+ };
8177
+ }
8178
+ if (this.vertexArray.indexBuffer) {
8179
+ const {
8180
+ indexBuffer
8181
+ } = this.vertexArray;
8182
+ const values = indexBuffer.indexType === "uint32" ? new Uint32Array(indexBuffer.debugData) : new Uint16Array(indexBuffer.debugData);
8183
+ table.indices = {
8184
+ name: "indices",
8185
+ type: indexBuffer.indexType,
8186
+ values: values.toString()
8187
+ };
8188
+ }
8189
+ return table;
8190
+ }
8191
+ _getBufferOrConstantValues(attribute, dataType) {
8192
+ const TypedArrayConstructor = getTypedArrayFromDataType(dataType);
8193
+ const typedArray = attribute instanceof Buffer2 ? new TypedArrayConstructor(attribute.debugData) : attribute;
8194
+ return typedArray.toString();
8195
+ }
8135
8196
  };
8136
8197
  var Model = _Model;
8137
8198
  __publicField(Model, "defaultProps", {
@@ -8175,6 +8236,9 @@ vec4 pbr_filterColor(vec4 colorUnused)
8175
8236
  features: device.features
8176
8237
  };
8177
8238
  }
8239
+ function getAttributeNames(bufferLayout) {
8240
+ return bufferLayout.attributes ? bufferLayout.attributes?.map((layout) => layout.attribute) : [bufferLayout.name];
8241
+ }
8178
8242
 
8179
8243
  // ../engine/src/geometry/geometry.ts
8180
8244
  var Geometry = class {
@@ -11929,10 +11993,8 @@ void main(void) {}`;
11929
11993
  }
11930
11994
 
11931
11995
  // ../webgl/src/adapter/resources/webgl-buffer.ts
11932
- var DEBUG_DATA_LENGTH = 10;
11933
11996
  var WEBGLBuffer = class extends Buffer2 {
11934
11997
  glIndexType = GLEnum2.UNSIGNED_SHORT;
11935
- debugData = null;
11936
11998
  constructor(device, props = {}) {
11937
11999
  super(device, props);
11938
12000
  this.device = device;
@@ -11947,7 +12009,6 @@ void main(void) {}`;
11947
12009
  this.glTarget = getWebGLTarget(this.props.usage);
11948
12010
  this.glUsage = getWebGLUsage(this.props.usage);
11949
12011
  this.glIndexType = this.props.indexType === "uint32" ? GLEnum2.UNSIGNED_INT : GLEnum2.UNSIGNED_SHORT;
11950
- this.debugData = null;
11951
12012
  if (props.data) {
11952
12013
  this._initWithData(props.data, props.byteOffset, props.byteLength);
11953
12014
  } else {
@@ -11955,17 +12016,15 @@ void main(void) {}`;
11955
12016
  }
11956
12017
  }
11957
12018
  _initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
11958
- assert2(ArrayBuffer.isView(data));
11959
- const glTarget = this._getWriteTarget();
12019
+ const glTarget = this.glTarget;
11960
12020
  this.gl.bindBuffer(glTarget, this.handle);
11961
12021
  this.gl.bufferData(glTarget, byteLength, this.glUsage);
11962
12022
  this.gl.bufferSubData(glTarget, byteOffset, data);
11963
12023
  this.gl.bindBuffer(glTarget, null);
11964
- this.debugData = data.slice(0, DEBUG_DATA_LENGTH);
11965
12024
  this.bytesUsed = byteLength;
11966
12025
  this.byteLength = byteLength;
12026
+ this._setDebugData(data, byteOffset, byteLength);
11967
12027
  this.trackAllocatedMemory(byteLength);
11968
- return this;
11969
12028
  }
11970
12029
  _initWithByteLength(byteLength) {
11971
12030
  assert2(byteLength >= 0);
@@ -11973,13 +12032,14 @@ void main(void) {}`;
11973
12032
  if (byteLength === 0) {
11974
12033
  data = new Float32Array(0);
11975
12034
  }
11976
- const glTarget = this._getWriteTarget();
12035
+ const glTarget = this.glTarget;
11977
12036
  this.gl.bindBuffer(glTarget, this.handle);
11978
12037
  this.gl.bufferData(glTarget, data, this.glUsage);
11979
12038
  this.gl.bindBuffer(glTarget, null);
11980
- this.debugData = null;
11981
12039
  this.bytesUsed = byteLength;
11982
12040
  this.byteLength = byteLength;
12041
+ this._setDebugData(null, 0, byteLength);
12042
+ this.trackAllocatedMemory(byteLength);
11983
12043
  return this;
11984
12044
  }
11985
12045
  destroy() {
@@ -12003,26 +12063,22 @@ void main(void) {}`;
12003
12063
  this.gl.bufferSubData(glTarget, byteOffset, data);
12004
12064
  }
12005
12065
  this.gl.bindBuffer(glTarget, null);
12066
+ this._setDebugData(data, byteOffset, data.byteLength);
12006
12067
  }
12007
12068
  async readAsync(byteOffset = 0, byteLength) {
12069
+ return this.readSyncWebGL2(byteOffset, byteLength);
12070
+ }
12071
+ readSyncWebGL2(byteOffset = 0, byteLength) {
12008
12072
  this.device.assertWebGL2();
12009
- byteLength = byteLength ?? this.byteLength;
12073
+ byteLength = byteLength ?? this.byteLength - byteOffset;
12010
12074
  const data = new Uint8Array(byteLength);
12011
12075
  const dstOffset = 0;
12012
12076
  this.gl.bindBuffer(GLEnum2.COPY_READ_BUFFER, this.handle);
12013
12077
  this.gl2.getBufferSubData(GLEnum2.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);
12014
12078
  this.gl.bindBuffer(GLEnum2.COPY_READ_BUFFER, null);
12079
+ this._setDebugData(data, byteOffset, byteLength);
12015
12080
  return data;
12016
12081
  }
12017
- _invalidateDebugData() {
12018
- this.debugData = null;
12019
- }
12020
- _getWriteTarget() {
12021
- return this.glTarget;
12022
- }
12023
- _getReadTarget() {
12024
- return this.glTarget;
12025
- }
12026
12082
  };
12027
12083
  function getWebGLTarget(usage) {
12028
12084
  if (usage & Buffer2.INDEX) {