Materials: Editor UI enhancements
When creating a new material, assigning the basic rendering model to the material resulted in an all black color. This will now be assigned the default color as specified in the preferences. The name of the material Properties tab has been changed to Physical for improved consistency in the user interface.
This commit is contained in:
committed by
Chris Hennes
parent
a9b0b1f534
commit
c5df1b3e55
@@ -138,10 +138,8 @@ bool MaterialManager::isMaterial(const QFileInfo& file) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
std::shared_ptr<App::Material> MaterialManager::defaultAppearance()
|
||||
{
|
||||
MaterialManager manager;
|
||||
|
||||
ParameterGrp::handle hGrp =
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
|
||||
|
||||
@@ -149,8 +147,9 @@ std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
uint32_t packed = color.getPackedRGB();
|
||||
packed = hGrp->GetUnsigned(parameter, packed);
|
||||
color.setPackedRGB(packed);
|
||||
color.a = 1.0; // The default color sets fully transparent, not opaque
|
||||
};
|
||||
auto intRandom = [] (int min, int max) -> int {
|
||||
auto intRandom = [](int min, int max) -> int {
|
||||
static std::mt19937 generator;
|
||||
std::uniform_int_distribution<int> distribution(min, max);
|
||||
return distribution(generator);
|
||||
@@ -163,7 +162,7 @@ std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
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);
|
||||
mat.diffuseColor = App::Color(red, green, blue, 1.0);
|
||||
}
|
||||
else {
|
||||
getColor("DefaultShapeColor", mat.diffuseColor);
|
||||
@@ -175,24 +174,34 @@ std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
|
||||
long initialTransparency = hGrp->GetInt("DefaultShapeTransparency", 0);
|
||||
long initialShininess = hGrp->GetInt("DefaultShapeShininess", 90);
|
||||
mat.shininess = ((float)initialShininess / 100.0F);
|
||||
mat.transparency = ((float)initialTransparency / 100.0F);
|
||||
|
||||
return std::make_shared<App::Material>(mat);
|
||||
}
|
||||
|
||||
std::shared_ptr<Material> MaterialManager::defaultMaterial()
|
||||
{
|
||||
MaterialManager manager;
|
||||
|
||||
auto mat = defaultAppearance();
|
||||
auto material = manager.getMaterial(defaultMaterialUUID());
|
||||
if (!material) {
|
||||
material = manager.getMaterial(QLatin1String("7f9fd73b-50c9-41d8-b7b2-575a030c1eeb"));
|
||||
}
|
||||
if (material->hasAppearanceModel(ModelUUIDs::ModelUUID_Rendering_Basic)) {
|
||||
material->getAppearanceProperty(QString::fromLatin1("DiffuseColor"))
|
||||
->setColor(mat.diffuseColor);
|
||||
->setColor(mat->diffuseColor);
|
||||
material->getAppearanceProperty(QString::fromLatin1("AmbientColor"))
|
||||
->setColor(mat.ambientColor);
|
||||
->setColor(mat->ambientColor);
|
||||
material->getAppearanceProperty(QString::fromLatin1("EmissiveColor"))
|
||||
->setColor(mat.emissiveColor);
|
||||
->setColor(mat->emissiveColor);
|
||||
material->getAppearanceProperty(QString::fromLatin1("SpecularColor"))
|
||||
->setColor(mat.specularColor);
|
||||
->setColor(mat->specularColor);
|
||||
material->getAppearanceProperty(QString::fromLatin1("Transparency"))
|
||||
->setFloat((float)initialTransparency / 100.0F);
|
||||
->setFloat(mat->transparency);
|
||||
material->getAppearanceProperty(QString::fromLatin1("Shininess"))
|
||||
->setFloat((float)initialShininess / 100.0F);
|
||||
->setFloat(mat->shininess);
|
||||
}
|
||||
|
||||
return material;
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
|
||||
static void cleanup();
|
||||
static void refresh();
|
||||
static std::shared_ptr<App::Material> defaultAppearance();
|
||||
static std::shared_ptr<Material> defaultMaterial();
|
||||
static QString defaultMaterialUUID();
|
||||
|
||||
|
||||
@@ -169,15 +169,12 @@ PyObject* MaterialTreeWidgetPy::setFilter(PyObject* args)
|
||||
}
|
||||
if (PyObject_TypeCheck(obj, &(Materials::MaterialFilterPy::Type))) {
|
||||
auto filter = static_cast<Materials::MaterialFilterPy*>(obj)->getMaterialFilterPtr();
|
||||
Base::Console().Log("Filter '%s'\n", filter->name().toStdString().c_str());
|
||||
auto filterPtr = std::make_shared<Materials::MaterialFilter>(*filter);
|
||||
getMaterialTreeWidgetPtr()->setFilter(filterPtr);
|
||||
}
|
||||
else if (PyList_Check(obj)) {
|
||||
// The argument is a list of filters
|
||||
Base::Console().Log("Filter List\n");
|
||||
Py_ssize_t n = PyList_Size(obj);
|
||||
Base::Console().Log("n = %d\n", n);
|
||||
if (n < 0) {
|
||||
Py_Return;
|
||||
}
|
||||
@@ -188,13 +185,8 @@ PyObject* MaterialTreeWidgetPy::setFilter(PyObject* args)
|
||||
if (PyObject_TypeCheck(item, &(Materials::MaterialFilterPy::Type))) {
|
||||
auto filter =
|
||||
static_cast<Materials::MaterialFilterPy*>(item)->getMaterialFilterPtr();
|
||||
Base::Console().Log("\tFilter '%s'\n",
|
||||
filter->name().toStdString().c_str()); auto filterPtr =
|
||||
std::make_shared<Materials::MaterialFilter>(*filter);
|
||||
auto filterPtr = std::make_shared<Materials::MaterialFilter>(*filter);
|
||||
filterList->push_back(filterPtr);
|
||||
// getMaterialTreeWidgetPtr()->setFilter(
|
||||
//
|
||||
// *static_cast<Materials::MaterialFilterPy*>(obj)->getMaterialFilterPtr());
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -222,8 +214,6 @@ PyObject* MaterialTreeWidgetPy::selectFilter(PyObject* args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Base::Console().Log("selectFilter(%s)\n", name);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include <Mod/Material/App/Exceptions.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
#include "MaterialDelegate.h"
|
||||
#include "MaterialSave.h"
|
||||
@@ -425,6 +426,13 @@ void MaterialsEditor::onAppearanceAdd(bool checked)
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
QString selected = dialog.selectedModel();
|
||||
_material->addAppearance(selected);
|
||||
auto model = getModelManager().getModel(selected);
|
||||
if (selected == Materials::ModelUUIDs::ModelUUID_Rendering_Basic
|
||||
|| model->inherits(Materials::ModelUUIDs::ModelUUID_Rendering_Basic)) {
|
||||
// Add default appearance properties
|
||||
*_material = *(getMaterialManager().defaultAppearance());
|
||||
}
|
||||
|
||||
updateMaterial();
|
||||
}
|
||||
else {
|
||||
@@ -1008,6 +1016,7 @@ void MaterialsEditor::updateMaterialAppearance()
|
||||
auto valueItem = new QStandardItem(_material->getAppearanceValueString(key));
|
||||
valueItem->setToolTip(itp->second.getDescription());
|
||||
QVariant variant;
|
||||
// variant.setValue(_material->getAppearanceValueString(key));
|
||||
variant.setValue(_material);
|
||||
valueItem->setData(variant);
|
||||
items.append(valueItem);
|
||||
|
||||
@@ -209,7 +209,7 @@
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabProperties">
|
||||
<attribute name="title">
|
||||
<string>Properties</string>
|
||||
<string>Physical</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_43">
|
||||
<item>
|
||||
|
||||
@@ -41,14 +41,18 @@ class ColorTransparencyTest(unittest.TestCase):
|
||||
|
||||
"""
|
||||
This test isn't currently valid as it draws from the hard coded default material.
|
||||
|
||||
The preference editor doesn't allow for setting transparencies. The default value
|
||||
of 0 corresponds to a fully transparent color, which is not desireable. It changes
|
||||
the transparency when loading to 1.0
|
||||
"""
|
||||
|
||||
self._pg.SetUnsigned('DefaultShapeColor', 0xff000000) # red
|
||||
obj = self._doc.addObject('Part::Box')
|
||||
|
||||
self.assertEqual(obj.ViewObject.ShapeAppearance[0].DiffuseColor, (1.0, 0.0, 0.0, 0.0),
|
||||
self.assertEqual(obj.ViewObject.ShapeAppearance[0].DiffuseColor, (1.0, 0.0, 0.0, 1.0),
|
||||
'default shape color was not set correctly')
|
||||
self.assertEqual(obj.ViewObject.ShapeMaterial.DiffuseColor, (1.0, 0.0, 0.0, 0.0),
|
||||
self.assertEqual(obj.ViewObject.ShapeMaterial.DiffuseColor, (1.0, 0.0, 0.0, 1.0),
|
||||
'default material color was not set correctly')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user