From 43578d88ce8622985180029fc269d34a8d93a243 Mon Sep 17 00:00:00 2001 From: Benjamin Perseghetti Date: Tue, 16 Jan 2024 21:30:29 -0500 Subject: [PATCH] Use MaterialColor Apply Enum and Entity. Signed-off-by: Benjamin Perseghetti --- src/systems/user_commands/UserCommands.cc | 86 +++++++++++++---------- test/integration/user_commands.cc | 3 +- test/worlds/material_color.sdf | 59 ---------------- 3 files changed, 51 insertions(+), 97 deletions(-) delete mode 100644 test/worlds/material_color.sdf diff --git a/src/systems/user_commands/UserCommands.cc b/src/systems/user_commands/UserCommands.cc index cca4feb7896..677d1a9f00b 100644 --- a/src/systems/user_commands/UserCommands.cc +++ b/src/systems/user_commands/UserCommands.cc @@ -969,32 +969,57 @@ bool UserCommandsPrivate::VisualService(const msgs::Visual &_req, void UserCommandsPrivate::OnCmdMaterialColor(const msgs::MaterialColor &_msg) { msgs::Visual _req; - auto msg = _req.New(); - msg->set_name(_msg.name()); - msg->set_parent_name(_msg.parent_name()); - msg->mutable_material()->mutable_ambient()->set_r(_msg.ambient().r()); - msg->mutable_material()->mutable_ambient()->set_g(_msg.ambient().g()); - msg->mutable_material()->mutable_ambient()->set_b(_msg.ambient().b()); - msg->mutable_material()->mutable_ambient()->set_a(_msg.ambient().a()); - msg->mutable_material()->mutable_diffuse()->set_r(_msg.diffuse().r()); - msg->mutable_material()->mutable_diffuse()->set_g(_msg.diffuse().g()); - msg->mutable_material()->mutable_diffuse()->set_b(_msg.diffuse().b()); - msg->mutable_material()->mutable_diffuse()->set_a(_msg.diffuse().a()); - msg->mutable_material()->mutable_specular()->set_r(_msg.specular().r()); - msg->mutable_material()->mutable_specular()->set_g(_msg.specular().g()); - msg->mutable_material()->mutable_specular()->set_b(_msg.specular().b()); - msg->mutable_material()->mutable_specular()->set_a(_msg.specular().a()); - msg->mutable_material()->mutable_emissive()->set_r(_msg.emissive().r()); - msg->mutable_material()->mutable_emissive()->set_g(_msg.emissive().g()); - msg->mutable_material()->mutable_emissive()->set_b(_msg.emissive().b()); - msg->mutable_material()->mutable_emissive()->set_a(_msg.emissive().a()); - - auto cmd = std::make_unique(msg, this->iface); + int numberOfEntities = 1; + auto entities = entitiesFromScopedName(_msg.entity().name(), + *this->iface->ecm); + if (entities.empty()) + { + gzwarn << "Entity name: " << _msg.entity().name() << ", is not found." + << std::endl; + return; + } + if ((entities.size() > 1) && + (_msg.apply() == + gz::msgs::MaterialColor::Apply::MaterialColor_Apply_ALL)) + { + numberOfEntities=entities.size(); + } - // Push to pending + for (int i = 0; i < numberOfEntities; i++) { - std::lock_guard lock(this->pendingMutex); - this->pendingCmds.push_back(std::move(cmd)); + auto msg = _req.New(); + if (entities.size() == 1) + { + msg->set_id(*entities.begin()); + } + else + { + msg->set_id(*entities.begin()); + } + msg->mutable_material()->mutable_ambient()->set_r(_msg.ambient().r()); + msg->mutable_material()->mutable_ambient()->set_g(_msg.ambient().g()); + msg->mutable_material()->mutable_ambient()->set_b(_msg.ambient().b()); + msg->mutable_material()->mutable_ambient()->set_a(_msg.ambient().a()); + msg->mutable_material()->mutable_diffuse()->set_r(_msg.diffuse().r()); + msg->mutable_material()->mutable_diffuse()->set_g(_msg.diffuse().g()); + msg->mutable_material()->mutable_diffuse()->set_b(_msg.diffuse().b()); + msg->mutable_material()->mutable_diffuse()->set_a(_msg.diffuse().a()); + msg->mutable_material()->mutable_specular()->set_r(_msg.specular().r()); + msg->mutable_material()->mutable_specular()->set_g(_msg.specular().g()); + msg->mutable_material()->mutable_specular()->set_b(_msg.specular().b()); + msg->mutable_material()->mutable_specular()->set_a(_msg.specular().a()); + msg->mutable_material()->mutable_emissive()->set_r(_msg.emissive().r()); + msg->mutable_material()->mutable_emissive()->set_g(_msg.emissive().g()); + msg->mutable_material()->mutable_emissive()->set_b(_msg.emissive().b()); + msg->mutable_material()->mutable_emissive()->set_a(_msg.emissive().a()); + + auto cmd = std::make_unique(msg, this->iface); + + // Push to pending + { + std::lock_guard lock(this->pendingMutex); + this->pendingCmds.push_back(std::move(cmd)); + } } } @@ -1793,18 +1818,7 @@ bool VisualCommand::Execute() // When size > 1, we don't know which entity to modify if (entities.size() == 1) { - auto subentities = - this->iface->ecm->ChildrenByComponents(entities[0], - components::Name(visualMsg->name())); - if (subentities.size() == 1) - { - visualEntity = subentities[0]; - } - else - { - visualEntity = entities[0]; - } - gzmsg << "Using visual entity id: " << visualEntity << std::endl; + visualEntity = entities[0]; } } diff --git a/test/integration/user_commands.cc b/test/integration/user_commands.cc index 4b0f456c8f4..23e457274da 100644 --- a/test/integration/user_commands.cc +++ b/test/integration/user_commands.cc @@ -1093,8 +1093,7 @@ TEST_F(UserCommandsTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(MaterialColor)) const std::string materialColorTopic = "/world/material_color/material_color"; msgs::MaterialColor materialColorMsg; - materialColorMsg.set_name("box_visual"); - materialColorMsg.set_parent_name("box_link"); + materialColorMsg.mutable_entity()->set_name("box::box_link::box_visual"); gz::msgs::Set(materialColorMsg.mutable_diffuse(), gz::math::Color(1.0f, 1.0f, 1.0f, 1.0f)); diff --git a/test/worlds/material_color.sdf b/test/worlds/material_color.sdf deleted file mode 100644 index f9443bdb40d..00000000000 --- a/test/worlds/material_color.sdf +++ /dev/null @@ -1,59 +0,0 @@ - - - - - 0.001 - 0 - - - - - - - ogre2 - - - 0 0.0 0.0 0 0 0 - - - - 1 0 1.3 0 0 0 - - 1.047 - - 320 - 240 - - - 0.1 - 100 - - - 1 - 30 - false - camera - - - - - 0.5 - - - - 0.3 0.3 0.3 1 - 0.3 0.3 0.3 1 - 0.3 0.3 0.3 1 - 0.3 0.3 0.3 1 - - - - - -