##

Mesh.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _GAZEBO_MESH_HH_
#define _GAZEBO_MESH_HH_
#include <vector>
#include <string>
#include <ignition/math/Vector3.hh>
#include <ignition/math/Vector2.hh>
#include "gazebo/common/CommonTypes.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace common
{
class Material;
class SubMesh;
class Skeleton;
class GZ_COMMON_VISIBLE Mesh
{
public: Mesh();
public: virtual ~Mesh();
public: void SetPath(const std::string &_path);
public: std::string GetPath() const;
public: void SetName(const std::string &_n);
public: std::string GetName() const;
public: ignition::math::Vector3d Max() const;
public: ignition::math::Vector3d Min() const;
public: unsigned int GetVertexCount() const;
public: unsigned int GetNormalCount() const;
public: unsigned int GetIndexCount() const;
public: unsigned int GetTexCoordCount() const;
public: void AddSubMesh(SubMesh *_child);
public: unsigned int GetSubMeshCount() const;
public: int AddMaterial(Material *_mat);
public: unsigned int GetMaterialCount() const;
public: const Material *GetMaterial(int _index) const;
public: int GetMaterialIndex(const Material *_mat) const;
public: const SubMesh *GetSubMesh(unsigned int _i) const;
public: const SubMesh *GetSubMesh(const std::string &_name) const;
public: void FillArrays(float **_vertArr, int **_indArr) const;
public: void RecalculateNormals();
public: void GetAABB(ignition::math::Vector3d &_center,
ignition::math::Vector3d &_minXYZ,
ignition::math::Vector3d &_maxXYZ) const;
public: void GenSphericalTexCoord(
const ignition::math::Vector3d &_center);
public: Skeleton* GetSkeleton() const;
public: void SetSkeleton(Skeleton *_skel);
public: bool HasSkeleton() const;
public: void Scale(double _factor);
public: void SetScale(const ignition::math::Vector3d &_factor);
public: void Center(const ignition::math::Vector3d &_center =
ignition::math::Vector3d::Zero);
public: void Translate(const ignition::math::Vector3d &_vec);
private: std::string name;
private: std::string path;
private: std::vector<SubMesh *> submeshes;
private: std::vector<Material *> materials;
private: Skeleton *skeleton;
};
class GZ_COMMON_VISIBLE NodeAssignment
{
public: NodeAssignment();
public: unsigned int vertexIndex;
public: unsigned int nodeIndex;
public: float weight;
};
class GZ_COMMON_VISIBLE SubMesh
{
public: enum PrimitiveType {POINTS, LINES, LINESTRIPS, TRIANGLES,
TRIFANS, TRISTRIPS};
public: SubMesh();
// cppcheck-suppress noExplicitConstructor
public: SubMesh(const SubMesh *_mesh);
public: virtual ~SubMesh();
public: void SetName(const std::string &_n);
public: std::string GetName() const;
public: void SetPrimitiveType(PrimitiveType _type);
public: PrimitiveType GetPrimitiveType() const;
public: void CopyVertices(
const std::vector<ignition::math::Vector3d> &_verts);
public: void CopyNormals(
const std::vector<ignition::math::Vector3d> &_norms);
public: void SetVertexCount(unsigned int _count);
public: void SetIndexCount(unsigned int _count);
public: void SetNormalCount(unsigned int _count);
public: void SetTexCoordCount(unsigned int _count);
public: void AddIndex(unsigned int _i);
public: void AddVertex(const ignition::math::Vector3d &_v);
public: void AddVertex(double _x, double _y, double _z);
public: void AddNormal(const ignition::math::Vector3d &_n);
public: void AddNormal(double _x, double _y, double _z);
public: void AddTexCoord(double _u, double _v);
public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
float _weight);
public: ignition::math::Vector3d Vertex(unsigned int _i) const;
public: void SetVertex(unsigned int _i,
const ignition::math::Vector3d &_v);
public: ignition::math::Vector3d Normal(unsigned int _i) const;
public: void SetNormal(unsigned int _i,
const ignition::math::Vector3d &_n);
public: ignition::math::Vector2d TexCoord(unsigned int _i) const;
public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
public: void SetTexCoord(unsigned int _i,
const ignition::math::Vector2d &_t);
public: unsigned int GetIndex(unsigned int _i) const;
public: ignition::math::Vector3d Max() const;
public: ignition::math::Vector3d Min() const;
public: unsigned int GetVertexCount() const;
public: unsigned int GetNormalCount() const;
public: unsigned int GetIndexCount() const;
public: unsigned int GetTexCoordCount() const;
public: unsigned int GetNodeAssignmentsCount() const;
public: unsigned int GetMaxIndex() const;
public: void SetMaterialIndex(unsigned int _index);
public: unsigned int GetMaterialIndex() const;
public: bool HasVertex(const ignition::math::Vector3d &_v) const;
public: unsigned int GetVertexIndex(
const ignition::math::Vector3d &_v) const;
public: void FillArrays(float **_vertArr, int **_indArr) const;
public: void RecalculateNormals();
public: void GenSphericalTexCoord(
const ignition::math::Vector3d &_center);
public: void Scale(double _factor);
public: void Center(const ignition::math::Vector3d &_center =
ignition::math::Vector3d::Zero);
public: void Translate(const ignition::math::Vector3d &_vec);
public: void SetScale(const ignition::math::Vector3d &_factor);
private: std::vector<ignition::math::Vector3d> vertices;
private: std::vector<ignition::math::Vector3d> normals;
private: std::vector<ignition::math::Vector2d> texCoords;
private: std::vector<unsigned int> indices;
private: std::vector<NodeAssignment> nodeAssignments;
private: PrimitiveType primitiveType;
private: int materialIndex;
private: std::string name;
};
}
}
#endif
gazebo::common::SubMesh::FillArrays
void FillArrays(float **_vertArr, int **_indArr) const
Put all the data into flat arrays.
gazebo::common::Mesh::GetMaterialCount
unsigned int GetMaterialCount() const
Get the number of materials.
gazebo::common::SubMesh::Center
void Center(const ignition::math::Vector3d &_center=ignition::math::Vector3d::Zero)
Move the center of the submesh to the given coordinate.
gazebo::common::Mesh::GetSubMeshCount
unsigned int GetSubMeshCount() const
Get the number of children.
gazebo::common::SubMesh::SetTexCoordCount
void SetTexCoordCount(unsigned int _count)
Resize the texture coordinate array.
gazebo::common::SubMesh::TRIFANS
Definition: Mesh.hh:218
gazebo::common::Mesh::Center
void Center(const ignition::math::Vector3d &_center=ignition::math::Vector3d::Zero)
Move the center of the mesh to the given coordinate.
gazebo::common::SubMesh::RecalculateNormals
void RecalculateNormals()
Recalculate all the normals.
gazebo::common::SubMesh::Scale
void Scale(double _factor)
Scale all vertices by _factor.
gazebo::common::SubMesh::SetVertex
void SetVertex(unsigned int _i, const ignition::math::Vector3d &_v)
Set a vertex.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::SubMesh::GetIndex
unsigned int GetIndex(unsigned int _i) const
Get an index.
gazebo::common::Mesh::AddMaterial
int AddMaterial(Material *_mat)
Add a material to the mesh.
gazebo::common::Mesh::Min
ignition::math::Vector3d Min() const
Get the minimum X, Y, Z values.
gazebo::common::SubMesh::POINTS
Definition: Mesh.hh:217
gazebo::common::NodeAssignment::weight
float weight
the weight (between 0 and 1)
Definition: Mesh.hh:210
gazebo::common::SubMesh::Min
ignition::math::Vector3d Min() const
Get the minimum X, Y, Z values from all the vertices.
gazebo::common::SubMesh::LINESTRIPS
Definition: Mesh.hh:217
gazebo::common::SubMesh::TRISTRIPS
Definition: Mesh.hh:218
gazebo::common::SubMesh::SubMesh
SubMesh()
Constructor.
gazebo::common::SubMesh::SetMaterialIndex
void SetMaterialIndex(unsigned int _index)
Set the material index.
common
common
Definition: FuelModelDatabase.hh:37
gazebo::common::SubMesh::GetMaterialIndex
unsigned int GetMaterialIndex() const
Get the material index.
gazebo::common::SubMesh::~SubMesh
virtual ~SubMesh()
Destructor.
system.hh
gazebo::common::NodeAssignment
Vertex to node weighted assignement for skeleton animation visualization.
Definition: Mesh.hh:198
gazebo::common::SubMesh::SetVertexCount
void SetVertexCount(unsigned int _count)
Resize the vertex array.
gazebo::common::Mesh::GetAABB
void GetAABB(ignition::math::Vector3d &_center, ignition::math::Vector3d &_minXYZ, ignition::math::Vector3d &_maxXYZ) const
Get AABB coordinate.
gazebo::common::Mesh::AddSubMesh
void AddSubMesh(SubMesh *_child)
Add a submesh mesh.
gazebo::common::SubMesh::TexCoord
ignition::math::Vector2d TexCoord(unsigned int _i) const
Get a tex coord.
gazebo::common::SubMesh::CopyVertices
void CopyVertices(const std::vector< ignition::math::Vector3d > &_verts)
Copy vertices from a vector.
gazebo::common::SubMesh::AddNormal
void AddNormal(const ignition::math::Vector3d &_n)
Add a normal to the mesh.
CommonTypes.hh
gazebo::common::SubMesh::TRIANGLES
Definition: Mesh.hh:217
gazebo::common::Mesh::SetPath
void SetPath(const std::string &_path)
Set the path which contains the mesh resource.
gazebo::common::Mesh::Scale
void Scale(double _factor)
Scale all vertices by _factor.
gazebo::common::SubMesh::GetName
std::string GetName() const
Get the name of this mesh.
gazebo::common::SubMesh
A child mesh.
Definition: Mesh.hh:214
gazebo::common::SubMesh::SetIndexCount
void SetIndexCount(unsigned int _count)
Resize the index array.
gazebo::common::SubMesh::AddNodeAssignment
void AddNodeAssignment(unsigned int _vertex, unsigned int _node, float _weight)
Add a vertex - skeleton node assignment.
gazebo::common::Mesh::GenSphericalTexCoord
void GenSphericalTexCoord(const ignition::math::Vector3d &_center)
Generate texture coordinates using spherical projection from center.
gazebo::common::Mesh::GetPath
std::string GetPath() const
Get the path which contains the mesh resource.
gazebo::common::SubMesh::SetNormalCount
void SetNormalCount(unsigned int _count)
Resize the normal array.
gazebo::common::Mesh::GetMaterialIndex
int GetMaterialIndex(const Material *_mat) const
Get the index of material.
gazebo::common::SubMesh::Normal
ignition::math::Vector3d Normal(unsigned int _i) const
Get a normal.
gazebo::common::Mesh::HasSkeleton
bool HasSkeleton() const
Return true if mesh is attached to a skeleton.
gazebo::common::Mesh::Max
ignition::math::Vector3d Max() const
Get the maximun X, Y, Z values.
gazebo::common::SubMesh::GetVertexIndex
unsigned int GetVertexIndex(const ignition::math::Vector3d &_v) const
Get the index of the vertex.
gazebo::common::SubMesh::GetNormalCount
unsigned int GetNormalCount() const
Return the number of normals.
gazebo::common::SubMesh::GetMaxIndex
unsigned int GetMaxIndex() const
Get the highest index value.
gazebo::common::SubMesh::AddIndex
void AddIndex(unsigned int _i)
Add an index to the mesh.
gazebo::common::SubMesh::HasVertex
bool HasVertex(const ignition::math::Vector3d &_v) const
Return true if this submesh has the vertex.
gazebo::common::SubMesh::PrimitiveType
PrimitiveType
An enumeration of the geometric mesh primitives.
Definition: Mesh.hh:217
gazebo::common::Mesh::GetIndexCount
unsigned int GetIndexCount() const
Return the number of indices.
gazebo::common::SubMesh::SetScale
void SetScale(const ignition::math::Vector3d &_factor)
Scale all vertices by the _factor vector.
gazebo::common::Mesh::SetScale
void SetScale(const ignition::math::Vector3d &_factor)
Scale all vertices by the _factor vector.
gazebo::common::Skeleton
A skeleton.
Definition: Skeleton.hh:52
gazebo::common::SubMesh::SetTexCoord
void SetTexCoord(unsigned int _i, const ignition::math::Vector2d &_t)
Set a tex coord.
gazebo::common::SubMesh::AddVertex
void AddVertex(const ignition::math::Vector3d &_v)
Add a vertex to the mesh.
gazebo::common::Mesh::GetSubMesh
const SubMesh * GetSubMesh(unsigned int _i) const
Get a child mesh.
gazebo::common::SubMesh::SetName
void SetName(const std::string &_n)
Set the name of this mesh.
gazebo::common::SubMesh::GetNodeAssignment
NodeAssignment GetNodeAssignment(unsigned int _i) const
Get a vertex - skeleton node assignment.
gazebo::common::SubMesh::GetPrimitiveType
PrimitiveType GetPrimitiveType() const
Get the primitive type.
gazebo::common::Mesh::GetVertexCount
unsigned int GetVertexCount() const
Return the number of vertices.
gazebo::common::SubMesh::LINES
Definition: Mesh.hh:217
gazebo::common::SubMesh::GetNodeAssignmentsCount
unsigned int GetNodeAssignmentsCount() const
Return the number of vertex - skeleton node assignments.
gazebo::common::Material
Encapsulates description of a material.
Definition: common/Material.hh:35
gazebo::common::Mesh::FillArrays
void FillArrays(float **_vertArr, int **_indArr) const
Put all the data into flat arrays.
gazebo::common::NodeAssignment::nodeIndex
unsigned int nodeIndex
node (or bone) index
Definition: Mesh.hh:207
gazebo::common::Mesh::GetSkeleton
Skeleton * GetSkeleton() const
Get the skeleton to which this mesh is attached.
gazebo::common::NodeAssignment::NodeAssignment
NodeAssignment()
Constructor.
gazebo::common::Mesh::GetNormalCount
unsigned int GetNormalCount() const
Return the number of normals.
gazebo::common::SubMesh::GetIndexCount
unsigned int GetIndexCount() const
Return the number of indicies.
gazebo::common::SubMesh::SetNormal
void SetNormal(unsigned int _i, const ignition::math::Vector3d &_n)
Set a normal.
gazebo::common::SubMesh::SetPrimitiveType
void SetPrimitiveType(PrimitiveType _type)
Set the primitive type.
gazebo::common::SubMesh::Max
ignition::math::Vector3d Max() const
Get the maximum X, Y, Z values from all the vertices.
gazebo::common::SubMesh::CopyNormals
void CopyNormals(const std::vector< ignition::math::Vector3d > &_norms)
Copy normals from a vector.
gazebo::common::Mesh
A 3D mesh.
Definition: Mesh.hh:42
gazebo::common::Mesh::Translate
void Translate(const ignition::math::Vector3d &_vec)
Move all vertices in all submeshes by _vec.
gazebo::common::SubMesh::Translate
void Translate(const ignition::math::Vector3d &_vec)
Move all vertices by _vec.
gazebo::common::Mesh::SetName
void SetName(const std::string &_n)
Set the name of this mesh.
gazebo::common::SubMesh::Vertex
ignition::math::Vector3d Vertex(unsigned int _i) const
Get a vertex.
gazebo::common::SubMesh::GetTexCoordCount
unsigned int GetTexCoordCount() const
Return the number of texture coordinates.
gazebo::common::SubMesh::GenSphericalTexCoord
void GenSphericalTexCoord(const ignition::math::Vector3d &_center)
Generate texture coordinates using spherical projection from center.
gazebo::common::Mesh::~Mesh
virtual ~Mesh()
Destructor.
gazebo::common::Mesh::SetSkeleton
void SetSkeleton(Skeleton *_skel)
Set the mesh skeleton.
gazebo::common::Mesh::GetTexCoordCount
unsigned int GetTexCoordCount() const
Return the number of texture coordinates.
gazebo::common::SubMesh::GetVertexCount
unsigned int GetVertexCount() const
Return the number of vertices.
gazebo::common::Mesh::GetName
std::string GetName() const
Get the name of this mesh.
gazebo::common::Mesh::RecalculateNormals
void RecalculateNormals()
Recalculate all the normals of each face defined by three indices.
gazebo::common::Mesh::Mesh
Mesh()
Constructor.
gazebo::common::SubMesh::AddTexCoord
void AddTexCoord(double _u, double _v)
Add a texture coord to the mesh.
gazebo::common::NodeAssignment::vertexIndex
unsigned int vertexIndex
index of the vertex
Definition: Mesh.hh:204
gazebo::common::Mesh::GetMaterial
const Material * GetMaterial(int _index) const
Get a material.