fast-mesh-wasm 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +493 -23
- package/dist/api-BUy7FRx7.js +64 -0
- package/dist/client-Bp9FRd70.js +2278 -0
- package/dist/client-m2zSdFlu.d.ts +305 -0
- package/dist/colormap-D_xH5hI5.js +303 -0
- package/dist/core-Cke_kZ2e.js +113 -0
- package/dist/core-D2X9GPfK.d.ts +15 -0
- package/dist/engine-B-ZEzR1c.js +1818 -0
- package/dist/mesh-B16gV3oX.d.ts +130 -0
- package/dist/mesh-B8pae8WA.js +428 -0
- package/dist/node.d.ts +6 -4
- package/dist/node.js +9 -5
- package/dist/protocol-CAUYm1gd.js +68 -0
- package/dist/protocol-W9R-iGl5.d.ts +293 -0
- package/dist/r3f.d.ts +59 -0
- package/dist/r3f.js +165 -0
- package/dist/react-CTADh3NN.js +124 -0
- package/dist/react.d.ts +65 -0
- package/dist/react.js +1 -0
- package/dist/scene-BG3EEyfw.js +1243 -0
- package/dist/scene-like-B_3qm0u6.d.ts +925 -0
- package/dist/snapshot-Cf6NgDl7.js +104 -0
- package/dist/store-D3ErV6o-.js +1379 -0
- package/dist/store-DNnHN33A.d.ts +285 -0
- package/dist/store.d.ts +61 -0
- package/dist/store.js +105 -0
- package/dist/three.d.ts +118 -0
- package/dist/three.js +390 -0
- package/dist/views-BaZqBxlX.js +189 -0
- package/dist/wasm/fast_mesh_wasm.d.ts +450 -31
- package/dist/wasm/fast_mesh_wasm.js +1122 -49
- package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +76 -7
- package/dist/wasm-threads/fast_mesh_wasm.d.ts +540 -0
- package/dist/wasm-threads/fast_mesh_wasm.js +1513 -0
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +93 -0
- package/dist/wasm-threads/package.json +7 -0
- package/dist/wasm-threads/snippets/fast-mesh-wasm-ae14781a92c2789e/inline0.js +16 -0
- package/dist/wasm-threads/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.js +107 -0
- package/dist/web.d.ts +3 -2
- package/dist/web.js +6 -3
- package/dist/worker-engine.d.ts +248 -0
- package/dist/worker-engine.js +1 -0
- package/dist/worker-entry.d.ts +1 -0
- package/dist/worker-entry.js +11 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +1 -0
- package/package.json +55 -4
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const __wbg_wasmscene_free: (a: number, b: number) => void;
|
|
4
|
+
export const __wbg_wbg_rayon_poolbuilder_free: (a: number, b: number) => void;
|
|
5
|
+
export const computeBounds: (a: number, b: number) => [number, number, number, number];
|
|
6
|
+
export const computeVertexNormals: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
7
|
+
export const initThreadPool: (a: number) => any;
|
|
8
|
+
export const wasmscene_abandon_field_step: (a: number) => void;
|
|
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
|
+
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
|
+
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_step: (a: number, b: number, c: number) => [number, number, number];
|
|
13
|
+
export const wasmscene_add_section: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
14
|
+
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];
|
|
16
|
+
export const wasmscene_begin_step: (a: number) => void;
|
|
17
|
+
export const wasmscene_can_redo: (a: number) => number;
|
|
18
|
+
export const wasmscene_can_undo: (a: number) => number;
|
|
19
|
+
export const wasmscene_cancel_step: (a: number) => [number, number];
|
|
20
|
+
export const wasmscene_clear_coloring: (a: number, b: number, c: number) => [number, number];
|
|
21
|
+
export const wasmscene_clear_history: (a: number) => [number, number];
|
|
22
|
+
export const wasmscene_closest_point: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
23
|
+
export const wasmscene_closest_point_on: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
24
|
+
export const wasmscene_colors_len: (a: number, b: number, c: number) => [number, number, number];
|
|
25
|
+
export const wasmscene_colors_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
26
|
+
export const wasmscene_compact: (a: number, b: number, c: number) => [number, number];
|
|
27
|
+
export const wasmscene_drop_add_mesh: (a: number, b: number) => void;
|
|
28
|
+
export const wasmscene_edit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
29
|
+
export const wasmscene_end_step: (a: number) => [number, number];
|
|
30
|
+
export const wasmscene_field_nearest: (a: number, b: number) => [number, number, number, number];
|
|
31
|
+
export const wasmscene_field_status: (a: number, b: number) => [number, number, number, number];
|
|
32
|
+
export const wasmscene_field_step: (a: number, b: number) => [number, number, number];
|
|
33
|
+
export const wasmscene_field_step_field: (a: number, b: number, c: number) => [number, number, number];
|
|
34
|
+
export const wasmscene_field_step_meshes: (a: number) => [number, number];
|
|
35
|
+
export const wasmscene_field_target_status: (a: number, b: number) => [number, number, number, number];
|
|
36
|
+
export const wasmscene_field_targets: (a: number, b: number) => [number, number, number, number];
|
|
37
|
+
export const wasmscene_field_values_len: (a: number, b: number) => [number, number, number];
|
|
38
|
+
export const wasmscene_field_values_ptr: (a: number, b: number) => [number, number, number];
|
|
39
|
+
export const wasmscene_find_contacts: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
40
|
+
export const wasmscene_finish_add_mesh: (a: number, b: number) => [number, number, number, number];
|
|
41
|
+
export const wasmscene_flush: (a: number) => [number, number];
|
|
42
|
+
export const wasmscene_indices_len: (a: number, b: number, c: number) => [number, number, number];
|
|
43
|
+
export const wasmscene_indices_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
44
|
+
export const wasmscene_intersects: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
45
|
+
export const wasmscene_matrix4: (a: number, b: number, c: number) => [number, number, number, number];
|
|
46
|
+
export const wasmscene_mesh_distance: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
47
|
+
export const wasmscene_new: () => number;
|
|
48
|
+
export const wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
|
|
49
|
+
export const wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
50
|
+
export const wasmscene_placement: (a: number, b: number, c: number) => [number, number, number, number];
|
|
51
|
+
export const wasmscene_positions_len: (a: number, b: number, c: number) => [number, number, number];
|
|
52
|
+
export const wasmscene_positions_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
53
|
+
export const wasmscene_raycast: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
|
|
54
|
+
export const wasmscene_redo: (a: number) => [number, number, number];
|
|
55
|
+
export const wasmscene_remove_field: (a: number, b: number) => [number, number];
|
|
56
|
+
export const wasmscene_remove_mesh: (a: number, b: number, c: number) => [number, number];
|
|
57
|
+
export const wasmscene_remove_section: (a: number, b: number) => [number, number];
|
|
58
|
+
export const wasmscene_repair: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
59
|
+
export const wasmscene_section: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
60
|
+
export const wasmscene_section_desc_plane: (a: number, b: number) => [number, number, number, number];
|
|
61
|
+
export const wasmscene_section_gap: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
62
|
+
export const wasmscene_set_coloring: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
63
|
+
export const wasmscene_set_defer_fields: (a: number, b: number) => void;
|
|
64
|
+
export const wasmscene_set_mode: (a: number, b: number, c: number, d: number) => [number, number];
|
|
65
|
+
export const wasmscene_set_placement: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
66
|
+
export const wasmscene_set_section_fill: (a: number, b: number, c: number) => [number, number];
|
|
67
|
+
export const wasmscene_set_section_meshes: (a: number, b: number, c: number, d: number) => [number, number];
|
|
68
|
+
export const wasmscene_set_section_plane: (a: number, b: number, c: number, d: number) => [number, number];
|
|
69
|
+
export const wasmscene_take_changes: (a: number) => [number, number];
|
|
70
|
+
export const wasmscene_triangle_count: (a: number, b: number, c: number) => [number, number, number];
|
|
71
|
+
export const wasmscene_triangle_slots: (a: number, b: number, c: number) => [number, number, number];
|
|
72
|
+
export const wasmscene_undo: (a: number) => [number, number, number];
|
|
73
|
+
export const wasmscene_update: (a: number, b: number, c: number) => [number, number];
|
|
74
|
+
export const wasmscene_update_sections: (a: number) => [number, number];
|
|
75
|
+
export const wasmscene_values_len: (a: number, b: number, c: number) => [number, number, number];
|
|
76
|
+
export const wasmscene_values_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
77
|
+
export const wasmscene_vertex_count: (a: number, b: number, c: number) => [number, number, number];
|
|
78
|
+
export const wasmscene_vertex_slots: (a: number, b: number, c: number) => [number, number, number];
|
|
79
|
+
export const wasmscene_withdraw_field: (a: number, b: number) => [number, number, number];
|
|
80
|
+
export const watchPoolCrashes: (a: number, b: number) => void;
|
|
81
|
+
export const wbg_rayon_poolbuilder_build: (a: number) => void;
|
|
82
|
+
export const wbg_rayon_poolbuilder_numThreads: (a: number) => number;
|
|
83
|
+
export const wbg_rayon_poolbuilder_receiver: (a: number) => number;
|
|
84
|
+
export const wbg_rayon_start_worker: (a: number) => void;
|
|
85
|
+
export const memory: WebAssembly.Memory;
|
|
86
|
+
export const __externref_table_alloc: () => number;
|
|
87
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
88
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
89
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
90
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
91
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
92
|
+
export const __wbindgen_thread_destroy: (a?: number, b?: number, c?: number) => void;
|
|
93
|
+
export const __wbindgen_start: (a: number) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
const describe = (e) => (e instanceof Error ? `${e.name}: ${e.message}` : String(e));
|
|
3
|
+
export function post_crash(channel, detail) {
|
|
4
|
+
try {
|
|
5
|
+
const c = new BroadcastChannel(channel);
|
|
6
|
+
c.postMessage({ kind: "poolCrash", detail });
|
|
7
|
+
c.close();
|
|
8
|
+
} catch {
|
|
9
|
+
// Nothing to report on: the scene cannot hear this thread.
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function watch_worker(channel) {
|
|
13
|
+
// The thread's loop runs in an async message handler: a trap rejects it.
|
|
14
|
+
addEventListener("unhandledrejection", (e) => post_crash(channel, describe(e.reason)));
|
|
15
|
+
addEventListener("error", (e) => post_crash(channel, e.error === undefined ? String(e.message) : describe(e.error)));
|
|
16
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Google Inc. All Rights Reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
* See the License for the specific language governing permissions and
|
|
11
|
+
* limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// Note: we use `wasm_bindgen_worker_`-prefixed message types to make sure
|
|
15
|
+
// we can handle bundling into other files, which might happen to have their
|
|
16
|
+
// own `postMessage`/`onmessage` communication channels.
|
|
17
|
+
//
|
|
18
|
+
// If we didn't take that into the account, we could send much simpler signals
|
|
19
|
+
// like just `0` or whatever, but the code would be less resilient.
|
|
20
|
+
|
|
21
|
+
function waitForMsgType(target, type) {
|
|
22
|
+
return new Promise(resolve => {
|
|
23
|
+
target.addEventListener('message', function onMsg({ data }) {
|
|
24
|
+
if (data?.type !== type) return;
|
|
25
|
+
target.removeEventListener('message', onMsg);
|
|
26
|
+
resolve(data);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
waitForMsgType(self, 'wasm_bindgen_worker_init').then(async ({ init, receiver }) => {
|
|
32
|
+
// # Note 1
|
|
33
|
+
// Our JS should have been generated in
|
|
34
|
+
// `[out-dir]/snippets/wasm-bindgen-rayon-[hash]/workerHelpers.js`,
|
|
35
|
+
// resolve the main module via `../../..`.
|
|
36
|
+
//
|
|
37
|
+
// This might need updating if the generated structure changes on wasm-bindgen
|
|
38
|
+
// side ever in the future, but works well with bundlers today. The whole
|
|
39
|
+
// point of this crate, after all, is to abstract away unstable features
|
|
40
|
+
// and temporary bugs so that you don't need to deal with them in your code.
|
|
41
|
+
//
|
|
42
|
+
// # Note 2
|
|
43
|
+
// This could be a regular import, but then some bundlers complain about
|
|
44
|
+
// circular deps.
|
|
45
|
+
//
|
|
46
|
+
// Dynamic import could be cheap if this file was inlined into the parent,
|
|
47
|
+
// which would require us just using `../../..` in `new Worker` below,
|
|
48
|
+
// but that doesn't work because wasm-pack unconditionally adds
|
|
49
|
+
// "sideEffects":false (see below).
|
|
50
|
+
//
|
|
51
|
+
// OTOH, even though it can't be inlined, it should be still reasonably
|
|
52
|
+
// cheap since the requested file is already in cache (it was loaded by
|
|
53
|
+
// the main thread).
|
|
54
|
+
const pkg = await import('../../../fast_mesh_wasm.js');
|
|
55
|
+
await pkg.default(init);
|
|
56
|
+
postMessage({ type: 'wasm_bindgen_worker_ready' });
|
|
57
|
+
pkg.wbg_rayon_start_worker(receiver);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Note: this is never used, but necessary to prevent a bug in Firefox
|
|
61
|
+
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1702191) where it collects
|
|
62
|
+
// Web Workers that have a shared WebAssembly memory with the main thread,
|
|
63
|
+
// but are not explicitly rooted via a `Worker` instance.
|
|
64
|
+
//
|
|
65
|
+
// By storing them in a variable, we can keep `Worker` objects around and
|
|
66
|
+
// prevent them from getting GC-d.
|
|
67
|
+
let _workers;
|
|
68
|
+
|
|
69
|
+
export async function startWorkers(module, memory, builder) {
|
|
70
|
+
if (builder.numThreads() === 0) {
|
|
71
|
+
throw new Error(`num_threads must be > 0.`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const workerInit = {
|
|
75
|
+
type: 'wasm_bindgen_worker_init',
|
|
76
|
+
init: { module_or_path: module, memory },
|
|
77
|
+
receiver: builder.receiver()
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
_workers = await Promise.all(
|
|
81
|
+
Array.from({ length: builder.numThreads() }, async () => {
|
|
82
|
+
// Self-spawn into a new Worker.
|
|
83
|
+
//
|
|
84
|
+
// TODO: while `new URL('...', import.meta.url) becomes a semi-standard
|
|
85
|
+
// way to get asset URLs relative to the module across various bundlers
|
|
86
|
+
// and browser, ideally we should switch to `import.meta.resolve`
|
|
87
|
+
// once it becomes a standard.
|
|
88
|
+
//
|
|
89
|
+
// Note: we could use `../../..` as the URL here to inline workerHelpers.js
|
|
90
|
+
// into the parent entry instead of creating another split point -
|
|
91
|
+
// this would be preferable from optimization perspective -
|
|
92
|
+
// however, Webpack then eliminates all message handler code
|
|
93
|
+
// because wasm-pack produces "sideEffects":false in package.json
|
|
94
|
+
// unconditionally.
|
|
95
|
+
//
|
|
96
|
+
// The only way to work around that is to have side effect code
|
|
97
|
+
// in an entry point such as Worker file itself.
|
|
98
|
+
const worker = new Worker(new URL('./workerHelpers.js', import.meta.url), {
|
|
99
|
+
type: 'module'
|
|
100
|
+
});
|
|
101
|
+
worker.postMessage(workerInit);
|
|
102
|
+
await waitForMsgType(worker, 'wasm_bindgen_worker_ready');
|
|
103
|
+
return worker;
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
builder.build();
|
|
107
|
+
}
|
package/dist/web.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Bounds, InitInput, computeBounds, computeVertexNormals } from "./
|
|
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";
|
|
2
|
+
import { n as FastMeshErrorCode, t as FastMeshError } from "./core-D2X9GPfK.js";
|
|
2
3
|
//#region src/web.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Loads the WebAssembly module. Await this once before calling any other function.
|
|
@@ -9,4 +10,4 @@ import { Bounds, InitInput, computeBounds, computeVertexNormals } from "./wasm/f
|
|
|
9
10
|
*/
|
|
10
11
|
export declare function init(input?: InitInput | Promise<InitInput>): Promise<void>;
|
|
11
12
|
//#endregion
|
|
12
|
-
export { Bounds, 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 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,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { t as FastMeshError } from "./core-Cke_kZ2e.js";
|
|
2
|
+
import { n as computeVertexNormals, r as markInitialized, t as computeBounds } from "./api-BUy7FRx7.js";
|
|
3
|
+
import { t as Scene } from "./scene-BG3EEyfw.js";
|
|
4
|
+
import wasmInit from "./wasm/fast_mesh_wasm.js";
|
|
2
5
|
//#region src/web.ts
|
|
3
6
|
let ready;
|
|
4
7
|
/**
|
|
@@ -9,8 +12,8 @@ let ready;
|
|
|
9
12
|
* Leave empty to load the file shipped with this package.
|
|
10
13
|
*/
|
|
11
14
|
function init(input) {
|
|
12
|
-
ready ??= wasmInit(input === void 0 ? void 0 : { module_or_path: input }).then(
|
|
15
|
+
ready ??= wasmInit(input === void 0 ? void 0 : { module_or_path: input }).then(markInitialized);
|
|
13
16
|
return ready;
|
|
14
17
|
}
|
|
15
18
|
//#endregion
|
|
16
|
-
export {
|
|
19
|
+
export { FastMeshError, Scene, computeBounds, computeVertexNormals, init };
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { a as WorkerMessage, i as Result, n as InitMessage, r as Request, t as ClientId } from "./protocol-W9R-iGl5.js";
|
|
2
|
+
import { WasmScene } from "./wasm/fast_mesh_wasm.js";
|
|
3
|
+
//#region src/worker/load.d.ts
|
|
4
|
+
/** What the engine needs of a wasm-bindgen glue module. */
|
|
5
|
+
interface Glue {
|
|
6
|
+
/** The glue's async init (fetches and instantiates its .wasm). */
|
|
7
|
+
default(): Promise<{
|
|
8
|
+
memory: WebAssembly.Memory;
|
|
9
|
+
}>;
|
|
10
|
+
WasmScene: typeof WasmScene;
|
|
11
|
+
}
|
|
12
|
+
/** The threaded glue: also starts wasm-bindgen-rayon's pool. */
|
|
13
|
+
interface ThreadedGlue extends Glue {
|
|
14
|
+
initThreadPool(threads: number): Promise<unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Makes the pool's threads report a panic or a trap on the
|
|
17
|
+
* `BroadcastChannel` named `channel` (a `PoolCrash` message). Call once,
|
|
18
|
+
* after the pool started.
|
|
19
|
+
*/
|
|
20
|
+
watchPoolCrashes(channel: string): void;
|
|
21
|
+
}
|
|
22
|
+
/** Options of {@link loadEngine}. */
|
|
23
|
+
interface LoadOptions {
|
|
24
|
+
/** The threads asked for: the threaded engine is tried unless 1. */
|
|
25
|
+
threads: number;
|
|
26
|
+
/** `crossOriginIsolated`: shared memory (and so threads) is available. */
|
|
27
|
+
isolated: boolean;
|
|
28
|
+
importThreaded: () => Promise<ThreadedGlue>;
|
|
29
|
+
importSingle: () => Promise<Glue>;
|
|
30
|
+
/**
|
|
31
|
+
* Development only: called once when the engine is single-threaded though
|
|
32
|
+
* more threads were asked for, or when its pool cannot be watched for crashes.
|
|
33
|
+
*/
|
|
34
|
+
warn?: (message: string) => void;
|
|
35
|
+
/** How long the pool may take to start: {@link POOL_TIMEOUT_MS} by default. */
|
|
36
|
+
poolTimeoutMs?: number;
|
|
37
|
+
/** The channel the pool's threads report a crash on (see {@link ThreadedGlue.watchPoolCrashes}). */
|
|
38
|
+
crashChannel?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Run before the threaded engine is tried: resolves with why it must not
|
|
41
|
+
* run in this browser, or `undefined` when it may (see
|
|
42
|
+
* {@link probeSharedGrowth}, {@link startEngine}'s default). A rejection
|
|
43
|
+
* counts as `undefined`.
|
|
44
|
+
*/
|
|
45
|
+
probe?: () => Promise<string | undefined>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Loads and initialises the glue to run: the threaded one with its pool
|
|
49
|
+
* started when `isolated` and `threads` is not 1, else (or when importing or
|
|
50
|
+
* instantiating it fails) the single-threaded one. Returns the glue, its
|
|
51
|
+
* memory and the threads the engine computes with (1 when single-threaded);
|
|
52
|
+
* `probeFailed` is set when the probe ruled the threaded engine out. The
|
|
53
|
+
* probe runs while the threaded glue is imported; only its instantiation
|
|
54
|
+
* waits for the probe's answer.
|
|
55
|
+
* Rejects with a {@link PoolStartError} when the pool fails or times out
|
|
56
|
+
* after the threaded glue instantiated (`warn` is then not called). A
|
|
57
|
+
* started pool is watched for crashes on `crashChannel`, when given.
|
|
58
|
+
*/
|
|
59
|
+
export declare function loadEngine(options: LoadOptions): Promise<{
|
|
60
|
+
wasm: Glue;
|
|
61
|
+
memory: WebAssembly.Memory;
|
|
62
|
+
threads: number;
|
|
63
|
+
probeFailed?: true;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Starts the Worker's engine for its {@link InitMessage}: loads the glue
|
|
67
|
+
* ({@link loadEngine}, probing with {@link probeSharedGrowth} unless
|
|
68
|
+
* `loaders` names a probe) and makes scenes use it. `isolated` defaults to the
|
|
69
|
+
* global `crossOriginIsolated`; development warnings are collected only on a
|
|
70
|
+
* page (where it is a boolean; Node `worker_threads` has none) and when
|
|
71
|
+
* `debug` is set. Resolves with what the ready message reports (`probeFailed`
|
|
72
|
+
* in production too: the scene caches it); rejects
|
|
73
|
+
* with a {@link PoolStartError} (its `warning` set in development) when the
|
|
74
|
+
* Worker must be replaced by a single-threaded one.
|
|
75
|
+
*/
|
|
76
|
+
export declare function startEngine(init: InitMessage, loaders: Pick<LoadOptions, "importThreaded" | "importSingle" | "poolTimeoutMs" | "probe">, isolated?: boolean | undefined): Promise<{
|
|
77
|
+
threads: number;
|
|
78
|
+
warning?: string;
|
|
79
|
+
probeFailed?: true;
|
|
80
|
+
}>;
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/worker/probe.d.ts
|
|
83
|
+
/** The parts of a nested Worker the probe uses. */
|
|
84
|
+
interface ProbeWorker {
|
|
85
|
+
postMessage(msg: unknown): void;
|
|
86
|
+
terminate(): void;
|
|
87
|
+
onmessage: ((e: {
|
|
88
|
+
data: unknown;
|
|
89
|
+
}) => void) | null;
|
|
90
|
+
onerror: ((e: unknown) => void) | null;
|
|
91
|
+
onmessageerror: ((e: unknown) => void) | null;
|
|
92
|
+
}
|
|
93
|
+
/** Starts a nested Worker running the classic script `source`; may throw. */
|
|
94
|
+
type ProbeSpawn = (source: string) => ProbeWorker;
|
|
95
|
+
/**
|
|
96
|
+
* Resolves with why the threaded engine must not run in this browser (a
|
|
97
|
+
* shared memory grown on a nested Worker cannot be filled or copied into
|
|
98
|
+
* here), or
|
|
99
|
+
* `undefined` when it may: the probe passed, or could not tell (no nested
|
|
100
|
+
* Workers, a Worker that failed, could not read or answer the message, or did
|
|
101
|
+
* not answer within `timeoutMs`). Never
|
|
102
|
+
* rejects. `spawn` defaults to Blob-URL Workers, and to no probe where there
|
|
103
|
+
* are none (Node).
|
|
104
|
+
*/
|
|
105
|
+
export declare function probeSharedGrowth(options?: {
|
|
106
|
+
spawn?: ProbeSpawn;
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
}): Promise<string | undefined>;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/worker/engine.d.ts
|
|
111
|
+
/** The engine's side of the message channel. */
|
|
112
|
+
export interface Port {
|
|
113
|
+
post(msg: Result, transfer: Transferable[]): void;
|
|
114
|
+
/**
|
|
115
|
+
* Posts a result that belongs to no batch (`{ kind: "update" }` on the
|
|
116
|
+
* wire): a background add landed while the engine was idle. Without it,
|
|
117
|
+
* meshes are never added in the background.
|
|
118
|
+
*/
|
|
119
|
+
postUpdate?(msg: Result, transfer: Transferable[]): void;
|
|
120
|
+
/** `cb` gets each batch of requests, in the order they were sent. */
|
|
121
|
+
onMessage(cb: (batch: Request[]) => void): void;
|
|
122
|
+
}
|
|
123
|
+
/** Options of {@link runEngine}. */
|
|
124
|
+
export interface EngineOptions {
|
|
125
|
+
/**
|
|
126
|
+
* Test-only: answers the `debugDump` query (`{ mesh }`) with copies of the
|
|
127
|
+
* mesh's render buffers, placement and matrix, for comparing mirrors.
|
|
128
|
+
*/
|
|
129
|
+
debug?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Test-only: called after each chunk of work: every request run (`kind`
|
|
132
|
+
* is the request's), every field computed (`"fieldBuild"`, `id` is the
|
|
133
|
+
* field's client id), every step of a field add's build
|
|
134
|
+
* (`"fieldBuildStep"`, with the id) and every such build abandoned for a
|
|
135
|
+
* superseded display (`"fieldBuildAbandon"`), every background add started
|
|
136
|
+
* (`"addMeshBegin"`), stepped (`"addMeshStep"`) and landed (`"addMesh"`),
|
|
137
|
+
* with the mesh's id, every operation of a repair
|
|
138
|
+
* list run in steps (`"repairOp"`), every field step (`"fieldStep"`) and
|
|
139
|
+
* every abandoned field step unit (`"fieldStepAbandon"`).
|
|
140
|
+
*/
|
|
141
|
+
onChunk?: (chunk: {
|
|
142
|
+
kind: string;
|
|
143
|
+
id?: ClientId;
|
|
144
|
+
}) => void;
|
|
145
|
+
/**
|
|
146
|
+
* How long the engine runs chunks before it yields to the message loop,
|
|
147
|
+
* in milliseconds: {@link YIELD_MS} by default. A yield costs a message
|
|
148
|
+
* round trip, so thousands of small requests run back to back, while a
|
|
149
|
+
* long operation lets newer batches in (and be coalesced) after each
|
|
150
|
+
* chunk past the budget. `0` yields after every chunk (tests).
|
|
151
|
+
*/
|
|
152
|
+
yieldMs?: number;
|
|
153
|
+
/**
|
|
154
|
+
* How many vertices of the due fields one field step computes:
|
|
155
|
+
* {@link STEP_POINTS} by default. Smaller steps notice a stale recompute
|
|
156
|
+
* sooner, at the cost of more step boundaries (tests use a few, so that a
|
|
157
|
+
* unit spans many steps). Rounded down and clamped to at least 1.
|
|
158
|
+
*/
|
|
159
|
+
stepPoints?: number;
|
|
160
|
+
/**
|
|
161
|
+
* The starvation guard, in milliseconds: {@link STALE_GUARD_MS} by
|
|
162
|
+
* default. Once this long has passed since the last field step unit
|
|
163
|
+
* completed, a queued drag move no longer abandons the unit: it completes
|
|
164
|
+
* and is published, and the newest pose follows. So a sustained drag whose
|
|
165
|
+
* recompute outlasts the gaps between moves still updates its colours
|
|
166
|
+
* about every guard plus one recompute, each update exactly one pose.
|
|
167
|
+
* Edits, repairs, compactions, removals, placements, undo, redo and drag
|
|
168
|
+
* cancels always abandon, and so do drag moves once the drag's `end` is
|
|
169
|
+
* queued (the final pose then follows within one recompute; a pointer
|
|
170
|
+
* that pauses without ending may wait up to two).
|
|
171
|
+
*/
|
|
172
|
+
staleGuardMs?: number;
|
|
173
|
+
/**
|
|
174
|
+
* Meshes of at least this many triangles are added in the background
|
|
175
|
+
* ({@link BACKGROUND_ADD_TRIANGLES} by default): see
|
|
176
|
+
* {@link Engine.#beginAdd}. `0` adds every mesh so (tests);
|
|
177
|
+
* `Infinity` none. NaN keeps the default; a negative value counts as 0.
|
|
178
|
+
* The init message's `backgroundAddTriangles`
|
|
179
|
+
* ({@link WorkerSceneOptions.backgroundAddTriangles}) overrides it in
|
|
180
|
+
* {@link serveEngine}.
|
|
181
|
+
*/
|
|
182
|
+
backgroundAddTriangles?: number;
|
|
183
|
+
/**
|
|
184
|
+
* The work of one step of a background add's BVH build
|
|
185
|
+
* ({@link ADD_STEP_WORK} by default): a triangle's box, or a triangle
|
|
186
|
+
* visited per tree level. Clamped to 1 to 2^32 − 1; NaN or less than 1
|
|
187
|
+
* keeps the default.
|
|
188
|
+
*/
|
|
189
|
+
addStepWork?: number;
|
|
190
|
+
/**
|
|
191
|
+
* The threads the engine computes with (1 by default; {@link serveEngine}
|
|
192
|
+
* passes what the start reports). With more than one, a request waiting
|
|
193
|
+
* on a background add lands it in one call (the parallel one-call
|
|
194
|
+
* build, several times faster than steps); with one, it keeps stepping
|
|
195
|
+
* with yields, which costs the same, so newer batches still arrive.
|
|
196
|
+
*/
|
|
197
|
+
threads?: number;
|
|
198
|
+
}
|
|
199
|
+
/** The default {@link EngineOptions.yieldMs}. */
|
|
200
|
+
export declare const YIELD_MS = 4;
|
|
201
|
+
/** The default {@link EngineOptions.staleGuardMs}. */
|
|
202
|
+
export declare const STALE_GUARD_MS = 200;
|
|
203
|
+
/** The default {@link EngineOptions.stepPoints}. */
|
|
204
|
+
export declare const STEP_POINTS = 4096;
|
|
205
|
+
/**
|
|
206
|
+
* The default {@link EngineOptions.backgroundAddTriangles}: smaller meshes
|
|
207
|
+
* add in well under a frame, in place.
|
|
208
|
+
*/
|
|
209
|
+
export declare const BACKGROUND_ADD_TRIANGLES = 65536;
|
|
210
|
+
/** The default {@link EngineOptions.addStepWork}: a few milliseconds of BVH build. */
|
|
211
|
+
export declare const ADD_STEP_WORK = 100000;
|
|
212
|
+
/**
|
|
213
|
+
* Runs the engine on `port` until the instance traps. The WebAssembly module
|
|
214
|
+
* must already be initialised.
|
|
215
|
+
*/
|
|
216
|
+
export declare function runEngine(port: Port, options?: EngineOptions): void;
|
|
217
|
+
/** A Worker's side of its channel: raw messages in, messages out. */
|
|
218
|
+
export interface Endpoint {
|
|
219
|
+
post(msg: WorkerMessage, transfer: Transferable[]): void;
|
|
220
|
+
/** `cb` gets each message's data, in order. */
|
|
221
|
+
onMessage(cb: (data: unknown) => void): void;
|
|
222
|
+
}
|
|
223
|
+
/** What a Worker's engine start reports in its ready message. */
|
|
224
|
+
export interface Started {
|
|
225
|
+
/** The threads the engine computes with: 1 when single-threaded. */
|
|
226
|
+
threads: number;
|
|
227
|
+
/** Development only: why it is single-threaded though more threads were asked for. */
|
|
228
|
+
warning?: string;
|
|
229
|
+
/** The browser cannot run the threaded engine (its probe failed): the scene stops asking for threads. */
|
|
230
|
+
probeFailed?: true;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Serves the engine on a Worker's endpoint once it starts. `ready` is the
|
|
234
|
+
* start itself (the WebAssembly module's initialisation), or a function
|
|
235
|
+
* starting it for the Worker's first {@link InitMessage} (as the browser
|
|
236
|
+
* Worker script does); with a promise, init messages are ignored. Batches
|
|
237
|
+
* arriving before are kept and run in order; then `{ kind: "ready" }` (with
|
|
238
|
+
* the {@link Started} report, 1 thread by default) is posted first. When the
|
|
239
|
+
* start fails, `{ kind: "fatal" }` is posted instead and nothing runs. When
|
|
240
|
+
* it fails with a {@link PoolStartError} (the threaded pool did not start),
|
|
241
|
+
* `{ kind: "fallback" }` is posted instead, giving back every batch received
|
|
242
|
+
* (and, one message each, every batch received later), their buffers
|
|
243
|
+
* transferred: the scene replaces this Worker with a single-threaded one and
|
|
244
|
+
* sends them there.
|
|
245
|
+
*/
|
|
246
|
+
export declare function serveEngine(endpoint: Endpoint, ready: Promise<unknown> | ((init: InitMessage) => Promise<Started>), options?: EngineOptions): void;
|
|
247
|
+
//#endregion
|
|
248
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as ADD_STEP_WORK, n as BACKGROUND_ADD_TRIANGLES, r as STALE_GUARD_MS, i as STEP_POINTS, a as YIELD_MS, c as loadEngine, u as probeSharedGrowth, o as runEngine, s as serveEngine, l as startEngine } from "./engine-B-ZEzR1c.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { l as startEngine, s as serveEngine } from "./engine-B-ZEzR1c.js";
|
|
2
|
+
//#region src/worker/entry.ts
|
|
3
|
+
const scope = globalThis;
|
|
4
|
+
serveEngine({
|
|
5
|
+
post: (msg, transfer) => scope.postMessage(msg, transfer),
|
|
6
|
+
onMessage: (cb) => scope.addEventListener("message", (e) => cb(e.data))
|
|
7
|
+
}, (init) => startEngine(init, {
|
|
8
|
+
importThreaded: () => import("./wasm-threads/fast_mesh_wasm.js"),
|
|
9
|
+
importSingle: () => import("./wasm/fast_mesh_wasm.js")
|
|
10
|
+
}));
|
|
11
|
+
//#endregion
|
package/dist/worker.d.ts
ADDED
package/dist/worker.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as WorkerScene, r as createWorkerScene } from "./client-Bp9FRd70.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-mesh-wasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Fast triangle mesh utilities for JavaScript, written in Rust and compiled to WebAssembly",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mesh",
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
"license": "MIT OR Apache-2.0",
|
|
23
23
|
"author": "DongGeun Yoon",
|
|
24
24
|
"type": "module",
|
|
25
|
-
"sideEffects":
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"./dist/node.js",
|
|
27
|
+
"./dist/worker-entry.js"
|
|
28
|
+
],
|
|
26
29
|
"exports": {
|
|
27
30
|
".": {
|
|
28
31
|
"node": {
|
|
@@ -34,6 +37,26 @@
|
|
|
34
37
|
"default": "./dist/web.js"
|
|
35
38
|
}
|
|
36
39
|
},
|
|
40
|
+
"./three": {
|
|
41
|
+
"types": "./dist/three.d.ts",
|
|
42
|
+
"default": "./dist/three.js"
|
|
43
|
+
},
|
|
44
|
+
"./worker": {
|
|
45
|
+
"types": "./dist/worker.d.ts",
|
|
46
|
+
"default": "./dist/worker.js"
|
|
47
|
+
},
|
|
48
|
+
"./store": {
|
|
49
|
+
"types": "./dist/store.d.ts",
|
|
50
|
+
"default": "./dist/store.js"
|
|
51
|
+
},
|
|
52
|
+
"./react": {
|
|
53
|
+
"types": "./dist/react.d.ts",
|
|
54
|
+
"default": "./dist/react.js"
|
|
55
|
+
},
|
|
56
|
+
"./r3f": {
|
|
57
|
+
"types": "./dist/r3f.d.ts",
|
|
58
|
+
"default": "./dist/r3f.js"
|
|
59
|
+
},
|
|
37
60
|
"./package.json": "./package.json"
|
|
38
61
|
},
|
|
39
62
|
"types": "./dist/web.d.ts",
|
|
@@ -43,10 +66,36 @@
|
|
|
43
66
|
"engines": {
|
|
44
67
|
"node": ">=22"
|
|
45
68
|
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@react-three/fiber": ">=9",
|
|
71
|
+
"react": ">=18",
|
|
72
|
+
"three": ">=0.160"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"@react-three/fiber": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"react": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"three": {
|
|
82
|
+
"optional": true
|
|
83
|
+
}
|
|
84
|
+
},
|
|
46
85
|
"devDependencies": {
|
|
47
86
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
48
|
-
"@
|
|
87
|
+
"@react-three/fiber": "^9.8.2",
|
|
88
|
+
"@react-three/test-renderer": "^9.1.1",
|
|
89
|
+
"@testing-library/react": "^16.3.3",
|
|
90
|
+
"@types/node": "^22.20.5",
|
|
91
|
+
"@types/react": "^19.3.0",
|
|
92
|
+
"@types/react-dom": "^19.3.0",
|
|
93
|
+
"@types/three": "^0.186.0",
|
|
94
|
+
"jsdom": "^30.1.3",
|
|
49
95
|
"publint": "^0.3.25",
|
|
96
|
+
"react": "^19.3.1",
|
|
97
|
+
"react-dom": "^19.3.1",
|
|
98
|
+
"three": "^0.186.1",
|
|
50
99
|
"tsdown": "^0.23.1",
|
|
51
100
|
"typescript": "^7.0.2",
|
|
52
101
|
"vitest": "^5.0.4"
|
|
@@ -57,7 +106,9 @@
|
|
|
57
106
|
},
|
|
58
107
|
"scripts": {
|
|
59
108
|
"build": "tsdown",
|
|
60
|
-
"test": "vitest run",
|
|
109
|
+
"test": "node ../../scripts/build-wasm.mjs --test && node ../../scripts/build-wasm.mjs --threads --test && tsdown && vitest run",
|
|
110
|
+
"bench": "node bench/scene.bench.mjs",
|
|
111
|
+
"bench:store": "node bench/store.bench.mjs",
|
|
61
112
|
"check": "publint --strict && attw --pack . --profile esm-only"
|
|
62
113
|
}
|
|
63
114
|
}
|