mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
json_utils: parse trs2 and trs3
This commit is contained in:
@@ -134,6 +134,58 @@ namespace e2d::json_utils
|
|||||||
try_parse_value(const rapidjson::Value& root, unit<T, Tag>& v) noexcept {
|
try_parse_value(const rapidjson::Value& root, unit<T, Tag>& v) noexcept {
|
||||||
return try_parse_value(root, v.value);
|
return try_parse_value(root, v.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
bool try_parse_value(const rapidjson::Value& root, trs2<T>& t) noexcept {
|
||||||
|
trs2<T> tt = trs2<T>::identity();
|
||||||
|
|
||||||
|
if ( root.HasMember("translation") ) {
|
||||||
|
if ( !try_parse_value(root["translation"], tt.translation) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( root.HasMember("rotation") ) {
|
||||||
|
if ( !try_parse_value(root["rotation"], tt.rotation) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( root.HasMember("scale") ) {
|
||||||
|
if ( !try_parse_value(root["scale"], tt.scale) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t = tt;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
bool try_parse_value(const rapidjson::Value& root, trs3<T>& t) noexcept {
|
||||||
|
trs3<T> tt = trs3<T>::identity();
|
||||||
|
|
||||||
|
if ( root.HasMember("translation") ) {
|
||||||
|
if ( !try_parse_value(root["translation"], tt.translation) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( root.HasMember("rotation") ) {
|
||||||
|
if ( !try_parse_value(root["rotation"], tt.rotation) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( root.HasMember("scale") ) {
|
||||||
|
if ( !try_parse_value(root["scale"], tt.scale) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t = tt;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace e2d::json_utils
|
namespace e2d::json_utils
|
||||||
|
|||||||
@@ -192,6 +192,24 @@ namespace
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
"t2" : {
|
||||||
|
"type" : "object",
|
||||||
|
"additionalProperties" : false,
|
||||||
|
"properties" : {
|
||||||
|
"translation" : { "$ref": "#/common_definitions/v2" },
|
||||||
|
"rotation" : { "type" : "number" },
|
||||||
|
"scale" : { "$ref": "#/common_definitions/v2" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"t3" : {
|
||||||
|
"type" : "object",
|
||||||
|
"additionalProperties" : false,
|
||||||
|
"properties" : {
|
||||||
|
"translation" : { "$ref": "#/common_definitions/v3" },
|
||||||
|
"rotation" : { "$ref": "#/common_definitions/q4" },
|
||||||
|
"scale" : { "$ref": "#/common_definitions/v3" }
|
||||||
|
}
|
||||||
|
},
|
||||||
"color" : {
|
"color" : {
|
||||||
"anyOf" : [{
|
"anyOf" : [{
|
||||||
"type" : "number"
|
"type" : "number"
|
||||||
|
|||||||
@@ -62,6 +62,18 @@ namespace
|
|||||||
"b3_4" : [1,2,3,4,5,6],
|
"b3_4" : [1,2,3,4,5,6],
|
||||||
"b3_5" : [1,2,3,4,5,6,7],
|
"b3_5" : [1,2,3,4,5,6,7],
|
||||||
|
|
||||||
|
"t2" : {
|
||||||
|
"translation" : [1,2],
|
||||||
|
"rotation" : 3,
|
||||||
|
"scale" : [4,5]
|
||||||
|
},
|
||||||
|
|
||||||
|
"t3" : {
|
||||||
|
"translation" : [1,2,3],
|
||||||
|
"rotation" : [4,5,6,7],
|
||||||
|
"scale" : [8,9,10]
|
||||||
|
},
|
||||||
|
|
||||||
"c0" : 0.5,
|
"c0" : 0.5,
|
||||||
"c1" : { "r" : 0.1, "b" : 0.2 },
|
"c1" : { "r" : 0.1, "b" : 0.2 },
|
||||||
"c2" : { "r" : 0.1, "g" : 0.2, "b" : 0.3, "a" : 0.4 },
|
"c2" : { "r" : 0.1, "g" : 0.2, "b" : 0.3, "a" : 0.4 },
|
||||||
@@ -189,6 +201,15 @@ TEST_CASE("json_utils") {
|
|||||||
REQUIRE_FALSE(json_utils::try_parse_value(doc["s2"], s3));
|
REQUIRE_FALSE(json_utils::try_parse_value(doc["s2"], s3));
|
||||||
REQUIRE_FALSE(json_utils::try_parse_value(doc["s2"], s4));
|
REQUIRE_FALSE(json_utils::try_parse_value(doc["s2"], s4));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
t2f t2;
|
||||||
|
REQUIRE(json_utils::try_parse_value(doc["t2"], t2));
|
||||||
|
REQUIRE(t2 == make_trs2(v2f(1,2), radf(3), v2f(4,5)));
|
||||||
|
|
||||||
|
t3f t3;
|
||||||
|
REQUIRE(json_utils::try_parse_value(doc["t3"], t3));
|
||||||
|
REQUIRE(t3 == make_trs3(v3f(1,2,3), q4f(4,5,6,7), v3f(8,9,10)));
|
||||||
|
}
|
||||||
{
|
{
|
||||||
color c0, c1, c2;
|
color c0, c1, c2;
|
||||||
REQUIRE(json_utils::try_parse_value(doc["c0"], c0));
|
REQUIRE(json_utils::try_parse_value(doc["c0"], c0));
|
||||||
|
|||||||
Reference in New Issue
Block a user