9namespace fs = std::filesystem;
15 if (
const char *xdg = std::getenv(
"XDG_CACHE_HOME"); xdg && *xdg) {
16 return fs::path(xdg) /
"mj_kdl_wrapper";
18 if (
const char *home = std::getenv(
"HOME"); home && *home) {
19 return fs::path(home) /
".cache" /
"mj_kdl_wrapper";
26 if (
const char *root = std::getenv(
"MJ_KDL_MENAGERIE"); root && *root) {
27 const auto path = fs::path(root) / relative;
28 if (fs::exists(path))
return path.string();
30 const auto path =
cache_root() /
"menagerie" / relative;
31 return fs::exists(path) ? path.string() :
"";
37 throw std::runtime_error(
38 relative.string() +
" not found. Searched $MJ_KDL_MENAGERIE and "
40 +
". Run 'mj-kdl-fetch-menagerie' or set MJ_KDL_MENAGERIE.");
45 const auto path =
cache_root() /
"assets" / relative;
46 return fs::exists(path) ? path.string() :
"";
49inline std::string
asset(
const fs::path &relative)
51 if (std::string path =
find_asset(relative); !path.empty())
return path;
52 throw std::runtime_error(
53 relative.string() +
" not found in " + (
cache_root() /
"assets").
string()
54 +
". Run 'mj-kdl-fetch-menagerie' to populate bundled assets.");
std::string asset(const fs::path &relative)
std::string menagerie_model(const fs::path &relative)
std::string find_asset(const fs::path &relative)
std::string find_menagerie_model(const fs::path &relative)