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

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 (101) hide show
  1. package/dist/dist.dev.js +1245 -0
  2. package/dist/{esm/draco-loader.js → draco-loader.js} +1 -1
  3. package/dist/draco-loader.js.map +1 -0
  4. package/dist/draco-worker-node.js +287 -141
  5. package/dist/draco-worker-node.js.map +4 -4
  6. package/dist/draco-worker.js +1 -1
  7. package/dist/draco-worker.js.map +4 -4
  8. package/dist/draco-writer-worker-node.js +290 -144
  9. package/dist/draco-writer-worker-node.js.map +4 -4
  10. package/dist/draco-writer-worker.js +3 -3
  11. package/dist/draco-writer-worker.js.map +4 -4
  12. package/dist/{esm/draco-writer.js → draco-writer.js} +3 -3
  13. package/dist/draco-writer.js.map +1 -0
  14. package/dist/draco3d/draco3d-types.js.map +1 -0
  15. package/dist/index.cjs +1028 -0
  16. package/dist/{esm/index.js → index.js} +6 -6
  17. package/dist/index.js.map +1 -0
  18. package/dist/{esm/lib → lib}/draco-builder.js +11 -10
  19. package/dist/lib/draco-builder.js.map +1 -0
  20. package/dist/{esm/lib → lib}/draco-module-loader.js +5 -5
  21. package/dist/lib/draco-module-loader.js.map +1 -0
  22. package/dist/{esm/lib → lib}/draco-parser.js +6 -7
  23. package/dist/lib/draco-parser.js.map +1 -0
  24. package/dist/lib/draco-types.js.map +1 -0
  25. package/dist/{esm/lib → lib}/utils/get-draco-schema.js +1 -1
  26. package/dist/lib/utils/get-draco-schema.js.map +1 -0
  27. package/dist/lib/utils/version.js +2 -0
  28. package/dist/lib/utils/version.js.map +1 -0
  29. package/dist/libs/draco_encoder.js +2 -52
  30. package/dist/libs/draco_encoder.js.map +1 -0
  31. package/dist/libs/draco_wasm_wrapper.js +1985 -117
  32. package/dist/libs/draco_wasm_wrapper.js.map +1 -0
  33. package/dist/{esm/workers → workers}/draco-worker-node.js +1 -1
  34. package/dist/workers/draco-worker-node.js.map +1 -0
  35. package/dist/{esm/workers → workers}/draco-worker.js +1 -1
  36. package/dist/workers/draco-worker.js.map +1 -0
  37. package/dist/{esm/workers → workers}/draco-writer-worker-node.js +1 -1
  38. package/dist/workers/draco-writer-worker-node.js.map +1 -0
  39. package/dist/{esm/workers → workers}/draco-writer-worker.js +1 -1
  40. package/dist/workers/draco-writer-worker.js.map +1 -0
  41. package/package.json +18 -10
  42. package/dist/bundle.d.ts +0 -2
  43. package/dist/bundle.d.ts.map +0 -1
  44. package/dist/dist.min.js +0 -4
  45. package/dist/dist.min.js.map +0 -7
  46. package/dist/es5/bundle.js +0 -6
  47. package/dist/es5/bundle.js.map +0 -1
  48. package/dist/es5/draco-loader.js +0 -31
  49. package/dist/es5/draco-loader.js.map +0 -1
  50. package/dist/es5/draco-writer.js +0 -63
  51. package/dist/es5/draco-writer.js.map +0 -1
  52. package/dist/es5/draco3d/draco3d-types.js +0 -51
  53. package/dist/es5/draco3d/draco3d-types.js.map +0 -1
  54. package/dist/es5/index.js +0 -88
  55. package/dist/es5/index.js.map +0 -1
  56. package/dist/es5/lib/draco-builder.js +0 -324
  57. package/dist/es5/lib/draco-builder.js.map +0 -1
  58. package/dist/es5/lib/draco-module-loader.js +0 -190
  59. package/dist/es5/lib/draco-module-loader.js.map +0 -1
  60. package/dist/es5/lib/draco-parser.js +0 -435
  61. package/dist/es5/lib/draco-parser.js.map +0 -1
  62. package/dist/es5/lib/draco-types.js +0 -2
  63. package/dist/es5/lib/draco-types.js.map +0 -1
  64. package/dist/es5/lib/utils/get-draco-schema.js +0 -47
  65. package/dist/es5/lib/utils/get-draco-schema.js.map +0 -1
  66. package/dist/es5/lib/utils/version.js +0 -9
  67. package/dist/es5/lib/utils/version.js.map +0 -1
  68. package/dist/es5/workers/draco-worker-node.js +0 -7
  69. package/dist/es5/workers/draco-worker-node.js.map +0 -1
  70. package/dist/es5/workers/draco-worker.js +0 -6
  71. package/dist/es5/workers/draco-worker.js.map +0 -1
  72. package/dist/es5/workers/draco-writer-worker-node.js +0 -54
  73. package/dist/es5/workers/draco-writer-worker-node.js.map +0 -1
  74. package/dist/es5/workers/draco-writer-worker.js +0 -53
  75. package/dist/es5/workers/draco-writer-worker.js.map +0 -1
  76. package/dist/esm/bundle.js +0 -4
  77. package/dist/esm/bundle.js.map +0 -1
  78. package/dist/esm/draco-loader.js.map +0 -1
  79. package/dist/esm/draco-writer.js.map +0 -1
  80. package/dist/esm/draco3d/draco3d-types.js.map +0 -1
  81. package/dist/esm/index.js.map +0 -1
  82. package/dist/esm/lib/draco-builder.js.map +0 -1
  83. package/dist/esm/lib/draco-module-loader.js.map +0 -1
  84. package/dist/esm/lib/draco-parser.js.map +0 -1
  85. package/dist/esm/lib/draco-types.js.map +0 -1
  86. package/dist/esm/lib/utils/get-draco-schema.js.map +0 -1
  87. package/dist/esm/lib/utils/version.js +0 -2
  88. package/dist/esm/lib/utils/version.js.map +0 -1
  89. package/dist/esm/libs/draco_decoder.wasm +0 -0
  90. package/dist/esm/libs/draco_encoder.js +0 -52
  91. package/dist/esm/libs/draco_wasm_wrapper.js +0 -117
  92. package/dist/esm/workers/draco-worker-node.js.map +0 -1
  93. package/dist/esm/workers/draco-worker.js.map +0 -1
  94. package/dist/esm/workers/draco-writer-worker-node.js.map +0 -1
  95. package/dist/esm/workers/draco-writer-worker.js.map +0 -1
  96. package/src/bundle.ts +0 -4
  97. /package/dist/{esm/draco3d → draco3d}/draco3d-types.js +0 -0
  98. /package/dist/{esm/lib → lib}/draco-types.js +0 -0
  99. /package/dist/{es5 → libs}/libs/draco_decoder.wasm +0 -0
  100. /package/dist/{es5 → libs}/libs/draco_encoder.js +0 -0
  101. /package/dist/{es5 → libs}/libs/draco_wasm_wrapper.js +0 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,1028 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ DRACO_EXTERNAL_LIBRARIES: () => DRACO_EXTERNAL_LIBRARIES,
