39 #include <OgreSceneNode.h>
40 #include <OgreSceneManager.h>
41 #include <OgreEntity.h>
42 #include <OgreSubEntity.h>
43 #include <OgreMaterialManager.h>
44 #include <OgreTextureManager.h>
45 #include <OgreSharedPtr.h>
46 #include <OgreTechnique.h>
52 Ogre::SceneNode* parent_node)
53 :
MarkerBase(owner, context, parent_node), entity_(nullptr)
73 S_MaterialPtr::iterator it;
76 Ogre::MaterialPtr material = *it;
77 if (!material.isNull())
79 Ogre::MaterialManager::getSingleton().remove(material->getName());
88 ROS_ASSERT(new_message->type == visualization_msgs::Marker::MESH_RESOURCE);
91 bool update_color =
false;
96 float r = new_message->color.r;
97 float g = new_message->color.g;
98 float b = new_message->color.b;
99 float a = new_message->color.a;
101 if (!
entity_ || old_message->mesh_resource != new_message->mesh_resource ||
102 old_message->mesh_use_embedded_materials != new_message->mesh_use_embedded_materials)
106 if (new_message->mesh_resource.empty())
113 std::stringstream ss;
114 ss <<
"Mesh resource marker [" <<
getStringID() <<
"] could not load ["
115 << new_message->mesh_resource <<
"]";
124 static uint32_t count = 0;
125 std::stringstream ss;
126 ss <<
"mesh_resource_marker_" << count++;
127 std::string
id = ss.str();
133 Ogre::MaterialPtr default_material = Ogre::MaterialManager::getSingleton().create(
134 ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
135 default_material->setReceiveShadows(
false);
136 default_material->getTechnique(0)->setLightingEnabled(
true);
137 default_material->getTechnique(0)->setAmbient(0.5, 0.5, 0.5);
140 if (new_message->mesh_use_embedded_materials)
143 for (
const Ogre::MaterialPtr& material :
getMaterials())
145 if (material->getName() !=
"BaseWhiteNoLighting")
147 Ogre::MaterialPtr new_material = material->clone(
id + material->getName());
149 Ogre::Pass* pass = new_material->getTechnique(0)->createPass();
150 pass->setAmbient(0.0
f, 0.0
f, 0.0
f);
151 pass->setDiffuse(0.0
f, 0.0
f, 0.0
f, 0.0
f);
152 pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
153 pass->setDepthWriteEnabled(
false);
154 pass->setLightingEnabled(
true);
160 for (uint32_t i = 0; i <
entity_->getNumSubEntities(); ++i)
162 std::string mat_name =
entity_->getSubEntity(i)->getMaterialName();
163 if (mat_name !=
"BaseWhiteNoLighting")
165 entity_->getSubEntity(i)->setMaterialName(
id + mat_name);
173 entity_->getSubEntity(i)->setMaterial(default_material);
179 entity_->setMaterial(default_material);
182 update_color = !(new_message->mesh_use_embedded_materials && r == 0 && g == 0 && b == 0 && a == 0);
192 if (!old_message || old_message->color.r != r || old_message->color.g != g ||
193 old_message->color.b != b || old_message->color.a != a)
202 bool depth_write = a >= 0.9998;
203 Ogre::SceneBlendType blending = depth_write ? Ogre::SBT_REPLACE : Ogre::SBT_TRANSPARENT_ALPHA;
204 bool tinting = new_message->mesh_use_embedded_materials;
206 for (
const Ogre::MaterialPtr& material :
materials_)
208 Ogre::Technique* technique = material->getTechnique(0);
209 Ogre::Pass* pass0 = technique->getPass(0);
210 Ogre::Pass* passT = technique->getPass(technique->getNumPasses() - 1);
214 Ogre::ColourValue color = pass0->getDiffuse();
216 pass0->setDiffuse(color);
218 passT->setAmbient(r * 0.5
f, g * 0.5
f, b * 0.5
f);
219 passT->setDiffuse(r, g, b, std::min(a, 0.5
f));
223 pass0->setAmbient(r * 0.5
f, g * 0.5
f, b * 0.5
f);
224 pass0->setDiffuse(r, g, b, a);
227 pass0->setSceneBlending(blending);
228 pass0->setDepthWriteEnabled(depth_write);
229 pass0->setLightingEnabled(
true);
233 Ogre::Vector3 pos, scale;
234 Ogre::Quaternion orient;
235 if (!
transform(new_message, pos, orient, scale))