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 the addition of new data types, a new
appearance preview UI, and changes in the array data types.

New data types were added to support more advanced workflows, such as
the Render Workbench.The Image datatype allows the material to embed
the image in the card instead of pointing to an image in an external
file. Multi-buyte strings span multiple lines as the name implies.
It preserves formatting accross those lines. Also several list types
are now supported, with the primary difference being the editors.
List is a list of strings, FileList is a list of file path names, and
ImageList is a list of embedded images.

For the appearance preview, the UI now uses the same Coin library as
is used in the documents, meaning the preview will look exactly the
same as the material will be shown in the documents.

The array data types are now more complete. The default value wasn't
being used as originially envisioned and was tehrefore removed. For
3D arrays, the Python API was implemented.

There were a lot of code clean ups. This involved removing logging
statements used for debugging during development, reduction of lint
warnings, and code refactoring.

The editor can automatically convert from previous format files to the
current format. This has been extended to material files generated by
the Render WB. Old format files are displayed in the editor with a
warning icon. Selecting one will require saving the file in the new
format before it can be used.
This commit is contained in:
David Carter
2023-12-03 13:22:43 -05:00
committed by Chris Hennes
parent 703561f7bc
commit 3dd6a67804
72 changed files with 4248 additions and 1334 deletions

View File

