From d01d1090376739213766148cab7480c668ae3114 Mon Sep 17 00:00:00 2001 From: Yejneshwar <81953958+Yejneshwar@users.noreply.github.com> Date: Wed, 4 Sep 2024 01:37:24 +0530 Subject: [PATCH] Ability to flush a GLB manifest to a stream (#143) --- GLTFSDK/Inc/GLTFSDK/GLBResourceWriter.h | 3 +++ GLTFSDK/Inc/GLTFSDK/GLTFResourceWriter.h | 1 + GLTFSDK/Inc/GLTFSDK/PBRUtils.h | 1 + GLTFSDK/Inc/GLTFSDK/ResourceReaderUtils.h | 1 + GLTFSDK/Source/GLBResourceWriter.cpp | 14 ++++++++++++-- GLTFSDK/Source/Validation.cpp | 2 ++ GLTFSDK/Source/Version.cpp | 1 + 7 files changed, 21 insertions(+), 2 deletions(-) diff --git a/GLTFSDK/Inc/GLTFSDK/GLBResourceWriter.h b/GLTFSDK/Inc/GLTFSDK/GLBResourceWriter.h index 06f2a1e..19d9aa0 100644 --- a/GLTFSDK/Inc/GLTFSDK/GLBResourceWriter.h +++ b/GLTFSDK/Inc/GLTFSDK/GLBResourceWriter.h @@ -20,6 +20,9 @@ namespace Microsoft GLBResourceWriter(std::unique_ptr streamCache); GLBResourceWriter(std::unique_ptr streamCache, std::unique_ptr tempBufferStream); + // Write to a stream instead of a file (can be useful for draco compression) + template + void FlushStream(const std::string& manifest, T* stream); void Flush(const std::string& manifest, const std::string& uri); std::string GenerateBufferUri(const std::string& bufferId) const override; std::ostream* GetBufferStream(const std::string& bufferId) override; diff --git a/GLTFSDK/Inc/GLTFSDK/GLTFResourceWriter.h b/GLTFSDK/Inc/GLTFSDK/GLTFResourceWriter.h index 9c706d4..111826e 100644 --- a/GLTFSDK/Inc/GLTFSDK/GLTFResourceWriter.h +++ b/GLTFSDK/Inc/GLTFSDK/GLTFResourceWriter.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include diff --git a/GLTFSDK/Inc/GLTFSDK/PBRUtils.h b/GLTFSDK/Inc/GLTFSDK/PBRUtils.h index 3105c7d..c5a191a 100644 --- a/GLTFSDK/Inc/GLTFSDK/PBRUtils.h +++ b/GLTFSDK/Inc/GLTFSDK/PBRUtils.h @@ -5,6 +5,7 @@ #include #include +#include namespace Microsoft { diff --git a/GLTFSDK/Inc/GLTFSDK/ResourceReaderUtils.h b/GLTFSDK/Inc/GLTFSDK/ResourceReaderUtils.h index b02a7c4..248c66c 100644 --- a/GLTFSDK/Inc/GLTFSDK/ResourceReaderUtils.h +++ b/GLTFSDK/Inc/GLTFSDK/ResourceReaderUtils.h @@ -8,6 +8,7 @@ #include #include #include +#include namespace Microsoft { diff --git a/GLTFSDK/Source/GLBResourceWriter.cpp b/GLTFSDK/Source/GLBResourceWriter.cpp index 9d3b934..4200098 100644 --- a/GLTFSDK/Source/GLBResourceWriter.cpp +++ b/GLTFSDK/Source/GLBResourceWriter.cpp @@ -4,6 +4,7 @@ #include #include +#include using namespace Microsoft::glTF; @@ -42,7 +43,8 @@ GLBResourceWriter::GLBResourceWriter(std::unique_ptr streamC { } -void GLBResourceWriter::Flush(const std::string& manifest, const std::string& uri) +template +void GLBResourceWriter::FlushStream(const std::string& manifest, T* stream) { uint32_t jsonChunkLength = static_cast(manifest.length()); const uint32_t jsonPaddingLength = ::CalculatePadding(jsonChunkLength); @@ -59,7 +61,6 @@ void GLBResourceWriter::Flush(const std::string& manifest, const std::string& ur + sizeof(binaryChunkLength) + GLB_CHUNK_TYPE_SIZE // 8 bytes (BIN header) + binaryChunkLength; - auto stream = m_streamWriterCache->Get(uri); // Write GLB header (12 bytes) StreamUtils::WriteBinary(*stream, GLB_HEADER_MAGIC_STRING, GLB_HEADER_MAGIC_STRING_SIZE); @@ -96,6 +97,15 @@ void GLBResourceWriter::Flush(const std::string& manifest, const std::string& ur } } +template void GLBResourceWriter::FlushStream(const std::string& manifest, std::fstream* stream); +template void GLBResourceWriter::FlushStream(const std::string& manifest, std::stringstream* stream); + +void GLBResourceWriter::Flush(const std::string& manifest, const std::string& uri) +{ + auto stream = m_streamWriterCache->Get(uri); + this->FlushStream(manifest, stream.get()); +} + std::string GLBResourceWriter::GenerateBufferUri(const std::string& bufferId) const { std::string bufferUri; diff --git a/GLTFSDK/Source/Validation.cpp b/GLTFSDK/Source/Validation.cpp index f081fac..d79df15 100644 --- a/GLTFSDK/Source/Validation.cpp +++ b/GLTFSDK/Source/Validation.cpp @@ -7,6 +7,8 @@ #include +#include + using namespace Microsoft::glTF; namespace diff --git a/GLTFSDK/Source/Version.cpp b/GLTFSDK/Source/Version.cpp index 87a5315..0db0593 100644 --- a/GLTFSDK/Source/Version.cpp +++ b/GLTFSDK/Source/Version.cpp @@ -8,6 +8,7 @@ #include #include #include +#include using namespace Microsoft::glTF;