fast-mesh-wasm 0.2.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 +488 -1
- package/dist/{api-D0o2HjaU.js → api-BUy7FRx7.js} +11 -11
- 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 +3 -2
- package/dist/node.js +5 -4
- 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 +458 -0
- package/dist/wasm/fast_mesh_wasm.js +1150 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +74 -0
- 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 +4 -2
- 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 +53 -4
- package/dist/api-HcskOwd7.d.ts +0 -43
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//#region src/core.ts
|
|
2
|
+
const CODES = /* @__PURE__ */ new Set([
|
|
3
|
+
"UNKNOWN_MESH",
|
|
4
|
+
"UNKNOWN_FIELD",
|
|
5
|
+
"UNKNOWN_SECTION",
|
|
6
|
+
"INVALID_ARGUMENT",
|
|
7
|
+
"INVALID_INDEX",
|
|
8
|
+
"STALE_BVH",
|
|
9
|
+
"STEP_NOT_OPEN",
|
|
10
|
+
"CORRUPTED",
|
|
11
|
+
"OUT_OF_MEMORY",
|
|
12
|
+
"STALE_LOOPS",
|
|
13
|
+
"INSTANCE_POISONED"
|
|
14
|
+
]);
|
|
15
|
+
/** An error thrown by fast-mesh, with a machine-readable `code`. */
|
|
16
|
+
var FastMeshError = class extends Error {
|
|
17
|
+
/** What went wrong; see {@link FastMeshErrorCode}. */
|
|
18
|
+
code;
|
|
19
|
+
constructor(code, message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "FastMeshError";
|
|
22
|
+
this.code = code;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Internal (not exported from the entries). Reports a listener's error
|
|
27
|
+
* without breaking the caller: `reportError`, else an async rethrow.
|
|
28
|
+
*/
|
|
29
|
+
function reportListenerError(error) {
|
|
30
|
+
const report = globalThis.reportError;
|
|
31
|
+
if (typeof report === "function") report(error);
|
|
32
|
+
else setTimeout(() => {
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
let poisoned = false;
|
|
37
|
+
let memory;
|
|
38
|
+
/** Stores the instance's memory; called once the module is instantiated. */
|
|
39
|
+
function setMemory(m) {
|
|
40
|
+
memory = m;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Throws the "call `await init()` first" error unless the module is
|
|
44
|
+
* instantiated. `what` names the call, e.g. `"computeBounds()"`.
|
|
45
|
+
*/
|
|
46
|
+
function ensureInitialized(what) {
|
|
47
|
+
if (memory === void 0) throw new Error(`fast-mesh-wasm is not initialized: call \`await init()\` before ${what}.`);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The instance's memory. Its `buffer` is replaced whenever the memory grows,
|
|
51
|
+
* so build views from it right before use.
|
|
52
|
+
*/
|
|
53
|
+
function wasmMemory() {
|
|
54
|
+
ensureInitialized("reading render views");
|
|
55
|
+
return memory;
|
|
56
|
+
}
|
|
57
|
+
function poisonedError() {
|
|
58
|
+
return new FastMeshError("INSTANCE_POISONED", "an earlier fast-mesh call panicked; the WebAssembly instance can no longer be used");
|
|
59
|
+
}
|
|
60
|
+
const CODED = /^([A-Z_]+): ([\s\S]*)$/;
|
|
61
|
+
const STACK_EXHAUSTED = /call stack/i;
|
|
62
|
+
function stackExhausted(e) {
|
|
63
|
+
return e instanceof RangeError && STACK_EXHAUSTED.test(e.message) || e instanceof Error && e.name === "InternalError";
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Runs a call into WebAssembly. A coded Rust error becomes a
|
|
67
|
+
* {@link FastMeshError}; a trap (a Rust panic) poisons the instance, and from
|
|
68
|
+
* then on every call throws `INSTANCE_POISONED` without entering WebAssembly.
|
|
69
|
+
*
|
|
70
|
+
* Stack exhaustion (a `RangeError` about the call stack, or Firefox's
|
|
71
|
+
* `InternalError`) poisons too: it can
|
|
72
|
+
* unwind out of WebAssembly mid-call, leaving Rust's state half-updated.
|
|
73
|
+
* Other errors, including messages with a `PREFIX: ` that is not a known
|
|
74
|
+
* code, pass through unchanged, so a foreign error is never relabelled.
|
|
75
|
+
*/
|
|
76
|
+
function call(fn) {
|
|
77
|
+
if (poisoned) throw poisonedError();
|
|
78
|
+
try {
|
|
79
|
+
return fn();
|
|
80
|
+
} catch (e) {
|
|
81
|
+
if (e instanceof WebAssembly.RuntimeError || stackExhausted(e)) {
|
|
82
|
+
poisoned = true;
|
|
83
|
+
throw poisonedError();
|
|
84
|
+
}
|
|
85
|
+
const m = e instanceof Error ? CODED.exec(e.message) : null;
|
|
86
|
+
if (m !== null && CODES.has(m[1])) throw new FastMeshError(m[1], m[2]);
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Releases a wasm-bindgen object without ever entering a poisoned instance.
|
|
92
|
+
* After poisoning only its JS side is detached (the glue's own finalizer is
|
|
93
|
+
* unregistered, so it cannot enter WebAssembly later either); the memory is
|
|
94
|
+
* lost with the instance anyway.
|
|
95
|
+
*/
|
|
96
|
+
function release(obj) {
|
|
97
|
+
if (poisoned) {
|
|
98
|
+
obj.__destroy_into_raw();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
call(() => obj.free());
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Frees an object once its owner is garbage collected, through
|
|
105
|
+
* {@link release}. Errors are swallowed: a finalizer has no caller to throw to.
|
|
106
|
+
*/
|
|
107
|
+
const finalizer = new FinalizationRegistry((obj) => {
|
|
108
|
+
try {
|
|
109
|
+
release(obj);
|
|
110
|
+
} catch {}
|
|
111
|
+
});
|
|
112
|
+
//#endregion
|
|
113
|
+
export { release as a, wasmMemory as c, finalizer as i, call as n, reportListenerError as o, ensureInitialized as r, setMemory as s, FastMeshError as t };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/core.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Error codes of {@link FastMeshError}.
|
|
4
|
+
* `INSTANCE_POISONED` means an earlier call panicked: the WebAssembly instance
|
|
5
|
+
* is unusable and every later call throws it. Reload the module to recover.
|
|
6
|
+
*/
|
|
7
|
+
type FastMeshErrorCode = "UNKNOWN_MESH" | "UNKNOWN_FIELD" | "UNKNOWN_SECTION" | "INVALID_ARGUMENT" | "INVALID_INDEX" | "STALE_BVH" | "STEP_NOT_OPEN" | "CORRUPTED" | "OUT_OF_MEMORY" | "STALE_LOOPS" | "INSTANCE_POISONED";
|
|
8
|
+
/** An error thrown by fast-mesh, with a machine-readable `code`. */
|
|
9
|
+
declare class FastMeshError extends Error {
|
|
10
|
+
/** What went wrong; see {@link FastMeshErrorCode}. */
|
|
11
|
+
readonly code: FastMeshErrorCode;
|
|
12
|
+
constructor(code: FastMeshErrorCode, message: string);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { FastMeshErrorCode as n, FastMeshError as t };
|