fast-mesh-wasm 0.2.0 → 0.3.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 (50) hide show
  1. package/README.md +488 -1
  2. package/dist/{api-D0o2HjaU.js → api-BUy7FRx7.js} +11 -11
  3. package/dist/client-Bp9FRd70.js +2278 -0
  4. package/dist/client-m2zSdFlu.d.ts +305 -0
  5. package/dist/colormap-D_xH5hI5.js +303 -0
  6. package/dist/core-Cke_kZ2e.js +113 -0
  7. package/dist/core-D2X9GPfK.d.ts +15 -0
  8. package/dist/engine-B-ZEzR1c.js +1818 -0
  9. package/dist/mesh-B16gV3oX.d.ts +130 -0
  10. package/dist/mesh-B8pae8WA.js +428 -0
  11. package/dist/node.d.ts +3 -2
  12. package/dist/node.js +5 -4
  13. package/dist/protocol-CAUYm1gd.js +68 -0
  14. package/dist/protocol-W9R-iGl5.d.ts +293 -0
  15. package/dist/r3f.d.ts +59 -0
  16. package/dist/r3f.js +165 -0
  17. package/dist/react-CTADh3NN.js +124 -0
  18. package/dist/react.d.ts +65 -0
  19. package/dist/react.js +1 -0
  20. package/dist/scene-BG3EEyfw.js +1243 -0
  21. package/dist/scene-like-B_3qm0u6.d.ts +925 -0
  22. package/dist/snapshot-Cf6NgDl7.js +104 -0
  23. package/dist/store-D3ErV6o-.js +1379 -0
  24. package/dist/store-DNnHN33A.d.ts +285 -0
  25. package/dist/store.d.ts +61 -0
  26. package/dist/store.js +105 -0
  27. package/dist/three.d.ts +118 -0
  28. package/dist/three.js +390 -0
  29. package/dist/views-BaZqBxlX.js +189 -0
  30. package/dist/wasm/fast_mesh_wasm.d.ts +458 -0
  31. package/dist/wasm/fast_mesh_wasm.js +1150 -0
  32. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  33. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +74 -0
  34. package/dist/wasm-threads/fast_mesh_wasm.d.ts +540 -0
  35. package/dist/wasm-threads/fast_mesh_wasm.js +1513 -0
  36. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
  37. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +93 -0
  38. package/dist/wasm-threads/package.json +7 -0
  39. package/dist/wasm-threads/snippets/fast-mesh-wasm-ae14781a92c2789e/inline0.js +16 -0
  40. package/dist/wasm-threads/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.js +107 -0
  41. package/dist/web.d.ts +3 -2
  42. package/dist/web.js +4 -2
  43. package/dist/worker-engine.d.ts +248 -0
  44. package/dist/worker-engine.js +1 -0
  45. package/dist/worker-entry.d.ts +1 -0
  46. package/dist/worker-entry.js +11 -0
  47. package/dist/worker.d.ts +2 -0
  48. package/dist/worker.js +1 -0
  49. package/package.json +53 -4
  50. package/dist/api-HcskOwd7.d.ts +0 -43
