fast-mesh-wasm 0.5.2 → 0.6.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 +7 -4
  2. package/dist/{client-BIPPznBZ.js → client-BrTp2eMp.js} +25 -1
  3. package/dist/{client-Uo7hHvD8.d.ts → client-Ds09vLkN.d.ts} +13 -2
  4. package/dist/{engine-BS8i5U8J.js → engine-DjdY3GxK.js} +7 -3
  5. package/dist/io.d.ts +19 -4
  6. package/dist/io.js +64 -9
  7. package/dist/{mesh-CqAIuOxU.d.ts → mesh-BsqIofgT.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 +1 -1
  11. package/dist/{protocol-BHAI0xiA.d.ts → protocol-Cb23HelE.d.ts} +7 -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-rsfM06St.js → scene-D0HNTwoo.js} +121 -15
  16. package/dist/{scene-like-CavrKbpQ.d.ts → scene-like-CADk1vfb.d.ts} +185 -31
  17. package/dist/{store-CZwml1K3.d.ts → store-BfC6kkf5.d.ts} +2 -2
  18. package/dist/{store-m9l0Al-m.js → store-DIQmxF_s.js} +2 -2
  19. package/dist/store.d.ts +2 -2
  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-CdOArjcB.js → views-B00kdV0R.js} +28 -1
  24. package/dist/wasm/fast_mesh_wasm.d.ts +21 -5
  25. package/dist/wasm/fast_mesh_wasm.js +37 -5
  26. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  27. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +3 -1
  28. package/dist/wasm-threads/fast_mesh_wasm.d.ts +21 -5
  29. package/dist/wasm-threads/fast_mesh_wasm.js +37 -5
  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 -1
  32. package/dist/web.d.ts +2 -2
  33. package/dist/web.js +1 -1
  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
@@ -1,5 +1,5 @@
1
+ import { a as encodeRule, c as SectionHandle, d as checkRegisterOptions, i as copyRule, l as rotationMatrix, n as meshViews, o as FieldHandle, r as checkInteractionPoints, s as MeshHandle, t as ViewGuard, u as targetsOf } from "./views-B00kdV0R.js";
1
2
  import { a as release, c as wasmMemory, i as finalizer, n as call, r as ensureInitialized, t as FastMeshError } from "./core-4OcWKu3r.js";
2
- import { a as FieldHandle, c as rotationMatrix, i as encodeRule, l as targetsOf, n as meshViews, o as MeshHandle, r as copyRule, s as SectionHandle, t as ViewGuard } from "./views-CdOArjcB.js";
3
3
  import { WasmScene } from "./wasm/fast_mesh_wasm.js";
4
4
  // src/changes.ts
5
5
  const ADDED = 1;
@@ -314,6 +314,8 @@ function useWasmScene(ctor) {
314
314
  }
315
315
  const meshIds = /* @__PURE__ */ new WeakMap();
316
316
  const rawIds = /* @__PURE__ */ new WeakMap();
