gltfpack: Deindex meshes with abnormally large vertex accessors #885
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.
If the index buffer is much smaller than vertex accessors, and vertex accessors
are shared, we end up re-unpacking the accessors repeatedly and producing huge
meshes that are inefficient for the rest of the processing pipeline.
This change detects these cases and switches to reading the individual elements
according to the index buffer, producing an unindexed mesh; the rest of the
processing will re-index it again.
For some extreme cases this may result in significant improvements in parsing and
processing time; the mesh from #884 could not be converted before this change,
and with this change it takes just 0.3s to do so.
Before settling on the approach here, I've also tried trimming the index buffers to
their min..max range and extracting an associated subrange from the accessors;
this worked but only got the problematic model down to 30s of conversion time
because many indices spanned a large range. Doing an early reindexing in this case
got this down to ~3s, but it still felt too long and too complicated, whereas this
approach generically solves this issue.
This relies on support for sparse accessors in cgltf_accessor_read functions,
which also fixes interaction between sparse accessors and parsing files with GPU
instancing extension; the patch has been submitted separately as jkuhlmann/cgltf#273.
Fixes #884.