From 07c6e6a6edf08b344c4f56f762fd3a6524029009 Mon Sep 17 00:00:00 2001 From: danwillm <39023874+danwillm@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:35:42 +0100 Subject: [PATCH 1/2] Don't write empty buffers --- src/gltf/GltfModel.hpp | 9 +++++++-- src/gltf/properties/BufferData.cpp | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gltf/GltfModel.hpp b/src/gltf/GltfModel.hpp index 0c4f40e..726e010 100644 --- a/src/gltf/GltfModel.hpp +++ b/src/gltf/GltfModel.hpp @@ -191,9 +191,14 @@ class GltfModel { if (!holder.ptrs.empty()) { std::vector bits; for (const auto& ptr : holder.ptrs) { - bits.push_back(ptr->serialize()); + json bit = ptr->serialize(); + if (!bit.empty()) { + bits.push_back(ptr->serialize()); + } + } + if (!bits.empty()) { + glTFJson[key] = bits; } - glTFJson[key] = bits; } } diff --git a/src/gltf/properties/BufferData.cpp b/src/gltf/properties/BufferData.cpp index b4394e9..0f1787b 100644 --- a/src/gltf/properties/BufferData.cpp +++ b/src/gltf/properties/BufferData.cpp @@ -20,6 +20,10 @@ BufferData::BufferData( : Holdable(), isGlb(false), uri(isEmbedded ? "" : std::move(uri)), binData(binData) {} json BufferData::serialize() const { + if (binData->size() == 0) { + return json{}; + } + json result{{"byteLength", binData->size()}}; if (!isGlb) { if (!uri.empty()) { From 09f6869ac20089ba904a3d1441bc691603fdbb86 Mon Sep 17 00:00:00 2001 From: danwillm <39023874+danwillm@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:00:34 +0100 Subject: [PATCH 2/2] use empty instead of size --- src/gltf/properties/BufferData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gltf/properties/BufferData.cpp b/src/gltf/properties/BufferData.cpp index 0f1787b..317c119 100644 --- a/src/gltf/properties/BufferData.cpp +++ b/src/gltf/properties/BufferData.cpp @@ -20,7 +20,7 @@ BufferData::BufferData( : Holdable(), isGlb(false), uri(isEmbedded ? "" : std::move(uri)), binData(binData) {} json BufferData::serialize() const { - if (binData->size() == 0) { + if (binData->empty()) { return json{}; }