b311480e |
1 | // Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
973c2be1 |
6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #define BUC60565 //GG_19/10/99 ; Don't change the color components when the corresponding |
16 | // coefficient is modified because the resulting color is computed in |
17 | // low level driver. |
18 | |
19 | #define IMP150200 //GG : Add IsEqual() IsDifferent() methods. |
20 | // Add NumberOfMaterials() MaterialName() class methods |
21 | |
22 | #define IMP171201 //GG : Add Add MaterialName() SetMaterialName() instance |
23 | // methods in order to set or retrieve name of the current |
24 | // material. |
25 | // Capitalize all material name strings. |
26 | // Thanks to Stephane ROUTELOUS. |
27 | |
7fd59977 |
28 | |
29 | //-Version |
30 | |
81bba717 |
31 | //-Design Declaration of variables specific to the definition |
32 | // of materials |
7fd59977 |
33 | |
81bba717 |
34 | //-Warning A material is defined by : |
35 | // - coefficient of transparence |
36 | // - coefficient of disperse reflection |
37 | // - coefficient of ambiant reflection |
38 | // - coefficient of specular reflection |
39 | // - coefficient of emission |
7fd59977 |
40 | |
81bba717 |
41 | // 2 properties permiting to define a material : |
42 | // - transparence |
43 | // - reflection, i.e. absorbtion properties |
44 | // and light diffusion |
7fd59977 |
45 | |
81bba717 |
46 | // Disperse reflection is considered a component |
47 | // The specular reflection is considered a component |
48 | // of the color of the light source |
7fd59977 |
49 | |
81bba717 |
50 | // To determine 3 colors of reflection it is necessary : |
51 | // - coefficient of disperse reflection |
52 | // - coefficient of ambiant reflection |
53 | // - coefficient of specular reflection |
7fd59977 |
54 | |
81bba717 |
55 | // ( Under GL, 3 colors are determined) |
7fd59977 |
56 | |
57 | //-References Getting started with DEC PHIGS, annexe C |
58 | // Iris Advanced Graphics, unite D |
59 | |
60 | //-Language C++ 2.0 |
61 | |
62 | //-Declarations |
63 | |
64 | // for the class |
65 | #include <Graphic3d_MaterialAspect.ixx> |
66 | |
67 | //-Aliases |
68 | |
69 | //-Global data definitions |
70 | |
71 | // -- le coefficient de reflection diffuse, la couleur et l'activite |
72 | // MyDiffuseCoef : Standard_ShortReal; |
73 | // MyDiffuseColor : Color; |
74 | // MyDiffuseActivity : Standard_Boolean; |
75 | |
76 | // -- le coefficient de reflection ambiante, la couleur et l'activite |
77 | // MyAmbientCoef : Standard_ShortReal; |
78 | // MyAmbientColor : Color; |
79 | // MyAmbientActivity : Standard_Boolean; |
80 | |
81 | // -- le coefficient de reflection speculaire, la couleur et l'activite |
82 | // MySpecularCoef : Standard_ShortReal; |
83 | // MySpecularColor : Color; |
84 | // MySpecularActivity : Standard_Boolean; |
85 | |
86 | // -- le coefficient d emission du materiau, la couleur et l'activite |
87 | // MyEmissiveCoef : Standard_ShortReal; |
88 | // MyEmissiveActivity : Standard_Boolean; |
89 | |
90 | // -- le coefficient de transparence |
91 | // MyTransparencyCoef : Standard_ShortReal; |
92 | |
93 | // -- le coefficient de concentration lumineuse |
94 | // MyShininess : Standard_ShortReal; |
95 | |
96 | //-Constructors |
97 | |
98 | //-Destructors |
99 | |
100 | //-Methods, in order |
101 | |
102 | Graphic3d_MaterialAspect::Graphic3d_MaterialAspect () |
103 | : MyAmbientColor(0.2, 0.2, 0.2, Quantity_TOC_RGB) |
104 | { |
105 | #ifdef IMP171201 |
106 | MyRequestedMaterialName = Graphic3d_NOM_DEFAULT; |
107 | Init(MyRequestedMaterialName); |
108 | #else |
109 | Init(Graphic3d_NOM_DEFAULT); |
110 | #endif |
111 | } |
112 | |
113 | Graphic3d_MaterialAspect::Graphic3d_MaterialAspect (const Graphic3d_NameOfMaterial AName) |
114 | : MyAmbientColor(0.2, 0.2, 0.2, Quantity_TOC_RGB) |
115 | { |
116 | #ifdef IMP171201 |
117 | MyRequestedMaterialName = AName; |
118 | Init(MyRequestedMaterialName); |
119 | #else |
120 | Init(AName); |
121 | #endif |
122 | } |
123 | |
124 | void Graphic3d_MaterialAspect::Init(const Graphic3d_NameOfMaterial AName) { |
125 | |
126 | MyMaterialType = Graphic3d_MATERIAL_ASPECT; |
127 | MyTransparencyCoef = Standard_ShortReal (0.0); |
128 | MyDiffuseActivity = Standard_True; |
129 | MyDiffuseCoef = Standard_ShortReal (0.65); |
130 | MyAmbientActivity = Standard_True; |
131 | MyAmbientCoef = Standard_ShortReal (0.3); |
132 | MySpecularActivity = Standard_True; |
133 | MySpecularCoef = Standard_ShortReal (0.0); |
134 | MyEmissiveActivity = Standard_False; |
135 | MyEmissiveCoef = Standard_ShortReal (0.0); |
136 | MyEnvReflexion = Standard_ShortReal(0.0); |
137 | MyShininess = Standard_ShortReal (0.039); |
138 | MyDiffuseColor.SetValues (0.0, 0.0, 0.0, Quantity_TOC_RGB); |
139 | MySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); |
140 | MyMaterialName = AName; |
141 | #ifdef IMP171201 |
142 | Standard_Integer index = Standard_Integer(AName); |
143 | if( index < NumberOfMaterials() ) { |
144 | MyStringName = MaterialName(index+1); |
145 | } |
146 | #endif |
147 | |
148 | switch (AName) { |
149 | case Graphic3d_NOM_PLASTIC : /* Blue plastic */ |
81bba717 |
150 | /* Lighting Coefficient */ |
7fd59977 |
151 | MyShininess = Standard_ShortReal (0.0078125); |
152 | MyAmbientCoef = Standard_ShortReal (0.5); |
153 | MyDiffuseCoef = Standard_ShortReal (0.24); |
154 | MySpecularCoef = Standard_ShortReal (0.06); |
155 | break; |
156 | |
157 | case Graphic3d_NOM_SHINY_PLASTIC : /* black plastic */ |
81bba717 |
158 | /* Lighting Coefficient */ |
7fd59977 |
159 | MyShininess = Standard_ShortReal (1.0); |
160 | MyAmbientCoef = Standard_ShortReal (0.44); |
161 | MyDiffuseCoef = Standard_ShortReal (0.5); |
162 | MySpecularCoef = Standard_ShortReal (1.0); |
163 | break; |
164 | |
165 | case Graphic3d_NOM_SATIN : |
166 | MyShininess = Standard_ShortReal (0.09375); |
167 | MyAmbientCoef = Standard_ShortReal (0.33); |
168 | MyDiffuseCoef = Standard_ShortReal (0.4); |
169 | MySpecularCoef = Standard_ShortReal (0.44); |
170 | break; |
171 | |
172 | case Graphic3d_NOM_NEON_GNC: |
81bba717 |
173 | /* Lighting Coefficient */ |
7fd59977 |
174 | MyShininess = Standard_ShortReal (0.05); |
175 | MyAmbientCoef = Standard_ShortReal (1.0); |
176 | MyDiffuseCoef = Standard_ShortReal (1.0); |
177 | MySpecularCoef = Standard_ShortReal (0.62); |
178 | MyEmissiveCoef = Standard_ShortReal (1.0); |
179 | MyEmissiveActivity = Standard_True; |
180 | MyAmbientActivity = Standard_False; |
181 | break; |
182 | |
183 | case Graphic3d_NOM_METALIZED : |
81bba717 |
184 | /* Lighting Coefficient */ |
7fd59977 |
185 | MyShininess = Standard_ShortReal (0.13); |
186 | MyAmbientCoef = Standard_ShortReal (0.9); |
187 | MyDiffuseCoef = Standard_ShortReal (0.47); |
188 | MySpecularCoef = Standard_ShortReal (0.45); |
189 | MyAmbientActivity = Standard_False; |
190 | |
81bba717 |
191 | /* Color resulting from dispersed */ |
7fd59977 |
192 | //MyDiffuseColor.SetValues (0.87, 0.96, 1.0, Quantity_TOC_RGB); |
193 | |
81bba717 |
194 | /* Color resulting from specular */ |
7fd59977 |
195 | //MySpecularColor.SetValues (0.93, 0.95, 0.78, Quantity_TOC_RGB); |
196 | break; |
197 | |
81bba717 |
198 | // Ascending Compatibility physical materials. The same definition is taken |
199 | // as in the next constructor. |
7fd59977 |
200 | |
201 | case Graphic3d_NOM_BRASS : |
202 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
203 | /* Initialisation of coefficients and lighting color : brass */ |
7fd59977 |
204 | MyShininess = Standard_ShortReal (0.21794844); |
205 | MyAmbientCoef = Standard_ShortReal (1.0); |
206 | MyDiffuseCoef = Standard_ShortReal (1.0); |
207 | MySpecularCoef = Standard_ShortReal (1.0); |
208 | |
81bba717 |
209 | /* Color resulting from ambient */ |
7fd59977 |
210 | MyAmbientColor.SetValues (0.329412, 0.223529, 0.027451, Quantity_TOC_RGB); |
211 | |
81bba717 |
212 | /* Color resulting from dispersed */ |
7fd59977 |
213 | MyDiffuseColor.SetValues (0.780392, 0.568627, 0.113725, Quantity_TOC_RGB); |
214 | |
81bba717 |
215 | /* Color resulting from specular */ |
7fd59977 |
216 | MySpecularColor.SetValues (0.992157, 0.941176, 0.807843, Quantity_TOC_RGB); |
217 | break; |
218 | |
219 | case Graphic3d_NOM_BRONZE : |
220 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
221 | /* Lighting Coefficient */ |
7fd59977 |
222 | MyShininess = Standard_ShortReal (0.2); |
223 | MyAmbientCoef = Standard_ShortReal (1.0); |
224 | MyDiffuseCoef = Standard_ShortReal (1.0); |
225 | MySpecularCoef = Standard_ShortReal (1.0); |
226 | |
81bba717 |
227 | /* Color resulting from ambient */ |
7fd59977 |
228 | MyAmbientColor.SetValues (0.2125, 0.1275, 0.054, Quantity_TOC_RGB); |
229 | |
81bba717 |
230 | /* Color resulting from dispersed */ |
7fd59977 |
231 | MyDiffuseColor.SetValues (0.714, 0.4284, 0.18144, Quantity_TOC_RGB); |
232 | |
81bba717 |
233 | /* Color resulting from specular */ |
7fd59977 |
234 | MySpecularColor.SetValues (0.393548, 0.271906, 0.166721, Quantity_TOC_RGB); |
235 | break; |
236 | |
237 | case Graphic3d_NOM_COPPER : |
238 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
239 | /* Lighting Coefficient */ |
7fd59977 |
240 | MyShininess = Standard_ShortReal (0.93); |
241 | MyAmbientCoef = Standard_ShortReal (1.0); |
242 | MyDiffuseCoef = Standard_ShortReal (1.0); |
243 | MySpecularCoef = Standard_ShortReal (1.0); |
244 | |
81bba717 |
245 | /* Color resulting from ambient */ |
7fd59977 |
246 | MyAmbientColor.SetValues (0.33, 0.26, 0.23, Quantity_TOC_RGB); |
247 | |
81bba717 |
248 | /* Color resulting from dispersed */ |
7fd59977 |
249 | MyDiffuseColor.SetValues (0.50, 0.11, 0.0, Quantity_TOC_RGB); |
250 | |
81bba717 |
251 | /* Color resulting from specular */ |
7fd59977 |
252 | MySpecularColor.SetValues (0.95, 0.73, 0.0, Quantity_TOC_RGB); |
253 | break; |
254 | |
255 | case Graphic3d_NOM_GOLD : |
256 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
257 | /* Lighting Coefficient */ |
7fd59977 |
258 | MyShininess = Standard_ShortReal (0.0625); |
259 | MyAmbientCoef = Standard_ShortReal (0.3); |
260 | MyDiffuseCoef = Standard_ShortReal (0.4); |
261 | MySpecularCoef = Standard_ShortReal (0.9); |
262 | |
81bba717 |
263 | /* Color resulting from ambient */ |
7fd59977 |
264 | MyAmbientColor.SetValues (1.0, 0.76862745, 0.31764706, Quantity_TOC_RGB); |
265 | |
81bba717 |
266 | /* Color resulting from dispersed */ |
7fd59977 |
267 | MyDiffuseColor.SetValues (1.0, 0.69, 0.0, Quantity_TOC_RGB); |
268 | |
81bba717 |
269 | /* Color resulting from specular */ |
7fd59977 |
270 | MySpecularColor.SetValues (1.0, 0.98, 0.78, Quantity_TOC_RGB); |
271 | break; |
272 | |
273 | case Graphic3d_NOM_PEWTER : |
274 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
275 | /* Lighting Coefficient */ |
7fd59977 |
276 | MyShininess = Standard_ShortReal (0.076923047); |
277 | MyAmbientCoef = Standard_ShortReal (1.0); |
278 | MyDiffuseCoef = Standard_ShortReal (1.0); |
279 | MySpecularCoef = Standard_ShortReal (1.0); |
280 | |
81bba717 |
281 | /* Color resulting from ambient */ |
7fd59977 |
282 | MyAmbientColor.SetValues (0.105882, 0.058824, 0.113725, Quantity_TOC_RGB); |
283 | |
81bba717 |
284 | /* Color resulting from dispersed */ |
7fd59977 |
285 | MyDiffuseColor.SetValues (0.427451, 0.470588, 0.541176, Quantity_TOC_RGB); |
286 | |
81bba717 |
287 | /* Color resulting from specular */ |
7fd59977 |
288 | MySpecularColor.SetValues (0.333333, 0.333333, 0.521569, Quantity_TOC_RGB); |
289 | break; |
290 | |
291 | case Graphic3d_NOM_PLASTER : |
292 | #ifdef BUG // The plaster material must be considered as Generic. |
293 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
294 | /* Lighting Coefficient */ |
7fd59977 |
295 | MyShininess = Standard_ShortReal (0.2); |
296 | MyAmbientCoef = Standard_ShortReal (1.0); |
297 | MyDiffuseCoef = Standard_ShortReal (1.0); |
298 | MySpecularCoef = Standard_ShortReal (1.0); |
299 | #else |
81bba717 |
300 | /* Lighting Coefficient */ |
7fd59977 |
301 | MyShininess = Standard_ShortReal (0.0078125) |
302 | ; |
303 | MyAmbientCoef = Standard_ShortReal (0.26); |
304 | MyDiffuseCoef = Standard_ShortReal (0.23); |
305 | MySpecularCoef = Standard_ShortReal (0.06); |
306 | #endif |
307 | |
81bba717 |
308 | /* Color resulting from ambient */ |
7fd59977 |
309 | MyAmbientColor.SetValues (0.19225, 0.19225, 0.19225, Quantity_TOC_RGB); |
310 | |
81bba717 |
311 | /* Color resulting from dispersed */ |
7fd59977 |
312 | MyDiffuseColor.SetValues (0.50754, 0.50754, 0.50754, Quantity_TOC_RGB); |
313 | |
81bba717 |
314 | /* Color resulting from specular */ |
7fd59977 |
315 | MySpecularColor.SetValues (0.508273, 0.508273, 0.508273, Quantity_TOC_RGB); |
316 | break; |
317 | |
318 | case Graphic3d_NOM_SILVER : |
319 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
320 | /* Lighting Coefficient */ |
7fd59977 |
321 | MyShininess = Standard_ShortReal (0.2); |
322 | MyAmbientCoef = Standard_ShortReal (1.0); |
323 | MyDiffuseCoef = Standard_ShortReal (1.0); |
324 | MySpecularCoef = Standard_ShortReal (1.0); |
325 | |
81bba717 |
326 | /* Color resulting from ambient */ |
7fd59977 |
327 | MyAmbientColor.SetValues (0.19225, 0.19225, 0.19225, Quantity_TOC_RGB); |
328 | |
81bba717 |
329 | /* Color resulting from dispersed */ |
7fd59977 |
330 | MyDiffuseColor.SetValues (0.50754, 0.50754, 0.50754, Quantity_TOC_RGB); |
331 | |
81bba717 |
332 | /* Color resulting from specular */ |
7fd59977 |
333 | MySpecularColor.SetValues (0.508273, 0.508273, 0.508273, Quantity_TOC_RGB); |
334 | break; |
335 | |
336 | case Graphic3d_NOM_STEEL : |
337 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
338 | /* Lighting Coefficient */ |
7fd59977 |
339 | MyShininess = Standard_ShortReal (0.06); |
340 | MyAmbientCoef = Standard_ShortReal (0.01); |
341 | MyDiffuseCoef = Standard_ShortReal (0.03); |
342 | MySpecularCoef = Standard_ShortReal (0.98); |
343 | |
81bba717 |
344 | /* Color resulting from specular */ |
7fd59977 |
345 | MySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); |
346 | break; |
347 | |
348 | case Graphic3d_NOM_STONE : |
349 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
350 | /* Lighting Coefficient */ |
7fd59977 |
351 | MyShininess = Standard_ShortReal (0.17); |
352 | MyAmbientCoef = Standard_ShortReal (0.19); |
353 | MyDiffuseCoef = Standard_ShortReal (0.75); |
354 | MySpecularCoef = Standard_ShortReal (0.08); |
355 | |
81bba717 |
356 | /* Color resulting from ambient */ |
7fd59977 |
357 | MyAmbientColor.SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB); |
358 | |
81bba717 |
359 | /* Color resulting from dispersed */ |
7fd59977 |
360 | MyDiffuseColor.SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB); |
361 | |
81bba717 |
362 | /* Color resulting from specular */ |
7fd59977 |
363 | MySpecularColor.SetValues (0.98, 1.0, 0.60, Quantity_TOC_RGB); |
364 | break; |
365 | |
81bba717 |
366 | // Ascending Compatibility of physical materials. Takes the same definition |
367 | // as in the next constructor. New materials |
7fd59977 |
368 | |
369 | case Graphic3d_NOM_CHROME : |
370 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
371 | /* Lighting Coefficient */ |
7fd59977 |
372 | MyShininess = Standard_ShortReal (0.1); |
373 | MyAmbientCoef = Standard_ShortReal (1.0); |
374 | MyDiffuseCoef = Standard_ShortReal (1.0); |
375 | MySpecularCoef = Standard_ShortReal (1.0); |
376 | |
81bba717 |
377 | /* Color resulting from ambient */ |
7fd59977 |
378 | MyAmbientColor.SetValues (0.35, 0.35, 0.35, Quantity_TOC_RGB); |
379 | |
81bba717 |
380 | /* Color resulting from dispersed */ |
7fd59977 |
381 | MyDiffuseColor.SetValues (0.4, 0.4, 0.4, Quantity_TOC_RGB); |
382 | |
81bba717 |
383 | /* Color resulting from specular */ |
7fd59977 |
384 | MySpecularColor.SetValues (0.974597, 0.974597, 0.974597, Quantity_TOC_RGB); |
385 | break; |
386 | |
387 | case Graphic3d_NOM_NEON_PHC: |
388 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
389 | /* Lighting Coefficient */ |
7fd59977 |
390 | MyShininess = Standard_ShortReal (0.05); |
391 | MyAmbientCoef = Standard_ShortReal (1.0); |
392 | MyDiffuseCoef = Standard_ShortReal (1.0); |
393 | MySpecularCoef = Standard_ShortReal (0.62); |
394 | MyEmissiveCoef = Standard_ShortReal (0.9); |
395 | MyEmissiveActivity = Standard_True; |
396 | MyAmbientActivity = Standard_False; |
397 | MyDiffuseActivity = Standard_False; |
398 | |
81bba717 |
399 | /* Color resulting from ambient */ |
7fd59977 |
400 | MyAmbientColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); |
401 | |
81bba717 |
402 | /* Color resulting from dispersed */ |
7fd59977 |
403 | MyDiffuseColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); |
404 | |
81bba717 |
405 | /* Color resulting from specular */ |
7fd59977 |
406 | MySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); |
407 | |
81bba717 |
408 | /* Color resulting from specular */ |
7fd59977 |
409 | MyEmissiveColor.SetValues (0.0, 1.0, 0.46, Quantity_TOC_RGB); |
410 | break; |
411 | |
412 | case Graphic3d_NOM_ALUMINIUM : |
413 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
414 | /* Lighting Coefficient */ |
7fd59977 |
415 | MyShininess = Standard_ShortReal (0.09); |
416 | MyAmbientCoef = Standard_ShortReal (1.0); |
417 | MyDiffuseCoef = Standard_ShortReal (1.0); |
418 | MySpecularCoef = Standard_ShortReal (1.0); |
419 | |
81bba717 |
420 | /* Color resulting from ambient */ |
7fd59977 |
421 | MyAmbientColor.SetValues (0.30, 0.30, 0.30, Quantity_TOC_RGB); |
422 | |
81bba717 |
423 | /* Color resulting from dispersed */ |
7fd59977 |
424 | MyDiffuseColor.SetValues (0.30, 0.30, 0.30, Quantity_TOC_RGB); |
425 | |
81bba717 |
426 | /* Color resulting from specular */ |
7fd59977 |
427 | MySpecularColor.SetValues (0.70, 0.70, 0.80, Quantity_TOC_RGB); |
428 | break; |
429 | |
430 | case Graphic3d_NOM_OBSIDIAN : |
431 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
432 | /* Lighting Coefficient */ |
7fd59977 |
433 | MyShininess = Standard_ShortReal (0.3); |
434 | MyAmbientCoef = Standard_ShortReal (1.0); |
435 | MyDiffuseCoef = Standard_ShortReal (1.0); |
436 | MySpecularCoef = Standard_ShortReal (1.0); |
437 | |
81bba717 |
438 | /* Color resulting from ambient */ |
7fd59977 |
439 | MyAmbientColor.SetValues (0.05375, 0.05, 0.06625, Quantity_TOC_RGB); |
440 | |
81bba717 |
441 | /* Color resulting from dispersed */ |
7fd59977 |
442 | MyDiffuseColor.SetValues (0.18275, 0.17, 0.22525, Quantity_TOC_RGB); |
443 | |
81bba717 |
444 | /* Color resulting from specular */ |
7fd59977 |
445 | MySpecularColor.SetValues (0.332741, 0.328634, 0.346435, Quantity_TOC_RGB); |
446 | break; |
447 | |
448 | case Graphic3d_NOM_JADE : |
449 | MyMaterialType = Graphic3d_MATERIAL_PHYSIC; |
81bba717 |
450 | /* Lighting Coefficient */ |
7fd59977 |
451 | MyShininess = Standard_ShortReal (0.1); |
452 | MyAmbientCoef = Standard_ShortReal (1.0); |
453 | MyDiffuseCoef = Standard_ShortReal (1.0); |
454 | MySpecularCoef = Standard_ShortReal (1.0); |
455 | |
81bba717 |
456 | /* Color resulting from ambient */ |
7fd59977 |
457 | MyAmbientColor.SetValues (0.135, 0.2225, 0.1575, Quantity_TOC_RGB); |
458 | |
81bba717 |
459 | /* Color resulting from dispersed */ |
7fd59977 |
460 | MyDiffuseColor.SetValues (0.54, 0.89, 0.63, Quantity_TOC_RGB); |
461 | |
81bba717 |
462 | /* Color resulting from specular */ |
7fd59977 |
463 | MySpecularColor.SetValues (0.316228, 0.316228, 0.316228, Quantity_TOC_RGB); |
464 | break; |
465 | default: |
466 | #ifdef IMP171201 |
467 | case Graphic3d_NOM_DEFAULT : |
468 | MyStringName = "Default"; |
469 | break; |
470 | case Graphic3d_NOM_UserDefined : |
471 | MyStringName = "UserDefined"; |
472 | #endif |
473 | break ; |
474 | } |
475 | } |
476 | |
477 | void Graphic3d_MaterialAspect::IncreaseShine (const Standard_Real ADelta) { |
478 | |
479 | Standard_ShortReal OldShine; |
480 | |
481 | OldShine = MyShininess; |
482 | MyShininess = (Standard_ShortReal)(MyShininess + MyShininess * ADelta / 100.); |
483 | if ( (MyShininess > 1.0) || (MyShininess < 0.0) ) { |
484 | MyShininess = OldShine; |
485 | } |
486 | } |
487 | |
81bba717 |
488 | /* Attribution of the type of material */ |
7fd59977 |
489 | void Graphic3d_MaterialAspect::SetMaterialType( const Graphic3d_TypeOfMaterial AType ) { |
490 | MyMaterialType = AType ; |
491 | #ifdef IMP171201 |
492 | if( AType != MyMaterialType ) |
493 | SetMaterialName("UserDefined"); |
494 | #endif |
495 | } |
496 | |
497 | |
498 | void Graphic3d_MaterialAspect::SetAmbient (const Standard_Real AValue) { |
499 | |
500 | if ((AValue < 0.0) || (AValue > 1.0)) |
501 | Graphic3d_MaterialDefinitionError::Raise |
502 | ("Bad value for SetAmbient < 0. or > 1.0"); |
503 | |
504 | |
505 | MyAmbientCoef = Standard_ShortReal (AValue); |
506 | #ifndef BUC60565 |
507 | Standard_Real R, G, B; |
508 | MyAmbientColor.Values (R, G, B, Quantity_TOC_RGB); |
509 | MyAmbientColor.SetValues |
510 | (R*AValue, G*AValue, B*AValue, Quantity_TOC_RGB); |
511 | #endif |
512 | #ifdef IMP171201 |
513 | if( MyAmbientActivity && |
514 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
515 | SetMaterialName("UserDefined"); |
516 | #endif |
517 | } |
518 | |
519 | void Graphic3d_MaterialAspect::SetColor (const Quantity_Color& AColor) { |
520 | |
521 | MyAmbientColor = AColor; |
522 | #ifdef IMP171201 |
523 | if( MyAmbientActivity && |
524 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
525 | SetMaterialName("UserDefined"); |
526 | #endif |
527 | } |
528 | |
81bba717 |
529 | /* Attribution of color ambient lighting */ |
7fd59977 |
530 | void Graphic3d_MaterialAspect::SetAmbientColor (const Quantity_Color& AColor) { |
531 | |
532 | MyAmbientColor = AColor; |
533 | #ifdef IMP171201 |
534 | if( MyAmbientActivity && |
535 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
536 | SetMaterialName("UserDefined"); |
537 | #endif |
538 | } |
539 | |
81bba717 |
540 | /* Attribution of color dispersed lighting */ |
7fd59977 |
541 | void Graphic3d_MaterialAspect::SetDiffuseColor (const Quantity_Color& AColor) { |
542 | |
543 | MyDiffuseColor = AColor; |
544 | #ifdef IMP171201 |
545 | if( MyDiffuseActivity && |
546 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
547 | SetMaterialName("UserDefined"); |
548 | #endif |
549 | } |
550 | |
81bba717 |
551 | /* Attribution of color specular lighting */ |
7fd59977 |
552 | void Graphic3d_MaterialAspect::SetSpecularColor (const Quantity_Color& AColor) { |
553 | |
554 | MySpecularColor = AColor; |
555 | #ifdef IMP171201 |
556 | if( MySpecularActivity && |
557 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
558 | SetMaterialName("UserDefined"); |
559 | #endif |
560 | } |
561 | |
562 | /* Affectation couleur d emission */ |
563 | void Graphic3d_MaterialAspect::SetEmissiveColor (const Quantity_Color& AColor) { |
564 | |
565 | MyEmissiveColor = AColor; |
566 | #ifdef IMP171201 |
567 | if( MyEmissiveActivity && |
568 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
569 | SetMaterialName("UserDefined"); |
570 | #endif |
571 | } |
572 | |
573 | void Graphic3d_MaterialAspect::SetDiffuse (const Standard_Real AValue) { |
574 | |
575 | if ((AValue < 0.0) || (AValue > 1.0)) |
576 | Graphic3d_MaterialDefinitionError::Raise |
577 | ("Bad value for SetDiffuse < 0. or > 1.0"); |
578 | |
579 | |
580 | MyDiffuseCoef = Standard_ShortReal (AValue); |
581 | #ifndef BUC60565 |
582 | Standard_Real R, G, B; |
583 | MyDiffuseColor.Values (R, G, B, Quantity_TOC_RGB); |
584 | MyDiffuseColor.SetValues |
585 | (R*AValue, G*AValue, B*AValue, Quantity_TOC_RGB); |
586 | #endif |
587 | #ifdef IMP171201 |
588 | if( MyDiffuseActivity && |
589 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
590 | SetMaterialName("UserDefined"); |
591 | #endif |
592 | } |
593 | |
81bba717 |
594 | /* Attribution of coefficient of emission */ |
7fd59977 |
595 | void Graphic3d_MaterialAspect::SetEmissive (const Standard_Real AValue) { |
596 | |
597 | if ((AValue < 0.0) || (AValue > 1.0)) |
598 | Graphic3d_MaterialDefinitionError::Raise |
599 | ("Bad value for SetEmissive < 0. or > 1.0"); |
600 | |
601 | //Standard_Real R, G, B; |
602 | |
603 | MyEmissiveCoef = Standard_ShortReal (AValue); |
604 | #ifdef IMP171201 |
605 | if( MyDiffuseActivity && |
606 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
607 | SetMaterialName("UserDefined"); |
608 | #endif |
609 | } |
610 | |
611 | void Graphic3d_MaterialAspect::SetReflectionModeOn (const Graphic3d_TypeOfReflection AType) { |
612 | |
613 | switch (AType) { |
614 | |
615 | case Graphic3d_TOR_AMBIENT : |
616 | MyAmbientActivity = Standard_True; |
617 | break; |
618 | |
619 | case Graphic3d_TOR_DIFFUSE : |
620 | MyDiffuseActivity = Standard_True; |
621 | break; |
622 | |
623 | case Graphic3d_TOR_SPECULAR : |
624 | MySpecularActivity = Standard_True; |
625 | break; |
626 | |
627 | case Graphic3d_TOR_EMISSION : |
628 | MyEmissiveActivity = Standard_True; |
629 | break; |
630 | } |
631 | #ifdef IMP171201 |
632 | if( MyMaterialType == Graphic3d_MATERIAL_PHYSIC ) |
633 | SetMaterialName("UserDefined"); |
634 | #endif |
635 | } |
636 | |
637 | void Graphic3d_MaterialAspect::SetReflectionModeOff (const Graphic3d_TypeOfReflection AType) { |
638 | |
639 | switch (AType) { |
640 | |
641 | case Graphic3d_TOR_AMBIENT : |
642 | MyAmbientActivity = Standard_False; |
643 | break; |
644 | |
645 | case Graphic3d_TOR_DIFFUSE : |
646 | MyDiffuseActivity = Standard_False; |
647 | break; |
648 | |
649 | case Graphic3d_TOR_SPECULAR : |
650 | MySpecularActivity = Standard_False; |
651 | break; |
652 | |
653 | case Graphic3d_TOR_EMISSION : |
654 | MyEmissiveActivity = Standard_False; |
655 | break; |
656 | } |
657 | #ifdef IMP171201 |
658 | if( MyMaterialType == Graphic3d_MATERIAL_PHYSIC ) |
659 | SetMaterialName("UserDefined"); |
660 | #endif |
661 | } |
662 | |
663 | void Graphic3d_MaterialAspect::SetSpecular (const Standard_Real AValue) { |
664 | |
665 | if ((AValue < 0.0) || (AValue > 1.0)) |
666 | Graphic3d_MaterialDefinitionError::Raise |
667 | ("Bad value for SetSpecular < 0. or > 1.0"); |
668 | |
669 | |
670 | MySpecularCoef = Standard_ShortReal (AValue); |
671 | #ifndef BUC60565 |
672 | Standard_Real R, G, B; |
673 | MySpecularColor.Values (R, G, B, Quantity_TOC_RGB); |
674 | MySpecularColor.SetValues |
675 | (R*AValue, G*AValue, B*AValue, Quantity_TOC_RGB); |
676 | #endif |
677 | #ifdef IMP171201 |
678 | if( MySpecularActivity && |
679 | (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) |
680 | SetMaterialName("UserDefined"); |
681 | #endif |
682 | } |
683 | |
684 | void Graphic3d_MaterialAspect::SetTransparency (const Standard_Real AValue) { |
685 | |
686 | if ((AValue < 0.0) || (AValue > 1.0)) |
687 | Graphic3d_MaterialDefinitionError::Raise |
688 | ("Bad value for SetTransparency < 0. or > 1.0"); |
689 | |
690 | MyTransparencyCoef = Standard_ShortReal (AValue); |
691 | } |
692 | |
693 | Quantity_Color Graphic3d_MaterialAspect::Color () const { |
694 | return (MyAmbientColor); |
695 | } |
696 | |
81bba717 |
697 | /* Access to the color of the ambient lighting */ |
7fd59977 |
698 | Quantity_Color Graphic3d_MaterialAspect::AmbientColor () const { |
699 | |
700 | return (MyAmbientColor); |
701 | } |
702 | |
81bba717 |
703 | /* Access to the color of the dispersed lighting */ |
7fd59977 |
704 | Quantity_Color Graphic3d_MaterialAspect::DiffuseColor () const { |
705 | |
706 | return (MyDiffuseColor); |
707 | } |
708 | |
81bba717 |
709 | /* Access to the color of the specular lighting */ |
7fd59977 |
710 | Quantity_Color Graphic3d_MaterialAspect::SpecularColor () const { |
711 | |
712 | return (MySpecularColor); |
713 | } |
714 | |
81bba717 |
715 | /* Access to the color of emission */ |
7fd59977 |
716 | Quantity_Color Graphic3d_MaterialAspect::EmissiveColor () const { |
717 | |
718 | return (MyEmissiveColor); |
719 | } |
720 | |
81bba717 |
721 | /* Access to the type of material */ |
7fd59977 |
722 | Standard_Boolean Graphic3d_MaterialAspect::MaterialType( const Graphic3d_TypeOfMaterial AType ) const { |
723 | return ( MyMaterialType == AType ) ; |
724 | } |
725 | |
726 | Standard_Boolean Graphic3d_MaterialAspect::ReflectionMode (const Graphic3d_TypeOfReflection AType) const { |
727 | |
728 | Standard_Boolean Result; |
729 | |
730 | Result = Standard_False; |
731 | |
732 | switch (AType) { |
733 | |
734 | case Graphic3d_TOR_AMBIENT : |
735 | Result = MyAmbientActivity; |
736 | break; |
737 | |
738 | case Graphic3d_TOR_DIFFUSE : |
739 | Result = MyDiffuseActivity; |
740 | break; |
741 | |
742 | case Graphic3d_TOR_SPECULAR : |
743 | Result = MySpecularActivity; |
744 | break; |
745 | |
746 | case Graphic3d_TOR_EMISSION : |
747 | Result = MyEmissiveActivity; |
748 | break; |
749 | } |
750 | return (Result); |
751 | |
752 | } |
753 | |
81bba717 |
754 | /* Access to the color of the ambient lighting */ |
7fd59977 |
755 | Standard_Real Graphic3d_MaterialAspect::Ambient () const { |
756 | |
757 | return (Standard_Real (MyAmbientCoef)); |
758 | |
759 | } |
760 | |
81bba717 |
761 | /* Access to the color of the dispersed lighting */ |
7fd59977 |
762 | Standard_Real Graphic3d_MaterialAspect::Diffuse () const { |
763 | |
764 | return (Standard_Real (MyDiffuseCoef)); |
765 | |
766 | } |
767 | |
81bba717 |
768 | /* Value of the coefficient of emission */ |
7fd59977 |
769 | Standard_Real Graphic3d_MaterialAspect::Emissive () const { |
770 | |
771 | return (Standard_Real (MyEmissiveCoef)); |
772 | |
773 | } |
774 | |
81bba717 |
775 | /* Access to the color of the specular lighting */ |
7fd59977 |
776 | Standard_Real Graphic3d_MaterialAspect::Specular () const { |
777 | |
778 | return (Standard_Real (MySpecularCoef)); |
779 | |
780 | } |
781 | |
81bba717 |
782 | /* Access to the coefficient of transparency */ |
7fd59977 |
783 | Standard_Real Graphic3d_MaterialAspect::Transparency () const { |
784 | |
785 | return (Standard_Real (MyTransparencyCoef)); |
786 | |
787 | } |
788 | |
81bba717 |
789 | /* Access to the coefficient of shineness */ |
7fd59977 |
790 | Standard_Real Graphic3d_MaterialAspect::Shininess () const { |
791 | |
792 | return (Standard_Real (MyShininess)); |
793 | |
794 | } |
795 | |
81bba717 |
796 | /* Attribution of the coefficient of shineness */ |
7fd59977 |
797 | void Graphic3d_MaterialAspect::SetShininess (const Standard_Real AValue) { |
798 | |
799 | if ((AValue < 0.0) || (AValue > 1.0)) |
800 | Graphic3d_MaterialDefinitionError::Raise |
801 | ("Bad value for Shininess < 0. or > 1.0"); |
802 | |
803 | MyShininess = Standard_ShortReal (AValue); |
804 | #ifdef IMP171201 |
805 | SetMaterialName("UserDefined"); |
806 | #endif |
807 | } |
808 | |
809 | |
810 | void Graphic3d_MaterialAspect::SetEnvReflexion(const Standard_ShortReal AValue) |
811 | { |
812 | MyEnvReflexion = AValue; |
813 | } |
814 | |
815 | |
816 | Standard_ShortReal Graphic3d_MaterialAspect::EnvReflexion() const |
817 | { |
818 | return MyEnvReflexion; |
819 | } |
820 | |
821 | Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::Name() const |
822 | { |
823 | return MyMaterialName; |
824 | } |
825 | |
826 | void Graphic3d_MaterialAspect::Reset() { |
827 | #ifdef IMP171201 |
828 | Init(MyRequestedMaterialName); |
829 | #else |
830 | Init(MyMaterialName); |
831 | #endif |
832 | } |
833 | |
834 | #ifdef IMP150200 |
835 | Standard_Boolean Graphic3d_MaterialAspect::IsEqual(const Graphic3d_MaterialAspect& other) const { |
836 | |
837 | if( MyAmbientCoef == other.Ambient() && |
838 | MyDiffuseCoef == other.Diffuse() && |
839 | MySpecularCoef == other.Specular() && |
840 | MyEmissiveCoef == other.Emissive() && |
841 | MyTransparencyCoef == other.Transparency() && |
842 | MyShininess == other.Shininess() && |
843 | MyEnvReflexion == other.EnvReflexion() && |
844 | MyAmbientColor == other.AmbientColor() && |
845 | MyDiffuseColor == other.DiffuseColor() && |
846 | MySpecularColor == other.SpecularColor() && |
847 | MyEmissiveColor == other.EmissiveColor() && |
848 | MyAmbientActivity == other.ReflectionMode(Graphic3d_TOR_AMBIENT) && |
849 | MyDiffuseActivity == other.ReflectionMode(Graphic3d_TOR_DIFFUSE) && |
850 | MySpecularActivity == other.ReflectionMode(Graphic3d_TOR_SPECULAR) && |
851 | MyEmissiveActivity == other.ReflectionMode(Graphic3d_TOR_EMISSION) ) |
852 | return Standard_True; |
853 | |
854 | return Standard_False; |
855 | } |
856 | |
857 | Standard_Boolean Graphic3d_MaterialAspect::IsDifferent(const Graphic3d_MaterialAspect& other) const { |
858 | |
859 | return !IsEqual(other); |
860 | } |
861 | |
862 | typedef struct _Material { |
863 | const char* name; |
864 | Graphic3d_TypeOfMaterial type; |
865 | } Material; |
866 | |
867 | static Material theMaterials[] = { |
868 | {"Brass",Graphic3d_MATERIAL_PHYSIC}, |
869 | {"Bronze",Graphic3d_MATERIAL_PHYSIC}, |
870 | {"Copper",Graphic3d_MATERIAL_PHYSIC}, |
871 | {"Gold",Graphic3d_MATERIAL_PHYSIC}, |
872 | {"Pewter",Graphic3d_MATERIAL_PHYSIC}, |
873 | {"Plastered",Graphic3d_MATERIAL_ASPECT}, |
874 | {"Plastified",Graphic3d_MATERIAL_ASPECT}, |
875 | {"Silver",Graphic3d_MATERIAL_PHYSIC}, |
876 | {"Steel",Graphic3d_MATERIAL_PHYSIC}, |
877 | {"Stone",Graphic3d_MATERIAL_PHYSIC}, |
878 | {"Shiny_plastified",Graphic3d_MATERIAL_ASPECT}, |
879 | {"Satined",Graphic3d_MATERIAL_ASPECT}, |
880 | {"Metalized",Graphic3d_MATERIAL_ASPECT}, |
881 | {"Ionized",Graphic3d_MATERIAL_ASPECT}, |
882 | {"Chrome",Graphic3d_MATERIAL_PHYSIC}, |
883 | {"Aluminium",Graphic3d_MATERIAL_PHYSIC}, |
884 | {"Obsidian",Graphic3d_MATERIAL_PHYSIC}, |
885 | {"Neon",Graphic3d_MATERIAL_PHYSIC}, |
886 | {"Jade",Graphic3d_MATERIAL_PHYSIC} |
887 | }; |
888 | |
889 | Standard_Integer Graphic3d_MaterialAspect::NumberOfMaterials() { |
890 | Standard_Integer n =sizeof(theMaterials)/sizeof(Material); |
891 | if( n > Graphic3d_NOM_DEFAULT ) { |
81bba717 |
892 | cout << " *** Graphic3d_MaterialAspect::NumberOfMaterials() may return a badvalue due to incoherente size between material name array and enum" << endl; |
7fd59977 |
893 | } |
894 | return Graphic3d_NOM_DEFAULT; |
895 | } |
896 | |
897 | Standard_CString Graphic3d_MaterialAspect::MaterialName(const Standard_Integer aRank) { |
898 | |
899 | if( aRank < 1 || aRank > NumberOfMaterials() ) |
900 | Standard_OutOfRange::Raise(" BAD index of material"); |
901 | |
902 | return theMaterials[aRank-1].name; |
903 | } |
904 | |
905 | Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType(const Standard_Integer aRank) { |
906 | |
907 | if( aRank < 1 || aRank > NumberOfMaterials() ) |
908 | Standard_OutOfRange::Raise(" BAD index of material"); |
909 | |
910 | return theMaterials[aRank-1].type; |
911 | } |
912 | #endif |
913 | |
914 | #ifdef IMP171201 |
915 | Standard_CString Graphic3d_MaterialAspect::MaterialName() const |
916 | { |
917 | return MyStringName.ToCString(); |
918 | } |
919 | void Graphic3d_MaterialAspect::SetMaterialName(const Standard_CString aNewName) |
920 | { |
921 | // if a component of a "standard" material change, the |
922 | // result is no more standard ( a blue gold is not a gold ) |
923 | MyMaterialName = Graphic3d_NOM_UserDefined; |
924 | MyStringName = aNewName; |
925 | } |
926 | #endif |