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 (C) 2012-2014 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 #include "gazebo/util/system.hh"
26 
27 namespace gazebo
28 {
29  namespace common
30  {
31  class Material;
32  class SubMesh;
33  class Skeleton;
34 
37 
41  {
43  public: Mesh();
44 
46  public: virtual ~Mesh();
47 
50  public: void SetPath(const std::string &_path);
51 
54  public: std::string GetPath() const;
55 
58  public: void SetName(const std::string &_n);
59 
62  public: std::string GetName() const;
63 
66  public: math::Vector3 GetMax() const;
67 
70  public: math::Vector3 GetMin() const;
71 
74  public: unsigned int GetVertexCount() const;
75 
78  public: unsigned int GetNormalCount() const;
79 
82  public: unsigned int GetIndexCount() const;
83 
86  public: unsigned int GetTexCoordCount() const;
87 
91  public: void AddSubMesh(SubMesh *_child);
92 
95  public: unsigned int GetSubMeshCount() const;
96 
100  public: int AddMaterial(Material *_mat);
101 
104  public: unsigned int GetMaterialCount() const;
105 
109  public: const Material *GetMaterial(int _index) const;
110 
115  public: const SubMesh *GetSubMesh(unsigned int _i) const;
116 
120  public: const SubMesh *GetSubMesh(const std::string &_name) const;
121 
125  public: void FillArrays(float **_vertArr, int **_indArr) const;
126 
129  public: void RecalculateNormals();
130 
135  public: void GetAABB(math::Vector3 &_center, math::Vector3 &_min_xyz,
136  math::Vector3 &_max_xyz) const;
137 
141  public: void GenSphericalTexCoord(const math::Vector3 &_center);
142 
145  public: Skeleton* GetSkeleton() const;
146 
148  public: void SetSkeleton(Skeleton *_skel);
149 
151  public: bool HasSkeleton() const;
152 
155  public: void Scale(double _factor);
156 
159  public: void SetScale(const math::Vector3 &_factor);
160 
164  public: void Center(const math::Vector3 &_center = math::Vector3::Zero);
165 
168  public: void Translate(const math::Vector3 &_vec);
169 
171  private: std::string name;
172 
174  private: std::string path;
175 
177  private: std::vector<SubMesh *> submeshes;
178 
180  private: std::vector<Material *> materials;
181 
183  private: Skeleton *skeleton;
184  };
185 
189  {
191  public: NodeAssignment();
192 
194  public: unsigned int vertexIndex;
195 
197  public: unsigned int nodeIndex;
198 
200  public: float weight;
201  };
202 
205  {
207  public: enum PrimitiveType {POINTS, LINES, LINESTRIPS, TRIANGLES,
208  TRIFANS, TRISTRIPS};
209 
211  public: SubMesh();
212 
214  public: SubMesh(const SubMesh *_mesh);
215 
217  public: virtual ~SubMesh();
218 
221  public: void SetName(const std::string &_n);
222 
225  public: std::string GetName() const;
226 
229  public: void SetPrimitiveType(PrimitiveType _type);
230 
233  public: PrimitiveType GetPrimitiveType() const;
234 
237  public: void CopyVertices(const std::vector<math::Vector3> &_verts);
238 
241  public: void CopyNormals(const std::vector<math::Vector3> &_norms);
242 
245  public: void SetVertexCount(unsigned int _count);
246 
249  public: void SetIndexCount(unsigned int _count);
250 
253  public: void SetNormalCount(unsigned int _count);
254 
257  public: void SetTexCoordCount(unsigned int _count);
258 
261  public: void AddIndex(unsigned int _i);
262 
265  public: void AddVertex(const math::Vector3 &_v);
266 
271  public: void AddVertex(double _x, double _y, double _z);
272 
275  public: void AddNormal(const math::Vector3 &_n);
276 
281  public: void AddNormal(double _x, double _y, double _z);
282 
286  public: void AddTexCoord(double _u, double _v);
287 
292  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
293  float _weight);
294 
298  public: math::Vector3 GetVertex(unsigned int _i) const;
299 
303  public: void SetVertex(unsigned int _i, const math::Vector3 &_v);
304 
308  public: math::Vector3 GetNormal(unsigned int _i) const;
309 
313  public: void SetNormal(unsigned int _i, const math::Vector3 &_n);
314 
318  public: math::Vector2d GetTexCoord(unsigned int _i) const;
319 
322  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
323 
327  public: void SetTexCoord(unsigned int _i, const math::Vector2d &_t);
328 
331  public: unsigned int GetIndex(unsigned int _i) const;
332 
335  public: math::Vector3 GetMax() const;
336 
339  public: math::Vector3 GetMin() const;
340 
342  public: unsigned int GetVertexCount() const;
343 
345  public: unsigned int GetNormalCount() const;
346 
348  public: unsigned int GetIndexCount() const;
349 
351  public: unsigned int GetTexCoordCount() const;
352 
354  public: unsigned int GetNodeAssignmentsCount() const;
355 
357  public: unsigned int GetMaxIndex() const;
358 
362  public: void SetMaterialIndex(unsigned int _index);
363 
365  public: unsigned int GetMaterialIndex() const;
366 
369  public: bool HasVertex(const math::Vector3 &_v) const;
370 
373  public: unsigned int GetVertexIndex(const math::Vector3 &_v) const;
374 
378  public: void FillArrays(float **_vertArr, int **_indArr) const;
379 
381  public: void RecalculateNormals();
382 
385  public: void SetSubMeshCenter(math::Vector3 _center);
386 
390  public: void GenSphericalTexCoord(const math::Vector3 &_center);
391 
394  public: void Scale(double _factor);
395 
399  public: void Center(const math::Vector3 &_center = math::Vector3::Zero);
400 
403  public: void Translate(const math::Vector3 &_vec);
404 
407  public: void SetScale(const math::Vector3 &_factor);
408 
410  private: std::vector< math::Vector3 > vertices;
411 
413  private: std::vector< math::Vector3 > normals;
414 
416  private: std::vector< math::Vector2d > texCoords;
417 
419  private: std::vector<unsigned int> indices;
420 
422  private: std::vector<NodeAssignment> nodeAssignments;
423 
425  private: PrimitiveType primitiveType;
426 
429  private: int materialIndex;
430 
432  private: std::string name;
433  };
435  }
436 }
437 
438 #endif