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 resources from Fuel #1186

Draft
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rviz_rendering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -130,6 +132,7 @@ ament_export_dependencies(
Eigen3
Qt5
rviz_ogre_vendor
gz-fuel_tools8
)

# Export old-style CMake variables
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions rviz_rendering/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<build_depend>resource_retriever</build_depend>
<build_depend>rviz_assimp_vendor</build_depend>
<build_depend>rviz_ogre_vendor</build_depend>
<build_depend>gz-fuel_tools8</build_depend>

<build_export_depend>eigen</build_export_depend>
<build_export_depend>qtbase5-dev</build_export_depend>
Expand All @@ -48,6 +49,7 @@
<exec_depend>resource_retriever</exec_depend>
<exec_depend>rviz_assimp_vendor</exec_depend>
<exec_depend>rviz_ogre_vendor</exec_depend>
<exec_depend>gz-fuel_tools8</exec_depend>

<!-- TODO(jacobperron): Replace with ament_lint_common when ament_copyright is working -->
<test_depend>ament_cmake_cppcheck</test_depend>
Expand All @@ -59,6 +61,7 @@
<test_depend>ament_cmake_xmllint</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>rviz_assimp_vendor</test_depend>
<test_depend>gz-fuel_tool8</test_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
15 changes: 13 additions & 2 deletions rviz_rendering/src/rviz_rendering/mesh_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include <QFileInfo> // NOLINT cpplint cannot handle include order here
#include <QString> // NOLINT cpplint cannot handle include order here

#include <gz/fuel_tools/Interface.hh>

#define ASSIMP_UNIFIED_HEADER_NAMES 1
#if defined(ASSIMP_UNIFIED_HEADER_NAMES)
#include "assimp/Importer.hpp"
Expand Down Expand Up @@ -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();
}
Expand Down