Only show valid and up to date meshes and materials in the editor
This commit is contained in:
parent
86f10f9f2a
commit
6e446d4260
1 changed files with 28 additions and 2 deletions
|
@ -735,14 +735,40 @@ void CommonEditor::set_undo_stack(UndoStack *stack) {
|
||||||
current_stack = stack;
|
current_stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mesh_readable(const file::Path path) {
|
||||||
|
auto file = file::open(path);
|
||||||
|
if(!file.has_value()) {
|
||||||
|
console::error(System::Renderer, "Failed to load mesh from {}!", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int version = 0;
|
||||||
|
file->read(&version);
|
||||||
|
|
||||||
|
return version == 5 || version == 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool material_readable(const file::Path path) {
|
||||||
|
auto file = file::open(path);
|
||||||
|
if(!file.has_value()) {
|
||||||
|
console::error(System::Core, "Failed to load material from {}!", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json j;
|
||||||
|
file->read_as_stream() >> j;
|
||||||
|
|
||||||
|
return j.count("version") && j["version"] == 2;
|
||||||
|
}
|
||||||
|
|
||||||
void cacheAssetFilesystem() {
|
void cacheAssetFilesystem() {
|
||||||
asset_files.clear();
|
asset_files.clear();
|
||||||
|
|
||||||
auto data_directory = "../../../data";
|
auto data_directory = "../../../data";
|
||||||
for(auto& p : std::filesystem::recursive_directory_iterator(data_directory)) {
|
for(auto& p : std::filesystem::recursive_directory_iterator(data_directory)) {
|
||||||
if(p.path().extension() == ".model") {
|
if(p.path().extension() == ".model" && mesh_readable(p.path())) {
|
||||||
asset_files[std::filesystem::relative(p, data_directory)] = AssetType::Mesh;
|
asset_files[std::filesystem::relative(p, data_directory)] = AssetType::Mesh;
|
||||||
} else if(p.path().extension() == ".material") {
|
} else if(p.path().extension() == ".material" && material_readable(p.path())) {
|
||||||
asset_files[std::filesystem::relative(p, data_directory)] = AssetType::Material;
|
asset_files[std::filesystem::relative(p, data_directory)] = AssetType::Material;
|
||||||
} else if(p.path().extension() == ".png") {
|
} else if(p.path().extension() == ".png") {
|
||||||
asset_files[std::filesystem::relative(p, data_directory)] = AssetType::Texture;
|
asset_files[std::filesystem::relative(p, data_directory)] = AssetType::Texture;
|
||||||
|
|
Reference in a new issue