From 6e446d4260284dae67c02895962946ffdaa97d62 Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Mon, 17 Aug 2020 09:39:31 -0400 Subject: [PATCH] Only show valid and up to date meshes and materials in the editor --- tools/common/src/commoneditor.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tools/common/src/commoneditor.cpp b/tools/common/src/commoneditor.cpp index add3d37..949e411 100755 --- a/tools/common/src/commoneditor.cpp +++ b/tools/common/src/commoneditor.cpp @@ -735,14 +735,40 @@ void CommonEditor::set_undo_stack(UndoStack *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() { asset_files.clear(); auto data_directory = "../../../data"; 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; - } 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; } else if(p.path().extension() == ".png") { asset_files[std::filesystem::relative(p, data_directory)] = AssetType::Texture;