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 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 _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 
153  public: void SetScale(const math::Vector3 &_factor);
154 
156  private: std::string name;
157 
159  private: std::string path;
160 
162  private: std::vector<SubMesh *> submeshes;
163 
165  private: std::vector<Material *> materials;
166 
168  private: Skeleton *skeleton;
169  };
170 
174  {
176  unsigned int vertexIndex;
177 
179  unsigned int nodeIndex;
180 
182  float weight;
183  };
184 
186  class SubMesh
187  {
191 
193  public: SubMesh();
194 
196  public: virtual ~SubMesh();
197 
200  public: void SetPrimitiveType(PrimitiveType _type);
201 
204  public: PrimitiveType GetPrimitiveType() const;
205 
208  public: void CopyVertices(const std::vector<math::Vector3> &_verts);
209 
212  public: void CopyNormals(const std::vector<math::Vector3> &_norms);
213 
216  public: void SetVertexCount(unsigned int _count);
217 
220  public: void SetIndexCount(unsigned int _count);
221 
224  public: void SetNormalCount(unsigned int _count);
225 
228  public: void SetTexCoordCount(unsigned int _count);
229 
232  public: void AddIndex(unsigned int _i);
233 
236  public: void AddVertex(const math::Vector3 &_v);
237 
242  public: void AddVertex(double _x, double _y, double _z);
243 
246  public: void AddNormal(const math::Vector3 &_n);
247 
252  public: void AddNormal(double _x, double _y, double _z);
253 
257  public: void AddTexCoord(double _u, double _v);
258 
263  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
264  float _weight);
265 
269  public: math::Vector3 GetVertex(unsigned int _i) const;
270 
274  public: void SetVertex(unsigned int _i, const math::Vector3 &_v);
275 
279  public: math::Vector3 GetNormal(unsigned int _i) const;
280 
284  public: void SetNormal(unsigned int _i, const math::Vector3 &_n);
285 
289  public: math::Vector2d GetTexCoord(unsigned int _i) const;
290 
293  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
294 
298  public: void SetTexCoord(unsigned int _i, const math::Vector2d &_t);
299 
302  public: unsigned int GetIndex(unsigned int _i) const;
303 
306  public: math::Vector3 GetMax() const;
307 
310  public: math::Vector3 GetMin() const;
311 
313  public: unsigned int GetVertexCount() const;
314 
316  public: unsigned int GetNormalCount() const;
317 
319  public: unsigned int GetIndexCount() const;
320 
322  public: unsigned int GetTexCoordCount() const;
323 
325  public: unsigned int GetNodeAssignmentsCount() const;
326 
328  public: unsigned int GetMaxIndex() const;
329 
333  public: void SetMaterialIndex(unsigned int _index);
334 
336  public: unsigned int GetMaterialIndex() const;
337 
340  public: bool HasVertex(const math::Vector3 &_v) const;
341 
344  public: unsigned int GetVertexIndex(const math::Vector3 &_v) const;
345 
349  public: void FillArrays(float **_vertArr, int **_indArr) const;
350 
352  public: void RecalculateNormals();
353 
356  public: void SetSubMeshCenter(math::Vector3 _center);
357 
361  public: void GenSphericalTexCoord(const math::Vector3 &_center);
362 
365  public: void Scale(double _factor);
366 
369  public: void SetScale(const math::Vector3 &_factor);
370 
372  private: std::vector< math::Vector3 > vertices;
373 
375  private: std::vector< math::Vector3 > normals;
376 
378  private: std::vector< math::Vector2d > texCoords;
379 
381  private: std::vector<unsigned int> indices;
382 
384  private: std::vector<NodeAssignment> nodeAssignments;
385 
387  private: PrimitiveType primitiveType;
388 
391  private: int materialIndex;
392  };
394  }
395 }
396 
397 #endif