Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support loading mesh by mesh name in <mesh><uri> #2007

Merged
merged 7 commits into from
Jul 21, 2023
Merged

Conversation

iche033
Copy link
Contributor

@iche033 iche033 commented Jun 7, 2023

🎉 New feature

Partially addresses gazebosim/gz-common#404, specifically gazebosim/gz-common#404 (comment) about handing over in-memory mesh data to gazebo.

Summary

Allow users to specify name of mesh in SDF via <mesh><uri>.

Addresses this use case: User has created common:Mesh object and added it to the MeshManager via AddMesh call. They now want to spawn a new model with this mesh using an SDF string that has <mesh><uri> set to the name of their common::Mesh.

Added integration test demonstrating the above use case. It uses unit_box (that comes with MeshManager) as an example but user should be able to supply their own mesh.

Test it

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@github-actions github-actions bot added the 🌱 garden Ignition Garden label Jun 7, 2023
test/integration/mesh_uri.cc Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jun 7, 2023

Codecov Report

Merging #2007 (9b02d4b) into gz-sim7 (001dd9b) will increase coverage by 0.04%.
The diff coverage is 60.00%.

❗ Current head 9b02d4b differs from pull request most recent head f587ddf. Consider uploading reports for the commit f587ddf to get more accurate results

@@             Coverage Diff             @@
##           gz-sim7    #2007      +/-   ##
===========================================
+ Coverage    64.99%   65.03%   +0.04%     
===========================================
  Files          353      354       +1     
  Lines        28618    28655      +37     
===========================================
+ Hits         18600    18636      +36     
- Misses       10018    10019       +1     
Impacted Files Coverage Δ
include/gz/sim/Util.hh 100.00% <ø> (ø)
.../plugins/component_inspector/ComponentInspector.cc 5.61% <0.00%> (ø)
src/rendering/RenderUtil.cc 39.03% <0.00%> (ø)
src/systems/buoyancy/Buoyancy.cc 82.25% <0.00%> (ø)
.../systems/environment_preload/EnvironmentPreload.cc 69.69% <0.00%> (ø)
.../multicopter_control/MulticopterVelocityControl.hh 100.00% <ø> (ø)
...rc/systems/performer_detector/PerformerDetector.hh 100.00% <ø> (ø)
src/systems/thruster/Thruster.cc 86.20% <0.00%> (ø)
src/systems/hydrodynamics/Hydrodynamics.cc 85.28% <50.00%> (ø)
src/rendering/SceneManager.cc 31.09% <52.94%> (+0.18%) ⬆️
... and 11 more

... and 1 file with indirect coverage changes

src/systems/physics/Physics.cc Outdated Show resolved Hide resolved
src/systems/physics/Physics.cc Outdated Show resolved Hide resolved
test/integration/mesh_uri.cc Outdated Show resolved Hide resolved
Signed-off-by: Ian Chen <[email protected]>
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comment and is @azeey 's comment resolved?

Comment on lines +20 to +26
#include <gz/msgs/entity_factory.pb.h>

#include <gz/common/Console.hh>
#include <gz/common/Util.hh>
#include <gz/math/Pose3.hh>
#include <gz/transport/Node.hh>
#include <gz/utils/ExtraTestMacros.hh>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphabetize

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are already in alphabetical order? The msgs one is up top because it's a .h file.

@iche033
Copy link
Contributor Author

iche033 commented Jun 9, 2023

small comment and is @azeey 's comment resolved?

not yet. That needs some discussion

@iche033 iche033 requested a review from mabelzhang as a code owner June 12, 2023 21:51
meshUri = fullPath;
descriptor.mesh = meshManager->Load(meshUri);
}
else if (common::URI(_geom.MeshShape()->Uri()).Scheme() == "name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be checked first? If we have name://foo.dae, but there's a foo.dae somewhere in the file search path, what would be the behavior?

Copy link
Contributor Author

@iche033 iche033 Jun 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok swapped order of check so that the scheme determines how the mesh will be loaded. So ror name://foo.dae it'll assume it's an in-memory mesh. 4f381ce

common::MeshManager::Instance();
std::string meshUri;
rendering::MeshDescriptor descriptor;
if (meshManager->IsValidFilename(_geom.MeshShape()->Uri()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this logic is duplicated in Physics.cc. Can it be refactored?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored into a helper function in Util class. 4f381ce

EXPECT_LT(0u, g_count);

// Empty scene - camera should see just red background
unsigned int bufferSize = g_image.width() *g_image.height() * 3u;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to lock the mutex before accessing g_image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added lock. 4f381ce

/// \brief Load a mesh from a Mesh SDF DOM
/// \param[in] _meshSdf Mesh SDF DOM
/// \return The loaded mesh or null if the mesh can not be loaded.
GZ_SIM_VISIBLE const common::Mesh *loadMesh(const sdf::Mesh *_meshSdf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer we use const refs for parameters instead of a pointer so it's left up to the caller to ensure that the pointer is valid. This also lines up with our style guide (https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs)

Suggested change
GZ_SIM_VISIBLE const common::Mesh *loadMesh(const sdf::Mesh *_meshSdf);
GZ_SIM_VISIBLE const common::Mesh *loadMesh(const sdf::Mesh &_meshSdf);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep done, switched to use const ref. 68816bb

@iche033 iche033 requested a review from ahcorde July 20, 2023 22:15
@iche033 iche033 merged commit 50a99e6 into gz-sim7 Jul 21, 2023
@iche033 iche033 deleted the mesh_name_uri branch July 21, 2023 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants