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 "gazebo/math/Vector3.hh"
24 #include "gazebo/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: const SubMesh *GetSubMesh(const std::string &_name) const;
120 
124  public: void FillArrays(float **_vertArr, int **_indArr) const;
125 
128  public: void RecalculateNormals();
129 
134  public: void GetAABB(math::Vector3 &_center, math::Vector3 &_min_xyz,
135  math::Vector3 &_max_xyz) const;
136 
140  public: void GenSphericalTexCoord(const math::Vector3 &_center);
141 
144  public: Skeleton* GetSkeleton() const;
145 
147  public: void SetSkeleton(Skeleton *_skel);
148 
150  public: bool HasSkeleton() const;
151 
154  public: void Scale(double _factor);
155 
158  public: void SetScale(const math::Vector3 &_factor);
159 
163  public: void Center(const math::Vector3 &_center = math::Vector3::Zero);
164 
167  public: void Translate(const math::Vector3 &_vec);
168 
170  private: std::string name;
171 
173  private: std::string path;
174 
176  private: std::vector<SubMesh *> submeshes;
177 
179  private: std::vector<Material *> materials;
180 
182  private: Skeleton *skeleton;
183  };
184 
188  {
190  unsigned int vertexIndex;
191 
193  unsigned int nodeIndex;
194 
196  float weight;
197  };
198 
200  class SubMesh
201  {
205 
207  public: SubMesh();
208 
210  public: SubMesh(const SubMesh *_mesh);
211 
213  public: virtual ~SubMesh();
214 
217  public: void SetName(const std::string &_n);
218 
221  public: std::string GetName() const;
222 
225  public: void SetPrimitiveType(PrimitiveType _type);
226 
229  public: PrimitiveType GetPrimitiveType() const;
230 
233  public: void CopyVertices(const std::vector<math::Vector3> &_verts);
234 
237  public: void CopyNormals(const std::vector<math::Vector3> &_norms);
238 
241  public: void SetVertexCount(unsigned int _count);
242 
245  public: void SetIndexCount(unsigned int _count);
246 
249  public: void SetNormalCount(unsigned int _count);
250 
253  public: void SetTexCoordCount(unsigned int _count);
254 
257  public: void AddIndex(unsigned int _i);
258 
261  public: void AddVertex(const math::Vector3 &_v);
262 
267  public: void AddVertex(double _x, double _y, double _z);
268 
271  public: void AddNormal(const math::Vector3 &_n);
272 
277  public: void AddNormal(double _x, double _y, double _z);
278 
282  public: void AddTexCoord(double _u, double _v);
283 
288  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
289  float _weight);
290 
294  public: math::Vector3 GetVertex(unsigned int _i) const;
295 
299  public: void SetVertex(unsigned int _i, const math::Vector3 &_v);
300 
304  public: math::Vector3 GetNormal(unsigned int _i) const;
305 
309  public: void SetNormal(unsigned int _i, const math::Vector3 &_n);
310 
314  public: math::Vector2d GetTexCoord(unsigned int _i) const;
315 
318  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
319 
323  public: void SetTexCoord(unsigned int _i, const math::Vector2d &_t);
324 
327  public: unsigned int GetIndex(unsigned int _i) const;
328 
331  public: math::Vector3 GetMax() const;
332 
335  public: math::Vector3 GetMin() const;
336 
338  public: unsigned int GetVertexCount() const;
339 
341  public: unsigned int GetNormalCount() const;
342 
344  public: unsigned int GetIndexCount() const;
345 
347  public: unsigned int GetTexCoordCount() const;
348 
350  public: unsigned int GetNodeAssignmentsCount() const;
351 
353  public: unsigned int GetMaxIndex() const;
354 
358  public: void SetMaterialIndex(unsigned int _index);
359 
361  public: unsigned int GetMaterialIndex() const;
362 
365  public: bool HasVertex(const math::Vector3 &_v) const;
366 
369  public: unsigned int GetVertexIndex(const math::Vector3 &_v) const;
370 
374  public: void FillArrays(float **_vertArr, int **_indArr) const;
375 
377  public: void RecalculateNormals();
378 
381  public: void SetSubMeshCenter(math::Vector3 _center);
382 
386  public: void GenSphericalTexCoord(const math::Vector3 &_center);
387 
390  public: void Scale(double _factor);
391 
395  public: void Center(const math::Vector3 &_center = math::Vector3::Zero);
396 
399  public: void Translate(const math::Vector3 &_vec);
400 
403  public: void SetScale(const math::Vector3 &_factor);
404 
406  private: std::vector< math::Vector3 > vertices;
407 
409  private: std::vector< math::Vector3 > normals;
410 
412  private: std::vector< math::Vector2d > texCoords;
413 
415  private: std::vector<unsigned int> indices;
416 
418  private: std::vector<NodeAssignment> nodeAssignments;
419 
421  private: PrimitiveType primitiveType;
422 
425  private: int materialIndex;
426 
428  private: std::string name;
429  };
431  }
432 }
433 
434 #endif