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
@@ -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
@@ -92,9 +93,58 @@ export class WasmScene {
92
93
  return v4;
93
94
  }
94
95
  /**
95
- * Builds about `budget` more units of a mesh being added (see
96
- * `MeshBuild::step`); `true` once its BVH is built. A failed build is
97
- * dropped.
96
+ * The render buffers of a mesh being added in steps, as
97
+ * `[positions_ptr, positions_len, normals_ptr, normals_len,
98
+ * indices_ptr, indices_len]` (as the `*_ptr` / `*_len` methods give
99
+ * them once it is added; normals 0, 0 until built or when off). The
100
+ * added mesh keeps these addresses and contents until it changes, so
101
+ * they can be copied out before it lands. Valid until the next call
102
+ * that may allocate.
103
+ * @param {number} build
104
+ * @returns {Uint32Array}
105
+ */
106
+ add_mesh_buffers(build) {
107
+ const ret = wasm.wasmscene_add_mesh_buffers(this.__wbg_ptr, build);
108
+ if (ret[3]) {
109
+ throw takeFromExternrefTable0(ret[2]);
110
+ }
111
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
112
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
113
+ return v1;
114
+ }
115
+ /**
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.
98
148
  * @param {number} build
99
149
  * @param {number} budget
100
150
  * @returns {boolean}
@@ -149,25 +199,25 @@ export class WasmScene {
149
199
  return v1;
150
200
  }
151
201
  /**
152
- * [`WasmScene::add_mesh`] in steps: starts building the mesh and its
153
- * BVH outside the scene ([`MeshBuild`]) and returns the build's id, for
154
- * [`WasmScene::add_mesh_step`] and [`WasmScene::finish_add_mesh`]. The
155
- * scene is unchanged until the mesh is added.
156
- * @param {Float64Array} positions
157
- * @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
158
212
  * @param {Float64Array | null | undefined} origin
159
213
  * @param {number} mode
160
214
  * @param {boolean} normals
161
215
  * @returns {number}
162
216
  */
163
- begin_add_mesh(positions, indices, origin, mode, normals) {
164
- const ptr0 = passArrayF64ToWasm0(positions, wasm.__wbindgen_malloc);
165
- const len0 = WASM_VECTOR_LEN;
166
- const ptr1 = passArray32ToWasm0(indices, wasm.__wbindgen_malloc);
167
- const len1 = WASM_VECTOR_LEN;
168
- var ptr2 = isLikeNone(origin) ? 0 : passArrayF64ToWasm0(origin, wasm.__wbindgen_malloc);
169
- var len2 = WASM_VECTOR_LEN;
170
- 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);
171
221
  if (ret[2]) {
172
222
  throw takeFromExternrefTable0(ret[1]);
173
223
  }
@@ -179,6 +229,23 @@ export class WasmScene {
179
229
  begin_step() {
180
230
  wasm.wasmscene_begin_step(this.__wbg_ptr);
181
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
+ }
182
249
  /**
183
250
  * True if `redo` would redo something.
184
251
  * @returns {boolean}
@@ -302,6 +369,20 @@ export class WasmScene {
302
369
  throw takeFromExternrefTable0(ret[0]);
303
370
  }
304
371
  }
372
+ /**
373
+ * The mesh's content stamp (`Scene::content_stamp`): it goes up
374
+ * whenever the mesh's positions, triangles or normals change.
375
+ * @param {number} index
376
+ * @param {number} generation
377
+ * @returns {number}
378
+ */
379
+ content_stamp(index, generation) {
380
+ const ret = wasm.wasmscene_content_stamp(this.__wbg_ptr, index, generation);
381
+ if (ret[2]) {
382
+ throw takeFromExternrefTable0(ret[1]);
383
+ }
384
+ return ret[0];
385
+ }
305
386
  /**
306
387
  * Drops a mesh being added in steps (nothing was added).
307
388
  * @param {number} build
@@ -502,8 +583,9 @@ export class WasmScene {
502
583
  return v2;
503
584
  }
504
585
  /**
505
- * Adds a mesh built in steps, finishing what is left of its BVH, and
506
- * 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.
507
589
  * @param {number} build
508
590
  * @returns {Uint32Array}
509
591
  */
@@ -603,6 +685,20 @@ export class WasmScene {
603
685
  wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
604
686
  return v1;
605
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
+ }
606
702
  /**
607
703
  * An empty scene with the default history budget.
608
704
  */
Binary file
@@ -8,11 +8,15 @@ export const wasmscene_abandon_field_step: (a: number) => void;
8
8
  export const wasmscene_add_distance_field: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
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
+ 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];
11
14
  export const wasmscene_add_mesh_step: (a: number, b: number, c: number) => [number, number, number];
