Ignition Common

API Reference

4.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>
28 
29 #include <ignition/utils/ImplPtr.hh>
30 
31 namespace ignition
32 {
33  namespace common
34  {
36  class IGNITION_COMMON_GRAPHICS_VISIBLE Material
37  {
40  public: enum ShadeMode
41  {
45  SHADE_MODE_BEGIN = 0,
46 
48  FLAT = 0,
49 
51  GOURAUD = 1,
52 
54  PHONG = 2,
55 
57  BLINN = 3,
58 
62  SHADE_MODE_END
63  };
64 
67  public: enum BlendMode
68  {
72  BLEND_MODE_BEGIN = 0,
73 
75  ADD = 0,
76 
78  MODULATE = 1,
79 
81  REPLACE = 2,
82 
86  BLEND_MODE_END
87  };
88 
90  public: Material();
91 
93  public: ~Material();
94 
97  public: explicit Material(const math::Color &_clr);
98 
101  public: std::string Name() const;
102 
106  public: void SetTextureImage(const std::string &_tex);
107 
111  public: void SetTextureImage(const std::string &_tex,
112  const std::string &_resourcePath);
113 
117  public: std::string TextureImage() const;
118 
121  public: void SetAmbient(const math::Color &_clr);
122 
125  public: math::Color Ambient() const;
126 
129  public: void SetDiffuse(const math::Color &_clr);
130 
133  public: math::Color Diffuse() const;
134 
137  public: void SetSpecular(const math::Color &_clr);
138 
141  public: math::Color Specular() const;
142 
145  public: void SetEmissive(const math::Color &_clr);
146 
149  public: math::Color Emissive() const;
150 
154  public: void SetTransparency(double _t);
155 
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 
285  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
286  };
287  }
288 }
289 #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:67
std::string Name() const
Get the name of the material.
double Transparency() const
Get the transparency percentage (0..1) A value of 1 is fully transparent and 0 is not transparent...
STL class.
double Shininess() const
Get the shininess.
Encapsulates description of a material.
Definition: Material.hh:36
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:40
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.