Ignition Common

API Reference

3.5.0
Material.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 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 IGNITION_COMMON_MATERIAL_HH_
18 #define IGNITION_COMMON_MATERIAL_HH_
19 
20 #include <iostream>
21 #include <memory>
22 #include <string>
23 
24 #include <ignition/math/Color.hh>
25 #include <ignition/common/graphics/Export.hh>
27 #include <ignition/common/Pbr.hh>
29 
30 namespace ignition
31 {
32  namespace common
33  {
34  // Forward declare private data class
35  class MaterialPrivate;
36 
38  class IGNITION_COMMON_GRAPHICS_VISIBLE Material
39  {
42  public: enum ShadeMode
43  {
47  SHADE_MODE_BEGIN = 0,
48 
50  FLAT = 0,
51 
53  GOURAUD = 1,
54 
56  PHONG = 2,
57 
59  BLINN = 3,
60 
64  SHADE_MODE_END
65  };
66 
69  public: enum BlendMode
70  {
74  BLEND_MODE_BEGIN = 0,
75 
77  ADD = 0,
78 
80  MODULATE = 1,
81 
83  REPLACE = 2,
84 
88  BLEND_MODE_END
89  };
90 
92  public: Material();
93 
95  public: ~Material();
96 
99  public: explicit Material(const math::Color &_clr);
100 
103  public: std::string Name() const;
104 
108  public: void SetTextureImage(const std::string &_tex);
109 
113  public: void SetTextureImage(const std::string &_tex,
114  const std::string &_resourcePath);
115 
119  public: std::string TextureImage() const;
120 
123  public: void SetAmbient(const math::Color &_clr);
124 
127  public: math::Color Ambient() const;
128 
131  public: void SetDiffuse(const math::Color &_clr);
132 
135  public: math::Color Diffuse() const;
136 
139  public: void SetSpecular(const math::Color &_clr);
140 
143  public: math::Color Specular() const;
144 
147  public: void SetEmissive(const math::Color &_clr);
148 
151  public: math::Color Emissive() const;
152 
155  public: void SetTransparency(double _t);
156 
159  public: double Transparency() const;
160 
165  public: void SetAlphaFromTexture(bool _enabled,
166  double _alpha = 0.5, bool _twoSided = true);
167 
170  public: bool TextureAlphaEnabled() const;
171 
174  public: double AlphaThreshold() const;
175 
178  public: bool TwoSidedEnabled() const;
179 
182  public: void SetShininess(double _t);
183 
186  public: double Shininess() const;
187 
192  public: void SetBlendFactors(double _srcFactor, double _dstFactor);
193 
197  public: void BlendFactors(double &_srcFactor, double &_dstFactor) const;
198 
201  public: void SetBlend(BlendMode _b);
202 
205  public: BlendMode Blend() const;
206 
208  public: std::string BlendStr() const;
209 
211  public: std::string ShadeStr() const;
212 
215  public: void SetShade(ShadeMode _b);
216 
219  public: ShadeMode Shade() const;
220 
223  public: void SetPointSize(double _size);
224 
227  public: double PointSize() const;
228 
231  public: void SetDepthWrite(bool _value);
232 
235  public: bool DepthWrite() const;
236 
239  public: void SetLighting(bool _value);
240 
243  public: bool Lighting() const;
244 
247  public: void SetPbrMaterial(const Pbr &_pbr);
248 
251  public: Pbr *PbrMaterial() const;
252 
256  public: friend std::ostream &operator<<(std::ostream &_out,
257  const ignition::common::Material &_m)
258  {
259  _out << "Material:\n";
260  _out << " Name: " << _m.Name() << "\n";
261  _out << " Texture: " << _m.TextureImage() << "\n";
262  _out << " Ambient: " << _m.Ambient() << "\n";
263  _out << " Diffuse: " << _m.Diffuse() << "\n";
264  _out << " Specular: " << _m.Specular() << "\n";
265  _out << " Emissive: " << _m.Emissive() << "\n";
266  _out << " Transparency: " << _m.Transparency() << "\n";
267  _out << " Shininess: " << _m.Shininess() << "\n";
268  _out << " BlendMode: " << _m.BlendStr() << "\n";
269  _out << " ShadeMode: " << _m.ShadeStr() << "\n";
270  _out << " DepthWrite: " << _m.DepthWrite() << "\n";
271  return _out;
272  }
273 
276  private: std::unique_ptr<MaterialPrivate> dataPtr;
278  };
279  }
280 }
281 #endif
friend std::ostream & operator<<(std::ostream &_out, const Material &_m)
Stream insertion operator param[in] _out the output stream to extract from param[out] _m the material...
Definition: Material.hh:256
BlendMode
Definition: Material.hh:69
std::string Name() const
Get the name of the material.
double Transparency() const
Get the transparency percentage (0..1)
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
STL class.
double Shininess() const
Get the shininess.
Encapsulates description of a material.
Definition: Material.hh:38
std::string ShadeStr() const
Get the shade mode string.
This class contains Physically-Based-Rendering (PBR) workflow properties.
Definition: Pbr.hh:55
std::string BlendStr() const
Get the blend mode string.
std::string TextureImage() const
Get a texture image.
bool DepthWrite() const
Get depth write.
math::Color Ambient() const
Get the ambient color.
ShadeMode
Definition: Material.hh:42
Forward declarations for the common classes.
math::Color Specular() const
Get the specular color.
math::Color Diffuse() const
Get the diffuse color.
STL class.
math::Color Emissive() const
Get the emissive color.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: SuppressWarning.hh:64