From 5cb0d3eefb5dfed0be6a286d1bc70b1ccaae7752 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Mon, 14 Aug 2023 08:40:45 -0700 Subject: [PATCH] World requires a scene and atmosphere Signed-off-by: Nate Koenig --- python/test/pyWorld_TEST.py | 2 +- src/World.cc | 24 ++++++++++-------------- src/World_TEST.cc | 7 ++++++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/python/test/pyWorld_TEST.py b/python/test/pyWorld_TEST.py index 08c62ab12..f77fcdc8e 100644 --- a/python/test/pyWorld_TEST.py +++ b/python/test/pyWorld_TEST.py @@ -202,7 +202,7 @@ def test_set_physics(self): def test_set_scene(self): world = World() - self.assertEqual(None, world.scene()) + self.assertNotEqual(None, world.scene()) scene = Scene() scene.set_ambient(Color.BLUE) diff --git a/src/World.cc b/src/World.cc index aacb571c9..461b3596a 100644 --- a/src/World.cc +++ b/src/World.cc @@ -47,8 +47,8 @@ class sdf::World::Implementation /// \return Errors, if any. public: Errors LoadSphericalCoordinates(sdf::ElementPtr _elem); - /// \brief Optional atmosphere model. - public: std::optional atmosphere; + /// \brief Required atmosphere model. + public: sdf::Atmosphere atmosphere; /// \brief Audio device name public: std::string audioDevice = "default"; @@ -60,8 +60,8 @@ class sdf::World::Implementation /// \brief Optional Gui parameters. public: std::optional gui; - /// \brief Optional Scene parameters. - public: std::optional scene; + /// \brief Required scene parameters. + public: sdf::Scene scene; /// \brief The frames specified in this world. public: std::vector frames; @@ -180,9 +180,8 @@ Errors World::Load(sdf::ElementPtr _sdf, const ParserConfig &_config) // Read the atmosphere element if (_sdf->HasElement("atmosphere")) { - this->dataPtr->atmosphere.emplace(); Errors atmosphereLoadErrors = - this->dataPtr->atmosphere->Load(_sdf->GetElement("atmosphere")); + this->dataPtr->atmosphere.Load(_sdf->GetElement("atmosphere")); errors.insert(errors.end(), atmosphereLoadErrors.begin(), atmosphereLoadErrors.end()); } @@ -314,9 +313,8 @@ Errors World::Load(sdf::ElementPtr _sdf, const ParserConfig &_config) // Load the Scene if (_sdf->HasElement("scene")) { - this->dataPtr->scene.emplace(); Errors sceneLoadErrors = - this->dataPtr->scene->Load(_sdf->GetElement("scene"), _config); + this->dataPtr->scene.Load(_sdf->GetElement("scene"), _config); errors.insert(errors.end(), sceneLoadErrors.begin(), sceneLoadErrors.end()); } @@ -459,7 +457,7 @@ Model *World::ModelByName(const std::string &_name) ///////////////////////////////////////////////// const sdf::Atmosphere *World::Atmosphere() const { - return optionalToPointer(this->dataPtr->atmosphere); + return &(this->dataPtr->atmosphere); } ///////////////////////////////////////////////// @@ -497,7 +495,7 @@ void World::SetGui(const sdf::Gui &_gui) ///////////////////////////////////////////////// const sdf::Scene *World::Scene() const { - return optionalToPointer(this->dataPtr->scene); + return &(this->dataPtr->scene); } ///////////////////////////////////////////////// @@ -1033,16 +1031,14 @@ sdf::ElementPtr World::ToElement(const OutputConfig &_config) const } // Atmosphere - if (this->dataPtr->atmosphere) - elem->InsertElement(this->dataPtr->atmosphere->ToElement(), true); + elem->InsertElement(this->dataPtr->atmosphere.ToElement(), true); // Gui if (this->dataPtr->gui) elem->InsertElement(this->dataPtr->gui->ToElement(), true); // Scene - if (this->dataPtr->scene) - elem->InsertElement(this->dataPtr->scene->ToElement(), true); + elem->InsertElement(this->dataPtr->scene.ToElement(), true); // Audio if (this->dataPtr->audioDevice != "default") diff --git a/src/World_TEST.cc b/src/World_TEST.cc index 9e9174a4f..b1f93b92e 100644 --- a/src/World_TEST.cc +++ b/src/World_TEST.cc @@ -39,6 +39,11 @@ TEST(DOMWorld, Construction) EXPECT_STREQ("default", world.AudioDevice().c_str()); EXPECT_EQ(gz::math::Vector3d::Zero, world.WindLinearVelocity()); + // The scene and atmosphere are requred, per the SDF spec. Make sure + // that they have been created. + EXPECT_TRUE(world.Scene()); + EXPECT_TRUE(world.Atmosphere()); + EXPECT_EQ(0u, world.ModelCount()); EXPECT_EQ(nullptr, world.ModelByIndex(0)); EXPECT_EQ(nullptr, world.ModelByIndex(1)); @@ -358,7 +363,7 @@ TEST(DOMWorld, SetGui) TEST(DOMWorld, SetScene) { sdf::World world; - EXPECT_EQ(nullptr, world.Scene()); + EXPECT_NE(nullptr, world.Scene()); sdf::Scene scene; scene.SetAmbient(gz::math::Color::Blue);