diff --git a/samples/tcl/materials.tcl b/samples/tcl/materials.tcl new file mode 100644 index 0000000000..f1b81ceae8 --- /dev/null +++ b/samples/tcl/materials.tcl @@ -0,0 +1,87 @@ +# Script displays properties of different materials available in OCCT + +set THE_MATERIALS {brass bronze copper gold jade neon_phc pewter obsidian plaster plastic satin silver steel stone chrome aluminium water glass diamond charcoal} +set THE_COLORS {default red green blue1} +set THE_ROW_DIST 35 + +proc drawLabels {} { + set x 20 + set y 15 + set r 25 + set g 25 + set b 25 + foreach aMatIter $::THE_MATERIALS { + vdrawtext "$aMatIter" $x $y 0 $r $g $b 2 1 000 0 14 1 Arial + incr y 10 + } + set x 40 + set y 5 + foreach aColIter $::THE_COLORS { + if { $aColIter == "red" } { + set r 255 + set g 0 + set b 0 + } elseif { $aColIter == "green" } { + set r 0 + set g 255 + set b 0 + } elseif { $aColIter == "blue1" } { + set r 0 + set g 0 + set b 255 + } + vdrawtext "$aColIter" $x $y 0 $r $g $b 1 1 000 0 14 1 Arial + incr x $::THE_ROW_DIST + } +} + +proc drawObjects {theRow theColor} { + set aSize 4 + set aCtr -2 + set aCounter 0 + set x [expr 30 + $theRow * $::THE_ROW_DIST] + set y 15 + foreach aMatIter $::THE_MATERIALS { + set aSph s${theRow}_${aCounter} + set aBox b${theRow}_${aCounter} + uplevel #0 psphere $aSph $aSize + uplevel #0 box $aBox $aCtr $aCtr $aCtr $aSize $aSize $aSize + uplevel #0 ttranslate $aSph $x $y 0 + uplevel #0 ttranslate $aBox [expr $x + 10] $y 0 + uplevel #0 vdisplay -noredraw $aSph $aBox + uplevel #0 vsetmaterial -noredraw $aSph $aBox $aMatIter + if {$theColor != ""} { + uplevel #0 vsetcolor -noredraw $aSph $aBox $theColor + } + incr aCounter + incr y 10 + } +} + +# setup 3D viewer content +pload MODELING VISUALIZATION + +catch { vclose View1 } +vinit View1 w=768 h=768 +vclear +vtop +vglinfo +vsetgradientbg 180 200 255 180 180 180 2 +vlight change 0 pos -1 1 1 +vsetdispmode 1 + +# adjust scene bounding box +box bnd 0 0 0 180 210 1 +vdisplay -noredraw bnd +vsetdispmode bnd 0 +vfit +vremove -noredraw bnd + +# draw spheres and boxes with different materials +drawLabels +drawObjects 0 "" +drawObjects 1 red +drawObjects 2 green +drawObjects 3 blue1 +#vfit +vzfit diff --git a/src/Graphic3d/Graphic3d.cdl b/src/Graphic3d/Graphic3d.cdl index 6d63fc0a68..dcf0a93066 100644 --- a/src/Graphic3d/Graphic3d.cdl +++ b/src/Graphic3d/Graphic3d.cdl @@ -115,32 +115,39 @@ is enumeration NameOfMaterial is NOM_BRASS, -- laiton (PHYSIC) - NOM_BRONZE, -- bronze (PHYSIC) - NOM_COPPER, -- cuivre (PHYSIC) - NOM_GOLD, -- or (PHYSIC) + NOM_BRONZE, -- bronze (PHYSIC) + NOM_COPPER, -- cuivre (PHYSIC) + NOM_GOLD, -- or (PHYSIC) - NOM_PEWTER, -- etain (PHYSIC) + NOM_PEWTER, -- etain (PHYSIC) - NOM_PLASTER, -- platre (GENERIC) - NOM_PLASTIC, -- plastic (GENERIC) + NOM_PLASTER, -- platre (GENERIC) + NOM_PLASTIC, -- plastic (GENERIC) - NOM_SILVER, -- argent (PHYSIC) + NOM_SILVER, -- argent (PHYSIC) - NOM_STEEL, -- acier (PHYSIC) + NOM_STEEL, -- acier (PHYSIC) - NOM_STONE, -- pierre (PHYSIC) + NOM_STONE, -- pierre (PHYSIC) - NOM_SHINY_PLASTIC, -- plastique brillant (GENERIC) - NOM_SATIN, -- satin (GENERIC) - NOM_METALIZED, -- metallise New (GENERIC) - NOM_NEON_GNC, -- neon New (GENERIC) - NOM_CHROME, -- chrome New (PHYSIC) - NOM_ALUMINIUM, -- aluminium New (PHYSIC) - NOM_OBSIDIAN, -- obsidian New (PHYSIC) - NOM_NEON_PHC, -- neon New (PHYSIC) - NOM_JADE, -- jade New (PHYSIC) - NOM_DEFAULT, - NOM_UserDefined -- owner material + NOM_SHINY_PLASTIC, -- plastique brillant (GENERIC) + NOM_SATIN, -- satin (GENERIC) + NOM_METALIZED, -- metallise New (GENERIC) + NOM_NEON_GNC, -- neon New (GENERIC) + NOM_CHROME, -- chrome New (PHYSIC) + NOM_ALUMINIUM, -- aluminium New (PHYSIC) + NOM_OBSIDIAN, -- obsidian New (PHYSIC) + NOM_NEON_PHC, -- neon New (PHYSIC) + NOM_JADE, -- jade New (PHYSIC) + + NOM_CHARCOAL, + + NOM_WATER, + NOM_GLASS, + NOM_DIAMOND, + + NOM_DEFAULT, + NOM_UserDefined -- owner material end NameOfMaterial; ---Purpose: Types of aspect materials. ---Category: Enumerations diff --git a/src/Graphic3d/Graphic3d_MaterialAspect.cdl b/src/Graphic3d/Graphic3d_MaterialAspect.cdl index a917a3d6f8..45fe0d1b70 100644 --- a/src/Graphic3d/Graphic3d_MaterialAspect.cdl +++ b/src/Graphic3d/Graphic3d_MaterialAspect.cdl @@ -143,6 +143,15 @@ is -- negative value or greater than 1.0. raises MaterialDefinitionError from Graphic3d is static; + SetRefractionIndex ( me : in out; + theValue : Real from Standard ) + ---Level: Public + ---Purpose: Modifies the refraction index of the material. + -- Category: Methods to modify the class definition + -- Warning: Raises MaterialDefinitionError if is a + -- lesser than 1.0. + raises MaterialDefinitionError from Graphic3d is static; + SetColor ( me : in out; AColor : Color from Quantity ) is static; @@ -313,7 +322,14 @@ is ---Purpose: Returns the transparency coefficient of the surface. ---Category: Inquire methods - Emissive ( me ) + RefractionIndex ( me ) + returns Real from Standard + is static; + ---Level: Public + ---Purpose: Returns the refraction index of the material + ---Category: Inquire methods + + Emissive ( me ) returns Real from Standard is static; ---Level: Public @@ -409,7 +425,7 @@ is Init ( me : out; AName : NameOfMaterial from Graphic3d) is private; --- +-- fields @@ -449,47 +465,44 @@ fields -- Iris Advanced Graphics, unit D -- -- - -- the coefficient of diffuse reflection, the colour, and the activity - MyDiffuseCoef : ShortReal from Standard; - MyDiffuseColor : Color from Quantity; - MyDiffuseActivity : Boolean from Standard; + -- the coefficient of diffuse reflection, the colour, and the activity + myDiffuseCoef : ShortReal from Standard; + myDiffuseColor : Color from Quantity; + myDiffuseActivity : Boolean from Standard; - -- the coefficient of ambient reflection, the colour - -- and the activity - MyAmbientCoef : ShortReal from Standard; - MyAmbientColor : Color from Quantity; - MyAmbientActivity : Boolean from Standard; + -- the coefficient of ambient reflection, the colour and the activity + myAmbientCoef : ShortReal from Standard; + myAmbientColor : Color from Quantity; + myAmbientActivity : Boolean from Standard; - -- the coefficient of specular reflection, the colour - -- and the activity - MySpecularCoef : ShortReal from Standard; - MySpecularColor : Color from Quantity; - MySpecularActivity : Boolean from Standard; - - -- the coefficient of emissive reflection - MyEmissiveCoef : ShortReal from Standard; - MyEmissiveColor : Color from Quantity; - MyEmissiveActivity : Boolean from Standard; + -- the coefficient of specular reflection, the colour and the activity + mySpecularCoef : ShortReal from Standard; + mySpecularColor : Color from Quantity; + mySpecularActivity : Boolean from Standard; - -- the coefficient of transparency - MyTransparencyCoef : ShortReal from Standard; + -- the coefficient of emissive reflection + myEmissiveCoef : ShortReal from Standard; + myEmissiveColor : Color from Quantity; + myEmissiveActivity : Boolean from Standard; - -- the coefficient of luminosity - MyShininess : ShortReal from Standard; + -- the coefficient of transparency and refraction index + myTransparencyCoef : ShortReal from Standard; + myRefractionIndex : ShortReal from Standard; + -- the specular exponent + myShininess : ShortReal from Standard; - -- the coeficient of reflexion for the environment texture - MyEnvReflexion : ShortReal from Standard; - - -- the type of material - --MyMaterialType : Boolean from Standard; - MyMaterialType : TypeOfMaterial from Graphic3d; + -- the coeficient of reflexion for the environment texture + myEnvReflexion : ShortReal from Standard; - -- the Name of material - MyMaterialName : NameOfMaterial from Graphic3d; - MyRequestedMaterialName : NameOfMaterial from Graphic3d; + -- the type of material + myMaterialType : TypeOfMaterial from Graphic3d; - -- the string name of the material - MyStringName : AsciiString from TCollection; + -- the Name of material + myMaterialName : NameOfMaterial from Graphic3d; + myRequestedMaterialName : NameOfMaterial from Graphic3d; + + -- the string name of the material + myStringName : AsciiString from TCollection; end MaterialAspect; diff --git a/src/Graphic3d/Graphic3d_MaterialAspect.cxx b/src/Graphic3d/Graphic3d_MaterialAspect.cxx index c7891ca8d4..e872ad3d06 100644 --- a/src/Graphic3d/Graphic3d_MaterialAspect.cxx +++ b/src/Graphic3d/Graphic3d_MaterialAspect.cxx @@ -12,891 +12,935 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#define BUC60565 //GG_19/10/99 ; Don't change the color components when the corresponding -// coefficient is modified because the resulting color is computed in -// low level driver. - -#define IMP150200 //GG : Add IsEqual() IsDifferent() methods. -// Add NumberOfMaterials() MaterialName() class methods - -#define IMP171201 //GG : Add Add MaterialName() SetMaterialName() instance -// methods in order to set or retrieve name of the current -// material. -// Capitalize all material name strings. -// Thanks to Stephane ROUTELOUS. - - -//-Version - -//-Design Declaration of variables specific to the definition -// of materials - -//-Warning A material is defined by : -// - coefficient of transparence -// - coefficient of disperse reflection -// - coefficient of ambiant reflection -// - coefficient of specular reflection -// - coefficient of emission - -// 2 properties permiting to define a material : -// - transparence -// - reflection, i.e. absorbtion properties -// and light diffusion - -// Disperse reflection is considered a component -// The specular reflection is considered a component -// of the color of the light source - -// To determine 3 colors of reflection it is necessary : -// - coefficient of disperse reflection -// - coefficient of ambiant reflection -// - coefficient of specular reflection - -// ( Under GL, 3 colors are determined) - -//-References Getting started with DEC PHIGS, annexe C -// Iris Advanced Graphics, unite D - -//-Language C++ 2.0 - -//-Declarations - -// for the class #include #include -//-Aliases -//-Global data definitions - -// -- le coefficient de reflection diffuse, la couleur et l'activite -// MyDiffuseCoef : Standard_ShortReal; -// MyDiffuseColor : Color; -// MyDiffuseActivity : Standard_Boolean; - -// -- le coefficient de reflection ambiante, la couleur et l'activite -// MyAmbientCoef : Standard_ShortReal; -// MyAmbientColor : Color; -// MyAmbientActivity : Standard_Boolean; - -// -- le coefficient de reflection speculaire, la couleur et l'activite -// MySpecularCoef : Standard_ShortReal; -// MySpecularColor : Color; -// MySpecularActivity : Standard_Boolean; - -// -- le coefficient d emission du materiau, la couleur et l'activite -// MyEmissiveCoef : Standard_ShortReal; -// MyEmissiveActivity : Standard_Boolean; - -// -- le coefficient de transparence -// MyTransparencyCoef : Standard_ShortReal; - -// -- le coefficient de concentration lumineuse -// MyShininess : Standard_ShortReal; - -//-Constructors - -//-Destructors - -//-Methods, in order - -Graphic3d_MaterialAspect::Graphic3d_MaterialAspect () -: MyAmbientColor(0.2, 0.2, 0.2, Quantity_TOC_RGB) -{ -#ifdef IMP171201 - MyRequestedMaterialName = Graphic3d_NOM_DEFAULT; - Init(MyRequestedMaterialName); -#else - Init(Graphic3d_NOM_DEFAULT); -#endif -} - -Graphic3d_MaterialAspect::Graphic3d_MaterialAspect (const Graphic3d_NameOfMaterial AName) -: MyAmbientColor(0.2, 0.2, 0.2, Quantity_TOC_RGB) +// ======================================================================= +// function : Graphic3d_MaterialAspect +// purpose : +// ======================================================================= +Graphic3d_MaterialAspect::Graphic3d_MaterialAspect() +: myAmbientColor (0.2, 0.2, 0.2, Quantity_TOC_RGB) { -#ifdef IMP171201 - MyRequestedMaterialName = AName; - Init(MyRequestedMaterialName); -#else - Init(AName); -#endif + myRequestedMaterialName = Graphic3d_NOM_DEFAULT; + Init (myRequestedMaterialName); } -void Graphic3d_MaterialAspect::Init(const Graphic3d_NameOfMaterial AName) { - - MyMaterialType = Graphic3d_MATERIAL_ASPECT; - MyTransparencyCoef = Standard_ShortReal (0.0); - MyDiffuseActivity = Standard_True; - MyDiffuseCoef = Standard_ShortReal (0.65); - MyAmbientActivity = Standard_True; - MyAmbientCoef = Standard_ShortReal (0.3); - MySpecularActivity = Standard_True; - MySpecularCoef = Standard_ShortReal (0.0); - MyEmissiveActivity = Standard_False; - MyEmissiveCoef = Standard_ShortReal (0.0); - MyEnvReflexion = Standard_ShortReal(0.0); - MyShininess = Standard_ShortReal (0.039); - MyDiffuseColor.SetValues (0.0, 0.0, 0.0, Quantity_TOC_RGB); - MySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); - MyMaterialName = AName; -#ifdef IMP171201 - Standard_Integer index = Standard_Integer(AName); - if( index < NumberOfMaterials() ) { - MyStringName = MaterialName(index+1); - } -#endif - - switch (AName) { - case Graphic3d_NOM_PLASTIC : /* Blue plastic */ - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.0078125); - MyAmbientCoef = Standard_ShortReal (0.5); - MyDiffuseCoef = Standard_ShortReal (0.24); - MySpecularCoef = Standard_ShortReal (0.06); - break; - - case Graphic3d_NOM_SHINY_PLASTIC : /* black plastic */ - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (1.0); - MyAmbientCoef = Standard_ShortReal (0.44); - MyDiffuseCoef = Standard_ShortReal (0.5); - MySpecularCoef = Standard_ShortReal (1.0); - break; - - case Graphic3d_NOM_SATIN : - MyShininess = Standard_ShortReal (0.09375); - MyAmbientCoef = Standard_ShortReal (0.33); - MyDiffuseCoef = Standard_ShortReal (0.4); - MySpecularCoef = Standard_ShortReal (0.44); - break; - - case Graphic3d_NOM_NEON_GNC: - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.05); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (0.62); - MyEmissiveCoef = Standard_ShortReal (1.0); - MyEmissiveActivity = Standard_True; - MyAmbientActivity = Standard_False; - break; - - case Graphic3d_NOM_METALIZED : - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.13); - MyAmbientCoef = Standard_ShortReal (0.9); - MyDiffuseCoef = Standard_ShortReal (0.47); - MySpecularCoef = Standard_ShortReal (0.45); - MyAmbientActivity = Standard_False; - - /* Color resulting from dispersed */ - //MyDiffuseColor.SetValues (0.87, 0.96, 1.0, Quantity_TOC_RGB); - - /* Color resulting from specular */ - //MySpecularColor.SetValues (0.93, 0.95, 0.78, Quantity_TOC_RGB); - break; - -// Ascending Compatibility physical materials. The same definition is taken -// as in the next constructor. - - case Graphic3d_NOM_BRASS : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Initialisation of coefficients and lighting color : brass */ - MyShininess = Standard_ShortReal (0.21794844); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.329412, 0.223529, 0.027451, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.780392, 0.568627, 0.113725, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.992157, 0.941176, 0.807843, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_BRONZE : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.2); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.2125, 0.1275, 0.054, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.714, 0.4284, 0.18144, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.393548, 0.271906, 0.166721, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_COPPER : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.93); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.33, 0.26, 0.23, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.50, 0.11, 0.0, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.95, 0.73, 0.0, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_GOLD : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.0625); - MyAmbientCoef = Standard_ShortReal (0.3); - MyDiffuseCoef = Standard_ShortReal (0.4); - MySpecularCoef = Standard_ShortReal (0.9); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (1.0, 0.76862745, 0.31764706, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (1.0, 0.69, 0.0, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (1.0, 0.98, 0.78, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_PEWTER : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.076923047); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.105882, 0.058824, 0.113725, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.427451, 0.470588, 0.541176, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.333333, 0.333333, 0.521569, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_PLASTER : -#ifdef BUG // The plaster material must be considered as Generic. - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.2); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); -#else - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.0078125) -; - MyAmbientCoef = Standard_ShortReal (0.26); - MyDiffuseCoef = Standard_ShortReal (0.23); - MySpecularCoef = Standard_ShortReal (0.06); -#endif - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.19225, 0.19225, 0.19225, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.50754, 0.50754, 0.50754, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.508273, 0.508273, 0.508273, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_SILVER : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.2); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.19225, 0.19225, 0.19225, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.50754, 0.50754, 0.50754, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.508273, 0.508273, 0.508273, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_STEEL : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.06); - MyAmbientCoef = Standard_ShortReal (0.01); - MyDiffuseCoef = Standard_ShortReal (0.03); - MySpecularCoef = Standard_ShortReal (0.98); - - /* Color resulting from specular */ - MySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_STONE : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.17); - MyAmbientCoef = Standard_ShortReal (0.19); - MyDiffuseCoef = Standard_ShortReal (0.75); - MySpecularCoef = Standard_ShortReal (0.08); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.98, 1.0, 0.60, Quantity_TOC_RGB); - break; - -// Ascending Compatibility of physical materials. Takes the same definition -// as in the next constructor. New materials - - case Graphic3d_NOM_CHROME : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.1); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.35, 0.35, 0.35, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.4, 0.4, 0.4, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.974597, 0.974597, 0.974597, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_NEON_PHC: - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.05); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (0.62); - MyEmissiveCoef = Standard_ShortReal (0.9); - MyEmissiveActivity = Standard_True; - MyAmbientActivity = Standard_False; - MyDiffuseActivity = Standard_False; - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MyEmissiveColor.SetValues (0.0, 1.0, 0.46, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_ALUMINIUM : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.09); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.30, 0.30, 0.30, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.30, 0.30, 0.30, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.70, 0.70, 0.80, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_OBSIDIAN : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.3); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.05375, 0.05, 0.06625, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.18275, 0.17, 0.22525, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.332741, 0.328634, 0.346435, Quantity_TOC_RGB); - break; - - case Graphic3d_NOM_JADE : - MyMaterialType = Graphic3d_MATERIAL_PHYSIC; - /* Lighting Coefficient */ - MyShininess = Standard_ShortReal (0.1); - MyAmbientCoef = Standard_ShortReal (1.0); - MyDiffuseCoef = Standard_ShortReal (1.0); - MySpecularCoef = Standard_ShortReal (1.0); - - /* Color resulting from ambient */ - MyAmbientColor.SetValues (0.135, 0.2225, 0.1575, Quantity_TOC_RGB); - - /* Color resulting from dispersed */ - MyDiffuseColor.SetValues (0.54, 0.89, 0.63, Quantity_TOC_RGB); - - /* Color resulting from specular */ - MySpecularColor.SetValues (0.316228, 0.316228, 0.316228, Quantity_TOC_RGB); - break; - default: -#ifdef IMP171201 - case Graphic3d_NOM_DEFAULT : - MyStringName = "Default"; - break; - case Graphic3d_NOM_UserDefined : - MyStringName = "UserDefined"; -#endif - break ; - } +// ======================================================================= +// function : Graphic3d_MaterialAspect +// purpose : +// ======================================================================= +Graphic3d_MaterialAspect::Graphic3d_MaterialAspect (const Graphic3d_NameOfMaterial theName) +: myAmbientColor (0.2, 0.2, 0.2, Quantity_TOC_RGB) +{ + myRequestedMaterialName = theName; + Init (myRequestedMaterialName); } -void Graphic3d_MaterialAspect::IncreaseShine (const Standard_Real ADelta) { +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName) +{ + myMaterialType = Graphic3d_MATERIAL_ASPECT; + myTransparencyCoef = 0.0f; + myRefractionIndex = 1.0f; + myDiffuseActivity = Standard_True; + myDiffuseCoef = 0.65f; + myAmbientActivity = Standard_True; + myAmbientCoef = 0.3f; + mySpecularActivity = Standard_True; + mySpecularCoef = 0.0f; + myEmissiveActivity = Standard_False; + myEmissiveCoef = 0.0f; + myEnvReflexion = 0.0f; + myShininess = 0.039f; + myDiffuseColor .SetValues (0.0, 0.0, 0.0, Quantity_TOC_RGB); + mySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); + myMaterialName = theName; -Standard_ShortReal OldShine; + Standard_Integer index = Standard_Integer (theName); + if (index < NumberOfMaterials()) + { + myStringName = MaterialName (index + 1); + } - OldShine = MyShininess; - MyShininess = (Standard_ShortReal)(MyShininess + MyShininess * ADelta / 100.); - if ( (MyShininess > 1.0) || (MyShininess < 0.0) ) { - MyShininess = OldShine; - } + switch (theName) + { + case Graphic3d_NOM_PLASTIC: // Blue plastic + myShininess = Standard_ShortReal (0.0078125); + myAmbientCoef = Standard_ShortReal (0.5); + myDiffuseCoef = Standard_ShortReal (0.24); + mySpecularCoef = Standard_ShortReal (0.06); + break; + case Graphic3d_NOM_SHINY_PLASTIC: // black plastic + myShininess = Standard_ShortReal (1.0); + myAmbientCoef = Standard_ShortReal (0.44); + myDiffuseCoef = Standard_ShortReal (0.5); + mySpecularCoef = Standard_ShortReal (1.0); + break; + case Graphic3d_NOM_SATIN : + myShininess = Standard_ShortReal (0.09375); + myAmbientCoef = Standard_ShortReal (0.33); + myDiffuseCoef = Standard_ShortReal (0.4); + mySpecularCoef = Standard_ShortReal (0.44); + break; + case Graphic3d_NOM_NEON_GNC: + myShininess = Standard_ShortReal (0.05); + myAmbientCoef = Standard_ShortReal (1.0); + myDiffuseCoef = Standard_ShortReal (1.0); + mySpecularCoef = Standard_ShortReal (0.62); + myEmissiveCoef = Standard_ShortReal (1.0); + myEmissiveActivity = Standard_True; + myAmbientActivity = Standard_False; + break; + case Graphic3d_NOM_METALIZED: + myShininess = Standard_ShortReal (0.13); + myAmbientCoef = Standard_ShortReal (0.9); + myDiffuseCoef = Standard_ShortReal (0.47); + mySpecularCoef = Standard_ShortReal (0.45); + myAmbientActivity = Standard_False; + + // Color resulting from dispersed + //myDiffuseColor .SetValues (0.87, 0.96, 1.0, Quantity_TOC_RGB); + // Color resulting from specular + //mySpecularColor.SetValues (0.93, 0.95, 0.78, Quantity_TOC_RGB); + break; + // Ascending Compatibility physical materials. The same definition is taken as in the next constructor. + case Graphic3d_NOM_BRASS: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.65f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.329f, 0.224f, 0.027f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.780f, 0.569f, 0.114f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.992f, 0.941f, 0.808f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_BRONZE: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.65f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.213f, 0.128f, 0.054f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.714f, 0.428f, 0.181f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.590f, 0.408f, 0.250f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_COPPER: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.65f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.191f, 0.074f, 0.023f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.604f, 0.270f, 0.083f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.950f, 0.640f, 0.540f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_GOLD: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.80f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.300f, 0.230f, 0.095f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.752f, 0.580f, 0.100f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (1.000f, 0.710f, 0.290f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_PEWTER: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.50f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.106f, 0.059f, 0.114f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.427f, 0.471f, 0.541f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.333f, 0.333f, 0.522f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_PLASTER: + myShininess = 0.01f; + myAmbientCoef = 0.26f; + myDiffuseCoef = 0.75f; + mySpecularCoef = 0.05f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.192f, 0.192f, 0.192f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.508f, 0.508f, 0.508f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.508f, 0.508f, 0.508f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_SILVER: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.75f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.275f, 0.275f, 0.250f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.630f, 0.630f, 0.630f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.950f, 0.930f, 0.880f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_STEEL: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.90f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.150f, 0.150f, 0.180f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.500f, 0.510f, 0.520f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.560f, 0.570f, 0.580f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_STONE: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.17f; + myAmbientCoef = 0.19f; + myDiffuseCoef = 0.75f; + mySpecularCoef = 0.08f; + + // Color resulting from ambient + myAmbientColor .SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.98, 1.0, 0.60, Quantity_TOC_RGB); + break; + // Ascending Compatibility of physical materials. Takes the same definition as in the next constructor. New materials + case Graphic3d_NOM_CHROME: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.90f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.200f, 0.200f, 0.225f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.550f, 0.550f, 0.550f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.975f, 0.975f, 0.975f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_ALUMINIUM: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.75f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.300f, 0.300f, 0.300f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.600f, 0.600f, 0.600f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.910f, 0.920f, 0.920f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_NEON_PHC: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.05f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 0.62f; + myEmissiveCoef = 0.90f; + myAmbientActivity = Standard_False; + myDiffuseActivity = Standard_False; + myEmissiveActivity = Standard_True; + + // Color resulting from ambient + myAmbientColor .SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB); + // Color resulting from specular + myEmissiveColor.SetValues (0.0, 1.0, 0.46, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_OBSIDIAN: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.3f; + myAmbientCoef = 1.0f; + myDiffuseCoef = 1.0f; + mySpecularCoef = 1.0f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.054f, 0.050f, 0.066f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.183f, 0.170f, 0.225f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.333f, 0.329f, 0.346f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_JADE: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.10f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.135f, 0.223f, 0.158f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.540f, 0.890f, 0.630f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.316f, 0.316f, 0.316f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_CHARCOAL: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.01f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + + // Color resulting from ambient + myAmbientColor .SetValues (0.050f, 0.050f, 0.050f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor .SetValues (0.150f, 0.150f, 0.150f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.000f, 0.000f, 0.000f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_WATER: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.90f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + myRefractionIndex = 1.33f; + myTransparencyCoef = 0.80f; + + // Color resulting from ambient + myAmbientColor.SetValues (0.450f, 0.450f, 0.475f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor.SetValues (0.050f, 0.050f, 0.075f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.380f, 0.380f, 0.380f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_GLASS: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.50f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + myRefractionIndex = 1.62f; + myTransparencyCoef = 0.80f; + + // Color resulting from ambient + myAmbientColor.SetValues (0.550f, 0.575f, 0.575f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor.SetValues (0.050f, 0.075f, 0.075f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.920f, 0.920f, 0.920f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_DIAMOND: + myMaterialType = Graphic3d_MATERIAL_PHYSIC; + + myShininess = 0.90f; + myAmbientCoef = 1.00f; + myDiffuseCoef = 1.00f; + mySpecularCoef = 1.00f; + myRefractionIndex = 2.42f; + myTransparencyCoef = 0.80f; + + // Color resulting from ambient + myAmbientColor.SetValues (0.550f, 0.550f, 0.550f, Quantity_TOC_RGB); + // Color resulting from dispersed + myDiffuseColor.SetValues (0.100f, 0.100f, 0.100f, Quantity_TOC_RGB); + // Color resulting from specular + mySpecularColor.SetValues (0.970f, 0.970f, 0.970f, Quantity_TOC_RGB); + break; + case Graphic3d_NOM_UserDefined: + myStringName = "UserDefined"; + break; + case Graphic3d_NOM_DEFAULT: + default: + myStringName = "Default"; + break; + } } -/* Attribution of the type of material */ -void Graphic3d_MaterialAspect::SetMaterialType( const Graphic3d_TypeOfMaterial AType ) { - MyMaterialType = AType ; -#ifdef IMP171201 - if( AType != MyMaterialType ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : IncreaseShine +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::IncreaseShine (const Standard_Real theDelta) +{ + Standard_ShortReal anOldShine = myShininess; + myShininess = Standard_ShortReal(myShininess + myShininess * theDelta / 100.0); + if (myShininess > 1.0 || myShininess < 0.0) + { + myShininess = anOldShine; + } } - -void Graphic3d_MaterialAspect::SetAmbient (const Standard_Real AValue) { - - if ((AValue < 0.0) || (AValue > 1.0)) - Graphic3d_MaterialDefinitionError::Raise - ("Bad value for SetAmbient < 0. or > 1.0"); - - - MyAmbientCoef = Standard_ShortReal (AValue); -#ifndef BUC60565 - Standard_Real R, G, B; - MyAmbientColor.Values (R, G, B, Quantity_TOC_RGB); - MyAmbientColor.SetValues - (R*AValue, G*AValue, B*AValue, Quantity_TOC_RGB); -#endif -#ifdef IMP171201 - if( MyAmbientActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : SetMaterialType +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetMaterialType (const Graphic3d_TypeOfMaterial theType) +{ + myMaterialType = theType; + if (theType != myMaterialType) + { + SetMaterialName ("UserDefined"); + } } -void Graphic3d_MaterialAspect::SetColor (const Quantity_Color& AColor) { +// ======================================================================= +// function : SetAmbient +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetAmbient (const Standard_Real theValue) +{ + if (theValue < 0.0 + || theValue > 1.0) + { + Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetAmbient < 0. or > 1.0"); + } - MyAmbientColor = AColor; -#ifdef IMP171201 - if( MyAmbientActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif + myAmbientCoef = Standard_ShortReal (theValue); + if (myAmbientActivity + && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -/* Attribution of color ambient lighting */ -void Graphic3d_MaterialAspect::SetAmbientColor (const Quantity_Color& AColor) { - - MyAmbientColor = AColor; -#ifdef IMP171201 - if( MyAmbientActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : SetColor +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetColor (const Quantity_Color& theColor) +{ + const Standard_ShortReal anAmbientCoeff = 0.25f; + myAmbientColor.SetValues (theColor.Red() * anAmbientCoeff, + theColor.Green() * anAmbientCoeff, + theColor.Blue() * anAmbientCoeff, Quantity_TOC_RGB); + myDiffuseColor = theColor; + if (myAmbientActivity && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -/* Attribution of color dispersed lighting */ -void Graphic3d_MaterialAspect::SetDiffuseColor (const Quantity_Color& AColor) { - - MyDiffuseColor = AColor; -#ifdef IMP171201 - if( MyDiffuseActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : SetAmbientColor +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetAmbientColor (const Quantity_Color& theColor) +{ + myAmbientColor = theColor; + if (myAmbientActivity + && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -/* Attribution of color specular lighting */ -void Graphic3d_MaterialAspect::SetSpecularColor (const Quantity_Color& AColor) { - - MySpecularColor = AColor; -#ifdef IMP171201 - if( MySpecularActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : SetDiffuseColor +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetDiffuseColor (const Quantity_Color& theColor) +{ + myDiffuseColor = theColor; + if (myDiffuseActivity + && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -/* Affectation couleur d emission */ -void Graphic3d_MaterialAspect::SetEmissiveColor (const Quantity_Color& AColor) { - - MyEmissiveColor = AColor; -#ifdef IMP171201 - if( MyEmissiveActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : SetSpecularColor +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetSpecularColor (const Quantity_Color& theColor) +{ + mySpecularColor = theColor; + if (mySpecularActivity + && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -void Graphic3d_MaterialAspect::SetDiffuse (const Standard_Real AValue) { - - if ((AValue < 0.0) || (AValue > 1.0)) - Graphic3d_MaterialDefinitionError::Raise - ("Bad value for SetDiffuse < 0. or > 1.0"); - - - MyDiffuseCoef = Standard_ShortReal (AValue); -#ifndef BUC60565 - Standard_Real R, G, B; - MyDiffuseColor.Values (R, G, B, Quantity_TOC_RGB); - MyDiffuseColor.SetValues - (R*AValue, G*AValue, B*AValue, Quantity_TOC_RGB); -#endif -#ifdef IMP171201 - if( MyDiffuseActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : SetEmissiveColor +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetEmissiveColor (const Quantity_Color& theColor) +{ + myEmissiveColor = theColor; + if (myEmissiveActivity + && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -/* Attribution of coefficient of emission */ -void Graphic3d_MaterialAspect::SetEmissive (const Standard_Real AValue) { +// ======================================================================= +// function : SetDiffuse +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetDiffuse (const Standard_Real theValue) +{ + if (theValue < 0.0 + || theValue > 1.0) + { + Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetDiffuse < 0. or > 1.0"); + } - if ((AValue < 0.0) || (AValue > 1.0)) - Graphic3d_MaterialDefinitionError::Raise - ("Bad value for SetEmissive < 0. or > 1.0"); - -//Standard_Real R, G, B; - - MyEmissiveCoef = Standard_ShortReal (AValue); -#ifdef IMP171201 - if( MyDiffuseActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif + myDiffuseCoef = Standard_ShortReal (theValue); + if (myDiffuseActivity + && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -void Graphic3d_MaterialAspect::SetReflectionModeOn (const Graphic3d_TypeOfReflection AType) { +// ======================================================================= +// function : SetEmissive +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetEmissive (const Standard_Real theValue) +{ + if (theValue < 0.0 + || theValue > 1.0) + { + Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetEmissive < 0. or > 1.0"); + } - switch (AType) { - - case Graphic3d_TOR_AMBIENT : - MyAmbientActivity = Standard_True; - break; - - case Graphic3d_TOR_DIFFUSE : - MyDiffuseActivity = Standard_True; - break; - - case Graphic3d_TOR_SPECULAR : - MySpecularActivity = Standard_True; - break; - - case Graphic3d_TOR_EMISSION : - MyEmissiveActivity = Standard_True; - break; - } -#ifdef IMP171201 - if( MyMaterialType == Graphic3d_MATERIAL_PHYSIC ) - SetMaterialName("UserDefined"); -#endif + myEmissiveCoef = Standard_ShortReal (theValue); + if (myDiffuseActivity + && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -void Graphic3d_MaterialAspect::SetReflectionModeOff (const Graphic3d_TypeOfReflection AType) { - - switch (AType) { - - case Graphic3d_TOR_AMBIENT : - MyAmbientActivity = Standard_False; - break; - - case Graphic3d_TOR_DIFFUSE : - MyDiffuseActivity = Standard_False; - break; - - case Graphic3d_TOR_SPECULAR : - MySpecularActivity = Standard_False; - break; - - case Graphic3d_TOR_EMISSION : - MyEmissiveActivity = Standard_False; - break; - } -#ifdef IMP171201 - if( MyMaterialType == Graphic3d_MATERIAL_PHYSIC ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : SetReflectionModeOn +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetReflectionModeOn (const Graphic3d_TypeOfReflection theType) +{ + switch (theType) + { + case Graphic3d_TOR_AMBIENT: + myAmbientActivity = Standard_True; + break; + case Graphic3d_TOR_DIFFUSE: + myDiffuseActivity = Standard_True; + break; + case Graphic3d_TOR_SPECULAR: + mySpecularActivity = Standard_True; + break; + case Graphic3d_TOR_EMISSION: + myEmissiveActivity = Standard_True; + break; + } + if (myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -void Graphic3d_MaterialAspect::SetSpecular (const Standard_Real AValue) { - - if ((AValue < 0.0) || (AValue > 1.0)) - Graphic3d_MaterialDefinitionError::Raise - ("Bad value for SetSpecular < 0. or > 1.0"); - - - MySpecularCoef = Standard_ShortReal (AValue); -#ifndef BUC60565 - Standard_Real R, G, B; - MySpecularColor.Values (R, G, B, Quantity_TOC_RGB); - MySpecularColor.SetValues - (R*AValue, G*AValue, B*AValue, Quantity_TOC_RGB); -#endif -#ifdef IMP171201 - if( MySpecularActivity && - (MyMaterialType == Graphic3d_MATERIAL_PHYSIC) ) - SetMaterialName("UserDefined"); -#endif +// ======================================================================= +// function : SetReflectionModeOff +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetReflectionModeOff (const Graphic3d_TypeOfReflection theType) +{ + switch (theType) + { + case Graphic3d_TOR_AMBIENT: + myAmbientActivity = Standard_False; + break; + case Graphic3d_TOR_DIFFUSE: + myDiffuseActivity = Standard_False; + break; + case Graphic3d_TOR_SPECULAR: + mySpecularActivity = Standard_False; + break; + case Graphic3d_TOR_EMISSION: + myEmissiveActivity = Standard_False; + break; + } + if (myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } -void Graphic3d_MaterialAspect::SetTransparency (const Standard_Real AValue) { +// ======================================================================= +// function : SetSpecular +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetSpecular (const Standard_Real theValue) +{ + if (theValue < 0.0 + || theValue > 1.0) + { + Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetSpecular < 0. or > 1.0"); + } - if ((AValue < 0.0) || (AValue > 1.0)) - Graphic3d_MaterialDefinitionError::Raise - ("Bad value for SetTransparency < 0. or > 1.0"); - - MyTransparencyCoef = Standard_ShortReal (AValue); + mySpecularCoef = Standard_ShortReal (theValue); + if (mySpecularActivity + && myMaterialType == Graphic3d_MATERIAL_PHYSIC) + { + SetMaterialName ("UserDefined"); + } } +// ======================================================================= +// function : SetTransparency +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetTransparency (const Standard_Real theValue) +{ + if (theValue < 0.0 + || theValue > 1.0) + { + Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetTransparency < 0. or > 1.0"); + } + + myTransparencyCoef = Standard_ShortReal (theValue); +} + +// ======================================================================= +// function : SetRefractionIndex +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetRefractionIndex (const Standard_Real theValue) +{ + if (theValue < 1.0) + { + Graphic3d_MaterialDefinitionError::Raise ("Bad value for refraction index < 1.0"); + } + + myRefractionIndex = static_cast (theValue); +} + +// ======================================================================= +// function : Color +// purpose : +// ======================================================================= const Quantity_Color& Graphic3d_MaterialAspect::Color() const { - return MyAmbientColor; + return myAmbientColor; } +// ======================================================================= +// function : AmbientColor +// purpose : +// ======================================================================= const Quantity_Color& Graphic3d_MaterialAspect::AmbientColor() const { - return MyAmbientColor; + return myAmbientColor; } +// ======================================================================= +// function : DiffuseColor +// purpose : +// ======================================================================= const Quantity_Color& Graphic3d_MaterialAspect::DiffuseColor() const { - return MyDiffuseColor; + return myDiffuseColor; } +// ======================================================================= +// function : SpecularColor +// purpose : +// ======================================================================= const Quantity_Color& Graphic3d_MaterialAspect::SpecularColor() const { - return MySpecularColor; + return mySpecularColor; } +// ======================================================================= +// function : EmissiveColor +// purpose : +// ======================================================================= const Quantity_Color& Graphic3d_MaterialAspect::EmissiveColor() const { - return MyEmissiveColor; + return myEmissiveColor; } -/* Access to the type of material */ -Standard_Boolean Graphic3d_MaterialAspect::MaterialType( const Graphic3d_TypeOfMaterial AType ) const { - return ( MyMaterialType == AType ) ; -} - -Standard_Boolean Graphic3d_MaterialAspect::ReflectionMode (const Graphic3d_TypeOfReflection AType) const { - -Standard_Boolean Result; - - Result = Standard_False; - - switch (AType) { - - case Graphic3d_TOR_AMBIENT : - Result = MyAmbientActivity; - break; - - case Graphic3d_TOR_DIFFUSE : - Result = MyDiffuseActivity; - break; - - case Graphic3d_TOR_SPECULAR : - Result = MySpecularActivity; - break; - - case Graphic3d_TOR_EMISSION : - Result = MyEmissiveActivity; - break; - } - return (Result); - -} - -/* Access to the color of the ambient lighting */ -Standard_Real Graphic3d_MaterialAspect::Ambient () const { - - return (Standard_Real (MyAmbientCoef)); - -} - -/* Access to the color of the dispersed lighting */ -Standard_Real Graphic3d_MaterialAspect::Diffuse () const { - - return (Standard_Real (MyDiffuseCoef)); - -} - -/* Value of the coefficient of emission */ -Standard_Real Graphic3d_MaterialAspect::Emissive () const { - - return (Standard_Real (MyEmissiveCoef)); - -} - -/* Access to the color of the specular lighting */ -Standard_Real Graphic3d_MaterialAspect::Specular () const { - - return (Standard_Real (MySpecularCoef)); - -} - -/* Access to the coefficient of transparency */ -Standard_Real Graphic3d_MaterialAspect::Transparency () const { - - return (Standard_Real (MyTransparencyCoef)); - -} - -/* Access to the coefficient of shineness */ -Standard_Real Graphic3d_MaterialAspect::Shininess () const { - - return (Standard_Real (MyShininess)); - -} - -/* Attribution of the coefficient of shineness */ -void Graphic3d_MaterialAspect::SetShininess (const Standard_Real AValue) { - - if ((AValue < 0.0) || (AValue > 1.0)) - Graphic3d_MaterialDefinitionError::Raise - ("Bad value for Shininess < 0. or > 1.0"); - - MyShininess = Standard_ShortReal (AValue); -#ifdef IMP171201 - SetMaterialName("UserDefined"); -#endif -} - - -void Graphic3d_MaterialAspect::SetEnvReflexion(const Standard_ShortReal AValue) +// ======================================================================= +// function : MaterialType +// purpose : +// ======================================================================= +Standard_Boolean Graphic3d_MaterialAspect::MaterialType (const Graphic3d_TypeOfMaterial theType) const { - MyEnvReflexion = AValue; + return myMaterialType == theType; } +// ======================================================================= +// function : ReflectionMode +// purpose : +// ======================================================================= +Standard_Boolean Graphic3d_MaterialAspect::ReflectionMode (const Graphic3d_TypeOfReflection theType) const +{ + switch (theType) + { + case Graphic3d_TOR_AMBIENT: return myAmbientActivity; + case Graphic3d_TOR_DIFFUSE: return myDiffuseActivity; + case Graphic3d_TOR_SPECULAR: return mySpecularActivity; + case Graphic3d_TOR_EMISSION: return myEmissiveActivity; + } + return Standard_False; +} +// ======================================================================= +// function : Ambient +// purpose : +// ======================================================================= +Standard_Real Graphic3d_MaterialAspect::Ambient() const +{ + return Standard_Real (myAmbientCoef); +} + +// ======================================================================= +// function : Diffuse +// purpose : +// ======================================================================= +Standard_Real Graphic3d_MaterialAspect::Diffuse() const +{ + return Standard_Real (myDiffuseCoef); +} + +// ======================================================================= +// function : Emissive +// purpose : +// ======================================================================= +Standard_Real Graphic3d_MaterialAspect::Emissive() const +{ + return Standard_Real (myEmissiveCoef); +} + +// ======================================================================= +// function : Specular +// purpose : +// ======================================================================= +Standard_Real Graphic3d_MaterialAspect::Specular() const +{ + return Standard_Real (mySpecularCoef); +} + +// ======================================================================= +// function : Transparency +// purpose : +// ======================================================================= +Standard_Real Graphic3d_MaterialAspect::Transparency() const +{ + return Standard_Real (myTransparencyCoef); +} + +// ======================================================================= +// function : RefractionIndex +// purpose : +// ======================================================================= +Standard_Real Graphic3d_MaterialAspect::RefractionIndex() const +{ + return myRefractionIndex; +} + +// ======================================================================= +// function : Shininess +// purpose : +// ======================================================================= +Standard_Real Graphic3d_MaterialAspect::Shininess() const +{ + return Standard_Real (myShininess); +} + +// ======================================================================= +// function : SetShininess +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetShininess (const Standard_Real theValue) +{ + if (theValue < 0.0 + || theValue > 1.0) + { + Graphic3d_MaterialDefinitionError::Raise ("Bad value for Shininess < 0. or > 1.0"); + } + + myShininess = Standard_ShortReal (theValue); + SetMaterialName ("UserDefined"); +} + +// ======================================================================= +// function : SetEnvReflexion +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetEnvReflexion (const Standard_ShortReal theValue) +{ + myEnvReflexion = theValue; +} + +// ======================================================================= +// function : EnvReflexion +// purpose : +// ======================================================================= Standard_ShortReal Graphic3d_MaterialAspect::EnvReflexion() const { - return MyEnvReflexion; + return myEnvReflexion; } +// ======================================================================= +// function : Name +// purpose : +// ======================================================================= Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::Name() const { - return MyMaterialName; + return myMaterialName; } -void Graphic3d_MaterialAspect::Reset() { -#ifdef IMP171201 - Init(MyRequestedMaterialName); -#else - Init(MyMaterialName); -#endif +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::Reset() +{ + Init (myRequestedMaterialName); } -#ifdef IMP150200 -Standard_Boolean Graphic3d_MaterialAspect::IsEqual(const Graphic3d_MaterialAspect& other) const { - - if( MyAmbientCoef == other.Ambient() && - MyDiffuseCoef == other.Diffuse() && - MySpecularCoef == other.Specular() && - MyEmissiveCoef == other.Emissive() && - MyTransparencyCoef == other.Transparency() && - MyShininess == other.Shininess() && - MyEnvReflexion == other.EnvReflexion() && - MyAmbientColor == other.AmbientColor() && - MyDiffuseColor == other.DiffuseColor() && - MySpecularColor == other.SpecularColor() && - MyEmissiveColor == other.EmissiveColor() && - MyAmbientActivity == other.ReflectionMode(Graphic3d_TOR_AMBIENT) && - MyDiffuseActivity == other.ReflectionMode(Graphic3d_TOR_DIFFUSE) && - MySpecularActivity == other.ReflectionMode(Graphic3d_TOR_SPECULAR) && - MyEmissiveActivity == other.ReflectionMode(Graphic3d_TOR_EMISSION) ) - return Standard_True; - - return Standard_False; +// ======================================================================= +// function : IsEqual +// purpose : +// ======================================================================= +Standard_Boolean Graphic3d_MaterialAspect::IsEqual (const Graphic3d_MaterialAspect& theOther) const +{ + return myAmbientCoef == theOther.myAmbientCoef + && myDiffuseCoef == theOther.myDiffuseCoef + && mySpecularCoef == theOther.mySpecularCoef + && myEmissiveCoef == theOther.myEmissiveCoef + && myTransparencyCoef == theOther.myTransparencyCoef + && myRefractionIndex == theOther.myRefractionIndex + && myShininess == theOther.myShininess + && myEnvReflexion == theOther.myEnvReflexion + && myAmbientColor == theOther.myAmbientColor + && myDiffuseColor == theOther.myDiffuseColor + && mySpecularColor == theOther.mySpecularColor + && myEmissiveColor == theOther.myEmissiveColor + && myAmbientActivity == theOther.myAmbientActivity + && myDiffuseActivity == theOther.myDiffuseActivity + && mySpecularActivity == theOther.mySpecularActivity + && myEmissiveActivity == theOther.myEmissiveActivity; } -Standard_Boolean Graphic3d_MaterialAspect::IsDifferent(const Graphic3d_MaterialAspect& other) const { - - return !IsEqual(other); +// ======================================================================= +// function : IsDifferent +// purpose : +// ======================================================================= +Standard_Boolean Graphic3d_MaterialAspect::IsDifferent (const Graphic3d_MaterialAspect& theOther) const +{ + return !IsEqual (theOther); } -typedef struct _Material { - const char* name; +typedef struct _Material +{ + const char* name; Graphic3d_TypeOfMaterial type; } Material; -static Material theMaterials[] = { - {"Brass",Graphic3d_MATERIAL_PHYSIC}, - {"Bronze",Graphic3d_MATERIAL_PHYSIC}, - {"Copper",Graphic3d_MATERIAL_PHYSIC}, - {"Gold",Graphic3d_MATERIAL_PHYSIC}, - {"Pewter",Graphic3d_MATERIAL_PHYSIC}, - {"Plastered",Graphic3d_MATERIAL_ASPECT}, - {"Plastified",Graphic3d_MATERIAL_ASPECT}, - {"Silver",Graphic3d_MATERIAL_PHYSIC}, - {"Steel",Graphic3d_MATERIAL_PHYSIC}, - {"Stone",Graphic3d_MATERIAL_PHYSIC}, - {"Shiny_plastified",Graphic3d_MATERIAL_ASPECT}, - {"Satined",Graphic3d_MATERIAL_ASPECT}, - {"Metalized",Graphic3d_MATERIAL_ASPECT}, - {"Ionized",Graphic3d_MATERIAL_ASPECT}, - {"Chrome",Graphic3d_MATERIAL_PHYSIC}, - {"Aluminium",Graphic3d_MATERIAL_PHYSIC}, - {"Obsidian",Graphic3d_MATERIAL_PHYSIC}, - {"Neon",Graphic3d_MATERIAL_PHYSIC}, - {"Jade",Graphic3d_MATERIAL_PHYSIC} +static Material theMaterials[] = +{ + {"Brass", Graphic3d_MATERIAL_PHYSIC}, + {"Bronze", Graphic3d_MATERIAL_PHYSIC}, + {"Copper", Graphic3d_MATERIAL_PHYSIC}, + {"Gold", Graphic3d_MATERIAL_PHYSIC}, + {"Pewter", Graphic3d_MATERIAL_PHYSIC}, + {"Plastered", Graphic3d_MATERIAL_ASPECT}, + {"Plastified", Graphic3d_MATERIAL_ASPECT}, + {"Silver", Graphic3d_MATERIAL_PHYSIC}, + {"Steel", Graphic3d_MATERIAL_PHYSIC}, + {"Stone", Graphic3d_MATERIAL_PHYSIC}, + {"Shiny_plastified", Graphic3d_MATERIAL_ASPECT}, + {"Satined", Graphic3d_MATERIAL_ASPECT}, + {"Metalized", Graphic3d_MATERIAL_ASPECT}, + {"Ionized", Graphic3d_MATERIAL_ASPECT}, + {"Chrome", Graphic3d_MATERIAL_PHYSIC}, + {"Aluminium", Graphic3d_MATERIAL_PHYSIC}, + {"Obsidian", Graphic3d_MATERIAL_PHYSIC}, + {"Neon", Graphic3d_MATERIAL_PHYSIC}, + {"Jade", Graphic3d_MATERIAL_PHYSIC}, + {"Charcoal", Graphic3d_MATERIAL_PHYSIC}, + {"Water", Graphic3d_MATERIAL_PHYSIC}, + {"Glass", Graphic3d_MATERIAL_PHYSIC}, + {"Diamond", Graphic3d_MATERIAL_PHYSIC} + }; -Standard_Integer Graphic3d_MaterialAspect::NumberOfMaterials() { +// ======================================================================= +// function : NumberOfMaterials +// purpose : +// ======================================================================= +Standard_Integer Graphic3d_MaterialAspect::NumberOfMaterials() +{ Standard_STATIC_ASSERT(sizeof(theMaterials)/sizeof(Material) == Graphic3d_NOM_DEFAULT); - return Graphic3d_NOM_DEFAULT; } -Standard_CString Graphic3d_MaterialAspect::MaterialName(const Standard_Integer aRank) { - - if( aRank < 1 || aRank > NumberOfMaterials() ) - Standard_OutOfRange::Raise(" BAD index of material"); - - return theMaterials[aRank-1].name; +// ======================================================================= +// function : MaterialName +// purpose : +// ======================================================================= +Standard_CString Graphic3d_MaterialAspect::MaterialName (const Standard_Integer theRank) +{ + if (theRank < 1 || theRank > NumberOfMaterials()) + { + Standard_OutOfRange::Raise ("BAD index of material"); + } + return theMaterials[theRank - 1].name; } +// ======================================================================= +// function : MaterialFromName +// purpose : +// ======================================================================= Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::MaterialFromName (const Standard_CString theName) { TCollection_AsciiString aName (theName); @@ -939,25 +983,36 @@ Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::MaterialFromName (const Stand return Graphic3d_NOM_DEFAULT; } -Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType(const Standard_Integer aRank) { - - if( aRank < 1 || aRank > NumberOfMaterials() ) - Standard_OutOfRange::Raise(" BAD index of material"); - - return theMaterials[aRank-1].type; +// ======================================================================= +// function : MaterialType +// purpose : +// ======================================================================= +Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType (const Standard_Integer theRank) +{ + if (theRank < 1 || theRank > NumberOfMaterials()) + { + Standard_OutOfRange::Raise ("BAD index of material"); + } + return theMaterials[theRank - 1].type; } -#endif -#ifdef IMP171201 +// ======================================================================= +// function : MaterialName +// purpose : +// ======================================================================= Standard_CString Graphic3d_MaterialAspect::MaterialName() const { - return MyStringName.ToCString(); + return myStringName.ToCString(); } -void Graphic3d_MaterialAspect::SetMaterialName(const Standard_CString aNewName) + +// ======================================================================= +// function : SetMaterialName +// purpose : +// ======================================================================= +void Graphic3d_MaterialAspect::SetMaterialName (const Standard_CString theNewName) { -// if a component of a "standard" material change, the -// result is no more standard ( a blue gold is not a gold ) - MyMaterialName = Graphic3d_NOM_UserDefined; - MyStringName = aNewName; + // if a component of a "standard" material change, the + // result is no more standard (a blue gold is not a gold) + myMaterialName = Graphic3d_NOM_UserDefined; + myStringName = theNewName; } -#endif diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index fafc64c2b2..a2fda6b64a 100644 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -1034,12 +1034,13 @@ void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFill // Back Material const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial(); // Light specificity - myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess()); - myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient()); - myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse()); - myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular()); - myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency()); - myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive()); + myCStructure->ContextFillArea.Back.Shininess = float (aBack.Shininess()); + myCStructure->ContextFillArea.Back.Ambient = float (aBack.Ambient()); + myCStructure->ContextFillArea.Back.Diffuse = float (aBack.Diffuse()); + myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular()); + myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency()); + myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex()); + myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive()); // Reflection mode myCStructure->ContextFillArea.Back.IsAmbient = (aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0); @@ -1077,12 +1078,13 @@ void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFill // Front Material const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial(); // Light specificity - myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess()); - myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient()); - myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse()); - myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular()); - myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency()); - myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive()); + myCStructure->ContextFillArea.Front.Shininess = float (aFront.Shininess()); + myCStructure->ContextFillArea.Front.Ambient = float (aFront.Ambient()); + myCStructure->ContextFillArea.Front.Diffuse = float (aFront.Diffuse()); + myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular()); + myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency()); + myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex()); + myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive()); // Reflection mode myCStructure->ContextFillArea.Front.IsAmbient = (aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0); diff --git a/src/InterfaceGraphic/InterfaceGraphic_Graphic3d.hxx b/src/InterfaceGraphic/InterfaceGraphic_Graphic3d.hxx index 525e082dba..950197a3ab 100644 --- a/src/InterfaceGraphic/InterfaceGraphic_Graphic3d.hxx +++ b/src/InterfaceGraphic/InterfaceGraphic_Graphic3d.hxx @@ -62,8 +62,9 @@ typedef struct { float Emission; int IsEmission; - float Transparency; float Shininess; + float Transparency; + float RefractionIndex; float EnvReflexion; diff --git a/src/OpenGl/OpenGl_AspectFace.cxx b/src/OpenGl/OpenGl_AspectFace.cxx index 3dc873319e..5807916981 100644 --- a/src/OpenGl/OpenGl_AspectFace.cxx +++ b/src/OpenGl/OpenGl_AspectFace.cxx @@ -33,7 +33,7 @@ namespace static OPENGL_SURF_PROP THE_DEFAULT_MATERIAL = { 0.2F, 0.8F, 0.1F, 0.0F, // amb, diff, spec, emsv - 1.0F, 10.0F, 0.0F, // trans, shine, env_reflexion + 1.0F, 10.0F, 1.0F, 0.0F, // trans, shine, index, env_reflexion 0, // isphysic (OPENGL_AMBIENT_MASK | OPENGL_DIFFUSE_MASK | OPENGL_SPECULAR_MASK), // color_mask {{ 1.0F, 1.0F, 1.0F, 1.0F }}, // ambient color @@ -110,6 +110,7 @@ void OpenGl_AspectFace::convertMaterial (const CALL_DEF_MATERIAL& theMat, // trans = 1. => transparent // in OpenGl it is opposite. theSurf.trans = 1.0f - theMat.Transparency; + theSurf.index = theMat.RefractionIndex; } // ======================================================================= diff --git a/src/OpenGl/OpenGl_AspectFace.hxx b/src/OpenGl/OpenGl_AspectFace.hxx index 2843fcbe75..109282f6c1 100644 --- a/src/OpenGl/OpenGl_AspectFace.hxx +++ b/src/OpenGl/OpenGl_AspectFace.hxx @@ -42,7 +42,7 @@ static const TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0. struct OPENGL_SURF_PROP { float amb, diff, spec, emsv; - float trans, shine; + float trans, shine, index; float env_reflexion; int isphysic; unsigned int color_mask; diff --git a/tests/bugs/demo/bug23410 b/tests/bugs/demo/bug23410 index 87393c8e62..d15b8fb67a 100755 --- a/tests/bugs/demo/bug23410 +++ b/tests/bugs/demo/bug23410 @@ -16,7 +16,7 @@ vsetdispmode 1 vfit vsetcolor result GREEN -checkcolor $x_coord $y_coord 0.45 0.95 0.05 +checkcolor $x_coord $y_coord 0.00 0.83 0.00 set 3dviewer 1 diff --git a/tests/bugs/vis/bug22879 b/tests/bugs/vis/bug22879 index 6bbcfca1bf..1af9dada4e 100755 --- a/tests/bugs/vis/bug22879 +++ b/tests/bugs/vis/bug22879 @@ -22,14 +22,14 @@ vdisplay b vsetdispmode 1 vsetcolor b ANTIQUEWHITE -checkcolor 24 55 0.75686198472976685 0 0 -checkcolor 16 76 0 0 0.50195999999999996 -checkcolor 26 107 0.18039199709892273 0.5686269998550415 0.180392 -checkcolor 34 114 0.29803898930549622 0.29803898930549622 0.298039 -checkcolor 24 131 0.61960697174072266 0 0 -checkcolor 18 139 0.21568599343299866 0 0.78431300000000004 -checkcolor 56 160 1 0 0 -checkcolor 30 160 0 1 0.90980300000000003 +checkcolor 24 55 0.753 0.000 0.000 +checkcolor 16 76 0.000 0.000 1.000 +checkcolor 25 107 0.000 1.000 0.000 +checkcolor 34 114 0.298 0.298 0.298 +checkcolor 24 131 0.922 0.000 0.000 +checkcolor 18 139 0.145 0.000 0.855 +checkcolor 56 160 1.000 0.000 0.000 +checkcolor 30 160 0.188 0.761 0.698 set only_screen 1 diff --git a/tests/bugs/vis/bug22912 b/tests/bugs/vis/bug22912 index 58b87e1516..4787f001cf 100644 --- a/tests/bugs/vis/bug22912 +++ b/tests/bugs/vis/bug22912 @@ -23,8 +23,8 @@ vsetcolor p_2 green vsettransparency p_1 0.5 vsettransparency p_1 0 -checkcolor 120 150 1 0.3 0.06 -checkcolor 180 273 0.39 1 0.058 +checkcolor 120 150 0.831 0.000 0.000 +checkcolor 180 273 0.000 0.753 0.000 set only_screen 1 diff --git a/tests/bugs/vis/bug24762_coloredshape b/tests/bugs/vis/bug24762_coloredshape index c126609666..afdcc4ded7 100644 --- a/tests/bugs/vis/bug24762_coloredshape +++ b/tests/bugs/vis/bug24762_coloredshape @@ -43,6 +43,6 @@ if {"$aWireColor" != "HOTPINK"} { if {"$anEdgeColor" != "RED"} { puts "Error: wrong Edge color" } -if {"$aFaceColor" != "LEMONCHIFFON1"} { +if {"$aFaceColor" != "GRAY62"} { puts "Error: wrong Face color" } diff --git a/tests/bugs/vis/bug5990 b/tests/bugs/vis/bug5990 index 2529ffdfa9..9bc462d48a 100755 --- a/tests/bugs/vis/bug5990 +++ b/tests/bugs/vis/bug5990 @@ -15,13 +15,13 @@ set y2 269 set x3 348 set y3 238 -set KUB_R 0.45098000764846802 -set KUB_G 0.32941100001335144 -set KUB_B 1 +set KUB_R 0.00 +set KUB_G 0.00 +set KUB_B 0.83 -set LINE_R 0 -set LINE_G 0 -set LINE_B 1 +set LINE_R 0.00 +set LINE_G 0.00 +set LINE_B 1.00 box b1 10 10 10 diff --git a/tests/v3d/grids.list b/tests/v3d/grids.list index 972d658298..1e5671dff9 100644 --- a/tests/v3d/grids.list +++ b/tests/v3d/grids.list @@ -12,3 +12,4 @@ 012 voxel 013 glsl 014 raytrace +015 materials diff --git a/tests/v3d/materials/bug24855 b/tests/v3d/materials/bug24855 new file mode 100644 index 0000000000..8b6a7eadf4 --- /dev/null +++ b/tests/v3d/materials/bug24855 @@ -0,0 +1,43 @@ +puts "========" +puts "OCC24855: Revision of parameters of standard materials" +puts "========" + +# custom shapes +set aShape [locate_data_file occ/Top.brep] + +# setup 3D viewer content +vinit View1 w=768 h=768 +vglinfo + +vsetgradientbg 180 200 255 180 180 180 2 + +# display shape +vlight change 0 pos -1 1 1 +restore $aShape s +vsetdispmode 1 +vdisplay s +vfit + +proc testmat {dirname filename} { + foreach {aMatIter} {brass bronze copper gold jade neon_phc pewter obsidian plaster plastic satin silver steel stone chrome aluminium charcoal} { + vsetmaterial -noredraw s $aMatIter + vdump $dirname/${filename}_${aMatIter}.png + } +} + +# make material screenshots +testmat $imagedir $casename + +vshaderprog s phong +testmat $imagedir ${casename}_phong + +vraytrace 1 +vtextureenv on 5 +vsetraytracemode aa=1 refl=1 + +testmat $imagedir ${casename}_rt + +vclear +vraytrace 0 +vtextureenv off +source $env(CASROOT)/samples/tcl/materials.tcl