Gazebo | Ignition | Community
Ask Your Question
1

Access rendering::Scene through world plugin

asked 2016-03-19 03:24:51 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

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!

edit retag flag offensive close merge delete

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.

sarvesh0303 gravatar imagesarvesh0303 ( 2016-06-24 02:27:49 -0600 )edit

Any luck with this?

plusk01 gravatar imageplusk01 ( 2018-02-06 12:19:36 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-02-06 12:37:43 -0600

chapulina gravatar image

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.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-03-19 03:24:51 -0600

Seen: 971 times

Last updated: Feb 06 '18