Ignition Rendering

API Reference

0.1.0
BaseMesh.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_BASEMESH_HH_
18 #define IGNITION_RENDERING_BASE_BASEMESH_HH_
19 
20 #include <string>
24 
25 namespace ignition
26 {
27  namespace rendering
28  {
30  template <class T>
31  class IGNITION_RENDERING_VISIBLE BaseMesh :
32  public virtual Mesh,
33  public virtual T
34  {
35  protected: BaseMesh();
36 
37  public: virtual ~BaseMesh();
38 
39  public: virtual unsigned int SubMeshCount() const;
40 
41  public: virtual bool HasSubMesh(ConstSubMeshPtr _subMesh) const;
42 
43  public: virtual bool HasSubMeshName(const std::string &_name) const;
44 
45  public: virtual SubMeshPtr SubMeshByName(
46  const std::string &_name) const;
47 
48  public: virtual SubMeshPtr SubMeshByIndex(unsigned int _index) const;
49 
50  // Documentation inherited.
51  public: virtual MaterialPtr Material() const;
52 
53  public: virtual void SetMaterial(const std::string &_name,
54  bool _unique = true);
55 
56  public: virtual void SetMaterial(MaterialPtr _material,
57  bool _unique = true);
58 
59  public: virtual void PreRender();
60 
61  public: virtual void Destroy();
62 
63  protected: virtual SubMeshStorePtr SubMeshes() const = 0;
64  };
65 
67  template <class T>
68  class IGNITION_RENDERING_VISIBLE BaseSubMesh :
69  public virtual SubMesh,
70  public virtual T
71  {
72  protected: BaseSubMesh();
73 
74  public: virtual ~BaseSubMesh();
75 
76  public: virtual MaterialPtr Material() const = 0;
77 
78  public: virtual void SetMaterial(const std::string &_name,
79  bool _unique = true);
80 
81  public: virtual void SetMaterial(MaterialPtr _material,
82  bool _unique = true) = 0;
83 
84  public: virtual void PreRender();
85  };
86 
88  // BaseMesh
90  template <class T>
92  {
93  }
94 
96  template <class T>
98  {
99  }
100 
102  template <class T>
103  unsigned int BaseMesh<T>::SubMeshCount() const
104  {
105  return this->SubMeshes()->Size();
106  }
107 
109  template <class T>
111  {
112  return this->SubMeshes()->Contains(_subMesh);
113  }
114 
116  template <class T>
117  bool BaseMesh<T>::HasSubMeshName(const std::string &_name) const
118  {
119  return this->SubMeshes()->ContainsName(_name);
120  }
121 
123  template <class T>
125  {
126  return this->SubMeshes()->GetByName(_name);
127  }
128 
130  template <class T>
131  SubMeshPtr BaseMesh<T>::SubMeshByIndex(unsigned int _index) const
132  {
133  return this->SubMeshes()->GetByIndex(_index);
134  }
135 
137  template <class T>
139  {
140  unsigned int count = this->SubMeshCount();
141  return (count > 0) ? this->SubMeshByIndex(0)->Material() :
142  MaterialPtr();
143  }
144 
146  template <class T>
147  void BaseMesh<T>::SetMaterial(const std::string &_name, bool _unique)
148  {
149  MaterialPtr material = this->Scene()->Material(_name);
150  if (material) this->SetMaterial(material, _unique);
151  }
152 
154  template <class T>
155  void BaseMesh<T>::SetMaterial(MaterialPtr _material, bool _unique)
156  {
157  unsigned int count = this->SubMeshCount();
158  _material = (_unique && count > 0) ? _material->Clone() : _material;
159 
160  for (unsigned int i = 0; i < count; ++i)
161  {
162  SubMeshPtr subMesh = this->SubMeshByIndex(i);
163  subMesh->SetMaterial(_material, false);
164  }
165  }
166 
168  template <class T>
170  {
171  unsigned int count = this->SubMeshCount();
172 
173  for (unsigned int i = 0; i < count; ++i)
174  {
175  SubMeshPtr subMesh = this->SubMeshByIndex(i);
176  subMesh->PreRender();
177  }
178 
179  T::PreRender();
180  }
181 
183  template <class T>
185  {
186  T::Destroy();
187  this->SubMeshes()->DestroyAll();
188  }
189 
191  // BaseSubMesh
193  template <class T>
195  {
196  }
197 
199  template <class T>
201  {
202  }
203 
205  template <class T>
206  void BaseSubMesh<T>::SetMaterial(const std::string &_name, bool _unique)
207  {
208  MaterialPtr material = this->Scene()->Material(_name);
209  if (material) this->SetMaterial(material, _unique);
210  }
211 
213  template <class T>
215  {
216  T::PreRender();
217  this->Material()->PreRender();
218  }
219  }
220 }
221 #endif
virtual ~BaseMesh()
Definition: BaseMesh.hh:97
virtual SubMeshPtr SubMeshByName(const std::string &_name) const
Get sub-mesh with given name.
Definition: BaseMesh.hh:124
Definition: BaseMesh.hh:68
virtual void PreRender()
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseMesh.hh:169
virtual SubMeshPtr SubMeshByIndex(unsigned int _index) const
Get sub-mesh at given index.
Definition: BaseMesh.hh:131
STL class.
virtual void SetMaterial(const std::string &_name, bool _unique=true)
Set the materials of this SubMesh. The specified material will be retrieved from the parent Scene...
Definition: BaseMesh.hh:206
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node...
Definition: Scene.hh:44
virtual void Destroy()
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: BaseMesh.hh:184
virtual unsigned int SubMeshCount() const
Get the sub-mesh count.
Definition: BaseMesh.hh:103
Definition: BaseMesh.hh:31
virtual ~BaseSubMesh()
Definition: BaseMesh.hh:200
BaseSubMesh()
Definition: BaseMesh.hh:194
virtual void PreRender()=0
Prepare this object and any of its children for rendering. This should be called for each object in a...
shared_ptr< Material > MaterialPtr
Definition: RenderTypes.hh:93
virtual void PreRender()
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseMesh.hh:214
Represents a collection of mesh geometries.
Definition: Mesh.hh:30
virtual void SetMaterial(const std::string &_name, bool _unique=true)
Set the materials of this Geometry. The specified material will be retrieved from the parent Scene...
Definition: BaseMesh.hh:147
virtual bool HasSubMeshName(const std::string &_name) const
Determine if has sub-mesh with given name.
Definition: BaseMesh.hh:117
Definition: ArrowVisual.hh:22
Represents a surface material of a Geometry.
Definition: Material.hh:34
virtual bool HasSubMesh(ConstSubMeshPtr _subMesh) const
Determine if has given sub-mesh.
Definition: BaseMesh.hh:110
BaseMesh()
Definition: BaseMesh.hh:91
Represents a single mesh geometry.
Definition: Mesh.hh:65
virtual MaterialPtr Material() const
Get the material of this geometry.
Definition: BaseMesh.hh:138
virtual MaterialPtr Material(const std::string &_name) const =0
Get material registered under the given name. If no material is registered under the given name...