fast-mesh-wasm 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +91 -3
  2. package/dist/{api-BUy7FRx7.js → api-4kz45-Mq.js} +2 -3
  3. package/dist/{client-CE6RvmvB.js → client-BIPPznBZ.js} +108 -24
  4. package/dist/{client-pv0Fwvl4.d.ts → client-Uo7hHvD8.d.ts} +25 -11
  5. package/dist/{colormap-DxGMYVfs.js → colormap-Dr5V3bvs.js} +1 -2
  6. package/dist/{core-Cke_kZ2e.js → core-4OcWKu3r.js} +2 -2
  7. package/dist/{core-D2X9GPfK.d.ts → core-CJ9D6U5A.d.ts} +1 -3
  8. package/dist/{engine-DLQAL9GT.js → engine-BS8i5U8J.js} +41 -11
  9. package/dist/io.d.ts +306 -0
  10. package/dist/io.js +1479 -0
  11. package/dist/{mesh-RtPVmPQy.d.ts → mesh-CqAIuOxU.d.ts} +15 -6
  12. package/dist/{mesh-zj7-wJBw.js → mesh-hPWBQPaN.js} +31 -8
  13. package/dist/node.d.ts +3 -5
  14. package/dist/node.js +4 -5
  15. package/dist/{protocol-z-jeCUGO.d.ts → protocol-BHAI0xiA.d.ts} +25 -7
  16. package/dist/{protocol-DkhGNP0h.js → protocol-Ci9LLiwO.js} +1 -2
  17. package/dist/r3f.d.ts +22 -6
  18. package/dist/r3f.js +28 -19
  19. package/dist/{react-CTADh3NN.js → react-DzrtrzZy.js} +4 -6
  20. package/dist/react.d.ts +4 -6
  21. package/dist/react.js +1 -1
  22. package/dist/{scene-like-YcY08oii.d.ts → scene-like-CavrKbpQ.d.ts} +590 -47
  23. package/dist/{scene-DyYdEQdy.js → scene-rsfM06St.js} +711 -21
  24. package/dist/{snapshot-Cf6NgDl7.js → snapshot-BkbGPspK.js} +1 -2
  25. package/dist/{store-C5nzCpxy.d.ts → store-CZwml1K3.d.ts} +5 -10
  26. package/dist/{store-Z6A2HPih.js → store-m9l0Al-m.js} +9 -12
  27. package/dist/store.d.ts +2 -4
  28. package/dist/store.js +4 -5
  29. package/dist/three.d.ts +2 -6
  30. package/dist/three.js +4 -6
  31. package/dist/{views-Dh3aWc2q.js → views-CdOArjcB.js} +6 -8
  32. package/dist/wasm/fast_mesh_wasm.d.ts +113 -8
  33. package/dist/wasm/fast_mesh_wasm.js +267 -8
  34. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  35. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +13 -1
  36. package/dist/wasm-threads/fast_mesh_wasm.d.ts +113 -8
  37. package/dist/wasm-threads/fast_mesh_wasm.js +268 -9
  38. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
  39. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +13 -1
  40. package/dist/web.d.ts +3 -5
  41. package/dist/web.js +4 -5
  42. package/dist/worker-engine.d.ts +1 -7
  43. package/dist/worker-engine.js +1 -1
  44. package/dist/worker-entry.js +2 -3
  45. package/dist/worker.d.ts +2 -2
  46. package/dist/worker.js +1 -1
  47. package/package.json +16 -4
@@ -1,5 +1,4 @@
1
1
  import { InitInput, WasmScene } from "./wasm/fast_mesh_wasm.js";
2
- //#region src/api.d.ts
3
2
  /** A 3D vector `[x, y, z]`. */
4
3
  type Vec3 = [x: number, y: number, z: number];
5
4
  /**
@@ -28,17 +27,27 @@ type Mat3 = readonly number[];
28
27
  * `update(mesh)` (`"manual"`).
29
28
  */
30
29
  type UpdateMode = "eager" | "lazy" | "manual";
31
- /** A placement to set: a rotation (row-major matrix or quaternion) and a translation. */
30
+ /** A placement to set: a rotation (row-major matrix or quaternion), a per-axis scale and a translation. */
32
31
  interface PlacementInput {
33
32
  /** A proper rotation: 9 numbers row-major, or a quaternion `[x, y, z, w]`. */
34
33
  rotation: Mat3 | Quat;
35
34
  translation: Readonly<Vec3>;
35
+ /**
36
+ * Per-axis scale: 3 finite positive numbers. Defaults to `[1, 1, 1]`
37
+ * (rigid). Both uniform and non-uniform scales are supported.
38
+ */
39
+ scale?: Readonly<Vec3>;
36
40
  }
37
- /** A mesh placement: world = rotation · local + translation. */
41
+ /** A mesh placement: world = rotation · (scale · local) + translation. */
38
42
  interface Placement {
39
43
  /** 9 numbers, row-major. */
40
44
  rotation: number[];
41
45
  translation: Vec3;
46
+ /**
47
+ * 3 numbers; `[1, 1, 1]` for a rigid placement. Always present from
48
+ * {@link Scene} and `WorkerScene`; absent on hosts that do not track scale.
49
+ */
50
+ scale?: Vec3;
42
51
  }
43
52
  /** Axis-aligned bounding box. */
