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
@@ -1,4 +1,4 @@
1
- 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, u as checkRegisterOptions } from "./views-mp7Mf8CQ.js";
1
+ import { _ as createBooleanDomain, a as encodeRule, c as SectionHandle, d as checkRegisterOptions, f as createSculptDomain, g as createDeformDomain, h as createInspectDomain, i as copyRule, l as rotationMatrix, m as createRemeshDomain, n as meshViews, 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 { a as release, c as wasmMemory, i as finalizer, n as call, r as ensureInitialized, t as FastMeshError } from "./core-4OcWKu3r.js";
3
3
  import { WasmScene } from "./wasm/fast_mesh_wasm.js";
4
4
  // src/changes.ts
@@ -314,6 +314,10 @@ 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;
319
+ /** The repair list's prefix code for {@link Symmetry} and {@link SurfaceFilter}. */
320
+ const BRUSH_MODIFIERS_CODE = 33;
317
321
  const MODES = {
318
322
  eager: 0,
319
323
  lazy: 1,
@@ -474,14 +478,88 @@ const REPAIR_CODES = {
474
478
  offset: 11,
475
479
  shell: 12,
476
480
  simplify: 13,
477
- subdivide: 14
481
+ subdivide: 14,
482
+ splitStretched: 16,
483
+ captureRestSizes: 17,
484
+ captureStrokeState: 18,
485
+ flatten: 19,
486
+ crease: 20,
487
+ clay: 21,
488
+ twist: 22,
489
+ makeManifold: 23,
490
+ resolveSelfIntersections: 24,
491
+ cleanupSlivers: 25
478
492
  };
479
- /** The op code of an {@link AutoRepairRequest}; see `crate::edit` in the Rust crate. */
493
+ /** The op code of a legacy {@link AutoRepairRequest}; see `crate::edit` in the Rust crate. */
480
494
  const AUTO_REPAIR_CODE = 15;
495
+ /** The op code of an extended preset {@link AutoRepairRequest}; see `crate::edit` in the Rust crate. */
496
+ const AUTO_REPAIR_PRESET_CODE = 26;
497
+ const AUTO_STAGE_OPS = {
498
+ 0: "weld",
499
+ 1: "removeDegenerate",
500
+ 2: "removeSmallComponents",
501
+ 3: "orient",
502
+ 4: "fillHoles",
503
+ 23: "makeManifold",
504
+ 24: "resolveSelfIntersections",
505
+ 25: "cleanupSlivers"
506
+ };
507
+ const PRESET_CODES = {
508
+ general: 0,
509
+ scan3d: 1,
510
+ print3d: 2,
511
+ cadImport: 3
512
+ };
513
+ const SELF_INTERSECTION_MODES = [
514
+ "none",
515
+ "deleteAndFill",
516
+ "cutAndStitch",
517
+ "voxelHeal"
518
+ ];
519
+ const SELF_INTERSECTION_MODE_CODES = {
520
+ none: 0,
521
+ deleteAndFill: 1,
522
+ cutAndStitch: 2,
523
+ voxelHeal: 3
524
+ };
481
525
  const FALLOFF_CODES = {
482
526
  linear: 0,
483
527
  smooth: 1
484
528
  };
529
+ const INFLATE_METHOD_CODES = {
530
+ vertexNormal: 0,
531
+ averageNormal: 1,
532
+ strokeNormal: 2
533
+ };
534
+ const SMOOTH_METHOD_CODES = {
535
+ taubin: 0,
536
+ laplacian: 1,
537
+ hcLaplacian: 2,
538
+ cotangent: 3
539
+ };
540
+ const GRAB_METHOD_CODES = {
541
+ sphere: 0,
542
+ geodesic: 1,
543
+ kelvinlet: 2
544
+ };
545
+ const FLATTEN_MODE_CODES = {
546
+ both: 0,
547
+ peaks: 1,
548
+ valleys: 2
549
+ };
550
+ const CLAY_PROFILE_CODES = {
551
+ round: 0,
552
+ strips: 1
553
+ };
554
+ const TWIST_METHOD_CODES = {
555
+ vortex: 0,
556
+ kelvinlet: 1
557
+ };
558
+ const OFFSET_ALGORITHM_CODES = {
559
+ normal: 0,
560
+ fhEdt: 1,
561
+ bvhSdf: 2
562
+ };
485
563
  const SUBDIVIDE_METHOD_CODES = { loop: 0 };
486
564
  /** An optional number for the binding: NaN when unset; an explicit NaN is rejected. */
487
565
  /** The `status` codes of `WasmScene.register`, in order. */
@@ -508,6 +586,16 @@ function optional(v, what) {
508
586
  function flagOf(v, fallback) {
509
587
  return v ?? fallback ? 1 : 0;
510
588
  }
589
+ function optVoxelSize(v) {
590
+ if (v === void 0) return NaN;
591
+ if (typeof v !== "number" || !Number.isFinite(v) || v <= 0) throw invalid("voxelSize must be positive and finite");
592
+ return v;
593
+ }
594
+ function optMaxVoxels(v) {
595
+ if (v === void 0) return NaN;
596
+ if (typeof v !== "number" || !Number.isInteger(v) || v < 64 || v > Number.MAX_SAFE_INTEGER) throw invalid("maxVoxels must be an integer of at least 64");
597
+ return v;
598
+ }
511
599
  /** A brush center as 3 values; anything else is `INVALID_ARGUMENT`. */
512
600
  function centerOf(center, values) {
513
601
  const c = center;
@@ -528,12 +616,76 @@ function encodeLoopId(id, out) {
528
616
  function isAutoRepair(op) {
529
617
  return op?.kind === "auto";
530
618
  }
619
+ function optionalVec3(v, what, values) {
620
+ if (v === void 0) {
621
+ values.push(0, 0, 0, 0);
622
+ return;
623
+ }
624
+ const c = v;
625
+ if (c?.length !== 3 || ![
626
+ c[0],
627
+ c[1],
628
+ c[2]
629
+ ].every((x) => typeof x === "number" && Number.isFinite(x))) throw invalid(`${what} must be 3 finite numbers`);
630
+ values.push(1, c[0], c[1], c[2]);
631
+ }
632
+ /** The prefix that wraps the op after it in a {@link VertexProtection}; see `crate::edit` in the Rust crate. */
633
+ function encodeProtect(protect, values) {
634
+ const { vertices, weights, band } = protect;
635
+ if (vertices?.length === void 0) throw invalid("protect.vertices must be an array of vertex ids");
636
+ const n = vertices.length;
637
+ if (weights !== void 0 && weights.length !== n) throw invalid("protect.weights must have one weight per vertex");
638
+ values.push(PROTECT_CODE, n, optional(band, "protect.band"));
639
+ for (let k = 0; k < n; k++) values.push(vertices[k]);
640
+ for (let k = 0; k < n; k++) values.push(weights === void 0 ? 0 : weights[k]);
641
+ }
642
+ /** Encodes prefix `33` (`brushModifiers`: symmetry + surface filter) before a brush op. */
643
+ function encodeBrushModifiers(symmetry, filter, values) {
644
+ if (symmetry === void 0 && filter === void 0) return;
645
+ let symMask = 0;
646
+ if (symmetry !== void 0) {
647
+ if (typeof symmetry !== "object" || symmetry === null) throw invalid("symmetry must be an object");
648
+ if (symmetry.x) symMask |= 1;
649
+ if (symmetry.y) symMask |= 2;
650
+ if (symmetry.z) symMask |= 4;
651
+ }
652
+ let filterKind = 0;
653
+ let p0 = NaN;
654
+ let p1 = NaN;
655
+ let normal;
656
+ if (filter !== void 0) {
657
+ if (typeof filter !== "object" || filter === null) throw invalid("filter must be an object");
658
+ switch (filter.kind) {
659
+ case "none": break;
660
+ case "peaksOnly":
661
+ case "valleysOnly":
662
+ filterKind = filter.kind === "peaksOnly" ? 1 : 2;
663
+ p0 = optional(filter.threshold, "filter.threshold");
664
+ p1 = optional(filter.contrast, "filter.contrast");
665
+ break;
666
+ case "normalAngle":
667
+ filterKind = 3;
668
+ p0 = optional(filter.maxAngleDeg, "filter.maxAngleDeg");
669
+ normal = filter.normal;
670
+ break;
671
+ default: throw invalid("filter.kind must be \"none\", \"peaksOnly\", \"valleysOnly\" or \"normalAngle\"");
672
+ }
673
+ }
674
+ values.push(BRUSH_MODIFIERS_CODE, symMask, filterKind, p0, p1);
675
+ optionalVec3(normal, "filter.normal", values);
676
+ }
531
677
  /** A repair op list as the binding's `(ops, loops)`; see `crate::edit` in the Rust crate. */
532
678
  function encodeRepair(ops) {
533
679
  const values = [];
534
680
  const loops = [];
535
681
  for (const o of ops) {
536
- values.push(codeIn(REPAIR_CODES, o?.op, "repair op"));
682
+ const code = codeIn(REPAIR_CODES, o?.op, "repair op");
683
+ const protect = o?.protect;
684
+ if (protect !== void 0) encodeProtect(protect, values);
685
+ const symmetry = o?.symmetry;
686
+ const filter = o?.filter;
687
+ encodeBrushModifiers(symmetry, filter, values);
688
+ values.push(code);
537
689
  switch (o.op) {
538
690
  case "weld":
539
691
  values.push(optional(o.tolerance, "tolerance"));
@@ -557,9 +709,12 @@ function encodeRepair(ops) {
557
709
  }
558
710
  case "inflate":
559
711
  centerOf(o.center, values);
560
- values.push(optional(o.radius, "radius"), codeIn(FALLOFF_CODES, o.falloff, "falloff"), optional(o.strength, "strength"));
712
+ values.push(optional(o.radius, "radius"), codeIn(FALLOFF_CODES, o.falloff, "falloff"), optional(o.strength, "strength"), o.method === void 0 ? NaN : codeIn(INFLATE_METHOD_CODES, o.method, "inflate method"));
561
713
  break;
562
714
  case "smooth":
715
+ centerOf(o.center, values);
716
+ values.push(optional(o.radius, "radius"), codeIn(FALLOFF_CODES, o.falloff, "falloff"), optional(o.strength, "strength"), optional(o.cycles, "cycles"), o.method === void 0 ? NaN : codeIn(SMOOTH_METHOD_CODES, o.method, "smooth method"));
717
+ break;
563
718
  case "relax":
564
719
  centerOf(o.center, values);
565
720
  values.push(optional(o.radius, "radius"), codeIn(FALLOFF_CODES, o.falloff, "falloff"), optional(o.strength, "strength"), optional(o.cycles, "cycles"));
@@ -582,19 +737,59 @@ function encodeRepair(ops) {
582
737
  d[1],
583
738
  d[2]
584
739
  ].every(Number.isFinite)) throw invalid("direction must be 3 finite numbers");
585
- values.push(d[0], d[1], d[2]);
740
+ values.push(d[0], d[1], d[2], o.method === void 0 ? NaN : codeIn(GRAB_METHOD_CODES, o.method, "grab method"), optional(o.poisson, "poisson"), flagOf(o.fromStroke, false), flagOf(o.adaptiveReach, false));
586
741
  break;
587
742
  }
588
- case "offset":
589
- values.push(optional(o.distance, "distance"));
743
+ case "flatten":
744
+ centerOf(o.center, values);
745
+ values.push(optional(o.radius, "radius"), codeIn(FALLOFF_CODES, o.falloff, "falloff"), optional(o.strength, "strength"), o.mode === void 0 ? NaN : codeIn(FLATTEN_MODE_CODES, o.mode, "flatten mode"));
746
+ optionalVec3(o.planeOrigin, "planeOrigin", values);
747
+ optionalVec3(o.planeNormal, "planeNormal", values);
748
+ break;
749
+ case "crease":
750
+ centerOf(o.center, values);
751
+ values.push(optional(o.radius, "radius"), codeIn(FALLOFF_CODES, o.falloff, "falloff"), optional(o.strength, "strength"), optional(o.pinch, "pinch"));
752
+ break;
753
+ case "clay":
754
+ centerOf(o.center, values);
755
+ values.push(optional(o.radius, "radius"), codeIn(FALLOFF_CODES, o.falloff, "falloff"), optional(o.strength, "strength"), o.profile === void 0 ? NaN : codeIn(CLAY_PROFILE_CODES, o.profile, "clay profile"));
756
+ optionalVec3(o.tangent, "tangent", values);
590
757
  break;
758
+ case "twist":
759
+ centerOf(o.center, values);
760
+ values.push(optional(o.radius, "radius"), codeIn(FALLOFF_CODES, o.falloff, "falloff"), optional(o.strength, "strength"), o.method === void 0 ? NaN : codeIn(TWIST_METHOD_CODES, o.method, "twist method"));
761
+ optionalVec3(o.axis, "axis", values);
762
+ break;
763
+ case "offset": {
764
+ const distance = optional(o.distance, "distance");
765
+ const alg = o.algorithm === void 0 ? NaN : codeIn(OFFSET_ALGORITHM_CODES, o.algorithm, "algorithm");
766
+ values.push(distance, alg, optVoxelSize(o.voxelSize), optMaxVoxels(o.maxVoxels));
767
+ break;
768
+ }
591
769
  case "shell":
592
770
  values.push(optional(o.thickness, "thickness"));
593
771
  break;
594
772
  case "simplify":
595
773
  values.push(optional(o.targetTriangles, "targetTriangles"), flagOf(o.preserveBoundary, true));
596
774
  break;
597
- case "subdivide": values.push(o.method === void 0 ? NaN : codeIn(SUBDIVIDE_METHOD_CODES, o.method, "method"), optional(o.levels, "levels"));
775
+ case "subdivide":
776
+ values.push(o.method === void 0 ? NaN : codeIn(SUBDIVIDE_METHOD_CODES, o.method, "method"), optional(o.levels, "levels"));
777
+ break;
778
+ case "splitStretched":
779
+ centerOf(o.center, values);
780
+ values.push(optional(o.radius, "radius"), optional(o.limit, "limit"), optional(o.maxSplits, "maxSplits"), flagOf(o.smooth, true), optional(o.sharpAngle, "sharpAngle"));
781
+ break;
782
+ case "captureRestSizes":
783
+ case "captureStrokeState":
784
+ values.push(flagOf(o.onlyIfMissing, false));
785
+ break;
786
+ case "makeManifold":
787
+ values.push(flagOf(o.removeDuplicates, true), flagOf(o.pruneFins, true), flagOf(o.splitNonManifoldEdges, true), flagOf(o.splitPinchVertices, true));
788
+ break;
789
+ case "resolveSelfIntersections":
790
+ values.push(o.mode === void 0 ? NaN : codeIn(SELF_INTERSECTION_MODE_CODES, o.mode, "mode"), optional(o.ringExpansion, "ringExpansion"), optVoxelSize(o.voxelSize), optMaxVoxels(o.maxVoxels), optional(o.maxHoleEdges, "maxHoleEdges"), flagOf(o.fair, true), optional(o.stitchTolerance, "stitchTolerance"));
791
+ break;
792
+ case "cleanupSlivers": values.push(optional(o.maxAspectRatio, "maxAspectRatio"), optional(o.minAngleDeg, "minAngleDeg"), optional(o.maxAngleDeg, "maxAngleDeg"), optional(o.maxIterations, "maxIterations"));
598
793
  }
599
794
  }
600
795
  return {
@@ -695,12 +890,14 @@ function decodeReport(op, r) {
695
890
  reason: FAIL_REASONS[r.next()]
696
891
  }))
697
892
  };
698
- case "inflate": return {
699
- moved: r.next(),
700
- maxDisplacement: r.next()
701
- };
893
+ case "inflate":
702
894
  case "smooth":
703
- case "relax": return {
895
+ case "relax":
896
+ case "grab":
897
+ case "flatten":
898
+ case "crease":
899
+ case "clay":
900
+ case "twist": return {
704
901
  moved: r.next(),
705
902
  maxDisplacement: r.next()
706
903
  };
@@ -711,15 +908,16 @@ function decodeReport(op, r) {
711
908
  rounds: r.next()
712
909
  };
713
910
  case "bridgeLoops": return { trianglesAdded: r.next() };
714
- case "grab": return {
715
- moved: r.next(),
716
- maxDisplacement: r.next()
717
- };
718
911
  case "offset": return {
719
912
  moved: r.next(),
720
913
  maxDisplacement: r.next(),
721
914
  degenerateRemoved: r.next(),
722
- verticesRemoved: r.next()
915
+ verticesRemoved: r.next(),
916
+ verticesAdded: r.next(),
917
+ trianglesAdded: r.next(),
918
+ trianglesRemoved: r.next(),
919
+ voxelSize: r.next(),
920
+ uvsDropped: r.flag()
723
921
  };
724
922
  case "shell": return {
725
923
  verticesAdded: r.next(),
@@ -737,14 +935,50 @@ function decodeReport(op, r) {
737
935
  verticesAdded: r.next(),
738
936
  trianglesAdded: r.next()
739
937
  };
938
+ case "splitStretched": {
939
+ const splits = r.next();
940
+ const remaining = r.next();
941
+ const vertices = new Uint32Array(3 * splits);
942
+ for (let k = 0; k < vertices.length; k++) vertices[k] = r.next();
943
+ return {
944
+ splits,
945
+ remaining,
946
+ vertices
947
+ };
948
+ }
949
+ case "captureRestSizes":
950
+ case "captureStrokeState": return {};
951
+ case "makeManifold": return {
952
+ removedDuplicateTriangles: r.next(),
953
+ prunedFinTriangles: r.next(),
954
+ splitNonManifoldEdges: r.next(),
955
+ splitPinchVertices: r.next(),
956
+ verticesAdded: r.next(),
957
+ removedVertices: r.next()
958
+ };
959
+ case "resolveSelfIntersections": return {
960
+ initialPairs: r.next(),
961
+ remainingPairs: r.next(),
962
+ removedTriangles: r.next(),
963
+ addedTriangles: r.next(),
964
+ modeUsed: SELF_INTERSECTION_MODES[r.next()],
965
+ uvsDropped: r.flag()
966
+ };
967
+ case "cleanupSlivers": return {
968
+ collapsedNeedles: r.next(),
969
+ flippedCaps: r.next(),
970
+ removedDegenerate: r.next(),
971
+ removedVertices: r.next()
972
+ };
740
973
  }
741
974
  }
742
975
  /** An auto repair's result, stage by stage in the order they ran; see `crate::edit` in the Rust crate. */
743
976
  function decodeAutoReport(r) {
744
- const ops = Object.keys(REPAIR_CODES);
745
977
  const stages = {};
746
978
  while (r.at < r.data.length) {
747
- const op = ops[r.next()];
979
+ const code = r.next();
980
+ const op = AUTO_STAGE_OPS[code];
981
+ if (op === void 0) throw invalid(`unknown auto repair stage code ${code}`);
748
982
  stages[op] = decodeReport(op, r);
749
983
  }
750
984
  return stages;
@@ -841,6 +1075,67 @@ var Scene = class {
841
1075
  /** History step nesting depth, mirrored from the calls made through this class. */
842
1076
  #stepDepth = 0;
843
1077
  #drag;
1078
+ /**
1079
+ * Callable repair domain (`scene.repair(mesh, op)` and `scene.repair.<method>(...)`).
1080
+ */
1081
+ repair = createRepairDomain({
1082
+ repair: ((mesh, op) => this.#runRepair(mesh, op)),
1083
+ analyze: (mesh, options) => this.analyze(mesh, options),
1084
+ join: (target, source, options) => this.join(target, source, options)
1085
+ });
1086
+ /**
1087
+ * Callable sculpt domain (`scene.sculpt(mesh, op)` and `scene.sculpt.<method>(...)`).
1088
+ */
1089
+ sculpt = createSculptDomain({
1090
+ sculpt: ((mesh, op) => this.#runRepair(mesh, op)),
1091
+ verticesInSphere: (mesh, center, radius) => this.verticesInSphere(mesh, center, radius),
1092
+ beginStep: () => this.beginStep(),
1093
+ endStep: () => this.endStep(),
1094
+ cancelStep: () => this.cancelStep()
1095
+ });
1096
+ /** Remesh, simplification, subdivision, and volumetric reconstruction domain. */
1097
+ remesh = createRemeshDomain({ repair: ((mesh, op) => this.#runRepair(mesh, op)) });
1098
+ /** Callable boolean, cutting, offsetting, and shell domain. */
1099
+ boolean = createBooleanDomain({
1100
+ isAsync: false,
1101
+ repair: ((mesh, op) => this.#runRepair(mesh, op)),
1102
+ boolean: (target, source, op) => this.#runBoolean(target, source, op),
1103
+ cutByPlane: (mesh, plane, options) => this.cutByPlane(mesh, plane, options)
1104
+ });
1105
+ /** Surface deformation and vertex-protection domain. */
1106
+ deform = createDeformDomain({ sculpt: ((mesh, op) => this.#runRepair(mesh, op)) });
1107
+ /** Defect analysis, metrology, queries, fields, and section inspection domain. */
1108
+ inspect = createInspectDomain({
1109
+ analyze: (mesh, options) => this.analyze(mesh, options),
1110
+ measure: (mesh) => this.measure(mesh),
1111
+ bounds: (mesh) => this.bounds(mesh),
1112
+ raycast: (origin, direction, options) => this.raycast(origin, direction, options),
1113
+ closestPoint: (point, options) => this.closestPoint(point, options),
1114
+ meshDistance: (a, b, options) => this.meshDistance(a, b, options),
1115
+ intersects: (a, b) => this.intersects(a, b),
1116
+ findContacts: (options) => this.findContacts(options),
1117
+ addDistanceField: (desc) => this.addDistanceField(desc),
1118
+ addThicknessField: (desc) => this.addThicknessField(desc),
1119
+ addCurvatureField: (desc) => this.addCurvatureField(desc),
1120
+ removeField: (field) => this.removeField(field),
1121
+ fieldValues: (field) => this.fieldValues(field),
1122
+ fieldNearest: (field) => this.fieldNearest(field),
1123
+ fieldStatus: (field) => this.fieldStatus(field),
1124
+ fieldTargetStatus: (field) => this.fieldTargetStatus(field),
1125
+ setColoring: (mesh, rule) => this.setColoring(mesh, rule),
1126
+ coloring: (mesh) => this.coloring(mesh),
1127
+ addSection: (desc) => this.addSection(desc),
1128
+ setSectionPlane: (section, plane) => this.setSectionPlane(section, plane),
1129
+ sectionPlane: (section) => this.sectionPlane(section),
1130
+ setSectionMeshes: (section, meshes) => this.setSectionMeshes(section, meshes),
1131
+ setSectionFill: (section, fill) => this.setSectionFill(section, fill),
1132
+ removeSection: (section) => this.removeSection(section),
1133
+ section: (section, mesh) => this.section(section, mesh),
1134
+ sectionGap: (section, a, b) => this.sectionGap(section, a, b),
1135
+ updateSections: () => this.updateSections()
1136
+ });
1137
+ /** Rigid registration and alignment domain. */
1138
+ align = createAlignDomain({ register: (moving, fixed, options) => this.register(moving, fixed, options) });
844
1139
  constructor(options = {}) {
845
1140
  ensureInitialized("new Scene()");
846
1141
  this.#raw = call(() => new RawScene());
@@ -982,6 +1277,7 @@ var Scene = class {
982
1277
  * one step; the removal is permanent. A drag of the source ends first,
983
1278
  * recording its moves as one step, so they survive a failed join.
984
1279
  *
1280
+ * @deprecated Use `scene.repair.join()` instead.
985
1281
  * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` for one
986
1282
  * mesh twice or loops that cannot bridge; `STALE_LOOPS` for a loop that is
987
1283
  * not there. A failed join changes nothing.
@@ -1009,14 +1305,20 @@ var Scene = class {
1009
1305
  * (`signedDistance >= 0`) stays on the mesh and the `-` side is added as
1010
1306
  * a new mesh with the same placement, so the world shape is kept.
1011
1307
  * Cutting a closed mesh with `cap` (the default) yields two closed
1012
- * meshes, capped with flat, unfaired patches.
1308
+ * meshes, capped with flat, unfaired patches. On a mesh with UVs, closed
1309
+ * means closed by exact position, so seams count as closed: the cap's UVs
1310
+ * come from the rim and blend across a seam. A rim that runs into a real
1311
+ * boundary of an open mesh stays open. A mesh without UVs is read by vertex
1312
+ * index, so its split vertices are such a boundary: weld it first.
1013
1313
  *
1014
1314
  * The cut undoes in one step; the added mesh stays, like the removed
1015
1315
  * source of {@link Scene.join}.
1016
1316
  *
1317
+ * @deprecated Use `scene.boolean.cut()` instead.
1017
1318
  * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` when
1018
- * the plane does not cut the mesh or a rim cannot be capped. A failed cut
1019
- * changes nothing.
1319
+ * the plane does not cut the mesh or a rim cannot be capped, as listed in
1320
+ * `docs/uv-channel.md`, for example a rim that closes by position with its
1321
+ * walls wound against each other. A failed cut changes nothing.
1020
1322
  */
1021
1323
  cutByPlane(mesh, plane, options) {
1022
1324
  const { index, generation } = this.#id(mesh);
@@ -1043,7 +1345,7 @@ var Scene = class {
1043
1345
  * input that is not closed, manifold and consistently wound. A failed
1044
1346
  * boolean changes nothing.
1045
1347
  */
1046
- boolean(target, source, op) {
1348
+ #runBoolean(target, source, op) {
1047
1349
  const ta = this.#id(target);
1048
1350
  const sb = this.#id(source);
1049
1351
  const code = codeIn({
@@ -1082,6 +1384,7 @@ var Scene = class {
1082
1384
  * followed exactly on a copy baked through it, so each such call costs a BVH
1083
1385
  * build. All distances are in world units.
1084
1386
  *
1387
+ * @deprecated Use `scene.align.register()` instead.
1085
1388
  * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` for one
1086
1389
  * mesh twice, a mesh without triangles or an invalid option; `STALE_BVH` for
1087
1390
  * a stale Manual `fixed`. Bad options and one mesh twice change nothing,
@@ -1171,6 +1474,19 @@ var Scene = class {
1171
1474
  };
1172
1475
  }
1173
1476
  /**
1477
+ * The mesh's origin. `views(mesh).positions()` are relative to it, while
1478
+ * `edit`'s `setPositions` and `addVertices` take positions with it added.
1479
+ */
1480
+ origin(mesh) {
1481
+ const { index, generation } = this.#id(mesh);
1482
+ const o = call(() => this.#peek().origin(index, generation));
1483
+ return [
1484
+ o[0],
1485
+ o[1],
1486
+ o[2]
1487
+ ];
1488
+ }
1489
+ /**
1174
1490
  * The column-major world matrix of the local render coordinates,
1175
1491
  * `placement · translate(origin)`, ready for renderers (convert to `f32`
1176
1492
  * yourself). The rotation columns carry the scale; normals need the
@@ -1180,6 +1496,29 @@ var Scene = class {
1180
1496
  const { index, generation } = this.#id(mesh);
1181
1497
  return call(() => this.#peek().matrix4(index, generation));
1182
1498
  }
1499
+ /**
1500
+ * Starts (`points`) or ends (`null`) an interaction: a gesture that changes
1501
+ * a placement or a mesh many times a second (a drag, a brush stroke), during
1502
+ * which a distance field too large to recompute per update stays live near
1503
+ * the contact, and is made exact when the gesture ends.
1504
+ *
1505
+ * While it lasts, a field with more finite values than `points` updates
1506
+ * only the vertices near its moved targets (within a margin that follows
1507
+ * the work, about `points` vertices an update), the vertices an edit moved
1508
+ * and a sweep of a quarter of `points` others. The rest keep their values
1509
+ * and colours, out of date by at most how far the meshes moved since, so
1510
+ * nothing turns far meanwhile. A smaller field updates as usual. Ending it
1511
+ * recomputes the fields it left out of date: their values and colours are
1512
+ * then those of an exact update. A gesture that changed nothing costs
1513
+ * nothing. The results do not depend on the thread count.
1514
+ *
1515
+ * @throws `INVALID_ARGUMENT` unless `points` is `null` or an integer in
1516
+ * `[1, 2^32)`.
1517
+ */
1518
+ setFieldInteraction(points) {
1519
+ const budget = checkInteractionPoints(points);
1520
+ call(() => this.#scene().set_field_interaction(budget ?? void 0));
1521
+ }
1183
1522
  /** Sets when the mesh's derived data follows its edits; see {@link UpdateMode}. */
1184
1523
  setMode(mesh, mode) {
1185
1524
  const { index, generation } = this.#id(mesh);
@@ -1529,6 +1868,7 @@ var Scene = class {
1529
1868
  * triangles, non-manifold edges and vertices, components, orientation
1530
1869
  * conflicts and, on request, self-intersection.
1531
1870
  *
1871
+ * @deprecated Use `scene.inspect.analyze()` or `scene.repair.analyze()` instead.
1532
1872
  * @throws `INVALID_ARGUMENT` for a negative or non-finite `weldTolerance`; `STALE_BVH`, see {@link AnalyzeOptions.selfIntersection}.
1533
1873
  */
1534
1874
  analyze(mesh, options = {}) {
@@ -1545,6 +1885,8 @@ var Scene = class {
1545
1885
  * non-manifold mesh still gets its area; only `volume` is `null`, with
1546
1886
  * `volumeReason` saying why. A read-only call: it leaves every view
1547
1887
  * valid.
1888
+ *
1889
+ * @deprecated Use `scene.inspect.measure()` instead.
1548
1890
  */
1549
1891
  measure(mesh) {
1550
1892
  const { index, generation } = this.#id(mesh);
@@ -1560,11 +1902,24 @@ var Scene = class {
1560
1902
  orientationConflicts: r[6]
1561
1903
  };
1562
1904
  }
1563
- repair(mesh, op) {
1905
+ /**
1906
+ * Runs one repair operation and returns its report, or a list of them in
1907
+ * order and returns their reports. A list is one transaction: one undo step,
1908
+ * and when any operation fails nothing changes and nothing is recorded.
1909
+ * `{ kind: "auto" }` runs the standard cleanup pipeline the same way and
1910
+ * returns a report per stage; see {@link AutoRepairRequest}.
1911
+ */
1912
+ #runRepair(mesh, op) {
1564
1913
  const { index, generation } = this.#id(mesh);
1565
1914
  if (isAutoRepair(op)) {
1566
- const values = Float64Array.of(AUTO_REPAIR_CODE, optional(op.weldTolerance, "weldTolerance"), optional(op.minTriangles, "minTriangles"), optional(op.maxEdges, "maxEdges"), op.fair === void 0 ? NaN : flagOf(op.fair, true));
1567
1915
  const noLoops = /* @__PURE__ */ new Uint32Array();
1916
+ if (op.preset === void 0 && op.selfIntersectionMode === void 0 && op.voxelSize === void 0 && op.maxVoxels === void 0) {
1917
+ const values = Float64Array.of(AUTO_REPAIR_CODE, optional(op.weldTolerance, "weldTolerance"), optional(op.minTriangles, "minTriangles"), optional(op.maxEdges, "maxEdges"), op.fair === void 0 ? NaN : flagOf(op.fair, true));
1918
+ return decodeAutoReport(new Reader(call(() => this.#scene().repair(index, generation, values, noLoops))));
1919
+ }
1920
+ const preset = op.preset === void 0 ? NaN : codeIn(PRESET_CODES, op.preset, "preset");
1921
+ const siMode = op.selfIntersectionMode === void 0 ? NaN : codeIn(SELF_INTERSECTION_MODE_CODES, op.selfIntersectionMode, "selfIntersectionMode");
1922
+ const values = Float64Array.of(AUTO_REPAIR_PRESET_CODE, preset, siMode, optional(op.weldTolerance, "weldTolerance"), optional(op.minTriangles, "minTriangles"), optional(op.maxEdges, "maxEdges"), op.fair === void 0 ? NaN : flagOf(op.fair, true), optVoxelSize(op.voxelSize), optMaxVoxels(op.maxVoxels));
1568
1923
  return decodeAutoReport(new Reader(call(() => this.#scene().repair(index, generation, values, noLoops))));
1569
1924
  }
1570
1925
  const ops = Array.isArray(op) ? op : [op];
@@ -1574,10 +1929,32 @@ var Scene = class {
1574
1929
  return Array.isArray(op) ? reports : reports[0];
1575
1930
  }
1576
1931
  /**
1932
+ * Live triangle-used vertex ids of `mesh` inside the closed local-space
1933
+ * sphere `(center, radius)`, in ascending order. Brings a `"lazy"` BVH up
1934
+ * to date first; throws `STALE_BVH` on a stale `"manual"` mesh.
1935
+ *
1936
+ * @deprecated Use `scene.sculpt.verticesInSphere()` instead.
1937
+ * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` when
1938
+ * `center` is not 3 finite numbers or `radius` is negative or non-finite;
1939
+ * `STALE_BVH` for a stale `"manual"` mesh.
1940
+ */
1941
+ verticesInSphere(mesh, center, radius) {
1942
+ const { index, generation } = this.#id(mesh);
1943
+ const c = center;
1944
+ if (c?.length !== 3 || ![
1945
+ c[0],
1946
+ c[1],
1947
+ c[2]
1948
+ ].every((x) => typeof x === "number" && Number.isFinite(x))) throw invalid("center must be 3 finite numbers");
1949
+ if (typeof radius !== "number" || !Number.isFinite(radius) || radius < 0) throw invalid("radius must be a finite non-negative number");
1950
+ return call(() => this.#scene().vertices_in_sphere(index, generation, c[0], c[1], c[2], radius));
1951
+ }
1952
+ /**
1577
1953
  * The nearest hit of a world ray over every mesh, or `null`. `direction`
1578
1954
  * need not be unit length; `distance` is in world units. Lazy meshes are
1579
1955
  * brought up to date first.
1580
1956
  *
1957
+ * @deprecated Use `scene.inspect.raycast()` instead.
1581
1958
  * @throws `INVALID_ARGUMENT` for a non-finite origin or a zero direction; `STALE_BVH` for a stale `"manual"` mesh.
1582
1959
  */
1583
1960
  raycast(origin, direction, options = {}) {
@@ -1600,6 +1977,8 @@ var Scene = class {
1600
1977
  /**
1601
1978
  * The surface point nearest to a world point, over every mesh or one, or
1602
1979
  * `null` when none is within `maxDistance`.
1980
+ *
1981
+ * @deprecated Use `scene.inspect.closestPoint()` instead.
1603
1982
  */
1604
1983
  closestPoint(point, options = {}) {
1605
1984
  const s = this.#scene();
@@ -1623,6 +2002,8 @@ var Scene = class {
1623
2002
  * The distance between two meshes' surfaces as placed, with a closest pair
1624
2003
  * of points, or `null` when it exceeds `maxDistance` (default `Infinity`)
1625
2004
  * or a mesh has no triangle.
2005
+ *
2006
+ * @deprecated Use `scene.inspect.meshDistance()` instead.
1626
2007
  */
1627
2008
  meshDistance(a, b, options = {}) {
1628
2009
  const ia = this.#id(a);
@@ -1638,13 +2019,21 @@ var Scene = class {
1638
2019
  triangleB: d[8]
1639
2020
  };
1640
2021
  }
1641
- /** Whether two meshes intersect or touch as placed. */
2022
+ /**
2023
+ * Whether two meshes intersect or touch as placed.
2024
+ *
2025
+ * @deprecated Use `scene.inspect.intersects()` instead.
2026
+ */
1642
2027
  intersects(a, b) {
1643
2028
  const ia = this.#id(a);
1644
2029
  const ib = this.#id(b);
1645
2030
  return call(() => this.#scene().intersects(ia.index, ia.generation, ib.index, ib.generation));
1646
2031
  }
1647
- /** Every mesh pair (or every pair of `pairs`) within `margin`, sorted by mesh id. */
2032
+ /**
2033
+ * Every mesh pair (or every pair of `pairs`) within `margin`, sorted by mesh id.
2034
+ *
2035
+ * @deprecated Use `scene.inspect.findContacts()` instead.
2036
+ */
1648
2037
  findContacts(options = {}) {
1649
2038
  const s = this.#scene();
1650
2039
  const pairs = options.pairs === void 0 ? void 0 : this.#flatIds(options.pairs.flat());
@@ -1823,6 +2212,7 @@ var Scene = class {
1823
2212
  * edits and placements by the mesh modes, like normals. Removing a mesh of
1824
2213
  * `to` removes it from the field, or the field with its last target.
1825
2214
  *
2215
+ * @deprecated Use `scene.inspect.addDistanceField()` instead.
1826
2216
  * @throws `INVALID_ARGUMENT` when `to` is empty, holds `on` or a mesh twice, `maxDistance` is negative or NaN, or the name is taken.
1827
2217
  */
1828
2218
  addDistanceField(desc) {
@@ -1835,6 +2225,7 @@ var Scene = class {
1835
2225
  * `maxDistance` read `Infinity`. It follows edits and placements by the
1836
2226
  * mesh modes, like normals, and colours like any field.
1837
2227
  *
2228
+ * @deprecated Use `scene.inspect.addThicknessField()` instead.
1838
2229
  * @throws `INVALID_ARGUMENT` when `maxDistance` is negative or NaN, or the name is taken.
1839
2230
  */
1840
2231
  addThicknessField(desc) {
@@ -1850,6 +2241,7 @@ var Scene = class {
1850
2241
  * negative in bowls, zero on flats). It follows edits and placements by
1851
2242
  * the mesh modes, like normals, and colours like any field.
1852
2243
  *
2244
+ * @deprecated Use `scene.inspect.addCurvatureField()` instead.
1853
2245
  * @throws `INVALID_ARGUMENT` when the name is taken.
1854
2246
  */
1855
2247
  addCurvatureField(desc) {