All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mesh.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Nate Koenig
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 _MESH_HH_
18 #define _MESH_HH_
19 
20 #include <vector>
21 #include <string>
22 
23 #include "math/Vector3.hh"
24 #include "math/Vector2d.hh"
25 
26 namespace gazebo
27 {
28  namespace common
29  {
30  class Material;
31  class SubMesh;
32  class Skeleton;
33 
36 
39  class Mesh
40  {
42  public: Mesh();
43 
45  public: virtual ~Mesh();
46 
49  public: void SetPath(const std::string &_path);
50 
53  public: std::string GetPath() const;
54 
57  public: void SetName(const std::string &_n);
58 
61  public: std::string GetName() const;
62 
65  public: math::Vector3 GetMax() const;
66 
69  public: math::Vector3 GetMin() const;
70 
73  public: unsigned int GetVertexCount() const;
74 
77  public: unsigned int GetNormalCount() const;
78 
81  public: unsigned int GetIndexCount() const;
82 
85  public: unsigned int GetTexCoordCount() const;
86 
90  public: void AddSubMesh(SubMesh *_child);
91 
94  public: unsigned int GetSubMeshCount() const;
95 
99  public: int AddMaterial(Material *_mat);
100 
103  public: unsigned int GetMaterialCount() const;
104 
108  public: const Material *GetMaterial(int _index) const;
109 
114  public: const SubMesh *GetSubMesh(unsigned int _i) const;
115 
119  public: void FillArrays(float **_vertArr, int **_indArr) const;
120 
123  public: void RecalculateNormals();
124 
129  public: void GetAABB(math::Vector3 &_center, math::Vector3 &_min_xyz,
130  math::Vector3 &_max_xyz) const;
131 
135  public: void GenSphericalTexCoord(const math::Vector3 &_center);
136 
139  public: Skeleton* GetSkeleton() const;
140 
142  public: void SetSkeleton(Skeleton *_skel);
143 
145  public: bool HasSkeleton() const;
146 
149  public: void Scale(double _factor);
150 
152  private: std::string name;
153 
155  private: std::string path;
156 
158  private: std::vector<SubMesh *> submeshes;
159 
161  private: std::vector<Material *> materials;
162 
164  private: Skeleton *skeleton;
165  };
166 
170  {
172  unsigned int vertexIndex;
173 
175  unsigned int nodeIndex;
176 
178  float weight;
179  };
180 
182  class SubMesh
183  {
187 
189  public: SubMesh();
190 
192  public: virtual ~SubMesh();
193 
196  public: void SetPrimitiveType(PrimitiveType _type);
197 
200  public: PrimitiveType GetPrimitiveType() const;
201 
204  public: void CopyVertices(const std::vector<math::Vector3> &_verts);
205 
208  public: void CopyNormals(const std::vector<math::Vector3> &_norms);
209 
212  public: void SetVertexCount(unsigned int _count);
213 
216  public: void SetIndexCount(unsigned int _count);
217 
220  public: void SetNormalCount(unsigned int _count);
221 
224  public: void SetTexCoordCount(unsigned int _count);
225 
228  public: void AddIndex(unsigned int _i);
229 
232  public: void AddVertex(const math::Vector3 &_v);
233 
238  public: void AddVertex(double _x, double _y, double _z);
239 
242  public: void AddNormal(const math::Vector3 &_n);
243 
248  public: void AddNormal(double _x, double _y, double _z);
249 
253  public: void AddTexCoord(double _u, double _v);
254 
259  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
260  float _weight);
261 
265  public: math::Vector3 GetVertex(unsigned int _i) const;
266 
270  public: void SetVertex(unsigned int _i, const math::Vector3 &_v);
271 
275  public: math::Vector3 GetNormal(unsigned int _i) const;
276 
280  public: void SetNormal(unsigned int _i, const math::Vector3 &_n);
281 
285  public: math::Vector2d GetTexCoord(unsigned int _i) const;
286 
289  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
290 
294  public: void SetTexCoord(unsigned int _i, const math::Vector2d &_t);
295 
298  public: unsigned int GetIndex(unsigned int _i) const;
299 
302  public: math::Vector3 GetMax() const;
303 
306  public: math::Vector3 GetMin() const;
307 
309  public: unsigned int GetVertexCount() const;
310 
312  public: unsigned int GetNormalCount() const;
313 
315  public: unsigned int GetIndexCount() const;
316 
318  public: unsigned int GetTexCoordCount() const;
319 
321  public: unsigned int GetNodeAssignmentsCount() const;
322 
324  public: unsigned int GetMaxIndex() const;
325 
329  public: void SetMaterialIndex(unsigned int _index);
330 
332  public: unsigned int GetMaterialIndex() const;
333 
336  public: bool HasVertex(const math::Vector3 &_v) const;
337 
340  public: unsigned int GetVertexIndex(const math::Vector3 &_v) const;
341 
345  public: void FillArrays(float **_vertArr, int **_indArr) const;
346 
348  public: void RecalculateNormals();
349 
352  public: void SetSubMeshCenter(math::Vector3 _center);
353 
357  public: void GenSphericalTexCoord(const math::Vector3 &_center);
358 
361  public: void Scale(double _factor);
362 
364  private: std::vector< math::Vector3 > vertices;
365 
367  private: std::vector< math::Vector3 > normals;
368 
370  private: std::vector< math::Vector2d > texCoords;
371 
373  private: std::vector<unsigned int> indices;
374 
376  private: std::vector<NodeAssignment> nodeAssignments;
377 
379  private: PrimitiveType primitiveType;
380 
383  private: int materialIndex;
384  };
386  }
387 }
388 
389 #endif