Mesh.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 
70  public: ignition::math::Vector3d Max() const;
71 
74  public: ignition::math::Vector3d Min() const;
75 
78  public: unsigned int GetVertexCount() const;
79 
82  public: unsigned int GetNormalCount() const;
83 
86  public: unsigned int GetIndexCount() const;
87 
90  public: unsigned int GetTexCoordCount() const;
91 
95  public: void AddSubMesh(SubMesh *_child);
96 
99  public: unsigned int GetSubMeshCount() const;
100 
104  public: int AddMaterial(Material *_mat);
105 
108  public: unsigned int GetMaterialCount() const;
109 
113  public: const Material *GetMaterial(int _index) const;
114 
118  public: int GetMaterialIndex(const Material *_mat) const;
119 
124  public: const SubMesh *GetSubMesh(unsigned int _i) const;
125 
129  public: const SubMesh *GetSubMesh(const std::string &_name) const;
130 
134  public: void FillArrays(float **_vertArr, int **_indArr) const;
135 
138  public: void RecalculateNormals();
139 
144  public: void GetAABB(ignition::math::Vector3d &_center,
145  ignition::math::Vector3d &_minXYZ,
146  ignition::math::Vector3d &_maxXYZ) const;
147 
151  public: void GenSphericalTexCoord(
152  const ignition::math::Vector3d &_center);
153 
156  public: Skeleton* GetSkeleton() const;
157 
159  public: void SetSkeleton(Skeleton *_skel);
160 
162  public: bool HasSkeleton() const;
163 
166  public: void Scale(double _factor);
167 
170  public: void SetScale(const ignition::math::Vector3d &_factor);
171 
175  public: void Center(const ignition::math::Vector3d &_center =
176  ignition::math::Vector3d::Zero);
177 
180  public: void Translate(const ignition::math::Vector3d &_vec);
181 
183  private: std::string name;
184 
186  private: std::string path;
187 
189  private: std::vector<SubMesh *> submeshes;
190 
192  private: std::vector<Material *> materials;
193 
195  private: Skeleton *skeleton;
196  };
197 
201  {
203  public: NodeAssignment();
204 
206  public: unsigned int vertexIndex;
207 
209  public: unsigned int nodeIndex;
210 
212  public: float weight;
213  };
214 
217  {
219  public: enum PrimitiveType {POINTS, LINES, LINESTRIPS, TRIANGLES,
220  TRIFANS, TRISTRIPS};
221 
223  public: SubMesh();
224 
226  public: SubMesh(const SubMesh *_mesh);
227 
229  public: virtual ~SubMesh();
230 
233  public: void SetName(const std::string &_n);
234 
237  public: std::string GetName() const;
238 
241  public: void SetPrimitiveType(PrimitiveType _type);
242 
245  public: PrimitiveType GetPrimitiveType() const;
246 
249  public: void CopyVertices(
250  const std::vector<ignition::math::Vector3d> &_verts);
251 
254  public: void CopyNormals(
255  const std::vector<ignition::math::Vector3d> &_norms);
256 
259  public: void SetVertexCount(unsigned int _count);
260 
263  public: void SetIndexCount(unsigned int _count);
264 
267  public: void SetNormalCount(unsigned int _count);
268 
271  public: void SetTexCoordCount(unsigned int _count);
272 
275  public: void AddIndex(unsigned int _i);
276 
279  public: void AddVertex(const ignition::math::Vector3d &_v);
280 
285  public: void AddVertex(double _x, double _y, double _z);
286 
289  public: void AddNormal(const ignition::math::Vector3d &_n);
290 
295  public: void AddNormal(double _x, double _y, double _z);
296 
300  public: void AddTexCoord(double _u, double _v);
301 
306  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
307  float _weight);
308 
312  public: ignition::math::Vector3d Vertex(unsigned int _i) const;
313 
317  public: void SetVertex(unsigned int _i,
318  const ignition::math::Vector3d &_v);
319 
323  public: ignition::math::Vector3d Normal(unsigned int _i) const;
324 
328  public: void SetNormal(unsigned int _i,
329  const ignition::math::Vector3d &_n);
330 
334  public: ignition::math::Vector2d TexCoord(unsigned int _i) const;
335 
338  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
339 
343  public: void SetTexCoord(unsigned int _i,
344  const ignition::math::Vector2d &_t);
345 
348  public: unsigned int GetIndex(unsigned int _i) const;
349 
352  public: ignition::math::Vector3d Max() const;
353 
356  public: ignition::math::Vector3d Min() const;
357 
359  public: unsigned int GetVertexCount() const;
360 
362  public: unsigned int GetNormalCount() const;
363 
365  public: unsigned int GetIndexCount() const;
366 
368  public: unsigned int GetTexCoordCount() const;
369 
371  public: unsigned int GetNodeAssignmentsCount() const;
372 
374  public: unsigned int GetMaxIndex() const;
375 
379  public: void SetMaterialIndex(unsigned int _index);
380 
382  public: unsigned int GetMaterialIndex() const;
383 
387  public: bool HasVertex(const ignition::math::Vector3d &_v) const;
388 
392  public: unsigned int GetVertexIndex(
393  const ignition::math::Vector3d &_v) const;
394 
398  public: void FillArrays(float **_vertArr, int **_indArr) const;
399 
401  public: void RecalculateNormals();
402 
406  public: void GenSphericalTexCoord(
407  const ignition::math::Vector3d &_center);
408 
411  public: void Scale(double _factor);
412 
416  public: void Center(const ignition::math::Vector3d &_center =
417  ignition::math::Vector3d::Zero);
418 
421  public: void Translate(const ignition::math::Vector3d &_vec);
422 
425  public: void SetScale(const ignition::math::Vector3d &_factor);
426 
428  private: std::vector<ignition::math::Vector3d> vertices;
429 
431  private: std::vector<ignition::math::Vector3d> normals;
432 
434  private: std::vector<ignition::math::Vector2d> texCoords;
435 
437  private: std::vector<unsigned int> indices;
438 
440  private: std::vector<NodeAssignment> nodeAssignments;
441 
443  private: PrimitiveType primitiveType;
444 
447  private: int materialIndex;
448 
450  private: std::string name;
451  };
453  }
454 }
455 
456 #endif
A 3D mesh.
Definition: Mesh.hh:44
A skeleton.
Definition: Skeleton.hh:53
Encapsulates description of a material.
Definition: common/Material.hh:34
A child mesh.
Definition: Mesh.hh:216
unsigned int nodeIndex
node (or bone) index
Definition: Mesh.hh:209
#define GZ_COMMON_VISIBLE
Definition: system.hh:84
unsigned int vertexIndex
index of the vertex
Definition: Mesh.hh:206
PrimitiveType
An enumeration of the geometric mesh primitives.
Definition: Mesh.hh:219
Vertex to node weighted assignement for skeleton animation visualization.
Definition: Mesh.hh:200
Definition: Mesh.hh:219
float weight
the weight (between 0 and 1)
Definition: Mesh.hh:212