common/Material.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17#ifndef GAZEBO_COMMON_MATERIAL_HH_
18#define GAZEBO_COMMON_MATERIAL_HH_
19
20#include <string>
21#include <iostream>
22#include <ignition/math/Color.hh>
23#include "gazebo/util/system.hh"
24
25namespace gazebo
26{
27 namespace common
28 {
31
34 class GZ_COMMON_VISIBLE Material
35 {
36 public: enum ShadeMode {FLAT, GOURAUD, PHONG, BLINN, SHADE_COUNT};
37 public: static std::string ShadeModeStr[SHADE_COUNT];
38
39 public: enum BlendMode {ADD, MODULATE, REPLACE, BLEND_COUNT};
40 public: static std::string BlendModeStr[BLEND_COUNT];
41
43 public: Material();
44
46 public: virtual ~Material();
47
50 public: explicit Material(const ignition::math::Color &_clr);
51
54 public: std::string GetName() const;
55
59 public: void SetTextureImage(const std::string &_tex);
60
64 public: void SetTextureImage(const std::string &_tex,
65 const std::string &_resourcePath);
66
70 public: std::string GetTextureImage() const;
71
74 public: void SetAmbient(const ignition::math::Color &_clr);
75
78 public: ignition::math::Color Ambient() const;
79
82 public: void SetDiffuse(const ignition::math::Color &_clr);
83
86 public: ignition::math::Color Diffuse() const;
87
90 public: void SetSpecular(const ignition::math::Color &_clr);
91
94 public: ignition::math::Color Specular() const;
95
98 public: void SetEmissive(const ignition::math::Color &_clr);
99
102 public: ignition::math::Color Emissive() const;
103
106 public: void SetTransparency(double _t);
107
110 public: double GetTransparency() const;
111
114 public: void SetShininess(double _t);
115
118 public: double GetShininess() const;
119
124 public: void SetBlendFactors(double _srcFactor, double _dstFactor);
125
129 public: void GetBlendFactors(double &_srcFactor, double &_dstFactor)
130 const;
131
134 public: void SetBlendMode(BlendMode _b);
135
138 public: BlendMode GetBlendMode() const;
139
142 public: void SetShadeMode(ShadeMode _b);
143
146 public: ShadeMode GetShadeMode() const;
147
150 public: void SetPointSize(double _size);
151
154 public: double GetPointSize() const;
155
158 public: void SetDepthWrite(bool _value);
159
162 public: bool GetDepthWrite() const;
163
166 public: void SetLighting(bool _value);
167
170 public: bool GetLighting() const;
171
175 public: friend std::ostream &operator<<(std::ostream &_out,
176 const gazebo::common::Material &_m)
177 {
178 _out << "Material:\n";
179 _out << " Name: " << _m.name << "\n";
180 _out << " Texture: " << _m.texImage << "\n";
181 _out << " Ambient: " << _m.ambient << "\n";
182 _out << " Diffuse: " << _m.diffuse << "\n";
183 _out << " Specular: " << _m.specular << "\n";
184 _out << " Emissive: " << _m.emissive << "\n";
185 _out << " Transparency: " << _m.transparency << "\n";
186 _out << " Shininess: " << _m.shininess << "\n";
187 _out << " BlendMode: " << BlendModeStr[_m.blendMode] << "\n";
188 _out << " ShadeMode: " << ShadeModeStr[_m.shadeMode] << "\n";
189 _out << " DepthWrite: " << _m.depthWrite << "\n";
190 return _out;
191 }
192
194 protected: std::string name;
195
197 protected: std::string texImage;
198
200 protected: ignition::math::Color ambient;
201
203 protected: ignition::math::Color diffuse;
204
206 protected: ignition::math::Color specular;
207
209 protected: ignition::math::Color emissive;
210
212 protected: double transparency = 0.0;
213
215 protected: double shininess = 0.0;
216
218 protected: double pointSize;
219
222
225
227 private: static unsigned int counter;
228
230 private: bool depthWrite = true;
231
232 private: bool lighting = true;
233
235 private: double srcBlendFactor;
236
238 private: double dstBlendFactor;
239 };
241 }
242}
243#endif
common
Definition FuelModelDatabase.hh:37
Encapsulates description of a material.
Definition common/Material.hh:35
void SetTextureImage(const std::string &_tex)
Set a texture image.
void SetShadeMode(ShadeMode _b)
Set the shading mode param[in] the shading mode.
ignition::math::Color Diffuse() const
Get the diffuse color.
bool GetDepthWrite() const
Get depth write.
void GetBlendFactors(double &_srcFactor, double &_dstFactor) const
Get the blend factors.
ignition::math::Color emissive
the emissive light color
Definition common/Material.hh:209
BlendMode GetBlendMode() const
Get the blending mode.
void SetDiffuse(const ignition::math::Color &_clr)
Set the diffuse color.
double pointSize
point size
Definition common/Material.hh:218
void SetSpecular(const ignition::math::Color &_clr)
Set the specular color.
BlendMode
Definition common/Material.hh:39
@ MODULATE
Definition common/Material.hh:39
@ REPLACE
Definition common/Material.hh:39
@ BLEND_COUNT
Definition common/Material.hh:39
@ ADD
Definition common/Material.hh:39
void SetTextureImage(const std::string &_tex, const std::string &_resourcePath)
Set a texture image.
ignition::math::Color Emissive() const
Get the emissive color.
void SetDepthWrite(bool _value)
Set depth write.
void SetTransparency(double _t)
Set the transparency percentage (0..1)
Material(const ignition::math::Color &_clr)
Create a material with a default color.
static std::string BlendModeStr[BLEND_COUNT]
Definition common/Material.hh:40
virtual ~Material()
Destructor.
void SetPointSize(double _size)
Set the point size.
double shininess
shininess value (0 to 1)
Definition common/Material.hh:215
ShadeMode GetShadeMode() const
Get the shading mode.
ignition::math::Color Specular() const
Get the specular color.
std::string texImage
the texture image file name
Definition common/Material.hh:197
static std::string ShadeModeStr[SHADE_COUNT]
Definition common/Material.hh:37
ignition::math::Color diffuse
the diffuse ligth color
Definition common/Material.hh:203
ShadeMode shadeMode
the shade mode
Definition common/Material.hh:224
void SetBlendMode(BlendMode _b)
Set the blending mode.
void SetShininess(double _t)
Set the shininess.
friend std::ostream & operator<<(std::ostream &_out, const gazebo::common::Material &_m)
Stream insertion operator param[in] _out the output stream to extract from param[out] _m the material...
Definition common/Material.hh:175
void SetAmbient(const ignition::math::Color &_clr)
Set the ambient color.
std::string GetName() const
Get the name of the material.
std::string name
the name of the material
Definition common/Material.hh:194
BlendMode blendMode
blend mode
Definition common/Material.hh:221
double GetTransparency() const
Get the transparency percentage (0..1)
void SetLighting(bool _value)
Set lighting enabled.
ignition::math::Color specular
the specular light color
Definition common/Material.hh:206
double GetPointSize() const
Get the point size.
ignition::math::Color ambient
the ambient light color
Definition common/Material.hh:200
bool GetLighting() const
Get lighting enabled.
double GetShininess() const
Get the shininess.
double transparency
transparency value in the range 0 to 1
Definition common/Material.hh:212
void SetBlendFactors(double _srcFactor, double _dstFactor)
Set the blende factors.
ShadeMode
Definition common/Material.hh:36
@ FLAT
Definition common/Material.hh:36
@ BLINN
Definition common/Material.hh:36
@ GOURAUD
Definition common/Material.hh:36
@ SHADE_COUNT
Definition common/Material.hh:36
@ PHONG
Definition common/Material.hh:36
std::string GetTextureImage() const
Get a texture image.
ignition::math::Color Ambient() const
Get the ambient color.
void SetEmissive(const ignition::math::Color &_clr)
Set the emissive color.
Forward declarations for the common classes.
Definition Animation.hh:27