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/README.md CHANGED
@@ -8,6 +8,8 @@ Fast triangle mesh utilities for JavaScript and TypeScript, written in Rust and
8
8
 
9
9
  **[Live demo](https://yoondonggeun.github.io/fast-mesh-wasm/)**: the [showcase app](examples/showcase) in your browser.
10
10
 
11
+ **[API reference](https://yoondonggeun.github.io/fast-mesh-wasm/api/)**: the [TypeScript API](https://yoondonggeun.github.io/fast-mesh-wasm/api/js/) of the `fast-mesh-wasm` package and the [Rust API](https://yoondonggeun.github.io/fast-mesh-wasm/api/rust/) of the workspace crates, rebuilt from `main` on every push. Task-oriented recipes live in the [cookbook](docs/cookbook).
12
+
11
13
  - Works in browsers (Vite, webpack, Next.js), Node.js and Bun
12
14
  - Installs the same way with npm, pnpm and bun. No native build step, no install scripts, zero dependencies
13
15
  - Full TypeScript types and inline docs, generated from the Rust source
@@ -202,7 +204,7 @@ const closest = scene.meshDistance(upper, lower); // { distance, a, b, ... }
202
204
  scene.free(); // or `using scene = new Scene()`
203
205
  ```
204
206
 
205
- Errors are `FastMeshError`s with a `code` (`UNKNOWN_MESH`, `INVALID_ARGUMENT`, `STALE_BVH`, ...). After a trap inside the WebAssembly module every later call throws `INSTANCE_POISONED`. A view is only valid until the next scene call that may allocate or move buffers: a kept view may read other data or be empty, so re-acquire views after any scene call. `new Scene({ debug: true })` makes views warn when they are read after such a call. Mesh edits (`scene.edit`), `analyze`, `repair`, sections (`addSection`, `section`, `sectionGap`) and `findContacts` are documented in the types.
207
+ Errors are `FastMeshError`s with a `code` (`UNKNOWN_MESH`, `INVALID_ARGUMENT`, `STALE_BVH`, ...). After a trap inside the WebAssembly module every later call throws `INSTANCE_POISONED`. A view is only valid until the next scene call that may allocate or move buffers: a kept view may read other data or be empty, so re-acquire views after any scene call. `new Scene({ debug: true })` makes views warn when they are read after such a call. Mesh edits (`scene.edit`), `analyze`, `measure`, `repair`, sections (`addSection`, `section`, `sectionGap`) and `findContacts` are documented in the types.
206
208
 
207
209
  ### Contact groups: fields to several meshes
208
210
 
@@ -293,7 +295,7 @@ const values = await scene.fetchFieldValues(gap); // `fieldValues` on Scene
293
295
  - **Requests run in order.** A newer colouring, section plane/meshes/fill or drag move drops the older one if it has not started yet, so fast toggling settles on the last state without doing the steps in between. Edits, repairs, `setPlacement`, adds, removals and undo/redo are never dropped. Each `setPlacement` is an undo step: for pointer-rate updates use a drag. Long work runs in steps: the Worker yields every few milliseconds during a field build, a field update or a large add, so newer batches are received (and coalesced) meanwhile.
294
296
  - **Drags are optimistic.** `scene.drag(mesh).move(pose)` moves the placement mirror at once, so the object follows the pointer; colours and sections catch up when the Worker's result arrives. In 9a a key's status covers only requests made under that key: a drag, `setPlacement` or edit puts its own key (`placement:<id>`, `edit:<id>`) into `"computing"`, not the `display:<id>` or `section:<id>:*` keys of the state that catches up after it. `end()` and `cancel()` return at once; `cancel()` restores the start pose and records nothing.
295
297
  - **Wide-range colouring during a drag.** After each batch the Worker recomputes the fields the batch made due in small steps, and drops the recompute when a newer move, `setPlacement`, edit, repair, compact, undo/redo or removal of either mesh is already queued; other requests wait for it. A pose's colours are applied all at once, never partly. So while the pointer keeps moving and one recompute takes longer than a frame, newer moves drop the recompute, until 200 ms have passed since the last colours were applied: then the recompute under way finishes and is shown, and the newest pose follows. During a sustained drag the colours therefore update about every 200 ms plus one recompute, each update exactly one pose, and when the drag ends (`end()`) the last pose's colours arrive within about one recompute (measured: one at 1M, but about 1.5 at 10M when most of the mesh is in range): the end drops a recompute kept for an older pose. A pointer that only pauses, without ending the drag, may wait up to two recomputes. Edits, undo/redo, removals and cancels always drop a stale recompute. `fetchFieldValues()` and `fieldStatus()` first bring every due field up to date in one go, which cannot be dropped, so do not poll them during a drag. On two touching 1M-triangle meshes with `maxDistance` 8, a recompute takes from about 0.07 s to 0.7 s depending on how much of the mesh is in range, and about ten times that at 10M; the Worker is never blocked for long, since a recompute runs in steps: about 12 ms at a time at 1M, and 14 to 18 ms for field builds and edits at 10M (see [docs/benchmarks.md](docs/benchmarks.md)). These are single-threaded figures; on a cross-origin isolated page the threaded engine makes a recompute 1.4 to 4.5 times faster (see [Multithreading (COOP/COEP)](#multithreading-coopcoep)). A contact range (a small `maxDistance`) keeps up with the pointer.
296
- - **Queries and anything that returns data** (`raycast`, `closestPoint`, `meshDistance`, `intersects`, `findContacts`, `analyze`, `edit`, `repair`, `fetchFieldValues`, `fieldStatus`, `sectionGap`) return promises. Once a frame loop runs they go out with the next `commitFrame()` (or after 100 ms if no frame comes); before the first `commitFrame()` they are sent on a microtask. For latency-critical picking, keep a light picking copy in a main-thread `Scene`.
298
+ - **Queries and anything that returns data** (`raycast`, `closestPoint`, `meshDistance`, `intersects`, `findContacts`, `analyze`, `measure`, `edit`, `repair`, `fetchFieldValues`, `fieldStatus`, `sectionGap`) return promises. Once a frame loop runs they go out with the next `commitFrame()` (or after 100 ms if no frame comes); before the first `commitFrame()` they are sent on a microtask. For latency-critical picking, keep a light picking copy in a main-thread `Scene`.
297
299
  - **Errors.** A failed state change shows on its key (`status(key).error`, a `FastMeshError` with the same `code` as on `Scene`); a failed promise rejects with it. After a trap inside the Worker every call fails with `INSTANCE_POISONED`, also when it happens on one of the multithreaded engine's pool threads (a panic or a trap in work split across threads); a few kinds of pool-thread failure still cannot be detected (see [Multithreading (COOP/COEP)](#multithreading-coopcoep)). `await scene.restart()` starts a new Worker and replays the scene from the main thread's mirrors: meshes (compacted: slot ids change, handles do not), placements, fields, colourings and sections. History is cleared, and edits or queries that had not finished fail and must be re-issued.
298
300
  - **Not in the Worker scene:** user-opened steps (`beginStep`/`endStep`/`cancelStep`), Lazy and Manual modes (it is always eager) and `takeChanges` (use `onChanges` or the return value of `commitFrame()`). `terminate()` stops the Worker.
299
301
  - **Large meshes.** `addMesh` copies its inputs on the main thread (they are then transferred to the Worker) and, without an `origin` option, scans the positions for the bounding-box centre. That takes about 9 ms for 1M triangles and about 63 ms for 10M (see [docs/benchmarks.md](docs/benchmarks.md)); passing `origin` skips the scan.
@@ -307,7 +309,53 @@ const scene = await createWorkerScene({ workerUrl: "/fast-mesh-wasm/worker-entry
307
309
  const scene = await createWorkerScene({ createWorker: () => new Worker(myUrl, { type: "module" }) });
308
310
  ```
309
311
 
310
- `fast-mesh-wasm/worker` is for browsers and is not supported in Node.js (its tests run it on Node's `worker_threads` as a harness only).
312
+ **Node.js.** `fast-mesh-wasm/worker` has no zero-config Node entry: `createWorkerScene()` with no
313
+ arguments creates a browser `Worker`. In Node use the synchronous `Scene` instead — each call blocks
314
+ until it returns, which is fine for a batch pipeline with no frame budget (repair, distance checks):
315
+
316
+ ```ts
317
+ import { Scene } from "fast-mesh-wasm"; // Node entry: the .wasm loads from disk on import
318
+
319
+ const scene = new Scene(); // no init() needed, as in browsers
320
+ const upper = scene.addMesh(upperPositions, upperIndices);
321
+ const lower = scene.addMesh(lowerPositions, lowerIndices);
322
+ scene.repair(upper, [{ op: "removeDegenerate" }]);
323
+ const gap = scene.addDistanceField({ name: "gap", on: upper, to: lower, maxDistance: 2 });
324
+ scene.setColoring(upper, { field: gap, map: "turbo", range: [-0.5, 1] });
325
+ const distance = scene.meshDistance(upper, lower)?.distance ?? Infinity;
326
+ const colors = scene.views(upper).colors(); // RGBA8, 4 bytes per vertex slot (null when uncoloured)
327
+ ```
328
+
329
+ `WorkerScene` still runs in Node through the `createWorker` option with a small `node:worker_threads`
330
+ adapter. It is always single-threaded there: Node reports no `crossOriginIsolated`, so `threads` is
331
+ ignored and `scene.threads` reads `1`. The bench and test harnesses do this
332
+ (`packages/fast-mesh-wasm/bench/worker-harness.mjs`, `test/harness/node-worker.mjs`); the shape is:
333
+
334
+ ```ts
335
+ import { Worker } from "node:worker_threads";
336
+ import { createWorkerScene } from "fast-mesh-wasm/worker";
337
+
338
+ const scene = await createWorkerScene({
339
+ createWorker: () => {
340
+ const worker = new Worker(workerUrl, { workerData: { serve: true } });
341
+ const listeners: ((e: { data: unknown }) => void)[] = [];
342
+ worker.on("message", (data) => {
343
+ for (const cb of listeners) cb({ data });
344
+ });
345
+ return {
346
+ postMessage: (msg: unknown, transfer?: Transferable[]) => worker.postMessage(msg, transfer),
347
+ addEventListener: (type: string, cb: (e: { data: unknown }) => void) => {
348
+ if (type === "message") listeners.push(cb);
349
+ },
350
+ terminate: () => worker.terminate(),
351
+ };
352
+ },
353
+ });
354
+ ```
355
+
356
+ where the worker script serves the engine on `parentPort` (see `bench/worker-harness.mjs`). Prefer
357
+ the synchronous `Scene` above unless a headless pipeline needs `WorkerScene` parity (status keys,
358
+ background adds).
311
359
 
312
360
  ## Multithreading (COOP/COEP)
313
361
 
@@ -1,6 +1,6 @@
1
- import { n as call, r as ensureInitialized, s as setMemory } from "./core-Cke_kZ2e.js";
1
+ import { n as call, r as ensureInitialized, s as setMemory } from "./core-4OcWKu3r.js";
2
2
  import * as wasm from "./wasm/fast_mesh_wasm.js";
3
- //#region src/api.ts
3
+ // src/api.ts
4
4
  /**
5
5
  * Called by the entry point once the WebAssembly module is instantiated, with
6
6
  * what `initSync` / the default init returned; keeps its memory for views.
@@ -60,5 +60,4 @@ function computeBounds(positions) {
60
60
  ]
61
61
  };
62
62
  }
63
- //#endregion
64
63
  export { computeVertexNormals as n, markInitialized as r, computeBounds as t };
@@ -1,7 +1,7 @@
1
- import { o as reportListenerError, t as FastMeshError } from "./core-Cke_kZ2e.js";
2
- import { a as FieldHandle, c as rotationMatrix, l as targetsOf, o as MeshHandle, r as copyRule, s as SectionHandle, t as ViewGuard } from "./views-Dh3aWc2q.js";
3
- import { a as supersedes, n as isLastWins, r as keyOf } from "./protocol-DkhGNP0h.js";
4
- //#region src/worker/client.ts
1
+ import { o as reportListenerError, t as FastMeshError } from "./core-4OcWKu3r.js";
2
+ import { a as FieldHandle, c as rotationMatrix, l as targetsOf, o as MeshHandle, r as copyRule, s as SectionHandle, t as ViewGuard } from "./views-CUBMOK0U.js";
3
+ import { a as supersedes, n as isLastWins, r as keyOf } from "./protocol-Ci9LLiwO.js";
4
+ // src/worker/client.ts
5
5
  /**
6
6
  * Starts a Worker running the scene engine and resolves once it is ready.
7
7
  * Rejects with `INSTANCE_POISONED` when the Worker could not load fast-mesh.
@@ -33,6 +33,8 @@ async function createWorkerScene(options = {}) {
33
33
  if (skipped && debug) console.warn(THREADS_UNAVAILABLE);
34
34
  return scene;
35
35
  }
36
+ /** The most threads {@link WorkerSceneOptions.threads} asks for; more are clamped. */
37
+ const MAX_THREADS = 64;
36
38
  /**
37
39
  * Set by `WorkerScene`'s static block: makes a scene (the constructor is
38
40
  * private) and returns it with its first Worker's start.
@@ -73,24 +75,45 @@ function transferOf(batch) {
73
75
  }
74
76
  /** The most failed requests kept for `restart()`. */
75
77
  const FAILED_LOG_LIMIT = 1e4;
76
- /** `placement · translate(origin)`, column-major, as `Scene.matrix4`. */
77
- function poseOf(rotation, translation, origin) {
78
+ /**
79
+ * `placement · translate(origin)`, column-major, as `Scene.matrix4`: the
80
+ * rotation columns carry the scale and the last column is
81
+ * `rotation · (scale · origin) + translation`, in the same operation order
82
+ * as the engine, so the mirrors stay bit-identical to it.
83
+ */
84
+ function poseOf(rotation, translation, origin, scale) {
78
85
  const r = rotation;
79
86
  const o = origin;
87
+ const s = scale;
80
88
  const m = /* @__PURE__ */ new Float64Array(16);
81
89
  for (let row = 0; row < 3; row++) {
82
- for (let col = 0; col < 3; col++) m[4 * col + row] = r[3 * row + col];
83
- m[12 + row] = r[3 * row] * o[0] + r[3 * row + 1] * o[1] + r[3 * row + 2] * o[2] + translation[row];
90
+ for (let col = 0; col < 3; col++) m[4 * col + row] = s[col] * r[3 * row + col];
91
+ m[12 + row] = r[3 * row] * (s[0] * o[0]) + r[3 * row + 1] * (s[1] * o[1]) + r[3 * row + 2] * (s[2] * o[2]) + translation[row];
84
92
  }
85
93
  m[15] = 1;
86
94
  return {
87
95
  rotation,
88
96
  translation,
97
+ scale,
89
98
  matrix4: m
90
99
  };
91
100
  }
92
101
  function samePose(a, b) {
93
- return a.matrix4.every((v, k) => v === b.matrix4[k]) && a.translation.every((v, k) => v === b.translation[k]);
102
+ return a.matrix4.every((v, k) => v === b.matrix4[k]) && a.translation.every((v, k) => v === b.translation[k]) && a.scale.every((v, k) => v === b.scale[k]);
103
+ }
104
+ /** A placement input's scale as a `Vec3`: `[1, 1, 1]` when omitted, as the engine defaults it. */
105
+ function scaleOf(scale) {
106
+ if (scale === void 0) return [
107
+ 1,
108
+ 1,
109
+ 1
110
+ ];
111
+ if (scale.length !== 3) throw invalid("scale must be 3 numbers");
112
+ return [
113
+ scale[0],
114
+ scale[1],
115
+ scale[2]
116
+ ];
94
117
  }
95
118
  /**
96
119
  * The engine's default origin, the bounding-box centre, or `undefined` when
@@ -754,6 +777,7 @@ var WorkerScene = class WorkerScene {
754
777
  if (st !== void 0) st.pose = {
755
778
  rotation: p.rotation,
756
779
  translation: p.translation,
780
+ scale: p.scale,
757
781
  matrix4: Float64Array.from(p.matrix4)
758
782
  };
759
783
  }
@@ -997,7 +1021,11 @@ var WorkerScene = class WorkerScene {
997
1021
  0,
998
1022
  0,
999
1023
  0
1000
- ], known),
1024
+ ], known, [
1025
+ 1,
1026
+ 1,
1027
+ 1
1028
+ ]),
1001
1029
  local: void 0,
1002
1030
  localUntil: 0,
1003
1031
  requested: void 0,
@@ -1086,7 +1114,10 @@ var WorkerScene = class WorkerScene {
1086
1114
  }
1087
1115
  for (const s of this.#sections.values()) if (!s.removed) s.meshes = s.meshes.filter((m) => m !== st);
1088
1116
  }
1089
- /** Sets a mesh's placement (one undo step); `placement()` follows when the result arrives. */
1117
+ /**
1118
+ * Sets a mesh's placement (one undo step), scale included (`[1, 1, 1]`
1119
+ * when omitted); `placement()` follows when the result arrives.
1120
+ */
1090
1121
  setPlacement(mesh, placement) {
1091
1122
  const st = this.#live(mesh);
1092
1123
  const rotation = rotationMatrix(placement.rotation);
@@ -1097,22 +1128,25 @@ var WorkerScene = class WorkerScene {
1097
1128
  t[1],
1098
1129
  t[2]
1099
1130
  ];
1100
- st.requested = poseOf(rotation, translation, st.origin);
1131
+ const scale = scaleOf(placement.scale);
1132
+ st.requested = poseOf(rotation, translation, st.origin, scale);
1101
1133
  st.requestedUntil = this.#push({
1102
1134
  kind: "setPlacement",
1103
1135
  rev: ++this.#rev,
1104
1136
  id: st.id,
1105
1137
  rotation,
1106
1138
  translation,
1139
+ scale,
1107
1140
  key: `placement:${st.id}`
1108
1141
  });
1109
1142
  }
1110
- /** The mesh's placement as mirrored (a drag's pose while it is held). */
1143
+ /** The mesh's placement as mirrored, scale always present (a drag's pose while it is held). */
1111
1144
  placement(mesh) {
1112
1145
  const p = this.#shown(this.#mirrored(mesh));
1113
1146
  return {
1114
1147
  rotation: [...p.rotation],
1115
- translation: [...p.translation]
1148
+ translation: [...p.translation],
1149
+ scale: [...p.scale]
1116
1150
  };
1117
1151
  }
1118
1152
  /** The column-major world matrix of the mesh's local render coordinates, as mirrored. */
@@ -1219,7 +1253,8 @@ var WorkerScene = class WorkerScene {
1219
1253
  t[1],
1220
1254
  t[2]
1221
1255
  ];
1222
- st.local = poseOf(rotation, translation, st.origin);
1256
+ const scale = scaleOf(placement.scale);
1257
+ st.local = poseOf(rotation, translation, st.origin, scale);
1223
1258
  this.#optimistic.add(st);
1224
1259
  this.#push({
1225
1260
  kind: "drag",
@@ -1228,6 +1263,7 @@ var WorkerScene = class WorkerScene {
1228
1263
  phase: "move",
1229
1264
  rotation,
1230
1265
  translation,
1266
+ scale,
1231
1267
  key
1232
1268
  });
1233
1269
  },
