API

Function loadGltf

  • Load a glTF/GLB asset, parse it, and upload mesh + material data to GPU. Registers a deferred PBR renderable builder and automatically parses glTF animations if present.

    Returns an AssetContainer. Pass it to addToScene which adds the hierarchy, registers animation ticks, and applies any scene-level settings.

    The source may be either:

    • A URL (string) — fetches the asset. Supports both binary GLB and separate .gltf + .bin + image files; relative .bin/image paths are resolved against non-blob:/data: URLs. blob: and data: URL strings have no directory base, so they must be self-contained like raw data.
    • Raw data (ArrayBuffer | Blob) — loads from already-loaded local data (drag-and-drop, OPFS, a fetch body, etc.). GLB-vs-glTF is determined from the data's magic bytes, not a file extension. Because raw data has no base URL it must be self-contained: a GLB, or a glTF whose buffers/images use data: URIs. A glTF that references external .bin/image files by relative path can only be loaded from a URL.

    Parameters

    • engine: EngineContext

      The engine to upload GPU resources to.

    • source: string | ArrayBuffer | Blob

      A URL string, or the raw ArrayBuffer/Blob of a self-contained glTF/GLB asset.

    Returns Promise<AssetContainer>