Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New scene manager GUI plugin that works with ign-gui's MinimalScene #813

Merged
merged 11 commits into from
Aug 10, 2021
452 changes: 452 additions & 0 deletions examples/worlds/minimal_scene.sdf

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions include/ignition/gazebo/rendering/RenderUtil.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
/// \return Name of the rendering scene.
public: std::string SceneName() const;

/// \brief Set the scene to use.
/// \param[in] _scene Pointer to the scene.
public: void SetScene(const rendering::ScenePtr &_scene);

/// \brief Set background color of render window
/// \param[in] _color Color of render window background
public: void SetBackgroundColor(const math::Color &_color);
Expand Down
1 change: 1 addition & 0 deletions src/gui/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ add_subdirectory(plot_3d)
add_subdirectory(plotting)
add_subdirectory(resource_spawner)
add_subdirectory(scene3d)
add_subdirectory(scene_manager)
add_subdirectory(shapes)
add_subdirectory(transform_control)
add_subdirectory(video_recorder)
Expand Down
7 changes: 7 additions & 0 deletions src/gui/plugins/scene_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gz_add_gui_plugin(GzSceneManager
SOURCES GzSceneManager.cc
QT_HEADERS GzSceneManager.hh
PRIVATE_LINK_LIBS
${PROJECT_LIBRARY_TARGET_NAME}-rendering
ignition-utils${IGN_UTILS_VER}::ignition-utils${IGN_UTILS_VER}
)
115 changes: 115 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "GzSceneManager.hh"

#include <ignition/common/Profiler.hh>
#include <ignition/gui/Application.hh>
#include <ignition/gui/GuiEvents.hh>
#include <ignition/plugin/Register.hh>
#include <ignition/rendering/RenderingIface.hh>
#include <ignition/rendering/Scene.hh>
#include <ignition/gui/MainWindow.hh>
chapulina marked this conversation as resolved.
Show resolved Hide resolved

#include "ignition/gazebo/EntityComponentManager.hh"
#include "ignition/gazebo/components/Name.hh"
#include "ignition/gazebo/components/World.hh"
#include "ignition/gazebo/rendering/RenderUtil.hh"

namespace ignition
{
namespace gazebo
{
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
/// \brief Private data class for GzSceneManager
class GzSceneManagerPrivate
{
/// \brief Update the 3D scene based on the latest state of the ECM.
public: void OnRender();

//// \brief Pointer to the rendering scene
public: rendering::ScenePtr scene;

/// \brief Rendering utility
public: RenderUtil renderUtil;
};
}
}
}

using namespace ignition;
using namespace gazebo;

/////////////////////////////////////////////////
GzSceneManager::GzSceneManager()
: GuiSystem(), dataPtr(std::make_unique<GzSceneManagerPrivate>())
{
}

/////////////////////////////////////////////////
GzSceneManager::~GzSceneManager() = default;

/////////////////////////////////////////////////
void GzSceneManager::LoadConfig(const tinyxml2::XMLElement *)
{
if (this->title.empty())
this->title = "Scene Manager";

ignition::gui::App()->findChild<
ignition::gui::MainWindow *>()->installEventFilter(this);
}

//////////////////////////////////////////////////
void GzSceneManager::Update(const UpdateInfo &_info,
EntityComponentManager &_ecm)
{
IGN_PROFILE("GzSceneManager::Update");

this->dataPtr->renderUtil.UpdateECM(_info, _ecm);
this->dataPtr->renderUtil.UpdateFromECM(_info, _ecm);
}

/////////////////////////////////////////////////
bool GzSceneManager::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == gui::events::Render::kType)
{
this->dataPtr->OnRender();
}

// Standard event processing
return QObject::eventFilter(_obj, _event);
}

/////////////////////////////////////////////////
void GzSceneManagerPrivate::OnRender()
{
if (nullptr == this->scene)
{
this->scene = rendering::sceneFromFirstRenderEngine();
if (nullptr == this->scene)
return;

this->renderUtil.SetScene(this->scene);
}

this->renderUtil.Update();
}

// Register this plugin
IGNITION_ADD_PLUGIN(ignition::gazebo::GzSceneManager,
ignition::gui::Plugin)
66 changes: 66 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef IGNITION_GAZEBO_GUI_GZSCENEMANAGER_HH_
#define IGNITION_GAZEBO_GUI_GZSCENEMANAGER_HH_

#include <memory>

#include <ignition/gazebo/gui/GuiSystem.hh>

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
class GzSceneManagerPrivate;

/// \brief Updates a 3D scene based on information coming from the ECM.
/// This plugin doesn't instantiate a new 3D scene. Instead, it relies on
/// another plugin being loaded alongside it that will create and paint the
/// scene to the window, such as `ignition::gui::plugins::Scene3D`.
class GzSceneManager : public GuiSystem
{
Q_OBJECT

/// \brief Constructor
public: GzSceneManager();

/// \brief Destructor
public: ~GzSceneManager() override;

// Documentation inherited
public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
override;

// Documentation inherited
public: void Update(const UpdateInfo &_info,
EntityComponentManager &_ecm) override;

// Documentation inherited
private: bool eventFilter(QObject *_obj, QEvent *_event) override;

/// \internal
/// \brief Pointer to private data.
private: std::unique_ptr<GzSceneManagerPrivate> dataPtr;
};
}
}
}

#endif
28 changes: 28 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

// TODO: remove invisible rectangle, see
// https://github.com/ignitionrobotics/ign-gui/issues/220
Rectangle {
visible: false
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
5 changes: 5 additions & 0 deletions src/gui/plugins/scene_manager/GzSceneManager.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="GzSceneManager/">
<file>GzSceneManager.qml</file>
</qresource>
</RCC>
12 changes: 12 additions & 0 deletions src/rendering/RenderUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,10 @@ void RenderUtilPrivate::RemoveRenderingEntities(
/////////////////////////////////////////////////
void RenderUtil::Init()
{
// Already initialized
if (nullptr != this->dataPtr->scene)
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
return;

ignition::common::SystemPaths pluginPath;
pluginPath.SetPluginPathEnv(kRenderPluginPathEnv);
rendering::setPluginPaths(pluginPath.PluginPaths());
Expand Down Expand Up @@ -2101,6 +2105,14 @@ void RenderUtil::SetSceneName(const std::string &_name)
this->dataPtr->sceneName = _name;
}

/////////////////////////////////////////////////
void RenderUtil::SetScene(const rendering::ScenePtr &_scene)
{
this->dataPtr->scene = _scene;
this->dataPtr->sceneManager.SetScene(_scene);
this->dataPtr->engine = _scene == nullptr ? nullptr : _scene->Engine();
}

/////////////////////////////////////////////////
std::string RenderUtil::SceneName() const
{
Expand Down