1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and / or modify it
6 // under the terms of the GNU Lesser General Public version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Vrml_Material.ixx>
16 Vrml_Material::Vrml_Material(const Handle(Quantity_HArray1OfColor)& aAmbientColor,
17 const Handle(Quantity_HArray1OfColor)& aDiffuseColor,
18 const Handle(Quantity_HArray1OfColor)& aSpecularColor,
19 const Handle(Quantity_HArray1OfColor)& aEmissiveColor,
20 const Handle(TColStd_HArray1OfReal)& aShininess,
21 const Handle(TColStd_HArray1OfReal)& aTransparency)
23 myAmbientColor = aAmbientColor;
24 myDiffuseColor = aDiffuseColor;
25 mySpecularColor = aSpecularColor;
26 myEmissiveColor = aEmissiveColor;
29 for ( i = aShininess->Lower(); i <= aShininess->Upper(); i++ )
31 if (aShininess->Value(i) < 0. || aShininess->Value(i) > 1.)
33 Standard_Failure::Raise("The value of aShininess is out of range (0 - 1)");
36 myShininess = aShininess;
38 for ( i = aTransparency->Lower(); i <= aTransparency->Upper(); i++ )
40 if (aTransparency->Value(i) < 0. || aTransparency->Value(i) > 1.)
42 Standard_Failure::Raise("The value of aTransparency is out of range (0 - 1)");
45 myTransparency = aTransparency;
48 Vrml_Material::Vrml_Material()
50 Quantity_Color tmpcolor;
51 // myAmbientColor = new Quantity_HArray1OfColor(1,1);
52 tmpcolor.SetValues(0.2, 0.2, 0.2, Quantity_TOC_RGB);
53 myAmbientColor = new Quantity_HArray1OfColor(1,1,tmpcolor);
54 // myAmbientColor->SetValue(1, tmpcolor);
55 // myDiffuseColor = new Quantity_HArray1OfColor(1,1);
56 tmpcolor.SetValues(0.8, 0.8, 0.8, Quantity_TOC_RGB);
57 myDiffuseColor = new Quantity_HArray1OfColor(1,1,tmpcolor);
58 // myDiffuseColor->SetValue(1, tmpcolor);
59 mySpecularColor = new Quantity_HArray1OfColor(1,1);
60 tmpcolor.SetValues(0, 0, 0, Quantity_TOC_RGB);
61 mySpecularColor->SetValue(1, tmpcolor);
62 myEmissiveColor = new Quantity_HArray1OfColor(1,1);
63 tmpcolor.SetValues(0, 0, 0, Quantity_TOC_RGB);
64 myEmissiveColor->SetValue(1, tmpcolor);
66 myShininess = new TColStd_HArray1OfReal (1,1,0.2);
67 myTransparency = new TColStd_HArray1OfReal (1,1,0);
70 void Vrml_Material::SetAmbientColor(const Handle(Quantity_HArray1OfColor)& aAmbientColor)
72 myAmbientColor = aAmbientColor;
75 Handle(Quantity_HArray1OfColor) Vrml_Material::AmbientColor() const
77 return myAmbientColor;
80 void Vrml_Material::SetDiffuseColor(const Handle(Quantity_HArray1OfColor)& aDiffuseColor)
82 myDiffuseColor = aDiffuseColor;
85 Handle(Quantity_HArray1OfColor) Vrml_Material::DiffuseColor() const
87 return myDiffuseColor;
90 void Vrml_Material::SetSpecularColor(const Handle(Quantity_HArray1OfColor)& aSpecularColor)
92 mySpecularColor = aSpecularColor;
95 Handle(Quantity_HArray1OfColor) Vrml_Material::SpecularColor() const
97 return mySpecularColor;
100 void Vrml_Material::SetEmissiveColor(const Handle(Quantity_HArray1OfColor)& aEmissiveColor)
102 myEmissiveColor = aEmissiveColor;
105 Handle(Quantity_HArray1OfColor) Vrml_Material::EmissiveColor() const
107 return myEmissiveColor;
110 void Vrml_Material::SetShininess(const Handle(TColStd_HArray1OfReal)& aShininess)
113 for ( i = aShininess->Lower(); i <= aShininess->Upper(); i++ )
115 if (aShininess->Value(i) < 0. || aShininess->Value(i) > 1.)
117 Standard_Failure::Raise("The value of aShininess is out of range (0 - 1)");
120 myShininess = aShininess;
123 Handle(TColStd_HArray1OfReal) Vrml_Material::Shininess() const
128 void Vrml_Material::SetTransparency(const Handle(TColStd_HArray1OfReal)& aTransparency)
131 for ( i = aTransparency->Lower(); i <= aTransparency->Upper(); i++ )
133 if (aTransparency->Value(i) < 0. || aTransparency->Value(i) > 1.)
135 Standard_Failure::Raise("The value of aTransparency is out of range (0 - 1)");
138 myTransparency = aTransparency;
141 Handle(TColStd_HArray1OfReal) Vrml_Material::Transparency() const
143 return myTransparency;
146 Standard_OStream& Vrml_Material::Print(Standard_OStream& anOStream) const
149 anOStream << "Material {" << endl;
151 if ( myAmbientColor->Length() != 1 ||
152 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Red() - 0.2) > 0.0001 ||
153 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Green() - 0.2) > 0.0001 ||
154 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Blue() - 0.2) > 0.0001 )
156 anOStream << " ambientColor [\n\t";
157 for ( i = myAmbientColor->Lower(); i <= myAmbientColor->Upper(); i++ )
159 anOStream << myAmbientColor->Value(i).Red() << ' ' << myAmbientColor->Value(i).Green() << ' ' << myAmbientColor->Value(i).Blue();
160 if ( i < myAmbientColor->Length() )
161 anOStream << ',' << endl << '\t'; // ,,,,,,,,,,
163 anOStream << " ]" << endl;
166 if ( myDiffuseColor->Length() != 1 ||
167 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Red() - 0.8) > 0.0001 ||
168 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Green() - 0.8) > 0.0001 ||
169 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Blue() - 0.8) > 0.0001 )
171 anOStream << " diffuseColor [\n\t";
172 for ( i = myDiffuseColor->Lower(); i <= myDiffuseColor->Upper(); i++ )
174 anOStream << myDiffuseColor->Value(i).Red() << ' ' << myDiffuseColor->Value(i).Green() << ' ' << myDiffuseColor->Value(i).Blue();
175 if ( i < myDiffuseColor->Length() )
176 anOStream << ',' << endl << '\t';
178 anOStream << " ]" << endl;
181 if ( mySpecularColor->Length() != 1 ||
182 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Red() - 0) > 0.0001 ||
183 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Green() - 0) > 0.0001 ||
184 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Blue() - 0) > 0.0001 )
186 anOStream << " specularColor [\n\t";
187 for ( i = mySpecularColor->Lower(); i <= mySpecularColor->Upper(); i++ )
189 anOStream << mySpecularColor->Value(i).Red() << ' ' << mySpecularColor->Value(i).Green() << ' ' << mySpecularColor->Value(i).Blue();
190 if ( i < mySpecularColor->Length() )
191 anOStream << ',' << endl << "\t";
193 anOStream << " ]" << endl;
196 if ( myEmissiveColor->Length() != 1 ||
197 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Red() - 0) > 0.0001 ||
198 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Green() - 0) > 0.0001 ||
199 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Blue() - 0) > 0.0001 )
201 anOStream << " emissiveColor [\n\t";
202 for ( i = myEmissiveColor->Lower(); i <= myEmissiveColor->Upper(); i++ )
204 anOStream << myEmissiveColor->Value(i).Red() << ' ' << myEmissiveColor->Value(i).Green() << ' ' << myEmissiveColor->Value(i).Blue();
205 if ( i < myEmissiveColor->Length() )
206 anOStream << ',' << endl << "\t";
208 anOStream << " ]" << endl;
211 if ( myShininess->Length() != 1 || Abs(myShininess->Value(myShininess->Lower()) - 0.2) > 0.0001 )
213 anOStream << " shininess\t\t[ ";
214 for ( i = myShininess->Lower(); i <= myShininess->Upper(); i++ )
216 anOStream << myShininess->Value(i);
217 if ( i < myShininess->Length() )
220 anOStream << " ]" << endl;
223 if ( myTransparency->Length() != 1 || Abs(myTransparency->Value(myTransparency->Lower()) - 0) > 0.0001 )
225 anOStream << " transparency\t[ ";
226 for ( i = myTransparency->Lower(); i <= myTransparency->Upper(); i++ )
228 anOStream << myTransparency->Value(i);
229 if ( i < myTransparency->Length() )
232 anOStream << " ]" << endl;
234 anOStream << '}' << endl;