Material: Material editor enhancements

Improves compatibility when using the legacy editor.

Corrects a number of issues that prevented saved files from being displayed when using the legacy editor.

Reduces the verbosity of console messages.
This commit is contained in:
David Carter
2024-02-04 10:55:56 -05:00
committed by Chris Hennes
parent 2ae5663144
commit 2a60613257
7 changed files with 81 additions and 25 deletions

View File

@@ -29,6 +29,7 @@
#include <App/Application.h>
#include "Exceptions.h"
#include "MaterialConfigLoader.h"
#include "MaterialLoader.h"
#include "MaterialManager.h"
#include "ModelManager.h"
@@ -123,7 +124,23 @@ std::shared_ptr<Material> MaterialManager::getMaterialByPath(const QString& path
for (auto& library : *_libraryList) {
if (cleanPath.startsWith(library->getDirectory())) {
return library->getMaterialByPath(cleanPath);
try {
return library->getMaterialByPath(cleanPath);
} catch (const MaterialNotFound&) {}
// See if it's a new file saved by the old editor
{
QMutexLocker locker(&_mutex);
if (MaterialConfigLoader::isConfigStyle(path)) {
auto material = MaterialConfigLoader::getMaterialFromPath(library, path);
if (material) {
(*_materialMap)[material->getUUID()] = library->addMaterial(material, path);
}
return material;
}
}
}
}
@@ -244,6 +261,21 @@ MaterialManager::materialsWithModelComplete(const QString& uuid) const
return dict;
}
void MaterialManager::dereference() const
{
// First clear the inheritences
for (auto& it : *_materialMap) {
auto material = it.second;
material->clearDereferenced();
material->clearInherited();
}
// Run the dereference again
for (auto& it : *_materialMap) {
dereference(it.second);
}
}
void MaterialManager::dereference(std::shared_ptr<Material> material) const
{
MaterialLoader::dereference(_materialMap, material);