Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gboisse opened this issue Mar 5, 2025 · 4 comments
Open
Assignees
Milestone

Comments

@gboisse
Copy link

gboisse commented Mar 5, 2025

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.

@lexaknyazev
Copy link
Member

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 lexaknyazev added this to the 2.0.x milestone Mar 5, 2025
@lexaknyazev lexaknyazev self-assigned this Mar 5, 2025
@javagl
Copy link
Contributor

javagl commented Mar 5, 2025

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")

@gboisse
Copy link
Author

gboisse commented Mar 5, 2025

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 gboisse closed this as completed Mar 5, 2025
@lexaknyazev
Copy link
Member

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

@lexaknyazev lexaknyazev reopened this Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants