-
|
I wanted to know there is a solution for the Here an example Vector used as position "x", "y", "z" #pragma once
#include <glm/glm.hpp>
#include <nlohmann/json.hpp>
namespace glm {
inline void to_json(nlohmann::json &j, const vec3 &vec) { j = nlohmann::json{{"x", vec.x}, {"y", vec.y}, {"z", vec.z}}; }
inline void from_json(const nlohmann::json &j, vec3 &vec) {
j.at("x").get_to(vec.x);
j.at("y").get_to(vec.y);
j.at("z").get_to(vec.z);
}
} // namespace glmVector used as color "r", "g", "b" #pragma once
#include <glm/glm.hpp>
#include <nlohmann/json.hpp>
namespace glm {
inline void to_json(nlohmann::json &j, const vec3 &vec) { j = nlohmann::json{{"r", vec.r}, {"g", vec.g}, {"b", vec.b}}; }
inline void from_json(const nlohmann::json &j, vec3 &vec) {
j.at("r").get_to(vec.r);
j.at("g").get_to(vec.g);
j.at("b").get_to(vec.b);
}
} // namespace glmI know these are the same values there just a union but I want the different labels in the json file. I think as long not both are needed in same file this maybe work but it definitely not works if both are needed. Has anyone solved this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
You would need to write your Alternatively, you could have types like |
Beta Was this translation helpful? Give feedback.
I tested it an it works. I added
Colorand kept the position vector the same.Vector used as position "x", "y", "z"
Vector used as color "r", "g", "b"