MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / defaultAppearance

Method defaultAppearance

src/Mod/Material/App/MaterialManager.cpp:141–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139//=====
140
141std::shared_ptr<App::Material> MaterialManager::defaultAppearance()
142{
143 ParameterGrp::handle hGrp =
144 App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
145
146 auto getColor = [hGrp](const char* parameter, Base::Color& color) {
147 uint32_t packed = color.getPackedRGB();
148 packed = hGrp->GetUnsigned(parameter, packed);
149 color.setPackedRGB(packed);
150 color.a = 1.0; // The default color sets fully transparent, not opaque
151 };
152 auto intRandom = [](int min, int max) -> int {
153 static std::mt19937 generator;
154 std::uniform_int_distribution<int> distribution(min, max);
155 return distribution(generator);
156 };
157
158 App::Material mat(App::Material::DEFAULT);
159 bool randomColor = hGrp->GetBool("RandomColor", false);
160
161 if (randomColor) {
162 float red = static_cast<float>(intRandom(0, 255)) / 255.0F;
163 float green = static_cast<float>(intRandom(0, 255)) / 255.0F;
164 float blue = static_cast<float>(intRandom(0, 255)) / 255.0F;
165 mat.diffuseColor = Base::Color(red, green, blue, 1.0);
166 }
167 else {
168 getColor("DefaultShapeColor", mat.diffuseColor);
169 }
170
171 getColor("DefaultAmbientColor", mat.ambientColor);
172 getColor("DefaultEmissiveColor", mat.emissiveColor);
173 getColor("DefaultSpecularColor", mat.specularColor);
174
175 long initialTransparency = hGrp->GetInt("DefaultShapeTransparency", 0);
176 long initialShininess = hGrp->GetInt("DefaultShapeShininess", 90);
177 mat.shininess = Base::fromPercent(initialShininess);
178 mat.transparency = Base::fromPercent(initialTransparency);
179
180 return std::make_shared<App::Material>(mat);
181}
182
183std::shared_ptr<Material> MaterialManager::defaultMaterial()
184{

Callers 1

onAppearanceAddMethod · 0.80

Calls 9

fromPercentFunction · 0.85
getPackedRGBMethod · 0.80
GetUnsignedMethod · 0.80
setPackedRGBMethod · 0.80
GetBoolMethod · 0.80
GetIntMethod · 0.80
ColorClass · 0.50
getColorFunction · 0.50

Tested by

no test coverage detected