fast-mesh-wasm 0.3.1 → 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 +5 -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-BpnthBYQ.js → engine-D6MpGb9i.js} +36 -10
  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-BFd6nYRe.js → scene-D6m9XM3O.js} +98 -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 +44 -12
  24. package/dist/wasm/fast_mesh_wasm.js +82 -20
  25. package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
  26. package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +5 -1
  27. package/dist/wasm-threads/fast_mesh_wasm.d.ts +44 -12
  28. package/dist/wasm-threads/fast_mesh_wasm.js +82 -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 +5 -1
  31. package/dist/web.d.ts +2 -2
  32. package/dist/web.js +1 -1
  33. package/dist/worker-engine.d.ts +7 -5
  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
@@ -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,7 +29,8 @@ 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
  /**
@@ -43,9 +44,20 @@ export class WasmScene {
43
44
  */
44
45
  add_mesh_buffers(build: number): Uint32Array;
45
46
  /**
46
- * Builds about `budget` more units of a mesh being added (see
47
- * `MeshBuild::step`); `true` once its BVH is built. A failed build is
48
- * dropped.
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.
49
61
  */
50
62
  add_mesh_step(build: number, budget: number): boolean;
51
63
  /**
@@ -63,16 +75,26 @@ export class WasmScene {
63
75
  */
64
76
  analyze(index: number, generation: number, weld_tolerance: number, self_intersection: boolean, max_listed: number): Float64Array;
65
77
  /**
66
- * [`WasmScene::add_mesh`] in steps: starts building the mesh and its
67
- * BVH outside the scene ([`MeshBuild`]) and returns the build's id, for
68
- * [`WasmScene::add_mesh_step`] and [`WasmScene::finish_add_mesh`]. The
69
- * 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.
70
86
  */
71
- 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;
72
88
  /**
73
89
  * Opens a history step, or one more nesting level of the open one.
74
90
  */
75
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;
76
98
  /**
77
99
  * True if `redo` would redo something.
78
100
  */
@@ -206,8 +228,9 @@ export class WasmScene {
206
228
  */
207
229
  find_contacts(margin: number, pairs?: Uint32Array | null): Float64Array;
208
230
  /**
209
- * Adds a mesh built in steps, finishing what is left of its BVH, and
210
- * 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.
211
234
  */
212
235
  finish_add_mesh(build: number): Uint32Array;
213
236
  /**
@@ -238,6 +261,11 @@ export class WasmScene {
238
261
  * point on a xyz, point on b xyz, triangle of a, triangle of b]`.
239
262
  */
240
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;
241
269
  /**
242
270
  * An empty scene with the default history budget.
243
271
  */
@@ -424,11 +452,14 @@ export interface InitOutput {
424
452
  readonly wasmscene_add_distance_field_deferred: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
425
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];
426
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];
427
457
  readonly wasmscene_add_mesh_step: (a: number, b: number, c: number) => [number, number, number];
428
458
  readonly wasmscene_add_section: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
429
459
  readonly wasmscene_analyze: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
430
- 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];
431
461
  readonly wasmscene_begin_step: (a: number) => void;
462
+ readonly wasmscene_bounds: (a: number, b: number, c: number) => [number, number, number, number];
432
463
  readonly wasmscene_can_redo: (a: number) => number;
433
464
  readonly wasmscene_can_undo: (a: number) => number;
434
465
  readonly wasmscene_cancel_step: (a: number) => [number, number];
@@ -460,6 +491,7 @@ export interface InitOutput {
460
491
  readonly wasmscene_intersects: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
461
492
  readonly wasmscene_matrix4: (a: number, b: number, c: number) => [number, number, number, number];
462
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];
463
495
  readonly wasmscene_new: () => number;
464
496
  readonly wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
465
497
  readonly wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];
