From 22d2d274ebaf1824e26f0d5c653d7f8894cda681 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 17 Oct 2024 18:57:41 +0200 Subject: [PATCH] Add support for AABB to yaml --- openVulkanoCpp/Extensions/RymlConverters.hpp | 12 ++++++++++ .../Extensions/YamlCppConverters.hpp | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/openVulkanoCpp/Extensions/RymlConverters.hpp b/openVulkanoCpp/Extensions/RymlConverters.hpp index 6261a5e..63ac35c 100644 --- a/openVulkanoCpp/Extensions/RymlConverters.hpp +++ b/openVulkanoCpp/Extensions/RymlConverters.hpp @@ -7,6 +7,7 @@ #pragma once #include "Math/Math.hpp" +#include "Math/AABB.hpp" #include #include #include @@ -49,6 +50,10 @@ namespace c4 m[1][3], m[2][3], m[3][3]); } + template + size_t to_chars(ryml::substr buf, const OpenVulkano::Math::AABB& bbox) + { return ryml::format(buf, "({},{},{}),({},{},{})", bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z); } + template bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2* v) { @@ -108,4 +113,11 @@ namespace c4 m[1][3], m[2][3], m[3][3]); return ret != ryml::yml::npos; } + + template + bool from_chars(ryml::csubstr buf, OpenVulkano::Math::AABB* bbox) + { + size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{})", bbox->min.x, bbox->min.y, bbox->min.z, bbox->max.x, bbox->max.y, bbox->max.z); + return ret != ryml::yml::npos; + } } \ No newline at end of file diff --git a/openVulkanoCpp/Extensions/YamlCppConverters.hpp b/openVulkanoCpp/Extensions/YamlCppConverters.hpp index 1d273a0..8f6ebc4 100644 --- a/openVulkanoCpp/Extensions/YamlCppConverters.hpp +++ b/openVulkanoCpp/Extensions/YamlCppConverters.hpp @@ -7,7 +7,10 @@ #pragma once #include "Base/UUID.hpp" +#include "Math/AABB.hpp" #include +#include +#include namespace YAML { @@ -29,4 +32,23 @@ namespace YAML return false; } }; + + template<> + struct convert + { + static Node encode(const OpenVulkano::Math::AABB& bbox) + { + return Node(fmt::format("({},{},{}),({},{},{})", bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z)); + } + + static bool decode(const Node& node, OpenVulkano::Math::AABB& bbox) + { + if (node.IsScalar()) + { + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar()), "({},{},{}),({},{},{})", bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z); + return ret != c4::csubstr::npos; + } + return false; + } + }; } \ No newline at end of file