diff --git a/examples/hello_world_plugin/HelloWorldPlugin.cc b/examples/hello_world_plugin/HelloWorldPlugin.cc index e47dbbdee..bc1e82082 100644 --- a/examples/hello_world_plugin/HelloWorldPlugin.cc +++ b/examples/hello_world_plugin/HelloWorldPlugin.cc @@ -38,40 +38,55 @@ namespace mock // Documentation Inherited. public: virtual std::string Name() const override { - return "test2"; + return "HelloWorldPlugin"; } + // Documentation Inherited. protected: virtual bool LoadImpl(const std::map &_params) override { return true; } + /// \brief Initialize the render engine. + /// \return True if the operation is successful protected: virtual bool InitImpl() override { return true; } + /// \brief Get a pointer to the list of scenes managed by the render + /// engine. + /// \return list of scenes protected: virtual ignition::rendering::SceneStorePtr Scenes() const override { return nullptr; } + /// \brief Create a scene. + /// \param[in] _id Unique scene Id + /// \parampin] _name Name of scene protected: virtual ignition::rendering::ScenePtr CreateSceneImpl(unsigned int _id, const std::string &_name) override { return nullptr; } + /// \brief Singelton setup. private: friend class ignition::common::SingletonT; }; class HelloWorldPlugin : public ignition::rendering::RenderEnginePlugin { + /// \brief Get the name of the render engine loaded by this plugin. + /// \return Name of render engine public: std::string Name() const { - return "test"; + return HelloWorldRenderEngine::Instance()->Name(); } + + /// \brief Get a pointer to the render engine loaded by this plugin. + /// \return Render engine instance public: ignition::rendering::RenderEngine *Engine() const { return HelloWorldRenderEngine::Instance(); diff --git a/examples/hello_world_plugin/README.md b/examples/hello_world_plugin/README.md index 29e7362bb..5f81c8215 100644 --- a/examples/hello_world_plugin/README.md +++ b/examples/hello_world_plugin/README.md @@ -19,3 +19,25 @@ This will generate the `HelloWorldPlugin` library under `build`. The exact name of the library file depends on the operating system such as `libHelloWorldPlugin.so` on Linux, `libHelloWorldPlugin.dylib` on macOS, and `HelloWorldPlugin.dll` on Windows. + +## Run + +Be sure to have the `IGN_GAZEBO_RENDER_ENGINE_PATH` environment variable set to the path +where your plugin is located. From within the `build` directory of this example, you can run + +~~~ +export IGN_GAZEBO_RENDER_ENGINE_PATH=$PWD +~~~ + +to set the environment variable accordingly. + + +Now you can run `ign gazebo` with the name of the resultant library file (without the `lib` prefix +or the file extension, i.e., libHelloWorldPlugin.so -> HelloWorldPlugin): + +~~~ +ign gazebo --render-engine HelloWorldPlugin +~~~ + +You should see a blank screen within the Ignition GUI, as this mocked plugin provides no implementation +for the scene. diff --git a/src/base/BaseRenderEngine.cc b/src/base/BaseRenderEngine.cc index bc5047f12..2a47f74c3 100644 --- a/src/base/BaseRenderEngine.cc +++ b/src/base/BaseRenderEngine.cc @@ -94,72 +94,108 @@ bool BaseRenderEngine::IsEnabled() const ////////////////////////////////////////////////// unsigned int BaseRenderEngine::SceneCount() const { - return this->Scenes()->Size(); + auto scenes = this->Scenes(); + if (scenes) + return scenes->Size(); + return 0u; } ////////////////////////////////////////////////// bool BaseRenderEngine::HasScene(ConstScenePtr _scene) const { - return this->Scenes()->Contains(_scene); + auto scenes = this->Scenes(); + if (scenes) + return scenes->Contains(_scene); + return false; } ////////////////////////////////////////////////// bool BaseRenderEngine::HasSceneId(unsigned int _id) const { - return this->Scenes()->ContainsId(_id); + auto scenes = this->Scenes(); + if (scenes) + return scenes->ContainsId(_id); + return false; } ////////////////////////////////////////////////// bool BaseRenderEngine::HasSceneName(const std::string &_name) const { - return this->Scenes()->ContainsName(_name); + auto scenes = this->Scenes(); + if (scenes) + return scenes->ContainsName(_name); + return false; } ////////////////////////////////////////////////// ScenePtr BaseRenderEngine::SceneById(unsigned int _id) const { - return this->Scenes()->GetById(_id); + auto scenes = this->Scenes(); + if (scenes) + return scenes->GetById(_id); + return ScenePtr(); } ////////////////////////////////////////////////// ScenePtr BaseRenderEngine::SceneByName(const std::string &_name) const { - return this->Scenes()->GetByName(_name); + auto scenes = this->Scenes(); + if (scenes) + return scenes->GetByName(_name); + return ScenePtr(); } ////////////////////////////////////////////////// ScenePtr BaseRenderEngine::SceneByIndex(unsigned int _index) const { - return this->Scenes()->GetByIndex(_index); + auto scenes = this->Scenes(); + if (scenes) + return scenes->GetByIndex(_index); + return ScenePtr(); } ////////////////////////////////////////////////// void BaseRenderEngine::DestroyScene(ScenePtr _scene) { + auto scenes = this->Scenes(); + if (!scenes) + return; this->Scenes()->Destroy(_scene); } ////////////////////////////////////////////////// void BaseRenderEngine::DestroySceneById(unsigned int _id) { + auto scenes = this->Scenes(); + if (!scenes) + return; this->Scenes()->DestroyById(_id); } ////////////////////////////////////////////////// void BaseRenderEngine::DestroySceneByName(const std::string &_name) { + auto scenes = this->Scenes(); + if (!scenes) + return; this->Scenes()->DestroyByName(_name); } ////////////////////////////////////////////////// void BaseRenderEngine::DestroySceneByIndex(unsigned int _index) { + auto scenes = this->Scenes(); + if (!scenes) + return; this->Scenes()->DestroyByIndex(_index); } ////////////////////////////////////////////////// void BaseRenderEngine::DestroyScenes() { + auto scenes = this->Scenes(); + if (!scenes) + return; this->Scenes()->DestroyAll(); }