glTF icon indicating copy to clipboard operation
glTF copied to clipboard

Question regarding accessor's byte offset when sparse data is available

Open gboisse opened this issue 1 year ago • 4 comments

I have been trying to figure that one out from the specifications but I can't seem to quite confirm the expected behaviour here for a glTF importer.

Currently, I apply the byte offset property from the accessor to both the "regular" data and the sparse data, like so:

buffer.m_data = gltfBuffer.data.data() + gltfBufferView.byteOffset + gltfAccessor.byteOffset;
buffer.m_sparseData = gltfSparseBuffer.data.data() + gltfSparseBufferView.byteOffset + gltfAccessor.byteOffset;

Is this correct? or is the byte offset property only meant to be applied to the "regular" data pointer? I couldn't find any glTF sample file so far that'd have non-zero byte offsets while using sparse accessors.

gboisse avatar Mar 05 '25 12:03 gboisse

The accessor.byteOffset is applied only to the data from accessor.bufferView (if the latter is used). The sparse data structure has dedicated offsets - accessor.sparse.indices.byteOffset and accessor.sparse.values.byteOffset - for sparse indices and values respectively.

lexaknyazev avatar Mar 05 '25 12:03 lexaknyazev

I found it helpful to think of accessor.sparse.indices and accessor.sparse.values as being "instances of the type Accessor": They define the data layout of a part of a buffer view. And as such, they contain everything that an accessor contains, and are somewhat independent of the accessor that contains them.

(Yes, the values essentially inherit the component type from the containing one, and of course they cannot contain further sparse accessors on their own - but on an abstract level, they are "the same data structure as an accessor")

javagl avatar Mar 05 '25 13:03 javagl

Thanks both for the quick answers and clarification 🙂

Having a glTF sample file with non-zero byte offsets for the sparse index and value buffers would be quite useful to catch these, but closing this issue now as my problem is resolved.

gboisse avatar Mar 05 '25 14:03 gboisse

Let's keep it open because it's worth adjusting the spec language a bit.

lexaknyazev avatar Mar 05 '25 14:03 lexaknyazev