Gazebo Common

API Reference

4.8.1
gz/common/Mesh.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 IGNITION_COMMON_MESH_HH_
18 #define IGNITION_COMMON_MESH_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include <gz/math/Vector3.hh>
25 #include <gz/math/Vector2.hh>
26 
27 #include <ignition/utils/ImplPtr.hh>
28 
29 #include <gz/common/config.hh>
31 #include <gz/common/graphics/Export.hh>
32 
33 namespace ignition
34 {
35  namespace common
36  {
37  class Material;
38  class Skeleton;
39 
42  class IGNITION_COMMON_GRAPHICS_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 Path() const;
57 
60  public: void SetName(const std::string &_name);
61 
64  public: std::string Name() const;
65 
68  public: ignition::math::Vector3d Max() const;
69 
72  public: ignition::math::Vector3d Min() const;
73 
76  public: unsigned int VertexCount() const;
77 
80  public: unsigned int NormalCount() const;
81 
84  public: unsigned int IndexCount() const;
85 
88  public: unsigned int TexCoordCount() const;
89 
95  public: std::weak_ptr<SubMesh> AddSubMesh(const SubMesh &_child);
96 
102  std::unique_ptr<SubMesh> _child);
103 
106  public: unsigned int SubMeshCount() const;
107 
111  public: int AddMaterial(const MaterialPtr &_mat);
112 
115  public: unsigned int MaterialCount() const;
116 
120  public: MaterialPtr MaterialByIndex(const unsigned int _index) const;
121 
126  public: int IndexOfMaterial(const Material *_mat) const;
127 
132  const unsigned int _index) const;
133 
138  const std::string &_name) const;
139 
143  public: void FillArrays(double **_vertArr, int **_indArr) const;
144 
147  public: void RecalculateNormals();
148 
153  public: void AABB(ignition::math::Vector3d &_center,
154  ignition::math::Vector3d &_minXYZ,
155  ignition::math::Vector3d &_maxXYZ) const;
156 
160  public: void GenSphericalTexCoord(
161  const ignition::math::Vector3d &_center);
162 
165  public: SkeletonPtr MeshSkeleton() const;
166 
169  public: void SetSkeleton(const SkeletonPtr &_skel);
170 
173  public: bool HasSkeleton() const;
174 
177  public: void Scale(const ignition::math::Vector3d &_factor);
178 
181  public: void SetScale(const ignition::math::Vector3d &_factor);
182 
186  public: void Center(const ignition::math::Vector3d &_center =
188 
191  public: void Translate(const ignition::math::Vector3d &_vec);
192 
205  public: double Volume() const;
206 
208  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
209  };
210  }
211 }
212 
213 #endif
Encapsulates description of a material.
Definition: gz/common/Material.hh:39
A 3D mesh.
Definition: gz/common/Mesh.hh:43
void Scale(const ignition::math::Vector3d &_factor)
Scale all vertices by _factor.
void Translate(const ignition::math::Vector3d &_vec)
Move all vertices in all submeshes by _vec.
unsigned int IndexCount() const
Get the number of indices.
void SetName(const std::string &_name)
Set the name of this mesh.
void Center(const ignition::math::Vector3d &_center=ignition::math::Vector3d::Zero)
Move the center of the mesh to the given coordinate in the mesh frame. This will move all the vertice...
int IndexOfMaterial(const Material *_mat) const
Get the index of material.
std::weak_ptr< SubMesh > AddSubMesh(const SubMesh &_child)
Add a submesh mesh. This can be an expensive since _child is copied into this mesh.
int AddMaterial(const MaterialPtr &_mat)
Add a material to the mesh.
std::string Path() const
Get the path which contains the mesh resource.
void FillArrays(double **_vertArr, int **_indArr) const
Put all the data into flat arrays.
std::string Name() const
Get the name of this mesh.
void RecalculateNormals()
Recalculate all the normals of each face defined by three indices.
double Volume() const
Compute the volume of this mesh. The primitive type must be TRIANGLES.
void SetPath(const std::string &_path)
Set the path which contains the mesh resource.
std::weak_ptr< SubMesh > SubMeshByIndex(const unsigned int _index) const
Get a child submesh by index.
unsigned int SubMeshCount() const
Get the number of child submeshes.
void AABB(ignition::math::Vector3d &_center, ignition::math::Vector3d &_minXYZ, ignition::math::Vector3d &_maxXYZ) const
Get axis-aligned bounding box in the mesh frame.
virtual ~Mesh()
Destructor.
ignition::math::Vector3d Min() const
Get the minimum X, Y, Z values.
unsigned int NormalCount() const
Get the number of normals.
ignition::math::Vector3d Max() const
Get the maximun X, Y, Z values.
unsigned int TexCoordCount() const
Get the number of texture coordinates.
bool HasSkeleton() const
Check if mesh is attached to a skeleton.
std::weak_ptr< SubMesh > SubMeshByName(const std::string &_name) const
Get a child submesh by name.
void SetScale(const ignition::math::Vector3d &_factor)
Set the scale all vertices.
void GenSphericalTexCoord(const ignition::math::Vector3d &_center)
Generate texture coordinates using spherical projection from center.
SkeletonPtr MeshSkeleton() const
Get the skeleton to which this mesh is attached.
std::weak_ptr< SubMesh > AddSubMesh(std::unique_ptr< SubMesh > _child)
Add a submesh mesh. This transfers ownership of _child to this mesh. The value of _child after this c...
unsigned int MaterialCount() const
Get the number of materials.
unsigned int VertexCount() const
Get the number of vertices.
void SetSkeleton(const SkeletonPtr &_skel)
Set the mesh skeleton.
MaterialPtr MaterialByIndex(const unsigned int _index) const
Get a material by index.
A child mesh.
Definition: gz/common/SubMesh.hh:43
static const Vector3 Zero
Forward declarations for the common classes.