Robotics StackExchange | Archived questions

Access rendering::Scene through world plugin

Hi Guys,

i want to access the scene data structure within my world plugin. I found the Issue #1076 where someone tried something similar. Due to the comments i do not try to access the structure in the plugin initialization phase, but everytime the plugin is updated. Therefore in the Load function, a callback is registered by:

 void MyPlugin::Load(physics::WorldPtr _parent, sdf::ElementPtr _sdf)
 {
 // [...]
 // register UpdateBegin Callback
 this->updateConnection = event::Events::ConnectWorldUpdateBegin(boost::bind(&MyPlugin::OnUpdate, this,_1));
 // [...]
 }

The Callback function is defined as followed:

void MyPlugin::OnUpdate(const common::UpdateInfo &_info)
{
 rendering::ScenePtr scene = rendering::RenderEngine::Instance()->GetScene();
if(!scene)
{
   gzerr << "(MyPlugin) rendering::RenderEngine::Instance()->GetScene() returned NULL.\n";
}
 else
{
  gzmsg << "(MyPlugin) Scene loaded.... \n";
}
// try alternative access
scene = rendering::get_scene(this->world->GetName());
if(!scene)
{
  gzerr << "(MyPlugin) rendering::get_scene() returned NULL.\n";
  return;
}
else
{
   gzmsg << "(MyPlugin) Scene loaded.... \n";
}

}

I tried this approach with Gazebo 2.2.3 as well as with Gazeb 6.5.1 and obtain both times the following output, indicating that always a nullptr is returned:

Error [MyPlugin.cc:221] (MyPlugin) rendering::RenderEngine::Instance()->GetScene() returned NULL.
Error [MyPlugin.cc:231] (MyPlugin) rendering::get_scene() returned NULL.

I assume that it is caused by the fact, that MyPlugin is of type WorldPlugin. I use the same approach in another SensorPlugin, where it works without any problems.

Is there any alternative in order to access it within a WorldPlugin?

With best regards!

Asked by Illuminatur on 2016-03-19 03:24:51 UTC

Comments

Hello, I'm having this exact problem right now. Have you figured out a method for this? You said it worked for a sensor plugin, but I need it to change the color of a light, so I don't have a sensor and thus need to use a world plugin.

Asked by sarvesh0303 on 2016-06-24 02:27:49 UTC

Any luck with this?

Asked by plusk01 on 2018-02-06 13:19:36 UTC

Answers

A rendering scene won't be created in gzserver unless there is a rendering sensor present, such as a camera.

If you're trying to access gzclient's scene, then you'll need a plugin which runs in the client process, like a Visual or GUI plugin.

Asked by chapulina on 2018-02-06 13:37:43 UTC

Comments