12
15
  export const wasmscene_add_section: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
13
16
  export const wasmscene_analyze: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
14
- 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];
15
18
  export const wasmscene_begin_step: (a: number) => void;
19
+ export const wasmscene_bounds: (a: number, b: number, c: number) => [number, number, number, number];
16
20
  export const wasmscene_can_redo: (a: number) => number;
17
21
  export const wasmscene_can_undo: (a: number) => number;
18
22
  export const wasmscene_cancel_step: (a: number) => [number, number];
@@ -23,6 +27,7 @@ export const wasmscene_closest_point_on: (a: number, b: number, c: number, d: nu
23
27
  export const wasmscene_colors_len: (a: number, b: number, c: number) => [number, number, number];
24
28
  export const wasmscene_colors_ptr: (a: number, b: number, c: number) => [number, number, number];
25
29
  export const wasmscene_compact: (a: number, b: number, c: number) => [number, number];
30
+ export const wasmscene_content_stamp: (a: number, b: number, c: number) => [number, number, number];
26
31
  export const wasmscene_drop_add_mesh: (a: number, b: number) => void;
27
32
  export const wasmscene_edit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
28
33
  export const wasmscene_end_step: (a: number) => [number, number];
@@ -43,6 +48,7 @@ export const wasmscene_indices_ptr: (a: number, b: number, c: number) => [number
43
48
  export const wasmscene_intersects: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
44
49
  export const wasmscene_matrix4: (a: number, b: number, c: number) => [number, number, number, number];
45
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];
46
52
  export const wasmscene_new: () => number;
47
53
  export const wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
48
54
  export const wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];
@@ -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
  */
@@ -431,11 +474,15 @@ export interface InitOutput {
431
474
  readonly wasmscene_add_distance_field: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
432
475
  readonly wasmscene_add_distance_field_deferred: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
433
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];
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];
434
480
  readonly wasmscene_add_mesh_step: (a: number, b: number, c: number) => [number, number, number];
435
481
  readonly wasmscene_add_section: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
436
482
  readonly wasmscene_analyze: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
437
- 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];
438
484
  readonly wasmscene_begin_step: (a: number) => void;
485
+ readonly wasmscene_bounds: (a: number, b: number, c: number) => [number, number, number, number];
439
486
  readonly wasmscene_can_redo: (a: number) => number;
440
487
  readonly wasmscene_can_undo: (a: number) => number;
441
488
  readonly wasmscene_cancel_step: (a: number) => [number, number];
@@ -446,6 +493,7 @@ export interface InitOutput {
446
493
  readonly wasmscene_colors_len: (a: number, b: number, c: number) => [number, number, number];
447
494
  readonly wasmscene_colors_ptr: (a: number, b: number, c: number) => [number, number, number];
448
495
  readonly wasmscene_compact: (a: number, b: number, c: number) => [number, number];
496
+ readonly wasmscene_content_stamp: (a: number, b: number, c: number) => [number, number, number];
449
497
  readonly wasmscene_drop_add_mesh: (a: number, b: number) => void;
450
498
  readonly wasmscene_edit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
451
499
  readonly wasmscene_end_step: (a: number) => [number, number];
@@ -466,6 +514,7 @@ export interface InitOutput {
466
514
  readonly wasmscene_intersects: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
467
515
  readonly wasmscene_matrix4: (a: number, b: number, c: number) => [number, number, number, number];
468
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];
469
518
  readonly wasmscene_new: () => number;
470
519
  readonly wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
471
520
  readonly wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];
