fast-mesh-wasm 0.5.0 → 0.5.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 (47) hide show
  1. package/README.md +51 -3
  2. package/dist/{api-BUy7FRx7.js → api-4kz45-Mq.js} +2 -3
  3. package/dist/{client-CE6RvmvB.js → client-C61Kku4i.js} +62 -18
  4. package/dist/{client-pv0Fwvl4.d.ts → client-tP6R9foI.d.ts} +13 -8
  5. package/dist/{colormap-DxGMYVfs.js → colormap-Dr5V3bvs.js} +1 -2
  6. package/dist/{core-Cke_kZ2e.js → core-4OcWKu3r.js} +2 -2
  7. package/dist/{core-D2X9GPfK.d.ts → core-CJ9D6U5A.d.ts} +1 -3
  8. package/dist/{engine-DLQAL9GT.js → engine-X1Awlc5y.js} +13 -8
  9. package/dist/io.d.ts +294 -0
  10. package/dist/io.js +1395 -0
  11. package/dist/{mesh-zj7-wJBw.js → mesh-CWvrjO8S.js} +3 -4
  12. package/dist/{mesh-RtPVmPQy.d.ts → mesh-D3fv56nF.d.ts} +1 -3
  13. package/dist/node.d.ts +3 -5
  14. package/dist/node.js +4 -5
  15. package/dist/{protocol-z-jeCUGO.d.ts → protocol-BGQAB0op.d.ts} +6 -3
  16. package/dist/{protocol-DkhGNP0h.js → protocol-Ci9LLiwO.js} +1 -2
  17. package/dist/r3f.d.ts +22 -6
  18. package/dist/r3f.js +28 -19
  19. package/dist/{react-CTADh3NN.js → react-DzrtrzZy.js} +4 -6
  20. package/dist/react.d.ts +4 -6
  21. package/dist/react.js +1 -1
  22. package/dist/{scene-DyYdEQdy.js → scene-BnkCS0sv.js} +592 -16
  23. package/dist/{scene-like-YcY08oii.d.ts → scene-like-BzkDNHCy.d.ts} +410 -42
  24. package/dist/{snapshot-Cf6NgDl7.js → snapshot-BkbGPspK.js} +1 -2
  25. package/dist/{store-C5nzCpxy.d.ts → store-BKFzSykN.d.ts} +3 -9
  26. package/dist/{store-Z6A2HPih.js → store-CEd2y2KS.js} +7 -9
  27. package/dist/store.d.ts +2 -4
  28. package/dist/store.js +4 -5
  29. package/dist/three.d.ts +2 -6
  30. package/dist/three.js +4 -6
  31. package/dist/{views-Dh3aWc2q.js → views-CUBMOK0U.js} +5 -8
  32. package/dist/wasm/fast_mesh_wasm.d.ts +77 -6
  33. package/dist/wasm/fast_mesh_wasm.js +167 -6
  34. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  35. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +8 -1
  36. package/dist/wasm-threads/fast_mesh_wasm.d.ts +77 -6
  37. package/dist/wasm-threads/fast_mesh_wasm.js +167 -6
  38. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
  39. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +8 -1
  40. package/dist/web.d.ts +3 -5
  41. package/dist/web.js +4 -5
  42. package/dist/worker-engine.d.ts +1 -7
  43. package/dist/worker-engine.js +1 -1
  44. package/dist/worker-entry.js +2 -3
  45. package/dist/worker.d.ts +2 -2
  46. package/dist/worker.js +1 -1
  47. package/package.json +16 -4
