| 52 | } |
| 53 | |
| 54 | void material_library::import_material(const std::string & path) |
| 55 | { |
| 56 | // todo - de-duplicate based on name |
| 57 | const json instance_doc = json::parse(read_file_text(path)); |
| 58 | const std::string name = get_filename_without_extension(path); |
| 59 | const std::string parent_path = parent_directory_from_filepath(path); |
| 60 | assert(!name.empty()); |
| 61 | |
| 62 | for (auto inst = instance_doc.begin(); inst != instance_doc.end(); ++inst) |
| 63 | { |
| 64 | if (starts_with(inst.key(), "@")) |
| 65 | { |
| 66 | const std::string type_key = inst.key(); |
| 67 | const std::string type_name = type_key.substr(1); |
| 68 | |
| 69 | if (type_name == get_typename<polymer_pbr_standard>()) |
| 70 | { |
| 71 | std::shared_ptr<polymer_pbr_standard> new_instance(new polymer_pbr_standard()); |
| 72 | *new_instance = inst.value(); |
| 73 | |
| 74 | material_instance inst; |
| 75 | inst.name = name; |
| 76 | inst.origin_path = parent_path; |
| 77 | inst.instance = new_instance; |
| 78 | instances[name] = inst; |
| 79 | |
| 80 | create_handle_for_asset(name.c_str(), static_cast<std::shared_ptr<base_material>>(new_instance)); |
| 81 | } |
| 82 | else if (type_name == get_typename<polymer_blinn_phong_standard>()) |
| 83 | { |
| 84 | std::shared_ptr<polymer_blinn_phong_standard> new_instance(new polymer_blinn_phong_standard()); |
| 85 | *new_instance = inst.value(); |
| 86 | |
| 87 | material_instance inst; |
| 88 | inst.name = name; |
| 89 | inst.origin_path = parent_path; |
| 90 | inst.instance = new_instance; |
| 91 | instances[name] = inst; |
| 92 | |
| 93 | create_handle_for_asset(name.c_str(), static_cast<std::shared_ptr<base_material>>(new_instance)); |
| 94 | } |
| 95 | } |
| 96 | else throw std::runtime_error("type key mismatch!"); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void material_library::export_material(const std::string & key) |
| 101 | { |
no test coverage detected