@@ -71,7 +71,8 @@ export class WasmScene {
71
71
  * Positions are stored as `p - origin` in `f32`; without `origin` it
72
72
  * is the bounding-box centre. `mode` is 0 (Eager), 1 (Lazy) or 2
73
73
  * (Manual); `normals` turns vertex normals on. The placement starts as
74
- * the identity. Nothing is added on error.
74
+ * the identity. A Lazy or Manual mesh builds its BVH on first use
75
+ * instead of up front. Nothing is added on error.
75
76
  * @param {Float64Array} positions
76
77
  * @param {Uint32Array} indices
77
78
  * @param {Float64Array | null | undefined} origin
@@ -95,9 +96,58 @@ export class WasmScene {
95
96
  return v4;
96
97
  }
97
98
  /**
98
- * Builds about `budget` more units of a mesh being added (see
99
- * `MeshBuild::step`); `true` once its BVH is built. A failed build is
100
- * dropped.
99
+ * The render buffers of a mesh being added in steps, as
100
+ * `[positions_ptr, positions_len, normals_ptr, normals_len,
101
+ * indices_ptr, indices_len]` (as the `*_ptr` / `*_len` methods give
102
+ * them once it is added; normals 0, 0 until built or when off). The
103
+ * added mesh keeps these addresses and contents until it changes, so
104
+ * they can be copied out before it lands. Valid until the next call
105
+ * that may allocate.
106
+ * @param {number} build
107
+ * @returns {Uint32Array}
108
+ */
109
+ add_mesh_buffers(build) {
110
+ const ret = wasm.wasmscene_add_mesh_buffers(this.__wbg_ptr, build);
111
+ if (ret[3]) {
112
+ throw takeFromExternrefTable0(ret[2]);
113
+ }
114
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
115
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
116
+ return v1;
117
+ }
118
+ /**
119
+ * Appends a chunk of flat `[a, b, c, ...]` indices to a mesh being
120
+ * added; the chunks must add up to its declared triangles.
121
+ * @param {number} build
122
+ * @param {Uint32Array} chunk
123
+ */
124
+ add_mesh_push_indices(build, chunk) {
125
+ const ptr0 = passArray32ToWasm0(chunk, wasm.__wbindgen_malloc);
126
+ const len0 = WASM_VECTOR_LEN;
127
+ const ret = wasm.wasmscene_add_mesh_push_indices(this.__wbg_ptr, build, ptr0, len0);
128
+ if (ret[1]) {
129
+ throw takeFromExternrefTable0(ret[0]);
130
+ }
131
+ }
132
+ /**
133
+ * Appends a chunk of flat `[x, y, z, ...]` world positions to a mesh
134
+ * being added; the chunks must add up to its declared vertices.
135
+ * @param {number} build
136
+ * @param {Float64Array} chunk
137
+ */
138
+ add_mesh_push_positions(build, chunk) {
139
+ const ptr0 = passArrayF64ToWasm0(chunk, wasm.__wbindgen_malloc);
140
+ const len0 = WASM_VECTOR_LEN;
141
+ const ret = wasm.wasmscene_add_mesh_push_positions(this.__wbg_ptr, build, ptr0, len0);
142
+ if (ret[1]) {
143
+ throw takeFromExternrefTable0(ret[0]);
144
+ }
145
+ }
146
+ /**
147
+ * Builds about `budget` more units of a mesh being added: first its
148
+ * store (vertices or triangles a unit), then its BVH (see
149
+ * `MeshBuild::step`); `true` once its BVH is built. The upload must be
150
+ * complete first. A failed build is dropped.
101
151
  * @param {number} build
102
152
  * @param {number} budget
103
153
  * @returns {boolean}
@@ -152,25 +202,25 @@ export class WasmScene {
152
202
  return v1;
153
203
  }
154
204
  /**
155
- * [`WasmScene::add_mesh`] in steps: starts building the mesh and its
156
- * BVH outside the scene ([`MeshBuild`]) and returns the build's id, for
157
- * [`WasmScene::add_mesh_step`] and [`WasmScene::finish_add_mesh`]. The
158
- * scene is unchanged until the mesh is added.
159
- * @param {Float64Array} positions
160
- * @param {Uint32Array} indices
205
+ * [`WasmScene::add_mesh`] in steps: reserves a mesh of `vertices`
206
+ * vertices and `triangles` triangles outside the scene and returns the
207
+ * build's id. Its inputs upload in chunks
208
+ * ([`WasmScene::add_mesh_push_positions`] and
209
+ * [`WasmScene::add_mesh_push_indices`]), then its store, BVH and
210
+ * normals build in steps ([`WasmScene::add_mesh_step`]), for
211
+ * [`WasmScene::finish_add_mesh`]. The scene is unchanged until the
212
+ * mesh is added.
213
+ * @param {number} vertices
214
+ * @param {number} triangles
161
215
  * @param {Float64Array | null | undefined} origin
162
216
  * @param {number} mode
163
217
  * @param {boolean} normals
164
218
  * @returns {number}
165
219
  */
166
- begin_add_mesh(positions, indices, origin, mode, normals) {
167
- const ptr0 = passArrayF64ToWasm0(positions, wasm.__wbindgen_malloc);
168
- const len0 = WASM_VECTOR_LEN;
169
- const ptr1 = passArray32ToWasm0(indices, wasm.__wbindgen_malloc);
170
- const len1 = WASM_VECTOR_LEN;
171
- var ptr2 = isLikeNone(origin) ? 0 : passArrayF64ToWasm0(origin, wasm.__wbindgen_malloc);
172
- var len2 = WASM_VECTOR_LEN;
173
- const ret = wasm.wasmscene_begin_add_mesh(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, mode, normals);
220
+ begin_add_mesh_upload(vertices, triangles, origin, mode, normals) {
221
+ var ptr0 = isLikeNone(origin) ? 0 : passArrayF64ToWasm0(origin, wasm.__wbindgen_malloc);
222
+ var len0 = WASM_VECTOR_LEN;
223
+ const ret = wasm.wasmscene_begin_add_mesh_upload(this.__wbg_ptr, vertices, triangles, ptr0, len0, mode, normals);
174
224
  if (ret[2]) {
175
225
  throw takeFromExternrefTable0(ret[1]);
176
226
  }
@@ -182,6 +232,23 @@ export class WasmScene {
182
232
  begin_step() {
183
233
  wasm.wasmscene_begin_step(this.__wbg_ptr);
184
234
  }
235
+ /**
236
+ * The box around the vertices the live triangles use, in the mesh's
237
+ * stored local coordinates: `[min xyz, max xyz]`. Empty without live
238
+ * triangles.
239
+ * @param {number} index
240
+ * @param {number} generation
241
+ * @returns {Float64Array}
242
+ */
243
+ bounds(index, generation) {
244
+ const ret = wasm.wasmscene_bounds(this.__wbg_ptr, index, generation);
245
+ if (ret[3]) {
246
+ throw takeFromExternrefTable0(ret[2]);
247
+ }
248
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
249
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
250
+ return v1;
251
+ }
185
252
  /**
186
253
  * True if `redo` would redo something.
187
254
  * @returns {boolean}
@@ -305,6 +372,20 @@ export class WasmScene {
305
372
  throw takeFromExternrefTable0(ret[0]);
306
373
  }
307
374
  }
375
+ /**
376
+ * The mesh's content stamp (`Scene::content_stamp`): it goes up
377
+ * whenever the mesh's positions, triangles or normals change.
378
+ * @param {number} index
379
+ * @param {number} generation
380
+ * @returns {number}
381
+ */
382
+ content_stamp(index, generation) {
383
+ const ret = wasm.wasmscene_content_stamp(this.__wbg_ptr, index, generation);
384
+ if (ret[2]) {
385
+ throw takeFromExternrefTable0(ret[1]);
386
+ }
387
+ return ret[0];
388
+ }
308
389
  /**
309
390
  * Drops a mesh being added in steps (nothing was added).
310
391
  * @param {number} build
@@ -505,8 +586,9 @@ export class WasmScene {
505
586
  return v2;
506
587
  }
507
588
  /**
508
- * Adds a mesh built in steps, finishing what is left of its BVH, and
509
- * returns `[index, generation]`, as [`WasmScene::add_mesh`] would.
589
+ * Adds a mesh built in steps, finishing what is left of its store,
590
+ * BVH and normals, and returns `[index, generation]`, as
591
+ * [`WasmScene::add_mesh`] would.
510
592
  * @param {number} build
511
593
  * @returns {Uint32Array}
512
594
  */
@@ -606,6 +688,20 @@ export class WasmScene {
606
688
  wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
607
689
  return v1;
608
690
  }
691
+ /**
692
+ * When the mesh's BVH, normals, fields and sections follow its edits:
693
+ * 0 (Eager), 1 (Lazy) or 2 (Manual).
694
+ * @param {number} index
695
+ * @param {number} generation
696
+ * @returns {number}
697
+ */
698
+ mode(index, generation) {
699
+ const ret = wasm.wasmscene_mode(this.__wbg_ptr, index, generation);
700
+ if (ret[2]) {
701
+ throw takeFromExternrefTable0(ret[1]);
702
+ }
703
+ return ret[0];
704
+ }
609
705
  /**
610
706
  * An empty scene with the default history budget.
611
707
  */
@@ -9,11 +9,15 @@ export const wasmscene_abandon_field_step: (a: number) => void;
9
9
  export const wasmscene_add_distance_field: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
10
10
  export const wasmscene_add_distance_field_deferred: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
11
11
  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];
12
+ export const wasmscene_add_mesh_buffers: (a: number, b: number) => [number, number, number, number];
13
+ export const wasmscene_add_mesh_push_indices: (a: number, b: number, c: number, d: number) => [number, number];
14
+ export const wasmscene_add_mesh_push_positions: (a: number, b: number, c: number, d: number) => [number, number];
12
15
  export const wasmscene_add_mesh_step: (a: number, b: number, c: number) => [number, number, number];
13
16
  export const wasmscene_add_section: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
14
17
  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];
18
+ 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
19
  export const wasmscene_begin_step: (a: number) => void;
20
+ export const wasmscene_bounds: (a: number, b: number, c: number) => [number, number, number, number];
17
21
  export const wasmscene_can_redo: (a: number) => number;
18
22
  export const wasmscene_can_undo: (a: number) => number;
19
23
  export const wasmscene_cancel_step: (a: number) => [number, number];
@@ -24,6 +28,7 @@ export const wasmscene_closest_point_on: (a: number, b: number, c: number, d: nu
24
28
  export const wasmscene_colors_len: (a: number, b: number, c: number) => [number, number, number];
25
29
  export const wasmscene_colors_ptr: (a: number, b: number, c: number) => [number, number, number];
26
30
  export const wasmscene_compact: (a: number, b: number, c: number) => [number, number];
31
+ export const wasmscene_content_stamp: (a: number, b: number, c: number) => [number, number, number];
27
32
  export const wasmscene_drop_add_mesh: (a: number, b: number) => void;
28
33
  export const wasmscene_edit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
29
34
  export const wasmscene_end_step: (a: number) => [number, number];
@@ -44,6 +49,7 @@ export const wasmscene_indices_ptr: (a: number, b: number, c: number) => [number
44
49
  export const wasmscene_intersects: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
45
50
  export const wasmscene_matrix4: (a: number, b: number, c: number) => [number, number, number, number];
46
51
  export const wasmscene_mesh_distance: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
52
+ export const wasmscene_mode: (a: number, b: number, c: number) => [number, number, number];
47
53
  export const wasmscene_new: () => number;
48
54
  export const wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
49
55
  export const wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];
package/dist/web.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as PlacementInput, A as RepairOp, B as SectionResult, C as MeshComponent, D as RayHit, E as OutOfRange, F as SceneOptions, G as SectionHandle, H as WeldReport, I as SectionContour, J as Bounds, K as Range, L as SectionDesc, M as RepairReportOf, N as Rgba, O as RaycastOptions, P as Scene, Q as Placement, R as SectionGap, S as MeshChange, T as OrientReport, U as FieldHandle, V as SignMode, W as MeshHandle, X as InitInput, Y as Indices, Z as Mat3, _ as FieldStatus, a as BoundaryLoop, at as computeBounds, b as FindContactsOptions, c as ColorRule, d as DegenerateReport, et as Positions, f as DistanceFieldDesc, g as EditResult, h as EditRef, i as AnalyzeOptions, it as Vec3, j as RepairReport, k as RemoveReport, l as Colormap, m as EditOp, n as AddMeshOptions, nt as Quat, o as ClosestHit, ot as computeVertexNormals, p as DragSession, q as MeshViews, r as Analysis, rt as UpdateMode, s as ClosestPointOptions, t as SceneLike, tt as Positions64, u as Contact, v as FillReport, w as MeshDistance, x as LoopId, y as FilledLoop, z as SectionPlane } from "./scene-like-B_3qm0u6.js";
1
+ import { $ as Placement, A as RemoveReport, B as SectionPlane, C as MeshChange, D as OutOfRange, E as OrientReport, F as Scene, G as MeshHandle, H as SignMode, I as SceneOptions, J as MeshViews, K as SectionHandle, L as SectionContour, M as RepairReport, N as RepairReportOf, O as RayHit, P as Rgba, Q as Mat3, R as SectionDesc, S as LoopId, T as MeshDistance, U as WeldReport, V as SectionResult, W as FieldHandle, X as Indices, Y as Bounds, Z as InitInput, _ as EditResult, a as BoundaryLoop, at as Vec3, b as FilledLoop, c as ColorRule, d as DegenerateReport, et as PlacementInput, f as DistanceFieldDesc, g as EditRef, h as EditOp, i as AnalyzeOptions, it as UpdateMode, j as RepairOp, k as RaycastOptions, l as Colormap, m as DragSession, n as AddMeshOptions, nt as Positions64, o as ClosestHit, ot as computeBounds, p as DragOptions, q as Range, r as Analysis, rt as Quat, s as ClosestPointOptions, st as computeVertexNormals, t as SceneLike, tt as Positions, u as Contact, v as FieldStatus, w as MeshComponent, x as FindContactsOptions, y as FillReport, z as SectionGap } from "./scene-like-DJKQP5uf.js";
2
2
  import { n as FastMeshErrorCode, t as FastMeshError } from "./core-D2X9GPfK.js";
3
3
  //#region src/web.d.ts
4
4
  /**
@@ -10,4 +10,4 @@ import { n as FastMeshErrorCode, t as FastMeshError } from "./core-D2X9GPfK.js";
10
10
  */
11
11
  export declare function init(input?: InitInput | Promise<InitInput>): Promise<void>;
12
12
  //#endregion
13
- export { type AddMeshOptions, type Analysis, type AnalyzeOptions, type BoundaryLoop, type Bounds, type ClosestHit, type ClosestPointOptions, type ColorRule, type Colormap, type Contact, type DegenerateReport, type DistanceFieldDesc, type DragSession, type EditOp, type EditRef, type EditResult, FastMeshError, type FastMeshErrorCode, type FieldHandle, type FieldStatus, type FillReport, type FilledLoop, type FindContactsOptions, type Indices, type InitInput, type LoopId, type Mat3, type MeshChange, type MeshComponent, type MeshDistance, type MeshHandle, type MeshViews, type OrientReport, type OutOfRange, type Placement, type PlacementInput, type Positions, type Positions64, type Quat, type Range, type RayHit, type RaycastOptions, type RemoveReport, type RepairOp, type RepairReport, type RepairReportOf, type Rgba, Scene, type SceneLike, type SceneOptions, type SectionContour, type SectionDesc, type SectionGap, type SectionHandle, type SectionPlane, type SectionResult, type SignMode, type UpdateMode, type Vec3, type WeldReport, computeBounds, computeVertexNormals };
13
+ export { type AddMeshOptions, type Analysis, type AnalyzeOptions, type BoundaryLoop, type Bounds, type ClosestHit, type ClosestPointOptions, type ColorRule, type Colormap, type Contact, type DegenerateReport, type DistanceFieldDesc, type DragOptions, type DragSession, type EditOp, type EditRef, type EditResult, FastMeshError, type FastMeshErrorCode, type FieldHandle, type FieldStatus, type FillReport, type FilledLoop, type FindContactsOptions, type Indices, type InitInput, type LoopId, type Mat3, type MeshChange, type MeshComponent, type MeshDistance, type MeshHandle, type MeshViews, type OrientReport, type OutOfRange, type Placement, type PlacementInput, type Positions, type Positions64, type Quat, type Range, type RayHit, type RaycastOptions, type RemoveReport, type RepairOp, type RepairReport, type RepairReportOf, type Rgba, Scene, type SceneLike, type SceneOptions, type SectionContour, type SectionDesc, type SectionGap, type SectionHandle, type SectionPlane, type SectionResult, type SignMode, type UpdateMode, type Vec3, type WeldReport, computeBounds, computeVertexNormals };
package/dist/web.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as FastMeshError } from "./core-Cke_kZ2e.js";
2
2
  import { n as computeVertexNormals, r as markInitialized, t as computeBounds } from "./api-BUy7FRx7.js";
3
- import { t as Scene } from "./scene-BG3EEyfw.js";
3
+ import { t as Scene } from "./scene-D6m9XM3O.js";
4
4
  import wasmInit from "./wasm/fast_mesh_wasm.js";
5
5
  //#region src/web.ts
6
6
  let ready;