fast-mesh-wasm 0.3.1 → 0.5.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 (39) hide show
  1. package/README.md +5 -2
  2. package/dist/{client-Bp9FRd70.js → client-CE6RvmvB.js} +42 -8
  3. package/dist/{client-m2zSdFlu.d.ts → client-pv0Fwvl4.d.ts} +8 -2
  4. package/dist/{colormap-D_xH5hI5.js → colormap-DxGMYVfs.js} +1 -1
  5. package/dist/{engine-BpnthBYQ.js → engine-DLQAL9GT.js} +82 -31
  6. package/dist/{mesh-B16gV3oX.d.ts → mesh-RtPVmPQy.d.ts} +8 -1
  7. package/dist/{mesh-B8pae8WA.js → mesh-zj7-wJBw.js} +52 -5
  8. package/dist/node.d.ts +2 -2
  9. package/dist/node.js +1 -1
  10. package/dist/{protocol-CAUYm1gd.js → protocol-DkhGNP0h.js} +6 -4
  11. package/dist/{protocol-W9R-iGl5.d.ts → protocol-z-jeCUGO.d.ts} +11 -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-BFd6nYRe.js → scene-DyYdEQdy.js} +177 -13
  16. package/dist/{scene-like-B_3qm0u6.d.ts → scene-like-YcY08oii.d.ts} +140 -7
  17. package/dist/{store-DNnHN33A.d.ts → store-C5nzCpxy.d.ts} +2 -2
  18. package/dist/{store-D3ErV6o-.js → store-Z6A2HPih.js} +3 -3
  19. package/dist/store.d.ts +2 -2
  20. package/dist/store.js +1 -1
  21. package/dist/three.d.ts +7 -6
  22. package/dist/three.js +7 -2
  23. package/dist/{views-BaZqBxlX.js → views-Dh3aWc2q.js} +1 -1
  24. package/dist/wasm/fast_mesh_wasm.d.ts +53 -12
  25. package/dist/wasm/fast_mesh_wasm.js +107 -20
  26. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  27. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +6 -1
  28. package/dist/wasm-threads/fast_mesh_wasm.d.ts +53 -12
  29. package/dist/wasm-threads/fast_mesh_wasm.js +107 -20
  30. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
  31. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +6 -1
  32. package/dist/web.d.ts +2 -2
  33. package/dist/web.js +1 -1
  34. package/dist/worker-engine.d.ts +7 -5
  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
package/README.md CHANGED
@@ -106,6 +106,9 @@ requestAnimationFrame(frame);
106
106
  - The engine's colour maps are sRGB-encoded bytes. The adapter converts them to three's linear working space as it copies them (a normalized `Uint16` colour attribute), so they look the same as in a renderer that passes the bytes through to a non-sRGB canvas.
107
107
  - A material you pass to `bindMesh` is used as given and must not be shared between bound meshes (the adapter controls its `color`, `vertexColors`, `opacity`, `transparent` and `depthWrite`). With `shading: "fragment"` it also patches the material's shaders and disposes its compiled program on bind and on restore (see [Fragment shading](#fragment-shading)).
108
108
  - The adapter only reads `scene.onChanges`; it never calls `takeChanges`.
109
+ - Bound meshes take their bounding box and sphere from the scene's live-vertex bounds (see `Scene.bounds`), recomputed only when positions or indices change; on a host without them the adapter walks the mirrors instead.
110
+ - Bound objects (and section groups) must sit under an untransformed parent: their matrices are driven as world matrices, so a transformed ancestor offsets them and is warned about once.
111
+ - With `new Scene({ debug: true })`, the views the adapter copies from are checked `Proxy` objects (see the Scene API section for their cost); the mirrors it uploads are always plain typed arrays.
109
112
 
110
113
  #### Fragment shading
111
114
 
@@ -149,7 +152,7 @@ colour(gap);
149
152
 
150
153
  // Drag the lower mesh. The whole drag is one undo step. Each `move`
151
154
  // recomputes the eager fields, so coalesce pointer events to one `move` per
152
- // animation frame.
155
+ // animation frame (`scene.drag(mesh, { coalesce: true })` does that for you).
153
156
  const drag = scene.drag(lower);
154
157
  let pending: { rotation: Quat; translation: Vec3 } | undefined;
155
158
  function onPointerMove(rotation: Quat, translation: Vec3) {
@@ -294,7 +297,7 @@ const values = await scene.fetchFieldValues(gap); // `fieldValues` on Scene
294
297
  - **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.
295
298
  - **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.
296
299
  - **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.
297
- - **Large meshes are added in the background.** A mesh of 65,536 triangles or more is built in steps inside the Worker, its normals and the copy of its buffers for the main thread included (about 1.1 s at 1M and 12 s at 10M, single-threaded) while the requests sent after it that do not need it run: toggles, edits, drags and queries of other meshes are answered within milliseconds instead of waiting. A request that names the new mesh (or a field not built yet that is measured on or to it), adds or removes a mesh, or queries every mesh (`raycast`, `closestPoint` without a mesh, `findContacts` without pairs) waits for it and finishes it first (in one call on a threaded engine, in steps that still yield on a single-threaded one), so the engine's state is the same as running the requests in order. Replies can come in another order, though: until the mesh lands, `status("mesh:<id>")` reads `"computing"` and its views are empty; its buffers arrive with that status turning `"ready"`, so a reply to an unrelated request sent after the add can arrive first. `createWorkerScene({ backgroundAddTriangles })` sets the threshold; `Infinity` turns background adds off (every add then comes back with its own batch's result).
300
+ - **Large meshes are added in the background.** A mesh of 65,536 triangles or more is built in steps inside the Worker, its upload, store build, normals and the copy of its buffers for the main thread included (about 1.1 s at 1M and 12 s at 10M, single-threaded) while the requests sent after it that do not need it run: toggles, edits, drags and queries of other meshes are answered within milliseconds instead of waiting. A request that names the new mesh (or a field not built yet that is measured on or to it), adds or removes a mesh, or queries every mesh (`raycast`, `closestPoint` without a mesh, `findContacts` without pairs) waits for it and finishes it first (in one call on a threaded engine, in steps that still yield on a single-threaded one), so the engine's state is the same as running the requests in order. Replies can come in another order, though: until the mesh lands, `status("mesh:<id>")` reads `"computing"` and its views are empty; its buffers arrive with that status turning `"ready"`, so a reply to an unrelated request sent after the add can arrive first. `createWorkerScene({ backgroundAddTriangles })` sets the threshold; `Infinity` turns background adds off (every add then comes back with its own batch's result).
298
301
 
