Merge pull request #19397 from kadet1090/three-point-lighting

Add three-point lighting
This commit is contained in:
Chris Hennes
2025-02-24 16:22:34 +00:00
committed by GitHub
23 changed files with 919 additions and 1088 deletions

View File

@@ -69,6 +69,8 @@
#include "ViewProviderAnalysis.h"
#include "ViewProviderFemPostObject.h"
#include <Base/Tools.h>
using namespace FemGui;
namespace sp = std::placeholders;
@@ -659,7 +661,7 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange)
if (Field.getEnumVector().empty() || Field.getValue() == 0) {
m_material->diffuseColor.setValue(SbColor(0.8, 0.8, 0.8));
float trans = float(Transparency.getValue()) / 100.0;
float trans = Base::fromPercent(Transparency.getValue());
m_material->transparency.setValue(trans);
m_materialBinding->value = SoMaterialBinding::OVERALL;
m_materialBinding->touch();
@@ -696,7 +698,7 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange)
SbColor* diffcol = m_material->diffuseColor.startEditing();
SbColor* edgeDiffcol = m_matPlainEdges->diffuseColor.startEditing();
float overallTransp = Transparency.getValue() / 100.0f;
float overallTransp = Base::fromPercent(Transparency.getValue());
m_material->transparency.setNum(numPts);
m_matPlainEdges->transparency.setNum(numPts);
float* transp = m_material->transparency.startEditing();
@@ -737,7 +739,7 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange)
void ViewProviderFemPostObject::WriteTransparency()
{
float trans = static_cast<float>(Transparency.getValue()) / 100.0;
float trans = Base::fromPercent(Transparency.getValue());
float* value = m_material->transparency.startEditing();
float* edgeValue = m_matPlainEdges->transparency.startEditing();
// m_material and m_matPlainEdges field containers have same size

View File

@@ -38,6 +38,8 @@
#include "ModelManager.h"
#include "ModelUuids.h"
#include <Base/Tools.h>
using namespace Materials;
@@ -174,8 +176,8 @@ std::shared_ptr<App::Material> MaterialManager::defaultAppearance()
long initialTransparency = hGrp->GetInt("DefaultShapeTransparency", 0);
long initialShininess = hGrp->GetInt("DefaultShapeShininess", 90);
mat.shininess = ((float)initialShininess / 100.0F);
mat.transparency = ((float)initialTransparency / 100.0F);
mat.shininess = Base::fromPercent(initialShininess);
mat.transparency = Base::fromPercent(initialTransparency);
return std::make_shared<App::Material>(mat);
}

View File

@@ -329,7 +329,7 @@ void ViewProviderMesh::onChanged(const App::Property* prop)
pcMatBinding->value = SoMaterialBinding::OVERALL;
}
if (prop == &LineTransparency) {
float trans = LineTransparency.getValue() / 100.0F;
float trans = Base::fromPercent(LineTransparency.getValue());
pLineColor->transparency = trans;
}
else if (prop == &LineWidth) {
@@ -590,7 +590,7 @@ void ViewProviderMesh::tryColorPerVertexOrFace(bool on)
pcMatBinding->value = SoMaterialBinding::OVERALL;
const App::Color& c = ShapeAppearance.getDiffuseColor();
pcShapeMaterial->diffuseColor.setValue(c.r, c.g, c.b);
pcShapeMaterial->transparency.setValue(Transparency.getValue() / 100.0F);
pcShapeMaterial->transparency.setValue(Base::fromPercent(Transparency.getValue()));
}
}

View File

@@ -33,6 +33,8 @@
#include "ViewProvider.h"
#include <Base/Tools.h>
using namespace PartGui;
@@ -88,7 +90,7 @@ void ViewProviderPart::applyTransparency(float transparency, std::vector<App::Co
for (auto& j : colors) {
// transparency hasn't been set for this face
if (j.a == 0.0) {
j.setTransparency(transparency/100.0F); // transparency comes in percent
j.setTransparency(Base::fromPercent(transparency)); // transparency comes in percent
}
}
}
@@ -101,7 +103,7 @@ void ViewProviderPart::applyTransparency(float transparency, std::vector<App::Ma
for (auto& j : colors) {
// transparency hasn't been set for this face
if (j.transparency == 0.0) {
j.transparency = transparency / 100.0F; // transparency comes in percent
j.transparency = Base::fromPercent(transparency); // transparency comes in percent
}
}
}

View File

@@ -97,19 +97,6 @@ FC_LOG_LEVEL_INIT("Part", true, true)
using namespace PartGui;
// Helper functions to consistently convert between float and long
namespace {
float fromPercent(long value)
{
return std::roundf(value) / 100.0F;
}
long toPercent(float value)
{
return std::lround(100.0 * value);
}
}
PROPERTY_SOURCE(PartGui::ViewProviderPartExt, Gui::ViewProviderGeometryObject)
@@ -364,9 +351,9 @@ void ViewProviderPartExt::onChanged(const App::Property* prop)
}
else if (prop == &Transparency) {
const App::Material& Mat = ShapeAppearance[0];
long value = toPercent(Mat.transparency);
long value = Base::toPercent(Mat.transparency);
if (value != Transparency.getValue()) {
float trans = fromPercent(Transparency.getValue());
float trans = Base::fromPercent(Transparency.getValue());
ShapeAppearance.setTransparency(trans);
}
}
@@ -676,7 +663,7 @@ std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const cha
if(!element || !element[0]) {
auto color = ShapeAppearance.getDiffuseColor();
color.setTransparency(Transparency.getValue()/100.0F);
color.setTransparency(Base::fromPercent(Transparency.getValue()));
ret["Face"] = color;
ret["Edge"] = LineColor.getValue();
ret["Vertex"] = PointColor.getValue();
@@ -687,7 +674,7 @@ std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const cha
auto size = ShapeAppearance.getSize();
if(element[4]=='*') {
auto color = ShapeAppearance.getDiffuseColor();
color.setTransparency(Transparency.getValue()/100.0F);
color.setTransparency(Base::fromPercent(Transparency.getValue()));
bool singleColor = true;
for(int i=0;i<size;++i) {
if (ShapeAppearance.getDiffuseColor(i) != color) {
@@ -699,7 +686,7 @@ std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const cha
}
if(size && singleColor) {
color = ShapeAppearance.getDiffuseColor(0);
color.setTransparency(Transparency.getValue()/100.0F);
color.setTransparency(Base::fromPercent(100.0F));
ret.clear();
}
ret["Face"] = color;
@@ -710,7 +697,7 @@ std::map<std::string,App::Color> ViewProviderPartExt::getElementColors(const cha
else
ret[element] = ShapeAppearance.getDiffuseColor();
if(size==1)
ret[element].setTransparency(Transparency.getValue()/100.0F);
ret[element].setTransparency(Base::fromPercent(Transparency.getValue()));
}
} else if (boost::starts_with(element,"Edge")) {
auto size = LineColorArray.getSize();

View File

@@ -3303,7 +3303,7 @@ void ViewProviderSketch::unsetEdit(int ModNum)
// Resets the override draw style mode when leaving the sketch edit mode.
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Sketcher/General");
auto disableShadedView = hGrp->GetBool("DisableShadedView", true);
auto disableShadedView = hGrp->GetBool("DisableShadedView", false);
if (disableShadedView) {
Gui::View3DInventorViewer* viewer =
static_cast<Gui::View3DInventor*>(mdi)->getViewer();
@@ -3400,7 +3400,7 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo
// Sets the view mode to no shading to prevent visibility issues against parallel surfaces with shininess when entering the sketch mode.
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Sketcher/General");
auto disableShadedView = hGrp->GetBool("DisableShadedView", true);
auto disableShadedView = hGrp->GetBool("DisableShadedView", false);
hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Sketcher/General");