From 2693be71bd64c1b499e81dbde1e9cd8a7c340811 Mon Sep 17 00:00:00 2001 From: ThomasDuvinage Date: Fri, 6 Dec 2024 16:19:54 +0900 Subject: [PATCH 1/2] [plugins] add plugins loading method --- src/CMakeLists.txt | 1 + src/main.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c45febf..3045dc9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -149,6 +149,7 @@ endif() find_package(Boost REQUIRED COMPONENTS program_options) add_executable(mc_mujoco main.cpp) +target_compile_definitions(mc_mujoco PUBLIC MUJOCO_BIN_DIR="${MUJOCO_BIN_DIR}") target_link_libraries(mc_mujoco PRIVATE mc_mujoco_lib Boost::program_options Boost::disable_autolinking) diff --git a/src/main.cpp b/src/main.cpp index 2d48c0a..3042022 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,28 @@ namespace po = boost::program_options; bool render_state = true; +#define MUJOCO_PLUGIN_DIR "mujoco_plugin" + + +void scanPluginLibraries(){ + // define platform-specific strings + #if defined(_WIN32) || defined(__CYGWIN__) + const std::string sep = "\\"; + #else + const std::string sep = "/"; + #endif + + const std::string plugin_dir = MUJOCO_BIN_DIR + sep + MUJOCO_PLUGIN_DIR; + mj_loadAllPluginLibraries( + plugin_dir.c_str(), +[](const char * filename, int first, int count) { + std::printf("Plugins registered by library '%s':\n", filename); + for(int i = first; i < first + count; ++i) + { + std::printf(" %s\n", mjp_getPluginAtSlot(i)->name); + } + }); +} + void simulate(mc_mujoco::MjSim & mj_sim) { bool done = false; @@ -68,6 +90,9 @@ int main(int argc, char * argv[]) config.visualize_collisions = vm["with-collisions"].as(); } } + + scanPluginLibraries(); + mc_mujoco::MjSim mj_sim(config); std::thread simThread(simulate, std::ref(mj_sim)); From 6eaa350a2865c6affc70fd1d5aac4b0f434ac1cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2024 07:22:33 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/main.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3042022..2dfe36b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,18 +14,20 @@ bool render_state = true; #define MUJOCO_PLUGIN_DIR "mujoco_plugin" - -void scanPluginLibraries(){ - // define platform-specific strings - #if defined(_WIN32) || defined(__CYGWIN__) - const std::string sep = "\\"; - #else - const std::string sep = "/"; - #endif +void scanPluginLibraries() +{ +// define platform-specific strings +#if defined(_WIN32) || defined(__CYGWIN__) + const std::string sep = "\\"; +#else + const std::string sep = "/"; +#endif const std::string plugin_dir = MUJOCO_BIN_DIR + sep + MUJOCO_PLUGIN_DIR; mj_loadAllPluginLibraries( - plugin_dir.c_str(), +[](const char * filename, int first, int count) { + plugin_dir.c_str(), + +[](const char * filename, int first, int count) + { std::printf("Plugins registered by library '%s':\n", filename); for(int i = first; i < first + count; ++i) {