299
302
  **Bundlers.** The Worker script is a separate file, `worker-entry.js`, loaded with `new Worker(new URL("./worker-entry.js", import.meta.url), { type: "module" })`. Vite and other bundlers that understand this pattern pick it up and emit it with the `.wasm` it loads: [`examples/webgpu`](examples/webgpu) uses the default with Vite, in both `vite build` and `vite dev` (open it with `?worker`). If your setup does not handle the pattern, serve the package's `dist/` folder (the Worker script loads the files next to it) and pass the script's URL, or create the Worker yourself:
300
303
 
@@ -1,6 +1,6 @@
1
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-BaZqBxlX.js";
3
- import { a as supersedes, n as isLastWins, r as keyOf } from "./protocol-CAUYm1gd.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
4
  //#region src/worker/client.ts
5
5
  /**
6
6
  * Starts a Worker running the scene engine and resolves once it is ready.
@@ -1035,8 +1035,47 @@ var WorkerScene = class WorkerScene {
1035
1035
  removeMesh(mesh) {
1036
1036
  const st = this.#live(mesh);
1037
1037
  if (this.#drag?.mesh === st) this.#drag.end();
1038
- st.removed = true;
1039
1038
  const rev = ++this.#rev;
1039
+ this.#noteRemoved(st, rev);
1040
+ this.#push({
1041
+ kind: "removeMesh",
1042
+ rev,
1043
+ id: st.id
1044
+ });
1045
+ }
1046
+ /**
1047
+ * Joins `source` into `target`; see `Scene.join`. The source stays usable
1048
+ * until the join lands: only a successful result removes it (a failed join
1049
+ * changes nothing, engine-side or here).
1050
+ */
1051
+ join(target, source, options) {
1052
+ const ta = this.#live(target);
1053
+ const st = this.#live(source);
1054
+ if (this.#drag?.mesh === st) this.#drag.end();
1055
+ const payload = copyInput(options, "options");
1056
+ let rev = 0;
1057
+ return this.#ask((r, qid) => {
1058
+ rev = r;
1059
+ return {
1060
+ kind: "join",
1061
+ rev: r,
1062
+ target: ta.id,
1063
+ source: st.id,
1064
+ payload,
1065
+ qid
1066
+ };
1067
+ }, (v) => v).then((report) => {
1068
+ this.#noteRemoved(st, rev);
1069
+ return report;
1070
+ });
1071
+ }
1072
+ /**
1073
+ * Notes a mesh as removed at `rev`: later calls on it give `UNKNOWN_MESH`,
1074
+ * fields on it (or only to it) are dropped and its section entries go. The
1075
+ * engine does the same when the removal lands.
1076
+ */
1077
+ #noteRemoved(st, rev) {
1078
+ st.removed = true;
1040
1079
  for (const f of this.#fields.values()) {
1041
1080
  if (f.removed) continue;
1042
1081
  if (f.desc.on === st.id || f.desc.to.length === 1 && f.desc.to[0] === st.id) this.#fieldRemoved(f, rev);
@@ -1046,11 +1085,6 @@ var WorkerScene = class WorkerScene {
1046
1085
  };
1047
1086
  }
1048
1087
  for (const s of this.#sections.values()) if (!s.removed) s.meshes = s.meshes.filter((m) => m !== st);
1049
- this.#push({
1050
- kind: "removeMesh",
1051
- rev,
1052
- id: st.id
1053
- });
1054
1088
  }
1055
1089
  /** Sets a mesh's placement (one undo step); `placement()` follows when the result arrives. */
