Mesh.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 _GAZEBO_MESH_HH_
18 #define _GAZEBO_MESH_HH_
19 
20 #include <vector>
21 #include <string>
22 
23 #include <ignition/math/Vector3.hh>
24 #include <ignition/math/Vector2.hh>
25 
27 #include "gazebo/util/system.hh"
28 
29 namespace gazebo
30 {
31  namespace common
32  {
33  class Material;
34  class SubMesh;
35  class Skeleton;
36 
39 
42  class GZ_COMMON_VISIBLE Mesh
43  {
45  public: Mesh();
46 
48  public: virtual ~Mesh();
49 
52  public: void SetPath(const std::string &_path);
53 
56  public: std::string GetPath() const;
57 
60  public: void SetName(const std::string &_n);
61 
64  public: std::string GetName() const;
65 
68  public: ignition::math::Vector3d Max() const;
69 
72  public: ignition::math::Vector3d Min() const;
73 
76  public: unsigned int GetVertexCount() const;
77 
80  public: unsigned int GetNormalCount() const;
81 
84  public: unsigned int GetIndexCount() const;
85 
88  public: unsigned int GetTexCoordCount() const;
89 
93  public: void AddSubMesh(SubMesh *_child);
94 
97  public: unsigned int GetSubMeshCount() const;
98 
102  public: int AddMaterial(Material *_mat);
103 
106  public: unsigned int GetMaterialCount() const;
107 
111  public: const Material *GetMaterial(int _index) const;
112 
116  public: int GetMaterialIndex(const Material *_mat) const;
117 
122  public: const SubMesh *GetSubMesh(unsigned int _i) const;
123 
127  public: const SubMesh *GetSubMesh(const std::string &_name) const;
128 
132  public: void FillArrays(float **_vertArr, int **_indArr) const;
133 
136  public: void RecalculateNormals();
137 
142  public: void GetAABB(ignition::math::Vector3d &_center,
143  ignition::math::Vector3d &_minXYZ,
144  ignition::math::Vector3d &_maxXYZ) const;
145 
149  public: void GenSphericalTexCoord(
150  const ignition::math::Vector3d &_center);
151 
154  public: Skeleton* GetSkeleton() const;
155 
157  public: void SetSkeleton(Skeleton *_skel);
158 
160  public: bool HasSkeleton() const;
161 
164  public: void Scale(double _factor);
165 
168  public: void SetScale(const ignition::math::Vector3d &_factor);
169 
173  public: void Center(const ignition::math::Vector3d &_center =
174  ignition::math::Vector3d::Zero);
175 
178  public: void Translate(const ignition::math::Vector3d &_vec);
179 
181  private: std::string name;
182 
184  private: std::string path;
185 
187  private: std::vector<SubMesh *> submeshes;
188 
190  private: std::vector<Material *> materials;
191 
193  private: Skeleton *skeleton;
194  };
195 
198  class GZ_COMMON_VISIBLE NodeAssignment
199  {
201  public: NodeAssignment();
202 
204  public: unsigned int vertexIndex;
205 
207  public: unsigned int nodeIndex;
208 
210  public: float weight;
211  };
212 
214  class GZ_COMMON_VISIBLE SubMesh
215  {
217  public: enum PrimitiveType {POINTS, LINES, LINESTRIPS, TRIANGLES,
218  TRIFANS, TRISTRIPS};
219 
221  public: SubMesh();
222 
224  // cppcheck-suppress noExplicitConstructor
225  public: SubMesh(const SubMesh *_mesh);
226 
228  public: virtual ~SubMesh();
229 
232  public: void SetName(const std::string &_n);
233 
236  public: std::string GetName() const;
237 
240  public: void SetPrimitiveType(PrimitiveType _type);
241 
244  public: PrimitiveType GetPrimitiveType() const;
245 
248  public: void CopyVertices(
249  const std::vector<ignition::math::Vector3d> &_verts);
250 
253  public: void CopyNormals(
254  const std::vector<ignition::math::Vector3d> &_norms);
255 
258  public: void SetVertexCount(unsigned int _count);
259 
262  public: void SetIndexCount(unsigned int _count);
263 
266  public: void SetNormalCount(unsigned int _count);
267 
270  public: void SetTexCoordCount(unsigned int _count);
271 
274  public: void AddIndex(unsigned int _i);
275 
278  public: void AddVertex(const ignition::math::Vector3d &_v);
279 
284  public: void AddVertex(double _x, double _y, double _z);
285 
288  public: void AddNormal(const ignition::math::Vector3d &_n);
289 
294  public: void AddNormal(double _x, double _y, double _z);
295 
299  public: void AddTexCoord(double _u, double _v);
300 
305  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
306  float _weight);
307 
311  public: ignition::math::Vector3d Vertex(unsigned int _i) const;
312 
316  public: void SetVertex(unsigned int _i,
317  const ignition::math::Vector3d &_v);
318 
322  public: ignition::math::Vector3d Normal(unsigned int _i) const;
323 
327  public: void SetNormal(unsigned int _i,
328  const ignition::math::Vector3d &_n);
329 
333  public: ignition::math::Vector2d TexCoord(unsigned int _i) const;
334 
337  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
338 
342  public: void SetTexCoord(unsigned int _i,
343  const ignition::math::Vector2d &_t);
344 
347  public: unsigned int GetIndex(unsigned int _i) const;
348 
351  public: ignition::math::Vector3d Max() const;
352 
355  public: ignition::math::Vector3d Min() const;
356 
358  public: unsigned int GetVertexCount() const;
359 
361  public: unsigned int GetNormalCount() const;
362 
364  public: unsigned int GetIndexCount() const;
365 
367  public: unsigned int GetTexCoordCount() const;
368 
370  public: unsigned int GetNodeAssignmentsCount() const;
371 
373  public: unsigned int GetMaxIndex() const;
374 
378  public: void SetMaterialIndex(unsigned int _index);
379 
381  public: unsigned int GetMaterialIndex() const;
382 
386  public: bool HasVertex(const ignition::math::Vector3d &_v) const;
387 
391  public: unsigned int GetVertexIndex(
392  const ignition::math::Vector3d &_v) const;
393 
397  public: void FillArrays(float **_vertArr, int **_indArr) const;
398 
400  public: void RecalculateNormals();
401 
405  public: void GenSphericalTexCoord(
406  const ignition::math::Vector3d &_center);
407 
410  public: void Scale(double _factor);
411 
415  public: void Center(const ignition::math::Vector3d &_center =
416  ignition::math::Vector3d::Zero);
417 
420  public: void Translate(const ignition::math::Vector3d &_vec);
421 
424  public: void SetScale(const ignition::math::Vector3d &_factor);
425 
427  private: std::vector<ignition::math::Vector3d> vertices;
428 
430  private: std::vector<ignition::math::Vector3d> normals;
431 
433  private: std::vector<ignition::math::Vector2d> texCoords;
434 
436  private: std::vector<unsigned int> indices;
437 
439  private: std::vector<NodeAssignment> nodeAssignments;
440 
442  private: PrimitiveType primitiveType;
443 
446  private: int materialIndex;
447 
449  private: std::string name;
450  };
452  }
453 }
454 
455 #endif
A 3D mesh.
Definition: Mesh.hh:42
PrimitiveType
An enumeration of the geometric mesh primitives.
Definition: Mesh.hh:217
A skeleton.
Definition: Skeleton.hh:52
Encapsulates description of a material.
Definition: common/Material.hh:34
Forward declarations for the common classes.
Definition: Animation.hh:26
A child mesh.
Definition: Mesh.hh:214
float weight
the weight (between 0 and 1)
Definition: Mesh.hh:210
unsigned int nodeIndex
node (or bone) index
Definition: Mesh.hh:207
Vertex to node weighted assignement for skeleton animation visualization.
Definition: Mesh.hh:198
Definition: Mesh.hh:217
unsigned int vertexIndex
index of the vertex
Definition: Mesh.hh:204