Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davesrocketshop
Copy link
Contributor

@davesrocketshop davesrocketshop commented May 2, 2024

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

@github-actions github-actions bot added Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD WB FEM Related to the FEM Workbench WB Part Design Related to the Part Design Workbench WB Part Related to the Part Workbench Materials Materials related WB MeshPart labels May 2, 2024
@maxwxyz
Copy link
Collaborator

maxwxyz commented May 3, 2024

with this PR, can we get rid of the default diffuse color, ambient color,... introduced in the settings a few days ago?

@davesrocketshop
Copy link
Contributor Author

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

@maxwxyz
Copy link
Collaborator

maxwxyz commented May 3, 2024

why not use the default material there instead of hacking it?

@davesrocketshop
Copy link
Contributor Author

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

@maxwxyz
Copy link
Collaborator

maxwxyz commented May 3, 2024

yes, I'm talking about the material appearance in the Part / Part Design preferences:
image

Line/Vertex color could stay. But the rest could be just using the default material or a material chooser or maybe launch the material editor to adjust it. Do these settings currently overwrite the default material or is this just a proxy and no material is applied?

@davesrocketshop
Copy link
Contributor Author

yes, I'm talking about the material appearance in the Part / Part Design preferences: image

Line/Vertex color could stay. But the rest could be just using the default material or a material chooser or maybe launch the material editor to adjust it. Do these settings currently overwrite the default material or is this just a proxy and no material is applied?

BTW, I'm defending someone else's code here, but yes. It does override the default material allowing you to customize what that default looks like. This is similar to specifying a custom appearance in the "Set appearance..." dialog only without the pop up.

Could it be done with the MaterialTreeWidget? Yes, but there would still need a separate dialog to specify a custom value. It works fine as shown.

@maxwxyz
Copy link
Collaborator

maxwxyz commented May 3, 2024

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?

@davesrocketshop
Copy link
Contributor Author

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

@davesrocketshop
Copy link
Contributor Author

Hold off on merging this... I'm reviewing a potential issue.

@adrianinsaval adrianinsaval marked this pull request as draft May 6, 2024 16:33
@adrianinsaval
Copy link
Member

please mark again as ready for review once ready

@yorikvanhavre
Copy link
Member

FYI @davesrocketshop when you don't want a PR to be merged, a good thing to do is to turn it back into draft

@davesrocketshop davesrocketshop force-pushed the material_appearance_pr branch 2 times, most recently from 755edcc to dcc315a Compare May 12, 2024 06:39
@davesrocketshop davesrocketshop marked this pull request as ready for review May 12, 2024 11:14
@chennes chennes self-requested a review May 13, 2024 16:08
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
Copy link
Member

@chennes chennes left a 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);
Copy link
Member

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().

Copy link
Contributor Author

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++) {
Copy link
Member

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?

Comment on lines +135 to +145
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);
}
Copy link
Member

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).

src/Gui/DlgMaterialPropertiesImp.cpp Outdated Show resolved Hide resolved
src/Gui/ViewProviderGeometryObject.cpp Show resolved Hide resolved
Comment on lines +120 to +121
// if (current.empty())
// current.push_back(vp->ShapeAppearance.getDiffuseColor());
Copy link
Member

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);
Copy link
Member

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]);
Copy link
Member

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?

Copy link
Contributor Author

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.");
Copy link
Member

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]) {
Copy link
Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Materials Materials related WB FEM Related to the FEM Workbench WB MeshPart WB Part Design Related to the Part Design Workbench WB Part Related to the Part Workbench
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants