@loaders.gl/draco 3.1.0-alpha.4 → 3.1.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 (70) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +5 -0
  4. package/dist/dist.min.js +4 -2
  5. package/dist/dist.min.js.map +7 -1
  6. package/dist/draco-loader.d.ts +28 -0
  7. package/dist/draco-loader.d.ts.map +1 -0
  8. package/dist/draco-loader.js +30 -0
  9. package/dist/draco-worker.js +2 -2
  10. package/dist/draco-worker.js.map +7 -1
  11. package/dist/draco-writer.d.ts +8 -0
  12. package/dist/draco-writer.d.ts.map +1 -0
  13. package/dist/draco-writer.js +44 -0
  14. package/dist/draco3d/draco3d-types.d.ts +295 -0
  15. package/dist/draco3d/draco3d-types.d.ts.map +1 -0
  16. package/dist/draco3d/draco3d-types.js +51 -0
  17. package/dist/es5/bundle.js +1 -1
  18. package/dist/es5/bundle.js.map +1 -1
  19. package/dist/es5/draco-loader.js +4 -8
  20. package/dist/es5/draco-loader.js.map +1 -1
  21. package/dist/es5/draco-writer.js +13 -46
  22. package/dist/es5/draco-writer.js.map +1 -1
  23. package/dist/es5/draco3d/draco3d-types.js +4 -4
  24. package/dist/es5/index.js +16 -51
  25. package/dist/es5/index.js.map +1 -1
  26. package/dist/es5/lib/draco-builder.js +244 -292
  27. package/dist/es5/lib/draco-builder.js.map +1 -1
  28. package/dist/es5/lib/draco-module-loader.js +65 -198
  29. package/dist/es5/lib/draco-module-loader.js.map +1 -1
  30. package/dist/es5/lib/draco-parser.js +308 -372
  31. package/dist/es5/lib/draco-parser.js.map +1 -1
  32. package/dist/es5/lib/utils/get-draco-schema.js +15 -15
  33. package/dist/es5/lib/utils/get-draco-schema.js.map +1 -1
  34. package/dist/es5/lib/utils/version.js +1 -1
  35. package/dist/es5/lib/utils/version.js.map +1 -1
  36. package/dist/esm/lib/draco-builder.js +4 -6
  37. package/dist/esm/lib/draco-builder.js.map +1 -1
  38. package/dist/esm/lib/draco-module-loader.js +4 -4
  39. package/dist/esm/lib/draco-module-loader.js.map +1 -1
  40. package/dist/esm/lib/draco-parser.js +2 -2
  41. package/dist/esm/lib/draco-parser.js.map +1 -1
  42. package/dist/esm/lib/utils/get-draco-schema.js +1 -1
  43. package/dist/esm/lib/utils/get-draco-schema.js.map +1 -1
  44. package/dist/esm/lib/utils/version.js +1 -1
  45. package/dist/esm/lib/utils/version.js.map +1 -1
  46. package/dist/index.d.ts +29 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +31 -0
  49. package/dist/lib/draco-builder.d.ts +107 -0
  50. package/dist/lib/draco-builder.d.ts.map +1 -0
  51. package/dist/lib/draco-builder.js +338 -0
  52. package/dist/lib/draco-module-loader.d.ts +3 -0
  53. package/dist/lib/draco-module-loader.d.ts.map +1 -0
  54. package/dist/lib/draco-module-loader.js +91 -0
  55. package/dist/lib/draco-parser.d.ts +137 -0
  56. package/dist/lib/draco-parser.d.ts.map +1 -0
  57. package/dist/lib/draco-parser.js +476 -0
  58. package/dist/lib/draco-types.d.ts +59 -0
  59. package/dist/lib/draco-types.d.ts.map +1 -0
  60. package/dist/lib/draco-types.js +3 -0
  61. package/dist/lib/utils/get-draco-schema.d.ts +8 -0
  62. package/dist/lib/utils/get-draco-schema.d.ts.map +1 -0
  63. package/dist/lib/utils/get-draco-schema.js +42 -0
  64. package/dist/lib/utils/version.d.ts +2 -0
  65. package/dist/lib/utils/version.d.ts.map +1 -0
  66. package/dist/lib/utils/version.js +7 -0
  67. package/dist/workers/draco-worker.d.ts +2 -0
  68. package/dist/workers/draco-worker.d.ts.map +1 -0
  69. package/dist/workers/draco-worker.js +5 -0
  70. package/package.json +8 -8
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Native Draco attribute names to GLTF attribute names.
4
+ const GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
5
+ POSITION: 'POSITION',
6
+ NORMAL: 'NORMAL',
7
+ COLOR_0: 'COLOR',
8
+ TEXCOORD_0: 'TEX_COORD'
9
+ };
10
+ const noop = () => { };
11
+ class DracoBuilder {
12
+ // draco - the draco decoder, either import `draco3d` or load dynamically
13
+ constructor(draco) {
14
+ this.draco = draco;
15
+ this.dracoEncoder = new this.draco.Encoder();
16
+ this.dracoMeshBuilder = new this.draco.MeshBuilder();
17
+ this.dracoMetadataBuilder = new this.draco.MetadataBuilder();
18
+ }
19
+ destroy() {
20
+ this.destroyEncodedObject(this.dracoMeshBuilder);
21
+ this.destroyEncodedObject(this.dracoEncoder);
22
+ this.destroyEncodedObject(this.dracoMetadataBuilder);
23
+ // @ts-ignore
24
+ this.dracoMeshBuilder = null;
25
+ // @ts-ignore
26
+ this.dracoEncoder = null;
27
+ // @ts-ignore
28
+ this.draco = null;
29
+ }
30
+ // TBD - when does this need to be called?
31
+ destroyEncodedObject(object) {
32
+ if (object) {
33
+ this.draco.destroy(object);
34
+ }
35
+ }
36
+ /**
37
+ * Encode mesh or point cloud
38
+ * @param mesh =({})
39
+ * @param options
40
+ */
41
+ encodeSync(mesh, options = {}) {
42
+ this.log = noop; // TODO
43
+ this._setOptions(options);
44
+ return options.pointcloud
45
+ ? this._encodePointCloud(mesh, options)
46
+ : this._encodeMesh(mesh, options);
47
+ }
48
+ // PRIVATE
49
+ _getAttributesFromMesh(mesh) {
50
+ // TODO - Change the encodePointCloud interface instead?
51
+ const attributes = { ...mesh, ...mesh.attributes };
52
+ // Fold indices into the attributes
53
+ if (mesh.indices) {
54
+ attributes.indices = mesh.indices;
55
+ }
56
+ return attributes;
57
+ }
58
+ _encodePointCloud(pointcloud, options) {
59
+ const dracoPointCloud = new this.draco.PointCloud();
60
+ if (options.metadata) {
61
+ this._addGeometryMetadata(dracoPointCloud, options.metadata);
62
+ }
63
+ const attributes = this._getAttributesFromMesh(pointcloud);
64
+ // Build a `DracoPointCloud` from the input data
65
+ this._createDracoPointCloud(dracoPointCloud, attributes, options);
66
+ const dracoData = new this.draco.DracoInt8Array();
67
+ try {
68
+ const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(dracoPointCloud, false, dracoData);
69
+ if (!(encodedLen > 0)) {
70
+ throw new Error('Draco encoding failed.');
71
+ }
72
+ this.log(`DRACO encoded ${dracoPointCloud.num_points()} points
73
+ with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);
74
+ return dracoInt8ArrayToArrayBuffer(dracoData);
75
+ }
76
+ finally {
77
+ this.destroyEncodedObject(dracoData);
78
+ this.destroyEncodedObject(dracoPointCloud);
79
+ }
80
+ }
81
+ _encodeMesh(mesh, options) {
82
+ const dracoMesh = new this.draco.Mesh();
83
+ if (options.metadata) {
84
+ this._addGeometryMetadata(dracoMesh, options.metadata);
85
+ }
86
+ const attributes = this._getAttributesFromMesh(mesh);
87
+ // Build a `DracoMesh` from the input data
88
+ this._createDracoMesh(dracoMesh, attributes, options);
89
+ const dracoData = new this.draco.DracoInt8Array();
90
+ try {
91
+ const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);
92
+ if (encodedLen <= 0) {
93
+ throw new Error('Draco encoding failed.');
94
+ }
95
+ this.log(`DRACO encoded ${dracoMesh.num_points()} points
96
+ with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);
97
+ return dracoInt8ArrayToArrayBuffer(dracoData);
98
+ }
99
+ finally {
100
+ this.destroyEncodedObject(dracoData);
101
+ this.destroyEncodedObject(dracoMesh);
102
+ }
103
+ }
104
+ /**
105
+ * Set encoding options.
106
+ * @param {{speed?: any; method?: any; quantization?: any;}} options
107
+ */
108
+ _setOptions(options) {
109
+ if ('speed' in options) {
110
+ // @ts-ignore
111
+ this.dracoEncoder.SetSpeedOptions(...options.speed);
112
+ }
113
+ if ('method' in options) {
114
+ const dracoMethod = this.draco[options.method || 'MESH_SEQUENTIAL_ENCODING'];
115
+ // assert(dracoMethod)
116
+ this.dracoEncoder.SetEncodingMethod(dracoMethod);
117
+ }
118
+ if ('quantization' in options) {
119
+ for (const attribute in options.quantization) {
120
+ const bits = options.quantization[attribute];
121
+ const dracoPosition = this.draco[attribute];
122
+ this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);
123
+ }
124
+ }
125
+ }
126
+ /**
127
+ * @param {Mesh} dracoMesh
128
+ * @param {object} attributes
129
+ * @returns {Mesh}
130
+ */
131
+ _createDracoMesh(dracoMesh, attributes, options) {
132
+ const optionalMetadata = options.attributesMetadata || {};
133
+ try {
134
+ const positions = this._getPositionAttribute(attributes);
135
+ if (!positions) {
136
+ throw new Error('positions');
137
+ }
138
+ const vertexCount = positions.length / 3;
139
+ for (let attributeName in attributes) {
140
+ const attribute = attributes[attributeName];
141
+ attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
142
+ const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);
143
+ if (uniqueId !== -1) {
144
+ this._addAttributeMetadata(dracoMesh, uniqueId, {
145
+ name: attributeName,
146
+ ...(optionalMetadata[attributeName] || {})
147
+ });
148
+ }
149
+ }
150
+ }
151
+ catch (error) {
152
+ this.destroyEncodedObject(dracoMesh);
153
+ throw error;
154
+ }
155
+ return dracoMesh;
156
+ }
157
+ /**
158
+ * @param {} dracoPointCloud
159
+ * @param {object} attributes
160
+ */
161
+ _createDracoPointCloud(dracoPointCloud, attributes, options) {
162
+ const optionalMetadata = options.attributesMetadata || {};
163
+ try {
164
+ const positions = this._getPositionAttribute(attributes);
165
+ if (!positions) {
166
+ throw new Error('positions');
167
+ }
168
+ const vertexCount = positions.length / 3;
169
+ for (let attributeName in attributes) {
170
+ const attribute = attributes[attributeName];
171
+ attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
172
+ const uniqueId = this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);
173
+ if (uniqueId !== -1) {
174
+ this._addAttributeMetadata(dracoPointCloud, uniqueId, {
175
+ name: attributeName,
176
+ ...(optionalMetadata[attributeName] || {})
177
+ });
178
+ }
179
+ }
180
+ }
181
+ catch (error) {
182
+ this.destroyEncodedObject(dracoPointCloud);
183
+ throw error;
184
+ }
185
+ return dracoPointCloud;
186
+ }
187
+ /**
188
+ * @param mesh
189
+ * @param attributeName
190
+ * @param attribute
191
+ * @param vertexCount
192
+ */
193
+ _addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
194
+ if (!ArrayBuffer.isView(attribute)) {
195
+ return -1;
196
+ }
197
+ const type = this._getDracoAttributeType(attributeName);
198
+ // @ts-ignore TODO/fix types
199
+ const size = attribute.length / vertexCount;
200
+ if (type === 'indices') {
201
+ // @ts-ignore TODO/fix types
202
+ const numFaces = attribute.length / 3;
203
+ this.log(`Adding attribute ${attributeName}, size ${numFaces}`);
204
+ // @ts-ignore assumes mesh is a Mesh, not a point cloud
205
+ this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);
206
+ return -1;
207
+ }
208
+ this.log(`Adding attribute ${attributeName}, size ${size}`);
209
+ const builder = this.dracoMeshBuilder;
210
+ const { buffer } = attribute;
211
+ switch (attribute.constructor) {
212
+ case Int8Array:
213
+ return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));
214
+ case Int16Array:
215
+ return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));
216
+ case Int32Array:
217
+ return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));
218
+ case Uint8Array:
219
+ case Uint8ClampedArray:
220
+ return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));
221
+ case Uint16Array:
222
+ return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));
223
+ case Uint32Array:
224
+ return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));
225
+ case Float32Array:
226
+ default:
227
+ return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
228
+ }
229
+ }
230
+ /**
231
+ * DRACO can compress attributes of know type better
232
+ * TODO - expose an attribute type map?
233
+ * @param attributeName
234
+ */
235
+ _getDracoAttributeType(attributeName) {
236
+ switch (attributeName.toLowerCase()) {
237
+ case 'indices':
238
+ return 'indices';
239
+ case 'position':
240
+ case 'positions':
241
+ case 'vertices':
242
+ return this.draco.POSITION;
243
+ case 'normal':
244
+ case 'normals':
245
+ return this.draco.NORMAL;
246
+ case 'color':
247
+ case 'colors':
248
+ return this.draco.COLOR;
249
+ case 'texcoord':
250
+ case 'texcoords':
251
+ return this.draco.TEX_COORD;
252
+ default:
253
+ return this.draco.GENERIC;
254
+ }
255
+ }
256
+ _getPositionAttribute(attributes) {
257
+ for (const attributeName in attributes) {
258
+ const attribute = attributes[attributeName];
259
+ const dracoType = this._getDracoAttributeType(attributeName);
260
+ if (dracoType === this.draco.POSITION) {
261
+ return attribute;
262
+ }
263
+ }
264
+ return null;
265
+ }
266
+ /**
267
+ * Add metadata for the geometry.
268
+ * @param dracoGeometry - WASM Draco Object
269
+ * @param metadata
270
+ */
271
+ _addGeometryMetadata(dracoGeometry, metadata) {
272
+ const dracoMetadata = new this.draco.Metadata();
273
+ this._populateDracoMetadata(dracoMetadata, metadata);
274
+ this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
275
+ }
276
+ /**
277
+ * Add metadata for an attribute to geometry.
278
+ * @param dracoGeometry - WASM Draco Object
279
+ * @param uniqueAttributeId
280
+ * @param metadata
281
+ */
282
+ _addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
283
+ // Note: Draco JS IDL doesn't seem to expose draco.AttributeMetadata, however it seems to
284
+ // create such objects automatically from draco.Metadata object.
285
+ const dracoAttributeMetadata = new this.draco.Metadata();
286
+ this._populateDracoMetadata(dracoAttributeMetadata, metadata);
287
+ // Draco3d doc note: Directly add attribute metadata to geometry.
288
+ // You can do this without explicitly adding |GeometryMetadata| to mesh.
289
+ this.dracoMeshBuilder.SetMetadataForAttribute(dracoGeometry, uniqueAttributeId, dracoAttributeMetadata);
290
+ }
291
+ /**
292
+ * Add contents of object or map to a WASM Draco Metadata Object
293
+ * @param dracoMetadata - WASM Draco Object
294
+ * @param metadata
295
+ */
296
+ _populateDracoMetadata(dracoMetadata, metadata) {
297
+ for (const [key, value] of getEntries(metadata)) {
298
+ switch (typeof value) {
299
+ case 'number':
300
+ if (Math.trunc(value) === value) {
301
+ this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);
302
+ }
303
+ else {
304
+ this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);
305
+ }
306
+ break;
307
+ case 'object':
308
+ if (value instanceof Int32Array) {
309
+ this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);
310
+ }
311
+ break;
312
+ case 'string':
313
+ default:
314
+ this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);
315
+ }
316
+ }
317
+ }
318
+ }
319
+ exports.default = DracoBuilder;
320
+ // HELPER FUNCTIONS
321
+ /**
322
+ * Copy encoded data to buffer
323
+ * @param dracoData
324
+ */
325
+ function dracoInt8ArrayToArrayBuffer(dracoData) {
326
+ const byteLength = dracoData.size();
327
+ const outputBuffer = new ArrayBuffer(byteLength);
328
+ const outputData = new Int8Array(outputBuffer);
329
+ for (let i = 0; i < byteLength; ++i) {
330
+ outputData[i] = dracoData.GetValue(i);
331
+ }
332
+ return outputBuffer;
333
+ }
334
+ /** Enable iteration over either an object or a map */
335
+ function getEntries(container) {
336
+ const hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');
337
+ return hasEntriesFunc ? container.entries() : Object.entries(container);
338
+ }
@@ -0,0 +1,3 @@
1
+ export declare function loadDracoDecoderModule(options: any): Promise<any>;
2
+ export declare function loadDracoEncoderModule(options: any): Promise<any>;
3
+ //# sourceMappingURL=draco-module-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draco-module-loader.d.ts","sourceRoot":"","sources":["../../src/lib/draco-module-loader.ts"],"names":[],"mappings":"AAgBA,wBAAsB,sBAAsB,CAAC,OAAO,KAAA,gBAenD;AAED,wBAAsB,sBAAsB,CAAC,OAAO,KAAA,gBAenD"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ // Dynamic DRACO module loading inspired by THREE.DRACOLoader
3
+ // https://github.com/mrdoob/three.js/blob/398c4f39ebdb8b23eefd4a7a5ec49ec0c96c7462/examples/jsm/loaders/DRACOLoader.js
4
+ // by Don McCurdy / https://www.donmccurdy.com / MIT license
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadDracoEncoderModule = exports.loadDracoDecoderModule = void 0;
7
+ const worker_utils_1 = require("@loaders.gl/worker-utils");
8
+ const DRACO_VERSION = '1.4.1';
9
+ const DRACO_JS_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_decoder.js`;
10
+ const DRACO_WASM_WRAPPER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_wasm_wrapper.js`;
11
+ const DRACO_WASM_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_decoder.wasm`;
12
+ const DRACO_ENCODER_URL = `https://raw.githubusercontent.com/google/draco/${DRACO_VERSION}/javascript/draco_encoder.js`;
13
+ let loadDecoderPromise;
14
+ let loadEncoderPromise;
15
+ async function loadDracoDecoderModule(options) {
16
+ const modules = options.modules || {};
17
+ // Check if a bundled draco3d library has been supplied by application
18
+ if (modules.draco3d) {
19
+ loadDecoderPromise =
20
+ loadDecoderPromise ||
21
+ modules.draco3d.createDecoderModule({}).then((draco) => {
22
+ return { draco };
23
+ });
24
+ }
25
+ else {
26
+ // If not, dynamically load the WASM script from our CDN
27
+ loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);
28
+ }
29
+ return await loadDecoderPromise;
30
+ }
31
+ exports.loadDracoDecoderModule = loadDracoDecoderModule;
32
+ async function loadDracoEncoderModule(options) {
33
+ const modules = options.modules || {};
34
+ // Check if a bundled draco3d library has been supplied by application
35
+ if (modules.draco3d) {
36
+ loadEncoderPromise =
37
+ loadEncoderPromise ||
38
+ modules.draco3d.createEncoderModule({}).then((draco) => {
39
+ return { draco };
40
+ });
41
+ }
42
+ else {
43
+ // If not, dynamically load the WASM script from our CDN
44
+ loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);
45
+ }
46
+ return await loadEncoderPromise;
47
+ }
48
+ exports.loadDracoEncoderModule = loadDracoEncoderModule;
49
+ // DRACO DECODER LOADING
50
+ async function loadDracoDecoder(options) {
51
+ let DracoDecoderModule;
52
+ let wasmBinary;
53
+ switch (options.draco && options.draco.decoderType) {
54
+ case 'js':
55
+ DracoDecoderModule = await (0, worker_utils_1.loadLibrary)(DRACO_JS_DECODER_URL, 'draco', options);
56
+ break;
57
+ case 'wasm':
58
+ default:
59
+ [DracoDecoderModule, wasmBinary] = await Promise.all([
60
+ await (0, worker_utils_1.loadLibrary)(DRACO_WASM_WRAPPER_URL, 'draco', options),
61
+ await (0, worker_utils_1.loadLibrary)(DRACO_WASM_DECODER_URL, 'draco', options)
62
+ ]);
63
+ }
64
+ // Depends on how import happened...
65
+ // @ts-ignore
66
+ DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;
67
+ return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);
68
+ }
69
+ function initializeDracoDecoder(DracoDecoderModule, wasmBinary) {
70
+ const options = {};
71
+ if (wasmBinary) {
72
+ options.wasmBinary = wasmBinary;
73
+ }
74
+ return new Promise((resolve) => {
75
+ DracoDecoderModule({
76
+ ...options,
77
+ onModuleLoaded: (draco) => resolve({ draco }) // Module is Promise-like. Wrap in object to avoid loop.
78
+ });
79
+ });
80
+ }
81
+ // ENCODER
82
+ async function loadDracoEncoder(options) {
83
+ let DracoEncoderModule = await (0, worker_utils_1.loadLibrary)(DRACO_ENCODER_URL, 'draco', options);
84
+ // @ts-ignore
85
+ DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;
86
+ return new Promise((resolve) => {
87
+ DracoEncoderModule({
88
+ onModuleLoaded: (draco) => resolve({ draco }) // Module is Promise-like. Wrap in object to avoid loop.
89
+ });
90
+ });
91
+ }
@@ -0,0 +1,137 @@
1
+ import type { TypedArray, MeshAttribute, MeshGeometry } from '@loaders.gl/schema';
2
+ import type { Draco3D, Decoder, Mesh, PointCloud, PointAttribute, Metadata, MetadataQuerier } from '../draco3d/draco3d-types';
3
+ import type { DracoMesh, DracoLoaderData, DracoAttribute, DracoMetadataEntry, DracoQuantizationTransform, DracoOctahedronTransform } from './draco-types';
4
+ /**
5
+ * @param topology - How triangle indices should be generated (mesh only)
6
+ * @param attributeNameEntry
7
+ * @param extraAttributes
8
+ * @param quantizedAttributes
9
+ * @param octahedronAttributes
10
+ */
11
+ export declare type DracoParseOptions = {
12
+ topology?: 'triangle-list' | 'triangle-strip';
13
+ attributeNameEntry?: string;
14
+ extraAttributes?: {
15
+ [uniqueId: string]: number;
16
+ };
17
+ quantizedAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];
18
+ octahedronAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];
19
+ };
20
+ export default class DracoParser {
21
+ draco: Draco3D;
22
+ decoder: Decoder;
23
+ metadataQuerier: MetadataQuerier;
24
+ constructor(draco: Draco3D);
25
+ /**
26
+ * Destroy draco resources
27
+ */
28
+ destroy(): void;
29
+ /**
30
+ * NOTE: caller must call `destroyGeometry` on the return value after using it
31
+ * @param arrayBuffer
32
+ * @param options
33
+ */
34
+ parseSync(arrayBuffer: ArrayBuffer, options?: DracoParseOptions): DracoMesh;
35
+ /**
36
+ * Extract
37
+ * @param dracoGeometry
38
+ * @param geometry_type
39
+ * @param options
40
+ * @returns
41
+ */
42
+ _getDracoLoaderData(dracoGeometry: Mesh | PointCloud, geometry_type: any, options: DracoParseOptions): DracoLoaderData;
43
+ /**
44
+ * Extract all draco provided information and metadata for each attribute
45
+ * @param dracoGeometry
46
+ * @param options
47
+ * @returns
48
+ */
49
+ _getDracoAttributes(dracoGeometry: Mesh | PointCloud, options: DracoParseOptions): {
50
+ [unique_id: number]: DracoAttribute;
51
+ };
52
+ /**
53
+ * Get standard loaders.gl mesh category data
54
+ * Extracts the geometry from draco
55
+ * @param dracoGeometry
56
+ * @param options
57
+ */
58
+ _getMeshData(dracoGeometry: Mesh | PointCloud, loaderData: DracoLoaderData, options: DracoParseOptions): MeshGeometry;
59
+ _getMeshAttributes(loaderData: DracoLoaderData, dracoGeometry: Mesh | PointCloud, options: DracoParseOptions): {
60
+ [attributeName: string]: MeshAttribute;
61
+ };
62
+ /**
63
+ * For meshes, we need indices to define the faces.
64
+ * @param dracoGeometry
65
+ */
66
+ _getTriangleListIndices(dracoGeometry: Mesh): Uint32Array;
67
+ /**
68
+ * For meshes, we need indices to define the faces.
69
+ * @param dracoGeometry
70
+ */
71
+ _getTriangleStripIndices(dracoGeometry: Mesh): Int32Array;
72
+ /**
73
+ *
74
+ * @param dracoGeometry
75
+ * @param dracoAttribute
76
+ * @param attributeName
77
+ */
78
+ _getAttributeValues(dracoGeometry: Mesh | PointCloud, attribute: DracoAttribute): {
79
+ value: TypedArray;
80
+ size: number;
81
+ };
82
+ /**
83
+ * DRACO does not store attribute names - We need to deduce an attribute name
84
+ * for each attribute
85
+ _getAttributeNames(
86
+ dracoGeometry: Mesh | PointCloud,
87
+ options: DracoParseOptions
88
+ ): {[unique_id: number]: string} {
89
+ const attributeNames: {[unique_id: number]: string} = {};
90
+ for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
91
+ const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
92
+ const attributeName = this._deduceAttributeName(dracoAttribute, options);
93
+ attributeNames[attributeName] = attributeName;
94
+ }
95
+ return attributeNames;
96
+ }
97
+ */
98
+ /**
99
+ * Deduce an attribute name.
100
+ * @note DRACO does not save attribute names, just general type (POSITION, COLOR)
101
+ * to help optimize compression. We generate GLTF compatible names for the Draco-recognized
102
+ * types
103
+ * @param attributeData
104
+ */
105
+ _deduceAttributeName(attribute: DracoAttribute, options: DracoParseOptions): string;
106
+ /** Get top level metadata */
107
+ _getTopLevelMetadata(dracoGeometry: Mesh | PointCloud): {
108
+ [entry: string]: DracoMetadataEntry;
109
+ };
110
+ /** Get per attribute metadata */
111
+ _getAttributeMetadata(dracoGeometry: Mesh | PointCloud, attributeId: number): {
112
+ [entry: string]: DracoMetadataEntry;
113
+ };
114
+ /**
115
+ * Extract metadata field values
116
+ * @param dracoMetadata
117
+ * @returns
118
+ */
119
+ _getDracoMetadata(dracoMetadata: Metadata): {
120
+ [entry: string]: DracoMetadataEntry;
121
+ };
122
+ /**
123
+ * Extracts possible values for one metadata entry by name
124
+ * @param dracoMetadata
125
+ * @param entryName
126
+ */
127
+ _getDracoMetadataField(dracoMetadata: Metadata, entryName: string): DracoMetadataEntry;
128
+ /** Skip transforms for specific attribute types */
129
+ _disableAttributeTransforms(options: DracoParseOptions): void;
130
+ /**
131
+ * Extract (and apply?) Position Transform
132
+ * @todo not used
133
+ */
134
+ _getQuantizationTransform(dracoAttribute: PointAttribute, options: DracoParseOptions): DracoQuantizationTransform | null;
135
+ _getOctahedronTransform(dracoAttribute: PointAttribute, options: DracoParseOptions): DracoOctahedronTransform | null;
136
+ }
137
+ //# sourceMappingURL=draco-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draco-parser.d.ts","sourceRoot":"","sources":["../../src/lib/draco-parser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,UAAU,EAAE,aAAa,EAAE,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAGhF,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,IAAI,EACJ,UAAU,EACV,cAAc,EACd,QAAQ,EACR,eAAe,EAGhB,MAAM,0BAA0B,CAAC;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