Add support for loading a glTF from an arbitrary stream #10
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've mostly kept the existing implementation of
GltfImport.LoadFile()
, but modified it to support any kind of stream (as long as the stream is readable). While loading from a file stream does probably cover most use cases, being able to load from any kind of stream does offer some benefints, e.g. when loading a glTF from a MemoryStream that is already in memory. My personal use case is loading a glTF from a zip archive's DeflateStream directly without having to decrompress the entire file first.There is a slight downside with this new implementation: the parsing of the JSON string can not be cancelled. A override of
StreamReader.ReadToEndAsync()
that takes a cancellation token exists in .NET 7, but I guess it will take a while until Unity catches up with that. That being said, I think that shouldn't be an issue, as glTFast parses JSON very fast and we can still cancel before starting to parse binary data.I've originally opened a PR in atteneder#646, but I'm reopening it here since it was suggested to do so in atteneder#650 (comment).