Ignition Common

API Reference

3.9.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 
183  public: void SetRenderOrder(float _renderOrder);
184 
187  public: float RenderOrder() const;
188 
191  public: void SetShininess(double _t);
192 
195  public: double Shininess() const;
196 
201  public: void SetBlendFactors(double _srcFactor, double _dstFactor);
202 
206  public: void BlendFactors(double &_srcFactor, double &_dstFactor) const;
207 
210  public: void SetBlend(BlendMode _b);
211 
214  public: BlendMode Blend() const;
215 
217  public: std::string BlendStr() const;
218 
220  public: std::string ShadeStr() const;
221 
224  public: void SetShade(ShadeMode _b);
225 
228  public: ShadeMode Shade() const;
229 
232  public: void SetPointSize(double _size);
233 
236  public: double PointSize() const;
237 
240  public: void SetDepthWrite(bool _value);
241 
244  public: bool DepthWrite() const;
245 
248  public: void SetLighting(bool _value);
249 
252  public: bool Lighting() const;
253 
256  public: void SetPbrMaterial(const Pbr &_pbr);
257 
260  public: Pbr *PbrMaterial() const;
261 
265  public: friend std::ostream &operator<<(std::ostream &_out,
266  const ignition::common::Material &_m)
267  {
268  _out << "Material:\n";
269  _out << " Name: " << _m.Name() << "\n";
270  _out << " Texture: " << _m.TextureImage() << "\n";
271  _out << " Ambient: " << _m.Ambient() << "\n";
272  _out << " Diffuse: " << _m.Diffuse() << "\n";
273  _out << " Specular: " << _m.Specular() << "\n";
274  _out << " Emissive: " << _m.Emissive() << "\n";
275  _out << " Transparency: " << _m.Transparency() << "\n";
276  _out << " Shininess: " << _m.Shininess() << "\n";
277  _out << " Render order: " << _m.RenderOrder() << "\n";
278  _out << " BlendMode: " << _m.BlendStr() << "\n";
279  _out << " ShadeMode: " << _m.ShadeStr() << "\n";
280  _out << " DepthWrite: " << _m.DepthWrite() << "\n";
281  return _out;
282  }
283 
286  private: std::unique_ptr<MaterialPrivate> dataPtr;
288  };
289  }
290 }
291 #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:265
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.
float RenderOrder() const
Get the render order.
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