1056
1090
  setPlacement(mesh, placement) {
@@ -1,6 +1,6 @@
1
- import { $ as PlacementInput, A as RepairOp, B as SectionResult, D as RayHit, G as SectionHandle, L as SectionDesc, M as RepairReportOf, O as RaycastOptions, Q as Placement, R as SectionGap, S as MeshChange, U as FieldHandle, W as MeshHandle, Y as Indices, _ as FieldStatus, b as FindContactsOptions, c as ColorRule, f as DistanceFieldDesc, g as EditResult, i as AnalyzeOptions, it as Vec3, m as EditOp, n as AddMeshOptions, o as ClosestHit, p as DragSession, q as MeshViews, r as Analysis, s as ClosestPointOptions, t as SceneLike, tt as Positions64, u as Contact, w as MeshDistance, z as SectionPlane } from "./scene-like-B_3qm0u6.js";
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
2
  import { t as FastMeshError } from "./core-D2X9GPfK.js";
3
- import "./protocol-W9R-iGl5.js";
3
+ import "./protocol-z-jeCUGO.js";
4
4
  //#region src/worker/client.d.ts
5
5
  /** What {@link WorkerScene} needs of a Worker; a browser `Worker` fits. */
6
6
  interface WorkerLike {
@@ -120,6 +120,12 @@ declare class WorkerScene implements SceneLike {
120
120
  * by `commitFrame()`.
121
121
  */
122
122
  removeMesh(mesh: MeshHandle): void;
123
+ /**
124
+ * Joins `source` into `target`; see `Scene.join`. The source stays usable
125
+ * until the join lands: only a successful result removes it (a failed join
126
+ * changes nothing, engine-side or here).
127
+ */
128
+ join(target: MeshHandle, source: MeshHandle, options: JoinOptions): Promise<JoinReport>;
123
129
  /** Sets a mesh's placement (one undo step); `placement()` follows when the result arrives. */
124
130
  setPlacement(mesh: MeshHandle, placement: PlacementInput): void;
125
131
  /** The mesh's placement as mirrored (a drag's pose while it is held). */
@@ -36,7 +36,7 @@ const SRGB_TO_LINEAR16 = (() => {
36
36
  * engine). Grayscale is `(i, i, i)`.
37
37
  */
38
38
  const TABLES = {
39
- turbo: "IxcbJxooKxw0Lx4/MyBKNiNVOSVfOyhpPipyQCx7Qi+ERDGMRTSURzebSDmiSTypST6vSkG1SkS7S0bBS0nGS0zLS0/PSlHTSlTXSlfbSVnfSVziSF/lR2LoRmXqRWftRGrvQ23wQnDyQXL0QHX1P3j2Pnv3PX34O4D4OoP5OYb5OIj5N4v5NY75NJD4M5P4Mpb3MZj2MJv2L571LqD0LaPyLKXxK6jwKqruKq3tKa/rKLLqKLToJ7bmJ7nkJrviJr3gJcDeJcLcJcTaJcbXJcjVJcrTJc3RJc/OJtHMJtLJJtTHJ9bEJ9jCKNq/Kdy9Kt26K9+4LOG1LeKyLuSwL+WtMOerMeioM+qmNOujNuygN+6eOe+bO/CZPfGWP/KUQfORQ/SPRfWMR/aKSfeHS/iFTvmDUPmAUvp+Vfp8V/t5Wvt3Xfx1X/xzYv1xZf1uaP1sav1qbf5ocP5mc/5kdv5ief5gfP1ef/1dgv1bhf1ZiPxXi/xWjvxUkftSlftRmPpPm/lOnvlMofhLpPdJp/ZIqvZGrfVFsPREs/NCtvJBufBAvO8/v+4+wu08xes7yOo6y+k5zec40OY30+Q21eM12OE029803d4z39wy4tox5Ngw5tYw6dQv69Iu7dAt784t8cws88or9Mgr9sYq+MQq+cEp+78o/L0o/bon/7gn/7Um/7Mm/7El/64l/6wk/6kk/6Yj/6Qj/6Ei/58i/5wi/5kh/5ch/5Qg/5Eg/44f/4wf/4ke/4Ye/4Me/4Ed/34d/3sc/3gc/3Ub/3Mb/3Aa/m0a/Goa+2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1K21tJ2llH2FZG11RF1lJD1VBC1E5B00xA0Uk+0Ec9z0U8zkM7zEA5yz44yjs3yDk2xzY0xjQzxDEywy4xwSswwCgvvyUuvSIsvB4ruhoquRYptxEotgsntAQm"
42
42
  };
@@ -1,6 +1,6 @@
1
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-BFd6nYRe.js";
3
- import { a as supersedes, n as isLastWins, r as keyOf, t as isInit } from "./protocol-CAUYm1gd.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";
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),
@@ -342,6 +342,8 @@ const ADD_STEP_WORK = 1e5;
342
342
  const ALL_POINTS = 4294967295;
343
343
  /** Bytes of a background add's render buffers copied per unit of {@link EngineOptions.addStepWork}. */
344
344
  const PACK_BYTES_PER_UNIT = 64;
345
+ /** Bytes of a background add's positions and indices uploaded per unit of {@link EngineOptions.addStepWork}. */
346
+ const UPLOAD_BYTES_PER_UNIT = 64;
345
347
  const now = typeof performance !== "undefined" && typeof performance.now === "function" ? () => performance.now() : () => Date.now();
346
348
  /**
347
349
  * Runs the engine on `port` until the instance traps. The WebAssembly module
@@ -758,7 +760,7 @@ var Engine = class {
758
760
  this.#unpack(req);
759
761
  try {
760
762
  if (req.kind === "addMesh" && this.#inBackground(req)) {
761
- this.#beginAdd(req);
763
+ await this.#beginAdd(req);
762
764
  this.#onChunk?.({
763
765
  kind: "addMeshBegin",
764
766
  id: req.id
@@ -798,20 +800,44 @@ var Engine = class {
798
800
  return this.#port.postUpdate !== void 0 && req.inline !== true && req.indices.byteLength / 12 >= this.#backgroundAdd;
799
801
  }
800
802
  /**
801
- * Starts adding a mesh in the background: the mesh and its BVH are built
802
- * outside the scene, a step at a time between other chunks and while the
803
- * Worker is idle, and it lands in the scene when built, in arrival order
804
- * with the other background adds. Until then its status is held, and a
805
- * request that depends on it ({@link Engine.#dependsOnAdds}) first
806
- * finishes every background add; other requests run meanwhile.
803
+ * Starts adding a mesh in the background: its inputs upload into wasm
804
+ * memory in chunks, yielding between them, then the mesh, its BVH and
805
+ * its normals are built outside the scene, a step at a time between
806
+ * other chunks and while the Worker is idle, and it lands in the scene
807
+ * when built, in arrival order with the other background adds. Until
808
+ * then its status is held, and a request that depends on it
809
+ * ({@link Engine.#dependsOnAdds}) first finishes every background add;
810
+ * other requests run meanwhile.
807
811
  */
808
- #beginAdd(req) {
812
+ async #beginAdd(req) {
809
813
  if (this.#meshes.has(req.id) || this.#adds.some((a) => a.id === req.id)) throw invalid(`mesh client id ${req.id} is already in use`);
810
814
  const positions = req.f64 ? new Float64Array(req.positions) : new Float32Array(req.positions);
811
- const token = this.#meshAdds.begin(positions, new Uint32Array(req.indices), {
815
+ const indices = new Uint32Array(req.indices);
816
+ if (positions.length % 3 !== 0) throw invalid("positions length must be a multiple of 3");
817
+ if (indices.length % 3 !== 0) throw invalid("indices length must be a multiple of 3");
818
+ const token = this.#meshAdds.beginUpload(positions.length / 3, indices.length / 3, {
812
819
  ...req.options,
813
820
  mode: "eager"
814
821
  });
822
+ try {
823
+ const bytes = this.#addStepWork * UPLOAD_BYTES_PER_UNIT;
824
+ const p = Math.max(1, Math.floor(bytes / positions.BYTES_PER_ELEMENT));
825
+ const n = Math.max(1, Math.floor(bytes / indices.BYTES_PER_ELEMENT));
826
+ for (let at = 0; at < positions.length; at += p) {
827
+ const chunk = positions.subarray(at, at + p);
828
+ this.#meshAdds.pushPositions(token, chunk instanceof Float64Array ? chunk : Float64Array.from(chunk));
829
+ await this.#maybeYield();
830
+ }
831
+ for (let at = 0; at < indices.length; at += n) {
832
+ this.#meshAdds.pushIndices(token, indices.subarray(at, at + n));
833
+ await this.#maybeYield();
834
+ }
835
+ } catch (e) {
836
+ try {
837
+ this.#meshAdds.drop(token);
838
+ } catch {}
839
+ throw e;
840
+ }
815
841
  this.#adds.push({
816
842
  id: req.id,
817
843
  token,
@@ -848,6 +874,7 @@ var Engine = class {
848
874
  case "drag":
849
875
  case "edit":
850
876
  case "repair": return this.#pending(req.id);
877
+ case "join": return this.#pending(req.target, req.source);
851
878
  case "coloring": return this.#pending(req.id) || req.rule !== null && this.#fieldPending(req.rule?.field);
852
879
  case "fetchFieldValues": return this.#fieldPending(req.field);
853
880
  case "field": return req.desc !== void 0 ? this.#pending(req.desc.on, ...req.desc.to) : this.#fieldPending(req.field);
@@ -914,8 +941,8 @@ var Engine = class {
914
941
  }
915
942
  /**
916
943
  * Whether `req` may change the positions, normals or triangles of the
917
- * mesh `id`: an edit, repair, compaction or removal of it, or any undo
918
- * or redo.
944
+ * mesh `id`: an edit, repair, compaction, join or removal of it, or any
945
+ * undo or redo.
919
946
  */
920
947
  #changesMesh(req, id) {
921
948
  switch (req.kind) {
@@ -923,6 +950,7 @@ var Engine = class {
923
950
  case "repair":
924
951
  case "compact":
925
952
  case "removeMesh": return req.id === id;
953
+ case "join": return req.target === id || req.source === id;
926
954
  case "undo":
927
955
  case "redo": return true;
928
956
  default: return false;
@@ -1158,8 +1186,8 @@ var Engine = class {
1158
1186
  * Whether the queued `req` makes a field step unit over `meshes` (the
1159
1187
  * meshes its fields are on and measured to) stale (§6.1): a drag move
1160
1188
  * (only with `moves`: within the starvation guard), a drag cancel or a
1161
- * placement, an edit, repair, compaction or removal of one of them, an
1162
- * undo or redo, or the removal of a field between two of them.
1189
+ * placement, an edit, repair, compaction, join or removal of one of them,
1190
+ * an undo or redo, or the removal of a field between two of them.
1163
1191
  */
1164
1192
  #makesStale(req, meshes, moves) {
1165
1193
  switch (req.kind) {
@@ -1169,6 +1197,7 @@ var Engine = class {
1169
1197
  case "repair":
1170
1198
  case "compact":
1171
1199
  case "removeMesh": return meshes.has(req.id);
1200
+ case "join": return meshes.has(req.target) || meshes.has(req.source);
1172
1201
  case "undo":
1173
1202
  case "redo": return true;
1174
1203
  case "field": {
@@ -1480,6 +1509,28 @@ var Engine = class {
1480
1509
  #meshId(h) {
1481
1510
  return this.#meshIds.get(h);
1482
1511
  }
1512
+ /**
1513
+ * Drops engine-side references of a removed mesh: fields on it (or only
1514
+ * to it) and its section entries. The scene did the same with the mesh.
1515
+ */
1516
+ #dropMeshRefs(id) {
1517
+ for (const [field, [on, ...to]] of this.#fieldMeshes) if (on === id || to.length === 1 && to[0] === id) this.#dropField(field);
1518
+ else if (to.includes(id)) {
1519
+ this.#fieldMeshes.set(field, [on, ...to.filter((m) => m !== id)]);
1520
+ const desc = this.#deferred.get(field);
1521
+ if (desc !== void 0) this.#deferred.set(field, {
1522
+ ...desc,
1523
+ to: desc.to.filter((m) => m !== id)
1524
+ });
1525
+ }
1526
+ for (const [section, meshes] of this.#sectionMeshes) if (meshes.includes(id)) {
1527
+ this.#sectionMeshes.set(section, meshes.filter((m) => m !== id));
1528
+ this.#goneEntries.push({
1529
+ section,
1530
+ mesh: id
1531
+ });
1532
+ }
1533
+ }
1483
1534
  #run(req, b) {
1484
1535
  const s = this.#scene;
1485
1536
  switch (req.kind) {
@@ -1500,22 +1551,22 @@ var Engine = class {
1500
1551
  this.#meshes.delete(req.id);
1501
1552
  this.#removed.push(h);
1502
1553
  if (this.#drag?.id === req.id) this.#drag = void 0;
1503
- for (const [field, [on, ...to]] of this.#fieldMeshes) if (on === req.id || to.length === 1 && to[0] === req.id) this.#dropField(field);
1504
- else if (to.includes(req.id)) {
1505
- this.#fieldMeshes.set(field, [on, ...to.filter((m) => m !== req.id)]);
1506
- const desc = this.#deferred.get(field);
1507
- if (desc !== void 0) this.#deferred.set(field, {
1508
- ...desc,
1509
- to: desc.to.filter((m) => m !== req.id)
1510
- });
1511
- }
1512
- for (const [section, meshes] of this.#sectionMeshes) if (meshes.includes(req.id)) {
1513
- this.#sectionMeshes.set(section, meshes.filter((m) => m !== req.id));
1514
- this.#goneEntries.push({
1515
- section,
1516
- mesh: req.id
1517
- });
1518
- }
1554
+ this.#dropMeshRefs(req.id);
1555
+ return;
1556
+ }
1557
+ case "join": {
1558
+ const target = this.#mesh(req.target);
1559
+ const source = this.#mesh(req.source);
1560
+ const value = s.join(target, source, req.payload);
1561
+ this.#meshes.delete(req.source);
1562
+ this.#removed.push(source);
1563
+ if (this.#drag?.id === req.source) this.#drag = void 0;
1564
+ this.#dropMeshRefs(req.source);
1565
+ if (req.qid !== void 0) b.replies.push({
1566
+ qid: req.qid,
1567
+ ok: true,
1568
+ value
1569
+ });
1519
1570
  return;
1520
1571
  }
1521
1572
  case "compact":
@@ -1,4 +1,4 @@
1
- import { W as MeshHandle, t as SceneLike } from "./scene-like-B_3qm0u6.js";
1
+ import { Z as MeshHandle, t as SceneLike } from "./scene-like-YcY08oii.js";
2
2
  import * as THREE from "three";
3
3
  //#region src/three/mesh.d.ts
4
4
  /** Options of {@link bindMesh}. */
@@ -122,6 +122,13 @@ type MeshBinding = Pick<BoundMesh, "mesh" | "object">;
122
122
  * the scene and leaves the object as it was (remove it from your THREE.Scene
123
123
  * and call {@link BoundMesh.dispose}).
124
124
  *
125
+ * The object must sit under an untransformed parent (its `matrix` is a world
126
+ * matrix); a transformed ancestor is detected and warned about once.
127
+ *
128
+ * With a debug scene (`new Scene({ debug: true })`), the views the binding
129
+ * copies from are checked `Proxy` objects (see `SceneOptions.debug` for
130
+ * their cost); the mirrors it uploads are always plain typed arrays.
131
+ *
125
132
  * The adapter only listens through {@link SceneLike.onChanges}: call
126
133
  * `scene.commitFrame()` once per animation frame, before rendering.
127
134
  */
@@ -1,5 +1,5 @@
1
1
  import { t as FastMeshError } from "./core-Cke_kZ2e.js";
2
- import { a as SRGB_TO_LINEAR16, i as SHADING_VERTEX, o as encodeValues, r as SHADING_FRAGMENT, s as shadingOf } from "./colormap-D_xH5hI5.js";
2
+ import { a as SRGB_TO_LINEAR16, i as SHADING_VERTEX, o as encodeValues, r as SHADING_FRAGMENT, s as shadingOf } from "./colormap-DxGMYVfs.js";
3
3
  import * as THREE from "three";
4
4
  //#region src/three/mesh.ts
5
5
  const DEFAULT_COLOR = 13421772;
@@ -74,6 +74,13 @@ const BUFFERS = {
74
74
  * the scene and leaves the object as it was (remove it from your THREE.Scene
75
75
  * and call {@link BoundMesh.dispose}).
76
76
  *
77
+ * The object must sit under an untransformed parent (its `matrix` is a world
78
+ * matrix); a transformed ancestor is detected and warned about once.
79
+ *
80
+ * With a debug scene (`new Scene({ debug: true })`), the views the binding
81
+ * copies from are checked `Proxy` objects (see `SceneOptions.debug` for
82
+ * their cost); the mirrors it uploads are always plain typed arrays.
83
+ *
77
84
  * The adapter only listens through {@link SceneLike.onChanges}: call
78
85
  * `scene.commitFrame()` once per animation frame, before rendering.
79
86
  */
@@ -179,19 +186,36 @@ function bindMesh(scene, mesh, options = {}) {
179
186
  if (shading !== void 0) setShadingUniforms(uniforms, shading);
180
187
  return true;
181
188
  };
182
- /** Live triangles' vertices only: dead slots keep stale positions. */
189
+ /**
190
+ * Live triangles' vertices only: dead slots keep stale positions. From the
191
+ * scene's bounds when the host has them (one engine pass instead of two
192
+ * walks over every slot), else walked from the mirrors.
193
+ */
183
194
  const computeBounds = () => {
184
195
  const position = attributeOf("positions");
185
196
  const index = attributeOf("indices");
186
197
  if (position === void 0 || index === void 0) return;
198
+ const box = geometry.boundingBox ??= new THREE.Box3();
199
+ const sphere = geometry.boundingSphere ??= new THREE.Sphere();
200
+ const fromScene = typeof scene.bounds === "function" ? scene.bounds(mesh) : void 0;
201
+ if (fromScene !== void 0) {
202
+ if (fromScene === null) {
203
+ box.makeEmpty();
204
+ sphere.set(new THREE.Vector3(), -1);
205
+ return;
206
+ }
207
+ box.min.fromArray(fromScene.min);
208
+ box.max.fromArray(fromScene.max);
209
+ box.getCenter(sphere.center);
210
+ sphere.radius = box.min.distanceTo(box.max) / 2;
211
+ return;
212
+ }
187
213
  const p = position.array;
188
214
  const t = index.array;
189
- const box = geometry.boundingBox ??= new THREE.Box3();
190
215
  box.makeEmpty();
191
216
  const point = new THREE.Vector3();
192
217
  const live = (k) => t[k] !== 0 || t[k + 1] !== 0 || t[k + 2] !== 0;
193
218
  for (let k = 0; k < t.length; k += 3) if (live(k)) for (let c = 0; c < 3; c++) box.expandByPoint(point.fromArray(p, 3 * t[k + c]));
194
- const sphere = geometry.boundingSphere ??= new THREE.Sphere();
195
219
  if (box.isEmpty()) {
196
220
  sphere.set(new THREE.Vector3(), -1);
197
221
  return;
@@ -264,12 +288,14 @@ function bindMesh(scene, mesh, options = {}) {
264
288
  apply(void 0);
265
289
  computeBounds();
266
290
  updateMatrix();
291
+ checkUntransformedParent(object);
267
292
  let unsubscribe;
268
293
  const detach = () => {
269
294
  unsubscribe?.();
270
295
  unsubscribe = void 0;
271
296
  };
272
297
  unsubscribe = scene.onChanges((changes) => {
298
+ checkUntransformedParent(object);
273
299
  for (const c of changes) {
274
300
  if (c.mesh !== mesh) continue;
275
301
  if (c.removed) {
@@ -310,6 +336,27 @@ function bindMesh(scene, mesh, options = {}) {
310
336
  if (options.opacity !== void 0) bound.setOpacity(options.opacity);
311
337
  return bound;
312
338
  }
339
+ /** Objects already warned about a transformed ancestor. */
340
+ const warnedParents = /* @__PURE__ */ new WeakSet();
341
+ /** Whether the object's own transform is the identity. */
342
+ function isIdentityTransform(o) {
343
+ if (!o.matrixAutoUpdate) return o.matrix.elements.every((v, i) => v === (i % 5 === 0 ? 1 : 0));
344
+ const { position: p, quaternion: q, scale: s } = o;
345
+ return p.x === 0 && p.y === 0 && p.z === 0 && q.x === 0 && q.y === 0 && q.z === 0 && q.w === 1 && s.x === 1 && s.y === 1 && s.z === 1;
346
+ }
347
+ /**
348
+ * Warns once per object when it sits under a transformed ancestor: the
349
+ * adapter drives its matrix as a world matrix, so a transformed parent
350
+ * offsets it. Internal: shared with the controls and section bindings.
351
+ */
352
+ function checkUntransformedParent(object) {
353
+ if (warnedParents.has(object)) return;
354
+ for (let p = object.parent; p !== null; p = p.parent) if (!isIdentityTransform(p)) {
355
+ warnedParents.add(object);
356
+ console.warn("fast-mesh-wasm/three: the bound object has a transformed ancestor; its matrix is driven as a world matrix, so add it under the scene or an untransformed group.");
357
+ return;
358
+ }
359
+ }
313
360
  /** `INVALID_ARGUMENT` unless `width` is a finite number `>= 0`. */
314
361
  function checkSoftness(width) {
315
362
  if (typeof width !== "number" || !Number.isFinite(width) || width < 0) throw new FastMeshError("INVALID_ARGUMENT", "edgeSoftness must be a finite number >= 0");
@@ -425,4 +472,4 @@ function patchMaterial(material, uniforms) {
425
472
  };
426
473
  }
427
474
  //#endregion
428
- export { bindMesh as t };
475
+ export { checkUntransformedParent as n, bindMesh as t };
package/dist/node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as PlacementInput, A as RepairOp, B as SectionResult, C as MeshComponent, D as RayHit, E as OutOfRange, F as SceneOptions, G as SectionHandle, H as WeldReport, I as SectionContour, J as Bounds, K as Range, L as SectionDesc, M as RepairReportOf, N as Rgba, O as RaycastOptions, P as Scene, Q as Placement, R as SectionGap, S as MeshChange, T as OrientReport, U as FieldHandle, V as SignMode, W as MeshHandle, X as InitInput, Y as Indices, Z as Mat3, _ as FieldStatus, a as BoundaryLoop, at as computeBounds, b as FindContactsOptions, c as ColorRule, d as DegenerateReport, et as Positions, f as DistanceFieldDesc, g as EditResult, h as EditRef, i as AnalyzeOptions, it as Vec3, j as RepairReport, k as RemoveReport, l as Colormap, m as EditOp, n as AddMeshOptions, nt as Quat, o as ClosestHit, ot as computeVertexNormals, p as DragSession, q as MeshViews, r as Analysis, rt as UpdateMode, s as ClosestPointOptions, t as SceneLike, tt as Positions64, u as Contact, v as FillReport, w as MeshDistance, x as LoopId, y as FilledLoop, z as SectionPlane } from "./scene-like-B_3qm0u6.js";
1
+ import { $ as Range, A as OrientReport, B as Scene, C as InflateReport, D as MeshChange, E as LoopId, F as RemoveReport, G as SectionPlane, H as SectionContour, I as RepairOp, J as SmoothReport, K as SectionResult, L as RepairReport, M as RayHit, N as RaycastOptions, O as MeshComponent, P as RemeshReport, Q as SectionHandle, R as RepairReportOf, S as FindContactsOptions, T as JoinReport, U as SectionDesc, V as SceneOptions, W as SectionGap, X as FieldHandle, Y as WeldReport, Z as MeshHandle, _ as EditRef, a as BoundaryLoop, at as Placement, b as FillReport, c as ClosestPointOptions, ct as Positions64, d as Contact, dt as Vec3, et as MeshViews, f as DegenerateReport, ft as computeBounds, g as EditOp, h as DragSession, i as AnalyzeOptions, it as Mat3, j as OutOfRange, k as MeshDistance, l as ColorRule, lt as Quat, m as DragOptions, n as AddMeshOptions, nt as Indices, o as BridgeReport, ot as PlacementInput, p as DistanceFieldDesc, pt as computeVertexNormals, q as SignMode, r as Analysis, rt as InitInput, s as ClosestHit, st as Positions, t as SceneLike, tt as Bounds, u as Colormap, ut as UpdateMode, v as EditResult, w as JoinOptions, x as FilledLoop, y as FieldStatus, z as Rgba } from "./scene-like-YcY08oii.js";
2
2
  import { n as FastMeshErrorCode, t as FastMeshError } from "./core-D2X9GPfK.js";
3
3
  //#region src/node.d.ts
4
4
  /**
@@ -8,4 +8,4 @@ import { n as FastMeshErrorCode, t as FastMeshError } from "./core-D2X9GPfK.js";
8
8
  */
9
9
  export declare function init(_input?: InitInput | Promise<InitInput>): Promise<void>;
10
10
  //#endregion
11
- export { type AddMeshOptions, type Analysis, type AnalyzeOptions, type BoundaryLoop, type Bounds, type ClosestHit, type ClosestPointOptions, type ColorRule, type Colormap, type Contact, type DegenerateReport, type DistanceFieldDesc, type DragSession, type EditOp, type EditRef, type EditResult, FastMeshError, type FastMeshErrorCode, type FieldHandle, type FieldStatus, type FillReport, type FilledLoop, type FindContactsOptions, type Indices, type InitInput, type LoopId, type Mat3, type MeshChange, type MeshComponent, type MeshDistance, type MeshHandle, type MeshViews, type OrientReport, type OutOfRange, type Placement, type PlacementInput, type Positions, type Positions64, type Quat, type Range, type RayHit, type RaycastOptions, type RemoveReport, type RepairOp, type RepairReport, type RepairReportOf, type Rgba, Scene, type SceneLike, type SceneOptions, type SectionContour, type SectionDesc, type SectionGap, type SectionHandle, type SectionPlane, type SectionResult, type SignMode, type UpdateMode, type Vec3, type WeldReport, computeBounds, computeVertexNormals };
11
+ export { type AddMeshOptions, type Analysis, type AnalyzeOptions, type BoundaryLoop, type Bounds, type BridgeReport, type ClosestHit, type ClosestPointOptions, type ColorRule, type Colormap, type Contact, type DegenerateReport, type DistanceFieldDesc, type DragOptions, type DragSession, type EditOp, type EditRef, type EditResult, FastMeshError, type FastMeshErrorCode, type FieldHandle, type FieldStatus, type FillReport, type FilledLoop, type FindContactsOptions, type Indices, type InflateReport, type InitInput, type JoinOptions, type JoinReport, type LoopId, type Mat3, type MeshChange, type MeshComponent, type MeshDistance, type MeshHandle, type MeshViews, type OrientReport, type OutOfRange, type Placement, type PlacementInput, type Positions, type Positions64, type Quat, type Range, type RayHit, type RaycastOptions, type RemeshReport, type RemoveReport, type RepairOp, type RepairReport, type RepairReportOf, type Rgba, Scene, type SceneLike, type SceneOptions, type SectionContour, type SectionDesc, type SectionGap, type SectionHandle, type SectionPlane, type SectionResult, type SignMode, type SmoothReport, type UpdateMode, type Vec3, type WeldReport, computeBounds, computeVertexNormals };
package/dist/node.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as FastMeshError } from "./core-Cke_kZ2e.js";
2
2
  import { n as computeVertexNormals, r as markInitialized, t as computeBounds } from "./api-BUy7FRx7.js";
3
- import { t as Scene } from "./scene-BFd6nYRe.js";
3
+ import { t as Scene } from "./scene-DyYdEQdy.js";
4
4
  import { initSync } from "./wasm/fast_mesh_wasm.js";
5
5
  import { readFileSync } from "node:fs";
6
6
  //#region src/node.ts
@@ -5,10 +5,11 @@ function isInit(data) {
5
5
  }
6
6
  /**
7
7
  * The key of a request: its own `key`, or a default naming what it targets
8
- * (`mesh:<id>` for add and remove, `edit:<id>` for edits, repairs and
9
- * compaction, `field:<id>`, `section:<id>` for section add and remove,
10
- * `section:<id>:<aspects>` for a section `set`, such as `section:3:plane` or
11
- * `section:3:plane+fill`, `history`). Queries have none.
8
+ * (`mesh:<id>` for add and remove, `edit:<id>` for edits, repairs,
9
+ * compaction and joins (the join's target), `field:<id>`,
10
+ * `section:<id>` for section add and remove, `section:<id>:<aspects>` for
11
+ * a section `set`, such as `section:3:plane` or `section:3:plane+fill`,
12
+ * `history`). Queries have none.
12
13
  */
13
14
  function keyOf(req) {
14
15
  if ("key" in req && req.key !== void 0) return req.key;
@@ -18,6 +19,7 @@ function keyOf(req) {
18
19
  case "compact":
19
20
  case "edit":
20
21
  case "repair": return `edit:${req.id}`;
22
+ case "join": return `edit:${req.target}`;
21
23
  case "undo":
22
24
  case "redo":
23
25
  case "clearHistory": return "history";
@@ -1,4 +1,4 @@
1
- import { B as SectionResult, K as Range, c as ColorRule, f as DistanceFieldDesc, n as AddMeshOptions, z as SectionPlane } from "./scene-like-B_3qm0u6.js";
1
+ import { $ as Range, G as SectionPlane, K as SectionResult, l as ColorRule, n as AddMeshOptions, p as DistanceFieldDesc } from "./scene-like-YcY08oii.js";
2
2
  //#region src/worker/protocol.d.ts
3
3
  /** A mesh, field or section id allocated on the main side. Unique per kind. */
4
4
  type ClientId = number;
@@ -77,6 +77,16 @@ type Request = {
77
77
  /** When set, the result (an `EditResult` or the repair report(s)) is replied under it. */
78
78
  qid?: number;
79
79
  key?: string;
80
+ } | {
81
+ kind: "join";
82
+ rev: number;
83
+ target: ClientId;
84
+ source: ClientId;
85
+ /** `JoinOptions`. */
86
+ payload: unknown;
87
+ /** When set, the `JoinReport` is replied under it. */
88
+ qid?: number;
89
+ key?: string;
80
90
  } | {
81
91
  kind: "undo" | "redo";
82
92
  rev: number;
package/dist/r3f.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { W as MeshHandle } from "./scene-like-B_3qm0u6.js";
2
- import { t as SceneStore } from "./store-DNnHN33A.js";
3
- import { n as BoundMesh, t as BindMeshOptions } from "./mesh-B16gV3oX.js";
1
+ import { Z as MeshHandle } from "./scene-like-YcY08oii.js";
2
+ import { t as SceneStore } from "./store-C5nzCpxy.js";
3
+ import { n as BoundMesh, t as BindMeshOptions } from "./mesh-RtPVmPQy.js";
4
4
  import * as THREE from "three";
5
5
  import { JSX } from "react";
6
6
  import { EventHandlers } from "@react-three/fiber";
package/dist/r3f.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as FastMeshError } from "./core-Cke_kZ2e.js";
2
- import { t as bindMesh } from "./mesh-B8pae8WA.js";
2
+ import { t as bindMesh } from "./mesh-zj7-wJBw.js";
3
3
  import { s as meshState } from "./snapshot-Cf6NgDl7.js";
4
- import { r as setFrameLoop } from "./store-D3ErV6o-.js";
4
+ import { r as setFrameLoop } from "./store-Z6A2HPih.js";
5
5
  import { c as useStoreSelector, i as useScene, l as StoreContext, t as SceneProvider } from "./react-CTADh3NN.js";
6
6
  import * as THREE from "three";
7
7
  import { createElement, useCallback, useContext, useLayoutEffect, useRef, useState } from "react";
package/dist/react.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { G as SectionHandle, W as MeshHandle } from "./scene-like-B_3qm0u6.js";
1
+ import { Q as SectionHandle, Z as MeshHandle } from "./scene-like-YcY08oii.js";
2
2
  import { t as FastMeshError } from "./core-D2X9GPfK.js";
3
- import { a as DisplayState, c as MeshState, d as SceneSnapshot, n as SectionPatch, p as SectionState, t as SceneStore } from "./store-DNnHN33A.js";
3
+ import { a as DisplayState, c as MeshState, d as SceneSnapshot, n as SectionPatch, p as SectionState, t as SceneStore } from "./store-C5nzCpxy.js";
4
4
  import { ReactElement, ReactNode } from "react";
5
5
  //#region src/react/index.d.ts
6
6
  /** Provides `store` to the hooks below it. */