317
+ /** The repair list's prefix code for a {@link VertexProtection}. */
318
+ const PROTECT_CODE = 32;
317
319
  const MODES = {
318
320
  eager: 0,
319
321
  lazy: 1,
@@ -474,7 +476,9 @@ const REPAIR_CODES = {
474
476
  offset: 11,
475
477
  shell: 12,
476
478
  simplify: 13,
477
- subdivide: 14
479
+ subdivide: 14,
480
+ splitStretched: 16,
481
+ captureRestSizes: 17
478
482
  };
479
483
  /** The op code of an {@link AutoRepairRequest}; see `crate::edit` in the Rust crate. */
480
484
  const AUTO_REPAIR_CODE = 15;
@@ -492,6 +496,14 @@ const REGISTER_STATUSES = [
492
496
  "tooFewCorrespondences",
493
497
  "diverged"
494
498
  ];
499
+ /** The `not applied` codes of `WasmScene.register`, in order. */
500
+ const REGISTER_NOT_APPLIED = [
501
+ null,
502
+ "notRequested",
503
+ "notConverged",
504
+ "rmseAboveLimit",
505
+ "tooFewInliers"
506
+ ];
495
507
  function optional(v, what) {
496
508
  if (v === void 0) return NaN;
497
509
  if (typeof v !== "number" || Number.isNaN(v)) throw invalid(`${what} must be a number`);
@@ -520,11 +532,23 @@ function encodeLoopId(id, out) {
520
532
  function isAutoRepair(op) {
521
533
  return op?.kind === "auto";
522
534
  }
535
+ /** The prefix that wraps the op after it in a {@link VertexProtection}; see `crate::edit` in the Rust crate. */
536
+ function encodeProtect(protect, values) {
537
+ const { vertices, weights } = protect;
538
+ if (vertices?.length === void 0) throw invalid("protect.vertices must be an array of vertex ids");
539
+ const n = vertices.length;
540
+ if (weights !== void 0 && weights.length !== n) throw invalid("protect.weights must have one weight per vertex");
541
+ values.push(PROTECT_CODE, n);
542
+ for (let k = 0; k < n; k++) values.push(vertices[k]);
543
+ for (let k = 0; k < n; k++) values.push(weights === void 0 ? 0 : weights[k]);
544
+ }
523
545
  /** A repair op list as the binding's `(ops, loops)`; see `crate::edit` in the Rust crate. */
524
546
  function encodeRepair(ops) {
525
547
  const values = [];
526
548
  const loops = [];
527
549
  for (const o of ops) {
550
+ const protect = o?.protect;
551
+ if (protect !== void 0) encodeProtect(protect, values);
528
552
  values.push(codeIn(REPAIR_CODES, o?.op, "repair op"));
529
553
  switch (o.op) {
530
554
  case "weld":
@@ -586,7 +610,14 @@ function encodeRepair(ops) {
586
610
  case "simplify":
587
611
  values.push(optional(o.targetTriangles, "targetTriangles"), flagOf(o.preserveBoundary, true));
588
612
  break;
589
- case "subdivide": values.push(o.method === void 0 ? NaN : codeIn(SUBDIVIDE_METHOD_CODES, o.method, "method"), optional(o.levels, "levels"));
613
+ case "subdivide":
614
+ values.push(o.method === void 0 ? NaN : codeIn(SUBDIVIDE_METHOD_CODES, o.method, "method"), optional(o.levels, "levels"));
615
+ break;
616
+ case "splitStretched":
617
+ centerOf(o.center, values);
618
+ values.push(optional(o.radius, "radius"), optional(o.limit, "limit"), optional(o.maxSplits, "maxSplits"), flagOf(o.smooth, true));
619
+ break;
620
+ case "captureRestSizes": values.push(flagOf(o.onlyIfMissing, false));
590
621
  }
591
622
  }
592
623
  return {
@@ -729,6 +760,18 @@ function decodeReport(op, r) {
729
760
  verticesAdded: r.next(),
730
761
  trianglesAdded: r.next()
731
762
  };
763
+ case "splitStretched": {
764
+ const splits = r.next();
765
+ const remaining = r.next();
766
+ const vertices = new Uint32Array(3 * splits);
767
+ for (let k = 0; k < vertices.length; k++) vertices[k] = r.next();
768
+ return {
769
+ splits,
770
+ remaining,
771
+ vertices
772
+ };
773
+ }
774
+ case "captureRestSizes": return {};
732
775
  }
733
776
  }
734
777
  /** An auto repair's result, stage by stage in the order they ran; see `crate::edit` in the Rust crate. */
@@ -1001,14 +1044,19 @@ var Scene = class {
1001
1044
  * (`signedDistance >= 0`) stays on the mesh and the `-` side is added as
1002
1045
  * a new mesh with the same placement, so the world shape is kept.
1003
1046
  * Cutting a closed mesh with `cap` (the default) yields two closed
1004
- * meshes, capped with flat, unfaired patches.
1047
+ * meshes, capped with flat, unfaired patches. On a mesh with UVs, closed
1048
+ * means closed by exact position, so seams count as closed: the cap's UVs
1049
+ * come from the rim and blend across a seam. A rim that runs into a real
1050
+ * boundary of an open mesh stays open. A mesh without UVs is read by vertex
1051
+ * index, so its split vertices are such a boundary: weld it first.
1005
1052
  *
1006
1053
  * The cut undoes in one step; the added mesh stays, like the removed
1007
1054
  * source of {@link Scene.join}.
1008
1055
  *
1009
1056
  * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` when
1010
- * the plane does not cut the mesh or a rim cannot be capped. A failed cut
1011
- * changes nothing.
1057
+ * the plane does not cut the mesh or a rim cannot be capped, as listed in
1058
+ * `docs/uv-channel.md`, for example a rim that closes by position with its
1059
+ * walls wound against each other. A failed cut changes nothing.
1012
1060
  */
1013
1061
  cutByPlane(mesh, plane, options) {
1014
1062
  const { index, generation } = this.#id(mesh);
@@ -1050,16 +1098,24 @@ var Scene = class {
1050
1098
  * Rigidly aligns the mesh `moving` to the mesh `fixed` by point-to-plane ICP,
1051
1099
  * with the closest points found through `fixed`'s BVH and trimmed by
1052
1100
  * `options.overlap`. A drag of either mesh ends first, recording its moves
1053
- * as one step.
1101
+ * as one step, once the arguments have been checked.
1054
1102
  *
1055
1103
  * **The initial guess is the current placements.** ICP finds the nearest
1056
1104
  * fit, so put the meshes roughly in place first with `setPlacement`.
1057
1105
  *
1058
- * **Applying.** By default a converged result becomes `moving`'s placement
1059
- * as one undo step (`applied` in the result); `apply: false` only returns
1060
- * it. A result that did not converge is never applied, so a failed alignment
1061
- * does not move anything; `placement` still holds the best estimate, for
1062
- * `setPlacement` if it will do.
1106
+ * **Applying.** By default a good result becomes `moving`'s placement as one
1107
+ * undo step (`applied` in the result): converged, with `rmse` within `maxRmse`
1108
+ * and enough points in range. Otherwise nothing moves, and `notApplied` says
1109
+ * why; `placement` still holds the estimate, for `setPlacement` if it will do.
1110
+ * `apply: false` only returns it.
1111
+ *
1112
+ * **Undetermined poses.** A plane's slide and a sphere's or a cylinder's spin
1113
+ * are not fixed by the data, though facets or noise can let the iteration
1114
+ * settle with a tiny `rmse`. These report `"underconstrained"` and list the
1115
+ * motions in `undetermined`. So do coarse regular meshes with exact fits close
1116
+ * by: a 16-sided sphere fits every 22.5 degrees. The check is local, so a
1117
+ * cube's 90-degree symmetry does not count. It adds a bounded cost: up to 12
1118
+ * restarts of up to 12 steps on at most 10,000 points.
1063
1119
  *
1064
1120
  * **Scales.** Only rotation and translation are solved. `moving`'s scale is
1065
1121
  * applied to its points and kept. `fixed`'s scale, uniform or not, is
@@ -1068,20 +1124,31 @@ var Scene = class {
1068
1124
  *
1069
1125
  * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` for one
1070
1126
  * mesh twice, a mesh without triangles or an invalid option; `STALE_BVH` for
1071
- * a stale Manual `fixed`. Nothing changes on a throw.
1127
+ * a stale Manual `fixed`. Bad options and one mesh twice change nothing,
1128
+ * and a drag keeps running. The other errors come after a drag has ended, and
1129
+ * change nothing else.
1072
1130
  */
1073
1131
  register(moving, fixed, options = {}) {
1074
1132
  const m = this.#id(moving);
1075
1133
  const f = this.#id(fixed);
1134
+ checkRegisterOptions(moving === fixed, options);
1076
1135
  const maxIterations = optional(options.maxIterations, "maxIterations");
1077
1136
  const tolerance = optional(options.tolerance, "tolerance");
1078
1137
  const overlap = optional(options.overlap, "overlap");
1079
1138
  const maxDistance = optional(options.maxDistance, "maxDistance");
1080
1139
  const maxSamples = optional(options.maxSamples, "maxSamples");
1140
+ const maxRmse = optional(options.maxRmse, "maxRmse");
1081
1141
  const apply = options.apply ?? true;
1082
1142
  if (this.#drag?.mesh === moving || this.#drag?.mesh === fixed) this.#drag.end();
1083
- const r = call(() => this.#scene().register(m.index, m.generation, f.index, f.generation, maxIterations, tolerance, overlap, maxDistance, maxSamples, apply));
1143
+ const r = call(() => this.#scene().register(m.index, m.generation, f.index, f.generation, maxIterations, tolerance, overlap, maxDistance, maxSamples, apply, maxRmse));
1084
1144
  const status = REGISTER_STATUSES[r[17]];
1145
+ const undetermined = [];
1146
+ for (let at = 24; at < r.length; at += 10) undetermined.push({
1147
+ translation: vec3At(r, at),
1148
+ rotation: vec3At(r, at + 3),
1149
+ about: vec3At(r, at + 6),
1150
+ alternativeRmse: r[at + 9]
1151
+ });
1085
1152
  return {
1086
1153
  placement: {
1087
1154
  rotation: Array.from(r.subarray(0, 9)),
@@ -1103,7 +1170,10 @@ var Scene = class {
1103
1170
  applied: r[18] === 1,
1104
1171
  samples: r[19],
1105
1172
  inliers: r[20],
1106
- conditioning: r[21]
1173
+ conditioning: r[21],
1174
+ notApplied: REGISTER_NOT_APPLIED[r[22]],
1175
+ maxRmse: r[23],
1176
+ undetermined
1107
1177
  };
1108
1178
  }
1109
1179
  /**
@@ -1141,6 +1211,19 @@ var Scene = class {
1141
1211
  };
1142
1212
  }
1143
1213
  /**
1214
+ * The mesh's origin. `views(mesh).positions()` are relative to it, while
1215
+ * `edit`'s `setPositions` and `addVertices` take positions with it added.
1216
+ */
1217
+ origin(mesh) {
1218
+ const { index, generation } = this.#id(mesh);
1219
+ const o = call(() => this.#peek().origin(index, generation));
1220
+ return [
1221
+ o[0],
1222
+ o[1],
1223
+ o[2]
1224
+ ];
1225
+ }
1226
+ /**
1144
1227
  * The column-major world matrix of the local render coordinates,
1145
1228
  * `placement · translate(origin)`, ready for renderers (convert to `f32`
1146
1229
  * yourself). The rotation columns carry the scale; normals need the
@@ -1150,6 +1233,29 @@ var Scene = class {
1150
1233
  const { index, generation } = this.#id(mesh);
1151
1234
  return call(() => this.#peek().matrix4(index, generation));
1152
1235
  }
1236
+ /**
1237
+ * Starts (`points`) or ends (`null`) an interaction: a gesture that changes
1238
+ * a placement or a mesh many times a second (a drag, a brush stroke), during
1239
+ * which a distance field too large to recompute per update stays live near
1240
+ * the contact, and is made exact when the gesture ends.
1241
+ *
1242
+ * While it lasts, a field with more finite values than `points` updates
1243
+ * only the vertices near its moved targets (within a margin that follows
1244
+ * the work, about `points` vertices an update), the vertices an edit moved
1245
+ * and a sweep of a quarter of `points` others. The rest keep their values
1246
+ * and colours, out of date by at most how far the meshes moved since, so
1247
+ * nothing turns far meanwhile. A smaller field updates as usual. Ending it
1248
+ * recomputes the fields it left out of date: their values and colours are
1249
+ * then those of an exact update. A gesture that changed nothing costs
1250
+ * nothing. The results do not depend on the thread count.
1251
+ *
1252
+ * @throws `INVALID_ARGUMENT` unless `points` is `null` or an integer in
1253
+ * `[1, 2^32)`.
1254
+ */
1255
+ setFieldInteraction(points) {
1256
+ const budget = checkInteractionPoints(points);
1257
+ call(() => this.#scene().set_field_interaction(budget ?? void 0));
1258
+ }
1153
1259
  /** Sets when the mesh's derived data follows its edits; see {@link UpdateMode}. */
1154
1260
  setMode(mesh, mode) {
1155
1261
  const { index, generation } = this.#id(mesh);
@@ -731,6 +731,8 @@ type RepairOp = {
731
731
  falloff: "linear" | "smooth";
732
732
  /** Displacement scale; negative pulls instead of pushing. */
733
733
  strength: number;
734
+ /** Vertices this op must hold in place, or move less. */
735
+ protect?: VertexProtection;
734
736
  } | {
735
737
  op: "smooth";
736
738
  /** Brush center in local mesh coordinates, as in `views(mesh).positions()`. */
@@ -741,6 +743,8 @@ type RepairOp = {
741
743
  strength: number;
742
744
  /** How many Taubin λ/μ cycles to run; 0 moves nothing. */
743
745
  cycles: number;
746
+ /** Vertices this op must hold in place, or move less. */
747
+ protect?: VertexProtection;
744
748
  } | {
745
749
  op: "remesh";
746
750
  /** Region center in local mesh coordinates, as in `views(mesh).positions()`. */
@@ -752,6 +756,38 @@ type RepairOp = {
752
756
  maxRounds?: number;
753
757
  /** Split long edges only (no collapses, no flips); unset means a full pass. */
754
758
  splitOnly?: boolean;
759
+ } | {
760
+ /**
761
+ * Records each vertex's longest edge as its rest size, for
762
+ * `splitStretched`. Run it before the deformation starts. Not an edit:
763
+ * no undo step, and it must be the only op of its list. Running it again
764
+ * accepts the mesh as it is then as the new rest shape; `onlyIfMissing`
765
+ * avoids that. The sizes last until a topology edit other than
766
+ * `splitStretched`, or an undo or redo of an edit from before the capture;
767
+ * undoing a topology edit from after it brings them back.
768
+ */
769
+ op: "captureRestSizes";
770
+ /** Keep rest sizes the mesh still holds. Unset means `false`. */
771
+ onlyIfMissing?: boolean;
772
+ } | {
773
+ /**
774
+ * Splits the edges a deformation stretched, and nothing else: an edge
775
+ * splits once it is past `limit` times the smaller rest size of its
776
+ * endpoints, measured by `captureRestSizes`. Existing vertices keep their
777
+ * ids and positions, nothing collapses or flips, and a triangle with no
778
+ * split edge keeps its slot. Fails while the mesh holds no valid rest
779
+ * sizes: see `captureRestSizes`.
780
+ */
781
+ op: "splitStretched";
782
+ /** Region center in local mesh coordinates; edges with an endpoint in the region are checked. */
783
+ center: Readonly<Vec3>;
784
+ radius: number;
785
+ /** Multiple of the rest size an edge may reach, above 1; unset means 4/3. */
786
+ limit?: number;
787
+ /** Most interior splits per call, the longest first; boundary edges do not count. Unset means 2^20. */
788
+ maxSplits?: number;
789
+ /** New interior vertices follow the surface's curvature; `false` uses midpoints. Unset means `true`. */
790
+ smooth?: boolean;
755
791
  } | {
756
792
  op: "bridgeLoops";
757
793
  /** The two loops to connect, from `analyze(mesh).loops`. Order is insignificant. */
@@ -768,6 +804,8 @@ type RepairOp = {
768
804
  strength: number;
769
805
  /** The drag vector in local coordinates; zero moves nothing. */
770
806
  direction: Readonly<Vec3>;
807
+ /** Vertices this op must hold in place, or move less. */
808
+ protect?: VertexProtection;
771
809
  } | {
772
810
  op: "relax";
773
811
  /** Brush center in local mesh coordinates, as in `views(mesh).positions()`. */
@@ -778,6 +816,8 @@ type RepairOp = {
778
816
  strength: number;
779
817
  /** How many plain Laplacian passes to run; 0 moves nothing. */
780
818
  cycles: number;
819
+ /** Vertices this op must hold in place, or move less. */
820
+ protect?: VertexProtection;
781
821
  } | {
782
822
  op: "offset";
783
823
  /**
@@ -868,6 +908,23 @@ interface FillReport {
868
908
  reason: "projectionFolds" | "noValidTriangulation" | "solver";
869
909
  }[];
870
910
  }
911
+ /**
912
+ * Vertices a brush op (`inflate`, `smooth`, `relax`, `grab`) holds back.
913
+ * After the op runs, each listed vertex's move is scaled by its weight: `0`
914
+ * leaves it at exactly the bytes it had, `1` keeps the whole move. The op's
915
+ * report describes its own move, before the scaling, and it stays one undo step;
916
+ * an op alone whose brush holds only vertices at `0` reports 0 and leaves no step.
917
+ * List only what the brush can reach: every listed vertex costs time per call.
918
+ *
919
+ * @throws `INVALID_ARGUMENT` from `repair` when a vertex is not alive, a weight
920
+ * is outside `[0, 1]`, or the lists differ in length.
921
+ */
922
+ interface VertexProtection {
923
+ /** The vertex slots to protect. */
924
+ vertices: Uint32Array | readonly number[];
925
+ /** One weight per vertex, each in `[0, 1]`; unset holds every listed vertex fully (all `0`). */
926
+ weights?: Float32Array | readonly number[];
927
+ }
871
928
  /** What `inflate` did. */
872
929
  interface InflateReport {
873
930
  moved: number;
@@ -885,6 +942,20 @@ interface RemeshReport {
885
942
  flips: number;
886
943
  rounds: number;
887
944
  }
945
+ /** What `splitStretched` did. */
946
+ interface StretchReport {
947
+ splits: number;
948
+ /** Edges still past the limit because `maxSplits` ran out, for a later call. */
949
+ remaining: number;
950
+ /**
951
+ * `new, a, b` per split, in order: the new vertex and its edge's endpoints,
952
+ * which may be new vertices from earlier in the list. For a caller that holds
953
+ * per-vertex state of its own and has to carry it over.
954
+ */
955
+ vertices: Uint32Array;
956
+ }
957
+ /** What `captureRestSizes` did: nothing to report. */
958
+ type CaptureRestReport = Record<string, never>;
888
959
  /** What `bridgeLoops` did. */
889
960
  interface BridgeReport {
890
961
  trianglesAdded: number;
@@ -982,20 +1053,48 @@ interface RegisterOptions {
982
1053
  */
983
1054
  maxSamples?: number;
984
1055
  /**
985
- * Whether a converged result becomes the moving mesh's placement, as one
986
- * undo step. A result that did not converge is never applied, whatever
987
- * this says. Default `true`.
1056
+ * Whether a good result becomes the moving mesh's placement, as one undo
1057
+ * step: it must converge, with `rmse` within `maxRmse` and at least half of
1058
+ * the points `overlap` expects in range. Anything else is not applied,
1059
+ * whatever this says; {@link RegisterResult.notApplied} says why. Default
1060
+ * `true`.
988
1061
  */
989
1062
  apply?: boolean;
1063
+ /**
1064
+ * The largest `rmse` (world units) that may be applied, to keep a wrong local
1065
+ * minimum from moving the mesh. Default: 1% of the moving points' extent,
1066
+ * reported as {@link RegisterResult.maxRmse}. Scans noisier than that need
1067
+ * their own limit; `Infinity` turns the guard off.
1068
+ */
1069
+ maxRmse?: number;
1070
+ }
1071
+ /** Why {@link Scene.register} did not apply its result. */
1072
+ type RegisterNotApplied = "notRequested" | "notConverged" | "rmseAboveLimit" | "tooFewInliers";
1073
+ /**
1074
+ * A rigid motion the data do not determine, in world coordinates: a point `p`
1075
+ * moves along `translation + rotation x (p - about)`, scaled so that the moving
1076
+ * mesh's points move by 1 (root mean square).
1077
+ */
1078
+ interface RegisterMotion {
1079
+ translation: Vec3;
1080
+ /** The rotation part, as an axis scaled by its rate. */
1081
+ rotation: Vec3;
1082
+ /** The point the rotation turns about: the moved points' centroid. */
1083
+ about: Vec3;
1084
+ /** The rmse of the other pose found along this motion, which fits as well. */
1085
+ alternativeRmse: number;
990
1086
  }
991
1087
  /**
992
1088
  * Why {@link Scene.register} stopped:
993
- * - `"converged"`: a step fell below the tolerance with all six rigid motions
994
- * constrained.
995
- * - `"maxIterations"`: the steps ran out first.
996
- * - `"underconstrained"`: a step fell below the tolerance, but the surface
997
- * does not determine some motion (a plane sliding in its plane, a tube along
998
- * its axis), which stayed where the current placement put it.
1089
+ * - `"converged"`: a step fell below the tolerance, and restarting from displaced
1090
+ * poses came back to the result, or only found worse fits: the data determine
1091
+ * every rigid motion locally.
1092
+ * - `"maxIterations"`: the steps ran out first, with no motion found undetermined.
1093
+ * - `"underconstrained"`: the data do not determine the pose. A restart stayed
1094
+ * displaced with a fit as good, as for a plane's slide, or a sphere's or a
1095
+ * cylinder's spin, even when facets or noise let the iteration settle with a
1096
+ * tiny `rmse`. {@link RegisterResult.undetermined} names the motions, and the
1097
+ * pose along them is arbitrary.
999
1098
  * - `"tooFewCorrespondences"`: fewer than six points have a usable closest
1000
1099
  * point.
1001
1100
  * - `"diverged"`: a step took points out of the range the query can represent.
@@ -1017,32 +1116,39 @@ interface RegisterResult {
1017
1116
  iterations: number;
1018
1117
  /**
1019
1118
  * `status === "converged"`. ICP is local, so this says the iteration settled
1020
- * and the surface determined the result, not that it found the right
1021
- * alignment: judge that from `rmse`.
1119
+ * and the data determine the result locally, not that it found the right
1120
+ * alignment: a far guess can settle in a wrong minimum. `maxRmse` guards
1121
+ * applying against that.
1022
1122
  */
1023
1123
  converged: boolean;
1024
1124
  /** Why iteration stopped. */
1025
1125
  status: RegisterStatus;
1026
1126
  /** Whether `placement` was set on the moving mesh. */
1027
1127
  applied: boolean;
1128
+ /** Why it was not; `null` exactly when `applied`. */
1129
+ notApplied: RegisterNotApplied | null;
1130
+ /** The `rmse` limit that applied (world units). */
1131
+ maxRmse: number;
1028
1132
  /** Points of the moving mesh sampled. */
1029
1133
  samples: number;
1030
1134
  /** Sampled points used at `placement`: the rest were trimmed or out of range. */
1031
1135
  inliers: number;
1032
1136
  /**
1033
- * How well the worst-constrained motion is determined, in `[0, 1]`: the
1034
- * smallest eigenvalue of the solver's normal equations over the largest at
1035
- * the last step. Below `1e-6` it counts as undetermined. A sphere's spin is
1036
- * determined only by its facets, so this falls as it is tessellated finer.
1037
- * 0 when no step ran.
1137
+ * The smallest eigenvalue of the solver's normal equations over the largest
1138
+ * at the last step, in `[0, 1]`; 0 when no step ran. Geometry only, with no
1139
+ * reference to noise: a low value warns of a weak motion, but a high one does
1140
+ * not show that it is determined. That is `undetermined`.
1038
1141
  */
1039
1142
  conditioning: number;
1143
+ /** The motions the data do not determine; non-empty only when `"underconstrained"`. */
1144
+ undetermined: RegisterMotion[];
1040
1145
  }
1041
1146
  /** Options of {@link Scene.cutByPlane}. */
1042
1147
  interface CutOptions {
1043
1148
  /**
1044
- * Close both openings with flat, unfaired patches. Defaults to `true`;
1045
- * without it both parts keep the open rim the cut leaves.
1149
+ * Close both openings with flat, unfaired patches, across UV seams on a
1150
+ * mesh with UVs. Defaults to `true`; without it both parts keep the open
1151
+ * rim the cut leaves.
1046
1152
  */
1047
1153
  cap?: boolean;
1048
1154
  }
@@ -1089,7 +1195,7 @@ interface AutoRepairReport {
1089
1195
  fillHoles: FillReport;
1090
1196
  }
1091
1197
  /** The report of a {@link RepairOp}. */
1092
- type RepairReport = WeldReport | DegenerateReport | RemoveReport | OrientReport | FillReport | InflateReport | SmoothReport | RemeshReport | BridgeReport | GrabReport | RelaxReport | OffsetReport | ShellReport | SimplifyReport | SubdivideReport;
1198
+ type RepairReport = WeldReport | DegenerateReport | RemoveReport | OrientReport | FillReport | InflateReport | SmoothReport | RemeshReport | BridgeReport | GrabReport | RelaxReport | OffsetReport | ShellReport | SimplifyReport | SubdivideReport | StretchReport | CaptureRestReport;
1093
1199
  /** The report type of a repair op. */
1094
1200
  type RepairReportOf<O extends RepairOp> = O extends {
1095
1201
  op: "weld";
@@ -1121,7 +1227,11 @@ type RepairReportOf<O extends RepairOp> = O extends {
1121
1227
  op: "simplify";
1122
1228
  } ? SimplifyReport : O extends {
1123
1229
  op: "subdivide";
1124
- } ? SubdivideReport : RepairReport;
1230
+ } ? SubdivideReport : O extends {
1231
+ op: "splitStretched";
1232
+ } ? StretchReport : O extends {
1233
+ op: "captureRestSizes";
1234
+ } ? CaptureRestReport : RepairReport;
1125
1235
  /**
1126
1236
  * A scene of editable meshes. Create it after `await init()`; release it with
1127
1237
  * {@link Scene.free} or a `using` declaration (otherwise it is freed when
@@ -1172,14 +1282,19 @@ declare class Scene implements SceneLike {
1172
1282
  * (`signedDistance >= 0`) stays on the mesh and the `-` side is added as
1173
1283
  * a new mesh with the same placement, so the world shape is kept.
1174
1284
  * Cutting a closed mesh with `cap` (the default) yields two closed
1175
- * meshes, capped with flat, unfaired patches.
1285
+ * meshes, capped with flat, unfaired patches. On a mesh with UVs, closed
1286
+ * means closed by exact position, so seams count as closed: the cap's UVs
1287
+ * come from the rim and blend across a seam. A rim that runs into a real
1288
+ * boundary of an open mesh stays open. A mesh without UVs is read by vertex
1289
+ * index, so its split vertices are such a boundary: weld it first.
1176
1290
  *
1177
1291
  * The cut undoes in one step; the added mesh stays, like the removed
1178
1292
  * source of {@link Scene.join}.
1179
1293
  *
1180
1294
  * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` when
1181
- * the plane does not cut the mesh or a rim cannot be capped. A failed cut
1182
- * changes nothing.
1295
+ * the plane does not cut the mesh or a rim cannot be capped, as listed in
1296
+ * `docs/uv-channel.md`, for example a rim that closes by position with its
1297
+ * walls wound against each other. A failed cut changes nothing.
1183
1298
  */
1184
1299
  cutByPlane(mesh: MeshHandle, plane: SectionPlane, options?: CutOptions): CutReport;
1185
1300
  /**
@@ -1200,16 +1315,24 @@ declare class Scene implements SceneLike {
1200
1315
  * Rigidly aligns the mesh `moving` to the mesh `fixed` by point-to-plane ICP,
1201
1316
  * with the closest points found through `fixed`'s BVH and trimmed by
1202
1317
  * `options.overlap`. A drag of either mesh ends first, recording its moves
1203
- * as one step.
1318
+ * as one step, once the arguments have been checked.
1204
1319
  *
1205
1320
  * **The initial guess is the current placements.** ICP finds the nearest
1206
1321
  * fit, so put the meshes roughly in place first with `setPlacement`.
1207
1322
  *
1208
- * **Applying.** By default a converged result becomes `moving`'s placement
1209
- * as one undo step (`applied` in the result); `apply: false` only returns
1210
- * it. A result that did not converge is never applied, so a failed alignment
1211
- * does not move anything; `placement` still holds the best estimate, for
1212
- * `setPlacement` if it will do.
1323
+ * **Applying.** By default a good result becomes `moving`'s placement as one
1324
+ * undo step (`applied` in the result): converged, with `rmse` within `maxRmse`
1325
+ * and enough points in range. Otherwise nothing moves, and `notApplied` says
1326
+ * why; `placement` still holds the estimate, for `setPlacement` if it will do.
1327
+ * `apply: false` only returns it.
1328
+ *
1329
+ * **Undetermined poses.** A plane's slide and a sphere's or a cylinder's spin
1330
+ * are not fixed by the data, though facets or noise can let the iteration
1331
+ * settle with a tiny `rmse`. These report `"underconstrained"` and list the
1332
+ * motions in `undetermined`. So do coarse regular meshes with exact fits close
1333
+ * by: a 16-sided sphere fits every 22.5 degrees. The check is local, so a
1334
+ * cube's 90-degree symmetry does not count. It adds a bounded cost: up to 12
1335
+ * restarts of up to 12 steps on at most 10,000 points.
1213
1336
  *
1214
1337
  * **Scales.** Only rotation and translation are solved. `moving`'s scale is
1215
1338
  * applied to its points and kept. `fixed`'s scale, uniform or not, is
@@ -1218,7 +1341,9 @@ declare class Scene implements SceneLike {
1218
1341
  *
1219
1342
  * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` for one
1220
1343
  * mesh twice, a mesh without triangles or an invalid option; `STALE_BVH` for
1221
- * a stale Manual `fixed`. Nothing changes on a throw.
1344
+ * a stale Manual `fixed`. Bad options and one mesh twice change nothing,
1345
+ * and a drag keeps running. The other errors come after a drag has ended, and
1346
+ * change nothing else.
1222
1347
  */
1223
1348
  register(moving: MeshHandle, fixed: MeshHandle, options?: RegisterOptions): RegisterResult;
1224
1349
  /**
@@ -1233,6 +1358,11 @@ declare class Scene implements SceneLike {
1233
1358
  setPlacement(mesh: MeshHandle, placement: PlacementInput): void;
1234
1359
  /** A mesh's placement, with the rotation as a row-major matrix. */
1235
1360
  placement(mesh: MeshHandle): Placement;
1361
+ /**
1362
+ * The mesh's origin. `views(mesh).positions()` are relative to it, while
1363
+ * `edit`'s `setPositions` and `addVertices` take positions with it added.
1364
+ */
1365
+ origin(mesh: MeshHandle): Vec3;
1236
1366
  /**
1237
1367
  * The column-major world matrix of the local render coordinates,
1238
1368
  * `placement · translate(origin)`, ready for renderers (convert to `f32`
@@ -1240,6 +1370,26 @@ declare class Scene implements SceneLike {
1240
1370
  * inverse-transpose (three.js' normal matrix does this from the matrix).
1241
1371
  */
1242
1372
  matrix4(mesh: MeshHandle): Float64Array;
1373
+ /**
1374
+ * Starts (`points`) or ends (`null`) an interaction: a gesture that changes
1375
+ * a placement or a mesh many times a second (a drag, a brush stroke), during
1376
+ * which a distance field too large to recompute per update stays live near
1377
+ * the contact, and is made exact when the gesture ends.
1378
+ *
1379
+ * While it lasts, a field with more finite values than `points` updates
1380
+ * only the vertices near its moved targets (within a margin that follows
1381
+ * the work, about `points` vertices an update), the vertices an edit moved
1382
+ * and a sweep of a quarter of `points` others. The rest keep their values
1383
+ * and colours, out of date by at most how far the meshes moved since, so
1384
+ * nothing turns far meanwhile. A smaller field updates as usual. Ending it
1385
+ * recomputes the fields it left out of date: their values and colours are
1386
+ * then those of an exact update. A gesture that changed nothing costs
1387
+ * nothing. The results do not depend on the thread count.
1388
+ *
1389
+ * @throws `INVALID_ARGUMENT` unless `points` is `null` or an integer in
1390
+ * `[1, 2^32)`.
1391
+ */
1392
+ setFieldInteraction(points: number | null): void;
1243
1393
  /** Sets when the mesh's derived data follows its edits; see {@link UpdateMode}. */
1244
1394
  setMode(mesh: MeshHandle, mode: UpdateMode): void;
1245
1395
  /** When the mesh's derived data follows its edits; see {@link UpdateMode}. */
@@ -1364,6 +1514,10 @@ declare class Scene implements SceneLike {
1364
1514
  * `{ kind: "auto" }` runs the standard cleanup pipeline the same way and
1365
1515
  * returns a report per stage; see {@link AutoRepairRequest}.
1366
1516
  *
1517
+ * A single `inflate`, `relax` or `grab` costs by the vertices under the brush, not the
1518
+ * mesh (it uses the BVH, and reaches only vertices a triangle uses); in a list
1519
+ * they scan the mesh, so a sculpt stroke should send its dabs one at a time.
1520
+ *
1367
1521
  * @throws `INVALID_ARGUMENT` for invalid options (`fillHoles` needs a bound or `loops`); `STALE_LOOPS` when a loop id of `fillHoles` no longer matches a loop of the mesh.
1368
1522
  */
1369
1523
  repair(mesh: MeshHandle, request: AutoRepairRequest): AutoRepairReport;
@@ -1598,4 +1752,4 @@ interface SceneLike {
1598
1752
  */
1599
1753
  bounds?(mesh: MeshHandle): Bounds | null;
1600
1754
  }
1601
- export { Scene as $, InflateReport as A, PlacementInput as At, OutOfRange as B, EditRef as C, MeshHandle as Ct, FilledLoop as D, InitInput as Dt, FillReport as E, Indices as Et, MeshChange as F, Vec3 as Ft, RegisterStatus as G, RaycastOptions as H, MeshComponent as I, computeBounds as It, RemoveReport as J, RelaxReport as K, MeshDistance as L, computeVertexNormals as Lt, JoinReport as M, Positions64 as Mt, LoopId as N, Quat as Nt, FindContactsOptions as O, Mat3 as Ot, MeasureResult as P, UpdateMode as Pt, Rgba as Q, OffsetReport as R, EditOp as S, FieldHandle as St, FieldStatus as T, Bounds as Tt, RegisterOptions as U, RayHit as V, RegisterResult as W, RepairReport as X, RepairOp as Y, RepairReportOf as Z, CutReport as _, SelectSpec as _t, AutoRepairReport as a, SectionResult as at, DragOptions as b, MeshViews as bt, BoundaryLoop as c, SimplifyReport as ct, ClosestPointOptions as d, ThicknessFieldDesc as dt, SceneOptions as et, ColorRule as f, WeldReport as ft, CutOptions as g, LassoSelect as gt, CurvatureFieldDesc as h, IsolateReport as ht, AnalyzeOptions as i, SectionPlane as it, JoinOptions as j, Positions as jt, GrabReport as k, Placement as kt, BridgeReport as l, SmoothReport as lt, Contact as m, ComponentSelect as mt, AddMeshOptions as n, SectionDesc as nt, AutoRepairRequest as o, ShellReport as ot, Colormap as p, BrushSelect as pt, RemeshReport as q, Analysis as r, SectionGap as rt, BooleanOp as s, SignMode as st, SceneLike as t, SectionContour as tt, ClosestHit as u, SubdivideReport as ut, DegenerateReport as v, VertexSelection as vt, EditResult as w, SectionHandle as wt, DragSession as x, SceneMeshViews as xt, DistanceFieldDesc as y, Range as yt, OrientReport as z };
1755
+ export { RepairReport as $, GrabReport as A, Bounds as At, OrientReport as B, Vec3 as Bt, EditOp as C, VertexSelection as Ct, FillReport as D, FieldHandle as Dt, FieldStatus as E, SceneMeshViews as Et, MeasureResult as F, PlacementInput as Ft, RegisterNotApplied as G, RayHit as H, computeVertexNormals as Ht, MeshChange as I, Positions as It, RegisterStatus as J, RegisterOptions as K, MeshComponent as L, Positions64 as Lt, JoinOptions as M, InitInput as Mt, JoinReport as N, Mat3 as Nt, FilledLoop as O, MeshHandle as Ot, LoopId as P, Placement as Pt, RepairOp as Q, MeshDistance as R, Quat as Rt, DragSession as S, SelectSpec as St, EditResult as T, MeshViews as Tt, RaycastOptions as U, OutOfRange as V, computeBounds as Vt, RegisterMotion as W, RemeshReport as X, RelaxReport as Y, RemoveReport as Z, CutOptions as _, WeldReport as _t, AutoRepairReport as a, SectionDesc as at, DistanceFieldDesc as b, IsolateReport as bt, BoundaryLoop as c, SectionResult as ct, ClosestHit as d, SimplifyReport as dt, RepairReportOf as et, ClosestPointOptions as f, SmoothReport as ft, CurvatureFieldDesc as g, VertexProtection as gt, Contact as h, ThicknessFieldDesc as ht, AnalyzeOptions as i, SectionContour as it, InflateReport as j, Indices as jt, FindContactsOptions as k, SectionHandle as kt, BridgeReport as l, ShellReport as lt, Colormap as m, SubdivideReport as mt, AddMeshOptions as n, Scene as nt, AutoRepairRequest as o, SectionGap as ot, ColorRule as p, StretchReport as pt, RegisterResult as q, Analysis as r, SceneOptions as rt, BooleanOp as s, SectionPlane as st, SceneLike as t, Rgba as tt, CaptureRestReport as u, SignMode as ut, CutReport as v, BrushSelect as vt, EditRef as w, Range as wt, DragOptions as x, LassoSelect as xt, DegenerateReport as y, ComponentSelect as yt, OffsetReport as z, UpdateMode as zt };
@@ -1,5 +1,5 @@
1
- import { $ as Scene, At as PlacementInput, B as OutOfRange, Ct as MeshHandle, Et as Indices, F as MeshChange, Mt as Positions64, Q as Rgba, S as EditOp, X as RepairReport, Y as RepairOp, a as AutoRepairReport, it as SectionPlane, n as AddMeshOptions, nt as SectionDesc, o as AutoRepairRequest, p as Colormap, st as SignMode, t as SceneLike, w as EditResult, wt as SectionHandle, x as DragSession } from "./scene-like-CavrKbpQ.js";
2
- import { i as WorkerScene } from "./client-Uo7hHvD8.js";
1
+ import { $ as RepairReport, C as EditOp, Ft as PlacementInput, I as MeshChange, Lt as Positions64, Ot as MeshHandle, Q as RepairOp, S as DragSession, T as EditResult, V as OutOfRange, a as AutoRepairReport, at as SectionDesc, jt as Indices, kt as SectionHandle, m as Colormap, n as AddMeshOptions, nt as Scene, o as AutoRepairRequest, st as SectionPlane, t as SceneLike, tt as Rgba, ut as SignMode } from "./scene-like-CADk1vfb.js";
2
+ import { i as WorkerScene } from "./client-Ds09vLkN.js";
3
3
  import { t as FastMeshError } from "./core-CJ9D6U5A.js";
4
4
  /** Options of `SceneStore.addMesh`: those both scenes take (a store mesh is always eager). */
5
5
  type StoreAddMeshOptions = Pick<AddMeshOptions, "origin" | "normals" | "uvs">;
@@ -1,7 +1,7 @@
1
1
  import { o as reportListenerError, t as FastMeshError } from "./core-4OcWKu3r.js";
2
- import { l as targetsOf } from "./views-CdOArjcB.js";
2
+ import { u as targetsOf } from "./views-B00kdV0R.js";
3
3
  import { i as sectionAspects } from "./protocol-Ci9LLiwO.js";
4
- import { a as watchStatusKeys, r as addFieldKeyed } from "./client-BIPPznBZ.js";
4
+ import { a as watchStatusKeys, r as addFieldKeyed } from "./client-BrTp2eMp.js";
5
5
  import { a as combine, c as sameData, n as EMPTY_SNAPSHOT, o as frozenCopy, t as DEFAULT_DISPLAY } from "./snapshot-BkbGPspK.js";
6
6
  // src/store/host.ts
7
7
  /** Whether `scene` is a Worker scene (structurally: it reports key statuses). */
package/dist/store.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Q as Rgba, st as SignMode } from "./scene-like-CavrKbpQ.js";
2
- import { _ as StoreAddMeshOptions, a as DisplayState, c as MeshState, d as SceneSnapshot, f as SectionParts, g as sectionState, h as meshState, i as ContactGroup, l as REMOVED_MESH_STATE, m as Status, n as SectionPatch, o as DistanceColoring, p as SectionState, r as createSceneStore, s as EMPTY_SNAPSHOT, t as SceneStore, u as REMOVED_SECTION_STATE } from "./store-CZwml1K3.js";
1
+ import { tt as Rgba, ut as SignMode } from "./scene-like-CADk1vfb.js";
2
+ import { _ as StoreAddMeshOptions, a as DisplayState, c as MeshState, d as SceneSnapshot, f as SectionParts, g as sectionState, h as meshState, i as ContactGroup, l as REMOVED_MESH_STATE, m as Status, n as SectionPatch, o as DistanceColoring, p as SectionState, r as createSceneStore, s as EMPTY_SNAPSHOT, t as SceneStore, u as REMOVED_SECTION_STATE } from "./store-BfC6kkf5.js";
3
3
  /** Options of {@link contactHeatmap}. Distances are in the meshes' units. */
4
4
  interface ContactHeatmapOptions {
5
5
  /** The penetration depth shown darkest (`deep`); deeper clamps to it. `> 0`. */