Ignition Common

API Reference

3.14.0
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 <ignition/math/Vector3.hh>
25 #include <ignition/math/Vector2.hh>
26 
28 #include <ignition/common/graphics/Export.hh>
30 
31 namespace ignition
32 {
33  namespace common
34  {
35  class Material;
36  class Skeleton;
37  class MeshPrivate;
38 
41  class IGNITION_COMMON_GRAPHICS_VISIBLE Mesh
42  {
44  public: Mesh();
45 
47  public: virtual ~Mesh();
48 
51  public: void SetPath(const std::string &_path);
52 
55  public: std::string Path() const;
56 
59  public: void SetName(const std::string &_name);
60 
63  public: std::string Name() const;
64 
67  public: ignition::math::Vector3d Max() const;
68 
71  public: ignition::math::Vector3d Min() const;
72 
75  public: unsigned int VertexCount() const;
76 
79  public: unsigned int NormalCount() const;
80 
83  public: unsigned int IndexCount() const;
84 
87  public: unsigned int TexCoordCount() const;
88 
94  public: std::weak_ptr<SubMesh> AddSubMesh(const SubMesh &_child);
95 
101  std::unique_ptr<SubMesh> _child);
102 
105  public: unsigned int SubMeshCount() const;
106 
110  public: int AddMaterial(const MaterialPtr &_mat);
111 
114  public: unsigned int MaterialCount() const;
115 
119  public: MaterialPtr MaterialByIndex(const unsigned int _index) const;
120 
125  public: int IndexOfMaterial(const Material *_mat) const;
126 
131  const unsigned int _index) const;
132 
137  const std::string &_name) const;
138 
142  public: void FillArrays(double **_vertArr, int **_indArr) const;
143 
146  public: void RecalculateNormals();
147 
152  public: void AABB(ignition::math::Vector3d &_center,
153  ignition::math::Vector3d &_minXYZ,
154  ignition::math::Vector3d &_maxXYZ) const;
155 
159  public: void GenSphericalTexCoord(
160  const ignition::math::Vector3d &_center);
161 
164  public: SkeletonPtr MeshSkeleton() const;
165 
168  public: void SetSkeleton(const SkeletonPtr &_skel);
169 
172  public: bool HasSkeleton() const;
173 
176  public: void Scale(const ignition::math::Vector3d &_factor);
177 
180  public: void SetScale(const ignition::math::Vector3d &_factor);
181 
185  public: void Center(const ignition::math::Vector3d &_center =
187 
190  public: void Translate(const ignition::math::Vector3d &_vec);
191 
204  public: double Volume() const;
205 
208  private: std::unique_ptr<MeshPrivate> dataPtr;
210  };
211  }
212 }
213 
214 #endif
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: SuppressWarning.hh:64
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
Encapsulates description of a material.
Definition: Material.hh:39
A 3D mesh.
Definition: Mesh.hh:42
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: SubMesh.hh:41
static const Vector3 Zero
Forward declarations for the common classes.