@@ -1266,6 +1302,10 @@ var WorkerScene = class WorkerScene {
1266
1302
  options
1267
1303
  }), (v) => v);
1268
1304
  }
1305
+ /** Scalar measurements of a mesh; see `Scene.measure`. */
1306
+ measure(mesh) {
1307
+ return this.#query("measure", () => ({ mesh: this.#live(mesh).id }), (v) => v);
1308
+ }
1269
1309
  repair(mesh, op) {
1270
1310
  return this.#ask((rev, qid) => ({
1271
1311
  kind: "repair",
@@ -1995,7 +2035,11 @@ var WorkerScene = class WorkerScene {
1995
2035
  0,
1996
2036
  0,
1997
2037
  0
1998
- ], st.origin))) continue;
2038
+ ], st.origin, [
2039
+ 1,
2040
+ 1,
2041
+ 1
2042
+ ]))) continue;
1999
2043
  st.requested = pose;
2000
2044
  st.requestedUntil = ++this.#rev;
2001
2045
  if (!samePose(pose, st.pose)) {
@@ -2008,6 +2052,7 @@ var WorkerScene = class WorkerScene {
2008
2052
  id: st.id,
2009
2053
  rotation: pose.rotation,
2010
2054
  translation: pose.translation,
2055
+ scale: pose.scale,
2011
2056
  key: `placement:${st.id}`
2012
2057
  });
