Add Pose support for yml
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "Math/Math.hpp"
|
||||
#include "Math/AABB.hpp"
|
||||
#include "Math/Pose.hpp"
|
||||
#include <ryml.hpp>
|
||||
#include <ryml_std.hpp>
|
||||
#include <c4/format.hpp>
|
||||
@@ -50,10 +51,13 @@ 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)
|
||||
inline 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>
|
||||
size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Pose<T>& pose)
|
||||
{ return ryml::format(buf, "({},{},{}),({},{},{},{})", pose.m_position.x, pose.m_position.y, pose.m_position.z, pose.m_orientation.x, pose.m_orientation.y, pose.m_orientation.z, pose.m_orientation.w); }
|
||||
|
||||
template<class T>
|
||||
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2<T>* v)
|
||||
{
|
||||
@@ -114,10 +118,16 @@ namespace c4
|
||||
return ret != ryml::yml::npos;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::AABB* bbox)
|
||||
inline 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;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Pose<T>* pose)
|
||||
{
|
||||
size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{},{})", pose->m_position.x, pose->m_position.y, pose->m_position.z, pose->m_orientation.x, pose->m_orientation.y, pose->m_orientation.z, pose->m_orientation.w);
|
||||
return ret != ryml::yml::npos;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "Base/UUID.hpp"
|
||||
#include "Math/AABB.hpp"
|
||||
#include "Math/Pose.hpp"
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <fmt/format.h>
|
||||
#include <c4/format.hpp>
|
||||
@@ -51,4 +52,23 @@ namespace YAML
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<OpenVulkano::Math::PoseF>
|
||||
{
|
||||
static Node encode(const OpenVulkano::Math::PoseF& pose)
|
||||
{
|
||||
return Node(fmt::format("({},{},{}),({},{},{},{})", pose.GetPosition().x, pose.GetPosition().y, pose.GetPosition().z, pose.GetOrientation().x, pose.GetOrientation().y, pose.GetOrientation().z, pose.GetOrientation().w));
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, OpenVulkano::Math::PoseF& pose)
|
||||
{
|
||||
if (node.IsScalar())
|
||||
{
|
||||
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{},{}),({},{},{},{})", pose.GetPosition().x, pose.GetPosition().y, pose.GetPosition().z, pose.GetOrientation().x, pose.GetOrientation().y, pose.GetOrientation().z, pose.GetOrientation().w);
|
||||
return ret != c4::csubstr::npos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user