From 51e5508fa02f679b9db052554b55bb2de2c39496 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sun, 9 Aug 2020 21:18:28 +0900 Subject: [PATCH 1/3] Add note on `sajson` branch. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e9b4134..830ef29 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ `TinyGLTF` is a header only C++11 glTF 2.0 https://github.com/KhronosGroup/glTF library. `TinyGLTF` uses Niels Lohmann's json library(https://github.com/nlohmann/json), so now it requires C++11 compiler. -If you are looking for old, C++03 version, please use `devel-picojson` branch. +If you are looking for old, C++03 version, please use `devel-picojson` branch(but not maintained anymore). ## Status @@ -13,6 +13,10 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch. - v2.1.0 release(Draco support) - v2.0.0 release(22 Aug, 2018)! +### Branches + +* `sajson` : Use sajson to parse JSON. Parsing only but faster compile time(2x reduction compared to json.hpp and RapidJson) + ## Builds [![Build Status](https://travis-ci.org/syoyo/tinygltf.svg?branch=devel)](https://travis-ci.org/syoyo/tinygltf) From 68adc4ba5eadff5a9ab8f98f32bece1e788f8a15 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 22 Oct 2020 22:27:12 +0900 Subject: [PATCH 2/3] Serialize empty JSON object when material has all default parameters. Fixes #294 . --- tests/tester.cc | 22 ++++++++++++++++++++++ tiny_gltf.h | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/tests/tester.cc b/tests/tester.cc index 012b54d..bc5f819 100644 --- a/tests/tester.cc +++ b/tests/tester.cc @@ -412,6 +412,28 @@ TEST_CASE("image-uri-spaces", "[issue-236]") { REQUIRE(true == ret); } +TEST_CASE("serialize-empty-material", "[issue-294]") { + + tinygltf::Model m; + + tinygltf::Material mat; + mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 1.0f, 1.0f, 1.0f}; // default baseColorFactor + m.materials.push_back(mat); + + std::stringstream os; + + tinygltf::TinyGLTF ctx; + ctx.WriteGltfSceneToStream(&m, os, false, false); + + // use nlohmann json(included inside of tiny_gltf.h) + json j = json::parse(os.str()); + + REQUIRE(1 == j["materials"].size()); + REQUIRE(j["asset"].is_null()); + REQUIRE(j["materials"][0].is_object()); + +} + #ifndef TINYGLTF_NO_FS TEST_CASE("expandpath-utf-8", "[pr-226]") { diff --git a/tiny_gltf.h b/tiny_gltf.h index 88e1093..00875f0 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -26,6 +26,7 @@ // THE SOFTWARE. // Version: +// - v2.4.3 Fix null object output when when material has all default parameters. // - v2.4.2 Decode percent-encoded URI. // - v2.4.1 Fix some glTF object class does not have `extensions` and/or // `extras` property. @@ -7225,6 +7226,15 @@ static void SerializeGltfModel(Model *model, json &o) { for (unsigned int i = 0; i < model->materials.size(); ++i) { json material; SerializeGltfMaterial(model->materials[i], material); + + if (JsonIsNull(material)) { + // Issue 294. + // `material` does not have any required parameters + // so the result may be null(unmodified) when all material parameters have default value. + // + // null is not allowed thus we create an empty JSON object. + JsonSetObject(material); + } JsonPushBack(materials, std::move(material)); } JsonAddMember(o, "materials", std::move(materials)); From 1923067982e2ba28bfd0bc60c746359d61351d7d Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 22 Oct 2020 22:38:56 +0900 Subject: [PATCH 3/3] Fix build when using RapidJSON backend. --- tests/tester.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/tester.cc b/tests/tester.cc index bc5f819..e0a174b 100644 --- a/tests/tester.cc +++ b/tests/tester.cc @@ -3,6 +3,9 @@ #define STB_IMAGE_WRITE_IMPLEMENTATION #include "tiny_gltf.h" +// Nlohmann json(include ../json.hpp) +#include "json.hpp" + #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include "catch.hpp" @@ -425,8 +428,8 @@ TEST_CASE("serialize-empty-material", "[issue-294]") { tinygltf::TinyGLTF ctx; ctx.WriteGltfSceneToStream(&m, os, false, false); - // use nlohmann json(included inside of tiny_gltf.h) - json j = json::parse(os.str()); + // use nlohmann json + nlohmann::json j = nlohmann::json::parse(os.str()); REQUIRE(1 == j["materials"].size()); REQUIRE(j["asset"].is_null());