API reference
Conversion methods, generated capabilities, directional formats, typed options, lifecycle, and failures.
Every conversion symbol is available from the libassimp entry. The lazy libassimp/capabilities subpath adds option and step descriptions, and libassimp/wasm is the binary.
convert
import type { AssimpFile, ConvertOptions, ConvertResult } from 'libassimp';
export declare const convert: <Format extends import('libassimp').ExportFormat>(
files: AssimpFile | readonly AssimpFile[],
options: ConvertOptions<Format>,
) => Promise<ConvertResult>;Converts one entry file to one canonical target. The first array element is the entry file; names must be unique and non-empty. ConvertOptions contains to, resolve, signal, onProgress, importOptions, postProcess, and target-specific exportOptions. Outputs are named after the entry: chair.obj to step gives chair.step.
convertFormats
import type { AssimpFile, ConvertFormatsOptions, ConvertFormatsResult, ConvertTarget } from 'libassimp';
export declare const convertFormats: <const Targets extends readonly [ConvertTarget, ...ConvertTarget[]]>(
files: AssimpFile | readonly AssimpFile[],
options: ConvertFormatsOptions<Targets>,
) => Promise<ConvertFormatsResult<Targets>>;Imports once and exports a non-empty target tuple sequentially. Each ConvertedFormat contains its literal format and ordered files; target order, repeats, and result positions are preserved. There is no caller ID field.
import { convertFormats } from 'libassimp';
const bytes = new Uint8Array();
const [ascii, binary] = await convertFormats(
{ name: 'part.glb', bytes },
{
targets: [
{ to: 'stl', exportOptions: { binary: false } },
{ to: 'stl', exportOptions: { binary: true } },
],
},
);
console.log(ascii.format, binary.format);createAssimp
import type { Assimp, CreateAssimpOptions } from 'libassimp';
export declare const createAssimp: (options?: CreateAssimpOptions) => Promise<Assimp>;An instance exposes convert, convertFormats, and directional formats. Work is FIFO-serialized per instance; create separate instances for parallel conversions. dispose() resolves after queued work drains; await using awaits it.
CreateAssimpOptions:
backend:'auto'(the Node default: native addon, else Wasm with a warning),'native'or'wasm'. Browsers use Wasm.wasmUrl: override the entry's single Wasm URL.wasmBinary: compile supplied bytes instead of fetching that URL.onLog: receive runtime diagnostics.recycleAboveBytes: drop an idle Wasm runtime above this much memory (default 512 MiB); a trapped one is also replaced.
Static generated data
import { assimpCapabilities, conversionEdges, defaultPostProcess } from 'libassimp';
const stl = assimpCapabilities.export.stl.exportOptions;
const glbToStl = conversionEdges.find(({ from, to }) => from === 'glb' && to === 'stl');
console.log(stl.binary.default, glbToStl, defaultPostProcess);assimpCapabilitiesis the keyed serializable registry: directional import/export metadata, exact export-option descriptors,ImportOptions, andPostProcessDescriptordata. Descriptions are left out of the root entry;libassimp/capabilitiesexports the same registry asDescribedCapabilities, with adescriptionon eachDescribedOptionDescriptorandDescribedPostProcessDescriptor.conversionEdgesis the exact import/export cross-product minus identity pairs.ConversionEdgeremains a discriminated union of valid pairs.defaultPostProcessis the default readonlyPostProcessSteptuple.
Importing these values does not load Wasm or the native addon.
Core types
AssimpFile
Prop
Type
ResolveFile
ResolveFile returns Uint8Array | undefined | Promise<Uint8Array | undefined> for an exact requested sidecar name.
Options
ImportOptions is the generated exact import configuration. ExportOptionsByFormat maps every canonical target to its exact options; ExportOptionsFor<Format> indexes that map. ExportOptionDescriptorsFor<Format> exposes its runtime descriptors. OptionDescriptor describes kind, default, bounds and enum values. No public index signature or raw native property bag exists.
Formats
ImportFormat and ExportFormat are directional unions. ImportFormatInfo describes readable extensions; ExportFormatInfo adds target-specific option descriptors. FormatInfo is the shared base. Native exporter IDs are private.
Requests and results
ConvertTarget, ConvertOptions, ConvertFormatsOptions, ConvertResult, ConvertedFormat, and ConvertFormatsResult preserve exact target types. Empty plural target arrays are rejected by both TypeScript and runtime validation. Each ConvertedFile holds Uint8Array<ArrayBuffer> bytes that it owns.
Diagnostics
Results carry a ConversionReport: warnings (ConversionWarning), timings (ConversionTimings, milliseconds), and peakMemoryBytes. onProgress, a ConvertProgressListener, receives throttled ConvertProgress reports per ConversionPhase.
Prop
Type
Node.js also exports createDirectoryResolver; see Resolve sidecar files.
Failures
AssimpError is a normal Error with an AssimpFailureCode. AssimpErrorContext may add formatIndex, canonical format, exact resolver fileName, and cause.
Prop
Type
import { AssimpError, convert } from 'libassimp';
try {
await convert(
{ name: 'model.glb', bytes: new Uint8Array() },
{ to: 'stl', exportOptions: { binary: true } },
);
} catch (error) {
if (error instanceof AssimpError) {
console.error(error.code, error.formatIndex, error.format, error.fileName, error.cause);
}
}Context fields that do not apply are absent. Handle failures gives each code's remedy. Plural output is atomic: a failed target exposes no partial result.
Versioning
Before 1.0, minor versions may break the prerelease API. Each removal is recorded in BREAKING_CHANGES.md.