Material: Appearance Updates 2
Improves the use of the ShapeAppearance property for the Part workbench.
removes DiffuseColor property
adds Python compatibility using custom attributes
transitions DiffuseColor to ShapeAppearance on open
Improved UI elements for setting object appearance, and appearance per face
Lays the foundation for future texture support
This commit is contained in:
committed by
Chris Hennes
parent
c4d0f3ed97
commit
5feb963f9d
@@ -89,7 +89,7 @@ void MaterialsEditor::setup()
|
||||
Gui::WaitCursor wc;
|
||||
ui->setupUi(this);
|
||||
|
||||
_warningIcon = QIcon(QString::fromStdString(":/icons/Warning.svg"));
|
||||
_warningIcon = QIcon(QLatin1String(":/icons/Warning.svg"));
|
||||
|
||||
getFavorites();
|
||||
getRecents();
|
||||
@@ -108,7 +108,7 @@ void MaterialsEditor::setup()
|
||||
|
||||
resize(width, height);
|
||||
|
||||
ui->buttonURL->setIcon(QIcon(QString::fromStdString(":/icons/internet-web-browser.svg")));
|
||||
ui->buttonURL->setIcon(QIcon(QLatin1String(":/icons/internet-web-browser.svg")));
|
||||
|
||||
connect(ui->standardButtons->button(QDialogButtonBox::Ok),
|
||||
&QPushButton::clicked,
|
||||
@@ -491,7 +491,7 @@ void MaterialsEditor::setMaterialDefaults()
|
||||
const char* name = App::licenseItems.at(index).at(App::posnOfFullName);
|
||||
// const char* url = App::licenseItems.at(index).at(App::posnOfUrl);
|
||||
// std::string licenseUrl = (paramGrp->GetASCII("prefLicenseUrl", url));
|
||||
_material->setLicense(QString::fromStdString(name));
|
||||
_material->setLicense(QLatin1String(name));
|
||||
|
||||
// Empty materials will have no parent
|
||||
_materialManager.dereference(_material);
|
||||
@@ -894,54 +894,120 @@ void MaterialsEditor::refreshMaterialTree()
|
||||
fillMaterialTree();
|
||||
}
|
||||
|
||||
void MaterialsEditor::updatePreview() const
|
||||
bool MaterialsEditor::updateTexturePreview() const
|
||||
{
|
||||
if (_material->hasAppearanceProperty(QString::fromStdString("AmbientColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QString::fromStdString("AmbientColor"));
|
||||
bool hasImage = false;
|
||||
QImage image;
|
||||
double scaling = 99.0;
|
||||
if (_material->hasModel(Materials::ModelUUIDs::ModelUUID_Rendering_Texture)) {
|
||||
// First try loading an embedded image
|
||||
try {
|
||||
auto property = _material->getAppearanceProperty(QLatin1String("TextureImage"));
|
||||
if (!property->isNull()) {
|
||||
// Base::Console().Log("Has 'TextureImage'\n");
|
||||
auto propertyValue = property->getString();
|
||||
if (!propertyValue.isEmpty()) {
|
||||
QByteArray by = QByteArray::fromBase64(propertyValue.toUtf8());
|
||||
image = QImage::fromData(by, "PNG"); //.scaled(64, 64, Qt::KeepAspectRatio);
|
||||
hasImage = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const Materials::PropertyNotFound&) {
|
||||
}
|
||||
|
||||
// If no embedded image, load from a path
|
||||
if (!hasImage) {
|
||||
try {
|
||||
auto property = _material->getAppearanceProperty(QLatin1String("TexturePath"));
|
||||
if (!property->isNull()) {
|
||||
// Base::Console().Log("Has 'TexturePath'\n");
|
||||
auto filePath = property->getString();
|
||||
if (!image.load(filePath)) {
|
||||
Base::Console().Log("Unable to load image '%s'\n",
|
||||
filePath.toStdString().c_str());
|
||||
// return; // ???
|
||||
}
|
||||
hasImage = true;
|
||||
}
|
||||
}
|
||||
catch (const Materials::PropertyNotFound&) {
|
||||
}
|
||||
}
|
||||
|
||||
// Apply any scaling
|
||||
try {
|
||||
auto property = _material->getAppearanceProperty(QLatin1String("TextureScaling"));
|
||||
if (!property->isNull()) {
|
||||
scaling = property->getFloat();
|
||||
// Base::Console().Log("Has 'TextureScaling' = %g\n", scaling);
|
||||
}
|
||||
}
|
||||
catch (const Materials::PropertyNotFound&) {
|
||||
}
|
||||
|
||||
if (hasImage) {
|
||||
_rendered->setTexture(image);
|
||||
}
|
||||
}
|
||||
|
||||
return hasImage;
|
||||
}
|
||||
|
||||
bool MaterialsEditor::updateMaterialPreview() const
|
||||
{
|
||||
if (_material->hasAppearanceProperty(QLatin1String("AmbientColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QLatin1String("AmbientColor"));
|
||||
_rendered->setAmbientColor(getColorHash(color, 255));
|
||||
}
|
||||
else {
|
||||
_rendered->resetAmbientColor();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QString::fromStdString("DiffuseColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QString::fromStdString("DiffuseColor"));
|
||||
if (_material->hasAppearanceProperty(QLatin1String("DiffuseColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QLatin1String("DiffuseColor"));
|
||||
_rendered->setDiffuseColor(getColorHash(color, 255));
|
||||
}
|
||||
else {
|
||||
_rendered->resetDiffuseColor();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QString::fromStdString("SpecularColor"))) {
|
||||
QString color =
|
||||
_material->getAppearanceValueString(QString::fromStdString("SpecularColor"));
|
||||
if (_material->hasAppearanceProperty(QLatin1String("SpecularColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QLatin1String("SpecularColor"));
|
||||
_rendered->setSpecularColor(getColorHash(color, 255));
|
||||
}
|
||||
else {
|
||||
_rendered->resetSpecularColor();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QString::fromStdString("EmissiveColor"))) {
|
||||
QString color =
|
||||
_material->getAppearanceValueString(QString::fromStdString("EmissiveColor"));
|
||||
if (_material->hasAppearanceProperty(QLatin1String("EmissiveColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QLatin1String("EmissiveColor"));
|
||||
_rendered->setEmissiveColor(getColorHash(color, 255));
|
||||
}
|
||||
else {
|
||||
_rendered->resetEmissiveColor();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QString::fromStdString("Shininess"))) {
|
||||
double value =
|
||||
_material->getAppearanceValue(QString::fromStdString("Shininess")).toDouble();
|
||||
if (_material->hasAppearanceProperty(QLatin1String("Shininess"))) {
|
||||
double value = _material->getAppearanceValue(QLatin1String("Shininess")).toDouble();
|
||||
_rendered->setShininess(value);
|
||||
}
|
||||
else {
|
||||
_rendered->resetShininess();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QString::fromStdString("Transparency"))) {
|
||||
double value =
|
||||
_material->getAppearanceValue(QString::fromStdString("Transparency")).toDouble();
|
||||
if (_material->hasAppearanceProperty(QLatin1String("Transparency"))) {
|
||||
double value = _material->getAppearanceValue(QLatin1String("Transparency")).toDouble();
|
||||
_rendered->setTransparency(value);
|
||||
}
|
||||
else {
|
||||
_rendered->resetTransparency();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MaterialsEditor::updatePreview() const
|
||||
{
|
||||
if (updateTexturePreview()) {
|
||||
return;
|
||||
}
|
||||
updateMaterialPreview();
|
||||
}
|
||||
|
||||
QString MaterialsEditor::getColorHash(const QString& colorString, int colorRange)
|
||||
@@ -1108,12 +1174,12 @@ QString MaterialsEditor::libraryPath(const std::shared_ptr<Materials::Material>&
|
||||
QString path;
|
||||
auto library = material->getLibrary();
|
||||
if (library) {
|
||||
path = QString::fromStdString("/%1/%2")
|
||||
path = QString::fromLatin1("/%1/%2")
|
||||
.arg(material->getLibrary()->getName())
|
||||
.arg(material->getDirectory());
|
||||
}
|
||||
else {
|
||||
path = QString::fromStdString("%1").arg(material->getDirectory());
|
||||
path = QString::fromLatin1("%1").arg(material->getDirectory());
|
||||
}
|
||||
|
||||
return path;
|
||||
|
||||
Reference in New Issue
Block a user