libassimp
0.4.1

Resolve sidecar files

Load referenced buffers, textures, materials, and layers asynchronously when Assimp asks for them.

Open Markdown

resolve(name) may return bytes, undefined, or a Promise of either. Supplied files are checked first; the resolver handles names not already present.

Fetch over the network

import { convert } from 'libassimp';const entryUrl = new URL('https://assets.example/scene.gltf');const entry = await fetch(entryUrl);const bytes = new Uint8Array(await entry.arrayBuffer());const { files } = await convert(  { name: 'scene.gltf', bytes },  {    to: 'glb',    resolve: async (name) => {      const response = await fetch(new URL(name, entryUrl));      return response.ok ? new Uint8Array(await response.arrayBuffer()) : undefined;    },  },);console.log(files[0].name);

Input

objcube.obj165 B
mtlcube.mtl55 B

Output

Preparing artifact…

Convert
—
Output
—
Files
—
WASM load
—

Returning undefined means unavailable; Assimp decides whether that reference is optional. Throwing or rejecting produces RESOLVE_FAILED with the exact fileName and original cause.

Read from a directory on Node.js

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

const bytes = new Uint8Array(await readFile('models/cube.obj'));
const { files } = await convert(
  { name: 'cube.obj', bytes },
  { to: 'glb', resolve: createDirectoryResolver('models') },
);

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

createDirectoryResolver(root) reads only inside root: absolute names, .. escapes, and symbolic links that leave root resolve as missing. Other I/O errors, such as EACCES, reject and surface as RESOLVE_FAILED.

The consumer callback is invoked once per exact requested name within a conversion. The native backend and JSPI hosts suspend inside parsing; other Wasm hosts transparently replay staged parsing from the settled per-call cache. The public behavior is identical.

Browser-picked files

Files already selected together are simplest as the input array. A directory picker can also populate a Map<string, Uint8Array> and return map.get(name) synchronously. No prefetch is required for sources that support async reads.

On this page