#include "render-config.h" #include "picojson.h" #include #include namespace example { bool LoadRenderConfig(example::RenderConfig* config, const char* filename) { std::ifstream is(filename); if (is.fail()) { std::cerr << "Cannot open " << filename << std::endl; return false; } std::istream_iterator input(is); std::string err; picojson::value v; input = picojson::parse(v, input, std::istream_iterator(), &err); if (!err.empty()) { std::cerr << err << std::endl; } if (!v.is()) { std::cerr << "Not a JSON object" << std::endl; return false; } picojson::object o = v.get(); if (o.find("obj_filename") != o.end()) { if (o["obj_filename"].is()) { config->obj_filename = o["obj_filename"].get(); } } if (o.find("gltf_filename") != o.end()) { if (o["gltf_filename"].is()) { config->gltf_filename = o["gltf_filename"].get(); } } if (o.find("eson_filename") != o.end()) { if (o["eson_filename"].is()) { config->eson_filename = o["eson_filename"].get(); } } config->scene_scale = 1.0f; if (o.find("scene_scale") != o.end()) { if (o["scene_scale"].is()) { config->scene_scale = static_cast(o["scene_scale"].get()); } } config->eye[0] = 0.0f; config->eye[1] = 0.0f; config->eye[2] = 5.0f; if (o.find("eye") != o.end()) { if (o["eye"].is()) { picojson::array arr = o["eye"].get(); if (arr.size() == 3) { config->eye[0] = static_cast(arr[0].get()); config->eye[1] = static_cast(arr[1].get()); config->eye[2] = static_cast(arr[2].get()); } } } config->up[0] = 0.0f; config->up[1] = 1.0f; config->up[2] = 0.0f; if (o.find("up") != o.end()) { if (o["up"].is()) { picojson::array arr = o["up"].get(); if (arr.size() == 3) { config->up[0] = static_cast(arr[0].get()); config->up[1] = static_cast(arr[1].get()); config->up[2] = static_cast(arr[2].get()); } } } config->look_at[0] = 0.0f; config->look_at[1] = 0.0f; config->look_at[2] = 0.0f; if (o.find("look_at") != o.end()) { if (o["look_at"].is()) { picojson::array arr = o["look_at"].get(); if (arr.size() == 3) { config->look_at[0] = static_cast(arr[0].get()); config->look_at[1] = static_cast(arr[1].get()); config->look_at[2] = static_cast(arr[2].get()); } } } config->fov = 45.0f; if (o.find("fov") != o.end()) { if (o["fov"].is()) { config->fov = static_cast(o["fov"].get()); } } config->width = 512; if (o.find("width") != o.end()) { if (o["width"].is()) { config->width = static_cast(o["width"].get()); } } config->height = 512; if (o.find("height") != o.end()) { if (o["height"].is()) { config->height = static_cast(o["height"].get()); } } return true; } } // namespace example