@matthewcpp/binary-gltf
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

binary-gltf

Simpe library for working with binary glTF files.

The library exposes a single parse method that takes an ArrayBuffer of a GLB file and returns an object with the following structure:

{
    json: Object,
    binary: DataView,
    extras: [
        {
            type: number,
            view: DataView
        }
    ]
}

If any error is encountered during parsing, an exception will be thrown.

Usage

Example use in browser (rollup):

import {BinaryGltf} from "@matthewcpp/binary-gltf";

try {
    const response = await fetch(url);
    const buffer = await response.arrayBuffer();
    const binaryGltf = BinaryGltf.parse(buffer);
} catch (e) {
    console.log(e.toString());
}

Example use in NodeJS:

const { BinaryGltf } = require("@matthewcpp/binary-gltf");
const fs = require("fs");

try {
    const data = fs.readFileSync(filePath);
    const binaryGltf = BinaryGltf.parse(data.buffer);
} catch (e) {
    console.log(e.toString());
}

Testing

  1. Build the library by running npm run build
  2. Test Browser usage: npm run test-web
  3. Test NodeJs usage: npm run test-node

Readme

Keywords

Package Sidebar

Install

npm i @matthewcpp/binary-gltf

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

11.4 kB

Total Files

9

Last publish

Collaborators

  • matthewcpp