34#include <OgreMeshManager.h>
35#include <OgreSceneManager.h>
36#include <OgreSceneNode.h>
37#include <OgreEntity.h>
38#include <OgreMaterialManager.h>
39#include <OgreManualObject.h>
41#include <rviz_common/logging.hpp>
47 : Shape(Shape::Mesh, scene_manager, parent_node), started_(false)
49 static uint32_t count = 0;
50 manual_object_ = scene_manager->createManualObject(
"MeshShape_ManualObject" + std::to_string(count++));
51 material_->setCullingMode(Ogre::CULL_NONE);
57 scene_manager_->destroyManualObject(manual_object_);
62 if (entity_ ==
nullptr && !started_)
63 manual_object_->estimateVertexCount(vcount);
68 if (!started_ && entity_)
70 RVIZ_COMMON_LOG_WARNING(
"Cannot modify mesh once construction is complete");
77 manual_object_->begin(material_name_, Ogre::RenderOperation::OT_TRIANGLE_LIST,
"rviz_rendering");
84 manual_object_->position(position);
90 manual_object_->position(position);
91 manual_object_->normal(normal);
94void MeshShape::addVertex(
const Ogre::Vector3& position,
const Ogre::Vector3& normal,
const Ogre::ColourValue& color)
97 manual_object_->position(position);
98 manual_object_->normal(normal);
99 manual_object_->colour(color);
104 manual_object_->normal(normal);
109 manual_object_->colour(color);
114 manual_object_->triangle(v1, v2, v3);
122 manual_object_->end();
123 static uint32_t count = 0;
124 std::string name =
"ConvertedMeshShape@" + std::to_string(count++);
125 manual_object_->convertToMesh(name);
126 entity_ = scene_manager_->createEntity(name);
129 entity_->setMaterialName(material_name_,
"rviz_rendering");
130 offset_node_->attachObject(entity_);
134 RVIZ_COMMON_LOG_ERROR(
"Unable to construct triangle mesh");
139 RVIZ_COMMON_LOG_ERROR(
"No triangles added");
147 entity_->detachFromParent();
148 const auto& mesh_name = entity_->getMesh()->getName();
149 if (Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().getByName(mesh_name))
151 Ogre::MeshManager::getSingleton().remove(mesh);
153 scene_manager_->destroyEntity(entity_);
156 manual_object_->clear();
void addColor(const Ogre::ColourValue &color)
Add color for a vertex.
void beginTriangles()
Start adding triangles to the mesh.
void addTriangle(unsigned int p1, unsigned int p2, unsigned int p3)
Add a triangle by indexing in the defined vertices.
void addVertex(const Ogre::Vector3 &position)
Add a vertex to the mesh (no normal defined). If using this function only (not using addTriangle()) i...
MeshShape(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node=nullptr)
Constructor.
void clear()
Clear the mesh.
void estimateVertexCount(size_t vcount)
void endTriangles()
Notify that the set of triangles to add is complete. No more triangles can be added,...
void addNormal(const Ogre::Vector3 &normal)
Add normal for a vertex.