@@ -0,0 +1,285 @@
1
+ import { $ as PlacementInput, A as RepairOp, E as OutOfRange, G as SectionHandle, L as SectionDesc, N as Rgba, P as Scene, S as MeshChange, V as SignMode, W as MeshHandle, Y as Indices, g as EditResult, j as RepairReport, l as Colormap, m as EditOp, n as AddMeshOptions, p as DragSession, t as SceneLike, tt as Positions64, z as SectionPlane } from "./scene-like-B_3qm0u6.js";
2
+ import { t as FastMeshError } from "./core-D2X9GPfK.js";
3
+ import { r as WorkerScene } from "./client-m2zSdFlu.js";
4
+ //#region src/store/host.d.ts
5
+ /** Options of `SceneStore.addMesh`: those both scenes take (a store mesh is always eager). */
6
+ type StoreAddMeshOptions = Pick<AddMeshOptions, "origin" | "normals">;
7
+ //#endregion
8
+ //#region src/store/snapshot.d.ts
9
+ /**
10
+ * The state of a mesh's or section's work: `"computing"` while it, or a
11
+ * result it depends on, is pending; `"ready"` once applied; `"error"` when
12
+ * the latest request failed; `"idle"` for nothing requested (or removed).
13
+ */
14
+ type Status = "idle" | "computing" | "ready" | "error";
15
+ /**
16
+ * Declarative distance colouring of a mesh: its vertices coloured by their
17
+ * signed distance to `distanceTo`. The store owns the distance field behind
18
+ * it. The colour fields are those of the scene's `ColorRule`.
19
+ */
20
+ interface DistanceColoring {
21
+ /**
22
+ * The mesh the distances are measured to, or several: each vertex then
23
+ * shows the smallest signed distance over them (the nearest surface, or
24
+ * the deepest penetration). A set: the order does not matter.
25
+ */
26
+ distanceTo: MeshHandle | readonly MeshHandle[];
27
+ /** Largest distance computed (inclusive); may be `Infinity`. */
28
+ maxDistance: number;
29
+ /** Defaults to `"auto"`. */
30
+ sign?: SignMode;
31
+ map: Colormap;
32
+ /** `[lo, hi]` mapped onto the colormap; finite, `lo < hi`. */
33
+ range: readonly [lo: number, hi: number];
34
+ below?: OutOfRange;
35
+ above?: OutOfRange;
36
+ center?: number;
37
+ base?: Rgba;
38
+ nan?: Rgba;
39
+ }
40
+ /**
41
+ * A contact group for `SceneStore.setContactGroup`: meshes coloured by their
42
+ * distance to their partners, each with one colour scale whichever partner
43
+ * it touches.
44
+ */
45
+ interface ContactGroup {
46
+ /** The members, all in the store, each once. */
47
+ meshes: readonly MeshHandle[];
48
+ /**
49
+ * Which members are measured to each other, either way round: listed
50
+ * pairs of members, or `"all"` (the default) for every pair.
51
+ */
52
+ pairs?: readonly (readonly [MeshHandle, MeshHandle])[] | "all";
53
+ /** The colouring of every member, its `distanceTo` being the member's partners. */
54
+ coloring: Omit<DistanceColoring, "distanceTo">;
55
+ }
56
+ /** How a mesh is shown. `opacity` and `visible` live only in the store. */
57
+ interface DisplayState {
58
+ /** Distance colouring, or `null` for none. */
59
+ coloring: DistanceColoring | null;
60
+ /** In [0, 1]; defaults to 1. */
61
+ opacity: number;
62
+ /** Defaults to `true`. */
63
+ visible: boolean;
64
+ }
65
+ /** A mesh in a {@link SceneSnapshot}. Frozen. */
66
+ interface MeshState {
67
+ /** What is applied (shown). */
68
+ display: DisplayState;
69
+ /** What was last requested; equals `display` once applied. */
70
+ desired: DisplayState;
71
+ status: Status;
72
+ /** The snapshot revision at which this state last changed. */
73
+ revision: number;
74
+ error?: FastMeshError;
75
+ }
76
+ /** The declarative parts of a section. */
77
+ interface SectionParts {
78
+ plane: SectionPlane;
79
+ meshes: readonly MeshHandle[];
80
+ fill: boolean;
81
+ }
82
+ /** A section in a {@link SceneSnapshot}. Frozen. */
83
+ interface SectionState extends SectionParts {
84
+ /** What was last requested; the top-level fields are what is applied. */
85
+ desired: SectionParts;
86
+ status: Status;
87
+ /** The snapshot revision at which this state last changed. */
88
+ revision: number;
89
+ error?: FastMeshError;
90
+ }
91
+ /** An immutable view of a store's scene; replaced (never mutated) on change. */
92
+ interface SceneSnapshot {
93
+ /** Increases with every new snapshot. */
94
+ revision: number;
95
+ meshes: ReadonlyMap<MeshHandle, MeshState>;
96
+ history: {
97
+ canUndo: boolean;
98
+ canRedo: boolean;
99
+ };
100
+ sections: ReadonlyMap<SectionHandle, SectionState>;
101
+ selection: MeshHandle | null;
102
+ /** `"error"` when any mesh, section or the history has an error, else `"computing"` while any is pending. */
103
+ status: "idle" | "computing" | "error";
104
+ /** The first error, when `status` is `"error"`. */
105
+ error?: FastMeshError;
106
+ }
107
+ /** The state of a mesh not in a snapshot (removed, or never added): `"idle"`, default display. */
108
+ declare const REMOVED_MESH_STATE: MeshState;
109
+ /** The snapshot of an empty scene; what the server renders (SSR). */
110
+ declare const EMPTY_SNAPSHOT: SceneSnapshot;
111
+ /** A mesh's state in `snap`, or {@link REMOVED_MESH_STATE} when it is not there. */
112
+ declare function meshState(snap: SceneSnapshot, mesh: MeshHandle): MeshState;
113
+ /**
114
+ * The state of a section not in a snapshot (removed, never added, or on the
115
+ * server): `"idle"`, no meshes, no fill, a placeholder plane through the
116
+ * origin facing +z.
117
+ */
118
+ declare const REMOVED_SECTION_STATE: SectionState;
119
+ /** A section's state in `snap`, or {@link REMOVED_SECTION_STATE} when it is not there. */
120
+ declare function sectionState(snap: SceneSnapshot, section: SectionHandle): SectionState;
121
+ //#endregion
122
+ //#region src/store/store.d.ts
123
+ /** A change to a section's declarative parts. */
124
+ type SectionPatch = Partial<SectionParts>;
125
+ /**
126
+ * An observable store over a scene. Read with {@link getSnapshot} and
127
+ * {@link subscribe}; change through its actions. Call {@link commitFrame}
128
+ * once per animation frame instead of the scene's.
129
+ */
130
+ declare class SceneStore {
131
+ #private;
132
+ /** The scene, for the renderer adapters (`bindMesh`, ...). */
133
+ readonly scene: SceneLike;
134
+ /** `"local"` over a `Scene`, `"worker"` over a `WorkerScene`. */
135
+ readonly mode: "local" | "worker";
136
+ constructor(scene: Scene | WorkerScene);
137
+ /**
138
+ * The current snapshot: frozen, replaced (never mutated) on change. It is
139
+ * up to date with the scene's statuses when read: a status change not yet
140
+ * announced refreshes it here, and its listeners are called on a microtask.
141
+ */
142
+ getSnapshot: () => SceneSnapshot;
143
+ /**
144
+ * Registers a listener called after each new snapshot; returns the function
145
+ * that removes it. A listener that throws does not stop the others nor the
146
+ * action that changed the state (which has taken effect): its error is
147
+ * reported with `reportError` (an async rethrow where there is none), as
148
+ * the Worker scene does with its listeners.
149
+ */
150
+ subscribe: (listener: () => void) => (() => void);
151
+ /**
152
+ * Call once per animation frame (instead of the scene's `commitFrame()`):
153
+ * applies the frame's declarative changes, then commits the scene's frame
154
+ * and returns its change records. From the first call on, declarative
155
+ * changes wait for it instead of applying on a microtask.
156
+ */
157
+ commitFrame(): MeshChange[];
158
+ /** Adds a mesh (default display) and returns its handle at once. */
159
+ addMesh(positions: Positions64, indices: Indices, options?: StoreAddMeshOptions): MeshHandle;
160
+ /**
161
+ * Removes a mesh; it leaves the snapshot (and the selection) at once. The
162
+ * scene drops the fields measured to it alone, and the colourings by them:
163
+ * a mesh coloured by distance to it alone shows no colouring, keeps its
164
+ * rule in `desired`, and is in `"error"` (`UNKNOWN_MESH`) from the next
165
+ * flush until its colouring changes. A colouring measured to it and other
166
+ * meshes keeps the others (its `distanceTo` loses the mesh). It leaves its
167
+ * contact groups, whose members' partners follow. Sections stop cutting it.
168
+ */
169
+ removeMesh(mesh: MeshHandle): void;
170
+ /** Sets a mesh's placement (one undo step). */
171
+ setPlacement(mesh: MeshHandle, placement: PlacementInput): void;
172
+ /** Starts a drag of a mesh; see the scene's `drag()`. Ending or cancelling it updates the snapshot. */
173
+ drag(mesh: MeshHandle): DragSession;
174
+ /** Edits a mesh's triangles (one undo step). */
175
+ edit(mesh: MeshHandle, ops: readonly EditOp[]): Promise<EditResult>;
176
+ /** Repairs a mesh (one undo step). */
177
+ repair(mesh: MeshHandle, op: RepairOp | readonly RepairOp[]): Promise<RepairReport | RepairReport[]>;
178
+ /** Undoes the latest step. */
179
+ undo(): void;
180
+ /** Redoes the latest undone step. */
181
+ redo(): void;
182
+ /**
183
+ * Changes how a mesh is shown. `desired` changes at once; `display` follows
184
+ * at the next `commitFrame()` (or a microtask without a frame loop). A
185
+ * patch equal to the current request changes nothing.
186
+ *
187
+ * A `coloring` colours the mesh by distance to `distanceTo` (one mesh or
188
+ * several) through a field the store owns (one per mesh, named
189
+ * `fast-mesh-store:<n>`, kept while colouring is off and replaced only
190
+ * when the set of meshes in `distanceTo`, `maxDistance` or `sign`
191
+ * changes). `display.coloring` is the colouring
192
+ * last applied: on a Worker scene, once its `display:` request is ready.
193
+ *
194
+ * @throws `UNKNOWN_MESH` for a mesh not in the store, `INVALID_ARGUMENT` for a bad value.
195
+ */
196
+ setDisplay(mesh: MeshHandle, patch: Partial<DisplayState>): void;
197
+ /**
198
+ * Sets contact group `id`, or removes it with `null`. Every member is
199
+ * coloured by `group.coloring` with its partners (the members it is paired
200
+ * with) as `distanceTo`, through one field per member measured to all of
201
+ * its partners: each vertex shows the smallest signed distance over them
202
+ * (the nearest surface, or the deepest penetration). Moving a member then
203
+ * recomputes only its own field and those of its partners. A member
204
+ * without partners shows no colouring.
205
+ *
206
+ * Members are coloured through {@link setDisplay}, so `desired` and
207
+ * `display` show the colourings (groups themselves are not in the
208
+ * snapshot). Setting the group colours every member, overriding a
209
+ * colouring the app gave it. A member's later `setDisplay` colouring
210
+ * overrides the group's: the group then leaves that member alone when it
211
+ * shrinks, is removed, or loses a mesh, until it is set again. Members
212
+ * dropped from the group, or all of them when it is removed, stop being
213
+ * coloured, and their store-owned fields are removed (not kept for later,
214
+ * as `setDisplay` keeps them). A removed mesh leaves its groups (and their
215
+ * pairs); a member left without partners stops being coloured.
216
+ *
217
+ * @throws `UNKNOWN_MESH` for a mesh not in the store; `INVALID_ARGUMENT`
218
+ * for a mesh listed twice, a mesh already in another group, a pair that
219
+ * is not two different members, or a bad colouring (`maxDistance`,
220
+ * `range`, `map` or `sign`; checked here rather than at the flush).
221
+ */
222
+ setContactGroup(id: string, group: ContactGroup | null): void;
223
+ /**
224
+ * The targets of the store-owned field behind the mesh's colouring (the
225
+ * one last sent to the scene), in the field's order: the order its
226
+ * nearest-target indices (`Scene.fieldNearest`,
227
+ * `WorkerScene.fetchFieldNearest`) refer to. That is ascending scene id,
228
+ * not the order of `distanceTo` or of a contact group's members. A target
229
+ * removed since leaves the list, as it leaves the field. Frozen; `null`
230
+ * when the mesh has no colouring.
231
+ *
232
+ * @throws `UNKNOWN_MESH` for a mesh not in the store; `INVALID_ARGUMENT`
233
+ * once the store is disposed.
234
+ */
235
+ coloringTargets(mesh: MeshHandle): readonly MeshHandle[] | null;
236
+ /**
237
+ * The values of the store-owned field behind the mesh's colouring (the one
238
+ * last sent to the scene), one per vertex slot, as of the field's last
239
+ * update: a copy the caller owns. `null` when the mesh has no colouring.
240
+ * On a Worker scene the request is ordered after the calls made before
241
+ * it, so it reads the colouring last flushed. Never a history step.
242
+ *
243
+ * Rejects with `UNKNOWN_MESH` for a mesh not in the store, and
244
+ * `INVALID_ARGUMENT` once the store is disposed.
245
+ */
246
+ fetchColoringValues(mesh: MeshHandle): Promise<Float32Array | null>;
247
+ /** Adds a plane section and returns its handle at once. */
248
+ addSection(desc: SectionDesc): SectionHandle;
249
+ /**
250
+ * Changes a section's plane, meshes or fill. `desired` changes at once;
251
+ * the section follows at the next `commitFrame()` (or a microtask without
252
+ * a frame loop), each aspect set only when it changed, the last value
253
+ * per frame winning.
254
+ *
255
+ * @throws `UNKNOWN_SECTION` for a section not in the store.
256
+ */
257
+ setSection(section: SectionHandle, patch: SectionPatch): void;
258
+ /** Removes a section; it leaves the snapshot at once. */
259
+ removeSection(section: SectionHandle): void;
260
+ /**
261
+ * Selects a mesh, or nothing with `null`. UI state only: the scene never sees it.
262
+ *
263
+ * @throws `UNKNOWN_MESH` for a mesh not in the store.
264
+ */
265
+ select(mesh: MeshHandle | null): void;
266
+ /**
267
+ * Restarts the Worker scene (see `WorkerScene.restart()`). Rejects with
268
+ * `INVALID_ARGUMENT` on a local (synchronous) scene.
269
+ */
270
+ restart(): Promise<void>;
271
+ /**
272
+ * Removes the distance fields the store owns (`fast-mesh-store:<n>`, and
273
+ * so the colourings by them) and stops listening to the scene. The rest of
274
+ * the scene is left as it is (it is the app's). On a Worker scene the
275
+ * removals are queued like any call, and sent with the scene's next
276
+ * `commitFrame()`; errors from a scene that can no longer take them (a
277
+ * poisoned Worker scene, for one) are ignored. Later actions throw
278
+ * `INVALID_ARGUMENT`; the last snapshot stays readable.
279
+ */
280
+ dispose(): void;
281
+ }
282
+ /** A store over `scene` (a `Scene` or a `WorkerScene`). */
283
+ declare function createSceneStore(scene: Scene | WorkerScene): SceneStore;
284
+ //#endregion
285
+ export { StoreAddMeshOptions as _, DisplayState as a, MeshState as c, SceneSnapshot as d, SectionParts as f, sectionState as g, meshState as h, ContactGroup as i, REMOVED_MESH_STATE as l, Status as m, SectionPatch as n, DistanceColoring as o, SectionState as p, createSceneStore as r, EMPTY_SNAPSHOT as s, SceneStore as t, REMOVED_SECTION_STATE as u };
@@ -0,0 +1,61 @@
1
+ import { N as Rgba, V as SignMode } from "./scene-like-B_3qm0u6.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-DNnHN33A.js";
3
+ //#region src/store/heatmap.d.ts
4
+ /** Options of {@link contactHeatmap}. Distances are in the meshes' units. */
5
+ interface ContactHeatmapOptions {
6
+ /** The penetration depth shown darkest (`deep`); deeper clamps to it. `> 0`. */
7
+ depth: number;
8
+ /**
9
+ * The gap shown `far`; farther shows the base colour. `>= 0`: at 0 only
10
+ * penetration (and the contact band) is coloured.
11
+ */
12
+ gap: number;
13
+ /**
14
+ * Distances in `[-tolerance, +tolerance]` are contact (`contact`). In
15
+ * `[0, min(depth, gap))`, or `[0, depth)` when `gap` is 0; defaults to 0.
16
+ */
17
+ tolerance?: number;
18
+ /**
19
+ * `true` computes every vertex's distance (`maxDistance: Infinity`), so any
20
+ * penetration deeper than `depth` shows `deep`; every update recomputes the
21
+ * whole field. `false` (the default) bounds the field at
22
+ * `2 · max(depth, gap)`, the fast contact path:
23
+ * vertices beyond it are far and show the base colour, deep penetration
24
+ * included. The bound sits past the range ends, so the values just beyond
25
+ * the coloured area are still known and its outer edge is a value
26
+ * boundary (which `bindMesh`'s fragment shading softens with
27
+ * `edgeSoftness`); only an edge from a coloured vertex to one beyond the
28
+ * bound (a deep interior, or a triangle longer than the margin) switches
29
+ * hard, half way along.
30
+ */
31
+ exactDepth?: boolean;
32
+ /** Defaults to `"auto"`. */
33
+ sign?: SignMode;
34
+ /** Overrides of the default colours. */
35
+ colors?: {
36
+ deep?: Rgba;
37
+ shallow?: Rgba;
38
+ contact?: Rgba;
39
+ near?: Rgba;
40
+ far?: Rgba;
41
+ };
42
+ }
43
+ /**
44
+ * A contact heatmap: spread it into a colouring with its target,
45
+ * `store.setDisplay(a, { coloring: { distanceTo: b, ...contactHeatmap({ depth, gap }) } })`.
46
+ *
47
+ * The range is `[-depth, gap]` (below clamps to `deep`, above shows the base
48
+ * colour). From `-depth` the colour runs from `deep` to `shallow` just below
49
+ * the contact band, is `contact` across `[-tolerance, +tolerance]` (a single
50
+ * stop at 0 when the tolerance is 0), then runs from `near` just above the
51
+ * band to `far` at `gap`. With `gap` 0 there is no gap ramp: the range is
52
+ * `[-depth, tolerance]` and anything beyond the band shows the base colour.
53
+ * A change of `tolerance` or `colors` alone keeps `maxDistance` and `sign`,
54
+ * so the store reuses its field and only recolours.
55
+ *
56
+ * @throws `INVALID_ARGUMENT` unless `depth > 0`, `gap >= 0` (both finite) and
57
+ * `0 ≤ tolerance < min(depth, gap)` (`< depth` when `gap` is 0).
58
+ */
59
+ export declare function contactHeatmap(options: ContactHeatmapOptions): Omit<DistanceColoring, "distanceTo">;
60
+ //#endregion
61
+ export { type ContactGroup, type ContactHeatmapOptions, type DisplayState, type DistanceColoring, EMPTY_SNAPSHOT, type MeshState, REMOVED_MESH_STATE, REMOVED_SECTION_STATE, type SceneSnapshot, SceneStore, type SectionParts, type SectionPatch, type SectionState, type Status, type StoreAddMeshOptions, createSceneStore, meshState, sectionState };
package/dist/store.js ADDED
@@ -0,0 +1,105 @@
1
+ import { t as FastMeshError } from "./core-Cke_kZ2e.js";
2
+ import { i as REMOVED_SECTION_STATE, l as sectionState, n as EMPTY_SNAPSHOT, r as REMOVED_MESH_STATE, s as meshState } from "./snapshot-Cf6NgDl7.js";
3
+ import { n as createSceneStore, t as SceneStore } from "./store-D3ErV6o-.js";
4
+ //#region src/store/heatmap.ts
5
+ /** The default colours: `#7f0000`, `#ff6b6b`, `#ffffff`, `#4caf50`, `#1e3a8a`. */
6
+ const DEFAULT_COLORS = {
7
+ deep: [
8
+ 127,
9
+ 0,
10
+ 0,
11
+ 255
12
+ ],
13
+ shallow: [
14
+ 255,
15
+ 107,
16
+ 107,
17
+ 255
18
+ ],
19
+ contact: [
20
+ 255,
21
+ 255,
22
+ 255,
23
+ 255
24
+ ],
25
+ near: [
26
+ 76,
27
+ 175,
28
+ 80,
29
+ 255
30
+ ],
31
+ far: [
32
+ 30,
33
+ 58,
34
+ 138,
35
+ 255
36
+ ]
37
+ };
38
+ /** How far (in t) the `shallow` and `near` stops sit from the contact band's edges. */
39
+ const EDGE = 1e-4;
40
+ function invalid(message) {
41
+ return new FastMeshError("INVALID_ARGUMENT", message);
42
+ }
43
+ /**
44
+ * A contact heatmap: spread it into a colouring with its target,
45
+ * `store.setDisplay(a, { coloring: { distanceTo: b, ...contactHeatmap({ depth, gap }) } })`.
46
+ *
47
+ * The range is `[-depth, gap]` (below clamps to `deep`, above shows the base
48
+ * colour). From `-depth` the colour runs from `deep` to `shallow` just below
49
+ * the contact band, is `contact` across `[-tolerance, +tolerance]` (a single
50
+ * stop at 0 when the tolerance is 0), then runs from `near` just above the
51
+ * band to `far` at `gap`. With `gap` 0 there is no gap ramp: the range is
52
+ * `[-depth, tolerance]` and anything beyond the band shows the base colour.
53
+ * A change of `tolerance` or `colors` alone keeps `maxDistance` and `sign`,
54
+ * so the store reuses its field and only recolours.
55
+ *
56
+ * @throws `INVALID_ARGUMENT` unless `depth > 0`, `gap >= 0` (both finite) and
57
+ * `0 ≤ tolerance < min(depth, gap)` (`< depth` when `gap` is 0).
58
+ */
59
+ function contactHeatmap(options) {
60
+ const { depth, gap, tolerance = 0, exactDepth = false, sign = "auto" } = options;
61
+ if (typeof depth !== "number" || !Number.isFinite(depth) || !(depth > 0)) throw invalid("depth must be a finite number > 0");
62
+ if (typeof gap !== "number" || !Number.isFinite(gap) || !(gap >= 0)) throw invalid("gap must be a finite number >= 0");
63
+ const ramp = gap > 0;
64
+ if (typeof tolerance !== "number" || !(tolerance >= 0 && tolerance < (ramp ? Math.min(depth, gap) : depth))) throw invalid("tolerance must be a number in [0, min(depth, gap)), or [0, depth) when gap is 0");
65
+ const o = options.colors;
66
+ const c = {
67
+ deep: o?.deep ?? DEFAULT_COLORS.deep,
68
+ shallow: o?.shallow ?? DEFAULT_COLORS.shallow,
69
+ contact: o?.contact ?? DEFAULT_COLORS.contact,
70
+ near: o?.near ?? DEFAULT_COLORS.near,
71
+ far: o?.far ?? DEFAULT_COLORS.far
72
+ };
73
+ const top = ramp ? gap : tolerance;
74
+ const t = (v) => (v + depth) / (depth + top);
75
+ const lo = t(-tolerance);
76
+ const hi = ramp ? t(tolerance) : 1;
77
+ const below = Math.min(EDGE, lo / 2);
78
+ const above = Math.min(EDGE, (1 - hi) / 2);
79
+ const band = tolerance === 0 ? [[lo, c.contact]] : [[lo, c.contact], [hi, c.contact]];
80
+ const wanted = [
81
+ [0, c.deep],
82
+ [lo - below, c.shallow],
83
+ ...band,
84
+ ...ramp ? [[hi + above, c.near], [1, c.far]] : []
85
+ ];
86
+ const stops = [];
87
+ for (const [pos, color] of wanted) {
88
+ const prev = stops[stops.length - 1];
89
+ if (prev !== void 0 && !(Math.fround(pos) > Math.fround(prev[0]))) {
90
+ if (pos !== 1) continue;
91
+ stops.pop();
92
+ }
93
+ stops.push(Object.freeze([pos, color]));
94
+ }
95
+ return {
96
+ maxDistance: exactDepth ? Infinity : 2 * Math.max(depth, gap),
97
+ sign,
98
+ map: { stops: Object.freeze(stops) },
99
+ range: Object.freeze([-depth, top]),
100
+ below: "clamp",
101
+ above: "base"
102
+ };
103
+ }
104
+ //#endregion
105
+ export { EMPTY_SNAPSHOT, REMOVED_MESH_STATE, REMOVED_SECTION_STATE, SceneStore, contactHeatmap, createSceneStore, meshState, sectionState };
@@ -0,0 +1,118 @@
1
+ import { G as SectionHandle, t as SceneLike } from "./scene-like-B_3qm0u6.js";
2
+ import { i as bindMesh, n as BoundMesh, r as MeshBinding, t as BindMeshOptions } from "./mesh-B16gV3oX.js";
3
+ import * as THREE from "three";
4
+ //#region src/three/controls.d.ts
5
+ /**
6
+ * What {@link attachTransformControls} needs of a TransformControls: its
7
+ * `dragging-changed` (`{ value: boolean }`) and `objectChange` events, the
8
+ * object it is attached to and whether it is dragging. Three's
9
+ * `TransformControls` (`three/addons/controls/TransformControls.js`) fits.
10
+ */
11
+ interface TransformControlsLike extends THREE.EventDispatcher<any> {
12
+ object?: THREE.Object3D;
13
+ dragging: boolean;
14
+ }
15
+ /** Options of {@link attachTransformControls}. */
16
+ interface AttachTransformControlsOptions {
17
+ /**
18
+ * Schedules a callback for the next animation frame. Defaults to
19
+ * `requestAnimationFrame` (or a 16 ms timeout where there is none). Tests
20
+ * can collect the callbacks and run them by hand.
21
+ *
22
+ * With the default, the move may run after the app's `commitFrame()` in the
23
+ * same frame, so the scene (fields, sections) shows it a frame late. To
24
+ * avoid that lag, pass a scheduler that queues the callback and drain the
25
+ * queue right before calling `commitFrame()`.
26
+ */
27
+ schedule?: (callback: () => void) => void;
28
+ }
29
+ /**
30
+ * Lets a TransformControls move a bound mesh: while the gizmo drags
31
+ * `bound.object`, its pose is sent to `scene.drag(bound.mesh)`, and the drag
32
+ * is ended (one undo step) when the gizmo lets go. Returns a function that
33
+ * detaches it (ending a drag in progress first).
34
+ *
35
+ * Pose and placement: `bound.object.matrix` is the scene mesh's
36
+ * `matrix4 = placement · translate(origin)`, so with placement `(R, t)` the
37
+ * object's quaternion is `R` and its position is `R · origin + t`. A pose is
38
+ * therefore sent as `{ rotation: quaternion, translation: position − R · origin }`,
39
+ * all in f64. The origin (fixed for the mesh) comes from the placement and
40
+ * matrix at the start of each drag: `origin = Rᵀ (m − t)`, with `m` the
41
+ * matrix's translation column.
42
+ *
43
+ * Placements are rigid: TransformControls' scale mode has no effect (the
44
+ * object's scale is kept at 1). The object must be a direct child of an
45
+ * untransformed parent (its matrix is a world matrix), as for `bindMesh`.
46
+ *
47
+ * The object's `position`, `quaternion` and `scale` are kept in step with its
48
+ * matrix (TransformControls reads them when a drag starts), so call this
49
+ * after `bindMesh` and before the gizmo grabs the object. While the gizmo
50
+ * drags, the object's matrix follows the gizmo, not the change stream (the
51
+ * scene lags by up to a frame); once the drag ends, the final placement is
52
+ * applied. When the drag is ended by the scene instead (`undo()` while
53
+ * dragging, for example), the object follows the scene again and the rest
54
+ * of the gesture is ignored. When the mesh is removed, the drag ends
55
+ * (no step is left open) and the attachment goes idle. A gesture that
56
+ * cannot start a drag (another drag is active) is ignored with a warning.
57
+ */
58
+ export declare function attachTransformControls(controls: TransformControlsLike, scene: SceneLike, bound: MeshBinding, options?: AttachTransformControlsOptions): () => void;
59
+ //#endregion
60
+ //#region src/three/section.d.ts
61
+ /** Options of {@link bindSection}. */
62
+ interface BindSectionOptions {
63
+ /** The contour line colour. Defaults to black. */
64
+ lineColor?: THREE.ColorRepresentation;
65
+ /** The fill colour. Defaults to a mid grey. */
66
+ fillColor?: THREE.ColorRepresentation;
67
+ /**
68
+ * Whether to add {@link BoundSection.plane} to the bound meshes' materials'
69
+ * `clippingPlanes`. Defaults to `true`.
70
+ */
71
+ clip?: boolean;
72
+ }
73
+ /** A section drawn by {@link bindSection}. */
74
+ interface BoundSection {
75
+ /**
76
+ * Add it to the THREE.Scene, untransformed (results are in world
77
+ * coordinates). Per bound mesh the section cuts, it holds a `LineSegments`
78
+ * of the contours and a `Mesh` of the fill (empty while the section has no
79
+ * fill).
80
+ */
81
+ readonly group: THREE.Group;
82
+ /**
83
+ * The section plane, kept equal to the scene's. Three clips away what lies
84
+ * on the plane's negative side, so the part on the side the section normal
85
+ * points to stays visible.
86
+ */
87
+ readonly plane: THREE.Plane;
88
+ /**
89
+ * Stops following the scene, removes the plane from the materials (if the
90
+ * section's removal has not already) and
91
+ * disposes the geometries and the line and fill materials. Safe to call
92
+ * more than once. The group stays wherever it was added.
93
+ */
94
+ dispose(): void;
95
+ }
96
+ /**
97
+ * Draws a section of the scene and clips the bound meshes at its plane.
98
+ *
99
+ * The plane is added to each bound mesh's `material.clippingPlanes` (unless
100
+ * `clip` is `false`), which three applies only when the renderer has
101
+ * `renderer.localClippingEnabled = true`. A mesh with an array of materials
102
+ * has the plane added to each; a material shared by several bound meshes
103
+ * gets it once.
104
+ *
105
+ * The lines and fill of a bound mesh are rebuilt when a frame's
106
+ * `sectionsChanged` lists the section for it; a mesh the section does not
107
+ * cut (or that is removed) draws nothing. Results are shown as last
108
+ * computed: a `"lazy"` or `"manual"` mesh's lag until the scene computes
109
+ * them. The plane follows `Scene.setSectionPlane` on the next frame.
110
+ * When the section is removed, the drawing is emptied and stops following
111
+ * the scene, and the plane is taken off the materials.
112
+ *
113
+ * Like `bindMesh`, it only listens through {@link SceneLike.onChanges}: call
114
+ * `scene.commitFrame()` once per animation frame.
115
+ */
116
+ export declare function bindSection(scene: SceneLike, section: SectionHandle, bound: readonly MeshBinding[], options?: BindSectionOptions): BoundSection;
117
+ //#endregion
118
+ export { type AttachTransformControlsOptions, type BindMeshOptions, type BindSectionOptions, type BoundMesh, type BoundSection, type MeshBinding, type SceneLike, type TransformControlsLike, bindMesh };