Gazebo Common

API Reference

6.0.0~pre2
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 GZ_COMMON_MATERIAL_HH_
18#define GZ_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/graphics/Export.hh>
28#include <gz/common/Image.hh>
29#include <gz/common/Pbr.hh>
30
31#include <gz/utils/ImplPtr.hh>
32
33namespace gz
34{
35 namespace common
36 {
38 class GZ_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
110 public: void SetTextureImage(const std::string &_tex,
111 const std::shared_ptr<const Image> &_img = nullptr);
112
116 public: void SetTextureImage(const std::string &_tex,
117 const std::string &_resourcePath);
118
122
126 public: std::string TextureImage() const;
127
130 public: void SetAmbient(const math::Color &_clr);
131
134 public: math::Color Ambient() const;
135
138 public: void SetDiffuse(const math::Color &_clr);
139
142 public: math::Color Diffuse() const;
143
146 public: void SetSpecular(const math::Color &_clr);
147
150 public: math::Color Specular() const;
151
154 public: void SetEmissive(const math::Color &_clr);
155
158 public: math::Color Emissive() const;
159
163 public: void SetTransparency(double _t);
164
168 public: double Transparency() const;
169
174 public: void SetAlphaFromTexture(bool _enabled,
175 double _alpha = 0.5, bool _twoSided = true);
176
179 public: bool TextureAlphaEnabled() const;
180
183 public: double AlphaThreshold() const;
184
187 public: bool TwoSidedEnabled() const;
188
192 public: void SetRenderOrder(float _renderOrder);
193
196 public: float RenderOrder() const;
197
200 public: void SetShininess(double _t);
201
204 public: double Shininess() const;
205
210 public: void SetBlendFactors(double _srcFactor, double _dstFactor);
211
215 public: void BlendFactors(double &_srcFactor, double &_dstFactor) const;
216
219 public: void SetBlend(BlendMode _b);
220
223 public: BlendMode Blend() const;
224
226 public: std::string BlendStr() const;
227
229 public: std::string ShadeStr() const;
230
233 public: void SetShade(ShadeMode _b);
234
237 public: ShadeMode Shade() const;
238
241 public: void SetPointSize(double _size);
242
245 public: double PointSize() const;
246
249 public: void SetDepthWrite(bool _value);
250
253 public: bool DepthWrite() const;
254
257 public: void SetLighting(bool _value);
258
261 public: bool Lighting() const;
262
265 public: void SetPbrMaterial(const Pbr &_pbr);
266
269 public: Pbr *PbrMaterial() const;
270
274 public: friend std::ostream &operator<<(std::ostream &_out,
275 const gz::common::Material &_m)
276 {
277 _out << "Material:\n";
278 _out << " Name: " << _m.Name() << "\n";
279 _out << " Texture: " << _m.TextureImage() << "\n";
280 _out << " Ambient: " << _m.Ambient() << "\n";
281 _out << " Diffuse: " << _m.Diffuse() << "\n";
282 _out << " Specular: " << _m.Specular() << "\n";
283 _out << " Emissive: " << _m.Emissive() << "\n";
284 _out << " Transparency: " << _m.Transparency() << "\n";
285 _out << " Shininess: " << _m.Shininess() << "\n";
286 _out << " Render order: " << _m.RenderOrder() << "\n";
287 _out << " BlendMode: " << _m.BlendStr() << "\n";
288 _out << " ShadeMode: " << _m.ShadeStr() << "\n";
289 _out << " DepthWrite: " << _m.DepthWrite() << "\n";
290 return _out;
291 }
292
294 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
295 };
296 }
297}
298#endif