Getting Started | TS
Installation
Install the trueform TypeScript SDK via npm.
Install
npm install @polydera/trueform
Usage
import * as tf from "@polydera/trueform";
const mesh = tf.readStl(await (await fetch("model.stl")).arrayBuffer());
const d = tf.distance(mesh, tf.point(0, 0, 0));
The package includes a WASM binary that is loaded automatically on first use.
Loading the WASM from a CDN
Use @polydera/trueform/manual when the WASM can't ship inside your build (e.g. Cloudflare Pages' 25 MiB per-file cap). Same API; you call init() yourself with blob URLs of the binaries fetched from a CDN:
import * as tf from "@polydera/trueform/manual";
const base = `https://cdn.jsdelivr.net/npm/@polydera/trueform@${VERSION}/dist`;
await tf.init({
wasmUrl: await tf.toBlobURL(`${base}/trueform_wasm.wasm`, "application/wasm"),
workerUrl: await tf.toBlobURL(`${base}/trueform_wasm.js`, "text/javascript"),
});
Requirements
- Node.js 18+ or any modern browser with WebAssembly support
- SharedArrayBuffer — required for multithreading. In browsers, the page must be served with:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Node.js enables SharedArrayBuffer by default.
