fast-mesh-wasm 0.5.3 → 0.7.0

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 (40) hide show
  1. package/README.md +2 -1
  2. package/dist/{client-f895H_yB.js → client-DFgvktkT.js} +183 -10
  3. package/dist/{client-D7yfPOyU.d.ts → client-nvmbhtn-.d.ts} +87 -14
  4. package/dist/{engine-BcJ5W6kS.js → engine-BL5_sWAf.js} +21 -6
  5. package/dist/io.d.ts +218 -5
  6. package/dist/io.js +3121 -12
  7. package/dist/{mesh-B3QP93wx.d.ts → mesh-BHTFxsXc.d.ts} +5 -2
  8. package/dist/{mesh-hPWBQPaN.js → mesh-DIWD2F5-.js} +51 -2
  9. package/dist/node.d.ts +2 -2
  10. package/dist/node.js +3 -2
  11. package/dist/{protocol-Dt0zgang.d.ts → protocol-DFR0JDAS.d.ts} +9 -1
  12. package/dist/r3f.d.ts +3 -3
  13. package/dist/r3f.js +2 -2
  14. package/dist/react.d.ts +2 -2
  15. package/dist/{scene-CXtM_bxV.js → scene-DUsj6uJD.js} +421 -29
  16. package/dist/{scene-like-Dq9_SaUL.d.ts → scene-like-CR_Dpohm.d.ts} +999 -133
  17. package/dist/{store-CIW19oCh.d.ts → store-8HWG90Jg.d.ts} +14 -3
  18. package/dist/{store-C9h7GFFl.js → store-BAzHRRkt.js} +18 -2
  19. package/dist/store.d.ts +3 -3
  20. package/dist/store.js +1 -1
  21. package/dist/three.d.ts +2 -2
  22. package/dist/three.js +1 -1
  23. package/dist/views-BSy-Qeg8.js +584 -0
  24. package/dist/wasm/fast_mesh_wasm.d.ts +21 -1
  25. package/dist/wasm/fast_mesh_wasm.js +50 -1
  26. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  27. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +3 -0
  28. package/dist/wasm-threads/fast_mesh_wasm.d.ts +21 -1
  29. package/dist/wasm-threads/fast_mesh_wasm.js +50 -1
  30. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
  31. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +3 -0
  32. package/dist/web.d.ts +2 -2
  33. package/dist/web.js +3 -2
  34. package/dist/worker-engine.d.ts +5 -3
  35. package/dist/worker-engine.js +1 -1
  36. package/dist/worker-entry.js +1 -1
  37. package/dist/worker.d.ts +1 -1
  38. package/dist/worker.js +1 -1
  39. package/package.json +1 -1
  40. package/dist/views-mp7Mf8CQ.js +0 -209
package/README.md CHANGED
@@ -305,7 +305,8 @@ const values = await scene.fetchFieldValues(gap); // `fieldValues` on Scene
305
305
  - **The frame loop.** `commitFrame()` sends everything queued since the last frame as one batch and returns the change records of the results received meanwhile (already applied to the mirrors, so `views`, `matrix4`, `placement`, `section` and `sectionPlane` read the new state). Results arrive between frames; nothing changes in the mirrors outside a message.
306
306
  - **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.
307
307
  - **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.