@@ -68,7 +68,8 @@ export class WasmScene {
68
68
  * Positions are stored as `p - origin` in `f32`; without `origin` it
69
69
  * is the bounding-box centre. `mode` is 0 (Eager), 1 (Lazy) or 2
70
70
  * (Manual); `normals` turns vertex normals on. The placement starts as
71
- * the identity. Nothing is added on error.
71
+ * the identity. A Lazy or Manual mesh builds its BVH on first use
72
+ * instead of up front. Nothing is added on error.
72
73
  * @param {Float64Array} positions
73
74
  * @param {Uint32Array} indices
74
75
  * @param {Float64Array | null | undefined} origin
@@ -112,9 +113,38 @@ export class WasmScene {
112
113
  return v1;
113
114
  }
114
115
  /**
115
- * Builds about `budget` more units of a mesh being added (see
116
- * `MeshBuild::step`); `true` once its BVH is built. A failed build is
117
- * dropped.
116
+ * Appends a chunk of flat `[a, b, c, ...]` indices to a mesh being
117
+ * added; the chunks must add up to its declared triangles.
118
+ * @param {number} build
119
+ * @param {Uint32Array} chunk
120
+ */
121
+ add_mesh_push_indices(build, chunk) {
122
+ const ptr0 = passArray32ToWasm0(chunk, wasm.__wbindgen_malloc);
123
+ const len0 = WASM_VECTOR_LEN;
124
+ const ret = wasm.wasmscene_add_mesh_push_indices(this.__wbg_ptr, build, ptr0, len0);
125
+ if (ret[1]) {
126
+ throw takeFromExternrefTable0(ret[0]);
127
+ }
128
+ }
129
+ /**
130
+ * Appends a chunk of flat `[x, y, z, ...]` world positions to a mesh
131
+ * being added; the chunks must add up to its declared vertices.
132
+ * @param {number} build
133
+ * @param {Float64Array} chunk
134
+ */
135
+ add_mesh_push_positions(build, chunk) {
136
+ const ptr0 = passArrayF64ToWasm0(chunk, wasm.__wbindgen_malloc);
137
+ const len0 = WASM_VECTOR_LEN;
138
+ const ret = wasm.wasmscene_add_mesh_push_positions(this.__wbg_ptr, build, ptr0, len0);
139
+ if (ret[1]) {
140
+ throw takeFromExternrefTable0(ret[0]);
141
+ }
142
+ }
143
+ /**
144
+ * Builds about `budget` more units of a mesh being added: first its
145
+ * store (vertices or triangles a unit), then its BVH (see
146
+ * `MeshBuild::step`); `true` once its BVH is built. The upload must be
147
+ * complete first. A failed build is dropped.
118
148
  * @param {number} build
119
149
  * @param {number} budget
120
150
  * @returns {boolean}
@@ -169,25 +199,25 @@ export class WasmScene {
169
199
  return v1;
170
200
  }
171
201
  /**
172
- * [`WasmScene::add_mesh`] in steps: starts building the mesh and its
173
- * BVH outside the scene ([`MeshBuild`]) and returns the build's id, for
174
- * [`WasmScene::add_mesh_step`] and [`WasmScene::finish_add_mesh`]. The
175
- * scene is unchanged until the mesh is added.
176
- * @param {Float64Array} positions
177
- * @param {Uint32Array} indices
202
+ * [`WasmScene::add_mesh`] in steps: reserves a mesh of `vertices`
203
+ * vertices and `triangles` triangles outside the scene and returns the
204
+ * build's id. Its inputs upload in chunks
205
+ * ([`WasmScene::add_mesh_push_positions`] and
206
+ * [`WasmScene::add_mesh_push_indices`]), then its store, BVH and
207
+ * normals build in steps ([`WasmScene::add_mesh_step`]), for
208
+ * [`WasmScene::finish_add_mesh`]. The scene is unchanged until the
209
+ * mesh is added.
210
+ * @param {number} vertices
211
+ * @param {number} triangles
178
212
  * @param {Float64Array | null | undefined} origin
179
213
  * @param {number} mode
180
214
  * @param {boolean} normals
181
215
  * @returns {number}
182
216
  */
183
- begin_add_mesh(positions, indices, origin, mode, normals) {
184
- const ptr0 = passArrayF64ToWasm0(positions, wasm.__wbindgen_malloc);
185
- const len0 = WASM_VECTOR_LEN;
186
- const ptr1 = passArray32ToWasm0(indices, wasm.__wbindgen_malloc);
187
- const len1 = WASM_VECTOR_LEN;
188
- var ptr2 = isLikeNone(origin) ? 0 : passArrayF64ToWasm0(origin, wasm.__wbindgen_malloc);
189
- var len2 = WASM_VECTOR_LEN;
190
- const ret = wasm.wasmscene_begin_add_mesh(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, mode, normals);
217
+ begin_add_mesh_upload(vertices, triangles, origin, mode, normals) {
218
+ var ptr0 = isLikeNone(origin) ? 0 : passArrayF64ToWasm0(origin, wasm.__wbindgen_malloc);
219
+ var len0 = WASM_VECTOR_LEN;
220
+ const ret = wasm.wasmscene_begin_add_mesh_upload(this.__wbg_ptr, vertices, triangles, ptr0, len0, mode, normals);
191
221
  if (ret[2]) {
192
222
  throw takeFromExternrefTable0(ret[1]);
193
223
  }
@@ -199,6 +229,23 @@ export class WasmScene {
199
229
  begin_step() {
200
230
  wasm.wasmscene_begin_step(this.__wbg_ptr);
201
231
  }
232
+ /**
233
+ * The box around the vertices the live triangles use, in the mesh's
234
+ * stored local coordinates: `[min xyz, max xyz]`. Empty without live
235
+ * triangles.
236
+ * @param {number} index
237
+ * @param {number} generation
238
+ * @returns {Float64Array}
239
+ */
240
+ bounds(index, generation) {
241
+ const ret = wasm.wasmscene_bounds(this.__wbg_ptr, index, generation);
242
+ if (ret[3]) {
243
+ throw takeFromExternrefTable0(ret[2]);
244
+ }
245
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
246
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
247
+ return v1;
248
+ }
202
249
  /**
203
250
  * True if `redo` would redo something.
204
251
  * @returns {boolean}
@@ -536,8 +583,9 @@ export class WasmScene {
536
583
  return v2;
537
584
  }
538
585
  /**
539
- * Adds a mesh built in steps, finishing what is left of its BVH, and
540
- * returns `[index, generation]`, as [`WasmScene::add_mesh`] would.
586
+ * Adds a mesh built in steps, finishing what is left of its store,
587
+ * BVH and normals, and returns `[index, generation]`, as
588
+ * [`WasmScene::add_mesh`] would.
541
589
  * @param {number} build
542
590
  * @returns {Uint32Array}
543
591
  */
@@ -637,6 +685,20 @@ export class WasmScene {
637
685
  wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
638
686
  return v1;
639
687
  }
688
+ /**
689
+ * When the mesh's BVH, normals, fields and sections follow its edits:
690
+ * 0 (Eager), 1 (Lazy) or 2 (Manual).
691
+ * @param {number} index
692
+ * @param {number} generation
693
+ * @returns {number}
694
+ */
695
+ mode(index, generation) {
696
+ const ret = wasm.wasmscene_mode(this.__wbg_ptr, index, generation);
697
+ if (ret[2]) {
698
+ throw takeFromExternrefTable0(ret[1]);
699
+ }
700
+ return ret[0];
701
+ }
640
702
  /**
641
703
  * An empty scene with the default history budget.
642
704
  */
Binary file
@@ -9,11 +9,14 @@ export const wasmscene_add_distance_field: (a: number, b: number, c: number, d:
9
9
  export const wasmscene_add_distance_field_deferred: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
10
10
  export const 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];
11
11
  export const wasmscene_add_mesh_buffers: (a: number, b: number) => [number, number, number, number];
12
+ export const wasmscene_add_mesh_push_indices: (a: number, b: number, c: number, d: number) => [number, number];
13
+ export const wasmscene_add_mesh_push_positions: (a: number, b: number, c: number, d: number) => [number, number];
12
14
  export const wasmscene_add_mesh_step: (a: number, b: number, c: number) => [number, number, number];
13
15
  export const wasmscene_add_section: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
14
16
  export const wasmscene_analyze: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
15
- export const 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];
17
+ export const wasmscene_begin_add_mesh_upload: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
16
18
  export const wasmscene_begin_step: (a: number) => void;
19
+ export const wasmscene_bounds: (a: number, b: number, c: number) => [number, number, number, number];
17
20
  export const wasmscene_can_redo: (a: number) => number;
18
21
  export const wasmscene_can_undo: (a: number) => number;
19
22
  export const wasmscene_cancel_step: (a: number) => [number, number];
@@ -45,6 +48,7 @@ export const wasmscene_indices_ptr: (a: number, b: number, c: number) => [number
45
48
  export const wasmscene_intersects: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
46
49
  export const wasmscene_matrix4: (a: number, b: number, c: number) => [number, number, number, number];
47
50
  export const wasmscene_mesh_distance: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
51
+ export const wasmscene_mode: (a: number, b: number, c: number) => [number, number, number];
48
52
  export const wasmscene_new: () => number;
49
53
  export const wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
50
54
  export const wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];
@@ -29,7 +29,8 @@ 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
  /**
@@ -43,9 +44,20 @@ export class WasmScene {
43
44
  */
44
45
  add_mesh_buffers(build: number): Uint32Array;
45
46
  /**
46
- * Builds about `budget` more units of a mesh being added (see
47
- * `MeshBuild::step`); `true` once its BVH is built. A failed build is
48
- * dropped.
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.
49
61
  */
50
62
  add_mesh_step(build: number, budget: number): boolean;
51
63
  /**
@@ -63,16 +75,26 @@ export class WasmScene {
63
75
  */
64
76
  analyze(index: number, generation: number, weld_tolerance: number, self_intersection: boolean, max_listed: number): Float64Array;
65
77
  /**
66
- * [`WasmScene::add_mesh`] in steps: starts building the mesh and its
67
- * BVH outside the scene ([`MeshBuild`]) and returns the build's id, for
68
- * [`WasmScene::add_mesh_step`] and [`WasmScene::finish_add_mesh`]. The
69
- * 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.
70
86
  */
71
- 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;
72
88
  /**
73
89
  * Opens a history step, or one more nesting level of the open one.
74
90
  */
75
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;
76
98
  /**
77
99
  * True if `redo` would redo something.
78
100
  */
@@ -206,8 +228,9 @@ export class WasmScene {
206
228
  */
207
229
  find_contacts(margin: number, pairs?: Uint32Array | null): Float64Array;
208
230
  /**
209
- * Adds a mesh built in steps, finishing what is left of its BVH, and
210
- * 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.
211
234
  */
212
235
  finish_add_mesh(build: number): Uint32Array;
213
236
  /**
@@ -238,6 +261,11 @@ export class WasmScene {
238
261
  * point on a xyz, point on b xyz, triangle of a, triangle of b]`.
239
262
  */
240
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;
241
269
  /**
242
270
  * An empty scene with the default history budget.
243
271
  */
@@ -447,11 +475,14 @@ export interface InitOutput {
447
475
  readonly wasmscene_add_distance_field_deferred: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
448
476
  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];
449
477
  readonly wasmscene_add_mesh_buffers: (a: number, b: number) => [number, number, number, number];
478
+ readonly wasmscene_add_mesh_push_indices: (a: number, b: number, c: number, d: number) => [number, number];
479
+ readonly wasmscene_add_mesh_push_positions: (a: number, b: number, c: number, d: number) => [number, number];
450
480
  readonly wasmscene_add_mesh_step: (a: number, b: number, c: number) => [number, number, number];
451
481
  readonly wasmscene_add_section: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
452
482
  readonly wasmscene_analyze: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
453
- 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];
483
+ readonly wasmscene_begin_add_mesh_upload: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
454
484
  readonly wasmscene_begin_step: (a: number) => void;
485
+ readonly wasmscene_bounds: (a: number, b: number, c: number) => [number, number, number, number];
455
486
  readonly wasmscene_can_redo: (a: number) => number;
456
487
  readonly wasmscene_can_undo: (a: number) => number;
457
488
  readonly wasmscene_cancel_step: (a: number) => [number, number];
@@ -483,6 +514,7 @@ export interface InitOutput {
483
514
  readonly wasmscene_intersects: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
484
515
  readonly wasmscene_matrix4: (a: number, b: number, c: number) => [number, number, number, number];
485
516
  readonly wasmscene_mesh_distance: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
517
+ readonly wasmscene_mode: (a: number, b: number, c: number) => [number, number, number];
486
518
  readonly wasmscene_new: () => number;
487
519
  readonly wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
488
520
  readonly wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];