bigwheels icon indicating copy to clipboard operation
bigwheels copied to clipboard

[glTF] Support bufferView stride (interleaved attributes)

Open footballhead opened this issue 1 year ago • 2 comments

The current implementation of GltfLoader::LoadMeshData assumes that each attribute is stored tightly packed. However, glTF allows for interleaved attributes, see 3.6.2. Trying to load interleaved data like it is tightly packed results in garbage output.

BigWheels should support interleaved attributes in order to correctly load models like:

footballhead avatar May 24 '24 22:05 footballhead

A curious case of this is SimpleTexture; the UVs are stored as four triples: (U_1, V_1, 0), (U_2, V_2, 0), (U_3, V_3, 0), (U_4, V_4, 0). If you stride the buffer then you only read the UVs and skip the 0. However, if you don't stride then you read (U_1, V_1), (0, U_2), (V_2, 0), (U_3, V_3)

footballhead avatar May 31 '24 21:05 footballhead

cgltf has a handful of helpers to interface with accessors; they all seem to take stride into account. E.g. cgltf_accessor_read_uint. It might be useful to replace any uses of GetStartAddress() and manual buffer reads with cgltf helpers

footballhead avatar Nov 04 '24 21:11 footballhead