Public Member Functions | Private Attributes | List of all members
rviz::MeshShape Class Reference

This class allows constructing Ogre shapes manually, from triangle lists. More...

#include <mesh_shape.h>

Inheritance diagram for rviz::MeshShape:
Inheritance graph
[legend]

Public Member Functions

void addColor (const Ogre::ColourValue &color)
 Add color for a vertex. More...
 
void addNormal (const Ogre::Vector3 &normal)
 Add normal for a vertex. More...
 
void addTriangle (unsigned int p1, unsigned int p2, unsigned int p3)
 Add a triangle by indexing in the defined vertices. More...
 
void addVertex (const Ogre::Vector3 &position)
 Add a vertex to the mesh (no normal defined). If using this function only (not using addTriangle()) it is assumed that triangles are added by specifying the 3 vertices in order (3 consecutive calls to this function). This means there must be 3*n calls to this function to add n triangles. If addTriangle() is used, indexing in the defined vertices is done. More...
 
void addVertex (const Ogre::Vector3 &position, const Ogre::Vector3 &normal)
 Add a vertex to the mesh with a normal defined. If using this function only (not using addTriangle()) it is assumed that triangles are added by specifying the 3 vertices in order (3 consecutive calls to this function). This means there must be 3*n calls to this function to add n triangles.If addTriangle() is used, indexing in the defined vertices is done. More...
 
void addVertex (const Ogre::Vector3 &position, const Ogre::Vector3 &normal, const Ogre::ColourValue &color)
 Add a vertex to the mesh with normal and color defined. If using this function only (not using addTriangle()) it is assumed that triangles are added by specifying the 3 vertices in order (3 consecutive calls to this function). This means there must be 3*n calls to this function to add n triangles.If addTriangle() is used, indexing in the defined vertices is done. More...
 
void beginTriangles ()
 Start adding triangles to the mesh. More...
 
void clear ()
 Clear the mesh. More...
 
void endTriangles ()
 Notify that the set of triangles to add is complete. No more triangles can be added, beginTriangles() can no longer be called unless clear() was called. More...
 
void estimateVertexCount (size_t vcount)
 
Ogre::ManualObject * getManualObject ()
 Get the manual object created for the mesh. More...
 
 MeshShape (Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node=nullptr)
 Constructor. More...
 
 ~MeshShape () override
 
- Public Member Functions inherited from rviz::Shape
Ogre::Entity * getEntity ()
 
Ogre::MaterialPtr getMaterial ()
 
const Ogre::Quaternion & getOrientation () override
 Get the local orientation of this object. More...
 
const Ogre::Vector3 & getPosition () override
 Get the local position of this object. More...
 
Ogre::SceneNode * getRootNode ()
 Get the root scene node (pivot node) for this object. More...
 
Type getType ()
 
void setColor (float r, float g, float b, float a) override
 Set the color of the object. Values are in the range [0, 1]. More...
 
void setColor (const Ogre::ColourValue &c)
 
void setOffset (const Ogre::Vector3 &offset)
 Set the offset for this shape. More...
 
void setOrientation (const Ogre::Quaternion &orientation) override
 Set the orientation of the object. More...
 
void setPosition (const Ogre::Vector3 &position) override
 Set the position of this object. More...
 
void setScale (const Ogre::Vector3 &scale) override
 Set the scale of the object. Always relative to the identity orientation of the object. More...
 
void setUserData (const Ogre::Any &data) override
 Sets user data on all ogre objects we own. More...
 
 Shape (Type shape_type, Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node=nullptr)
 Constructor. More...
 
 ~Shape () override
 
- Public Member Functions inherited from rviz::Object
 Object (Ogre::SceneManager *scene_manager)
 
virtual ~Object ()
 

Private Attributes

Ogre::ManualObject * manual_object_
 
bool started_
 

Additional Inherited Members

- Public Types inherited from rviz::Shape
enum  Type {
  Cone, Cube, Cylinder, Sphere,
  Mesh
}
 
- Static Public Member Functions inherited from rviz::Shape
static Ogre::Entity * createEntity (const std::string &name, Type shape_type, Ogre::SceneManager *scene_manager)
 
- Protected Attributes inherited from rviz::Shape
Ogre::Entity * entity_
 
Ogre::MaterialPtr material_
 
std::string material_name_
 
Ogre::SceneNode * offset_node_
 
Ogre::SceneNode * scene_node_
 
Type type_
 
- Protected Attributes inherited from rviz::Object
Ogre::SceneManager * scene_manager_
 Ogre scene manager this object is part of. More...
 

Detailed Description

This class allows constructing Ogre shapes manually, from triangle lists.

For example: Assuming we have a set of mesh triangles represented like this:

struct Triangle
{
  unsigned v1, v2, v3; // index for the 3 vertices that make up a triangle
};
std::vector<Triangle> triangles;
std::vector<Ogre::Vector3> vertices;
std::vector<Ogre::Vector3> normals; // normal at every vertex

we can use this class to render the mesh as follows:

rviz::MeshShape *shape = new MeshShape(scene_manager);
mesh->estimateVertexCount(vertices.size());
mesh->beginTriangles();
for (std::size_t i = 0 ; i < vertices.size() ; ++i)
  mesh->addVertex(vertices[i], normals[i]);
for (std::size_t i = 0 ; i < triangles.size() ; ++i)
  mesh->addTriangle(triangles[i].v1, triangles[i].v2, triangles[i].v3);
mesh->endTriangles();

Definition at line 68 of file mesh_shape.h.

Constructor & Destructor Documentation

◆ MeshShape()

rviz::MeshShape::MeshShape ( Ogre::SceneManager *  scene_manager,
Ogre::SceneNode *  parent_node = nullptr 
)

Constructor.

Parameters
scene_managerThe scene manager this object is associated with
parent_nodeA scene node to use as the parent of this object. If NULL, uses the root scene node.

Definition at line 45 of file mesh_shape.cpp.

◆ ~MeshShape()

rviz::MeshShape::~MeshShape ( )
override

Definition at line 54 of file mesh_shape.cpp.

Member Function Documentation

◆ addColor()

void rviz::MeshShape::addColor ( const Ogre::ColourValue &  color)

Add color for a vertex.

Definition at line 109 of file mesh_shape.cpp.

◆ addNormal()

void rviz::MeshShape::addNormal ( const Ogre::Vector3 &  normal)

Add normal for a vertex.

Definition at line 104 of file mesh_shape.cpp.

◆ addTriangle()

void rviz::MeshShape::addTriangle ( unsigned int  p1,
unsigned int  p2,
unsigned int  p3 
)

Add a triangle by indexing in the defined vertices.

Definition at line 114 of file mesh_shape.cpp.

◆ addVertex() [1/3]

void rviz::MeshShape::addVertex ( const Ogre::Vector3 &  position)

Add a vertex to the mesh (no normal defined). If using this function only (not using addTriangle()) it is assumed that triangles are added by specifying the 3 vertices in order (3 consecutive calls to this function). This means there must be 3*n calls to this function to add n triangles. If addTriangle() is used, indexing in the defined vertices is done.

Definition at line 81 of file mesh_shape.cpp.

◆ addVertex() [2/3]

void rviz::MeshShape::addVertex ( const Ogre::Vector3 &  position,
const Ogre::Vector3 &  normal 
)

Add a vertex to the mesh with a normal defined. If using this function only (not using addTriangle()) it is assumed that triangles are added by specifying the 3 vertices in order (3 consecutive calls to this function). This means there must be 3*n calls to this function to add n triangles.If addTriangle() is used, indexing in the defined vertices is done.

Definition at line 87 of file mesh_shape.cpp.

◆ addVertex() [3/3]

void rviz::MeshShape::addVertex ( const Ogre::Vector3 &  position,
const Ogre::Vector3 &  normal,
const Ogre::ColourValue &  color 
)

Add a vertex to the mesh with normal and color defined. If using this function only (not using addTriangle()) it is assumed that triangles are added by specifying the 3 vertices in order (3 consecutive calls to this function). This means there must be 3*n calls to this function to add n triangles.If addTriangle() is used, indexing in the defined vertices is done.

Definition at line 94 of file mesh_shape.cpp.

◆ beginTriangles()

void rviz::MeshShape::beginTriangles ( )

Start adding triangles to the mesh.

Definition at line 66 of file mesh_shape.cpp.

◆ clear()

void rviz::MeshShape::clear ( )

Clear the mesh.

Definition at line 141 of file mesh_shape.cpp.

◆ endTriangles()

void rviz::MeshShape::endTriangles ( )

Notify that the set of triangles to add is complete. No more triangles can be added, beginTriangles() can no longer be called unless clear() was called.

Definition at line 119 of file mesh_shape.cpp.

◆ estimateVertexCount()

void rviz::MeshShape::estimateVertexCount ( size_t  vcount)

Definition at line 60 of file mesh_shape.cpp.

◆ getManualObject()

Ogre::ManualObject* rviz::MeshShape::getManualObject ( )
inline

Get the manual object created for the mesh.

Definition at line 129 of file mesh_shape.h.

Member Data Documentation

◆ manual_object_

Ogre::ManualObject* rviz::MeshShape::manual_object_
private

Definition at line 137 of file mesh_shape.h.

◆ started_

bool rviz::MeshShape::started_
private

Definition at line 136 of file mesh_shape.h.


The documentation for this class was generated from the following files:


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Aug 15 2022 02:05:18