com.unity.cloud.gltfast icon indicating copy to clipboard operation
com.unity.cloud.gltfast copied to clipboard

Add support for loading a glTF from an arbitrary stream

Open sandr01d opened this issue 1 year ago • 0 comments

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 https://github.com/atteneder/glTFast/pull/646, but I'm reopening it here since it was suggested to do so in https://github.com/atteneder/glTFast/issues/650#issuecomment-1757855125.

sandr01d avatar Jan 16 '24 12:01 sandr01d