@loaders.gl/draco 4.2.0-alpha.5 → 4.2.0-beta.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.
@@ -9,10 +9,11 @@ import {VERSION} from './lib/utils/version';
9
9
 
10
10
  export type DracoLoaderOptions = LoaderOptions & {
11
11
  draco?: DracoParseOptions & {
12
+ /** @deprecated WASM decoding is faster but JS is more backwards compatible */
12
13
  decoderType?: 'wasm' | 'js';
14
+ /** @deprecated Specify where to load the Draco decoder library */
13
15
  libraryPath?: string;
14
- extraAttributes?;
15
- attributeNameEntry?: string;
16
+ /** Override the URL to the worker bundle (by default loads from unpkg.com) */
16
17
  workerUrl?: string;
17
18
  };
18
19
  };
@@ -20,7 +21,9 @@ export type DracoLoaderOptions = LoaderOptions & {
20
21
  /**
21
22
  * Worker loader for Draco3D compressed geometries
22
23
  */
23
- export const DracoLoader: Loader<DracoMesh, never, DracoLoaderOptions> = {
24
+ export const DracoLoader = {
25
+ dataType: null as unknown as DracoMesh,
26
+ batchType: null as never,
24
27
  name: 'Draco',
25
28
  id: 'draco',
26
29
  module: 'draco',
@@ -39,4 +42,4 @@ export const DracoLoader: Loader<DracoMesh, never, DracoLoaderOptions> = {
39
42
  attributeNameEntry: undefined
40
43
  }
41
44
  }
42
- };
45
+ } as const satisfies Loader<DracoMesh, never, DracoLoaderOptions>;
@@ -29,7 +29,7 @@ const DEFAULT_DRACO_WRITER_OPTIONS = {
29
29
  /**
30
30
  * Exporter for Draco3D compressed geometries
31
31
  */
32
- export const DracoWriter: WriterWithEncoder<DracoMesh, unknown, DracoWriterOptions> = {
32
+ export const DracoWriter = {
33
33
  name: 'DRACO',
34
34
  id: 'draco',
35
35
  module: 'draco',
@@ -39,7 +39,7 @@ export const DracoWriter: WriterWithEncoder<DracoMesh, unknown, DracoWriterOptio
39
39
  draco: DEFAULT_DRACO_WRITER_OPTIONS
40
40
  },
41
41
  encode
42
- };
42
+ } as const satisfies WriterWithEncoder<DracoMesh, unknown, DracoWriterOptions>;
43
43
 
44
44
  async function encode(data: DracoMesh, options: DracoWriterOptions = {}): Promise<ArrayBuffer> {
45
45
  // Dynamically load draco
package/src/index.ts CHANGED
@@ -45,10 +45,10 @@ export {DracoWorkerLoader};
45
45
  /**
46
46
  * Loader for Draco3D compressed geometries
47
47
  */
48
- export const DracoLoader: LoaderWithParser<DracoMesh, never, DracoLoaderOptions> = {
48
+ export const DracoLoader = {
49
49
  ...DracoWorkerLoader,
50
50
  parse
51
- };
51
+ } as const satisfies LoaderWithParser<DracoMesh, never, DracoLoaderOptions>;
52
52
 
53
53
  async function parse(arrayBuffer: ArrayBuffer, options?: DracoLoaderOptions): Promise<DracoMesh> {
54
54
  const {draco} = await loadDracoDecoderModule(options);
@@ -273,7 +273,7 @@ export default class DracoBuilder {
273
273
  attributeName: string,
274
274
  attribute: TypedArray,
275
275
  vertexCount: number
276
- ) {
276
+ ): number {
277
277
  if (!ArrayBuffer.isView(attribute)) {
278
278
  return -1;
279
279
  }
@@ -317,8 +317,16 @@ export default class DracoBuilder {
317
317
  return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));
318
318
 
319
319
  case Float32Array:
320
- default:
321
320
  return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
321
+
322
+ // case Float64Array:
323
+ // Add attribute does not seem to be exposed
324
+ // return builder.AddAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
325
+
326
+ default:
327
+ // eslint-disable-next-line no-console
328
+ console.warn('Unsupported attribute type', attribute);
329
+ return -1;
322
330
  }
323
331
  }
324
332
 
@@ -35,14 +35,12 @@ export async function loadDracoDecoderModule(options) {
35
35
 
36
36
  // Check if a bundled draco3d library has been supplied by application
37
37
  if (modules.draco3d) {
38
- loadDecoderPromise =
39
- loadDecoderPromise ||
40
- modules.draco3d.createDecoderModule({}).then((draco) => {
41
- return {draco};
42
- });
38
+ loadDecoderPromise ||= modules.draco3d.createDecoderModule({}).then((draco) => {
39
+ return {draco};
40
+ });
43
41
  } else {
44
42
  // If not, dynamically load the WASM script from our CDN
45
- loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);
43
+ loadDecoderPromise ||= loadDracoDecoder(options);
46
44
  }