2013
2058
  }
@@ -2308,5 +2353,4 @@ function normalised(plane) {
2308
2353
  ]
2309
2354
  };
2310
2355
  }
2311
- //#endregion
2312
- export { watchStatusKeys as i, addFieldKeyed as n, createWorkerScene as r, WorkerScene as t };
2356
+ export { watchStatusKeys as a, createWorkerScene as i, WorkerScene as n, addFieldKeyed as r, MAX_THREADS as t };
@@ -1,7 +1,6 @@
1
- import { D as MeshChange, G as SectionPlane, I as RepairOp, K as SectionResult, M as RayHit, N as RaycastOptions, Q as SectionHandle, R as RepairReportOf, S as FindContactsOptions, T as JoinReport, U as SectionDesc, W as SectionGap, X as FieldHandle, Z as MeshHandle, at as Placement, c as ClosestPointOptions, ct as Positions64, d as Contact, dt as Vec3, et as MeshViews, g as EditOp, h as DragSession, i as AnalyzeOptions, k as MeshDistance, l as ColorRule, n as AddMeshOptions, nt as Indices, ot as PlacementInput, p as DistanceFieldDesc, r as Analysis, s as ClosestHit, t as SceneLike, v as EditResult, w as JoinOptions, y as FieldStatus } from "./scene-like-YcY08oii.js";
2
- import { t as FastMeshError } from "./core-D2X9GPfK.js";
3
- import "./protocol-z-jeCUGO.js";
4
- //#region src/worker/client.d.ts
1
+ import { $ as SectionPlane, A as JoinReport, B as RaycastOptions, C as FieldStatus, Ct as Placement, E as FindContactsOptions, Et as Positions64, F as MeshDistance, K as RepairReportOf, M as MeasureResult, N as MeshChange, Q as SectionGap, S as EditResult, W as RepairOp, Z as SectionDesc, _ as DistanceFieldDesc, _t as MeshHandle, b as EditOp, bt as Indices, c as ClosestHit, et as SectionResult, f as Contact, gt as FieldHandle, ht as MeshViews, i as AnalyzeOptions, k as JoinOptions, kt as Vec3, l as ClosestPointOptions, n as AddMeshOptions, r as Analysis, t as SceneLike, u as ColorRule, vt as SectionHandle, wt as PlacementInput, y as DragSession, z as RayHit } from "./scene-like-BzkDNHCy.js";
2
+ import { t as FastMeshError } from "./core-CJ9D6U5A.js";
3
+ import "./protocol-BGQAB0op.js";
5
4
  /** What {@link WorkerScene} needs of a Worker; a browser `Worker` fits. */
