24
#include "PreCompiled.h"
31
#include "Application.h"
37
float fromPercent(long value)
39
return std::roundf(value) / 100.0F;
42
long toPercent(float value)
44
return std::lround(100.0 * value);
63
Material::Material(const char* MatName)
71
Material::Material(MaterialType MatType)
79
void Material::set(const char* MatName)
81
if (strcmp("Brass", MatName) == 0) {
84
else if (strcmp("Bronze", MatName) == 0) {
87
else if (strcmp("Copper", MatName) == 0) {
90
else if (strcmp("Gold", MatName) == 0) {
93
else if (strcmp("Pewter", MatName) == 0) {
96
else if (strcmp("Plaster", MatName) == 0) {
99
else if (strcmp("Plastic", MatName) == 0) {
102
else if (strcmp("Silver", MatName) == 0) {
105
else if (strcmp("Steel", MatName) == 0) {
108
else if (strcmp("Stone", MatName) == 0) {
111
else if (strcmp("Shiny plastic", MatName) == 0) {
112
setType(SHINY_PLASTIC);
114
else if (strcmp("Satin", MatName) == 0) {
117
else if (strcmp("Metalized", MatName) == 0) {
120
else if (strcmp("Neon GNC", MatName) == 0) {
123
else if (strcmp("Chrome", MatName) == 0) {
126
else if (strcmp("Aluminium", MatName) == 0) {
129
else if (strcmp("Obsidian", MatName) == 0) {
132
else if (strcmp("Neon PHC", MatName) == 0) {
135
else if (strcmp("Jade", MatName) == 0) {
138
else if (strcmp("Ruby", MatName) == 0) {
141
else if (strcmp("Emerald", MatName) == 0) {
144
else if (strcmp("Default", MatName) == 0) {
148
setType(USER_DEFINED);
152
void Material::setType(MaterialType MatType)
157
ambientColor.set(0.3294F, 0.2235F, 0.0275F);
158
diffuseColor.set(0.7804F, 0.5686F, 0.1137F);
159
specularColor.set(0.9922F, 0.9412F, 0.8078F);
160
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
162
transparency = 0.0000F;
165
ambientColor.set(0.2125F, 0.1275F, 0.0540F);
166
diffuseColor.set(0.7140F, 0.4284F, 0.1814F);
167
specularColor.set(0.3935F, 0.2719F, 0.1667F);
168
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
170
transparency = 0.0000F;
173
ambientColor.set(0.3300F, 0.2600F, 0.2300F);
174
diffuseColor.set(0.5000F, 0.1100F, 0.0000F);
175
specularColor.set(0.9500F, 0.7300F, 0.0000F);
176
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
178
transparency = 0.0000F;
181
ambientColor.set(0.3000F, 0.2306F, 0.0953F);
182
diffuseColor.set(0.4000F, 0.2760F, 0.0000F);
183
specularColor.set(0.9000F, 0.8820F, 0.7020F);
184
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
186
transparency = 0.0000F;
189
ambientColor.set(0.1059F, 0.0588F, 0.1137F);
190
diffuseColor.set(0.4275F, 0.4706F, 0.5412F);
191
specularColor.set(0.3333F, 0.3333F, 0.5216F);
192
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
194
transparency = 0.0000F;
197
ambientColor.set(0.0500F, 0.0500F, 0.0500F);
198
diffuseColor.set(0.1167F, 0.1167F, 0.1167F);
199
specularColor.set(0.0305F, 0.0305F, 0.0305F);
200
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
202
transparency = 0.0000F;
205
ambientColor.set(0.1000F, 0.1000F, 0.1000F);
206
diffuseColor.set(0.0000F, 0.0000F, 0.0000F);
207
specularColor.set(0.0600F, 0.0600F, 0.0600F);
208
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
210
transparency = 0.0000F;
213
ambientColor.set(0.1922F, 0.1922F, 0.1922F);
214
diffuseColor.set(0.5075F, 0.5075F, 0.5075F);
215
specularColor.set(0.5083F, 0.5083F, 0.5083F);
216
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
218
transparency = 0.0000F;
221
ambientColor.set(0.0020F, 0.0020F, 0.0020F);
222
diffuseColor.set(0.0000F, 0.0000F, 0.0000F);
223
specularColor.set(0.9800F, 0.9800F, 0.9800F);
224
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
226
transparency = 0.0000F;
229
ambientColor.set(0.1900F, 0.1520F, 0.1178F);
230
diffuseColor.set(0.7500F, 0.6000F, 0.4650F);
231
specularColor.set(0.0784F, 0.0800F, 0.0480F);
232
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
234
transparency = 0.0000F;
237
ambientColor.set(0.0880F, 0.0880F, 0.0880F);
238
diffuseColor.set(0.0000F, 0.0000F, 0.0000F);
239
specularColor.set(1.0000F, 1.0000F, 1.0000F);
240
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
242
transparency = 0.0000F;
245
ambientColor.set(0.0660F, 0.0660F, 0.0660F);
246
diffuseColor.set(0.0000F, 0.0000F, 0.0000F);
247
specularColor.set(0.4400F, 0.4400F, 0.4400F);
248
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
250
transparency = 0.0000F;
253
ambientColor.set(0.1800F, 0.1800F, 0.1800F);
254
diffuseColor.set(0.0000F, 0.0000F, 0.0000F);
255
specularColor.set(0.4500F, 0.4500F, 0.4500F);
256
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
258
transparency = 0.0000F;
261
ambientColor.set(0.2000F, 0.2000F, 0.2000F);
262
diffuseColor.set(0.0000F, 0.0000F, 0.0000F);
263
specularColor.set(0.6200F, 0.6200F, 0.6200F);
264
emissiveColor.set(1.0000F, 1.0000F, 0.0000F);
266
transparency = 0.0000F;
269
ambientColor.set(0.3500F, 0.3500F, 0.3500F);
270
diffuseColor.set(0.9176F, 0.9176F, 0.9176F);
271
specularColor.set(0.9746F, 0.9746F, 0.9746F);
272
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
274
transparency = 0.0000F;
277
ambientColor.set(0.3000F, 0.3000F, 0.3000F);
278
diffuseColor.set(0.3000F, 0.3000F, 0.3000F);
279
specularColor.set(0.7000F, 0.7000F, 0.8000F);
280
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
282
transparency = 0.0000F;
285
ambientColor.set(0.0538F, 0.0500F, 0.0662F);
286
diffuseColor.set(0.1828F, 0.1700F, 0.2253F);
287
specularColor.set(0.3327F, 0.3286F, 0.3464F);
288
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
290
transparency = 0.0000F;
293
ambientColor.set(1.0000F, 1.0000F, 1.0000F);
294
diffuseColor.set(1.0000F, 1.0000F, 1.0000F);
295
specularColor.set(0.6200F, 0.6200F, 0.6200F);
296
emissiveColor.set(0.0000F, 0.9000F, 0.4140F);
298
transparency = 0.0000F;
301
ambientColor.set(0.1350F, 0.2225F, 0.1575F);
302
diffuseColor.set(0.5400F, 0.8900F, 0.6300F);
303
specularColor.set(0.3162F, 0.3162F, 0.3162F);
304
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
306
transparency = 0.0000F;
309
ambientColor.set(0.1745F, 0.0118F, 0.0118F);
310
diffuseColor.set(0.6142F, 0.0414F, 0.0414F);
311
specularColor.set(0.7278F, 0.6279F, 0.6267F);
312
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
314
transparency = 0.0000F;
317
ambientColor.set(0.0215F, 0.1745F, 0.0215F);
318
diffuseColor.set(0.0757F, 0.6142F, 0.0757F);
319
specularColor.set(0.6330F, 0.7278F, 0.6330F);
320
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
322
transparency = 0.0000F;
327
ambientColor.set(0.3333F, 0.3333F, 0.3333F);
328
diffuseColor.set(0.8000F, 0.8000F, 0.9000F);
329
specularColor.set(0.5333F, 0.5333F, 0.5333F);
330
emissiveColor.set(0.0000F, 0.0000F, 0.0000F);
332
transparency = 0.0000F;
337
App::Material Material::getDefaultAppearance()
339
ParameterGrp::handle hGrp =
340
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
342
auto getColor = [hGrp](const char* parameter, App::Color& color) {
343
uint32_t packed = color.getPackedRGB();
344
packed = hGrp->GetUnsigned(parameter, packed);
345
color.setPackedRGB(packed);
347
auto intRandom = [](int min, int max) -> int {
348
static std::mt19937 generator;
349
std::uniform_int_distribution<int> distribution(min, max);
350
return distribution(generator);
353
App::Material mat(App::Material::DEFAULT);
354
mat.transparency = fromPercent(hGrp->GetInt("DefaultShapeTransparency", 0));
355
long shininess = toPercent(mat.shininess);
356
mat.shininess = fromPercent(hGrp->GetInt("DefaultShapeShininess", shininess));
359
bool randomColor = hGrp->GetBool("RandomColor", false);
363
float red = static_cast<float>(intRandom(0, 255)) / 255.0F;
364
float green = static_cast<float>(intRandom(0, 255)) / 255.0F;
365
float blue = static_cast<float>(intRandom(0, 255)) / 255.0F;
366
mat.diffuseColor = App::Color(red, green, blue);
370
getColor("DefaultShapeColor", mat.diffuseColor);
373
getColor("DefaultAmbientColor", mat.ambientColor);
374
getColor("DefaultEmissiveColor", mat.emissiveColor);
375
getColor("DefaultSpecularColor", mat.specularColor);