fast-mesh-wasm 0.3.0 → 0.4.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 (38) hide show
  1. package/README.md +7 -2
  2. package/dist/{client-Bp9FRd70.js → client-Bpjy-eFY.js} +1 -1
  3. package/dist/{client-m2zSdFlu.d.ts → client-D-O5-tAg.d.ts} +2 -2
  4. package/dist/{colormap-D_xH5hI5.js → colormap-DxGMYVfs.js} +1 -1
  5. package/dist/{engine-B-ZEzR1c.js → engine-D6MpGb9i.js} +155 -20
  6. package/dist/{mesh-B16gV3oX.d.ts → mesh-BUVxv3jo.d.ts} +8 -1
  7. package/dist/{mesh-B8pae8WA.js → mesh-zj7-wJBw.js} +52 -5
  8. package/dist/node.d.ts +2 -2
  9. package/dist/node.js +1 -1
  10. package/dist/{protocol-W9R-iGl5.d.ts → protocol-CK6_3aqo.d.ts} +1 -1
  11. package/dist/r3f.d.ts +3 -3
  12. package/dist/r3f.js +2 -2
  13. package/dist/react.d.ts +2 -2
  14. package/dist/{scene-BG3EEyfw.js → scene-D6m9XM3O.js} +111 -12
  15. package/dist/{scene-like-B_3qm0u6.d.ts → scene-like-DJKQP5uf.d.ts} +46 -5
  16. package/dist/{store-D3ErV6o-.js → store-Ml3TQGsR.js} +2 -2
  17. package/dist/{store-DNnHN33A.d.ts → store-QWRDXlAn.d.ts} +2 -2
  18. package/dist/store.d.ts +2 -2
  19. package/dist/store.js +1 -1
  20. package/dist/three.d.ts +7 -6
  21. package/dist/three.js +7 -2
  22. package/dist/{views-BaZqBxlX.js → views-Dh3aWc2q.js} +1 -1
  23. package/dist/wasm/fast_mesh_wasm.d.ts +61 -12
  24. package/dist/wasm/fast_mesh_wasm.js +116 -20
  25. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  26. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +7 -1
  27. package/dist/wasm-threads/fast_mesh_wasm.d.ts +61 -12
  28. package/dist/wasm-threads/fast_mesh_wasm.js +116 -20
  29. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
  30. package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +7 -1
  31. package/dist/web.d.ts +2 -2
  32. package/dist/web.js +1 -1
  33. package/dist/worker-engine.d.ts +16 -7
  34. package/dist/worker-engine.js +1 -1
  35. package/dist/worker-entry.js +1 -1
  36. package/dist/worker.d.ts +1 -1
  37. package/dist/worker.js +1 -1
  38. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { a as release, c as wasmMemory, i as finalizer, n as call, r as ensureInitialized, t as FastMeshError } from "./core-Cke_kZ2e.js";
2
- import { a as FieldHandle, c as rotationMatrix, i as encodeRule, l as targetsOf, n as meshViews, o as MeshHandle, r as copyRule, s as SectionHandle, t as ViewGuard } from "./views-BaZqBxlX.js";
2
+ import { a as FieldHandle, c as rotationMatrix, i as encodeRule, l as targetsOf, n as meshViews, o as MeshHandle, r as copyRule, s as SectionHandle, t as ViewGuard } from "./views-Dh3aWc2q.js";
3
3
  import { WasmScene } from "./wasm/fast_mesh_wasm.js";
4
4
  //#region src/changes.ts
5
5
  const ADDED = 1;
@@ -78,6 +78,11 @@ const MODES = {
78
78
  lazy: 1,
79
79
  manual: 2
80
80
  };
81
+ const MODE_NAMES = [
82
+ "eager",
83
+ "lazy",
84
+ "manual"
85
+ ];
81
86
  function modeCode(mode) {
82
87
  if (!Object.hasOwn(MODES, mode)) throw invalid("mode must be \"eager\", \"lazy\" or \"manual\"");
83
88
  return MODES[mode];
@@ -239,7 +244,7 @@ function encodeRepair(ops) {
239
244
  count = o.loops.length;
240
245
  for (const id of o.loops) encodeLoopId(id, loops);
241
246
  }
242
- values.push(optional(o.maxEdges, "maxEdges"), optional(o.maxPerimeter, "maxPerimeter"), optional(o.maxArea, "maxArea"), count, flagOf(o.allowUnclean, false), flagOf(o.fair, true), optional(o.dpLimit, "dpLimit"));
247
+ values.push(optional(o.maxEdges, "maxEdges"), optional(o.maxPerimeter, "maxPerimeter"), optional(o.maxArea, "maxArea"), count, flagOf(o.allowUnclean, false), flagOf(o.fair, true), optional(o.dpLimit, "dpLimit"), optional(o.maxDihedral, "maxDihedral"), optional(o.maxRefineVertices, "maxRefineVertices"));
243
248
  break;
244
249
  }
