GLB

Last modified by Farooq Sheikh on 2019/10/11 06:07

What is a GLB file?

GLB is the binary file format representation of 3D models saved in the GL Transmission Format (glTF). Information about 3D models such as node hierarchy, cameras, materials, animations and meshes in binary format. This binary format stores the glTF asset (JSON, .bin and images) in a binary blob. It also avoids the issue of increase in file size which happens in case of glTF. GLB file format results in compact file sizes, fast loading, complete 3D scene representation, and extensibility for further development. The format uses model/gltf-binary as MIME type. 

GLB File Format

The content delivery methods used by glTF result in extra processing to decode the base-64 encoded binary data and also increases the file size by ~33%. These delivery methods, which contributed to the formation of GLB file format, include:

  • glTF JSON points to external binary data (geometry, key frames, skins), and images.
  • glTF JSON embeds base64-encoded binary data, and images inline using data URIs.

GLB as a container format was introduced as binary file format for representation of glTF asset in a binary blob to avoid the issues caused by glTF. GLB file format specifications should be referred for any reader/writer implementation of the same for applications development.

File Structure

GLB file format is based on little endian and its structure is as shown below:

GLB File Structure

This shows that:

  • A 12-byte preamble, entitled the header.
  • One or more chunks that contains JSON content and binary data.

Header

The GLB file format header consists of three 4-byte entries:

  • uint32 magic - magic equals 0x46546C67. It is ASCII string glTF, and can be used to identify data as Binary glTF
  • uint32 version - indicates the version of Binary glTF container format
  • uin32 length - the total length of the Binary glTF, including Header and all chunks in bytes

Chunks

Each chunk in a GLB file has the following structure:

uint32uint32ubyte[]
chunkLengthchunkTypechunkData
  • chunkLength - length of chunkData in bytes
  • chunkType - indicates indicates the type of chunk
  • chunkData - binary payload of chunk

where the chunk types are:

 Chunk TypeASCIIDescriptionOccurrences
1.0x4E4F534AJSONStructured JSON content1
2.0x004E4942BINBinary buffer0 or 1

The start and end of each chunk must be aligned to 4-byte boundary and padding should be used for this purpose.

Structured JSON Content

This should be the very first chunk of Binary glTF asset and enables the implementation to progressively retrieve resources from subsequent chunks. This also provides the capability to read only a selected subset of resources from a Binary glTF asset such as the coarsest LOD of a mesh. In order to meet the alignment requirements, this chunk must be padded with trailing Space chars (0x20).

Binary Buffer

This chunk contains the binary payload for geometry, animation key frames, skins, and images. It should be the second chunk of the Binary glTF asset and must be padded with trailing zeros (0x00) to satisfy the alignment requirements.

References

Created by Kashif Iqbal on 2019/09/10 02:56