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 under
6 // the terms of the GNU Lesser General Public License 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.
15 #include <Standard_Type.hxx>
16 #include <Vrml_Material.hxx>
18 IMPLEMENT_STANDARD_RTTIEXT(Vrml_Material,Standard_Transient)
20 Vrml_Material::Vrml_Material(const Handle(Quantity_HArray1OfColor)& aAmbientColor,
21 const Handle(Quantity_HArray1OfColor)& aDiffuseColor,
22 const Handle(Quantity_HArray1OfColor)& aSpecularColor,
23 const Handle(Quantity_HArray1OfColor)& aEmissiveColor,
24 const Handle(TColStd_HArray1OfReal)& aShininess,
25 const Handle(TColStd_HArray1OfReal)& aTransparency)
27 myAmbientColor = aAmbientColor;
28 myDiffuseColor = aDiffuseColor;
29 mySpecularColor = aSpecularColor;
30 myEmissiveColor = aEmissiveColor;
33 for ( i = aShininess->Lower(); i <= aShininess->Upper(); i++ )
35 if (aShininess->Value(i) < 0. || aShininess->Value(i) > 1.)
37 throw Standard_Failure("The value of aShininess is out of range (0 - 1)");
40 myShininess = aShininess;
42 for ( i = aTransparency->Lower(); i <= aTransparency->Upper(); i++ )
44 if (aTransparency->Value(i) < 0. || aTransparency->Value(i) > 1.)
46 throw Standard_Failure("The value of aTransparency is out of range (0 - 1)");
49 myTransparency = aTransparency;
52 Vrml_Material::Vrml_Material()
54 Quantity_Color tmpcolor;
55 // myAmbientColor = new Quantity_HArray1OfColor(1,1);
56 tmpcolor.SetValues(0.2, 0.2, 0.2, Quantity_TOC_RGB);
57 myAmbientColor = new Quantity_HArray1OfColor(1,1,tmpcolor);
58 // myAmbientColor->SetValue(1, tmpcolor);
59 // myDiffuseColor = new Quantity_HArray1OfColor(1,1);
60 tmpcolor.SetValues(0.8, 0.8, 0.8, Quantity_TOC_RGB);
61 myDiffuseColor = new Quantity_HArray1OfColor(1,1,tmpcolor);
62 // myDiffuseColor->SetValue(1, tmpcolor);
63 mySpecularColor = new Quantity_HArray1OfColor(1,1);
64 tmpcolor.SetValues(0, 0, 0, Quantity_TOC_RGB);
65 mySpecularColor->SetValue(1, tmpcolor);
66 myEmissiveColor = new Quantity_HArray1OfColor(1,1);
67 tmpcolor.SetValues(0, 0, 0, Quantity_TOC_RGB);
68 myEmissiveColor->SetValue(1, tmpcolor);
70 myShininess = new TColStd_HArray1OfReal (1,1,0.2);
71 myTransparency = new TColStd_HArray1OfReal (1,1,0);
74 void Vrml_Material::SetAmbientColor(const Handle(Quantity_HArray1OfColor)& aAmbientColor)
76 myAmbientColor = aAmbientColor;
79 Handle(Quantity_HArray1OfColor) Vrml_Material::AmbientColor() const
81 return myAmbientColor;
84 void Vrml_Material::SetDiffuseColor(const Handle(Quantity_HArray1OfColor)& aDiffuseColor)
86 myDiffuseColor = aDiffuseColor;
89 Handle(Quantity_HArray1OfColor) Vrml_Material::DiffuseColor() const
91 return myDiffuseColor;
94 void Vrml_Material::SetSpecularColor(const Handle(Quantity_HArray1OfColor)& aSpecularColor)
96 mySpecularColor = aSpecularColor;
99 Handle(Quantity_HArray1OfColor) Vrml_Material::SpecularColor() const
101 return mySpecularColor;
104 void Vrml_Material::SetEmissiveColor(const Handle(Quantity_HArray1OfColor)& aEmissiveColor)
106 myEmissiveColor = aEmissiveColor;
109 Handle(Quantity_HArray1OfColor) Vrml_Material::EmissiveColor() const
111 return myEmissiveColor;
114 void Vrml_Material::SetShininess(const Handle(TColStd_HArray1OfReal)& aShininess)
117 for ( i = aShininess->Lower(); i <= aShininess->Upper(); i++ )
119 if (aShininess->Value(i) < 0. || aShininess->Value(i) > 1.)
121 throw Standard_Failure("The value of aShininess is out of range (0 - 1)");
124 myShininess = aShininess;
127 Handle(TColStd_HArray1OfReal) Vrml_Material::Shininess() const
132 void Vrml_Material::SetTransparency(const Handle(TColStd_HArray1OfReal)& aTransparency)
135 for ( i = aTransparency->Lower(); i <= aTransparency->Upper(); i++ )
137 if (aTransparency->Value(i) < 0. || aTransparency->Value(i) > 1.)
139 throw Standard_Failure("The value of aTransparency is out of range (0 - 1)");
142 myTransparency = aTransparency;
145 Handle(TColStd_HArray1OfReal) Vrml_Material::Transparency() const
147 return myTransparency;
150 Standard_OStream& Vrml_Material::Print(Standard_OStream& anOStream) const
153 anOStream << "Material {\n";
155 if ( myAmbientColor->Length() != 1 ||
156 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Red() - 0.2) > 0.0001 ||
157 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Green() - 0.2) > 0.0001 ||
158 Abs(myAmbientColor->Value(myAmbientColor->Lower()).Blue() - 0.2) > 0.0001 )
160 anOStream << " ambientColor [\n\t";
161 for ( i = myAmbientColor->Lower(); i <= myAmbientColor->Upper(); i++ )
163 anOStream << myAmbientColor->Value(i).Red() << ' ' << myAmbientColor->Value(i).Green() << ' ' << myAmbientColor->Value(i).Blue();
164 if ( i < myAmbientColor->Length() )
165 anOStream << ",\n\t"; // ,,,,,,,,,,
170 if ( myDiffuseColor->Length() != 1 ||
171 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Red() - 0.8) > 0.0001 ||
172 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Green() - 0.8) > 0.0001 ||
173 Abs(myDiffuseColor->Value(myDiffuseColor->Lower()).Blue() - 0.8) > 0.0001 )
175 anOStream << " diffuseColor [\n\t";
176 for ( i = myDiffuseColor->Lower(); i <= myDiffuseColor->Upper(); i++ )
178 anOStream << myDiffuseColor->Value(i).Red() << ' ' << myDiffuseColor->Value(i).Green() << ' ' << myDiffuseColor->Value(i).Blue();
179 if ( i < myDiffuseColor->Length() )
180 anOStream << ",\n\t";
185 if ( mySpecularColor->Length() != 1 ||
186 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Red() - 0) > 0.0001 ||
187 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Green() - 0) > 0.0001 ||
188 Abs(mySpecularColor->Value(mySpecularColor->Lower()).Blue() - 0) > 0.0001 )
190 anOStream << " specularColor [\n\t";
191 for ( i = mySpecularColor->Lower(); i <= mySpecularColor->Upper(); i++ )
193 anOStream << mySpecularColor->Value(i).Red() << ' ' << mySpecularColor->Value(i).Green() << ' ' << mySpecularColor->Value(i).Blue();
194 if ( i < mySpecularColor->Length() )
195 anOStream << ",\n\t";
200 if ( myEmissiveColor->Length() != 1 ||
201 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Red() - 0) > 0.0001 ||
202 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Green() - 0) > 0.0001 ||
203 Abs(myEmissiveColor->Value(myEmissiveColor->Lower()).Blue() - 0) > 0.0001 )
205 anOStream << " emissiveColor [\n\t";
206 for ( i = myEmissiveColor->Lower(); i <= myEmissiveColor->Upper(); i++ )
208 anOStream << myEmissiveColor->Value(i).Red() << ' ' << myEmissiveColor->Value(i).Green() << ' ' << myEmissiveColor->Value(i).Blue();
209 if ( i < myEmissiveColor->Length() )
210 anOStream << ",\n\t";
215 if ( myShininess->Length() != 1 || Abs(myShininess->Value(myShininess->Lower()) - 0.2) > 0.0001 )
217 anOStream << " shininess\t\t[ ";
218 for ( i = myShininess->Lower(); i <= myShininess->Upper(); i++ )
220 anOStream << myShininess->Value(i);
221 if ( i < myShininess->Length() )
227 if ( myTransparency->Length() != 1 || Abs(myTransparency->Value(myTransparency->Lower()) - 0) > 0.0001 )
229 anOStream << " transparency\t[ ";
230 for ( i = myTransparency->Lower(); i <= myTransparency->Upper(); i++ )
232 anOStream << myTransparency->Value(i);
233 if ( i < myTransparency->Length() )