6
5
  interface WorkerLike {
7
6
  postMessage(msg: unknown, transfer?: Transferable[]): void;
@@ -71,6 +70,8 @@ interface KeyStatus {
71
70
  * Rejects with `INSTANCE_POISONED` when the Worker could not load fast-mesh.
72
71
  */
73
72
  declare function createWorkerScene(options?: WorkerSceneOptions): Promise<WorkerScene>;
73
+ /** The most threads {@link WorkerSceneOptions.threads} asks for; more are clamped. */
74
+ declare const MAX_THREADS = 64;
74
75
  /**
75
76
  * A scene whose engine runs in a Worker, from {@link createWorkerScene}. It
76
77
  * mirrors `Scene` (always `"eager"`) with these differences:
@@ -126,9 +127,12 @@ declare class WorkerScene implements SceneLike {
126
127
  * changes nothing, engine-side or here).
127
128
  */
128
129
  join(target: MeshHandle, source: MeshHandle, options: JoinOptions): Promise<JoinReport>;
129
- /** Sets a mesh's placement (one undo step); `placement()` follows when the result arrives. */
130
+ /**
131
+ * Sets a mesh's placement (one undo step), scale included (`[1, 1, 1]`
132
+ * when omitted); `placement()` follows when the result arrives.
133
+ */
130
134
  setPlacement(mesh: MeshHandle, placement: PlacementInput): void;
131
- /** The mesh's placement as mirrored (a drag's pose while it is held). */
135
+ /** The mesh's placement as mirrored, scale always present (a drag's pose while it is held). */
132
136
  placement(mesh: MeshHandle): Placement;
133
137
  /** The column-major world matrix of the mesh's local render coordinates, as mirrored. */
134
138
  matrix4(mesh: MeshHandle): Float64Array;
@@ -158,6 +162,8 @@ declare class WorkerScene implements SceneLike {
158
162
  compact(mesh: MeshHandle): void;
159
163
  /** A report of the mesh's defects; see `Scene.analyze`. */
160
164
  analyze(mesh: MeshHandle, options?: AnalyzeOptions): Promise<Analysis>;
165
+ /** Scalar measurements of a mesh; see `Scene.measure`. */
166
+ measure(mesh: MeshHandle): Promise<MeasureResult>;
161
167
  /** Runs one repair operation, or a list as one transaction; see `Scene.repair`. */
162
168
  repair<const O extends RepairOp>(mesh: MeshHandle, op: O): Promise<RepairReportOf<O>>;
163
169
  repair<const O extends readonly RepairOp[]>(mesh: MeshHandle, ops: O): Promise<{ -readonly [K in keyof O]: RepairReportOf<O[K]>; }>;
@@ -307,5 +313,4 @@ declare class WorkerScene implements SceneLike {
307
313
  */
308
314
  terminate(): void;
309
315
  }
310
- //#endregion
311
- export { createWorkerScene as a, WorkerSceneOptions as i, WorkerLike as n, WorkerScene as r, KeyStatus as t };
316
+ export { WorkerSceneOptions as a, WorkerScene as i, MAX_THREADS as n, createWorkerScene as o, WorkerLike as r, KeyStatus as t };
@@ -1,4 +1,4 @@
1
- //#region src/colormap.ts
1
+ // src/colormap.ts
2
2
  /** The rule's `base` colour when it gives none. */
3
3
  const DEFAULT_BASE = [
4
4
  200,
@@ -299,5 +299,4 @@ vec4 fmShade(vec4 a) {
299
299
  return fmLinear(fmFar(a.w));
300
300
  }
301
301
  `;
302
- //#endregion
303
302
  export { SRGB_TO_LINEAR16 as a, SHADING_VERTEX as i, DEFAULT_NAN as n, encodeValues as o, SHADING_FRAGMENT as r, shadingOf as s, DEFAULT_BASE as t };
@@ -1,4 +1,4 @@
1
- //#region src/core.ts
1
+ // src/core.ts
2
2
  const CODES = /* @__PURE__ */ new Set([
3
3
  "UNKNOWN_MESH",
4
4
  "UNKNOWN_FIELD",
@@ -10,6 +10,7 @@ const CODES = /* @__PURE__ */ new Set([
10
10
  "CORRUPTED",
11
11
  "OUT_OF_MEMORY",
12
12
  "STALE_LOOPS",
13
+ "STALE_SELECTION",
13
14
  "INSTANCE_POISONED"
14
15
  ]);
15
16
  /** An error thrown by fast-mesh, with a machine-readable `code`. */
@@ -109,5 +110,4 @@ const finalizer = new FinalizationRegistry((obj) => {
109
110
  release(obj);
110
111
  } catch {}
111
112
  });
112
- //#endregion
113
113
  export { release as a, wasmMemory as c, finalizer as i, call as n, reportListenerError as o, ensureInitialized as r, setMemory as s, FastMeshError as t };
@@ -1,15 +1,13 @@
1
- //#region src/core.d.ts
2
1
  /**
3
2
  * Error codes of {@link FastMeshError}.
4
3
  * `INSTANCE_POISONED` means an earlier call panicked: the WebAssembly instance
5
4
  * is unusable and every later call throws it. Reload the module to recover.
6
5
  */
7
- type FastMeshErrorCode = "UNKNOWN_MESH" | "UNKNOWN_FIELD" | "UNKNOWN_SECTION" | "INVALID_ARGUMENT" | "INVALID_INDEX" | "STALE_BVH" | "STEP_NOT_OPEN" | "CORRUPTED" | "OUT_OF_MEMORY" | "STALE_LOOPS" | "INSTANCE_POISONED";
6
+ type FastMeshErrorCode = "UNKNOWN_MESH" | "UNKNOWN_FIELD" | "UNKNOWN_SECTION" | "INVALID_ARGUMENT" | "INVALID_INDEX" | "STALE_BVH" | "STEP_NOT_OPEN" | "CORRUPTED" | "OUT_OF_MEMORY" | "STALE_LOOPS" | "STALE_SELECTION" | "INSTANCE_POISONED";
8
7
  /** An error thrown by fast-mesh, with a machine-readable `code`. */
9
8
  declare class FastMeshError extends Error {
10
9
  /** What went wrong; see {@link FastMeshErrorCode}. */
11
10
  readonly code: FastMeshErrorCode;
12
11
  constructor(code: FastMeshErrorCode, message: string);
13
12
  }
14
- //#endregion
15
13
  export { FastMeshErrorCode as n, FastMeshError as t };
@@ -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-BnkCS0sv.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}. */
@@ -1575,7 +1574,8 @@ var Engine = class {
1575
1574
  case "setPlacement":
1576
1575
  s.setPlacement(this.#mesh(req.id), {
1577
1576
  rotation: req.rotation,
1578
- translation: req.translation
1577
+ translation: req.translation,
1578
+ ...req.scale === void 0 ? {} : { scale: req.scale }
1579
1579
  });
1580
1580
  return;
1581
1581
  case "drag":
@@ -1656,7 +1656,8 @@ var Engine = class {
1656
1656
  if (req.rotation === void 0 || req.translation === void 0) throw invalid("a drag move needs a rotation and a translation");
1657
1657
  return {
1658
1658
  rotation: req.rotation,
1659
- translation: req.translation
1659
+ translation: req.translation,
1660
+ ...req.scale === void 0 ? {} : { scale: req.scale }
1660
1661
  };
1661
1662
  };
1662
1663
  if (req.phase === "begin") {
@@ -1799,6 +1800,10 @@ var Engine = class {
1799
1800
  const a = args;
1800
1801
  return s.analyze(this.#mesh(a.mesh), a.options);
1801
1802
  }
1803
+ case "measure": {
1804
+ const a = args;
1805
+ return s.measure(this.#mesh(a.mesh));
1806
+ }
1802
1807
  case "fieldTargetStatus": {
1803
1808
  const a = args;
1804
1809
  return s.fieldTargetStatus(this.#field(a.field));
@@ -1853,6 +1858,7 @@ var Engine = class {
1853
1858
  id,
1854
1859
  rotation: p.rotation,
1855
1860
  translation: p.translation,
1861
+ scale: p.scale,
1856
1862
  matrix4: Array.from(s.matrix4(c.mesh))
1857
1863
  });
1858
1864
  }
@@ -1974,5 +1980,4 @@ var Engine = class {
1974
1980
  return wire;
1975
1981
  }
1976
1982
  };
1977
- //#endregion
1978
1983
  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 };