308
- - **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.
308
+ - **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. A drag move does not drop a recompute under way: it finishes and is shown, and the newest pose follows. During a sustained drag the colours therefore update about once per recompute, each update exactly one pose, and when the drag ends (`end()`) the last pose's colours arrive within about one recompute (measured before this default changed: 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. To keep a field too wide for this live, see `setFieldInteraction` below. 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.
309
+ - **Interactions.** `scene.setFieldInteraction(points)` starts a gesture and `setFieldInteraction(null)` ends it (on `Scene` too). During one, a field with more than `points` finite values updates about `points` vertices closest to the contact per update, those around an edit and a run of others; the rest keep their values and colours, out of date by up to how far the meshes moved. **During an interaction `fetchFieldValues()`, `fieldValues()`, `fieldNearest()` and the colours can hold those stale values, and `fieldStatus()` still says `current: true`:** bringing a field up to date means only the tier's update then. Read values you rely on after ending it: the end recomputes every vertex it left out of date, in steps on the Worker, and the values and colours are then those of an exact update. A gesture that changed nothing costs nothing.
309
310
  - **Queries and anything that returns data** (`raycast`, `closestPoint`, `meshDistance`, `intersects`, `findContacts`, `analyze`, `measure`, `register`, `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`.
310
311
  - **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.
311
312
  - **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.
@@ -1,4 +1,4 @@
1
- import { a as FieldHandle, c as rotationMatrix, l as targetsOf, o as MeshHandle, r as copyRule, s as SectionHandle, t as ViewGuard, u as checkRegisterOptions } from "./views-mp7Mf8CQ.js";
1
+ import { _ as createBooleanDomain, c as SectionHandle, d as checkRegisterOptions, f as createSculptDomain, g as createDeformDomain, h as createInspectDomain, i as copyRule, l as rotationMatrix, m as createRemeshDomain, o as FieldHandle, p as createRepairDomain, r as checkInteractionPoints, s as MeshHandle, t as ViewGuard, u as targetsOf, v as createAlignDomain } from "./views-BSy-Qeg8.js";
2
2
  import { o as reportListenerError, t as FastMeshError } from "./core-4OcWKu3r.js";
3
3
  import { a as supersedes, n as isLastWins, r as keyOf } from "./protocol-Ci9LLiwO.js";
4
4
  // src/worker/client.ts
@@ -377,6 +377,59 @@ var WorkerScene = class WorkerScene {
377
377
  #warned = false;
378
378
  /** The current Worker's crash channel (see `#watch`), while it may run threaded. */
379
379
  #crashWatch;
380
+ /**
381
+ * Callable async repair domain (`worker.repair(mesh, op)` and `worker.repair.<method>(...)`).
382
+ */
383
+ repair = createRepairDomain({
384
+ repair: ((mesh, op) => this.#runRepair(mesh, op)),
385
+ analyze: (mesh, options) => this.analyze(mesh, options),
386
+ join: (target, source, options) => this.join(target, source, options)
387
+ });
388
+ /**
389
+ * Callable async sculpt domain (`worker.sculpt(mesh, op)` and `worker.sculpt.<method>(...)`).
390
+ */
391
+ sculpt = createSculptDomain({
392
+ sculpt: ((mesh, op) => this.#runRepair(mesh, op)),
393
+ verticesInSphere: (mesh, center, radius) => this.verticesInSphere(mesh, center, radius)
394
+ });
395
+ /** Async remesh, simplification, subdivision, and volumetric reconstruction domain. */
396
+ remesh = createRemeshDomain({ repair: ((mesh, op) => this.#runRepair(mesh, op)) });
397
+ /** Callable async boolean, offsetting, and shell domain (`offset` and `shell` execute in worker). */
398
+ boolean = createBooleanDomain({
399
+ isAsync: true,
400
+ repair: ((mesh, op) => this.#runRepair(mesh, op))
401
+ });
402
+ /** Async surface deformation and vertex-protection domain. */
403
+ deform = createDeformDomain({ sculpt: ((mesh, op) => this.#runRepair(mesh, op)) });
404
+ /** Async defect analysis, metrology, queries, fields, and section inspection domain. */
405
+ inspect = createInspectDomain({
406
+ analyze: (mesh, options) => this.analyze(mesh, options),
407
+ measure: (mesh) => this.measure(mesh),
408
+ bounds: (mesh) => this.bounds(mesh),
409
+ raycast: (origin, direction, options) => this.raycast(origin, direction, options),
410
+ closestPoint: (point, options) => this.closestPoint(point, options),
411
+ meshDistance: (a, b, options) => this.meshDistance(a, b, options),
412
+ intersects: (a, b) => this.intersects(a, b),
413
+ findContacts: (options) => this.findContacts(options),
414
+ addDistanceField: (desc) => this.addDistanceField(desc),
415
+ removeField: (field) => this.removeField(field),
416
+ fieldValues: (field) => this.fetchFieldValues(field),
417
+ fieldNearest: (field) => this.fetchFieldNearest(field),
418
+ fieldStatus: (field) => this.fieldStatus(field),
419
+ fieldTargetStatus: (field) => this.fieldTargetStatus(field),
420
+ setColoring: (mesh, rule) => this.setColoring(mesh, rule),
421
+ coloring: (mesh) => this.coloring(mesh),
422
+ addSection: (desc) => this.addSection(desc),
423
+ setSectionPlane: (section, plane) => this.setSectionPlane(section, plane),
424
+ sectionPlane: (section) => this.sectionPlane(section),
425
+ setSectionMeshes: (section, meshes) => this.setSectionMeshes(section, meshes),
426
+ setSectionFill: (section, fill) => this.setSectionFill(section, fill),
427
+ removeSection: (section) => this.removeSection(section),
428
+ section: (section, mesh) => this.section(section, mesh),
429
+ sectionGap: (section, a, b) => this.sectionGap(section, a, b)
430
+ });
431
+ /** Async rigid registration and alignment domain. */
432
+ align = createAlignDomain({ register: (moving, fixed, options) => this.register(moving, fixed, options) });
380
433
  /** Use {@link createWorkerScene}. */
381
434
  constructor(make, options) {
382
435
  this.#make = make;
@@ -844,6 +897,7 @@ var WorkerScene = class WorkerScene {
844
897
  st.add = void 0;
845
898
  }
846
899
  for (const name of BUFFERS) this.#applyBuffer(st, name, c);
900
+ if (c.bounds !== void 0) st.bounds = cloneBounds(c.bounds);
847
901
  }
848
902
  const record = {
849
903
  mesh: st.handle,
@@ -869,6 +923,7 @@ var WorkerScene = class WorkerScene {
869
923
  st.colors = null;
870
924
  st.values = null;
871
925
  st.uvs = null;
926
+ st.bounds = null;
872
927
  st.shown = null;
873
928
  this.#guard?.bump();
874
929
  }
@@ -1026,6 +1081,7 @@ var WorkerScene = class WorkerScene {
1026
1081
  shown: null,
1027
1082
  pendingRules: /* @__PURE__ */ new Map(),
1028
1083
  indices: /* @__PURE__ */ new Uint32Array(0),
1084
+ bounds: void 0,
1029
1085
  pose: poseOf(IDENTITY, [
1030
1086
  0,
1031
1087
  0,
@@ -1085,6 +1141,8 @@ var WorkerScene = class WorkerScene {
1085
1141
  * Joins `source` into `target`; see `Scene.join`. The source stays usable
1086
1142
  * until the join lands: only a successful result removes it (a failed join
1087
1143
  * changes nothing, engine-side or here).
1144
+ *
1145
+ * @deprecated Use `workerScene.repair.join()` instead.
1088
1146
  */
1089
1147
  join(target, source, options) {
1090
1148
  const ta = this.#live(target);
@@ -1130,6 +1188,8 @@ var WorkerScene = class WorkerScene {
1130
1188
  * result reaches `placement()` with its batch, like a `setPlacement`.
1131
1189
  * Not replayed by a restart: an unanswered one rejects with
1132
1190
  * `INSTANCE_POISONED`, like an edit.
1191
+ *
1192
+ * @deprecated Use `workerScene.align.register()` instead.
1133
1193
  */
1134
1194
  register(moving, fixed, options = {}) {
1135
1195
  const m = this.#live(moving);
@@ -1190,10 +1250,26 @@ var WorkerScene = class WorkerScene {
1190
1250
  return this.#shown(this.#mirrored(mesh)).matrix4.slice();
1191
1251
  }
1192
1252
  /**
1253
+ * The box around the vertices the live triangles use, in the mesh's local
1254
+ * render coordinates, mirrored from the Worker. `null` without live triangles.
1255
+ */
1256
+ bounds(mesh) {
1257
+ const st = this.#mirrored(mesh);
1258
+ if (st.bounds === void 0) return;
1259
+ return cloneBounds(st.bounds);
1260
+ }
1261
+ /**
1193
1262
  * The mirrors of the mesh's render buffers, at full slot length. Each
1194
1263
  * getter returns the current mirror; a mirror is replaced when the slot
1195
1264
  * count changes or a buffer turns on or off, so get views right before use.
1196
1265
  */
1266
+ /**
1267
+ * The mesh's origin. `views(mesh).positions()` are relative to it, while
1268
+ * `edit`'s `setPositions` and `addVertices` take positions with it added.
1269
+ */
1270
+ origin(mesh) {
1271
+ return [...this.#live(mesh).origin];
1272
+ }
1197
1273
  views(mesh) {
1198
1274
  const st = this.#mirrored(mesh);
1199
1275
  const guard = this.#guard;
@@ -1332,18 +1408,27 @@ var WorkerScene = class WorkerScene {
1332
1408
  id: st.id
1333
1409
  });
1334
1410
  }
1335
- /** A report of the mesh's defects; see `Scene.analyze`. */
1411
+ /**
1412
+ * A report of the mesh's defects; see `Scene.analyze`.
1413
+ *
1414
+ * @deprecated Use `workerScene.inspect.analyze()` or `workerScene.repair.analyze()` instead.
1415
+ */
1336
1416
  analyze(mesh, options) {
1337
1417
  return this.#query("analyze", () => ({
1338
1418
  mesh: this.#live(mesh).id,
1339
1419
  options
1340
1420
  }), (v) => v);
1341
1421
  }
1342
- /** Scalar measurements of a mesh; see `Scene.measure`. */
1422
+ /**
1423
+ * Scalar measurements of a mesh; see `Scene.measure`.
1424
+ *
1425
+ * @deprecated Use `workerScene.inspect.measure()` instead.
1426
+ */
1343
1427
  measure(mesh) {
1344
1428
  return this.#query("measure", () => ({ mesh: this.#live(mesh).id }), (v) => v);
1345
1429
  }
1346
- repair(mesh, op) {
1430
+ /** Runs one repair operation, a list as one transaction, or the auto pipeline; see `Scene.repair`. */
1431
+ #runRepair(mesh, op) {
1347
1432
  return this.#ask((rev, qid) => ({
1348
1433
  kind: "repair",
1349
1434
  rev,
@@ -1352,6 +1437,33 @@ var WorkerScene = class WorkerScene {
1352
1437
  qid
1353
1438
  }), (v) => v);
1354
1439
  }
1440
+ /**
1441
+ * Live triangle-used vertex ids of `mesh` inside the closed local-space
1442
+ * sphere `(center, radius)`, in ascending order; see `Scene.verticesInSphere`.
1443
+ *
1444
+ * @deprecated Use `workerScene.sculpt.verticesInSphere()` instead.
1445
+ */
1446
+ verticesInSphere(mesh, center, radius) {
1447
+ return this.#query("verticesInSphere", () => {
1448
+ const id = this.#live(mesh).id;
1449
+ const c = center;
1450
+ if (c?.length !== 3 || ![
1451
+ c[0],
1452
+ c[1],
1453
+ c[2]
1454
+ ].every((x) => typeof x === "number" && Number.isFinite(x))) throw invalid("center must be 3 finite numbers");
1455
+ if (typeof radius !== "number" || !Number.isFinite(radius) || radius < 0) throw invalid("radius must be a finite non-negative number");
1456
+ return {
1457
+ mesh: id,
1458
+ center: [
1459
+ c[0],
1460
+ c[1],
1461
+ c[2]
1462
+ ],
1463
+ radius
1464
+ };
1465
+ }, (v) => v);
1466
+ }
1355
1467
  /** Undoes the latest step; an active drag is ended first. */
1356
1468
  undo() {
1357
1469
  this.#alive();
@@ -1403,7 +1515,11 @@ var WorkerScene = class WorkerScene {
1403
1515
  get canRedo() {
1404
1516
  return this.#history.canRedo;
1405
1517
  }
1406
- /** Adds a signed distance field; see `Scene.addDistanceField`. */
1518
+ /**
1519
+ * Adds a signed distance field; see `Scene.addDistanceField`.
1520
+ *
1521
+ * @deprecated Use `workerScene.inspect.addDistanceField()` instead.
1522
+ */
1407
1523
  addDistanceField(desc) {
1408
1524
  return this.#addField(desc, void 0);
1409
1525
  }
@@ -1596,6 +1712,18 @@ var WorkerScene = class WorkerScene {
1596
1712
  st.plane = normalised(p);
1597
1713
  });
1598
1714
  }
1715
+ /**
1716
+ * Starts (`points`) or ends (`null`) an interaction; see
1717
+ * {@link Scene.setFieldInteraction}. A recompute under way when it changes
1718
+ * is dropped and starts over under the new setting.
1719
+ */
1720
+ setFieldInteraction(points) {
1721
+ this.#push({
1722
+ kind: "fieldInteraction",
1723
+ rev: ++this.#rev,
1724
+ points: checkInteractionPoints(points)
1725
+ });
1726
+ }
1599
1727
  /** Changes the meshes a section cuts. Last wins per frame. */
1600
1728
  setSectionMeshes(section, meshes) {
1601
1729
  const list = this.#meshList(meshes);
@@ -1667,7 +1795,11 @@ var WorkerScene = class WorkerScene {
1667
1795
  b: this.#live(b).id
1668
1796
  }), (v) => v);
1669
1797
  }
1670
- /** The nearest hit of a world ray over every mesh, or `null`; see `Scene.raycast`. */
1798
+ /**
1799
+ * The nearest hit of a world ray over every mesh, or `null`; see `Scene.raycast`.
1800
+ *
1801
+ * @deprecated Use `workerScene.inspect.raycast()` instead.
1802
+ */
1671
1803
  raycast(origin, direction, options) {
1672
1804
  return this.#query("raycast", () => ({
1673
1805
  origin: [...origin],
@@ -1678,7 +1810,11 @@ var WorkerScene = class WorkerScene {
1678
1810
  mesh: this.#handleOf(v.mesh)
1679
1811
  });
1680
1812
  }
1681
- /** The surface point nearest to a world point, or `null`; see `Scene.closestPoint`. */
1813
+ /**
1814
+ * The surface point nearest to a world point, or `null`; see `Scene.closestPoint`.
1815
+ *
1816
+ * @deprecated Use `workerScene.inspect.closestPoint()` instead.
1817
+ */
1682
1818
  closestPoint(point, options = {}) {
1683
1819
  return this.#query("closestPoint", () => ({
1684
1820
  point: [...point],
@@ -1691,7 +1827,11 @@ var WorkerScene = class WorkerScene {
1691
1827
  mesh: this.#handleOf(v.mesh)
1692
1828
  });
1693
1829
  }
1694
- /** The distance between two meshes' surfaces, or `null`; see `Scene.meshDistance`. */
1830
+ /**
1831
+ * The distance between two meshes' surfaces, or `null`; see `Scene.meshDistance`.
1832
+ *
1833
+ * @deprecated Use `workerScene.inspect.meshDistance()` instead.
1834
+ */
1695
1835
  meshDistance(a, b, options) {
1696
1836
  return this.#query("meshDistance", () => ({
1697
1837
  a: this.#live(a).id,
@@ -1699,14 +1839,22 @@ var WorkerScene = class WorkerScene {
1699
1839
  options
1700
1840
  }), (v) => v);
1701
1841
  }
1702
- /** Whether two meshes intersect or touch as placed. */
1842
+ /**
1843
+ * Whether two meshes intersect or touch as placed.
1844
+ *
1845
+ * @deprecated Use `workerScene.inspect.intersects()` instead.
1846
+ */
1703
1847
  intersects(a, b) {
1704
1848
  return this.#query("intersects", () => ({
1705
1849
  a: this.#live(a).id,
1706
1850
  b: this.#live(b).id
1707
1851
  }), (v) => v);
1708
1852
  }
1709
- /** Every mesh pair (or every pair of `pairs`) within `margin`; see `Scene.findContacts`. */
1853
+ /**
1854
+ * Every mesh pair (or every pair of `pairs`) within `margin`; see `Scene.findContacts`.
1855
+ *
1856
+ * @deprecated Use `workerScene.inspect.findContacts()` instead.
1857
+ */
1710
1858
  findContacts(options = {}) {
1711
1859
  return this.#query("findContacts", () => ({
1712
1860
  margin: options.margin,
@@ -2277,6 +2425,31 @@ function copyArray(value, what, copy) {
2277
2425
  * slot order, as world positions before placement (local plus origin, in
2278
2426
  * `f64`, so the engine gets the same `f32` local positions back).
2279
2427
  */
2428
+ function cloneBounds(b) {
2429
+ if (b === null) return null;
2430
+ return {
2431
+ min: [
2432
+ b.min[0],
2433
+ b.min[1],
2434
+ b.min[2]
2435
+ ],
2436
+ max: [
2437
+ b.max[0],
2438
+ b.max[1],
2439
+ b.max[2]
2440
+ ],
2441
+ center: [
2442
+ b.center[0],
2443
+ b.center[1],
2444
+ b.center[2]
2445
+ ],
2446
+ size: [
2447
+ b.size[0],
2448
+ b.size[1],
2449
+ b.size[2]
2450
+ ]
2451
+ };
2452
+ }
2280
2453
  function liveGeometry(st) {
2281
2454
  const idx = st.indices;
2282
2455
  const p = st.positions;
@@ -1,6 +1,6 @@
1
- import { $ as RepairReportOf, Ct as SceneMeshViews, Et as SectionHandle, F as MeshChange, G as RegisterOptions, H as RaycastOptions, K as RegisterResult, L as MeshDistance, Lt as Vec3, M as JoinReport, Mt as PlacementInput, O as FindContactsOptions, Ot as Indices, P as MeasureResult, Pt as Positions64, S as EditOp, T as FieldStatus, Tt as MeshHandle, V as RayHit, Z as RepairOp, a as AutoRepairReport, at as SectionGap, d as ClosestPointOptions, f as ColorRule, i as AnalyzeOptions, it as SectionDesc, j as JoinOptions, jt as Placement, m as Contact, n as AddMeshOptions, o as AutoRepairRequest, ot as SectionPlane, r as Analysis, st as SectionResult, t as SceneLike, u as ClosestHit, w as EditResult, wt as FieldHandle, x as DragSession, y as DistanceFieldDesc } from "./scene-like-Dq9_SaUL.js";
1
+ import { $t as FindContactsOptions, Ar as Vec3, B as WorkerDeformDomain, Bn as SectionGap, Cn as RegisterOptions, Ct as AnalyzeOptions, D as WorkerRemeshDomain, Dr as Positions64, Ft as ClosestPointOptions, Hn as SectionResult, It as ColorRule, Kt as DragSession, N as WorkerInspectDomain, Pt as ClosestHit, Rt as Contact, St as Analysis, Tr as PlacementInput, Vn as SectionPlane, Wt as DistanceFieldDesc, Xt as FieldStatus, Yt as EditResult, _ as WorkerRepairDomain, _r as FieldHandle, at as WorkerSculptDomain, bn as RaycastOptions, br as Bounds, dn as MeasureResult, fn as MeshChange, lr as SceneMeshViews, mn as MeshDistance, n as SceneLike, on as JoinOptions, pt as WorkerBooleanDomain, qt as EditOp, sn as JoinReport, vr as MeshHandle, wn as RegisterResult, wr as Placement, xr as Indices, xt as AddMeshOptions, yn as RayHit, yr as SectionHandle, yt as WorkerAlignDomain, zn as SectionDesc } from "./scene-like-CR_Dpohm.js";
2
2
  import { t as FastMeshError } from "./core-CJ9D6U5A.js";
3
- import "./protocol-Dt0zgang.js";
3
+ import "./protocol-DFR0JDAS.js";
4
4
  /** What {@link WorkerScene} needs of a Worker; a browser `Worker` fits. */
5
5
  interface WorkerLike {
6
6
  postMessage(msg: unknown, transfer?: Transferable[]): void;
@@ -99,6 +99,24 @@ declare const MAX_THREADS = 64;
99
99
  */
100
100
  declare class WorkerScene implements SceneLike {
101
101
  #private;
102
+ /**
103
+ * Callable async repair domain (`worker.repair(mesh, op)` and `worker.repair.<method>(...)`).
104
+ */
105
+ readonly repair: WorkerRepairDomain;
106
+ /**
107
+ * Callable async sculpt domain (`worker.sculpt(mesh, op)` and `worker.sculpt.<method>(...)`).
108
+ */
109
+ readonly sculpt: WorkerSculptDomain;
110
+ /** Async remesh, simplification, subdivision, and volumetric reconstruction domain. */
111
+ readonly remesh: WorkerRemeshDomain;
112
+ /** Callable async boolean, offsetting, and shell domain (`offset` and `shell` execute in worker). */
113
+ readonly boolean: WorkerBooleanDomain;
114
+ /** Async surface deformation and vertex-protection domain. */
115
+ readonly deform: WorkerDeformDomain;
116
+ /** Async defect analysis, metrology, queries, fields, and section inspection domain. */
117
+ readonly inspect: WorkerInspectDomain;
118
+ /** Async rigid registration and alignment domain. */
119
+ readonly align: WorkerAlignDomain;
102
120
  /** Use {@link createWorkerScene}. */
103
121
  private constructor();
104
122
  /**
@@ -125,6 +143,8 @@ declare class WorkerScene implements SceneLike {
125
143
  * Joins `source` into `target`; see `Scene.join`. The source stays usable
126
144
  * until the join lands: only a successful result removes it (a failed join
127
145
  * changes nothing, engine-side or here).
146
+ *
147
+ * @deprecated Use `workerScene.repair.join()` instead.
128
148
  */
129
149
  join(target: MeshHandle, source: MeshHandle, options: JoinOptions): Promise<JoinReport>;
130
150
  /**
@@ -133,6 +153,8 @@ declare class WorkerScene implements SceneLike {
133
153
  * result reaches `placement()` with its batch, like a `setPlacement`.
134
154
  * Not replayed by a restart: an unanswered one rejects with
135
155
  * `INSTANCE_POISONED`, like an edit.
156
+ *
157
+ * @deprecated Use `workerScene.align.register()` instead.
136
158
  */
137
159
  register(moving: MeshHandle, fixed: MeshHandle, options?: RegisterOptions): Promise<RegisterResult>;
138
160
  /**
@@ -144,11 +166,21 @@ declare class WorkerScene implements SceneLike {
144
166
  placement(mesh: MeshHandle): Placement;
145
167
  /** The column-major world matrix of the mesh's local render coordinates, as mirrored. */
146
168
  matrix4(mesh: MeshHandle): Float64Array;
169
+ /**
170
+ * The box around the vertices the live triangles use, in the mesh's local
171
+ * render coordinates, mirrored from the Worker. `null` without live triangles.
172
+ */
173
+ bounds(mesh: MeshHandle): Bounds | null;
147
174
  /**
148
175
  * The mirrors of the mesh's render buffers, at full slot length. Each
149
176
  * getter returns the current mirror; a mirror is replaced when the slot
150
177
  * count changes or a buffer turns on or off, so get views right before use.
151
178
  */
179
+ /**
180
+ * The mesh's origin. `views(mesh).positions()` are relative to it, while
181
+ * `edit`'s `setPositions` and `addVertices` take positions with it added.
182
+ */
183
+ origin(mesh: MeshHandle): Vec3;
152
184
  views(mesh: MeshHandle): SceneMeshViews;
153
185
  /**
154
186
  * The rule the mirrored colours and values are made by (a frozen copy of
@@ -168,14 +200,25 @@ declare class WorkerScene implements SceneLike {
168
200
  edit(mesh: MeshHandle, ops: readonly EditOp[]): Promise<EditResult>;
169
201
  /** Compacts a mesh's slots (its slot counts change). */
170
202
  compact(mesh: MeshHandle): void;
171
- /** A report of the mesh's defects; see `Scene.analyze`. */
203
+ /**
204
+ * A report of the mesh's defects; see `Scene.analyze`.
205
+ *
206
+ * @deprecated Use `workerScene.inspect.analyze()` or `workerScene.repair.analyze()` instead.
207
+ */
172
208
  analyze(mesh: MeshHandle, options?: AnalyzeOptions): Promise<Analysis>;
173
- /** Scalar measurements of a mesh; see `Scene.measure`. */
209
+ /**
210
+ * Scalar measurements of a mesh; see `Scene.measure`.
211
+ *
212
+ * @deprecated Use `workerScene.inspect.measure()` instead.
213
+ */
174
214
  measure(mesh: MeshHandle): Promise<MeasureResult>;
175
- /** Runs one repair operation, a list as one transaction, or the auto pipeline; see `Scene.repair`. */
176
- repair(mesh: MeshHandle, request: AutoRepairRequest): Promise<AutoRepairReport>;
177
- repair<const O extends RepairOp>(mesh: MeshHandle, op: O): Promise<RepairReportOf<O>>;
178
- repair<const O extends readonly RepairOp[]>(mesh: MeshHandle, ops: O): Promise<{ -readonly [K in keyof O]: RepairReportOf<O[K]>; }>;
215
+ /**
216
+ * Live triangle-used vertex ids of `mesh` inside the closed local-space
217
+ * sphere `(center, radius)`, in ascending order; see `Scene.verticesInSphere`.
218
+ *
219
+ * @deprecated Use `workerScene.sculpt.verticesInSphere()` instead.
220
+ */
221
+ verticesInSphere(mesh: MeshHandle, center: Readonly<Vec3>, radius: number): Promise<Uint32Array>;
179
222
  /** Undoes the latest step; an active drag is ended first. */
180
223
  undo(): void;
181
224
  /** Redoes the latest undone step; an active drag is ended first. */
@@ -190,7 +233,11 @@ declare class WorkerScene implements SceneLike {
190
233
  get canUndo(): boolean;
191
234
  /** Whether there is a step to redo, as of the latest result. */
192
235
  get canRedo(): boolean;
193
- /** Adds a signed distance field; see `Scene.addDistanceField`. */
236
+ /**
237
+ * Adds a signed distance field; see `Scene.addDistanceField`.
238
+ *
239
+ * @deprecated Use `workerScene.inspect.addDistanceField()` instead.
240
+ */
194
241
  addDistanceField(desc: DistanceFieldDesc): FieldHandle;
195
242
  /** Removes a field, and a colouring by it. */
196
243
  removeField(field: FieldHandle): void;
@@ -219,6 +266,12 @@ declare class WorkerScene implements SceneLike {
219
266
  addSection(desc: SectionDesc): SectionHandle;
220
267
  /** Moves a section's plane; `sectionPlane()` returns it at once. Last wins per frame. */
221
268
  setSectionPlane(section: SectionHandle, plane: SectionPlane): void;
269
+ /**
270
+ * Starts (`points`) or ends (`null`) an interaction; see
271
+ * {@link Scene.setFieldInteraction}. A recompute under way when it changes
272
+ * is dropped and starts over under the new setting.
273
+ */
274
+ setFieldInteraction(points: number | null): void;
222
275
  /** Changes the meshes a section cuts. Last wins per frame. */
223
276
  setSectionMeshes(section: SectionHandle, meshes: readonly MeshHandle[]): void;
224
277
  /** Turns a section's fill on or off. Last wins per frame. */
@@ -236,17 +289,37 @@ declare class WorkerScene implements SceneLike {
236
289
  sectionPlane(section: SectionHandle): SectionPlane;
237
290
  /** The closest pair between two meshes' contours in a section; see `Scene.sectionGap`. */
238
291
  sectionGap(section: SectionHandle, a: MeshHandle, b: MeshHandle): Promise<SectionGap | null>;
239
- /** The nearest hit of a world ray over every mesh, or `null`; see `Scene.raycast`. */
292
+ /**
293
+ * The nearest hit of a world ray over every mesh, or `null`; see `Scene.raycast`.
294
+ *
295
+ * @deprecated Use `workerScene.inspect.raycast()` instead.
296
+ */
240
297
  raycast(origin: Readonly<Vec3>, direction: Readonly<Vec3>, options?: RaycastOptions): Promise<RayHit | null>;
241
- /** The surface point nearest to a world point, or `null`; see `Scene.closestPoint`. */
298
+ /**
299
+ * The surface point nearest to a world point, or `null`; see `Scene.closestPoint`.
300
+ *
301
+ * @deprecated Use `workerScene.inspect.closestPoint()` instead.
302
+ */
242
303
  closestPoint(point: Readonly<Vec3>, options?: ClosestPointOptions): Promise<ClosestHit | null>;
243
- /** The distance between two meshes' surfaces, or `null`; see `Scene.meshDistance`. */
304
+ /**
305
+ * The distance between two meshes' surfaces, or `null`; see `Scene.meshDistance`.
306
+ *
307
+ * @deprecated Use `workerScene.inspect.meshDistance()` instead.
308
+ */
244
309
  meshDistance(a: MeshHandle, b: MeshHandle, options?: {
245
310
  maxDistance?: number;
246
311
  }): Promise<MeshDistance | null>;
247
- /** Whether two meshes intersect or touch as placed. */
312
+ /**
313
+ * Whether two meshes intersect or touch as placed.
314
+ *
315
+ * @deprecated Use `workerScene.inspect.intersects()` instead.
316
+ */
248
317
  intersects(a: MeshHandle, b: MeshHandle): Promise<boolean>;
249
- /** Every mesh pair (or every pair of `pairs`) within `margin`; see `Scene.findContacts`. */
318
+ /**
319
+ * Every mesh pair (or every pair of `pairs`) within `margin`; see `Scene.findContacts`.
320
+ *
321
+ * @deprecated Use `workerScene.inspect.findContacts()` instead.
322
+ */
250
323
  findContacts(options?: FindContactsOptions): Promise<Contact[]>;
251
324
  /** Registers a listener for {@link WorkerScene.commitFrame}; returns the function that removes it. */
252
325
  onChanges(listener: (changes: MeshChange[]) => void): () => void;
@@ -1,5 +1,5 @@
1
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-CXtM_bxV.js";
2
+ import { i as useWasmScene, n as fieldSteps, r as meshAdds, t as Scene } from "./scene-DUsj6uJD.js";
3
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
@@ -327,7 +327,7 @@ async function startEngine(init, loaders, isolated = globalThis.crossOriginIsola
327
327
  /** The default {@link EngineOptions.yieldMs}. */
328
328
  const YIELD_MS = 4;
329
329
  /** The default {@link EngineOptions.staleGuardMs}. */
330
- const STALE_GUARD_MS = 200;
330
+ const STALE_GUARD_MS = 0;
331
331
  /** The default {@link EngineOptions.stepPoints}. */
332
332
  const STEP_POINTS = 4096;
333
333
  /**
@@ -643,7 +643,7 @@ var Engine = class {
643
643
  this.#yieldMs = options.yieldMs ?? 4;
644
644
  const points = Math.floor(options.stepPoints ?? 4096);
645
645
  this.#stepPoints = points >= 1 ? Math.min(points, ALL_POINTS) : 1;
646
- this.#staleGuardMs = options.staleGuardMs ?? 200;
646
+ this.#staleGuardMs = options.staleGuardMs ?? 0;
647
647
  const bg = options.backgroundAddTriangles;
648
648
  this.#backgroundAdd = bg === void 0 || Number.isNaN(bg) ? BACKGROUND_ADD_TRIANGLES : Math.max(0, bg);
649
649
  const work = Math.floor(options.addStepWork ?? 1e5);
@@ -1203,6 +1203,7 @@ var Engine = class {
1203
1203
  #makesStale(req, meshes, moves) {
1204
1204
  switch (req.kind) {
1205
1205
  case "drag": return meshes.has(req.id) && (req.phase === "cancel" || moves && (req.phase === "move" || req.phase === "end" && req.rotation !== void 0));
1206
+ case "fieldInteraction": return true;
1206
1207
  case "setPlacement":
1207
1208
  case "edit":
1208
1209
  case "repair":
@@ -1379,7 +1380,10 @@ var Engine = class {
1379
1380
  * recorded operation would drop them even if a later one fails).
1380
1381
  */
1381
1382
  #inSteps(req) {
1382
- return Array.isArray(req.payload) && req.payload.length > 1 && this.#drag === void 0 && !this.#scene.canRedo();
1383
+ return Array.isArray(req.payload) && req.payload.length > 1 && !req.payload.some((o) => {
1384
+ const name = o?.op;
1385
+ return name === "captureRestSizes" || name === "captureStrokeState";
1386
+ }) && this.#drag === void 0 && !this.#scene.canRedo();
1383
1387
  }
1384
1388
  async #repairInSteps(req, b) {
1385
1389
  const s = this.#scene;
@@ -1591,6 +1595,9 @@ var Engine = class {
1591
1595
  });
1592
1596
  return;
1593
1597
  }
1598
+ case "fieldInteraction":
1599
+ s.setFieldInteraction(req.points);
1600
+ return;
1594
1601
  case "compact":
1595
1602
  s.compact(this.#mesh(req.id));
1596
1603
  return;
@@ -1652,14 +1659,17 @@ var Engine = class {
1652
1659
  case "section":
1653
1660
  this.#runSection(req);
1654
1661
  return;
1655
- case "query":
1662
+ case "query": {
1656
1663
  if (req.name === "fieldStatus" || req.name === "fieldNearest" || req.name === "fieldTargetStatus" || req.name === "debugDump") this.#settleFields();
1664
+ const value = this.#query(req.name, req.args);
1657
1665
  b.replies.push({
1658
1666
  qid: req.qid,
1659
1667
  ok: true,
1660
- value: this.#query(req.name, req.args)
1668
+ value
1661
1669
  });
1670
+ if (req.name === "verticesInSphere" && value instanceof Uint32Array) b.transfer.push(value.buffer);
1662
1671
  return;
1672
+ }
1663
1673
  case "fetchFieldValues": {
1664
1674
  this.#settleFields();
1665
1675
  const values = s.fieldValues(this.#field(req.field)).slice();
@@ -1827,6 +1837,10 @@ var Engine = class {
1827
1837
  const a = args;
1828
1838
  return s.measure(this.#mesh(a.mesh));
1829
1839
  }
1840
+ case "verticesInSphere": {
1841
+ const a = args;
1842
+ return s.verticesInSphere(this.#mesh(a.mesh), a.center, a.radius);
1843
+ }
1830
1844
  case "fieldTargetStatus": {
1831
1845
  const a = args;
1832
1846
  return s.fieldTargetStatus(this.#field(a.field));
@@ -1989,6 +2003,7 @@ var Engine = class {
1989
2003
  if (c.removed) return wire;
1990
2004
  wire.vertexSlots = this.#scene.vertexSlots(c.mesh);
1991
2005
  wire.triangleSlots = this.#scene.triangleSlots(c.mesh);
2006
+ if (c.added || c.capacityChanged || c.positions === "all" || c.positions.length > 0 || c.indices === "all" || c.indices.length > 0) wire.bounds = this.#scene.bounds(c.mesh);
1992
2007
  let packed = c.added ? this.#packed.get(c.mesh) : void 0;
1993
2008
  if (packed !== void 0 && packed.stamp !== this.#meshAdds.stamp(c.mesh)) packed = void 0;
1994
2009
  const views = this.#scene.views(c.mesh);