fast-mesh-wasm 0.5.0 → 0.5.2

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 +91 -3
  2. package/dist/{api-BUy7FRx7.js → api-4kz45-Mq.js} +2 -3
  3. package/dist/{client-CE6RvmvB.js → client-BIPPznBZ.js} +108 -24
  4. package/dist/{client-pv0Fwvl4.d.ts → client-Uo7hHvD8.d.ts} +25 -11
  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-BS8i5U8J.js} +41 -11
  9. package/dist/io.d.ts +306 -0
  10. package/dist/io.js +1479 -0
  11. package/dist/{mesh-RtPVmPQy.d.ts → mesh-CqAIuOxU.d.ts} +15 -6
  12. package/dist/{mesh-zj7-wJBw.js → mesh-hPWBQPaN.js} +31 -8
  13. package/dist/node.d.ts +3 -5
  14. package/dist/node.js +4 -5
  15. package/dist/{protocol-z-jeCUGO.d.ts → protocol-BHAI0xiA.d.ts} +25 -7
  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-like-YcY08oii.d.ts → scene-like-CavrKbpQ.d.ts} +590 -47
  23. package/dist/{scene-DyYdEQdy.js → scene-rsfM06St.js} +711 -21
  24. package/dist/{snapshot-Cf6NgDl7.js → snapshot-BkbGPspK.js} +1 -2
  25. package/dist/{store-C5nzCpxy.d.ts → store-CZwml1K3.d.ts} +5 -10
  26. package/dist/{store-Z6A2HPih.js → store-m9l0Al-m.js} +9 -12
  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-CdOArjcB.js} +6 -8
  32. package/dist/wasm/fast_mesh_wasm.d.ts +113 -8
  33. package/dist/wasm/fast_mesh_wasm.js +267 -8
  34. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  35. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +13 -1
  36. package/dist/wasm-threads/fast_mesh_wasm.d.ts +113 -8
  37. package/dist/wasm-threads/fast_mesh_wasm.js +268 -9
  38. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
  39. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +13 -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
@@ -1,6 +1,6 @@
1
- import { s as setMemory, t as FastMeshError } from "./core-Cke_kZ2e.js";
2
- import { i as useWasmScene, n as fieldSteps, r as meshAdds, t as Scene } from "./scene-DyYdEQdy.js";
3
- import { a as supersedes, n as isLastWins, r as keyOf, t as isInit } from "./protocol-DkhGNP0h.js";
1
+ import { s as setMemory, t as FastMeshError } from "./core-4OcWKu3r.js";
2
+ import { i as useWasmScene, n as fieldSteps, r as meshAdds, t as Scene } from "./scene-rsfM06St.js";
3
+ import { a as supersedes, n as isLastWins, r as keyOf, t as isInit } from "./protocol-Ci9LLiwO.js";
4
4
  /**
5
5
  * A module importing a shared memory `e.m` (1 page, at most 2), exporting
6
6
  * `grow(pages)` (`memory.grow`: the old size in pages, or -1),
@@ -323,8 +323,7 @@ async function startEngine(init, loaders, isolated = globalThis.crossOriginIsola
323
323
  ...probeFailed === void 0 ? {} : { probeFailed }
324
324
  };
325
325
  }
326
- //#endregion
327
- //#region src/worker/engine.ts
326
+ // src/worker/engine.ts
328
327
  /** The default {@link EngineOptions.yieldMs}. */
329
328
  const YIELD_MS = 4;
330
329
  /** The default {@link EngineOptions.staleGuardMs}. */
@@ -480,10 +479,11 @@ const STRIDE = {
480
479
  normals: 3,
481
480
  colors: 4,
482
481
  values: 1,
482
+ uvs: 2,
483
483
  indices: 3
484
484
  };
485
485
  /** A buffer's dirty ranges: the values change with the colours. */
486
- const rangesOf = (c, name) => c[name === "values" ? "colors" : name];
486
+ const rangesOf = (c, name) => c[name === "values" ? "colors" : name] ?? [];
487
487
  /** Copies the dirty elements of `view` into a fresh buffer: the whole view for `"all"`. */
