fast-mesh-wasm 0.7.0 → 0.8.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.
- package/README.md +43 -3
- package/dist/client-CJWOKQMM.d.ts +664 -0
- package/dist/{client-DFgvktkT.js → client-DQADH6KL.js} +1753 -123
- package/dist/{engine-BL5_sWAf.js → engine-D2124Vml.js} +983 -51
- package/dist/io.d.ts +7 -2
- package/dist/io.js +6 -6
- package/dist/{mesh-DIWD2F5-.js → mesh-BtWBMRMO.js} +2 -1
- package/dist/{mesh-BHTFxsXc.d.ts → mesh-DTm2Fnqa.d.ts} +3 -2
- package/dist/node.d.ts +4 -2
- package/dist/node.js +4 -4
- package/dist/primitives-6T0eQiSm.d.ts +157 -0
- package/dist/{scene-DUsj6uJD.js → primitives-wasm-C30Bk4ut.js} +1359 -64
- package/dist/primitives-wasm-d9m2vikb.d.ts +43 -0
- package/dist/{protocol-Ci9LLiwO.js → protocol-Bvjmvlb3.js} +38 -3
- package/dist/{protocol-DFR0JDAS.d.ts → protocol-Da0kmXuF.d.ts} +417 -3
- package/dist/r3f.d.ts +3 -3
- package/dist/r3f.js +3 -3
- package/dist/{react-DzrtrzZy.js → react-DIuy5dyR.js} +12 -3
- package/dist/react.d.ts +6 -3
- package/dist/react.js +1 -1
- package/dist/scene-like-Bx7lZKif.d.ts +4808 -0
- package/dist/{store-BAzHRRkt.js → store-BxzcXy9y.js} +415 -65
- package/dist/{store-8HWG90Jg.d.ts → store-LM3iU8E4.d.ts} +98 -10
- package/dist/store.d.ts +3 -3
- package/dist/store.js +1 -1
- package/dist/three.d.ts +13 -11
- package/dist/three.js +63 -18
- package/dist/views-DPMbo0Sl.js +3147 -0
- package/dist/wasm/fast_mesh_wasm.d.ts +541 -8
- package/dist/wasm/fast_mesh_wasm.js +2083 -93
- package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +94 -0
- package/dist/wasm-threads/fast_mesh_wasm.d.ts +541 -8
- package/dist/wasm-threads/fast_mesh_wasm.js +2084 -94
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +94 -0
- package/dist/wave6-wasm-Bt4vTlKz.js +146 -0
- package/dist/web.d.ts +4 -2
- package/dist/web.js +4 -4
- package/dist/worker-engine.d.ts +20 -2
- package/dist/worker-engine.js +1 -1
- package/dist/worker-entry.js +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/api-4kz45-Mq.js +0 -63
- package/dist/client-nvmbhtn-.d.ts +0 -398
- package/dist/scene-like-CR_Dpohm.d.ts +0 -2511
- package/dist/views-BSy-Qeg8.js +0 -584
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { o as reportListenerError, t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
2
|
-
import {
|
|
3
|
-
import { i as sectionAspects } from "./protocol-
|
|
4
|
-
import { a as watchStatusKeys, r as addFieldKeyed } from "./client-
|
|
2
|
+
import { In as targetsOf, u as checkHistoryEntry } from "./views-DPMbo0Sl.js";
|
|
3
|
+
import { i as sectionAspects } from "./protocol-Bvjmvlb3.js";
|
|
4
|
+
import { a as fieldTargets, c as watchStatusKeys, o as presenceVersion, r as addFieldKeyed, s as sectionMeshes } from "./client-DQADH6KL.js";
|
|
5
5
|
import { a as combine, c as sameData, n as EMPTY_SNAPSHOT, o as frozenCopy, t as DEFAULT_DISPLAY } from "./snapshot-BkbGPspK.js";
|
|
6
6
|
// src/store/host.ts
|
|
7
7
|
/** Whether `scene` is a Worker scene (structurally: it reports key statuses). */
|
|
@@ -42,6 +42,14 @@ function tracker(changed) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
+
* {@link Host.presence} from either scene. A stand-in scene without `has`
|
|
46
|
+
* (tests make them) has every mesh it was given.
|
|
47
|
+
*/
|
|
48
|
+
function presenceIn(scene, mesh) {
|
|
49
|
+
if (typeof scene.has !== "function") return "live";
|
|
50
|
+
return scene.has(mesh) ? "live" : scene.isRestorable(mesh) ? "restorable" : "gone";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
45
53
|
* The synchronous scene. Calls apply at once, so every key is `"ready"`,
|
|
46
54
|
* except one whose latest call made through `track` threw: that key is
|
|
47
55
|
* `"error"` until a call under it succeeds. Nothing is ever pending, so
|
|
@@ -58,7 +66,9 @@ function localHost(scene) {
|
|
|
58
66
|
mode: "local",
|
|
59
67
|
scene,
|
|
60
68
|
addMesh: (positions, indices, options) => scene.addMesh(positions, indices, options),
|
|
61
|
-
removeMesh: (mesh) => scene.removeMesh(mesh),
|
|
69
|
+
removeMesh: (mesh, options) => scene.removeMesh(mesh, options),
|
|
70
|
+
presence: (mesh) => presenceIn(scene, mesh),
|
|
71
|
+
presenceVersion: () => 0,
|
|
62
72
|
setPlacement: (mesh, placement) => scene.setPlacement(mesh, placement),
|
|
63
73
|
edit: (mesh, ops) => promised(() => scene.edit(mesh, ops)),
|
|
64
74
|
repair: ((mesh, op) => promised(() => scene.repair(mesh, op))),
|
|
@@ -70,8 +80,15 @@ function localHost(scene) {
|
|
|
70
80
|
redo: () => {
|
|
71
81
|
scene.redo();
|
|
72
82
|
},
|
|
83
|
+
beginStep: () => scene.beginStep(),
|
|
84
|
+
endStep: () => scene.endStep(),
|
|
85
|
+
cancelStep: () => scene.cancelStep(),
|
|
73
86
|
canUndo: () => scene.canUndo(),
|
|
74
87
|
canRedo: () => scene.canRedo(),
|
|
88
|
+
recordEntry: (entry) => scene.recordEntry(entry),
|
|
89
|
+
historyBudget: () => scene.historyBudget(),
|
|
90
|
+
setHistoryBudget: (bytes) => scene.setHistoryBudget(bytes),
|
|
91
|
+
onPermanent: (listener) => scene.onPermanent(listener),
|
|
75
92
|
status: (key) => {
|
|
76
93
|
const error = errors.get(key);
|
|
77
94
|
return error === void 0 ? {
|
|
@@ -101,12 +118,21 @@ function localHost(scene) {
|
|
|
101
118
|
forgetErrors,
|
|
102
119
|
addField: (desc) => scene.addDistanceField(desc),
|
|
103
120
|
removeField: (field) => scene.removeField(field),
|
|
121
|
+
fieldTargets: (field) => {
|
|
122
|
+
try {
|
|
123
|
+
scene.fieldStatus(field);
|
|
124
|
+
return;
|
|
125
|
+
} catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
104
129
|
fieldValues: (field) => promised(() => scene.fieldValues(field).slice()),
|
|
105
130
|
setColoring: (mesh, rule) => scene.setColoring(mesh, rule),
|
|
106
131
|
addSection: (desc) => scene.addSection(desc),
|
|
107
132
|
setSectionPlane: (section, plane) => scene.setSectionPlane(section, plane),
|
|
108
133
|
setSectionMeshes: (section, meshes) => scene.setSectionMeshes(section, meshes),
|
|
109
134
|
setSectionFill: (section, fill) => scene.setSectionFill(section, fill),
|
|
135
|
+
sectionMeshes: () => void 0,
|
|
110
136
|
removeSection: (section) => scene.removeSection(section),
|
|
111
137
|
restart: () => Promise.reject(new FastMeshError("INVALID_ARGUMENT", "restart needs a Worker scene"))
|
|
112
138
|
};
|
|
@@ -123,7 +149,9 @@ function workerHost(scene) {
|
|
|
123
149
|
mode: "worker",
|
|
124
150
|
scene,
|
|
125
151
|
addMesh: (positions, indices, options) => scene.addMesh(positions, indices, options),
|
|
126
|
-
removeMesh: (mesh) => scene.removeMesh(mesh),
|
|
152
|
+
removeMesh: (mesh, options) => scene.removeMesh(mesh, options),
|
|
153
|
+
presence: (mesh) => presenceIn(scene, mesh),
|
|
154
|
+
presenceVersion: () => presenceVersion(scene),
|
|
127
155
|
setPlacement: (mesh, placement) => scene.setPlacement(mesh, placement),
|
|
128
156
|
edit: (mesh, ops) => scene.edit(mesh, ops),
|
|
129
157
|
repair: ((mesh, op) => scene.repair(mesh, op)),
|
|
@@ -131,8 +159,15 @@ function workerHost(scene) {
|
|
|
131
159
|
verticesInSphere: (mesh, center, radius) => scene.verticesInSphere(mesh, center, radius),
|
|
132
160
|
undo: () => scene.undo(),
|
|
133
161
|
redo: () => scene.redo(),
|
|
162
|
+
beginStep: () => scene.beginStep(),
|
|
163
|
+
endStep: () => scene.endStep(),
|
|
164
|
+
cancelStep: () => scene.cancelStep(),
|
|
134
165
|
canUndo: () => scene.canUndo,
|
|
135
166
|
canRedo: () => scene.canRedo,
|
|
167
|
+
recordEntry: (entry) => scene.recordEntry(entry),
|
|
168
|
+
historyBudget: () => scene.historyBudget,
|
|
169
|
+
setHistoryBudget: (bytes) => scene.setHistoryBudget(bytes),
|
|
170
|
+
onPermanent: (listener) => scene.onPermanent(listener),
|
|
136
171
|
status: (key) => {
|
|
137
172
|
const error = errors.get(key);
|
|
138
173
|
const s = scene.status(key);
|
|
@@ -148,12 +183,14 @@ function workerHost(scene) {
|
|
|
148
183
|
idOf: (handle) => scene.idOf(handle),
|
|
149
184
|
addField: (desc, key) => key === void 0 ? scene.addDistanceField(desc) : addFieldKeyed(scene, desc, key),
|
|
150
185
|
removeField: (field) => scene.removeField(field),
|
|
186
|
+
fieldTargets: (field) => fieldTargets(scene, field),
|
|
151
187
|
fieldValues: (field) => scene.fetchFieldValues(field),
|
|
152
188
|
setColoring: (mesh, rule) => scene.setColoring(mesh, rule),
|
|
153
189
|
addSection: (desc) => scene.addSection(desc),
|
|
154
190
|
setSectionPlane: (section, plane) => scene.setSectionPlane(section, plane),
|
|
155
191
|
setSectionMeshes: (section, meshes) => scene.setSectionMeshes(section, meshes),
|
|
156
192
|
setSectionFill: (section, fill) => scene.setSectionFill(section, fill),
|
|
193
|
+
sectionMeshes: (section) => sectionMeshes(scene, section),
|
|
157
194
|
removeSection: (section) => scene.removeSection(section),
|
|
158
195
|
restart: () => {
|
|
159
196
|
const before = new Map(errors);
|
|
@@ -303,6 +340,10 @@ var SceneStore = class {
|
|
|
303
340
|
#host;
|
|
304
341
|
#meshes = /* @__PURE__ */ new Map();
|
|
305
342
|
#sections = /* @__PURE__ */ new Map();
|
|
343
|
+
/** Meshes that left the scene and that undo or redo can bring back. */
|
|
344
|
+
#parked = /* @__PURE__ */ new Map();
|
|
345
|
+
/** The host's `presenceVersion` last followed. */
|
|
346
|
+
#presenceSeen = 0;
|
|
306
347
|
#listeners = /* @__PURE__ */ new Set();
|
|
307
348
|
#unsubscribe;
|
|
308
349
|
/** Meshes whose display changed since the last flush. */
|
|
@@ -352,18 +393,24 @@ var SceneStore = class {
|
|
|
352
393
|
#frameLoop = false;
|
|
353
394
|
#flushQueued = false;
|
|
354
395
|
#disposed = false;
|
|
355
|
-
constructor(scene) {
|
|
396
|
+
constructor(scene, options = {}) {
|
|
356
397
|
this.#host = hostOf(scene);
|
|
357
398
|
this.scene = this.#host.scene;
|
|
358
399
|
this.mode = this.#host.mode;
|
|
400
|
+
if (options.historyBudget !== void 0) this.#host.setHistoryBudget(options.historyBudget);
|
|
359
401
|
const event = () => {
|
|
360
402
|
if (!this.#disposed) {
|
|
403
|
+
if (this.#host.presenceVersion() !== this.#presenceSeen) this.#followPresence();
|
|
361
404
|
this.#stale = true;
|
|
362
405
|
this.#queueUpdate();
|
|
363
406
|
}
|
|
364
407
|
};
|
|
408
|
+
const changes = (records) => {
|
|
409
|
+
if (!this.#disposed) this.#followChanges(records);
|
|
410
|
+
event();
|
|
411
|
+
};
|
|
365
412
|
this.#unsubscribe = [
|
|
366
|
-
scene.onChanges(
|
|
413
|
+
scene.onChanges(changes),
|
|
367
414
|
this.#host.onStatus(event),
|
|
368
415
|
() => this.#host.stop()
|
|
369
416
|
];
|
|
@@ -408,7 +455,12 @@ var SceneStore = class {
|
|
|
408
455
|
this.#update();
|
|
409
456
|
return changes;
|
|
410
457
|
}
|
|
411
|
-
/**
|
|
458
|
+
/**
|
|
459
|
+
* Adds a mesh (default display) and returns its handle at once. With
|
|
460
|
+
* `undoable` the add is an undo step, or part of the open one: undo takes
|
|
461
|
+
* the mesh out of the snapshot, and redo brings it back with the same
|
|
462
|
+
* handle and display.
|
|
463
|
+
*/
|
|
412
464
|
addMesh(positions, indices, options) {
|
|
413
465
|
this.#alive();
|
|
414
466
|
const handle = this.#host.addMesh(positions, indices, options);
|
|
@@ -417,6 +469,26 @@ var SceneStore = class {
|
|
|
417
469
|
id: this.#host.idOf(handle),
|
|
418
470
|
display: DEFAULT_DISPLAY,
|
|
419
471
|
desired: DEFAULT_DISPLAY,
|
|
472
|
+
asked: null,
|
|
473
|
+
sent: null
|
|
474
|
+
});
|
|
475
|
+
this.#dirtyMeshes.add(handle);
|
|
476
|
+
this.#update();
|
|
477
|
+
return handle;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Registers an already-created scene `MeshHandle` in the store so snapshots,
|
|
481
|
+
* dirty-buffer tracking, and `meshState` work cleanly for it.
|
|
482
|
+
*/
|
|
483
|
+
adoptMesh(handle) {
|
|
484
|
+
this.#alive();
|
|
485
|
+
if (this.#meshes.has(handle)) return handle;
|
|
486
|
+
this.#meshes.set(handle, {
|
|
487
|
+
handle,
|
|
488
|
+
id: this.#host.idOf(handle),
|
|
489
|
+
display: DEFAULT_DISPLAY,
|
|
490
|
+
desired: DEFAULT_DISPLAY,
|
|
491
|
+
asked: null,
|
|
420
492
|
sent: null
|
|
421
493
|
});
|
|
422
494
|
this.#dirtyMeshes.add(handle);
|
|
@@ -431,12 +503,42 @@ var SceneStore = class {
|
|
|
431
503
|
* flush until its colouring changes. A colouring measured to it and other
|
|
432
504
|
* meshes keeps the others (its `distanceTo` loses the mesh). It leaves its
|
|
433
505
|
* contact groups, whose members' partners follow. Sections stop cutting it.
|
|
506
|
+
*
|
|
507
|
+
* With `undoable` the removal is an undo step, or part of the open one
|
|
508
|
+
* ({@link isRestorable} tells whether it can still be undone). The undo
|
|
509
|
+
* brings the mesh back into the snapshot with the same handle and display,
|
|
510
|
+
* puts it back into the sections that cut it, and colours again the meshes
|
|
511
|
+
* that were coloured by distance to it (unless their colouring was changed
|
|
512
|
+
* since). It does not rejoin its contact groups: set them again with
|
|
513
|
+
* {@link setContactGroup}. A removal larger than {@link historyBudget} is
|
|
514
|
+
* permanent: {@link onPermanent} tells.
|
|
434
515
|
*/
|
|
435
|
-
removeMesh(mesh) {
|
|
516
|
+
removeMesh(mesh, options) {
|
|
436
517
|
this.#alive();
|
|
437
|
-
this.#host.removeMesh(mesh);
|
|
438
|
-
|
|
439
|
-
|
|
518
|
+
this.#host.removeMesh(mesh, options);
|
|
519
|
+
this.#leave([mesh], false);
|
|
520
|
+
this.#update();
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Whether undo or redo can still bring back a mesh that left the store: it
|
|
524
|
+
* was removed with `undoable`, or its undoable add was undone, and the
|
|
525
|
+
* history has not dropped the step. `false` for a mesh in the store.
|
|
526
|
+
*/
|
|
527
|
+
isRestorable(mesh) {
|
|
528
|
+
this.#alive();
|
|
529
|
+
return this.#parked.has(mesh) && this.#host.presence(mesh) === "restorable";
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Meshes are out of the scene (removed here, or by an undo or a redo): they
|
|
533
|
+
* leave the snapshot and whatever names them. Those undo or redo can bring
|
|
534
|
+
* back are kept aside. Meshes that leave together keep their colourings by
|
|
535
|
+
* each other, as the scene keeps their fields. `followed`: the store learns
|
|
536
|
+
* it from the scene, after requests it has made meanwhile.
|
|
537
|
+
*/
|
|
538
|
+
#leave(meshes, followed) {
|
|
539
|
+
for (const mesh of meshes) {
|
|
540
|
+
const entry = this.#meshes.get(mesh);
|
|
541
|
+
if (entry === void 0) continue;
|
|
440
542
|
this.#meshes.delete(mesh);
|
|
441
543
|
this.#pendingDisplay.delete(entry);
|
|
442
544
|
this.#dropFields.delete(entry);
|
|
@@ -446,56 +548,24 @@ var SceneStore = class {
|
|
|
446
548
|
const display = `display:${entry.id}`;
|
|
447
549
|
const field = entry.field === void 0 ? void 0 : `field:${entry.field.id}`;
|
|
448
550
|
this.#host.forgetErrors((k) => k === display || k === field);
|
|
551
|
+
if (this.#host.presence(mesh) === "restorable") this.#parked.set(mesh, entry);
|
|
449
552
|
}
|
|
553
|
+
for (const mesh of meshes) this.#dropMesh(mesh, followed);
|
|
554
|
+
}
|
|
555
|
+
/** A mesh that left is no longer selected, measured to, cut or grouped. */
|
|
556
|
+
#dropMesh(mesh, followed) {
|
|
450
557
|
if (this.#selection === mesh) this.#selection = null;
|
|
451
|
-
for (const other of this.#meshes.values())
|
|
452
|
-
const prune = (d) => {
|
|
453
|
-
const c = withoutTarget(d.coloring, mesh);
|
|
454
|
-
return c === d.coloring ? d : Object.freeze({
|
|
455
|
-
...d,
|
|
456
|
-
coloring: c
|
|
457
|
-
});
|
|
458
|
-
};
|
|
459
|
-
const before = [
|
|
460
|
-
other.display,
|
|
461
|
-
other.desired,
|
|
462
|
-
other.sent
|
|
463
|
-
];
|
|
464
|
-
other.display = prune(other.display);
|
|
465
|
-
other.desired = prune(other.desired);
|
|
466
|
-
other.sent = withoutTarget(other.sent, mesh);
|
|
467
|
-
if (other.inflight !== void 0) other.inflight.value = withoutTarget(other.inflight.value, mesh);
|
|
468
|
-
if (other.display !== before[0] || other.desired !== before[1] || other.sent !== before[2]) this.#dirtyMeshes.add(other.handle);
|
|
469
|
-
const owned = other.field;
|
|
470
|
-
if (owned === void 0 || !owned.to.includes(mesh)) continue;
|
|
471
|
-
if (owned.to.length > 1) {
|
|
472
|
-
const at = owned.to.indexOf(mesh);
|
|
473
|
-
other.field = {
|
|
474
|
-
...owned,
|
|
475
|
-
to: owned.to.filter((_, k) => k !== at),
|
|
476
|
-
toIds: owned.toIds.filter((_, k) => k !== at)
|
|
477
|
-
};
|
|
478
|
-
this.#dirtyMeshes.add(other.handle);
|
|
479
|
-
continue;
|
|
480
|
-
}
|
|
481
|
-
const fieldKey = `field:${owned.id}`;
|
|
482
|
-
this.#host.forgetErrors((k) => k === fieldKey);
|
|
483
|
-
other.field = void 0;
|
|
484
|
-
other.sent = null;
|
|
485
|
-
other.inflight = void 0;
|
|
486
|
-
this.#dirtyMeshes.add(other.handle);
|
|
487
|
-
if (other.display.coloring !== null) other.display = Object.freeze({
|
|
488
|
-
...other.display,
|
|
489
|
-
coloring: null
|
|
490
|
-
});
|
|
491
|
-
if (other.desired.coloring !== null) {
|
|
492
|
-
this.#pendingDisplay.add(other);
|
|
493
|
-
this.#schedule();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
558
|
+
for (const other of this.#meshes.values()) this.#dropTarget(other, mesh, followed);
|
|
496
559
|
const without = (meshes) => meshes.includes(mesh) ? Object.freeze(meshes.filter((m) => m !== mesh)) : meshes;
|
|
497
560
|
for (const s of this.#sections.values()) {
|
|
498
561
|
const { applied, sent, desired } = s;
|
|
562
|
+
if (followed && sent.meshes.includes(mesh) && !sameData(sent.meshes, applied.meshes)) {
|
|
563
|
+
delete s.inflight.meshes;
|
|
564
|
+
s.sent = this.#withMeshes(s.sent, applied.meshes);
|
|
565
|
+
s.retry = true;
|
|
566
|
+
this.#pendingSections.add(s);
|
|
567
|
+
this.#schedule();
|
|
568
|
+
}
|
|
499
569
|
s.applied = this.#withMeshes(s.applied, without(s.applied.meshes));
|
|
500
570
|
s.sent = this.#withMeshes(s.sent, without(s.sent.meshes));
|
|
501
571
|
s.desired = this.#withMeshes(s.desired, without(s.desired.meshes));
|
|
@@ -522,7 +592,177 @@ var SceneStore = class {
|
|
|
522
592
|
}
|
|
523
593
|
}
|
|
524
594
|
}
|
|
525
|
-
|
|
595
|
+
}
|
|
596
|
+
/** `mesh` is no longer a target of `other`'s colouring and store-owned field. */
|
|
597
|
+
#dropTarget(other, mesh, followed) {
|
|
598
|
+
const unsure = followed && !sameData(other.sent, other.display.coloring);
|
|
599
|
+
const prune = (d) => {
|
|
600
|
+
const c = withoutTarget(d.coloring, mesh);
|
|
601
|
+
return c === d.coloring ? d : Object.freeze({
|
|
602
|
+
...d,
|
|
603
|
+
coloring: c
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
const before = [
|
|
607
|
+
other.display,
|
|
608
|
+
other.desired,
|
|
609
|
+
other.sent
|
|
610
|
+
];
|
|
611
|
+
other.display = prune(other.display);
|
|
612
|
+
other.desired = prune(other.desired);
|
|
613
|
+
other.sent = withoutTarget(other.sent, mesh);
|
|
614
|
+
if (other.inflight !== void 0) other.inflight.value = withoutTarget(other.inflight.value, mesh);
|
|
615
|
+
if (other.display !== before[0] || other.desired !== before[1] || other.sent !== before[2]) this.#dirtyMeshes.add(other.handle);
|
|
616
|
+
const owned = other.field;
|
|
617
|
+
if (owned === void 0 || !owned.to.includes(mesh)) return;
|
|
618
|
+
if (owned.to.length > 1 && unsure) {
|
|
619
|
+
this.#startOver(other);
|
|
620
|
+
this.#pendingDisplay.add(other);
|
|
621
|
+
this.#dirtyMeshes.add(other.handle);
|
|
622
|
+
this.#schedule();
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (owned.to.length > 1) {
|
|
626
|
+
const at = owned.to.indexOf(mesh);
|
|
627
|
+
other.field = {
|
|
628
|
+
...owned,
|
|
629
|
+
to: owned.to.filter((_, k) => k !== at),
|
|
630
|
+
toIds: owned.toIds.filter((_, k) => k !== at)
|
|
631
|
+
};
|
|
632
|
+
this.#dirtyMeshes.add(other.handle);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
const fieldKey = `field:${owned.id}`;
|
|
636
|
+
this.#host.forgetErrors((k) => k === fieldKey);
|
|
637
|
+
other.field = void 0;
|
|
638
|
+
other.sent = null;
|
|
639
|
+
other.inflight = void 0;
|
|
640
|
+
this.#dirtyMeshes.add(other.handle);
|
|
641
|
+
if (other.display.coloring !== null) other.display = Object.freeze({
|
|
642
|
+
...other.display,
|
|
643
|
+
coloring: null
|
|
644
|
+
});
|
|
645
|
+
if (other.desired.coloring !== null) {
|
|
646
|
+
this.#pendingDisplay.add(other);
|
|
647
|
+
this.#schedule();
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* The colouring last sent for `entry` may never have applied: forgets it
|
|
652
|
+
* (and its field), so that the next flush sends what is desired.
|
|
653
|
+
*/
|
|
654
|
+
#startOver(entry) {
|
|
655
|
+
entry.inflight = void 0;
|
|
656
|
+
if (entry.sent === null) {
|
|
657
|
+
entry.sent = entry.display.coloring;
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
entry.sent = null;
|
|
661
|
+
try {
|
|
662
|
+
this.#dropField(entry);
|
|
663
|
+
} catch {}
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* A parked mesh is back in the scene: it comes back into the snapshot as
|
|
667
|
+
* it was. The scene kept its own field and colouring; the colourings
|
|
668
|
+
* measured to it and the sections that cut it are asked for again.
|
|
669
|
+
*/
|
|
670
|
+
#comeBack(mesh) {
|
|
671
|
+
const entry = this.#parked.get(mesh);
|
|
672
|
+
if (entry === void 0) return;
|
|
673
|
+
this.#parked.delete(mesh);
|
|
674
|
+
this.#meshes.set(mesh, entry);
|
|
675
|
+
this.#dirtyMeshes.add(mesh);
|
|
676
|
+
if (entry.inflight !== void 0) this.#inflightMeshes.add(entry);
|
|
677
|
+
this.#checkField(entry);
|
|
678
|
+
const own = [entry.desired.coloring, entry.sent].flatMap((c) => c === null ? [] : targetsOf(c.distanceTo));
|
|
679
|
+
for (const target of /* @__PURE__ */ new Set([...own, ...entry.field?.to ?? []])) if (this.#host.presence(target) !== "live") this.#dropTarget(entry, target, true);
|
|
680
|
+
if (!sameData(entry.sent, entry.display.coloring)) this.#startOver(entry);
|
|
681
|
+
if (!sameData(entry.desired, entry.display) || !sameData(entry.desired.coloring, entry.sent)) {
|
|
682
|
+
this.#pendingDisplay.add(entry);
|
|
683
|
+
this.#schedule();
|
|
684
|
+
}
|
|
685
|
+
const live = (m) => this.#host.presence(m) === "live";
|
|
686
|
+
for (const other of [...this.#meshes.values(), ...this.#parked.values()]) {
|
|
687
|
+
const asked = other.asked;
|
|
688
|
+
const to = asked === null ? [] : targetsOf(asked.distanceTo);
|
|
689
|
+
if (asked === null || !to.includes(mesh)) continue;
|
|
690
|
+
other.desired = Object.freeze({
|
|
691
|
+
...other.desired,
|
|
692
|
+
coloring: to.every(live) ? asked : Object.freeze({
|
|
693
|
+
...asked,
|
|
694
|
+
distanceTo: Object.freeze(to.filter(live))
|
|
695
|
+
})
|
|
696
|
+
});
|
|
697
|
+
if (this.#meshes.get(other.handle) === other) {
|
|
698
|
+
this.#dirtyMeshes.add(other.handle);
|
|
699
|
+
this.#pendingDisplay.add(other);
|
|
700
|
+
this.#schedule();
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
for (const s of this.#sections.values()) if (s.asked.includes(mesh) && !s.desired.meshes.includes(mesh)) {
|
|
704
|
+
s.desired = this.#withMeshes(s.desired, Object.freeze(s.asked.filter((m) => m === mesh || s.desired.meshes.includes(m))));
|
|
705
|
+
this.#dirtySections.add(s.handle);
|
|
706
|
+
this.#pendingSections.add(s);
|
|
707
|
+
this.#schedule();
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* After meshes moved: when the scene no longer has the store-owned field
|
|
712
|
+
* as the store knows it (a target left and came back within one result,
|
|
713
|
+
* or left before the mesh did), the next flush colours the mesh again.
|
|
714
|
+
*/
|
|
715
|
+
#checkField(entry) {
|
|
716
|
+
const field = entry.field;
|
|
717
|
+
const left = field === void 0 ? void 0 : this.#host.fieldTargets(field.handle);
|
|
718
|
+
if (field === void 0 || left === void 0 || left !== null && left.length === field.to.length) return;
|
|
719
|
+
entry.sent = null;
|
|
720
|
+
entry.inflight = void 0;
|
|
721
|
+
entry.display = Object.freeze({
|
|
722
|
+
...entry.display,
|
|
723
|
+
coloring: null
|
|
724
|
+
});
|
|
725
|
+
this.#dirtyMeshes.add(entry.handle);
|
|
726
|
+
if (left === null) {
|
|
727
|
+
const key = `field:${field.id}`;
|
|
728
|
+
this.#host.forgetErrors((k) => k === key);
|
|
729
|
+
entry.field = void 0;
|
|
730
|
+
} else this.#dropField(entry);
|
|
731
|
+
if (this.#meshes.get(entry.handle) === entry) {
|
|
732
|
+
this.#pendingDisplay.add(entry);
|
|
733
|
+
this.#schedule();
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
/** Follows a frame's change records: meshes undo or redo took out of the scene or brought back. */
|
|
737
|
+
#followChanges(records) {
|
|
738
|
+
const left = records.filter((c) => c.removed && this.#meshes.has(c.mesh)).map((c) => c.mesh);
|
|
739
|
+
this.#leave(left.filter((m) => this.#host.presence(m) !== "live"), true);
|
|
740
|
+
for (const c of records) if (!c.removed && this.#parked.has(c.mesh) && this.#host.presence(c.mesh) === "live") this.#comeBack(c.mesh);
|
|
741
|
+
this.#dropGone();
|
|
742
|
+
}
|
|
743
|
+
/** Follows the history at once, as a local scene applies it. */
|
|
744
|
+
#followHistory() {
|
|
745
|
+
if (this.mode === "local") this.#followPresence();
|
|
746
|
+
}
|
|
747
|
+
/** Follows where undoable adds and removals, their undo and redo moved meshes. */
|
|
748
|
+
#followPresence() {
|
|
749
|
+
this.#presenceSeen = this.#host.presenceVersion();
|
|
750
|
+
this.#leave([...this.#meshes.keys()].filter((m) => this.#host.presence(m) !== "live"), true);
|
|
751
|
+
for (const mesh of [...this.#parked.keys()]) if (this.#host.presence(mesh) === "live") this.#comeBack(mesh);
|
|
752
|
+
for (const entry of this.#meshes.values()) this.#checkField(entry);
|
|
753
|
+
for (const s of this.#sections.values()) {
|
|
754
|
+
const cut = this.#host.sectionMeshes(s.handle);
|
|
755
|
+
if (cut !== void 0 && (cut.length !== s.sent.meshes.length || !cut.every((m) => s.sent.meshes.includes(m)))) {
|
|
756
|
+
s.sent = this.#withMeshes(s.sent, Object.freeze([...cut]));
|
|
757
|
+
this.#pendingSections.add(s);
|
|
758
|
+
this.#schedule();
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
this.#dropGone();
|
|
762
|
+
}
|
|
763
|
+
/** Forgets the parked meshes nothing can bring back any more. */
|
|
764
|
+
#dropGone() {
|
|
765
|
+
for (const mesh of [...this.#parked.keys()]) if (this.#host.presence(mesh) === "gone") this.#parked.delete(mesh);
|
|
526
766
|
}
|
|
527
767
|
/** `parts` with `meshes`, the same object when they are. */
|
|
528
768
|
#withMeshes(parts, meshes) {
|
|
@@ -594,19 +834,121 @@ var SceneStore = class {
|
|
|
594
834
|
throw e;
|
|
595
835
|
});
|
|
596
836
|
}
|
|
597
|
-
/**
|
|
837
|
+
/**
|
|
838
|
+
* Undoes the latest step. A mesh the step added undoably leaves the
|
|
839
|
+
* snapshot and one it removed undoably comes back: at once on a local
|
|
840
|
+
* scene, with the frame that delivers the result on a Worker scene.
|
|
841
|
+
*/
|
|
598
842
|
undo() {
|
|
599
843
|
this.#alive();
|
|
600
844
|
this.#host.undo();
|
|
845
|
+
this.#followHistory();
|
|
601
846
|
this.#update();
|
|
602
847
|
}
|
|
603
|
-
/** Redoes the latest undone step. */
|
|
848
|
+
/** Redoes the latest undone step; meshes follow as for {@link undo}. */
|
|
604
849
|
redo() {
|
|
605
850
|
this.#alive();
|
|
606
851
|
this.#host.redo();
|
|
852
|
+
this.#followHistory();
|
|
853
|
+
this.#update();
|
|
854
|
+
}
|
|
855
|
+
/** Opens a nested transaction step; edits/repairs/placements coalesce until {@link endStep}. */
|
|
856
|
+
beginStep() {
|
|
857
|
+
this.#alive();
|
|
858
|
+
this.#host.beginStep();
|
|
859
|
+
this.#update();
|
|
860
|
+
}
|
|
861
|
+
/** Commits one level of the open step transaction. Throws `STEP_NOT_OPEN` when none is open. */
|
|
862
|
+
endStep() {
|
|
863
|
+
this.#alive();
|
|
864
|
+
this.#host.endStep();
|
|
865
|
+
this.#update();
|
|
866
|
+
}
|
|
867
|
+
/** Reverts and discards the active step transaction, however deeply nested. */
|
|
868
|
+
cancelStep() {
|
|
869
|
+
this.#alive();
|
|
870
|
+
this.#host.cancelStep();
|
|
871
|
+
this.#followHistory();
|
|
607
872
|
this.#update();
|
|
608
873
|
}
|
|
609
874
|
/**
|
|
875
|
+
* Records an entry of the application's own in the undo history, in order
|
|
876
|
+
* with mesh edits: see the scene's `recordEntry`. The snapshot read in its
|
|
877
|
+
* `undo` and `redo` has the meshes as the step left them. On a Worker scene
|
|
878
|
+
* they run when the result arrives.
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* ```ts
|
|
882
|
+
* const before = curves;
|
|
883
|
+
* curves = [...curves, curve];
|
|
884
|
+
* store.recordEntry({
|
|
885
|
+
* undo: () => (curves = before),
|
|
886
|
+
* redo: () => (curves = [...before, curve]),
|
|
887
|
+
* bytes: curve.points.byteLength,
|
|
888
|
+
* });
|
|
889
|
+
* ```
|
|
890
|
+
*/
|
|
891
|
+
recordEntry(entry) {
|
|
892
|
+
this.#alive();
|
|
893
|
+
const { bytes, coalesce } = checkHistoryEntry(entry);
|
|
894
|
+
this.#host.recordEntry({
|
|
895
|
+
undo: () => {
|
|
896
|
+
this.#catchUp();
|
|
897
|
+
entry.undo();
|
|
898
|
+
},
|
|
899
|
+
redo: () => {
|
|
900
|
+
this.#catchUp();
|
|
901
|
+
entry.redo();
|
|
902
|
+
},
|
|
903
|
+
drop: () => entry.drop?.(),
|
|
904
|
+
bytes,
|
|
905
|
+
...coalesce === void 0 ? {} : { coalesce }
|
|
906
|
+
});
|
|
907
|
+
this.#update();
|
|
908
|
+
}
|
|
909
|
+
/** The scene has undone or redone a step and calls the application: the snapshot follows first. */
|
|
910
|
+
#catchUp() {
|
|
911
|
+
if (this.#disposed) return;
|
|
912
|
+
if (this.mode === "local" || this.#host.presenceVersion() !== this.#presenceSeen) this.#followPresence();
|
|
913
|
+
this.#stale = true;
|
|
914
|
+
this.#queueUpdate();
|
|
915
|
+
}
|
|
916
|
+
/** The most bytes the undo history may hold: 256 MiB unless it was set. */
|
|
917
|
+
get historyBudget() {
|
|
918
|
+
return this.#host.historyBudget();
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Changes the most bytes the undo history may hold. A smaller budget is met
|
|
922
|
+
* at once, the oldest steps first; a mesh only a dropped step could bring
|
|
923
|
+
* back is gone for good.
|
|
924
|
+
*
|
|
925
|
+
* @throws `INVALID_ARGUMENT` for anything but a number, 0 or more.
|
|
926
|
+
*/
|
|
927
|
+
setHistoryBudget(bytes) {
|
|
928
|
+
this.#alive();
|
|
929
|
+
this.#host.setHistoryBudget(bytes);
|
|
930
|
+
this.#followHistory();
|
|
931
|
+
this.#update();
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Registers a listener called with each step the history could not keep,
|
|
935
|
+
* since it is larger than the whole budget: an action that is permanent, or
|
|
936
|
+
* one just undone that cannot be redone; see the scene's `onPermanent`.
|
|
937
|
+
* Returns the function that removes it.
|
|
938
|
+
*
|
|
939
|
+
* @example
|
|
940
|
+
* ```ts
|
|
941
|
+
* store.onPermanent(({ lost, gone }) => {
|
|
942
|
+
* if (lost === "undo" && gone.includes(mesh)) {
|
|
943
|
+
* notify("Removed for good: it is larger than the undo memory.");
|
|
944
|
+
* }
|
|
945
|
+
* });
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
onPermanent(listener) {
|
|
949
|
+
return this.#host.onPermanent(listener);
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
610
952
|
* Changes how a mesh is shown. `desired` changes at once; `display` follows
|
|
611
953
|
* at the next `commitFrame()` (or a microtask without a frame loop). A
|
|
612
954
|
* patch equal to the current request changes nothing.
|
|
@@ -636,6 +978,7 @@ var SceneStore = class {
|
|
|
636
978
|
if (patch.coloring !== void 0) {
|
|
637
979
|
if (patch.coloring !== null && typeof patch.coloring !== "object") throw invalid("coloring must be an object or null");
|
|
638
980
|
if (!sameData(patch.coloring, entry.desired.coloring)) next.coloring = frozenCopy(patch.coloring);
|
|
981
|
+
entry.asked = next.coloring;
|
|
639
982
|
}
|
|
640
983
|
if (next.opacity === entry.desired.opacity && next.visible === entry.desired.visible && next.coloring === entry.desired.coloring) return;
|
|
641
984
|
entry.desired = Object.freeze(next);
|
|
@@ -793,6 +1136,7 @@ var SceneStore = class {
|
|
|
793
1136
|
id: this.#host.idOf(handle),
|
|
794
1137
|
applied: parts,
|
|
795
1138
|
desired: parts,
|
|
1139
|
+
asked: parts.meshes,
|
|
796
1140
|
sent: parts,
|
|
797
1141
|
inflight: {}
|
|
798
1142
|
});
|
|
@@ -813,7 +1157,10 @@ var SceneStore = class {
|
|
|
813
1157
|
const entry = this.#section(section);
|
|
814
1158
|
const next = { ...entry.desired };
|
|
815
1159
|
if (patch.plane !== void 0 && !sameData(patch.plane, next.plane)) next.plane = frozenCopy(patch.plane);
|
|
816
|
-
if (patch.meshes !== void 0
|
|
1160
|
+
if (patch.meshes !== void 0) {
|
|
1161
|
+
if (!sameData(patch.meshes, next.meshes)) next.meshes = frozenCopy(patch.meshes);
|
|
1162
|
+
entry.asked = next.meshes;
|
|
1163
|
+
}
|
|
817
1164
|
if (patch.fill !== void 0) {
|
|
818
1165
|
if (typeof patch.fill !== "boolean") throw invalid("fill must be a boolean");
|
|
819
1166
|
next.fill = patch.fill;
|
|
@@ -892,6 +1239,7 @@ var SceneStore = class {
|
|
|
892
1239
|
for (const off of this.#unsubscribe.splice(0)) off();
|
|
893
1240
|
this.#pendingDisplay.clear();
|
|
894
1241
|
this.#pendingSections.clear();
|
|
1242
|
+
this.#parked.clear();
|
|
895
1243
|
}
|
|
896
1244
|
#alive() {
|
|
897
1245
|
if (this.#disposed) throw invalid("the store is disposed");
|
|
@@ -953,7 +1301,7 @@ var SceneStore = class {
|
|
|
953
1301
|
const drop = this.#dropFields.delete(entry) && want === null;
|
|
954
1302
|
try {
|
|
955
1303
|
this.#host.track(key, () => {
|
|
956
|
-
if (sameData(want, entry.sent)) {
|
|
1304
|
+
if (sameData(want, entry.sent) && (want !== null || this.#host.status(key).status !== "error")) {
|
|
957
1305
|
if (drop) this.#dropField(entry);
|
|
958
1306
|
return;
|
|
959
1307
|
}
|
|
@@ -1025,9 +1373,11 @@ var SceneStore = class {
|
|
|
1025
1373
|
}
|
|
1026
1374
|
/** Sends each aspect of a section whose desired value differs from the one sent, under its own key. */
|
|
1027
1375
|
#flushSection(entry) {
|
|
1376
|
+
const retry = entry.retry === true;
|
|
1377
|
+
entry.retry = void 0;
|
|
1028
1378
|
for (const a of ASPECTS) {
|
|
1029
1379
|
const want = entry.desired[a];
|
|
1030
|
-
if (sameData(want, entry.sent[a])) continue;
|
|
1380
|
+
if (sameData(want, entry.sent[a]) && !(retry && a === "meshes")) continue;
|
|
1031
1381
|
try {
|
|
1032
1382
|
this.#host.track(`section:${entry.id}:${a}`, () => {
|
|
1033
1383
|
if (a === "plane") this.#host.setSectionPlane(entry.handle, want);
|
|
@@ -1376,8 +1726,8 @@ var SceneStore = class {
|
|
|
1376
1726
|
}
|
|
1377
1727
|
};
|
|
1378
1728
|
/** A store over `scene` (a `Scene` or a `WorkerScene`). */
|
|
1379
|
-
function createSceneStore(scene) {
|
|
1380
|
-
return new SceneStore(scene);
|
|
1729
|
+
function createSceneStore(scene, options) {
|
|
1730
|
+
return new SceneStore(scene, options);
|
|
1381
1731
|
}
|
|
1382
1732
|
/**
|
|
1383
1733
|
* Internal, not exported from `fast-mesh-wasm/store`: switches the store's
|