Scene* json_parse_scene(const jsonvalue& json) { // prepare scene auto scene = new Scene(); // camera if (json.object_contains("camera")) scene->camera = json_parse_camera(json.object_element("camera")); if (json.object_contains("lookat_camera")) scene->camera = json_parse_lookatcamera(json.object_element("lookat_camera")); // surfaces if(json.object_contains("surfaces")) scene->surfaces = json_parse_surfaces(json.object_element("surfaces")); // meshes if(json.object_contains("json_meshes")) { json_texture_path_push(json.object_element("json_meshes").as_string()); scene->meshes = json_parse_meshes(load_json(json.object_element("json_meshes").as_string())); json_texture_path_pop(); } if(json.object_contains("meshes")) { scene->meshes = json_parse_meshes(json.object_element("meshes")); } // lights if(json.object_contains("lights")) scene->lights = json_parse_lights(json.object_element("lights")); // animation if(json.object_contains("animation")) scene->animation = json_parse_scene_animation(json.object_element("animation")); // rendering parameters json_set_optvalue(json, scene->image_width, "image_width"); json_set_optvalue(json, scene->image_height, "image_height"); json_set_optvalue(json, scene->image_samples, "image_samples"); json_set_optvalue(json, scene->background, "background"); json_parse_opttexture(json, scene->background_txt, "background_txt"); json_set_optvalue(json, scene->ambient, "ambient"); json_set_optvalue(json, scene->path_max_depth, "path_max_depth"); json_set_optvalue(json, scene->path_sample_brdf, "path_sample_brdf"); json_set_optvalue(json, scene->path_shadows, "path_shadows"); // done return scene; }
Mesh* json_parse_mesh(const jsonvalue& json) { auto mesh = new Mesh(); if(json.object_contains("json_mesh")) { json_texture_path_push(json.object_element("json_mesh").as_string()); mesh = json_parse_mesh(load_json(json.object_element("json_mesh").as_string())); json_texture_path_pop(); } json_set_optvalue(json, mesh->frame, "frame"); json_set_optvalue(json, mesh->pos, "pos"); json_set_optvalue(json, mesh->norm, "norm"); json_set_optvalue(json, mesh->texcoord, "texcoord"); json_set_optvalue(json, mesh->triangle, "triangle"); json_set_optvalue(json, mesh->quad, "quad"); json_set_optvalue(json, mesh->point, "point"); json_set_optvalue(json, mesh->line, "line"); json_set_optvalue(json, mesh->spline, "spline"); if(json.object_contains("material")) mesh->mat = json_parse_material(json.object_element("material")); json_set_optvalue(json, mesh->subdivision_catmullclark_level, "subdivision_catmullclark_level"); json_set_optvalue(json, mesh->subdivision_catmullclark_smooth, "subdivision_catmullclark_smooth"); json_set_optvalue(json, mesh->subdivision_bezier_level, "subdivision_bezier_level"); json_set_optvalue(json, mesh->subdivision_bezier_uniform, "subdivision_bezier_uniform"); if(json.object_contains("animation")) mesh->animation = json_parse_frame_animation(json.object_element("animation")); if(json.object_contains("skinning")) mesh->skinning = json_parse_mesh_skinning(json.object_element("skinning")); if(json.object_contains("json_skinning")) mesh->skinning = json_parse_mesh_skinning(load_json(json.object_element("json_skinning").as_string())); if(json.object_contains("simulation")) mesh->simulation = json_parse_mesh_simulation(json.object_element("simulation")); if (mesh->skinning) { if (mesh->skinning->vert_rest_pos.empty()) mesh->skinning->vert_rest_pos = mesh->pos; if (mesh->skinning->vert_rest_norm.empty()) mesh->skinning->vert_rest_norm = mesh->norm; if (mesh->pos.empty()) mesh->pos = mesh->skinning->vert_rest_pos; if (mesh->norm.empty()) mesh->norm = mesh->skinning->vert_rest_norm; } return mesh; }