@meshinspector/meshlib-mt 1.0.0-5638 → 3.1.3-337

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 CHANGED
@@ -45,6 +45,21 @@ Without them `SharedArrayBuffer` is unavailable and the module will fail to init
45
45
  use the single-threaded [`@meshinspector/meshlib`](https://www.npmjs.com/package/@meshinspector/meshlib)
46
46
  package in that case.
47
47
 
48
+ For a Vite dev server, set them in `vite.config.js` (and make sure whatever hosts the production
49
+ build sends them too; `vite-plugin-cross-origin-isolation` can stamp them for `vite preview`):
50
+
51
+ ```js
52
+ // vite.config.js
53
+ export default {
54
+ server: {
55
+ headers: {
56
+ 'Cross-Origin-Opener-Policy': 'same-origin',
57
+ 'Cross-Origin-Embedder-Policy': 'require-corp',
58
+ },
59
+ },
60
+ };
61
+ ```
62
+
48
63
  ## Usage
49
64
 
50
65
  The default export is an async factory. Await it once to get the module instance, then call
@@ -77,6 +92,21 @@ tris.delete();
77
92
  mesh.delete();
78
93
  ```
79
94
 
95
+ ## Using with bundlers
96
+
97
+ Bundlers (Vite, webpack, Rollup) hash and relocate the sidecar `meshlib-mt.wasm`, so the module
98
+ can't locate it on its own. Import the wasm as an asset URL and hand it to the loader via
99
+ `locateFile`:
100
+
101
+ ```js
102
+ import createMeshLib from '@meshinspector/meshlib-mt';
103
+ import wasmUrl from '@meshinspector/meshlib-mt/meshlib-mt.wasm?url';
104
+
105
+ const ml = await createMeshLib( { locateFile: () => wasmUrl } );
106
+ ```
107
+
108
+ The page must also be [cross-origin isolated](#browser-requirements-cross-origin-isolation).
109
+
80
110
  ## TypeScript
81
111
 
82
112
  The package ships type definitions, so `createMeshLib` and the whole module API are typed with
package/index.d.mts CHANGED
@@ -178,5 +178,19 @@ export type MeshLibModule =
178
178
  & Functions
179
179
  & ModuleClasses;
180
180
 
181
- declare function createMeshLib( options?: unknown ): Promise<MeshLibModule>;
181
+ /** Options for the module factory (the Emscripten `Module` object). All optional. */
182
+ export interface CreateMeshLibOptions {
183
+ /**
184
+ * Resolve the URL of a runtime file — most importantly the sidecar `.wasm`. Bundlers should
185
+ * pass this pointing at a `?url` import of the wasm; see "Using with Vite / bundlers" in the
186
+ * README.
187
+ */
188
+ locateFile?: ( path: string, scriptDirectory: string ) => string;
189
+ /** Multi-threaded build only: URL or Blob of the main script, so pthread workers can load it. */
190
+ mainScriptUrlOrBlob?: string | Blob;
191
+ print?: ( text: string ) => void;
192
+ printErr?: ( text: string ) => void;
193
+ }
194
+
195
+ declare function createMeshLib( options?: CreateMeshLibOptions ): Promise<MeshLibModule>;
182
196
  export default createMeshLib;