488
488
  function copyRanges(view, ranges, stride) {
489
489
  if (ranges === "all") return view.slice().buffer;
@@ -815,6 +815,8 @@ var Engine = class {
815
815
  const indices = new Uint32Array(req.indices);
816
816
  if (positions.length % 3 !== 0) throw invalid("positions length must be a multiple of 3");
817
817
  if (indices.length % 3 !== 0) throw invalid("indices length must be a multiple of 3");
818
+ const uvs = req.uvs === void 0 ? void 0 : new Float32Array(req.uvs);
819
+ if (uvs !== void 0 && uvs.length !== 2 * positions.length / 3) throw invalid("uvs need 2 values per vertex");
818
820
  const token = this.#meshAdds.beginUpload(positions.length / 3, indices.length / 3, {
819
821
  ...req.options,
820
822
  mode: "eager"
@@ -832,6 +834,13 @@ var Engine = class {
832
834
  this.#meshAdds.pushIndices(token, indices.subarray(at, at + n));
833
835
  await this.#maybeYield();
834
836
  }
837
+ if (uvs !== void 0) {
838
+ const u = Math.max(1, Math.floor(bytes / uvs.BYTES_PER_ELEMENT));
839
+ for (let at = 0; at < uvs.length; at += u) {
840
+ this.#meshAdds.pushUvs(token, uvs.subarray(at, at + u));
841
+ await this.#maybeYield();
842
+ }
843
+ }
835
844
  } catch (e) {
836
845
  try {
837
846
  this.#meshAdds.drop(token);
@@ -875,6 +884,7 @@ var Engine = class {
875
884
  case "edit":
876
885
  case "repair": return this.#pending(req.id);
877
886
  case "join": return this.#pending(req.target, req.source);
887
+ case "register": return this.#pending(req.moving, req.fixed);
878
888
  case "coloring": return this.#pending(req.id) || req.rule !== null && this.#fieldPending(req.rule?.field);
879
889
  case "fetchFieldValues": return this.#fieldPending(req.field);
880
890
  case "field": return req.desc !== void 0 ? this.#pending(req.desc.on, ...req.desc.to) : this.#fieldPending(req.field);
@@ -1186,7 +1196,8 @@ var Engine = class {
1186
1196
  * Whether the queued `req` makes a field step unit over `meshes` (the
1187
1197
  * meshes its fields are on and measured to) stale (§6.1): a drag move
1188
1198
  * (only with `moves`: within the starvation guard), a drag cancel or a
1189
- * placement, an edit, repair, compaction, join or removal of one of them,
1199
+ * placement, a registration of one of them, an edit, repair, compaction,
1200
+ * join or removal of one of them,
1190
1201
  * an undo or redo, or the removal of a field between two of them.
1191
1202
  */
1192
1203
  #makesStale(req, meshes, moves) {
@@ -1198,6 +1209,7 @@ var Engine = class {
1198
1209
  case "compact":
1199
1210
  case "removeMesh": return meshes.has(req.id);
1200
1211
  case "join": return meshes.has(req.target) || meshes.has(req.source);
1212
+ case "register": return meshes.has(req.moving);
1201
1213
  case "undo":
1202
1214
  case "redo": return true;
1203
1215
  case "field": {
@@ -1539,7 +1551,8 @@ var Engine = class {
1539
1551
  const positions = req.f64 ? new Float64Array(req.positions) : new Float32Array(req.positions);
1540
1552
  const h = s.addMesh(positions, new Uint32Array(req.indices), {
1541
1553
  ...req.options,
1542
- mode: "eager"
1554
+ mode: "eager",
1555
+ ...req.uvs === void 0 ? {} : { uvs: new Float32Array(req.uvs) }
1543
1556
  });
1544
1557
  this.#meshes.set(req.id, h);
1545
1558
  this.#meshIds.set(h, req.id);
@@ -1569,13 +1582,23 @@ var Engine = class {
1569
1582
  });
1570
1583
  return;
1571
1584
  }
1585
+ case "register": {
1586
+ const value = s.register(this.#mesh(req.moving), this.#mesh(req.fixed), req.payload);
1587
+ b.replies.push({
1588
+ qid: req.qid,
1589
+ ok: true,
1590
+ value
1591
+ });
1592
+ return;
1593
+ }
1572
1594
  case "compact":
1573
1595
  s.compact(this.#mesh(req.id));
1574
1596
  return;
1575
1597
  case "setPlacement":
1576
1598
  s.setPlacement(this.#mesh(req.id), {
1577
1599
  rotation: req.rotation,
1578
- translation: req.translation
1600
+ translation: req.translation,
1601
+ ...req.scale === void 0 ? {} : { scale: req.scale }
1579
1602
  });
1580
1603
  return;
1581
1604
  case "drag":
@@ -1656,7 +1679,8 @@ var Engine = class {
1656
1679
  if (req.rotation === void 0 || req.translation === void 0) throw invalid("a drag move needs a rotation and a translation");
1657
1680
  return {
1658
1681
  rotation: req.rotation,
1659
- translation: req.translation
1682
+ translation: req.translation,
1683
+ ...req.scale === void 0 ? {} : { scale: req.scale }
1660
1684
  };
1661
1685
  };
1662
1686
  if (req.phase === "begin") {
@@ -1799,6 +1823,10 @@ var Engine = class {
1799
1823
  const a = args;
1800
1824
  return s.analyze(this.#mesh(a.mesh), a.options);
1801
1825
  }
1826
+ case "measure": {
1827
+ const a = args;
1828
+ return s.measure(this.#mesh(a.mesh));
1829
+ }
1802
1830
  case "fieldTargetStatus": {
1803
1831
  const a = args;
1804
1832
  return s.fieldTargetStatus(this.#field(a.field));
@@ -1824,6 +1852,7 @@ var Engine = class {
1824
1852
  normals: v.normals()?.slice() ?? null,
1825
1853
  colors: v.colors()?.slice() ?? null,
1826
1854
  values: v.values?.()?.slice() ?? null,
1855
+ uvs: v.uvs()?.slice() ?? null,
1827
1856
  indices: v.indices().slice(),
1828
1857
  placement: s.placement(h),
1829
1858
  matrix4: Array.from(s.matrix4(h))
@@ -1853,6 +1882,7 @@ var Engine = class {
1853
1882
  id,
1854
1883
  rotation: p.rotation,
1855
1884
  translation: p.translation,
1885
+ scale: p.scale,
1856
1886
  matrix4: Array.from(s.matrix4(c.mesh))
1857
1887
  });
1858
1888
  }
@@ -1943,6 +1973,7 @@ var Engine = class {
1943
1973
  normals: c.normals,
1944
1974
  colors: c.colors,
1945
1975
  indices: c.indices,
1976
+ ...c.uvs === void 0 ? {} : { uvs: c.uvs },
1946
1977
  fields: c.fieldsChanged.map((f) => this.#fieldIds.get(f)),
1947
1978
  sections: c.sectionsChanged.map((x) => this.#sectionIds.get(x)),
1948
1979
  vertexSlots: 0,
@@ -1974,5 +2005,4 @@ var Engine = class {
1974
2005
  return wire;
1975
2006
  }
1976
2007
  };
1977
- //#endregion
1978
2008
  export { YIELD_MS as a, loadEngine as c, STEP_POINTS as i, startEngine as l, BACKGROUND_ADD_TRIANGLES as n, runEngine as o, STALE_GUARD_MS as r, serveEngine as s, ADD_STEP_WORK as t, probeSharedGrowth as u };
package/dist/io.d.ts ADDED
@@ -0,0 +1,306 @@
1
+ import { Ct as MeshHandle, t as SceneLike } from "./scene-like-CavrKbpQ.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 `TEXCOORD_0` as float pairs where the mesh has UVs, `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, colors and UVs 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
+ /** TEX_COORD bits, over the UVs' range. Defaults to `16`. */
117
+ uv?: number;
118
+ /**
119
+ * TEX_COORD bits. Defaults to `12`. Validated but currently unused: UVs
120
+ * ride issue #137 (there is no UV channel to encode yet).
121
+ */
122
+ texCoord?: number;
123
+ }
124
+ /** The Draco encoder settings shared by {@link encodeDraco} and the `draco: true` {@link exportGLTF} path. */
125
+ export interface DracoCompressionOptions {
126
+ /**
127
+ * A ready draco3d encoder module, as `createEncoderModule` resolves. When
128
+ * omitted, one is created from the `draco3d` package and shared across
129
+ * calls. Pass one in to reuse a module (or to supply the `.wasm` in an
130
+ * environment the default lookup cannot reach, like a bundled Worker).
131
+ */
132
+ encoderModule?: unknown;
133
+ /**
134
+ * The encoder `.wasm` bytes, forwarded to `createEncoderModule` when the
135
+ * shared module is created. Bundlers cannot always locate draco3d's own
136
+ * `.wasm` next to its glue (Vite workers, inlined builds): fetch the
137
+ * encoder asset (a `?url` import of `draco3d/draco_encoder.wasm`) and pass
138
+ * its bytes here. Ignored when `encoderModule` is given.
139
+ */
140
+ wasmBinary?: Uint8Array | ArrayBuffer;
141
+ /** Per-attribute quantization bits (each an integer 1..30). */
142
+ quantizationBits?: DracoQuantizationBits;
143
+ /**
144
+ * How hard the encoder squeezes: an integer 0..10, defaulting to `5`.
145
+ * Higher levels encode slower into fewer bytes (the encode/decode speeds
146
+ * run at `10 - level`); `0` is the fastest encode.
147
+ */
148
+ compressionLevel?: number;
149
+ /**
150
+ * Keep the decoded faces (and vertices) in input order via sequential
151
+ * encoding. Defaults to `false`: the edgebreaker reorders faces while
152
+ * compressing better. Either way the same triangles decode.
153
+ */
154
+ preserveFaceOrder?: boolean;
155
+ }
156
+ /** Options of {@link encodeDraco}: the encoder settings plus the extra attributes. */
157
+ export interface DracoEncodeOptions extends DracoCompressionOptions {
158
+ /**
159
+ * Per-vertex normals: 3 numbers per vertex, encoded as the NORMAL
160
+ * attribute. Must match `positions` in length.
161
+ */
162
+ normals?: ArrayLike<number>;
163
+ /**
164
+ * Per-vertex colors: 4 bytes (RGBA) per vertex, encoded as a normalized
165
+ * COLOR attribute. Each value must be an integer 0..255.
166
+ */
167
+ colors?: ArrayLike<number>;
168
+ /** Texture coordinates: 2 finite numbers per vertex. */
169
+ uvs?: ArrayLike<number>;
170
+ }
171
+ /**
172
+ * Encodes a triangle mesh into standalone Draco bytes (a `.drc` file):
173
+ * positions always, plus the `normals`/`colors`/`uvs` options when given.
174
+ * Positions encode as 32-bit floats (wider inputs narrow).
175
+ *
176
+ * The draco3d encoder (WASM) initializes on first use; its module is shared
177
+ * across calls. Needs the `draco3d` package installed unless `options`
178
+ * supplies the module or its `.wasm`.
179
+ *
180
+ * Decodes through {@link decodeDraco} (positions, faces and UVs: normals and
181
+ * colors need draco3d's own decoder).
182
+ */
183
+ export declare function encodeDraco(positions: ArrayLike<number>, indices: ArrayLike<number>, options?: DracoEncodeOptions): Promise<Uint8Array>;
184
+ /**
185
+ * An imported glTF mesh: one scene mesh per glTF (node, primitive). The
186
+ * node's world placement is baked into `positions` (world coordinates, like
187
+ * the exporters write with the default `applyPlacement`) and also returned
188
+ * as `placement` (column-major, like `scene.matrix4`).
189
+ *
190
+ * Only uncompressed buffers are read. `KHR_draco_mesh_compression`
191
+ * primitives throw (decode them with {@link importGLTFAsync}), as do sparse
192
+ * accessors. External (non-embedded) `.bin` buffers load through
193
+ * {@link importGLTFAsync}'s `resolveBuffer`. Animations, skins, materials
194
+ * beyond per-vertex colors and `TEXCOORD_1` and up are skipped: the documented
195
+ * subset.
196
+ */
197
+ export interface ImportedMesh {
198
+ /** The node name, else the mesh name, else `"mesh"` (deduplicated). */
199
+ name: string;
200
+ /** World positions: 3 f64 per vertex, node placements baked in. */
201
+ positions: Float64Array;
202
+ /** 3 vertex ids per triangle. */
203
+ indices: Uint32Array;
204
+ /** The node's world matrix: 16 numbers, column-major. */
205
+ placement: Float64Array;
206
+ /** RGBA bytes per vertex from `COLOR_0`, or `null` without colors. */
207
+ colors: Uint8Array | null;
208
+ /**
209
+ * 2 floats per vertex from `TEXCOORD_0` (`scene.addMesh`'s `uvs`), or `null`
210
+ * without UVs. In glTF's convention: `v` points down from the image's top.
211
+ */
212
+ uvs: Float32Array | null;
213
+ }
214
+ /**
215
+ * Reads a glTF 2.0 asset: a binary `.glb`, or a `.gltf` JSON whose buffers
216
+ * are embedded base64 data URIs. Every triangle primitive of every mesh
217
+ * instanced by the default scene becomes one mesh (node transforms composed
218
+ * down the hierarchy, so placements are preserved); other primitive modes
219
+ * throw, except `TRIANGLE_STRIP` and `TRIANGLE_FAN`, which are expanded.
220
+ *
221
+ * @throws When the container is malformed, a buffer is external (load it
222
+ * with {@link importGLTFAsync} and a `resolveBuffer` callback), a primitive
223
+ * is Draco-compressed (decode it with {@link importGLTFAsync}) or not a
224
+ * triangle mesh, or the file holds no triangle meshes.
225
+ */
226
+ export declare function importGLTF(bytes: Uint8Array | ArrayBuffer): ImportedMesh[];
227
+ /**
228
+ * A Draco-decoded triangle mesh: 3 f64 positions per vertex and 3 Uint32
229
+ * vertex ids per triangle, ready for `scene.addMesh`.
230
+ */
231
+ export interface DecodedDracoMesh {
232
+ /** 3 f64 per vertex. */
233
+ positions: Float64Array;
234
+ /** 3 vertex ids per triangle. */
235
+ indices: Uint32Array;
236
+ /** 2 floats per vertex from the texture-coordinate attribute, or `null` without one. */
237
+ uvs: Float32Array | null;
238
+ }
239
+ /**
240
+ * Supplies an external glTF buffer's bytes, by its `uri` as declared
241
+ * (`"model.bin"`, a relative path, an absolute URL: passed through
242
+ * verbatim). Called at most once per external buffer, in buffer order.
243
+ *
244
+ * The importer never fetches: this callback is the only way external bytes
245
+ * enter (fetch / FileReader / fs on the caller's side). Cap sizes here —
246
+ * reject URIs outside the asset's directory and buffers past a byte budget
247
+ * before returning them; oversized or hostile buffers otherwise land in
248
+ * memory unchecked.
249
+ */
250
+ export type GltfBufferResolver = (uri: string) => Uint8Array | ArrayBuffer | Promise<Uint8Array | ArrayBuffer>;
251
+ /** Options of {@link decodeDraco} and {@link importGLTFAsync}. */
252
+ export interface DracoDecodeOptions {
253
+ /**
254
+ * A ready draco3d decoder module, as `createDecoderModule` resolves. When
255
+ * omitted, one is created from the `draco3d` package and shared across
256
+ * calls. Pass one in to reuse a module (or to supply the `.wasm` in an
257
+ * environment the default lookup cannot reach, like a bundled Worker).
258
+ */
259
+ decoderModule?: unknown;
260
+ /**
261
+ * The decoder `.wasm` bytes, forwarded to `createDecoderModule` when the
262
+ * shared module is created. Bundlers cannot always locate draco3d's own
263
+ * `.wasm` next to its glue (Vite workers, inlined builds): fetch the
264
+ * decoder asset (a `?url` import of `draco3d/draco_decoder.wasm`) and pass
265
+ * its bytes here. Ignored when `decoderModule` is given.
266
+ */
267
+ wasmBinary?: Uint8Array | ArrayBuffer;
268
+ }
269
+ /** Options of {@link importGLTFAsync}: Draco decoding plus external buffers. */
270
+ export interface GltfImportOptions extends DracoDecodeOptions {
271
+ /**
272
+ * Loads external (non-embedded) `.bin` buffers, by URI. Without one, an
273
+ * external buffer throws. Embedded data URIs and the GLB body chunk never
274
+ * consult it.
275
+ */
276
+ resolveBuffer?: GltfBufferResolver;
277
+ }
278
+ /**
279
+ * Decodes a standalone Draco file (`.drc`): a compressed triangle mesh. Only
280
+ * triangle meshes decode; point clouds throw.
281
+ *
282
+ * The draco3d decoder (WASM) initializes on first use; its module is shared
283
+ * across calls. Needs the `draco3d` package installed unless `options`
284
+ * supplies the module or its `.wasm`.
285
+ *
286
+ * @throws When the bytes are not a Draco triangle mesh.
287
+ */
288
+ export declare function decodeDraco(bytes: Uint8Array | ArrayBuffer, options?: DracoDecodeOptions): Promise<DecodedDracoMesh>;
289
+ /**
290
+ * Reads a glTF 2.0 asset like {@link importGLTF}: `KHR_draco_mesh_compression`
291
+ * primitives decode through the draco3d decoder (WASM), and external
292
+ * (non-embedded) `.bin` buffers load through `options.resolveBuffer`. A Draco
293
+ * primitive's positions and faces come from its compressed buffer view
294
+ * (attribute ids from the extension); its node placement still bakes into
295
+ * world positions and its `TEXCOORD_0` UVs, while colors read as `null` (compressed attributes beyond
296
+ * POSITION are not mapped).
297
+ *
298
+ * Primitives without the extension decode synchronously in place, so assets
299
+ * without Draco never initialize the decoder.
300
+ *
301
+ * @throws When the container is malformed, a buffer is external without a
302
+ * `resolveBuffer` (or its bytes cannot be resolved), a Draco primitive fails
303
+ * to decode, a primitive is not a triangle mesh, or the file holds no
304
+ * triangle meshes.
305
+ */
306
+ export declare function importGLTFAsync(bytes: Uint8Array | ArrayBuffer, options?: GltfImportOptions): Promise<ImportedMesh[]>;