Improve mesh components

This commit is contained in:
2024-12-06 09:11:03 -06:00
parent a4774e6189
commit e6672945ae
24 changed files with 366 additions and 42 deletions

View File

@ -10,6 +10,7 @@ using namespace Dawn;
glm::vec3 JSON::vec3(const json &j) {
if(j.type() == json::value_t::array) {
assertTrue(j.size() == 3, "Invalid size for vec3");
return glm::vec3(j[0].get<float_t>(), j[1].get<float_t>(), j[2].get<float_t>());
} else if(j.type() == json::value_t::object) {
assertTrue(j.contains("x"), "Missing x in vec3");
@ -27,6 +28,33 @@ glm::vec3 JSON::vec3(const json &j) {
return glm::vec3(0.0f);
}
glm::vec4 JSON::vec4(const json &j) {
if(j.type() == json::value_t::array) {
assertTrue(j.size() == 4, "Invalid size for vec4");
return glm::vec4(
j[0].get<float_t>(),
j[1].get<float_t>(),
j[2].get<float_t>(),
j[3].get<float_t>()
);
} else if(j.type() == json::value_t::object) {
assertTrue(j.contains("x"), "Missing x in vec4");
assertTrue(j.contains("y"), "Missing y in vec4");
assertTrue(j.contains("z"), "Missing z in vec4");
assertTrue(j.contains("w"), "Missing w in vec4");
return glm::vec4(
j["x"].get<float_t>(),
j["y"].get<float_t>(),
j["z"].get<float_t>(),
j["w"].get<float_t>()
);
}
assertUnreachable("Invalid JSON type for vec4");
return glm::vec4(0.0f);
}
struct Color JSON::color(const json &j) {
if(j.type() == json::value_t::array) {
return {

View File

@ -18,6 +18,14 @@ namespace Dawn {
*/
static glm::vec3 vec3(const json &j);
/**
* Parses the given JSON string as a vec4.
*
* @param j JSON obj to parse.
* @return Parsed vec4.
*/
static glm::vec4 vec4(const json &j);
/**
* Parses the given JSON string as a color.
*