Ignition Rendering

API Reference

0.1.0
BaseMaterial.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 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_RENDERING_BASE_BASEMATERIAL_HH_
18 #define IGNITION_RENDERING_BASE_BASEMATERIAL_HH_
19 
20 #include <string>
21 
24 
25 namespace ignition
26 {
27  namespace rendering
28  {
29  template <class T>
30  class IGNITION_RENDERING_VISIBLE BaseMaterial :
31  public virtual Material,
32  public virtual T
33  {
34  protected: BaseMaterial();
35 
36  public: virtual ~BaseMaterial();
37 
38  public: virtual MaterialPtr Clone(const std::string &_name = "") const;
39 
40  public: virtual void SetAmbient(const double _r, const double _g,
41  const double _b, const double _a = 1.0);
42 
43  public: virtual void SetAmbient(const math::Color &_color) = 0;
44 
45  public: virtual void SetDiffuse(const double _r, const double _g,
46  const double _b, const double _a = 1.0);
47 
48  public: virtual void SetDiffuse(const math::Color &_color) = 0;
49 
50  public: virtual void SetSpecular(const double _r, const double _g,
51  const double _b, const double _a = 1.0);
52 
53  public: virtual void SetSpecular(const math::Color &_color) = 0;
54 
55  public: virtual void SetEmissive(const double _r, const double _g,
56  const double _b, const double _a = 1.0);
57 
58  public: virtual void SetEmissive(const math::Color &_color) = 0;
59 
60  public: virtual void SetReceiveShadows(const bool _receiveShadows) = 0;
61 
62  public: virtual void ClearTexture() = 0;
63 
64  public: virtual void ClearNormalMap() = 0;
65 
66  public: virtual void SetShaderType(enum ShaderType _type) = 0;
67 
68  public: virtual void CopyFrom(ConstMaterialPtr _material);
69 
70  public: virtual void CopyFrom(const common::Material &_material);
71 
72  public: virtual void PreRender();
73 
74  protected: virtual void Reset();
75  };
76 
78  template <class T>
80  {
81  }
82 
84  template <class T>
86  {
87  }
88 
90  template <class T>
91  void BaseMaterial<T>::SetAmbient(const double _r, const double _g,
92  const double _b, const double _a)
93  {
94  this->SetAmbient(math::Color(_r, _g, _b, _a));
95  }
96 
98  template <class T>
99  void BaseMaterial<T>::SetDiffuse(const double _r, const double _g,
100  const double _b, const double _a)
101  {
102  this->SetDiffuse(math::Color(_r, _g, _b, _a));
103  }
104 
106  template <class T>
107  void BaseMaterial<T>::SetSpecular(const double _r, const double _g,
108  const double _b, const double _a)
109  {
110  this->SetSpecular(math::Color(_r, _g, _b, _a));
111  }
112 
114  template <class T>
115  void BaseMaterial<T>::SetEmissive(const double _r, const double _g,
116  const double _b, const double _a)
117  {
118  this->SetEmissive(math::Color(_r, _g, _b, _a));
119  }
120 
122  template <class T>
124  {
125  auto baseShared = this->shared_from_this();
126 
127  auto thisShared =
128  std::dynamic_pointer_cast<const BaseMaterial<T>>(baseShared);
129 
130  MaterialPtr material = T::Scene()->CreateMaterial(_name);
131  material->CopyFrom(thisShared);
132  return material;
133  }
134 
136  template <class T>
138  {
139  this->SetLightingEnabled(_material->LightingEnabled());
140  this->SetAmbient(_material->Ambient());
141  this->SetDiffuse(_material->Diffuse());
142  this->SetSpecular(_material->Specular());
143  this->SetEmissive(_material->Emissive());
144  this->SetShininess(_material->Shininess());
145  this->SetTransparency(_material->Transparency());
146  this->SetReflectivity(_material->Reflectivity());
147  this->SetCastShadows(_material->CastShadows());
148  this->SetReceiveShadows(_material->ReceiveShadows());
149  this->SetReflectionEnabled(_material->ReflectionEnabled());
150  this->SetTexture(_material->Texture());
151  this->SetNormalMap(_material->NormalMap());
152  this->SetShaderType(_material->ShaderType());
153  }
154 
156  template <class T>
157  void BaseMaterial<T>::CopyFrom(const common::Material &_material)
158  {
159  this->SetLightingEnabled(_material.Lighting());
160  this->SetAmbient(_material.Ambient());
161  this->SetDiffuse(_material.Diffuse());
162  this->SetSpecular(_material.Specular());
163  this->SetEmissive(_material.Emissive());
164  this->SetShininess(_material.Shininess());
165  this->SetTransparency(_material.Transparency());
166  // TODO: update common::Material
167  this->SetReflectivity(0);
168  this->SetTexture(_material.TextureImage());
169  // TODO: update common::Material
170  this->SetCastShadows(true);
171  // TODO: update common::Material
172  this->SetReceiveShadows(true);
173  // TODO: update common::Material
174  this->SetReflectionEnabled(true);
175  // TODO: update common::Material
176  this->ClearNormalMap();
177  // TODO: update common::Material
178  this->SetShaderType(ST_PIXEL);
179  }
180 
182  template <class T>
184  {
185  // do nothing
186  }
187 
189  template <class T>
191  {
192  this->SetLightingEnabled(true);
193  this->SetAmbient(0.3, 0.3, 0.3);
194  this->SetDiffuse(0.7, 0.7, 0.7);
195  this->SetSpecular(0.01, 0.01, 0.01);
196  this->SetEmissive(0, 0, 0);
197  this->SetShininess(1.5);
198  this->SetTransparency(0);
199  this->SetReflectivity(0);
200  this->SetCastShadows(true);
201  this->SetReceiveShadows(true);
202  this->SetReflectionEnabled(true);
203  this->ClearTexture();
204  this->ClearNormalMap();
205  this->SetShaderType(ST_PIXEL);
206  }
207  }
208 }
209 #endif
virtual void SetDiffuse(const double _r, const double _g, const double _b, const double _a=1.0)
Set the diffuse color.
Definition: BaseMaterial.hh:99
virtual void Reset()
Definition: BaseMaterial.hh:190
BaseMaterial()
Definition: BaseMaterial.hh:79
virtual void SetAmbient(const double _r, const double _g, const double _b, const double _a=1.0)
Set the ambient color.
Definition: BaseMaterial.hh:91
virtual void PreRender()
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseMaterial.hh:183
virtual void CopyFrom(ConstMaterialPtr _material)
Copy properties from given Material.
Definition: BaseMaterial.hh:137
STL class.
virtual void SetEmissive(const double _r, const double _g, const double _b, const double _a=1.0)
Set the emissive color.
Definition: BaseMaterial.hh:115
T dynamic_pointer_cast(T... args)
virtual ~BaseMaterial()
Definition: BaseMaterial.hh:85
ShaderType
Available types of shaders. Note that not all rendering-engines will be able to use each type...
Definition: ShaderType.hh:31
Definition: BaseMaterial.hh:30
Shader shader.
Definition: ShaderType.hh:37
virtual void SetSpecular(const double _r, const double _g, const double _b, const double _a=1.0)
Set the specular color.
Definition: BaseMaterial.hh:107
Definition: ArrowVisual.hh:22
Represents a surface material of a Geometry.
Definition: Material.hh:34
virtual MaterialPtr Clone(const std::string &_name="") const
Clone this material.
Definition: BaseMaterial.hh:123