diff --git a/src/experimental/platform/CMakeLists.txt b/src/experimental/platform/CMakeLists.txt index 733b9ad4..4bf46f26 100644 --- a/src/experimental/platform/CMakeLists.txt +++ b/src/experimental/platform/CMakeLists.txt @@ -20,67 +20,67 @@ add_library(${MUJOCO_PLATFORM_TARGET_NAME} STATIC) target_sources(${MUJOCO_PLATFORM_TARGET_NAME} PUBLIC - egl_utils.cc - egl_utils.h - enum_utils.h - file_dialog.h - graphics_mode.cc - graphics_mode.h - gui.cc - gui.h - gui_spec.cc - gui_spec.h helpers.cc helpers.h - imgui_widgets.cc - imgui_widgets.h - interaction.cc - interaction.h - model_holder.cc - model_holder.h - picture_gui.h - picture_gui.cc - plugin.cc - plugin.h - renderer.cc - renderer.h - sim_history.cc - sim_history.h - sim_profiler.cc - sim_profiler.h - spec_editor.cc - spec_editor.h - step_control.cc - step_control.h - window.cc - window.h + hal/egl_utils.cc + hal/egl_utils.h + hal/graphics_mode.cc + hal/graphics_mode.h + hal/renderer.cc + hal/renderer.h + hal/window.cc + hal/window.h + sim/model_holder.cc + sim/model_holder.h + sim/sim_history.cc + sim/sim_history.h + sim/sim_profiler.cc + sim/sim_profiler.h + sim/step_control.cc + sim/step_control.h + ux/enum_utils.h + ux/file_dialog.h + ux/gui.cc + ux/gui.h + ux/gui_spec.cc + ux/gui_spec.h + ux/imgui_widgets.cc + ux/imgui_widgets.h + ux/interaction.cc + ux/interaction.h + ux/picture_gui.h + ux/picture_gui.cc + ux/plugin.cc + ux/plugin.h + ux/spec_editor.cc + ux/spec_editor.h ) if(NOT WIN32) target_sources(${MUJOCO_PLATFORM_TARGET_NAME} PUBLIC - object_launcher_plugin.cc + ux/object_launcher_plugin.cc ) endif() if(APPLE) - set_source_files_properties(window_osx.mm PROPERTIES + set_source_files_properties(hal/window_osx.mm PROPERTIES COMPILE_FLAGS "-x objective-c++") target_sources(${MUJOCO_PLATFORM_TARGET_NAME} PUBLIC - window_osx.mm - file_dialog_cocoa.mm + hal/window_osx.mm + ux/file_dialog_cocoa.mm ) elseif(UNIX AND NOT APPLE) target_sources(${MUJOCO_PLATFORM_TARGET_NAME} PUBLIC - file_dialog_zenity.cc + ux/file_dialog_zenity.cc ) elseif(WIN32) target_sources(${MUJOCO_PLATFORM_TARGET_NAME} PUBLIC - file_dialog_win.cc + ux/file_dialog_win.cc ) else() target_sources(${MUJOCO_PLATFORM_TARGET_NAME} PUBLIC - file_dialog.cc + ux/file_dialog.cc ) endif() diff --git a/src/experimental/platform/egl_utils.cc b/src/experimental/platform/hal/egl_utils.cc similarity index 99% rename from src/experimental/platform/egl_utils.cc rename to src/experimental/platform/hal/egl_utils.cc index a91109ad..7ec0fc48 100644 --- a/src/experimental/platform/egl_utils.cc +++ b/src/experimental/platform/hal/egl_utils.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/egl_utils.h" +#include "experimental/platform/hal/egl_utils.h" #include diff --git a/src/experimental/platform/egl_utils.h b/src/experimental/platform/hal/egl_utils.h similarity index 83% rename from src/experimental/platform/egl_utils.h rename to src/experimental/platform/hal/egl_utils.h index dc01dfda..342b15b9 100644 --- a/src/experimental/platform/egl_utils.h +++ b/src/experimental/platform/hal/egl_utils.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_EGL_UTILS_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_EGL_UTILS_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_EGL_UTILS_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_EGL_UTILS_H_ #include @@ -25,4 +25,4 @@ std::shared_ptr CreateEglContext(); } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_EGL_UTILS_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_EGL_UTILS_H_ diff --git a/src/experimental/platform/graphics_mode.cc b/src/experimental/platform/hal/graphics_mode.cc similarity index 98% rename from src/experimental/platform/graphics_mode.cc rename to src/experimental/platform/hal/graphics_mode.cc index e291ed78..d992f1f4 100644 --- a/src/experimental/platform/graphics_mode.cc +++ b/src/experimental/platform/hal/graphics_mode.cc @@ -12,9 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/graphics_mode.h" +#include "experimental/platform/hal/graphics_mode.h" #include + #include namespace mujoco::platform { diff --git a/src/experimental/platform/graphics_mode.h b/src/experimental/platform/hal/graphics_mode.h similarity index 90% rename from src/experimental/platform/graphics_mode.h rename to src/experimental/platform/hal/graphics_mode.h index e5e79764..d81dfa96 100644 --- a/src/experimental/platform/graphics_mode.h +++ b/src/experimental/platform/hal/graphics_mode.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GRAPHICS_MODE_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GRAPHICS_MODE_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_GRAPHICS_MODE_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_GRAPHICS_MODE_H_ #include @@ -56,4 +56,4 @@ GraphicsMode GraphicsModeFromString(std::string_view str, } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GRAPHICS_MODE_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_GRAPHICS_MODE_H_ diff --git a/src/experimental/platform/renderer.cc b/src/experimental/platform/hal/renderer.cc similarity index 93% rename from src/experimental/platform/renderer.cc rename to src/experimental/platform/hal/renderer.cc index 42c77d5f..4a9be6c1 100644 --- a/src/experimental/platform/renderer.cc +++ b/src/experimental/platform/hal/renderer.cc @@ -12,23 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/renderer.h" +#include "experimental/platform/hal/renderer.h" #include #include #include #include -#include - -#include #include +#include +#include #if !defined(__EMSCRIPTEN__) && !defined(__APPLE__) -#include "experimental/platform/egl_utils.h" +#include "experimental/platform/hal/egl_utils.h" #endif #include "experimental/filament/render_context_filament.h" -#include "experimental/platform/graphics_mode.h" -#include "experimental/platform/plugin.h" +#include "experimental/platform/hal/graphics_mode.h" +#include "experimental/platform/ux/plugin.h" namespace mujoco::platform { @@ -47,9 +46,9 @@ Renderer::Renderer(void* native_window, GraphicsMode gfx) : native_window_(native_window), gfx_(gfx) { if (IsClassic(gfx_)) { if (native_window == nullptr) { - #if !defined(__EMSCRIPTEN__) && !defined(__APPLE__) - graphics_api_context_ = CreateEglContext(); - #endif +#if !defined(__EMSCRIPTEN__) && !defined(__APPLE__) + graphics_api_context_ = CreateEglContext(); +#endif } if (ImGui::GetCurrentContext()) { ImGui_ImplOpenGL3_Init(); @@ -147,8 +146,7 @@ void Renderer::Render(const mjModel* model, mjData* data, vis_option = &default_opt; } - mjv_updateScene(model, data, vis_option, perturb, camera, mjCAT_ALL, - &scene_); + mjv_updateScene(model, data, vis_option, perturb, camera, mjCAT_ALL, &scene_); const bool render_to_texture = !pixels.empty(); if (render_to_texture) { @@ -215,8 +213,8 @@ int Renderer::UploadImage(int texture_id, const std::byte* pixels, int width, return 0; } else { return mjrf_uploadGuiImage(texture_id, - reinterpret_cast(pixels), - width, height, bpp, &render_context_); + reinterpret_cast(pixels), + width, height, bpp, &render_context_); } } diff --git a/src/experimental/platform/renderer.h b/src/experimental/platform/hal/renderer.h similarity index 94% rename from src/experimental/platform/renderer.h rename to src/experimental/platform/hal/renderer.h index 2ac900b5..5efee347 100644 --- a/src/experimental/platform/renderer.h +++ b/src/experimental/platform/hal/renderer.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_RENDERER_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_RENDERER_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_RENDERER_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_RENDERER_H_ #include #include @@ -23,7 +23,7 @@ #include #include -#include "experimental/platform/graphics_mode.h" +#include "experimental/platform/hal/graphics_mode.h" namespace mujoco::platform { @@ -113,4 +113,4 @@ class Renderer { } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_RENDERER_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_RENDERER_H_ diff --git a/src/experimental/platform/window.cc b/src/experimental/platform/hal/window.cc similarity index 90% rename from src/experimental/platform/window.cc rename to src/experimental/platform/hal/window.cc index 466db1a9..faf9a6d1 100644 --- a/src/experimental/platform/window.cc +++ b/src/experimental/platform/hal/window.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/window.h" +#include "experimental/platform/hal/window.h" #include #include @@ -32,10 +32,9 @@ #include #include #include -#include "experimental/platform/graphics_mode.h" +#include "experimental/platform/hal/graphics_mode.h" #include "user/user_resource.h" - // Because X11/Xlib.h defines Status. #ifdef Status #undef Status @@ -126,9 +125,9 @@ Window::Window(std::string_view title, int width, int height, Config config) } const float content_scale = ImGui_ImplSDL2_GetContentScaleForDisplay(0); - sdl_window_ = SDL_CreateWindow(title.data(), SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, width, - height, window_flags); + sdl_window_ = + SDL_CreateWindow(title.data(), SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, width, height, window_flags); if (!sdl_window_) { mju_error("Error creating window: %s", SDL_GetError()); } @@ -156,14 +155,14 @@ Window::Window(std::string_view title, int width, int height, Config config) SDL_VERSION(&wmi.version); SDL_GetWindowWMInfo(sdl_window_, &wmi); - #if defined(__linux__) - native_window_ = reinterpret_cast(wmi.info.x11.window); - #elif defined(__WIN32__) - native_window_ = reinterpret_cast(wmi.info.win.window); - #elif defined(__APPLE__) - native_window_ = - GetNativeWindowOsx(reinterpret_cast(wmi.info.cocoa.window)); - #endif +#if defined(__linux__) + native_window_ = reinterpret_cast(wmi.info.x11.window); +#elif defined(__WIN32__) + native_window_ = reinterpret_cast(wmi.info.win.window); +#elif defined(__APPLE__) + native_window_ = + GetNativeWindowOsx(reinterpret_cast(wmi.info.cocoa.window)); +#endif } int drawable_width = width; @@ -244,8 +243,7 @@ void Window::Present(std::span pixels) { SDL_Surface* surface = SDL_GetWindowSurface(sdl_window_); const unsigned char* src = reinterpret_cast(pixels.data()); - unsigned char* dst = - static_cast(surface->pixels); + unsigned char* dst = static_cast(surface->pixels); for (int i = 0; i < height_; ++i) { for (int j = 0; j < width_; ++j) { @@ -260,14 +258,12 @@ void Window::Present(std::span pixels) { } SDL_RenderPresent(sdl_renderer_); - } else if (config_.gfx_mode != GraphicsMode::FilamentVulkan - && config_.gfx_mode != GraphicsMode::FilamentOpenGl) { + } else if (config_.gfx_mode != GraphicsMode::FilamentVulkan && + config_.gfx_mode != GraphicsMode::FilamentOpenGl) { SDL_GL_SwapWindow(sdl_window_); } } -GraphicsMode Window::GetGraphicsMode() const { - return config_.gfx_mode; -} +GraphicsMode Window::GetGraphicsMode() const { return config_.gfx_mode; } } // namespace mujoco::platform diff --git a/src/experimental/platform/window.h b/src/experimental/platform/hal/window.h similarity index 93% rename from src/experimental/platform/window.h rename to src/experimental/platform/hal/window.h index 63927ccb..4e9f504a 100644 --- a/src/experimental/platform/window.h +++ b/src/experimental/platform/hal/window.h @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_WINDOW_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_WINDOW_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_WINDOW_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_WINDOW_H_ #include #include #include #include -#include #include -#include "experimental/platform/graphics_mode.h" +#include +#include "experimental/platform/hal/graphics_mode.h" namespace mujoco::platform { @@ -104,4 +104,4 @@ class Window { } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_WINDOW_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_HAL_WINDOW_H_ diff --git a/src/experimental/platform/window_osx.mm b/src/experimental/platform/hal/window_osx.mm similarity index 100% rename from src/experimental/platform/window_osx.mm rename to src/experimental/platform/hal/window_osx.mm diff --git a/src/experimental/platform/model_holder.cc b/src/experimental/platform/sim/model_holder.cc similarity index 98% rename from src/experimental/platform/model_holder.cc rename to src/experimental/platform/sim/model_holder.cc index 52652eaa..402dde8e 100644 --- a/src/experimental/platform/model_holder.cc +++ b/src/experimental/platform/sim/model_holder.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/model_holder.h" +#include "experimental/platform/sim/model_holder.h" #include #include diff --git a/src/experimental/platform/model_holder.h b/src/experimental/platform/sim/model_holder.h similarity index 93% rename from src/experimental/platform/model_holder.h rename to src/experimental/platform/sim/model_holder.h index e14d2c6a..abb13b90 100644 --- a/src/experimental/platform/model_holder.h +++ b/src/experimental/platform/sim/model_holder.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_MODEL_HOLDER_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_MODEL_HOLDER_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_MODEL_HOLDER_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_MODEL_HOLDER_H_ #include #include @@ -81,4 +81,4 @@ class ModelHolder { }; } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_MODEL_HOLDER_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_MODEL_HOLDER_H_ diff --git a/src/experimental/platform/sim_history.cc b/src/experimental/platform/sim/sim_history.cc similarity index 97% rename from src/experimental/platform/sim_history.cc rename to src/experimental/platform/sim/sim_history.cc index db22c6ca..b32d7232 100644 --- a/src/experimental/platform/sim_history.cc +++ b/src/experimental/platform/sim/sim_history.cc @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/sim_history.h" +#include "experimental/platform/sim/sim_history.h" #include #include #include + #include namespace mujoco::platform { diff --git a/src/experimental/platform/sim_history.h b/src/experimental/platform/sim/sim_history.h similarity index 94% rename from src/experimental/platform/sim_history.h rename to src/experimental/platform/sim/sim_history.h index 46601f58..cb1bf065 100644 --- a/src/experimental/platform/sim_history.h +++ b/src/experimental/platform/sim/sim_history.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_HISTORY_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_HISTORY_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_SIM_HISTORY_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_SIM_HISTORY_H_ #include #include @@ -91,4 +91,4 @@ class SimHistory { } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_HISTORY_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_SIM_HISTORY_H_ diff --git a/src/experimental/platform/sim_profiler.cc b/src/experimental/platform/sim/sim_profiler.cc similarity index 99% rename from src/experimental/platform/sim_profiler.cc rename to src/experimental/platform/sim/sim_profiler.cc index a2032db9..7aca0c4c 100644 --- a/src/experimental/platform/sim_profiler.cc +++ b/src/experimental/platform/sim/sim_profiler.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/sim_profiler.h" +#include "experimental/platform/sim/sim_profiler.h" -#include #include #include +#include namespace mujoco::platform { diff --git a/src/experimental/platform/sim_profiler.h b/src/experimental/platform/sim/sim_profiler.h similarity index 88% rename from src/experimental/platform/sim_profiler.h rename to src/experimental/platform/sim/sim_profiler.h index 11887563..4e9cce46 100644 --- a/src/experimental/platform/sim_profiler.h +++ b/src/experimental/platform/sim/sim_profiler.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_PROFILER_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_PROFILER_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_SIM_PROFILER_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_SIM_PROFILER_H_ #include @@ -52,4 +52,4 @@ class SimProfiler { } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_PROFILER_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_SIM_PROFILER_H_ diff --git a/src/experimental/platform/step_control.cc b/src/experimental/platform/sim/step_control.cc similarity index 99% rename from src/experimental/platform/step_control.cc rename to src/experimental/platform/sim/step_control.cc index 38c97fe2..7dbb9340 100644 --- a/src/experimental/platform/step_control.cc +++ b/src/experimental/platform/sim/step_control.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/step_control.h" +#include "experimental/platform/sim/step_control.h" #include #include diff --git a/src/experimental/platform/step_control.h b/src/experimental/platform/sim/step_control.h similarity index 95% rename from src/experimental/platform/step_control.h rename to src/experimental/platform/sim/step_control.h index 7cebbd1b..0fec3025 100644 --- a/src/experimental/platform/step_control.h +++ b/src/experimental/platform/sim/step_control.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_STEP_CONTROL_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_STEP_CONTROL_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_STEP_CONTROL_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_STEP_CONTROL_H_ #include #include @@ -123,4 +123,4 @@ class StepControl { } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_STEP_CONTROL_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SIM_STEP_CONTROL_H_ diff --git a/src/experimental/platform/enum_utils.h b/src/experimental/platform/ux/enum_utils.h similarity index 96% rename from src/experimental/platform/enum_utils.h rename to src/experimental/platform/ux/enum_utils.h index a6e8ec0b..16ca6607 100644 --- a/src/experimental/platform/enum_utils.h +++ b/src/experimental/platform/ux/enum_utils.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_ENUM_UTILS_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_ENUM_UTILS_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_ENUM_UTILS_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_ENUM_UTILS_H_ #include #include @@ -167,4 +167,4 @@ constexpr std::string_view enum_to_string(E value) { } // namespace mujoco::platform::enum_utils -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_ENUM_UTILS_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_ENUM_UTILS_H_ diff --git a/src/experimental/platform/file_dialog.cc b/src/experimental/platform/ux/file_dialog.cc similarity index 97% rename from src/experimental/platform/file_dialog.cc rename to src/experimental/platform/ux/file_dialog.cc index 661b86dd..df1e0675 100644 --- a/src/experimental/platform/file_dialog.cc +++ b/src/experimental/platform/ux/file_dialog.cc @@ -12,10 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/file_dialog.h" +#include "experimental/platform/ux/file_dialog.h" #include - #include #include #include diff --git a/src/experimental/platform/file_dialog.h b/src/experimental/platform/ux/file_dialog.h similarity index 90% rename from src/experimental/platform/file_dialog.h rename to src/experimental/platform/ux/file_dialog.h index 303cf850..2ae80b09 100644 --- a/src/experimental/platform/file_dialog.h +++ b/src/experimental/platform/ux/file_dialog.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_FILE_DIALOG_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_FILE_DIALOG_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_FILE_DIALOG_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_FILE_DIALOG_H_ #include #include @@ -56,4 +56,4 @@ DialogResult SelectPathDialog(std::string_view path); } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_FILE_DIALOG_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_FILE_DIALOG_H_ diff --git a/src/experimental/platform/file_dialog_cocoa.mm b/src/experimental/platform/ux/file_dialog_cocoa.mm similarity index 97% rename from src/experimental/platform/file_dialog_cocoa.mm rename to src/experimental/platform/ux/file_dialog_cocoa.mm index b9caa2bd..a17e20ce 100644 --- a/src/experimental/platform/file_dialog_cocoa.mm +++ b/src/experimental/platform/ux/file_dialog_cocoa.mm @@ -16,7 +16,7 @@ #include #include -#include "experimental/platform/file_dialog.h" +#include "experimental/platform/ux/file_dialog.h" namespace mujoco::platform { diff --git a/src/experimental/platform/file_dialog_win.cc b/src/experimental/platform/ux/file_dialog_win.cc similarity index 99% rename from src/experimental/platform/file_dialog_win.cc rename to src/experimental/platform/ux/file_dialog_win.cc index 8b970bff..37a774df 100644 --- a/src/experimental/platform/file_dialog_win.cc +++ b/src/experimental/platform/ux/file_dialog_win.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/file_dialog.h" +#include "experimental/platform/ux/file_dialog.h" #ifndef UNICODE #define UNICODE diff --git a/src/experimental/platform/file_dialog_zenity.cc b/src/experimental/platform/ux/file_dialog_zenity.cc similarity index 98% rename from src/experimental/platform/file_dialog_zenity.cc rename to src/experimental/platform/ux/file_dialog_zenity.cc index 21d51dc1..20d7a421 100644 --- a/src/experimental/platform/file_dialog_zenity.cc +++ b/src/experimental/platform/ux/file_dialog_zenity.cc @@ -12,10 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/file_dialog.h" - #include -#include #include #include #include @@ -23,11 +20,14 @@ #include #include +#include #include -#include #include +#include #include +#include "experimental/platform/ux/file_dialog.h" + namespace mujoco::platform { static DialogResult RunZenity(std::vector& args) { diff --git a/src/experimental/platform/gui.cc b/src/experimental/platform/ux/gui.cc similarity index 99% rename from src/experimental/platform/gui.cc rename to src/experimental/platform/ux/gui.cc index f9a4c5b8..a5405cb1 100644 --- a/src/experimental/platform/gui.cc +++ b/src/experimental/platform/ux/gui.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/gui.h" +#include "experimental/platform/ux/gui.h" #include #include @@ -26,8 +26,8 @@ #include #include #include "experimental/platform/helpers.h" -#include "experimental/platform/interaction.h" -#include "experimental/platform/imgui_widgets.h" +#include "experimental/platform/ux/imgui_widgets.h" +#include "experimental/platform/ux/interaction.h" namespace mujoco::platform { diff --git a/src/experimental/platform/gui.h b/src/experimental/platform/ux/gui.h similarity index 97% rename from src/experimental/platform/gui.h rename to src/experimental/platform/ux/gui.h index d0b1ff79..cfa8fd80 100644 --- a/src/experimental/platform/gui.h +++ b/src/experimental/platform/ux/gui.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GUI_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GUI_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_GUI_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_GUI_H_ // A collection of functions for building ImGui panels for common MuJoCo // visualization and manipulation UX. These functions are primarily used by @@ -131,4 +131,4 @@ void StatsGui(const mjModel* model, const mjData* data, bool paused, float fps); } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GUI_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_GUI_H_ diff --git a/src/experimental/platform/gui_spec.cc b/src/experimental/platform/ux/gui_spec.cc similarity index 99% rename from src/experimental/platform/gui_spec.cc rename to src/experimental/platform/ux/gui_spec.cc index 7991fc03..d845ab09 100644 --- a/src/experimental/platform/gui_spec.cc +++ b/src/experimental/platform/ux/gui_spec.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/gui_spec.h" +#include "experimental/platform/ux/gui_spec.h" #include #include @@ -20,8 +20,8 @@ #include #include #include -#include "experimental/platform/imgui_widgets.h" -#include "experimental/platform/spec_editor.h" +#include "experimental/platform/ux/imgui_widgets.h" +#include "experimental/platform/ux/spec_editor.h" // Define the mujoco X macros to add fields to the ImGui_DataTable. // We limit the fields to the ones with a matching element by comparing the diff --git a/src/experimental/platform/gui_spec.h b/src/experimental/platform/ux/gui_spec.h similarity index 88% rename from src/experimental/platform/gui_spec.h rename to src/experimental/platform/ux/gui_spec.h index 6ff5b0cc..21b437ab 100644 --- a/src/experimental/platform/gui_spec.h +++ b/src/experimental/platform/ux/gui_spec.h @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GUI_SPEC_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GUI_SPEC_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_GUI_SPEC_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_GUI_SPEC_H_ #include -#include "experimental/platform/spec_editor.h" +#include "experimental/platform/ux/spec_editor.h" namespace mujoco::platform { @@ -44,4 +44,4 @@ void ElementModelGui(const mjModel* model, mjsElement* element); } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_GUI_SPEC_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_GUI_SPEC_H_ diff --git a/src/experimental/platform/imgui_widgets.cc b/src/experimental/platform/ux/imgui_widgets.cc similarity index 94% rename from src/experimental/platform/imgui_widgets.cc rename to src/experimental/platform/ux/imgui_widgets.cc index 5e828dae..9ffbbe3e 100644 --- a/src/experimental/platform/imgui_widgets.cc +++ b/src/experimental/platform/ux/imgui_widgets.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/imgui_widgets.h" +#include "experimental/platform/ux/imgui_widgets.h" #include #include @@ -62,8 +62,7 @@ KeyValues ReadIniSection(const std::string& contents, } ImGui_DataPtrTable::ImGui_DataPtrTable(float w1, float w2) { - ImGui::BeginTable("##PropertiesTable", 2, - ImGuiTableFlags_RowBg); + ImGui::BeginTable("##PropertiesTable", 2, ImGuiTableFlags_RowBg); const float width = ImGui::GetContentRegionAvail().x; ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, width * w1); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, width * w2); @@ -87,43 +86,44 @@ void ImGui_DataPtrTable::DataPtr(const char* label, const uintptr_t* ptr, } void ImGui_DataPtrTable::DataPtr(const char* label, const char* ptr, int index, - int n) { + int n) { MakeLabel(label); ScopedStyle style; style.Color(ImGuiCol_Text, ImColor(255, 0, 0, 255)); ImGui::Text("%s", "(char not implemented, please report bug)"); } -void ImGui_DataPtrTable::DataPtr(const char* label, const mjtByte* ptr, int index, - int n) { +void ImGui_DataPtrTable::DataPtr(const char* label, const mjtByte* ptr, + int index, int n) { for (int i = 0; i < n; ++i) { MakeLabel(label, i, n); ImGui::Text("%s", ptr[index + i] ? "true" : "false"); } } -void ImGui_DataPtrTable::DataPtr(const char* label, const mjtSize* ptr, int index, - int n) { +void ImGui_DataPtrTable::DataPtr(const char* label, const mjtSize* ptr, + int index, int n) { Numeric(label, ptr, index, n); } void ImGui_DataPtrTable::DataPtr(const char* label, const int* ptr, int index, - int n) { + int n) { Numeric(label, ptr, index, n); } void ImGui_DataPtrTable::DataPtr(const char* label, const float* ptr, int index, - int n) { + int n) { Numeric(label, ptr, index, n); } -void ImGui_DataPtrTable::DataPtr(const char* label, const double* ptr, int index, - int n) { +void ImGui_DataPtrTable::DataPtr(const char* label, const double* ptr, + int index, int n) { Numeric(label, ptr, index, n); } template -void ImGui_DataPtrTable::Numeric(const char* label, const T* ptr, int index, int n) { +void ImGui_DataPtrTable::Numeric(const char* label, const T* ptr, int index, + int n) { const T* addr = ptr + index * n; using U = std::conditional_t, float, int>; @@ -137,8 +137,7 @@ void ImGui_DataPtrTable::Numeric(const char* label, const T* ptr, int index, int } } - constexpr const char* fmt1 = - std::is_floating_point_v ? "%f" : "%d"; + constexpr const char* fmt1 = std::is_floating_point_v ? "%f" : "%d"; constexpr const char* fmt2 = std::is_floating_point_v ? "%f %f" : "%d %d"; constexpr const char* fmt3 = @@ -146,9 +145,7 @@ void ImGui_DataPtrTable::Numeric(const char* label, const T* ptr, int index, int constexpr const char* fmt4 = std::is_floating_point_v ? "%f %f %f %f" : "%d %d %d %d"; - auto text1 = [&](int offset) { - ImGui::Text(fmt1, (U)(addr[offset])); - }; + auto text1 = [&](int offset) { ImGui::Text(fmt1, (U)(addr[offset])); }; auto text2 = [&](int offset) { ImGui::Text(fmt2, (U)(addr[offset + 0]), (U)(addr[offset + 1])); }; @@ -299,7 +296,8 @@ void ImGui_SpecElementTable::operator()(const char* name, const char* alt_name, (*this)(name, quat, ref_quat, tooltip); break; case mjORIENTATION_AXISANGLE: - (*this)(aname("axisangle").c_str(), alt.axisangle, ref_alt.axisangle, tooltip); + (*this)(aname("axisangle").c_str(), alt.axisangle, ref_alt.axisangle, + tooltip); break; case mjORIENTATION_XYAXES: (*this)(aname("xyaxes").c_str(), alt.xyaxes, ref_alt.xyaxes, tooltip); @@ -328,7 +326,6 @@ bool ImGui_Slider(const char* name, mjtNum* value, mjtNum min, mjtNum max) { return res; } - bool ImGui_BeginHSplit(const char* id, float* height, bool* open) { const ImVec2 region = ImGui::GetContentRegionAvail(); if (*height < 0) { diff --git a/src/experimental/platform/imgui_widgets.h b/src/experimental/platform/ux/imgui_widgets.h similarity index 97% rename from src/experimental/platform/imgui_widgets.h rename to src/experimental/platform/ux/imgui_widgets.h index 9bf2a4f3..619e1055 100644 --- a/src/experimental/platform/imgui_widgets.h +++ b/src/experimental/platform/ux/imgui_widgets.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_IMGUI_WIDGETS_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_IMGUI_WIDGETS_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_WIDGETS_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_WIDGETS_H_ #include #include @@ -28,7 +28,7 @@ #include #include #include -#include "experimental/platform/enum_utils.h" +#include "experimental/platform/ux/enum_utils.h" namespace mujoco::platform { @@ -140,9 +140,7 @@ struct ScopedStyle { return *this; } - ImVec4 CurrentColor(ImGuiCol col) { - return ImGui::GetStyle().Colors[col]; - } + ImVec4 CurrentColor(ImGuiCol col) { return ImGui::GetStyle().Colors[col]; } void Reset() { ImGui::PopStyleVar(num_vars); @@ -200,8 +198,7 @@ class ImGui_DataPtrTable { class ImGui_SpecElementTable : public ImGui_DataPtrTable { public: explicit ImGui_SpecElementTable(bool read_only = true) - : read_only_(read_only) { - } + : read_only_(read_only) {} // Scalar values used by mjSpec elements. void operator()(const char* label, mjtByte& val, const mjtByte& ref, @@ -273,8 +270,9 @@ class ImGui_SpecElementTable : public ImGui_DataPtrTable { } // Special handling for treating enum values as integers. - template , T>> - void operator()(const char* label, T& val, const T& ref, const char* tooltip) { + template , T>> + void operator()(const char* label, T& val, const T& ref, + const char* tooltip) { Label(label, tooltip); Input(val, ref); } @@ -570,4 +568,4 @@ void MaybeSaveToClipboard(const std::string& contents); } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_IMGUI_WIDGETS_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_IMGUI_WIDGETS_H_ diff --git a/src/experimental/platform/interaction.cc b/src/experimental/platform/ux/interaction.cc similarity index 97% rename from src/experimental/platform/interaction.cc rename to src/experimental/platform/ux/interaction.cc index 149e0c1a..646684b2 100644 --- a/src/experimental/platform/interaction.cc +++ b/src/experimental/platform/ux/interaction.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/interaction.h" +#include "experimental/platform/ux/interaction.h" #include #include @@ -245,7 +245,8 @@ void MoveCamera(const mjModel* m, const mjData* d, mjvCamera* cam, // y movement: either dolly (forward/back) or pedestal (up/down) mju_addToScl3(cam->lookat, - (motion == CameraMotion::TRUCK_PEDESTAL) ? up : forward, dy); + (motion == CameraMotion::TRUCK_PEDESTAL) ? up : forward, + dy); // x movement: camera truck (left/right) mju_addToScl3(cam->lookat, right, dx); @@ -341,8 +342,9 @@ static PickResult PickGeom(const mjModel* m, const mjData* d, const mjtNum ray_pos[3], const mjtNum ray_dir[3], const mjvOption* vis_options) { PickResult result; - result.dist = mj_ray(m, d, ray_pos, ray_dir, vis_options->geomgroup, - vis_options->flags[mjVIS_STATIC], -1, &result.geom, nullptr); + result.dist = + mj_ray(m, d, ray_pos, ray_dir, vis_options->geomgroup, + vis_options->flags[mjVIS_STATIC], -1, &result.geom, nullptr); mju_addScl3(result.point, ray_pos, ray_dir, result.dist); result.body = m->geom_bodyid[result.geom]; return result; @@ -541,8 +543,8 @@ static PickResult PickSkin(const mjModel* m, const mjData* d, int vertid; mjtNum test_dist = mju_raySkin(m->skin_facenum[i], m->skin_vertnum[i], - m->skin_face + 3 * m->skin_faceadr[i], - skinvert, ray_pos, ray_dir, &vertid); + m->skin_face + 3 * m->skin_faceadr[i], + skinvert, ray_pos, ray_dir, &vertid); if (test_dist < 0) { continue; } else if (result.dist >= 0 && test_dist >= result.dist) { @@ -554,9 +556,9 @@ static PickResult PickSkin(const mjModel* m, const mjData* d, // find body with largest weight for this vertex float best_weight = -1; for (int j = m->skin_boneadr[i]; - j < m->skin_boneadr[i] + m->skin_bonenum[i]; j++) { + j < m->skin_boneadr[i] + m->skin_bonenum[i]; j++) { for (int k = m->skin_bonevertadr[j]; - k < m->skin_bonevertadr[j] + m->skin_bonevertnum[j]; k++) { + k < m->skin_bonevertadr[j] + m->skin_bonevertnum[j]; k++) { // get vertex id and weight const int vertex_id = m->skin_bonevertid[k]; const float vertex_weight = m->skin_bonevertweight[k]; diff --git a/src/experimental/platform/interaction.h b/src/experimental/platform/ux/interaction.h similarity index 92% rename from src/experimental/platform/interaction.h rename to src/experimental/platform/ux/interaction.h index ef9e8c2c..9e6e9972 100644 --- a/src/experimental/platform/interaction.h +++ b/src/experimental/platform/ux/interaction.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_INTERACTION_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_INTERACTION_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_INTERACTION_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_INTERACTION_H_ #include @@ -22,7 +22,7 @@ namespace mujoco::platform { // The result of a pick operation. struct PickResult { mjtNum point[3] = {0, 0, 0}; // World coordinates - mjtNum dist = -1; // Distance from the camera. + mjtNum dist = -1; // Distance from the camera. int body = -1; int geom = -1; int flex = -1; @@ -77,9 +77,8 @@ void InitPerturb(const mjModel* m, const mjData* d, const mjvCamera* cam, mjvPerturb* pert, mjtPertBit active); void MovePerturb(const mjModel* m, const mjData* d, const mjvCamera* cam, - mjvPerturb* pert, mjtMouse action, mjtNum reldx, - mjtNum reldy); + mjvPerturb* pert, mjtMouse action, mjtNum reldx, mjtNum reldy); } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_INTERACTION_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_INTERACTION_H_ diff --git a/src/experimental/platform/object_launcher_plugin.cc b/src/experimental/platform/ux/object_launcher_plugin.cc similarity index 96% rename from src/experimental/platform/object_launcher_plugin.cc rename to src/experimental/platform/ux/object_launcher_plugin.cc index ad065bae..d4de9414 100644 --- a/src/experimental/platform/object_launcher_plugin.cc +++ b/src/experimental/platform/ux/object_launcher_plugin.cc @@ -19,8 +19,8 @@ #include #include -#include "experimental/platform/imgui_widgets.h" -#include "experimental/platform/plugin.h" +#include "experimental/platform/ux/imgui_widgets.h" +#include "experimental/platform/ux/plugin.h" namespace mujoco::studio { @@ -53,7 +53,9 @@ class ObjectLauncher { } } - void HandleKeyboardEvent() { if (enabled_) active_ = true; } + void HandleKeyboardEvent() { + if (enabled_) active_ = true; + } bool UpdateSpecPreCompile(mjSpec* spec, const mjModel* model, const mjData* data, const mjvCamera* camera) { @@ -88,7 +90,8 @@ class ObjectLauncher { if (!geom) return false; ObjectInfo& object = objects_.emplace_back(); - object.name = "projectile" + std::to_string(counter_++);; + object.name = "projectile" + std::to_string(counter_++); + ; object.expiration = data->time + lifetime_; mjtNum pos[3]; diff --git a/src/experimental/platform/picture_gui.cc b/src/experimental/platform/ux/picture_gui.cc similarity index 93% rename from src/experimental/platform/picture_gui.cc rename to src/experimental/platform/ux/picture_gui.cc index 33f169af..7281c3d7 100644 --- a/src/experimental/platform/picture_gui.cc +++ b/src/experimental/platform/ux/picture_gui.cc @@ -12,16 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/picture_gui.h" +#include "experimental/platform/ux/picture_gui.h" #include #include #include #include -#include "experimental/platform/imgui_widgets.h" -#include "experimental/platform/renderer.h" -#include "experimental/platform/window.h" +#include "experimental/platform/hal/renderer.h" +#include "experimental/platform/hal/window.h" +#include "experimental/platform/ux/imgui_widgets.h" namespace mujoco::platform { @@ -44,7 +44,7 @@ static bool PipGuiImpl(const mjModel* model, mjData* data, const int height = width / window->GetAspectRatio(); std::vector output(width * height * 3); - const int combo_width = (width-30) / 2; + const int combo_width = (width - 30) / 2; ImGui::PushID(pip); ImGui::SetNextItemWidth(combo_width); diff --git a/src/experimental/platform/picture_gui.h b/src/experimental/platform/ux/picture_gui.h similarity index 80% rename from src/experimental/platform/picture_gui.h rename to src/experimental/platform/ux/picture_gui.h index 73abdb2b..ef80d1f4 100644 --- a/src/experimental/platform/picture_gui.h +++ b/src/experimental/platform/ux/picture_gui.h @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_PICTURE_GUI_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_PICTURE_GUI_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_PICTURE_GUI_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_PICTURE_GUI_H_ #include #include -#include "experimental/platform/renderer.h" -#include "experimental/platform/window.h" +#include "experimental/platform/hal/renderer.h" +#include "experimental/platform/hal/window.h" namespace mujoco::platform { @@ -37,4 +37,4 @@ void PipGui(const mjModel* model, mjData* data, platform::Window* window, } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_PICTURE_GUI_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_PICTURE_GUI_H_ diff --git a/src/experimental/platform/plugin.cc b/src/experimental/platform/ux/plugin.cc similarity index 98% rename from src/experimental/platform/plugin.cc rename to src/experimental/platform/ux/plugin.cc index 3ddb6e1b..058e9bd5 100644 --- a/src/experimental/platform/plugin.cc +++ b/src/experimental/platform/ux/plugin.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/plugin.h" +#include "experimental/platform/ux/plugin.h" #include #include diff --git a/src/experimental/platform/plugin.h b/src/experimental/platform/ux/plugin.h similarity index 96% rename from src/experimental/platform/plugin.h rename to src/experimental/platform/ux/plugin.h index 5e47fae9..a8eaf23e 100644 --- a/src/experimental/platform/plugin.h +++ b/src/experimental/platform/ux/plugin.h @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_PLUGIN_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_PLUGIN_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_PLUGIN_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_PLUGIN_H_ #include + #include namespace mujoco::platform { @@ -30,7 +31,6 @@ void RegisterPlugin(T plugin); template void ForEachPlugin(const std::function& fn); - // Plugin for processing custom UI windows. The plugin will be listed in the // "Plugins" main menu and, when selected, an ImGui window will be opened with // the name of the plugin as the title. The `update` function can then be used @@ -123,4 +123,4 @@ struct SpecEditorPlugin final { } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_PLUGIN_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_PLUGIN_H_ diff --git a/src/experimental/platform/spec_editor.cc b/src/experimental/platform/ux/spec_editor.cc similarity index 93% rename from src/experimental/platform/spec_editor.cc rename to src/experimental/platform/ux/spec_editor.cc index dab71b49..38eab60d 100644 --- a/src/experimental/platform/spec_editor.cc +++ b/src/experimental/platform/ux/spec_editor.cc @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/platform/spec_editor.h" +#include "experimental/platform/ux/spec_editor.h" #include #include + #include -#include "experimental/platform/model_holder.h" +#include "experimental/platform/sim/model_holder.h" namespace mujoco::platform { @@ -62,9 +63,7 @@ std::unique_ptr SpecEditor::Compile() { return holder; } -mjSpec* SpecEditor::GetActiveSpec() const { - return active_spec_.get(); -} +mjSpec* SpecEditor::GetActiveSpec() const { return active_spec_.get(); } mjsElement* SpecEditor::AddElement(mjtObj type) { // TODO: check that type is only for spec elements. @@ -135,7 +134,7 @@ void SpecEditor::SetActiveElement(mjsElement* element) { int index = 0; for (mjsElement* iter = mjs_firstElement(spec, type); iter != nullptr; - iter = mjs_nextElement(spec, iter), ++index) { + iter = mjs_nextElement(spec, iter), ++index) { if (iter == element) { active_element_key_ = active_map_.LookupElementKey({type, index}); if (active_element_key_ == kInvalidElementKey) { @@ -171,13 +170,9 @@ void SpecEditor::UpdateReferenceElement() { } } -mjsElement* SpecEditor::GetActiveElement() const { - return active_element_; -} +mjsElement* SpecEditor::GetActiveElement() const { return active_element_; } -mjsElement* SpecEditor::GetRefElement() const { - return ref_element_; -} +mjsElement* SpecEditor::GetRefElement() const { return ref_element_; } void SpecEditor::CommitChanges(mjsElement* element) { if (element == nullptr) { @@ -209,14 +204,13 @@ void SpecEditor::Undo() { active_map_.Insert(entry.key, entry.type_index); } - active_element_ = active_map_.Resolve(active_spec_.get(), active_element_key_); + active_element_ = + active_map_.Resolve(active_spec_.get(), active_element_key_); UpdateReferenceElement(); } } -bool SpecEditor::CanUndo() const { - return cursor_ > 0; -} +bool SpecEditor::CanUndo() const { return cursor_ > 0; } void SpecEditor::Redo() { if (CanRedo()) { @@ -230,14 +224,13 @@ void SpecEditor::Redo() { active_map_.Remove(entry.key); } - active_element_ = active_map_.Resolve(active_spec_.get(), active_element_key_); + active_element_ = + active_map_.Resolve(active_spec_.get(), active_element_key_); UpdateReferenceElement(); } } -bool SpecEditor::CanRedo() const { - return cursor_ < history_.size() - 1; -} +bool SpecEditor::CanRedo() const { return cursor_ < history_.size() - 1; } void SpecEditor::AppendHistory(HistoryEntry entry) { ++cursor_; @@ -312,7 +305,8 @@ SpecEditor::SpecPtr SpecEditor::Copy(const mjSpec* spec) { return SpecPtr(mj_copySpec(spec), mj_deleteSpec); } -mjsElement* SpecEditor::AddElementToSpec(mjSpec* spec, mjtObj type, mjsBody* body) { +mjsElement* SpecEditor::AddElementToSpec(mjSpec* spec, mjtObj type, + mjsBody* body) { if (spec == nullptr || type == mjOBJ_UNKNOWN) { return nullptr; } diff --git a/src/experimental/platform/spec_editor.h b/src/experimental/platform/ux/spec_editor.h similarity index 92% rename from src/experimental/platform/spec_editor.h rename to src/experimental/platform/ux/spec_editor.h index b9338c94..1576396d 100644 --- a/src/experimental/platform/spec_editor.h +++ b/src/experimental/platform/ux/spec_editor.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SPEC_EDITOR_H_ -#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SPEC_EDITOR_H_ +#ifndef MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_SPEC_EDITOR_H_ +#define MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_SPEC_EDITOR_H_ #include #include @@ -22,7 +22,7 @@ #include #include -#include "experimental/platform/model_holder.h" +#include "experimental/platform/sim/model_holder.h" namespace mujoco::platform { @@ -139,10 +139,10 @@ class SpecEditor { // A single entry in the history buffer. struct HistoryEntry { - SpecPtr spec; // A full copy of a spec. - Operation op; // The operation performed on the spec. - ElementKey key; // The key of the element being modified. - TypeIndex type_index; // The type/index of the element after the change. + SpecPtr spec; // A full copy of a spec. + Operation op; // The operation performed on the spec. + ElementKey key; // The key of the element being modified. + TypeIndex type_index; // The type/index of the element after the change. }; // Appends a new HistoryEntry to the history buffer. @@ -174,4 +174,4 @@ class SpecEditor { }; } // namespace mujoco::platform -#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_SPEC_EDITOR_H_ +#endif // MUJOCO_SRC_EXPERIMENTAL_PLATFORM_UX_SPEC_EDITOR_H_ diff --git a/src/experimental/studio/app.cc b/src/experimental/studio/app.cc index 7dadad45..b9cf91fb 100644 --- a/src/experimental/studio/app.cc +++ b/src/experimental/studio/app.cc @@ -35,19 +35,19 @@ #include #include #include -#include "experimental/platform/file_dialog.h" -#include "experimental/platform/graphics_mode.h" -#include "experimental/platform/gui.h" -#include "experimental/platform/gui_spec.h" +#include "experimental/platform/hal/graphics_mode.h" +#include "experimental/platform/hal/renderer.h" +#include "experimental/platform/hal/window.h" #include "experimental/platform/helpers.h" -#include "experimental/platform/imgui_widgets.h" -#include "experimental/platform/interaction.h" -#include "experimental/platform/model_holder.h" -#include "experimental/platform/picture_gui.h" -#include "experimental/platform/plugin.h" -#include "experimental/platform/renderer.h" -#include "experimental/platform/step_control.h" -#include "experimental/platform/window.h" +#include "experimental/platform/sim/model_holder.h" +#include "experimental/platform/sim/step_control.h" +#include "experimental/platform/ux/file_dialog.h" +#include "experimental/platform/ux/gui.h" +#include "experimental/platform/ux/gui_spec.h" +#include "experimental/platform/ux/imgui_widgets.h" +#include "experimental/platform/ux/interaction.h" +#include "experimental/platform/ux/picture_gui.h" +#include "experimental/platform/ux/plugin.h" namespace mujoco::studio { @@ -727,7 +727,7 @@ void App::HandleKeyboardEvents() { ui_.camera_idx = platform::SetCamera(model(), &camera_, ui_.camera_idx - 1); } else if (has_model() && ImGui_IsChordJustPressed(ImGuiKey_RightBracket)) { ui_.camera_idx = platform::SetCamera(model(), &camera_, ui_.camera_idx + 1); - // WASD camera controls for free camera. + // WASD camera controls for free camera. } else if (is_freecam_wasd && (ImGui::IsKeyDown(ImGuiKey_W) || ImGui::IsKeyDown(ImGuiKey_S) || ImGui::IsKeyDown(ImGuiKey_A) || ImGui::IsKeyDown(ImGuiKey_D) || @@ -1129,8 +1129,8 @@ void App::SpecExplorerGui() { mjsElement* element = tmp_.curr_element; bool open = element != nullptr; - if (platform::ImGui_BeginHSplit("SpecExplorerTree", - &tmp_.explorer_split, &open)) { + if (platform::ImGui_BeginHSplit("SpecExplorerTree", &tmp_.explorer_split, + &open)) { platform::SpecTreeGui(&element, spec()); if (element != tmp_.curr_element) { @@ -1147,8 +1147,8 @@ void App::SpecExplorerGui() { } } - if (platform::ImGui_HSplit("SpecExplorerProperties", - &tmp_.explorer_split, &open)) { + if (platform::ImGui_HSplit("SpecExplorerProperties", &tmp_.explorer_split, + &open)) { ImGui::Text("%s", mju_type2Str(tmp_.curr_element->elemtype)); ImGui::SameLine(); ImGui::Text("(%d)", mjs_getId(tmp_.curr_element)); @@ -1434,8 +1434,9 @@ void App::ToolBarGui() { const float label_width = GetExpectedLabelWidth(); const float copy_btn_width = ImGui::CalcTextSize(ICON_COPY_CAMERA).x + ImGui::GetStyle().FramePadding.x * 2; - const float theme_width = ImGui::CalcTextSize(platform::ICON_FA_CIRCLE_O).x + - ImGui::GetStyle().FramePadding.x * 2; + const float theme_width = + ImGui::CalcTextSize(platform::ICON_FA_CIRCLE_O).x + + ImGui::GetStyle().FramePadding.x * 2; const float sp = ImGui::GetStyle().ItemSpacing.x; const float right_width = label_width + sp + label_width + sp + label_width + sp + copy_btn_width + sp + @@ -1766,8 +1767,7 @@ void App::MainMenuGui() { } ImGui::Separator(); - - #ifdef __linux__ +#ifdef __linux__ if (ImGui::BeginMenu("Graphics Mode (Experimental)")) { std::optional mode; if (ImGui::MenuItem( @@ -1814,7 +1814,7 @@ void App::MainMenuGui() { } ImGui::EndMenu(); } - #endif // __linux__ +#endif // __linux__ ImGui::EndMenu(); } diff --git a/src/experimental/studio/app.h b/src/experimental/studio/app.h index 7b438d68..222cdf73 100644 --- a/src/experimental/studio/app.h +++ b/src/experimental/studio/app.h @@ -26,18 +26,18 @@ #include #include -#include "experimental/platform/graphics_mode.h" -#include "experimental/platform/gui.h" -#include "experimental/platform/gui_spec.h" -#include "experimental/platform/interaction.h" -#include "experimental/platform/model_holder.h" -#include "experimental/platform/picture_gui.h" -#include "experimental/platform/renderer.h" -#include "experimental/platform/sim_history.h" -#include "experimental/platform/sim_profiler.h" -#include "experimental/platform/spec_editor.h" -#include "experimental/platform/step_control.h" -#include "experimental/platform/window.h" +#include "experimental/platform/hal/graphics_mode.h" +#include "experimental/platform/hal/renderer.h" +#include "experimental/platform/hal/window.h" +#include "experimental/platform/sim/model_holder.h" +#include "experimental/platform/sim/sim_history.h" +#include "experimental/platform/sim/sim_profiler.h" +#include "experimental/platform/sim/step_control.h" +#include "experimental/platform/ux/gui.h" +#include "experimental/platform/ux/gui_spec.h" +#include "experimental/platform/ux/interaction.h" +#include "experimental/platform/ux/picture_gui.h" +#include "experimental/platform/ux/spec_editor.h" namespace mujoco::studio { diff --git a/src/experimental/studio/main.cc b/src/experimental/studio/main.cc index 87f67351..9d48834f 100644 --- a/src/experimental/studio/main.cc +++ b/src/experimental/studio/main.cc @@ -26,7 +26,7 @@ #include #include #include -#include "experimental/platform/graphics_mode.h" +#include "experimental/platform/hal/graphics_mode.h" #include "experimental/studio/app.h" ABSL_FLAG(int, window_width, 1400, "Window width"); diff --git a/src/experimental/studio/wasm.cc b/src/experimental/studio/wasm.cc index 1a4738a7..8e5e8768 100644 --- a/src/experimental/studio/wasm.cc +++ b/src/experimental/studio/wasm.cc @@ -25,7 +25,7 @@ #include #include -#include "experimental/platform/graphics_mode.h" +#include "experimental/platform/hal/graphics_mode.h" #include "experimental/studio/app.h" // Global app instance. Lifetime is controlled by Init/Deinit calls which are