From 7e5fcd2bf75b237a6615dd8ed90afa8786e58bc0 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Sun, 25 Oct 2020 22:50:19 -0700 Subject: [PATCH 1/3] add sky Signed-off-by: Ian Chen --- .github/ci/packages.apt | 4 +- CMakeLists.txt | 8 +- examples/worlds/sky.sdf | 305 ++++++++++++++++++ .../ignition/gazebo/rendering/RenderUtil.hh | 4 + src/Conversions.cc | 29 ++ src/Conversions_TEST.cc | 37 +++ src/gui/plugins/scene3d/Scene3D.cc | 5 + src/rendering/RenderUtil.cc | 15 + 8 files changed, 401 insertions(+), 6 deletions(-) create mode 100644 examples/worlds/sky.sdf diff --git a/.github/ci/packages.apt b/.github/ci/packages.apt index 48c14d060a..db9cf33607 100644 --- a/.github/ci/packages.apt +++ b/.github/ci/packages.apt @@ -9,8 +9,8 @@ libignition-math6-eigen3-dev libignition-msgs6-dev libignition-physics3-dev libignition-plugin-dev -libignition-rendering4-dev -libignition-sensors4-dev +libignition-rendering5-dev +libignition-sensors5-dev libignition-tools-dev libignition-transport9-dev libogre-1.9-dev diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b3647c99d..c994973f03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ set(IGN_PHYSICS_VER ${ignition-physics3_VERSION_MAJOR}) #-------------------------------------- # Find ignition-sensors -ign_find_package(ignition-sensors4 REQUIRED +ign_find_package(ignition-sensors5 REQUIRED COMPONENTS rendering air_pressure @@ -110,12 +110,12 @@ ign_find_package(ignition-sensors4 REQUIRED depth_camera thermal_camera ) -set(IGN_SENSORS_VER ${ignition-sensors4_VERSION_MAJOR}) +set(IGN_SENSORS_VER ${ignition-sensors5_VERSION_MAJOR}) #-------------------------------------- # Find ignition-rendering -ign_find_package(ignition-rendering4 REQUIRED) -set(IGN_RENDERING_VER ${ignition-rendering4_VERSION_MAJOR}) +ign_find_package(ignition-rendering5 REQUIRED) +set(IGN_RENDERING_VER ${ignition-rendering5_VERSION_MAJOR}) #-------------------------------------- # Find ignition-math diff --git a/examples/worlds/sky.sdf b/examples/worlds/sky.sdf new file mode 100644 index 0000000000..604c456a40 --- /dev/null +++ b/examples/worlds/sky.sdf @@ -0,0 +1,305 @@ + + + + + + + + + + + + 3D View + false + docked + + + ogre2 + scene + 0.4 0.4 0.4 + 0.8 0.8 0.8 + + 6 0 1.0 0 0.0 3.14 + + + + + + World control + false + false + 72 + 121 + 1 + + floating + + + + + + + true + true + true + + + + + + + World stats + false + false + 110 + 290 + 1 + + floating + + + + + + + true + true + true + true + + + + + + RGB camera + 350 + 315 + + camera + + + + + + + 0.001 + 1.0 + + + + + ogre2 + + + + + + + + 1.0 1.0 1.0 + 0.8 0.8 0.8 + + + + + true + 0 0 10 0 0 0 + 0.8 0.8 0.8 1 + 0.8 0.8 0.8 1 + -0.5 0.1 -0.9 + + + + true + + + + + 0 0 1 + + + + + + + 0 0 1 + 100 100 + + + + 0.8 0.8 0.8 1 + 0.8 0.8 0.8 1 + 0.8 0.8 0.8 1 + + + + + + + 0 0 0.5 0 0 0 + + + + 1 + 0 + 0 + 1 + 0 + 1 + + 1.0 + + + + + 1 1 1 + + + + + + + + 1 1 1 + + + + 1 0 0 1 + 1 0 0 1 + 1 0 0 1 + + + + + + + 0 -1.5 0.5 0 0 0 + + + + 2 + 0 + 0 + 2 + 0 + 2 + + 2.0 + + + + + 0.5 + 1.0 + + + + + + + + 0.5 + 1.0 + + + + 0 1 0 1 + 0 1 0 1 + 0 1 0 1 + + + + + + + 0 1.5 0.5 0 0 0 + + + + 3 + 0 + 0 + 3 + 0 + 3 + + 3.0 + + + + + 0.5 + + + + + + + + 0.5 + + + + 0 0 1 1 + 0 0 1 1 + 0 0 1 1 + + + + + + + true + -3 0 0.5 0 0.0 0 + + 0.05 0.05 0.05 0 0 0 + + + + 0.1 0.1 0.1 + + + + + + + 0.1 0.1 0.1 + + + + + + 1.047 + + 320 + 240 + + + 0.1 + 100 + + + 1 + 30 + true + camera + + + + + + + diff --git a/include/ignition/gazebo/rendering/RenderUtil.hh b/include/ignition/gazebo/rendering/RenderUtil.hh index 36cb1ad63e..28235486ef 100644 --- a/include/ignition/gazebo/rendering/RenderUtil.hh +++ b/include/ignition/gazebo/rendering/RenderUtil.hh @@ -94,6 +94,10 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// \param[in] _ambient Color of ambient light public: void SetAmbientLight(const math::Color &_ambient); + /// \brief Set whether to enable sky in the scene + /// \param[in] _enabled True to enable sky, false to disable sky + public: void SetSkyEnabled(bool _enabled); + /// \brief Show grid view in the scene public: void ShowGrid(); diff --git a/src/Conversions.cc b/src/Conversions.cc index b5cc4b1ca5..8f023ad01c 100644 --- a/src/Conversions.cc +++ b/src/Conversions.cc @@ -624,6 +624,21 @@ msgs::Scene ignition::gazebo::convert(const sdf::Scene &_in) out.set_shadows(_in.Shadows()); out.set_grid(_in.Grid()); out.set_origin_visual(_in.OriginVisual()); + + if (_in.Sky()) + { + msgs::Sky *skyMsg = out.mutable_sky(); + skyMsg->set_time(_in.Sky()->Time()); + skyMsg->set_sunrise(_in.Sky()->Sunrise()); + skyMsg->set_sunset(_in.Sky()->Sunset()); + skyMsg->set_wind_speed(_in.Sky()->CloudSpeed()); + skyMsg->set_wind_direction(_in.Sky()->CloudDirection().Radian()); + skyMsg->set_humidity(_in.Sky()->CloudHumidity()); + skyMsg->set_mean_cloud_size(_in.Sky()->CloudMeanSize()); + msgs::Set(skyMsg->mutable_cloud_ambient(), + _in.Sky()->CloudAmbient()); + } + return out; } @@ -639,6 +654,20 @@ sdf::Scene ignition::gazebo::convert(const msgs::Scene &_in) out.SetShadows(_in.shadows()); out.SetGrid(_in.grid()); out.SetOriginVisual(_in.origin_visual()); + + if (_in.has_sky()) + { + sdf::Sky sky; + sky.SetTime(_in.sky().time()); + sky.SetSunrise(_in.sky().sunrise()); + sky.SetSunset(_in.sky().sunset()); + sky.SetCloudSpeed(_in.sky().wind_speed()); + sky.SetCloudDirection(math::Angle(_in.sky().wind_direction())); + sky.SetCloudHumidity(_in.sky().humidity()); + sky.SetCloudMeanSize(_in.sky().mean_cloud_size()); + sky.SetCloudAmbient(msgs::Convert(_in.sky().cloud_ambient())); + out.SetSky(sky); + } return out; } diff --git a/src/Conversions_TEST.cc b/src/Conversions_TEST.cc index b25232fed2..b23841440d 100644 --- a/src/Conversions_TEST.cc +++ b/src/Conversions_TEST.cc @@ -482,6 +482,7 @@ TEST(Conversions, Scene) EXPECT_TRUE(sceneMsg.shadows()); EXPECT_TRUE(sceneMsg.grid()); EXPECT_TRUE(sceneMsg.origin_visual()); + EXPECT_FALSE(sceneMsg.has_sky()); auto newScene = convert(sceneMsg); EXPECT_EQ(math::Color(0.1f, 0.2f, 0.3f, 0.4f), newScene.Ambient()); @@ -489,6 +490,42 @@ TEST(Conversions, Scene) EXPECT_TRUE(newScene.Shadows()); EXPECT_TRUE(newScene.Grid()); EXPECT_TRUE(newScene.OriginVisual()); + EXPECT_EQ(nullptr, newScene.Sky()); + + // sky + sdf::Sky sky; + sky.SetTime(10); + sky.SetSunrise(4.0); + sky.SetSunset(15.0); + sky.SetCloudSpeed(5.0); + sky.SetCloudDirection(math::Angle(3.14)); + sky.SetCloudHumidity(0.11); + sky.SetCloudMeanSize(0.88); + sky.SetCloudAmbient(math::Color::Red); + scene.SetSky(sky); + + auto sceneSkyMsg = convert(scene); + EXPECT_TRUE(sceneSkyMsg.has_sky()); + EXPECT_DOUBLE_EQ(10.0, sceneSkyMsg.sky().time()); + EXPECT_DOUBLE_EQ(4.0, sceneSkyMsg.sky().sunrise()); + EXPECT_DOUBLE_EQ(15.0, sceneSkyMsg.sky().sunset()); + EXPECT_DOUBLE_EQ(5.0, sceneSkyMsg.sky().wind_speed()); + EXPECT_DOUBLE_EQ(3.14, sceneSkyMsg.sky().wind_direction()); + EXPECT_DOUBLE_EQ(0.11, sceneSkyMsg.sky().humidity()); + EXPECT_DOUBLE_EQ(0.88, sceneSkyMsg.sky().mean_cloud_size()); + EXPECT_EQ(math::Color::Red, + msgs::Convert(sceneSkyMsg.sky().cloud_ambient())); + + auto newSceneSky = convert(sceneSkyMsg); + ASSERT_NE(nullptr, newSceneSky.Sky()); + EXPECT_DOUBLE_EQ(10.0, newSceneSky.Sky()->Time()); + EXPECT_DOUBLE_EQ(4.0, newSceneSky.Sky()->Sunrise()); + EXPECT_DOUBLE_EQ(15.0, newSceneSky.Sky()->Sunset()); + EXPECT_DOUBLE_EQ(5.0, newSceneSky.Sky()->CloudSpeed()); + EXPECT_EQ(math::Angle(3.14), newSceneSky.Sky()->CloudDirection()); + EXPECT_DOUBLE_EQ(0.11, newSceneSky.Sky()->CloudHumidity()); + EXPECT_DOUBLE_EQ(0.88, newSceneSky.Sky()->CloudMeanSize()); + EXPECT_EQ(math::Color::Red, newSceneSky.Sky()->CloudAmbient()); } ///////////////////////////////////////////////// diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 9d5e81cd59..5011df2a84 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -2147,6 +2147,11 @@ void Scene3D::LoadConfig(const tinyxml2::XMLElement *_pluginElem) this->dataPtr->renderUtil->SetBackgroundColor(bgColor); } + if (_pluginElem->FirstChildElement("sky")) + { + this->dataPtr->renderUtil->SetSkyEnabled(true); + } + if (auto elem = _pluginElem->FirstChildElement("camera_pose")) { math::Pose3d pose; diff --git a/src/rendering/RenderUtil.cc b/src/rendering/RenderUtil.cc index 379ece6b57..af467903d9 100644 --- a/src/rendering/RenderUtil.cc +++ b/src/rendering/RenderUtil.cc @@ -105,6 +105,9 @@ class ignition::gazebo::RenderUtilPrivate /// \brief Name of scene public: std::string sceneName = "scene"; + //// \brief True to enable sky in the scene + public: bool skyEnabled = false; + /// \brief Scene background color public: math::Color backgroundColor = math::Color::Black; @@ -320,6 +323,11 @@ void RenderUtil::Update() this->dataPtr->scene->SetBackgroundColor(scene.Background()); if (scene.Grid() && !this->dataPtr->enableSensors) this->ShowGrid(); + if (scene.Sky()) + { + this->dataPtr->scene->SetSkyEnabled(true); + } + // only one scene so break break; } @@ -1231,6 +1239,7 @@ void RenderUtil::Init() this->dataPtr->engine->CreateScene(this->dataPtr->sceneName); this->dataPtr->scene->SetAmbientLight(this->dataPtr->ambientLight); this->dataPtr->scene->SetBackgroundColor(this->dataPtr->backgroundColor); + this->dataPtr->scene->SetSkyEnabled(this->dataPtr->skyEnabled); } this->dataPtr->sceneManager.SetScene(this->dataPtr->scene); if (this->dataPtr->enableSensors) @@ -1305,6 +1314,12 @@ std::string RenderUtil::SceneName() const return this->dataPtr->sceneName; } +///////////////////////////////////////////////// +void RenderUtil::SetSkyEnabled(bool _enabled) +{ + this->dataPtr->skyEnabled = _enabled; +} + ///////////////////////////////////////////////// void RenderUtil::SetUseCurrentGLContext(bool _enable) { From fccdf5acbc8caf552606c44524bceaedfd18a3b7 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 30 Nov 2020 20:29:24 -0800 Subject: [PATCH 2/3] update sun dir, print warning Signed-off-by: Ian Chen --- examples/worlds/sky.sdf | 4 ++-- src/gui/plugins/scene3d/Scene3D.cc | 4 +++- src/rendering/SceneManager.cc | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/worlds/sky.sdf b/examples/worlds/sky.sdf index 604c456a40..d555a0a0b4 100644 --- a/examples/worlds/sky.sdf +++ b/examples/worlds/sky.sdf @@ -2,7 +2,7 @@ @@ -119,7 +119,7 @@ Currently only suppored using ogre2 rendering engine plugin. 0 0 10 0 0 0 0.8 0.8 0.8 1 0.8 0.8 0.8 1 - -0.5 0.1 -0.9 + 0.0 0.6 -0.9 diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 5011df2a84..49a57c1765 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -2147,9 +2147,11 @@ void Scene3D::LoadConfig(const tinyxml2::XMLElement *_pluginElem) this->dataPtr->renderUtil->SetBackgroundColor(bgColor); } - if (_pluginElem->FirstChildElement("sky")) + if (auto elem = _pluginElem->FirstChildElement("sky")) { this->dataPtr->renderUtil->SetSkyEnabled(true); + if (!elem->NoChildren()) + ignwarn << "Child elements of are not supported yet" << std::endl; } if (auto elem = _pluginElem->FirstChildElement("camera_pose")) diff --git a/src/rendering/SceneManager.cc b/src/rendering/SceneManager.cc index 20b4e8ab11..cfd30539e5 100644 --- a/src/rendering/SceneManager.cc +++ b/src/rendering/SceneManager.cc @@ -477,7 +477,7 @@ rendering::MaterialPtr SceneManager::LoadMaterial( { material->SetTexture(fullPath); // Use alpha channel for transparency - material->SetAlphaFromTexture(true); + // material->SetAlphaFromTexture(true); } else ignerr << "Unable to find file [" << albedoMap << "]\n"; @@ -516,6 +516,22 @@ rendering::MaterialPtr SceneManager::LoadMaterial( else ignerr << "Unable to find file [" << emissiveMap << "]\n"; } + + // light map + std::string lightMap = workflow->LightMap(); + if (!lightMap.empty()) + { + std::string fullPath = common::findFile(lightMap); + if (!fullPath.empty()) + { + unsigned int uvSet = workflow->LightMapTexCoordSet(); + material->SetLightMap(fullPath, uvSet); + } + else + { + ignerr << "Unable to find file [" << lightMap << "]\n"; + } + } } return material; } From fb239554be0968eec0cd98677835240a595279bc Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 1 Dec 2020 17:08:45 -0800 Subject: [PATCH 3/3] undo changes Signed-off-by: Ian Chen --- src/rendering/SceneManager.cc | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/rendering/SceneManager.cc b/src/rendering/SceneManager.cc index cfd30539e5..20b4e8ab11 100644 --- a/src/rendering/SceneManager.cc +++ b/src/rendering/SceneManager.cc @@ -477,7 +477,7 @@ rendering::MaterialPtr SceneManager::LoadMaterial( { material->SetTexture(fullPath); // Use alpha channel for transparency - // material->SetAlphaFromTexture(true); + material->SetAlphaFromTexture(true); } else ignerr << "Unable to find file [" << albedoMap << "]\n"; @@ -516,22 +516,6 @@ rendering::MaterialPtr SceneManager::LoadMaterial( else ignerr << "Unable to find file [" << emissiveMap << "]\n"; } - - // light map - std::string lightMap = workflow->LightMap(); - if (!lightMap.empty()) - { - std::string fullPath = common::findFile(lightMap); - if (!fullPath.empty()) - { - unsigned int uvSet = workflow->LightMapTexCoordSet(); - material->SetLightMap(fullPath, uvSet); - } - else - { - ignerr << "Unable to find file [" << lightMap << "]\n"; - } - } } return material; }