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