@loaders.gl/draco 4.0.0-beta.3 → 4.0.0-beta.4

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
@@ -62,7 +62,6 @@ var __exports__ = (() => {
62
62
  var DEFAULT_DRACO_OPTIONS = {
63
63
  draco: {
64
64
  decoderType: typeof WebAssembly === "object" ? "wasm" : "js",
65
- // 'js' for IE11
66
65
  libraryPath: "libs/",
67
66
  extraAttributes: {},
68
67
  attributeNameEntry: void 0
@@ -72,7 +71,6 @@ var __exports__ = (() => {
72
71
  name: "Draco",
73
72
  id: "draco",
74
73
  module: "draco",
75
- // shapes: ['mesh'],
76
74
  version: VERSION,
77
75
  worker: true,
78
76
  extensions: ["drc"],
@@ -222,24 +220,15 @@ var __exports__ = (() => {
222
220
  };
223
221
  var INDEX_ITEM_SIZE = 4;
224
222
  var DracoParser = class {
225
- // draco - the draco decoder, either import `draco3d` or load dynamically
226
223
  constructor(draco) {
227
224
  this.draco = draco;
228
225
  this.decoder = new this.draco.Decoder();
229
226
  this.metadataQuerier = new this.draco.MetadataQuerier();
230
227
  }
231
- /**
232
- * Destroy draco resources
233
- */
234
228
  destroy() {
235
229
  this.draco.destroy(this.decoder);
236
230
  this.draco.destroy(this.metadataQuerier);
237
231
  }
238
- /**
239
- * NOTE: caller must call `destroyGeometry` on the return value after using it
240
- * @param arrayBuffer
241
- * @param options
242
- */
243
232
  parseSync(arrayBuffer, options = {}) {
244
233
  const buffer = new this.draco.DecoderBuffer();
245
234
  buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
@@ -284,14 +273,6 @@ var __exports__ = (() => {
284
273
  }
285
274
  }
286
275
  }
287
- // Draco specific "loader data"
288
- /**
289
- * Extract
290
- * @param dracoGeometry
291
- * @param geometry_type
292
- * @param options
293
- * @returns
294
- */
295
276
  _getDracoLoaderData(dracoGeometry, geometry_type, options) {
296
277
  const metadata = this._getTopLevelMetadata(dracoGeometry);
297
278
  const attributes = this._getDracoAttributes(dracoGeometry, options);
@@ -304,12 +285,6 @@ var __exports__ = (() => {
304
285
  attributes
305
286
  };
306
287
  }
307
- /**
308
- * Extract all draco provided information and metadata for each attribute
309
- * @param dracoGeometry
310
- * @param options
311
- * @returns
312
- */
313
288
  _getDracoAttributes(dracoGeometry, options) {
314
289
  const dracoAttributes = {};
315
290
  for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
@@ -337,12 +312,6 @@ var __exports__ = (() => {
337
312
  }
338
313
  return dracoAttributes;
339
314
  }
340
- /**
341
- * Get standard loaders.gl mesh category data
342
- * Extracts the geometry from draco
343
- * @param dracoGeometry
344
- * @param options
345
- */
346
315
  _getMeshData(dracoGeometry, loaderData, options) {
347
316
  const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
348
317
  const positionAttribute = attributes.POSITION;
@@ -355,7 +324,6 @@ var __exports__ = (() => {
355
324
  return {
356
325
  topology: "triangle-strip",
357
326
  mode: 4,
358
- // GL.TRIANGLES
359
327
  attributes,
360
328
  indices: {
361
329
  value: this._getTriangleStripIndices(dracoGeometry),
@@ -367,7 +335,6 @@ var __exports__ = (() => {
367
335
  return {
368
336
  topology: "triangle-list",
369
337
  mode: 5,
370
- // GL.TRIANGLE_STRIP
371
338
  attributes,
372
339
  indices: {
373
340
  value: this._getTriangleListIndices(dracoGeometry),
@@ -379,7 +346,6 @@ var __exports__ = (() => {
379
346
  return {
380
347
  topology: "point-list",
381
348
  mode: 0,
382
- // GL.POINTS
383
349
  attributes
384
350
  };
385
351
  }
@@ -402,11 +368,6 @@ var __exports__ = (() => {
402
368
  }
403
369
  return attributes;
404
370
  }
405
- // MESH INDICES EXTRACTION
406
- /**
407
- * For meshes, we need indices to define the faces.
408
- * @param dracoGeometry
409
- */
410
371
  _getTriangleListIndices(dracoGeometry) {
411
372
  const numFaces = dracoGeometry.num_faces();
412
373
  const numIndices = numFaces * 3;
@@ -419,10 +380,6 @@ var __exports__ = (() => {
419
380
  this.draco._free(ptr);
420
381
  }
421
382
  }
422
- /**
423
- * For meshes, we need indices to define the faces.
424
- * @param dracoGeometry
425
- */
426
383
  _getTriangleStripIndices(dracoGeometry) {
427
384
  const dracoArray = new this.draco.DracoInt32Array();
428
385
  try {
@@ -432,12 +389,6 @@ var __exports__ = (() => {
432
389
  this.draco.destroy(dracoArray);
433
390
  }
434
391
  }
435
- /**
436
- *
437
- * @param dracoGeometry
438
- * @param dracoAttribute
439
- * @param attributeName
440
- */
441
392
  _getAttributeValues(dracoGeometry, attribute) {
442
393
  const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
443
394
  const numComponents = attribute.num_components;
@@ -459,30 +410,6 @@ var __exports__ = (() => {
459
410
  size: numComponents
460
411
  };
461
412
  }
462
- // Attribute names
463
- /**
464
- * DRACO does not store attribute names - We need to deduce an attribute name
465
- * for each attribute
466
- _getAttributeNames(
467
- dracoGeometry: Mesh | PointCloud,
468
- options: DracoParseOptions
469
- ): {[unique_id: number]: string} {
470
- const attributeNames: {[unique_id: number]: string} = {};
471
- for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
472
- const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
473
- const attributeName = this._deduceAttributeName(dracoAttribute, options);
474
- attributeNames[attributeName] = attributeName;
475
- }
476
- return attributeNames;
477
- }
478
- */
479
- /**
480
- * Deduce an attribute name.
481
- * @note DRACO does not save attribute names, just general type (POSITION, COLOR)
482
- * to help optimize compression. We generate GLTF compatible names for the Draco-recognized
483
- * types
484
- * @param attributeData
485
- */
486
413
  _deduceAttributeName(attribute, options) {
487
414
  const uniqueId = attribute.unique_id;
488
415
  for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) {
@@ -503,22 +430,14 @@ var __exports__ = (() => {
503
430
  }
504
431
  return `CUSTOM_ATTRIBUTE_${uniqueId}`;
505
432
  }
506
- // METADATA EXTRACTION
507
- /** Get top level metadata */
508
433
  _getTopLevelMetadata(dracoGeometry) {
509
434
  const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
510
435
  return this._getDracoMetadata(dracoMetadata);
511
436
  }
512
- /** Get per attribute metadata */
513
437
  _getAttributeMetadata(dracoGeometry, attributeId) {
514
438
  const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
515
439
  return this._getDracoMetadata(dracoMetadata);
516
440
  }
517
- /**
518
- * Extract metadata field values
519
- * @param dracoMetadata
520
- * @returns
521
- */
522
441
  _getDracoMetadata(dracoMetadata) {
523
442
  if (!dracoMetadata || !dracoMetadata.ptr) {
524
443
  return {};
@@ -531,11 +450,6 @@ var __exports__ = (() => {
531
450
  }
532
451
  return result;
533
452
  }
534
- /**
535
- * Extracts possible values for one metadata entry by name
536
- * @param dracoMetadata
537
- * @param entryName
538
- */
539
453
  _getDracoMetadataField(dracoMetadata, entryName) {
540
454
  const dracoArray = new this.draco.DracoInt32Array();
541
455
  try {
@@ -551,8 +465,6 @@ var __exports__ = (() => {
551
465
  this.draco.destroy(dracoArray);
552
466
  }
553
467
  }
554
- // QUANTIZED ATTRIBUTE SUPPORT (NO DECOMPRESSION)
555
- /** Skip transforms for specific attribute types */
556
468
  _disableAttributeTransforms(options) {
557
469
  const {
558
470
  quantizedAttributes = [],
@@ -563,10 +475,6 @@ var __exports__ = (() => {
563
475
  this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
564
476
  }
565
477
  }
566
- /**
567
- * Extract (and apply?) Position Transform
568
- * @todo not used
569
- */
570
478
  _getQuantizationTransform(dracoAttribute, options) {
571
479
  const {
572
480
  quantizedAttributes = []
@@ -609,7 +517,6 @@ var __exports__ = (() => {
609
517
  }
610
518
  return null;
611
519
  }
612
- // HELPERS
613
520
  };
614
521
  function getDracoDataType(draco, attributeType) {
615
522
  switch (attributeType) {
@@ -682,10 +589,7 @@ var __exports__ = (() => {
682
589
  var window_ = globals.window || globals.self || globals.global || {};
683
590
  var global_ = globals.global || globals.self || globals.window || {};
684
591
  var document_ = globals.document || {};
685
- var isBrowser = (
686
- // @ts-ignore process.browser
687
- typeof process !== "object" || String(process) !== "[object process]" || process.browser
688
- );
592
+ var isBrowser = typeof process !== "object" || String(process) !== "[object process]" || process.browser;
689
593
  var isWorker = typeof importScripts === "function";
690
594
  var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
691
595
  var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
@@ -698,8 +602,7 @@ var __exports__ = (() => {
698
602
  if (moduleName) {
699
603
  libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
700
604
  }
701
- loadLibraryPromises[libraryUrl] = // eslint-disable-next-line @typescript-eslint/no-misused-promises
702
- loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
605
+ loadLibraryPromises[libraryUrl] = loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
703
606
  return await loadLibraryPromises[libraryUrl];
704
607
  }
705
608
  function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
@@ -746,7 +649,7 @@ var __exports__ = (() => {
746
649
  return void 0 && (void 0)(scriptSource, id);
747
650
  }
748
651
  if (isWorker) {
749
- eval.call(global_, scriptSource);
652
+ eval.call(globalThis, scriptSource);
750
653
  return null;
751
654
  }
752
655
  const script = document.createElement("script");
@@ -779,13 +682,9 @@ var __exports__ = (() => {
779
682
  var DRACO_ENCODER_VERSION = "1.4.1";
780
683
  var STATIC_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_DECODER_VERSION}`;
781
684
  var DRACO_EXTERNAL_LIBRARIES = {
782
- /** The primary Draco3D encoder, javascript wrapper part */
783
685
  DECODER: "draco_wasm_wrapper.js",
784
- /** The primary draco decoder, compiled web assembly part */
785
686
  DECODER_WASM: "draco_decoder.wasm",
786
- /** Fallback decoder for non-webassebly environments. Very big bundle, lower performance */
787
687
  FALLBACK_DECODER: "draco_decoder.js",
788
- /** Draco encoder */
789
688
  ENCODER: "draco_encoder.js"
790
689
  };
791
690
  var DRACO_EXTERNAL_LIBRARY_URLS = {
@@ -847,7 +746,6 @@ var __exports__ = (() => {
847
746
  onModuleLoaded: (draco) => resolve({
848
747
  draco
849
748
  })
850
- // Module is Promise-like. Wrap in object to avoid loop.
851
749
  });
852
750
  });
853
751
  }
@@ -859,7 +757,6 @@ var __exports__ = (() => {
859
757
  onModuleLoaded: (draco) => resolve({
860
758
  draco
861
759
  })
862
- // Module is Promise-like. Wrap in object to avoid loop.
863
760
  });
864
761
  });
865
762
  }
@@ -874,7 +771,6 @@ var __exports__ = (() => {
874
771
  var noop = () => {
875
772
  };
876
773
  var DracoBuilder = class {
877
- // draco - the draco decoder, either import `draco3d` or load dynamically
878
774
  constructor(draco) {
879
775
  this.draco = draco;
880
776
  this.dracoEncoder = new this.draco.Encoder();
@@ -889,23 +785,16 @@ var __exports__ = (() => {
889
785
  this.dracoEncoder = null;
890
786
  this.draco = null;
891
787
  }
892
- // TBD - when does this need to be called?
893
788
  destroyEncodedObject(object) {
894
789
  if (object) {
895
790
  this.draco.destroy(object);
896
791
  }
897
792
  }
898
- /**
899
- * Encode mesh or point cloud
900
- * @param mesh =({})
901
- * @param options
902
- */
903
793
  encodeSync(mesh, options = {}) {
904
794
  this.log = noop;
905
795
  this._setOptions(options);
906
796
  return options.pointcloud ? this._encodePointCloud(mesh, options) : this._encodeMesh(mesh, options);
907
797
  }
908
- // PRIVATE
909
798
  _getAttributesFromMesh(mesh) {
910
799
  const attributes = {
911
800
  ...mesh,
@@ -958,10 +847,6 @@ var __exports__ = (() => {
958
847
  this.destroyEncodedObject(dracoMesh);
959
848
  }
960
849
  }
961
- /**
962
- * Set encoding options.
963
- * @param {{speed?: any; method?: any; quantization?: any;}} options
964
- */
965
850
  _setOptions(options) {
966
851
  if ("speed" in options) {
967
852
  this.dracoEncoder.SetSpeedOptions(...options.speed);
@@ -978,11 +863,6 @@ var __exports__ = (() => {
978
863
  }
979
864
  }
980
865
  }
981
- /**
982
- * @param {Mesh} dracoMesh
983
- * @param {object} attributes
984
- * @returns {Mesh}
985
- */
986
866
  _createDracoMesh(dracoMesh, attributes, options) {
987
867
  const optionalMetadata = options.attributesMetadata || {};
988
868
  try {
@@ -1008,10 +888,6 @@ var __exports__ = (() => {
1008
888
  }
1009
889
  return dracoMesh;
1010
890
  }
1011
- /**
1012
- * @param {} dracoPointCloud
1013
- * @param {object} attributes
1014
- */
1015
891
  _createDracoPointCloud(dracoPointCloud, attributes, options) {
1016
892
  const optionalMetadata = options.attributesMetadata || {};
1017
893
  try {
@@ -1037,12 +913,6 @@ var __exports__ = (() => {
1037
913
  }
1038
914
  return dracoPointCloud;
1039
915
  }
1040
- /**
1041
- * @param mesh
1042
- * @param attributeName
1043
- * @param attribute
1044
- * @param vertexCount
1045
- */
1046
916
  _addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
1047
917
  if (!ArrayBuffer.isView(attribute)) {
1048
918
  return -1;
@@ -1079,11 +949,6 @@ var __exports__ = (() => {
1079
949
  return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
1080
950
  }
1081
951
  }
1082
- /**
1083
- * DRACO can compress attributes of know type better
1084
- * TODO - expose an attribute type map?
1085
- * @param attributeName
1086
- */
1087
952
  _getDracoAttributeType(attributeName) {
1088
953
  switch (attributeName.toLowerCase()) {
1089
954
  case "indices":
@@ -1115,32 +980,16 @@ var __exports__ = (() => {
1115
980
  }
1116
981
  return null;
1117
982
  }
1118
- /**
1119
- * Add metadata for the geometry.
1120
- * @param dracoGeometry - WASM Draco Object
1121
- * @param metadata
1122
- */
1123
983
  _addGeometryMetadata(dracoGeometry, metadata) {
1124
984
  const dracoMetadata = new this.draco.Metadata();
1125
985
  this._populateDracoMetadata(dracoMetadata, metadata);
1126
986
  this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
1127
987
  }
1128
- /**
1129
- * Add metadata for an attribute to geometry.
1130
- * @param dracoGeometry - WASM Draco Object
1131
- * @param uniqueAttributeId
1132
- * @param metadata
1133
- */
1134
988
  _addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
1135
989
  const dracoAttributeMetadata = new this.draco.Metadata();
1136
990
  this._populateDracoMetadata(dracoAttributeMetadata, metadata);
1137
991
  this.dracoMeshBuilder.SetMetadataForAttribute(dracoGeometry, uniqueAttributeId, dracoAttributeMetadata);
1138
992
  }
1139
- /**
1140
- * Add contents of object or map to a WASM Draco Metadata Object
1141
- * @param dracoMetadata - WASM Draco Object
1142
- * @param metadata
1143
- */
1144
993
  _populateDracoMetadata(dracoMetadata, metadata) {
1145
994
  for (const [key, value] of getEntries(metadata)) {
1146
995
  switch (typeof value) {
@@ -1180,14 +1029,7 @@ var __exports__ = (() => {
1180
1029
  // src/draco-writer.ts
1181
1030
  var DEFAULT_DRACO_WRITER_OPTIONS = {
1182
1031
  pointcloud: false,
1183
- // Set to true if pointcloud (mode: 0, no indices)
1184
1032
  attributeNameEntry: "name"
1185
- // Draco Compression Parameters
1186
- // method: 'MESH_EDGEBREAKER_ENCODING', // Use draco defaults
1187
- // speed: [5, 5], // Use draco defaults
1188
- // quantization: { // Use draco defaults
1189
- // POSITION: 10
1190
- // }
1191
1033
  };
1192
1034
  var DracoWriter = {
1193
1035
  name: "DRACO",