Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OGRE cannot add compositor to a CameraPlugin's Viewport?

I tried writing a gazebo::CameraPlugin to generate motion blur for the camera. For this, I wanted to use OGRE's Motion Blur compositor. However, addCompositor returns 0, indicating failure. Could anybody tell me what I am doing wrong here? Is it at all possible what I am trying to do?

Here is a minimal example:

#include "gazebo/gazebo.hh"
#include "gazebo/plugins/CameraPlugin.hh"

#include "OGRE/OgreCompositorManager.h"
#include "OGRE/OgreViewport.h"

#include <iostream>

namespace gazebo
  class CameraBlur : public CameraPlugin
    public: CameraBlur() 
            : CameraPlugin() 

    public: void Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf)
      gzwarn << "Loading CameraBlur\n";
      // Don't forget to load the camera plugin
      CameraPlugin::Load(_parent, _sdf);

      Ogre::Viewport* v = /*CameraPlugin::*/parentSensor->GetCamera()->GetViewport();
      // See if viewport != NULL:
      gzwarn << "viewport ptr:" << v << '\n';
      gzwarn << "add compositor: " << Ogre::CompositorManager::getSingleton().addCompositor(v, "Motion Blur", -1) << '\n';
      // This doesn't do anything when above line fails
      Ogre::CompositorManager::getSingleton().setCompositorEnabled(v, "Motion Blur", true);

    public: void OnNewFrame(const unsigned char *_image,
        unsigned int _width, unsigned int _height, unsigned int _depth,
        const std::string &_format)