Add support for sparse accessors #12379
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thatSimpleSparseAccessor
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:
A summary:
A sparse accessor is an accessor that has a
sparse
property. Thesparse
object contains two objects, namelyindices
andvalues
. These are actually "small accessors": They refer to abufferView
and have abyteOffset
, one has acomponentType
. The type is taken from the containing accessor.The
loadFromBufferView
function ofGltfVertexBufferLoader
checks whether the accessor whose data is supposed to be loaded has thesparse
property. If it does, then it callshandleSparseAccessor
, which does the main work:loadDependencyBufferViewTypedArray
which loads the required buffer views for the indices and valueshandleSparseAccessor
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 justaccessorData[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
andvalues
from thesparse
object basically are just "accessors". For now, I just added some helper functions likeGltfIndexBufferLoader.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 inGltfLoader
...?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
CONTRIBUTORS.md
CHANGES.md
with a short summary of my change