From 81f7dbe53a112d05217a79bb1c986f9ada3b6631 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Tue, 2 Aug 2022 01:05:34 +0900 Subject: [PATCH 1/3] Partial fix of issue 365 --- tiny_gltf.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 59756e9..234e831 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1424,6 +1424,10 @@ class TinyGLTF { bool preserve_image_channels_ = false; /// Default false(expand channels to /// RGBA) for backward compatibility. + // Warning & error messages + std::string warn_; + std::string err_; + FsCallbacks fs = { #ifndef TINYGLTF_NO_FS &tinygltf::FileExists, &tinygltf::ExpandFilePath, @@ -7525,7 +7529,7 @@ static bool WriteGltfFile(const std::string &output, return WriteGltfStream(gltfFile, content); } -static void WriteBinaryGltfStream(std::ostream &stream, +static bool WriteBinaryGltfStream(std::ostream &stream, const std::string &content, const std::vector &binBuffer) { const std::string header = "glTF"; @@ -7579,9 +7583,12 @@ static void WriteBinaryGltfStream(std::ostream &stream, std::streamsize(padding.size())); } } + + // TODO: Check error on stream.write + return true; } -static void WriteBinaryGltfFile(const std::string &output, +static bool WriteBinaryGltfFile(const std::string &output, const std::string &content, const std::vector &binBuffer) { #ifdef _WIN32 @@ -7599,7 +7606,7 @@ static void WriteBinaryGltfFile(const std::string &output, #else std::ofstream gltfFile(output.c_str(), std::ios::binary); #endif - WriteBinaryGltfStream(gltfFile, content, binBuffer); + return WriteBinaryGltfStream(gltfFile, content, binBuffer); } bool TinyGLTF::WriteGltfSceneToStream(Model *model, std::ostream &stream, @@ -7647,12 +7654,11 @@ bool TinyGLTF::WriteGltfSceneToStream(Model *model, std::ostream &stream, } if (writeBinary) { - WriteBinaryGltfStream(stream, JsonToString(output), binBuffer); + return WriteBinaryGltfStream(stream, JsonToString(output), binBuffer); } else { - WriteGltfStream(stream, JsonToString(output, prettyPrint ? 2 : -1)); + return WriteGltfStream(stream, JsonToString(output, prettyPrint ? 2 : -1)); } - return true; } bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename, @@ -7737,12 +7743,11 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename, } if (writeBinary) { - WriteBinaryGltfFile(filename, JsonToString(output), binBuffer); + return WriteBinaryGltfFile(filename, JsonToString(output), binBuffer); } else { - WriteGltfFile(filename, JsonToString(output, (prettyPrint ? 2 : -1))); + return WriteGltfFile(filename, JsonToString(output, (prettyPrint ? 2 : -1))); } - return true; } } // namespace tinygltf From 0b31543098a9827aeb723304bd902efe5e995f13 Mon Sep 17 00:00:00 2001 From: feiy Date: Sat, 13 Aug 2022 10:08:17 +0800 Subject: [PATCH 2/3] Adding serialization code for sparse accessors. --- tiny_gltf.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tiny_gltf.h b/tiny_gltf.h index 234e831..ce7248e 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -6693,6 +6693,27 @@ static void SerializeGltfAccessor(Accessor &accessor, json &o) { if (accessor.extras.Type() != NULL_TYPE) { SerializeValue("extras", accessor.extras, o); } + + // sparse + if (accessor.sparse.isSparse) + { + json sparse; + SerializeNumberProperty("count", accessor.sparse.count, sparse); + { + json indices; + SerializeNumberProperty("bufferView", accessor.sparse.indices.bufferView, indices); + SerializeNumberProperty("byteOffset", accessor.sparse.indices.byteOffset, indices); + SerializeNumberProperty("componentType", accessor.sparse.indices.componentType, indices); + JsonAddMember(sparse, "indices", std::move(indices)); + } + { + json values; + SerializeNumberProperty("bufferView", accessor.sparse.values.bufferView, values); + SerializeNumberProperty("byteOffset", accessor.sparse.values.bufferView, values); + JsonAddMember(sparse, "values", std::move(values)); + } + JsonAddMember(o, "sparse", std::move(sparse)); + } } static void SerializeGltfAnimationChannel(AnimationChannel &channel, json &o) { From 1a8814d687b52e26901d65506c3c23f720a5c813 Mon Sep 17 00:00:00 2001 From: feiy Date: Sun, 14 Aug 2022 19:49:07 +0800 Subject: [PATCH 3/3] Sparse accessor serialization: typo fix. --- tiny_gltf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index ce7248e..8964be5 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -6709,7 +6709,7 @@ static void SerializeGltfAccessor(Accessor &accessor, json &o) { { json values; SerializeNumberProperty("bufferView", accessor.sparse.values.bufferView, values); - SerializeNumberProperty("byteOffset", accessor.sparse.values.bufferView, values); + SerializeNumberProperty("byteOffset", accessor.sparse.values.byteOffset, values); JsonAddMember(sparse, "values", std::move(values)); } JsonAddMember(o, "sparse", std::move(sparse));