Mesh.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 
26 #include "gazebo/math/Vector3.hh"
27 #include "gazebo/math/Vector2d.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  namespace common
34  {
35  class Material;
36  class SubMesh;
37  class Skeleton;
38 
41 
45  {
47  public: Mesh();
48 
50  public: virtual ~Mesh();
51 
54  public: void SetPath(const std::string &_path);
55 
58  public: std::string GetPath() const;
59 
62  public: void SetName(const std::string &_n);
63 
66  public: std::string GetName() const;
67 
71  public: math::Vector3 GetMax() const GAZEBO_DEPRECATED(6.0);
72 
75  public: ignition::math::Vector3d Max() const;
76 
80  public: math::Vector3 GetMin() const GAZEBO_DEPRECATED(6.0);
81 
84  public: ignition::math::Vector3d Min() const;
85 
88  public: unsigned int GetVertexCount() const;
89 
92  public: unsigned int GetNormalCount() const;
93 
96  public: unsigned int GetIndexCount() const;
97 
100  public: unsigned int GetTexCoordCount() const;
101 
105  public: void AddSubMesh(SubMesh *_child);
106 
109  public: unsigned int GetSubMeshCount() const;
110 
114  public: int AddMaterial(Material *_mat);
115 
118  public: unsigned int GetMaterialCount() const;
119 
123  public: const Material *GetMaterial(int _index) const;
124 
128  public: int GetMaterialIndex(const Material *_mat) const;
129 
134  public: const SubMesh *GetSubMesh(unsigned int _i) const;
135 
139  public: const SubMesh *GetSubMesh(const std::string &_name) const;
140 
144  public: void FillArrays(float **_vertArr, int **_indArr) const;
145 
148  public: void RecalculateNormals();
149 
156  public: void GetAABB(math::Vector3 &_center, math::Vector3 &_min_xyz,
157  math::Vector3 &_max_xyz) const
158  GAZEBO_DEPRECATED(6.0);
159 
164  public: void GetAABB(ignition::math::Vector3d &_center,
165  ignition::math::Vector3d &_minXYZ,
166  ignition::math::Vector3d &_maxXYZ) const;
167 
173  public: void GenSphericalTexCoord(const math::Vector3 &_center)
174  GAZEBO_DEPRECATED(6.0);
175 
179  public: void GenSphericalTexCoord(
180  const ignition::math::Vector3d &_center);
181 
184  public: Skeleton* GetSkeleton() const;
185 
187  public: void SetSkeleton(Skeleton *_skel);
188 
190  public: bool HasSkeleton() const;
191 
194  public: void Scale(double _factor);
195 
200  public: void SetScale(const math::Vector3 &_factor)
201  GAZEBO_DEPRECATED(6.0);
202 
205  public: void SetScale(const ignition::math::Vector3d &_factor);
206 
212  public: void Center(const math::Vector3 &_center = math::Vector3::Zero)
213  GAZEBO_DEPRECATED(6.0);
214 
218  public: void Center(const ignition::math::Vector3d &_center =
219  ignition::math::Vector3d::Zero);
220 
225  public: void Translate(const math::Vector3 &_vec) GAZEBO_DEPRECATED(6.0);
226 
229  public: void Translate(const ignition::math::Vector3d &_vec);
230 
232  private: std::string name;
233 
235  private: std::string path;
236 
238  private: std::vector<SubMesh *> submeshes;
239 
241  private: std::vector<Material *> materials;
242 
244  private: Skeleton *skeleton;
245  };
246 
250  {
252  public: NodeAssignment();
253 
255  public: unsigned int vertexIndex;
256 
258  public: unsigned int nodeIndex;
259 
261  public: float weight;
262  };
263 
266  {
268  public: enum PrimitiveType {POINTS, LINES, LINESTRIPS, TRIANGLES,
269  TRIFANS, TRISTRIPS};
270 
272  public: SubMesh();
273 
275  public: SubMesh(const SubMesh *_mesh);
276 
278  public: virtual ~SubMesh();
279 
282  public: void SetName(const std::string &_n);
283 
286  public: std::string GetName() const;
287 
290  public: void SetPrimitiveType(PrimitiveType _type);
291 
294  public: PrimitiveType GetPrimitiveType() const;
295 
300  public: void CopyVertices(const std::vector<math::Vector3> &_verts)
301  GAZEBO_DEPRECATED(6.0);
302 
305  public: void CopyVertices(
306  const std::vector<ignition::math::Vector3d> &_verts);
307 
312  public: void CopyNormals(const std::vector<math::Vector3> &_norms)
313  GAZEBO_DEPRECATED(6.0);
314 
317  public: void CopyNormals(
318  const std::vector<ignition::math::Vector3d> &_norms);
319 
322  public: void SetVertexCount(unsigned int _count);
323 
326  public: void SetIndexCount(unsigned int _count);
327 
330  public: void SetNormalCount(unsigned int _count);
331 
334  public: void SetTexCoordCount(unsigned int _count);
335 
338  public: void AddIndex(unsigned int _i);
339 
344  public: void AddVertex(const math::Vector3 &_v) GAZEBO_DEPRECATED(6.0);
345 
348  public: void AddVertex(const ignition::math::Vector3d &_v);
349 
354  public: void AddVertex(double _x, double _y, double _z);
355 
360  public: void AddNormal(const math::Vector3 &_n) GAZEBO_DEPRECATED(6.0);
361 
364  public: void AddNormal(const ignition::math::Vector3d &_n);
365 
370  public: void AddNormal(double _x, double _y, double _z);
371 
375  public: void AddTexCoord(double _u, double _v);
376 
381  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
382  float _weight);
383 
389  public: math::Vector3 GetVertex(unsigned int _i) const
390  GAZEBO_DEPRECATED(6.0);
391 
395  public: ignition::math::Vector3d Vertex(unsigned int _i) const;
396 
402  public: void SetVertex(unsigned int _i, const math::Vector3 &_v)
403  GAZEBO_DEPRECATED(6.0);
404 
408  public: void SetVertex(unsigned int _i,
409  const ignition::math::Vector3d &_v);
410 
416  public: math::Vector3 GetNormal(unsigned int _i) const
417  GAZEBO_DEPRECATED(6.0);
418 
422  public: ignition::math::Vector3d Normal(unsigned int _i) const;
423 
429  public: void SetNormal(unsigned int _i, const math::Vector3 &_n)
430  GAZEBO_DEPRECATED(6.0);
431 
435  public: void SetNormal(unsigned int _i,
436  const ignition::math::Vector3d &_n);
437 
443  public: math::Vector2d GetTexCoord(unsigned int _i) const
444  GAZEBO_DEPRECATED(6.0);
445 
449  public: ignition::math::Vector2d TexCoord(unsigned int _i) const;
450 
453  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
454 
460  public: void SetTexCoord(unsigned int _i, const math::Vector2d &_t)
461  GAZEBO_DEPRECATED(6.0);
462 
466  public: void SetTexCoord(unsigned int _i,
467  const ignition::math::Vector2d &_t);
468 
471  public: unsigned int GetIndex(unsigned int _i) const;
472 
476  public: math::Vector3 GetMax() const GAZEBO_DEPRECATED(6.0);
477 
480  public: ignition::math::Vector3d Max() const;
481 
485  public: math::Vector3 GetMin() const GAZEBO_DEPRECATED(6.0);
486 
489  public: ignition::math::Vector3d Min() const;
490 
492  public: unsigned int GetVertexCount() const;
493 
495  public: unsigned int GetNormalCount() const;
496 
498  public: unsigned int GetIndexCount() const;
499 
501  public: unsigned int GetTexCoordCount() const;
502 
504  public: unsigned int GetNodeAssignmentsCount() const;
505 
507  public: unsigned int GetMaxIndex() const;
508 
512  public: void SetMaterialIndex(unsigned int _index);
513 
515  public: unsigned int GetMaterialIndex() const;
516 
522  public: bool HasVertex(const math::Vector3 &_v) const
523  GAZEBO_DEPRECATED(6.0);
524 
528  public: bool HasVertex(const ignition::math::Vector3d &_v) const;
529 
534  public: unsigned int GetVertexIndex(const math::Vector3 &_v) const
535  GAZEBO_DEPRECATED(6.0);
536 
540  public: unsigned int GetVertexIndex(
541  const ignition::math::Vector3d &_v) const;
542 
546  public: void FillArrays(float **_vertArr, int **_indArr) const;
547 
549  public: void RecalculateNormals();
550 
556  public: void GenSphericalTexCoord(const math::Vector3 &_center)
557  GAZEBO_DEPRECATED(6.0);
558 
562  public: void GenSphericalTexCoord(
563  const ignition::math::Vector3d &_center);
564 
567  public: void Scale(double _factor);
568 
574  public: void Center(const math::Vector3 &_center = math::Vector3::Zero)
575  GAZEBO_DEPRECATED(6.0);
576 
580  public: void Center(const ignition::math::Vector3d &_center =
581  ignition::math::Vector3d::Zero);
582 
587  public: void Translate(const math::Vector3 &_vec) GAZEBO_DEPRECATED(6.0);
588 
591  public: void Translate(const ignition::math::Vector3d &_vec);
592 
597  public: void SetScale(const math::Vector3 &_factor)
598  GAZEBO_DEPRECATED(6.0);
599 
602  public: void SetScale(const ignition::math::Vector3d &_factor);
603 
605  private: std::vector<ignition::math::Vector3d> vertices;
606 
608  private: std::vector<ignition::math::Vector3d> normals;
609 
611  private: std::vector<ignition::math::Vector2d> texCoords;
612 
614  private: std::vector<unsigned int> indices;
615 
617  private: std::vector<NodeAssignment> nodeAssignments;
618 
620  private: PrimitiveType primitiveType;
621 
624  private: int materialIndex;
625 
627  private: std::string name;
628  };
630  }
631 }
632 
633 #endif
A 3D mesh.
Definition: Mesh.hh:44
A skeleton.
Definition: Skeleton.hh:53
Encapsulates description of a material.
Definition: common/Material.hh:34
Generic double x, y vector.
Definition: Vector2d.hh:36
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:47
A child mesh.
Definition: Mesh.hh:265
unsigned int nodeIndex
node (or bone) index
Definition: Mesh.hh:258
#define GZ_COMMON_VISIBLE
Definition: system.hh:91
unsigned int vertexIndex
index of the vertex
Definition: Mesh.hh:255
PrimitiveType
An enumeration of the geometric mesh primitives.
Definition: Mesh.hh:268
Vertex to node weighted assignement for skeleton animation visualization.
Definition: Mesh.hh:249
static const Vector3 Zero
math::Vector3(0, 0, 0)
Definition: Vector3.hh:42
Definition: Mesh.hh:268
float weight
the weight (between 0 and 1)
Definition: Mesh.hh:261