44
53
  interface Bounds {
@@ -67,8 +76,29 @@ declare function computeVertexNormals(positions: Positions, indices: Indices): F
67
76
  * @throws If `positions` is empty or its length is not a multiple of 3.
68
77
  */
69
78
  declare function computeBounds(positions: Positions): Bounds;
70
- //#endregion
71
- //#region src/views.d.ts
79
+ /**
80
+ * A mesh in a {@link Scene}. Opaque: pass it to the scene's methods. The same
81
+ * mesh always gives the same handle object, so handles compare with `===`.
82
+ */
83
+ declare class MeshHandle {
84
+ private readonly brand;
85
+ }
86
+ /**
87
+ * A field in a {@link Scene}. Opaque and deduplicated like {@link MeshHandle}.
88
+ * The scene keeps every field handle it gave out for its own lifetime, even
89
+ * after the field is removed, so a removal in a change record names the same
90
+ * object you hold.
91
+ */
92
+ declare class FieldHandle {
93
+ private readonly brand;
94
+ }
95
+ /**
96
+ * A section in a {@link Scene}. Opaque and deduplicated like {@link MeshHandle},
97
+ * and kept for the scene's lifetime like {@link FieldHandle}.
98
+ */
99
+ declare class SectionHandle {
100
+ private readonly brand;
101
+ }
72
102
  /**
73
103
  * Zero-copy views of one mesh's render buffers, slot-aligned.
74
104
  *
@@ -98,40 +128,72 @@ interface MeshViews {
98
128
  * provide it.
99
129
  */
100
130
  values?(): Float32Array | null;
131
+ /**
132
+ * Texture coordinates, 2 floats per vertex slot, or `null` for a mesh
133
+ * without them (never given, or dropped by an operation: see
134
+ * `docs/uv-channel.md`). Optional for other {@link SceneLike} hosts; `Scene`
135
+ * and `WorkerScene` provide it ({@link SceneMeshViews}).
136
+ */
137
+ uvs?(): Float32Array | null;
101
138
  /** 3 vertex indices per triangle slot; a removed triangle reads `0, 0, 0`. */
102
139
  indices(): Uint32Array;
103
140
  }
104
- //#endregion
105
- //#region src/changes.d.ts
141
+ /** {@link MeshViews} of `Scene` and `WorkerScene`, which always provide `uvs`. */
142
+ interface SceneMeshViews extends MeshViews {
143
+ uvs(): Float32Array | null;
144
+ }
106
145
  /** `[start, count]` in elements: vertex slots, or triangle slots for indices. */
107
146
  type Range = readonly [start: number, count: number];
