VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
SerializationUtils.hpp
Go to the documentation of this file.
1
6
7#pragma once
8#include <nlohmann/json.hpp>
9#include <glm/glm.hpp>
10#include <glm/gtc/quaternion.hpp>
11
12namespace glm {
13 inline void to_json(nlohmann::json& j, const glm::vec2& v) {
14 j = nlohmann::json{{"x", v.x}, {"y", v.y}};
15 }
16 inline void from_json(const nlohmann::json& j, glm::vec2& v) {
17 if (j.contains("x")) j.at("x").get_to(v.x);
18 if (j.contains("y")) j.at("y").get_to(v.y);
19 }
20
21
22 // Serialize vec3
23 inline void to_json(nlohmann::json& j, const vec3& v) {
24 j = nlohmann::json::array({v.x, v.y, v.z});
25 }
26
27 // Deserialize vec3
28 inline void from_json(const nlohmann::json& j, vec3& v) {
29 if(j.is_array() && j.size() >= 3) {
30 v.x = j[0]; v.y = j[1]; v.z = j[2];
31 }
32 }
33
34 // Serialize vec4
35 inline void to_json(nlohmann::json& j, const vec4& v) {
36 j = nlohmann::json::array({v.x, v.y, v.z, v.w});
37 }
38
39 // Deserialize vec4
40 inline void from_json(const nlohmann::json& j, vec4& v) {
41 if(j.is_array() && j.size() >= 4) {
42 v.x = j[0]; v.y = j[1]; v.z = j[2]; v.w = j[3];
43 }
44 }
45
46 // Serialize quat
47 inline void to_json(nlohmann::json& j, const quat& q) {
48 j = nlohmann::json::array({q.w, q.x, q.y, q.z});
49 }
50
51 inline void from_json(const nlohmann::json& j, quat& q) {
52 if(j.is_array() && j.size() >= 4) {
53 q.w = j[0]; q.x = j[1]; q.y = j[2]; q.z = j[3];
54 }
55 }
56}