Skip to content
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

Add support for sparse accessors #12379

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

javagl
Copy link
Contributor

@javagl javagl commented Dec 18, 2024

Opening this as a draft for addressing #10284

Description

The cx20 gltf-test repo is an invaluable resource for checking the compatibility of glTF viewers with the glTF specification. CesiumJS is among the ones with the larger number of ✅'s. But there is still that SimpleSparseAccessor example, which uses a pretty fundamental glTF concept - namely, sparse accessors - that shows a ❌...

This PR is a DRAFT, and the state is kinda messy, but it already loads that sample:

Cesium Sparse 0001

A summary:

A sparse accessor is an accessor that has a sparse property. The sparse object contains two objects, namely indices and values. These are actually "small accessors": They refer to a bufferView and have a byteOffset, one has a componentType. The type is taken from the containing accessor.

The loadFromBufferView function of GltfVertexBufferLoader checks whether the accessor whose data is supposed to be loaded has the sparse property. If it does, then it calls handleSparseAccessor, which does the main work:

  • The function calls a new function loadDependencyBufferViewTypedArray which loads the required buffer views for the indices and values
  • These buffer views are used for creating typed arrays of the indices and values. (This is a bit quirky - see notes below...)
  • The handleSparseAccessor finally performs the sparse substitution. It just writes the substituted values into the typed array of the original accessor data. The pseudocode for that is just accessorData[indices[i]] = values[i].

TODO:

The functionality for creating typed arrays from buffer views (based on "accessor information") is required elsewhere - namely, for standard index- and attribute accessors After all, the indices and values from the sparse object basically are just "accessors". For now, I just added some helper functions like GltfIndexBufferLoader.createIndicesTypedArrayFromBufferViewTypedArray for that 🤪 It's not clear what could be the best place for offering these. They could be standalone functions, or maybe 'static' functions in GltfLoader ...?

Beyond that: Tests, tests, tests, comments, comments, comments, ....

Issue number and link

#10284

Testing plan

Load the SimpleSparseAccessor model (and other models with sparse accessors), and check that they are displayed properly.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

Copy link

Thank you for the pull request, @javagl!

✅ We can confirm we have a CLA on file for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant