Luca
Luca

Reputation: 41

Are the position, normals, texcoords and other such attributes of a gltf 3D model always found in the same buffer?

I have recently started studying gltf files so forgive me if this question seems silly. If the position texcoords etc. are found in the same buffer I have no problem parsing the file and displaying the model in the c++ program I made. But if they can be stored in different buffer then my code logic won't work. I've been looking through some samples of 3d models stored in gltf files and this thought struck me but I couldn't find any files that store such attributes in different buffer so I thought maybe they can't be stored in different buffers.

Upvotes: 2

Views: 551

Answers (1)

Don McCurdy
Don McCurdy

Reputation: 11970

In glTF terminology, a Buffer is a unit of storage or transmission, and could be an external .bin file or embedded in a GLB. Buffers contain all binary data in the file – including e.g. animation keyframes, which you probably don't want to upload to the GPU.

Each Buffer will contain one or more "Buffer Views", and those are the appropriate structure to upload to the GPU. A buffer view containing vertex attributes is guaranteed not to contain other types of data. But the vertex attributes for a single mesh might be split into more than one buffer view. There are a few reasons, like compression, this might be the right choice. See: Buffers and Buffer Views.

If you need to guarantee your glTF files follow a specific vertex buffer layout, I'd recommend pre-processing the files with a tool like gltfpack or gltf-transform.

Upvotes: 2

Related Questions