@draco-rust/decoder 0.2.0 → 0.3.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.
package/README.md CHANGED
@@ -60,7 +60,9 @@ if (!result.success) throw new Error(result.error);
60
60
  const { index, attributes } = result; // attributes[i]: { name, array, itemSize, normalized, ... }
61
61
  ```
62
62
 
63
- Without the second argument every attribute comes back in its own type.
63
+ Without the second argument every attribute comes back in its own type. The
64
+ index is a `Uint32Array`; a third argument `{ index: "auto" }` makes it a
65
+ `Uint16Array` wherever the points number at most 65536, half the bytes.
64
66
 
65
67
  ### On workers
66
68
 
@@ -80,6 +82,10 @@ them. The stream is copied to the worker; `pool.decode(bytes, requests, {
80
82
  transfer: true })` hands over the buffer itself instead. The pool runs on Web
81
83
  Workers, on Node's worker threads (Node 20.16 and later), and from a CDN. With
82
84
  `workers: 0`, or where there are no workers, it decodes on the calling thread.
85
+ `pool.decode` also takes `index`, as `decode_draco` does, and an `AbortSignal`
86
+ as `signal`: aborting rejects the promise at once. A decode a worker has
87
+ already started still runs to its end and its result is dropped; one not yet
88
+ sent is never sent.
83
89
  A bundler that follows `new URL("./worker.js", import.meta.url)`, as Vite and
84
90
  webpack do, emits the worker on its own.
85
91
 
@@ -114,7 +120,7 @@ package's other entries do not need it.
114
120
  ### From a CDN, without a bundler
115
121
 
116
122
  ```js
117
- import init, { parse_drc_bytes } from "https://cdn.jsdelivr.net/npm/@draco-rust/decoder@0.2/mesh/index.js";
123
+ import init, { parse_drc_bytes } from "https://cdn.jsdelivr.net/npm/@draco-rust/decoder@0.3/mesh/index.js";
118
124
  await init(); // finds index_bg.wasm next to the script