47
45
  return await loadDecoderPromise;
48
46
  }
@@ -52,14 +50,12 @@ export async function loadDracoEncoderModule(options) {
52
50
 
53
51
  // Check if a bundled draco3d library has been supplied by application
54
52
  if (modules.draco3d) {
55
- loadEncoderPromise =
56
- loadEncoderPromise ||
57
- modules.draco3d.createEncoderModule({}).then((draco) => {
58
- return {draco};
59
- });
53
+ loadEncoderPromise ||= modules.draco3d.createEncoderModule({}).then((draco) => {
54
+ return {draco};
55
+ });
60
56
  } else {
61
57
  // If not, dynamically load the WASM script from our CDN
62
- loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);
58
+ loadEncoderPromise ||= loadDracoEncoder(options);
63
59
  }
64
60
  return await loadEncoderPromise;
65
61
  }
@@ -28,18 +28,17 @@ import type {
28
28
  import {getMeshBoundingBox} from '@loaders.gl/schema';
29
29
  import {getDracoSchema} from './utils/get-draco-schema';
30
30
 
31
- /**
32
- * @param topology - How triangle indices should be generated (mesh only)
33
- * @param attributeNameEntry
34
- * @param extraAttributes
35
- * @param quantizedAttributes
36
- * @param octahedronAttributes
37
- */
31
+ /** Options to control draco parsing */
38
32
  export type DracoParseOptions = {
33
+ /** How triangle indices should be generated (mesh only) */
39
34
  topology?: 'triangle-list' | 'triangle-strip';
35
+ /** Specify which attribute metadata entry stores the attribute name */
40
36
  attributeNameEntry?: string;
37
+ /** Names and ids of extra attributes to include in the output */
41
38
  extraAttributes?: {[uniqueId: string]: number};
39
+ /** Skip transforms specific quantized attributes */
42
40
  quantizedAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];
41
+ /** Skip transforms specific octahedron encoded attributes */
43
42
  octahedronAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];
44
43
  };
45
44
 
@@ -65,7 +64,11 @@ const DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
65
64
  4: Uint16Array,
66
65
  5: Int32Array,
67
66
  6: Uint32Array,
67
+ // 7: BigInt64Array,
68
+ // 8: BigUint64Array,
68
69
  9: Float32Array
70
+ // 10: Float64Array
71
+ // 11: BOOL - What array type do we use for this?
69
72
  };
70
73
 
71
74
  const INDEX_ITEM_SIZE = 4;
@@ -293,14 +296,17 @@ export default class DracoParser {
293
296
  for (const loaderAttribute of Object.values(loaderData.attributes)) {
294
297
  const attributeName = this._deduceAttributeName(loaderAttribute, options);
295
298
  loaderAttribute.name = attributeName;
296
- const {value, size} = this._getAttributeValues(dracoGeometry, loaderAttribute);
297
- attributes[attributeName] = {
298
- value,
299
- size,
300
- byteOffset: loaderAttribute.byte_offset,
301
- byteStride: loaderAttribute.byte_stride,
302
- normalized: loaderAttribute.normalized
303
- };
299
+ const values = this._getAttributeValues(dracoGeometry, loaderAttribute);
300
+ if (values) {
301
+ const {value, size} = values;
302
+ attributes[attributeName] = {
303
+ value,
304
+ size,
305
+ byteOffset: loaderAttribute.byte_offset,
306
+ byteStride: loaderAttribute.byte_stride,
307
+ normalized: loaderAttribute.normalized
308
+ };
309
+ }
304
310
  }
305
311
 
306
312
  return attributes;
@@ -350,8 +356,13 @@ export default class DracoParser {
350
356
  _getAttributeValues(
351
357
  dracoGeometry: Mesh | PointCloud,
352
358
  attribute: DracoAttribute
353
- ): {value: TypedArray; size: number} {
359
+ ): {value: TypedArray; size: number} | null {
354
360
  const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
361
+ if (!TypedArrayCtor) {
362
+ // eslint-disable-next-line no-console
363
+ console.warn(`DRACO: Unsupported attribute type ${attribute.data_type}`);
364
+ return null;
365
+ }
355
366
  const numComponents = attribute.num_components;
356
367
  const numPoints = dracoGeometry.num_points();
357
368
  const numValues = numPoints * numComponents;