package/dist/io.d.ts ADDED
@@ -0,0 +1,294 @@
1
+ import { _t as MeshHandle, t as SceneLike } from "./scene-like-BzkDNHCy.js";
2
+ /** Shared by every exporter: whether local render coordinates are mapped to the world. */
3
+ export interface ExportOptions {
4
+ /**
5
+ * Map the mesh through `scene.matrix4(mesh)` (placement and origin) before
6
+ * writing, so the file holds world coordinates. Defaults to `true`; pass
7
+ * `false` for the local render coordinates in `views(mesh).positions()`.
8
+ * Normals follow through the inverse-transpose rotation.
9
+ */
10
+ applyPlacement?: boolean;
11
+ }
12
+ /** Options of {@link exportSTL}. */
13
+ export interface StlExportOptions extends ExportOptions {
14
+ /**
15
+ * Write binary STL (one 50-byte record per triangle). Defaults to `true`;
16
+ * `false` writes ASCII STL (`solid name ... endsolid name`).
17
+ */
18
+ binary?: boolean;
19
+ /** The `solid` name (ASCII) and 80-byte header text (binary). Defaults to `"mesh"`. */
20
+ name?: string;
21
+ }
22
+ /** Options of {@link exportOBJ}. */
23
+ export interface ObjExportOptions extends ExportOptions {
24
+ /** The `o` object name. Defaults to `"mesh"`. */
25
+ name?: string;
26
+ }
27
+ /** Options of {@link exportPLY}. */
28
+ export interface PlyExportOptions extends ExportOptions {
29
+ /**
30
+ * Write binary little-endian PLY (`binary_little_endian 1.0`). Defaults to
31
+ * `true`; `false` writes ASCII (`ascii`) PLY.
32
+ */
33
+ binary?: boolean;
34
+ }
35
+ /** Options of {@link exportGLTF}. */
36
+ export interface GltfExportOptions extends ExportOptions {
37
+ /**
38
+ * Write a binary `.glb` (JSON + BIN chunks). Defaults to `true`; `false`
39
+ * writes a `.gltf` JSON whose buffer is an embedded base64 data URI, so the
40
+ * result stays a single value either way.
41
+ */
42
+ binary?: boolean;
43
+ /** The glTF asset's `generator` string. Defaults to `"fast-mesh-wasm"`. */
44
+ generator?: string;
45
+ /** The mesh and node names. Defaults to `"mesh"`. */
46
+ name?: string;
47
+ /**
48
+ * Compress the primitive with Draco (`KHR_draco_mesh_compression`) instead
49
+ * of raw buffer views. Defaults to `false`; with `true` the call is async
50
+ * (a `Promise<Uint8Array>`), encoding through the draco3d encoder (WASM),
51
+ * which lazy-loads like the decoder. Reads back through
52
+ * {@link importGLTFAsync}.
53
+ */
54
+ draco?: boolean;
55
+ /**
56
+ * The Draco encoder settings (quantization, compression level, face-order
57
+ * preservation, encoder module). Only read when `draco` is `true`; the
58
+ * attributes themselves always come from the mesh.
59
+ */
60
+ dracoOptions?: DracoCompressionOptions;
61
+ }
62
+ /**
63
+ * Binary STL: an 80-byte header, the triangle count, then 50 bytes per
64
+ * triangle (normal, three corners as f32, a zero attribute word).
65
+ */
66
+ export declare function exportSTL(scene: SceneLike, mesh: MeshHandle, options?: StlExportOptions): Uint8Array;
67
+ /**
68
+ * Wavefront OBJ: `v` positions (with `r g b` 0..1 suffixes where the mesh
69
+ * is colored, a widely read extension), `vn` normals where present, and
70
+ * `f` faces (`v//vn` with normals, else `v`). 1-based.
71
+ */
72
+ export declare function exportOBJ(scene: SceneLike, mesh: MeshHandle, options?: ObjExportOptions): Uint8Array;
73
+ /**
74
+ * Stanford PLY: `x y z` floats, `nx ny nz` where normals exist, `red green
75
+ * blue alpha` uchar where colors exist, and `vertex_indices` faces.
76
+ */
77
+ export declare function exportPLY(scene: SceneLike, mesh: MeshHandle, options?: PlyExportOptions): Uint8Array;
78
+ /**
79
+ * glTF 2.0: one node, one mesh, one `TRIANGLES` primitive with `POSITION`
80
+ * (plus `NORMAL` where present and `COLOR_0` as normalized RGBA bytes where
81
+ * the mesh is colored). Binary (default) returns a `.glb`; `binary: false`
82
+ * a `.gltf` JSON with the buffer embedded as a base64 data URI.
83
+ *
84
+ * Pass `draco: true` for `KHR_draco_mesh_compression` instead: the call
85
+ * becomes async (a `Promise<Uint8Array>`), encoding through the draco3d
86
+ * encoder (WASM), which lazy-loads like the decoder.
87
+ */
88
+ export declare function exportGLTF(scene: SceneLike, mesh: MeshHandle, options?: GltfExportOptions & {
89
+ draco?: false;
90
+ }): Uint8Array;
91
+ /**
92
+ * glTF 2.0 with `draco: true`: the same node, mesh and `TRIANGLES`
93
+ * primitive, but the positions (plus normals and colors where present) ride
94
+ * a Draco bitstream in one buffer view instead of raw buffer views. The
95
+ * primitive's accessors describe the decoded shape (POSITION keeps its
96
+ * min/max); `extensionsUsed`/`extensionsRequired` name the extension.
97
+ *
98
+ * The draco3d encoder (WASM) initializes on first use; its module is shared
99
+ * across calls. Needs the `draco3d` package installed unless `dracoOptions`
100
+ * supplies the module or its `.wasm`. Reads back through
101
+ * {@link importGLTFAsync} (compressed attributes beyond POSITION stay
102
+ * unmapped there); the sync {@link importGLTF} still throws on it.
103
+ */
104
+ export declare function exportGLTF(scene: SceneLike, mesh: MeshHandle, options: GltfExportOptions & {
105
+ draco: true;
106
+ }): Promise<Uint8Array>;
107
+ export declare function exportGLTF(scene: SceneLike, mesh: MeshHandle, options?: GltfExportOptions): Uint8Array | Promise<Uint8Array>;
108
+ /** Per-attribute Draco quantization bits: fewer bits compress smaller, at coarser values. */
109
+ export interface DracoQuantizationBits {
110
+ /** POSITION bits. Defaults to `14`. */
111
+ position?: number;
112
+ /** NORMAL bits. Defaults to `10`. */
113
+ normal?: number;
114
+ /** COLOR bits. Defaults to `8` (lossless for byte colors). */
115
+ color?: number;
116
+ /**
117
+ * TEX_COORD bits. Defaults to `12`. Validated but currently unused: UVs
118
+ * ride issue #137 (there is no UV channel to encode yet).
119
+ */
120
+ texCoord?: number;
121
+ }
122
+ /** The Draco encoder settings shared by {@link encodeDraco} and the `draco: true` {@link exportGLTF} path. */
123
+ export interface DracoCompressionOptions {
124
+ /**
125
+ * A ready draco3d encoder module, as `createEncoderModule` resolves. When
126
+ * omitted, one is created from the `draco3d` package and shared across
127
+ * calls. Pass one in to reuse a module (or to supply the `.wasm` in an
128
+ * environment the default lookup cannot reach, like a bundled Worker).
129
+ */
130
+ encoderModule?: unknown;
131
+ /**
132
+ * The encoder `.wasm` bytes, forwarded to `createEncoderModule` when the
133
+ * shared module is created. Bundlers cannot always locate draco3d's own
134
+ * `.wasm` next to its glue (Vite workers, inlined builds): fetch the
135
+ * encoder asset (a `?url` import of `draco3d/draco_encoder.wasm`) and pass
136
+ * its bytes here. Ignored when `encoderModule` is given.
137
+ */
138
+ wasmBinary?: Uint8Array | ArrayBuffer;
139
+ /** Per-attribute quantization bits (each an integer 1..30). */
140
+ quantizationBits?: DracoQuantizationBits;
141
+ /**
142
+ * How hard the encoder squeezes: an integer 0..10, defaulting to `5`.
143
+ * Higher levels encode slower into fewer bytes (the encode/decode speeds
144
+ * run at `10 - level`); `0` is the fastest encode.
145
+ */
146
+ compressionLevel?: number;
147
+ /**
148
+ * Keep the decoded faces (and vertices) in input order via sequential
149
+ * encoding. Defaults to `false`: the edgebreaker reorders faces while
150
+ * compressing better. Either way the same triangles decode.
151
+ */
152
+ preserveFaceOrder?: boolean;
153
+ }
154
+ /** Options of {@link encodeDraco}: the encoder settings plus the extra attributes. */
155
+ export interface DracoEncodeOptions extends DracoCompressionOptions {
156
+ /**
157
+ * Per-vertex normals: 3 numbers per vertex, encoded as the NORMAL
158
+ * attribute. Must match `positions` in length.
159
+ */
160
+ normals?: ArrayLike<number>;
161
+ /**
162
+ * Per-vertex colors: 4 bytes (RGBA) per vertex, encoded as a normalized
163
+ * COLOR attribute. Each value must be an integer 0..255.
164
+ */
165
+ colors?: ArrayLike<number>;
166
+ }
167
+ /**
168
+ * Encodes a triangle mesh into standalone Draco bytes (a `.drc` file):
169
+ * positions always, plus the `normals`/`colors` options when given.
170
+ * Positions encode as 32-bit floats (wider inputs narrow).
171
+ *
172
+ * The draco3d encoder (WASM) initializes on first use; its module is shared
173
+ * across calls. Needs the `draco3d` package installed unless `options`
174
+ * supplies the module or its `.wasm`.
175
+ *
176
+ * Decodes through {@link decodeDraco} (positions and faces only: it maps
177
+ * POSITION alone, so normals and colors need draco3d's own decoder).
178
+ */
179
+ export declare function encodeDraco(positions: ArrayLike<number>, indices: ArrayLike<number>, options?: DracoEncodeOptions): Promise<Uint8Array>;
180
+ /**
181
+ * An imported glTF mesh: one scene mesh per glTF (node, primitive). The
182
+ * node's world placement is baked into `positions` (world coordinates, like
183
+ * the exporters write with the default `applyPlacement`) and also returned
184
+ * as `placement` (column-major, like `scene.matrix4`).
185
+ *
186
+ * Only uncompressed buffers are read. `KHR_draco_mesh_compression`
187
+ * primitives throw (decode them with {@link importGLTFAsync}), as do sparse
188
+ * accessors. External (non-embedded) `.bin` buffers load through
189
+ * {@link importGLTFAsync}'s `resolveBuffer`. Animations, skins and materials
190
+ * beyond per-vertex colors are skipped: the documented subset.
191
+ */
192
+ export interface ImportedMesh {
193
+ /** The node name, else the mesh name, else `"mesh"` (deduplicated). */
194
+ name: string;
195
+ /** World positions: 3 f64 per vertex, node placements baked in. */
196
+ positions: Float64Array;
197
+ /** 3 vertex ids per triangle. */
198
+ indices: Uint32Array;
199
+ /** The node's world matrix: 16 numbers, column-major. */
200
+ placement: Float64Array;
201
+ /** RGBA bytes per vertex from `COLOR_0`, or `null` without colors. */
202
+ colors: Uint8Array | null;
203
+ }
204
+ /**
205
+ * Reads a glTF 2.0 asset: a binary `.glb`, or a `.gltf` JSON whose buffers
206
+ * are embedded base64 data URIs. Every triangle primitive of every mesh
207
+ * instanced by the default scene becomes one mesh (node transforms composed
208
+ * down the hierarchy, so placements are preserved); other primitive modes
209
+ * throw, except `TRIANGLE_STRIP` and `TRIANGLE_FAN`, which are expanded.
210
+ *
211
+ * @throws When the container is malformed, a buffer is external (load it
212
+ * with {@link importGLTFAsync} and a `resolveBuffer` callback), a primitive
213
+ * is Draco-compressed (decode it with {@link importGLTFAsync}) or not a
214
+ * triangle mesh, or the file holds no triangle meshes.
215
+ */
216
+ export declare function importGLTF(bytes: Uint8Array | ArrayBuffer): ImportedMesh[];
217
+ /**
218
+ * A Draco-decoded triangle mesh: 3 f64 positions per vertex and 3 Uint32
219
+ * vertex ids per triangle, ready for `scene.addMesh`.
220
+ */
221
+ export interface DecodedDracoMesh {
222
+ /** 3 f64 per vertex. */
223
+ positions: Float64Array;
224
+ /** 3 vertex ids per triangle. */
225
+ indices: Uint32Array;
226
+ }
227
+ /**
228
+ * Supplies an external glTF buffer's bytes, by its `uri` as declared
229
+ * (`"model.bin"`, a relative path, an absolute URL: passed through
230
+ * verbatim). Called at most once per external buffer, in buffer order.
231
+ *
232
+ * The importer never fetches: this callback is the only way external bytes
233
+ * enter (fetch / FileReader / fs on the caller's side). Cap sizes here —
234
+ * reject URIs outside the asset's directory and buffers past a byte budget
235
+ * before returning them; oversized or hostile buffers otherwise land in
236
+ * memory unchecked.
237
+ */
238
+ export type GltfBufferResolver = (uri: string) => Uint8Array | ArrayBuffer | Promise<Uint8Array | ArrayBuffer>;
239
+ /** Options of {@link decodeDraco} and {@link importGLTFAsync}. */
240
+ export interface DracoDecodeOptions {
241
+ /**
242
+ * A ready draco3d decoder module, as `createDecoderModule` resolves. When
243
+ * omitted, one is created from the `draco3d` package and shared across
244
+ * calls. Pass one in to reuse a module (or to supply the `.wasm` in an
245
+ * environment the default lookup cannot reach, like a bundled Worker).
246
+ */
247
+ decoderModule?: unknown;
248
+ /**
249
+ * The decoder `.wasm` bytes, forwarded to `createDecoderModule` when the
250
+ * shared module is created. Bundlers cannot always locate draco3d's own
251
+ * `.wasm` next to its glue (Vite workers, inlined builds): fetch the
252
+ * decoder asset (a `?url` import of `draco3d/draco_decoder.wasm`) and pass
253
+ * its bytes here. Ignored when `decoderModule` is given.
254
+ */
255
+ wasmBinary?: Uint8Array | ArrayBuffer;
256
+ }
257
+ /** Options of {@link importGLTFAsync}: Draco decoding plus external buffers. */
258
+ export interface GltfImportOptions extends DracoDecodeOptions {
259
+ /**
260
+ * Loads external (non-embedded) `.bin` buffers, by URI. Without one, an
261
+ * external buffer throws. Embedded data URIs and the GLB body chunk never
262
+ * consult it.
263
+ */
264
+ resolveBuffer?: GltfBufferResolver;
265
+ }
266
+ /**
267
+ * Decodes a standalone Draco file (`.drc`): a compressed triangle mesh. Only
268
+ * triangle meshes decode; point clouds throw.
269
+ *
270
+ * The draco3d decoder (WASM) initializes on first use; its module is shared
271
+ * across calls. Needs the `draco3d` package installed unless `options`
272
+ * supplies the module or its `.wasm`.
273
+ *
274
+ * @throws When the bytes are not a Draco triangle mesh.
275
+ */
276
+ export declare function decodeDraco(bytes: Uint8Array | ArrayBuffer, options?: DracoDecodeOptions): Promise<DecodedDracoMesh>;
277
+ /**
278
+ * Reads a glTF 2.0 asset like {@link importGLTF}: `KHR_draco_mesh_compression`
279
+ * primitives decode through the draco3d decoder (WASM), and external
280
+ * (non-embedded) `.bin` buffers load through `options.resolveBuffer`. A Draco
281
+ * primitive's positions and faces come from its compressed buffer view
282
+ * (attribute ids from the extension); its node placement still bakes into
283
+ * world positions, while colors read as `null` (compressed attributes beyond
284
+ * POSITION are not mapped).
285
+ *
286
+ * Primitives without the extension decode synchronously in place, so assets
287
+ * without Draco never initialize the decoder.
288
+ *
289
+ * @throws When the container is malformed, a buffer is external without a
290
+ * `resolveBuffer` (or its bytes cannot be resolved), a Draco primitive fails
291
+ * to decode, a primitive is not a triangle mesh, or the file holds no
292
+ * triangle meshes.
293
+ */
294
+ export declare function importGLTFAsync(bytes: Uint8Array | ArrayBuffer, options?: GltfImportOptions): Promise<ImportedMesh[]>;