@loaders.gl/draco 4.2.0-alpha.4 → 4.2.0-alpha.5

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.
Files changed (48) hide show
  1. package/dist/dist.dev.js +260 -79
  2. package/dist/dist.min.js +11 -0
  3. package/dist/draco-loader.d.ts +2 -2
  4. package/dist/draco-loader.d.ts.map +1 -1
  5. package/dist/draco-loader.js +23 -17
  6. package/dist/draco-writer.d.ts +2 -2
  7. package/dist/draco-writer.d.ts.map +1 -1
  8. package/dist/draco-writer.js +30 -23
  9. package/dist/draco3d/draco3d-types.js +48 -41
  10. package/dist/index.cjs +26 -71
  11. package/dist/index.cjs.map +7 -0
  12. package/dist/index.d.ts +6 -6
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +27 -21
  15. package/dist/lib/draco-builder.d.ts +2 -2
  16. package/dist/lib/draco-builder.d.ts.map +1 -1
  17. package/dist/lib/draco-builder.js +309 -243
  18. package/dist/lib/draco-module-loader.js +78 -62
  19. package/dist/lib/draco-parser.d.ts +2 -2
  20. package/dist/lib/draco-parser.d.ts.map +1 -1
  21. package/dist/lib/draco-parser.js +434 -323
  22. package/dist/lib/draco-types.js +1 -1
  23. package/dist/lib/utils/get-draco-schema.d.ts +1 -1
  24. package/dist/lib/utils/get-draco-schema.d.ts.map +1 -1
  25. package/dist/lib/utils/get-draco-schema.js +29 -32
  26. package/dist/lib/utils/version.js +3 -1
  27. package/dist/workers/draco-worker-node.js +1 -1
  28. package/dist/workers/draco-worker.js +0 -1
  29. package/dist/workers/draco-writer-worker-node.js +20 -25
  30. package/dist/workers/draco-writer-worker.js +19 -25
  31. package/package.json +12 -9
  32. package/dist/draco-loader.js.map +0 -1
  33. package/dist/draco-writer.js.map +0 -1
  34. package/dist/draco3d/draco3d-types.js.map +0 -1
  35. package/dist/index.js.map +0 -1
  36. package/dist/lib/draco-builder.js.map +0 -1
  37. package/dist/lib/draco-module-loader.js.map +0 -1
  38. package/dist/lib/draco-parser.js.map +0 -1
  39. package/dist/lib/draco-types.js.map +0 -1
  40. package/dist/lib/utils/get-draco-schema.js.map +0 -1
  41. package/dist/lib/utils/version.js.map +0 -1
  42. package/dist/libs/libs/draco_decoder.wasm +0 -0
  43. package/dist/libs/libs/draco_encoder.js +0 -52
  44. package/dist/libs/libs/draco_wasm_wrapper.js +0 -117
  45. package/dist/workers/draco-worker-node.js.map +0 -1
  46. package/dist/workers/draco-worker.js.map +0 -1
  47. package/dist/workers/draco-writer-worker-node.js.map +0 -1
  48. package/dist/workers/draco-writer-worker.js.map +0 -1
package/dist/dist.dev.js CHANGED
@@ -2,8 +2,8 @@
2
2
  if (typeof exports === 'object' && typeof module === 'object')