24
+ DRACO_EXTERNAL_LIBRARY_URLS: () => DRACO_EXTERNAL_LIBRARY_URLS,
25
+ DracoLoader: () => DracoLoader2,
26
+ DracoWorkerLoader: () => DracoLoader,
27
+ DracoWriter: () => DracoWriter,
28
+ DracoWriterWorker: () => DracoWriterWorker
29
+ });
30
+ module.exports = __toCommonJS(src_exports);
31
+
32
+ // src/lib/utils/version.ts
33
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
34
+
35
+ // src/draco-loader.ts
36
+ var DEFAULT_DRACO_OPTIONS = {
37
+ draco: {
38
+ decoderType: typeof WebAssembly === "object" ? "wasm" : "js",
39
+ // 'js' for IE11
40
+ libraryPath: "libs/",
41
+ extraAttributes: {},
42
+ attributeNameEntry: void 0
43
+ }
44
+ };
45
+ var DracoLoader = {
46
+ name: "Draco",
47
+ id: "draco",
48
+ module: "draco",
49
+ // shapes: ['mesh'],
50
+ version: VERSION,
51
+ worker: true,
52
+ extensions: ["drc"],
53
+ mimeTypes: ["application/octet-stream"],
54
+ binary: true,
55
+ tests: ["DRACO"],
56
+ options: DEFAULT_DRACO_OPTIONS
57
+ };
58
+
59
+ // src/lib/draco-parser.ts
60
+ var import_schema2 = require("@loaders.gl/schema");
61
+
62
+ // src/lib/utils/get-draco-schema.ts
63
+ var import_schema = require("@loaders.gl/schema");
64
+ function getDracoSchema(attributes, loaderData, indices) {
65
+ const metadata = makeMetadata(loaderData.metadata);
66
+ const fields = [];
67
+ const namedLoaderDataAttributes = transformAttributesLoaderData(loaderData.attributes);
68
+ for (const attributeName in attributes) {
69
+ const attribute = attributes[attributeName];
70
+ const field = getArrowFieldFromAttribute(
71
+ attributeName,
72
+ attribute,
73
+ namedLoaderDataAttributes[attributeName]
74
+ );
75
+ fields.push(field);
76
+ }
77
+ if (indices) {
78
+ const indicesField = getArrowFieldFromAttribute("indices", indices);
79
+ fields.push(indicesField);
80
+ }
81
+ return { fields, metadata };
82
+ }
83
+ function transformAttributesLoaderData(loaderData) {
84
+ const result = {};
85
+ for (const key in loaderData) {
86
+ const dracoAttribute = loaderData[key];
87
+ result[dracoAttribute.name || "undefined"] = dracoAttribute;
88
+ }
89
+ return result;
90
+ }
91
+ function getArrowFieldFromAttribute(attributeName, attribute, loaderData) {
92
+ const metadataMap = loaderData ? makeMetadata(loaderData.metadata) : void 0;
93
+ const field = (0, import_schema.deduceMeshField)(attributeName, attribute, metadataMap);
94
+ return field;
95
+ }
96
+ function makeMetadata(metadata) {
97
+ Object.entries(metadata);
98
+ const serializedMetadata = {};
99
+ for (const key in metadata) {
100
+ serializedMetadata[`${key}.string`] = JSON.stringify(metadata[key]);
101
+ }
102
+ return serializedMetadata;
103
+ }
104
+
105
+ // src/lib/draco-parser.ts
106
+ var DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {
107
+ POSITION: "POSITION",
108
+ NORMAL: "NORMAL",
109
+ COLOR: "COLOR_0",
110
+ TEX_COORD: "TEXCOORD_0"
111
+ };
112
+ var DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
113
+ 1: Int8Array,
114
+ 2: Uint8Array,
115
+ 3: Int16Array,
116
+ 4: Uint16Array,
117
+ 5: Int32Array,
118
+ 6: Uint32Array,
119
+ 9: Float32Array
120
+ };
121
+ var INDEX_ITEM_SIZE = 4;
122
+ var DracoParser = class {
123
+ // draco - the draco decoder, either import `draco3d` or load dynamically
124
+ constructor(draco) {
125
+ this.draco = draco;
126
+ this.decoder = new this.draco.Decoder();
127
+ this.metadataQuerier = new this.draco.MetadataQuerier();
128
+ }
129
+ /**
130
+ * Destroy draco resources
131
+ */
132
+ destroy() {
133
+ this.draco.destroy(this.decoder);
134
+ this.draco.destroy(this.metadataQuerier);
135
+ }
136
+ /**
137
+ * NOTE: caller must call `destroyGeometry` on the return value after using it
138
+ * @param arrayBuffer
139
+ * @param options
140
+ */
141
+ parseSync(arrayBuffer, options = {}) {
142
+ const buffer = new this.draco.DecoderBuffer();
143
+ buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
144
+ this._disableAttributeTransforms(options);
145
+ const geometry_type = this.decoder.GetEncodedGeometryType(buffer);
146
+ const dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
147
+ try {
148
+ let dracoStatus;
149
+ switch (geometry_type) {
150
+ case this.draco.TRIANGULAR_MESH:
151
+ dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
152
+ break;
153
+ case this.draco.POINT_CLOUD:
154
+ dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
155
+ break;
156
+ default:
157
+ throw new Error("DRACO: Unknown geometry type.");
158
+ }
159
+ if (!dracoStatus.ok() || !dracoGeometry.ptr) {
160
+ const message = `DRACO decompression failed: ${dracoStatus.error_msg()}`;
161
+ throw new Error(message);
162
+ }
163
+ const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);
164
+ const geometry = this._getMeshData(dracoGeometry, loaderData, options);
165
+ const boundingBox = (0, import_schema2.getMeshBoundingBox)(geometry.attributes);
166
+ const schema = getDracoSchema(geometry.attributes, loaderData, geometry.indices);
167
+ const data = {
168
+ loader: "draco",
169
+ loaderData,
170
+ header: {
171
+ vertexCount: dracoGeometry.num_points(),
172
+ boundingBox
173
+ },
174
+ ...geometry,
175
+ schema
176
+ };
177
+ return data;
178
+ } finally {
179
+ this.draco.destroy(buffer);
180
+ if (dracoGeometry) {
181
+ this.draco.destroy(dracoGeometry);
182
+ }
183
+ }
184
+ }
185
+ // Draco specific "loader data"
186
+ /**
187
+ * Extract
188
+ * @param dracoGeometry
189
+ * @param geometry_type
190
+ * @param options
191
+ * @returns
192
+ */
193
+ _getDracoLoaderData(dracoGeometry, geometry_type, options) {
194
+ const metadata = this._getTopLevelMetadata(dracoGeometry);
195
+ const attributes = this._getDracoAttributes(dracoGeometry, options);
196
+ return {
197
+ geometry_type,
198
+ num_attributes: dracoGeometry.num_attributes(),
199
+ num_points: dracoGeometry.num_points(),
200
+ num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
201
+ metadata,
202
+ attributes
203
+ };
204
+ }
205
+ /**
206
+ * Extract all draco provided information and metadata for each attribute
207
+ * @param dracoGeometry
208
+ * @param options
209
+ * @returns
210
+ */
211
+ _getDracoAttributes(dracoGeometry, options) {
212
+ const dracoAttributes = {};
213
+ for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
214
+ const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
215
+ const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
216
+ dracoAttributes[dracoAttribute.unique_id()] = {
217
+ unique_id: dracoAttribute.unique_id(),
218
+ attribute_type: dracoAttribute.attribute_type(),
219
+ data_type: dracoAttribute.data_type(),
220
+ num_components: dracoAttribute.num_components(),
221
+ byte_offset: dracoAttribute.byte_offset(),
222
+ byte_stride: dracoAttribute.byte_stride(),
223
+ normalized: dracoAttribute.normalized(),
224
+ attribute_index: attributeId,
225
+ metadata
226
+ };
227
+ const quantization = this._getQuantizationTransform(dracoAttribute, options);
228
+ if (quantization) {
229
+ dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
230
+ }
231
+ const octahedron = this._getOctahedronTransform(dracoAttribute, options);
232
+ if (octahedron) {
233
+ dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
234
+ }
235
+ }
236
+ return dracoAttributes;
237
+ }
238
+ /**
239
+ * Get standard loaders.gl mesh category data
240
+ * Extracts the geometry from draco
241
+ * @param dracoGeometry
242
+ * @param options
243
+ */
244
+ _getMeshData(dracoGeometry, loaderData, options) {
245
+ const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
246
+ const positionAttribute = attributes.POSITION;
247
+ if (!positionAttribute) {
248
+ throw new Error("DRACO: No position attribute found.");
249
+ }
250
+ if (dracoGeometry instanceof this.draco.Mesh) {
251
+ switch (options.topology) {
252
+ case "triangle-strip":
253
+ return {
254
+ topology: "triangle-strip",
255
+ mode: 4,
256
+ // GL.TRIANGLES
257
+ attributes,
258
+ indices: {
259
+ value: this._getTriangleStripIndices(dracoGeometry),
260
+ size: 1
261
+ }
262
+ };
263
+ case "triangle-list":
264
+ default:
265
+ return {
266
+ topology: "triangle-list",
267
+ mode: 5,
268
+ // GL.TRIANGLE_STRIP
269
+ attributes,
270
+ indices: {
271
+ value: this._getTriangleListIndices(dracoGeometry),
272
+ size: 1
273
+ }
274
+ };
275
+ }
276
+ }
277
+ return {
278
+ topology: "point-list",
279
+ mode: 0,
280
+ // GL.POINTS
281
+ attributes
282
+ };
283
+ }
284
+ _getMeshAttributes(loaderData, dracoGeometry, options) {
285
+ const attributes = {};
286
+ for (const loaderAttribute of Object.values(loaderData.attributes)) {
287
+ const attributeName = this._deduceAttributeName(loaderAttribute, options);
288
+ loaderAttribute.name = attributeName;
289
+ const { value, size } = this._getAttributeValues(dracoGeometry, loaderAttribute);
290
+ attributes[attributeName] = {
291
+ value,
292
+ size,
293
+ byteOffset: loaderAttribute.byte_offset,
294
+ byteStride: loaderAttribute.byte_stride,
295
+ normalized: loaderAttribute.normalized
296
+ };
297
+ }
298
+ return attributes;
299
+ }
300
+ // MESH INDICES EXTRACTION
301
+ /**
302
+ * For meshes, we need indices to define the faces.
303
+ * @param dracoGeometry
304
+ */
305
+ _getTriangleListIndices(dracoGeometry) {
306
+ const numFaces = dracoGeometry.num_faces();
307
+ const numIndices = numFaces * 3;
308
+ const byteLength = numIndices * INDEX_ITEM_SIZE;
309
+ const ptr = this.draco._malloc(byteLength);
310
+ try {
311
+ this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
312
+ return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
313
+ } finally {
314
+ this.draco._free(ptr);
315
+ }
316
+ }
317
+ /**
318
+ * For meshes, we need indices to define the faces.
319
+ * @param dracoGeometry
320
+ */
321
+ _getTriangleStripIndices(dracoGeometry) {
322
+ const dracoArray = new this.draco.DracoInt32Array();
323
+ try {
324
+ this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);
325
+ return getUint32Array(dracoArray);
326
+ } finally {
327
+ this.draco.destroy(dracoArray);
328
+ }
329
+ }
330
+ /**
331
+ *
332
+ * @param dracoGeometry
333
+ * @param dracoAttribute
334
+ * @param attributeName
335
+ */
336
+ _getAttributeValues(dracoGeometry, attribute) {
337
+ const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
338
+ const numComponents = attribute.num_components;
339
+ const numPoints = dracoGeometry.num_points();
340
+ const numValues = numPoints * numComponents;
341
+ const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;
342
+ const dataType = getDracoDataType(this.draco, TypedArrayCtor);
343
+ let value;
344
+ const ptr = this.draco._malloc(byteLength);
345
+ try {
346
+ const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
347
+ this.decoder.GetAttributeDataArrayForAllPoints(
348
+ dracoGeometry,
349
+ dracoAttribute,
350
+ dataType,
351
+ byteLength,
352
+ ptr
353
+ );
354
+ value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
355
+ } finally {
356
+ this.draco._free(ptr);
357
+ }
358
+ return { value, size: numComponents };
359
+ }
360
+ // Attribute names
361
+ /**
362
+ * DRACO does not store attribute names - We need to deduce an attribute name
363
+ * for each attribute
364
+ _getAttributeNames(
365
+ dracoGeometry: Mesh | PointCloud,
366
+ options: DracoParseOptions
367
+ ): {[unique_id: number]: string} {
368
+ const attributeNames: {[unique_id: number]: string} = {};
369
+ for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
370
+ const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
371
+ const attributeName = this._deduceAttributeName(dracoAttribute, options);
372
+ attributeNames[attributeName] = attributeName;
373
+ }
374
+ return attributeNames;
375
+ }
376
+ */
377
+ /**
378
+ * Deduce an attribute name.
379
+ * @note DRACO does not save attribute names, just general type (POSITION, COLOR)
380
+ * to help optimize compression. We generate GLTF compatible names for the Draco-recognized
381
+ * types
382
+ * @param attributeData
383
+ */
384
+ _deduceAttributeName(attribute, options) {
385
+ const uniqueId = attribute.unique_id;
386
+ for (const [attributeName, attributeUniqueId] of Object.entries(
387
+ options.extraAttributes || {}
388
+ )) {
389
+ if (attributeUniqueId === uniqueId) {
390
+ return attributeName;
391
+ }
392
+ }
393
+ const thisAttributeType = attribute.attribute_type;
394
+ for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
395
+ const attributeType = this.draco[dracoAttributeConstant];
396
+ if (attributeType === thisAttributeType) {
397
+ return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
398
+ }
399
+ }
400
+ const entryName = options.attributeNameEntry || "name";
401
+ if (attribute.metadata[entryName]) {
402
+ return attribute.metadata[entryName].string;
403
+ }
404
+ return `CUSTOM_ATTRIBUTE_${uniqueId}`;
405
+ }
406
+ // METADATA EXTRACTION
407
+ /** Get top level metadata */
408
+ _getTopLevelMetadata(dracoGeometry) {
409
+ const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
410
+ return this._getDracoMetadata(dracoMetadata);
411
+ }
412
+ /** Get per attribute metadata */
413
+ _getAttributeMetadata(dracoGeometry, attributeId) {
414
+ const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
415
+ return this._getDracoMetadata(dracoMetadata);
416
+ }
417
+ /**
418
+ * Extract metadata field values
419
+ * @param dracoMetadata
420
+ * @returns
421
+ */
422
+ _getDracoMetadata(dracoMetadata) {
423
+ if (!dracoMetadata || !dracoMetadata.ptr) {
424
+ return {};
425
+ }
426
+ const result = {};
427
+ const numEntries = this.metadataQuerier.NumEntries(dracoMetadata);
428
+ for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) {
429
+ const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
430
+ result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
431
+ }
432
+ return result;
433
+ }
434
+ /**
435
+ * Extracts possible values for one metadata entry by name
436
+ * @param dracoMetadata
437
+ * @param entryName
438
+ */
439
+ _getDracoMetadataField(dracoMetadata, entryName) {
440
+ const dracoArray = new this.draco.DracoInt32Array();
441
+ try {
442
+ this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);
443
+ const intArray = getInt32Array(dracoArray);
444
+ return {
445
+ int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
446
+ string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
447
+ double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
448
+ intArray
449
+ };
450
+ } finally {
451
+ this.draco.destroy(dracoArray);
452
+ }
453
+ }
454
+ // QUANTIZED ATTRIBUTE SUPPORT (NO DECOMPRESSION)
455
+ /** Skip transforms for specific attribute types */
456
+ _disableAttributeTransforms(options) {
457
+ const { quantizedAttributes = [], octahedronAttributes = [] } = options;
458
+ const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];
459
+ for (const dracoAttributeName of skipAttributes) {
460
+ this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
461
+ }
462
+ }
463
+ /**
464
+ * Extract (and apply?) Position Transform
465
+ * @todo not used
466
+ */
467
+ _getQuantizationTransform(dracoAttribute, options) {
468
+ const { quantizedAttributes = [] } = options;
469
+ const attribute_type = dracoAttribute.attribute_type();
470
+ const skip = quantizedAttributes.map((type) => this.decoder[type]).includes(attribute_type);
471
+ if (skip) {
472
+ const transform = new this.draco.AttributeQuantizationTransform();
473
+ try {
474
+ if (transform.InitFromAttribute(dracoAttribute)) {
475
+ return {
476
+ quantization_bits: transform.quantization_bits(),
477
+ range: transform.range(),
478
+ min_values: new Float32Array([1, 2, 3]).map((i) => transform.min_value(i))
479
+ };
480
+ }
481
+ } finally {
482
+ this.draco.destroy(transform);
483
+ }
484
+ }
485
+ return null;
486
+ }
487
+ _getOctahedronTransform(dracoAttribute, options) {
488
+ const { octahedronAttributes = [] } = options;
489
+ const attribute_type = dracoAttribute.attribute_type();
490
+ const octahedron = octahedronAttributes.map((type) => this.decoder[type]).includes(attribute_type);
491
+ if (octahedron) {
492
+ const transform = new this.draco.AttributeQuantizationTransform();
493
+ try {
494
+ if (transform.InitFromAttribute(dracoAttribute)) {
495
+ return {
496
+ quantization_bits: transform.quantization_bits()
497
+ };
498
+ }
499
+ } finally {
500
+ this.draco.destroy(transform);
501
+ }
502
+ }
503
+ return null;
504
+ }
505
+ // HELPERS
506
+ };
507
+ function getDracoDataType(draco, attributeType) {
508
+ switch (attributeType) {
509
+ case Float32Array:
510
+ return draco.DT_FLOAT32;
511
+ case Int8Array:
512
+ return draco.DT_INT8;
513
+ case Int16Array:
514
+ return draco.DT_INT16;
515
+ case Int32Array:
516
+ return draco.DT_INT32;
517
+ case Uint8Array:
518
+ return draco.DT_UINT8;
519
+ case Uint16Array:
520
+ return draco.DT_UINT16;
521
+ case Uint32Array:
522
+ return draco.DT_UINT32;
523
+ default:
524
+ return draco.DT_INVALID;
525
+ }
526
+ }
527
+ function getInt32Array(dracoArray) {
528
+ const numValues = dracoArray.size();
529
+ const intArray = new Int32Array(numValues);
530
+ for (let i = 0; i < numValues; i++) {
531
+ intArray[i] = dracoArray.GetValue(i);
532
+ }
533
+ return intArray;
534
+ }
535
+ function getUint32Array(dracoArray) {
536
+ const numValues = dracoArray.size();
537
+ const intArray = new Int32Array(numValues);
538
+ for (let i = 0; i < numValues; i++) {
539
+ intArray[i] = dracoArray.GetValue(i);
540
+ }
541
+ return intArray;
542
+ }
543
+
544
+ // src/lib/draco-module-loader.ts
545
+ var import_worker_utils = require("@loaders.gl/worker-utils");
546
+ var DRACO_DECODER_VERSION = "1.5.6";
547
+ var DRACO_ENCODER_VERSION = "1.4.1";
548
+ var STATIC_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_DECODER_VERSION}`;
549
+ var DRACO_EXTERNAL_LIBRARIES = {
550
+ /** The primary Draco3D encoder, javascript wrapper part */
551
+ DECODER: "draco_wasm_wrapper.js",
552
+ /** The primary draco decoder, compiled web assembly part */
553
+ DECODER_WASM: "draco_decoder.wasm",
554
+ /** Fallback decoder for non-webassebly environments. Very big bundle, lower performance */
555
+ FALLBACK_DECODER: "draco_decoder.js",
556
+ /** Draco encoder */
557
+ ENCODER: "draco_encoder.js"
558
+ };
559
+ var DRACO_EXTERNAL_LIBRARY_URLS = {
560
+ [DRACO_EXTERNAL_LIBRARIES.DECODER]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.DECODER}`,
561
+ [DRACO_EXTERNAL_LIBRARIES.DECODER_WASM]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.DECODER_WASM}`,
562
+ [DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER}`,
563
+ [DRACO_EXTERNAL_LIBRARIES.ENCODER]: `https://raw.githubusercontent.com/google/draco/${DRACO_ENCODER_VERSION}/javascript/${DRACO_EXTERNAL_LIBRARIES.ENCODER}`
564
+ };
565
+ var loadDecoderPromise;
566
+ var loadEncoderPromise;
567
+ async function loadDracoDecoderModule(options) {
568
+ const modules = options.modules || {};
569
+ if (modules.draco3d) {
570
+ loadDecoderPromise = loadDecoderPromise || modules.draco3d.createDecoderModule({}).then((draco) => {
571
+ return { draco };
572
+ });
573
+ } else {
574
+ loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);
575
+ }
576
+ return await loadDecoderPromise;
577
+ }
578
+ async function loadDracoEncoderModule(options) {
579
+ const modules = options.modules || {};
580
+ if (modules.draco3d) {
581
+ loadEncoderPromise = loadEncoderPromise || modules.draco3d.createEncoderModule({}).then((draco) => {
582
+ return { draco };
583
+ });
584
+ } else {
585
+ loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);
586
+ }
587
+ return await loadEncoderPromise;
588
+ }
589
+ async function loadDracoDecoder(options) {
590
+ let DracoDecoderModule;
591
+ let wasmBinary;
592
+ switch (options.draco && options.draco.decoderType) {
593
+ case "js":
594
+ DracoDecoderModule = await (0, import_worker_utils.loadLibrary)(
595
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER],
596
+ "draco",
597
+ options,
598
+ DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER
599
+ );
600
+ break;
601
+ case "wasm":
602
+ default:
603
+ [DracoDecoderModule, wasmBinary] = await Promise.all([
604
+ await (0, import_worker_utils.loadLibrary)(
605
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER],
606
+ "draco",
607
+ options,
608
+ DRACO_EXTERNAL_LIBRARIES.DECODER
609
+ ),
610
+ await (0, import_worker_utils.loadLibrary)(
611
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM],
612
+ "draco",
613
+ options,
614
+ DRACO_EXTERNAL_LIBRARIES.DECODER_WASM
615
+ )
616
+ ]);
617
+ }
618
+ DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;
619
+ return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);
620
+ }
621
+ function initializeDracoDecoder(DracoDecoderModule, wasmBinary) {
622
+ const options = {};
623
+ if (wasmBinary) {
624
+ options.wasmBinary = wasmBinary;
625
+ }
626
+ return new Promise((resolve) => {
627
+ DracoDecoderModule({
628
+ ...options,
629
+ onModuleLoaded: (draco) => resolve({ draco })
630
+ // Module is Promise-like. Wrap in object to avoid loop.
631
+ });
632
+ });
633
+ }
634
+ async function loadDracoEncoder(options) {
635
+ let DracoEncoderModule = await (0, import_worker_utils.loadLibrary)(
636
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.ENCODER],
637
+ "draco",
638
+ options,
639
+ DRACO_EXTERNAL_LIBRARIES.ENCODER
640
+ );
641
+ DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;
642
+ return new Promise((resolve) => {
643
+ DracoEncoderModule({
644
+ onModuleLoaded: (draco) => resolve({ draco })
645
+ // Module is Promise-like. Wrap in object to avoid loop.
646
+ });
647
+ });
648
+ }
649
+
650
+ // src/lib/draco-builder.ts
651
+ var GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
652
+ POSITION: "POSITION",
653
+ NORMAL: "NORMAL",
654
+ COLOR_0: "COLOR",
655
+ TEXCOORD_0: "TEX_COORD"
656
+ };
657
+ var noop = () => {
658
+ };
659
+ var DracoBuilder = class {
660
+ // draco - the draco decoder, either import `draco3d` or load dynamically
661
+ constructor(draco) {
662
+ this.draco = draco;
663
+ this.dracoEncoder = new this.draco.Encoder();
664
+ this.dracoMeshBuilder = new this.draco.MeshBuilder();
665
+ this.dracoMetadataBuilder = new this.draco.MetadataBuilder();
666
+ }
667
+ destroy() {
668
+ this.destroyEncodedObject(this.dracoMeshBuilder);
669
+ this.destroyEncodedObject(this.dracoEncoder);
670
+ this.destroyEncodedObject(this.dracoMetadataBuilder);
671
+ this.dracoMeshBuilder = null;
672
+ this.dracoEncoder = null;
673
+ this.draco = null;
674
+ }
675
+ // TBD - when does this need to be called?
676
+ destroyEncodedObject(object) {
677
+ if (object) {
678
+ this.draco.destroy(object);
679
+ }
680
+ }
681
+ /**
682
+ * Encode mesh or point cloud
683
+ * @param mesh =({})
684
+ * @param options
685
+ */
686
+ encodeSync(mesh, options = {}) {
687
+ this.log = noop;
688
+ this._setOptions(options);
689
+ return options.pointcloud ? this._encodePointCloud(mesh, options) : this._encodeMesh(mesh, options);
690
+ }
691
+ // PRIVATE
692
+ _getAttributesFromMesh(mesh) {
693
+ const attributes = { ...mesh, ...mesh.attributes };
694
+ if (mesh.indices) {
695
+ attributes.indices = mesh.indices;
696
+ }
697
+ return attributes;
698
+ }
699
+ _encodePointCloud(pointcloud, options) {
700
+ const dracoPointCloud = new this.draco.PointCloud();
701
+ if (options.metadata) {
702
+ this._addGeometryMetadata(dracoPointCloud, options.metadata);
703
+ }
704
+ const attributes = this._getAttributesFromMesh(pointcloud);
705
+ this._createDracoPointCloud(dracoPointCloud, attributes, options);
706
+ const dracoData = new this.draco.DracoInt8Array();
707
+ try {
708
+ const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(
709
+ dracoPointCloud,
710
+ false,
711
+ dracoData
712
+ );
713
+ if (!(encodedLen > 0)) {
714
+ throw new Error("Draco encoding failed.");
715
+ }
716
+ this.log(`DRACO encoded ${dracoPointCloud.num_points()} points
717
+ with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);
718
+ return dracoInt8ArrayToArrayBuffer(dracoData);
719
+ } finally {
720
+ this.destroyEncodedObject(dracoData);
721
+ this.destroyEncodedObject(dracoPointCloud);
722
+ }
723
+ }
724
+ _encodeMesh(mesh, options) {
725
+ const dracoMesh = new this.draco.Mesh();
726
+ if (options.metadata) {
727
+ this._addGeometryMetadata(dracoMesh, options.metadata);
728
+ }
729
+ const attributes = this._getAttributesFromMesh(mesh);
730
+ this._createDracoMesh(dracoMesh, attributes, options);
731
+ const dracoData = new this.draco.DracoInt8Array();
732
+ try {
733
+ const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);
734
+ if (encodedLen <= 0) {
735
+ throw new Error("Draco encoding failed.");
736
+ }
737
+ this.log(`DRACO encoded ${dracoMesh.num_points()} points
738
+ with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);
739
+ return dracoInt8ArrayToArrayBuffer(dracoData);
740
+ } finally {
741
+ this.destroyEncodedObject(dracoData);
742
+ this.destroyEncodedObject(dracoMesh);
743
+ }
744
+ }
745
+ /**
746
+ * Set encoding options.
747
+ * @param {{speed?: any; method?: any; quantization?: any;}} options
748
+ */
749
+ _setOptions(options) {
750
+ if ("speed" in options) {
751
+ this.dracoEncoder.SetSpeedOptions(...options.speed);
752
+ }
753
+ if ("method" in options) {
754
+ const dracoMethod = this.draco[options.method || "MESH_SEQUENTIAL_ENCODING"];
755
+ this.dracoEncoder.SetEncodingMethod(dracoMethod);
756
+ }
757
+ if ("quantization" in options) {
758
+ for (const attribute in options.quantization) {
759
+ const bits = options.quantization[attribute];
760
+ const dracoPosition = this.draco[attribute];
761
+ this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);
762
+ }
763
+ }
764
+ }
765
+ /**
766
+ * @param {Mesh} dracoMesh
767
+ * @param {object} attributes
768
+ * @returns {Mesh}
769
+ */
770
+ _createDracoMesh(dracoMesh, attributes, options) {
771
+ const optionalMetadata = options.attributesMetadata || {};
772
+ try {
773
+ const positions = this._getPositionAttribute(attributes);
774
+ if (!positions) {
775
+ throw new Error("positions");
776
+ }
777
+ const vertexCount = positions.length / 3;
778
+ for (let attributeName in attributes) {
779
+ const attribute = attributes[attributeName];
780
+ attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
781
+ const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);
782
+ if (uniqueId !== -1) {
783
+ this._addAttributeMetadata(dracoMesh, uniqueId, {
784
+ name: attributeName,
785
+ ...optionalMetadata[attributeName] || {}
786
+ });
787
+ }
788
+ }
789
+ } catch (error) {
790
+ this.destroyEncodedObject(dracoMesh);
791
+ throw error;
792
+ }
793
+ return dracoMesh;
794
+ }
795
+ /**
796
+ * @param {} dracoPointCloud
797
+ * @param {object} attributes
798
+ */
799
+ _createDracoPointCloud(dracoPointCloud, attributes, options) {
800
+ const optionalMetadata = options.attributesMetadata || {};
801
+ try {
802
+ const positions = this._getPositionAttribute(attributes);
803
+ if (!positions) {
804
+ throw new Error("positions");
805
+ }
806
+ const vertexCount = positions.length / 3;
807
+ for (let attributeName in attributes) {
808
+ const attribute = attributes[attributeName];
809
+ attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
810
+ const uniqueId = this._addAttributeToMesh(
811
+ dracoPointCloud,
812
+ attributeName,
813
+ attribute,
814
+ vertexCount
815
+ );
816
+ if (uniqueId !== -1) {
817
+ this._addAttributeMetadata(dracoPointCloud, uniqueId, {
818
+ name: attributeName,
819
+ ...optionalMetadata[attributeName] || {}
820
+ });
821
+ }
822
+ }
823
+ } catch (error) {
824
+ this.destroyEncodedObject(dracoPointCloud);
825
+ throw error;
826
+ }
827
+ return dracoPointCloud;
828
+ }
829
+ /**
830
+ * @param mesh
831
+ * @param attributeName
832
+ * @param attribute
833
+ * @param vertexCount
834
+ */
835
+ _addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
836
+ if (!ArrayBuffer.isView(attribute)) {
837
+ return -1;
838
+ }
839
+ const type = this._getDracoAttributeType(attributeName);
840
+ const size = attribute.length / vertexCount;
841
+ if (type === "indices") {
842
+ const numFaces = attribute.length / 3;
843
+ this.log(`Adding attribute ${attributeName}, size ${numFaces}`);
844
+ this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);
845
+ return -1;
846
+ }
847
+ this.log(`Adding attribute ${attributeName}, size ${size}`);
848
+ const builder = this.dracoMeshBuilder;
849
+ const { buffer } = attribute;
850
+ switch (attribute.constructor) {
851
+ case Int8Array:
852
+ return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));
853
+ case Int16Array:
854
+ return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));
855
+ case Int32Array:
856
+ return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));
857
+ case Uint8Array:
858
+ case Uint8ClampedArray:
859
+ return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));
860
+ case Uint16Array:
861
+ return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));
862
+ case Uint32Array:
863
+ return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));
864
+ case Float32Array:
865
+ default:
866
+ return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
867
+ }
868
+ }
869
+ /**
870
+ * DRACO can compress attributes of know type better
871
+ * TODO - expose an attribute type map?
872
+ * @param attributeName
873
+ */
874
+ _getDracoAttributeType(attributeName) {
875
+ switch (attributeName.toLowerCase()) {
876
+ case "indices":
877
+ return "indices";
878
+ case "position":
879
+ case "positions":
880
+ case "vertices":
881
+ return this.draco.POSITION;
882
+ case "normal":
883
+ case "normals":
884
+ return this.draco.NORMAL;
885
+ case "color":
886
+ case "colors":
887
+ return this.draco.COLOR;
888
+ case "texcoord":
889
+ case "texcoords":
890
+ return this.draco.TEX_COORD;
891
+ default:
892
+ return this.draco.GENERIC;
893
+ }
894
+ }
895
+ _getPositionAttribute(attributes) {
896
+ for (const attributeName in attributes) {
897
+ const attribute = attributes[attributeName];
898
+ const dracoType = this._getDracoAttributeType(attributeName);
899
+ if (dracoType === this.draco.POSITION) {
900
+ return attribute;
901
+ }
902
+ }
903
+ return null;
904
+ }
905
+ /**
906
+ * Add metadata for the geometry.
907
+ * @param dracoGeometry - WASM Draco Object
908
+ * @param metadata
909
+ */
910
+ _addGeometryMetadata(dracoGeometry, metadata) {
911
+ const dracoMetadata = new this.draco.Metadata();
912
+ this._populateDracoMetadata(dracoMetadata, metadata);
913
+ this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
914
+ }
915
+ /**
916
+ * Add metadata for an attribute to geometry.
917
+ * @param dracoGeometry - WASM Draco Object
918
+ * @param uniqueAttributeId
919
+ * @param metadata
920
+ */
921
+ _addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
922
+ const dracoAttributeMetadata = new this.draco.Metadata();
923
+ this._populateDracoMetadata(dracoAttributeMetadata, metadata);
924
+ this.dracoMeshBuilder.SetMetadataForAttribute(
925
+ dracoGeometry,
926
+ uniqueAttributeId,
927
+ dracoAttributeMetadata
928
+ );
929
+ }
930
+ /**
931
+ * Add contents of object or map to a WASM Draco Metadata Object
932
+ * @param dracoMetadata - WASM Draco Object
933
+ * @param metadata
934
+ */
935
+ _populateDracoMetadata(dracoMetadata, metadata) {
936
+ for (const [key, value] of getEntries(metadata)) {
937
+ switch (typeof value) {
938
+ case "number":
939
+ if (Math.trunc(value) === value) {
940
+ this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);
941
+ } else {
942
+ this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);
943
+ }
944
+ break;
945
+ case "object":
946
+ if (value instanceof Int32Array) {
947
+ this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);
948
+ }
949
+ break;
950
+ case "string":
951
+ default:
952
+ this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);
953
+ }
954
+ }
955
+ }
956
+ };
957
+ function dracoInt8ArrayToArrayBuffer(dracoData) {
958
+ const byteLength = dracoData.size();
959
+ const outputBuffer = new ArrayBuffer(byteLength);
960
+ const outputData = new Int8Array(outputBuffer);
961
+ for (let i = 0; i < byteLength; ++i) {
962
+ outputData[i] = dracoData.GetValue(i);
963
+ }
964
+ return outputBuffer;
965
+ }
966
+ function getEntries(container) {
967
+ const hasEntriesFunc = container.entries && !container.hasOwnProperty("entries");
968
+ return hasEntriesFunc ? container.entries() : Object.entries(container);
969
+ }
970
+
971
+ // src/draco-writer.ts
972
+ var DEFAULT_DRACO_WRITER_OPTIONS = {
973
+ pointcloud: false,
974
+ // Set to true if pointcloud (mode: 0, no indices)
975
+ attributeNameEntry: "name"
976
+ // Draco Compression Parameters
977
+ // method: 'MESH_EDGEBREAKER_ENCODING', // Use draco defaults
978
+ // speed: [5, 5], // Use draco defaults
979
+ // quantization: { // Use draco defaults
980
+ // POSITION: 10
981
+ // }
982
+ };
983
+ var DracoWriter = {
984
+ name: "DRACO",
985
+ id: "draco",
986
+ module: "draco",
987
+ version: VERSION,
988
+ extensions: ["drc"],
989
+ encode,
990
+ options: {
991
+ draco: DEFAULT_DRACO_WRITER_OPTIONS
992
+ }
993
+ };
994
+ async function encode(data, options = {}) {
995
+ const { draco } = await loadDracoEncoderModule(options);
996
+ const dracoBuilder = new DracoBuilder(draco);
997
+ try {
998
+ return dracoBuilder.encodeSync(data, options.draco);
999
+ } finally {
1000
+ dracoBuilder.destroy();
1001
+ }
1002
+ }
1003
+
1004
+ // src/index.ts
1005
+ var DracoWriterWorker = {
1006
+ id: "draco-writer",
1007
+ name: "Draco compressed geometry writer",
1008
+ module: "draco",
1009
+ version: VERSION,
1010
+ worker: true,
1011
+ options: {
1012
+ draco: {},
1013
+ source: null
1014
+ }
1015
+ };
1016
+ var DracoLoader2 = {
1017
+ ...DracoLoader,
1018
+ parse
1019
+ };
1020
+ async function parse(arrayBuffer, options) {
1021
+ const { draco } = await loadDracoDecoderModule(options);
1022
+ const dracoParser = new DracoParser(draco);
1023
+ try {
1024
+ return dracoParser.parseSync(arrayBuffer, options == null ? void 0 : options.draco);
1025
+ } finally {
1026
+ dracoParser.destroy();
1027
+ }
1028
+ }