From 45239e9e12077ade60bd01078e7ce92acf353889 Mon Sep 17 00:00:00 2001 From: AzulRadio <50132891+AzulRadio@users.noreply.github.com> Date: Thu, 13 Jun 2024 02:32:15 -0500 Subject: [PATCH 1/2] Add support for no gravity link (#2398) Signed-off-by: youhy Signed-off-by: Ian Chen Co-authored-by: Ian Chen --- src/SdfEntityCreator.cc | 8 ++++++++ src/systems/physics/Physics.cc | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/SdfEntityCreator.cc b/src/SdfEntityCreator.cc index 6947ff329c..a84343fd42 100644 --- a/src/SdfEntityCreator.cc +++ b/src/SdfEntityCreator.cc @@ -588,6 +588,14 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Link *_link) linkEntity, components::WindMode(_link->EnableWind())); } + if (!_link->EnableGravity()) + { + // If disable gravity, create a gravity component to the entity + // This gravity will have value 0,0,0 + this->dataPtr->ecm->CreateComponent( + linkEntity, components::Gravity()); + } + // Visuals for (uint64_t visualIndex = 0; visualIndex < _link->VisualCount(); ++visualIndex) diff --git a/src/systems/physics/Physics.cc b/src/systems/physics/Physics.cc index 544f16d54e..c61279205f 100644 --- a/src/systems/physics/Physics.cc +++ b/src/systems/physics/Physics.cc @@ -1160,6 +1160,24 @@ void PhysicsPrivate::CreateLinkEntities(const EntityComponentManager &_ecm) link.SetInertial(inertial->Data()); } + // 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); + } + } + auto linkPtrPhys = modelPtrPhys->ConstructLink(link); this->entityLinkMap.AddEntity(_entity, linkPtrPhys); this->topLevelModelMap.insert(std::make_pair(_entity, From ca1b62602e282a905c4373da09128a10720d74e1 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 25 Jun 2024 19:35:56 -0700 Subject: [PATCH 2/2] Add GravityEnabled boolean component (#2451) This adds a boolean GravityEnabled component to the existing gz/sim/components/Gravity.hh header file, which should be used with Link entities instead of the Vector3 gravity component. --------- Signed-off-by: Steve Peters Signed-off-by: youhy Co-authored-by: youhy --- include/gz/sim/components/Gravity.hh | 5 +++++ src/SdfEntityCreator.cc | 5 ++--- src/systems/physics/Physics.cc | 21 ++++++--------------- 3 files changed, 13 insertions(+), 18 deletions(-) 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) } } } 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);