@meshinspector/meshlib 3.1.3-322 → 3.1.3-429
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 +53 -10
- package/bindings.d.mts +1696 -163
- package/index.d.mts +22 -171
- package/meshlib.mjs +123 -138
- package/meshlib.node.mjs +152 -0
- package/meshlib.node.wasm +0 -0
- package/meshlib.wasm +0 -0
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -50,16 +50,27 @@ const indices = new Uint32Array([
|
|
|
50
50
|
3, 6, 2, 3, 7, 6, 0, 4, 7, 0, 7, 3, 1, 2, 6, 1, 6, 5,
|
|
51
51
|
]);
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
using coords = ml.VertCoords.fromArray(positions);
|
|
54
|
+
using tris = ml.Triangulation.fromArray(indices);
|
|
55
|
+
using mesh = ml.Mesh.fromTriangles(coords, tris);
|
|
56
56
|
|
|
57
57
|
console.log('volume =', mesh.volume()); // ~8
|
|
58
|
+
// `using` frees these WebAssembly-backed objects automatically at the end of scope
|
|
59
|
+
```
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
> `using` requires Node.js 24+ or a current browser. On older runtimes, call `.delete()`
|
|
62
|
+
> instead — see [Memory management](#memory-management).
|
|
63
|
+
|
|
64
|
+
## Using with bundlers
|
|
65
|
+
|
|
66
|
+
Bundlers (Vite, webpack, Rollup) hash and relocate the sidecar `meshlib.wasm`, so the module can't
|
|
67
|
+
locate it on its own. Import the wasm as an asset URL and hand it to the loader via `locateFile`:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import createMeshLib from '@meshinspector/meshlib';
|
|
71
|
+
import wasmUrl from '@meshinspector/meshlib/meshlib.wasm?url';
|
|
72
|
+
|
|
73
|
+
const ml = await createMeshLib( { locateFile: () => wasmUrl } );
|
|
63
74
|
```
|
|
64
75
|
|
|
65
76
|
## TypeScript
|
|
@@ -71,15 +82,47 @@ no extra setup:
|
|
|
71
82
|
import createMeshLib, { type Mesh } from '@meshinspector/meshlib';
|
|
72
83
|
|
|
73
84
|
const ml = await createMeshLib();
|
|
74
|
-
|
|
85
|
+
using mesh: Mesh = ml.Mesh.fromTriangles(coords, tris);
|
|
75
86
|
const { valid, distSq } = ml.findProjection(point, mesh);
|
|
76
87
|
```
|
|
77
88
|
|
|
78
89
|
## Memory management
|
|
79
90
|
|
|
80
91
|
Values returned from the API (meshes, bit sets, settings, result objects, …) hold
|
|
81
|
-
WebAssembly memory that the JavaScript garbage collector does not reclaim
|
|
82
|
-
|
|
92
|
+
WebAssembly memory that the JavaScript garbage collector does not reclaim, so each one
|
|
93
|
+
must be freed explicitly.
|
|
94
|
+
|
|
95
|
+
The preferred way is JavaScript's explicit resource management: declare a handle with
|
|
96
|
+
`using` and it is freed automatically when its scope ends — even if an exception is thrown.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
using mesh = ml.Mesh.fromTriangles(coords, tris);
|
|
100
|
+
// ... use mesh; it is freed at the end of this scope
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
When the number of handles is dynamic (for example built in a loop), collect them in a
|
|
104
|
+
`DisposableStack`, which frees everything it holds, in reverse order, at the end of the scope:
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
using stack = new DisposableStack();
|
|
108
|
+
for (const path of inputPaths) {
|
|
109
|
+
const cloud = stack.use(ml.PointsLoad.fromAnySupportedFormat(path));
|
|
110
|
+
// ... use cloud
|
|
111
|
+
}
|
|
112
|
+
// every handle passed to stack.use(...) is freed here
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`using` and `DisposableStack` are part of JavaScript's Explicit Resource Management,
|
|
116
|
+
available in Node.js 24+ and current browsers. On older runtimes and browsers, call
|
|
117
|
+
`.delete()` on each object when you are done instead:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const mesh = ml.Mesh.fromTriangles(coords, tris);
|
|
121
|
+
// ... use mesh
|
|
122
|
+
mesh.delete();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
See also, on MDN: [`using`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using) and [`DisposableStack`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack).
|
|
83
126
|
|
|
84
127
|
## License
|
|
85
128
|
|