GLTFLoader: Respect file contents length defined in header #21122
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.
Related issue: --
Description
Right now GLTFLoader assumes the entire buffer makes up the contents of the file when parsing chunks in processing a binary GLTF but that can cause problems when the length defined in the GLTF header is different that the remaining size of the buffer.
I found this when helping a user in NASA-AMMOS/3DTilesRendererJS#153 load a 3d tile set and found that the B3DM files (spec), which seem to define the GLTF buffer as being 4 bytes longer than the inner GLTF header does, were failing to load. In the referenced issue the B3DM files are further packed into a CMPT file (spec), as well.
The files load correctly without error in Cesium and it parses them the same way resulting in the 4 extra bytes in the buffer. However when parsing the file contents Cesium uses the header length to iterate over the buffer chunks rather than the remaining array length, which seems like a more correct interpretation of the spec:
https://github.com/CesiumGS/cesium/blob/master/Source/ThirdParty/GltfPipeline/parseGlb.js#L83-L87
cc @donmccurdy