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
@@ -271,7 +271,7 @@ protected:
|
||||
std::make_pair(QT_TRANSLATE_NOOP("EditMode", "Color"),
|
||||
QT_TRANSLATE_NOOP("EditMode",
|
||||
"The object will have the color of its individual faces "
|
||||
"editable with the Part FaceColors command"))},
|
||||
"editable with the Part FaceAppearances command"))},
|
||||
};
|
||||
int userEditMode = userEditModes.begin()->first;
|
||||
|
||||
|
||||
@@ -41,62 +41,6 @@
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel2">
|
||||
<property name="text">
|
||||
<string>Ambient color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::ColorButton" name="ambientColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="textLabel1">
|
||||
<property name="text">
|
||||
<string>Diffuse color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="Gui::ColorButton" name="diffuseColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Emissive color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="Gui::ColorButton" name="emissiveColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="textLabel3">
|
||||
<property name="text">
|
||||
<string>Specular color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="Gui::ColorButton" name="specularColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
@@ -149,6 +93,76 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="textLabel1">
|
||||
<property name="text">
|
||||
<string>Diffuse color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::ColorButton" name="ambientColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="Gui::ColorButton" name="emissiveColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="textLabel3">
|
||||
<property name="text">
|
||||
<string>Specular color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="Gui::ColorButton" name="diffuseColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel2">
|
||||
<property name="text">
|
||||
<string>Ambient color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="Gui::ColorButton" name="specularColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Emissive color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QPushButton" name="buttonReset">
|
||||
<property name="text">
|
||||
<string>Reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QPushButton" name="buttonDefault">
|
||||
<property name="text">
|
||||
<string>Default</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include <App/Color.h>
|
||||
#include <App/Material.h>
|
||||
#include <App/PropertyStandard.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "DlgMaterialPropertiesImp.h"
|
||||
#include "ui_DlgMaterialProperties.h"
|
||||
#include "ViewProvider.h"
|
||||
@@ -46,11 +49,12 @@ DlgMaterialPropertiesImp::DlgMaterialPropertiesImp(const std::string& mat, QWidg
|
||||
: QDialog(parent, fl)
|
||||
, ui(new Ui_DlgMaterialProperties)
|
||||
, material(mat)
|
||||
, updateColors(true)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setupConnections();
|
||||
|
||||
if (material != "ShapeMaterial") {
|
||||
if (material != "ShapeAppearance") {
|
||||
ui->textLabel1->hide();
|
||||
ui->diffuseColor->hide();
|
||||
}
|
||||
@@ -68,6 +72,8 @@ DlgMaterialPropertiesImp::~DlgMaterialPropertiesImp() = default;
|
||||
|
||||
void DlgMaterialPropertiesImp::setupConnections()
|
||||
{
|
||||
Base::Console().Log("DlgMaterialPropertiesImp::setupConnections()\n");
|
||||
|
||||
connect(ui->ambientColor, &ColorButton::changed,
|
||||
this, &DlgMaterialPropertiesImp::onAmbientColorChanged);
|
||||
connect(ui->diffuseColor, &ColorButton::changed,
|
||||
@@ -78,6 +84,10 @@ void DlgMaterialPropertiesImp::setupConnections()
|
||||
this, &DlgMaterialPropertiesImp::onSpecularColorChanged);
|
||||
connect(ui->shininess, qOverload<int>(&QSpinBox::valueChanged),
|
||||
this, &DlgMaterialPropertiesImp::onShininessValueChanged);
|
||||
connect(ui->buttonReset, &QPushButton::clicked,
|
||||
this, &DlgMaterialPropertiesImp::onButtonReset);
|
||||
connect(ui->buttonDefault, &QPushButton::clicked,
|
||||
this, &DlgMaterialPropertiesImp::onButtonDefault);
|
||||
}
|
||||
|
||||
QColor DlgMaterialPropertiesImp::diffuseColor() const
|
||||
@@ -85,24 +95,54 @@ QColor DlgMaterialPropertiesImp::diffuseColor() const
|
||||
return ui->diffuseColor->color();
|
||||
}
|
||||
|
||||
App::Material DlgMaterialPropertiesImp::getMaterial()
|
||||
{
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto& materials = ShapeAppearance->getValues();
|
||||
auto mat = materials[0];
|
||||
|
||||
mat.setType(App::Material::USER_DEFINED);
|
||||
|
||||
// Reset any texture data
|
||||
mat.image = "";
|
||||
mat.imagePath = "";
|
||||
mat.uuid = "";
|
||||
|
||||
return mat;
|
||||
}
|
||||
}
|
||||
|
||||
return App::Material::getDefaultAppearance();
|
||||
}
|
||||
|
||||
App::Color DlgMaterialPropertiesImp::getColor(const QColor& color) const
|
||||
{
|
||||
float r = (float)color.red() / 255.0F;
|
||||
float g = (float)color.green() / 255.0F;
|
||||
float b = (float)color.blue() / 255.0F;
|
||||
|
||||
return App::Color(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ambient color.
|
||||
*/
|
||||
void DlgMaterialPropertiesImp::onAmbientColorChanged()
|
||||
{
|
||||
QColor col = ui->ambientColor->color();
|
||||
float r = (float)col.red() / 255.0f;
|
||||
float g = (float)col.green() / 255.0f;
|
||||
float b = (float)col.blue() / 255.0f;
|
||||
App::Color ambient(r, g, b);
|
||||
if (updateColors) {
|
||||
App::Color ambient = getColor(ui->ambientColor->color());
|
||||
|
||||
for (std::vector<ViewProvider*>::iterator it= Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterial>()) {
|
||||
auto ShapeMaterial = static_cast<App::PropertyMaterial*>(prop);
|
||||
App::Material mat = ShapeMaterial->getValue();
|
||||
mat.ambientColor = ambient;
|
||||
ShapeMaterial->setValue(mat);
|
||||
for (std::vector<ViewProvider*>::iterator it= Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto mat = getMaterial();
|
||||
mat.ambientColor = ambient;
|
||||
ShapeAppearance->setValue(mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,19 +152,17 @@ void DlgMaterialPropertiesImp::onAmbientColorChanged()
|
||||
*/
|
||||
void DlgMaterialPropertiesImp::onDiffuseColorChanged()
|
||||
{
|
||||
QColor col = ui->diffuseColor->color();
|
||||
float r = (float)col.red() / 255.0f;
|
||||
float g = (float)col.green() / 255.0f;
|
||||
float b = (float)col.blue() / 255.0f;
|
||||
App::Color diffuse(r, g, b);
|
||||
if (updateColors) {
|
||||
App::Color diffuse = getColor(ui->diffuseColor->color());
|
||||
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterial>()) {
|
||||
auto ShapeMaterial = static_cast<App::PropertyMaterial*>(prop);
|
||||
App::Material mat = ShapeMaterial->getValue();
|
||||
mat.diffuseColor = diffuse;
|
||||
ShapeMaterial->setValue(mat);
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto mat = getMaterial();
|
||||
mat.diffuseColor = diffuse;
|
||||
ShapeAppearance->setValue(mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,19 +172,17 @@ void DlgMaterialPropertiesImp::onDiffuseColorChanged()
|
||||
*/
|
||||
void DlgMaterialPropertiesImp::onEmissiveColorChanged()
|
||||
{
|
||||
QColor col = ui->emissiveColor->color();
|
||||
float r = (float)col.red() / 255.0f;
|
||||
float g = (float)col.green() / 255.0f;
|
||||
float b = (float)col.blue() / 255.0f;
|
||||
App::Color emissive(r, g, b);
|
||||
if (updateColors) {
|
||||
App::Color emissive = getColor(ui->emissiveColor->color());
|
||||
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterial>()) {
|
||||
auto ShapeMaterial = static_cast<App::PropertyMaterial*>(prop);
|
||||
App::Material mat = ShapeMaterial->getValue();
|
||||
mat.emissiveColor = emissive;
|
||||
ShapeMaterial->setValue(mat);
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto mat = getMaterial();
|
||||
mat.emissiveColor = emissive;
|
||||
ShapeAppearance->setValue(mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,19 +192,17 @@ void DlgMaterialPropertiesImp::onEmissiveColorChanged()
|
||||
*/
|
||||
void DlgMaterialPropertiesImp::onSpecularColorChanged()
|
||||
{
|
||||
QColor col = ui->specularColor->color();
|
||||
float r = (float)col.red() / 255.0f;
|
||||
float g = (float)col.green() / 255.0f;
|
||||
float b = (float)col.blue() / 255.0f;
|
||||
App::Color specular(r, g, b);
|
||||
if (updateColors) {
|
||||
App::Color specular = getColor(ui->specularColor->color());
|
||||
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterial>()) {
|
||||
auto ShapeMaterial = static_cast<App::PropertyMaterial*>(prop);
|
||||
App::Material mat = ShapeMaterial->getValue();
|
||||
mat.specularColor = specular;
|
||||
ShapeMaterial->setValue(mat);
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto mat = getMaterial();
|
||||
mat.specularColor = specular;
|
||||
ShapeAppearance->setValue(mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,14 +212,63 @@ void DlgMaterialPropertiesImp::onSpecularColorChanged()
|
||||
*/
|
||||
void DlgMaterialPropertiesImp::onShininessValueChanged(int sh)
|
||||
{
|
||||
float shininess = (float)sh / 100.0f;
|
||||
if (updateColors) {
|
||||
float shininess = (float)sh / 100.0F;
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto mat = getMaterial();
|
||||
mat.shininess = shininess;
|
||||
ShapeAppearance->setValue(mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the colors to the Coin3D defaults
|
||||
*/
|
||||
void DlgMaterialPropertiesImp::onButtonReset(bool checked)
|
||||
{
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterial>()) {
|
||||
auto ShapeMaterial = static_cast<App::PropertyMaterial*>(prop);
|
||||
App::Material mat = ShapeMaterial->getValue();
|
||||
mat.shininess = shininess;
|
||||
ShapeMaterial->setValue(mat);
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto mat = getMaterial();
|
||||
|
||||
App::Color defaultAmbient(0.2, 0.2, 0.2);
|
||||
App::Color defaultDiffuse(0.8, 0.8, 0.8);
|
||||
App::Color black(0, 0, 0);
|
||||
|
||||
mat.ambientColor = defaultAmbient;
|
||||
mat.diffuseColor = defaultDiffuse;
|
||||
mat.emissiveColor = black;
|
||||
mat.specularColor = black;
|
||||
mat.shininess = 0.2;
|
||||
ShapeAppearance->setValue(mat);
|
||||
|
||||
setButtonColors();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the colors to the current default
|
||||
*/
|
||||
void DlgMaterialPropertiesImp::onButtonDefault(bool checked)
|
||||
{
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto mat = App::Material::getDefaultAppearance();
|
||||
|
||||
ShapeAppearance->setValue(mat);
|
||||
|
||||
setButtonColors();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,33 +280,82 @@ void DlgMaterialPropertiesImp::setViewProviders(const std::vector<Gui::ViewProvi
|
||||
{
|
||||
Objects = Obj;
|
||||
|
||||
setButtonColors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the button colors to match the current material settings.
|
||||
*/
|
||||
void DlgMaterialPropertiesImp::setButtonColors()
|
||||
{
|
||||
for (std::vector<ViewProvider*>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
|
||||
App::Property* prop = (*it)->getPropertyByName(material.c_str());
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterial>()) {
|
||||
auto ShapeMaterial = static_cast<App::PropertyMaterial*>(prop);
|
||||
App::Material mat = ShapeMaterial->getValue();
|
||||
int r = int(mat.ambientColor.r * 255.0f);
|
||||
int g = int(mat.ambientColor.g * 255.0f);
|
||||
int b = int(mat.ambientColor.b * 255.0f);
|
||||
if (prop && prop->isDerivedFrom<App::PropertyMaterialList>()) {
|
||||
auto ShapeAppearance = static_cast<App::PropertyMaterialList*>(prop);
|
||||
auto& materials = ShapeAppearance->getValues();
|
||||
auto& mat = materials[0];
|
||||
int r = int(mat.ambientColor.r * 255.0F);
|
||||
int g = int(mat.ambientColor.g * 255.0F);
|
||||
int b = int(mat.ambientColor.b * 255.0F);
|
||||
ui->ambientColor->setColor(QColor(r, g, b));
|
||||
r = int(mat.diffuseColor.r * 255.0f);
|
||||
g = int(mat.diffuseColor.g * 255.0f);
|
||||
b = int(mat.diffuseColor.b * 255.0f);
|
||||
r = int(mat.diffuseColor.r * 255.0F);
|
||||
g = int(mat.diffuseColor.g * 255.0F);
|
||||
b = int(mat.diffuseColor.b * 255.0F);
|
||||
ui->diffuseColor->setColor(QColor(r, g, b));
|
||||
r = int(mat.emissiveColor.r * 255.0f);
|
||||
g = int(mat.emissiveColor.g * 255.0f);
|
||||
b = int(mat.emissiveColor.b * 255.0f);
|
||||
r = int(mat.emissiveColor.r * 255.0F);
|
||||
g = int(mat.emissiveColor.g * 255.0F);
|
||||
b = int(mat.emissiveColor.b * 255.0F);
|
||||
ui->emissiveColor->setColor(QColor(r, g, b));
|
||||
r = int(mat.specularColor.r * 255.0f);
|
||||
g = int(mat.specularColor.g * 255.0f);
|
||||
b = int(mat.specularColor.b * 255.0f);
|
||||
r = int(mat.specularColor.r * 255.0F);
|
||||
g = int(mat.specularColor.g * 255.0F);
|
||||
b = int(mat.specularColor.b * 255.0F);
|
||||
ui->specularColor->setColor(QColor(r, g, b));
|
||||
ui->shininess->blockSignals(true);
|
||||
ui->shininess->setValue((int)(100.0f * (mat.shininess + 0.001f)));
|
||||
ui->shininess->setValue((int)(100.0f * (mat.shininess + 0.001F)));
|
||||
ui->shininess->blockSignals(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Gui::Dialog::DlgFaceMaterialPropertiesImp as a child of 'parent', with the
|
||||
* name 'name' and widget flags set to 'f'.
|
||||
*
|
||||
* The dialog will by default be modeless, unless you set 'modal' to
|
||||
* true to construct a modal dialog.
|
||||
*
|
||||
* This differs from Gui::Dialog::DlgMaterialPropertiesImp in that it does not update
|
||||
* the underlying object. This is undesirable when we're updating only a single face.
|
||||
*/
|
||||
DlgFaceMaterialPropertiesImp::DlgFaceMaterialPropertiesImp(const std::string& mat,
|
||||
QWidget* parent,
|
||||
Qt::WindowFlags fl)
|
||||
: DlgMaterialPropertiesImp(mat, parent, fl)
|
||||
{
|
||||
Base::Console().Log("DlgFaceMaterialPropertiesImp::DlgFaceMaterialPropertiesImp()\n");
|
||||
|
||||
// Override the base class on this. Otherwise the whole object changes
|
||||
updateColors = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the object and frees any allocated resources
|
||||
*/
|
||||
DlgFaceMaterialPropertiesImp::~DlgFaceMaterialPropertiesImp() = default;
|
||||
|
||||
App::Material DlgFaceMaterialPropertiesImp::getCustomAppearance() const
|
||||
{
|
||||
App::Material material;
|
||||
material.setType(App::Material::USER_DEFINED);
|
||||
|
||||
material.ambientColor = getColor(ui->ambientColor->color());
|
||||
material.diffuseColor = getColor(ui->diffuseColor->color());
|
||||
material.emissiveColor = getColor(ui->emissiveColor->color());
|
||||
material.specularColor = getColor(ui->specularColor->color());
|
||||
material.shininess = (float)ui->shininess->value() / 100.0F;
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
#include "moc_DlgMaterialPropertiesImp.cpp"
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace App
|
||||
{
|
||||
class Color;
|
||||
class Material;
|
||||
}
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
class ViewProvider;
|
||||
@@ -48,18 +54,36 @@ public:
|
||||
void setViewProviders(const std::vector<Gui::ViewProvider*>&);
|
||||
QColor diffuseColor() const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
void setupConnections();
|
||||
App::Material getMaterial();
|
||||
App::Color getColor(const QColor& color) const;
|
||||
void onAmbientColorChanged();
|
||||
void onDiffuseColorChanged();
|
||||
void onEmissiveColorChanged();
|
||||
void onSpecularColorChanged();
|
||||
void onShininessValueChanged(int);
|
||||
void onButtonReset(bool checked);
|
||||
void onButtonDefault(bool checked);
|
||||
void setButtonColors();
|
||||
|
||||
private:
|
||||
protected:
|
||||
std::unique_ptr<Ui_DlgMaterialProperties> ui;
|
||||
std::string material;
|
||||
std::vector<Gui::ViewProvider*> Objects;
|
||||
bool updateColors;
|
||||
};
|
||||
|
||||
class GuiExport DlgFaceMaterialPropertiesImp: public DlgMaterialPropertiesImp
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DlgFaceMaterialPropertiesImp(const std::string& mat,
|
||||
QWidget* parent = nullptr,
|
||||
Qt::WindowFlags fl = Qt::WindowFlags());
|
||||
~DlgFaceMaterialPropertiesImp() override;
|
||||
App::Material getCustomAppearance() const;
|
||||
};
|
||||
|
||||
} // namespace Dialog
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#include <random>
|
||||
#include <Inventor/SoPickedPoint.h>
|
||||
#include <Inventor/actions/SoRayPickAction.h>
|
||||
#include <Inventor/actions/SoSearchAction.h>
|
||||
@@ -35,12 +34,14 @@
|
||||
#include <Inventor/nodes/SoMaterial.h>
|
||||
#include <Inventor/nodes/SoSeparator.h>
|
||||
#include <Inventor/nodes/SoSwitch.h>
|
||||
#include <Inventor/nodes/SoTexture2.h>
|
||||
#endif
|
||||
|
||||
#include <Inventor/nodes/SoResetTransform.h>
|
||||
|
||||
#include <App/GeoFeature.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
@@ -56,12 +57,12 @@ using namespace Gui;
|
||||
namespace {
|
||||
float fromPercent(long value)
|
||||
{
|
||||
return static_cast<float>(value) / 100.0F;
|
||||
return std::roundf(value) / 100.0F;
|
||||
}
|
||||
|
||||
long toPercent(float value)
|
||||
{
|
||||
return static_cast<long>(100.0 * value + 0.5);
|
||||
return std::lround(100.0 * value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +72,7 @@ const App::PropertyIntegerConstraint::Constraints intPercent = {0, 100, 5};
|
||||
|
||||
ViewProviderGeometryObject::ViewProviderGeometryObject()
|
||||
{
|
||||
App::Material mat = getUserDefinedMaterial();
|
||||
App::Material mat = App::Material::getDefaultAppearance();
|
||||
long initialTransparency = toPercent(mat.transparency);
|
||||
|
||||
static const char* dogroup = "Display Options";
|
||||
@@ -95,10 +96,29 @@ ViewProviderGeometryObject::ViewProviderGeometryObject()
|
||||
|
||||
Selectable.setValue(isSelectionEnabled());
|
||||
|
||||
pcSwitchAppearance = new SoSwitch;
|
||||
pcSwitchAppearance->ref();
|
||||
pcSwitchTexture = new SoSwitch;
|
||||
pcSwitchTexture->ref();
|
||||
|
||||
pcShapeMaterial = new SoMaterial;
|
||||
setSoMaterial(mat);
|
||||
setCoinAppearance(mat);
|
||||
pcShapeMaterial->ref();
|
||||
|
||||
pcShapeTexture2D = new SoTexture2;
|
||||
pcShapeTexture2D->ref();
|
||||
|
||||
pcTextureGroup3D = new SoGroup;
|
||||
pcTextureGroup3D->ref();
|
||||
|
||||
// Materials go first, with textured faces drawing over them
|
||||
pcSwitchAppearance->addChild(pcShapeMaterial);
|
||||
pcSwitchAppearance->addChild(pcSwitchTexture);
|
||||
pcSwitchTexture->addChild(pcShapeTexture2D);
|
||||
pcSwitchTexture->addChild(pcTextureGroup3D);
|
||||
pcSwitchAppearance->whichChild.setValue(0);
|
||||
pcSwitchTexture->whichChild.setValue(SO_SWITCH_NONE);
|
||||
|
||||
pcBoundingBox = new Gui::SoFCBoundingBox;
|
||||
pcBoundingBox->ref();
|
||||
|
||||
@@ -110,54 +130,15 @@ ViewProviderGeometryObject::ViewProviderGeometryObject()
|
||||
|
||||
ViewProviderGeometryObject::~ViewProviderGeometryObject()
|
||||
{
|
||||
pcSwitchAppearance->unref();
|
||||
pcSwitchTexture->unref();
|
||||
pcShapeMaterial->unref();
|
||||
pcShapeTexture2D->unref();
|
||||
pcTextureGroup3D->unref();
|
||||
pcBoundingBox->unref();
|
||||
pcBoundColor->unref();
|
||||
}
|
||||
|
||||
App::Material ViewProviderGeometryObject::getUserDefinedMaterial()
|
||||
{
|
||||
ParameterGrp::handle hGrp =
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
|
||||
|
||||
auto getColor = [hGrp](const char* parameter, App::Color& color) {
|
||||
uint32_t packed = color.getPackedRGB();
|
||||
packed = hGrp->GetUnsigned(parameter, packed);
|
||||
color.setPackedRGB(packed);
|
||||
};
|
||||
auto intRandom = [] (int min, int max) -> int {
|
||||
static std::mt19937 generator;
|
||||
std::uniform_int_distribution<int> distribution(min, max);
|
||||
return distribution(generator);
|
||||
};
|
||||
|
||||
App::Material mat(App::Material::DEFAULT);
|
||||
mat.transparency = fromPercent(hGrp->GetInt("DefaultShapeTransparency", 0));
|
||||
long shininess = toPercent(mat.shininess);
|
||||
mat.shininess = fromPercent(hGrp->GetInt("DefaultShapeShininess", shininess));
|
||||
|
||||
// This is handled in the material code when using the object appearance
|
||||
bool randomColor = hGrp->GetBool("RandomColor", false);
|
||||
|
||||
// diffuse color
|
||||
if (randomColor) {
|
||||
float red = static_cast<float>(intRandom(0, 255)) / 255.0F;
|
||||
float green = static_cast<float>(intRandom(0, 255)) / 255.0F;
|
||||
float blue = static_cast<float>(intRandom(0, 255)) / 255.0F;
|
||||
mat.diffuseColor = App::Color(red, green, blue);
|
||||
}
|
||||
else {
|
||||
// Color = (204, 204, 230) = 3435980543UL
|
||||
getColor("DefaultShapeColor", mat.diffuseColor);
|
||||
}
|
||||
|
||||
getColor("DefaultAmbientColor", mat.ambientColor);
|
||||
getColor("DefaultEmissiveColor", mat.emissiveColor);
|
||||
getColor("DefaultSpecularColor", mat.specularColor);
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
bool ViewProviderGeometryObject::isSelectionEnabled() const
|
||||
{
|
||||
ParameterGrp::handle hGrp =
|
||||
@@ -187,12 +168,14 @@ void ViewProviderGeometryObject::onChanged(const App::Property* prop)
|
||||
if (getObject() && getObject()->testStatus(App::ObjectStatus::TouchOnColorChange)) {
|
||||
getObject()->touch(true);
|
||||
}
|
||||
const App::Material& Mat = ShapeAppearance[0];
|
||||
long value = toPercent(ShapeAppearance.getTransparency());
|
||||
if (value != Transparency.getValue()) {
|
||||
Transparency.setValue(value);
|
||||
}
|
||||
setSoMaterial(Mat);
|
||||
if (ShapeAppearance.getSize() == 1) {
|
||||
const App::Material& Mat = ShapeAppearance[0];
|
||||
setCoinAppearance(Mat);
|
||||
}
|
||||
}
|
||||
else if (prop == &BoundingBox) {
|
||||
showBoundingBox(BoundingBox.getValue());
|
||||
@@ -288,14 +271,33 @@ unsigned long ViewProviderGeometryObject::getBoundColor() const
|
||||
return bbcol;
|
||||
}
|
||||
|
||||
void ViewProviderGeometryObject::setSoMaterial(const App::Material& source)
|
||||
void ViewProviderGeometryObject::setCoinAppearance(const App::Material& source)
|
||||
{
|
||||
#if 0
|
||||
if (!source.image.empty()) {
|
||||
Base::Console().Log("setCoinAppearance(Texture)\n");
|
||||
activateTexture2D();
|
||||
|
||||
QByteArray by = QByteArray::fromBase64(QString::fromStdString(source.image).toUtf8());
|
||||
auto image = QImage::fromData(by, "PNG"); //.scaled(64, 64, Qt::KeepAspectRatio);
|
||||
|
||||
SoSFImage texture;
|
||||
Gui::BitmapFactory().convert(image, texture);
|
||||
pcShapeTexture2D->image = texture;
|
||||
} else {
|
||||
Base::Console().Log("setCoinAppearance(Material)\n");
|
||||
activateMaterial();
|
||||
}
|
||||
#endif
|
||||
activateMaterial();
|
||||
|
||||
// Always set the material for items such as lines that don't support textures
|
||||
pcShapeMaterial->ambientColor.setValue(source.ambientColor.r,
|
||||
source.ambientColor.g,
|
||||
source.ambientColor.b);
|
||||
source.ambientColor.g,
|
||||
source.ambientColor.b);
|
||||
pcShapeMaterial->diffuseColor.setValue(source.diffuseColor.r,
|
||||
source.diffuseColor.g,
|
||||
source.diffuseColor.b);
|
||||
source.diffuseColor.g,
|
||||
source.diffuseColor.b);
|
||||
pcShapeMaterial->specularColor.setValue(source.specularColor.r,
|
||||
source.specularColor.g,
|
||||
source.specularColor.b);
|
||||
@@ -306,6 +308,31 @@ void ViewProviderGeometryObject::setSoMaterial(const App::Material& source)
|
||||
pcShapeMaterial->transparency.setValue(source.transparency);
|
||||
}
|
||||
|
||||
void ViewProviderGeometryObject::activateMaterial()
|
||||
{
|
||||
pcSwitchAppearance->whichChild.setValue(0);
|
||||
pcSwitchTexture->whichChild.setValue(SO_SWITCH_NONE);
|
||||
}
|
||||
|
||||
void ViewProviderGeometryObject::activateTexture2D()
|
||||
{
|
||||
pcSwitchAppearance->whichChild.setValue(1);
|
||||
pcSwitchTexture->whichChild.setValue(0);
|
||||
}
|
||||
|
||||
void ViewProviderGeometryObject::activateTexture3D()
|
||||
{
|
||||
pcSwitchAppearance->whichChild.setValue(1);
|
||||
pcSwitchTexture->whichChild.setValue(1);
|
||||
}
|
||||
|
||||
void ViewProviderGeometryObject::activateMixed3D()
|
||||
{
|
||||
pcSwitchAppearance->whichChild.setValue(SO_SWITCH_ALL);
|
||||
pcSwitchTexture->whichChild.setValue(1);
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
float getBoundBoxFontSize()
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
class SoPickedPointList;
|
||||
class SoSwitch;
|
||||
class SoSensor;
|
||||
class SoTexture2;
|
||||
class SbVec2s;
|
||||
class SoBaseColor;
|
||||
|
||||
@@ -58,7 +59,6 @@ public:
|
||||
|
||||
// Display properties
|
||||
App::PropertyPercent Transparency;
|
||||
// App::PropertyMaterial ShapeMaterial; // Default appearance and physical properties
|
||||
App::PropertyMaterialList ShapeAppearance; // May be different from material
|
||||
App::PropertyBool BoundingBox;
|
||||
App::PropertyBool Selectable;
|
||||
@@ -108,13 +108,30 @@ protected:
|
||||
void handleChangedPropertyName(Base::XMLReader& reader,
|
||||
const char* TypeName,
|
||||
const char* PropName) override;
|
||||
void setCoinAppearance(const App::Material& source);
|
||||
|
||||
/**
|
||||
* Select which appearance type is active
|
||||
*
|
||||
*/
|
||||
/** Material only */
|
||||
void activateMaterial();
|
||||
/** 2D Texture */
|
||||
void activateTexture2D();
|
||||
/** 3D texture only */
|
||||
void activateTexture3D();
|
||||
/** Mix of material and 3D textures */
|
||||
void activateMixed3D();
|
||||
|
||||
private:
|
||||
void setSoMaterial(const App::Material& source);
|
||||
bool isSelectionEnabled() const;
|
||||
|
||||
protected:
|
||||
SoSwitch* pcSwitchAppearance {nullptr};
|
||||
SoSwitch* pcSwitchTexture {nullptr};
|
||||
SoMaterial* pcShapeMaterial {nullptr};
|
||||
SoTexture2* pcShapeTexture2D {nullptr};
|
||||
SoGroup* pcTextureGroup3D {nullptr};
|
||||
SoFCBoundingBox* pcBoundingBox {nullptr};
|
||||
SoSwitch* pcBoundSwitch {nullptr};
|
||||
SoBaseColor* pcBoundColor {nullptr};
|
||||
|
||||
@@ -71,7 +71,7 @@ PyObject* ViewProviderGeometryObjectPy::getCustomAttributes(const char* attr) co
|
||||
|
||||
PyObject* ViewProviderGeometryObjectPy::getUserDefinedMaterial()
|
||||
{
|
||||
App::Material mat = ViewProviderGeometryObject::getUserDefinedMaterial();
|
||||
App::Material mat = App::Material::getDefaultAppearance();
|
||||
return new App::MaterialPy(new App::Material(mat));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user