245
250
  }
@@ -326,7 +331,8 @@ function decodeReport(op, r) {
326
331
  trianglesAdded: r.next(),
327
332
  verticesAdded: r.next(),
328
333
  converged: r.flag(),
329
- weights: WEIGHTS[r.next()]
334
+ weights: WEIGHTS[r.next()],
335
+ refineCapped: r.flag()
330
336
  })),
331
337
  skipped: r.many(() => ({
332
338
  id: r.loopId(),
@@ -599,6 +605,47 @@ var Scene = class {
599
605
  const m = modeCode(mode);
600
606
  call(() => this.#scene().set_mode(index, generation, m));
601
607
  }
608
+ /** When the mesh's derived data follows its edits; see {@link UpdateMode}. */
609
+ mode(mesh) {
610
+ const { index, generation } = this.#id(mesh);
611
+ const code = call(() => this.#peek().mode(index, generation));
612
+ return MODE_NAMES[code] ?? "eager";
613
+ }
614
+ /**
615
+ * The box around the vertices the live triangles use, in the mesh's local
616
+ * render coordinates ({@link Scene.matrix4} maps them to the world). Dead
617
+ * slots keep stale positions, so they are excluded. `null` without live
618
+ * triangles.
619
+ */
620
+ bounds(mesh) {
621
+ const { index, generation } = this.#id(mesh);
622
+ const b = call(() => this.#peek().bounds(index, generation));
623
+ if (b.length === 0) return null;
624
+ const min = [
625
+ b[0],
626
+ b[1],
627
+ b[2]
628
+ ];
629
+ const max = [
630
+ b[3],
631
+ b[4],
632
+ b[5]
633
+ ];
634
+ return {
635
+ min,
636
+ max,
637
+ center: [
638
+ (min[0] + max[0]) / 2,
639
+ (min[1] + max[1]) / 2,
640
+ (min[2] + max[2]) / 2
641
+ ],
642
+ size: [
643
+ max[0] - min[0],
644
+ max[1] - min[1],
645
+ max[2] - min[2]
646
+ ]
647
+ };
648
+ }
602
649
  /** Brings the mesh's derived data up to date now, whatever its mode. */
603
650
  update(mesh) {
604
651
  const { index, generation } = this.#id(mesh);
@@ -645,6 +692,7 @@ var Scene = class {
645
692
  * {@link Scene.commitFrame} instead.
646
693
  */
647
694
  takeChanges() {
695
+ this.#drag?.applyPending();
648
696
  const s = this.#scene();
649
697
  const raw = decodeChanges(call(() => s.take_changes()));
650
698
  const out = raw.map((c) => ({
@@ -742,6 +790,8 @@ var Scene = class {
742
790
  /** Ends one nesting level of the open step. Throws `STEP_NOT_OPEN` when none is open. */
743
791
  endStep() {
744
792
  const s = this.#scene();
793
+ const drag = this.#drag;
794
+ if (drag !== void 0 && this.#stepDepth > 0 && this.#stepDepth <= drag.depth) drag.applyPending();
745
795
  call(() => s.end_step());
746
796
  this.#stepDepth--;
747
797
  if (this.#drag !== void 0 && this.#stepDepth < this.#drag.depth) this.#drag.abandon();
@@ -757,16 +807,20 @@ var Scene = class {
757
807
  * Starts dragging a mesh: the moves until {@link DragSession.end} form one
758
808
  * undo step (nested in the open step, if there is one). One drag at a time.
759
809
  * Every {@link DragSession.move} recomputes the eager fields, so make at most
760
- * one move per animation frame, with the latest pointer pose.
810
+ * one move per animation frame, with the latest pointer pose, or pass
811
+ * `{ coalesce: true }` to have the drag do that for you.
761
812
  */
762
- drag(mesh) {
813
+ drag(mesh, options = {}) {
763
814
  this.#id(mesh);
764
815
  if (this.#drag !== void 0) throw invalid("a drag is already active; end or cancel it first");
816
+ const coalesce = options.coalesce ?? false;
765
817
  const start = this.placement(mesh);
766
818
  const outermost = this.#stepDepth === 0;
767
819
  this.beginStep();
768
820
  const depth = this.#stepDepth;
769
821
  let active = true;
822
+ /** The latest coalesced pose, not yet applied. */
823
+ let pending;
770
824
  const finish = () => {
771
825
  if (!active) return false;
772
826
  active = false;
@@ -776,6 +830,13 @@ var Scene = class {
776
830
  const close = () => {
777
831
  while (this.#stepDepth >= depth) this.endStep();
778
832
  };
833
+ const applyPending = () => {
834
+ if (pending !== void 0) {
835
+ const pose = pending;
836
+ pending = void 0;
837
+ this.setPlacement(mesh, pose);
838
+ }
839
+ };
779
840
  const session = {
780
841
  depth,
781
842
  mesh,
@@ -784,13 +845,37 @@ var Scene = class {
784
845
  },
785
846
  move: (placement) => {
786
847
  if (!active) throw invalid("the drag is over");
787
- this.setPlacement(mesh, placement);
848
+ if (!coalesce) {
849
+ this.setPlacement(mesh, placement);
850
+ return;
851
+ }
852
+ const rotation = rotationMatrix(placement.rotation);
853
+ if (!rotation.every(Number.isFinite)) throw invalid("rotation must be finite numbers");
854
+ const t = placement.translation;
855
+ if (t?.length !== 3 || ![
856
+ t[0],
857
+ t[1],
858
+ t[2]
859
+ ].every(Number.isFinite)) throw invalid("translation must be 3 finite numbers");
860
+ pending = {
861
+ rotation,
862
+ translation: [
863
+ t[0],
864
+ t[1],
865
+ t[2]
866
+ ]
867
+ };
788
868
  },
789
869
  end: () => {
790
- if (finish()) close();
870
+ if (finish()) try {
871
+ applyPending();
872
+ } finally {
873
+ close();
874
+ }
791
875
  },
792
876
  cancel: () => {
793
877
  if (!finish()) return;
878
+ pending = void 0;
794
879
  if (outermost) {
795
880
  this.cancelStep();
796
881
  return;
@@ -803,7 +888,8 @@ var Scene = class {
803
888
  },
804
889
  abandon: () => {
805
890
  finish();
806
- }
891
+ },
892
+ applyPending
807
893
  };
808
894
  this.#drag = session;
809
895
  return session;
@@ -1088,19 +1174,32 @@ var Scene = class {
1088
1174
  }
1089
1175
  static {
1090
1176
  meshAddsOf = (scene) => ({
1091
- begin: (positions, indices, options = {}) => {
1177
+ beginUpload: (vertices, triangles, options = {}) => {
1092
1178
  const s = scene.#scene();
1093
1179
  const mode = modeCode(options.mode ?? "eager");
1094
1180
  const origin = options.origin === void 0 ? void 0 : Float64Array.from(options.origin);
1095
- const p = toFloat64(positions);
1096
- const i = toUint32(indices);
1097
- return call(() => s.begin_add_mesh(p, i, origin, mode, options.normals ?? true));
1181
+ return call(() => s.begin_add_mesh_upload(vertices, triangles, origin, mode, options.normals ?? true));
1098
1182
  },
1183
+ pushPositions: (token, chunk) => call(() => scene.#scene().add_mesh_push_positions(token, chunk)),
1184
+ pushIndices: (token, chunk) => call(() => scene.#scene().add_mesh_push_indices(token, chunk)),
1099
1185
  step: (token, budget) => call(() => scene.#scene().add_mesh_step(token, budget)),
1186
+ buffers: (token) => {
1187
+ const [pp, pl, np, nl, ip, il] = call(() => scene.#peek().add_mesh_buffers(token));
1188
+ const memory = wasmMemory().buffer;
1189
+ return {
1190
+ positions: new Float32Array(memory, pp, pl),
1191
+ normals: np === 0 ? null : new Float32Array(memory, np, nl),
1192
+ indices: new Uint32Array(memory, ip, il)
1193
+ };
1194
+ },
1100
1195
  finish: (token) => {
1101
1196
  const id = call(() => scene.#scene().finish_add_mesh(token));
1102
1197
  return scene.#meshHandle(id[0], id[1]);
1103
1198
  },
1199
+ stamp: (mesh) => {
1200
+ const { index, generation } = scene.#id(mesh);
1201
+ return call(() => scene.#peek().content_stamp(index, generation));
1202
+ },
1104
1203
  drop: (token) => call(() => scene.#peek().drop_add_mesh(token))
1105
1204
  });
1106
1205
  }
@@ -167,6 +167,8 @@ interface MeshChange {
167
167
  * The drag is over once it is ended or cancelled, and also when its step goes
168
168
  * away without it: an `undo()`, `redo()`, `clearHistory()` or `removeMesh()` of
169
169
  * the dragged mesh ends it first, and a `cancelStep()` (or an `endStep()` that closes the drag's step) abandons it.
170
+ * An `endStep()` lands a pending coalesced pose in the closing step first; a
171
+ * `cancelStep()` drops it with the step.
170
172
  */
171
173
  interface DragSession {
172
174
  /**
@@ -174,7 +176,8 @@ interface DragSession {
174
176
  *
175
177
  * Each move recomputes the eager fields that depend on the mesh, so
176
178
  * coalesce pointer events to one move per animation frame (keep the latest
177
- * pose and apply it before {@link Scene.commitFrame}).
179
+ * pose and apply it before {@link Scene.commitFrame}), or start the drag
180
+ * with {@link DragOptions.coalesce}.
178
181
  */
179
182
  move(placement: PlacementInput): void;
180
183
  /**
@@ -199,6 +202,18 @@ interface DragSession {
199
202
  */
200
203
  cancel(): void;
201
204
  }
205
+ /** Options of {@link Scene.drag}. */
206
+ interface DragOptions {
207
+ /**
208
+ * Coalesce moves: each {@link DragSession.move} only remembers its pose,
209
+ * and the latest one is applied once at the next {@link Scene.commitFrame}
210
+ * (or {@link DragSession.end}). For pointer events at 120–250 Hz: without
211
+ * it, every move recomputes the eager fields. Until the frame,
212
+ * {@link Scene.placement} and {@link Scene.matrix4} show the last applied
213
+ * pose. `WorkerScene` drags always coalesce. Defaults to `false`.
214
+ */
215
+ coalesce?: boolean;
216
+ }
202
217
  /** Options of {@link Scene.addMesh}. */
203
218
  interface AddMeshOptions {
204
219
  /**
@@ -379,7 +394,10 @@ interface SectionDesc {
379
394
  }
380
395
  /** One chain of a section: a closed loop or an open polyline. */
381
396
  interface SectionContour {
382
- /** World xyz, 3 floats per point. A copy. */
397
+ /**
398
+ * World xyz, 3 floats per point. A copy. Where the plane passes exactly
399
+ * through a vertex, the contour repeats that point (a zero-length segment).
400
+ */
383
401
  points: Float32Array;
384
402
  closed: boolean;
385
403
  }
@@ -551,6 +569,10 @@ type RepairOp = {
551
569
  allowUnclean?: boolean;
552
570
  fair?: boolean;
553
571
  dpLimit?: number;
572
+ /** Reject a minimum-weight triangulation past this dihedral, in radians. */
573
+ maxDihedral?: number;
574
+ /** Stop refining a patch once it has this many new vertices. */
575
+ maxRefineVertices?: number;
554
576
  };
555
577
  /** What `weld` did. */
556
578
  interface WeldReport {
@@ -586,6 +608,8 @@ interface FilledLoop {
586
608
  converged: boolean;
587
609
  /** The Laplacian weights fairing used; `null` when it did not run. */
588
610
  weights: "cotangent" | "uniform" | null;
611
+ /** Whether refinement stopped early on its vertex budget or rounds. */
612
+ refineCapped: boolean;
589
613
  }
590
614
  /** What `fillHoles` did, each list in loop order. */
591
615
  interface FillReport {
@@ -665,6 +689,15 @@ declare class Scene implements SceneLike {
665
689
  matrix4(mesh: MeshHandle): Float64Array;
666
690
  /** Sets when the mesh's derived data follows its edits; see {@link UpdateMode}. */
667
691
  setMode(mesh: MeshHandle, mode: UpdateMode): void;
692
+ /** When the mesh's derived data follows its edits; see {@link UpdateMode}. */
693
+ mode(mesh: MeshHandle): UpdateMode;
694
+ /**
695
+ * The box around the vertices the live triangles use, in the mesh's local
696
+ * render coordinates ({@link Scene.matrix4} maps them to the world). Dead
697
+ * slots keep stale positions, so they are excluded. `null` without live
698
+ * triangles.
699
+ */
700
+ bounds(mesh: MeshHandle): Bounds | null;
668
701
  /** Brings the mesh's derived data up to date now, whatever its mode. */
669
702
  update(mesh: MeshHandle): void;
670
703
  /** Brings every mesh that is not `"manual"` up to date. */
@@ -729,9 +762,10 @@ declare class Scene implements SceneLike {
729
762
  * Starts dragging a mesh: the moves until {@link DragSession.end} form one
730
763
  * undo step (nested in the open step, if there is one). One drag at a time.
731
764
  * Every {@link DragSession.move} recomputes the eager fields, so make at most
732
- * one move per animation frame, with the latest pointer pose.
765
+ * one move per animation frame, with the latest pointer pose, or pass
766
+ * `{ coalesce: true }` to have the drag do that for you.
733
767
  */
734
- drag(mesh: MeshHandle): DragSession;
768
+ drag(mesh: MeshHandle, options?: DragOptions): DragSession;
735
769
  /**
736
770
  * Edits a mesh's geometry with a list of ops, run in Rust as one
737
771
  * transaction: one undo step (or part of the open step), and when any op
@@ -920,6 +954,13 @@ interface SceneLike {
920
954
  * falls back to vertex colours on a host without it.
921
955
  */
922
956
  coloring?(mesh: MeshHandle): ColorRule | null;
957
+ /**
958
+ * The box around the vertices the mesh's live triangles use, in local
959
+ * render coordinates, or `null` without live triangles. Optional:
960
+ * `bindMesh` takes its bounds from it and walks the mirrors on a host
961
+ * without it.
962
+ */
963
+ bounds?(mesh: MeshHandle): Bounds | null;
923
964
  }
924
965
  //#endregion
925
- export { PlacementInput as $, RepairOp as A, SectionResult as B, MeshComponent as C, RayHit as D, OutOfRange as E, SceneOptions as F, SectionHandle as G, WeldReport as H, SectionContour as I, Bounds as J, Range as K, SectionDesc as L, RepairReportOf as M, Rgba as N, RaycastOptions as O, Scene as P, Placement as Q, SectionGap as R, MeshChange as S, OrientReport as T, FieldHandle as U, SignMode as V, MeshHandle as W, InitInput as X, Indices as Y, Mat3 as Z, FieldStatus as _, BoundaryLoop as a, computeBounds as at, FindContactsOptions as b, ColorRule as c, DegenerateReport as d, Positions as et, DistanceFieldDesc as f, EditResult as g, EditRef as h, AnalyzeOptions as i, Vec3 as it, RepairReport as j, RemoveReport as k, Colormap as l, EditOp as m, AddMeshOptions as n, Quat as nt, ClosestHit as o, computeVertexNormals as ot, DragSession as p, MeshViews as q, Analysis as r, UpdateMode as rt, ClosestPointOptions as s, SceneLike as t, Positions64 as tt, Contact as u, FillReport as v, MeshDistance as w, LoopId as x, FilledLoop as y, SectionPlane as z };
966
+ export { Placement as $, RemoveReport as A, SectionPlane as B, MeshChange as C, OutOfRange as D, OrientReport as E, Scene as F, MeshHandle as G, SignMode as H, SceneOptions as I, MeshViews as J, SectionHandle as K, SectionContour as L, RepairReport as M, RepairReportOf as N, RayHit as O, Rgba as P, Mat3 as Q, SectionDesc as R, LoopId as S, MeshDistance as T, WeldReport as U, SectionResult as V, FieldHandle as W, Indices as X, Bounds as Y, InitInput as Z, EditResult as _, BoundaryLoop as a, Vec3 as at, FilledLoop as b, ColorRule as c, DegenerateReport as d, PlacementInput as et, DistanceFieldDesc as f, EditRef as g, EditOp as h, AnalyzeOptions as i, UpdateMode as it, RepairOp as j, RaycastOptions as k, Colormap as l, DragSession as m, AddMeshOptions as n, Positions64 as nt, ClosestHit as o, computeBounds as ot, DragOptions as p, Range as q, Analysis as r, Quat as rt, ClosestPointOptions as s, computeVertexNormals as st, SceneLike as t, Positions as tt, Contact as u, FieldStatus as v, MeshComponent as w, FindContactsOptions as x, FillReport as y, SectionGap as z };
@@ -1,7 +1,7 @@
1
1
  import { o as reportListenerError, t as FastMeshError } from "./core-Cke_kZ2e.js";
2
- import { l as targetsOf } from "./views-BaZqBxlX.js";
2
+ import { l as targetsOf } from "./views-Dh3aWc2q.js";
3
3
  import { i as sectionAspects } from "./protocol-CAUYm1gd.js";
4
- import { i as watchStatusKeys, n as addFieldKeyed } from "./client-Bp9FRd70.js";
4
+ import { i as watchStatusKeys, n as addFieldKeyed } from "./client-Bpjy-eFY.js";
5
5
  import { a as combine, c as sameData, n as EMPTY_SNAPSHOT, o as frozenCopy, t as DEFAULT_DISPLAY } from "./snapshot-Cf6NgDl7.js";
6
6
  //#region src/store/host.ts
7
7
  /** Whether `scene` is a Worker scene (structurally: it reports key statuses). */
@@ -1,6 +1,6 @@
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";
1
+ import { B as SectionPlane, C as MeshChange, D as OutOfRange, F as Scene, G as MeshHandle, H as SignMode, K as SectionHandle, M as RepairReport, P as Rgba, R as SectionDesc, X as Indices, _ as EditResult, et as PlacementInput, h as EditOp, j as RepairOp, l as Colormap, m as DragSession, n as AddMeshOptions, nt as Positions64, t as SceneLike } from "./scene-like-DJKQP5uf.js";
2
2
  import { t as FastMeshError } from "./core-D2X9GPfK.js";
3
- import { r as WorkerScene } from "./client-m2zSdFlu.js";
3
+ import { r as WorkerScene } from "./client-D-O5-tAg.js";
4
4
  //#region src/store/host.d.ts
5
5
  /** Options of `SceneStore.addMesh`: those both scenes take (a store mesh is always eager). */
6
6
  type StoreAddMeshOptions = Pick<AddMeshOptions, "origin" | "normals">;
package/dist/store.d.ts CHANGED
@@ -1,5 +1,5 @@
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";
1
+ import { H as SignMode, P as Rgba } from "./scene-like-DJKQP5uf.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-QWRDXlAn.js";
3
3
  //#region src/store/heatmap.d.ts
4
4
  /** Options of {@link contactHeatmap}. Distances are in the meshes' units. */
5
5
  interface ContactHeatmapOptions {
package/dist/store.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as FastMeshError } from "./core-Cke_kZ2e.js";
2
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";
3
+ import { n as createSceneStore, t as SceneStore } from "./store-Ml3TQGsR.js";
4
4
  //#region src/store/heatmap.ts
5
5
  /** The default colours: `#7f0000`, `#ff6b6b`, `#ffffff`, `#4caf50`, `#1e3a8a`. */
6
6
  const DEFAULT_COLORS = {
package/dist/three.d.ts CHANGED
@@ -1,5 +1,5 @@
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";
1
+ import { K as SectionHandle, t as SceneLike } from "./scene-like-DJKQP5uf.js";
2
+ import { i as bindMesh, n as BoundMesh, r as MeshBinding, t as BindMeshOptions } from "./mesh-BUVxv3jo.js";
3
3
  import * as THREE from "three";
4
4
  //#region src/three/controls.d.ts
5
5
  /**
@@ -42,7 +42,8 @@ interface AttachTransformControlsOptions {
42
42
  *
43
43
  * Placements are rigid: TransformControls' scale mode has no effect (the
44
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`.
45
+ * untransformed parent (its matrix is a world matrix), as for `bindMesh`;
46
+ * a transformed ancestor is detected and warned about once.
46
47
  *
47
48
  * The object's `position`, `quaternion` and `scale` are kept in step with its
48
49
  * matrix (TransformControls reads them when a drag starts), so call this
@@ -74,9 +75,9 @@ interface BindSectionOptions {
74
75
  interface BoundSection {
75
76
  /**
76
77
  * 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).
78
+ * coordinates; a transformed ancestor is detected and warned about once).
79
+ * Per bound mesh the section cuts, it holds a `LineSegments` of the contours
80
+ * and a `Mesh` of the fill (empty while the section has no fill).
80
81
  */
81
82
  readonly group: THREE.Group;
82
83
  /**
package/dist/three.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as FastMeshError } from "./core-Cke_kZ2e.js";
2
- import { t as bindMesh } from "./mesh-B8pae8WA.js";
2
+ import { n as checkUntransformedParent, t as bindMesh } from "./mesh-zj7-wJBw.js";
3
3
  import * as THREE from "three";
4
4
  //#region src/three/controls.ts
5
5
  const defaultSchedule = (callback) => {
@@ -34,7 +34,8 @@ function rotate(q, v) {
34
34
  *
35
35
  * Placements are rigid: TransformControls' scale mode has no effect (the
36
36
  * object's scale is kept at 1). The object must be a direct child of an
37
- * untransformed parent (its matrix is a world matrix), as for `bindMesh`.
37
+ * untransformed parent (its matrix is a world matrix), as for `bindMesh`;
38
+ * a transformed ancestor is detected and warned about once.
38
39
  *
39
40
  * The object's `position`, `quaternion` and `scale` are kept in step with its
40
41
  * matrix (TransformControls reads them when a drag starts), so call this
@@ -166,6 +167,7 @@ function attachTransformControls(controls, scene, bound, options = {}) {
166
167
  };
167
168
  const onObjectChange = () => {
168
169
  if (live() === void 0 || controls.object !== object) return;
170
+ checkUntransformedParent(object);
169
171
  object.scale.set(1, 1, 1);
170
172
  object.updateMatrix();
171
173
  const q = object.quaternion;
@@ -204,6 +206,7 @@ function attachTransformControls(controls, scene, bound, options = {}) {
204
206
  controls.addEventListener("dragging-changed", onDraggingChanged);
205
207
  controls.addEventListener("objectChange", onObjectChange);
206
208
  syncFromScene();
209
+ checkUntransformedParent(object);
207
210
  return () => {
208
211
  if (!attached) return;
209
212
  attached = false;
@@ -349,7 +352,9 @@ function bindSection(scene, section, bound, options = {}) {
349
352
  unsubscribe?.();
350
353
  unsubscribe = void 0;
351
354
  };
355
+ checkUntransformedParent(group);
352
356
  unsubscribe = scene.onChanges((changes) => {
357
+ checkUntransformedParent(group);
353
358
  let plane;
354
359
  try {
355
360
  plane = scene.sectionPlane(section);
@@ -1,5 +1,5 @@
1
1
  import { c as wasmMemory, n as call, t as FastMeshError } from "./core-Cke_kZ2e.js";
2
- import { n as DEFAULT_NAN, t as DEFAULT_BASE } from "./colormap-D_xH5hI5.js";
2
+ import { n as DEFAULT_NAN, t as DEFAULT_BASE } from "./colormap-DxGMYVfs.js";
3
3
  //#region src/handles.ts
4
4
  /**
5
5
  * A mesh in a {@link Scene}. Opaque: pass it to the scene's methods. The same
@@ -29,13 +29,35 @@ export class WasmScene {
29
29
  * Positions are stored as `p - origin` in `f32`; without `origin` it
30
30
  * is the bounding-box centre. `mode` is 0 (Eager), 1 (Lazy) or 2
31
31
  * (Manual); `normals` turns vertex normals on. The placement starts as
32
- * the identity. Nothing is added on error.
32
+ * the identity. A Lazy or Manual mesh builds its BVH on first use
33
+ * instead of up front. Nothing is added on error.
33
34
  */
34
35
  add_mesh(positions: Float64Array, indices: Uint32Array, origin: Float64Array | null | undefined, mode: number, normals: boolean): Uint32Array;
35
36
  /**
36
- * Builds about `budget` more units of a mesh being added (see
37
- * `MeshBuild::step`); `true` once its BVH is built. A failed build is
38
- * dropped.
37
+ * The render buffers of a mesh being added in steps, as
38
+ * `[positions_ptr, positions_len, normals_ptr, normals_len,
39
+ * indices_ptr, indices_len]` (as the `*_ptr` / `*_len` methods give
40
+ * them once it is added; normals 0, 0 until built or when off). The
41
+ * added mesh keeps these addresses and contents until it changes, so
42
+ * they can be copied out before it lands. Valid until the next call
43
+ * that may allocate.
44
+ */
45
+ add_mesh_buffers(build: number): Uint32Array;
46
+ /**
47
+ * Appends a chunk of flat `[a, b, c, ...]` indices to a mesh being
48
+ * added; the chunks must add up to its declared triangles.
49
+ */
50
+ add_mesh_push_indices(build: number, chunk: Uint32Array): void;
51
+ /**
52
+ * Appends a chunk of flat `[x, y, z, ...]` world positions to a mesh
53
+ * being added; the chunks must add up to its declared vertices.
54
+ */
55
+ add_mesh_push_positions(build: number, chunk: Float64Array): void;
56
+ /**
57
+ * Builds about `budget` more units of a mesh being added: first its
58
+ * store (vertices or triangles a unit), then its BVH (see
59
+ * `MeshBuild::step`); `true` once its BVH is built. The upload must be
60
+ * complete first. A failed build is dropped.
39
61
  */
40
62
  add_mesh_step(build: number, budget: number): boolean;
41
63
  /**
@@ -53,16 +75,26 @@ export class WasmScene {
53
75
  */
54
76
  analyze(index: number, generation: number, weld_tolerance: number, self_intersection: boolean, max_listed: number): Float64Array;
55
77
  /**
56
- * [`WasmScene::add_mesh`] in steps: starts building the mesh and its
57
- * BVH outside the scene ([`MeshBuild`]) and returns the build's id, for
58
- * [`WasmScene::add_mesh_step`] and [`WasmScene::finish_add_mesh`]. The
59
- * scene is unchanged until the mesh is added.
78
+ * [`WasmScene::add_mesh`] in steps: reserves a mesh of `vertices`
79
+ * vertices and `triangles` triangles outside the scene and returns the
80
+ * build's id. Its inputs upload in chunks
81
+ * ([`WasmScene::add_mesh_push_positions`] and
82
+ * [`WasmScene::add_mesh_push_indices`]), then its store, BVH and
83
+ * normals build in steps ([`WasmScene::add_mesh_step`]), for
84
+ * [`WasmScene::finish_add_mesh`]. The scene is unchanged until the
85
+ * mesh is added.
60
86
  */
61
- begin_add_mesh(positions: Float64Array, indices: Uint32Array, origin: Float64Array | null | undefined, mode: number, normals: boolean): number;
87
+ begin_add_mesh_upload(vertices: number, triangles: number, origin: Float64Array | null | undefined, mode: number, normals: boolean): number;
62
88
  /**
63
89
  * Opens a history step, or one more nesting level of the open one.
64
90
  */
65
91
  begin_step(): void;
92
+ /**
93
+ * The box around the vertices the live triangles use, in the mesh's
94
+ * stored local coordinates: `[min xyz, max xyz]`. Empty without live
95
+ * triangles.
96
+ */
97
+ bounds(index: number, generation: number): Float64Array;
66
98
  /**
67
99
  * True if `redo` would redo something.
68
100
  */
@@ -108,6 +140,11 @@ export class WasmScene {
108
140
  * edits leave the history (placements stay).
109
141
  */
110
142
  compact(index: number, generation: number): void;
143
+ /**
144
+ * The mesh's content stamp (`Scene::content_stamp`): it goes up
145
+ * whenever the mesh's positions, triangles or normals change.
146
+ */
147
+ content_stamp(index: number, generation: number): number;
111
148
  /**
112
149
  * Drops a mesh being added in steps (nothing was added).
113
150
  */
@@ -191,8 +228,9 @@ export class WasmScene {
191
228
  */
192
229
  find_contacts(margin: number, pairs?: Uint32Array | null): Float64Array;
193
230
  /**
194
- * Adds a mesh built in steps, finishing what is left of its BVH, and
195
- * returns `[index, generation]`, as [`WasmScene::add_mesh`] would.
231
+ * Adds a mesh built in steps, finishing what is left of its store,
232
+ * BVH and normals, and returns `[index, generation]`, as
233
+ * [`WasmScene::add_mesh`] would.
196
234
  */
197
235
  finish_add_mesh(build: number): Uint32Array;
198
236
  /**
@@ -223,6 +261,11 @@ export class WasmScene {
223
261
  * point on a xyz, point on b xyz, triangle of a, triangle of b]`.
224
262
  */
225
263
  mesh_distance(a_index: number, a_generation: number, b_index: number, b_generation: number, max_distance: number): Float64Array;
264
+ /**
265
+ * When the mesh's BVH, normals, fields and sections follow its edits:
266
+ * 0 (Eager), 1 (Lazy) or 2 (Manual).
267
+ */
268
+ mode(index: number, generation: number): number;
226
269
  /**
227
270
  * An empty scene with the default history budget.
228
271
  */
@@ -408,11 +451,15 @@ export interface InitOutput {
408
451
  readonly wasmscene_add_distance_field: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
409
452
  readonly wasmscene_add_distance_field_deferred: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
410
453
  readonly wasmscene_add_mesh: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number, number, number];
454
+ readonly wasmscene_add_mesh_buffers: (a: number, b: number) => [number, number, number, number];
455
+ readonly wasmscene_add_mesh_push_indices: (a: number, b: number, c: number, d: number) => [number, number];
456
+ readonly wasmscene_add_mesh_push_positions: (a: number, b: number, c: number, d: number) => [number, number];
411
457
  readonly wasmscene_add_mesh_step: (a: number, b: number, c: number) => [number, number, number];
412
458
  readonly wasmscene_add_section: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
413
459
  readonly wasmscene_analyze: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
414
- readonly wasmscene_begin_add_mesh: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number, number];
460
+ readonly wasmscene_begin_add_mesh_upload: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
415
461
  readonly wasmscene_begin_step: (a: number) => void;
462
+ readonly wasmscene_bounds: (a: number, b: number, c: number) => [number, number, number, number];
416
463
  readonly wasmscene_can_redo: (a: number) => number;
417
464
  readonly wasmscene_can_undo: (a: number) => number;
418
465
  readonly wasmscene_cancel_step: (a: number) => [number, number];
@@ -423,6 +470,7 @@ export interface InitOutput {
423
470
  readonly wasmscene_colors_len: (a: number, b: number, c: number) => [number, number, number];
424
471
  readonly wasmscene_colors_ptr: (a: number, b: number, c: number) => [number, number, number];
425
472
  readonly wasmscene_compact: (a: number, b: number, c: number) => [number, number];
473
+ readonly wasmscene_content_stamp: (a: number, b: number, c: number) => [number, number, number];
426
474
  readonly wasmscene_drop_add_mesh: (a: number, b: number) => void;
427
475
  readonly wasmscene_edit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
428
476
  readonly wasmscene_end_step: (a: number) => [number, number];
@@ -443,6 +491,7 @@ export interface InitOutput {
443
491
  readonly wasmscene_intersects: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
444
492
  readonly wasmscene_matrix4: (a: number, b: number, c: number) => [number, number, number, number];
445
493
  readonly wasmscene_mesh_distance: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
494
+ readonly wasmscene_mode: (a: number, b: number, c: number) => [number, number, number];
446
495
  readonly wasmscene_new: () => number;
447
496
  readonly wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
448
497
  readonly wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];