@@ -54,7 +54,6 @@ MaterialLibrary::MaterialLibrary(const QString& libraryName,
void MaterialLibrary::createFolder(const QString& path)
{
QString filePath = getLocalPath(path);
// Base::Console().Log("\tfilePath = '%s'\n", filePath.toStdString().c_str());
QDir fileDir(filePath);
if (!fileDir.exists()) {
@@ -68,8 +67,6 @@ void MaterialLibrary::createFolder(const QString& path)
// This accepts the filesystem path as returned from getLocalPath
void MaterialLibrary::deleteDir(MaterialManager& manager, const QString& path)
{
// Base::Console().Log("Removing directory '%s'\n", path.toStdString().c_str());
// Remove the children first
QDirIterator it(path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
@@ -109,12 +106,9 @@ void MaterialLibrary::deleteDir(MaterialManager& manager, const QString& path)
// This accepts the filesystem path as returned from getLocalPath
void MaterialLibrary::deleteFile(MaterialManager& manager, const QString& path)
{
// Base::Console().Log("Removing file '%s'\n", path.toStdString().c_str());
if (QFile::remove(path)) {
// Remove from the map
QString rPath = getRelativePath(path);
// Base::Console().Log("\trpath '%s'\n", rPath.toStdString().c_str());
try {
auto material = getMaterialByPath(rPath);
manager.remove(material->getUUID());
@@ -132,15 +126,11 @@ void MaterialLibrary::deleteFile(MaterialManager& manager, const QString& path)
void MaterialLibrary::deleteRecursive(const QString& path)
{
std::string pstring = path.toStdString();
Base::Console().Log("\tdeleteRecursive '%s'\n", pstring.c_str());
if (isRoot(path)) {
return;
}
QString filePath = getLocalPath(path);
// Base::Console().Log("\tfilePath = '%s'\n", filePath.toStdString().c_str());
MaterialManager manager;
QFileInfo info(filePath);
@@ -159,16 +149,13 @@ void MaterialLibrary::updatePaths(const QString& oldPath, const QString& newPath
QString np = getRelativePath(newPath);
std::unique_ptr<std::map<QString, std::shared_ptr<Material>>> pathMap =
std::make_unique<std::map<QString, std::shared_ptr<Material>>>();
for (auto itp = _materialPathMap->begin(); itp != _materialPathMap->end(); itp++) {
QString path = itp->first;
for (auto& itp : *_materialPathMap) {
QString path = itp.first;
if (path.startsWith(op)) {
path = np + path.remove(0, op.size());
}
Base::Console().Error("Path '%s' -> '%s'\n",
itp->first.toStdString().c_str(),
path.toStdString().c_str());
itp->second->setDirectory(path);
(*pathMap)[path] = itp->second;
itp.second->setDirectory(path);
(*pathMap)[path] = itp.second;
}
_materialPathMap = std::move(pathMap);
@@ -177,9 +164,7 @@ void MaterialLibrary::updatePaths(const QString& oldPath, const QString& newPath
void MaterialLibrary::renameFolder(const QString& oldPath, const QString& newPath)
{
QString filePath = getLocalPath(oldPath);
// Base::Console().Log("\tfilePath = '%s'\n", filePath.toStdString().c_str());
QString newFilePath = getLocalPath(newPath);
// Base::Console().Log("\tnew filePath = '%s'\n", newFilePath.toStdString().c_str());
QDir fileDir(filePath);
if (fileDir.exists()) {
@@ -192,25 +177,15 @@ void MaterialLibrary::renameFolder(const QString& oldPath, const QString& newPat
updatePaths(oldPath, newPath);
}
std::shared_ptr<Material> MaterialLibrary::saveMaterial(std::shared_ptr<Material> material,
std::shared_ptr<Material> MaterialLibrary::saveMaterial(const std::shared_ptr<Material>& material,
const QString& path,
bool overwrite,
bool saveAsCopy,
bool saveInherited)
{
QString filePath = getLocalPath(path);
// Base::Console().Log("\tfilePath = '%s'\n", filePath.toStdString().c_str());
QFile file(filePath);
// Update UUID if required
// if name changed true
// if (material->getName() != file.fileName()) {
// material->newUuid();
// }
// if overwrite false having warned the user
// if old format true, but already set
QFileInfo info(file);
QDir fileDir(info.path());
if (!fileDir.exists()) {
@@ -252,7 +227,7 @@ bool MaterialLibrary::fileExists(const QString& path) const
return info.exists();
}
std::shared_ptr<Material> MaterialLibrary::addMaterial(std::shared_ptr<Material> material,
std::shared_ptr<Material> MaterialLibrary::addMaterial(const std::shared_ptr<Material>& material,
const QString& path)
{
QString filePath = getRelativePath(path);
@@ -267,11 +242,6 @@ std::shared_ptr<Material> MaterialLibrary::addMaterial(std::shared_ptr<Material>
std::shared_ptr<Material> MaterialLibrary::getMaterialByPath(const QString& path) const
{
// Base::Console().Log("MaterialLibrary::getMaterialByPath(%s)\n", path.toStdString().c_str());
// for (auto itp = _materialPathMap->begin(); itp != _materialPathMap->end(); itp++) {
// Base::Console().Log("\tpath = '%s'\n", itp->first.toStdString().c_str());
// }
QString filePath = getRelativePath(path);
try {
auto material = _materialPathMap->at(filePath);
@@ -282,7 +252,7 @@ std::shared_ptr<Material> MaterialLibrary::getMaterialByPath(const QString& path
}
}
const QString MaterialLibrary::getUUIDFromPath(const QString& path) const
QString MaterialLibrary::getUUIDFromPath(const QString& path) const
{
QString filePath = getRelativePath(path);
try {
@@ -300,34 +270,32 @@ MaterialLibrary::getMaterialTree() const
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>> materialTree =
std::make_shared<std::map<QString, std::shared_ptr<MaterialTreeNode>>>();
for (auto it = _materialPathMap->begin(); it != _materialPathMap->end(); it++) {
auto filename = it->first;
auto material = it->second;
for (auto& it : *_materialPathMap) {
auto filename = it.first;
auto material = it.second;
// 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<MaterialTreeNode>>> node = materialTree;
for (auto itp = list.begin(); itp != list.end(); itp++) {
// Base::Console().Log("\t%s", itp->toStdString().c_str());
if (itp->endsWith(QString::fromStdString(".FCMat"))) {
for (auto& itp : list) {
if (itp.endsWith(QString::fromStdString(".FCMat"))) {
std::shared_ptr<MaterialTreeNode> child = std::make_shared<MaterialTreeNode>();
child->setData(material);
(*node)[*itp] = child;
(*node)[itp] = child;
}
else {
// Add the folder only if it's not already there
if (node->count(*itp) == 0) {
if (node->count(itp) == 0) {
auto mapPtr =
std::make_shared<std::map<QString, std::shared_ptr<MaterialTreeNode>>>();
std::shared_ptr<MaterialTreeNode> child = std::make_shared<MaterialTreeNode>();
child->setFolder(mapPtr);
(*node)[*itp] = child;
(*node)[itp] = child;
node = mapPtr;
}
else {
node = (*node)[*itp]->getFolder();
node = (*node)[itp]->getFolder();
}
}
}
@@ -341,18 +309,18 @@ MaterialLibrary::getMaterialTree() const
// Start at the root
auto node = materialTree;
for (auto itp = list.begin(); itp != list.end(); itp++) {
for (auto& itp : list) {
// Add the folder only if it's not already there
if (node->count(*itp) == 0) {
if (node->count(itp) == 0) {
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>> mapPtr =
std::make_shared<std::map<QString, std::shared_ptr<MaterialTreeNode>>>();
std::shared_ptr<MaterialTreeNode> child = std::make_shared<MaterialTreeNode>();
child->setFolder(mapPtr);
(*node)[*itp] = child;
(*node)[itp] = child;
node = mapPtr;
}
else {
node = (*node)[*itp]->getFolder();
node = (*node)[itp]->getFolder();
}
}
}
@@ -368,8 +336,3 @@ MaterialExternalLibrary::MaterialExternalLibrary(const QString& libraryName,
bool readOnly)
: MaterialLibrary(libraryName, dir, icon, readOnly)
{}
MaterialExternalLibrary::~MaterialExternalLibrary()
{
// delete directory;
}