u/json: Add u_json_get_pose_permissive

To parse poses from non-Monado configs with non-standard member names.
This commit is contained in:
Moses Turner 2022-09-19 21:52:03 -05:00 committed by Jakob Bornecrantz
parent b31eb76718
commit 48e8894b74
2 changed files with 46 additions and 0 deletions

View file

@ -278,6 +278,42 @@ u_json_get_pose(const cJSON *json, struct xrt_pose *out_pose)
return good;
}
bool
u_json_get_pose_permissive(const cJSON *json, struct xrt_pose *out_pose)
{
struct xrt_pose tmp;
const char *position_names[] = {"position", "translation", "location", "pos", "loc"};
const char *orientation_names[] = {"orientation", "rotation", "rot"};
bool found_position = false;
for (uint32_t i = 0; i < ARRAY_SIZE(position_names); i++) {
found_position = u_json_get_vec3(u_json_get(json, position_names[i]), &tmp.position);
if (found_position) {
break;
}
}
if (!found_position) {
return false;
}
bool found_orientation = false;
for (uint32_t i = 0; i < ARRAY_SIZE(orientation_names); i++) {
found_orientation = u_json_get_vec3(u_json_get(json, orientation_names[i]), &tmp.position);
if (found_orientation) {
break;
}
}
if (!found_orientation) {
return false;
}
return true;
}
size_t
u_json_get_float_array(const cJSON *json_array, float *out_array, size_t max_size)

View file

@ -110,6 +110,16 @@ bool
u_json_get_pose(const cJSON *json, struct xrt_pose *out_pose);
/*!
* @brief Parse a pose from a JSON object, composed of
* a vec3 named "position", "translation", "location", "pos", or "loc"
* and a quat named "orientation". "rotation", or "rot"
*
* @return true if successful, false if not.
*/
bool
u_json_get_pose_permissive(const cJSON *json, struct xrt_pose *out_pose);
/*!
* @brief Parse up to max_size floats from a JSON array.
*