Skip to content

Commit ede3e81

Browse files
authored
Merge pull request #14 from mc-rtc/feat/nix-convertpath
Use mc_rtc::convertPath, fix non-ros display
2 parents a700fed + a184a5b commit ede3e81

3 files changed

Lines changed: 4 additions & 38 deletions

File tree

src/widgets/Robot.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <mc_rbdyn/RobotLoader.h>
44
#include <mc_rbdyn/Robots.h>
5+
#include <mc_rtc/path.h>
56

67
#include <mc_rtc/version.h>
78

@@ -83,7 +84,7 @@ struct RobotBody : public Object3D, public SceneGraph::Drawable3D
8384
case Geometry::MESH:
8485
{
8586
const auto & mesh = boost::get<rbd::parsers::Geometry::Mesh>(visual.geometry.data);
86-
auto path = convertURI(mesh.filename, rm_path);
87+
auto path = mc_rtc::convertURI(mesh.filename, rm_path);
8788
object = gui.loadMesh(path.string(), color(visual.material), this, group_);
8889
// FIXME Bake scale in mesh?
8990
auto scale = mesh.scaleV;

src/widgets/Visual.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Visual.h"
2+
#include <mc_rtc/path.h>
23

34
namespace mc_rtc::magnum
45
{
@@ -29,7 +30,7 @@ void Visual::draw3D()
2930
auto handleMesh = [&]()
3031
{
3132
const auto & in = boost::get<Geometry::Mesh>(visual_.geometry.data);
32-
auto path = convertURI(in.filename, "");
33+
auto path = mc_rtc::convertURI(in.filename, "");
3334
if(path != mesh_)
3435
{
3536
mesh_ = path;

src/widgets/utils.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,42 +74,6 @@ inline sva::PTransformd convert(const Magnum::Matrix4 & m)
7474
return {r_map.cast<double>(), t_map.cast<double>()};
7575
}
7676

77-
inline fs::path convertURI(const std::string & uri, [[maybe_unused]] std::string_view default_dir = "")
78-
{
79-
const std::string package = "package://";
80-
if(uri.size() >= package.size() && uri.find(package) == 0)
81-
{
82-
size_t split = uri.find('/', package.size());
83-
std::string pkg = uri.substr(package.size(), split - package.size());
84-
auto leaf = fs::path(uri.substr(split + 1));
85-
fs::path MC_ENV_DESCRIPTION_PATH(mc_rtc::MC_ENV_DESCRIPTION_PATH);
86-
#ifndef __EMSCRIPTEN__
87-
# ifndef MC_RTC_HAS_ROS_SUPPORT
88-
// FIXME Prompt the user for unknown packages
89-
if(pkg == "jvrc_description") { pkg = (MC_ENV_DESCRIPTION_PATH / ".." / "jvrc_description").string(); }
90-
else if(pkg == "mc_env_description") { pkg = MC_ENV_DESCRIPTION_PATH.string(); }
91-
else if(pkg == "mc_int_obj_description")
92-
{
93-
pkg = (MC_ENV_DESCRIPTION_PATH / ".." / "mc_int_obj_description").string();
94-
}
95-
else { pkg = default_dir; }
96-
# else
97-
# ifdef MC_RTC_ROS_IS_ROS2
98-
pkg = ament_index_cpp::get_package_share_directory(pkg);
99-
# else
100-
pkg = ros::package::getPath(pkg);
101-
# endif
102-
# endif
103-
#else
104-
pkg = "/assets/" + pkg;
105-
#endif
106-
return pkg / leaf;
107-
}
108-
const std::string file = "file://";
109-
if(uri.size() >= file.size() && uri.find(file) == 0) { return fs::path(uri.substr(file.size())); }
110-
return uri;
111-
}
112-
11377
inline Magnum::Color4 color(const rbd::parsers::Material & m)
11478
{
11579
if(m.type == rbd::parsers::Material::Type::COLOR)

0 commit comments

Comments
 (0)