Advanced Bun @vulfram/engine@vulfram/gltf-loader

GLTF Loader

This example mirrors the integration flow used in vulfram-engine demos: load GLB bytes, instantiate the entity graph, and dispose resources safely.

What You Will Explore

  • Loading GLB data from disk and feeding it to the loader pipeline.
  • Instantiating imported node hierarchies into the active world.
  • Cleaning up loaded resources and instances during teardown.

Prerequisites

  • A local Bun runtime.
  • An accessible GLB asset file for testing.
  • A bootstrapped Vulfram engine world.

Install

bash
bun add @vulfram/engine @vulfram/transport-bun @vulfram/gltf-loader

Boot snippet (Bun)

ts
import { Mount, World3D, createWindow, initEngine, tick } from '@vulfram/engine';
import { loadGltfAsset } from '@vulfram/gltf-loader';
import { transportBunFfi } from '@vulfram/transport-bun';
import { readFileSync } from 'node:fs';

initEngine({ transport: transportBunFfi });
const { windowId } = createWindow({ title: 'GLTF Loader Demo', size: [1280, 720] });

const worldId = World3D.create3DWorld();
Mount.mountWorld(worldId, { target: { kind: 'window', windowId } });

const data = readFileSync('./assets/treehouse_concept.glb');
const asset = await loadGltfAsset({ worldId, data, materialMode: 'standard' });
const instance = asset.instantiate({
  rootTransform: { position: [0, -1.5, 0], rotation: [0, 0, 0, 1], scale: [1, 1, 1] }
});

let last = performance.now();
function frame(now: number) {
  const dt = now - last;
  last = now;
  tick(now, dt);
  requestAnimationFrame(frame);
}
requestAnimationFrame(frame);

// Later cleanup:
// instance.disposeEntities();
// asset.disposeAll();

// Install:
// bun add @vulfram/engine @vulfram/transport-bun @vulfram/gltf-loader
Live demo canvas