New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Material: Appearance Updates 2 #13792
base: main
Are you sure you want to change the base?
Material: Appearance Updates 2 #13792
Conversation
with this PR, can we get rid of the default diffuse color, ambient color,... introduced in the settings a few days ago? |
No. They're still used. The set the default appearance |
why not use the default material there instead of hacking it? |
This would make sense for objects in part and part design, but less so for line colors, draft workbench, etc. The appearance can be used where there is no associated shape property |
I know it was introduced with another PR. But the settings there do not overwrite / save my default material, right? Does a new object then have a material with the settings in the preferences and where is that stored? |
Not yet. Work in progress |
Hold off on merging this... I'm reviewing a potential issue. |
please mark again as ready for review once ready |
FYI @davesrocketshop when you don't want a PR to be merged, a good thing to do is to turn it back into draft |
755edcc
to
dcc315a
Compare
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
dcc315a
to
542cd63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly just questions and little stuff.
|
||
long toPercent(float value) | ||
{ | ||
return static_cast<long>(100.0 * value + 0.5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter is (almost) right here, this code should use std::roundl()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is plagiarized code. I'll update.
aboutToSetValue(); | ||
setSize(colors.size(), _lValueList[0]); | ||
|
||
for (int i = 0; i < colors.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use range-for here?
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of boilerplate repeated a half dozen times with only a single line change -- in the future it would be a good idea to refactor to eliminate that code duplication (and to modernize the for loop).
// if (current.empty()) | ||
// current.push_back(vp->ShapeAppearance.getDiffuseColor()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just delete?
connect(d->ui->buttonCustomAppearance, | ||
&QPushButton::clicked, | ||
this, | ||
&FaceAppearances::onbuttonCustomAppearanceClicked); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd capitalize the "B" in onbuttonCustomAppearanceClicked
here, it jumps out as an error to a reader otherwise.
std::vector<App::Color> colBool; | ||
colBool.resize(boolMap.Extent(), this->ShapeAppearance.getDiffuseColor()); | ||
std::vector<App::Material> colBool; | ||
colBool.resize(boolMap.Extent(), this->ShapeAppearance[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check size first here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The PropertyMaterialList code ensures there's always at least one entry
@@ -175,7 +177,7 @@ ViewProviderPartExt::ViewProviderPartExt() | |||
ADD_PROPERTY_TYPE(LineColor, (lmat.diffuseColor), osgroup, App::Prop_None, "Set object line color."); | |||
ADD_PROPERTY_TYPE(PointColor, (vmat.diffuseColor), osgroup, App::Prop_None, "Set object point color"); | |||
ADD_PROPERTY_TYPE(PointColorArray, (PointColor.getValue()), osgroup, App::Prop_None, "Object point color array."); | |||
ADD_PROPERTY_TYPE(DiffuseColor,(ShapeAppearance.getDiffuseColors()), osgroup, App::Prop_None, "Object diffuse color."); | |||
// ADD_PROPERTY_TYPE(DiffuseColor,(ShapeAppearance.getDiffuseColors()), osgroup, App::Prop_None, "Object diffuse color."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to leave this here I'd also leave a comment about why
else if (!colBase.empty() && colBase[0] != this->ShapeAppearance.getDiffuseColor()) { | ||
colBase.resize(baseMap.Extent(), colBase[0]); | ||
applyColor(hist[0], colBase, colCham); | ||
else if (colBase.getSize() > 0 && colBase[0] != this->ShapeAppearance[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change to getSize() > 0
? I typically advise the opposite change (though I wasn't going to bother suggesting it in this PR).
Co-authored-by: Chris Hennes <[email protected]>
Improves the use of the ShapeAppearance property for the Part workbench.