0024704: Visualization - inherit OpenGl_Structure from Graphic3d_CStructure
[occt.git] / src / Graphic3d / Graphic3d_MaterialAspect.cxx
CommitLineData
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//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 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>
b5eb7166 66#include <Standard_Assert.hxx>
7fd59977 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
102Graphic3d_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
113Graphic3d_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
124void 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
477void Graphic3d_MaterialAspect::IncreaseShine (const Standard_Real ADelta) {
478
479Standard_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 489void 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
498void 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
519void 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 530void 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 541void 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 552void 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 */
563void 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
573void 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 595void 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
611void 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
637void 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
663void 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
684void 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
63bcc448 693const Quantity_Color& Graphic3d_MaterialAspect::Color() const
694{
695 return MyAmbientColor;
7fd59977 696}
697
63bcc448 698const Quantity_Color& Graphic3d_MaterialAspect::AmbientColor() const
699{
700 return MyAmbientColor;
7fd59977 701}
702
63bcc448 703const Quantity_Color& Graphic3d_MaterialAspect::DiffuseColor() const
704{
705 return MyDiffuseColor;
7fd59977 706}
707
63bcc448 708const Quantity_Color& Graphic3d_MaterialAspect::SpecularColor() const
709{
710 return MySpecularColor;
7fd59977 711}
712
63bcc448 713const Quantity_Color& Graphic3d_MaterialAspect::EmissiveColor() const
714{
715 return MyEmissiveColor;
7fd59977 716}
717
81bba717 718/* Access to the type of material */
7fd59977 719Standard_Boolean Graphic3d_MaterialAspect::MaterialType( const Graphic3d_TypeOfMaterial AType ) const {
720 return ( MyMaterialType == AType ) ;
721}
722
723Standard_Boolean Graphic3d_MaterialAspect::ReflectionMode (const Graphic3d_TypeOfReflection AType) const {
724
725Standard_Boolean Result;
726
727 Result = Standard_False;
728
729 switch (AType) {
730
731 case Graphic3d_TOR_AMBIENT :
732 Result = MyAmbientActivity;
733 break;
734
735 case Graphic3d_TOR_DIFFUSE :
736 Result = MyDiffuseActivity;
737 break;
738
739 case Graphic3d_TOR_SPECULAR :
740 Result = MySpecularActivity;
741 break;
742
743 case Graphic3d_TOR_EMISSION :
744 Result = MyEmissiveActivity;
745 break;
746 }
747 return (Result);
748
749}
750
81bba717 751/* Access to the color of the ambient lighting */
7fd59977 752Standard_Real Graphic3d_MaterialAspect::Ambient () const {
753
754 return (Standard_Real (MyAmbientCoef));
755
756}
757
81bba717 758/* Access to the color of the dispersed lighting */
7fd59977 759Standard_Real Graphic3d_MaterialAspect::Diffuse () const {
760
761 return (Standard_Real (MyDiffuseCoef));
762
763}
764
81bba717 765/* Value of the coefficient of emission */
7fd59977 766Standard_Real Graphic3d_MaterialAspect::Emissive () const {
767
768 return (Standard_Real (MyEmissiveCoef));
769
770}
771
81bba717 772/* Access to the color of the specular lighting */
7fd59977 773Standard_Real Graphic3d_MaterialAspect::Specular () const {
774
775 return (Standard_Real (MySpecularCoef));
776
777}
778
81bba717 779/* Access to the coefficient of transparency */
7fd59977 780Standard_Real Graphic3d_MaterialAspect::Transparency () const {
781
782 return (Standard_Real (MyTransparencyCoef));
783
784}
785
81bba717 786/* Access to the coefficient of shineness */
7fd59977 787Standard_Real Graphic3d_MaterialAspect::Shininess () const {
788
789 return (Standard_Real (MyShininess));
790
791}
792
81bba717 793/* Attribution of the coefficient of shineness */
7fd59977 794void Graphic3d_MaterialAspect::SetShininess (const Standard_Real AValue) {
795
796 if ((AValue < 0.0) || (AValue > 1.0))
797 Graphic3d_MaterialDefinitionError::Raise
798 ("Bad value for Shininess < 0. or > 1.0");
799
800 MyShininess = Standard_ShortReal (AValue);
801#ifdef IMP171201
802 SetMaterialName("UserDefined");
803#endif
804}
805
806
807void Graphic3d_MaterialAspect::SetEnvReflexion(const Standard_ShortReal AValue)
808{
809 MyEnvReflexion = AValue;
810}
811
812
813Standard_ShortReal Graphic3d_MaterialAspect::EnvReflexion() const
814{
815 return MyEnvReflexion;
816}
817
818Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::Name() const
819{
820 return MyMaterialName;
821}
822
823void Graphic3d_MaterialAspect::Reset() {
824#ifdef IMP171201
825 Init(MyRequestedMaterialName);
826#else
827 Init(MyMaterialName);
828#endif
829}
830
831#ifdef IMP150200
832Standard_Boolean Graphic3d_MaterialAspect::IsEqual(const Graphic3d_MaterialAspect& other) const {
833
834 if( MyAmbientCoef == other.Ambient() &&
835 MyDiffuseCoef == other.Diffuse() &&
836 MySpecularCoef == other.Specular() &&
837 MyEmissiveCoef == other.Emissive() &&
838 MyTransparencyCoef == other.Transparency() &&
839 MyShininess == other.Shininess() &&
840 MyEnvReflexion == other.EnvReflexion() &&
841 MyAmbientColor == other.AmbientColor() &&
842 MyDiffuseColor == other.DiffuseColor() &&
843 MySpecularColor == other.SpecularColor() &&
844 MyEmissiveColor == other.EmissiveColor() &&
845 MyAmbientActivity == other.ReflectionMode(Graphic3d_TOR_AMBIENT) &&
846 MyDiffuseActivity == other.ReflectionMode(Graphic3d_TOR_DIFFUSE) &&
847 MySpecularActivity == other.ReflectionMode(Graphic3d_TOR_SPECULAR) &&
848 MyEmissiveActivity == other.ReflectionMode(Graphic3d_TOR_EMISSION) )
849 return Standard_True;
850
851 return Standard_False;
852}
853
854Standard_Boolean Graphic3d_MaterialAspect::IsDifferent(const Graphic3d_MaterialAspect& other) const {
855
856 return !IsEqual(other);
857}
858
859typedef struct _Material {
860 const char* name;
861 Graphic3d_TypeOfMaterial type;
862} Material;
863
864static Material theMaterials[] = {
865 {"Brass",Graphic3d_MATERIAL_PHYSIC},
866 {"Bronze",Graphic3d_MATERIAL_PHYSIC},
867 {"Copper",Graphic3d_MATERIAL_PHYSIC},
868 {"Gold",Graphic3d_MATERIAL_PHYSIC},
869 {"Pewter",Graphic3d_MATERIAL_PHYSIC},
870 {"Plastered",Graphic3d_MATERIAL_ASPECT},
871 {"Plastified",Graphic3d_MATERIAL_ASPECT},
872 {"Silver",Graphic3d_MATERIAL_PHYSIC},
873 {"Steel",Graphic3d_MATERIAL_PHYSIC},
874 {"Stone",Graphic3d_MATERIAL_PHYSIC},
875 {"Shiny_plastified",Graphic3d_MATERIAL_ASPECT},
876 {"Satined",Graphic3d_MATERIAL_ASPECT},
877 {"Metalized",Graphic3d_MATERIAL_ASPECT},
878 {"Ionized",Graphic3d_MATERIAL_ASPECT},
879 {"Chrome",Graphic3d_MATERIAL_PHYSIC},
880 {"Aluminium",Graphic3d_MATERIAL_PHYSIC},
881 {"Obsidian",Graphic3d_MATERIAL_PHYSIC},
882 {"Neon",Graphic3d_MATERIAL_PHYSIC},
883 {"Jade",Graphic3d_MATERIAL_PHYSIC}
884};
885
886Standard_Integer Graphic3d_MaterialAspect::NumberOfMaterials() {
b5eb7166 887 Standard_STATIC_ASSERT(sizeof(theMaterials)/sizeof(Material) == Graphic3d_NOM_DEFAULT);
888
7fd59977 889 return Graphic3d_NOM_DEFAULT;
890}
891
892Standard_CString Graphic3d_MaterialAspect::MaterialName(const Standard_Integer aRank) {
893
894 if( aRank < 1 || aRank > NumberOfMaterials() )
895 Standard_OutOfRange::Raise(" BAD index of material");
896
897 return theMaterials[aRank-1].name;
898}
899
900Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType(const Standard_Integer aRank) {
901
902 if( aRank < 1 || aRank > NumberOfMaterials() )
903 Standard_OutOfRange::Raise(" BAD index of material");
904
905 return theMaterials[aRank-1].type;
906}
907#endif
908
909#ifdef IMP171201
910Standard_CString Graphic3d_MaterialAspect::MaterialName() const
911{
912 return MyStringName.ToCString();
913}
914void Graphic3d_MaterialAspect::SetMaterialName(const Standard_CString aNewName)
915{
916// if a component of a "standard" material change, the
917// result is no more standard ( a blue gold is not a gold )
918 MyMaterialName = Graphic3d_NOM_UserDefined;
919 MyStringName = aNewName;
920}
921#endif