| 139 | //===== |
| 140 | |
| 141 | std::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 | |
| 183 | std::shared_ptr<Material> MaterialManager::defaultMaterial() |
| 184 | { |
no test coverage detected