From 070fed948daba630cb51e753313e511e7ab164fb Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 20 Jun 2024 16:05:50 -0700 Subject: [PATCH 1/2] Add GravityEnabled boolean component Signed-off-by: Steve Peters --- include/gz/sim/components/Gravity.hh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/gz/sim/components/Gravity.hh b/include/gz/sim/components/Gravity.hh index fe3cf88a9f..713e797acf 100644 --- a/include/gz/sim/components/Gravity.hh +++ b/include/gz/sim/components/Gravity.hh @@ -36,6 +36,11 @@ namespace components /// \brief Store the gravity acceleration. using Gravity = Component; IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.Gravity", Gravity) + + /// \brief Store the gravity acceleration. + using GravityEnabled = Component; + IGN_GAZEBO_REGISTER_COMPONENT( + "ign_gazebo_components.GravityEnabled", GravityEnabled) } } } From 85231c7e0ab28b97face371e8b74a39a32948821 Mon Sep 17 00:00:00 2001 From: youhy Date: Sun, 23 Jun 2024 12:11:37 -0500 Subject: [PATCH 2/2] change zero gravity vector to component gravityenabled Signed-off-by: youhy --- src/SdfEntityCreator.cc | 5 ++--- src/systems/physics/Physics.cc | 21 ++++++--------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/SdfEntityCreator.cc b/src/SdfEntityCreator.cc index a84343fd42..71c295db9b 100644 --- a/src/SdfEntityCreator.cc +++ b/src/SdfEntityCreator.cc @@ -590,10 +590,9 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Link *_link) if (!_link->EnableGravity()) { - // If disable gravity, create a gravity component to the entity - // This gravity will have value 0,0,0 + // If disable gravity, create a GravityEnabled component to the entity this->dataPtr->ecm->CreateComponent( - linkEntity, components::Gravity()); + linkEntity, components::GravityEnabled(false)); } // Visuals diff --git a/src/systems/physics/Physics.cc b/src/systems/physics/Physics.cc index c61279205f..687178a369 100644 --- a/src/systems/physics/Physics.cc +++ b/src/systems/physics/Physics.cc @@ -1161,21 +1161,12 @@ void PhysicsPrivate::CreateLinkEntities(const EntityComponentManager &_ecm) } // get link gravity - const components::Gravity *gravity = - _ecm.Component(_entity); - if (nullptr != gravity) - { - // Entity has a gravity component that is all zeros when - // is set to false - // See SdfEntityCreator::CreateEntities() - if (gravity->Data() == math::Vector3d::Zero) - { - link.SetEnableGravity(false); - } - else - { - link.SetEnableGravity(true); - } + const components::GravityEnabled *gravityEnabled = + _ecm.Component(_entity); + if (nullptr != gravityEnabled) + { + // gravityEnabled set in SdfEntityCreator::CreateEntities() + link.SetEnableGravity(gravityEnabled->Data()); } auto linkPtrPhys = modelPtrPhys->ConstructLink(link);