Gazebo Common

API Reference

4.7.0
gz/common/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 <gz/math/Color.hh>
25 
26 #include <gz/common/config.hh>
27 #include <gz/common/graphics/Export.hh>
28 #include <gz/common/EnumIface.hh>
29 #include <gz/common/Pbr.hh>
30 
31 #include <ignition/utils/ImplPtr.hh>
32 
33 namespace ignition
34 {
35  namespace common
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 
156  public: void SetTransparency(double _t);
157 
161  public: double Transparency() const;
162 
167  public: void SetAlphaFromTexture(bool _enabled,
168  double _alpha = 0.5, bool _twoSided = true);
169 
172  public: bool TextureAlphaEnabled() const;
173 
176  public: double AlphaThreshold() const;
177 
180  public: bool TwoSidedEnabled() const;
181 
185  public: void SetRenderOrder(float _renderOrder);
186 
189  public: float RenderOrder() const;
190 
193  public: void SetShininess(double _t);
194 
197  public: double Shininess() const;
198 
203  public: void SetBlendFactors(double _srcFactor, double _dstFactor);
204 
208  public: void BlendFactors(double &_srcFactor, double &_dstFactor) const;
209 
212  public: void SetBlend(BlendMode _b);
213 
216  public: BlendMode Blend() const;
217 
219  public: std::string BlendStr() const;
220 
222  public: std::string ShadeStr() const;
223 
226  public: void SetShade(ShadeMode _b);
227 
230  public: ShadeMode Shade() const;
231 
234  public: void SetPointSize(double _size);
235 
238  public: double PointSize() const;
239 
242  public: void SetDepthWrite(bool _value);
243 
246  public: bool DepthWrite() const;
247 
250  public: void SetLighting(bool _value);
251 
254  public: bool Lighting() const;
255 
258  public: void SetPbrMaterial(const Pbr &_pbr);
259 
262  public: Pbr *PbrMaterial() const;
263 
267  public: friend std::ostream &operator<<(std::ostream &_out,
268  const ignition::common::Material &_m)
269  {
270  _out << "Material:\n";
271  _out << " Name: " << _m.Name() << "\n";
272  _out << " Texture: " << _m.TextureImage() << "\n";
273  _out << " Ambient: " << _m.Ambient() << "\n";
274  _out << " Diffuse: " << _m.Diffuse() << "\n";
275  _out << " Specular: " << _m.Specular() << "\n";
276  _out << " Emissive: " << _m.Emissive() << "\n";
277  _out << " Transparency: " << _m.Transparency() << "\n";
278  _out << " Shininess: " << _m.Shininess() << "\n";
279  _out << " Render order: " << _m.RenderOrder() << "\n";
280  _out << " BlendMode: " << _m.BlendStr() << "\n";
281  _out << " ShadeMode: " << _m.ShadeStr() << "\n";
282  _out << " DepthWrite: " << _m.DepthWrite() << "\n";
283  return _out;
284  }
285 
287  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
288  };
289  }
290 }
291 #endif
ShadeMode
Definition: gz/common/Material.hh:42
bool DepthWrite() const
Get depth write.
std::string BlendStr() const
Get the blend mode string.
Forward declarations for the common classes.
std::string Name() const
Get the name of the material.
STL class.
float RenderOrder() const
Get the render order.
double Shininess() const
Get the shininess.
std::string TextureImage() const
Get a texture image.
Encapsulates description of a material.
Definition: gz/common/Material.hh:38
math::Color Emissive() const
Get the emissive color.
STL class.
BlendMode
Definition: gz/common/Material.hh:69
math::Color Diffuse() const
Get the diffuse color.
std::string ShadeStr() const
Get the shade mode string.
This class contains Physically-Based-Rendering (PBR) workflow properties.
Definition: gz/common/Pbr.hh:56
friend std::ostream & operator<<(std::ostream &_out, const ignition::common::Material &_m)
Stream insertion operator param[in] _out the output stream to extract from param[out] _m the material...
Definition: gz/common/Material.hh:267
double Transparency() const
Get the transparency percentage (0..1) A value of 1 is fully transparent and 0 is not transparent.
math::Color Ambient() const
Get the ambient color.
math::Color Specular() const
Get the specular color.