All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 _GAZEBO_MESH_HH_
18 #define _GAZEBO_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 
114  public: int GetMaterialIndex(const Material *_mat) const;
115 
120  public: const SubMesh *GetSubMesh(unsigned int _i) const;
121 
125  public: const SubMesh *GetSubMesh(const std::string &_name) const;
126 
130  public: void FillArrays(float **_vertArr, int **_indArr) const;
131 
134  public: void RecalculateNormals();
135 
140  public: void GetAABB(math::Vector3 &_center, math::Vector3 &_min_xyz,
141  math::Vector3 &_max_xyz) const;
142 
146  public: void GenSphericalTexCoord(const math::Vector3 &_center);
147 
150  public: Skeleton* GetSkeleton() const;
151 
153  public: void SetSkeleton(Skeleton *_skel);
154 
156  public: bool HasSkeleton() const;
157 
160  public: void Scale(double _factor);
161 
164  public: void SetScale(const math::Vector3 &_factor);
165 
169  public: void Center(const math::Vector3 &_center = math::Vector3::Zero);
170 
173  public: void Translate(const math::Vector3 &_vec);
174 
176  private: std::string name;
177 
179  private: std::string path;
180 
182  private: std::vector<SubMesh *> submeshes;
183 
185  private: std::vector<Material *> materials;
186 
188  private: Skeleton *skeleton;
189  };
190 
194  {
196  public: NodeAssignment();
197 
199  public: unsigned int vertexIndex;
200 
202  public: unsigned int nodeIndex;
203 
205  public: float weight;
206  };
207 
210  {
212  public: enum PrimitiveType {POINTS, LINES, LINESTRIPS, TRIANGLES,
213  TRIFANS, TRISTRIPS};
214 
216  public: SubMesh();
217 
219  public: SubMesh(const SubMesh *_mesh);
220 
222  public: virtual ~SubMesh();
223 
226  public: void SetName(const std::string &_n);
227 
230  public: std::string GetName() const;
231 
234  public: void SetPrimitiveType(PrimitiveType _type);
235 
238  public: PrimitiveType GetPrimitiveType() const;
239 
242  public: void CopyVertices(const std::vector<math::Vector3> &_verts);
243 
246  public: void CopyNormals(const std::vector<math::Vector3> &_norms);
247 
250  public: void SetVertexCount(unsigned int _count);
251 
254  public: void SetIndexCount(unsigned int _count);
255 
258  public: void SetNormalCount(unsigned int _count);
259 
262  public: void SetTexCoordCount(unsigned int _count);
263 
266  public: void AddIndex(unsigned int _i);
267 
270  public: void AddVertex(const math::Vector3 &_v);
271 
276  public: void AddVertex(double _x, double _y, double _z);
277 
280  public: void AddNormal(const math::Vector3 &_n);
281 
286  public: void AddNormal(double _x, double _y, double _z);
287 
291  public: void AddTexCoord(double _u, double _v);
292 
297  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
298  float _weight);
299 
303  public: math::Vector3 GetVertex(unsigned int _i) const;
304 
308  public: void SetVertex(unsigned int _i, const math::Vector3 &_v);
309 
313  public: math::Vector3 GetNormal(unsigned int _i) const;
314 
318  public: void SetNormal(unsigned int _i, const math::Vector3 &_n);
319 
323  public: math::Vector2d GetTexCoord(unsigned int _i) const;
324 
327  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
328 
332  public: void SetTexCoord(unsigned int _i, const math::Vector2d &_t);
333 
336  public: unsigned int GetIndex(unsigned int _i) const;
337 
340  public: math::Vector3 GetMax() const;
341 
344  public: math::Vector3 GetMin() const;
345 
347  public: unsigned int GetVertexCount() const;
348 
350  public: unsigned int GetNormalCount() const;
351 
353  public: unsigned int GetIndexCount() const;
354 
356  public: unsigned int GetTexCoordCount() const;
357 
359  public: unsigned int GetNodeAssignmentsCount() const;
360 
362  public: unsigned int GetMaxIndex() const;
363 
367  public: void SetMaterialIndex(unsigned int _index);
368 
370  public: unsigned int GetMaterialIndex() const;
371 
374  public: bool HasVertex(const math::Vector3 &_v) const;
375 
378  public: unsigned int GetVertexIndex(const math::Vector3 &_v) const;
379 
383  public: void FillArrays(float **_vertArr, int **_indArr) const;
384 
386  public: void RecalculateNormals();
387 
390  public: void SetSubMeshCenter(math::Vector3 _center);
391 
395  public: void GenSphericalTexCoord(const math::Vector3 &_center);
396 
399  public: void Scale(double _factor);
400 
404  public: void Center(const math::Vector3 &_center = math::Vector3::Zero);
405 
408  public: void Translate(const math::Vector3 &_vec);
409 
412  public: void SetScale(const math::Vector3 &_factor);
413 
415  private: std::vector< math::Vector3 > vertices;
416 
418  private: std::vector< math::Vector3 > normals;
419 
421  private: std::vector< math::Vector2d > texCoords;
422 
424  private: std::vector<unsigned int> indices;
425 
427  private: std::vector<NodeAssignment> nodeAssignments;
428 
430  private: PrimitiveType primitiveType;
431 
434  private: int materialIndex;
435 
437  private: std::string name;
438  };
440  }
441 }
442 
443 #endif
A 3D mesh.
Definition: Mesh.hh:40
A skeleton.
Definition: Skeleton.hh:50
Encapsulates description of a material.
Definition: common/Material.hh:34
Generic double x, y vector.
Definition: Vector2d.hh:39
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
A child mesh.
Definition: Mesh.hh:209
unsigned int nodeIndex
node (or bone) index
Definition: Mesh.hh:202
unsigned int vertexIndex
index of the vertex
Definition: Mesh.hh:199
PrimitiveType
An enumeration of the geometric mesh primitives.
Definition: Mesh.hh:212
Vertex to node weighted assignement for skeleton animation visualization.
Definition: Mesh.hh:193
static const Vector3 Zero
math::Vector3(0, 0, 0)
Definition: Vector3.hh:46
Definition: Mesh.hh:212
float weight
the weight (between 0 and 1)
Definition: Mesh.hh:205
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48