3
3
  module.exports = factory();
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
- else if (typeof exports === 'object') exports['loader'] = factory();
6
- else root['loader'] = factory();})(globalThis, function () {
5
+ else if (typeof exports === 'object') exports['loaders'] = factory();
6
+ else root['loaders'] = factory();})(globalThis, function () {
7
7
  "use strict";
8
8
  var __exports__ = (() => {
9
9
  var __create = Object.create;
@@ -27,6 +27,7 @@ var __exports__ = (() => {
27
27
  }
28
28
  return to;
29
29
  };
30
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
30
31
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
32
  // If the importer is in node compatibility mode or this is not an ESM
32
33
  // file that has been converted to a CommonJS file using a Babel-
@@ -37,6 +38,13 @@ var __exports__ = (() => {
37
38
  ));
38
39
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
40
 
41
+ // external-global-plugin:@loaders.gl/core
42
+ var require_core = __commonJS({
43
+ "external-global-plugin:@loaders.gl/core"(exports, module) {
44
+ module.exports = globalThis.loaders;
45
+ }
46
+ });
47
+
40
48
  // (disabled):../worker-utils/src/lib/node/require-utils.node
41
49
  var require_require_utils = __commonJS({
42
50
  "(disabled):../worker-utils/src/lib/node/require-utils.node"() {
@@ -44,9 +52,9 @@ var __exports__ = (() => {
44
52
  }
45
53
  });
46
54
 
47
- // src/index.ts
48
- var src_exports = {};
49
- __export(src_exports, {
55
+ // bundle.ts
56
+ var bundle_exports = {};
57
+ __export(bundle_exports, {
50
58
  DRACO_EXTERNAL_LIBRARIES: () => DRACO_EXTERNAL_LIBRARIES,
51
59
  DRACO_EXTERNAL_LIBRARY_URLS: () => DRACO_EXTERNAL_LIBRARY_URLS,
52
60
  DracoLoader: () => DracoLoader2,
@@ -54,15 +62,17 @@ var __exports__ = (() => {
54
62
  DracoWriter: () => DracoWriter,
55
63
  DracoWriterWorker: () => DracoWriterWorker
56
64
  });
65
+ __reExport(bundle_exports, __toESM(require_core(), 1));
57
66
 
58
67
  // src/lib/utils/version.ts
59
- var VERSION = true ? "4.2.0-alpha.4" : "latest";
68
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
60
69
 
61
70
  // src/draco-loader.ts
62
71
  var DracoLoader = {
63
72
  name: "Draco",
64
73
  id: "draco",
65
74
  module: "draco",
75
+ // shapes: ['mesh'],
66
76
  version: VERSION,
67
77
  worker: true,
68
78
  extensions: ["drc"],
@@ -72,6 +82,7 @@ var __exports__ = (() => {
72
82
  options: {
73
83
  draco: {
74
84
  decoderType: typeof WebAssembly === "object" ? "wasm" : "js",
85
+ // 'js' for IE11
75
86
  libraryPath: "libs/",
76
87
  extraAttributes: {},
77
88
  attributeNameEntry: void 0
@@ -125,7 +136,10 @@ var __exports__ = (() => {
125
136
  maxY = y > maxY ? y : maxY;
126
137
  maxZ = z > maxZ ? z : maxZ;
127
138
  }
128
- return [[minX, minY, minZ], [maxX, maxY, maxZ]];
139
+ return [
140
+ [minX, minY, minZ],
141
+ [maxX, maxY, maxZ]
142
+ ];
129
143
  }
130
144
 
131
145
  // ../schema/src/lib/mesh/deduce-mesh-schema.ts
@@ -134,14 +148,7 @@ var __exports__ = (() => {
134
148
  const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
135
149
  return {
136
150
  name,
137
- type: {
138
- type: "fixed-size-list",
139
- listSize: attribute.size,
140
- children: [{
141
- name: "value",
142
- type
143
- }]
144
- },
151
+ type: { type: "fixed-size-list", listSize: attribute.size, children: [{ name: "value", type }] },
145
152
  nullable: false,
146
153
  metadata
147
154
  };
@@ -167,17 +174,18 @@ var __exports__ = (() => {
167
174
  const namedLoaderDataAttributes = transformAttributesLoaderData(loaderData.attributes);
168
175
  for (const attributeName in attributes) {
169
176
  const attribute = attributes[attributeName];
170
- const field = getArrowFieldFromAttribute(attributeName, attribute, namedLoaderDataAttributes[attributeName]);
177
+ const field = getArrowFieldFromAttribute(
178
+ attributeName,
179
+ attribute,
180
+ namedLoaderDataAttributes[attributeName]
181
+ );
171
182
  fields.push(field);
172
183
  }
173
184
  if (indices) {
174
185
  const indicesField = getArrowFieldFromAttribute("indices", indices);
175
186
  fields.push(indicesField);
176
187
  }
177
- return {
178
- fields,
179
- metadata
180
- };
188
+ return { fields, metadata };
181
189
  }
182
190
  function transformAttributesLoaderData(loaderData) {
183
191
  const result = {};
@@ -219,15 +227,24 @@ var __exports__ = (() => {
219
227
  };
220
228
  var INDEX_ITEM_SIZE = 4;
221
229
  var DracoParser = class {
230
+ // draco - the draco decoder, either import `draco3d` or load dynamically
222
231
  constructor(draco) {
223
232
  this.draco = draco;
224
233
  this.decoder = new this.draco.Decoder();
225
234
  this.metadataQuerier = new this.draco.MetadataQuerier();
226
235
  }
236
+ /**
237
+ * Destroy draco resources
238
+ */
227
239
  destroy() {
228
240
  this.draco.destroy(this.decoder);
229
241
  this.draco.destroy(this.metadataQuerier);
230
242
  }
243
+ /**
244
+ * NOTE: caller must call `destroyGeometry` on the return value after using it
245
+ * @param arrayBuffer
246
+ * @param options
247
+ */
231
248
  parseSync(arrayBuffer, options = {}) {
232
249
  const buffer = new this.draco.DecoderBuffer();
233
250
  buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
@@ -272,6 +289,14 @@ var __exports__ = (() => {
272
289
  }
273
290
  }
274
291
  }
292
+ // Draco specific "loader data"
293
+ /**
294
+ * Extract
295
+ * @param dracoGeometry
296
+ * @param geometry_type
297
+ * @param options
298
+ * @returns
299
+ */
275
300
  _getDracoLoaderData(dracoGeometry, geometry_type, options) {
276
301
  const metadata = this._getTopLevelMetadata(dracoGeometry);
277
302
  const attributes = this._getDracoAttributes(dracoGeometry, options);
@@ -284,6 +309,12 @@ var __exports__ = (() => {
284
309
  attributes
285
310
  };
286
311
  }
312
+ /**
313
+ * Extract all draco provided information and metadata for each attribute
314
+ * @param dracoGeometry
315
+ * @param options
316
+ * @returns
317
+ */
287
318
  _getDracoAttributes(dracoGeometry, options) {
288
319
  const dracoAttributes = {};
289
320
  for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
@@ -311,6 +342,12 @@ var __exports__ = (() => {
311
342
  }
312
343
  return dracoAttributes;
313
344
  }
345
+ /**
346
+ * Get standard loaders.gl mesh category data
347
+ * Extracts the geometry from draco
348
+ * @param dracoGeometry
349
+ * @param options
350
+ */
314
351
  _getMeshData(dracoGeometry, loaderData, options) {
315
352
  const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
316
353
  const positionAttribute = attributes.POSITION;
@@ -323,6 +360,7 @@ var __exports__ = (() => {
323
360
  return {
324
361
  topology: "triangle-strip",
325
362
  mode: 4,
363
+ // GL.TRIANGLES
326
364
  attributes,
327
365
  indices: {
328
366
  value: this._getTriangleStripIndices(dracoGeometry),
@@ -334,6 +372,7 @@ var __exports__ = (() => {
334
372
  return {
335
373
  topology: "triangle-list",
336
374
  mode: 5,
375
+ // GL.TRIANGLE_STRIP
337
376
  attributes,
338
377
  indices: {
339
378
  value: this._getTriangleListIndices(dracoGeometry),
@@ -345,6 +384,7 @@ var __exports__ = (() => {
345
384
  return {
346
385
  topology: "point-list",
347
386
  mode: 0,
387
+ // GL.POINTS
348
388
  attributes
349
389
  };
350
390
  }
@@ -353,10 +393,7 @@ var __exports__ = (() => {
353
393
  for (const loaderAttribute of Object.values(loaderData.attributes)) {
354
394
  const attributeName = this._deduceAttributeName(loaderAttribute, options);
355
395
  loaderAttribute.name = attributeName;
356
- const {
357
- value,
358
- size
359
- } = this._getAttributeValues(dracoGeometry, loaderAttribute);
396
+ const { value, size } = this._getAttributeValues(dracoGeometry, loaderAttribute);
360
397
  attributes[attributeName] = {
361
398
  value,
362
399
  size,
@@ -367,6 +404,11 @@ var __exports__ = (() => {
367
404
  }
368
405
  return attributes;
369
406
  }
407
+ // MESH INDICES EXTRACTION
408
+ /**
409
+ * For meshes, we need indices to define the faces.
410
+ * @param dracoGeometry
411
+ */
370
412
  _getTriangleListIndices(dracoGeometry) {
371
413
  const numFaces = dracoGeometry.num_faces();
372
414
  const numIndices = numFaces * 3;
@@ -379,6 +421,10 @@ var __exports__ = (() => {
379
421
  this.draco._free(ptr);
380
422
  }
381
423
  }
424
+ /**
425
+ * For meshes, we need indices to define the faces.
426
+ * @param dracoGeometry
427
+ */
382
428
  _getTriangleStripIndices(dracoGeometry) {
383
429
  const dracoArray = new this.draco.DracoInt32Array();
384
430
  try {
@@ -388,6 +434,12 @@ var __exports__ = (() => {
388
434
  this.draco.destroy(dracoArray);
389
435
  }
390
436
  }
437
+ /**
438
+ *
439
+ * @param dracoGeometry
440
+ * @param dracoAttribute
441
+ * @param attributeName
442
+ */
391
443
  _getAttributeValues(dracoGeometry, attribute) {
392
444
  const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
393
445
  const numComponents = attribute.num_components;
@@ -399,19 +451,48 @@ var __exports__ = (() => {
399
451
  const ptr = this.draco._malloc(byteLength);
400
452
  try {
401
453
  const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
402
- this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
454
+ this.decoder.GetAttributeDataArrayForAllPoints(
455
+ dracoGeometry,
456
+ dracoAttribute,
457
+ dataType,
458
+ byteLength,
459
+ ptr
460
+ );
403
461
  value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
404
462
  } finally {
405
463
  this.draco._free(ptr);
406
464
  }
407
- return {
408
- value,
409
- size: numComponents
410
- };
411
- }
465
+ return { value, size: numComponents };
466
+ }
467
+ // Attribute names
468
+ /**
469
+ * DRACO does not store attribute names - We need to deduce an attribute name
470
+ * for each attribute
471
+ _getAttributeNames(
472
+ dracoGeometry: Mesh | PointCloud,
473
+ options: DracoParseOptions
474
+ ): {[unique_id: number]: string} {
475
+ const attributeNames: {[unique_id: number]: string} = {};
476
+ for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
477
+ const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
478
+ const attributeName = this._deduceAttributeName(dracoAttribute, options);
479
+ attributeNames[attributeName] = attributeName;
480
+ }
481
+ return attributeNames;
482
+ }
483
+ */
484
+ /**
485
+ * Deduce an attribute name.
486
+ * @note DRACO does not save attribute names, just general type (POSITION, COLOR)
487
+ * to help optimize compression. We generate GLTF compatible names for the Draco-recognized
488
+ * types
489
+ * @param attributeData
490
+ */
412
491
  _deduceAttributeName(attribute, options) {
413
492
  const uniqueId = attribute.unique_id;
414
- for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) {
493
+ for (const [attributeName, attributeUniqueId] of Object.entries(
494
+ options.extraAttributes || {}
495
+ )) {
415
496
  if (attributeUniqueId === uniqueId) {
416
497
  return attributeName;
417
498
  }
@@ -429,14 +510,22 @@ var __exports__ = (() => {
429
510
  }
430
511
  return `CUSTOM_ATTRIBUTE_${uniqueId}`;
431
512
  }
513
+ // METADATA EXTRACTION
514
+ /** Get top level metadata */
432
515
  _getTopLevelMetadata(dracoGeometry) {
433
516
  const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
434
517
  return this._getDracoMetadata(dracoMetadata);
435
518
  }
519
+ /** Get per attribute metadata */
436
520
  _getAttributeMetadata(dracoGeometry, attributeId) {
437
521
  const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
438
522
  return this._getDracoMetadata(dracoMetadata);
439
523
  }
524
+ /**
525
+ * Extract metadata field values
526
+ * @param dracoMetadata
527
+ * @returns
528
+ */
440
529
  _getDracoMetadata(dracoMetadata) {
441
530
  if (!dracoMetadata || !dracoMetadata.ptr) {
442
531
  return {};
@@ -449,6 +538,11 @@ var __exports__ = (() => {
449
538
  }
450
539
  return result;
451
540
  }
541
+ /**
542
+ * Extracts possible values for one metadata entry by name
543
+ * @param dracoMetadata
544
+ * @param entryName
545
+ */
452
546
  _getDracoMetadataField(dracoMetadata, entryName) {
453
547
  const dracoArray = new this.draco.DracoInt32Array();
454
548
  try {
@@ -464,20 +558,21 @@ var __exports__ = (() => {
464
558
  this.draco.destroy(dracoArray);
465
559
  }
466
560
  }
561
+ // QUANTIZED ATTRIBUTE SUPPORT (NO DECOMPRESSION)
562
+ /** Skip transforms for specific attribute types */
467
563
  _disableAttributeTransforms(options) {
468
- const {
469
- quantizedAttributes = [],
470
- octahedronAttributes = []
471
- } = options;
564
+ const { quantizedAttributes = [], octahedronAttributes = [] } = options;
472
565
  const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];
473
566
  for (const dracoAttributeName of skipAttributes) {
474
567
  this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
475
568
  }
476
569
  }
570
+ /**
571
+ * Extract (and apply?) Position Transform
572
+ * @todo not used
573
+ */
477
574
  _getQuantizationTransform(dracoAttribute, options) {
478
- const {
479
- quantizedAttributes = []
480
- } = options;
575
+ const { quantizedAttributes = [] } = options;
481
576
  const attribute_type = dracoAttribute.attribute_type();
482
577
  const skip = quantizedAttributes.map((type) => this.decoder[type]).includes(attribute_type);
483
578
  if (skip) {
@@ -497,9 +592,7 @@ var __exports__ = (() => {
497
592
  return null;
498
593
  }
499
594
  _getOctahedronTransform(dracoAttribute, options) {
500
- const {
501
- octahedronAttributes = []
502
- } = options;
595
+ const { octahedronAttributes = [] } = options;
503
596
  const attribute_type = dracoAttribute.attribute_type();
504
597
  const octahedron = octahedronAttributes.map((type) => this.decoder[type]).includes(attribute_type);
505
598
  if (octahedron) {
@@ -516,6 +609,7 @@ var __exports__ = (() => {
516
609
  }
517
610
  return null;
518
611
  }
612
+ // HELPERS
519
613
  };
520
614
  function getDracoDataType(draco, attributeType) {
521
615
  switch (attributeType) {
@@ -555,14 +649,17 @@ var __exports__ = (() => {
555
649
  }
556
650
 
557
651
  // ../worker-utils/src/lib/env-utils/version.ts
652
+ var NPM_TAG = "latest";
558
653
  function getVersion() {
559
654
  if (!globalThis._loadersgl_?.version) {
560
655
  globalThis._loadersgl_ = globalThis._loadersgl_ || {};
561
- if (false) {
562
- console.warn("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
656
+ if (typeof __VERSION__ === "undefined") {
657
+ console.warn(
658
+ "loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN."
659
+ );
563
660
  globalThis._loadersgl_.version = NPM_TAG;
564
661
  } else {
565
- globalThis._loadersgl_.version = "4.2.0-alpha.4";
662
+ globalThis._loadersgl_.version = __VERSION__;
566
663
  }
567
664
  }
568
665
  return globalThis._loadersgl_.version;
@@ -587,7 +684,10 @@ var __exports__ = (() => {
587
684
  var window_ = globals.window || globals.self || globals.global || {};
588
685
  var global_ = globals.global || globals.self || globals.window || {};
589
686
  var document_ = globals.document || {};
590
- var isBrowser = typeof process !== "object" || String(process) !== "[object process]" || process.browser;
687
+ var isBrowser = (
688
+ // @ts-ignore process.browser
689
+ typeof process !== "object" || String(process) !== "[object process]" || process.browser
690
+ );
591
691
  var isWorker = typeof importScripts === "function";
592
692
  var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
593
693
  var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
@@ -600,7 +700,8 @@ var __exports__ = (() => {
600
700
  if (moduleName) {
601
701
  libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
602
702
  }
603
- loadLibraryPromises[libraryUrl] = loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
703
+ loadLibraryPromises[libraryUrl] = // eslint-disable-next-line @typescript-eslint/no-misused-promises
704
+ loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
604
705
  return await loadLibraryPromises[libraryUrl];
605
706
  }
606
707
  function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
@@ -680,9 +781,13 @@ var __exports__ = (() => {
680
781
  var DRACO_ENCODER_VERSION = "1.4.1";
681
782
  var STATIC_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_DECODER_VERSION}`;
682
783
  var DRACO_EXTERNAL_LIBRARIES = {
784
+ /** The primary Draco3D encoder, javascript wrapper part */
683
785
  DECODER: "draco_wasm_wrapper.js",
786
+ /** The primary draco decoder, compiled web assembly part */
684
787
  DECODER_WASM: "draco_decoder.wasm",
788
+ /** Fallback decoder for non-webassebly environments. Very big bundle, lower performance */
685
789
  FALLBACK_DECODER: "draco_decoder.js",
790
+ /** Draco encoder */
686
791
  ENCODER: "draco_encoder.js"
687
792
  };
688
793
  var DRACO_EXTERNAL_LIBRARY_URLS = {
@@ -697,9 +802,7 @@ var __exports__ = (() => {
697
802
  const modules = options.modules || {};
698
803
  if (modules.draco3d) {
699
804
  loadDecoderPromise = loadDecoderPromise || modules.draco3d.createDecoderModule({}).then((draco) => {
700
- return {
701
- draco
702
- };
805
+ return { draco };
703
806
  });
704
807
  } else {
705
808
  loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);
@@ -710,9 +813,7 @@ var __exports__ = (() => {
710
813
  const modules = options.modules || {};
711
814
  if (modules.draco3d) {
712
815
  loadEncoderPromise = loadEncoderPromise || modules.draco3d.createEncoderModule({}).then((draco) => {
713
- return {
714
- draco
715
- };
816
+ return { draco };
716
817
  });
717
818
  } else {
718
819
  loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);
@@ -724,11 +825,29 @@ var __exports__ = (() => {
724
825
  let wasmBinary;
725
826
  switch (options.draco && options.draco.decoderType) {
726
827
  case "js":
727
- DracoDecoderModule = await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER], "draco", options, DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER);
828
+ DracoDecoderModule = await loadLibrary(
829
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER],
830
+ "draco",
831
+ options,
832
+ DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER
833
+ );
728
834
  break;
729
835
  case "wasm":
730
836
  default:
731
- [DracoDecoderModule, wasmBinary] = await Promise.all([await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER], "draco", options, DRACO_EXTERNAL_LIBRARIES.DECODER), await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM], "draco", options, DRACO_EXTERNAL_LIBRARIES.DECODER_WASM)]);
837
+ [DracoDecoderModule, wasmBinary] = await Promise.all([
838
+ await loadLibrary(
839
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER],
840
+ "draco",
841
+ options,
842
+ DRACO_EXTERNAL_LIBRARIES.DECODER
843
+ ),
844
+ await loadLibrary(
845
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM],
846
+ "draco",
847
+ options,
848
+ DRACO_EXTERNAL_LIBRARIES.DECODER_WASM
849
+ )
850
+ ]);
732
851
  }
733
852
  DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;
734
853
  return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);
@@ -741,20 +860,23 @@ var __exports__ = (() => {
741
860
  return new Promise((resolve) => {
742
861
  DracoDecoderModule({
743
862
  ...options,
744
- onModuleLoaded: (draco) => resolve({
745
- draco
746
- })
863
+ onModuleLoaded: (draco) => resolve({ draco })
864
+ // Module is Promise-like. Wrap in object to avoid loop.
747
865
  });
748
866
  });
749
867
  }
750
868
  async function loadDracoEncoder(options) {
751
- let DracoEncoderModule = await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.ENCODER], "draco", options, DRACO_EXTERNAL_LIBRARIES.ENCODER);
869
+ let DracoEncoderModule = await loadLibrary(
870
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.ENCODER],
871
+ "draco",
872
+ options,
873
+ DRACO_EXTERNAL_LIBRARIES.ENCODER
874
+ );
752
875
  DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;
753
876
  return new Promise((resolve) => {
754
877
  DracoEncoderModule({
755
- onModuleLoaded: (draco) => resolve({
756
- draco
757
- })
878
+ onModuleLoaded: (draco) => resolve({ draco })
879
+ // Module is Promise-like. Wrap in object to avoid loop.
758
880
  });
759
881
  });
760
882
  }
@@ -769,6 +891,7 @@ var __exports__ = (() => {
769
891
  var noop = () => {
770
892
  };
771
893
  var DracoBuilder = class {
894
+ // draco - the draco decoder, either import `draco3d` or load dynamically
772
895
  constructor(draco) {
773
896
  this.draco = draco;
774
897
  this.dracoEncoder = new this.draco.Encoder();
@@ -783,21 +906,25 @@ var __exports__ = (() => {
783
906
  this.dracoEncoder = null;
784
907
  this.draco = null;
785
908
  }
909
+ // TBD - when does this need to be called?
786
910
  destroyEncodedObject(object) {
787
911
  if (object) {
788
912
  this.draco.destroy(object);
789
913
  }
790
914
  }
915
+ /**
916
+ * Encode mesh or point cloud
917
+ * @param mesh =({})
918
+ * @param options
919
+ */
791
920
  encodeSync(mesh, options = {}) {
792
921
  this.log = noop;
793
922
  this._setOptions(options);
794
923
  return options.pointcloud ? this._encodePointCloud(mesh, options) : this._encodeMesh(mesh, options);
795
924
  }
925
+ // PRIVATE
796
926
  _getAttributesFromMesh(mesh) {
797
- const attributes = {
798
- ...mesh,
799
- ...mesh.attributes
800
- };
927
+ const attributes = { ...mesh, ...mesh.attributes };
801
928
  if (mesh.indices) {
802
929
  attributes.indices = mesh.indices;
803
930
  }
@@ -812,7 +939,11 @@ var __exports__ = (() => {
812
939
  this._createDracoPointCloud(dracoPointCloud, attributes, options);
813
940
  const dracoData = new this.draco.DracoInt8Array();
814
941
  try {
815
- const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(dracoPointCloud, false, dracoData);
942
+ const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(
943
+ dracoPointCloud,
944
+ false,
945
+ dracoData
946
+ );
816
947
  if (!(encodedLen > 0)) {
817
948
  throw new Error("Draco encoding failed.");
818
949
  }
@@ -845,6 +976,10 @@ var __exports__ = (() => {
845
976
  this.destroyEncodedObject(dracoMesh);
846
977
  }
847
978
  }
979
+ /**
980
+ * Set encoding options.
981
+ * @param {{speed?: any; method?: any; quantization?: any;}} options
982
+ */
848
983
  _setOptions(options) {
849
984
  if ("speed" in options) {
850
985
  this.dracoEncoder.SetSpeedOptions(...options.speed);
@@ -861,6 +996,11 @@ var __exports__ = (() => {
861
996
  }
862
997
  }
863
998
  }
999
+ /**
1000
+ * @param {Mesh} dracoMesh
1001
+ * @param {object} attributes
1002
+ * @returns {Mesh}
1003
+ */
864
1004
  _createDracoMesh(dracoMesh, attributes, options) {
865
1005
  const optionalMetadata = options.attributesMetadata || {};
866
1006
  try {
@@ -886,6 +1026,10 @@ var __exports__ = (() => {
886
1026
  }
887
1027
  return dracoMesh;
888
1028
  }
1029
+ /**
1030
+ * @param {} dracoPointCloud
1031
+ * @param {object} attributes
1032
+ */
889
1033
  _createDracoPointCloud(dracoPointCloud, attributes, options) {
890
1034
  const optionalMetadata = options.attributesMetadata || {};
891
1035
  try {
@@ -897,7 +1041,12 @@ var __exports__ = (() => {
897
1041
  for (let attributeName in attributes) {
898
1042
  const attribute = attributes[attributeName];
899
1043
  attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
900
- const uniqueId = this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);
1044
+ const uniqueId = this._addAttributeToMesh(
1045
+ dracoPointCloud,
1046
+ attributeName,
1047
+ attribute,
1048
+ vertexCount
1049
+ );
901
1050
  if (uniqueId !== -1) {
902
1051
  this._addAttributeMetadata(dracoPointCloud, uniqueId, {
903
1052
  name: attributeName,
@@ -911,6 +1060,12 @@ var __exports__ = (() => {
911
1060
  }
912
1061
  return dracoPointCloud;
913
1062
  }
1063
+ /**
1064
+ * @param mesh
1065
+ * @param attributeName
1066
+ * @param attribute
1067
+ * @param vertexCount
1068
+ */
914
1069
  _addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
915
1070
  if (!ArrayBuffer.isView(attribute)) {
916
1071
  return -1;
@@ -925,9 +1080,7 @@ var __exports__ = (() => {
925
1080
  }
926
1081
  this.log(`Adding attribute ${attributeName}, size ${size}`);
927
1082
  const builder = this.dracoMeshBuilder;
928
- const {
929
- buffer
930
- } = attribute;
1083
+ const { buffer } = attribute;
931
1084
  switch (attribute.constructor) {
932
1085
  case Int8Array:
933
1086
  return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));
@@ -947,6 +1100,11 @@ var __exports__ = (() => {
947
1100
  return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
948
1101
  }
949
1102
  }
1103
+ /**
1104
+ * DRACO can compress attributes of know type better
1105
+ * TODO - expose an attribute type map?
1106
+ * @param attributeName
1107
+ */
950
1108
  _getDracoAttributeType(attributeName) {
951
1109
  switch (attributeName.toLowerCase()) {
952
1110
  case "indices":
@@ -978,16 +1136,36 @@ var __exports__ = (() => {
978
1136
  }
979
1137
  return null;
980
1138
  }
1139
+ /**
1140
+ * Add metadata for the geometry.
1141
+ * @param dracoGeometry - WASM Draco Object
1142
+ * @param metadata
1143
+ */
981
1144
  _addGeometryMetadata(dracoGeometry, metadata) {
982
1145
  const dracoMetadata = new this.draco.Metadata();
983
1146
  this._populateDracoMetadata(dracoMetadata, metadata);
984
1147
  this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
985
1148
  }
1149
+ /**
1150
+ * Add metadata for an attribute to geometry.
1151
+ * @param dracoGeometry - WASM Draco Object
1152
+ * @param uniqueAttributeId
1153
+ * @param metadata
1154
+ */
986
1155
  _addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
987
1156
  const dracoAttributeMetadata = new this.draco.Metadata();
988
1157
  this._populateDracoMetadata(dracoAttributeMetadata, metadata);
989
- this.dracoMeshBuilder.SetMetadataForAttribute(dracoGeometry, uniqueAttributeId, dracoAttributeMetadata);
990
- }
1158
+ this.dracoMeshBuilder.SetMetadataForAttribute(
1159
+ dracoGeometry,
1160
+ uniqueAttributeId,
1161
+ dracoAttributeMetadata
1162
+ );
1163
+ }
1164
+ /**
1165
+ * Add contents of object or map to a WASM Draco Metadata Object
1166
+ * @param dracoMetadata - WASM Draco Object
1167
+ * @param metadata
1168
+ */
991
1169
  _populateDracoMetadata(dracoMetadata, metadata) {
992
1170
  for (const [key, value] of getEntries(metadata)) {
993
1171
  switch (typeof value) {
@@ -1027,7 +1205,14 @@ var __exports__ = (() => {
1027
1205
  // src/draco-writer.ts
1028
1206
  var DEFAULT_DRACO_WRITER_OPTIONS = {
1029
1207
  pointcloud: false,
1208
+ // Set to true if pointcloud (mode: 0, no indices)
1030
1209
  attributeNameEntry: "name"
1210
+ // Draco Compression Parameters
1211
+ // method: 'MESH_EDGEBREAKER_ENCODING', // Use draco defaults
1212
+ // speed: [5, 5], // Use draco defaults
1213
+ // quantization: { // Use draco defaults
1214
+ // POSITION: 10
1215
+ // }
1031
1216
  };
1032
1217
  var DracoWriter = {
1033
1218
  name: "DRACO",
@@ -1041,9 +1226,7 @@ var __exports__ = (() => {
1041
1226
  encode
1042
1227
  };
1043
1228
  async function encode(data, options = {}) {
1044
- const {
1045
- draco
1046
- } = await loadDracoEncoderModule(options);
1229
+ const { draco } = await loadDracoEncoderModule(options);
1047
1230
  const dracoBuilder = new DracoBuilder(draco);
1048
1231
  try {
1049
1232
  return dracoBuilder.encodeSync(data, options.draco);
@@ -1069,9 +1252,7 @@ var __exports__ = (() => {
1069
1252
  parse
1070
1253
  };
1071
1254
  async function parse(arrayBuffer, options) {
1072
- const {
1073
- draco
1074
- } = await loadDracoDecoderModule(options);
1255
+ const { draco } = await loadDracoDecoderModule(options);
1075
1256
  const dracoParser = new DracoParser(draco);
1076
1257
  try {
1077
1258
  return dracoParser.parseSync(arrayBuffer, options?.draco);
@@ -1079,7 +1260,7 @@ var __exports__ = (() => {
1079
1260
  dracoParser.destroy();
1080
1261
  }
1081
1262
  }
1082
- return __toCommonJS(src_exports);
1263
+ return __toCommonJS(bundle_exports);
1083
1264
  })();
1084
1265
  return __exports__;
1085
1266
  });