iflow-engine-base 0.0.1

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 (50) hide show
  1. package/README.md +2 -0
  2. package/dist/assets/bim-engine-sdk.z34pmn5f.css +1 -0
  3. package/dist/assets/hdr/001.hdr +0 -0
  4. package/dist/assets/viewcube/cn_back.png +0 -0
  5. package/dist/assets/viewcube/cn_bottom.png +0 -0
  6. package/dist/assets/viewcube/cn_front.png +0 -0
  7. package/dist/assets/viewcube/cn_left.png +0 -0
  8. package/dist/assets/viewcube/cn_right.png +0 -0
  9. package/dist/assets/viewcube/cn_top.png +0 -0
  10. package/dist/assets/viewcube/home.png +0 -0
  11. package/dist/bim-engine-sdk.es.js +13022 -0
  12. package/dist/bim-engine-sdk.es.js.map +1 -0
  13. package/dist/bim-engine-sdk.umd.js +841 -0
  14. package/dist/bim-engine-sdk.umd.js.map +1 -0
  15. package/dist/draco/DRACOLoader.js +739 -0
  16. package/dist/draco/draco_decoder.js +52 -0
  17. package/dist/draco/draco_decoder.wasm +0 -0
  18. package/dist/draco/draco_encoder.js +33 -0
  19. package/dist/draco/draco_wasm_wrapper.js +104 -0
  20. package/dist/index.d.ts +610 -0
  21. package/dist/model/gujianzhu.glb +0 -0
  22. package/dist/model/test1/lod3/nodes.json +1 -0
  23. package/dist/model/test1/lod3/primitives/0.glb +0 -0
  24. package/dist/model/test1/lod3/primitives/1.glb +0 -0
  25. package/dist/model/test1/lod4/nodes.json +1 -0
  26. package/dist/model/test1/lod4/primitives/0.glb +0 -0
  27. package/dist/model/test1/lod5/nodes.json +1 -0
  28. package/dist/model/test1/lod5/primitives/0.glb +0 -0
  29. package/dist/model/test1/lod6/nodes.json +1 -0
  30. package/dist/model/test1/lod6/primitives/0.glb +0 -0
  31. package/dist/model/test2/info.zip +0 -0
  32. package/dist/model/test2/lod0/nodes.json +1 -0
  33. package/dist/model/test2/lod0/primitives/0.glb +0 -0
  34. package/dist/model/test2/lod0/primitives/1.glb +0 -0
  35. package/dist/model/test2/lod0/primitives/10.glb +0 -0
  36. package/dist/model/test2/lod0/primitives/11.glb +0 -0
  37. package/dist/model/test2/lod0/primitives/12.glb +0 -0
  38. package/dist/model/test2/lod0/primitives/13.glb +0 -0
  39. package/dist/model/test2/lod0/primitives/14.glb +0 -0
  40. package/dist/model/test2/lod0/primitives/15.glb +0 -0
  41. package/dist/model/test2/lod0/primitives/2.glb +0 -0
  42. package/dist/model/test2/lod0/primitives/3.glb +0 -0
  43. package/dist/model/test2/lod0/primitives/4.glb +0 -0
  44. package/dist/model/test2/lod0/primitives/5.glb +0 -0
  45. package/dist/model/test2/lod0/primitives/6.glb +0 -0
  46. package/dist/model/test2/lod0/primitives/7.glb +0 -0
  47. package/dist/model/test2/lod0/primitives/8.glb +0 -0
  48. package/dist/model/test2/lod0/primitives/9.glb +0 -0
  49. package/dist/model/test2/property.zip +0 -0
  50. package/package.json +46 -0
