MCPcopy Create free account
hub / github.com/ddiakopoulos/polymer / import_material

Method import_material

libraries/lib-engine/src/material-library.cpp:54–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void 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
100void material_library::export_material(const std::string & key)
101{

Callers 1

walk_directoryMethod · 0.80

Calls 9

read_file_textFunction · 0.85
starts_withFunction · 0.85
create_handle_for_assetFunction · 0.85
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected