Search code examples
gltf

How to correctly interpret data from a gltf file?


Data:

pos Accessor { buffer_view: "bufferView_30", byte_offset: 0, byte_stride: 12, component_type: F32, count: 24, kind: Vec3, max: Some([0.5, 0.5, 0.5]), min: Some([-0.5, -0.5, -0.5]), name: None }
pos BufferView { buffer: "BoxTextured", byte_offset: 72, byte_length: 768, target: Some(ArrayBuffer), name: None }
pos Buffer { uri: "BoxTextured.bin", byte_length: 840, kind: Some("arraybuffer"), name: None }

.

normal Accessor { buffer_view: "bufferView_30", byte_offset: 288, byte_stride: 12, component_type: F32, count: 24, kind: Vec3, max: Some([1, 1, 1]), min: Some([-1, -1, -1]), name: None }
normal BufferView { buffer: "BoxTextured", byte_offset: 72, byte_length: 768, target: Some(ArrayBuffer), name: None }
normal Buffer { uri: "BoxTextured.bin", byte_length: 840, kind: Some("arraybuffer"), name: None }

.

uv Accessor { buffer_view: "bufferView_30", byte_offset: 576, byte_stride: 8, component_type: F32, count: 24, kind: Vec2, max: Some([6, 1]), min: Some([0, 0]), name: None }
uv BufferView { buffer: "BoxTextured", byte_offset: 72, byte_length: 768, target: Some(ArrayBuffer), name: None }
uv Buffer { uri: "BoxTextured.bin", byte_length: 840, kind: Some("arraybuffer"), name: None }

.

ind Accessor { buffer_view: "bufferView_29", byte_offset: 0, byte_stride: 0, component_type: U16, count: 36, kind: Scalar, max: None, min: None, name: None }
ind BufferView { buffer: "BoxTextured", byte_offset: 0, byte_length: 72, target: Some(ElementArrayBuffer), name: None }
ind Buffer { uri: "BoxTextured.bin", byte_length: 840, kind: Some("arraybuffer"), name: None }

.

indices [0, 1, 2, 3, 2, 1, 4, 5, 6, 7, 6, 5, 8, 9, 10, 11, 10, 9, 12, 13, 14, 15, 14, 13, 16, 17, 18, 19, 18, 17, 20, 21, 22, 23, 22, 21]

I am trying to load the following sample model.

Position and Normal have a count of 24. They have the format of a Vec3, so it contains 8 Vec3's. That seems correct for a cube. The index count is 36, there are two triangle per face and with 6 faces with have 2 * 3 * 6 = 36. So the indices also seem to be correct.

But why do the texture coordinates have a count of 24? UV's have the format of a Vec2 which means that there are 12 Vec2's. Shouldn't UV's have a count of 16?

Also the indices have a range of 0 to 23. This also doesn't make much sense to me, shouldn't it only go from 0 to 7?


Solution

  • The mistake was that I assumed the count parameter indicated the count of the individual components instead of the complete component type.

    For example the box has 24 position vertices and not just 8.