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:
David Carter
2024-06-01 18:26:38 -04:00
committed by Chris Hennes
parent c4d0f3ed97
commit 5feb963f9d
55 changed files with 1540 additions and 714 deletions

View File

@@ -333,6 +333,11 @@ void MaterialProperty::setString(const QString& value)
_valuePtr->setValue(QVariant(value));
}
void MaterialProperty::setString(const std::string& value)
{
_valuePtr->setValue(QVariant(QString::fromStdString(value)));
}
void MaterialProperty::setBoolean(bool value)
{
_valuePtr->setValue(QVariant(value));
@@ -1545,13 +1550,21 @@ Material& Material::operator=(const App::Material& other)
addAppearance(ModelUUIDs::ModelUUID_Rendering_Basic);
}
getAppearanceProperty(QString::fromLatin1("AmbientColor"))->setColor(other.ambientColor);
getAppearanceProperty(QString::fromLatin1("DiffuseColor"))->setColor(other.diffuseColor);
getAppearanceProperty(QString::fromLatin1("SpecularColor"))->setColor(other.specularColor);
getAppearanceProperty(QString::fromLatin1("EmissiveColor"))->setColor(other.emissiveColor);
getAppearanceProperty(QString::fromLatin1("Shininess"))->setFloat(other.shininess);
getAppearanceProperty(QString::fromLatin1("Transparency"))->setFloat(other.transparency);
// std::string uuid;
getAppearanceProperty(QLatin1String("AmbientColor"))->setColor(other.ambientColor);
getAppearanceProperty(QLatin1String("DiffuseColor"))->setColor(other.diffuseColor);
getAppearanceProperty(QLatin1String("SpecularColor"))->setColor(other.specularColor);
getAppearanceProperty(QLatin1String("EmissiveColor"))->setColor(other.emissiveColor);
getAppearanceProperty(QLatin1String("Shininess"))->setFloat(other.shininess);
getAppearanceProperty(QLatin1String("Transparency"))->setFloat(other.transparency);
if (!other.image.empty() || !other.imagePath.empty()) {
if (!hasAppearanceModel(ModelUUIDs::ModelUUID_Rendering_Texture)) {
addAppearance(ModelUUIDs::ModelUUID_Rendering_Texture);
}
getAppearanceProperty(QLatin1String("TextureImage"))->setString(other.image);
getAppearanceProperty(QLatin1String("TexturePath"))->setString(other.imagePath);
}
return *this;
}
@@ -1641,33 +1654,46 @@ App::Material Material::getMaterialAppearance() const
App::Material material(App::Material::DEFAULT);
bool custom = false;
if (hasAppearanceProperty(QString::fromLatin1("AmbientColor"))) {
material.ambientColor =
getAppearanceProperty(QString::fromLatin1("AmbientColor"))->getColor();
if (hasAppearanceProperty(QLatin1String("AmbientColor"))) {
material.ambientColor = getAppearanceProperty(QLatin1String("AmbientColor"))->getColor();
custom = true;
}
if (hasAppearanceProperty(QString::fromLatin1("DiffuseColor"))) {
material.diffuseColor =
getAppearanceProperty(QString::fromLatin1("DiffuseColor"))->getColor();
if (hasAppearanceProperty(QLatin1String("DiffuseColor"))) {
material.diffuseColor = getAppearanceProperty(QLatin1String("DiffuseColor"))->getColor();
custom = true;
}
if (hasAppearanceProperty(QString::fromLatin1("SpecularColor"))) {
material.specularColor =
getAppearanceProperty(QString::fromLatin1("SpecularColor"))->getColor();
if (hasAppearanceProperty(QLatin1String("SpecularColor"))) {
material.specularColor = getAppearanceProperty(QLatin1String("SpecularColor"))->getColor();
custom = true;
}
if (hasAppearanceProperty(QString::fromLatin1("EmissiveColor"))) {
material.emissiveColor =
getAppearanceProperty(QString::fromLatin1("EmissiveColor"))->getColor();
if (hasAppearanceProperty(QLatin1String("EmissiveColor"))) {
material.emissiveColor = getAppearanceProperty(QLatin1String("EmissiveColor"))->getColor();
custom = true;
}
if (hasAppearanceProperty(QString::fromLatin1("Shininess"))) {
material.shininess = getAppearanceProperty(QString::fromLatin1("Shininess"))->getFloat();
if (hasAppearanceProperty(QLatin1String("Shininess"))) {
material.shininess = getAppearanceProperty(QLatin1String("Shininess"))->getFloat();
custom = true;
}
if (hasAppearanceProperty(QString::fromLatin1("Transparency"))) {
material.transparency =
getAppearanceProperty(QString::fromLatin1("Transparency"))->getFloat();
if (hasAppearanceProperty(QLatin1String("Transparency"))) {
material.transparency = getAppearanceProperty(QLatin1String("Transparency"))->getFloat();
custom = true;
}
if (hasAppearanceProperty(QLatin1String("TextureImage"))) {
auto property = getAppearanceProperty(QLatin1String("TextureImage"));
if (!property->isNull()) {
Base::Console().Log("Has 'TextureImage'\n");
material.image = property->getString().toStdString();
}
custom = true;
}
else if (hasAppearanceProperty(QLatin1String("TexturePath"))) {
auto property = getAppearanceProperty(QLatin1String("TexturePath"));
if (!property->isNull()) {
Base::Console().Log("Has 'TexturePath'\n");
material.imagePath = property->getString().toStdString();
}
custom = true;
}

View File

@@ -116,6 +116,7 @@ public:
void setValue(const QString& value);
void setValue(const std::shared_ptr<MaterialValue>& value);
void setString(const QString& value);
void setString(const std::string& value);
void setBoolean(bool value);
void setBoolean(int value);
void setBoolean(const QString& value);

View File

@@ -21,15 +21,23 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include <QImage>
#include <QImageReader>
#include <Inventor/nodes/SoGroup.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoOrthographicCamera.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.h>
#include <Inventor/nodes/SoSwitch.h>
#include <Inventor/nodes/SoTexture2.h>
#endif
#include <Inventor/nodes/SoTextureCoordinateEnvironment.h>
#include <App/Application.h>
#include <Base/Parameter.h>
#include <Gui/BitmapFactory.h>
#include "AppearancePreview.h"
@@ -123,11 +131,24 @@ AppearancePreview::AppearancePreview(QWidget* parent)
// setBackground();
setEnabledNaviCube(false);
auto root = dynamic_cast<SoSeparator*>(getSceneGraph());
_group = dynamic_cast<SoSeparator*>(getSceneGraph());
_group->ref();
_switch = new SoSwitch();
_switch->ref();
_material = new SoMaterial();
_material->ref();
root->addChild(_material);
root->addChild(new SoSphere());
_texture = new SoTexture2();
_texture->ref();
_environment = new SoTextureCoordinateEnvironment();
_environment->ref();
_switch->addChild(_material);
_switch->addChild(_texture);
_switch->whichChild.setValue(0);
_group->addChild(_switch);
_group->addChild(new SoSphere());
setCameraType(SoOrthographicCamera::getClassTypeId());
setViewDirection(SbVec3f(1, 1, -5));
@@ -136,8 +157,30 @@ AppearancePreview::AppearancePreview(QWidget* parent)
AppearancePreview::~AppearancePreview()
{
if (_switch) {
if (_switch->findChild(_material) > -1) {
_switch->removeChild(_material);
}
if (_switch->findChild(_texture) > -1) {
_switch->removeChild(_texture);
}
}
if (_group) {
if (_group->findChild(_switch) > -1) {
_group->removeChild(_switch);
}
}
_group->unref();
_group = nullptr;
_switch->unref();
_switch = nullptr;
_material->unref();
_material = nullptr;
_texture->unref();
_texture = nullptr;
_environment->unref();
_environment = nullptr;
}
void AppearancePreview::applySettings()
@@ -148,8 +191,19 @@ void AppearancePreview::applySettings()
viewSettings->applySettings();
}
void AppearancePreview::setCoinTexture()
{
_switch->whichChild.setValue(1);
}
void AppearancePreview::setCoinMaterial()
{
_switch->whichChild.setValue(0);
}
void AppearancePreview::setAmbientColor(const QColor& color)
{
setCoinMaterial();
_material->ambientColor.setValue(
SbColor(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0));
_material->ambientColor.setDefault(false);
@@ -157,6 +211,7 @@ void AppearancePreview::setAmbientColor(const QColor& color)
void AppearancePreview::setDiffuseColor(const QColor& color)
{
setCoinMaterial();
_material->diffuseColor.setValue(
SbColor(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0));
_material->diffuseColor.setDefault(false);
@@ -164,6 +219,7 @@ void AppearancePreview::setDiffuseColor(const QColor& color)
void AppearancePreview::setSpecularColor(const QColor& color)
{
setCoinMaterial();
_material->specularColor.setValue(
SbColor(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0));
_material->specularColor.setDefault(false);
@@ -171,6 +227,7 @@ void AppearancePreview::setSpecularColor(const QColor& color)
void AppearancePreview::setEmissiveColor(const QColor& color)
{
setCoinMaterial();
_material->emissiveColor.setValue(
SbColor(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0));
_material->emissiveColor.setDefault(false);
@@ -178,48 +235,74 @@ void AppearancePreview::setEmissiveColor(const QColor& color)
void AppearancePreview::setShininess(double value)
{
setCoinMaterial();
_material->shininess.setValue(value);
_material->shininess.setDefault(false);
}
void AppearancePreview::setTransparency(double value)
{
setCoinMaterial();
_material->transparency.setValue(value);
_material->transparency.setDefault(false);
}
void AppearancePreview::setTexture(const QImage& image)
{
setCoinTexture();
SoSFImage texture;
Gui::BitmapFactory().convert(image, texture);
_texture->image = texture;
}
void AppearancePreview::setTextureScaling(double scale)
{}
void AppearancePreview::resetAmbientColor()
{
setCoinMaterial();
_material->ambientColor.deleteValues(0);
_material->ambientColor.setDefault(true);
}
void AppearancePreview::resetDiffuseColor()
{
setCoinMaterial();
_material->diffuseColor.deleteValues(0);
_material->diffuseColor.setDefault(true);
}
void AppearancePreview::resetSpecularColor()
{
setCoinMaterial();
_material->specularColor.deleteValues(0);
_material->specularColor.setDefault(true);
}
void AppearancePreview::resetEmissiveColor()
{
setCoinMaterial();
_material->emissiveColor.deleteValues(0);
_material->emissiveColor.setDefault(true);
}
void AppearancePreview::resetShininess()
{
setCoinMaterial();
_material->shininess.deleteValues(0);
_material->shininess.setDefault(true);
}
void AppearancePreview::resetTransparency()
{
setCoinMaterial();
_material->transparency.deleteValues(0);
_material->transparency.setDefault(true);
}
void AppearancePreview::resetTexture()
{}
void AppearancePreview::resetTextureScaling()
{}

View File

@@ -26,7 +26,11 @@
#include <Gui/View3DInventorViewer.h>
#include <Gui/View3DSettings.h>
class SoGroup;
class SoMaterial;
class SoSwitch;
class SoTexture2;
class SoTextureCoordinateEnvironment;
namespace MatGui
{
@@ -57,6 +61,8 @@ public:
void setEmissiveColor(const QColor& color);
void setShininess(double value);
void setTransparency(double value);
void setTexture(const QImage& image);
void setTextureScaling(double scale);
void resetAmbientColor();
void resetDiffuseColor();
@@ -64,12 +70,20 @@ public:
void resetEmissiveColor();
void resetShininess();
void resetTransparency();
void resetTexture();
void resetTextureScaling();
private:
SoSeparator* _group;
SoSwitch* _switch;
SoMaterial* _material;
SoTexture2* _texture;
SoTextureCoordinateEnvironment* _environment;
std::unique_ptr<AppearanceSettings> viewSettings;
void applySettings();
void setCoinTexture();
void setCoinMaterial();
};
} // namespace MatGui

View File

@@ -369,7 +369,7 @@
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Shape Appearance:</string>
<string>Custom Appearance</string>
</property>
</widget>
</item>
@@ -401,7 +401,7 @@
<widget class="Gui::ColorButton" name="buttonLineColor"/>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="buttonUserDefinedMaterial">
<widget class="QPushButton" name="buttonCustomAppearance">
<property name="text">
<string notr="true">...</string>
</property>

View File

@@ -167,7 +167,6 @@ DlgDisplayPropertiesImp::DlgDisplayPropertiesImp(bool floating, QWidget* parent,
std::vector<Gui::ViewProvider*> views = getSelection();
setDisplayModes(views);
setMaterial(views);
setColorPlot(views);
setShapeAppearance(views);
setLineColor(views);
@@ -276,10 +275,10 @@ void DlgDisplayPropertiesImp::setupConnections()
qOverload<int>(&QSpinBox::valueChanged),
this,
&DlgDisplayPropertiesImp::onSpinLineTransparencyValueChanged);
connect(d->ui.buttonUserDefinedMaterial,
connect(d->ui.buttonCustomAppearance,
&Gui::ColorButton::clicked,
this,
&DlgDisplayPropertiesImp::onButtonUserDefinedMaterialClicked);
&DlgDisplayPropertiesImp::onbuttonCustomAppearanceClicked);
connect(d->ui.buttonColorPlot,
&Gui::ColorButton::clicked,
this,
@@ -309,7 +308,6 @@ void DlgDisplayPropertiesImp::OnChange(Gui::SelectionSingleton::SubjectType& rCa
|| Reason.Type == Gui::SelectionChanges::ClrSelection) {
std::vector<Gui::ViewProvider*> views = getSelection();
setDisplayModes(views);
setMaterial(views);
setColorPlot(views);
setShapeAppearance(views);
setLineColor(views);
@@ -357,15 +355,10 @@ void DlgDisplayPropertiesImp::slotChangedObject(const Gui::ViewProvider& obj,
}
}
else if (prop.isDerivedFrom<App::PropertyMaterialList>()) {
//auto& value = static_cast<const App::PropertyMaterialList&>(prop).getValue();
if (prop_name == "ShapeAppearance") {
// Base::Console().Log("slotChangeObject(ShapeAppearance)\n");
// bool blocked = d->ui.buttonColor->blockSignals(true);
// auto color = value.diffuseColor;
// d->ui.buttonColor->setColor(QColor((int)(255.0f * color.r),
// (int)(255.0f * color.g),
// (int)(255.0f * color.b)));
// d->ui.buttonColor->blockSignals(blocked);
auto& values = static_cast<const App::PropertyMaterialList&>(prop).getValues();
auto& material = values[0];
d->ui.widgetMaterial->setMaterial(QString::fromStdString(material.uuid));
}
}
else if (prop.isDerivedFrom<App::PropertyInteger>()) {
@@ -419,10 +412,10 @@ void DlgDisplayPropertiesImp::reject()
/**
* Opens a dialog that allows to modify the 'ShapeMaterial' property of all selected view providers.
*/
void DlgDisplayPropertiesImp::onButtonUserDefinedMaterialClicked()
void DlgDisplayPropertiesImp::onbuttonCustomAppearanceClicked()
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
Gui::Dialog::DlgMaterialPropertiesImp dlg("ShapeMaterial", this);
Gui::Dialog::DlgMaterialPropertiesImp dlg("ShapeAppearance", this);
dlg.setViewProviders(Provider);
dlg.exec();
@@ -586,25 +579,6 @@ void DlgDisplayPropertiesImp::setDisplayModes(const std::vector<Gui::ViewProvide
}
}
void DlgDisplayPropertiesImp::setMaterial(const std::vector<Gui::ViewProvider*>& views)
{
Q_UNUSED(views);
// bool material = false;
// App::Material mat = App::Material(App::Material::DEFAULT);
// for (auto view : views) {
// if (auto* prop =
// dynamic_cast<App::PropertyMaterial*>(view->getPropertyByName("ShapeMaterial"))) {
// mat = prop->getValue();
// material = mat.uuid.empty();
// if (!material) {
// d->ui.widgetMaterial->setMaterial(QString::fromStdString(mat.uuid));
// }
// break;
// }
// }
// d->ui.buttonUserDefinedMaterial->setEnabled(material);
}
void DlgDisplayPropertiesImp::setColorPlot(const std::vector<Gui::ViewProvider*>& views)
{
bool material = false;
@@ -627,16 +601,13 @@ void DlgDisplayPropertiesImp::setShapeAppearance(const std::vector<Gui::ViewProv
for (auto view : views) {
if (auto* prop =
dynamic_cast<App::PropertyMaterialList*>(view->getPropertyByName("ShapeAppearance"))) {
material = true;
mat = prop->getValues()[0];
material = mat.uuid.empty();
if (!material) {
d->ui.widgetMaterial->setMaterial(QString::fromStdString(mat.uuid));
}
d->ui.widgetMaterial->setMaterial(QString::fromStdString(mat.uuid));
break;
}
}
// d->ui.buttonUserDefinedMaterial->setEnabled(material);
d->ui.buttonUserDefinedMaterial->setEnabled(true);
d->ui.buttonCustomAppearance->setEnabled(material);
}
void DlgDisplayPropertiesImp::setLineColor(const std::vector<Gui::ViewProvider*>& views)
@@ -694,21 +665,7 @@ void DlgDisplayPropertiesImp::onMaterialSelected(
for (auto it : Provider) {
if (auto* prop = dynamic_cast<App::PropertyMaterialList*>(
it->getPropertyByName("ShapeAppearance"))) {
App::Material mat;
mat.ambientColor =
material->getAppearanceProperty(QString::fromLatin1("AmbientColor"))->getColor();
mat.diffuseColor =
material->getAppearanceProperty(QString::fromLatin1("DiffuseColor"))->getColor();
mat.emissiveColor =
material->getAppearanceProperty(QString::fromLatin1("EmissiveColor"))->getColor();
mat.specularColor =
material->getAppearanceProperty(QString::fromLatin1("SpecularColor"))->getColor();
mat.shininess =
material->getAppearanceProperty(QString::fromLatin1("Shininess"))->getFloat();
mat.transparency =
material->getAppearanceProperty(QString::fromLatin1("Transparency"))->getFloat();
mat.uuid = material->getUUID().toStdString();
prop->setValue(mat);
prop->setValue(material->getMaterialAppearance());
}
}
}

View File

@@ -75,7 +75,7 @@ private Q_SLOTS:
void onButtonPointColorChanged();
void onSpinLineWidthValueChanged(int);
void onSpinLineTransparencyValueChanged(int);
void onButtonUserDefinedMaterialClicked();
void onbuttonCustomAppearanceClicked();
void onButtonColorPlotClicked();
void onMaterialSelected(const std::shared_ptr<Materials::Material>& material);
@@ -87,7 +87,6 @@ private:
void setupFilters();
void slotChangedObject(const Gui::ViewProvider&, const App::Property& Prop);
void setDisplayModes(const std::vector<Gui::ViewProvider*>&);
void setMaterial(const std::vector<Gui::ViewProvider*>&);
void setColorPlot(const std::vector<Gui::ViewProvider*>&);
void setShapeAppearance(const std::vector<Gui::ViewProvider*>&);
void setLineColor(const std::vector<Gui::ViewProvider*>&);

View File

@@ -31,7 +31,6 @@
#include <Base/Console.h>
#include <Gui/Application.h>
#include <Gui/DlgMaterialPropertiesImp.h>
#include <Gui/DockWindowManager.h>
#include <Gui/Document.h>
#include <Gui/Selection.h>

View File

@@ -285,9 +285,19 @@ QModelIndex MaterialTreeWidget::findInTree(const QString& uuid)
void MaterialTreeWidget::setMaterial(const QString& uuid)
{
if (uuid.isEmpty() || uuid == m_uuid) {
if (uuid == m_uuid) {
return;
}
if (uuid.isEmpty()) {
// Nothing is selected
QItemSelectionModel* selectionModel = m_materialTree->selectionModel();
selectionModel->clear();
m_material->clear();
return;
}
updateMaterial(uuid);
// Now select the material in the tree
@@ -634,6 +644,11 @@ void MaterialTreeWidget::onSelectMaterial(const QItemSelection& selected,
{
Q_UNUSED(deselected);
if (selected.isEmpty()) {
m_uuid.clear();
return;
}
// Get the UUID before changing the underlying data model
QString uuid;
auto model = dynamic_cast<QStandardItemModel*>(m_materialTree->model());

View File

@@ -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;

View File

@@ -152,6 +152,8 @@ private:
void onInheritNew(bool checked);
void setMaterialDefaults();
bool updateTexturePreview() const;
bool updateMaterialPreview() const;
void updatePreview() const;
static QString getColorHash(const QString& colorString, int colorRange = 255);

View File

@@ -61,10 +61,10 @@
#include <Gui/QtAll.h>
#endif
// // Inventor includes OpenGL
// #ifndef __InventorAll__
// # include <Gui/InventorAll.h>
// #endif
// Inventor includes OpenGL
#ifndef __InventorAll__
# include <Gui/InventorAll.h>
#endif
#endif //_PreComp_

View File

@@ -35,8 +35,9 @@ AppearanceModel:
Type: 'File'
Units: ''
URL: ''
Description: "Path to file containing a texture image. Only used if TextureImage is unpopulated"
Description: "Path to file containing a texture image. Only used if Texture Image is unpopulated"
TextureImage:
DisplayName: "Texture Image"
Type: 'Image'
Units: ''
URL: ''