Material: Material editor enhancements
Continues the work of the material subsystem improvements. This merge covers the continued development of the material editor. The primary improvements are in the handling of 2D and 3D array properties. These properties are now fully editable, and can be saved and restored. The cards now separate the author and license. These were previously saved as a single item. Future support will be provided for standard open source licenses. Saving operations validate the cards to ensure UUIDs of materials are considered. Warnings are given when a save could potentially impact the models, such as saving over a material instead of creating a new instance. The editor is still not complete. There are a number of functional elements, such as drag/drop operations, folder creation, and deletion operations that need to be added to the main tree. State needs to be saved and restored to improve the user experience. The appearance preview also needs significant work. This will be handled in a future PR.
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "Exceptions.h"
|
||||
#include "Model.h"
|
||||
#include "ModelLibrary.h"
|
||||
#include "ModelManager.h"
|
||||
|
||||
|
||||
using namespace Materials;
|
||||
@@ -66,6 +67,15 @@ QString LibraryBase::getLocalPath(const QString& path) const
|
||||
return filePath;
|
||||
}
|
||||
|
||||
bool LibraryBase::isRoot(const QString& path) const
|
||||
{
|
||||
QString localPath = getLocalPath(path);
|
||||
QString cleanPath = getLocalPath(QString::fromStdString(""));
|
||||
std::string pLocal = localPath.toStdString();
|
||||
std::string pclean = cleanPath.toStdString();
|
||||
return (cleanPath == localPath);
|
||||
}
|
||||
|
||||
QString LibraryBase::getRelativePath(const QString& path) const
|
||||
{
|
||||
QString filePath;
|
||||
@@ -97,17 +107,80 @@ TYPESYSTEM_SOURCE(Materials::ModelLibrary, LibraryBase)
|
||||
|
||||
ModelLibrary::ModelLibrary(const QString& libraryName, const QString& dir, const QString& icon)
|
||||
: LibraryBase(libraryName, dir, icon)
|
||||
{}
|
||||
{
|
||||
_modelPathMap = std::make_unique<std::map<QString, std::shared_ptr<Model>>>();
|
||||
}
|
||||
|
||||
ModelLibrary::ModelLibrary()
|
||||
{}
|
||||
{
|
||||
_modelPathMap = std::make_unique<std::map<QString, std::shared_ptr<Model>>>();
|
||||
}
|
||||
|
||||
Model* ModelLibrary::addModel(const Model& model, const QString& path)
|
||||
std::shared_ptr<Model> ModelLibrary::getModelByPath(const QString& path) const
|
||||
{
|
||||
QString filePath = getRelativePath(path);
|
||||
Model* newModel = new Model(model);
|
||||
newModel->setLibrary(*this);
|
||||
try {
|
||||
std::shared_ptr<Model> model = _modelPathMap->at(filePath);
|
||||
return model;
|
||||
}
|
||||
catch (std::out_of_range& e) {
|
||||
throw ModelNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Model> ModelLibrary::addModel(const Model& model, const QString& path)
|
||||
{
|
||||
QString filePath = getRelativePath(path);
|
||||
std::shared_ptr<Model> newModel = std::make_shared<Model>(model);
|
||||
newModel->setLibrary(getptr());
|
||||
newModel->setDirectory(filePath);
|
||||
|
||||
(*_modelPathMap)[filePath] = newModel;
|
||||
|
||||
return newModel;
|
||||
}
|
||||
|
||||
std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>>
|
||||
ModelLibrary::getModelTree(ModelFilter filter) const
|
||||
{
|
||||
std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>> modelTree =
|
||||
std::make_shared<std::map<QString, std::shared_ptr<ModelTreeNode>>>();
|
||||
|
||||
for (auto it = _modelPathMap->begin(); it != _modelPathMap->end(); it++) {
|
||||
auto filename = it->first;
|
||||
auto model = it->second;
|
||||
|
||||
if (ModelManager::passFilter(filter, model->getType())) {
|
||||
// Base::Console().Log("Relative path '%s'\n\t", filename.toStdString().c_str());
|
||||
QStringList list = filename.split(QString::fromStdString("/"));
|
||||
|
||||
// Start at the root
|
||||
std::shared_ptr<std::map<QString, std::shared_ptr<ModelTreeNode>>> node = modelTree;
|
||||
for (auto itp = list.begin(); itp != list.end(); itp++) {
|
||||
// Base::Console().Log("\t%s", itp->toStdString().c_str());
|
||||
if (ModelManager::isModel(*itp)) {
|
||||
std::shared_ptr<ModelTreeNode> child = std::make_shared<ModelTreeNode>();
|
||||
child->setData(model);
|
||||
(*node)[*itp] = child;
|
||||
}
|
||||
else {
|
||||
// Add the folder only if it's not already there
|
||||
if (node->count(*itp) == 0) {
|
||||
auto mapPtr =
|
||||
std::make_shared<std::map<QString, std::shared_ptr<ModelTreeNode>>>();
|
||||
std::shared_ptr<ModelTreeNode> child = std::make_shared<ModelTreeNode>();
|
||||
child->setFolder(mapPtr);
|
||||
(*node)[*itp] = child;
|
||||
node = mapPtr;
|
||||
}
|
||||
else {
|
||||
node = (*node)[*itp]->getFolder();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Base::Console().Log("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return modelTree;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user