Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for loading a glTF from an arbitrary stream #10

Closed
wants to merge 2 commits into from

Conversation

sandr01d
Copy link

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).

@sandr01d sandr01d changed the title Stream Add support for loading a glTF from an arbitrary stream Jan 16, 2024
@atteneder
Copy link
Collaborator

@sandr01d Thanks a lot for this contribution!

I've reviewed it and improved it in some aspects internally:

  • Avoids string concatenation (memory garbage) when stream can seek.
  • fix: Proper error with glbs > 2GB in size.
  • fix: Incorrect use of m_Logger.Error.
  • fix: Missed passing on cancellationToken to ReadAsync
  • fix: ReadAsync might not return all requested bytes.
  • Added unit tests.

It'll be merged internally and released soon.

Again, thanks!

@atteneder atteneder closed this Jun 24, 2024
Needle-Mirror-Bot pushed a commit to needle-mirror/com.unity.cloud.gltfast that referenced this pull request Jun 28, 2024
## [6.7.0] - 2024-06-25

### Added
- (Import) Support for [materials variants extension](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_variants).
- Serialization support for material extensions IOR, Sheen and Specular.
- (Import) Ability to load a glTF from a generic `Stream` (`GltfImport.LoadStream`; thanks [sandr01d][sandr01d] for [#10](Unity-Technologies/com.unity.cloud.gltfast#10)).

### Changed
- (Import) Prefabs imported from glTF assets (at design-time) don't have the glTF logo icon assigned to them anymore. This makes it more consistent with other file types (like FBX; fixes [#557](atteneder/glTFast#557)).

### Deprecated
- `MetaMaterialExport`. Always use `MaterialExport.GetDefaultMaterialExport` to get the correct material export.

### Fixed
- (Export) glTFast shader based materials and textures are exported correctly when using the default render pipeline.
- Added missing entries to the API documentation.
- (Export) Base colors are now in correct, linear color space.
- Alpha mode blend now works as expected in HDRP 11 and newer as well (fixes [#699](atteneder/glTFast#699)).
- (Export) Fixed mesh min/max when using Draco compression.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants