Material: Compatibility with older FCMat files

Provides compatibility loading older files outside the context of
a library.

Older material files were loaded by specifying a path. The new
material system used the path to associated the material with a
library, which may not be appropriate for legacy files. This change
allows the use of materials outside of a library.

Additionally, legacy files often have name/value pairs not part of the
standard list of properties. Since these were unable to be mapped to
a model property they were ignored. Materials now maintain a legacy
map to hold properties not associated with a property model. These
properties are considered transient and will not be saved. It is not
intended for this feature to be used as a generic container for
properties not mapped to an appropriate model.

Fixes #13302
This commit is contained in:
David Carter
2024-04-06 15:41:07 -04:00
committed by Yorik van Havre
parent 2f81d8712b
commit bc36c8dab5
8 changed files with 135 additions and 0 deletions

View File

@@ -499,6 +499,9 @@ Material::Material(const Material& other)
MaterialProperty prop(it.second);
_appearance[it.first] = std::make_shared<MaterialProperty>(prop);
}
for (auto& it : other._legacy) {
_legacy[it.first] = it.second;
}
}
QString Material::getAuthorAndLicense() const
@@ -890,6 +893,13 @@ void Material::setAppearanceValue(const QString& name,
}
}
void Material::setLegacyValue(const QString& name, const QString& value)
{
setEditStateAlter();
_legacy[name] = value;
}
std::shared_ptr<MaterialProperty> Material::getPhysicalProperty(const QString& name)
{
try {
@@ -1047,6 +1057,19 @@ bool Material::hasAppearanceProperty(const QString& name) const
return true;
}
bool Material::hasNonLegacyProperty(const QString& name) const
{
if (hasPhysicalProperty(name) || hasAppearanceProperty(name)) {
return true;
}
return false;
}
bool Material::hasLegacyProperties() const
{
return !_legacy.empty();
}
bool Material::isInherited(const QString& uuid) const
{
if (_physicalUuids.contains(uuid)) {
@@ -1464,6 +1487,10 @@ Material& Material::operator=(const Material& other)
MaterialProperty prop(it.second);
_appearance[it.first] = std::make_shared<MaterialProperty>(prop);
}
_legacy.clear();
for (auto& it : other._legacy) {
_legacy[it.first] = it.second;
}
return *this;
}