diff --git a/src/ObjCommon/XModel/Gltf/JsonGltf.h b/src/ObjCommon/XModel/Gltf/JsonGltf.h index 91315e67..fe081504 100644 --- a/src/ObjCommon/XModel/Gltf/JsonGltf.h +++ b/src/ObjCommon/XModel/Gltf/JsonGltf.h @@ -325,21 +325,21 @@ namespace gltf class JsonRoot { public: - std::optional> accessors; - std::optional> animations; JsonAsset asset; - std::optional> buffers; - std::optional> bufferViews; - std::optional> images; - std::optional> materials; - std::optional> meshes; - std::optional> nodes; - std::optional> skins; std::optional scene; std::optional> scenes; + std::optional> nodes; + std::optional> animations; + std::optional> materials; + std::optional> meshes; std::optional> textures; + std::optional> images; + std::optional> skins; + std::optional> accessors; + std::optional> bufferViews; + std::optional> buffers; }; NLOHMANN_DEFINE_TYPE_EXTENSION( - JsonRoot, accessors, animations, asset, buffers, bufferViews, images, materials, meshes, nodes, skins, scene, scenes, textures); + JsonRoot, asset, scene, scenes, nodes, animations, materials, meshes, textures, images, skins, accessors, bufferViews, buffers); } // namespace gltf diff --git a/src/ObjWriting/XModel/Gltf/GltfBinOutput.cpp b/src/ObjWriting/XModel/Gltf/GltfBinOutput.cpp index 1f01b24e..7b5320e0 100644 --- a/src/ObjWriting/XModel/Gltf/GltfBinOutput.cpp +++ b/src/ObjWriting/XModel/Gltf/GltfBinOutput.cpp @@ -33,7 +33,7 @@ std::optional BinOutput::CreateBufferUri(const void* buffer, size_t return std::nullopt; } -void BinOutput::EmitJson(const nlohmann::json& json) const +void BinOutput::EmitJson(const nlohmann::ordered_json& json) const { static constexpr uint32_t ZERO = 0u; diff --git a/src/ObjWriting/XModel/Gltf/GltfBinOutput.h b/src/ObjWriting/XModel/Gltf/GltfBinOutput.h index 91eacc75..d333ebd9 100644 --- a/src/ObjWriting/XModel/Gltf/GltfBinOutput.h +++ b/src/ObjWriting/XModel/Gltf/GltfBinOutput.h @@ -12,7 +12,7 @@ namespace gltf explicit BinOutput(std::ostream& stream); std::optional CreateBufferUri(const void* buffer, size_t bufferSize) const override; - void EmitJson(const nlohmann::json& json) const override; + void EmitJson(const nlohmann::ordered_json& json) const override; void EmitBuffer(const void* buffer, size_t bufferSize) const override; void Finalize() const override; diff --git a/src/ObjWriting/XModel/Gltf/GltfOutput.h b/src/ObjWriting/XModel/Gltf/GltfOutput.h index 8cc7a3da..eafd5b2e 100644 --- a/src/ObjWriting/XModel/Gltf/GltfOutput.h +++ b/src/ObjWriting/XModel/Gltf/GltfOutput.h @@ -18,7 +18,7 @@ namespace gltf public: virtual std::optional CreateBufferUri(const void* buffer, size_t bufferSize) const = 0; - virtual void EmitJson(const nlohmann::json& json) const = 0; + virtual void EmitJson(const nlohmann::ordered_json& json) const = 0; virtual void EmitBuffer(const void* buffer, size_t bufferSize) const = 0; virtual void Finalize() const = 0; }; diff --git a/src/ObjWriting/XModel/Gltf/GltfTextOutput.cpp b/src/ObjWriting/XModel/Gltf/GltfTextOutput.cpp index c80a72f9..402deff8 100644 --- a/src/ObjWriting/XModel/Gltf/GltfTextOutput.cpp +++ b/src/ObjWriting/XModel/Gltf/GltfTextOutput.cpp @@ -32,7 +32,7 @@ std::optional TextOutput::CreateBufferUri(const void* buffer, const return output; } -void TextOutput::EmitJson(const nlohmann::json& json) const +void TextOutput::EmitJson(const nlohmann::ordered_json& json) const { m_stream << std::setw(4) << json; } diff --git a/src/ObjWriting/XModel/Gltf/GltfTextOutput.h b/src/ObjWriting/XModel/Gltf/GltfTextOutput.h index d6b9d7b9..4fe847e7 100644 --- a/src/ObjWriting/XModel/Gltf/GltfTextOutput.h +++ b/src/ObjWriting/XModel/Gltf/GltfTextOutput.h @@ -12,7 +12,7 @@ namespace gltf explicit TextOutput(std::ostream& stream); std::optional CreateBufferUri(const void* buffer, size_t bufferSize) const override; - void EmitJson(const nlohmann::json& json) const override; + void EmitJson(const nlohmann::ordered_json& json) const override; void EmitBuffer(const void* buffer, size_t bufferSize) const override; void Finalize() const override; diff --git a/src/ObjWriting/XModel/Gltf/GltfWriter.cpp b/src/ObjWriting/XModel/Gltf/GltfWriter.cpp index b3576ed0..7dc5a564 100644 --- a/src/ObjWriting/XModel/Gltf/GltfWriter.cpp +++ b/src/ObjWriting/XModel/Gltf/GltfWriter.cpp @@ -98,7 +98,7 @@ namespace FillBufferData(gltf, xmodel, bufferData); CreateBuffer(gltf, xmodel, bufferData); - const json jRoot = gltf; + const ordered_json jRoot = gltf; m_output->EmitJson(jRoot); if (!bufferData.empty()) diff --git a/src/Utils/Json/JsonExtension.h b/src/Utils/Json/JsonExtension.h index 7f2b761b..b7040d92 100644 --- a/src/Utils/Json/JsonExtension.h +++ b/src/Utils/Json/JsonExtension.h @@ -14,17 +14,19 @@ // partial specialization (full specialization works too) namespace nlohmann { - template void optional_to_json(nlohmann::json& j, const char* name, const std::optional& value) + template::value, int> = 0> + void optional_to_json(BasicJsonType& j, const char* name, const std::optional& value) { if (value) j[name] = *value; } - template void optional_from_json(const nlohmann::json& j, const char* name, std::optional& value) + template::value, int> = 0> + void optional_from_json(const BasicJsonType& j, const char* name, std::optional& value) { const auto it = j.find(name); if (it != j.end() && !it->is_null()) - value = it->get(); + value = it->template get(); else value = std::nullopt; } @@ -32,7 +34,8 @@ namespace nlohmann template constexpr bool is_optional = false; template constexpr bool is_optional> = true; - template void extended_to_json(const char* key, nlohmann::json& j, const T& value) + template::value, int> = 0> + void extended_to_json(const char* key, BasicJsonType& j, const T& value) { if constexpr (is_optional) nlohmann::optional_to_json(j, key, value); @@ -40,7 +43,8 @@ namespace nlohmann j[key] = value; } - template void extended_from_json(const char* key, const nlohmann::json& j, T& value) + template::value, int> = 0> + void extended_from_json(const char* key, const BasicJsonType& j, T& value) { if constexpr (is_optional) nlohmann::optional_from_json(j, key, value); @@ -53,11 +57,13 @@ namespace nlohmann #define EXTEND_JSON_FROM(v1) extended_from_json(#v1, nlohmann_json_j, nlohmann_json_t.v1); #define NLOHMANN_DEFINE_TYPE_EXTENSION(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) \ + template::value, int> = 0> \ + inline void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) \ { \ NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(EXTEND_JSON_TO, __VA_ARGS__)) \ } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) \ + template::value, int> = 0> \ + inline void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) \ { \ NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(EXTEND_JSON_FROM, __VA_ARGS__)) \ }