I have this file from Khronos GitHub: https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Box/glTF-Embedded/Box.gltf
In attributes under primitives and under meshes, there are 2 fields which are NORMAL & POSITION: what they refer to? And how to access their data? If i understand the position is a vec3 but where to find the 3 values of the vec3?
The values of the NORMAL and POSITION fields are indices into the
accessors array in the file. Each accessor in turn refers (again via index) to an element of
bufferViews and those refer to a
buffers element. In this case (since it is an embedded gltf file) the vertex data is encoded into the
uri field of the buffer.
Alright, but how to read this (embedded) uri which is encoded in base 64? And what mean the letters A, g, w,…?
Checking the spec section on URIs would tell you that these are encoded according to RFC 2397
You have to decode the data embedded in the URI to make sense of it, but it will decode to binary data, not something that is human readable.
Cool, and if I have a .bin file I have to open it and then read from? If so, How to read from it? I mean is there any standard type of reading this file to get the right values?
How to interpret the contents of an external file (i.e. one referred to by the
uri property of a
buffer) is defined by the
bufferView. There’s no headers or anything else specified about the external files’ contents, they simply store binary data and the .gltf file determines how it must be interpreted.
The same byte range of an external file could even be interpreted in two different ways by different accessors/bufferViews - although that is probably very rare in practice.
Great, so I have to store all the data (in .bin) in a C++ vector, for example, and then use the byteOfset, byteStride… to access the right data? Is it correct? I really understood how .gltf file works but I struggle how to render the vertices in other terms, I struggle how to get the position, normal and tangent values so I can render the model. I want to get the values (x,y and z coordinates). In my opinion, I have to open the file in a read binary mode, then store all the data in a vector then access them according to byteOffset and byteStride. This is what I think. Do you agree? And are there some other advices to give me. I really appreciate you help
Yeah, that is the gist of it.
Details about how you get the contents of the external files into memory could be done differently (e.g. you could memory map the files), but that does not change how you go about interpreting those bytes.