From 635ec7820df3b598bf9b9f03582ca1008cff8805 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Fri, 12 Apr 2024 13:24:12 -0700 Subject: [PATCH] Support loading resources from Fuel Signed-off-by: Nate Koenig --- rviz_rendering/CMakeLists.txt | 4 ++++ rviz_rendering/package.xml | 3 +++ rviz_rendering/src/rviz_rendering/mesh_loader.cpp | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/rviz_rendering/CMakeLists.txt b/rviz_rendering/CMakeLists.txt index fee1258b8..3e58982eb 100644 --- a/rviz_rendering/CMakeLists.txt +++ b/rviz_rendering/CMakeLists.txt @@ -39,6 +39,7 @@ find_package(ament_index_cpp REQUIRED) find_package(eigen3_cmake_module REQUIRED) find_package(Eigen3 REQUIRED) find_package(resource_retriever REQUIRED) +find_package(gz-fuel_tools8 REQUIRED) # TODO(wjwwood): this block is to setup the windeployqt tool, could be removed later. if(Qt5_FOUND AND WIN32 AND TARGET Qt5::qmake AND NOT TARGET Qt5::windeployqt) @@ -103,6 +104,7 @@ target_link_libraries(rviz_rendering PUBLIC Qt5::Widgets rviz_ogre_vendor::OgreMain rviz_ogre_vendor::OgreOverlay + gz-fuel_tools8::gz-fuel_tools8 ) if(TARGET Eigen3::Eigen) # TODO(sloretz) require target to exist when https://github.com/ros2/choco-packages/issues/19 is addressed @@ -130,6 +132,7 @@ ament_export_dependencies( Eigen3 Qt5 rviz_ogre_vendor + gz-fuel_tools8 ) # Export old-style CMake variables @@ -179,6 +182,7 @@ if(BUILD_TESTING) PUBLIC rviz_ogre_vendor::OgreMain rviz_rendering + gz-fuel_tools8::gz-fuel_tools8 ) ament_add_gmock(string_helper_test test/rviz_rendering/string_helper_test.cpp) diff --git a/rviz_rendering/package.xml b/rviz_rendering/package.xml index 3cda5cf12..ae158253c 100644 --- a/rviz_rendering/package.xml +++ b/rviz_rendering/package.xml @@ -35,6 +35,7 @@ resource_retriever rviz_assimp_vendor rviz_ogre_vendor + gz-fuel_tools8 eigen qtbase5-dev @@ -48,6 +49,7 @@ resource_retriever rviz_assimp_vendor rviz_ogre_vendor + gz-fuel_tools8 ament_cmake_cppcheck @@ -59,6 +61,7 @@ ament_cmake_xmllint ament_lint_auto rviz_assimp_vendor + gz-fuel_tool8 ament_cmake diff --git a/rviz_rendering/src/rviz_rendering/mesh_loader.cpp b/rviz_rendering/src/rviz_rendering/mesh_loader.cpp index 3ebe8eb46..ea5c7749c 100644 --- a/rviz_rendering/src/rviz_rendering/mesh_loader.cpp +++ b/rviz_rendering/src/rviz_rendering/mesh_loader.cpp @@ -47,6 +47,8 @@ #include // NOLINT cpplint cannot handle include order here #include // NOLINT cpplint cannot handle include order here +#include + #define ASSIMP_UNIFIED_HEADER_NAMES 1 #if defined(ASSIMP_UNIFIED_HEADER_NAMES) #include "assimp/Importer.hpp" @@ -108,11 +110,20 @@ Ogre::MeshPtr loadMeshFromResource(const std::string & resource_path) return mesh; } else { AssimpLoader assimp_loader; + std::string file_resource_path = resource_path; + + // Check to see if the resource is referencing a Fuel resource. + // If so, then use fuel_tools to resolve the path. This will + // also download the resource if it doesn't exist on disk. + if (resource_path.find("https://fuel") == 0) { + file_resource_path = "file://" + + gz::fuel_tools::fetchResource(resource_path); + } - const aiScene * scene = assimp_loader.getScene(resource_path); + const aiScene * scene = assimp_loader.getScene(file_resource_path); if (!scene) { RVIZ_RENDERING_LOG_ERROR_STREAM( - "Could not load resource [" << resource_path.c_str() << "]: " << + "Could not load resource [" << file_resource_path.c_str() << "]: " << assimp_loader.getErrorMessage()); return Ogre::MeshPtr(); }