119
125
  ```
120
126
 
@@ -141,4 +147,4 @@ For a subpath entry, resolve its own file, for example
141
147
  - Licensed under Apache-2.0, like Draco.
142
148
  ## This build
143
149
 
144
- `@draco-rust/decoder@0.2.0` was built from draco-rust commit `8650e1ca`, with draco-core 2.3.2, draco-io 0.6.0, draco-gltf 0.7.0.
150
+ `@draco-rust/decoder@0.3.1` was built from draco-rust commit `18d16cdc`, with draco-core 2.3.3, draco-io 0.6.1, draco-gltf 0.7.0.
package/index.d.ts CHANGED
@@ -3,8 +3,8 @@
3
3
 
4
4
  /** The name of a typed array `decode_draco` can convert an attribute to. */
5
5
  export type DracoArrayType =
6
- | "Int8Array" | "Uint8Array" | "Int16Array" | "Uint16Array"
7
- | "Int32Array" | "Uint32Array" | "Float32Array";
6
+ | "Int8Array" | "Uint8Array" | "Int16Array" | "Uint16Array"
7
+ | "Int32Array" | "Uint32Array" | "Float32Array";
8
8
 
9
9
  /** A Draco attribute type, as `semantic` names it. */
10
10
  export type DracoSemantic = "POSITION" | "NORMAL" | "COLOR" | "TEX_COORD" | "GENERIC";
@@ -14,62 +14,58 @@ export type DracoSemantic = "POSITION" | "NORMAL" | "COLOR" | "TEX_COORD" | "GEN
14
14
  * attribute of that type. `name` is handed back unchanged.
15
15
  */
16
16
  export interface DracoAttributeRequest {
17
- name?: string;
18
- id?: number;
19
- semantic?: DracoSemantic;
20
- type?: DracoArrayType;
17
+ name?: string;
18
+ id?: number;
19
+ semantic?: DracoSemantic;
20
+ type?: DracoArrayType;
21
21
  }
22
22
 
23
23
  /** The typed arrays an attribute can come back in. */
24
24
  export type DracoArray =
25
- | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array
26
- | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
25
+ | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array
26
+ | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
27
27
 
28
28
  export interface DracoAttribute {
29
- /** The request's `name`, or else the name the stream's metadata gives it. */
30
- name?: string;
31
- uniqueId: number;
32
- semantic: DracoSemantic;
33
- array: DracoArray;
34
- itemSize: number;
35
- normalized: boolean;
29
+ /** The request's `name`, or else the name the stream's metadata gives it. */
30
+ name?: string;
31
+ uniqueId: number;
32
+ semantic: DracoSemantic;
33
+ array: DracoArray;
34
+ itemSize: number;
35
+ normalized: boolean;
36
36
  }
37
37
 
38
- export interface DracoDecodeResult {
39
- success: boolean;
40
- error?: string;
41
- warnings: string[];
42
- geometry?: "mesh" | "point_cloud";
43
- /** Triangle corners for a mesh, `null` for a point cloud. */
44
- index: Uint32Array | null;
45
- attributes: DracoAttribute[];
38
+ export interface DracoDecodeOptions {
39
+ /**
40
+ * The index's array: `"Uint32Array"`, the default, or `"auto"`, which uses a
41
+ * `Uint16Array` when every point number fits, at most 65536 points, and
42
+ * halves what a worker sends back.
43
+ */
44
+ index?: "Uint32Array" | "auto";
46
45
  }
47
46
 
48
-
47
+ export interface DracoDecodeResult {
48
+ success: boolean;
49
+ error?: string;
50
+ warnings: string[];
51
+ geometry?: "mesh" | "point_cloud";
52
+ /** Triangle corners for a mesh, `null` for a point cloud. */
53
+ index: Uint32Array | Uint16Array | null;
54
+ attributes: DracoAttribute[];
55
+ }
49
56
 
50
57
  /**
51
- * Decodes a Draco stream and returns its attributes as typed arrays.
52
- *
53
- * `attributes` is `undefined` for every attribute in its own component type,
54
- * or an array of requests `{ name, id, semantic, type }`:
55
- *
56
- * - `id`, a unique id, finds that attribute, as glTF's
57
- * `KHR_draco_mesh_compression` names them; a missing one is an error.
58
- * - `semantic` (`"POSITION"`, `"NORMAL"`, `"COLOR"`, `"TEX_COORD"` or
59
- * `"GENERIC"`) finds the first attribute of that type instead, as a `.drc`
60
- * file is read; a missing one is left out.
61
- * - `type`, a typed array's name such as `"Float32Array"` or
62
- * `"Uint16Array"`, converts the values the way upstream's
63
- * `GetAttributeDataArrayForAllPoints` does; without it the values keep
64
- * their own type. A value the type cannot hold is an error.
65
- *
66
- * The result is `{ success, error, warnings, geometry, index, attributes }`,
67
- * where `geometry` is `"mesh"` or `"point_cloud"` as the stream's header says,
68
- * `index` a `Uint32Array` of triangle corners for a mesh and `null` for a
69
- * point cloud, and each attribute `{ name, uniqueId, semantic, array,
70
- * itemSize, normalized }`.
58
+ * Decodes a Draco stream and returns its attributes as typed arrays: every
59
+ * attribute in its own type, or the ones `attributes` requests, converted as
60
+ * upstream's `GetAttributeDataArrayForAllPoints` converts them.
71
61
  */
72
- export function decode_draco(data: Uint8Array, attributes: DracoAttributeRequest[] | undefined): DracoDecodeResult;
62
+ export function decode_draco(
63
+ data: Uint8Array,
64
+ attributes?: DracoAttributeRequest[],
65
+ options?: DracoDecodeOptions,
66
+ ): DracoDecodeResult;
67
+
68
+
73
69
 
74
70
  /**
75
71
  * Install the panic hook, so a panic reads as a message rather than a trap.
@@ -94,38 +90,38 @@ export function version(): string;
94
90
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
95
91
 
96
92
  export interface InitOutput {
97
- readonly memory: WebAssembly.Memory;
98
- readonly decode_draco: (a: number, b: number, c: number) => number;
99
- readonly init: () => void;
100
- readonly parse_drc_bytes: (a: number, b: number) => number;
101
- readonly supported_extensions: (a: number) => void;
102
- readonly version: (a: number) => void;
103
- readonly __wbindgen_export: (a: number, b: number) => number;
104
- readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
105
- readonly __wbindgen_export3: (a: number) => void;
106
- readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
107
- readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
108
- readonly __wbindgen_start: () => void;
93
+ readonly memory: WebAssembly.Memory;
94
+ readonly decode_draco: (a: number, b: number, c: number, d: number) => number;
95
+ readonly parse_drc_bytes: (a: number, b: number) => number;
96
+ readonly supported_extensions: (a: number) => void;
97
+ readonly version: (a: number) => void;
98
+ readonly init: () => void;
99
+ readonly __wbindgen_export: (a: number, b: number) => number;
100
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
101
+ readonly __wbindgen_export3: (a: number) => void;
102
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
103
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
104
+ readonly __wbindgen_start: () => void;
109
105
  }
110
106
 
111
107
  export type SyncInitInput = BufferSource | WebAssembly.Module;
112
108
 
113
109
  /**
114
- * Instantiates the given `module`, which can either be bytes or
115
- * a precompiled `WebAssembly.Module`.
116
- *
117
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
118
- *
119
- * @returns {InitOutput}
120
- */
110
+ * Instantiates the given `module`, which can either be bytes or
111
+ * a precompiled `WebAssembly.Module`.
112
+ *
113
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
114
+ *
115
+ * @returns {InitOutput}
116
+ */
121
117
  export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
122
118
 
123
119
  /**
124
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
125
- * for everything else, calls `WebAssembly.instantiate` directly.
126
- *
127
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
128
- *
129
- * @returns {Promise<InitOutput>}
130
- */
120
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
121
+ * for everything else, calls `WebAssembly.instantiate` directly.
122
+ *
123
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
124
+ *
125
+ * @returns {Promise<InitOutput>}
126
+ */
131
127
  export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;