# Convert a model

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

Canonical page: https://libassimp.xyz/docs/guides/convert-a-model

## One file [#one-file]

```typescript
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);
```

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

## Supplied sidecars [#supplied-sidecars]

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

```typescript
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 [#typed-pipeline-settings]

```typescript
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 [#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.

```typescript
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](https://libassimp.xyz/docs/guides/convert-to-multiple-formats.mdx) when the same imported scene needs several targets.