@@ -0,0 +1,739 @@
1
+ import {
2
+ BufferAttribute,
3
+ BufferGeometry,
4
+ Color,
5
+ ColorManagement,
6
+ FileLoader,
7
+ Loader,
8
+ LinearSRGBColorSpace,
9
+ SRGBColorSpace,
10
+ InterleavedBuffer,
11
+ InterleavedBufferAttribute
12
+ } from 'three';
13
+
14
+ const _taskCache = new WeakMap();
15
+
16
+ /**
17
+ * A loader for the Draco format.
18
+ *
19
+ * [Draco](https://google.github.io/draco/) is an open source library for compressing
20
+ * and decompressing 3D meshes and point clouds. Compressed geometry can be significantly smaller,
21
+ * at the cost of additional decoding time on the client device.
22
+ *
23
+ * Standalone Draco files have a `.drc` extension, and contain vertex positions, normals, colors,
24
+ * and other attributes. Draco files do not contain materials, textures, animation, or node hierarchies –
25
+ * to use these features, embed Draco geometry inside of a glTF file. A normal glTF file can be converted
26
+ * to a Draco-compressed glTF file using [glTF-Pipeline](https://github.com/CesiumGS/gltf-pipeline).
27
+ * When using Draco with glTF, an instance of `DRACOLoader` will be used internally by {@link GLTFLoader}.
28
+ *
29
+ * It is recommended to create one DRACOLoader instance and reuse it to avoid loading and creating
30
+ * multiple decoder instances.
31
+ *
32
+ * `DRACOLoader` will automatically use either the JS or the WASM decoding library, based on
33
+ * browser capabilities.
34
+ *
35
+ * ```js
36
+ * const loader = new DRACOLoader();
37
+ * loader.setDecoderPath( '/examples/jsm/libs/draco/' );
38
+ *
39
+ * const geometry = await dracoLoader.loadAsync( 'models/draco/bunny.drc' );
40
+ * geometry.computeVertexNormals(); // optional
41
+ *
42
+ * dracoLoader.dispose();
43
+ * ```
44
+ *
45
+ * @augments Loader
46
+ * @three_import import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
47
+ */
48
+ class DRACOLoader extends Loader {
49
+
50
+ /**
51
+ * Constructs a new Draco loader.
52
+ *
53
+ * @param {LoadingManager} [manager] - The loading manager.
54
+ */
55
+ constructor( manager ) {
56
+
57
+ super( manager );
58
+
59
+ this.decoderPath = '';
60
+ this.decoderConfig = {};
61
+ this.decoderBinary = null;
62
+ this.decoderPending = null;
63
+
64
+ this.workerLimit = 4;
65
+ this.workerPool = [];
66
+ this.workerNextTaskID = 1;
67
+ this.workerSourceURL = '';
68
+
69
+ this.defaultAttributeIDs = {
70
+ position: 'POSITION',
71
+ normal: 'NORMAL',
72
+ color: 'COLOR',
73
+ uv: 'TEX_COORD'
74
+ };
75
+ this.defaultAttributeTypes = {
76
+ position: 'Float32Array',
77
+ normal: 'Float32Array',
78
+ color: 'Float32Array',
79
+ uv: 'Float32Array'
80
+ };
81
+
82
+ }
83
+
84
+ /**
85
+ * Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
86
+ *
87
+ * @param {string} path - The decoder path.
88
+ * @return {DRACOLoader} A reference to this loader.
89
+ */
90
+ setDecoderPath( path ) {
91
+
92
+ this.decoderPath = path;
93
+
94
+ return this;
95
+
96
+ }
97
+
98
+ /**
99
+ * Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
100
+ *
101
+ * @param {{type:('js'|'wasm')}} config - The decoder config.
102
+ * @return {DRACOLoader} A reference to this loader.
103
+ */
104
+ setDecoderConfig( config ) {
105
+
106
+ this.decoderConfig = config;
107
+
108
+ return this;
109
+
110
+ }
111
+
112
+ /**
113
+ * Sets the maximum number of Web Workers to be used during decoding.
114
+ * A lower limit may be preferable if workers are also for other tasks in the application.
115
+ *
116
+ * @param {number} workerLimit - The worker limit.
117
+ * @return {DRACOLoader} A reference to this loader.
118
+ */
119
+ setWorkerLimit( workerLimit ) {
120
+
121
+ this.workerLimit = workerLimit;
122
+
123
+ return this;
124
+
125
+ }
126
+
127
+ /**
128
+ * Starts loading from the given URL and passes the loaded Draco asset
129
+ * to the `onLoad()` callback.
130
+ *
131
+ * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
132
+ * @param {function(BufferGeometry)} onLoad - Executed when the loading process has been finished.
133
+ * @param {onProgressCallback} onProgress - Executed while the loading is in progress.
134
+ * @param {onErrorCallback} onError - Executed when errors occur.
135
+ */
136
+ load( url, onLoad, onProgress, onError ) {
137
+
138
+ const loader = new FileLoader( this.manager );
139
+
140
+ loader.setPath( this.path );
141
+ loader.setResponseType( 'arraybuffer' );
142
+ loader.setRequestHeader( this.requestHeader );
143
+ loader.setWithCredentials( this.withCredentials );
144
+
145
+ loader.load( url, ( buffer ) => {
146
+
147
+ this.parse( buffer, onLoad, onError );
148
+
149
+ }, onProgress, onError );
150
+
151
+ }
152
+
153
+ /**
154
+ * Parses the given Draco data.
155
+ *
156
+ * @param {ArrayBuffer} buffer - The raw Draco data as an array buffer.
157
+ * @param {function(BufferGeometry)} onLoad - Executed when the loading/parsing process has been finished.
158
+ * @param {onErrorCallback} onError - Executed when errors occur.
159
+ */
160
+ parse( buffer, onLoad, onError = ()=>{} ) {
161
+
162
+ this.decodeDracoFile( buffer, onLoad, null, null, SRGBColorSpace, onError ).catch( onError );
163
+
164
+ }
165
+
166
+ //
167
+
168
+ decodeDracoFile( buffer, callback, attributeIDs, attributeTypes, vertexColorSpace = LinearSRGBColorSpace, onError = () => {} ) {
169
+
170
+ const taskConfig = {
171
+ attributeIDs: attributeIDs || this.defaultAttributeIDs,
172
+ attributeTypes: attributeTypes || this.defaultAttributeTypes,
173
+ useUniqueIDs: !! attributeIDs,
174
+ vertexColorSpace: vertexColorSpace,
175
+ };
176
+
177
+ return this.decodeGeometry( buffer, taskConfig ).then( callback ).catch( onError );
178
+
179
+ }
180
+
181
+ decodeGeometry( buffer, taskConfig ) {
182
+
183
+ const taskKey = JSON.stringify( taskConfig );
184
+
185
+ // Check for an existing task using this buffer. A transferred buffer cannot be transferred
186
+ // again from this thread.
187
+ if ( _taskCache.has( buffer ) ) {
188
+
189
+ const cachedTask = _taskCache.get( buffer );
190
+
191
+ if ( cachedTask.key === taskKey ) {
192
+
193
+ return cachedTask.promise;
194
+
195
+ } else if ( buffer.byteLength === 0 ) {
196
+
197
+ // Technically, it would be possible to wait for the previous task to complete,
198
+ // transfer the buffer back, and decode again with the second configuration. That
199
+ // is complex, and I don't know of any reason to decode a Draco buffer twice in
200
+ // different ways, so this is left unimplemented.
201
+ throw new Error(
202
+
203
+ 'THREE.DRACOLoader: Unable to re-decode a buffer with different ' +
204
+ 'settings. Buffer has already been transferred.'
205
+
206
+ );
207
+
208
+ }
209
+
210
+ }
211
+
212
+ //
213
+
214
+ let worker;
215
+ const taskID = this.workerNextTaskID ++;
216
+ const taskCost = buffer.byteLength;
217
+
218
+ // Obtain a worker and assign a task, and construct a geometry instance
219
+ // when the task completes.
220
+ const geometryPending = this._getWorker( taskID, taskCost )
221
+ .then( ( _worker ) => {
222
+
223
+ worker = _worker;
224
+
225
+ return new Promise( ( resolve, reject ) => {
226
+
227
+ worker._callbacks[ taskID ] = { resolve, reject };
228
+
229
+ worker.postMessage( { type: 'decode', id: taskID, taskConfig, buffer }, [ buffer ] );
230
+
231
+ // this.debug();
232
+
233
+ } );
234
+
235
+ } )
236
+ .then( ( message ) => this._createGeometry( message.geometry ) );
237
+
238
+ // Remove task from the task list.
239
+ // Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
240
+ geometryPending
241
+ .catch( () => true )
242
+ .then( () => {
243
+
244
+ if ( worker && taskID ) {
245
+
246
+ this._releaseTask( worker, taskID );
247
+
248
+ // this.debug();
249
+
250
+ }
251
+
252
+ } );
253
+
254
+ // Cache the task result.
255
+ _taskCache.set( buffer, {
256
+
257
+ key: taskKey,
258
+ promise: geometryPending
259
+
260
+ } );
261
+
262
+ return geometryPending;
263
+
264
+ }
265
+
266
+ _createGeometry( geometryData ) {
267
+
268
+ const geometry = new BufferGeometry();
269
+
270
+ if ( geometryData.index ) {
271
+
272
+ geometry.setIndex( new BufferAttribute( geometryData.index.array, 1 ) );
273
+
274
+ }
275
+
276
+ for ( let i = 0; i < geometryData.attributes.length; i ++ ) {
277
+
278
+ const { name, array, itemSize, stride, vertexColorSpace } = geometryData.attributes[ i ];
279
+
280
+ let attribute;
281
+
282
+ if ( itemSize === stride ) {
283
+
284
+ attribute = new BufferAttribute( array, itemSize );
285
+
286
+ } else {
287
+
288
+ const buffer = new InterleavedBuffer( array, stride );
289
+
290
+ attribute = new InterleavedBufferAttribute( buffer, itemSize, 0 );
291
+
292
+ }
293
+
294
+ if ( name === 'color' ) {
295
+
296
+ this._assignVertexColorSpace( attribute, vertexColorSpace );
297
+
298
+ attribute.normalized = ( array instanceof Float32Array ) === false;
299
+
300
+ }
301
+
302
+ geometry.setAttribute( name, attribute );
303
+
304
+ }
305
+
306
+ return geometry;
307
+
308
+ }
309
+
310
+ _assignVertexColorSpace( attribute, inputColorSpace ) {
311
+
312
+ // While .drc files do not specify colorspace, the only 'official' tooling
313
+ // is PLY and OBJ converters, which use sRGB. We'll assume sRGB when a .drc
314
+ // file is passed into .load() or .parse(). GLTFLoader uses internal APIs
315
+ // to decode geometry, and vertex colors are already Linear-sRGB in there.
316
+
317
+ if ( inputColorSpace !== SRGBColorSpace ) return;
318
+
319
+ const _color = new Color();
320
+
321
+ for ( let i = 0, il = attribute.count; i < il; i ++ ) {
322
+
323
+ _color.fromBufferAttribute( attribute, i );
324
+ ColorManagement.colorSpaceToWorking( _color, SRGBColorSpace );
325
+ attribute.setXYZ( i, _color.r, _color.g, _color.b );
326
+
327
+ }
328
+
329
+ }
330
+
331
+ _loadLibrary( url, responseType ) {
332
+
333
+ const loader = new FileLoader( this.manager );
334
+ loader.setPath( this.decoderPath );
335
+ loader.setResponseType( responseType );
336
+ loader.setWithCredentials( this.withCredentials );
337
+
338
+ return new Promise( ( resolve, reject ) => {
339
+
340
+ loader.load( url, resolve, undefined, reject );
341
+
342
+ } );
343
+
344
+ }
345
+
346
+ preload() {
347
+
348
+ this._initDecoder();
349
+
350
+ return this;
351
+
352
+ }
353
+
354
+ _initDecoder() {
355
+
356
+ if ( this.decoderPending ) return this.decoderPending;
357
+
358
+ const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
359
+ const librariesPending = [];
360
+
361
+ if ( useJS ) {
362
+
363
+ librariesPending.push( this._loadLibrary( 'draco_decoder.js', 'text' ) );
364
+
365
+ } else {
366
+
367
+ librariesPending.push( this._loadLibrary( 'draco_wasm_wrapper.js', 'text' ) );
368
+ librariesPending.push( this._loadLibrary( 'draco_decoder.wasm', 'arraybuffer' ) );
369
+
370
+ }
371
+
372
+ this.decoderPending = Promise.all( librariesPending )
373
+ .then( ( libraries ) => {
374
+
375
+ const jsContent = libraries[ 0 ];
376
+
377
+ if ( ! useJS ) {
378
+
379
+ this.decoderConfig.wasmBinary = libraries[ 1 ];
380
+
381
+ }
382
+
383
+ const fn = DRACOWorker.toString();
384
+
385
+ const body = [
386
+ '/* draco decoder */',
387
+ jsContent,
388
+ '',
389
+ '/* worker */',
390
+ fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
391
+ ].join( '\n' );
392
+
393
+ this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
394
+
395
+ } );
396
+
397
+ return this.decoderPending;
398
+
399
+ }
400
+
401
+ _getWorker( taskID, taskCost ) {
402
+
403
+ return this._initDecoder().then( () => {
404
+
405
+ if ( this.workerPool.length < this.workerLimit ) {
406
+
407
+ const worker = new Worker( this.workerSourceURL );
408
+
409
+ worker._callbacks = {};
410
+ worker._taskCosts = {};
411
+ worker._taskLoad = 0;
412
+
413
+ worker.postMessage( { type: 'init', decoderConfig: this.decoderConfig } );
414
+
415
+ worker.onmessage = function ( e ) {
416
+
417
+ const message = e.data;
418
+
419
+ switch ( message.type ) {
420
+
421
+ case 'decode':
422
+ worker._callbacks[ message.id ].resolve( message );
423
+ break;
424
+
425
+ case 'error':
426
+ worker._callbacks[ message.id ].reject( message );
427
+ break;
428
+
429
+ default:
430
+ console.error( 'THREE.DRACOLoader: Unexpected message, "' + message.type + '"' );
431
+
432
+ }
433
+
434
+ };
435
+
436
+ this.workerPool.push( worker );
437
+
438
+ } else {
439
+
440
+ this.workerPool.sort( function ( a, b ) {
441
+
442
+ return a._taskLoad > b._taskLoad ? - 1 : 1;
443
+
444
+ } );
445
+
446
+ }
447
+
448
+ const worker = this.workerPool[ this.workerPool.length - 1 ];
449
+ worker._taskCosts[ taskID ] = taskCost;
450
+ worker._taskLoad += taskCost;
451
+ return worker;
452
+
453
+ } );
454
+
455
+ }
456
+
457
+ _releaseTask( worker, taskID ) {
458
+
459
+ worker._taskLoad -= worker._taskCosts[ taskID ];
460
+ delete worker._callbacks[ taskID ];
461
+ delete worker._taskCosts[ taskID ];
462
+
463
+ }
464
+
465
+ debug() {
466
+
467
+ console.log( 'Task load: ', this.workerPool.map( ( worker ) => worker._taskLoad ) );
468
+
469
+ }
470
+
471
+ dispose() {
472
+
473
+ for ( let i = 0; i < this.workerPool.length; ++ i ) {
474
+
475
+ this.workerPool[ i ].terminate();
476
+
477
+ }
478
+
479
+ this.workerPool.length = 0;
480
+
481
+ if ( this.workerSourceURL !== '' ) {
482
+
483
+ URL.revokeObjectURL( this.workerSourceURL );
484
+
485
+ }
486
+
487
+ return this;
488
+
489
+ }
490
+
491
+ }
492
+
493
+ /* WEB WORKER */
494
+
495
+ function DRACOWorker() {
496
+
497
+ let decoderConfig;
498
+ let decoderPending;
499
+
500
+ onmessage = function ( e ) {
501
+
502
+ const message = e.data;
503
+
504
+ switch ( message.type ) {
505
+
506
+ case 'init':
507
+ decoderConfig = message.decoderConfig;
508
+ decoderPending = new Promise( function ( resolve/*, reject*/ ) {
509
+
510
+ decoderConfig.onModuleLoaded = function ( draco ) {
511
+
512
+ // Module is Promise-like. Wrap before resolving to avoid loop.
513
+ resolve( { draco: draco } );
514
+
515
+ };
516
+
517
+ DracoDecoderModule( decoderConfig ); // eslint-disable-line no-undef
518
+
519
+ } );
520
+ break;
521
+
522
+ case 'decode':
523
+ const buffer = message.buffer;
524
+ const taskConfig = message.taskConfig;
525
+ decoderPending.then( ( module ) => {
526
+
527
+ const draco = module.draco;
528
+ const decoder = new draco.Decoder();
529
+
530
+ try {
531
+
532
+ const geometry = decodeGeometry( draco, decoder, new Int8Array( buffer ), taskConfig );
533
+
534
+ const buffers = geometry.attributes.map( ( attr ) => attr.array.buffer );
535
+
536
+ if ( geometry.index ) buffers.push( geometry.index.array.buffer );
537
+
538
+ self.postMessage( { type: 'decode', id: message.id, geometry }, buffers );
539
+
540
+ } catch ( error ) {
541
+
542
+ console.error( error );
543
+
544
+ self.postMessage( { type: 'error', id: message.id, error: error.message } );
545
+
546
+ } finally {
547
+
548
+ draco.destroy( decoder );
549
+
550
+ }
551
+
552
+ } );
553
+ break;
554
+
555
+ }
556
+
557
+ };
558
+
559
+ function decodeGeometry( draco, decoder, array, taskConfig ) {
560
+
561
+ const attributeIDs = taskConfig.attributeIDs;
562
+ const attributeTypes = taskConfig.attributeTypes;
563
+
564
+ let dracoGeometry;
565
+ let decodingStatus;
566
+
567
+ const geometryType = decoder.GetEncodedGeometryType( array );
568
+
569
+ if ( geometryType === draco.TRIANGULAR_MESH ) {
570
+
571
+ dracoGeometry = new draco.Mesh();
572
+ decodingStatus = decoder.DecodeArrayToMesh( array, array.byteLength, dracoGeometry );
573
+
574
+ } else if ( geometryType === draco.POINT_CLOUD ) {
575
+
576
+ dracoGeometry = new draco.PointCloud();
577
+ decodingStatus = decoder.DecodeArrayToPointCloud( array, array.byteLength, dracoGeometry );
578
+
579
+ } else {
580
+
581
+ throw new Error( 'THREE.DRACOLoader: Unexpected geometry type.' );
582
+
583
+ }
584
+
585
+ if ( ! decodingStatus.ok() || dracoGeometry.ptr === 0 ) {
586
+
587
+ throw new Error( 'THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg() );
588
+
589
+ }
590
+
591
+ const geometry = { index: null, attributes: [] };
592
+
593
+ // Gather all vertex attributes.
594
+ for ( const attributeName in attributeIDs ) {
595
+
596
+ const attributeType = self[ attributeTypes[ attributeName ] ];
597
+
598
+ let attribute;
599
+ let attributeID;
600
+
601
+ // A Draco file may be created with default vertex attributes, whose attribute IDs
602
+ // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
603
+ // a Draco file may contain a custom set of attributes, identified by known unique
604
+ // IDs. glTF files always do the latter, and `.drc` files typically do the former.
605
+ if ( taskConfig.useUniqueIDs ) {
606
+
607
+ attributeID = attributeIDs[ attributeName ];
608
+ attribute = decoder.GetAttributeByUniqueId( dracoGeometry, attributeID );
609
+
610
+ } else {
611
+
612
+ attributeID = decoder.GetAttributeId( dracoGeometry, draco[ attributeIDs[ attributeName ] ] );
613
+
614
+ if ( attributeID === - 1 ) continue;
615
+
616
+ attribute = decoder.GetAttribute( dracoGeometry, attributeID );
617
+
618
+ }
619
+
620
+ const attributeResult = decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute );
621
+
622
+ if ( attributeName === 'color' ) {
623
+
624
+ attributeResult.vertexColorSpace = taskConfig.vertexColorSpace;
625
+
626
+ }
627
+
628
+ geometry.attributes.push( attributeResult );
629
+
630
+ }
631
+
632
+ // Add index.
633
+ if ( geometryType === draco.TRIANGULAR_MESH ) {
634
+
635
+ geometry.index = decodeIndex( draco, decoder, dracoGeometry );
636
+
637
+ }
638
+
639
+ draco.destroy( dracoGeometry );
640
+
641
+ return geometry;
642
+
643
+ }
644
+
645
+ function decodeIndex( draco, decoder, dracoGeometry ) {
646
+
647
+ const numFaces = dracoGeometry.num_faces();
648
+ const numIndices = numFaces * 3;
649
+ const byteLength = numIndices * 4;
650
+
651
+ const ptr = draco._malloc( byteLength );
652
+ decoder.GetTrianglesUInt32Array( dracoGeometry, byteLength, ptr );
653
+ const index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice();
654
+ draco._free( ptr );
655
+
656
+ return { array: index, itemSize: 1 };
657
+
658
+ }
659
+
660
+ function decodeAttribute( draco, decoder, dracoGeometry, attributeName, TypedArray, attribute ) {
661
+
662
+ const count = dracoGeometry.num_points();
663
+ const itemSize = attribute.num_components();
664
+ const dracoDataType = getDracoDataType( draco, TypedArray );
665
+
666
+ // Reference: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#data-alignment
667
+ const srcByteStride = itemSize * TypedArray.BYTES_PER_ELEMENT;
668
+ const dstByteStride = Math.ceil( srcByteStride / 4 ) * 4;
669
+
670
+ const dstStride = dstByteStride / TypedArray.BYTES_PER_ELEMENT
671
+
672
+ const srcByteLength = count * srcByteStride;
673
+ const dstByteLength = count * dstByteStride;
674
+
675
+ const ptr = draco._malloc( srcByteLength );
676
+ decoder.GetAttributeDataArrayForAllPoints( dracoGeometry, attribute, dracoDataType, srcByteLength, ptr );
677
+
678
+ const srcArray = new TypedArray( draco.HEAPF32.buffer, ptr, srcByteLength / TypedArray.BYTES_PER_ELEMENT );
679
+ let dstArray;
680
+
681
+ if ( srcByteStride === dstByteStride ) {
682
+
683
+ // THREE.BufferAttribute
684
+
685
+ dstArray = srcArray.slice();
686
+
687
+ } else {
688
+
689
+ // THREE.InterleavedBufferAttribute
690
+
691
+ dstArray = new TypedArray( dstByteLength / TypedArray.BYTES_PER_ELEMENT );
692
+
693
+ let dstOffset = 0
694
+
695
+ for ( let i = 0, il = srcArray.length; i < il; i++ ) {
696
+
697
+ for ( let j = 0; j < itemSize; j++ ) {
698
+
699
+ dstArray[ dstOffset + j ] = srcArray[ i * itemSize + j ]
700
+
701
+ }
702
+
703
+ dstOffset += dstStride;
704
+
705
+ }
706
+
707
+ }
708
+
709
+ draco._free( ptr );
710
+
711
+ return {
712
+ name: attributeName,
713
+ count: count,
714
+ itemSize: itemSize,
715
+ array: dstArray,
716
+ stride: dstStride
717
+ };
718
+
719
+ }
720
+
721
+ function getDracoDataType( draco, TypedArray ) {
722
+
723
+ switch ( TypedArray ) {
724
+
725
+ case Float32Array: return draco.DT_FLOAT32;
726
+ case Int8Array: return draco.DT_INT8;
727
+ case Int16Array: return draco.DT_INT16;
728
+ case Int32Array: return draco.DT_INT32;
729
+ case Uint8Array: return draco.DT_UINT8;
730
+ case Uint16Array: return draco.DT_UINT16;
731
+ case Uint32Array: return draco.DT_UINT32;
732
+
733
+ }
734
+
735
+ }
736
+
737
+ }
738
+
739
+ export { DRACOLoader };