-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialize vector of glm:vec2 #1739
Comments
Strange. This code compiles with Xcode: #include "json.hpp"
#include <iostream>
#include "/usr/local/Cellar/glm/0.9.9.5/include/glm/glm.hpp"
using json = nlohmann::json;
namespace glm {
void to_json(json& j, const glm::vec2& P) {
j = { { "x", P.x }, { "y", P.y } };
};
void from_json(const json& j, glm::vec2& P) {
P.x = j.at("x").get<double>();
P.y = j.at("y").get<double>();
}
}
int main()
{
json j;
std::vector<glm::vec2> points{ glm::vec2( 70, -140 ), glm::vec2(30, -30), glm::vec2(20, 125) };
j["points"] = points;
std::cout << j << std::endl;
} Output:
Can you try this minimal example? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Any idea why
Update: Nevermind, I just saw in the README that the two function must be in the same namespace as glm::vec3 type. |
@h4k1m0u You can also use this alternate method for third-party types which avoids placing the functions into the |
Thanks @falbrechtskirchinger. I'll have a look later, seems advanced but I may need it in the future. |
I had the same problem, and It worked when I put the functions (to_json, from_json) inside glm namespace. |
I'd like to serialize a vector of glm:vec2;
I have tried to follow the instructions in the readme and implemented from and to json methods like so:
this little snippet wont compile and I got the following errors:
the funny thing is that when I replace glm::vec2 with a simple Point struct, it compiles, and works as expected.
I'm on windows, using Visual Studio, using the single header from the master branch version3.7.0
The text was updated successfully, but these errors were encountered: