libassimp
0.1.0

Convert a model

Pass one entry file, configure its typed pipeline, and consume every output sidecar.

Open Markdown

One file

import { convert } from 'libassimp';import { readFile } from 'node:fs/promises';const bytes = new Uint8Array(await readFile('part.stl'));const { files } = await convert({ name: 'part.stl', bytes }, { to: 'glb' });console.log(files[0].name, files[0].bytes.byteLength);

Input

objcube.obj136 B

Output

Preparing artifact…

Convert
Output
Files
WASM load

The name selects the importer and is the base path for references.

Supplied sidecars

The first element is the entry file; later elements are named files the importer may open.

import { convert } from 'libassimp';
import { readFile } from 'node:fs/promises';

const load = async (name: string) => ({ name, bytes: new Uint8Array(await readFile(name)) });
const { files } = await convert([await load('scene.gltf'), await load('scene.bin')], {
  to: 'usdz',
  exportOptions: { optimizeForMobile: true },
});

console.log(files[0].name);

Use resolve when the file set is lazy or remote.

Typed pipeline settings

import { convert, defaultPostProcess } from 'libassimp';

const bytes = new Uint8Array();
const { files } = await convert(
  { name: 'model.obj', bytes },
  {
    to: 'stl',
    importOptions: { objUnitScaleToMeters: 0.001 },
    postProcess: [...defaultPostProcess, 'flipUvs'],
    exportOptions: { binary: true },
  },
);

console.log(files[0].name);

The compiler offers only options applicable to stl, and runtime validation rejects unknown keys, wrong values, bounds violations, and conflicting post-process steps before Wasm work. Supplying postProcess replaces the default tuple.

Every output file

gltf writes JSON and a binary sidecar; OBJ normally writes OBJ then MTL. Preserve order and names unless your storage layer rewrites references too.

import { convert } from 'libassimp';
import { writeFile } from 'node:fs/promises';

const bytes = new Uint8Array();
const { files } = await convert({ name: 'part.glb', bytes }, { to: 'gltf' });
for (const file of files) await writeFile(file.name, file.bytes);

Use convert to multiple formats when the same imported scene needs several targets.

On this page