init() function
Default export of @taucad/opencascade.js — signature, options, and singleton pattern.
init is the default export of @taucad/opencascade.js. It instantiates the
WASM module and returns a Promise resolving to the bound OCCT runtime.
import init from '@taucad/opencascade.js';
import wasmUrl from '@taucad/opencascade.js/wasm?url';
const oc = await init({ locateFile: () => wasmUrl });The @taucad/opencascade.js/wasm subpath export resolves to the shipped
opencascade_full.wasm. The multi-threaded variant uses the same init
signature from @taucad/opencascade.js/multi with wasm at
@taucad/opencascade.js/multi/wasm. See Bundler & locateFile
for Vite, Next.js, Bun, Node, and Deno-specific recipes (including the MT variant).
Options
Prop
Type
Memoised singleton pattern
init is expensive — wasm instantiation, runtime bootstrap, and class
registration sum to ~200 ms warm / ~2 s cold. Always memoise the Promise.
let ocPromise: ReturnType<typeof init> | undefined;
export const getOc = () => (ocPromise ??= init({ locateFile: () => wasmUrl }));Calling getOc() from multiple call sites returns the same Promise; only the
first call triggers init.
Return type
The resolved value is the bound OCCT module — a plain object whose properties
are the bound classes and namespaces (oc.BRepPrimAPI_MakeBox,
oc.TopoDS, oc.Interface_Static) plus emscripten runtime
methods (oc.FS, oc.HEAP8, oc.HEAPF32).
The full surface is documented under the API Reference.
Multi-threaded subpath
Import @taucad/opencascade.js/multi with wasm at @taucad/opencascade.js/multi/wasm. The init signature is identical; Emscripten pre-spawns pthread workers during instantiation (PTHREAD_POOL_SIZE=navigator.hardwareConcurrency is baked into the binary). No extra JS worker wiring is required beyond locateFile.
After await init(...), run this once before any parallel-aware OCCT call:
oc.BOPAlgo_Options.SetParallelMode(true);
oc.BRepMesh_IncrementalMesh.SetParallelDefault(true);
const pool = oc.OSD_ThreadPool.DefaultPool(-1);
pool.SetNbDefaultThreadsToLaunch(pool.NbThreads());Skipping the pool sizing leaves OCCT's lazy default pool smaller than the pre-spawned worker count and caps speedup on mesh/boolean workloads. See Multi-threaded build for the full activation walkthrough and BENCHMARKS.md for ST vs MT numbers.