Add support for AABB to yaml
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Math/Math.hpp"
|
||||
#include "Math/AABB.hpp"
|
||||
#include <ryml.hpp>
|
||||
#include <ryml_std.hpp>
|
||||
#include <c4/format.hpp>
|
||||
@@ -49,6 +50,10 @@ namespace c4
|
||||
m[1][3], m[2][3], m[3][3]);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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<class T>
|
||||
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2<T>* v)
|
||||
{
|
||||
@@ -108,4 +113,11 @@ namespace c4
|
||||
m[1][3], m[2][3], m[3][3]);
|
||||
return ret != ryml::yml::npos;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Base/UUID.hpp"
|
||||
#include "Math/AABB.hpp"
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <fmt/format.h>
|
||||
#include <c4/format.hpp>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
@@ -29,4 +32,23 @@ namespace YAML
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<OpenVulkano::Math::AABB>
|
||||
{
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user