108
- //#endregion
109
- //#region src/handles.d.ts
110
- /**
111
- * A mesh in a {@link Scene}. Opaque: pass it to the scene's methods. The same
112
- * mesh always gives the same handle object, so handles compare with `===`.
113
- */
114
- declare class MeshHandle {
115
- private readonly brand;
147
+ /** A snapshot of selected vertices of one mesh; see the module docs. */
148
+ interface VertexSelection {
149
+ /** The mesh selected from. */
150
+ mesh: MeshHandle;
151
+ /** The selected vertex slots, ascending. */
152
+ vertices: Uint32Array;
153
+ /** The mesh's content stamp when taken; see `Scene.selectionAlive`. */
154
+ stamp: number;
116
155
  }
117
- /**
118
- * A field in a {@link Scene}. Opaque and deduplicated like {@link MeshHandle}.
119
- * The scene keeps every field handle it gave out for its own lifetime, even
120
- * after the field is removed, so a removal in a change record names the same
121
- * object you hold.
122
- */
123
- declare class FieldHandle {
124
- private readonly brand;
156
+ /** A sphere brush: every used vertex within `radius` of `center`. */
157
+ interface BrushSelect {
158
+ kind: "brush";
159
+ /** Brush centre; `space` says which coordinates it is in. */
160
+ center: Readonly<Vec3>;
161
+ /** Radius in the same units; 0 selects vertices exactly at `center`. */
162
+ radius: number;
163
+ /**
164
+ * `"local"` (mesh render coordinates, as in `views(mesh).positions()`) or
165
+ * `"world"` (converted with the mesh's placement at call time). Defaults
166
+ * to `"local"`.
167
+ */
168
+ space?: "local" | "world";
125
169
  }
126
170
  /**
127
- * A section in a {@link Scene}. Opaque and deduplicated like {@link MeshHandle},
128
- * and kept for the scene's lifetime like {@link FieldHandle}.
171
+ * A 2D polygon: every used vertex whose projection falls inside it.
172
+ * Project your screen-space polygon to mesh-local coordinates with your
173
+ * camera first; `axis` picks the projection plane.
129
174
  */
130
- declare class SectionHandle {
131
- private readonly brand;
175
+ interface LassoSelect {
176
+ kind: "lasso";
177
+ /** Flat `[x0, y0, x1, y1, ...]` polygon corners in local coordinates. */
178
+ polygon: Float32Array | readonly number[];
179
+ /** The local plane projected onto. Defaults to `"xy"`. */
180
+ axis?: "xy" | "xz" | "yz";
181
+ }
182
+ /** The connected component (over shared triangle edges) holding `seed`. */
183
+ interface ComponentSelect {
184
+ kind: "component";
185
+ /** A vertex slot of the component to pick; it must be alive. */
186
+ seed: number;
187
+ }
188
+ /** What `Scene.select` takes. */
189
+ type SelectSpec = BrushSelect | LassoSelect | ComponentSelect;
190
+ /** What `Scene.isolate` did. */
191
+ interface IsolateReport {
192
+ /** Triangles fully outside the selection that were removed. */
193
+ removedTriangles: number;
194
+ /** The same vertex set with the post-edit stamp. */
195
+ selection: VertexSelection;
132
196
  }
133
- //#endregion
134
- //#region src/scene.d.ts
135
197
  /**
136
198
  * What changed in one mesh since the previous {@link Scene.takeChanges}.
137
199
  * Range lists are ascending; `"all"` means re-upload the whole buffer.
@@ -157,6 +219,12 @@ interface MeshChange {
157
219
  colors: Range[] | "all";
158
220
  /** Triangle slots. */
159
221
  indices: Range[] | "all";
222
+ /**
223
+ * Vertex slots. Only on a record of a mesh that has UVs or just lost them:
224
+ * `"all"` with `views(mesh).uvs()` reading `null` means an operation dropped
225
+ * them, and `"all"` after `undo` that they came back.
226
+ */
227
+ uvs?: Range[] | "all";
160
228
  fieldsChanged: FieldHandle[];
161
229
  sectionsChanged: SectionHandle[];
162
230
  }
@@ -225,6 +293,13 @@ interface AddMeshOptions {
225
293
  mode?: UpdateMode;
226
294
  /** Keep vertex normals up to date. Defaults to `true`. */
227
295
  normals?: boolean;
296
+ /**
297
+ * Texture coordinates: 2 finite values per vertex, stored as `f32` and read
298
+ * back with `views(mesh).uvs()`. Without them the mesh has no UV channel and
299
+ * pays nothing. Every operation keeps them aligned or drops them, undoably;
300
+ * see `docs/uv-channel.md`. Weld keeps seams apart.
301
+ */
302
+ uvs?: Float32Array | readonly number[];
228
303
  }
229
304
  /** Options of the {@link Scene} constructor. */
230
305
  interface SceneOptions {
@@ -329,6 +404,41 @@ interface DistanceFieldDesc {
329
404
  /** Defaults to `"auto"`. */
330
405
  sign?: SignMode;
331
406
  }
407
+ /**
408
+ * A per-vertex wall-thickness field to add with
409
+ * {@link Scene.addThicknessField}: the distance to the opposite surface
410
+ * along each vertex's smooth normal, in world units (the placement's scale
411
+ * applied, so scaled meshes read scaled).
412
+ *
413
+ * Vertices whose rays escape in both directions (open sheets, the rims of
414
+ * open meshes), dead slots and unused vertices hold NaN; hits beyond
415
+ * `maxDistance` hold `Infinity`. Colour it like any field: NaN takes the
416
+ * rule's `nan` colour, `Infinity` follows `above`.
417
+ */
418
+ interface ThicknessFieldDesc {
419
+ /** Unique among the fields on `on`. */
420
+ name: string;
421
+ /** The mesh whose vertices carry the values. */
422
+ on: MeshHandle;
423
+ /** Largest thickness kept (inclusive); thicker vertices hold `Infinity`. May be `Infinity`. */
424
+ maxDistance: number;
425
+ }
426
+ /**
427
+ * A per-vertex curvature field to add with
428
+ * {@link Scene.addCurvatureField}: the signed mean curvature at each vertex,
429
+ * in 1/world-units (positive on domes, about `1 / r` on a sphere of radius
430
+ * `r` with outward normals; negative in bowls and dents; zero on flat
431
+ * spots; a saddle takes the sign of its dominant bend).
432
+ *
433
+ * Dead slots and vertices no triangle uses hold NaN; colour it like any
434
+ * field: NaN takes the rule's `nan` colour.
435
+ */
436
+ interface CurvatureFieldDesc {
437
+ /** Unique among the fields on `on`. */
438
+ name: string;
439
+ /** The mesh whose vertices carry the values. */
440
+ on: MeshHandle;
441
+ }
332
442
  /** The state of a field, from {@link Scene.fieldStatus}. */
333
443
  interface FieldStatus {
334
444
  /** True when the values match the meshes and placements as they are now. */
@@ -454,6 +564,18 @@ type EditOp = {
454
564
  } | {
455
565
  op: "removeVertices";
456
566
  vertices: Uint32Array | readonly number[] | readonly EditRef[];
567
+ } |
568
+ /**
569
+ * Sets the UVs of vertices (2 values each; undoable like the rest of the
570
+ * edit), `addVertices` ones included. `addVertices` alone gives a mesh with
571
+ * UVs the UV `(0, 0)`, and `setPositions` leaves them as they were.
572
+ *
573
+ * @throws `INVALID_ARGUMENT` on a mesh without UVs.
574
+ */
575
+ {
576
+ op: "setUvs";
577
+ vertices: Uint32Array | readonly (number | EditRef)[];
578
+ uvs: Float32Array | readonly number[];
457
579
  };
458
580
  /** What {@link Scene.edit} added. */
459
581
  interface EditResult {
@@ -524,8 +646,36 @@ interface Analysis {
524
646
  selfIntersects: boolean | null;
525
647
  }
526
648
  /**
527
- * Options of {@link Scene.analyze}. Distances are in mesh units: placements are
528
- * rigid, so local and world distances agree.
649
+ * Scalar measurements of a mesh, from {@link Scene.measure}. The report is
650
+ * in world coordinates (the placement applied), so scaled meshes measure
651
+ * scaled. Thickness (#116) and curvature (#117) build on this.
652
+ */
653
+ interface MeasureResult {
654
+ /** The total triangle area; always defined. */
655
+ area: number;
656
+ /**
657
+ * The enclosed volume, or `null` when the mesh is not watertight (open
658
+ * or non-manifold), with `volumeReason` saying why. The volume is the
659
+ * absolute signed sum, so inconsistent winding does not fail the call:
660
+ * it only shows up in `orientationConflicts`, while partly cancelling
661
+ * the number. Require `orientationConflicts === 0` for a strict reading.
662
+ */
663
+ volume: number | null;
664
+ /** No boundary loop or open chain and no non-manifold edge. */
665
+ closed: boolean;
666
+ /** Why `volume` is `null`; `null` exactly when `closed`. */
667
+ volumeReason: "open" | "non-manifold" | null;
668
+ /** The boundary loops and open chains, as `analyze` reports them. */
669
+ boundaryLoops: number;
670
+ /** How many edges have three or more triangles. */
671
+ nonManifoldEdges: number;
672
+ /** Interior edges used in the same direction by both their triangles. */
673
+ orientationConflicts: number;
674
+ }
675
+ /**
676
+ * Options of {@link Scene.analyze}. Distances are in mesh units; with a
677
+ * rigid placement local and world distances agree, with a scaled one local
678
+ * distances are in unscaled units.
529
679
  */
530
680
  interface AnalyzeOptions {
531
681
  /**
@@ -600,12 +750,72 @@ type RepairOp = {
600
750
  targetLength?: number;
601
751
  /** Maximum split/collapse/flip rounds; unset means the default (10). */
602
752
  maxRounds?: number;
753
+ /** Split long edges only (no collapses, no flips); unset means a full pass. */
754
+ splitOnly?: boolean;
603
755
  } | {
604
756
  op: "bridgeLoops";
605
757
  /** The two loops to connect, from `analyze(mesh).loops`. Order is insignificant. */
606
758
  loops: readonly [LoopId, LoopId];
607
759
  /** Maximum vertices per loop; unset means the default (128). */
608
760
  maxEdges?: number;
761
+ } | {
762
+ op: "grab";
763
+ /** Brush center in local mesh coordinates, as in `views(mesh).positions()`. */
764
+ center: Readonly<Vec3>;
765
+ radius: number;
766
+ falloff: "linear" | "smooth";
767
+ /** Displacement scale; the per-vertex offset is `strength * falloff * direction`. */
768
+ strength: number;
769
+ /** The drag vector in local coordinates; zero moves nothing. */
770
+ direction: Readonly<Vec3>;
771
+ } | {
772
+ op: "relax";
773
+ /** Brush center in local mesh coordinates, as in `views(mesh).positions()`. */
774
+ center: Readonly<Vec3>;
775
+ radius: number;
776
+ falloff: "linear" | "smooth";
777
+ /** Displacement scale; the per-vertex weight is `strength * falloff`. */
778
+ strength: number;
779
+ /** How many plain Laplacian passes to run; 0 moves nothing. */
780
+ cycles: number;
781
+ } | {
782
+ op: "offset";
783
+ /**
784
+ * How far to move the surface along its smooth normals, in mesh units
785
+ * (equal to world units). Positive follows the normals (outward on an
786
+ * outward-wound closed mesh); negative sinks inward. Must be finite;
787
+ * 0 moves nothing.
788
+ */
789
+ distance: number;
790
+ } | {
791
+ op: "shell";
792
+ /**
793
+ * Wall thickness in mesh units (equal to world units): the input
794
+ * surface stays and gains a reversed copy one thickness against its
795
+ * smooth normals, with every boundary rim stitched shut. Must be
796
+ * positive and finite.
797
+ */
798
+ thickness: number;
799
+ } | {
800
+ op: "simplify";
801
+ /**
802
+ * Stop once this many triangles are alive; must be at least 1. A target
803
+ * at or above the live count leaves the mesh alone.
804
+ */
805
+ targetTriangles: number;
806
+ /** Keep boundary vertices in place; defaults to `true`. */
807
+ preserveBoundary?: boolean;
808
+ } | {
809
+ op: "subdivide";
810
+ /**
811
+ * Subdivision scheme; only `"loop"` exists. Defaults to `"loop"`.
812
+ */
813
+ method?: "loop";
814
+ /**
815
+ * How many times to split every triangle; must be an integer of at
816
+ * least 1. Each level quadruples the triangle count. Defaults to `1`.
817
+ */
818
+ levels?: number;
609
819
  };
610
820
  /** What `weld` did. */
611
821
  interface WeldReport {
@@ -650,7 +860,7 @@ interface FillReport {
650
860
  /** Loops left out: beyond a bound, or unclean (or open). */
651
861
  skipped: {
652
862
  id: LoopId;
653
- reason: "bounds" | "unclean";
863
+ reason: "bounds" | "unclean" | "uvSeam";
654
864
  }[];
655
865
  /** Selected loops that could not be filled; they stay open. */
656
866
  failed: {
@@ -679,6 +889,54 @@ interface RemeshReport {
679
889
  interface BridgeReport {
680
890
  trianglesAdded: number;
681
891
  }
892
+ /** What `grab` did. */
893
+ interface GrabReport {
894
+ moved: number;
895
+ maxDisplacement: number;
896
+ }
897
+ /** What `relax` did. */
898
+ interface RelaxReport {
899
+ moved: number;
900
+ maxDisplacement: number;
901
+ }
902
+ /** What `offset` did. */
903
+ interface OffsetReport {
904
+ moved: number;
905
+ maxDisplacement: number;
906
+ /** Degenerate triangles the cleanup pass removed. */
907
+ degenerateRemoved: number;
908
+ /** Vertices the cleanup pass removed. */
909
+ verticesRemoved: number;
910
+ }
911
+ /** What `shell` did. */
912
+ interface ShellReport {
913
+ /** Copy vertices added. */
914
+ verticesAdded: number;
915
+ /** Copy and wall triangles added. */
916
+ trianglesAdded: number;
917
+ /** Boundary rims stitched to their copy. A closed mesh has none. */
918
+ loopsClosed: number;
919
+ /** Degenerate triangles the cleanup pass removed. */
920
+ degenerateRemoved: number;
921
+ /** Vertices the cleanup pass removed. */
922
+ verticesRemoved: number;
923
+ }
924
+ /** What `simplify` did. */
925
+ interface SimplifyReport {
926
+ /** Edge collapses performed. */
927
+ collapsed: number;
928
+ /** Triangles removed (one per boundary collapse, two per interior one). */
929
+ trianglesRemoved: number;
930
+ /** Vertices removed (one per collapse). */
931
+ verticesRemoved: number;
932
+ }
933
+ /** What `subdivide` did. */
934
+ interface SubdivideReport {
935
+ /** Vertices added, one per subdivided edge per level. */
936
+ verticesAdded: number;
937
+ /** Triangles added: three per subdivided triangle per level. */
938
+ trianglesAdded: number;
939
+ }
682
940
  /** Options of {@link Scene.join}. */
683
941
  interface JoinOptions {
684
942
  /** The loop on the target, from `analyze(target).loops`. */
@@ -697,8 +955,141 @@ interface JoinReport {
697
955
  /** Bridge triangles between the two loops. */
698
956
  bridgeTrianglesAdded: number;
699
957
  }
958
+ /** Options of {@link Scene.register}. */
959
+ interface RegisterOptions {
960
+ /** The most solver steps. 0 only measures the current placement. Default 50. */
961
+ maxIterations?: number;
962
+ /**
963
+ * Stops when one step moves every point by at most this fraction of the
964
+ * moving mesh's extent (the largest distance of its points from their
965
+ * centroid). Default `1e-6`.
966
+ */
967
+ tolerance?: number;
968
+ /**
969
+ * The fraction of the moving mesh expected to lie over the fixed one, in
970
+ * `(0, 1]`: each iteration uses that many of its points, closest first, so
971
+ * the rest (the part beyond the overlap, and outliers) do not pull the
972
+ * result. Set it a little below the true overlap for partial scans.
973
+ * Default 1: every point counts, and nothing is rejected.
974
+ */
975
+ overlap?: number;
976
+ /** Points farther than this from the fixed mesh (world units) are not used. Default: no limit. */
977
+ maxDistance?: number;
978
+ /**
979
+ * The most points of the moving mesh to use, evenly spaced over its
980
+ * triangles' centroids and its vertices. `rmse` is measured on these.
981
+ * Default 100,000.
982
+ */
983
+ maxSamples?: number;
984
+ /**
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`.
988
+ */
989
+ apply?: boolean;
990
+ }
991
+ /**
992
+ * 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.
999
+ * - `"tooFewCorrespondences"`: fewer than six points have a usable closest
1000
+ * point.
1001
+ * - `"diverged"`: a step took points out of the range the query can represent.
1002
+ */
1003
+ type RegisterStatus = "converged" | "maxIterations" | "underconstrained" | "tooFewCorrespondences" | "diverged";
1004
+ /** What {@link Scene.register} found. */
1005
+ interface RegisterResult {
1006
+ /**
1007
+ * The moving mesh's aligned placement, with its scale unchanged: the
1008
+ * converged result, or the best estimate when it did not converge.
1009
+ */
1010
+ placement: Placement;
1011
+ /**
1012
+ * The root mean square distance (world units) from the used points to the
1013
+ * fixed mesh at `placement`; `Infinity` when no point has a closest point.
1014
+ */
1015
+ rmse: number;
1016
+ /** Solver steps taken. */
1017
+ iterations: number;
1018
+ /**
1019
+ * `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`.
1022
+ */
1023
+ converged: boolean;
1024
+ /** Why iteration stopped. */
1025
+ status: RegisterStatus;
1026
+ /** Whether `placement` was set on the moving mesh. */
1027
+ applied: boolean;
1028
+ /** Points of the moving mesh sampled. */
1029
+ samples: number;
1030
+ /** Sampled points used at `placement`: the rest were trimmed or out of range. */
1031
+ inliers: number;
1032
+ /**
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.
1038
+ */
1039
+ conditioning: number;
1040
+ }
1041
+ /** Options of {@link Scene.cutByPlane}. */
1042
+ interface CutOptions {
1043
+ /**
1044
+ * Close both openings with flat, unfaired patches. Defaults to `true`;
1045
+ * without it both parts keep the open rim the cut leaves.
1046
+ */
1047
+ cap?: boolean;
1048
+ }
1049
+ /** What {@link Scene.cutByPlane} did. */
1050
+ interface CutReport {
1051
+ /** The original handle, now holding the `+` side. */
1052
+ kept: MeshHandle;
1053
+ /** The new handle holding the `-` side. */
1054
+ removed: MeshHandle;
1055
+ /** Alive triangles of {@link CutReport.kept}, cap included. */
1056
+ keptTriangles: number;
1057
+ /** Alive triangles of {@link CutReport.removed}, cap included. */
1058
+ removedTriangles: number;
1059
+ /** Cap triangles added on both sides together. */
1060
+ capTriangles: number;
1061
+ }
1062
+ /** Which boolean for {@link Scene.boolean} to compute. */
1063
+ type BooleanOp = "union" | "subtract" | "intersect";
1064
+ /**
1065
+ * The standard cleanup pipeline for {@link Scene.repair}: weld, remove
1066
+ * degenerate, orient, remove small components, fill holes, as one transaction.
1067
+ * The library owns the order; an option left out takes the library's default.
1068
+ */
1069
+ interface AutoRepairRequest {
1070
+ kind: "auto";
1071
+ /** Vertices at most this far apart are welded, in mesh units. Default `1e-5`. */
1072
+ weldTolerance?: number;
1073
+ /** Components with fewer triangles are removed; the largest always stays. Default `500`. */
1074
+ minTriangles?: number;
1075
+ /** Fill only holes with at most this many edges; `Infinity` fills any size. Default `64`. */
1076
+ maxEdges?: number;
1077
+ /** Refine and fair each fill so it follows the surrounding curvature. Default `true`. */
1078
+ fair?: boolean;
1079
+ }
1080
+ /**
1081
+ * What an {@link AutoRepairRequest} did, one report per stage, keyed by the
1082
+ * stage's {@link RepairOp} name. The keys iterate in the order the stages ran.
1083
+ */
1084
+ interface AutoRepairReport {
1085
+ weld: WeldReport;
1086
+ removeDegenerate: DegenerateReport;
1087
+ orient: OrientReport;
1088
+ removeSmallComponents: RemoveReport;
1089
+ fillHoles: FillReport;
1090
+ }
700
1091
  /** The report of a {@link RepairOp}. */
701
- type RepairReport = WeldReport | DegenerateReport | RemoveReport | OrientReport | FillReport | InflateReport | SmoothReport | RemeshReport | BridgeReport;
1092
+ type RepairReport = WeldReport | DegenerateReport | RemoveReport | OrientReport | FillReport | InflateReport | SmoothReport | RemeshReport | BridgeReport | GrabReport | RelaxReport | OffsetReport | ShellReport | SimplifyReport | SubdivideReport;
702
1093
  /** The report type of a repair op. */
703
1094
  type RepairReportOf<O extends RepairOp> = O extends {
704
1095
  op: "weld";
@@ -718,7 +1109,19 @@ type RepairReportOf<O extends RepairOp> = O extends {
718
1109
  op: "remesh";
719
1110
  } ? RemeshReport : O extends {
720
1111
  op: "bridgeLoops";
721
- } ? BridgeReport : RepairReport;
1112
+ } ? BridgeReport : O extends {
1113
+ op: "grab";
1114
+ } ? GrabReport : O extends {
1115
+ op: "relax";
1116
+ } ? RelaxReport : O extends {
1117
+ op: "offset";
1118
+ } ? OffsetReport : O extends {
1119
+ op: "shell";
1120
+ } ? ShellReport : O extends {
1121
+ op: "simplify";
1122
+ } ? SimplifyReport : O extends {
1123
+ op: "subdivide";
1124
+ } ? SubdivideReport : RepairReport;
722
1125
  /**
723
1126
  * A scene of editable meshes. Create it after `await init()`; release it with
724
1127
  * {@link Scene.free} or a `using` declaration (otherwise it is freed when
@@ -742,7 +1145,8 @@ declare class Scene implements SceneLike {
742
1145
  * identity, so {@link Scene.matrix4} maps the local coordinates back to
743
1146
  * where they were given.
744
1147
  *
745
- * @throws `INVALID_ARGUMENT` for bad lengths or options, `INVALID_INDEX` for an index out of range.
1148
+ * @throws `INVALID_ARGUMENT` for bad lengths or options (`uvs` not 2 finite
1149
+ * values per vertex included), `INVALID_INDEX` for an index out of range.
746
1150
  */
747
1151
  addMesh(positions: Positions64, indices: Indices, options?: AddMeshOptions): MeshHandle;
748
1152
  /**
@@ -764,11 +1168,67 @@ declare class Scene implements SceneLike {
764
1168
  */
765
1169
  join(target: MeshHandle, source: MeshHandle, options: JoinOptions): JoinReport;
766
1170
  /**
767
- * Sets a mesh's placement: world = rotation · local + translation, where
768
- * local is relative to the mesh origin. A quaternion is normalised and
769
- * converted in double precision.
1171
+ * Cuts `mesh` with a world `plane`: the `+` side
1172
+ * (`signedDistance >= 0`) stays on the mesh and the `-` side is added as
1173
+ * a new mesh with the same placement, so the world shape is kept.
1174
+ * Cutting a closed mesh with `cap` (the default) yields two closed
1175
+ * meshes, capped with flat, unfaired patches.
1176
+ *
1177
+ * The cut undoes in one step; the added mesh stays, like the removed
1178
+ * source of {@link Scene.join}.
1179
+ *
1180
+ * @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.
1183
+ */
1184
+ cutByPlane(mesh: MeshHandle, plane: SectionPlane, options?: CutOptions): CutReport;
1185
+ /**
1186
+ * Combines `source` into `target` in the world: the union, subtraction
1187
+ * (`target` minus `source`) or intersection. Returns `target`, now
1188
+ * holding the result with its placement; `source` is unchanged.
1189
+ *
1190
+ * Both meshes must be closed and manifold. The boolean undoes in one
1191
+ * step. Combining a mesh with itself is a no-op for `"union"` and
1192
+ * `"intersect"`, and clears it for `"subtract"`.
1193
+ *
1194
+ * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` for an
1195
+ * input that is not closed, manifold and consistently wound. A failed
1196
+ * boolean changes nothing.
1197
+ */
1198
+ boolean(target: MeshHandle, source: MeshHandle, op: BooleanOp): MeshHandle;
1199
+ /**
1200
+ * Rigidly aligns the mesh `moving` to the mesh `fixed` by point-to-plane ICP,
1201
+ * with the closest points found through `fixed`'s BVH and trimmed by
1202
+ * `options.overlap`. A drag of either mesh ends first, recording its moves
1203
+ * as one step.
1204
+ *
1205
+ * **The initial guess is the current placements.** ICP finds the nearest
1206
+ * fit, so put the meshes roughly in place first with `setPlacement`.
1207
+ *
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.
1213
+ *
1214
+ * **Scales.** Only rotation and translation are solved. `moving`'s scale is
1215
+ * applied to its points and kept. `fixed`'s scale, uniform or not, is
1216
+ * followed exactly on a copy baked through it, so each such call costs a BVH
1217
+ * build. All distances are in world units.
1218
+ *
1219
+ * @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` for one
1220
+ * mesh twice, a mesh without triangles or an invalid option; `STALE_BVH` for
1221
+ * a stale Manual `fixed`. Nothing changes on a throw.
1222
+ */
1223
+ register(moving: MeshHandle, fixed: MeshHandle, options?: RegisterOptions): RegisterResult;
1224
+ /**
1225
+ * Sets a mesh's placement: world = rotation · (scale · local) + translation,
1226
+ * where local is relative to the mesh origin. A quaternion is normalised
1227
+ * and converted in double precision. The scale defaults to `[1, 1, 1]`
1228
+ * (rigid) and must be 3 finite positive numbers.
770
1229
  *
771
- * @throws `INVALID_ARGUMENT` when the rotation is not a proper rotation or a quaternion is zero.
1230
+ * @throws `INVALID_ARGUMENT` when the rotation is not a proper rotation, the
1231
+ * scale is not 3 finite positive numbers, or a quaternion is zero.
772
1232
  */
773
1233
  setPlacement(mesh: MeshHandle, placement: PlacementInput): void;
774
1234
  /** A mesh's placement, with the rotation as a row-major matrix. */
@@ -776,7 +1236,8 @@ declare class Scene implements SceneLike {
776
1236
  /**
777
1237
  * The column-major world matrix of the local render coordinates,
778
1238
  * `placement · translate(origin)`, ready for renderers (convert to `f32`
779
- * yourself).
1239
+ * yourself). The rotation columns carry the scale; normals need the
1240
+ * inverse-transpose (three.js' normal matrix does this from the matrix).
780
1241
  */
781
1242
  matrix4(mesh: MeshHandle): Float64Array;
782
1243
  /** Sets when the mesh's derived data follows its edits; see {@link UpdateMode}. */
@@ -807,7 +1268,7 @@ declare class Scene implements SceneLike {
807
1268
  * view; re-acquire views after every scene call that may allocate, since a
808
1269
  * kept one may read other data or be empty (see {@link MeshViews}).
809
1270
  */
810
- views(mesh: MeshHandle): MeshViews;
1271
+ views(mesh: MeshHandle): SceneMeshViews;
811
1272
  /**
812
1273
  * Everything that changed since the previous call, one record per mesh.
813
1274
  * There is a single consumer: apps that use {@link Scene.onChanges} call
@@ -888,13 +1349,24 @@ declare class Scene implements SceneLike {
888
1349
  * @throws `INVALID_ARGUMENT` for a negative or non-finite `weldTolerance`; `STALE_BVH`, see {@link AnalyzeOptions.selfIntersection}.
889
1350
  */
890
1351
  analyze(mesh: MeshHandle, options?: AnalyzeOptions): Analysis;
1352
+ /**
1353
+ * Scalar measurements of a mesh in world coordinates: its surface area
1354
+ * (always) and, when watertight, its enclosed volume. An open or
1355
+ * non-manifold mesh still gets its area; only `volume` is `null`, with
1356
+ * `volumeReason` saying why. A read-only call: it leaves every view
1357
+ * valid.
1358
+ */
1359
+ measure(mesh: MeshHandle): MeasureResult;
891
1360
  /**
892
1361
  * Runs one repair operation and returns its report, or a list of them in
893
1362
  * order and returns their reports. A list is one transaction: one undo step,
894
1363
  * and when any operation fails nothing changes and nothing is recorded.
1364
+ * `{ kind: "auto" }` runs the standard cleanup pipeline the same way and
1365
+ * returns a report per stage; see {@link AutoRepairRequest}.
895
1366
  *
896
1367
  * @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.
897
1368
  */
1369
+ repair(mesh: MeshHandle, request: AutoRepairRequest): AutoRepairReport;
898
1370
  repair<const O extends RepairOp>(mesh: MeshHandle, op: O): RepairReportOf<O>;
899
1371
  repair<const O extends readonly RepairOp[]>(mesh: MeshHandle, ops: O): { -readonly [K in keyof O]: RepairReportOf<O[K]>; };
900
1372
  /**
@@ -922,6 +1394,61 @@ declare class Scene implements SceneLike {
922
1394
  intersects(a: MeshHandle, b: MeshHandle): boolean;
923
1395
  /** Every mesh pair (or every pair of `pairs`) within `margin`, sorted by mesh id. */
924
1396
  findContacts(options?: FindContactsOptions): Contact[];
1397
+ /**
1398
+ * Selects vertices of a mesh: a sphere brush, a lasso polygon, or the
1399
+ * connected component holding a seed vertex. The result is a snapshot
1400
+ * (ascending ids plus the mesh's content stamp); any edit, repair, compact,
1401
+ * undo or redo of the mesh invalidates it, and the selection methods then
1402
+ * throw `STALE_SELECTION` instead of silently remapping ids. Placement
1403
+ * changes keep selections valid. Only vertices a live triangle uses can
1404
+ * be selected (dead or never-used slots never are).
1405
+ *
1406
+ * @throws `UNKNOWN_MESH` for a removed mesh; `INVALID_ARGUMENT` for a bad
1407
+ * spec; `INVALID_INDEX` for an out-of-range component seed.
1408
+ */
1409
+ select(mesh: MeshHandle, spec: SelectSpec): VertexSelection;
1410
+ /**
1411
+ * Whether `sel` is still usable: its mesh is alive and no topology edit
1412
+ * landed since it was taken. Never throws.
1413
+ */
1414
+ selectionAlive(sel: VertexSelection): boolean;
1415
+ /**
1416
+ * Grows a selection by `steps` rings of edge neighbours (staying on live
1417
+ * vertices). The result carries the current stamp, so a fresh selection
1418
+ * can be grown right after an edit. `steps` 0 returns an equal copy.
1419
+ *
1420
+ * @throws `STALE_SELECTION` when the mesh changed since the selection;
1421
+ * `UNKNOWN_MESH` for a removed mesh.
1422
+ */
1423
+ selectGrow(sel: VertexSelection, steps?: number): VertexSelection;
1424
+ /**
1425
+ * Shrinks a selection by `steps` rings, dropping the members with a live
1426
+ * neighbour outside the set. Interior selections (no boundary) survive
1427
+ * unchanged; shrinking past the core gives an empty (still valid)
1428
+ * selection.
1429
+ *
1430
+ * @throws `STALE_SELECTION` when the mesh changed since the selection;
1431
+ * `UNKNOWN_MESH` for a removed mesh.
1432
+ */
1433
+ selectShrink(sel: VertexSelection, steps?: number): VertexSelection;
1434
+ /**
1435
+ * Inverts a selection: every live vertex outside it. The result carries
1436
+ * the current stamp.
1437
+ *
1438
+ * @throws `STALE_SELECTION` when the mesh changed since the selection;
1439
+ * `UNKNOWN_MESH` for a removed mesh.
1440
+ */
1441
+ selectInvert(sel: VertexSelection): VertexSelection;
1442
+ /**
1443
+ * Isolates a selection: removes the triangles fully outside it (no
1444
+ * selected vertex), one undo step. Boundary triangles with at least one
1445
+ * selected vertex stay. An empty selection selects nothing to keep and
1446
+ * throws `INVALID_ARGUMENT` rather than clearing the mesh.
1447
+ *
1448
+ * @throws `STALE_SELECTION` when the mesh changed since the selection;
1449
+ * `UNKNOWN_MESH` for a removed mesh.
1450
+ */
1451
+ isolate(mesh: MeshHandle, sel: VertexSelection): IsolateReport;
925
1452
  /**
926
1453
  * Adds a signed distance field: one value per vertex slot of `on`, the
927
1454
  * distance to `to` as placed (negative inside), `Infinity` beyond
@@ -933,6 +1460,25 @@ declare class Scene implements SceneLike {
933
1460
  * @throws `INVALID_ARGUMENT` when `to` is empty, holds `on` or a mesh twice, `maxDistance` is negative or NaN, or the name is taken.
934
1461
  */
935
1462
  addDistanceField(desc: DistanceFieldDesc): FieldHandle;
1463
+ /**
1464
+ * Adds a per-vertex wall-thickness field: one value per vertex slot of
1465
+ * `on`, the distance to the opposite surface along the vertex's smooth
1466
+ * normal, in world units. Open sheets and rims read NaN, hits beyond
1467
+ * `maxDistance` read `Infinity`. It follows edits and placements by the
1468
+ * mesh modes, like normals, and colours like any field.
1469
+ *
1470
+ * @throws `INVALID_ARGUMENT` when `maxDistance` is negative or NaN, or the name is taken.
1471
+ */
1472
+ addThicknessField(desc: ThicknessFieldDesc): FieldHandle;
1473
+ /**
1474
+ * Adds a per-vertex curvature field: one value per vertex slot of `on`,
1475
+ * the signed mean curvature there, in 1/world-units (positive on domes,
1476
+ * negative in bowls, zero on flats). It follows edits and placements by
1477
+ * the mesh modes, like normals, and colours like any field.
1478
+ *
1479
+ * @throws `INVALID_ARGUMENT` when the name is taken.
1480
+ */
1481
+ addCurvatureField(desc: CurvatureFieldDesc): FieldHandle;
936
1482
  /** Removes a field, and a colouring by it. Its handle then gives `UNKNOWN_FIELD`. */
937
1483
  removeField(field: FieldHandle): void;
938
1484
  /**
@@ -1015,8 +1561,6 @@ declare class Scene implements SceneLike {
1015
1561
  */
1016
1562
  sectionGap(section: SectionHandle, a: MeshHandle, b: MeshHandle): SectionGap | null;
1017
1563
  }
1018
- //#endregion
1019
- //#region src/scene-like.d.ts
1020
1564
  /**
1021
1565
  * What the adapters need from a scene: render buffers, placements, section
1022
1566
  * results, change notification and drags. All methods are synchronous.
@@ -1025,8 +1569,8 @@ interface SceneLike {
1025
1569
  /**
1026
1570
  * Views of the mesh's render buffers. Slot counts follow from them, so
1027
1571
  * `positions()` must be exactly 3 × vertex slots long and `indices()`
1028
- * exactly 3 × triangle slots long (normals 3 and colours 4 per vertex slot,
1029
- * when present): `positions().length / 3` vertex slots and
1572
+ * exactly 3 × triangle slots long (normals 3, colours 4 and UVs 2 per vertex
1573
+ * slot, when present): `positions().length / 3` vertex slots and
1030
1574
  * `indices().length / 3` triangle slots.
1031
1575
  */
1032
1576
  views(mesh: MeshHandle): MeshViews;
@@ -1054,5 +1598,4 @@ interface SceneLike {
1054
1598
  */
1055
1599
  bounds?(mesh: MeshHandle): Bounds | null;
1056
1600
  }
1057
- //#endregion
1058
- export { Range as $, OrientReport as A, Scene as B, InflateReport as C, MeshChange as D, LoopId as E, RemoveReport as F, SectionPlane as G, SectionContour as H, RepairOp as I, SmoothReport as J, SectionResult as K, RepairReport as L, RayHit as M, RaycastOptions as N, MeshComponent as O, RemeshReport as P, SectionHandle as Q, RepairReportOf as R, FindContactsOptions as S, JoinReport as T, SectionDesc as U, SceneOptions as V, SectionGap as W, FieldHandle as X, WeldReport as Y, MeshHandle as Z, EditRef as _, BoundaryLoop as a, Placement as at, FillReport as b, ClosestPointOptions as c, Positions64 as ct, Contact as d, Vec3 as dt, MeshViews as et, DegenerateReport as f, computeBounds as ft, EditOp as g, DragSession as h, AnalyzeOptions as i, Mat3 as it, OutOfRange as j, MeshDistance as k, ColorRule as l, Quat as lt, DragOptions as m, AddMeshOptions as n, Indices as nt, BridgeReport as o, PlacementInput as ot, DistanceFieldDesc as p, computeVertexNormals as pt, SignMode as q, Analysis as r, InitInput as rt, ClosestHit as s, Positions as st, SceneLike as t, Bounds as tt, Colormap as u, UpdateMode as ut, EditResult as v, JoinOptions as w, FilledLoop as x, FieldStatus as y, Rgba as z };
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 };