Implementation:Google deepmind Mujoco Platform UI Adapter
| Knowledge Sources | |
|---|---|
| Domains | Platform Abstraction, Input Handling, GUI, Rendering |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Base platform UI adapter implementation providing default rendering context management and input event translation from platform-specific events to MuJoCo UI state updates.
Description
This file implements the PlatformUIAdapter base class methods that are shared across all platform backends. It manages the mjrContext lifecycle (default initialization, creation from model, and freeing), translates platform input events (key presses, mouse button clicks, mouse movement, scroll wheel, file drops, window resize, and window refresh) into mjuiState updates, and dispatches them to an optional application-level event callback. Key translation and mouse button mapping are delegated to virtual methods overridden by platform-specific subclasses.
Usage
Serves as the base class for platform-specific adapters like GlfwAdapter. The Simulate class interacts with this interface for all platform operations, while subclasses override the pure virtual methods for window-specific behavior.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: simulate/platform_ui_adapter.cc
- Lines: 1-248
Key Functions
// Constructor: initialize default mjrContext
PlatformUIAdapter::PlatformUIAdapter();
// Free the OpenGL rendering context
void PlatformUIAdapter::FreeMjrContext();
// Create or refresh rendering context for a model
bool PlatformUIAdapter::RefreshMjrContext(const mjModel* m, int fontscale);
// Input event handlers
void PlatformUIAdapter::OnFilesDrop(int count, const char** paths);
void PlatformUIAdapter::OnKey(int key, int scancode, int act);
void PlatformUIAdapter::OnMouseButton(int button, int act);
void PlatformUIAdapter::OnMouseMove(double x, double y);
void PlatformUIAdapter::OnScroll(double xoffset, double yoffset);
// Window event handlers
void PlatformUIAdapter::OnWindowRefresh();
void PlatformUIAdapter::OnWindowResize(int width, int height);
// Update mjuiState from current platform state
void PlatformUIAdapter::UpdateMjuiState();
Import
#include "platform_ui_adapter.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | const mjModel* | Yes (for RefreshMjrContext) | Model used to create rendering context resources |
| fontscale | int | Yes (for RefreshMjrContext) | Font scale constant (mjtFontScale) |
| key | int | Yes (for OnKey) | Platform-specific key code, translated via TranslateKeyCode |
| button | int | Yes (for OnMouseButton) | Platform-specific mouse button identifier |
| x, y | double | Yes (for OnMouseMove) | Mouse cursor coordinates |
| xoffset, yoffset | double | Yes (for OnScroll) | Scroll wheel delta values |
Outputs
| Name | Type | Description |
|---|---|---|
| con_ | mjrContext | Internal rendering context created/refreshed for the model |
| state_ | mjuiState | Updated UI state reflecting current input (mouse, keys, modifiers) |
| return value (RefreshMjrContext) | bool | True if the context was newly created or refreshed |