GLTF: Fix nasty bug with incorrect buffer indices on export #108302
+79
−80
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.
I was writing some code with the GLTF module when I noticed that the buffer indices inside of each buffer view was just... completely and totally wrong at export time. Each buffer view had its buffer index set to its own buffer view index.
The problem was caused by this line of code:
This line is utter nonsense. The
bv->buffer
is a buffer index, not a buffer view index. Ther_accessor
is actually a buffer view index... but it's incorrectly named, so I've also fixed that in this PR.This bug was hidden thanks to this loop in the export code:
This code effectively says... ignore the data in the buffer view, use index 0 always instead. That's just... so bad. Complete and utter nonsense. It completely breaks using any buffer other than 0 and breaks all intermediate export code that tries to take a look at what the buffer view's buffer is.
I also renamed
_encode_buffer_view
to_encode_accessor_into_buffer_view
because it's not just buffer views, it also deals heavily with accessor stuff. I also fixed a bug where 16-bitMAT3
s were being misaligned (MAT3
is used by nothing in glTF so it went unnoticed until I combed over this code). Also, I improved the comments.